diff options
| author | Léo Lam <leo@leolam.fr> | 2026-09-28 03:39:31 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2026-10-13 02:55:29 +0200 |
| commit | 89322a8d0cb0c1aaab509ab653a9368a2ae5dea9 (patch) | |
| tree | 32eb8a0aaa2dd4b25343643ac61b0808f6562d4e /src/KingSystem/Physics/System/physStaticCompoundMgr.cpp | |
| parent | 0ee30415f78a5edc870c0947ca19292f01152205 (diff) | |
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/<Kind>/phys<Kind>Shape.cpp | RigidBody/Shape/phys<Kind>Shape.cpp |
| RigidBody/Shape/<Kind>/phys<Kind>RigidBody.cpp | RigidBody/physRigidBody<Kind>.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)
Diffstat (limited to 'src/KingSystem/Physics/System/physStaticCompoundMgr.cpp')
| -rw-r--r-- | src/KingSystem/Physics/System/physStaticCompoundMgr.cpp | 177 |
1 files changed, 177 insertions, 0 deletions
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 <Havok/Physics2012/Internal/Collide/StaticCompound/hkpStaticCompoundShape.h> +#include <prim/seadScopedLock.h> +#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<StaticCompoundRigidBodyGroup*>(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<int>(shape.getInstanceUserData(instance_id)); + auto* sc = group->getStaticCompound(); + *p_group = group; + *p_map_object = sc->getMapObject(object_idx); + } +} + +} // namespace ksys::phys |
