From 569b210e376af76df40f33a7c0089f4c53392a0b Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 6 Oct 2022 10:00:17 -0700 Subject: [PATCH] Match and link CMaterialList, nearly match CMaterialFilter Former-commit-id: e25205bd6979f36be0eb6e6f64cee993ca306af2 --- configure.py | 1 + include/Collision/CMaterialFilter.hpp | 5 ++++- include/Collision/CMaterialList.hpp | 6 ++++-- src/Collision/CMaterialFilter.cpp | 25 +++++++++++++++++++++++++ src/Collision/CMaterialList.cpp | 12 ++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/Collision/CMaterialFilter.cpp create mode 100644 src/Collision/CMaterialList.cpp diff --git a/configure.py b/configure.py index 7b69047a..0138c52b 100755 --- a/configure.py +++ b/configure.py @@ -28,6 +28,7 @@ COMPLETE_OBJECTS = [ "MetroidPrime/HUD/CHUDMemoParms", "MetroidPrime/ScriptObjects/CScriptDebugCameraWaypoint", "Weapons/IWeaponRenderer", + "Collision/CMaterialList", "Collision/CMRay", "Kyoto/Basics/CStopwatch", "Kyoto/Basics/COsContextDolphin", diff --git a/include/Collision/CMaterialFilter.hpp b/include/Collision/CMaterialFilter.hpp index 59bf00e6..6880396d 100644 --- a/include/Collision/CMaterialFilter.hpp +++ b/include/Collision/CMaterialFilter.hpp @@ -6,6 +6,7 @@ #include "Collision/CMaterialList.hpp" class CMaterialFilter { + static const CMaterialFilter skPassEverything; public: enum EFilterType { kFT_Always, @@ -14,7 +15,7 @@ public: kFT_IncludeExclude, }; - CMaterialFilter() : type(kFT_Always) {} + CMaterialFilter() : include(0x00000000FFFFFFFF), exclude(0), type(kFT_Always) {} CMaterialFilter(const CMaterialList& include, const CMaterialList& exclude, EFilterType type) : include(include), exclude(exclude), type(type) {} @@ -29,6 +30,8 @@ public: return CMaterialFilter(include, exclude, kFT_IncludeExclude); } + bool Passes(const CMaterialList& other) const; + private: CMaterialList include; CMaterialList exclude; diff --git a/include/Collision/CMaterialList.hpp b/include/Collision/CMaterialList.hpp index a1282f00..8c1fe409 100644 --- a/include/Collision/CMaterialList.hpp +++ b/include/Collision/CMaterialList.hpp @@ -116,9 +116,11 @@ public: // HasMaterials__13CMaterialListCFv weak // GetField__13CMaterialListCFUxUx weak // Intersection__13CMaterialListCFRC13CMaterialList weak - // BitPosition__13CMaterialListFUx global + static s32 BitPosition(u64 flags); // GetMaterialString__13CMaterialListCFv weak - // SharesMaterials__13CMaterialListCFRC13CMaterialList weak + u64 SharesMaterials(const CMaterialList& other) const { + return (other.value & value); + } private: u64 value; diff --git a/src/Collision/CMaterialFilter.cpp b/src/Collision/CMaterialFilter.cpp new file mode 100644 index 00000000..0a4668cf --- /dev/null +++ b/src/Collision/CMaterialFilter.cpp @@ -0,0 +1,25 @@ +#include "Collision/CMaterialFilter.hpp" + +const CMaterialFilter CMaterialFilter::skPassEverything; + +bool CMaterialFilter::Passes(const CMaterialList& other) const { + switch (type) { + case kFT_Always: + return true; + case kFT_Include: + return other.SharesMaterials(include) != 0 ? true : false; + case kFT_Exclude: + return other.SharesMaterials(exclude) == 0; + case kFT_IncludeExclude: { + bool ret = false; + if (other.SharesMaterials(include) != 0) { + if (other.SharesMaterials(exclude) == 0) { + ret = true; + } + } + return ret; + } + default: + return true; + } +} diff --git a/src/Collision/CMaterialList.cpp b/src/Collision/CMaterialList.cpp new file mode 100644 index 00000000..956927fa --- /dev/null +++ b/src/Collision/CMaterialList.cpp @@ -0,0 +1,12 @@ +#include "Collision/CMaterialList.hpp" + +s32 CMaterialList::BitPosition(u64 flags) { + for (int ret = 0, i = 0; i < 32; ++i) { + if ((flags & 1) != 0) { + return ret; + } + flags >>= 1; + ++ret; + } + return -1; +}