From 89322a8d0cb0c1aaab509ab653a9368a2ae5dea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 28 Sep 2026 03:39:31 +0200 Subject: ksys/phys: rearrange the folder layout to match link order A folder's files are linked before its subfolders, and the rigid body files are linked as one flat sequence. ListShape is the one file that does not fit this order. | Old | New | |---|---| | RigidBody/Shape//physShape.cpp | RigidBody/Shape/physShape.cpp | | RigidBody/Shape//physRigidBody.cpp | RigidBody/physRigidBody.cpp | | RigidBody/Shape/List/physListShapeRigidBody.cpp | RigidBody/physRigidBodyListShape.cpp | | physHavokMemoryAllocator.cpp | System/physHavokMemoryAllocator.cpp | | StaticCompound/physStaticCompound{,Mgr,RigidBodyGroup,Util}.cpp | System/ | | StaticCompound/physStaticCompound{Info,Autogen}.cpp | System/physStaticCompoundInfo.cpp | The original has the type infos' cleanup functions just before StaticCompoundInfo's functions, so the merged file defines the reflection data first, with plain static cleanup functions as in Havok's generated reflection code. Template instantiations would be emitted after the rest of the file. (AI assisted using Claude Fable 5.1 and Claude Opus 5.5) --- .../Physics/System/physStaticCompoundMgr.cpp | 177 +++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 src/KingSystem/Physics/System/physStaticCompoundMgr.cpp (limited to 'src/KingSystem/Physics/System/physStaticCompoundMgr.cpp') diff --git a/src/KingSystem/Physics/System/physStaticCompoundMgr.cpp b/src/KingSystem/Physics/System/physStaticCompoundMgr.cpp new file mode 100644 index 00000000..95c4c607 --- /dev/null +++ b/src/KingSystem/Physics/System/physStaticCompoundMgr.cpp @@ -0,0 +1,177 @@ +#include "KingSystem/Physics/System/physStaticCompoundMgr.h" +#include +#include +#include "KingSystem/Physics/System/physStaticCompound.h" +#include "KingSystem/Physics/System/physStaticCompoundInfo.h" +#include "KingSystem/Physics/System/physStaticCompoundRigidBodyGroup.h" +#include "KingSystem/Physics/System/physSystem.h" + +namespace ksys::phys { + +StaticCompoundMgr::StaticCompoundMgr() = default; + +StaticCompoundMgr::~StaticCompoundMgr() { + if (mGroupHandler) { + System::instance()->removeSystemGroupHandler(mGroupHandler); + mGroupHandler = nullptr; + } +} + +bool StaticCompoundMgr::init() { + if (!mGroupHandler) + mGroupHandler = System::instance()->addSystemGroupHandler(ContactLayerType::Entity); + + return true; +} + +void StaticCompoundMgr::addStaticCompound(StaticCompound* sc) { + auto lock = sead::makeScopedLock(mCS); + + if (mStaticCompounds.indexOf(sc) < 0) + mStaticCompounds.pushBack(sc); +} + +void StaticCompoundMgr::removeStaticCompound(StaticCompound* sc) { + auto lock = sead::makeScopedLock(mCS); + + int index = mStaticCompounds.indexOf(sc); + if (index >= 0) + mStaticCompounds.erase(index); +} + +void StaticCompoundMgr::resetExtraTransformsAndApply() { + auto lock = sead::makeScopedLock(mCS); + + for (int i = 0, n = mStaticCompounds.size(); i < n; ++i) + mStaticCompounds[i]->resetExtraTransformsAndApply(); +} + +// NON_MATCHING: should be a tail call but somehow isn't +StaticCompoundRigidBodyGroup* StaticCompoundMgr::getBodyGroup(int group_index) const { + if (mStaticCompounds.size() < 1) + return nullptr; + + return mStaticCompounds[0]->getFieldBodyGroup(group_index + 1); +} + +bool StaticCompoundMgr::hasBodyGroup(const StaticCompoundRigidBodyGroup* group) const { + if (!group) + return false; + + auto lock = sead::makeScopedLock(mCS); + + for (int i = 0, n = mStaticCompounds.size(); i < n; ++i) { + if (!mStaticCompounds[i]->isInitialised()) + continue; + if (!mStaticCompounds[i]->hasFieldBodyGroup(group)) + continue; + + return true; + } + + return false; +} + +void StaticCompoundMgr::processUpdates() { + auto lock = sead::makeScopedLock(mCS); + + for (int i = 0, n = mStaticCompounds.size(); i < n; ++i) + mStaticCompounds[i]->processUpdates(); +} + +void StaticCompoundMgr::recomputeTransformMatrix() { + auto lock = sead::makeScopedLock(mCS); + + for (int i = 0, n = mStaticCompounds.size(); i < n; ++i) + mStaticCompounds[i]->recomputeTransformMatrix(); +} + +sead::Matrix34f +StaticCompoundMgr::getTransformedMatrix(StaticCompoundRigidBodyGroup* const& p_group, + const sead::Matrix34f& mtx) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return mtx; + return group->getTransformedMatrix(mtx); +} + +sead::Matrix34f +StaticCompoundMgr::getInvTransformedMatrix(StaticCompoundRigidBodyGroup* const& p_group, + const sead::Matrix34f& mtx) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return mtx; + return group->getInvTransformedMatrix(mtx); +} + +sead::Vector3f StaticCompoundMgr::getTransformedPos(StaticCompoundRigidBodyGroup* const& p_group, + const sead::Vector3f& pos) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return pos; + return group->getTransformedPos(pos); +} + +sead::Vector3f StaticCompoundMgr::getRotatedDir(StaticCompoundRigidBodyGroup* const& p_group, + const sead::Vector3f& dir) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return dir; + return group->getRotatedDir(dir); +} + +void StaticCompoundMgr::setExtraTransform(StaticCompoundRigidBodyGroup* const& p_group, + const sead::Matrix34f& transform, int index) { + auto* group = p_group; + if (!hasBodyGroup(group)) + return; + group->setExtraTransform(transform, index); +} + +const sead::Matrix34f& +StaticCompoundMgr::getExtraTransform(StaticCompoundRigidBodyGroup* const& p_group, + int index) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return sead::Matrix34f::ident; + return group->getExtraTransform(index); +} + +RigidBody* StaticCompoundMgr::getRigidBody(StaticCompoundRigidBodyGroup* const& p_group) const { + auto* group = p_group; + if (!hasBodyGroup(group)) + return nullptr; + + for (int i = 0; i < NumBodyLayerTypes; ++i) { + if (auto* body = group->getRigidBody(BodyLayerType(i))) + return body; + } + + return nullptr; +} + +void StaticCompoundMgr::getBodyGroupAndMapObject(StaticCompoundRigidBodyGroup** p_group, + map::Object** p_map_object, + const hkpStaticCompoundShape& shape, + const u32* shape_key) const { + auto* group = reinterpret_cast(shape.getUserData()); + + int instance_id; + hkpShapeKey child_key; + auto extract_key = [&] { + shape.decomposeShapeKey(*shape_key, instance_id, child_key); + return instance_id != -1; + }; + + if (!group || !extract_key()) { + *p_group = nullptr; + *p_map_object = nullptr; + } else { + auto object_idx = static_cast(shape.getInstanceUserData(instance_id)); + auto* sc = group->getStaticCompound(); + *p_group = group; + *p_map_object = sc->getMapObject(object_idx); + } +} + +} // namespace ksys::phys -- cgit v1.2.3