ksys/phys: Move common headers (Defines, MaterialMask) out of System/

This commit is contained in:
Léo Lam
2022-02-13 19:08:08 +01:00
parent 3512b78627
commit dfcfbbe4a4
31 changed files with 36 additions and 36 deletions
@@ -6,7 +6,7 @@
#include <hostio/seadHostIONode.h>
#include <prim/seadRuntimeTypeInfo.h>
#include <thread/seadCriticalSection.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/physDefines.h"
namespace ksys::phys {
@@ -12,8 +12,8 @@
#include <prim/seadSafeString.h>
#include <thread/seadAtomic.h>
#include <thread/seadMutex.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/System/physMaterialMask.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Physics/physMaterialMask.h"
#include "KingSystem/Utils/Types.h"
namespace sead {
@@ -1,106 +0,0 @@
#include "KingSystem/Physics/System/physDefines.h"
namespace ksys::phys {
ContactLayerType getContactLayerType(ContactLayer layer) {
if (layer > ContactLayer::EntityEnd)
return ContactLayerType::Sensor;
return ContactLayerType::Entity;
}
u32 makeContactLayerMask(ContactLayer layer) {
if (layer < FirstSensor)
return 1 << layer;
return 1 << (layer - FirstSensor);
}
u32 getContactLayerBase(ContactLayerType type) {
if (type == ContactLayerType::Entity)
return FirstEntity;
return FirstSensor;
}
u32 getContactLayerBaseRelativeValue(ContactLayer layer) {
return layer - (layer < FirstSensor ? FirstEntity : FirstSensor);
}
const char* contactLayerToText(ContactLayer layer) {
return layer.text();
}
ContactLayer contactLayerFromText(const sead::SafeString& text) {
for (auto layer : ContactLayer()) {
if (text == layer.text())
return layer;
}
return 0;
}
const char* materialToText(Material material) {
return material.text();
}
Material materialFromText(const sead::SafeString& text) {
for (auto material : Material()) {
if (text == material.text())
return material;
}
return 0;
}
const char* groundHitToText(GroundHit hit) {
return hit.text();
}
GroundHit groundHitFromText(const sead::SafeString& text) {
for (auto hit : GroundHit()) {
if (text == hit.text())
return hit;
}
return GroundHit::HitAll;
}
const char* floorCodeToText(FloorCode code) {
return code.text();
}
FloorCode floorCodeFromText(const sead::SafeString& text) {
for (auto code : FloorCode()) {
if (text == code.text())
return code;
}
return 0;
}
const char* wallCodeToText(WallCode code) {
return code.text();
}
WallCode wallCodeFromText(const sead::SafeString& text) {
for (auto code : WallCode()) {
if (text == code.text())
return code;
}
return 0;
}
MotionType motionTypeFromText(const sead::SafeString& text) {
static constexpr const char* texts[] = {
"Dynamic",
"Fixed",
"Keyframed",
};
static_assert(int(MotionType::Dynamic) == 0);
static_assert(int(MotionType::Fixed) == 1);
static_assert(int(MotionType::Keyframed) == 2);
int type = 0;
for (const char* type_text : texts) {
if (text == type_text)
return static_cast<MotionType>(type);
++type;
}
return MotionType::Unknown;
}
} // namespace ksys::phys
-316
View File
@@ -1,316 +0,0 @@
#pragma once
#include <basis/seadTypes.h>
#include <prim/seadEnum.h>
#include <prim/seadSafeString.h>
#include "KingSystem/Utils/BitField.h"
namespace ksys::phys {
enum class ContactLayerType {
Entity,
Sensor,
Invalid,
};
SEAD_ENUM(ContactLayer,
EntityObject,\
EntitySmallObject,\
EntityGroundObject,\
EntityPlayer,\
EntityNPC,\
EntityRagdoll,\
EntityWater,\
EntityAirWall,\
EntityGround,\
EntityGroundSmooth,\
EntityGroundRough,\
EntityRope,\
EntityTree,\
EntityNPC_NoHitPlayer,\
EntityHitOnlyWater,\
EntityWallForClimb,\
EntityHitOnlyGround,\
EntityQueryCustomReceiver,\
EntityForbidden18,\
EntityNoHit,\
EntityMeshVisualizer,\
EntityForbidden21,\
EntityForbidden22,\
EntityForbidden23,\
EntityForbidden24,\
EntityForbidden25,\
EntityForbidden26,\
EntityForbidden27,\
EntityForbidden28,\
EntityForbidden29,\
EntityForbidden30,\
EntityEnd,\
SensorObject,\
SensorSmallObject,\
SensorPlayer,\
SensorEnemy,\
SensorNPC,\
SensorHorse,\
SensorRope,\
SensorAttackPlayer,\
SensorAttackEnemy,\
SensorChemical,\
SensorTerror,\
SensorHitOnlyInDoor,\
SensorInDoor,\
SensorReserve13,\
SensorReserve14,\
SensorChemicalElement,\
SensorAttackCommon,\
SensorQueryOnly,\
SensorTree,\
SensorCamera,\
SensorMeshVisualizer,\
SensorNoHit,\
SensorReserve20,\
SensorCustomReceiver,\
SensorEnd)
constexpr int MaxNumLayersPerType = 32;
constexpr auto FirstEntity = ContactLayer::EntityObject;
constexpr auto LastEntity = ContactLayer::EntityMeshVisualizer;
constexpr auto FirstSensor = ContactLayer::SensorObject;
constexpr auto LastSensor = ContactLayer::SensorCustomReceiver;
SEAD_ENUM(Material,
Undefined,\
Soil,\
Stone,\
Sand,\
Metal,\
WireNet,\
Grass,\
Wood,\
Water,\
Snow,\
Ice,\
Lava,\
Bog,\
HeavySand,\
Cloth,\
Glass,\
Bone,\
Rope,\
CharControl,\
Ragdoll,\
Surfing,\
GuardianFoot,\
HeavySnow,\
Unused0,\
LaunchPad,\
Conveyer,\
Rail,\
Grudge,\
Meat,\
Vegetable,\
Bomb,\
MagicBall,\
Barrier,\
AirWall,\
Misc,\
GrudgeSlow
)
constexpr bool isInvalidMaterial(Material::ValueType mat) {
return mat >= Material::size();
}
SEAD_ENUM(GroundHit,
Player,\
Animal,\
NPC,\
Camera,\
AttackHitPlayer,\
AttackHitEnemy,\
Arrow,\
Bomb,\
Magnet,\
CameraBody,\
IK,\
Grudge,\
MovingTrolley,\
LineOfSight,\
Giant,\
HitAll,\
Ignore
)
SEAD_ENUM(FloorCode,
None,\
Return,\
FlowStraight,\
FlowLeft,\
FlowRight,\
Slip,\
NarrowPlace,\
TopBroadleafTree,\
TopConiferousTree,\
Fall,\
Attach,\
NoImpulseUpperMove,\
NoPreventFall
)
SEAD_ENUM(WallCode,
None,\
NoClimb,\
Hang,\
LadderUp,\
Ladder,\
Slip,\
LadderSide,\
NoSlipRain,\
NoDashUpAndNoClimb,\
IceMakerBlock
)
enum class MotionType {
Dynamic = 0,
Fixed = 1,
Keyframed = 2,
Unknown = 3,
Invalid = -1,
};
union ReceiverMask {
union Data {
util::BitField<0, 5, u32> layer;
// TODO: rename once we figure out what this layer is used for
util::BitField<5, 1, bool, u32> has_layer2;
util::BitField<6, 5, u32> layer2;
};
union CustomReceiverData {
util::BitField<0, 21, u32> layer;
util::BitField<21, 10, u32> group_handler_index;
};
constexpr ReceiverMask() : raw(0) { is_custom_receiver = true; }
constexpr explicit ReceiverMask(u32 raw_) : raw(raw_) {}
constexpr ReceiverMask(const ReceiverMask&) = default;
constexpr ReceiverMask& operator=(const ReceiverMask& m) {
raw = m.raw;
return *this;
}
static ReceiverMask make(ContactLayer layer) {
ReceiverMask mask;
if (layer == ContactLayer::SensorCustomReceiver) {
mask.is_custom_receiver = true;
mask.custom_receiver_data.layer.Init(ContactLayer::SensorCustomReceiver - FirstSensor);
} else {
mask.is_custom_receiver = false;
mask.data.layer.Init(layer - FirstSensor);
}
return mask;
}
u32 raw;
Data data;
CustomReceiverData custom_receiver_data;
// FIXME: is this a sensor layer mask?
util::BitField<0, 21, u32> layer_mask;
util::BitField<31, 1, bool, u32> is_custom_receiver;
};
union EntityCollisionFilterInfo {
union Data {
ContactLayer getLayer() const { return int(layer); }
ContactLayer getLayerSensor() const { return int(layer + FirstSensor); }
GroundHit getGroundHit() const { return int(ground_hit); }
u32 raw;
util::BitField<0, 5, u32> layer;
util::BitField<24, 1, u32> unk24;
util::BitField<25, 1, u32> unk25;
util::BitField<26, 4, u32> ground_hit;
};
union GroundHitMask {
ContactLayer getLayer() const { return int(layer); }
void addGroundHit(GroundHit hit) {
raw |= (1 << hit) << decltype(ground_hit_types)::StartBit();
}
u32 raw;
util::BitField<0, 1, u32> unk;
util::BitField<8, 16, u32> ground_hit_types;
util::BitField<24, 1, u32> unk24;
util::BitField<25, 5, u32> layer;
};
constexpr explicit EntityCollisionFilterInfo(u32 raw_ = 0) : raw(raw_) {}
constexpr EntityCollisionFilterInfo(const EntityCollisionFilterInfo&) = default;
constexpr EntityCollisionFilterInfo& operator=(const EntityCollisionFilterInfo& m) {
raw = m.raw;
return *this;
}
bool operator==(EntityCollisionFilterInfo rhs) const { return raw == rhs.raw; }
bool operator!=(EntityCollisionFilterInfo rhs) const { return raw != rhs.raw; }
static EntityCollisionFilterInfo make(ContactLayer layer, GroundHit ground_hit) {
EntityCollisionFilterInfo mask;
mask.data.layer.Init(layer);
mask.data.ground_hit.Init(ground_hit);
return mask;
}
ContactLayer getLayer() const {
return is_ground_hit_mask ? ground_hit.getLayer() : data.getLayer();
}
ContactLayer getLayerSensor() const {
return is_ground_hit_mask ? ContactLayer(ContactLayer::SensorCustomReceiver) :
data.getLayerSensor();
}
GroundHit getGroundHit() const {
return is_ground_hit_mask ? GroundHit::HitAll : data.getGroundHit();
}
u32 raw;
Data data;
GroundHitMask ground_hit;
util::BitField<5, 1, bool, u32> unk5;
/// Whether ground collision is disabled.
util::BitField<6, 1, bool, u32> no_ground_collision;
/// Whether water collision is disabled.
util::BitField<7, 1, bool, u32> no_water_collision;
util::BitField<16, 10, u32> group_handler_index;
util::BitField<30, 1, bool, u32> unk30;
util::BitField<31, 1, bool, u32> is_ground_hit_mask;
};
static_assert(sizeof(EntityCollisionFilterInfo) == sizeof(u32));
ContactLayerType getContactLayerType(ContactLayer layer);
u32 makeContactLayerMask(ContactLayer layer);
u32 getContactLayerBase(ContactLayerType type);
u32 getContactLayerBaseRelativeValue(ContactLayer layer);
const char* contactLayerToText(ContactLayer layer);
ContactLayer contactLayerFromText(const sead::SafeString& text);
const char* materialToText(Material material);
Material materialFromText(const sead::SafeString& text);
const char* groundHitToText(GroundHit hit);
GroundHit groundHitFromText(const sead::SafeString& text);
const char* floorCodeToText(FloorCode code);
FloorCode floorCodeFromText(const sead::SafeString& text);
const char* wallCodeToText(WallCode code);
WallCode wallCodeFromText(const sead::SafeString& text);
MotionType motionTypeFromText(const sead::SafeString& text);
} // namespace ksys::phys
@@ -3,8 +3,8 @@
#include <container/seadSafeArray.h>
#include <prim/seadBitUtil.h>
#include <prim/seadSafeString.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/System/physGroupFilter.h"
#include "KingSystem/Physics/physDefines.h"
namespace ksys::phys {
@@ -6,7 +6,7 @@
#include <container/seadSafeArray.h>
#include <prim/seadRuntimeTypeInfo.h>
#include <thread/seadCriticalSection.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/physDefines.h"
namespace ksys::phys {
@@ -1,80 +0,0 @@
#include "KingSystem/Physics/System/physMaterialMask.h"
#include "KingSystem/Physics/System/physMaterialTable.h"
#include "KingSystem/Physics/System/physSystem.h"
namespace ksys::phys {
MaterialMask::MaterialMask() = default;
MaterialMask::MaterialMask(MaterialMaskData data) : mData(data) {}
MaterialMask::MaterialMask(Material mat, FloorCode floor, WallCode wall, bool flag) {
mData.material.Init(mat);
mData.floor.Init(floor);
mData.wall.Init(wall);
mData.setFlag(flag);
}
MaterialMask::MaterialMask(Material mat, const char* submat_name, FloorCode floor, WallCode wall,
bool flag)
: mSubMaterialNameCache(submat_name) {
auto submat_idx = getSubMaterialIdx(mat, submat_name);
if (!MaterialMaskData::isValidSubMaterialIdx(submat_idx))
submat_idx = 0;
mData.raw = {};
mData.material.Init(mat);
mData.sub_material.Init(submat_idx);
mData.floor.Init(floor);
mData.wall.Init(wall);
mData.setFlag(flag);
}
MaterialMask::MaterialMask(Material mat, int submat_idx, FloorCode floor, WallCode wall, bool flag)
: mSubMaterialNameCache(getSubMaterialName(mat, submat_idx).cstr()) {
mData.raw = {};
mData.material.Init(mat);
mData.sub_material.Init(submat_idx);
mData.floor.Init(floor);
mData.wall.Init(wall);
mData.setFlag(flag);
}
MaterialMask::~MaterialMask() = default;
const char* MaterialMask::getMaterialName() const {
const Material material = getMaterial();
if (isInvalidMaterial(material.value()))
return "Incorrent"; // sic
return materialToText(material);
}
const char* MaterialMask::getSubMaterialName() const {
if (mSubMaterialNameCache != nullptr)
return mSubMaterialNameCache;
mSubMaterialNameCache = getSubMaterialName(getMaterial(), getSubMaterialIdx()).cstr();
return mSubMaterialNameCache;
}
int MaterialMask::getSubMaterialIdx(Material mat, const sead::SafeString& submat_name) {
return System::instance()->getMaterialTable()->getSubMaterialIdx(mat, submat_name);
}
const sead::SafeString& MaterialMask::getSubMaterialName(Material mat, int submat_idx) {
return System::instance()->getMaterialTable()->getSubMaterial(mat, submat_idx);
}
int MaterialMask::getNumSubMaterials(Material mat) {
return System::instance()->getMaterialTable()->getNumSubMaterials(mat);
}
const sead::SafeString& MaterialMask::getSubMaterialName(int mat, int submat_idx) {
return getSubMaterialName(Material(mat), submat_idx);
}
void MaterialMask::setMaterial(Material mat) {
mData.material = {};
mData.material.SetUnsafe(mat);
}
} // namespace ksys::phys
@@ -1,92 +0,0 @@
#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"
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) {
raw = other.raw;
return *this;
}
static constexpr bool isValidSubMaterialIdx(int idx) {
return u32(idx) < (1 << decltype(sub_material)::NumBits());
}
void setFlag(bool b) {
if (!b)
clearFlag();
else
setFlag();
}
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;
util::BitField<23, 8, u32> custom_flags;
// TODO: rename once we figure out what this flag is
util::BitField<31, 1, u32> flag;
};
static_assert(sizeof(MaterialMaskData) == sizeof(u32));
class MaterialMask {
public:
MaterialMask();
explicit MaterialMask(MaterialMaskData data);
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.
virtual ~MaterialMask();
MaterialMask& operator=(const MaterialMask& other) {
mData = other.mData;
mSubMaterialNameCache = nullptr;
return *this;
}
MaterialMaskData& getData() { return mData; }
const MaterialMaskData& getData() const { return mData; }
u32 getRawData() const { return mData.raw; }
Material getMaterial() const { return Material::ValueType(mData.material.Value()); }
int getSubMaterialIdx() const { return mData.sub_material; }
const char* getMaterialName() const;
const char* getSubMaterialName() const;
void setMaterial(Material mat);
static int getSubMaterialIdx(Material mat, const sead::SafeString& submat_name);
static const sead::SafeString& getSubMaterialName(Material mat, int submat_idx);
static int getNumSubMaterials(Material mat);
static const sead::SafeString& getSubMaterialName(int mat, int submat_idx);
private:
MaterialMaskData mData{};
/// Fetching the name of a sub-material from the MaterialTable is an expensive operation,
/// so it is only done once and the result is cached.
mutable const char* mSubMaterialNameCache{};
};
} // namespace ksys::phys
@@ -6,7 +6,7 @@
#include <agl/Utils/aglParameterObj.h>
#include <agl/Utils/aglResParameter.h>
#include <container/seadSafeArray.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Utils/Types.h"
namespace ksys::phys {
@@ -4,8 +4,8 @@
#include <math/seadVector.h>
#include <prim/seadDelegate.h>
#include <prim/seadTypedBitFlag.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/System/physRigidContactPoints.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Utils/Types.h"
namespace ksys::phys {
@@ -1,7 +1,7 @@
#pragma once
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/System/physGroupFilter.h"
#include "KingSystem/Physics/physDefines.h"
namespace ksys::phys {
+1 -1
View File
@@ -4,7 +4,7 @@
#include <container/seadPtrArray.h>
#include <heap/seadDisposer.h>
#include <thread/seadCriticalSection.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Utils/Types.h"
namespace ksys::phys {
@@ -7,7 +7,7 @@
#include <agl/Utils/aglResParameter.h>
#include <container/seadSafeArray.h>
#include <prim/seadEnum.h>
#include "KingSystem/Physics/System/physDefines.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Utils/Types.h"
namespace ksys::res {