From fc850bdfad2cbf6ccea4e3fff2e798d722abac39 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 15 Jan 2026 23:18:45 -0800 Subject: [PATCH] CGuiObject progress, initial CParticleSwoosh --- config/GM8E01_00/symbols.txt | 28 ++-- configure.py | 37 ++++- include/GuiSys/CGuiObject.hpp | 15 +-- include/Kyoto/Audio/CAudioGroupSet.hpp | 19 ++- include/Kyoto/Basics/CCast.hpp | 17 ++- include/Kyoto/Basics/CStopwatch.hpp | 4 + include/Kyoto/Math/CTransform4f.hpp | 4 +- include/Kyoto/Math/CVector3f.hpp | 3 +- include/Kyoto/Particles/CElementGen.hpp | 2 +- include/Kyoto/Particles/CParticleElectric.hpp | 2 +- include/Kyoto/Particles/CParticleGen.hpp | 2 +- include/Kyoto/Particles/CParticleSwoosh.hpp | 42 +++++- .../Kyoto/Particles/CSwooshDescription.hpp | 1 + include/Kyoto/Particles/IElement.hpp | 2 +- include/Kyoto/Text/CFontRenderState.hpp | 16 +++ include/rstl/auto_ptr.hpp | 15 ++- include/rstl/construct.hpp | 4 +- include/rstl/list.hpp | 1 + include/rstl/vector.hpp | 3 + src/GuiSys/CGuiObject.cpp | 72 +++++++--- src/Kyoto/Audio/DolphinCAudioGroupSet.cpp | 48 ++++--- src/Kyoto/CDependencyGroup.cpp | 2 - src/Kyoto/Particles/CParticleSwoosh.cpp | 126 ++++++++++++++++++ src/Kyoto/Text/CFontRenderState.cpp | 24 ++++ 24 files changed, 397 insertions(+), 92 deletions(-) create mode 100644 src/Kyoto/Particles/CParticleSwoosh.cpp create mode 100644 src/Kyoto/Text/CFontRenderState.cpp diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 3ad84d1c..481be14f 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -2205,7 +2205,7 @@ GetMapArea__9CMapWorldCFi = .text:0x800A13B8; // type:function size:0x2C scope:g __dt__9CMapWorldFv = .text:0x800A13E4; // type:function size:0x110 scope:global fn_800A14F4 = .text:0x800A14F4; // type:function size:0xC0 __ct__9CMapWorldFR12CInputStream = .text:0x800A15B4; // type:function size:0x284 scope:global -fn_800A1838 = .text:0x800A1838; // type:function size:0xF8 +__as__Q24rstl36vectorFRCQ24rstl36vector = .text:0x800A1838; // type:function size:0xF8 __ct__Q29CMapWorld15CMapAreaBFSInfoFiiff = .text:0x800A1930; // type:function size:0x14 scope:global __ct__Q29CMapWorld18CMapWorldDrawParmsFfffffRC13CStateManagerRC12CTransform4fRC12CTransform4fRC6IWorldRC13CMapWorldInfofb = .text:0x800A1944; // type:function size:0x44 scope:global GetMapArea__Q29CMapWorld12CMapAreaDataCFv = .text:0x800A1988; // type:function size:0x64 scope:global @@ -13214,18 +13214,18 @@ Invoke__16CFontInstructionCFR16CFontRenderStateP17CTextRenderBuffer = .text:0x80 ConvertToTextureSpace__16CFontRenderStateCFRC10CTextColor = .text:0x802FECC4; // type:function size:0x30 scope:global PopState__16CFontRenderStateFv = .text:0x802FECF4; // type:function size:0x48 scope:global __as__14CSaveableStateFRC14CSaveableState = .text:0x802FED3C; // type:function size:0x190 scope:global -fn_802FEECC = .text:0x802FEECC; // type:function size:0x10C +__as__Q24rstl47vector<10CTextColor,Q24rstl17rmemory_allocator>FRCQ24rstl47vector<10CTextColor,Q24rstl17rmemory_allocator> = .text:0x802FEECC; // type:function size:0x10C PushState__16CFontRenderStateFv = .text:0x802FEFD8; // type:function size:0x28 scope:global -fn_802FF000 = .text:0x802FF000; // type:function size:0x28 -fn_802FF028 = .text:0x802FF028; // type:function size:0x70 -fn_802FF098 = .text:0x802FF098; // type:function size:0x84 -fn_802FF11C = .text:0x802FF11C; // type:function size:0x208 +push_front__Q24rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>FRC14CSaveableState = .text:0x802FF000; // type:function size:0x28 +do_insert_before__Q24rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>FPQ34rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>4nodeRC14CSaveableState = .text:0x802FF028; // type:function size:0x70 +create_node__Q24rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>FPQ34rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>4nodePQ34rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>4nodeRC14CSaveableState = .text:0x802FF098; // type:function size:0x84 +__ct__14CSaveableStateFRC14CSaveableState = .text:0x802FF11C; // type:function size:0x208 SetColor__16CFontRenderStateF10EColorTypeRC10CTextColor = .text:0x802FF324; // type:function size:0xC0 scope:global RefreshPalette__16CFontRenderStateFv = .text:0x802FF3E4; // type:function size:0x3C scope:global RefreshColor__16CFontRenderStateF10EColorType = .text:0x802FF420; // type:function size:0x180 scope:global __ct__16CFontRenderStateFv = .text:0x802FF5A0; // type:function size:0xD4 scope:global -fn_802FF674 = .text:0x802FF674; // type:function size:0x94 -fn_802FF708 = .text:0x802FF708; // type:function size:0x104 +do_erase__Q24rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>FPQ34rstl49list<14CSaveableState,Q24rstl17rmemory_allocator>4node = .text:0x802FF674; // type:function size:0x94 +reserve__Q24rstl47vector<10CTextColor,Q24rstl17rmemory_allocator>Fi = .text:0x802FF708; // type:function size:0x104 __dt__26CLineExtraSpaceInstructionFv = .text:0x802FF80C; // type:function size:0x5C scope:weak PageInvoke__26CLineExtraSpaceInstructionCFR16CFontRenderStateP17CTextRenderBuffer = .text:0x802FF868; // type:function size:0x2C scope:global Invoke__26CLineExtraSpaceInstructionCFR16CFontRenderStateP17CTextRenderBuffer = .text:0x802FF894; // type:function size:0xC scope:global @@ -14055,12 +14055,12 @@ Update__15CParticleSwooshFd = .text:0x8032E704; // type:function size:0x4B0 scop IsLargeEnough__15CParticleSwooshCFv = .text:0x8032EBB4; // type:function size:0x28 scope:global __dt__15CParticleSwooshFv = .text:0x8032EBDC; // type:function size:0x208 scope:global __ct__15CParticleSwooshF28TToken<18CSwooshDescription>i = .text:0x8032EDE4; // type:function size:0x7DC scope:global -fn_8032F5C0 = .text:0x8032F5C0; // type:function size:0x7C -fn_8032F63C = .text:0x8032F63C; // type:function size:0x28 -fn_8032F664 = .text:0x8032F664; // type:function size:0xE4 +push_back__Q24rstl67vectorFRCQ215CParticleSwoosh11SSwooshData = .text:0x8032F5C0; // type:function size:0x7C +construct__4rstlFPvRCQ215CParticleSwoosh11SSwooshData = .text:0x8032F63C; // type:function size:0x28 +__ct__Q215CParticleSwoosh11SSwooshDataFRCQ215CParticleSwoosh11SSwooshData = .text:0x8032F664; // type:function size:0xE4 __ct__Q215CParticleSwoosh11SSwooshDataFRC9CVector3fRC9CVector3fffibRC12CTransform4fRC9CVector3fffRC6CColor = .text:0x8032F748; // type:function size:0xDC scope:global -fn_8032F824 = .text:0x8032F824; // type:function size:0xD8 -fn_8032F8FC = .text:0x8032F8FC; // type:function size:0x68 +reserve__Q24rstl67vectorFi = .text:0x8032F824; // type:function size:0xD8 +uninitialized_copy,Q24rstl17rmemory_allocator>,Q215CParticleSwoosh11SSwooshData>__4rstlFQ24rstl154pointer_iterator,Q24rstl17rmemory_allocator>Q24rstl154pointer_iterator,Q24rstl17rmemory_allocator>PQ215CParticleSwoosh11SSwooshData = .text:0x8032F8FC; // type:function size:0x68 CreateWPSM__26CParticleSwooshDataFactoryFP18CSwooshDescriptionR12CInputStreamP11CSimplePool = .text:0x8032F964; // type:function size:0x4DC scope:global CreateGeneratorDescription__26CParticleSwooshDataFactoryFR12CInputStreamP11CSimplePool = .text:0x8032FE40; // type:function size:0x8C scope:global GetGeneratorDesc__26CParticleSwooshDataFactoryFR12CInputStreamP11CSimplePool = .text:0x8032FECC; // type:function size:0x84 scope:global @@ -22127,7 +22127,7 @@ mParticleLifetimePercentageRemainder__16CParticleGlobals = .sbss:0x805A94A8; // mCurrentParticle__16CParticleGlobals = .sbss:0x805A94AC; // type:object size:0x4 scope:global data:4byte mParticleAccessParameters__16CParticleGlobals = .sbss:0x805A94B0; // type:object size:0x4 scope:global data:4byte mCurrentParticleSystem__16CParticleGlobals = .sbss:0x805A94B4; // type:object size:0x4 scope:global data:4byte -mSwooshAliveCount__15CParticleSwoosh = .sbss:0x805A94B8; // type:object size:0x8 scope:global data:4byte +mSwooshAliveCount__15CParticleSwoosh = .sbss:0x805A94B8; // type:object size:0x4 scope:global data:4byte lbl_805A94C0 = .sbss:0x805A94C0; // type:object size:0x1 data:byte lbl_805A94C4 = .sbss:0x805A94C4; // type:object size:0x1 data:byte lbl_805A94C8 = .sbss:0x805A94C8; // type:object size:0x1 data:byte diff --git a/configure.py b/configure.py index 71b2f581..3e445fae 100755 --- a/configure.py +++ b/configure.py @@ -247,11 +247,29 @@ cflags_runtime = [ ] cflags_retro = [ - *cflags_base, + "-nodefaults", + "-proc gekko", + "-align powerpc", + "-enum int", + "-fp hardware", + "-Cpp_exceptions off", + # "-W all", + "-O4,p", + "-maxerrors 1", + "-nosyspath", + "-RTTI off", + "-fp_contract on", + "-str reuse", + "-i include", + "-i libc", + f"-i build/{config.version}/include", + f"-DVERSION={version_num}", + "-DPRIME1", + "-DNONMATCHING=0", "-use_lmw_stmw on", "-str reuse,pool,readonly", "-gccinc", - "-inline deferred,noauto", + "-inline deferred", "-common on", "-i extern/musyx/include", # "-sym on", @@ -358,6 +376,17 @@ def RetroLib(lib_name, progress_category, objects): "shift_jis": False, } +def KyotoLib(lib_name, progress_category, objects): + return { + "lib": lib_name + "CW" + "D" if args.debug else "", + "mw_version": "GC/1.3.2", + "cflags": [*cflags_retro, "-pragma \"inline_max_size(250)\""], + "host": False, + "progress_category": progress_category, + "objects": objects, + "shift_jis": False, + } + def MusyX( objects, @@ -1217,7 +1246,7 @@ config.libs = [ Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Collision/CMRay.cpp"), ], ), - RetroLib( + KyotoLib( "Kyoto1", "core", [ @@ -1579,7 +1608,7 @@ config.libs = [ ], }, # TODO: Merge this with zlib and Kyoto1 - RetroLib( + KyotoLib( "Kyoto2", "core", [ diff --git a/include/GuiSys/CGuiObject.hpp b/include/GuiSys/CGuiObject.hpp index ab5b7a13..5f551f35 100644 --- a/include/GuiSys/CGuiObject.hpp +++ b/include/GuiSys/CGuiObject.hpp @@ -25,19 +25,15 @@ public: void RotateReset(); CVector3f RotateO2P(const CVector3f& vec) const; - CVector3f RotateW2O(const CVector3f& offset) const { - return x34_worldXF.TransposeRotate(offset); - } + CVector3f RotateW2O(const CVector3f& offset) const { return x34_worldXF.TransposeRotate(offset); } CVector3f RotateTranslateW2O(const CVector3f& vec) const; void MultiplyO2P(const CTransform4f& xf); void RecalculateTransforms(); - void AddChildObject(CGuiObject* child, bool a, bool b); + void AddChildObject(CGuiObject* child, bool makeWorldLocal, bool atEnd); + + void SetParent(CGuiObject* obj) { x64_parent = obj; } - void SetParent(CGuiObject* obj) { - x64_parent = obj; - } - CGuiObject* Parent(); const CGuiObject* GetParent() const { return x64_parent; } const CGuiObject* GetChildObject() const; @@ -45,6 +41,9 @@ public: const CGuiObject* GetNextSibling() const; CGuiObject* NextSibling(); + CVector3f VectorSomething(const CVector3f& vec) { + return CVector3f(vec.GetX(), vec.GetY(), vec.GetZ()); + } private: CTransform4f x4_localXF; diff --git a/include/Kyoto/Audio/CAudioGroupSet.hpp b/include/Kyoto/Audio/CAudioGroupSet.hpp index 2063137b..91a67c81 100644 --- a/include/Kyoto/Audio/CAudioGroupSet.hpp +++ b/include/Kyoto/Audio/CAudioGroupSet.hpp @@ -9,6 +9,7 @@ #include "rstl/string.hpp" #include "Kyoto/CResFactory.hpp" +#include "Kyoto/Streams/CMemoryInStream.hpp" class CInputStream; class CAudioGrpSetLoc { @@ -24,15 +25,23 @@ public: const void* GetSampleDir() const; private: + uint ReadHeader(void* ptr, uint len, uint& readPosition) { + CMemoryInStream in(ptr, len); + x10_baseDirName = rstl::string(in); + x20_groupSetName = rstl::string(in); + const uint ret = in.ReadLong(); + readPosition = in.GetReadPosition(); + return ret; + } rstl::auto_ptr< uchar > x0_data; rstl::auto_ptr< uchar > x8_; rstl::string x10_baseDirName; rstl::string x20_groupSetName; - uint x30_; - uint x34_; - uint x38_; - uint x3c_; - uint x40_; + uint x30_aramSize; + uchar* x34_; + uchar* x38_; + uchar* x3c_; + uchar* x40_; }; class CAudioGroupSet { diff --git a/include/Kyoto/Basics/CCast.hpp b/include/Kyoto/Basics/CCast.hpp index a4e94cf4..385d71cf 100644 --- a/include/Kyoto/Basics/CCast.hpp +++ b/include/Kyoto/Basics/CCast.hpp @@ -12,7 +12,7 @@ inline uchar ToUint8(register float in) { register uchar* ptr = &a; asm { - psq_st in, 0(ptr), 1, OS_FASTCAST_U8 + psq_st in, 0(ptr), 1, OS_FASTCAST_U8 } return *ptr; } @@ -22,7 +22,7 @@ inline char ToInt8(register float in) { register char* ptr = &a; asm { - psq_st in, 0(ptr), 1, OS_FASTCAST_S8 + psq_st in, 0(ptr), 1, OS_FASTCAST_S8 } return *ptr; } @@ -30,7 +30,7 @@ inline char ToInt8(register float in) { inline float ToReal32(register const uchar& in) { register float r; asm { - psq_l r, 0(in), 1, 2 + psq_l r, 0(in), 1, 2 } return r; } @@ -40,7 +40,7 @@ inline short FtoS(register float in) { register short* ptr = &a; asm { - psq_st in, 0(ptr), 1, OS_FASTCAST_S16 + psq_st in, 0(ptr), 1, OS_FASTCAST_S16 } return *ptr; } @@ -50,7 +50,7 @@ inline ushort FtoUS(register float in) { register ushort* ptr = &a; asm { - psq_st in, 0(ptr), 1, OS_FASTCAST_U16 + psq_st in, 0(ptr), 1, OS_FASTCAST_U16 } return *ptr; } @@ -68,8 +68,13 @@ inline int FtoL(float in) { return static_cast< int >(in); } inline float LtoF(int in) { return static_cast< float >(in); } inline float ToReal32(int in) { return static_cast< float >(in); } inline int ToInt32(float in) { return static_cast< int >(in); } -inline unsigned short ToUint16(short in) { return static_cast(in); } +inline unsigned short ToUint16(short in) { return static_cast< unsigned short >(in); } inline char ToChar(int c) { return ToUint8(c); } +inline int ToInt16(const s64 v) { + return v % 4096; +} + +inline const short ToInt16(const int in) { return static_cast(in); } } // namespace CCast #endif // _CCAST diff --git a/include/Kyoto/Basics/CStopwatch.hpp b/include/Kyoto/Basics/CStopwatch.hpp index e14b15a4..e446eff3 100644 --- a/include/Kyoto/Basics/CStopwatch.hpp +++ b/include/Kyoto/Basics/CStopwatch.hpp @@ -42,6 +42,10 @@ public: } static void Wait(float); + + static s64 GetGlobalMicros() { + return mGlobalTimer.GetElapsedMicros(); + } private: static CSWData mData; diff --git a/include/Kyoto/Math/CTransform4f.hpp b/include/Kyoto/Math/CTransform4f.hpp index cf60c744..f1135b29 100644 --- a/include/Kyoto/Math/CTransform4f.hpp +++ b/include/Kyoto/Math/CTransform4f.hpp @@ -36,7 +36,9 @@ public: CTransform4f(const CTransform4f& other); CTransform4f& operator=(const CTransform4f& other); - CVector3f GetTranslation() const { return CVector3f(m03, m13, m23); } + CVector3f GetTranslation() const { + return CVector3f(m03, m13, m23); + } CVector3f GetRight() const { return CVector3f(m00, m10, m20); } const CVector3f GetForward() const { return CVector3f(m01, m11, m21); } CVector3f GetUp() const { return CVector3f(m02, m12, m22); } diff --git a/include/Kyoto/Math/CVector3f.hpp b/include/Kyoto/Math/CVector3f.hpp index 20a4d972..cb99a9c5 100644 --- a/include/Kyoto/Math/CVector3f.hpp +++ b/include/Kyoto/Math/CVector3f.hpp @@ -113,7 +113,7 @@ public: static const CVector3f& Right() { return sRightVector; } static const CVector3f& Forward() { return sForwardVector; } static const CVector3f& Back() { return sBackVector; } - + protected: float mX; float mY; @@ -139,6 +139,7 @@ inline bool operator==(const CVector3f& lhs, const CVector3f& rhs) { inline bool operator!=(const CVector3f& lhs, const CVector3f& rhs) { return lhs.GetX() != rhs.GetX() || lhs.GetY() != rhs.GetY() || lhs.GetZ() != rhs.GetZ(); } + inline CVector3f operator-(const CVector3f& lhs, const CVector3f& rhs) { float x = lhs.GetX() - rhs.GetX(); float y = lhs.GetY() - rhs.GetY(); diff --git a/include/Kyoto/Particles/CElementGen.hpp b/include/Kyoto/Particles/CElementGen.hpp index c30d892a..1d6f83da 100644 --- a/include/Kyoto/Particles/CElementGen.hpp +++ b/include/Kyoto/Particles/CElementGen.hpp @@ -48,7 +48,7 @@ public: EOptionalSystemFlags = kOSF_One); ~CElementGen() override; - virtual void Update(double) override; + virtual bool Update(double) override; virtual void Render() const override; virtual void SetOrientation(const CTransform4f& orientation) override; virtual void SetTranslation(const CVector3f& translation) override; diff --git a/include/Kyoto/Particles/CParticleElectric.hpp b/include/Kyoto/Particles/CParticleElectric.hpp index 7e736520..f8d1b243 100644 --- a/include/Kyoto/Particles/CParticleElectric.hpp +++ b/include/Kyoto/Particles/CParticleElectric.hpp @@ -13,7 +13,7 @@ public: explicit CParticleElectric(TToken< CElectricDescription > desc); ~CParticleElectric() override; - void Update(double) override; + bool Update(double) override; void Render() const override; void SetOrientation(const CTransform4f& orientation) override; void SetTranslation(const CVector3f& translation) override; diff --git a/include/Kyoto/Particles/CParticleGen.hpp b/include/Kyoto/Particles/CParticleGen.hpp index 98e4a750..fdc72842 100644 --- a/include/Kyoto/Particles/CParticleGen.hpp +++ b/include/Kyoto/Particles/CParticleGen.hpp @@ -15,7 +15,7 @@ class CWarp; class CParticleGen { public: virtual ~CParticleGen() = 0; - virtual void Update(double) = 0; + virtual bool Update(double) = 0; virtual void Render() const = 0; virtual void SetOrientation(const CTransform4f& orientation) = 0; virtual void SetTranslation(const CVector3f& translation) = 0; diff --git a/include/Kyoto/Particles/CParticleSwoosh.hpp b/include/Kyoto/Particles/CParticleSwoosh.hpp index 7c274e8e..d0ac0172 100644 --- a/include/Kyoto/Particles/CParticleSwoosh.hpp +++ b/include/Kyoto/Particles/CParticleSwoosh.hpp @@ -13,11 +13,43 @@ class CParticleSwoosh : public CParticleGen { public: - struct SSwooshData {}; + struct SSwooshData { + SSwooshData(const CVector3f& translation = CVector3f::Zero(), + const CVector3f& offset = CVector3f::Zero(), float irot = 0.f, float rotm = 0.f, int startFrame = 0, + bool active = false, const CTransform4f& orient = CTransform4f::Identity(), + const CVector3f& velocity = CVector3f::Zero(), float leftRadius = 0.f, float rightRadius = 0.f, + const CColor& color = CColor(0.f, 0.f, 0.f, 0.f)) + : mActive(active) + , mLeftRad(leftRadius) + , mRightRad(rightRadius) + , mTranslation(translation) + , mOffset(offset) + , mUseOffset(offset) + , mInitialRot(irot) + , mRotm(rotm) + , mOrientation(orient) + , mColor(color) + , mStartFrame(startFrame) + , mVelocity(velocity) {} + + bool mActive; + float mLeftRad; + float mRightRad; + CVector3f mTranslation; // Updated by system's velocity sources or user code + CVector3f mOffset; // Updated by POFS once per system update (also resets x24_useOffset) + CVector3f mUseOffset; // Combination of POFS and NPOS, once per particle instance + float mInitialRot; // Rotation bias once per system update + float mRotm; // Rotation bias once per particle instance + CTransform4f mOrientation; // Updated by user code + int mFrame; // Frame index of evaluated data + CColor mColor; // Updated by COLR + int mStartFrame; + CVector3f mVelocity; + }; CParticleSwoosh(TToken< CSwooshDescription > desc, int i); ~CParticleSwoosh(); - void Update(double); + bool Update(double dt); void Render() const; void SetOrientation(const CTransform4f& orientation); void SetTranslation(const CVector3f& translation); @@ -48,6 +80,8 @@ public: const int GetSwooshCount() const { return x15c_swooshes.size(); } + bool IsLargeEnough() const; + private: TLockedToken< CSwooshDescription > x1c_desc; uint x28_curFrame; @@ -57,7 +91,7 @@ private: CTransform4f x44_orientation; CTransform4f x74_invOrientation; CVector3f xa4_globalTranslation; - CTransform4f xa4_globalOrientation; + CTransform4f xb0_globalOrientation; CVector3f xe0_globalScale; CTransform4f xec_scaleXf; CTransform4f x11c_invScaleXf; @@ -94,6 +128,8 @@ private: CVector3f x1fc_aabbMax; float x208_maxRadius; CColor x20c_moduColor; + + static uint mSwooshAliveCount; }; #endif // _CPARTICLESWOOSH diff --git a/include/Kyoto/Particles/CSwooshDescription.hpp b/include/Kyoto/Particles/CSwooshDescription.hpp index fd2964b9..cc87df9e 100644 --- a/include/Kyoto/Particles/CSwooshDescription.hpp +++ b/include/Kyoto/Particles/CSwooshDescription.hpp @@ -8,6 +8,7 @@ class CRealElement; class CUVElement; class CVectorElement; class CSwooshDescription { +public: CSwooshDescription(); ~CSwooshDescription(); diff --git a/include/Kyoto/Particles/IElement.hpp b/include/Kyoto/Particles/IElement.hpp index d816b61f..cbcbda7f 100644 --- a/include/Kyoto/Particles/IElement.hpp +++ b/include/Kyoto/Particles/IElement.hpp @@ -55,7 +55,7 @@ public: struct SUVElementSet { float xMin, yMin, xMax, yMax; - // SUVElementSet() : xMin(0.f), yMin(1.f), xMax(0.f), yMax(1.f) {} + SUVElementSet() : xMin(0.f), yMin(0.f), xMax(0.f), yMax(0.f) {} // SUVElementSet(float xMin, float yMin, float xMax, float yMax) //: xMin(xMin), yMin(yMin), xMax(xMax), yMax(yMax) {} // SUVElementSet(const SUVElementSet& other) diff --git a/include/Kyoto/Text/CFontRenderState.hpp b/include/Kyoto/Text/CFontRenderState.hpp index 429f3715..8353791f 100644 --- a/include/Kyoto/Text/CFontRenderState.hpp +++ b/include/Kyoto/Text/CFontRenderState.hpp @@ -5,12 +5,28 @@ #include "Kyoto/Text/CRasterFont.hpp" #include "Kyoto/Text/CSaveableState.hpp" #include "Kyoto/Text/TextCommon.hpp" +#include class CBlockInstruction; class CLineInstruction; +namespace rstl { +template < typename T, typename Container = vector< T > > +class stack { +public: + stack(const typename Container::allocator_type& allocator = typename Container::allocator_type()) + : container(allocator) {} + void push(const T& v) { container.push_back(v); } + T& top() { return container.front(); } + void pop() { container.pop_back(); } + +private: + Container container; +}; +} // namespace rstl class CFontRenderState { public: + CFontRenderState(); uint ConvertToTextureSpace(const CTextColor& color) const; void PushState(); void PopState(); diff --git a/include/rstl/auto_ptr.hpp b/include/rstl/auto_ptr.hpp index 3bc2623e..297ac369 100644 --- a/include/rstl/auto_ptr.hpp +++ b/include/rstl/auto_ptr.hpp @@ -22,14 +22,15 @@ public: other.x0_has = false; } auto_ptr& operator=(const auto_ptr& other) { - if (&other != this) { - if (x0_has) { - delete x4_item; - } - x0_has = other.x0_has; - x4_item = other.x4_item; - other.x0_has = false; + if (&other == this) { + return *this; } + if (x0_has) { + delete x4_item; + } + x0_has = other.x0_has; + x4_item = other.x4_item; + other.x0_has = false; return *this; } T* get() const { return x4_item; } diff --git a/include/rstl/construct.hpp b/include/rstl/construct.hpp index 0a8fa6ed..23d0d661 100644 --- a/include/rstl/construct.hpp +++ b/include/rstl/construct.hpp @@ -25,11 +25,13 @@ inline void destroy(It begin, It end) { } template < typename It, typename T > -inline void uninitialized_copy(It begin, It end, T* out) { +inline T* uninitialized_copy(It begin, It end, T* out) { It cur = begin; for (; cur != end; ++out, ++cur) { construct(out, *cur); } + + return out; } template < typename S, typename D > diff --git a/include/rstl/list.hpp b/include/rstl/list.hpp index cfd06d97..f9d82984 100644 --- a/include/rstl/list.hpp +++ b/include/rstl/list.hpp @@ -27,6 +27,7 @@ public: , x14_count(0) {} ~list(); + void push_front(const T& val) { do_insert_before(x4_start, val); } void push_back(const T& val) { do_insert_before(x8_end, val); } void clear() { erase(begin(), end()); } diff --git a/include/rstl/vector.hpp b/include/rstl/vector.hpp index aef39dce..7cce6429 100644 --- a/include/rstl/vector.hpp +++ b/include/rstl/vector.hpp @@ -35,6 +35,7 @@ protected: T* xc_items; public: + typedef Alloc allocator_type; typedef pointer_iterator< T, vector< T, Alloc >, Alloc > iterator; typedef const_pointer_iterator< T, vector< T, Alloc >, Alloc > const_iterator; typedef T value_type; @@ -83,6 +84,8 @@ public: rstl::construct(xc_items + x4_count, in); ++x4_count; } + + void pop_back(); vector& operator=(const vector& other); diff --git a/src/GuiSys/CGuiObject.cpp b/src/GuiSys/CGuiObject.cpp index 17667a39..68e16e53 100644 --- a/src/GuiSys/CGuiObject.cpp +++ b/src/GuiSys/CGuiObject.cpp @@ -1,5 +1,7 @@ #include "GuiSys/CGuiObject.hpp" #include "Kyoto/Alloc/CMemory.hpp" +#include "Kyoto/Math/CMatrix3f.hpp" +#include "dolphin/os.h" CGuiObject::CGuiObject() : x4_localXF(CTransform4f::Identity()) @@ -35,9 +37,8 @@ void CGuiObject::Draw(const CGuiWidgetDrawParms& parms) const { } void CGuiObject::MoveInWorld(const CVector3f& offset) { - CVector3f pos; if (GetParent() != nullptr) { - pos = GetParent()->RotateW2O(offset); + (void)GetParent()->RotateW2O(offset); } x4_localXF.AddTranslation(offset); RecalculateTransforms(); @@ -52,19 +53,24 @@ void CGuiObject::SetLocalPosition(const CVector3f& pos) { } void CGuiObject::RotateReset() { - CVector3f tmpPos = x4_localXF.GetTranslation(); + const CVector3f tmpPos = x4_localXF.GetTranslation(); x4_localXF = CTransform4f::Identity(); x4_localXF.SetTranslation(tmpPos); RecalculateTransforms(); } CVector3f CGuiObject::RotateO2P(const CVector3f& vec) const { - CVector3f tmp = x4_localXF.Rotate(vec); + const CVector3f tmp = x4_localXF.Rotate(vec); return tmp; } +inline CVector3f StupidSubtract(const CVector3f& lhs, const CVector3f& rhs) { + return CVector3f(lhs.GetX() - rhs.GetX(), lhs.GetY() - rhs.GetY(), lhs.GetZ() - rhs.GetZ()); +} + CVector3f CGuiObject::RotateTranslateW2O(const CVector3f& vec) const { - CVector3f tmp = x34_worldXF.TransposeRotate(vec - x34_worldXF.GetTranslation()); + const CVector3f tmp = + x34_worldXF.TransposeRotate(StupidSubtract(vec, x34_worldXF.GetTranslation())); return tmp; } @@ -73,23 +79,49 @@ void CGuiObject::MultiplyO2P(const CTransform4f& xf) { RecalculateTransforms(); } -void CGuiObject::AddChildObject(CGuiObject* obj, bool makeWorldLocal, bool atEnd) { - obj->SetParent(this); +void CGuiObject::AddChildObject(CGuiObject* child, const bool makeWorldLocal, const bool atEnd) { + child->SetParent(this); - if (!x68_child) { - x68_child = obj; + CGuiObject* cur = x68_child; + if (cur == nullptr) { + x68_child = child; } else if (atEnd) { - CGuiObject* prev = nullptr; - CGuiObject* cur = x68_child; - for (; cur; cur = cur->x6c_nextSibling) { - prev = cur; - } - - if (prev) { - prev->x6c_nextSibling = obj; - } + do { + CGuiObject* next = cur->x6c_nextSibling; + if (next == nullptr) { + cur->x6c_nextSibling = child; + break; + } + cur = next; + } while (true); } else { + child->x6c_nextSibling = x68_child; + x68_child = child; } + + if (makeWorldLocal) { + const CGuiObject* parent = child->GetParent(); + CTransform4f worldLocalXf = CTransform4f::Identity(); + CVector3f position = parent->x34_worldXF.GetTranslation() * -1.f; + const float upMag = parent->x34_worldXF.GetUp().Magnitude(); + const float forwardMag = parent->x34_worldXF.GetForward().Magnitude(); + const float rightMag = parent->x34_worldXF.GetRight().Magnitude(); + const CVector3f _tmp1 = parent->x34_worldXF.GetColumn(kDZ); + const CVector3f m2 = (1.f / upMag) * _tmp1; + const CVector3f _tmp2 = parent->x34_worldXF.GetColumn(kDY); + const CVector3f m1 = (1.f / forwardMag) * _tmp2; + const CVector3f _tmp3 = parent->x34_worldXF.GetColumn(kDX); + const CVector3f m0 = (1.f / rightMag) * _tmp3; + const CMatrix3f tmpMtx(m0, m1, m2); + const CVector3f pos = tmpMtx * position; + + worldLocalXf = CTransform4f(tmpMtx.Get00(), tmpMtx.Get01(), tmpMtx.Get02(), pos.GetX(), // + tmpMtx.Get10(), tmpMtx.Get11(), tmpMtx.Get12(), pos.GetY(), // + tmpMtx.Get20(), tmpMtx.Get21(), tmpMtx.Get22(), pos.GetZ()); + child->x4_localXF = worldLocalXf * child->x34_worldXF; + } + + RecalculateTransforms(); } const CGuiObject* CGuiObject::GetChildObject() const { return x68_child; } @@ -100,9 +132,7 @@ CGuiObject* CGuiObject::NextSibling() { return x6c_nextSibling; } CGuiObject* CGuiObject::Parent() { return x64_parent; } -void CGuiObject::RecalculateTransforms() { - -} +void CGuiObject::RecalculateTransforms() {} void CGuiObject::SetLocalTransform(const CTransform4f& xf) { x4_localXF = xf; diff --git a/src/Kyoto/Audio/DolphinCAudioGroupSet.cpp b/src/Kyoto/Audio/DolphinCAudioGroupSet.cpp index 6232b4ec..8c6dafb8 100644 --- a/src/Kyoto/Audio/DolphinCAudioGroupSet.cpp +++ b/src/Kyoto/Audio/DolphinCAudioGroupSet.cpp @@ -1,10 +1,10 @@ #include "Kyoto/Audio/CAudioGroupSet.hpp" #include "Kyoto/Audio/CAudioSys.hpp" -#include "Kyoto/Streams/CMemoryInStream.hpp" -#include "Kyoto/CFactoryMgr.hpp" +#include "Kyoto/Alloc/CMemory.hpp" #include "rstl/auto_ptr.hpp" +#include CAudioGroupSet::CAudioGroupSet(const TLockedToken< CAudioGrpSetLoc >& group) : x0_baseDir(group->GetBaseDirName()) @@ -15,20 +15,38 @@ CAudioGroupSet::~CAudioGroupSet() {} void CAudioGroupSet::Reload() {} -void CAudioGroupSet::FreeSampleBuffer() { - x20_groupSetTok.data()->FreeSampleBuffer(); -} - -CAudioGrpSetLoc::CAudioGrpSetLoc(const rstl::auto_ptr< uchar >& data, int length) -: x0_data(data.get()), x30_(0), x34_(0), x38_(0), x3c_(0), x40_(0) { - int __n; - { - CMemoryInStream in(x0_data.get(), length); - x10_baseDirName = rstl::string(in); - x20_groupSetName = rstl::string(in); - __n = in.ReadLong(); - } +void CAudioGroupSet::FreeSampleBuffer() { x20_groupSetTok.data()->FreeSampleBuffer(); } +CAudioGrpSetLoc::CAudioGrpSetLoc(const rstl::auto_ptr< uchar >& data, const int length) +: x0_data(data.release()), x30_aramSize(0), x34_(0), x38_(0), x3c_(0), x40_(0) { + uint readPosition; + const uint poolSize = ReadHeader(data.get(), length, readPosition); CAudioSys::GetVerbose(); + const uint projectOffset = readPosition + poolSize; + const uint projectSize = *reinterpret_cast< uint* >(data.get() + projectOffset); + CAudioSys::GetVerbose(); + const uint sampOffset = projectOffset + projectSize; + const uint sampSize = *reinterpret_cast< uint* >(data.get() + sampOffset + 4); + CAudioSys::GetVerbose(); + x30_aramSize = sampSize; + const uint sdirOffset = sampOffset + sampSize; + const uint sdirSize = *reinterpret_cast< uint* >(data.get() + sampOffset); + CAudioSys::GetVerbose(); + + x8_ = rstl::auto_ptr< uchar >(static_cast< uchar* >( + CMemory::Alloc(poolSize + projectSize + sdirSize + 8, IAllocator::kHI_RoundUpLen))); + uchar* ptr = x0_data.get(); + x34_ = x8_.get(); + memcpy(x34_, ptr + readPosition, poolSize); + uint roundedPoolSize = ((poolSize + 3) & ~3); + x38_ = x8_.get() + roundedPoolSize; + memcpy(x38_, ptr + (projectOffset + 4), projectSize); + uint roundedProjectSize = ((projectSize + 3) & ~3); + roundedProjectSize += roundedPoolSize; + x3c_ = x8_.get() + roundedProjectSize; + memcpy(x3c_, ptr + (sdirOffset + 4), sdirSize); + ptr += (projectOffset + projectSize); + ptr += 4; + x40_ = ptr; } void CAudioGrpSetLoc::FreeSampleBuffer() { diff --git a/src/Kyoto/CDependencyGroup.cpp b/src/Kyoto/CDependencyGroup.cpp index 032a34cc..e54353cd 100644 --- a/src/Kyoto/CDependencyGroup.cpp +++ b/src/Kyoto/CDependencyGroup.cpp @@ -1,8 +1,6 @@ #include "Kyoto/CDependencyGroup.hpp" #include "Kyoto/CResFactory.hpp" #include "Kyoto/Streams/CInputStream.hpp" -/* this is such a hack... */ -#pragma inline_max_size(250) CDependencyGroup::CDependencyGroup(CInputStream& in) { ReadFromStream(in); } diff --git a/src/Kyoto/Particles/CParticleSwoosh.cpp b/src/Kyoto/Particles/CParticleSwoosh.cpp new file mode 100644 index 00000000..332e9a1f --- /dev/null +++ b/src/Kyoto/Particles/CParticleSwoosh.cpp @@ -0,0 +1,126 @@ +#include "Kyoto/Particles/CParticleSwoosh.hpp" + +#include "Kyoto/Basics/CStopwatch.hpp" +#include "Kyoto/Particles/CParticleGlobals.hpp" +#include "Kyoto/Particles/CSwooshDescription.hpp" + +#pragma inline_max_size(250) +uint CParticleSwoosh::mSwooshAliveCount = 0; + +CParticleSwoosh::CParticleSwoosh(const TToken< CSwooshDescription > desc, const int leng) +: x1c_desc(desc) +, x28_curFrame(0) +, x2c_PSLT(0) +, x30_curTime(0.0) +, x38_translation(0.f, 0.f, 0.f) +, x44_orientation(CTransform4f::Identity()) +, x74_invOrientation(CTransform4f::Identity()) +, xa4_globalTranslation(0.f, 0.f, 0.f) +, xb0_globalOrientation(CTransform4f::Identity()) +, xe0_globalScale(1.f, 1.f, 1.f) +, xec_scaleXf(CTransform4f::Identity()) +, x11c_invScaleXf(CTransform4f::Identity()) +, x14c_localScale(1.f, 1.f, 1.f) +, x158_curParticle(0) +, x1ac_particleCount(0) +, x1b0_SPLN(0) +, x1c0_rand( + CCast::ToInt16(x1c_desc->x45_26_CRND ? CCast::ToInt16(CStopwatch::GetGlobalMicros()) : 99)) +, x1c4_(0.f) +, x1c8_(0.f) +, x1d0_24_emitting(true) +, x1d0_26_forceOneUpdate(false) +, x1d0_27_renderGaps(false) +, x1d0_31_constantTex(false) +, x1d1_24_constantUv(false) +, x1e4_tex(nullptr) +, x1e8_uvSpan(1.f) +, x1ec_TSPN(0) +, x1f0_aabbMin(CVector3f::Zero()) +, x1fc_aabbMax(CVector3f::Zero()) +, x208_maxRadius(0.f) +, x20c_moduColor(0xffffffff) { + CGlobalRandom _(x1c0_rand); + mSwooshAliveCount++; + + if (leng > 0) { + x1b4_LENG = leng; + } else { + if (x1c_desc->x10_LENG) { + x1c_desc->x10_LENG->GetValue(0, x1b4_LENG); + } + } + ++x1b4_LENG; + + if (x1c_desc->x18_SIDE) { + x1c_desc->x18_SIDE->GetValue(0, x1b8_SIDE); + } + + x1d0_28_LLRD = x1c_desc->x44_24_LLRD; + x1d0_29_VLS1 = x1c_desc->x44_26_VLS1; + x1d0_30_VLS2 = x1c_desc->x44_27_VLS2; + + if (IsLargeEnough()) { + if (x1c_desc->x0_PSLT) { + x1c_desc->x0_PSLT->GetValue(0, x2c_PSLT); + } else { + x2c_PSLT = 0x7fffff; + } + + x1d0_25_AALP = x1c_desc->x44_31_AALP; + + if (x1c_desc->x38_SPLN) { + x1c_desc->x38_SPLN->GetValue(0, x1b0_SPLN); + } + if (x1b0_SPLN < 0) { + x1b0_SPLN = 0; + } + + x15c_swooshes.clear(); + x15c_swooshes.reserve(x1b4_LENG); + for (int i = 0; i < x15c_swooshes.capacity(); i++) { + x15c_swooshes.push_back(SSwooshData()); + } + + SetOrientation(CTransform4f::Identity()); + + x16c_p0.clear(); + x16c_p0.reserve(x1b8_SIDE); + + for (int i = 0; i < x16c_p0.capacity(); i++) { + x16c_p0.push_back(CVector3f::Zero()); + } + x17c_p1.clear(); + x17c_p1.reserve(x1b8_SIDE); + for (int i = 0; i < x17c_p1.capacity(); i++) { + x17c_p1.push_back(CVector3f::Zero()); + } + + x18c_p2.clear(); + x18c_p2.reserve(x1b8_SIDE); + for (int i = 0; i < x18c_p2.capacity(); i++) { + x18c_p2.push_back(CVector3f::Zero()); + } + x19c_p3.clear(); + x19c_p3.reserve(x1b8_SIDE); + for (int i = 0; i < x19c_p3.capacity(); i++) { + x19c_p3.push_back(CVector3f::Zero()); + } + } +} + +CParticleSwoosh::~CParticleSwoosh() { --mSwooshAliveCount; } + +bool CParticleSwoosh::IsLargeEnough() const { return x1b4_LENG >= 2 && x1b8_SIDE >= 2; } + +bool CParticleSwoosh::Update(double dt) { + if (!IsLargeEnough()) { + return false; + } + OSTime time = OSGetTime(); + CGlobalRandom _(x1c0_rand); + CParticleGlobals::SetParticleLifetime(x1b4_LENG); + CParticleGlobals::SetEmitterTime(x28_curFrame); + CParticleGlobals::UpdateParticleLifetimeTweenValues(0); + float t = time * (1/60.f); +} \ No newline at end of file diff --git a/src/Kyoto/Text/CFontRenderState.cpp b/src/Kyoto/Text/CFontRenderState.cpp new file mode 100644 index 00000000..9efa17c3 --- /dev/null +++ b/src/Kyoto/Text/CFontRenderState.cpp @@ -0,0 +1,24 @@ +#include "Kyoto/Text/CFontRenderState.hpp" + +#pragma inline_max_size(250) +CFontRenderState::CFontRenderState() +: x88_curBlock(nullptr) +, xd4_curX(0) +, xd8_curY(0) +, xdc_currentLineInst(nullptr) +, x108_lineInitialized(true) { + x0_state.GetColors()[0] = CTextColor(255, 255, 255, 255); + x0_state.GetColors()[1] = CTextColor(128, 128, 128, 255); + x0_state.GetColors()[2] = CTextColor(255, 255, 255, 255); + RefreshPalette(); +} + +void CFontRenderState::PushState() { + x10c_pushedStates.push_front(x0_state); +} + +void CFontRenderState::PopState() { + x0_state = *x10c_pushedStates.begin(); + x10c_pushedStates.pop_front(); + RefreshPalette(); +} \ No newline at end of file