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