ksys/phys: Rename Shape/Body classes to avoid confusion

What we currently call BoxBody, CapsuleBody, etc. is actually
BoxShape, CapsuleShape, etc. (those classes encapsulate Havok shapes)

So this commit renames Body -> Shape and Shape -> ShapeParam.
This commit is contained in:
Léo Lam 2022-01-30 02:08:30 +01:00
parent a1a283acf7
commit 60e2b1664f
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
8 changed files with 79 additions and 79 deletions

View File

@ -83585,21 +83585,21 @@ Address,Quality,Size,Name
0x0000007100fab688,U,000276, 0x0000007100fab688,U,000276,
0x0000007100fab79c,U,000008, 0x0000007100fab79c,U,000008,
0x0000007100fab7a4,U,000184, 0x0000007100fab7a4,U,000184,
0x0000007100fab85c,O,000332,_ZN4ksys4phys12CapsuleShape4initEPN4sead4HeapE 0x0000007100fab85c,O,000332,_ZN4ksys4phys17CapsuleShapeParam11createShapeEPN4sead4HeapE
0x0000007100fab9a8,O,000184,_ZN4ksys4phys11CapsuleBody5cloneEPN4sead4HeapE 0x0000007100fab9a8,O,000184,_ZN4ksys4phys12CapsuleShape5cloneEPN4sead4HeapE
0x0000007100faba60,O,000008,_ZNK4ksys4phys11CapsuleBody9getRadiusEv 0x0000007100faba60,O,000008,_ZNK4ksys4phys12CapsuleShape9getRadiusEv
0x0000007100faba68,O,000060,_ZNK4ksys4phys11CapsuleBody11getVerticesEPN4sead7Vector3IfEES5_ 0x0000007100faba68,O,000060,_ZNK4ksys4phys12CapsuleShape11getVerticesEPN4sead7Vector3IfEES5_
0x0000007100fabaa4,U,000032, 0x0000007100fabaa4,U,000032,
0x0000007100fabac4,O,000064,_ZN4ksys4phys11CapsuleBodyD1Ev 0x0000007100fabac4,O,000064,_ZN4ksys4phys12CapsuleShapeD1Ev
0x0000007100fabb04,O,000072,_ZN4ksys4phys11CapsuleBodyD0Ev 0x0000007100fabb04,O,000072,_ZN4ksys4phys12CapsuleShapeD0Ev
0x0000007100fabb4c,O,000060,_ZN4ksys4phys11CapsuleBody9setRadiusEf 0x0000007100fabb4c,O,000060,_ZN4ksys4phys12CapsuleShape9setRadiusEf
0x0000007100fabb88,O,000192,_ZN4ksys4phys11CapsuleBody11setVerticesERKN4sead7Vector3IfEES6_ 0x0000007100fabb88,O,000192,_ZN4ksys4phys12CapsuleShape11setVerticesERKN4sead7Vector3IfEES6_
0x0000007100fabc48,O,000140,_ZNK4ksys4phys11CapsuleBody9getVolumeEv 0x0000007100fabc48,O,000140,_ZNK4ksys4phys12CapsuleShape9getVolumeEv
0x0000007100fabcd4,O,000008,_ZN4ksys4phys11CapsuleBody8getShapeEv 0x0000007100fabcd4,O,000008,_ZN4ksys4phys12CapsuleShape8getShapeEv
0x0000007100fabcdc,O,000008,_ZNK4ksys4phys11CapsuleBody8getShapeEv 0x0000007100fabcdc,O,000008,_ZNK4ksys4phys12CapsuleShape8getShapeEv
0x0000007100fabce4,U,000252, 0x0000007100fabce4,U,000252,
0x0000007100fabde0,U,000160, 0x0000007100fabde0,U,000160,
0x0000007100fabe80,O,000192,_ZN4ksys4phys11CapsuleBody14sub_7100FABE80EPN4sead7Vector3IfEES5_RK12hkTransformf 0x0000007100fabe80,O,000192,_ZN4ksys4phys12CapsuleShape14sub_7100FABE80EPN4sead7Vector3IfEES5_RK12hkTransformf
0x0000007100fabf40,U,000204, 0x0000007100fabf40,U,000204,
0x0000007100fac00c,U,000092, 0x0000007100fac00c,U,000092,
0x0000007100fac068,U,000008, 0x0000007100fac068,U,000008,

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

View File

@ -7,14 +7,14 @@ namespace ksys::phys {
class BoxParam; class BoxParam;
struct BoxBody { struct BoxShape {
virtual ~BoxBody(); virtual ~BoxShape();
RigidBody* init(u32 flag, RigidBodyInstanceParam* params, sead::Heap* heap); RigidBody* createBody(u32 flag, const RigidBodyInstanceParam& params, sead::Heap* heap);
}; };
struct BoxShape { struct BoxShapeParam {
BoxBody* init(sead::Heap* heap); BoxShape* createShape(sead::Heap* heap);
}; };
class BoxParam : public RigidBodyInstanceParam { class BoxParam : public RigidBodyInstanceParam {
@ -22,7 +22,7 @@ class BoxParam : public RigidBodyInstanceParam {
public: public:
u8 _90; u8 _90;
float _94; float _94;
BoxShape shape; BoxShapeParam shape;
}; };
} // namespace ksys::phys } // namespace ksys::phys

View File

@ -6,7 +6,7 @@
namespace ksys::phys { namespace ksys::phys {
CapsuleBody::CapsuleBody(const CapsuleShape& shape_, hkpShape* hkp_shape_) CapsuleShape::CapsuleShape(const CapsuleShapeParam& shape_, hkpShape* hkp_shape_)
: vertex_a(shape_.vertex_a), vertex_b(shape_.vertex_b), radius(shape_.radius), : vertex_a(shape_.vertex_a), vertex_b(shape_.vertex_b), radius(shape_.radius),
material_mask(shape_.material, shape_.sub_material, shape_.floor_code, shape_.wall_code), material_mask(shape_.material, shape_.sub_material, shape_.floor_code, shape_.wall_code),
shape(hkp_shape_) { shape(hkp_shape_) {
@ -15,13 +15,13 @@ CapsuleBody::CapsuleBody(const CapsuleShape& shape_, hkpShape* hkp_shape_)
setMaterialMask(material_mask); setMaterialMask(material_mask);
} }
void CapsuleBody::setMaterialMask(const MaterialMask& mask) { void CapsuleShape::setMaterialMask(const MaterialMask& mask) {
material_mask = mask; material_mask = mask;
if (shape) if (shape)
shape->setUserData(mask.getRawData()); shape->setUserData(mask.getRawData());
} }
CapsuleBody* CapsuleShape::init(sead::Heap* heap) { CapsuleShape* CapsuleShapeParam::createShape(sead::Heap* heap) {
void* ptr = heap->tryAlloc(sizeof(hkpCapsuleShape), 0x10); void* ptr = heap->tryAlloc(sizeof(hkpCapsuleShape), 0x10);
if (ptr == nullptr) if (ptr == nullptr)
return nullptr; return nullptr;
@ -29,41 +29,41 @@ CapsuleBody* CapsuleShape::init(sead::Heap* heap) {
auto* hk_shape = auto* hk_shape =
new (ptr) hkpCapsuleShape(hkVector4(vertex_a.x, vertex_a.y, vertex_a.z), new (ptr) hkpCapsuleShape(hkVector4(vertex_a.x, vertex_a.y, vertex_a.z),
hkVector4(vertex_b.x, vertex_b.y, vertex_b.z), radius); hkVector4(vertex_b.x, vertex_b.y, vertex_b.z), radius);
return new (heap) CapsuleBody(*this, hk_shape); return new (heap) CapsuleShape(*this, hk_shape);
} }
CapsuleBody* CapsuleBody::clone(sead::Heap* heap) { CapsuleShape* CapsuleShape::clone(sead::Heap* heap) {
CapsuleShape shape; CapsuleShapeParam param_clone;
shape.radius = radius; param_clone.radius = radius;
shape.vertex_a = vertex_a; param_clone.vertex_a = vertex_a;
shape.vertex_b = vertex_b; param_clone.vertex_b = vertex_b;
CapsuleBody* body = shape.init(heap); CapsuleShape* cloned = param_clone.createShape(heap);
body->material_mask = material_mask; cloned->material_mask = material_mask;
if (body->shape != nullptr) if (cloned->shape != nullptr)
body->shape->setUserData(material_mask.getRawData()); cloned->shape->setUserData(material_mask.getRawData());
return body; return cloned;
} }
f32 CapsuleBody::getRadius() const { f32 CapsuleShape::getRadius() const {
return radius; return radius;
} }
void CapsuleBody::getVertices(sead::Vector3f* va, sead::Vector3f* vb) const { void CapsuleShape::getVertices(sead::Vector3f* va, sead::Vector3f* vb) const {
if (va != nullptr) if (va != nullptr)
*va = vertex_a; *va = vertex_a;
if (vb != nullptr) if (vb != nullptr)
*vb = vertex_b; *vb = vertex_b;
} }
CapsuleBody::~CapsuleBody() { CapsuleShape::~CapsuleShape() {
if (shape != nullptr) { if (shape != nullptr) {
::operator delete(shape); ::operator delete(shape);
shape = nullptr; shape = nullptr;
} }
} }
bool CapsuleBody::setRadius(f32 r) { bool CapsuleShape::setRadius(f32 r) {
if (r == radius || r <= 0.0f) { if (r == radius || r <= 0.0f) {
return false; return false;
} }
@ -72,7 +72,7 @@ bool CapsuleBody::setRadius(f32 r) {
return true; return true;
} }
bool CapsuleBody::setVertices(const sead::Vector3f& va, const sead::Vector3f& vb) { bool CapsuleShape::setVertices(const sead::Vector3f& va, const sead::Vector3f& vb) {
if (vertex_a == va && vertex_b == vb) { if (vertex_a == va && vertex_b == vb) {
return false; return false;
} }
@ -82,21 +82,21 @@ bool CapsuleBody::setVertices(const sead::Vector3f& va, const sead::Vector3f& vb
return true; return true;
} }
f32 CapsuleBody::getVolume() const { f32 CapsuleShape::getVolume() const {
f32 dist = (vertex_a - vertex_b).length(); f32 dist = (vertex_a - vertex_b).length();
return sead::Mathf::pi() * radius * radius * (dist + radius * 4.0f / 3.0f); return sead::Mathf::pi() * radius * radius * (dist + radius * 4.0f / 3.0f);
} }
hkpShape* CapsuleBody::getShape() { hkpShape* CapsuleShape::getShape() {
return shape; return shape;
} }
const hkpShape* CapsuleBody::getShape() const { const hkpShape* CapsuleShape::getShape() const {
return shape; return shape;
} }
void CapsuleBody::sub_7100FABE80(sead::Vector3f* veca, sead::Vector3f* vecb, void CapsuleShape::sub_7100FABE80(sead::Vector3f* veca, sead::Vector3f* vecb,
const hkTransformf& rb_vec) { const hkTransformf& rb_vec) {
if (veca != nullptr) { if (veca != nullptr) {
hkVector4 tmp; hkVector4 tmp;
tmp.setTransformedPos(rb_vec, toHkVec4(vertex_a)); tmp.setTransformedPos(rb_vec, toHkVec4(vertex_a));

View File

@ -14,10 +14,10 @@ class hkpShape;
namespace ksys::phys { namespace ksys::phys {
class CapsuleParam; class CapsuleParam;
struct CapsuleBody; struct CapsuleShape;
struct CapsuleShape { struct CapsuleShapeParam {
CapsuleBody* init(sead::Heap* heap); CapsuleShape* createShape(sead::Heap* heap);
sead::Vector3f vertex_a; sead::Vector3f vertex_a;
sead::Vector3f vertex_b; sead::Vector3f vertex_b;
@ -30,21 +30,21 @@ struct CapsuleShape {
bool _38 = false; bool _38 = false;
}; };
struct CapsuleBody { struct CapsuleShape {
enum class Flag { enum class Flag {
Modified = 1 << 0, Modified = 1 << 0,
}; };
CapsuleBody(const CapsuleShape& shape_, hkpShape* hkp_shape_); CapsuleShape(const CapsuleShapeParam& shape_, hkpShape* hkp_shape_);
virtual ~CapsuleBody(); virtual ~CapsuleShape();
virtual hkpShape* getShape(); virtual hkpShape* getShape();
virtual const hkpShape* getShape() const; virtual const hkpShape* getShape() const;
virtual void updateChanges(); virtual void updateChanges();
virtual void scaleVerts(f32 scale); virtual void scaleVerts(f32 scale);
RigidBody* init(u32 flag, RigidBodyInstanceParam* params, sead::Heap* heap); RigidBody* createBody(u32 flag, const RigidBodyInstanceParam& params, sead::Heap* heap);
CapsuleBody* clone(sead::Heap* heap); CapsuleShape* clone(sead::Heap* heap);
f32 getRadius() const; f32 getRadius() const;
void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const; void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const;
bool setRadius(f32 r); bool setRadius(f32 r);
@ -66,7 +66,7 @@ class CapsuleParam : public RigidBodyInstanceParam {
public: public:
u8 _90; u8 _90;
float _94; float _94;
CapsuleShape shape; CapsuleShapeParam shape;
}; };
} // namespace ksys::phys } // namespace ksys::phys

View File

@ -7,14 +7,14 @@ namespace ksys::phys {
class CylinderParam; class CylinderParam;
struct CylinderBody { struct CylinderShape {
virtual ~CylinderBody(); virtual ~CylinderShape();
RigidBody* init(u32 flag, RigidBodyInstanceParam* params, sead::Heap* heap); RigidBody* createBody(u32 flag, const RigidBodyInstanceParam& params, sead::Heap* heap);
}; };
struct CylinderShape { struct CylinderShapeParam {
CylinderBody* init(sead::Heap* heap); CylinderShape* createShape(sead::Heap* heap);
}; };
class CylinderParam : public RigidBodyInstanceParam { class CylinderParam : public RigidBodyInstanceParam {
@ -22,7 +22,7 @@ class CylinderParam : public RigidBodyInstanceParam {
public: public:
u8 _90; u8 _90;
float _94; float _94;
CylinderShape shape; CylinderShapeParam shape;
}; };
} // namespace ksys::phys } // namespace ksys::phys

View File

@ -7,14 +7,14 @@ namespace ksys::phys {
class SphereParam; class SphereParam;
struct SphereBody { struct SphereShape {
virtual ~SphereBody(); virtual ~SphereShape();
RigidBody* init(u32 flag, RigidBodyInstanceParam* params, sead::Heap* heap); RigidBody* createBody(u32 flag, const RigidBodyInstanceParam& params, sead::Heap* heap);
}; };
struct SphereShape { struct SphereShapeParam {
SphereBody* init(sead::Heap* heap); SphereShape* createShape(sead::Heap* heap);
}; };
class SphereParam : public RigidBodyInstanceParam { class SphereParam : public RigidBodyInstanceParam {
@ -22,7 +22,7 @@ class SphereParam : public RigidBodyInstanceParam {
public: public:
u8 _90; u8 _90;
float _94; float _94;
SphereShape shape; SphereShapeParam shape;
}; };
} // namespace ksys::phys } // namespace ksys::phys

View File

@ -7,14 +7,14 @@ namespace ksys::phys {
class WaterCylinderParam; class WaterCylinderParam;
struct WaterCylinderBody { struct WaterCylinderShape {
virtual ~WaterCylinderBody(); virtual ~WaterCylinderShape();
RigidBody* init(u32 flag, RigidBodyInstanceParam* params, sead::Heap* heap); RigidBody* createBody(u32 flag, const RigidBodyInstanceParam& params, sead::Heap* heap);
}; };
struct WaterCylinderShape { struct WaterCylinderShapeParam {
WaterCylinderBody* init(sead::Heap* heap); WaterCylinderShape* createShape(sead::Heap* heap);
}; };
class WaterCylinderParam : public RigidBodyInstanceParam { class WaterCylinderParam : public RigidBodyInstanceParam {
@ -22,7 +22,7 @@ class WaterCylinderParam : public RigidBodyInstanceParam {
public: public:
u8 _90; u8 _90;
float _94; float _94;
WaterCylinderShape shape; WaterCylinderShapeParam shape;
}; };
} // namespace ksys::phys } // namespace ksys::phys

View File

@ -13,8 +13,8 @@ RigidBody* RigidBodyFactory::createSphere(RigidBodyInstanceParam* params, sead::
params->motion_type = MotionType::Keyframed; params->motion_type = MotionType::Keyframed;
auto* v = sead::DynamicCast<SphereParam>(params); auto* v = sead::DynamicCast<SphereParam>(params);
SphereBody* body = v->shape.init(heap); auto* shape = v->shape.createShape(heap);
return body->init(1, params, heap); return shape->createBody(1, *params, heap);
} }
RigidBody* RigidBodyFactory::createCapsule(RigidBodyInstanceParam* params, sead::Heap* heap) { RigidBody* RigidBodyFactory::createCapsule(RigidBodyInstanceParam* params, sead::Heap* heap) {
@ -22,8 +22,8 @@ RigidBody* RigidBodyFactory::createCapsule(RigidBodyInstanceParam* params, sead:
params->motion_type = MotionType::Keyframed; params->motion_type = MotionType::Keyframed;
auto* v = sead::DynamicCast<CapsuleParam>(params); auto* v = sead::DynamicCast<CapsuleParam>(params);
CapsuleBody* body = v->shape.init(heap); auto* shape = v->shape.createShape(heap);
return body->init(1, params, heap); return shape->createBody(1, *params, heap);
} }
RigidBody* RigidBodyFactory::createCylinder(RigidBodyInstanceParam* params, sead::Heap* heap) { RigidBody* RigidBodyFactory::createCylinder(RigidBodyInstanceParam* params, sead::Heap* heap) {
@ -31,8 +31,8 @@ RigidBody* RigidBodyFactory::createCylinder(RigidBodyInstanceParam* params, sead
params->motion_type = MotionType::Keyframed; params->motion_type = MotionType::Keyframed;
auto* v = sead::DynamicCast<CylinderParam>(params); auto* v = sead::DynamicCast<CylinderParam>(params);
CylinderBody* body = v->shape.init(heap); auto* shape = v->shape.createShape(heap);
return body->init(1, params, heap); return shape->createBody(1, *params, heap);
} }
RigidBody* RigidBodyFactory::createWaterCylinder(RigidBodyInstanceParam* params, sead::Heap* heap) { RigidBody* RigidBodyFactory::createWaterCylinder(RigidBodyInstanceParam* params, sead::Heap* heap) {
@ -40,8 +40,8 @@ RigidBody* RigidBodyFactory::createWaterCylinder(RigidBodyInstanceParam* params,
params->motion_type = MotionType::Keyframed; params->motion_type = MotionType::Keyframed;
auto* v = sead::DynamicCast<WaterCylinderParam>(params); auto* v = sead::DynamicCast<WaterCylinderParam>(params);
WaterCylinderBody* body = v->shape.init(heap); auto* body = v->shape.createShape(heap);
return body->init(1, params, heap); return body->createBody(1, *params, heap);
} }
RigidBody* RigidBodyFactory::createBox(RigidBodyInstanceParam* params, sead::Heap* heap) { RigidBody* RigidBodyFactory::createBox(RigidBodyInstanceParam* params, sead::Heap* heap) {
@ -49,8 +49,8 @@ RigidBody* RigidBodyFactory::createBox(RigidBodyInstanceParam* params, sead::Hea
params->motion_type = MotionType::Keyframed; params->motion_type = MotionType::Keyframed;
auto* v = sead::DynamicCast<BoxParam>(params); auto* v = sead::DynamicCast<BoxParam>(params);
BoxBody* body = v->shape.init(heap); auto* body = v->shape.createShape(heap);
return body->init(1, params, heap); return body->createBody(1, *params, heap);
} }
} // namespace ksys::phys } // namespace ksys::phys