summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/System/physDefines.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2022-02-13 01:16:38 +0100
committerLéo Lam <leo@leolam.fr>2022-02-13 01:16:52 +0100
commitfc8d4b5c683694c3287ef13975d2f231822287c1 (patch)
treea79da1f9ce3a7b26fb6227ec1e03ca9cd8cfef8f /src/KingSystem/Physics/System/physDefines.cpp
parent0c3ee0dd841026ca5221f5f3493c0a86d5030437 (diff)
Fix matching issue in ksys::phys::motionTypeFromText
Diffstat (limited to 'src/KingSystem/Physics/System/physDefines.cpp')
-rw-r--r--src/KingSystem/Physics/System/physDefines.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/KingSystem/Physics/System/physDefines.cpp b/src/KingSystem/Physics/System/physDefines.cpp
index 2b75af66..5f505dc6 100644
--- a/src/KingSystem/Physics/System/physDefines.cpp
+++ b/src/KingSystem/Physics/System/physDefines.cpp
@@ -84,17 +84,23 @@ WallCode wallCodeFromText(const sead::SafeString& text) {
return 0;
}
-// duplicated branches?
-#ifdef NON_MATCHING
MotionType motionTypeFromText(const sead::SafeString& text) {
- if (text == "Dynamic")
- return MotionType::Dynamic;
- if (text == "Fixed")
- return MotionType::Fixed;
- if (text == "Keyframed")
- return MotionType::Keyframed;
+ 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;
}
-#endif
} // namespace ksys::phys