ksys/phys: Match CapsuleShape::init

This commit is contained in:
Léo Lam 2022-01-04 02:08:38 +01:00
parent 7791352833
commit 6511ecd711
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 62 additions and 50 deletions

View File

@ -83569,7 +83569,7 @@ Address,Quality,Size,Name
0x0000007100fab688,U,000276,
0x0000007100fab79c,U,000008,
0x0000007100fab7a4,U,000184,
0x0000007100fab85c,W,000332,_ZN4ksys4phys12CapsuleShape4initEPN4sead4HeapE
0x0000007100fab85c,O,000332,_ZN4ksys4phys12CapsuleShape4initEPN4sead4HeapE
0x0000007100fab9a8,O,000184,_ZN4ksys4phys11CapsuleBody5cloneEPN4sead4HeapE
0x0000007100faba60,O,000008,_ZNK4ksys4phys11CapsuleBody9getRadiusEv
0x0000007100faba68,O,000060,_ZNK4ksys4phys11CapsuleBody11getVerticesEPN4sead7Vector3IfEES5_

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

View File

@ -5,6 +5,21 @@
namespace ksys::phys {
CapsuleBody::CapsuleBody(const CapsuleShape& shape_, hkpShape* hkp_shape_)
: 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),
shape(hkp_shape_) {
if (shape_._38)
material_mask.getData().setCustomFlag(MaterialMaskData::CustomFlag::_0);
setMaterialMask(material_mask);
}
void CapsuleBody::setMaterialMask(const MaterialMask& mask) {
material_mask = mask;
if (shape)
shape->setUserData(mask.getRawData());
}
CapsuleBody* CapsuleShape::init(sead::Heap* heap) {
void* ptr = heap->tryAlloc(sizeof(hkpCapsuleShape), 0x10);
if (ptr == nullptr)
@ -13,14 +28,7 @@ CapsuleBody* CapsuleShape::init(sead::Heap* heap) {
auto* hk_shape =
new (ptr) hkpCapsuleShape(hkVector4(vertex_a.x, vertex_a.y, vertex_a.z),
hkVector4(vertex_b.x, vertex_b.y, vertex_b.z), radius);
auto* body = new (heap) CapsuleBody(vertex_a, vertex_b, radius, material, sub_material,
floor_code, wall_code, hk_shape);
if (_38) {
body->material_mask.getData().flag_23 = true;
}
body->material_mask.clearSubMaterialNameCache();
hk_shape->setUserData(body->material_mask.getRawData());
return body;
return new (heap) CapsuleBody(*this, hk_shape);
}
CapsuleBody* CapsuleBody::clone(sead::Heap* heap) {

View File

@ -13,41 +13,7 @@ class hkpShape;
namespace ksys::phys {
class CapsuleView;
struct CapsuleShape;
struct CapsuleBody {
enum class Flag {
Modified = 1 << 0,
};
CapsuleBody(const sead::Vector3f& va, const sead::Vector3f& vb, f32 r, Material material,
const char* sub_material, FloorCode floor_code, WallCode wall_code,
hkpShape* shape_)
: vertex_a(va), vertex_b(vb), radius(r),
material_mask(material, sub_material, floor_code, wall_code, false), shape(shape_) {}
virtual ~CapsuleBody();
virtual hkpShape* getShape();
virtual const hkpShape* getShape() const;
virtual void updateChanges();
virtual void scaleVerts(f32 scale);
RigidBody* init(u32 flag, RigidBodyParamView* view, sead::Heap* heap);
CapsuleBody* clone(sead::Heap* heap);
f32 getRadius() const;
void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const;
bool setRadius(f32 r);
bool setVertices(const sead::Vector3f& va, const sead::Vector3f& vb);
f32 getVolume() const;
void sub_7100FABE80(sead::Vector3f* veca, sead::Vector3f* vecb, const hkVector4& rb_vec);
sead::Vector3f vertex_a;
sead::TypedBitFlag<Flag, sead::Atomic<u32>> flags{};
sead::Vector3f vertex_b;
f32 radius;
MaterialMask material_mask;
hkpShape* shape;
};
struct CapsuleBody;
struct CapsuleShape {
CapsuleBody* init(sead::Heap* heap);
@ -63,6 +29,37 @@ struct CapsuleShape {
bool _38 = false;
};
struct CapsuleBody {
enum class Flag {
Modified = 1 << 0,
};
CapsuleBody(const CapsuleShape& shape_, hkpShape* hkp_shape_);
virtual ~CapsuleBody();
virtual hkpShape* getShape();
virtual const hkpShape* getShape() const;
virtual void updateChanges();
virtual void scaleVerts(f32 scale);
RigidBody* init(u32 flag, RigidBodyParamView* view, sead::Heap* heap);
CapsuleBody* clone(sead::Heap* heap);
f32 getRadius() const;
void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const;
bool setRadius(f32 r);
bool setVertices(const sead::Vector3f& va, const sead::Vector3f& vb);
f32 getVolume() const;
void sub_7100FABE80(sead::Vector3f* veca, sead::Vector3f* vecb, const hkVector4& rb_vec);
void setMaterialMask(const MaterialMask& mask);
sead::Vector3f vertex_a;
sead::TypedBitFlag<Flag, sead::Atomic<u32>> flags{};
sead::Vector3f vertex_b;
f32 radius;
MaterialMask material_mask;
hkpShape* shape;
};
class CapsuleView : public RigidBodyParamView {
SEAD_RTTI_OVERRIDE(CapsuleView, RigidBodyParamView)
public:

View File

@ -1,6 +1,7 @@
#pragma once
#include <basis/seadTypes.h>
#include <prim/seadEnum.h>
#include <prim/seadSafeString.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Utils/BitField.h"
@ -8,6 +9,9 @@
namespace ksys::phys {
union MaterialMaskData {
// FIXME: incomplete
SEAD_ENUM(CustomFlag, _0)
constexpr explicit MaterialMaskData(u32 raw_ = 0) : raw(raw_) {}
constexpr MaterialMaskData(const MaterialMaskData&) = default;
constexpr MaterialMaskData& operator=(const MaterialMaskData& other) {
@ -28,13 +32,16 @@ union MaterialMaskData {
void setFlag() { flag = 1; }
void clearFlag() { flag = 0; }
void setCustomFlag(CustomFlag custom_flag) {
raw |= 1 << (decltype(custom_flags)::StartBit() + custom_flag);
}
u32 raw;
util::BitField<0, 6, u32> material;
util::BitField<6, 4, int, u32> sub_material;
util::BitField<10, 5, u32> floor;
util::BitField<15, 5, u32> wall;
// TODO: rename
util::BitField<23, 1, u32> flag_23;
util::BitField<23, 8, u32> custom_flags;
// TODO: rename once we figure out what this flag is
util::BitField<31, 1, u32> flag;
};
@ -44,9 +51,10 @@ class MaterialMask {
public:
MaterialMask();
explicit MaterialMask(MaterialMaskData data);
MaterialMask(Material mat, FloorCode floor, WallCode wall, bool flag);
MaterialMask(Material mat, const char* submat_name, FloorCode floor, WallCode wall, bool flag);
MaterialMask(Material mat, int submat_idx, FloorCode floor, WallCode wall, bool flag);
MaterialMask(Material mat, FloorCode floor, WallCode wall, bool flag = false);
MaterialMask(Material mat, const char* submat_name, FloorCode floor, WallCode wall,
bool flag = false);
MaterialMask(Material mat, int submat_idx, FloorCode floor, WallCode wall, bool flag = false);
MaterialMask(const MaterialMask& other) : mData(other.mData) {}
// XXX: this doesn't need to be virtual.
@ -68,7 +76,6 @@ public:
const char* getSubMaterialName() const;
void setMaterial(Material mat);
void clearSubMaterialNameCache() { mSubMaterialNameCache = nullptr; }
static int getSubMaterialIdx(Material mat, const sead::SafeString& submat_name);
static const sead::SafeString& getSubMaterialName(Material mat, int submat_idx);