From dfcfbbe4a4d0efc696b414edf59e0ce807b2d910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 13 Feb 2022 19:08:08 +0100 Subject: ksys/phys: Move common headers (Defines, MaterialMask) out of System/ --- src/KingSystem/Physics/CMakeLists.txt | 8 +- .../Physics/RigidBody/Shape/Box/physBoxShape.h | 2 +- .../RigidBody/Shape/BoxWater/physBoxWaterShape.h | 2 +- .../RigidBody/Shape/Capsule/physCapsuleShape.h | 4 +- .../RigidBody/Shape/Cylinder/physCylinderShape.h | 2 +- .../Shape/CylinderWater/physCylinderWaterShape.h | 2 +- .../RigidBody/Shape/Polytope/physPolytopeShape.h | 2 +- src/KingSystem/Physics/RigidBody/Shape/physShape.h | 4 +- .../Physics/RigidBody/Shape/physShapeParamObj.h | 2 +- src/KingSystem/Physics/RigidBody/physRigidBody.h | 2 +- .../Physics/RigidBody/physRigidBodyAccessor.h | 2 +- .../RigidBody/physRigidBodyFromResource.cpp | 2 +- .../Physics/RigidBody/physRigidBodyFromShape.cpp | 2 +- .../Physics/RigidBody/physRigidBodyParam.h | 2 +- .../Physics/RigidBody/physRigidBodyRequestMgr.cpp | 2 +- .../Physics/RigidBody/physRigidBodyRequestMgr.h | 2 +- .../Physics/RigidBody/physRigidBodySet.h | 2 +- .../StaticCompound/physStaticCompoundInfo.h | 2 +- .../Physics/System/physContactListener.h | 2 +- src/KingSystem/Physics/System/physContactMgr.h | 4 +- src/KingSystem/Physics/System/physDefines.cpp | 106 ------- src/KingSystem/Physics/System/physDefines.h | 316 --------------------- .../Physics/System/physEntityGroupFilter.h | 2 +- src/KingSystem/Physics/System/physGroupFilter.h | 2 +- src/KingSystem/Physics/System/physMaterialMask.cpp | 80 ------ src/KingSystem/Physics/System/physMaterialMask.h | 92 ------ src/KingSystem/Physics/System/physMaterialTable.h | 2 +- .../Physics/System/physRigidContactPointsEx.h | 2 +- .../Physics/System/physSensorGroupFilter.h | 2 +- src/KingSystem/Physics/System/physSystem.h | 2 +- src/KingSystem/Physics/System/physSystemData.h | 2 +- src/KingSystem/Physics/physDefines.cpp | 106 +++++++ src/KingSystem/Physics/physDefines.h | 316 +++++++++++++++++++++ src/KingSystem/Physics/physMaterialMask.cpp | 80 ++++++ src/KingSystem/Physics/physMaterialMask.h | 92 ++++++ 35 files changed, 627 insertions(+), 627 deletions(-) delete mode 100644 src/KingSystem/Physics/System/physDefines.cpp delete mode 100644 src/KingSystem/Physics/System/physDefines.h delete mode 100644 src/KingSystem/Physics/System/physMaterialMask.cpp delete mode 100644 src/KingSystem/Physics/System/physMaterialMask.h create mode 100644 src/KingSystem/Physics/physDefines.cpp create mode 100644 src/KingSystem/Physics/physDefines.h create mode 100644 src/KingSystem/Physics/physMaterialMask.cpp create mode 100644 src/KingSystem/Physics/physMaterialMask.h (limited to 'src') diff --git a/src/KingSystem/Physics/CMakeLists.txt b/src/KingSystem/Physics/CMakeLists.txt index 68940afd..58d78215 100644 --- a/src/KingSystem/Physics/CMakeLists.txt +++ b/src/KingSystem/Physics/CMakeLists.txt @@ -107,16 +107,12 @@ target_sources(uking PRIVATE System/physContactListener.h System/physContactMgr.cpp System/physContactMgr.h - System/physDefines.cpp - System/physDefines.h System/physEntityGroupFilter.cpp System/physEntityGroupFilter.h System/physGroupFilter.cpp System/physGroupFilter.h System/physInstanceSet.cpp System/physInstanceSet.h - System/physMaterialMask.cpp - System/physMaterialMask.h System/physMaterialTable.cpp System/physMaterialTable.h System/physParamSet.cpp @@ -134,6 +130,10 @@ target_sources(uking PRIVATE System/physUserTag.cpp System/physUserTag.h + physDefines.cpp + physDefines.h physConversions.h physHeapUtil.h + physMaterialMask.cpp + physMaterialMask.h ) diff --git a/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h b/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h index 86c5ba72..a1da021b 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h @@ -6,7 +6,7 @@ #include "KingSystem/Physics/RigidBody/Shape/physShape.h" #include "KingSystem/Physics/RigidBody/physRigidBody.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkTransformf; class hkpBoxShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/BoxWater/physBoxWaterShape.h b/src/KingSystem/Physics/RigidBody/Shape/BoxWater/physBoxWaterShape.h index 1512bb5a..ec55eaed 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/BoxWater/physBoxWaterShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/BoxWater/physBoxWaterShape.h @@ -4,7 +4,7 @@ #include #include #include "KingSystem/Physics/RigidBody/Shape/physShape.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkpPlaneShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h b/src/KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h index 3a5618aa..5190f212 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h @@ -7,8 +7,8 @@ #include "KingSystem/Physics/RigidBody/Shape/physShape.h" #include "KingSystem/Physics/RigidBody/physRigidBody.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physDefines.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physDefines.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkpShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h b/src/KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h index 82ff0109..2e5cb723 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h @@ -6,7 +6,7 @@ #include "KingSystem/Physics/RigidBody/Shape/physShape.h" #include "KingSystem/Physics/RigidBody/physRigidBody.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkTransformf; class hkpCylinderShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterShape.h b/src/KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterShape.h index cf08bb2b..a06a2b8f 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/CylinderWater/physCylinderWaterShape.h @@ -5,7 +5,7 @@ #include "KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h" #include "KingSystem/Physics/RigidBody/physRigidBody.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h index dc55ca0d..bc7a64f2 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h @@ -8,7 +8,7 @@ #include #include "KingSystem/Physics/RigidBody/Shape/physShape.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkpConvexTransformShape; class hkpConvexVerticesShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/physShape.h b/src/KingSystem/Physics/RigidBody/Shape/physShape.h index 672c6cb4..db53e44f 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physShape.h @@ -2,8 +2,8 @@ #include #include -#include "KingSystem/Physics/System/physDefines.h" -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physDefines.h" +#include "KingSystem/Physics/physMaterialMask.h" class hkpShape; diff --git a/src/KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h b/src/KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h index 7f781502..2f14c967 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h @@ -4,7 +4,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/physRigidBody.h b/src/KingSystem/Physics/RigidBody/physRigidBody.h index e7925e35..84df78a1 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBody.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBody.h @@ -10,7 +10,7 @@ #include #include #include "KingSystem/Physics/RigidBody/physRigidBodyAccessor.h" -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Types.h" enum hkpCollidableQualityType : int; diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyAccessor.h b/src/KingSystem/Physics/RigidBody/physRigidBodyAccessor.h index 8e32ed40..af47cac4 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyAccessor.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyAccessor.h @@ -3,7 +3,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" class hkpRigidBody; diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFromResource.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyFromResource.cpp index 0299fa75..a17d16b9 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyFromResource.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFromResource.cpp @@ -5,8 +5,8 @@ #include #include #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physMaterialMask.h" #include "KingSystem/Physics/physConversions.h" +#include "KingSystem/Physics/physMaterialMask.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp index 8d80917a..7e1de581 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp @@ -20,9 +20,9 @@ #include "KingSystem/Physics/RigidBody/Shape/Sphere/physSphereShape.h" #include "KingSystem/Physics/RigidBody/Shape/physShape.h" #include "KingSystem/Physics/RigidBody/physRigidBodyParam.h" -#include "KingSystem/Physics/System/physDefines.h" #include "KingSystem/Physics/System/physGroupFilter.h" #include "KingSystem/Physics/physConversions.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/HeapUtil.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyParam.h b/src/KingSystem/Physics/RigidBody/physRigidBodyParam.h index b367c1bf..d561b056 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyParam.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyParam.h @@ -6,7 +6,7 @@ #include #include #include "KingSystem/Physics/RigidBody/Shape/physShape.h" -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Types.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.cpp index 886da47b..7498f536 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.cpp @@ -1,6 +1,6 @@ #include "KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.h" #include -#include "KingSystem/Physics/System/physMaterialMask.h" +#include "KingSystem/Physics/physMaterialMask.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.h b/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.h index ca53405b..880f7286 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyRequestMgr.h @@ -9,8 +9,8 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" #include "KingSystem/Physics/System/physRigidContactPointsEx.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Container/LockFreeQueue.h" #include "KingSystem/Utils/Types.h" diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodySet.h b/src/KingSystem/Physics/RigidBody/physRigidBodySet.h index aeb9aeaf..8de77946 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodySet.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBodySet.h @@ -5,7 +5,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h b/src/KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h index 2afe1ef5..dfd31ed9 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundInfo.h @@ -1,7 +1,7 @@ #pragma once #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" class hkTypeInfo; diff --git a/src/KingSystem/Physics/System/physContactListener.h b/src/KingSystem/Physics/System/physContactListener.h index b5f3d057..a01218a3 100644 --- a/src/KingSystem/Physics/System/physContactListener.h +++ b/src/KingSystem/Physics/System/physContactListener.h @@ -6,7 +6,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/System/physContactMgr.h b/src/KingSystem/Physics/System/physContactMgr.h index 24971513..388f185d 100644 --- a/src/KingSystem/Physics/System/physContactMgr.h +++ b/src/KingSystem/Physics/System/physContactMgr.h @@ -12,8 +12,8 @@ #include #include #include -#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 { diff --git a/src/KingSystem/Physics/System/physDefines.cpp b/src/KingSystem/Physics/System/physDefines.cpp deleted file mode 100644 index 5f505dc6..00000000 --- a/src/KingSystem/Physics/System/physDefines.cpp +++ /dev/null @@ -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(type); - ++type; - } - return MotionType::Unknown; -} - -} // namespace ksys::phys diff --git a/src/KingSystem/Physics/System/physDefines.h b/src/KingSystem/Physics/System/physDefines.h deleted file mode 100644 index 1de8e860..00000000 --- a/src/KingSystem/Physics/System/physDefines.h +++ /dev/null @@ -1,316 +0,0 @@ -#pragma once - -#include -#include -#include -#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 diff --git a/src/KingSystem/Physics/System/physEntityGroupFilter.h b/src/KingSystem/Physics/System/physEntityGroupFilter.h index ec10b4ee..a5a8689c 100644 --- a/src/KingSystem/Physics/System/physEntityGroupFilter.h +++ b/src/KingSystem/Physics/System/physEntityGroupFilter.h @@ -3,8 +3,8 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" #include "KingSystem/Physics/System/physGroupFilter.h" +#include "KingSystem/Physics/physDefines.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/System/physGroupFilter.h b/src/KingSystem/Physics/System/physGroupFilter.h index 3ce5dd07..cb7843c1 100644 --- a/src/KingSystem/Physics/System/physGroupFilter.h +++ b/src/KingSystem/Physics/System/physGroupFilter.h @@ -6,7 +6,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/System/physMaterialMask.cpp b/src/KingSystem/Physics/System/physMaterialMask.cpp deleted file mode 100644 index c468c76d..00000000 --- a/src/KingSystem/Physics/System/physMaterialMask.cpp +++ /dev/null @@ -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 diff --git a/src/KingSystem/Physics/System/physMaterialMask.h b/src/KingSystem/Physics/System/physMaterialMask.h deleted file mode 100644 index 8098cab5..00000000 --- a/src/KingSystem/Physics/System/physMaterialMask.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -#include -#include -#include -#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 diff --git a/src/KingSystem/Physics/System/physMaterialTable.h b/src/KingSystem/Physics/System/physMaterialTable.h index 04240b0d..9d94bd81 100644 --- a/src/KingSystem/Physics/System/physMaterialTable.h +++ b/src/KingSystem/Physics/System/physMaterialTable.h @@ -6,7 +6,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Types.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/System/physRigidContactPointsEx.h b/src/KingSystem/Physics/System/physRigidContactPointsEx.h index 04f3bf90..305171af 100644 --- a/src/KingSystem/Physics/System/physRigidContactPointsEx.h +++ b/src/KingSystem/Physics/System/physRigidContactPointsEx.h @@ -4,8 +4,8 @@ #include #include #include -#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 { diff --git a/src/KingSystem/Physics/System/physSensorGroupFilter.h b/src/KingSystem/Physics/System/physSensorGroupFilter.h index b8707d28..4762d65b 100644 --- a/src/KingSystem/Physics/System/physSensorGroupFilter.h +++ b/src/KingSystem/Physics/System/physSensorGroupFilter.h @@ -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 { diff --git a/src/KingSystem/Physics/System/physSystem.h b/src/KingSystem/Physics/System/physSystem.h index efdc0d7a..06dbc551 100644 --- a/src/KingSystem/Physics/System/physSystem.h +++ b/src/KingSystem/Physics/System/physSystem.h @@ -4,7 +4,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Types.h" namespace ksys::phys { diff --git a/src/KingSystem/Physics/System/physSystemData.h b/src/KingSystem/Physics/System/physSystemData.h index a759c72f..91267807 100644 --- a/src/KingSystem/Physics/System/physSystemData.h +++ b/src/KingSystem/Physics/System/physSystemData.h @@ -7,7 +7,7 @@ #include #include #include -#include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/physDefines.h" #include "KingSystem/Utils/Types.h" namespace ksys::res { diff --git a/src/KingSystem/Physics/physDefines.cpp b/src/KingSystem/Physics/physDefines.cpp new file mode 100644 index 00000000..a9d50e1d --- /dev/null +++ b/src/KingSystem/Physics/physDefines.cpp @@ -0,0 +1,106 @@ +#include "KingSystem/Physics/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(type); + ++type; + } + return MotionType::Unknown; +} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/physDefines.h b/src/KingSystem/Physics/physDefines.h new file mode 100644 index 00000000..1de8e860 --- /dev/null +++ b/src/KingSystem/Physics/physDefines.h @@ -0,0 +1,316 @@ +#pragma once + +#include +#include +#include +#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 diff --git a/src/KingSystem/Physics/physMaterialMask.cpp b/src/KingSystem/Physics/physMaterialMask.cpp new file mode 100644 index 00000000..365248fa --- /dev/null +++ b/src/KingSystem/Physics/physMaterialMask.cpp @@ -0,0 +1,80 @@ +#include "KingSystem/Physics/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 diff --git a/src/KingSystem/Physics/physMaterialMask.h b/src/KingSystem/Physics/physMaterialMask.h new file mode 100644 index 00000000..8baa349a --- /dev/null +++ b/src/KingSystem/Physics/physMaterialMask.h @@ -0,0 +1,92 @@ +#pragma once + +#include +#include +#include +#include "KingSystem/Physics/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 -- cgit v1.2.3