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; +}