Mercurial > mm7
annotate Sprites.cpp @ 2462:1d04e48651d4
Render split into interface and realization, added Direct3D 11
author | a.parshin |
---|---|
date | Tue, 12 Aug 2014 21:34:18 +0300 |
parents | ed1e4cff79a2 |
children | b054ea5daf45 |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2207
diff
changeset
|
5 #define _CRT_SECURE_NO_WARNINGS |
0 | 6 #include <string.h> |
1017 | 7 #include <algorithm> |
2336 | 8 #include "ErrorHandling.h" |
0 | 9 |
10 #include "Sprites.h" | |
11 #include "PaletteManager.h" | |
12 #include "LOD.h" | |
13 #include "FrameTableInc.h" | |
14 | |
15 #include "mm7_data.h" | |
1295 | 16 #include "Outdoor.h" |
17 #include "DecorationList.h" | |
18 #include "MM7.h" | |
19 #include "Actor.h" | |
1828
35c1e4ff6ba7
party_finds_gold to Party::PartyFindsGold, cleaned up, moved Level/Decoration.h reference out of Indoor.h
Grumpy7
parents:
1583
diff
changeset
|
20 #include "Level/Decoration.h" |
2207 | 21 #include "OurMath.h" |
0 | 22 |
23 | |
24 | |
25 struct SpriteFrameTable *pSpriteFrameTable; | |
26 | |
27 | |
28 | |
29 | |
30 //----- (0044D4D8) -------------------------------------------------------- | |
31 void SpriteFrameTable::ReleaseSFrames() | |
32 { | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2340
diff
changeset
|
33 free(this->pSpriteSFrames); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2340
diff
changeset
|
34 this->pSpriteSFrames = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2340
diff
changeset
|
35 this->uNumSpriteFrames = 0; |
0 | 36 } |
37 | |
38 //----- (0044D4F6) -------------------------------------------------------- | |
39 void SpriteFrameTable::ResetSomeSpriteFlags() | |
40 { | |
41 int v1; // esi@1 | |
42 signed int i; // edx@1 | |
43 char *v3; // eax@2 | |
44 | |
45 v1 = 0; | |
46 for ( i = 0; i < (signed int)this->uNumSpriteFrames; ++i ) | |
47 { | |
48 v3 = (char *)&this->pSpriteSFrames[v1].uFlags; | |
49 ++v1; | |
50 *v3 &= 0x7Fu; | |
51 } | |
52 } | |
53 | |
54 //----- (0044D513) -------------------------------------------------------- | |
670 | 55 void SpriteFrameTable::InitializeSprite( signed int uSpriteID ) |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
56 { |
670 | 57 //SpriteFrameTable *v2; // esi@1 |
58 unsigned int v3; // ebx@3 | |
59 //char *v4; // edx@3 | |
60 //int v5; // eax@3 | |
2334 | 61 // SpriteFrame *v6; // ecx@5 |
62 // int v7; // eax@5 | |
670 | 63 __int16 v8; // ax@6 |
64 //signed int v9; // edx@6 | |
65 //int v10; // ecx@6 | |
2334 | 66 // signed int v11; // edi@10 |
670 | 67 __int16 v12; // ax@16 |
2334 | 68 // int v13; // ecx@16 |
670 | 69 size_t v14; // eax@19 |
2334 | 70 // signed int v15; // edi@19 |
71 // __int16 v16; // ax@27 | |
72 // int v17; // ecx@27 | |
73 // signed int v18; // edi@29 | |
74 // SpriteFrame *v19; // eax@30 | |
75 // __int16 v20; // ax@45 | |
76 // int v21; // ecx@45 | |
0 | 77 |
670 | 78 char Str[32]; // [sp+Ch] [bp-3Ch]@19 |
79 char sprite_name[20]; // [sp+2Ch] [bp-1Ch]@15 | |
80 char Source[4]; // [sp+40h] [bp-8h]@19 | |
0 | 81 |
82 | |
670 | 83 //v2 = this; |
84 if ( uSpriteID <= this->uNumSpriteFrames ) | |
0 | 85 { |
670 | 86 if ( uSpriteID >= 0 ) |
0 | 87 { |
670 | 88 v3 = uSpriteID; |
89 | |
1980 | 90 int uFlags = pSpriteSFrames[v3].uFlags; |
670 | 91 if (!(uFlags & 0x0080)) //not loaded |
92 { | |
93 pSpriteSFrames[v3].uFlags |= 0x80; //set loaded | |
94 while ( 1 ) | |
95 { | |
96 pSpriteSFrames[v3].uPaletteIndex = pPaletteManager->LoadPalette(pSpriteSFrames[v3].uPaletteID); | |
97 if ( uFlags & 0x10 ) //single frame per frame sequence | |
98 { | |
99 v8 = pSprites_LOD->LoadSprite(pSpriteSFrames[v3].pTextureName, pSpriteSFrames[v3].uPaletteID); | |
100 for (uint i = 0; i < 8; ++i) | |
101 { | |
102 | |
103 pSpriteSFrames[v3].pHwSpriteIDs[i] = v8; | |
104 } | |
105 | |
106 } | |
107 else if ( uFlags & 0x10000 ) | |
108 { | |
109 for (uint i = 0; i < 8; ++i) | |
110 { | |
111 switch ( i ) | |
112 { | |
113 case 3: | |
114 case 4: | |
115 case 5: | |
116 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName); | |
117 break; | |
118 case 2: | |
119 case 6: | |
120 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
121 break; | |
122 case 0: | |
123 case 1: | |
124 case 7: | |
125 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName); | |
126 break; | |
127 } | |
128 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
129 | |
130 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
131 } | |
132 | |
133 } | |
134 else if ( uFlags & 0x40 ) //part of monster fidgeting seq | |
135 { | |
136 strcpy(Source, "stA"); | |
137 strcpy(Str, pSpriteSFrames[v3].pTextureName); | |
138 v14 = strlen(Str); | |
139 strcpy(&Str[v14-3], Source); | |
140 for (uint i = 0; i < 8; ++i) | |
141 { | |
142 switch ( i ) | |
143 { | |
144 case 0: | |
145 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName); | |
146 break; | |
147 case 4: | |
148 sprintf(sprite_name, "%s4",&Str ); | |
149 break; | |
150 case 3: | |
151 case 5: | |
152 sprintf(sprite_name, "%s3",&Str ); | |
153 break; | |
154 case 2: | |
155 case 6: | |
156 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
157 break; | |
158 case 1: | |
159 case 7: | |
160 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName); | |
161 break; | |
162 } | |
163 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
164 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
165 } | |
166 } | |
167 | |
168 else | |
169 { | |
170 for (uint i = 0; i < 8; ++i) | |
171 | |
172 { | |
173 | |
174 if (((0x0100 << i) & pSpriteSFrames[v3].uFlags) ) //mirrors | |
175 { | |
176 switch ( i ) | |
177 { | |
178 case 1: | |
179 sprintf(sprite_name, "%s7", pSpriteSFrames[v3].pTextureName); | |
180 break; | |
181 case 2: | |
182 sprintf(sprite_name, "%s6", pSpriteSFrames[v3].pTextureName); | |
183 break; | |
184 case 3: | |
185 sprintf(sprite_name, "%s5", pSpriteSFrames[v3].pTextureName); | |
186 break; | |
187 case 4: | |
188 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName); | |
189 break; | |
190 | |
191 case 5: | |
192 sprintf(sprite_name, "%s3", pSpriteSFrames[v3].pTextureName); | |
193 break; | |
194 | |
195 case 6: | |
196 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
197 break; | |
198 case 7: | |
199 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName); | |
200 break; | |
201 } | |
202 } | |
203 else | |
204 { | |
205 sprintf(sprite_name, "%s%i", pSpriteSFrames[v3].pTextureName, i); | |
206 | |
207 } | |
208 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
209 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
210 | |
211 } | |
212 } | |
213 | |
214 if ( !(pSpriteSFrames[v3].uFlags & 1) ) | |
215 return; | |
216 ++v3; | |
217 } | |
218 } | |
219 } | |
0 | 220 } |
221 } | |
222 | |
223 //----- (0044D813) -------------------------------------------------------- | |
670 | 224 signed int SpriteFrameTable::FastFindSprite( char *pSpriteName ) |
1017 | 225 { |
670 | 226 signed int result; // eax@2 |
0 | 227 |
1017 | 228 int searchResult = BinarySearch(pSpriteName); |
229 if ( searchResult < 0 ) | |
0 | 230 result = 0; |
231 else | |
1017 | 232 result = this->pSpriteEFrames[searchResult]; |
0 | 233 return result; |
234 } | |
235 | |
236 //----- (0044D83A) -------------------------------------------------------- | |
1017 | 237 int SpriteFrameTable::BinarySearch( const char *pSpriteName ) |
0 | 238 { |
1017 | 239 int startPos = 0; |
240 int endPos = uNumEFrames; | |
241 while ( 1 ) | |
0 | 242 { |
1017 | 243 int searchRange = endPos - startPos; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
244 int middleFrameIndex = startPos + (endPos - startPos) / 2; |
1017 | 245 int comparisonResult = _stricmp(pSpriteName, this->pSpritePFrames[middleFrameIndex]->pIconName); |
246 if ( !comparisonResult ) | |
0 | 247 { |
1017 | 248 return middleFrameIndex; |
249 } | |
250 if ( startPos == endPos ) | |
251 { | |
252 return -1; | |
0 | 253 } |
1017 | 254 if ( comparisonResult >= 0 ) |
255 { | |
256 startPos += max(((endPos - startPos) / 2), 1); | |
257 } | |
258 else{ | |
259 endPos = max(((endPos - startPos) / 2), 1) + startPos; | |
260 } | |
0 | 261 } |
262 } | |
263 | |
264 //----- (0044D8D0) -------------------------------------------------------- | |
639 | 265 SpriteFrame *SpriteFrameTable::GetFrame(unsigned int uSpriteID, unsigned int uTime) |
0 | 266 { |
639 | 267 //SpriteFrame *v3; // edi@1 |
0 | 268 SpriteFrame *v4; // ecx@1 |
639 | 269 //__int16 v5; // dx@2 |
270 //int v6; // edx@3 | |
271 //unsigned int v7; // eax@3 | |
272 //char *i; // ecx@3 | |
273 //int v9; // esi@5 | |
274 //SpriteFrame *result; // eax@6 | |
0 | 275 |
639 | 276 v4 = &pSpriteSFrames[uSpriteID]; |
277 if (~v4->uFlags & 1 || !v4->uAnimLength) | |
278 return pSpriteSFrames + uSpriteID; | |
279 | |
280 for (uint t = (uTime / 8) % v4->uAnimLength; t > v4->uAnimTime; ++v4) | |
281 t -= v4->uAnimTime; | |
282 return v4; | |
283 | |
284 /*for (v4; v4->uAnimTime <= t; ++v4) | |
285 | |
286 v6 = (uTime / 8) % v4->uAnimLength; | |
287 //v7 = uSpriteID; | |
0 | 288 for ( i = (char *)&v4->uAnimTime; ; i += 60 ) |
289 { | |
290 v9 = *(short *)i; | |
291 if ( v6 <= v9 ) | |
292 break; | |
293 v6 -= v9; | |
294 ++v7; | |
295 } | |
639 | 296 return &pSpriteSFrames[v7];*/ |
297 | |
0 | 298 } |
299 | |
300 //----- (0044D91F) -------------------------------------------------------- | |
301 SpriteFrame *SpriteFrameTable::GetFrameBy_x(unsigned int uSpriteID, signed int a3) | |
302 { | |
303 SpriteFrame *v3; // edi@1 | |
304 SpriteFrame *v4; // esi@1 | |
305 __int16 v5; // ax@2 | |
306 int v6; // ecx@3 | |
307 int v7; // edx@3 | |
308 unsigned int v8; // eax@3 | |
309 int v9; // ecx@3 | |
310 char *i; // edx@3 | |
311 int v11; // esi@5 | |
312 SpriteFrame *result; // eax@6 | |
313 | |
314 v3 = this->pSpriteSFrames; | |
315 v4 = &v3[uSpriteID]; | |
316 if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 ) | |
317 { | |
318 v6 = v5; | |
319 v7 = a3 % v5; | |
320 v8 = uSpriteID; | |
321 v9 = v6 - v7; | |
322 for ( i = (char *)&v4->uAnimTime; ; i += 60 ) | |
323 { | |
324 v11 = *(short *)i; | |
325 if ( v9 <= v11 ) | |
326 break; | |
327 v9 -= v11; | |
328 ++v8; | |
329 } | |
330 result = &v3[v8]; | |
331 } | |
332 else | |
333 { | |
334 result = &v3[uSpriteID]; | |
335 } | |
336 return result; | |
337 } | |
338 | |
339 //----- (0044D96D) -------------------------------------------------------- | |
340 void SpriteFrameTable::ToFile() | |
341 { | |
342 SpriteFrameTable *v1; // esi@1 | |
343 FILE *v2; // eax@1 | |
344 FILE *v3; // edi@1 | |
345 | |
346 v1 = this; | |
347 v2 = fopen("data\\dsft.bin", "wb"); | |
348 v3 = v2; | |
349 if ( !v2 ) | |
1545 | 350 Error("Unable to save dsft.bin!"); |
0 | 351 fwrite(v1, 4u, 1u, v2); |
352 fwrite(&v1->uNumEFrames, 4u, 1u, v3); | |
353 fwrite(v1->pSpriteSFrames, 0x3Cu, v1->uNumSpriteFrames, v3); | |
354 fwrite(v1->pSpriteEFrames, 2u, v1->uNumEFrames, v3); | |
355 fclose(v3); | |
356 } | |
357 | |
358 //----- (0044D9D7) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
359 void SpriteFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 360 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
361 uint num_mm6_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
362 uint num_mm6_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
363 if (data_mm6) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
364 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
365 num_mm6_frames = *(int *)data_mm6; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
366 num_mm6_eframes = *((int *)data_mm6 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
367 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
368 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
369 uint num_mm7_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
370 uint num_mm7_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
371 if (data_mm7) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
372 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
373 num_mm7_frames = *(int *)data_mm7; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
374 num_mm7_eframes = *((int *)data_mm7 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
375 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
376 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
377 uint num_mm8_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
378 uint num_mm8_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
379 if (data_mm8) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
380 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
381 num_mm8_frames = *(int *)data_mm8; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
382 num_mm8_eframes = *((int *)data_mm8 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
383 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
384 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
385 uNumSpriteFrames = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
386 uNumEFrames = num_mm6_eframes + num_mm7_eframes + num_mm8_eframes; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
387 |
1583 | 388 pSpriteSFrames = (SpriteFrame *)malloc(uNumSpriteFrames * sizeof(SpriteFrame)); |
389 pSpriteEFrames = (__int16 *)malloc(uNumSpriteFrames * sizeof(short)); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
390 |
1583 | 391 pSpritePFrames = (SpriteFrame **)malloc(4 * uNumSpriteFrames); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
392 |
1980 | 393 uint mm7_frames_size = num_mm7_frames * sizeof(SpriteFrame); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
394 memcpy(pSpriteSFrames, (char *)data_mm7 + 8, mm7_frames_size); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
395 memcpy(pSpriteEFrames, (char *)data_mm7 + 8 + mm7_frames_size, 2 * num_mm7_eframes); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
396 |
1980 | 397 uint mm6_frames_size = num_mm6_frames * sizeof(SpriteFrame_mm6); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
398 for (uint i = 0; i < num_mm6_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
399 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
400 memcpy(pSpriteSFrames + num_mm7_frames + i, (char *)data_mm6 + 8 + i * sizeof(SpriteFrame_mm6), sizeof(SpriteFrame_mm6)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
401 pSpriteSFrames[num_mm7_frames + i].uAnimLength = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
402 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
403 memcpy(pSpriteEFrames + num_mm7_frames, (char *)data_mm6 + 8 + mm6_frames_size, 2 * num_mm6_eframes); |
1541 | 404 |
1980 | 405 uint mm8_frames_size = num_mm8_frames * sizeof(SpriteFrame); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
406 memcpy(pSpriteSFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8, mm8_frames_size); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
407 memcpy(pSpriteEFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8 + mm8_frames_size, 2 * num_mm8_eframes); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
408 |
2436
ed1e4cff79a2
fixed uninitialized memory access in SpriteFrameTable::FromFile
Grumpy7
parents:
2420
diff
changeset
|
409 //the original was using num_mmx_frames, but never accessed any element beyond num_mmx_eframes, but boing beyong eframes caused invalid memory accesses |
ed1e4cff79a2
fixed uninitialized memory access in SpriteFrameTable::FromFile
Grumpy7
parents:
2420
diff
changeset
|
410 for (uint i = 0; i < num_mm6_eframes + num_mm7_eframes + num_mm8_eframes; ++i) |
ed1e4cff79a2
fixed uninitialized memory access in SpriteFrameTable::FromFile
Grumpy7
parents:
2420
diff
changeset
|
411 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; |
0 | 412 } |
413 | |
414 //----- (0044DA92) -------------------------------------------------------- | |
415 bool SpriteFrameTable::FromFileTxt(const char *Args) | |
416 { | |
417 SpriteFrameTable *v2; // ebx@1 | |
418 FILE *v3; // eax@1 | |
419 unsigned int v4; // esi@3 | |
420 signed int result; // eax@10 | |
421 FILE *v6; // ST18_4@11 | |
422 char *i; // eax@11 | |
423 const char *v8; // ST20_4@14 | |
424 __int16 v9; // ax@14 | |
425 const char *v10; // ST0C_4@14 | |
426 double v11; // st7@14 | |
427 int v12; // eax@14 | |
428 const char *v13; // ST04_4@14 | |
429 __int16 v14; // ax@14 | |
430 const char *v15; // ST00_4@14 | |
431 int v16; // eax@14 | |
432 int v17; // eax@17 | |
433 int v18; // eax@23 | |
434 int v19; // eax@24 | |
435 int v20; // eax@25 | |
436 int v21; // eax@28 | |
437 int v22; // eax@29 | |
438 int j; // edi@30 | |
439 const char *v24; // esi@31 | |
440 int v25; // eax@32 | |
441 int v26; // edx@53 | |
442 int v27; // ecx@54 | |
443 int v28; // eax@55 | |
444 signed int k; // edx@58 | |
445 SpriteFrame *v30; // ecx@59 | |
446 int v31; // esi@59 | |
447 int l; // eax@60 | |
448 signed int v33; // eax@65 | |
449 int v34; // edi@66 | |
450 int v35; // esi@66 | |
451 SpriteFrame **v36; // eax@69 | |
452 int v37; // ecx@69 | |
453 SpriteFrame *v38; // edx@69 | |
454 __int16 *v39; // eax@69 | |
455 int v40; // ecx@69 | |
456 char Buf[500]; // [sp+Ch] [bp-2F0h]@3 | |
457 FrameTableTxtLine v42; // [sp+200h] [bp-FCh]@4 | |
458 FrameTableTxtLine v43; // [sp+27Ch] [bp-80h]@4 | |
459 FILE *File; // [sp+2F8h] [bp-4h]@1 | |
460 unsigned int Argsa; // [sp+304h] [bp+8h]@3 | |
461 int Argsb; // [sp+304h] [bp+8h]@59 | |
462 FILE *Argsc; // [sp+304h] [bp+8h]@67 | |
463 | |
464 v2 = this; | |
465 ReleaseSFrames(); | |
466 v3 = fopen(Args, "r"); | |
467 File = v3; | |
468 if ( !v3 ) | |
1545 | 469 Error("CSpriteFrameTable::load - Unable to open file: %s.", Args); |
470 | |
0 | 471 v4 = 0; |
472 Argsa = 0; | |
473 if ( fgets(Buf, 490, v3) ) | |
474 { | |
475 do | |
476 { | |
477 *strchr(Buf, '\n') = 0; | |
478 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 479 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 480 ++Argsa; |
481 } | |
482 while ( fgets(Buf, 490, File) ); | |
483 v4 = Argsa; | |
484 } | |
485 v2->uNumSpriteFrames = v4; | |
1583 | 486 v2->pSpriteSFrames = (SpriteFrame *)malloc(60 * v4); |
487 v2->pSpriteEFrames = (__int16 *)malloc(2 * v2->uNumSpriteFrames); | |
488 v2->pSpritePFrames = (SpriteFrame **)malloc(4 * v2->uNumSpriteFrames); | |
0 | 489 if ( v2->pSpriteSFrames ) |
490 { | |
491 v6 = File; | |
492 v2->uNumSpriteFrames = 0; | |
493 fseek(v6, 0, 0); | |
494 for ( i = fgets(Buf, 490, File); i; i = fgets(Buf, 490, File) ) | |
495 { | |
496 *strchr(Buf, 10) = 0; | |
497 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 498 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 499 { |
500 v8 = v43.pProperties[0]; | |
501 v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags = 0; | |
502 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteIndex = 0; | |
503 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pIconName, v8); | |
504 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pTextureName, v43.pProperties[1]); | |
505 v9 = atoi(v43.pProperties[3]); | |
506 v10 = v43.pProperties[4]; | |
507 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteID = v9; | |
508 v11 = atof(v10) * 65536.0; | |
509 v12 = abs((signed __int64)v11); | |
510 v13 = v43.pProperties[5]; | |
511 v2->pSpriteSFrames[v2->uNumSpriteFrames].scale = v12; | |
512 v14 = atoi(v13); | |
513 v15 = v43.pProperties[6]; | |
514 v2->pSpriteSFrames[v2->uNumSpriteFrames].uGlowRadius = v14; | |
515 v2->pSpriteSFrames[v2->uNumSpriteFrames].uAnimTime = atoi(v15); | |
516 v16 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
517 if ( *(short *)(v16 + 48) ) | |
518 *(int *)(v16 + 44) |= 2u; | |
1104 | 519 if ( !_stricmp(v43.pProperties[2], "new") ) |
0 | 520 { |
521 v17 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
522 *(int *)v17 |= 4u; | |
523 v2->pSpritePFrames[v2->uNumEFrames] = &v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
524 v2->pSpriteEFrames[v2->uNumEFrames++] = LOWORD(v2->uNumSpriteFrames); | |
525 } | |
1104 | 526 if ( !_stricmp(v43.pProperties[10], "1") ) |
0 | 527 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; |
1104 | 528 if ( !_stricmp(v43.pProperties[11], "1") ) |
0 | 529 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; |
1104 | 530 if ( !_stricmp(v43.pProperties[12], "1") ) |
0 | 531 { |
532 v18 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
533 *(int *)v18 |= 0x20u; | |
534 } | |
535 v19 = atoi(v43.pProperties[7]) - 1; | |
536 if ( v19 ) | |
537 { | |
538 v20 = v19 - 2; | |
539 if ( v20 ) | |
540 { | |
541 if ( v20 == 2 ) | |
542 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0xE0u; | |
543 } | |
544 else | |
545 { | |
546 v21 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
547 *(int *)v21 |= 0x1E000u; | |
548 } | |
549 } | |
550 else | |
551 { | |
552 v22 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
553 *(int *)v22 |= 0x10u; | |
554 } | |
701 | 555 for ( j = 13; j < v43.uPropCount; ++j ) |
0 | 556 { |
557 v24 = v43.pProperties[j]; | |
1104 | 558 if ( _stricmp(v43.pProperties[j], "Luminous") ) |
0 | 559 { |
1104 | 560 if ( _stricmp(v24, "Mirror0") ) |
0 | 561 { |
1104 | 562 if ( _stricmp(v24, "Mirror1") ) |
0 | 563 { |
1104 | 564 if ( _stricmp(v24, "Mirror2") ) |
0 | 565 { |
1104 | 566 if ( _stricmp(v24, "Mirror3") ) |
0 | 567 { |
1104 | 568 if ( _stricmp(v24, "Mirror4") ) |
0 | 569 { |
1104 | 570 if ( _stricmp(v24, "Mirror5") ) |
0 | 571 { |
1104 | 572 if ( _stricmp(v24, "Mirror6") ) |
0 | 573 { |
1104 | 574 if ( !_stricmp(v24, "Mirror7") ) |
0 | 575 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x80u; |
576 } | |
577 else | |
578 { | |
579 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x40u; | |
580 } | |
581 } | |
582 else | |
583 { | |
584 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x20u; | |
585 } | |
586 } | |
587 else | |
588 { | |
589 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x10u; | |
590 } | |
591 } | |
592 else | |
593 { | |
594 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 8u; | |
595 } | |
596 } | |
597 else | |
598 { | |
599 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; | |
600 } | |
601 } | |
602 else | |
603 { | |
604 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; | |
605 } | |
606 } | |
607 else | |
608 { | |
609 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 1u; | |
610 } | |
611 } | |
612 else | |
613 { | |
614 v25 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
615 *(int *)v25 |= 2u; | |
616 } | |
617 } | |
618 ++v2->uNumSpriteFrames; | |
619 } | |
620 } | |
621 fclose(File); | |
622 v26 = 0; | |
623 if ( (signed int)(v2->uNumSpriteFrames - 1) > 0 ) | |
624 { | |
625 v27 = 0; | |
626 do | |
627 { | |
628 v28 = (int)&v2->pSpriteSFrames[v27]; | |
629 if ( !(*(char *)(v28 + 104) & 4) ) | |
630 *(int *)(v28 + 44) |= 1u; | |
631 ++v26; | |
632 ++v27; | |
633 } | |
634 while ( v26 < (signed int)(v2->uNumSpriteFrames - 1) ); | |
635 } | |
636 for ( k = 0; k < (signed int)v2->uNumSpriteFrames; *(short *)(Argsb + 56) = v31 ) | |
637 { | |
638 v30 = v2->pSpriteSFrames; | |
639 Argsb = (int)&v30[k]; | |
640 v31 = *(short *)(Argsb + 54); | |
641 if ( *(char *)(Argsb + 44) & 1 ) | |
642 { | |
643 ++k; | |
644 for ( l = (int)&v30[k]; *(char *)(l + 44) & 1; l += 60 ) | |
645 { | |
646 v31 += *(short *)(l + 54); | |
647 ++k; | |
648 } | |
649 LOWORD(v31) = v30[k].uAnimTime + v31; | |
650 } | |
651 ++k; | |
652 } | |
653 v33 = v2->uNumEFrames; | |
654 if ( v33 > 0 ) | |
655 { | |
656 v34 = 0; | |
657 v35 = 0; | |
658 File = (FILE *)1; | |
659 do | |
660 { | |
661 Argsc = File; | |
662 if ( (signed int)File < v33 ) | |
663 { | |
664 do | |
665 { | |
1104 | 666 if ( _stricmp(v2->pSpritePFrames[(int)Argsc]->pIconName, v2->pSpritePFrames[v35]->pIconName) < 0 ) |
0 | 667 { |
668 v36 = v2->pSpritePFrames; | |
669 v37 = (int)&v36[(int)Argsc]; | |
670 v38 = *(SpriteFrame **)v37; | |
671 *(int *)v37 = (int)v36[v35]; | |
672 v2->pSpritePFrames[v35] = v38; | |
673 v39 = v2->pSpriteEFrames; | |
674 v40 = (int)&v39[(int)Argsc]; | |
675 LOWORD(v38) = *(short *)v40; | |
676 *(short *)v40 = v39[v34]; | |
677 v2->pSpriteEFrames[v34] = (signed __int16)v38; | |
678 } | |
679 Argsc = (FILE *)((char *)Argsc + 1); | |
680 } | |
681 while ( (signed int)Argsc < v2->uNumEFrames ); | |
682 } | |
683 File = (FILE *)((char *)File + 1); | |
684 v33 = v2->uNumEFrames; | |
685 ++v35; | |
686 ++v34; | |
687 } | |
688 while ( (signed int)((char *)File - 1) < v33 ); | |
689 } | |
690 result = 1; | |
691 } | |
692 else | |
693 { | |
694 MessageBoxW(nullptr, L"CSpriteFrameTable::load - Out of Memory!", nullptr, 0); | |
695 fclose(File); | |
696 result = 0; | |
697 } | |
698 return result; | |
1295 | 699 } |
700 //----- (0046E26D) -------------------------------------------------------- | |
701 void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2) | |
702 { | |
703 int v2; // edx@5 | |
704 unsigned __int16 *v3; // eax@5 | |
705 unsigned __int16 v4; // ax@6 | |
706 LevelDecoration *v5; // edi@7 | |
707 DecorationDesc *v6; // esi@8 | |
708 int v7; // edx@9 | |
709 int v8; // eax@9 | |
710 int v9; // ecx@11 | |
711 int v10; // ebx@13 | |
712 int v11; // esi@13 | |
713 int v12; // ebp@15 | |
714 int v13; // ebx@15 | |
715 int v14; // esi@16 | |
716 int v15; // edi@17 | |
717 int v16; // eax@17 | |
718 int v17; // esi@19 | |
719 char v18; // zf@23 | |
720 int v19; // [sp+0h] [bp-10h]@15 | |
721 unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5 | |
722 int v21; // [sp+8h] [bp-8h]@15 | |
723 int v22; // [sp+Ch] [bp-4h]@13 | |
724 | |
725 if ( a1 >= 0 ) | |
726 { | |
727 if ( a1 <= 127 ) | |
728 { | |
729 if ( a2 >= 0 ) | |
730 { | |
731 if ( a2 <= 127 ) | |
732 { | |
733 v2 = a1 + (a2 << 7); | |
734 v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
735 v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
736 if ( v3 ) | |
737 { | |
738 do | |
739 { | |
740 v4 = *v3; | |
741 if ( PID_TYPE(v4) == OBJECT_Decoration) | |
742 { | |
743 v5 = &pLevelDecorations[(signed __int16)v4 >> 3]; | |
1489 | 744 if (!(v5->uFlags & LEVEL_DECORATION_INVISIBLE)) |
1295 | 745 { |
746 v6 = &pDecorationList->pDecorations[v5->uDecorationDescID]; | |
747 if (!v6->CanMoveThrough()) | |
748 { | |
749 v7 = v6->uRadius; | |
750 v8 = v5->vPosition.x; | |
751 if ( stru_721530.sMaxX <= v8 + v7 ) | |
752 { | |
753 if ( stru_721530.sMinX >= v8 - v7 ) | |
754 { | |
755 v9 = v5->vPosition.y; | |
756 if ( stru_721530.sMaxY <= v9 + v7 ) | |
757 { | |
758 if ( stru_721530.sMinY >= v9 - v7 ) | |
759 { | |
760 v10 = v6->uDecorationHeight; | |
761 v11 = v5->vPosition.z; | |
762 v22 = v10; | |
763 if ( stru_721530.sMaxZ <= v11 + v10 ) | |
764 { | |
765 if ( stru_721530.sMinZ >= v11 ) | |
766 { | |
767 v12 = v8 - stru_721530.normal.x; | |
768 v19 = v9 - stru_721530.normal.y; | |
769 v13 = stru_721530.prolly_normal_d + v7; | |
1546 | 770 v21 = ((v8 - stru_721530.normal.x) * stru_721530.direction.y |
771 - (v9 - stru_721530.normal.y) * stru_721530.direction.x) >> 16; | |
1295 | 772 if ( abs(v21) <= stru_721530.prolly_normal_d + v7 ) |
773 { | |
1546 | 774 v14 = (v12 * stru_721530.direction.x + v19 * stru_721530.direction.y) >> 16; |
1295 | 775 if ( v14 > 0 ) |
776 { | |
777 v15 = v5->vPosition.z; | |
2207 | 778 v16 = stru_721530.normal.z + fixpoint_mul(stru_721530.direction.z, v14); |
1295 | 779 if ( v16 >= v15 ) |
780 { | |
781 if ( v16 <= v22 + v15 ) | |
782 { | |
783 v17 = v14 - integer_sqrt(v13 * v13 - v21 * v21); | |
784 if ( v17 < 0 ) | |
785 v17 = 0; | |
786 if ( v17 < stru_721530.field_7C ) | |
787 { | |
788 stru_721530.field_7C = v17; | |
789 stru_721530.uFaceID = (signed __int16)*v20; | |
790 } | |
791 } | |
792 } | |
793 } | |
794 } | |
795 } | |
796 } | |
797 } | |
798 } | |
799 } | |
800 } | |
801 } | |
802 } | |
803 } | |
804 v3 = v20 + 1; | |
805 v18 = *v20 == 0; | |
806 ++v20; | |
807 } | |
808 while ( !v18 ); | |
809 } | |
810 } | |
811 } | |
812 } | |
813 } | |
814 } |