diff options
| author | Léo Lam <leo@leolam.fr> | 2022-02-13 19:08:08 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2022-02-13 19:08:08 +0100 |
| commit | dfcfbbe4a4d0efc696b414edf59e0ce807b2d910 (patch) | |
| tree | e0037359e62ed494b4330f28897c49d6827145ed /src/KingSystem/Physics/physDefines.cpp | |
| parent | 3512b78627490b952db0dc4b4a8fc58d49e8d55b (diff) | |
ksys/phys: Move common headers (Defines, MaterialMask) out of System/
Diffstat (limited to 'src/KingSystem/Physics/physDefines.cpp')
| -rw-r--r-- | src/KingSystem/Physics/physDefines.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
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<MotionType>(type); + ++type; + } + return MotionType::Unknown; +} + +} // namespace ksys::phys |
