Skip to content

Commit 4e7bcfa

Browse files
madebrfoxtacles
andauthored
Implement BoundingVolume0x64 (isledecomp#276)
* Implement BoundingVolume0x64 * Matches * format --------- Co-authored-by: Christian Semmler <mail@csemmler.com>
1 parent 4da5bff commit 4e7bcfa

6 files changed

Lines changed: 368 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ add_library(goldp SHARED
214214
GolDP/src/igdbmodelindexarray0x8.cpp
215215
GolDP/src/gdbmodelindexarray0xc.cpp
216216
GolDP/src/greyfalconnode0x1c.cpp
217+
GolDP/src/boundingvolume0x64.cpp
217218
util/decomp.cpp
218219
$<TARGET_OBJECTS:common_goldp>
219220
)

GolDP/include/boundingvolume0x64.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef BOUNDINGVOLUME0X64_H
2+
#define BOUNDINGVOLUME0X64_H
3+
4+
#include "decomp.h"
5+
#include "golmath.h"
6+
#include "goltxtparser.h"
7+
#include "shadowwolf0xc.h"
8+
#include "types.h"
9+
10+
class GdbVertexArray0xc;
11+
12+
// VTABLE: GOLDP 0x10056c48
13+
// SIZE 0xf1c
14+
class BvbTxtParser : public GolTxtParser {
15+
// SYNTHETIC: GOLDP 0x10030050 FOLDED
16+
// BvbTxtParser::`scalar deleting destructor'
17+
18+
// SYNTHETIC: GOLDP 0x1001b000 FOLDED
19+
// BvbTxtParser::~MdbTxtParser
20+
};
21+
22+
// VTABLE: GOLDP 0x10056c3c
23+
// SIZE 0x64
24+
class BoundingVolume0x64 {
25+
public:
26+
BoundingVolume0x64();
27+
28+
virtual ~BoundingVolume0x64(); // vtable+0x00
29+
virtual void VTable0x04(undefined4* p_arg1, const LegoChar* p_name, LegoBool32 p_binary); // vtable+0x04
30+
virtual void VTable0x08(); // vtable+0x08
31+
32+
// SYNTHETIC: GOLDP 0x1002e5e0
33+
// BoundingVolume0x64::`vector deleting destructor'
34+
35+
private:
36+
struct PolygonId0x08 {
37+
LegoU16 m_unk0x00;
38+
LegoU16 m_unk0x02;
39+
LegoU16 m_unk0x04;
40+
LegoU16 m_unk0x06;
41+
};
42+
struct PolygonRange0x14 {
43+
GolVec3 m_unk0x00;
44+
undefined2 m_unk0x0c;
45+
undefined2 m_unk0x0e;
46+
undefined2 m_unk0x10[2];
47+
};
48+
49+
void FUN_1001bb10(GolFileParser& p_parser);
50+
void FUN_1001bbb0(GolFileParser& p_parser);
51+
void FUN_1001bd00(GolFileParser& p_parser);
52+
undefined4 FUN_1001be50();
53+
54+
undefined4 m_unk0x04; // 0x04
55+
PolygonRange0x14* m_unk0x08; // 0x08
56+
GdbVertexArray0xc* m_unk0x0c; // 0x0c
57+
undefined4 m_unk0x10; // 0x10
58+
PolygonId0x08* m_unk0x14; // 0x14
59+
ShadowWolf0xc m_unk0x18; // 0x18
60+
ShadowWolf0xc* m_unk0x24; // 0x24
61+
undefined4 m_unk0x28; // 0x28
62+
GolVec3* m_unk0x2c; // 0x2c
63+
undefined m_unk0x30[0x64 - 0x30]; // 0x30
64+
};
65+
#endif // BOUNDINGVOLUME0X64_H

GolDP/include/zoweeblubberworth0xf0.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class AmberLensBase0x120;
1111
class AmberHaze0x1c;
1212
class BoundingShape0x2c;
13+
class BoundingVolume0x64;
1314
class CmbModelPart0x34;
1415
class GolFileParser;
1516
class FloatyBoat0x28;
@@ -203,7 +204,7 @@ class ZoweeBlubberworth0xf0 {
203204
LegoU32 m_unk0x8c; // 0x8c
204205
WdbLight0x10* m_unk0x90; // 0x90
205206
LegoFloat m_unk0x94; // 0x94
206-
undefined4 m_unk0x98; // 0x98
207+
BoundingVolume0x64* m_unk0x98; // 0x98
207208
undefined4 m_unk0x9c; // 0x9c
208209
undefined4 m_unk0xa0; // 0xa0
209210
LegoChar* m_unk0xa4; // 0xa4

GolDP/src/boundingvolume0x64.cpp

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
#include "boundingvolume0x64.h"
2+
3+
#include "gdbvertexarray0xc.h"
4+
#include "golbinparser.h"
5+
#include "golerror.h"
6+
7+
DECOMP_SIZE_ASSERT(BoundingVolume0x64, 0x64)
8+
9+
// FUNCTION: GOLDP 0x1001b770
10+
BoundingVolume0x64::BoundingVolume0x64() : m_unk0x24(&m_unk0x18)
11+
{
12+
m_unk0x04 = 0;
13+
m_unk0x08 = NULL;
14+
m_unk0x0c = NULL;
15+
m_unk0x10 = 0;
16+
m_unk0x14 = NULL;
17+
m_unk0x28 = 0;
18+
m_unk0x2c = NULL;
19+
}
20+
21+
// FUNCTION: GOLDP 0x1001b7b0
22+
BoundingVolume0x64::~BoundingVolume0x64()
23+
{
24+
VTable0x08();
25+
}
26+
27+
// FUNCTION: GOLDP 0x1001b800
28+
void BoundingVolume0x64::VTable0x04(undefined4* p_arg1, const LegoChar* p_name, LegoBool32 p_binary)
29+
{
30+
if (m_unk0x08 != NULL) {
31+
VTable0x08();
32+
}
33+
GolFileParser* parser;
34+
if (p_binary) {
35+
parser = new GolBinParser;
36+
if (parser == NULL) {
37+
GOL_FATALERROR(c_golErrorOutOfMemory);
38+
}
39+
parser->SetSuffix(".bvb");
40+
}
41+
else {
42+
parser = new BvbTxtParser;
43+
if (parser == NULL) {
44+
GOL_FATALERROR(c_golErrorOutOfMemory);
45+
}
46+
}
47+
parser->OpenFileForRead(p_name);
48+
GolFileParser::ParserTokenType token;
49+
while ((token = parser->GetNextToken()) != GolFileParser::e_syntaxerror) {
50+
switch (token) {
51+
case GolFileParser::e_unknown0x27:
52+
if (m_unk0x18.GetRenderer() != NULL) {
53+
parser->HandleUnexpectedToken(GolFileParser::e_unsuportedKeyword);
54+
}
55+
m_unk0x18.FUN_10025f90(reinterpret_cast<WhiteFalcon0x140*>(p_arg1), *parser);
56+
break;
57+
case GolFileParser::e_unknown0x34:
58+
if (m_unk0x0c != 0) {
59+
parser->HandleUnexpectedToken(GolFileParser::e_unsuportedKeyword);
60+
}
61+
m_unk0x0c = new GdbVertexArray0xc;
62+
if (m_unk0x0c == NULL) {
63+
GOL_FATALERROR(c_golErrorOutOfMemory);
64+
}
65+
m_unk0x0c->VTable0x08(*parser);
66+
break;
67+
case GolFileParser::e_unknown0x2d:
68+
FUN_1001bb10(*parser);
69+
break;
70+
case GolFileParser::e_unknown0x8b:
71+
FUN_1001bbb0(*parser);
72+
break;
73+
case GolFileParser::e_unknown0x8e:
74+
FUN_1001bd00(*parser);
75+
break;
76+
default:
77+
parser->HandleUnexpectedToken(GolFileParser::e_syntaxerror);
78+
}
79+
}
80+
if (m_unk0x04 != 0) {
81+
m_unk0x28 = FUN_1001be50();
82+
m_unk0x2c = new GolVec3[m_unk0x28];
83+
if (m_unk0x2c == NULL) {
84+
GOL_FATALERROR(c_golErrorOutOfMemory);
85+
}
86+
}
87+
parser->Dispose();
88+
if (parser != NULL) {
89+
delete parser;
90+
}
91+
}
92+
93+
// FUNCTION: GOLDP 0x1001ba90
94+
void BoundingVolume0x64::VTable0x08()
95+
{
96+
if (m_unk0x08 != NULL) {
97+
if (m_unk0x0c != NULL) {
98+
m_unk0x0c->VTable0x0c();
99+
if (m_unk0x0c != NULL) {
100+
delete m_unk0x0c;
101+
}
102+
}
103+
if (m_unk0x14 != NULL) {
104+
delete[] m_unk0x14;
105+
}
106+
if (m_unk0x08 != NULL) {
107+
delete[] m_unk0x08;
108+
}
109+
if (m_unk0x2c != NULL) {
110+
delete[] m_unk0x2c;
111+
}
112+
m_unk0x04 = 0;
113+
m_unk0x08 = NULL;
114+
m_unk0x0c = 0;
115+
m_unk0x10 = 0;
116+
m_unk0x14 = NULL;
117+
m_unk0x24 = &m_unk0x18;
118+
m_unk0x28 = 0;
119+
m_unk0x2c = NULL;
120+
}
121+
}
122+
123+
// FUNCTION: GOLDP 0x1001bb10
124+
void BoundingVolume0x64::FUN_1001bb10(GolFileParser& p_parser)
125+
{
126+
LegoU32 i;
127+
128+
m_unk0x10 = p_parser.ReadBracketedCountAndLeftCurly();
129+
if (m_unk0x10 == 0) {
130+
p_parser.HandleUnexpectedToken(GolFileParser::e_int);
131+
}
132+
m_unk0x14 = new PolygonId0x08[m_unk0x10];
133+
if (m_unk0x14 == NULL) {
134+
GOL_FATALERROR(c_golErrorOutOfMemory);
135+
}
136+
for (i = 0; i < m_unk0x10; i++) {
137+
m_unk0x14[i].m_unk0x00 = p_parser.ReadInteger();
138+
m_unk0x14[i].m_unk0x02 = p_parser.ReadInteger();
139+
m_unk0x14[i].m_unk0x04 = p_parser.ReadInteger();
140+
m_unk0x14[i].m_unk0x06 = p_parser.ReadInteger();
141+
}
142+
p_parser.ReadRightCurly();
143+
}
144+
145+
// FUNCTION: GOLDP 0x1001bbb0
146+
void BoundingVolume0x64::FUN_1001bbb0(GolFileParser& p_parser)
147+
{
148+
LegoU32 i;
149+
150+
m_unk0x04 = p_parser.ReadBracketedCountAndLeftCurly();
151+
if (m_unk0x04 == 0) {
152+
p_parser.HandleUnexpectedToken(GolFileParser::e_int);
153+
}
154+
m_unk0x08 = new PolygonRange0x14[m_unk0x04];
155+
if (m_unk0x08 == NULL) {
156+
GOL_FATALERROR(c_golErrorOutOfMemory);
157+
}
158+
for (i = 0; i < m_unk0x04; i++) {
159+
LegoU32 j;
160+
for (j = 0; j < 2; j++) {
161+
switch (p_parser.GetNextToken()) {
162+
case GolFileParser::e_unknown0x8d:
163+
m_unk0x08[i].m_unk0x10[j] = -2;
164+
break;
165+
case GolFileParser::e_unknown0x8c:
166+
m_unk0x08[i].m_unk0x10[j] = -1;
167+
break;
168+
case GolFileParser::e_int:
169+
m_unk0x08[i].m_unk0x10[j] = p_parser.GetLastInt();
170+
break;
171+
default:
172+
p_parser.HandleUnexpectedToken(GolFileParser::e_syntaxerror);
173+
break;
174+
}
175+
}
176+
GolVec4 v;
177+
v.m_x = p_parser.ReadFloat();
178+
v.m_y = p_parser.ReadFloat();
179+
v.m_z = p_parser.ReadFloat();
180+
v.m_u = p_parser.ReadFloat();
181+
GolVec3* ptrVec = &m_unk0x08[i].m_unk0x00;
182+
ptrVec->m_x = v.m_x;
183+
ptrVec->m_y = v.m_y;
184+
ptrVec->m_z = v.m_z;
185+
m_unk0x08[i].m_unk0x0c = p_parser.ReadInteger();
186+
m_unk0x08[i].m_unk0x0e = p_parser.ReadInteger();
187+
}
188+
p_parser.ReadRightCurly();
189+
}
190+
191+
// FUNCTION: GOLDP 0x1001bd00
192+
void BoundingVolume0x64::FUN_1001bd00(GolFileParser& p_parser)
193+
{
194+
LegoU32 i;
195+
196+
m_unk0x04 = p_parser.ReadBracketedCountAndLeftCurly();
197+
if (m_unk0x04 == 0) {
198+
p_parser.HandleUnexpectedToken(GolFileParser::e_int);
199+
}
200+
m_unk0x08 = new PolygonRange0x14[m_unk0x04];
201+
if (m_unk0x08 == NULL) {
202+
GOL_FATALERROR(c_golErrorOutOfMemory);
203+
}
204+
for (i = 0; i < m_unk0x04; i++) {
205+
LegoU32 j;
206+
for (j = 0; j < 2; j++) {
207+
LegoS32 v = p_parser.ReadInteger();
208+
if (v < 0) {
209+
if (v == -1) {
210+
m_unk0x08[i].m_unk0x10[j] = -1;
211+
}
212+
else if (v == -2) {
213+
m_unk0x08[i].m_unk0x10[j] = -2;
214+
}
215+
else {
216+
p_parser.HandleUnexpectedToken(GolFileParser::e_syntaxerror);
217+
}
218+
}
219+
else {
220+
m_unk0x08[i].m_unk0x10[j] = v;
221+
}
222+
}
223+
int i3[3];
224+
i3[0] = p_parser.ReadInteger();
225+
i3[1] = p_parser.ReadInteger();
226+
i3[2] = p_parser.ReadInteger();
227+
GolVec3* ptrVec = &m_unk0x08[i].m_unk0x00;
228+
ptrVec->m_x = static_cast<float>(i3[0]) / static_cast<float>(0x40000000);
229+
ptrVec->m_y = static_cast<float>(i3[1]) / static_cast<float>(0x40000000);
230+
ptrVec->m_z = static_cast<float>(i3[2]) / static_cast<float>(0x40000000);
231+
m_unk0x08[i].m_unk0x0c = p_parser.ReadInteger();
232+
m_unk0x08[i].m_unk0x0e = p_parser.ReadInteger();
233+
}
234+
p_parser.ReadRightCurly();
235+
}
236+
237+
// FUNCTION: GOLDP 0x1001be50
238+
undefined4 BoundingVolume0x64::FUN_1001be50()
239+
{
240+
LegoU16* stack = new LegoU16[m_unk0x04];
241+
if (stack == NULL) {
242+
GOL_FATALERROR(c_golErrorOutOfMemory);
243+
}
244+
245+
LegoU32 index = 0;
246+
LegoU32 maxStackSize = 0;
247+
LegoU32 stackSize = 0;
248+
LegoU32 prevIndex = 0;
249+
*stack = 0;
250+
LegoU16* stackHead = stack;
251+
252+
for (;;) {
253+
PolygonRange0x14* obj = &m_unk0x08[index];
254+
if (stackSize > maxStackSize) {
255+
maxStackSize = stackSize;
256+
}
257+
258+
LegoU32 rightIndex = obj->m_unk0x10[1];
259+
if (prevIndex != rightIndex) {
260+
LegoU32 leftIndex = obj->m_unk0x10[0];
261+
if (prevIndex != leftIndex && leftIndex != 0xffff && leftIndex != 0xfffe) {
262+
stackSize++;
263+
stackHead++;
264+
prevIndex = index;
265+
index = leftIndex;
266+
*stackHead = leftIndex;
267+
continue;
268+
}
269+
if (rightIndex != 0xffff && rightIndex != 0xfffe) {
270+
stackSize++;
271+
stackHead++;
272+
prevIndex = index;
273+
index = rightIndex;
274+
*stackHead = rightIndex;
275+
continue;
276+
}
277+
}
278+
279+
if (stackSize < 1) {
280+
break;
281+
}
282+
prevIndex = index;
283+
stackSize--;
284+
stackHead--;
285+
index = *stackHead;
286+
}
287+
delete[] stack;
288+
return maxStackSize + 1;
289+
}

0 commit comments

Comments
 (0)