summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2022-03-25 22:34:22 +0100
committerLéo Lam <leo@leolam.fr>2022-03-25 23:22:12 +0100
commit9f8530ec90d2fa77aa45a96e081afdd30ec8aed6 (patch)
tree55dad9bd7e63f1cf3ccf0eb8ed8f3aa47a1e1959
parentf3b3653b0f7bce79adb0e46240f88ef9518f9d44 (diff)
ksys/phys: Finish StaticCompoundMgr
-rw-r--r--data/uking_functions.csv30
-rw-r--r--src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp2
-rw-r--r--src/KingSystem/Physics/StaticCompound/physStaticCompound.h4
-rw-r--r--src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.cpp155
-rw-r--r--src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h41
-rw-r--r--src/KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h1
6 files changed, 213 insertions, 20 deletions
diff --git a/data/uking_functions.csv b/data/uking_functions.csv
index a421a6a2..6f0069a7 100644
--- a/data/uking_functions.csv
+++ b/data/uking_functions.csv
@@ -84222,7 +84222,7 @@ Address,Quality,Size,Name
0x0000007100fcac9c,O,000112,_ZN4ksys4phys14StaticCompound24recomputeTransformMatrixEv
0x0000007100fcad0c,O,000328,_ZN4ksys4phys14StaticCompound20applyExtraTransformsERKN4sead8Matrix34IfEE
0x0000007100fcae54,O,000028,_ZN4ksys4phys14StaticCompound17getFieldBodyGroupEi
-0x0000007100fcae70,O,000084,_ZNK4ksys4phys14StaticCompound17hasFieldBodyGroupEPNS0_28StaticCompoundRigidBodyGroupE
+0x0000007100fcae70,O,000084,_ZNK4ksys4phys14StaticCompound17hasFieldBodyGroupEPKNS0_28StaticCompoundRigidBodyGroupE
0x0000007100fcaec4,O,000008,_ZNK4ksys4phys14StaticCompound27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE
0x0000007100fcaecc,O,000092,_ZNK4ksys4phys14StaticCompound18getRuntimeTypeInfoEv
0x0000007100fcaf28,O,000008,_ZNK4ksys4phys14StaticCompound10needsParseEv
@@ -84240,20 +84240,20 @@ Address,Quality,Size,Name
0x0000007100fcb470,O,000076,_ZN4ksys4phys17StaticCompoundMgrD1Ev
0x0000007100fcb4bc,O,000084,_ZN4ksys4phys17StaticCompoundMgrD0Ev
0x0000007100fcb510,O,000068,_ZN4ksys4phys17StaticCompoundMgr4initEv
-0x0000007100fcb554,U,000140,
-0x0000007100fcb5e0,U,000120,
-0x0000007100fcb658,U,000124,
-0x0000007100fcb6d4,U,000052,
-0x0000007100fcb708,U,000124,
-0x0000007100fcb784,U,000124,
-0x0000007100fcb800,U,000212,
-0x0000007100fcb8d4,U,000212,somePhysicsCalcPositionStuff
-0x0000007100fcb9a8,U,000176,
-0x0000007100fcba58,U,000176,
-0x0000007100fcbb08,U,000220,
-0x0000007100fcbbe4,U,000176,
-0x0000007100fcbc94,U,000324,
-0x0000007100fcbdd8,U,000104,
+0x0000007100fcb554,O,000140,_ZN4ksys4phys17StaticCompoundMgr17addStaticCompoundEPNS0_14StaticCompoundE
+0x0000007100fcb5e0,O,000120,_ZN4ksys4phys17StaticCompoundMgr20removeStaticCompoundEPNS0_14StaticCompoundE
+0x0000007100fcb658,O,000124,_ZN4ksys4phys17StaticCompoundMgr28resetExtraTransformsAndApplyEv
+0x0000007100fcb6d4,m,000052,_ZNK4ksys4phys17StaticCompoundMgr12getBodyGroupEi
+0x0000007100fcb708,O,000124,_ZN4ksys4phys17StaticCompoundMgr14processUpdatesEv
+0x0000007100fcb784,O,000124,_ZN4ksys4phys17StaticCompoundMgr24recomputeTransformMatrixEv
+0x0000007100fcb800,O,000212,_ZNK4ksys4phys17StaticCompoundMgr20getTransformedMatrixERKPNS0_28StaticCompoundRigidBodyGroupERKN4sead8Matrix34IfEE
+0x0000007100fcb8d4,O,000212,_ZNK4ksys4phys17StaticCompoundMgr23getInvTransformedMatrixERKPNS0_28StaticCompoundRigidBodyGroupERKN4sead8Matrix34IfEE
+0x0000007100fcb9a8,O,000176,_ZNK4ksys4phys17StaticCompoundMgr17getTransformedPosERKPNS0_28StaticCompoundRigidBodyGroupERKN4sead7Vector3IfEE
+0x0000007100fcba58,O,000176,_ZNK4ksys4phys17StaticCompoundMgr13getRotatedDirERKPNS0_28StaticCompoundRigidBodyGroupERKN4sead7Vector3IfEE
+0x0000007100fcbb08,O,000220,_ZN4ksys4phys17StaticCompoundMgr17setExtraTransformERKPNS0_28StaticCompoundRigidBodyGroupERKN4sead8Matrix34IfEEi
+0x0000007100fcbbe4,O,000176,_ZNK4ksys4phys17StaticCompoundMgr17getExtraTransformERKPNS0_28StaticCompoundRigidBodyGroupEi
+0x0000007100fcbc94,O,000324,_ZNK4ksys4phys17StaticCompoundMgr12getRigidBodyERKPNS0_28StaticCompoundRigidBodyGroupE
+0x0000007100fcbdd8,O,000104,_ZNK4ksys4phys17StaticCompoundMgr24getBodyGroupAndMapObjectEPPNS0_28StaticCompoundRigidBodyGroupEPPNS_3map6ObjectERK22hkpStaticCompoundShapePKj
0x0000007100fcbe40,O,000168,_ZN4ksys4phys28StaticCompoundRigidBodyGroupC1Ev
0x0000007100fcbee8,O,000288,_ZN4ksys4phys28StaticCompoundRigidBodyGroupD1Ev
0x0000007100fcc008,O,001492,_ZN4ksys4phys28StaticCompoundRigidBodyGroup4initERK16hkpPhysicsSystemPN4sead8Matrix34IfEEPNS0_14StaticCompoundEPNS5_4HeapE
diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp b/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp
index 47b3620f..88853b39 100644
--- a/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp
+++ b/src/KingSystem/Physics/StaticCompound/physStaticCompound.cpp
@@ -222,7 +222,7 @@ StaticCompoundRigidBodyGroup* StaticCompound::getFieldBodyGroup(int idx) {
return &mFieldBodyGroups[idx];
}
-bool StaticCompound::hasFieldBodyGroup(StaticCompoundRigidBodyGroup* group) const {
+bool StaticCompound::hasFieldBodyGroup(const StaticCompoundRigidBodyGroup* group) const {
for (int i = 0, n = mFieldBodyGroups.size(); i < n; ++i) {
if (&mFieldBodyGroups[i] == group)
return true;
diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h
index 78c7f5cf..4c328e51 100644
--- a/src/KingSystem/Physics/StaticCompound/physStaticCompound.h
+++ b/src/KingSystem/Physics/StaticCompound/physStaticCompound.h
@@ -27,6 +27,8 @@ public:
StaticCompound();
~StaticCompound() override;
+ bool isInitialised() const { return mFlags.isOn(Flag::Initialised); }
+
bool isAnyRigidBodyAddedToWorld() const;
bool isAnyRigidBodyAddedOrBeingAddedToWorld() const;
void removeFromWorld();
@@ -45,7 +47,7 @@ public:
int getNumFieldBodyGroups() const { return mFieldBodyGroups.size(); }
StaticCompoundRigidBodyGroup* getFieldBodyGroup(int idx);
- bool hasFieldBodyGroup(StaticCompoundRigidBodyGroup* group) const;
+ bool hasFieldBodyGroup(const StaticCompoundRigidBodyGroup* group) const;
// res::Resource interface
void doCreate_(u8* buffer, u32 buffer_size, sead::Heap* parent_heap) override;
diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.cpp b/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.cpp
index f5d79b25..c16285a2 100644
--- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.cpp
+++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.cpp
@@ -1,4 +1,9 @@
#include "KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h"
+#include <Havok/Physics2012/Internal/Collide/StaticCompound/hkpStaticCompoundShape.h>
+#include <prim/seadScopedLock.h>
+#include "KingSystem/Physics/StaticCompound/physStaticCompound.h"
+#include "KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h"
+#include "KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h"
#include "KingSystem/Physics/System/physSystem.h"
namespace ksys::phys {
@@ -19,4 +24,154 @@ bool StaticCompoundMgr::init() {
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
diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h b/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h
index 5b15b9e5..ab84d282 100644
--- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h
+++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h
@@ -2,11 +2,21 @@
#include <container/seadPtrArray.h>
#include <hostio/seadHostIONode.h>
+#include <math/seadMatrix.h>
+#include <math/seadVector.h>
#include <thread/seadCriticalSection.h>
+class hkpStaticCompoundShape;
+
+namespace ksys::map {
+class Object;
+}
+
namespace ksys::phys {
+class RigidBody;
class StaticCompound;
+class StaticCompoundRigidBodyGroup;
class SystemGroupHandler;
/// Provides convenient access to all loaded StaticCompounds.
@@ -17,18 +27,43 @@ public:
bool init();
- // 0x0000007100fcb554
void addStaticCompound(StaticCompound* sc);
- // 0x0000007100fcb5e0
void removeStaticCompound(StaticCompound* sc);
+ void resetExtraTransformsAndApply();
+ StaticCompoundRigidBodyGroup* getBodyGroup(int group_index) const;
+ bool hasBodyGroup(const StaticCompoundRigidBodyGroup* group) const;
+ void processUpdates();
+ void recomputeTransformMatrix();
+
+ sead::Matrix34f getTransformedMatrix(StaticCompoundRigidBodyGroup* const& p_group,
+ const sead::Matrix34f& mtx) const;
+ sead::Matrix34f getInvTransformedMatrix(StaticCompoundRigidBodyGroup* const& p_group,
+ const sead::Matrix34f& mtx) const;
+ sead::Vector3f getTransformedPos(StaticCompoundRigidBodyGroup* const& p_group,
+ const sead::Vector3f& pos) const;
+ sead::Vector3f getRotatedDir(StaticCompoundRigidBodyGroup* const& p_group,
+ const sead::Vector3f& dir) const;
+
+ void setExtraTransform(StaticCompoundRigidBodyGroup* const& p_group,
+ const sead::Matrix34f& transform, int index);
+
+ const sead::Matrix34f& getExtraTransform(StaticCompoundRigidBodyGroup* const& p_group,
+ int index) const;
+
+ RigidBody* getRigidBody(StaticCompoundRigidBodyGroup* const& p_group) const;
+
+ void getBodyGroupAndMapObject(StaticCompoundRigidBodyGroup** p_group,
+ map::Object** p_map_object, const hkpStaticCompoundShape& shape,
+ const u32* shape_key) const;
+
SystemGroupHandler* getGroupHandler() const { return mGroupHandler; }
// TODO: more functions
private:
sead::FixedPtrArray<StaticCompound, 0x40> mStaticCompounds;
- sead::CriticalSection mCS;
+ mutable sead::CriticalSection mCS;
SystemGroupHandler* mGroupHandler{};
};
diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h b/src/KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h
index 7800c1b6..21f8df37 100644
--- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h
+++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundRigidBodyGroup.h
@@ -71,6 +71,7 @@ public:
sead::Vector3f getRotatedDir(const sead::Vector3f& dir) const;
RigidBody* getRigidBody(BodyLayerType body_layer_type) const;
+ StaticCompound* getStaticCompound() const { return mStaticCompound; }
void processUpdates();