From f70dd96ade1bcc8d329f8e50116c5f3bbc9b8d27 Mon Sep 17 00:00:00 2001 From: Robin Kisman <99972691+KcRobin9@users.noreply.github.com> Date: Sat, 23 Mar 2024 14:28:04 +0100 Subject: [PATCH] Implement mmBoundTemplate::ComputeEdges() Unsure about the line: `v1 = *((__int16 *)&this->Polygons[j + 1].MtlIndex + num_verts);` --- code/midtown/mmdyna/bndtmpl.cpp | 68 ++++++++++++++++++++++++++++++++ code/midtown/mmdyna/bndtmpl.h | 4 +- code/midtown/mmdyna/bndtmpl2.cpp | 13 ++++++ code/midtown/mmdyna/bndtmpl2.h | 2 +- code/midtown/mmdyna/poly.h | 10 +++++ 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/code/midtown/mmdyna/bndtmpl.cpp b/code/midtown/mmdyna/bndtmpl.cpp index f94b32a1..8920d38d 100644 --- a/code/midtown/mmdyna/bndtmpl.cpp +++ b/code/midtown/mmdyna/bndtmpl.cpp @@ -20,6 +20,74 @@ define_dummy_symbol(mmdyna_bndtmpl); #include "bndtmpl.h" +#include "vector7/geomath.h" + +#include "bndtmpl2.h" +#include "poly.h" + +void mmBoundTemplate::ComputeBounds() +{ + GetBoundInfo(NumVerts, Verts, &BBMin, &BBMax, &Center, &Radius); + RadiusSqr = Radius * Radius; +} + +void mmBoundTemplate::ComputeEdges() +{ + i32 total_verts = 0; + + for (i32 i = 0; i < NumPolys; ++i) + { + total_verts += Polygons[i].GetNumVerts(); + } + + i32* edge_1s = new i32[4 * total_verts]; + i32* edge_2s = new i32[4 * total_verts]; + + i32 num_edges = 0; + + for (i32 j = 0; j < NumPolys; ++j) + { + mmPolygon& poly = Polygons[j + 1]; + + i32 num_verts = poly.GetNumVerts(); + + i32 v1 = poly.MtlIndex + num_verts; // ? + // Original line: v1 = *((__int16 *)&this->Polygons[j + 1].MtlIndex + num_verts); + + for (i32 k = 0; k < num_verts; ++k) + { + i32 v2 = poly.VertIndices[k]; + + if (!EdgeInList(v1, v2, num_edges, edge_1s, edge_2s)) + { + edge_1s[num_edges] = v1; + edge_2s[num_edges++] = v2; + } + + v1 = v2; + } + } + + if (num_edges) + { + EdgeVerts1 = new u32[4 * num_edges]; + EdgeVerts2 = new u32[4 * num_edges]; + HotVerts = Verts; + NumHotVerts2 = NumVerts; + + for (i32 m = 0; m < num_edges; ++m) + { + EdgeVerts1[m] = edge_1s[m]; + EdgeVerts2[m] = edge_2s[m]; + } + + NumEdges = num_edges; + } + + delete[] edge_1s; + delete[] edge_2s; +} + #ifdef ARTS_DEV_BUILD void mmBoundTemplate::DrawGraph() {} diff --git a/code/midtown/mmdyna/bndtmpl.h b/code/midtown/mmdyna/bndtmpl.h index 4317b209..dc883727 100644 --- a/code/midtown/mmdyna/bndtmpl.h +++ b/code/midtown/mmdyna/bndtmpl.h @@ -107,13 +107,13 @@ class mmBoundTemplate ARTS_IMPORT i32 CollideTerrains(mmBoundTemplate** arg1, Matrix34& arg2, mmEdgeBodyIsect* arg3, i32 arg4, i32 arg5); // ?ComputeBounds@mmBoundTemplate@@QAEXXZ | mmdyna:bndtmpl2 - ARTS_IMPORT void ComputeBounds(); + ARTS_EXPORT void ComputeBounds(); // ?ComputeEdgeNormals@mmBoundTemplate@@QAEXXZ | mmdyna:bndtmpl2 ARTS_IMPORT void ComputeEdgeNormals(); // ?ComputeEdges@mmBoundTemplate@@QAEXXZ | mmdyna:bndtmpl2 - ARTS_IMPORT void ComputeEdges(); + ARTS_EXPORT void ComputeEdges(); #ifdef ARTS_DEV_BUILD // ?Draw@mmBoundTemplate@@QAEXXZ diff --git a/code/midtown/mmdyna/bndtmpl2.cpp b/code/midtown/mmdyna/bndtmpl2.cpp index 91838b1e..d858b07f 100644 --- a/code/midtown/mmdyna/bndtmpl2.cpp +++ b/code/midtown/mmdyna/bndtmpl2.cpp @@ -19,3 +19,16 @@ define_dummy_symbol(mmdyna_bndtmpl2); #include "bndtmpl2.h" + +b32 EdgeInList(i32 v1, i32 v2, ilong count, i32* edge_1s, i32* edge_2s) +{ + for (i32 i = 0; i < count; ++i) + { + if ((v1 == edge_1s[i] && v2 == edge_2s[i]) || (v1 == edge_2s[i] && v2 == edge_1s[i])) + { + return true; + } + } + + return false; +} \ No newline at end of file diff --git a/code/midtown/mmdyna/bndtmpl2.h b/code/midtown/mmdyna/bndtmpl2.h index 273ebc98..c4a425fe 100644 --- a/code/midtown/mmdyna/bndtmpl2.h +++ b/code/midtown/mmdyna/bndtmpl2.h @@ -51,7 +51,7 @@ */ // ?EdgeInList@@YA_NHHJPAH0@Z -ARTS_IMPORT bool EdgeInList(i32 arg1, i32 arg2, ilong arg3, i32* arg4, i32* arg5); +ARTS_EXPORT b32 EdgeInList(i32 v1, i32 v2, ilong count, i32* edge_1s, i32* edge_2s); // ?BoundBytesPaged@@3HA ARTS_IMPORT extern i32 BoundBytesPaged; diff --git a/code/midtown/mmdyna/poly.h b/code/midtown/mmdyna/poly.h index b9932346..c9fa1cb4 100644 --- a/code/midtown/mmdyna/poly.h +++ b/code/midtown/mmdyna/poly.h @@ -102,6 +102,16 @@ class mmPolygon ARTS_IMPORT void PlotTriangle(i32 arg1, i32 arg2, i32 arg3, mmBoundTemplate* arg4, i32 arg5); public: + i32 GetNumVerts() const + { + return IsQuad() ? 4 : 3; + } + + b32 IsQuad() const + { + return (Flags & 4) != 0; + } + u16 RoomId; u8 MtlIndex;