From 953c5e1edf5086f5d793e82c3c4f9498cdec4e4b Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 18 Mar 2024 16:00:01 -0700 Subject: [PATCH] Initial CPathCamera --- config/GM8E01_00/symbols.txt | 6 +-- config/GM8E01_01/symbols.txt | 6 +-- .../MetroidPrime/Cameras/CCameraSpline.hpp | 4 ++ src/Kyoto/Alloc/CMediumAllocPool.cpp | 44 ++++++++++++++----- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index a102786c..411dd09d 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -1438,7 +1438,7 @@ GetKnotPosition__11CBallCameraCFi = .text:0x8005D084; // type:function size:0x54 GetKnotT__13CCameraSplineCFi = .text:0x8005D0D8; // type:function size:0x24 scope:global CalculateKnots__13CCameraSplineFRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D0FC; // type:function size:0x3B4 scope:global __as__Q24rstl45vector<9TUniqueId,Q24rstl17rmemory_allocator>FRCQ24rstl45vector<9TUniqueId,Q24rstl17rmemory_allocator> = .text:0x8005D4B0; // type:function size:0xF4 scope:global -Initialise__13CCameraSplineFRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D5A4; // type:function size:0x44 scope:global +Initialise__13CCameraSplineF9TUniqueIdRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D5A4; // type:function size:0x44 scope:global __dt__13CCameraSplineFv = .text:0x8005D5E8; // type:function size:0x178 scope:global __ct__13CCameraSplineFb = .text:0x8005D760; // type:function size:0x50 scope:global Reset__13CCameraSpringFv = .text:0x8005D7B0; // type:function size:0x44 scope:global @@ -6929,7 +6929,7 @@ ClampToClosedDoor__11CPathCameraFR13CStateManager = .text:0x8012DD3C; // type:fu MoveAlongSpline__11CPathCameraFfR13CStateManager = .text:0x8012DE30; // type:function size:0x3D8 scope:global Reset__11CPathCameraFRC12CTransform4fR13CStateManager = .text:0x8012E208; // type:function size:0x4A0 scope:global __dt__11CPathCameraFv = .text:0x8012E6A8; // type:function size:0x70 scope:global -__ct__11CPathCameraF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC12CTransform4fbbbbbfffffffQ211CPathCamera22EInitialSplinePosition = .text:0x8012E718; // type:function size:0x17C scope:global +__ct__11CPathCameraF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC12CTransform4fbfffffUlQ211CPathCamera22EInitialSplinePosition = .text:0x8012E718; // type:function size:0x17C scope:global __sinit_CPathCamera_cpp = .text:0x8012E894; // type:function size:0x78 scope:local fn_8012E90C = .text:0x8012E90C; // type:function size:0x4 AddRipple__11CFluidPlaneFRC7CRippleRC12CScriptWaterR13CStateManager = .text:0x8012E910; // type:function size:0x54 scope:global @@ -18268,7 +18268,7 @@ __vt__11CBCCoverCmd = .data:0x803E0B8C; // type:object size:0xC scope:global __vt__14CBCWallHangCmd = .data:0x803E0B98; // type:object size:0x48 scope:global lbl_803E0BE0 = .data:0x803E0BE0; // type:object size:0x18 __vt__17CScriptCoverPoint = .data:0x803E0BF8; // type:object size:0x6C scope:global -lbl_803E0C68 = .data:0x803E0C68; // type:object size:0x78 +__vt__11CPathCamera = .data:0x803E0C68; // type:object size:0x78 lbl_803E0CE0 = .data:0x803E0CE0; // type:object size:0x20 __vt__19CScriptGrapplePoint = .data:0x803E0D00; // type:object size:0x6C scope:global __vt__19CHUDBillboardEffect = .data:0x803E0D70; // type:object size:0x6C scope:global diff --git a/config/GM8E01_01/symbols.txt b/config/GM8E01_01/symbols.txt index 0793702f..f2090015 100644 --- a/config/GM8E01_01/symbols.txt +++ b/config/GM8E01_01/symbols.txt @@ -1438,7 +1438,7 @@ GetKnotPosition__11CBallCameraCFi = .text:0x8005D100; // type:function size:0x54 GetKnotT__13CCameraSplineCFi = .text:0x8005D154; // type:function size:0x24 scope:global CalculateKnots__13CCameraSplineFRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D178; // type:function size:0x3B4 scope:global __as__Q24rstl45vector<9TUniqueId,Q24rstl17rmemory_allocator>FRCQ24rstl45vector<9TUniqueId,Q24rstl17rmemory_allocator> = .text:0x8005D52C; // type:function size:0xF4 scope:global -Initialise__13CCameraSplineFRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D620; // type:function size:0x44 scope:global +Initialise__13CCameraSplineF9TUniqueIdRCQ24rstl48vector<11SConnection,Q24rstl17rmemory_allocator>R13CStateManager = .text:0x8005D620; // type:function size:0x44 scope:global __dt__13CCameraSplineFv = .text:0x8005D664; // type:function size:0x178 scope:global __ct__13CCameraSplineFb = .text:0x8005D7DC; // type:function size:0x50 scope:global Reset__13CCameraSpringFv = .text:0x8005D82C; // type:function size:0x44 scope:global @@ -6931,7 +6931,7 @@ ClampToClosedDoor__11CPathCameraFR13CStateManager = .text:0x8012DDB8; // type:fu MoveAlongSpline__11CPathCameraFfR13CStateManager = .text:0x8012DEAC; // type:function size:0x3D8 scope:global Reset__11CPathCameraFRC12CTransform4fR13CStateManager = .text:0x8012E284; // type:function size:0x4A0 scope:global __dt__11CPathCameraFv = .text:0x8012E724; // type:function size:0x70 scope:global -__ct__11CPathCameraF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC12CTransform4fbbbbbfffffffQ211CPathCamera22EInitialSplinePosition = .text:0x8012E794; // type:function size:0x17C scope:global +__ct__11CPathCameraF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC12CTransform4fbfffffUlQ211CPathCamera22EInitialSplinePosition = .text:0x8012E794; // type:function size:0x17C scope:global __sinit_CPathCamera_cpp = .text:0x8012E910; // type:function size:0x78 scope:global nullsub_209 = .text:0x8012E988; // type:function size:0x4 scope:global AddRipple__11CFluidPlaneFRC7CRippleRC12CScriptWaterR13CStateManager = .text:0x8012E98C; // type:function size:0x54 scope:global @@ -18321,7 +18321,7 @@ __vt__11CBCCoverCmd = .data:0x803E0D6C; // type:object size:0xC scope:global __vt__14CBCWallHangCmd = .data:0x803E0D78; // type:object size:0x48 scope:global lbl_803E0BE0 = .data:0x803E0DC0; // type:object size:0x18 scope:global __vt__17CScriptCoverPoint = .data:0x803E0DD8; // type:object size:0x70 scope:global -lbl_803E0C68 = .data:0x803E0E48; // type:object size:0x78 scope:global +__vt__11CPathCamera = .data:0x803E0E48; // type:object size:0x78 scope:global lbl_803E0CE0 = .data:0x803E0EC0; // type:object size:0x20 scope:global __vt__19CScriptGrapplePoint = .data:0x803E0EE0; // type:object size:0x6C scope:global __vt__19CHUDBillboardEffect = .data:0x803E0F50; // type:object size:0x70 scope:global diff --git a/include/MetroidPrime/Cameras/CCameraSpline.hpp b/include/MetroidPrime/Cameras/CCameraSpline.hpp index 058c5957..31b2ec32 100644 --- a/include/MetroidPrime/Cameras/CCameraSpline.hpp +++ b/include/MetroidPrime/Cameras/CCameraSpline.hpp @@ -7,8 +7,10 @@ #include "Kyoto/Math/CVector3f.hpp" +#include "MetroidPrime/CEntityInfo.hpp" #include "rstl/vector.hpp" +class CStateManager; class CCameraSpline { public: CCameraSpline(bool closedLoop); @@ -16,6 +18,8 @@ public: // tODO + void Initialise(TUniqueId, const rstl::vector&, CStateManager&); + private: rstl::vector< CVector3f > x4_positions; rstl::vector< TUniqueId > x14_wpTracker; diff --git a/src/Kyoto/Alloc/CMediumAllocPool.cpp b/src/Kyoto/Alloc/CMediumAllocPool.cpp index 69c50856..bcace74a 100644 --- a/src/Kyoto/Alloc/CMediumAllocPool.cpp +++ b/src/Kyoto/Alloc/CMediumAllocPool.cpp @@ -178,19 +178,43 @@ void* SMediumAllocPuddle::FindFreeEntry(uint numBlocks) { } void SMediumAllocPuddle::Free(const void* ptr) { - uint r28 = 0; - uint r29 = x8_bookKeeping[((uint)ptr - (uint)x0_mainData.get()) / 32]; - x14_numBlocks += r29; - x18_numAllocs--; - uchar* bookKeepingStart = x8_bookKeeping; - uchar* block = &x8_bookKeeping[((uint)ptr - (uint)x0_mainData.get()) / 32]; + uint blockOffset = ((uint)ptr - (uint)x0_mainData.get()) / 32; + uint blockCount = x8_bookKeeping[blockOffset]; - if (xc_cachedBookKeepingAddr == block) { - r28 = 1; + x14_numBlocks += blockCount; + --x18_numAllocs; + + uchar* bookKeepingStart = x8_bookKeeping; + uchar* cachedBookKeep = bookKeepingStart + blockOffset; + uchar* block = bookKeepingStart + blockOffset; + uchar* bookKeepingPtr = block; + + if (block > bookKeepingStart && block[-1] & 0x80) { + if ((block[-1] & 0x60)) { + blockOffset = (((0x40 - (block[-1] & 0x60)) != 0) / 32) + 1; + } else if ((block[-1] & 0x60) == 0x60ul) { + blockOffset = 3; + } else { + blockOffset = block[-2] + (block[-1] & 0x7f) * 256; + } + + bookKeepingPtr = block - ((ushort)blockOffset); + blockOffset = (ushort)(blockCount + ((ushort)blockOffset)); } - if (block > bookKeepingStart) { - if ((block[-1] & 0x80) != 0) { + uint blockCount2 = blockOffset; + uchar* ptr1 = block + blockCount; + if (ptr1 < bookKeepingStart + x1c_numEntries && (ptr1[0] & 0x80) != 0) { + blockOffset = GetBlockOffset(ptr1, bookKeepingStart + GetNumEntries()); + blockCount2 += blockOffset; + } + + InitBookKeeping(bookKeepingPtr, blockCount2); + if (cachedBookKeep == block) { + if (bookKeepingPtr != bookKeepingStart) { + xc_cachedBookKeepingAddr = nullptr; + } else { + xc_cachedBookKeepingAddr = bookKeepingPtr - bookKeepingPtr[-1]; } } }