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