summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2022-02-12 17:00:47 +0100
committerLéo Lam <leo@leolam.fr>2022-02-12 17:04:00 +0100
commit2dc8daf02f9c254698537538cb5fa2a87203c150 (patch)
tree078864d03bd26ba639c0e8925cac3dda284558a5 /src
parentbc66305e3d8c537f446dde96d607e63f5e4d3f2e (diff)
ksys/phys: Implement ListShapeRigidBody
Diffstat (limited to 'src')
-rw-r--r--src/KingSystem/Physics/RigidBody/Shape/List/physListShape.h1
-rw-r--r--src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.cpp80
-rw-r--r--src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h54
-rw-r--r--src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp5
-rw-r--r--src/KingSystem/Physics/RigidBody/physRigidBodyFactory.h3
5 files changed, 141 insertions, 2 deletions
diff --git a/src/KingSystem/Physics/RigidBody/Shape/List/physListShape.h b/src/KingSystem/Physics/RigidBody/Shape/List/physListShape.h
index eb66a258..cdeecb5d 100644
--- a/src/KingSystem/Physics/RigidBody/Shape/List/physListShape.h
+++ b/src/KingSystem/Physics/RigidBody/Shape/List/physListShape.h
@@ -100,7 +100,6 @@ private:
class ListShapeRigidBodyParam : public RigidBodyInstanceParam {
SEAD_RTTI_OVERRIDE(ListShapeRigidBodyParam, RigidBodyInstanceParam)
public:
- u8 _90;
ListShapeParam shape;
};
diff --git a/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.cpp b/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.cpp
index 8dff51a3..6e9a5969 100644
--- a/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.cpp
+++ b/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.cpp
@@ -1 +1,81 @@
#include "KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h"
+#include "KingSystem/Physics/RigidBody/Shape/List/physListShape.h"
+#include "KingSystem/Physics/RigidBody/physRigidBodyFactory.h"
+#include "KingSystem/Utils/SafeDelete.h"
+
+namespace ksys::phys {
+
+ListShapeRigidBody* ListShapeRigidBody::make(RigidBodyInstanceParam* param, sead::Heap* heap) {
+ return RigidBodyFactory::createList(param, heap);
+}
+
+ListShapeRigidBody::ListShapeRigidBody(hkpRigidBody* hk_body, ListShape* shape,
+ ContactLayerType layer_type, const sead::SafeString& name,
+ bool set_flag_10, sead::Heap* heap)
+ : RigidBodyFromShape(hk_body, layer_type, name, set_flag_10, heap), mShape(shape) {}
+
+ListShapeRigidBody::~ListShapeRigidBody() {
+ if (hasFlag(RigidBody::Flag::_10) && mShape) {
+ util::safeDelete(mShape);
+ }
+}
+
+Shape* ListShapeRigidBody::replaceWithNewSphere(int index, const SphereShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewSphere(index, param, heap);
+}
+
+Shape* ListShapeRigidBody::replaceWithNewCapsule(int index, const CapsuleShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewCapsule(index, param, heap);
+}
+
+Shape* ListShapeRigidBody::replaceWithNewCylinder(int index, const CylinderShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewCylinder(index, param, heap);
+}
+
+Shape* ListShapeRigidBody::replaceWithNewBox(int index, const BoxShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewBox(index, param, heap);
+}
+
+Shape* ListShapeRigidBody::replaceWithNewPolytope(int index, const PolytopeShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewPolytope(index, param, heap);
+}
+
+Shape* ListShapeRigidBody::replaceWithNewCharacterPrism(int index,
+ const CharacterPrismShapeParam& param,
+ sead::Heap* heap) {
+ return mShape->replaceWithNewCharacterPrism(index, param, heap);
+}
+
+void ListShapeRigidBody::setMaterialMask(const MaterialMask& mask, int index) {
+ mShape->setMaterialMask(mask, index);
+}
+
+const MaterialMask& ListShapeRigidBody::getMaterialMask(int index) const {
+ return mShape->getMaterialMask(index);
+}
+
+float ListShapeRigidBody::getVolume() {
+ return mShape->getVolume();
+}
+
+Shape* ListShapeRigidBody::getShape_() {
+ return mShape;
+}
+
+const Shape* ListShapeRigidBody::getShape_() const {
+ return mShape;
+}
+
+u32 ListShapeRigidBody::getCollisionMasks(RigidBody::CollisionMasks* masks, const u32* unk) {
+ masks->ignored_layers = ~mContactMask;
+ masks->collision_filter_info = getCollisionFilterInfo();
+ masks->material_mask = getMaterialMask(unk != nullptr ? int(*unk) : 0).getRawData();
+ return 0;
+}
+
+} // namespace ksys::phys
diff --git a/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h b/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h
index 6b61a7d4..dad7141f 100644
--- a/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h
+++ b/src/KingSystem/Physics/RigidBody/Shape/List/physListShapeRigidBody.h
@@ -4,10 +4,64 @@
namespace ksys::phys {
+struct BoxShapeParam;
+struct CapsuleShapeParam;
+struct CharacterPrismShapeParam;
+struct CylinderShapeParam;
+struct PolytopeShapeParam;
+struct SphereShapeParam;
+
+class ListShape;
+
class ListShapeRigidBody : public RigidBodyFromShape {
SEAD_RTTI_OVERRIDE(ListShapeRigidBody, RigidBodyFromShape)
public:
static ListShapeRigidBody* make(RigidBodyInstanceParam* param, sead::Heap* heap);
+
+ ListShapeRigidBody(hkpRigidBody* hk_body, ListShape* shape, ContactLayerType layer_type,
+ const sead::SafeString& name, bool set_flag_10, sead::Heap* heap);
+ ~ListShapeRigidBody() override;
+
+ /// Replace the shape at the specified index with a new sphere shape.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewSphere(int index, const SphereShapeParam& param, sead::Heap* heap);
+
+ /// Replace the shape at the specified index with a new capsule shape.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewCapsule(int index, const CapsuleShapeParam& param, sead::Heap* heap);
+
+ /// Replace the shape at the specified index with a new cylinder shape.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewCylinder(int index, const CylinderShapeParam& param, sead::Heap* heap);
+
+ /// Replace the shape at the specified index with a new box shape.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewBox(int index, const BoxShapeParam& param, sead::Heap* heap);
+
+ /// Replace the shape at the specified index with a new polytope shape.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewPolytope(int index, const PolytopeShapeParam& param, sead::Heap* heap);
+
+ /// Replace the shape at the specified index with a new character prism.
+ /// The shape that is being replaced will be deleted.
+ Shape* replaceWithNewCharacterPrism(int index, const CharacterPrismShapeParam& param,
+ sead::Heap* heap);
+
+ /// Set the material mask for the shape at the specified index.
+ void setMaterialMask(const MaterialMask& mask, int index);
+
+ /// Get the material mask for the shape at the specified index.
+ const MaterialMask& getMaterialMask(int index) const;
+
+ float getVolume() override;
+
+protected:
+ Shape* getShape_() override;
+ const Shape* getShape_() const override;
+ u32 getCollisionMasks(RigidBody::CollisionMasks* masks, const u32* unk) override;
+
+private:
+ ListShape* mShape{};
};
} // namespace ksys::phys
diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp
index f66707dd..0e98c947 100644
--- a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp
+++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp
@@ -7,6 +7,7 @@
#include "KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h"
#include "KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterRigidBody.h"
#include "KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterShape.h"
+#include "KingSystem/Physics/RigidBody/Shape/List/physListShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Sphere/physSphereShape.h"
#include "KingSystem/Physics/RigidBody/physRigidBodyFromShape.h"
@@ -56,4 +57,8 @@ PolytopeRigidBody* RigidBodyFactory::createPolytope(RigidBodyInstanceParam* para
return createRigidBody<PolytopeRigidBody, PolytopeShape, PolytopeParam>(params, heap);
}
+ListShapeRigidBody* RigidBodyFactory::createList(RigidBodyInstanceParam* params, sead::Heap* heap) {
+ return createRigidBody<ListShapeRigidBody, ListShape, ListShapeRigidBodyParam>(params, heap);
+}
+
} // namespace ksys::phys
diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.h b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.h
index 246bed89..d8207ec7 100644
--- a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.h
+++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.h
@@ -13,6 +13,7 @@ class BoxWaterRigidBody;
class CapsuleRigidBody;
class CylinderRigidBody;
class CylinderWaterRigidBody;
+class ListShapeRigidBody;
class PolytopeRigidBody;
class RigidBody;
struct RigidBodyInstanceParam;
@@ -28,7 +29,7 @@ public:
static BoxRigidBody* createBox(RigidBodyInstanceParam* params, sead::Heap* heap);
static BoxWaterRigidBody* createBoxWater(RigidBodyInstanceParam* params, sead::Heap* heap);
static PolytopeRigidBody* createPolytope(RigidBodyInstanceParam* params, sead::Heap* heap);
- static RigidBody* createCollection(RigidBodyInstanceParam* params, sead::Heap* heap);
+ static ListShapeRigidBody* createList(RigidBodyInstanceParam* params, sead::Heap* heap);
};
} // namespace ksys::phys