diff --git a/data/uking_functions.csv b/data/uking_functions.csv index ba746a6b..27895306 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -73748,8 +73748,8 @@ Address,Quality,Size,Name 0x0000007100d406e4,O,000028,_ZNK4ksys3act14PhysicsUserTag8getName2Ev 0x0000007100d40700,O,000204,_ZNK4ksys3act14PhysicsUserTag27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE 0x0000007100d407cc,O,000092,_ZNK4ksys3act14PhysicsUserTag18getRuntimeTypeInfoEv -0x0000007100d40828,U,000360,PlacementMap::ctor -0x0000007100d40990,U,000644,PlacementMap::dtor +0x0000007100d40828,O,000360,_ZN4ksys3map12PlacementMapC1Ev +0x0000007100d40990,O,000644,_ZN4ksys3map12PlacementMapD1Ev 0x0000007100d40c14,U,000072,PlacementMap::loadStaticMap_ 0x0000007100d40c5c,U,001692,PlacementMap::doLoadStaticMap_ 0x0000007100d412f8,U,000104,PlacementMap::parseStaticMap_ diff --git a/src/KingSystem/Map/CMakeLists.txt b/src/KingSystem/Map/CMakeLists.txt index 9bf05203..4c612d59 100644 --- a/src/KingSystem/Map/CMakeLists.txt +++ b/src/KingSystem/Map/CMakeLists.txt @@ -14,6 +14,10 @@ target_sources(uking PRIVATE mapObjectLink.h mapPlacementActors.cpp mapPlacementActors.h + mapPlacementMap.cpp + mapPlacementMap.h + mapPlacementMapMgr.cpp + mapPlacementMapMgr.h mapPlacementMgr.cpp mapPlacementMgr.h mapPlacementTree.cpp diff --git a/src/KingSystem/Map/mapPlacementMap.cpp b/src/KingSystem/Map/mapPlacementMap.cpp new file mode 100644 index 00000000..ea3531d1 --- /dev/null +++ b/src/KingSystem/Map/mapPlacementMap.cpp @@ -0,0 +1,36 @@ +#include "KingSystem/Map/mapPlacementMap.h" + +namespace ksys::map { + +PlacementMap::PlacementMap() { + mInitStatus = InitStatus::None; + mParsedNumStaticObjs = 0xFFFFFFFF; + mStaticMapLoaded = StaticMap::None; + mNumStaticObjs = 0xFFFFFFFF; + mMat = sead::Matrix34f::ident; + mDistanceToCurrentMapUnit = 0; + mSkipLoadStaticMap = 0; + _38c = 0xFFFFFFFF; + mIdx = 0; + _388 = 0; + mCol = 0; + mRow = 0; + mNumRoutes = 0; + mP18 = 0; + mMgr = 0; + mPa = 0; + mDynamicGroupIdx = 0xFFFFFFFF; + mRes[0].mStatus = HkscRes::Status::_0; + mRes[1].mStatus = HkscRes::Status::_0; + mRes[2].mStatus = HkscRes::Status::_0; + mRes[3].mStatus = HkscRes::Status::_0; +} + +PlacementMap::~PlacementMap() { + mRoutes.freeBuffer(); + for (auto& r : mRes) { + r.cleanup(); + } +} + +} // namespace ksys::map diff --git a/src/KingSystem/Map/mapPlacementMap.h b/src/KingSystem/Map/mapPlacementMap.h new file mode 100644 index 00000000..91ae9013 --- /dev/null +++ b/src/KingSystem/Map/mapPlacementMap.h @@ -0,0 +1,131 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include "KingSystem/Map/mapPlacementActors.h" +#include "KingSystem/Map/mapPlacementMapMgr.h" +#include "KingSystem/Physics/StaticCompound/physStaticCompound.h" +#include "KingSystem/Resource/resHandle.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::map { + +class PlacementMapMgr; + +class PlacementMap { + struct HkscRes { + public: + enum class Status : int { + _0 = 0, + _1 = 1, + _2 = 2, // Call cleanupHkscMaybe(), if ok, set to 3 + _3 = 3, + _4 = 4, // Call staticCompoundStuff, if ok, set to 5 + _5 = 5, + }; + + HkscRes() = default; + ~HkscRes() = default; + + void cleanup() { + auto* r = mRes.getResource(); + if (auto sc = sead::DynamicCast(r)) { + if (sc->calledFromMapDtor()) { + sc->cleanUp(); + } + } + } + + res::Handle mRes; + Status mStatus; + }; + KSYS_CHECK_SIZE_NX150(HkscRes, 0x58); + + enum class StaticMap : u16 { None = 0, Loaded = 1 << 0, Parsed = 1 << 8 }; + enum class InitStatus : int { + None = 0, + StaticLoaded = 1, + DynamicLoadStarted = 2, + DynamicLoaded = 3, + _4 = 4, + _5 = 5, // x_9 takes initStatus from 4 to 5 in pmm->updateHkscLoadStatuesMaybe() + }; + KSYS_CHECK_SIZE_NX150(InitStatus, 4); + +public: + PlacementMap(); + ~PlacementMap(); + +private: + int loadStaticMap_(bool load); + void doLoadStaticMap_(bool load); + + bool parseStaticMap_(sead::Heap* heap, u8* data); + void parseMap_(sead::Heap* heap, u8* data, int group, u32 idx); + + bool loadDynamicMap(); + + int parseDynamicMap(); + + void resetDynamic(); + void unload(); + void unloadStaticMubin(); + int x_6(); + void x_5(); + int traverseStuff(sead::Vector3f* vec, PlacementActors* pa, int id); + + phys::BodyGroup* getFieldBodyGroup(u32 field_body_group_index); + void cleanupPhysics(); + bool loadStaticCompound(int index, bool is_auto_gen_mu, bool load_maybe); + int x_2(int id); + void x(int id, Object* obj); + void unloadHksc(int id); + int x_4(int id); + int x_1(int id); + bool staticCompoundStuff(int sc_id, bool cleanup); + int cleanHkscMaybe(int id); + bool sub_7100D43F18(const sead::Vector3f& pos); + void doDisableObjStaticCompound(Object* obj, bool disable); + void x_9(); + + void x_7(int idx, int unknown, char column, char row, const sead::SafeString& mubinPath, + const sead::SafeString& folderAndFile, int map_id_maybe, bool skip_load_static_map); + + u16 mSkipLoadStaticMap; + StaticMap mStaticMapLoaded; + u16 _04; + s16 _06; + sead::FixedSafeString<128> mMubinPath; + sead::FixedSafeString<128> mFolderAndFile; + u32 mIdx; + sead::SafeArray mRes; + res::Handle mStaticMubinRes; + res::Handle mDynamicMubinRes; + int mDynamicGroupIdx; + int mParsedNumStaticObjs; + int mNumStaticObjs; + InitStatus mInitStatus; + s8 mCol; + s8 mRow; + u16 _352; + sead::Matrix34f mMat; + int mDistanceToCurrentMapUnit; + u32 _388; // 388 check x_7() called .... + u32 _38c; // 38c ... from MapMgr::ctor (a8) + PlacementActors* mPa; + PlacementMapMgr* mMgr; + void* mP18; + sead::Buffer mRoutes; + int mNumRoutes; + int gap_38c; + sead::CriticalSection mCs; +}; + +KSYS_CHECK_SIZE_NX150(PlacementMap, 0x400); + +} // namespace ksys::map diff --git a/src/KingSystem/Map/mapPlacementMapMgr.cpp b/src/KingSystem/Map/mapPlacementMapMgr.cpp new file mode 100644 index 00000000..3ab81e10 --- /dev/null +++ b/src/KingSystem/Map/mapPlacementMapMgr.cpp @@ -0,0 +1,3 @@ +#include "KingSystem/Map/mapPlacementMapMgr.h" + +namespace ksys::map {} // namespace ksys::map diff --git a/src/KingSystem/Map/mapPlacementMapMgr.h b/src/KingSystem/Map/mapPlacementMapMgr.h new file mode 100644 index 00000000..ce86eceb --- /dev/null +++ b/src/KingSystem/Map/mapPlacementMapMgr.h @@ -0,0 +1,58 @@ +#pragma once + +#include +#include +#include +#include +#include "KingSystem/Map/mapPlacementMap.h" +#include "KingSystem/Resource/resHandle.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::map { + +class MapProperties; +class Placement18; +class FarActorMerge; + +class PlacementMap; + +/* NOT WORKING */ +class PlacementMapMgr { + /* NOT WORKING */ + class PlacementMapArray { + public: + PlacementMapArray() = default; + ~PlacementMapArray() = default; + + sead::PtrArray mMaps; + sead::PtrArray mPtrs; + PlacementActors* mPa; + s64 _28; + res::Handle mRes; + Placement18* mP18; + s32 _88; + s32 _8c; + void* _90; + }; + KSYS_CHECK_SIZE_NX150(PlacementMapArray, 0x98); + +public: + PlacementMapMgr() = default; + ~PlacementMapMgr() = default; + +private: + sead::Buffer mMaps; + MapProperties* mMapProps; + s32 _18; + s32 _1c; + PlacementMapArray mMapArray; + FarActorMerge* mFarActorMerge; + s32 mNeedLoadDynMap; + s32 mNeedLoadDynMapPhysics; + bool mIsShrineOrDivineBeast; + bool mIsShrine; +}; + +KSYS_CHECK_SIZE_NX150(PlacementMapMgr, 0xD0); + +} // namespace ksys::map diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h index 397e55c8..c03d68eb 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h @@ -41,6 +41,9 @@ public: bool finishParsing_() override; bool m7_() override; + void cleanUp(); + bool calledFromMapDtor(); + private: enum class Flag { Initialised = 1 << 0,