Mercurial > mm7
annotate Sprites.cpp @ 2424:255168c31655
* Added win 8.1 support to builds
* Removed strict requirement so that display/os should support 16 bit resolutions (even if they aren't really used)
author | a.parshin |
---|---|
date | Wed, 23 Jul 2014 12:58:30 +0300 |
parents | 0313c761d203 |
children | ed1e4cff79a2 |
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 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
409 for (uint i = 0; i < num_mm7_frames; ++i) |
2420 | 410 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]];//Uninitialized memory access |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
411 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
412 for (uint i = num_mm7_frames; i < num_mm6_frames + num_mm7_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
413 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm7_frames]; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
414 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
415 for (uint i = num_mm6_frames + num_mm7_frames; i < num_mm6_frames + num_mm7_frames + num_mm8_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
416 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm6_frames + num_mm7_frames]; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
417 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
418 //for (uint i = 0; i < uNumSpriteFrames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
419 // pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; |
0 | 420 } |
421 | |
422 //----- (0044DA92) -------------------------------------------------------- | |
423 bool SpriteFrameTable::FromFileTxt(const char *Args) | |
424 { | |
425 SpriteFrameTable *v2; // ebx@1 | |
426 FILE *v3; // eax@1 | |
427 unsigned int v4; // esi@3 | |
428 signed int result; // eax@10 | |
429 FILE *v6; // ST18_4@11 | |
430 char *i; // eax@11 | |
431 const char *v8; // ST20_4@14 | |
432 __int16 v9; // ax@14 | |
433 const char *v10; // ST0C_4@14 | |
434 double v11; // st7@14 | |
435 int v12; // eax@14 | |
436 const char *v13; // ST04_4@14 | |
437 __int16 v14; // ax@14 | |
438 const char *v15; // ST00_4@14 | |
439 int v16; // eax@14 | |
440 int v17; // eax@17 | |
441 int v18; // eax@23 | |
442 int v19; // eax@24 | |
443 int v20; // eax@25 | |
444 int v21; // eax@28 | |
445 int v22; // eax@29 | |
446 int j; // edi@30 | |
447 const char *v24; // esi@31 | |
448 int v25; // eax@32 | |
449 int v26; // edx@53 | |
450 int v27; // ecx@54 | |
451 int v28; // eax@55 | |
452 signed int k; // edx@58 | |
453 SpriteFrame *v30; // ecx@59 | |
454 int v31; // esi@59 | |
455 int l; // eax@60 | |
456 signed int v33; // eax@65 | |
457 int v34; // edi@66 | |
458 int v35; // esi@66 | |
459 SpriteFrame **v36; // eax@69 | |
460 int v37; // ecx@69 | |
461 SpriteFrame *v38; // edx@69 | |
462 __int16 *v39; // eax@69 | |
463 int v40; // ecx@69 | |
464 char Buf[500]; // [sp+Ch] [bp-2F0h]@3 | |
465 FrameTableTxtLine v42; // [sp+200h] [bp-FCh]@4 | |
466 FrameTableTxtLine v43; // [sp+27Ch] [bp-80h]@4 | |
467 FILE *File; // [sp+2F8h] [bp-4h]@1 | |
468 unsigned int Argsa; // [sp+304h] [bp+8h]@3 | |
469 int Argsb; // [sp+304h] [bp+8h]@59 | |
470 FILE *Argsc; // [sp+304h] [bp+8h]@67 | |
471 | |
472 v2 = this; | |
473 ReleaseSFrames(); | |
474 v3 = fopen(Args, "r"); | |
475 File = v3; | |
476 if ( !v3 ) | |
1545 | 477 Error("CSpriteFrameTable::load - Unable to open file: %s.", Args); |
478 | |
0 | 479 v4 = 0; |
480 Argsa = 0; | |
481 if ( fgets(Buf, 490, v3) ) | |
482 { | |
483 do | |
484 { | |
485 *strchr(Buf, '\n') = 0; | |
486 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 487 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 488 ++Argsa; |
489 } | |
490 while ( fgets(Buf, 490, File) ); | |
491 v4 = Argsa; | |
492 } | |
493 v2->uNumSpriteFrames = v4; | |
1583 | 494 v2->pSpriteSFrames = (SpriteFrame *)malloc(60 * v4); |
495 v2->pSpriteEFrames = (__int16 *)malloc(2 * v2->uNumSpriteFrames); | |
496 v2->pSpritePFrames = (SpriteFrame **)malloc(4 * v2->uNumSpriteFrames); | |
0 | 497 if ( v2->pSpriteSFrames ) |
498 { | |
499 v6 = File; | |
500 v2->uNumSpriteFrames = 0; | |
501 fseek(v6, 0, 0); | |
502 for ( i = fgets(Buf, 490, File); i; i = fgets(Buf, 490, File) ) | |
503 { | |
504 *strchr(Buf, 10) = 0; | |
505 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 506 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 507 { |
508 v8 = v43.pProperties[0]; | |
509 v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags = 0; | |
510 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteIndex = 0; | |
511 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pIconName, v8); | |
512 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pTextureName, v43.pProperties[1]); | |
513 v9 = atoi(v43.pProperties[3]); | |
514 v10 = v43.pProperties[4]; | |
515 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteID = v9; | |
516 v11 = atof(v10) * 65536.0; | |
517 v12 = abs((signed __int64)v11); | |
518 v13 = v43.pProperties[5]; | |
519 v2->pSpriteSFrames[v2->uNumSpriteFrames].scale = v12; | |
520 v14 = atoi(v13); | |
521 v15 = v43.pProperties[6]; | |
522 v2->pSpriteSFrames[v2->uNumSpriteFrames].uGlowRadius = v14; | |
523 v2->pSpriteSFrames[v2->uNumSpriteFrames].uAnimTime = atoi(v15); | |
524 v16 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
525 if ( *(short *)(v16 + 48) ) | |
526 *(int *)(v16 + 44) |= 2u; | |
1104 | 527 if ( !_stricmp(v43.pProperties[2], "new") ) |
0 | 528 { |
529 v17 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
530 *(int *)v17 |= 4u; | |
531 v2->pSpritePFrames[v2->uNumEFrames] = &v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
532 v2->pSpriteEFrames[v2->uNumEFrames++] = LOWORD(v2->uNumSpriteFrames); | |
533 } | |
1104 | 534 if ( !_stricmp(v43.pProperties[10], "1") ) |
0 | 535 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; |
1104 | 536 if ( !_stricmp(v43.pProperties[11], "1") ) |
0 | 537 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; |
1104 | 538 if ( !_stricmp(v43.pProperties[12], "1") ) |
0 | 539 { |
540 v18 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
541 *(int *)v18 |= 0x20u; | |
542 } | |
543 v19 = atoi(v43.pProperties[7]) - 1; | |
544 if ( v19 ) | |
545 { | |
546 v20 = v19 - 2; | |
547 if ( v20 ) | |
548 { | |
549 if ( v20 == 2 ) | |
550 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0xE0u; | |
551 } | |
552 else | |
553 { | |
554 v21 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
555 *(int *)v21 |= 0x1E000u; | |
556 } | |
557 } | |
558 else | |
559 { | |
560 v22 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
561 *(int *)v22 |= 0x10u; | |
562 } | |
701 | 563 for ( j = 13; j < v43.uPropCount; ++j ) |
0 | 564 { |
565 v24 = v43.pProperties[j]; | |
1104 | 566 if ( _stricmp(v43.pProperties[j], "Luminous") ) |
0 | 567 { |
1104 | 568 if ( _stricmp(v24, "Mirror0") ) |
0 | 569 { |
1104 | 570 if ( _stricmp(v24, "Mirror1") ) |
0 | 571 { |
1104 | 572 if ( _stricmp(v24, "Mirror2") ) |
0 | 573 { |
1104 | 574 if ( _stricmp(v24, "Mirror3") ) |
0 | 575 { |
1104 | 576 if ( _stricmp(v24, "Mirror4") ) |
0 | 577 { |
1104 | 578 if ( _stricmp(v24, "Mirror5") ) |
0 | 579 { |
1104 | 580 if ( _stricmp(v24, "Mirror6") ) |
0 | 581 { |
1104 | 582 if ( !_stricmp(v24, "Mirror7") ) |
0 | 583 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x80u; |
584 } | |
585 else | |
586 { | |
587 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x40u; | |
588 } | |
589 } | |
590 else | |
591 { | |
592 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x20u; | |
593 } | |
594 } | |
595 else | |
596 { | |
597 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x10u; | |
598 } | |
599 } | |
600 else | |
601 { | |
602 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 8u; | |
603 } | |
604 } | |
605 else | |
606 { | |
607 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; | |
608 } | |
609 } | |
610 else | |
611 { | |
612 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; | |
613 } | |
614 } | |
615 else | |
616 { | |
617 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 1u; | |
618 } | |
619 } | |
620 else | |
621 { | |
622 v25 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
623 *(int *)v25 |= 2u; | |
624 } | |
625 } | |
626 ++v2->uNumSpriteFrames; | |
627 } | |
628 } | |
629 fclose(File); | |
630 v26 = 0; | |
631 if ( (signed int)(v2->uNumSpriteFrames - 1) > 0 ) | |
632 { | |
633 v27 = 0; | |
634 do | |
635 { | |
636 v28 = (int)&v2->pSpriteSFrames[v27]; | |
637 if ( !(*(char *)(v28 + 104) & 4) ) | |
638 *(int *)(v28 + 44) |= 1u; | |
639 ++v26; | |
640 ++v27; | |
641 } | |
642 while ( v26 < (signed int)(v2->uNumSpriteFrames - 1) ); | |
643 } | |
644 for ( k = 0; k < (signed int)v2->uNumSpriteFrames; *(short *)(Argsb + 56) = v31 ) | |
645 { | |
646 v30 = v2->pSpriteSFrames; | |
647 Argsb = (int)&v30[k]; | |
648 v31 = *(short *)(Argsb + 54); | |
649 if ( *(char *)(Argsb + 44) & 1 ) | |
650 { | |
651 ++k; | |
652 for ( l = (int)&v30[k]; *(char *)(l + 44) & 1; l += 60 ) | |
653 { | |
654 v31 += *(short *)(l + 54); | |
655 ++k; | |
656 } | |
657 LOWORD(v31) = v30[k].uAnimTime + v31; | |
658 } | |
659 ++k; | |
660 } | |
661 v33 = v2->uNumEFrames; | |
662 if ( v33 > 0 ) | |
663 { | |
664 v34 = 0; | |
665 v35 = 0; | |
666 File = (FILE *)1; | |
667 do | |
668 { | |
669 Argsc = File; | |
670 if ( (signed int)File < v33 ) | |
671 { | |
672 do | |
673 { | |
1104 | 674 if ( _stricmp(v2->pSpritePFrames[(int)Argsc]->pIconName, v2->pSpritePFrames[v35]->pIconName) < 0 ) |
0 | 675 { |
676 v36 = v2->pSpritePFrames; | |
677 v37 = (int)&v36[(int)Argsc]; | |
678 v38 = *(SpriteFrame **)v37; | |
679 *(int *)v37 = (int)v36[v35]; | |
680 v2->pSpritePFrames[v35] = v38; | |
681 v39 = v2->pSpriteEFrames; | |
682 v40 = (int)&v39[(int)Argsc]; | |
683 LOWORD(v38) = *(short *)v40; | |
684 *(short *)v40 = v39[v34]; | |
685 v2->pSpriteEFrames[v34] = (signed __int16)v38; | |
686 } | |
687 Argsc = (FILE *)((char *)Argsc + 1); | |
688 } | |
689 while ( (signed int)Argsc < v2->uNumEFrames ); | |
690 } | |
691 File = (FILE *)((char *)File + 1); | |
692 v33 = v2->uNumEFrames; | |
693 ++v35; | |
694 ++v34; | |
695 } | |
696 while ( (signed int)((char *)File - 1) < v33 ); | |
697 } | |
698 result = 1; | |
699 } | |
700 else | |
701 { | |
702 MessageBoxW(nullptr, L"CSpriteFrameTable::load - Out of Memory!", nullptr, 0); | |
703 fclose(File); | |
704 result = 0; | |
705 } | |
706 return result; | |
1295 | 707 } |
708 //----- (0046E26D) -------------------------------------------------------- | |
709 void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2) | |
710 { | |
711 int v2; // edx@5 | |
712 unsigned __int16 *v3; // eax@5 | |
713 unsigned __int16 v4; // ax@6 | |
714 LevelDecoration *v5; // edi@7 | |
715 DecorationDesc *v6; // esi@8 | |
716 int v7; // edx@9 | |
717 int v8; // eax@9 | |
718 int v9; // ecx@11 | |
719 int v10; // ebx@13 | |
720 int v11; // esi@13 | |
721 int v12; // ebp@15 | |
722 int v13; // ebx@15 | |
723 int v14; // esi@16 | |
724 int v15; // edi@17 | |
725 int v16; // eax@17 | |
726 int v17; // esi@19 | |
727 char v18; // zf@23 | |
728 int v19; // [sp+0h] [bp-10h]@15 | |
729 unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5 | |
730 int v21; // [sp+8h] [bp-8h]@15 | |
731 int v22; // [sp+Ch] [bp-4h]@13 | |
732 | |
733 if ( a1 >= 0 ) | |
734 { | |
735 if ( a1 <= 127 ) | |
736 { | |
737 if ( a2 >= 0 ) | |
738 { | |
739 if ( a2 <= 127 ) | |
740 { | |
741 v2 = a1 + (a2 << 7); | |
742 v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
743 v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
744 if ( v3 ) | |
745 { | |
746 do | |
747 { | |
748 v4 = *v3; | |
749 if ( PID_TYPE(v4) == OBJECT_Decoration) | |
750 { | |
751 v5 = &pLevelDecorations[(signed __int16)v4 >> 3]; | |
1489 | 752 if (!(v5->uFlags & LEVEL_DECORATION_INVISIBLE)) |
1295 | 753 { |
754 v6 = &pDecorationList->pDecorations[v5->uDecorationDescID]; | |
755 if (!v6->CanMoveThrough()) | |
756 { | |
757 v7 = v6->uRadius; | |
758 v8 = v5->vPosition.x; | |
759 if ( stru_721530.sMaxX <= v8 + v7 ) | |
760 { | |
761 if ( stru_721530.sMinX >= v8 - v7 ) | |
762 { | |
763 v9 = v5->vPosition.y; | |
764 if ( stru_721530.sMaxY <= v9 + v7 ) | |
765 { | |
766 if ( stru_721530.sMinY >= v9 - v7 ) | |
767 { | |
768 v10 = v6->uDecorationHeight; | |
769 v11 = v5->vPosition.z; | |
770 v22 = v10; | |
771 if ( stru_721530.sMaxZ <= v11 + v10 ) | |
772 { | |
773 if ( stru_721530.sMinZ >= v11 ) | |
774 { | |
775 v12 = v8 - stru_721530.normal.x; | |
776 v19 = v9 - stru_721530.normal.y; | |
777 v13 = stru_721530.prolly_normal_d + v7; | |
1546 | 778 v21 = ((v8 - stru_721530.normal.x) * stru_721530.direction.y |
779 - (v9 - stru_721530.normal.y) * stru_721530.direction.x) >> 16; | |
1295 | 780 if ( abs(v21) <= stru_721530.prolly_normal_d + v7 ) |
781 { | |
1546 | 782 v14 = (v12 * stru_721530.direction.x + v19 * stru_721530.direction.y) >> 16; |
1295 | 783 if ( v14 > 0 ) |
784 { | |
785 v15 = v5->vPosition.z; | |
2207 | 786 v16 = stru_721530.normal.z + fixpoint_mul(stru_721530.direction.z, v14); |
1295 | 787 if ( v16 >= v15 ) |
788 { | |
789 if ( v16 <= v22 + v15 ) | |
790 { | |
791 v17 = v14 - integer_sqrt(v13 * v13 - v21 * v21); | |
792 if ( v17 < 0 ) | |
793 v17 = 0; | |
794 if ( v17 < stru_721530.field_7C ) | |
795 { | |
796 stru_721530.field_7C = v17; | |
797 stru_721530.uFaceID = (signed __int16)*v20; | |
798 } | |
799 } | |
800 } | |
801 } | |
802 } | |
803 } | |
804 } | |
805 } | |
806 } | |
807 } | |
808 } | |
809 } | |
810 } | |
811 } | |
812 v3 = v20 + 1; | |
813 v18 = *v20 == 0; | |
814 ++v20; | |
815 } | |
816 while ( !v18 ); | |
817 } | |
818 } | |
819 } | |
820 } | |
821 } | |
822 } |