Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mmBoundTemplate::ComputeEdges() #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions code/midtown/mmdyna/bndtmpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code allocates 4 * total_verts bytes, which is just total_verts ints.

i32* edge_2s = new i32[4 * total_verts];

i32 num_edges = 0;

for (i32 j = 0; j < NumPolys; ++j)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use i, since the previous one isn't used at this point.

{
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);
Comment on lines +54 to +55
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's doing poly.VertIndices[num_verts - 1] (MtlIndex is stored 2 bytes before the VertIndices)


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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather move the num_edges++ to a separate line after, since multiple things rely on it in this branch.

}

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()
{}
Expand Down
4 changes: 2 additions & 2 deletions code/midtown/mmdyna/bndtmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions code/midtown/mmdyna/bndtmpl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion code/midtown/mmdyna/bndtmpl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions code/midtown/mmdyna/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down