COBBTree: Return std::array from GetTriangleVertexIndices() directly

While the game binary uses an out pointer here, we can slightly modify
it in this case in order to make it more difficult to misuse the
call-sites by returning the data directly as a std::array.
This commit is contained in:
Lioncash 2020-04-06 01:10:59 -04:00
parent 248a4e57c9
commit e76804079d
3 changed files with 22 additions and 19 deletions

View File

@ -217,11 +217,9 @@ bool CCollidableOBBTree::SphereCollideWithLeafMoving(const COBBTree::CLeafData&
} }
} }
u16 vertIndices[3]; const auto vertIndices = x10_tree->GetTriangleVertexIndices(triIdx);
x10_tree->GetTriangleVertexIndices(triIdx, vertIndices);
for (int k = 0; k < 3; ++k) { for (int k = 0; k < 3; ++k) {
u16 vertIdx = vertIndices[k]; const u16 vertIdx = vertIndices[k];
if (testVert[k]) { if (testVert[k]) {
if (CMetroidAreaCollider::g_DupPrimitiveCheckCount != CMetroidAreaCollider::g_DupVertexList[vertIdx]) { if (CMetroidAreaCollider::g_DupPrimitiveCheckCount != CMetroidAreaCollider::g_DupVertexList[vertIdx]) {
CMetroidAreaCollider::g_DupVertexList[vertIdx] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIdx] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
@ -246,8 +244,7 @@ bool CCollidableOBBTree::SphereCollideWithLeafMoving(const COBBTree::CLeafData&
CMetroidAreaCollider::g_DupEdgeList[edgeIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupEdgeList[edgeIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupEdgeList[edgeIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupEdgeList[edgeIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
u16 vertIndices[3]; const auto vertIndices = x10_tree->GetTriangleVertexIndices(triIdx);
x10_tree->GetTriangleVertexIndices(triIdx, vertIndices);
CMetroidAreaCollider::g_DupVertexList[vertIndices[0]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[0]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupVertexList[vertIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupVertexList[vertIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
@ -309,8 +306,7 @@ bool CCollidableOBBTree::AABoxCollideWithLeafMoving(const COBBTree::CLeafData& l
if (CollisionUtil::TriBoxOverlap(center, extent, surf.GetVert(0), surf.GetVert(1), surf.GetVert(2))) { if (CollisionUtil::TriBoxOverlap(center, extent, surf.GetVert(0), surf.GetVert(1), surf.GetVert(2))) {
const_cast<CCollidableOBBTree&>(*this).x1c_hits += 1; const_cast<CCollidableOBBTree&>(*this).x1c_hits += 1;
u16 vertIndices[3]; const auto vertIndices = x10_tree->GetTriangleVertexIndices(triIdx);
x10_tree->GetTriangleVertexIndices(triIdx, vertIndices);
double d = dOut; double d = dOut;
if (CMetroidAreaCollider::MovingAABoxCollisionCheck_BoxVertexTri(surf, aabb, components.x6c4_vertIdxs, dir, d, if (CMetroidAreaCollider::MovingAABoxCollisionCheck_BoxVertexTri(surf, aabb, components.x6c4_vertIdxs, dir, d,
@ -363,8 +359,7 @@ bool CCollidableOBBTree::AABoxCollideWithLeafMoving(const COBBTree::CLeafData& l
CMetroidAreaCollider::g_DupEdgeList[edgeIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupEdgeList[edgeIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupEdgeList[edgeIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupEdgeList[edgeIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
u16 vertIndices[3]; const auto vertIndices = x10_tree->GetTriangleVertexIndices(triIdx);
x10_tree->GetTriangleVertexIndices(triIdx, vertIndices);
CMetroidAreaCollider::g_DupVertexList[vertIndices[0]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[0]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupVertexList[vertIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[1]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;
CMetroidAreaCollider::g_DupVertexList[vertIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount; CMetroidAreaCollider::g_DupVertexList[vertIndices[2]] = CMetroidAreaCollider::g_DupPrimitiveCheckCount;

View File

@ -105,22 +105,26 @@ CCollisionSurface COBBTree::GetSurface(u16 idx) const {
x18_indexData.x60_vertices[vert3], mat); x18_indexData.x60_vertices[vert3], mat);
} }
void COBBTree::GetTriangleVertexIndices(u16 idx, u16 indicesOut[3]) const { std::array<u16, 3> COBBTree::GetTriangleVertexIndices(u16 idx) const {
const auto surfIdx = size_t{idx} * 3; const auto surfIdx = size_t{idx} * 3;
const CCollisionEdge& e0 = x18_indexData.x40_edges[x18_indexData.x50_surfaceIndices[surfIdx]]; const CCollisionEdge& e0 = x18_indexData.x40_edges[x18_indexData.x50_surfaceIndices[surfIdx]];
const CCollisionEdge& e1 = x18_indexData.x40_edges[x18_indexData.x50_surfaceIndices[surfIdx + 1]]; const CCollisionEdge& e1 = x18_indexData.x40_edges[x18_indexData.x50_surfaceIndices[surfIdx + 1]];
indicesOut[2] = (e1.GetVertIndex1() != e0.GetVertIndex1() && e1.GetVertIndex1() != e0.GetVertIndex2()) std::array<u16, 3> indices{};
indices[2] = (e1.GetVertIndex1() != e0.GetVertIndex1() && e1.GetVertIndex1() != e0.GetVertIndex2())
? e1.GetVertIndex1() ? e1.GetVertIndex1()
: e1.GetVertIndex2(); : e1.GetVertIndex2();
const u32 material = x18_indexData.x0_materials[x18_indexData.x30_surfaceMaterials[idx]]; const u32 material = x18_indexData.x0_materials[x18_indexData.x30_surfaceMaterials[idx]];
if ((material & 0x2000000) != 0) { if ((material & 0x2000000) != 0) {
indicesOut[0] = e0.GetVertIndex2(); indices[0] = e0.GetVertIndex2();
indicesOut[1] = e0.GetVertIndex1(); indices[1] = e0.GetVertIndex1();
} else { } else {
indicesOut[0] = e0.GetVertIndex1(); indices[0] = e0.GetVertIndex1();
indicesOut[1] = e0.GetVertIndex2(); indices[1] = e0.GetVertIndex2();
} }
return indices;
} }
CCollisionSurface COBBTree::GetTransformedSurface(u16 idx, const zeus::CTransform& xf) const { CCollisionSurface COBBTree::GetTransformedSurface(u16 idx, const zeus::CTransform& xf) const {

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -79,7 +80,10 @@ public:
const zeus::CVector3f&); const zeus::CVector3f&);
CCollisionSurface GetSurface(u16 idx) const; CCollisionSurface GetSurface(u16 idx) const;
const u16* GetTriangleEdgeIndices(u16 idx) const { return &x18_indexData.x50_surfaceIndices[idx * 3]; } const u16* GetTriangleEdgeIndices(u16 idx) const { return &x18_indexData.x50_surfaceIndices[idx * 3]; }
void GetTriangleVertexIndices(u16 idx, u16 indicesOut[3]) const;
// In the game binary, this used to use an out pointer for the indices after the index.
std::array<u16, 3> GetTriangleVertexIndices(u16 idx) const;
const CCollisionEdge& GetEdge(int idx) const { return x18_indexData.x40_edges[idx]; } const CCollisionEdge& GetEdge(int idx) const { return x18_indexData.x40_edges[idx]; }
const zeus::CVector3f& GetVert(int idx) const { return x18_indexData.x60_vertices[idx]; } const zeus::CVector3f& GetVert(int idx) const { return x18_indexData.x60_vertices[idx]; }
u32 GetVertMaterial(u16 idx) const { return x18_indexData.x0_materials[x18_indexData.x10_vertMaterials[idx]]; } u32 GetVertMaterial(u16 idx) const { return x18_indexData.x0_materials[x18_indexData.x10_vertMaterials[idx]]; }