ksys/phys: Add more StaticCompound stuff, part 1

This commit is contained in:
Léo Lam 2022-03-21 23:51:40 +01:00
parent 7ca13b5938
commit c97cf995ef
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
8 changed files with 191 additions and 18 deletions

View File

@ -84236,10 +84236,10 @@ Address,Quality,Size,Name
0x0000007100fcb1ec,O,000048,_ZNK4ksys4phys18StaticCompoundInfo12getShapeInfoEi
0x0000007100fcb21c,O,000120,_ZN4ksys4phys16getBodyLayerTypeENS0_12ContactLayerE
0x0000007100fcb294,O,000396,_GLOBAL__sub_I_physStaticCompoundAutogen.cpp
0x0000007100fcb420,U,000080,
0x0000007100fcb470,U,000076,
0x0000007100fcb4bc,U,000084,
0x0000007100fcb510,U,000068,
0x0000007100fcb420,O,000080,_ZN4ksys4phys17StaticCompoundMgrC1Ev
0x0000007100fcb470,O,000076,_ZN4ksys4phys17StaticCompoundMgrD1Ev
0x0000007100fcb4bc,O,000084,_ZN4ksys4phys17StaticCompoundMgrD0Ev
0x0000007100fcb510,O,000068,_ZN4ksys4phys17StaticCompoundMgr4initEv
0x0000007100fcb554,U,000140,
0x0000007100fcb5e0,U,000120,
0x0000007100fcb658,U,000124,
@ -84255,8 +84255,8 @@ Address,Quality,Size,Name
0x0000007100fcbc94,U,000324,
0x0000007100fcbdd8,U,000104,
0x0000007100fcbe40,O,000168,_ZN4ksys4phys9BodyGroupC1Ev
0x0000007100fcbee8,U,000288,BodyGroup::dtor
0x0000007100fcc008,U,001492,FieldBodyGroup::init
0x0000007100fcbee8,O,000288,_ZN4ksys4phys9BodyGroupD1Ev
0x0000007100fcc008,O,001492,_ZN4ksys4phys9BodyGroup4initERK16hkpPhysicsSystemPN4sead8Matrix34IfEEPNS0_14StaticCompoundEPNS5_4HeapE
0x0000007100fcc5dc,U,000120,BodyGroup::x
0x0000007100fcc654,U,000120,BodyGroup::x_0
0x0000007100fcc6cc,U,000248,BodyGroup::x_1
@ -84269,7 +84269,7 @@ Address,Quality,Size,Name
0x0000007100fccc7c,U,000312,BodyGroup::x_8
0x0000007100fccdb4,U,000944,BodyGroup::x_9
0x0000007100fcd164,U,000244,BodyGroup::x_10
0x0000007100fcd258,U,000288,BodyGroup::x_11
0x0000007100fcd258,O,000288,_ZN4ksys4phys9BodyGroup12modifyMatrixERKN4sead8Matrix34IfEEi
0x0000007100fcd378,U,000028,BodyGroup::x_12
0x0000007100fcd394,U,000144,BodyGroup::x_16
0x0000007100fcd424,U,000164,BodyGroup::x_13

Can't render this file because it is too large.

View File

@ -96,6 +96,8 @@ target_sources(uking PRIVATE
StaticCompound/physStaticCompoundBodyGroup.h
StaticCompound/physStaticCompoundInfo.cpp
StaticCompound/physStaticCompoundInfo.h
StaticCompound/physStaticCompoundMgr.cpp
StaticCompound/physStaticCompoundMgr.h
StaticCompound/physStaticCompoundUtil.cpp
StaticCompound/physStaticCompoundUtil.h

View File

@ -59,7 +59,7 @@ public:
_1 = 1,
_2 = 2,
TerrainHeightField = 3,
_4 = 4,
StaticCompoundBody = 4,
CharacterController = 5,
TeraMesh = 6,
};

View File

@ -1,7 +1,104 @@
#include "KingSystem/Physics/StaticCompound/physStaticCompoundBodyGroup.h"
#include <Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h>
#include <Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h>
#include "KingSystem/Physics/RigidBody/physRigidBodyFromResource.h"
#include "KingSystem/Physics/RigidBody/physRigidBodyParam.h"
#include "KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h"
#include "KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h"
#include "KingSystem/Physics/System/physSystem.h"
namespace ksys::phys {
// TODO: rename
constexpr int BodyGroupNumMatrices = 8;
BodyGroup::BodyGroup() = default;
BodyGroup::~BodyGroup() {
mFlags.reset(Flag::Initialised);
for (int i = 0, n = mRigidBodiesPerBodyLayerType.size(); i < n; ++i) {
delete mRigidBodiesPerBodyLayerType[i];
}
mRigidBodiesPerBodyLayerType.freeBuffer();
mShapesPerBodyLayerType.freeBuffer();
mMatrices2.freeBuffer();
mMatrices.freeBuffer();
_e8.freeBuffer();
mRigidBodies.freeBuffer();
}
void BodyGroup::init(const hkpPhysicsSystem& system, sead::Matrix34f* mtx, StaticCompound* sc,
sead::Heap* heap) {
mStaticCompound = sc;
mMtxPtr = mtx;
const int num_rigid_bodies = system.getRigidBodies().getSize();
mRigidBodies.allocBuffer(num_rigid_bodies + NumBodyLayerTypes, heap);
if (num_rigid_bodies > 0) {
auto* group_handler = System::instance()->getStaticCompoundMgr()->getGroupHandler();
mRigidBodiesPerBodyLayerType.allocBufferAssert(NumBodyLayerTypes, heap);
mShapesPerBodyLayerType.allocBufferAssert(NumBodyLayerTypes, heap);
for (int i = 0; i < NumBodyLayerTypes; ++i) {
mRigidBodiesPerBodyLayerType[i] = nullptr;
mShapesPerBodyLayerType[i] = nullptr;
}
for (int i = 0; i < num_rigid_bodies; ++i) {
hkpRigidBody* hk_body = system.getRigidBodies()[i];
bool is_entity = sead::SafeString(hk_body->getName()).include("Entity");
auto layer_type = is_entity ? ContactLayerType::Entity : ContactLayerType::Sensor;
auto* body = new (heap) RigidBodyFromResource(0.0, hk_body, layer_type, heap,
RigidBody::Type::StaticCompoundBody);
RigidBodyInstanceParam param;
param.max_linear_velocity = 1000;
body->initMotionAccessor(param, heap, /* init_motion */ false);
BodyLayerType body_layer_type = getBodyLayerType(body->getContactLayer());
mRigidBodiesPerBodyLayerType[int(body_layer_type)] = body;
body->updateCollidableQualityType(true);
body->changeMotionType(MotionType::Fixed);
if (body->isEntity()) {
body->setSystemGroupHandler(group_handler);
body->enableGroundCollision(false);
body->enableWaterCollision(false);
}
mRigidBodies.pushBack(body);
// XXX: eww, const_cast
auto* shape =
const_cast<hkpShape*>(system.getRigidBodies()[i]->getCollidable()->getShape());
shape->m_userData = reinterpret_cast<hkUlong>(this);
mShapesPerBodyLayerType[int(body_layer_type)] = shape;
}
}
mMatrices2.allocBufferAssert(BodyGroupNumMatrices, heap);
mMatrices.allocBufferAssert(BodyGroupNumMatrices, heap);
for (int i = 0, n = mMatrices2.size(); i < n; ++i) {
mMatrices2[i].makeIdentity();
mMatrices[i].makeIdentity();
}
mFlags.set(Flag::Initialised);
}
void BodyGroup::modifyMatrix(const sead::Matrix34f& matrix, int index) {
if (mMatrices[index] == matrix)
return;
mMatrices[index] = matrix;
mModifiedMatrices |= 1 << index;
mFlags.set(Flag::HasModifiedMatrix);
}
} // namespace ksys::phys

View File

@ -5,10 +5,12 @@
#include <container/seadPtrArray.h>
#include <math/seadMatrix.h>
#include <math/seadVector.h>
#include <prim/seadTypedBitFlag.h>
#include <thread/seadAtomic.h>
#include "KingSystem/Utils/Types.h"
class hkpPhysicsSystem;
class hkpShape;
namespace ksys::phys {
@ -29,12 +31,27 @@ public:
void disableCollision(BodyLayerType body_layer_type, int instance_id, bool x);
sead::Atomic<u32> _0;
sead::Atomic<u32> _4;
sead::Buffer<void*> _8;
sead::Buffer<void*> _18;
sead::Buffer<void*> _28;
sead::Buffer<void*> _38;
void modifyMatrix(const sead::Matrix34f& matrix, int index);
private:
enum class Flag {
Initialised = 1 << 0,
HasModifiedMatrix = 1 << 3,
};
struct Unk1 {
virtual ~Unk1();
u8 _8[0xc0];
};
sead::TypedBitFlag<Flag, sead::Atomic<u32>> mFlags;
sead::Atomic<u32> mModifiedMatrices;
sead::Buffer<RigidBody*> mRigidBodiesPerBodyLayerType;
sead::Buffer<const hkpShape*> mShapesPerBodyLayerType;
// TODO: rename
sead::Buffer<sead::Matrix34f> mMatrices;
sead::Buffer<sead::Matrix34f> mMatrices2;
sead::Matrix34f mMtx0 = sead::Matrix34f::ident;
sead::Matrix34f mMtx1 = sead::Matrix34f::ident;
sead::Matrix34f* mMtxPtr{};
@ -43,7 +60,7 @@ public:
sead::Vector3f _c8 = sead::Vector3f::zero;
sead::Vector3f _d4 = sead::Vector3f::zero;
u32 _e0{};
sead::Buffer<void*> _e8;
sead::Buffer<Unk1> _e8;
};
KSYS_CHECK_SIZE_NX150(BodyGroup, 0xf8);

View File

@ -0,0 +1,22 @@
#include "KingSystem/Physics/StaticCompound/physStaticCompoundMgr.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;
}
} // namespace ksys::phys

View File

@ -0,0 +1,30 @@
#pragma once
#include <container/seadPtrArray.h>
#include <hostio/seadHostIONode.h>
#include <thread/seadCriticalSection.h>
namespace ksys::phys {
class StaticCompound;
class SystemGroupHandler;
/// Provides convenient access to all loaded StaticCompounds.
class StaticCompoundMgr : public sead::hostio::Node {
public:
StaticCompoundMgr();
virtual ~StaticCompoundMgr();
bool init();
SystemGroupHandler* getGroupHandler() const { return mGroupHandler; }
// TODO: more functions
private:
sead::FixedPtrArray<StaticCompound, 0x40> mStaticCompounds;
sead::CriticalSection mCS;
SystemGroupHandler* mGroupHandler{};
};
} // namespace ksys::phys

View File

@ -15,13 +15,14 @@ class CollisionInfo;
class ContactLayerCollisionInfo;
class ContactLayerCollisionInfoGroup;
class ContactMgr;
class ContactPointInfo;
class GroupFilter;
class LayerContactPointInfo;
class MaterialTable;
class RayCastForRequest;
class RigidBody;
class RigidBodyRequestMgr;
class ContactPointInfo;
class LayerContactPointInfo;
class StaticCompoundMgr;
class SystemData;
class SystemGroupHandler;
@ -42,6 +43,7 @@ public:
float get64() const { return _64; }
float getTimeFactor() const { return mTimeFactor; }
ContactMgr* getContactMgr() const { return mContactMgr; }
StaticCompoundMgr* getStaticCompoundMgr() const { return mStaticCompoundMgr; }
RigidBodyRequestMgr* getRigidBodyRequestMgr() const { return mRigidBodyRequestMgr; }
SystemData* getSystemData() const { return mSystemData; }
MaterialTable* getMaterialTable() const { return mMaterialTable; }
@ -83,6 +85,9 @@ public:
// 0x0000007101216a20
void removeRigidBodyFromContactSystem(RigidBody* body);
// 0x000000710121686c
SystemGroupHandler* addSystemGroupHandler(ContactLayerType layer_type, int free_list_idx = 0);
// 0x0000007101215b68
void removeSystemGroupHandler(SystemGroupHandler* handler);
hkpWorld* getHavokWorld(ContactLayerType type) const;
@ -138,7 +143,7 @@ private:
sead::FixedPtrArray<void*, 2> _128;
ContactMgr* mContactMgr;
void* _150;
void* _158;
StaticCompoundMgr* mStaticCompoundMgr;
RigidBodyRequestMgr* mRigidBodyRequestMgr;
void* _168;
void* mRigidBodyDividedMeshShapeMgr;