From 969bcdba35b5ac8406a86a7d0840f8986cb7b9b3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 7 Mar 2020 04:46:17 -0500 Subject: [PATCH 1/3] CPVSVisOctree: Use static qualifying name for ReadBoundingBoxBig() It looks very odd using the name of the object being initialized to call through to a static member function. We can disambiguate this by making use of the qualifying name directly. --- Runtime/Graphics/CPVSVisOctree.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index d1767ebc6..67bd7f231 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -4,9 +4,9 @@ namespace urde { CPVSVisOctree CPVSVisOctree::MakePVSVisOctree(const u8* data) { CMemoryInStream r(data, 68); - zeus::CAABox aabb = aabb.ReadBoundingBoxBig(r); - u32 numObjects = r.readUint32Big(); - u32 numLights = r.readUint32Big(); + const zeus::CAABox aabb = zeus::CAABox::ReadBoundingBoxBig(r); + const u32 numObjects = r.readUint32Big(); + const u32 numLights = r.readUint32Big(); r.readUint32Big(); return CPVSVisOctree(aabb, numObjects, numLights, data + r.position()); } From 4034e3b31fb041f72bdcf9e77562d209f179f2b3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 7 Mar 2020 04:50:16 -0500 Subject: [PATCH 2/3] CPVSVisOctree: Make use of std::array where applicable Makes the arrays strongly typed. --- Runtime/Graphics/CPVSVisOctree.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index 67bd7f231..e08440d85 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/CPVSVisOctree.hpp" +#include + namespace urde { CPVSVisOctree CPVSVisOctree::MakePVSVisOctree(const u8* data) { @@ -17,9 +19,10 @@ CPVSVisOctree::CPVSVisOctree(const zeus::CAABox& aabb, u32 numObjects, u32 numLi x20_bufferFlag = 0; } -static const u32 NumChildTable[] = {0, 2, 2, 4, 2, 4, 4, 8}; - -u32 CPVSVisOctree::GetNumChildren(u8 byte) const { return NumChildTable[byte & 0x7]; } +u32 CPVSVisOctree::GetNumChildren(u8 byte) const { + static constexpr std::array numChildTable{0, 2, 2, 4, 2, 4, 4, 8}; + return numChildTable[byte & 0x7]; +} u32 CPVSVisOctree::GetChildIndex(const u8*, const zeus::CVector3f&) const { return 0; } @@ -29,7 +32,7 @@ s32 CPVSVisOctree::IterateSearch(u8 nodeData, const zeus::CVector3f& tp) const { zeus::CVector3f newMin = x2c_searchAabb.center(); zeus::CVector3f newMax; - bool highFlags[3]; + std::array highFlags{}; if (tp.x() > newMin.x()) { newMax.x() = x2c_searchAabb.max.x(); @@ -58,7 +61,7 @@ s32 CPVSVisOctree::IterateSearch(u8 nodeData, const zeus::CVector3f& tp) const { highFlags[2] = false; } - u8 axisCounts[2] = {1, 1}; + std::array axisCounts{1, 1}; if (nodeData & 0x1) axisCounts[0] = 2; if (nodeData & 0x2) From 8d42eb428795936aaf5a8c2b12fa92eddb2e9e30 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 7 Mar 2020 04:59:04 -0500 Subject: [PATCH 3/3] CPVSVisOctree: Initialize in-class member variables where applicable Provides a deterministic initial state for the default constructor. --- Runtime/Graphics/CPVSVisOctree.cpp | 10 +++++++--- Runtime/Graphics/CPVSVisOctree.hpp | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index e08440d85..ed278b2d4 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -14,9 +14,13 @@ CPVSVisOctree CPVSVisOctree::MakePVSVisOctree(const u8* data) { } CPVSVisOctree::CPVSVisOctree(const zeus::CAABox& aabb, u32 numObjects, u32 numLights, const u8* c) -: x0_aabb(aabb), x18_numObjects(numObjects), x1c_numLights(numLights), x20_bufferFlag(c != nullptr), x24_octreeData(c) { - x2c_searchAabb = x0_aabb; - x20_bufferFlag = 0; +: x0_aabb(aabb) +, x18_numObjects(numObjects) +, x1c_numLights(numLights) +, x20_bufferFlag(c != nullptr) +, x24_octreeData(c) +, x2c_searchAabb(x0_aabb) { + x20_bufferFlag = false; } u32 CPVSVisOctree::GetNumChildren(u8 byte) const { diff --git a/Runtime/Graphics/CPVSVisOctree.hpp b/Runtime/Graphics/CPVSVisOctree.hpp index ff9de4be6..9116546ac 100644 --- a/Runtime/Graphics/CPVSVisOctree.hpp +++ b/Runtime/Graphics/CPVSVisOctree.hpp @@ -10,10 +10,10 @@ namespace urde { class CPVSVisOctree { zeus::CAABox x0_aabb; - u32 x18_numObjects; - u32 x1c_numLights; - bool x20_bufferFlag; - const u8* x24_octreeData; + u32 x18_numObjects = 0; + u32 x1c_numLights = 0; + bool x20_bufferFlag = false; + const u8* x24_octreeData = nullptr; zeus::CAABox x2c_searchAabb; public: