From c804527d7a247aca80b88de56191bb13938de38a Mon Sep 17 00:00:00 2001 From: savage13 Date: Sun, 20 Feb 2022 17:50:28 -0500 Subject: [PATCH] PlacementMap: Add x_0, x_4(); change u16 mStaticCompoundId to s16 mStaticCompundActorId (#85) --- data/uking_functions.csv | 4 +- src/KingSystem/Map/mapObject.cpp | 4 +- src/KingSystem/Map/mapObject.h | 6 +- src/KingSystem/Map/mapPlacementMap.cpp | 90 +++++++++++++++++-- src/KingSystem/Map/mapPlacementMap.h | 6 +- src/KingSystem/Map/mapPlacementMgr.h | 2 + .../StaticCompound/physStaticCompound.cpp | 8 +- .../StaticCompound/physStaticCompound.h | 2 +- 8 files changed, 103 insertions(+), 19 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 2722a676..567917b5 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -73767,9 +73767,9 @@ Address,Quality,Size,Name 0x0000007100d43280,O,000588,_ZN4ksys3map12PlacementMap14cleanupPhysicsEv 0x0000007100d434cc,O,000424,_ZN4ksys3map12PlacementMap18loadStaticCompoundEibb 0x0000007100d43674,O,000400,_ZN4ksys3map12PlacementMap3x_2Ei -0x0000007100d43804,U,000552,PlacementMap::x_0 +0x0000007100d43804,O,000552,_ZN4ksys3map12PlacementMap26updateObjectCollisionAndIdEiPNS0_6ObjectE 0x0000007100d43a2c,O,000028,_ZN4ksys3map12PlacementMap10unloadHkscEi -0x0000007100d43a48,U,000620,PlacementMap::x_4 +0x0000007100d43a48,O,000620,_ZN4ksys3map12PlacementMap26clearStaticCompoundActorIdEi 0x0000007100d43cb4,U,000172,PlacementMap::x_1 0x0000007100d43d60,U,000248,PlacementMap::staticCompoundStuff 0x0000007100d43e58,O,000192,_ZN4ksys3map12PlacementMap25doSomethingStaticCompoundEi diff --git a/src/KingSystem/Map/mapObject.cpp b/src/KingSystem/Map/mapObject.cpp index d0b57fde..8dc08124 100644 --- a/src/KingSystem/Map/mapObject.cpp +++ b/src/KingSystem/Map/mapObject.cpp @@ -61,7 +61,7 @@ void Object::initData(MubinIter* iter, u8 idx, u32 actor_data_idx, ActorData* da mFlags.makeAllZero(); mIdx = 0; mNumLinksPointingToMe = 0; - mStaticCompoundId = 0xFFFF; + mStaticCompoundActorId = -1; _18 = nullptr; _20 = nullptr; _10 = nullptr; @@ -88,7 +88,7 @@ void Object::initData(MubinIter* iter, u8 idx, u32 actor_data_idx, ActorData* da _10 = nullptr; _18 = nullptr; _20 = nullptr; - mStaticCompoundId = 0xFFFF; + mStaticCompoundActorId = -1; mActorDataIdx = actor_data_idx; mProc = nullptr; mLinkData = nullptr; diff --git a/src/KingSystem/Map/mapObject.h b/src/KingSystem/Map/mapObject.h index cdb2092e..f5c110c0 100644 --- a/src/KingSystem/Map/mapObject.h +++ b/src/KingSystem/Map/mapObject.h @@ -40,6 +40,7 @@ public: _100 = 0x100, ActorCreated = 0x200, _400 = 0x400, + _800 = 0x800, _2000 = 0x2000, _4000 = 0x4000, _8000 = 0x8000, @@ -187,7 +188,8 @@ public: auto getActorDataIdx() const { return mActorDataIdx; } auto getIdx() const { return mIdx; } auto getId() const { return mId; } - auto getStaticCompoundId() const { return mStaticCompoundId; } + auto getStaticCompoundActorId() const { return mStaticCompoundActorId; } + void setStaticCompoundActorId(s16 id) { mStaticCompoundActorId = id; } const ActorData& getActorData() const { return PlacementMgr::instance()->mPlacementActors->mActorData[mActorDataIdx]; @@ -215,7 +217,7 @@ private: sead::TypedBitFlag mActorFlags8; u8 _b = 0xff; u16 mId = 0; - u16 mStaticCompoundId = 0xffff; + s16 mStaticCompoundActorId = -1; void* _10 = nullptr; void* _18 = nullptr; void* _20 = nullptr; diff --git a/src/KingSystem/Map/mapPlacementMap.cpp b/src/KingSystem/Map/mapPlacementMap.cpp index 8bc0988b..ad4cfeef 100644 --- a/src/KingSystem/Map/mapPlacementMap.cpp +++ b/src/KingSystem/Map/mapPlacementMap.cpp @@ -40,6 +40,73 @@ PlacementMap::~PlacementMap() { r.cleanup(); } } +bool PlacementMap::clearStaticCompoundActorId(int idx) { + const auto lock = sead::makeScopedLock(mCs); + const auto& resource = mRes[idx].mRes.getResource(); + if (auto* sc = sead::DynamicCast(resource)) { + if (sc->calledFromMapDtor()) { + return false; + } + mRes[idx].mRes.requestUnload(); + } + + for (int i = mParsedNumStaticObjs; i <= mNumStaticObjs; i++) { + auto* obj = mPa->getStaticObj_2(i); + if (getStaticCompoundIdFromPosition(*obj) == idx) { + obj->setStaticCompoundActorId(-1); + } + } + + int gid = mDynamicGroupIdx; + if (gid >= 0) { + int num_objs = mPa->getNumObjs(gid); + for (int i = 0; i < num_objs; i++) { + auto* obj = mPa->getObj(gid, i); + if (getStaticCompoundIdFromPosition(*obj) == idx) { + obj->setStaticCompoundActorId(-1); + } + } + } + return true; +} + +void PlacementMap::updateObjectCollisionAndId(int index, Object* obj) { + if (PlacementMgr::instance()->auto17(obj)) { + return; + } + if (getStaticCompoundIdFromPosition(*obj) != index) { + return; + } + auto& rsrc = mRes[index]; + obj->setStaticCompoundActorId(-1); + + const auto lock = sead::makeScopedLock(mCs); + + auto* sc = sead::DynamicCast(rsrc.mRes.getResource()); + if (!sc) { + return; + } + u32 hash_id = obj->getHashId(); + int srt_hash = 0; + obj->getMubinIter().tryGetParamIntByKey(&srt_hash, "SRTHash"); + int idx = sc->setMapObject(hash_id, static_cast(srt_hash), obj); + obj->setStaticCompoundActorId(idx); + if (obj->getStaticCompoundActorId() < 0) { + return; + } + bool disable = false; + if (obj->shouldSkipSpawn() || + (obj->checkActorDataFlag(mPa, map::ActorData::Flag::MapConstPassive) && + obj->getFlags0().isOn(Object::Flag0::_800))) { + obj->resetFlags0(Object::Flag0::_200000); + disable = false; + } else { + obj->setFlags0(Object::Flag0::_200000); + disable = true; + } + sc->disableCollision(idx, disable); +} + bool PlacementMap::parseStaticMap_(sead::Heap* heap, u8* data) { if (!mMubinPath.isEmpty()) { if (!mSkipLoadStaticMap) { @@ -52,14 +119,25 @@ bool PlacementMap::parseStaticMap_(sead::Heap* heap, u8* data) { mStaticMapLoaded = true; return false; } - +int PlacementMap::getStaticCompoundIdFromPosition(const Object& object) const { + if (mMgr->isShrineOrDivineBeast()) { + return 0; + } + return getStaticCompoundIdFromPosition(object.getTranslate().x, object.getTranslate().z); +} +int PlacementMap::getStaticCompoundIdFromPosition(float x, float z) const { + if (mMgr->isShrineOrDivineBeast()) { + return 0; + } + return getStaticCompoundIdFromPosition(sead::Vector3f(x, 0, z)); +} int PlacementMap::getStaticCompoundIdFromPosition(const sead::Vector3f& pos) const { if (mMgr->isShrineOrDivineBeast()) { return 0; } float dx = (pos.x - (1000 * mCol - 5000)); float dz = (pos.z - (1000 * mRow - 4000)); - return (2 * (dz > 500.0)) + (dx > 500.0); + return (2 * (dz > 500.0f)) + (dx > 500.0f); } bool PlacementMap::isDynamicLoaded(const sead::Vector3f& pos) { @@ -144,20 +222,20 @@ PlacementMap::MapObjStatus PlacementMap::x_2(int hksc_idx) { sc->sub_7100FCAD0C(mMat); for (int i = mParsedNumStaticObjs; i <= mNumStaticObjs; i++) { - x_0(hksc_idx, mPa->getStaticObj_0(i)); + updateObjectCollisionAndId(hksc_idx, mPa->getStaticObj_0(i)); } const int gid = mDynamicGroupIdx; if (gid >= 0) { int n = mPa->getNumObjs(gid); for (int i = 0; i < n; i++) { - x_0(hksc_idx, mPa->getObj(gid, i)); + updateObjectCollisionAndId(hksc_idx, mPa->getObj(gid, i)); } } return MapObjStatus::Loading; } void PlacementMap::doDisableObjStaticCompound(Object* obj, bool disable) { - if ((s16)obj->getStaticCompoundId() < 0) { + if ((s16)obj->getStaticCompoundActorId() < 0) { return; } const auto lock = sead::makeScopedLock(mCs); @@ -175,7 +253,7 @@ void PlacementMap::doDisableObjStaticCompound(Object* obj, bool disable) { int idx = getStaticCompoundIdFromPosition(obj->getTranslate()); auto* resource = mRes[idx].mRes.getResource(); if (auto* sc = sead::DynamicCast(resource)) { - s16 sc_id = obj->getStaticCompoundId(); + s16 sc_id = obj->getStaticCompoundActorId(); sc->disableCollision(sc_id, disable); } } diff --git a/src/KingSystem/Map/mapPlacementMap.h b/src/KingSystem/Map/mapPlacementMap.h index c5dcf62f..7e563654 100644 --- a/src/KingSystem/Map/mapPlacementMap.h +++ b/src/KingSystem/Map/mapPlacementMap.h @@ -92,9 +92,9 @@ private: void cleanupPhysics(); bool loadStaticCompound(int hksc_idx, bool is_auto_gen_mu, bool req_arg_8); MapObjStatus x_2(int hksc_idx); - void x_0(int id, Object* obj); + void updateObjectCollisionAndId(int id, Object* obj); void unloadHksc(int hksc_idx); - int x_4(int id); + bool clearStaticCompoundActorId(int id); int x_1(int id); bool staticCompoundStuff(int sc_id, bool cleanup); int doSomethingStaticCompound(int hksc_idx); @@ -106,6 +106,8 @@ private: const sead::SafeString& folder_and_file, int map_id_maybe, bool skip_load_static_map); int getStaticCompoundIdFromPosition(const sead::Vector3f& pos) const; + int getStaticCompoundIdFromPosition(float x, float z) const; + int getStaticCompoundIdFromPosition(const Object& object) const; u8 _0; u8 mSkipLoadStaticMap; diff --git a/src/KingSystem/Map/mapPlacementMgr.h b/src/KingSystem/Map/mapPlacementMgr.h index b8956d3d..b5dacda9 100644 --- a/src/KingSystem/Map/mapPlacementMgr.h +++ b/src/KingSystem/Map/mapPlacementMgr.h @@ -55,6 +55,8 @@ public: bool someFlagCheck() const; void threadFn(sead::Thread* thread, sead::MessageQueue::Element msg); + // 0x00000071011eb4dc + bool auto17(Object* obj); enum class MgrFlag { _1 = 0x1, diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp b/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp index 6986e510..ea20e2df 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp @@ -62,11 +62,11 @@ void StaticCompound::doCreate_(u8* buffer, u32 buffer_size, sead::Heap* parent_h mHeap->adjust(); } -void StaticCompound::setMapObject(u32 hash_id, u32 srt_hash, map::Object* object) { +int StaticCompound::setMapObject(u32 hash_id, u32 srt_hash, map::Object* object) { int idx = mStaticCompoundInfo->getActorIdx(hash_id, srt_hash); - if (idx < 0 || idx >= mMapObjects.size()) - return; - mMapObjects[idx] = object; + if (idx >= 0 && idx < mMapObjects.size()) + mMapObjects[idx] = object; + return idx; } map::Object* StaticCompound::getMapObject(int shape_idx) const { diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h index e5e61505..18129f00 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h @@ -27,7 +27,7 @@ public: StaticCompound(); ~StaticCompound() override; - void setMapObject(u32 hash_id, u32 srt_hash, map::Object* object); + int setMapObject(u32 hash_id, u32 srt_hash, map::Object* object); map::Object* getMapObject(int shape_idx) const; bool disableCollision(int actor_idx, bool x);