Various build fixes for host builds

This commit is contained in:
Luke Street 2022-10-20 21:32:04 -04:00
parent f535084540
commit 2659556809
22 changed files with 13340 additions and 3438 deletions

View File

@ -8,7 +8,6 @@
], ],
"cStandard": "c99", "cStandard": "c99",
"cppStandard": "c++98", "cppStandard": "c++98",
"defines": ["__MWERKS__=1"],
"intelliSenseMode": "linux-clang-x86", "intelliSenseMode": "linux-clang-x86",
"compilerPath": "" "compilerPath": ""
} }

View File

@ -26,6 +26,7 @@ LIBS = [
"lib": "TRK_MINNOW_DOLPHIN", "lib": "TRK_MINNOW_DOLPHIN",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["MetroTRK/mslsupp", True], ["MetroTRK/mslsupp", True],
], ],
@ -34,6 +35,7 @@ LIBS = [
"lib": "MetroidPrimeCW", "lib": "MetroidPrimeCW",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"host": True,
"objects": [ "objects": [
["MetroidPrime/main", False], ["MetroidPrime/main", False],
"MetroidPrime/IRenderer", "MetroidPrime/IRenderer",
@ -86,7 +88,7 @@ LIBS = [
"MetroidPrime/CPauseScreen", "MetroidPrime/CPauseScreen",
"MetroidPrime/Tweaks/CTweakGui", "MetroidPrime/Tweaks/CTweakGui",
"MetroidPrime/ScriptObjects/CScriptActor", "MetroidPrime/ScriptObjects/CScriptActor",
"MetroidPrime/ScriptObjects/CScriptTrigger", ["MetroidPrime/ScriptObjects/CScriptTrigger", False],
"MetroidPrime/ScriptObjects/CScriptWaypoint", "MetroidPrime/ScriptObjects/CScriptWaypoint",
"MetroidPrime/Enemies/CPatterned", "MetroidPrime/Enemies/CPatterned",
"MetroidPrime/ScriptObjects/CScriptDoor", "MetroidPrime/ScriptObjects/CScriptDoor",
@ -231,7 +233,7 @@ LIBS = [
"MetroidPrime/Factories/CScannableObjectInfo", "MetroidPrime/Factories/CScannableObjectInfo",
"MetroidPrime/Enemies/CMetroid", "MetroidPrime/Enemies/CMetroid",
"MetroidPrime/Player/CScanDisplay", "MetroidPrime/Player/CScanDisplay",
"MetroidPrime/ScriptObjects/CScriptSteam", ["MetroidPrime/ScriptObjects/CScriptSteam", False],
["MetroidPrime/ScriptObjects/CScriptRipple", False], ["MetroidPrime/ScriptObjects/CScriptRipple", False],
"MetroidPrime/CBoneTracking", "MetroidPrime/CBoneTracking",
"MetroidPrime/Player/CFaceplateDecoration", "MetroidPrime/Player/CFaceplateDecoration",
@ -395,6 +397,7 @@ LIBS = [
"lib": "WorldFormatCW", "lib": "WorldFormatCW",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"WorldFormat/CAreaOctTree_Tests", "WorldFormat/CAreaOctTree_Tests",
["WorldFormat/CCollisionSurface", True], ["WorldFormat/CCollisionSurface", True],
@ -414,6 +417,7 @@ LIBS = [
"lib": "WeaponsCW", "lib": "WeaponsCW",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"Weapons/CProjectileWeapon", "Weapons/CProjectileWeapon",
"Weapons/CProjectileWeaponDataFactory", "Weapons/CProjectileWeaponDataFactory",
@ -429,12 +433,14 @@ LIBS = [
"lib": "MetaRenderCW", "lib": "MetaRenderCW",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": ["MetaRender/CCubeRenderer"], "objects": ["MetaRender/CCubeRenderer"],
}, },
{ {
"lib": "GuiSysCW", "lib": "GuiSysCW",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"GuiSys/CAuiMain", "GuiSys/CAuiMain",
"GuiSys/CAuiMeter", "GuiSys/CAuiMeter",
@ -461,6 +467,7 @@ LIBS = [
"lib": "CollisionCW", "lib": "CollisionCW",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"Collision/CCollidableAABox", "Collision/CCollidableAABox",
"Collision/CCollidableCollisionSurface", "Collision/CCollidableCollisionSurface",
@ -479,6 +486,7 @@ LIBS = [
"lib": "Kyoto_CW1", "lib": "Kyoto_CW1",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"Kyoto/Basics/CBasics", "Kyoto/Basics/CBasics",
["Kyoto/Basics/CStopwatch", True], ["Kyoto/Basics/CStopwatch", True],
@ -632,6 +640,7 @@ LIBS = [
"lib": "zlib", "lib": "zlib",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_runtime", "cflags": "$cflags_runtime",
"host": True,
"objects": [ "objects": [
["Kyoto/zlib/adler32", True], ["Kyoto/zlib/adler32", True],
["Kyoto/zlib/infblock", True], ["Kyoto/zlib/infblock", True],
@ -647,6 +656,7 @@ LIBS = [
"lib": "Kyoto_CW2", "lib": "Kyoto_CW2",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True,
"objects": [ "objects": [
"Kyoto/CARAMManager", "Kyoto/CARAMManager",
"Kyoto/Math/CFrustumPlanes", "Kyoto/Math/CFrustumPlanes",
@ -708,6 +718,7 @@ LIBS = [
"lib": "ai", "lib": "ai",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/ai", False], ["Dolphin/ai", False],
], ],
@ -716,6 +727,7 @@ LIBS = [
"lib": "ar", "lib": "ar",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/ar/ar", "Dolphin/ar/ar",
"Dolphin/ar/arq", "Dolphin/ar/arq",
@ -725,6 +737,7 @@ LIBS = [
"lib": "base", "lib": "base",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/PPCArch", True], ["Dolphin/PPCArch", True],
], ],
@ -733,6 +746,7 @@ LIBS = [
"lib": "db", "lib": "db",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/db", True], ["Dolphin/db", True],
], ],
@ -741,6 +755,7 @@ LIBS = [
"lib": "dsp", "lib": "dsp",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/dsp/dsp", False], ["Dolphin/dsp/dsp", False],
["Dolphin/dsp/dsp_debug", True], ["Dolphin/dsp/dsp_debug", True],
@ -751,6 +766,7 @@ LIBS = [
"lib": "dvd", "lib": "dvd",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/dvd/dvdlow", "Dolphin/dvd/dvdlow",
"Dolphin/dvd/dvdfs", "Dolphin/dvd/dvdfs",
@ -766,6 +782,7 @@ LIBS = [
"lib": "gx", "lib": "gx",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/gx/GXInit", "Dolphin/gx/GXInit",
"Dolphin/gx/GXFifo", "Dolphin/gx/GXFifo",
@ -788,6 +805,7 @@ LIBS = [
"lib": "mtx", "lib": "mtx",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/mtx/mtx", "Dolphin/mtx/mtx",
"Dolphin/mtx/mtx44vec", "Dolphin/mtx/mtx44vec",
@ -800,6 +818,7 @@ LIBS = [
"lib": "os", "lib": "os",
"mwcc_version": "1.2.5e", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/os/__start", True], ["Dolphin/os/__start", True],
"Dolphin/os/OS", "Dolphin/os/OS",
@ -829,6 +848,7 @@ LIBS = [
"lib": "pad", "lib": "pad",
"mwcc_version": "1.2.5e", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/pad/PadClamp", True], ["Dolphin/pad/PadClamp", True],
["Dolphin/pad/pad", False], ["Dolphin/pad/pad", False],
@ -838,12 +858,16 @@ LIBS = [
"lib": "vi", "lib": "vi",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"objects": ["Dolphin/vi"], "host": False,
"objects": [
"Dolphin/vi"
],
}, },
{ {
"lib": "MSL_C.PPCEABI.bare.H", "lib": "MSL_C.PPCEABI.bare.H",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_runtime", "cflags": "$cflags_runtime",
"host": False,
"objects": [ "objects": [
["Runtime/__mem", True], ["Runtime/__mem", True],
["Runtime/__va_arg", True], ["Runtime/__va_arg", True],
@ -915,6 +939,7 @@ LIBS = [
"lib": "musyx", "lib": "musyx",
"mwcc_version": "1.3.2", "mwcc_version": "1.3.2",
"cflags": "$cflags_musyx", "cflags": "$cflags_musyx",
"host": False,
"objects": [ "objects": [
"musyx/seq", "musyx/seq",
"musyx/synth", "musyx/synth",
@ -953,6 +978,7 @@ LIBS = [
"lib": "dtk", "lib": "dtk",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/dtk", True], ["Dolphin/dtk", True],
], ],
@ -961,6 +987,7 @@ LIBS = [
"lib": "card", "lib": "card",
"mwcc_version": "1.2.5e", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/card/CARDBios", False], ["Dolphin/card/CARDBios", False],
["Dolphin/card/CARDUnlock", True], ["Dolphin/card/CARDUnlock", True],
@ -984,6 +1011,7 @@ LIBS = [
"lib": "si", "lib": "si",
"mwcc_version": "1.2.5e", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/si/SIBios", False], ["Dolphin/si/SIBios", False],
["Dolphin/si/SISamplingRate", True], ["Dolphin/si/SISamplingRate", True],
@ -993,6 +1021,7 @@ LIBS = [
"lib": "exi", "lib": "exi",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/exi/EXIBios", "Dolphin/exi/EXIBios",
"Dolphin/exi/EXIUart", "Dolphin/exi/EXIUart",
@ -1002,6 +1031,7 @@ LIBS = [
"lib": "thp", "lib": "thp",
"mwcc_version": "1.2.5", "mwcc_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
"Dolphin/thp/THPDec", "Dolphin/thp/THPDec",
"Dolphin/thp/THPAudio", "Dolphin/thp/THPAudio",
@ -1011,6 +1041,7 @@ LIBS = [
"lib": "gba", "lib": "gba",
"mwcc_version": "1.2.5e", "mwcc_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False,
"objects": [ "objects": [
["Dolphin/GBA/GBA", True], ["Dolphin/GBA/GBA", True],
["Dolphin/GBA/GBAGetProcessStatus", False], ["Dolphin/GBA/GBAGetProcessStatus", False],
@ -1092,6 +1123,9 @@ else:
n.variable("wine", "wine ") n.variable("wine", "wine ")
n.variable("exe", "") n.variable("exe", "")
n.newline() n.newline()
n.variable("host_cflags", "-I include/ -Wno-trigraphs")
n.variable("host_cppflags",
"-std=c++98 -I include/ -fno-exceptions -fno-rtti -Wno-trigraphs")
### ###
# Rules # Rules
@ -1133,10 +1167,9 @@ else:
n.rule(name="ar", command="$devkitppc/bin/powerpc-eabi-ar crs $out $in", n.rule(name="ar", command="$devkitppc/bin/powerpc-eabi-ar crs $out $in",
description="AR $out") description="AR $out")
n.newline() n.newline()
n.rule(name="host_cc", command="clang $host_cflags -c -o $out $in",
n.rule(name="host_cc", command="clang -I include/ -Wno-trigraphs -o $out $in",
description="host_cc $out") description="host_cc $out")
n.rule(name="host_cpp", command="clang++ -std=c++03 -I include/ -Wno-trigraphs -o $out $in", n.rule(name="host_cpp", command="clang++ $host_cppflags -c -o $out $in",
description="host_c++ $out") description="host_c++ $out")
n.newline() n.newline()
@ -1144,6 +1177,7 @@ n.newline()
# Build # Build
### ###
all_source_files = [] all_source_files = []
all_host_source_files = []
for lib in LIBS: for lib in LIBS:
inputs = [] inputs = []
if "lib" in lib: if "lib" in lib:
@ -1152,7 +1186,7 @@ for lib in LIBS:
else: else:
n.comment("Loose files") n.comment("Loose files")
for object in lib["objects"]: for object in lib["objects"]:
completed = False completed = None
add_to_all = True add_to_all = True
if type(object) is list: if type(object) is list:
if len(object) > 2: if len(object) > 2:
@ -1167,6 +1201,8 @@ for lib in LIBS:
elif os.path.exists(os.path.join("src", f"{object}.c")): elif os.path.exists(os.path.join("src", f"{object}.c")):
c_file = os.path.join("src", f"{object}.c") c_file = os.path.join("src", f"{object}.c")
if c_file is not None: if c_file is not None:
if completed is None:
print(f"Mark as incomplete: {c_file}")
rule = "mwcc" rule = "mwcc"
if mwcc_version == "1.2.5e": if mwcc_version == "1.2.5e":
mwcc_version = "1.2.5" mwcc_version = "1.2.5"
@ -1178,11 +1214,14 @@ for lib in LIBS:
"basedir": os.path.dirname(f"$builddir/src/{object}"), "basedir": os.path.dirname(f"$builddir/src/{object}"),
"basefile": f"$builddir/src/{object}" "basefile": f"$builddir/src/{object}"
}) })
if lib["host"]:
n.build(f"$builddir/host/{object}.o", "host_cc" if c_file.endswith(".c") else "host_cpp", c_file, n.build(f"$builddir/host/{object}.o", "host_cc" if c_file.endswith(".c") else "host_cpp", c_file,
variables={ variables={
"basedir": os.path.dirname(f"$builddir/src/{object}"), "basedir": os.path.dirname(f"$builddir/src/{object}"),
"basefile": f"$builddir/src/{object}" "basefile": f"$builddir/src/{object}"
}) })
if add_to_all:
all_host_source_files.append(f"$builddir/host/{object}.o")
if add_to_all: if add_to_all:
all_source_files.append(f"$builddir/src/{object}.o") all_source_files.append(f"$builddir/src/{object}.o")
if os.path.exists(os.path.join("asm", f"{object}.s")): if os.path.exists(os.path.join("asm", f"{object}.s")):
@ -1232,7 +1271,7 @@ n.newline()
# Helper rule for building all source files, with a host compiler # Helper rule for building all source files, with a host compiler
### ###
n.comment("Adds a command for building all source files with a host compiler") n.comment("Adds a command for building all source files with a host compiler")
n.build("all_source_host", "phony", [s.replace("/src/", "/host/") for s in all_source_files]) n.build("all_source_host", "phony", all_host_source_files)
n.newline() n.newline()
### ###

View File

@ -1,9 +1,9 @@
#ifndef _CMEMORY #ifndef _CMEMORY
#define _CMEMORY #define _CMEMORY
#include "types.h"
#include "Kyoto/Alloc/IAllocator.hpp"
#include "Kyoto/Alloc/CCallStack.hpp" #include "Kyoto/Alloc/CCallStack.hpp"
#include "Kyoto/Alloc/IAllocator.hpp"
#include "types.h"
class COsContext; class COsContext;
class CMemory { class CMemory {
@ -16,7 +16,8 @@ public:
static void SetAllocator(COsContext& ctx, IAllocator& allocator); static void SetAllocator(COsContext& ctx, IAllocator& allocator);
static IAllocator* GetAllocator(); static IAllocator* GetAllocator();
static void* Alloc(size_t len, IAllocator::EHint hint = IAllocator::kHI_None, static void* Alloc(size_t len, IAllocator::EHint hint = IAllocator::kHI_None,
IAllocator::EScope scope = IAllocator::kSC_Unk1, IAllocator::EType type = IAllocator::kTP_Heap, IAllocator::EScope scope = IAllocator::kSC_Unk1,
IAllocator::EType type = IAllocator::kTP_Heap,
const CCallStack& callstack = CCallStack(-1, "??(??)")); const CCallStack& callstack = CCallStack(-1, "??(??)"));
static void Free(const void* ptr); static void Free(const void* ptr);
static void SetOutOfMemoryCallback(IAllocator::FOutOfMemoryCb callback, const void* context); static void SetOutOfMemoryCallback(IAllocator::FOutOfMemoryCb callback, const void* context);
@ -26,13 +27,25 @@ public:
void* operator new(size_t sz, const char*, const char*); void* operator new(size_t sz, const char*, const char*);
void* operator new[](size_t sz, const char*, const char*); void* operator new[](size_t sz, const char*, const char*);
// TODO remove // TODO remove
#ifdef __MWERKS__
inline void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); } inline void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
inline void* operator new[](size_t sz) { return operator new[](sz, "??(??)", nullptr); } inline void* operator new[](size_t sz) { return operator new[](sz, "??(??)", nullptr); }
#else
__attribute__((weak)) void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
__attribute__((weak)) void* operator new[](size_t sz) {
return operator new[](sz, "??(??)", nullptr);
}
#endif
// placement new // placement new
inline void* operator new(size_t n, void* ptr) { return ptr; }; inline void* operator new(size_t n, void* ptr) { return ptr; };
#ifdef __MWERKS__
inline void operator delete(void* ptr) { CMemory::Free(ptr); } inline void operator delete(void* ptr) { CMemory::Free(ptr); }
inline void operator delete[](void* ptr) { CMemory::Free(ptr); } inline void operator delete[](void* ptr) { CMemory::Free(ptr); }
#else
__attribute__((weak)) void operator delete(void* ptr) { CMemory::Free(ptr); }
__attribute__((weak)) void operator delete[](void* ptr) { CMemory::Free(ptr); }
#endif
#define NEW new ("??(??)", nullptr) #define NEW new ("??(??)", nullptr)

View File

@ -10,6 +10,8 @@
#include "Kyoto/CResLoader.hpp" #include "Kyoto/CResLoader.hpp"
#include "Kyoto/IObjectStore.hpp" #include "Kyoto/IObjectStore.hpp"
class IDvdRequest;
class CPakFile : CDvdFile { class CPakFile : CDvdFile {
public: public:
bool IsWorldPak() const { return x28_26_worldPak; } bool IsWorldPak() const { return x28_26_worldPak; }
@ -24,7 +26,7 @@ private:
bool x28_26_worldPak : 1; bool x28_26_worldPak : 1;
bool x28_27_stashedInARAM : 1; bool x28_27_stashedInARAM : 1;
int x2c_asyncLoadPhase; // EAsyncPhase int x2c_asyncLoadPhase; // EAsyncPhase
rstl::auto_ptr< void > x30_dvdReq; // IDvdRequest rstl::auto_ptr< IDvdRequest > x30_dvdReq;
rstl::vector< uchar > x38_headerData; rstl::vector< uchar > x38_headerData;
uint x48_resTableOffset; uint x48_resTableOffset;
uint x4c_resTableCount; uint x4c_resTableCount;

View File

@ -21,6 +21,7 @@ public:
static float SqrtF(float v); static float SqrtF(float v);
static inline float Limit(float v, float h) { return fabs(v) > h ? h * Sign(v) : v; } static inline float Limit(float v, float h) { return fabs(v) > h ? h * Sign(v) : v; }
static inline float Sign(float v) { return FastFSel(v, 1.f, -1.f); } static inline float Sign(float v) { return FastFSel(v, 1.f, -1.f); }
#ifdef __MWERKS__
static inline float FastFSel(register float v, register float h, register float l) { static inline float FastFSel(register float v, register float h, register float l) {
register float out; register float out;
asm { asm {
@ -28,6 +29,11 @@ public:
} }
return out; return out;
} }
#else
static inline float FastFSel(float v, float h, float l) {
return v >= 0.f ? h : l;
}
#endif
static inline float AbsF(float v) { return fabs(v); } static inline float AbsF(float v) { return fabs(v); }
static inline double AbsD(double v) { return fabs(v); } static inline double AbsD(double v) { return fabs(v); }
static inline int AbsI(int v) { return abs(v); } static inline int AbsI(int v) { return abs(v); }

View File

@ -3,6 +3,8 @@
#include "types.h" #include "types.h"
#include "stddef.h"
class CInputStream; class CInputStream;
template < typename T > template < typename T >
struct TType {}; struct TType {};

View File

@ -3,6 +3,7 @@
#include "types.h" #include "types.h"
#include "stddef.h"
class COutputStream; class COutputStream;

View File

@ -6,36 +6,37 @@
#include "rstl/optional_object.hpp" #include "rstl/optional_object.hpp"
#include "rstl/vector.hpp" #include "rstl/vector.hpp"
template < typename T >
T GetAverageValue(const T* ptr, int count); // TODO
template < typename T > template < typename T >
class TAverage : rstl::vector< T > { class TAverage : rstl::vector< T > {
public: public:
TAverage() {} TAverage() {}
TAverage(int capacity, const T& value); TAverage(int capacity, const T& value);
void AddValue(const T& value); void AddValue(const T& value);
rstl::optional_object< T > GetAverage() const { rstl::optional_object< T > GetAverage() const {
if (empty()) { if (this->empty()) {
return rstl::optional_object_null(); return rstl::optional_object_null();
} else { } else {
return GetAverageValue(data(), size()); return GetAverageValue(this->data(), this->size());
} }
} }
}; };
template < typename T > template < typename T >
TAverage< T >::TAverage(int capacity, const T& value) { TAverage< T >::TAverage(int capacity, const T& value) {
resize(capacity, value); this->resize(capacity, value);
} }
template < typename T > template < typename T >
void TAverage< T >::AddValue(const T& value) { void TAverage< T >::AddValue(const T& value) {
if (size() == capacity()) { if (this->size() == this->capacity()) {
// TODO ? // TODO ?
x4_count -= 1; this->x4_count -= 1;
} }
insert(begin(), value); this->insert(this->begin(), value);
} }
template < typename T >
T GetAverageValue(const T* ptr, int count); // TODO
#endif // _TAVERAGE #endif // _TAVERAGE

View File

@ -16,11 +16,11 @@ public:
// resize(value, N); TODO // resize(value, N); TODO
} }
void AddValue(const T& value) { void AddValue(const T& value) {
push_back(value); this->push_back(value);
for (int i = size() - 1; i > 0; --i) { for (int i = this->size() - 1; i > 0; --i) {
operator[](i) = operator[](i - 1); this->operator[](i) = this->operator[](i - 1);
} }
operator[](0) = value; this->operator[](0) = value;
} }
rstl::optional_object< T > GetAverage() const; rstl::optional_object< T > GetAverage() const;
}; };

View File

@ -51,8 +51,9 @@ public:
CTransform4f CalculateCameraBobTransformation() const; CTransform4f CalculateCameraBobTransformation() const;
static void ReadTweaks(CInputStream& in); static void ReadTweaks(CInputStream& in);
static const CVector2f& GetCameraBobExtent() { return CVector2f(kCameraBobExtentX, kCameraBobExtentY); } // static float GetCameraBobExtentX() { return kCameraBobExtentX; }
static float GetCameraBobPeriod() { return kCameraBobPeriod; } // static float GetCameraBobExtentY() { return kCameraBobExtentY; }
// static float GetCameraBobPeriod() { return kCameraBobPeriod; }
static float GetOrbitBobScale() { return kOrbitBobScale; } static float GetOrbitBobScale() { return kOrbitBobScale; }
static float GetMaxOrbitBobScale() { return kMaxOrbitBobScale; } static float GetMaxOrbitBobScale() { return kMaxOrbitBobScale; }
static float GetSlowSpeedPeriodScale() { return kSlowSpeedPeriodScale; } static float GetSlowSpeedPeriodScale() { return kSlowSpeedPeriodScale; }
@ -85,6 +86,7 @@ private:
float x100_wanderMagnitude; float x100_wanderMagnitude;
float x104_targetWanderMagnitude; float x104_targetWanderMagnitude;
public:
static float kCameraBobExtentX; static float kCameraBobExtentX;
static float kCameraBobExtentY; static float kCameraBobExtentY;
static float kCameraBobPeriod; static float kCameraBobPeriod;

View File

@ -17,7 +17,6 @@ private:
typedef red_black_tree< K, value_type, 1, select1st< value_type >, Cmp, Alloc > rep_type; typedef red_black_tree< K, value_type, 1, select1st< value_type >, Cmp, Alloc > rep_type;
public: public:
typedef pair< K, V > value_type;
// typedef typename rep_type::iterator iterator; // typedef typename rep_type::iterator iterator;
typedef typename rep_type::const_iterator const_iterator; typedef typename rep_type::const_iterator const_iterator;

View File

@ -47,7 +47,7 @@ void rc_ptr< T >::ReleaseData() {
template < typename T > template < typename T >
class ncrc_ptr : public rc_ptr< T > { class ncrc_ptr : public rc_ptr< T > {
public: public:
ncrc_ptr(T* ptr) : rc_ptr(ptr) {} ncrc_ptr(T* ptr) : rc_ptr< T >(ptr) {}
}; };
} // namespace rstl } // namespace rstl

View File

@ -144,7 +144,7 @@ void vector< T, Alloc >::reserve(int newSize) {
if (newSize <= x8_capacity) { if (newSize <= x8_capacity) {
return; return;
} }
T* newData = x0_allocator.allocate2< T >(newSize); T* newData = x0_allocator.template allocate2< T >(newSize);
uninitialized_copy(begin(), end(), newData); uninitialized_copy(begin(), end(), newData);
destroy(xc_items, xc_items + x4_count); destroy(xc_items, xc_items + x4_count);
x0_allocator.deallocate(xc_items); x0_allocator.deallocate(xc_items);
@ -154,7 +154,7 @@ void vector< T, Alloc >::reserve(int newSize) {
template < typename T, typename Alloc > template < typename T, typename Alloc >
typename vector< T, Alloc >::iterator vector< T, Alloc >::insert(iterator it, const T& value) { typename vector< T, Alloc >::iterator vector< T, Alloc >::insert(iterator it, const T& value) {
iterator::difference_type diff = it - begin(); // distance(begin(), it); typename iterator::difference_type diff = it - begin(); // distance(begin(), it);
const_counting_iterator< T > in(&value, 0); const_counting_iterator< T > in(&value, 0);
insert_into(it, 1, in); insert_into(it, 1, in);
return begin() + diff; return begin() + diff;

View File

@ -7,6 +7,11 @@
#include "Kyoto/Streams/COutputStream.hpp" #include "Kyoto/Streams/COutputStream.hpp"
#include "types.h" #include "types.h"
#ifndef __MWERKS__
// TODO
#define __HI(x) (*(int*)&x)
#endif
CVector3f CVector3f::sZeroVector(0.f, 0.f, 0.f); CVector3f CVector3f::sZeroVector(0.f, 0.f, 0.f);
CVector3f CVector3f::sUpVector(0.f, 0.f, 1.f); CVector3f CVector3f::sUpVector(0.f, 0.f, 1.f);
CVector3f CVector3f::sDownVector(0.f, 0.f, -1.f); CVector3f CVector3f::sDownVector(0.f, 0.f, -1.f);
@ -26,8 +31,8 @@ void CVector3f::PutTo(COutputStream& out) const {
CVector3f CVector3f::Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle) { CVector3f CVector3f::Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle) {
CVector3f ab = CVector3f::Cross(a, b); CVector3f ab = CVector3f::Cross(a, b);
CVector3f vec = CVector3f::Cross(ab.AsNormalized(), a); CVector3f vec = CVector3f::Cross(ab.AsNormalized(), a);
float sinAngle = sin(angle.AsRadians()); float sinAngle = sine(angle);
float cosAngle = cos(angle.AsRadians()); float cosAngle = cosine(angle);
return cosAngle * a + vec * sinAngle; return cosAngle * a + vec * sinAngle;
} }
@ -79,16 +84,16 @@ bool CVector3f::IsMagnitudeSafe() const {
} }
bool CVector3f::CanBeNormalized() const { bool CVector3f::CanBeNormalized() const {
int x = *(int*)&mX; int x = __HI(mX);
int y = *(int*)&mY; int y = __HI(mY);
int z = *(int*)&mZ; int z = __HI(mZ);
if ((x & 0x7f800000) == 0x7f800000 || (y & 0x7f800000) == 0x7f800000 || if ((x & 0x7f800000) == 0x7f800000 || (y & 0x7f800000) == 0x7f800000 ||
(z & 0x7f800000) == 0x7f800000) { (z & 0x7f800000) == 0x7f800000) {
return false; return false;
} }
if ((float)fabs(mX) < FLT_EPSILON && (float)fabs(mY) < FLT_EPSILON && if (CMath::AbsF(mX) < FLT_EPSILON && CMath::AbsF(mY) < FLT_EPSILON &&
(float)fabs(mZ) < FLT_EPSILON) { CMath::AbsF(mZ) < FLT_EPSILON) {
return false; return false;
} }
@ -113,6 +118,6 @@ float CVector3f::GetAngleDiff(const CVector3f& a, const CVector3f& b) {
} }
bool CVector3f::IsEqu(const CVector3f& vec, float epsilon) const { bool CVector3f::IsEqu(const CVector3f& vec, float epsilon) const {
return (float)fabs(mX - vec.mX) <= epsilon && (float)fabs(mY - vec.mY) <= epsilon && return CMath::AbsF(mX - vec.mX) <= epsilon && CMath::AbsF(mY - vec.mY) <= epsilon &&
(float)fabs(mZ - vec.mZ) <= epsilon; CMath::AbsF(mZ - vec.mZ) <= epsilon;
} }

View File

@ -2,8 +2,8 @@
#include "string.h" #include "string.h"
#include "Kyoto/Streams/StreamSupport.hpp"
#include "Kyoto/Alloc/CMemory.hpp" #include "Kyoto/Alloc/CMemory.hpp"
#include "Kyoto/Streams/StreamSupport.hpp"
CInputStream::CInputStream(int len) CInputStream::CInputStream(int len)
: x4_blockOffset(0) : x4_blockOffset(0)

View File

@ -12,7 +12,7 @@ void joyboot_callback(s32 chan, s32 ret) {}
const uint MAGIC = 0x414d5445; const uint MAGIC = 0x414d5445;
#endif #endif
static CGBASupport* g_GBA; CGBASupport* g_GBA;
inline bool GetFontEncoding() { return OSGetFontEncode() == 1; } inline bool GetFontEncoding() { return OSGetFontEncode() == 1; }
@ -87,16 +87,16 @@ bool CGBASupport::IsReady() { return CheckReadyStatus(); }
void CGBASupport::Update(float dt) { void CGBASupport::Update(float dt) {
switch (x34_phase) { switch (x34_phase) {
case kP_LoadClientPad: case kP_LoadClientPad: {
CheckReadyStatus(); CheckReadyStatus();
break; break;
}
case kP_StartProbeTimeout: case kP_StartProbeTimeout: {
x38_timeout = 4.f; x38_timeout = 4.f;
x34_phase = kP_PollProbe; x34_phase = kP_PollProbe;
// [[fallthrough]]; // [[fallthrough]];
}
case kP_PollProbe: case kP_PollProbe: {
int channel = 1; int channel = 1;
do { do {
uint result = SIProbe(channel); uint result = SIProbe(channel);
@ -114,14 +114,14 @@ void CGBASupport::Update(float dt) {
x34_phase = kP_Failed; x34_phase = kP_Failed;
} }
break; break;
}
case kP_StartJoyBusBoot: case kP_StartJoyBusBoot: {
x34_phase = kP_PollJoyBusBoot; x34_phase = kP_PollJoyBusBoot;
GBAJoyBootAsync(x40_siChan, x40_siChan << 1, 2, x2c_buffer.get(), x0_file.Length(), &x3c_status, GBAJoyBootAsync(x40_siChan, x40_siChan << 1, 2, x2c_buffer.get(), x0_file.Length(), &x3c_status,
&joyboot_callback); &joyboot_callback);
break; break;
}
case kP_PollJoyBusBoot: case kP_PollJoyBusBoot: {
int status = GBAGetProcessStatus(x40_siChan, &x3c_status); int status = GBAGetProcessStatus(x40_siChan, &x3c_status);
if (status != GBA_BUSY) { if (status != GBA_BUSY) {
if (GBAGetStatus(x40_siChan, &x3c_status) == GBA_NOT_READY) { if (GBAGetStatus(x40_siChan, &x3c_status) == GBA_NOT_READY) {
@ -132,7 +132,8 @@ void CGBASupport::Update(float dt) {
} }
} }
break; break;
case kP_DataTransfer: }
case kP_DataTransfer: {
if (PollResponse()) { if (PollResponse()) {
x34_phase = kP_Complete; x34_phase = kP_Complete;
break; break;
@ -141,6 +142,8 @@ void CGBASupport::Update(float dt) {
if (x38_timeout == 0.f) if (x38_timeout == 0.f)
x34_phase = kP_Failed; x34_phase = kP_Failed;
break; break;
}
case kP_Standby:
case kP_Complete: case kP_Complete:
case kP_Failed: case kP_Failed:
break; break;
@ -229,6 +232,7 @@ bool CGBASupport::PollResponse() {
} while ((GBAGetStatus(x40_siChan, &gbaStatus) == GBA_NOT_READY || (gbaStatus & 0x8) == 0) || } while ((GBAGetStatus(x40_siChan, &gbaStatus) == GBA_NOT_READY || (gbaStatus & 0x8) == 0) ||
(GBAGetStatus(x40_siChan, &gbaStatus) != GBA_READY || gbaStatus != 0x38)); (GBAGetStatus(x40_siChan, &gbaStatus) != GBA_READY || gbaStatus != 0x38));
{
uint read; uint read;
uchar fusionStatus[4]; uchar fusionStatus[4];
if (GBARead(x40_siChan, reinterpret_cast< uchar* >(&read), &gbaStatus) != GBA_READY) { if (GBARead(x40_siChan, reinterpret_cast< uchar* >(&read), &gbaStatus) != GBA_READY) {
@ -248,6 +252,7 @@ bool CGBASupport::PollResponse() {
fusionBeat = true; fusionBeat = true;
} }
x45_fusionBeat = fusionBeat; x45_fusionBeat = fusionBeat;
}
end: end:
return true; return true;

View File

@ -215,8 +215,8 @@ CPlayerGun::CPlayerGun(TUniqueId playerId)
, x538_playerId(playerId) , x538_playerId(playerId)
, x53a_powerBomb(kInvalidUniqueId) , x53a_powerBomb(kInvalidUniqueId)
, x53c_lightId(kInvalidUniqueId) , x53c_lightId(kInvalidUniqueId)
, x550_camBob(CPlayerCameraBob::kCBT_One, CPlayerCameraBob::GetCameraBobPeriod(), , x550_camBob(CPlayerCameraBob::kCBT_One, CPlayerCameraBob::kCameraBobPeriod,
CPlayerCameraBob::GetCameraBobExtent()) CVector2f(CPlayerCameraBob::kCameraBobExtentX, CPlayerCameraBob::kCameraBobExtentY))
, x658_(1) , x658_(1)
, x65c_(0.f) , x65c_(0.f)
, x660_(0.f) , x660_(0.f)
@ -311,24 +311,26 @@ CPlayerGun::~CPlayerGun() {}
void CPlayerGun::AddToRenderer(const CFrustumPlanes& frustum, const CStateManager&) const { void CPlayerGun::AddToRenderer(const CFrustumPlanes& frustum, const CStateManager&) const {
rstl::optional_object< CModelData >& model = x72c_currentBeam->SolidModelData(); rstl::optional_object< CModelData >& model = x72c_currentBeam->SolidModelData();
if (model) if (model) {
model->RenderParticles(frustum); model->RenderParticles(frustum);
} }
}
void CPlayerGun::PreRender(CStateManager& mgr, const CFrustumPlanes& frustum, void CPlayerGun::PreRender(CStateManager& mgr, const CFrustumPlanes& frustum,
const CVector3f& camPos) { const CVector3f& camPos) {
const CPlayerState& playerState = *mgr.GetPlayerState(); const CPlayerState& playerState = *mgr.GetPlayerState();
if (playerState.GetCurrentVisor() == CPlayerState::kPV_Scan) if (playerState.GetCurrentVisor() == CPlayerState::kPV_Scan) {
return; return;
}
CPlayerState::EPlayerVisor activeVisor = playerState.GetActiveVisor(mgr); CPlayerState::EPlayerVisor activeVisor = playerState.GetActiveVisor(mgr);
switch (activeVisor) { switch (activeVisor) {
case CPlayerState::kPV_Thermal: case CPlayerState::kPV_Thermal: {
float rgb = float rgb =
CMath::Clamp(0.6f, 0.5f * x380_shotSmokeTimer + 0.6f - x378_shotSmokeStartTimer, 1.f); CMath::Clamp(0.6f, 0.5f * x380_shotSmokeTimer + 0.6f - x378_shotSmokeStartTimer, 1.f);
x0_lights.BuildConstantAmbientLighting(CColor(rgb, rgb, rgb, 1.f)); x0_lights.BuildConstantAmbientLighting(CColor(rgb, rgb, rgb, 1.f));
break; break;
}
case CPlayerState::kPV_Combat: { case CPlayerState::kPV_Combat: {
CAABox aabb = x72c_currentBeam->GetBounds(CTransform4f::Translate(camPos) * x4a8_gunWorldXf); CAABox aabb = x72c_currentBeam->GetBounds(CTransform4f::Translate(camPos) * x4a8_gunWorldXf);
if (mgr.GetNextAreaId() != kInvalidAreaId) { if (mgr.GetNextAreaId() != kInvalidAreaId) {
@ -351,16 +353,19 @@ void CPlayerGun::PreRender(CStateManager& mgr, const CFrustumPlanes& frustum,
break; break;
} }
if (x740_grappleArm->GetActive()) if (x740_grappleArm->GetActive()) {
x740_grappleArm->PreRender(mgr, frustum, camPos); x740_grappleArm->PreRender(mgr, frustum, camPos);
}
if (x678_morph.GetGunState() != CGunMorph::kGS_OutWipeDone || if (x678_morph.GetGunState() != CGunMorph::kGS_OutWipeDone ||
activeVisor == CPlayerState::kPV_XRay) activeVisor == CPlayerState::kPV_XRay) {
x6e0_rightHandModel.AnimationData()->PreRender(); x6e0_rightHandModel.AnimationData()->PreRender();
}
if (x833_28_phazonBeamActive) if (x833_28_phazonBeamActive) {
gpRender->AllocatePhazonSuitMaskTexture(); gpRender->AllocatePhazonSuitMaskTexture();
} }
}
void CPlayerGun::TouchModel(const CStateManager&) const {} void CPlayerGun::TouchModel(const CStateManager&) const {}

View File

@ -24,7 +24,7 @@ void CScriptRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId,
CEntity::AcceptScriptMsg(msg, objId, stateMgr); CEntity::AcceptScriptMsg(msg, objId, stateMgr);
switch (msg) { switch (msg) {
case kSM_SetToZero: case kSM_SetToZero: {
if (!x30_24_active) { if (!x30_24_active) {
return; return;
} }
@ -46,7 +46,7 @@ void CScriptRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId,
stateMgr.SetLastRelayId(GetUniqueId()); stateMgr.SetLastRelayId(GetUniqueId());
} }
break; break;
}
case kSM_Deleted: case kSM_Deleted:
UpdateObjectRef(stateMgr); UpdateObjectRef(stateMgr);
break; break;

View File

@ -4,7 +4,6 @@
#include "MetroidPrime/CStateManager.hpp" #include "MetroidPrime/CStateManager.hpp"
#include "MetroidPrime/ScriptObjects/CScriptWater.hpp" #include "MetroidPrime/ScriptObjects/CScriptWater.hpp"
CScriptRipple::CScriptRipple(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, CScriptRipple::CScriptRipple(TUniqueId uid, const rstl::string& name, const CEntityInfo& info,
const CVector3f& vec, bool active, float f1) const CVector3f& vec, bool active, float f1)
: CEntity(uid, info, active, name), x34_magnitude(f1 >= 0.f ? f1 : 0.5f), x38_center(vec) {} : CEntity(uid, info, active, name), x34_magnitude(f1 >= 0.f ? f1 : 0.5f), x38_center(vec) {}
@ -13,7 +12,7 @@ CScriptRipple::~CScriptRipple() {}
void CScriptRipple::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { void CScriptRipple::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
switch (msg) { switch (msg) {
case (kSM_Play): case (kSM_Play): {
if (!GetActive()) { if (!GetActive()) {
return; return;
} }
@ -33,6 +32,7 @@ void CScriptRipple::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSt
} }
} }
break; break;
}
default: default:
CEntity::AcceptScriptMsg(msg, uid, mgr); CEntity::AcceptScriptMsg(msg, uid, mgr);
break; break;

View File

@ -196,6 +196,8 @@ void CScriptSpecialFunction::PreRender(CStateManager&, const CFrustumPlanes& fru
x1e4_30_ = val; x1e4_30_ = val;
break; break;
} }
default:
break;
} }
} }
@ -476,7 +478,7 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
} }
break; break;
} }
case kSF_RumbleEffect: case kSF_RumbleEffect: {
if (msg != kSM_Action) { if (msg != kSM_Action) {
break; break;
} }
@ -498,6 +500,7 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
mgr.GetRumbleManager()->Rumble(mgr, pos, rumbFx, xfc_float1, kRP_One); mgr.GetRumbleManager()->Rumble(mgr, pos, rumbFx, xfc_float1, kRP_One);
} }
break; break;
}
case kSF_InventoryActivator: { case kSF_InventoryActivator: {
if (msg == kSM_Action && mgr.GetPlayerState()->HasPowerUp(x1c4_item)) { if (msg == kSM_Action && mgr.GetPlayerState()->HasPowerUp(x1c4_item)) {
SendScriptMsgs(kSS_Zero, mgr, kSM_None); SendScriptMsgs(kSS_Zero, mgr, kSM_None);

File diff suppressed because it is too large Load Diff