@@ -120,104 +120,109 @@ void IGdbModel0x40::VTable0x24()
120120void IGdbModel0x40::VTable0x00 (GolFileParser& p_parser)
121121{
122122 m_unk0x20 = p_parser.ReadBracketedCountAndLeftCurly ();
123+ LegoU32 count = 0 ;
123124 if (m_unk0x20 == 0 ) {
124125 p_parser.HandleUnexpectedToken (GolFileParser::e_int);
125126 }
126127 m_unk0x24 = new LegoU32[m_unk0x20];
127128 if (m_unk0x24 == NULL ) {
128129 GOL_FATALERROR (c_golErrorOutOfMemory);
129130 }
130- LegoS32 count = 0 ;
131- LegoU32 stackSize = 0 ;
132- LegoBool32 seen = FALSE ;
133131 LegoU32 field0;
134132 LegoU32 field1;
135133 LegoU32 field2;
136134 LegoU32 colorStack[10 ];
137- LegoU32* colorStackPointer = colorStack;
138135 LegoU32 i;
139- for (i = 0 ; i < m_unk0x20; i++) {
140- switch (p_parser.GetNextToken ()) {
141- case GolFileParser::e_unknown0x31:
142- if (seen) {
143- count += 1 ;
144- seen = FALSE ;
145- }
146- field1 = p_parser.ReadInteger ();
147- if (field1 >= 0x40 ) {
148- p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
149- }
150- field0 = p_parser.ReadInteger ();
151- field2 = p_parser.ReadInteger ();
152- if (field2 + field1 > 0x40 ) {
153- p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
154- }
155- m_unk0x24[count] = 0x0 << 28 ;
156- m_unk0x24[count] |= (field1 & 0x3f ) << 22 ;
157- m_unk0x24[count] |= ((field2 + 0xffff ) & 0x3f ) << 16 ;
158- m_unk0x24[count++] |= (field0 & 0xffff );
159- break ;
136+ LegoU32 stackSize;
137+ LegoBool32 seen;
138+ LegoU32* colorStackPointer;
160139
161- case GolFileParser::e_unknown0x2d:
162- if (seen) {
163- count += 1 ;
164- seen = FALSE ;
165- }
166- field0 = p_parser.ReadInteger ();
167- field1 = p_parser.ReadInteger ();
168- if (field1 > 0xff ) {
169- p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
170- }
171- m_unk0x24[count] = 0x2 << 28 ;
172- m_unk0x24[count] |= ((field1 & 0x7f ) << 16 );
173- m_unk0x24[count++] |= (field0 & 0xffff );
174- break ;
140+ if ((stackSize = 0 , i = count, seen = FALSE , i < m_unk0x20)) {
141+ colorStackPointer = colorStack;
142+ for (; i < m_unk0x20; i++) {
143+ switch (p_parser.GetNextToken ()) {
144+ case GolFileParser::e_unknown0x31:
145+ if (seen) {
146+ count += 1 ;
147+ seen = FALSE ;
148+ }
149+ field1 = p_parser.ReadInteger ();
150+ if (field1 >= 0x40 ) {
151+ p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
152+ }
153+ field0 = p_parser.ReadInteger ();
154+ field2 = p_parser.ReadInteger ();
155+ if (field2 + field1 > 0x40 ) {
156+ p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
157+ }
158+ m_unk0x24[count] = 0x0 << 28 ;
159+ m_unk0x24[count] |= (field1 & 0x3f ) << 22 ;
160+ m_unk0x24[count] |= ((field2 + 0xffff ) & 0x3f ) << 16 ;
161+ m_unk0x24[count++] |= (field0 & 0xffff );
162+ break ;
175163
176- case GolFileParser::e_unknown0x2f:
177- field1 = p_parser.ReadInteger ();
178- if (stackSize >= sizeOfArray (colorStack)) {
179- p_parser.HandleUnexpectedToken (GolFileParser::e_unsuportedKeyword);
180- }
181- seen = TRUE ;
182- stackSize += 1 ;
183- *colorStackPointer++ = field1;
184- m_unk0x24[count] = 0xa << 28 ;
185- m_unk0x24[count] |= field1 & 0xffffff ;
186- break ;
164+ case GolFileParser::e_unknown0x2d:
165+ if (seen) {
166+ count += 1 ;
167+ seen = FALSE ;
168+ }
169+ field0 = p_parser.ReadInteger ();
170+ field1 = p_parser.ReadInteger ();
171+ if (field1 > 0xff ) {
172+ p_parser.HandleUnexpectedToken (GolFileParser::e_unsuported);
173+ }
174+ m_unk0x24[count] = 0x2 << 28 ;
175+ m_unk0x24[count] |= ((field1 & 0x7f ) << 16 );
176+ m_unk0x24[count++] |= (field0 & 0xffff );
177+ break ;
187178
188- case GolFileParser::e_unknown0x30:
189- if (stackSize == 0 ) {
190- p_parser.HandleUnexpectedToken (GolFileParser::e_unsuportedKeyword);
191- }
192- stackSize -= 1 ;
193- seen = TRUE ;
194- m_unk0x24[count] = 0xa << 28 ;
195- m_unk0x24[count] |= colorStackPointer[-2 ] & 0xffffff ;
196- colorStackPointer--;
197- break ;
179+ case GolFileParser::e_unknown0x2f:
180+ field1 = p_parser.ReadInteger ();
181+ if (stackSize >= sizeOfArray (colorStack)) {
182+ p_parser.HandleUnexpectedToken (GolFileParser::e_unsuportedKeyword);
183+ }
184+ seen = TRUE ;
185+ stackSize += 1 ;
186+ *colorStackPointer++ = field1;
187+ m_unk0x24[count] = 0xa << 28 ;
188+ m_unk0x24[count] |= field1 & 0xffffff ;
189+ break ;
198190
199- case GolFileParser::e_unknown0x32:
200- field1 = p_parser.ReadInteger ();
201- seen = TRUE ;
202- m_unk0x24[count] = 0xa << 28 ;
203- m_unk0x24[count] |= field1 & 0xffffff ;
204- break ;
191+ case GolFileParser::e_unknown0x30:
192+ if (stackSize < 1 ) {
193+ p_parser.HandleUnexpectedToken (GolFileParser::e_unsuportedKeyword);
194+ }
195+ stackSize -= 1 ;
196+ seen = TRUE ;
197+ m_unk0x24[count] = 0xa << 28 ;
198+ colorStackPointer--;
199+ m_unk0x24[count] |= colorStackPointer[-1 ] & 0xffffff ;
200+ break ;
205201
206- case GolFileParser::e_unknown0x27:
207- if (seen) {
208- count += 1 ;
209- seen = FALSE ;
210- }
211- field0 = p_parser.ReadInteger ();
212- m_unk0x24[count] = 0x8 << 28 ;
213- m_unk0x24[count++] |= (field0 & 0x00ffffff );
214- break ;
202+ case GolFileParser::e_unknown0x32:
203+ field1 = p_parser.ReadInteger ();
204+ seen = TRUE ;
205+ m_unk0x24[count] = 0xa << 28 ;
206+ m_unk0x24[count] |= field1 & 0xffffff ;
207+ break ;
215208
216- default :
217- p_parser.HandleUnexpectedToken (GolFileParser::e_syntaxerror);
218- break ;
209+ case GolFileParser::e_unknown0x27:
210+ if (seen) {
211+ count += 1 ;
212+ seen = FALSE ;
213+ }
214+ field0 = p_parser.ReadInteger ();
215+ m_unk0x24[count] = 0x8 << 28 ;
216+ m_unk0x24[count++] |= (field0 & 0x00ffffff );
217+ break ;
218+
219+ default :
220+ p_parser.HandleUnexpectedToken (GolFileParser::e_syntaxerror);
221+ break ;
222+ }
219223 }
220224 }
225+
221226 if (p_parser.GetNextToken () != GolFileParser::e_rightCurly) {
222227 p_parser.HandleUnexpectedToken (GolFileParser::e_rightCurly);
223228 }
@@ -287,7 +292,6 @@ void IGdbModel0x40::VTable0x14(GolFileParser& p_parser)
287292// FUNCTION: GOLDP 0x100278c0
288293void IGdbModel0x40::VTable0x38 (GolVec3* p_center, LegoFloat* p_radius, LegoFloat p_scale) const
289294{
290- LegoFloat radiusSquared;
291295 LegoU32 countGroups;
292296 GolVec3 vertex;
293297 GolVec3 max;
@@ -337,10 +341,11 @@ void IGdbModel0x40::VTable0x38(GolVec3* p_center, LegoFloat* p_radius, LegoFloat
337341 }
338342 }
339343 if (countGroups != 0 ) {
340- radiusSquared = -FLT_MAX ;
341- p_center->m_x = (max.m_x + min.m_x ) / 2 .0f ;
342- p_center->m_y = (max.m_y + min.m_y ) / 2 .0f ;
343- p_center->m_z = (max.m_z + min.m_z ) / 2 .0f ;
344+ GolVec3* center = p_center;
345+ center->m_x = (max.m_x + min.m_x ) / 2 .0f ;
346+ center->m_y = (max.m_y + min.m_y ) / 2 .0f ;
347+ center->m_z = (max.m_z + min.m_z ) / 2 .0f ;
348+ LegoFloat radiusSquared = -FLT_MAX ;
344349 maskPtr = m_unk0x24;
345350 endMaskPtr = m_unk0x24 + m_unk0x20;
346351 for (; maskPtr < endMaskPtr; maskPtr++) {
@@ -350,7 +355,7 @@ void IGdbModel0x40::VTable0x38(GolVec3* p_center, LegoFloat* p_radius, LegoFloat
350355 LegoU32 endVertexIndex = vertexIndex + 1 + ((mask >> 16 ) & 0x3f );
351356 for (; vertexIndex < endVertexIndex; vertexIndex++) {
352357 m_unk0x10->VTable0x14 (vertexIndex, &vertex);
353- LegoFloat distSquared = p_center ->DistanceSquaredTo (vertex);
358+ LegoFloat distSquared = center ->DistanceSquaredTo (vertex);
354359 if (distSquared > radiusSquared) {
355360 radiusSquared = distSquared;
356361 }
@@ -360,7 +365,11 @@ void IGdbModel0x40::VTable0x38(GolVec3* p_center, LegoFloat* p_radius, LegoFloat
360365 break ;
361366 }
362367 }
363- *p_center *= p_scale;
368+ center->m_x = p_scale * center->m_x ;
369+ LegoFloat y = center->m_y ;
370+ center->m_y = y * p_scale;
371+ LegoFloat z = center->m_z ;
372+ center->m_z = z * p_scale;
364373 *p_radius = static_cast <LegoFloat>(sqrt (radiusSquared)) * p_scale;
365374 }
366375}
0 commit comments