annotate Engine/Objects/ObjectList.cpp @ 2541:a902abdfc7f2

1. Renamed class Game to class Engine. 2. Separated game logic as state of FSM from game logic as engine. 3. Found out that many UI screen initializers were optimized away, intially they all returned newly created window as separate object like it is done in CharacterUI_Initialize.
author a.parshin
date Sun, 10 May 2015 01:29:11 +0200
parents 68cdef6879a0
children
rev   line source
2498
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
Ritor1
parents:
diff changeset
2 #include <stdlib.h>
Ritor1
parents:
diff changeset
3 #include <crtdbg.h>
Ritor1
parents:
diff changeset
4
Ritor1
parents:
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2499
diff changeset
6
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2499
diff changeset
7 #include "Engine/Engine.h"
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2499
diff changeset
8
2498
Ritor1
parents:
diff changeset
9 #include "ObjectList.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2498
diff changeset
10 #include "../Graphics/Sprites.h"
68cdef6879a0 engine folder
Ritor1
parents: 2498
diff changeset
11 #include "../Tables/FrameTableInc.h"
2498
Ritor1
parents:
diff changeset
12
Ritor1
parents:
diff changeset
13 //----- (0042EB42) --------------------------------------------------------
Ritor1
parents:
diff changeset
14 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID)
Ritor1
parents:
diff changeset
15 {
Ritor1
parents:
diff changeset
16 unsigned int v2; // edx@1
Ritor1
parents:
diff changeset
17 signed int v3; // eax@1
Ritor1
parents:
diff changeset
18 char *v4; // ecx@2
Ritor1
parents:
diff changeset
19
Ritor1
parents:
diff changeset
20 v2 = this->uNumObjects;
Ritor1
parents:
diff changeset
21 v3 = 0;
Ritor1
parents:
diff changeset
22 if ( (signed int)this->uNumObjects <= 0 )
Ritor1
parents:
diff changeset
23 {
Ritor1
parents:
diff changeset
24 LABEL_5:
Ritor1
parents:
diff changeset
25 LOWORD(v3) = 0;
Ritor1
parents:
diff changeset
26 }
Ritor1
parents:
diff changeset
27 else
Ritor1
parents:
diff changeset
28 {
Ritor1
parents:
diff changeset
29 v4 = (char *)&this->pObjects->uObjectID;
Ritor1
parents:
diff changeset
30 while ( uItemID != *(short *)v4 )
Ritor1
parents:
diff changeset
31 {
Ritor1
parents:
diff changeset
32 ++v3;
Ritor1
parents:
diff changeset
33 v4 += 56;
Ritor1
parents:
diff changeset
34 if ( v3 >= (signed int)v2 )
Ritor1
parents:
diff changeset
35 goto LABEL_5;
Ritor1
parents:
diff changeset
36 }
Ritor1
parents:
diff changeset
37 }
Ritor1
parents:
diff changeset
38 return v3;
Ritor1
parents:
diff changeset
39 }
Ritor1
parents:
diff changeset
40 //----- (00459064) --------------------------------------------------------
Ritor1
parents:
diff changeset
41 void ObjectList::InitializeSprites()
Ritor1
parents:
diff changeset
42 {
Ritor1
parents:
diff changeset
43 for (uint i = 0; i < uNumObjects; ++i)
Ritor1
parents:
diff changeset
44 pSpriteFrameTable->InitializeSprite(pObjects[i].uSpriteID);
Ritor1
parents:
diff changeset
45 }
Ritor1
parents:
diff changeset
46
Ritor1
parents:
diff changeset
47 //----- (00459090) --------------------------------------------------------
Ritor1
parents:
diff changeset
48 void ObjectList::ToFile()
Ritor1
parents:
diff changeset
49 {
Ritor1
parents:
diff changeset
50 ObjectList *v1; // esi@1
Ritor1
parents:
diff changeset
51 FILE *v2; // eax@1
Ritor1
parents:
diff changeset
52 FILE *v3; // edi@1
Ritor1
parents:
diff changeset
53
Ritor1
parents:
diff changeset
54 v1 = this;
Ritor1
parents:
diff changeset
55 v2 = fopen("data\\dobjlist.bin", "wb");
Ritor1
parents:
diff changeset
56 v3 = v2;
Ritor1
parents:
diff changeset
57 if ( !v2 )
Ritor1
parents:
diff changeset
58 Error("Unable to save dobjlist.bin!");
Ritor1
parents:
diff changeset
59 fwrite(v1, 4u, 1u, v2);
Ritor1
parents:
diff changeset
60 fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3);
Ritor1
parents:
diff changeset
61 fclose(v3);
Ritor1
parents:
diff changeset
62 }
Ritor1
parents:
diff changeset
63
Ritor1
parents:
diff changeset
64 //----- (004590DC) --------------------------------------------------------
Ritor1
parents:
diff changeset
65 void ObjectList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
Ritor1
parents:
diff changeset
66 {
Ritor1
parents:
diff changeset
67 uint num_mm6_objs = data_mm6 ? *(int *)data_mm6 : 0,
Ritor1
parents:
diff changeset
68 num_mm7_objs = data_mm7 ? *(int *)data_mm7 : 0,
Ritor1
parents:
diff changeset
69 num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0;
Ritor1
parents:
diff changeset
70
Ritor1
parents:
diff changeset
71 uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs;
Ritor1
parents:
diff changeset
72 Assert(uNumObjects);
Ritor1
parents:
diff changeset
73 Assert(!num_mm8_objs);
Ritor1
parents:
diff changeset
74
Ritor1
parents:
diff changeset
75 pObjects = (ObjectDesc *)malloc(uNumObjects * sizeof(ObjectDesc));
Ritor1
parents:
diff changeset
76 memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc));
Ritor1
parents:
diff changeset
77 for (uint i = 0; i < num_mm6_objs; ++i)
Ritor1
parents:
diff changeset
78 {
Ritor1
parents:
diff changeset
79 auto src = (ObjectDesc_mm6 *)((char *)data_mm6 + 4) + i;
Ritor1
parents:
diff changeset
80 ObjectDesc* dst = &pObjects[num_mm7_objs + i];
Ritor1
parents:
diff changeset
81 memcpy(dst->field_0, src->field_0, sizeof(dst->field_0));
Ritor1
parents:
diff changeset
82 dst->uObjectID = src->uObjectID;
Ritor1
parents:
diff changeset
83 dst->uRadius = src->uRadius;
Ritor1
parents:
diff changeset
84 dst->uHeight = src->uHeight;
Ritor1
parents:
diff changeset
85 dst->uFlags = src->uFlags;
Ritor1
parents:
diff changeset
86 dst->uSpriteID = src->uSpriteID;
Ritor1
parents:
diff changeset
87 dst->uLifetime = src->uLifetime;
Ritor1
parents:
diff changeset
88 dst->uParticleTrailColor = src->uParticleTrailColor;
Ritor1
parents:
diff changeset
89 dst->uSpeed = src->uSpeed;
Ritor1
parents:
diff changeset
90 dst->uParticleTrailColorR = src->uParticleTrailColorR;
Ritor1
parents:
diff changeset
91 dst->uParticleTrailColorG = src->uParticleTrailColorG;
Ritor1
parents:
diff changeset
92 dst->uParticleTrailColorB = src->uParticleTrailColorB;
Ritor1
parents:
diff changeset
93 dst->field_35_clr = src->field_35_clr;
Ritor1
parents:
diff changeset
94 dst->field_36_clr = 0;
Ritor1
parents:
diff changeset
95 dst->field_37_clr = 0;
Ritor1
parents:
diff changeset
96 }
Ritor1
parents:
diff changeset
97 }
Ritor1
parents:
diff changeset
98
Ritor1
parents:
diff changeset
99 //----- (00459123) --------------------------------------------------------
Ritor1
parents:
diff changeset
100 bool ObjectList::FromFileTxt(const char *Args)
Ritor1
parents:
diff changeset
101 {
Ritor1
parents:
diff changeset
102 ObjectList *v2; // ebx@1
Ritor1
parents:
diff changeset
103 __int32 v3; // edi@1
Ritor1
parents:
diff changeset
104 FILE *v4; // eax@1
Ritor1
parents:
diff changeset
105 unsigned int v5; // esi@3
Ritor1
parents:
diff changeset
106 void *v6; // eax@9
Ritor1
parents:
diff changeset
107 FILE *v7; // ST0C_4@11
Ritor1
parents:
diff changeset
108 char *i; // eax@11
Ritor1
parents:
diff changeset
109 unsigned __int16 v9; // ax@14
Ritor1
parents:
diff changeset
110 const char *v10; // ST20_4@14
Ritor1
parents:
diff changeset
111 __int16 v11; // ax@14
Ritor1
parents:
diff changeset
112 const char *v12; // ST1C_4@14
Ritor1
parents:
diff changeset
113 __int16 v13; // ax@14
Ritor1
parents:
diff changeset
114 const char *v14; // ST18_4@14
Ritor1
parents:
diff changeset
115 __int16 v15; // ax@14
Ritor1
parents:
diff changeset
116 const char *v16; // ST14_4@14
Ritor1
parents:
diff changeset
117 __int16 v17; // ax@14
Ritor1
parents:
diff changeset
118 const char *v18; // ST10_4@14
Ritor1
parents:
diff changeset
119 __int16 v19; // ax@14
Ritor1
parents:
diff changeset
120 const char *v20; // ST0C_4@14
Ritor1
parents:
diff changeset
121 int v21; // esi@16
Ritor1
parents:
diff changeset
122 const char *v22; // edi@16
Ritor1
parents:
diff changeset
123 int v23; // eax@17
Ritor1
parents:
diff changeset
124 int v24; // eax@19
Ritor1
parents:
diff changeset
125 int v25; // eax@21
Ritor1
parents:
diff changeset
126 int v26; // eax@21
Ritor1
parents:
diff changeset
127 int v27; // eax@21
Ritor1
parents:
diff changeset
128 int v28; // eax@23
Ritor1
parents:
diff changeset
129 int v29; // eax@25
Ritor1
parents:
diff changeset
130 int v30; // eax@27
Ritor1
parents:
diff changeset
131 int v31; // eax@29
Ritor1
parents:
diff changeset
132 const char *v32; // edi@30
Ritor1
parents:
diff changeset
133 const char *v33; // ST20_4@35
Ritor1
parents:
diff changeset
134 int v34; // eax@35
Ritor1
parents:
diff changeset
135 char v35; // al@35
Ritor1
parents:
diff changeset
136 const char *v36; // ST1C_4@35
Ritor1
parents:
diff changeset
137 char v37; // al@35
Ritor1
parents:
diff changeset
138 const char *v38; // ST18_4@35
Ritor1
parents:
diff changeset
139 FrameTableTxtLine v40; // [sp+8h] [bp-460h]@14
Ritor1
parents:
diff changeset
140 FrameTableTxtLine v41; // [sp+84h] [bp-3E4h]@12
Ritor1
parents:
diff changeset
141 char Dest; // [sp+100h] [bp-368h]@14
Ritor1
parents:
diff changeset
142 char Buf; // [sp+178h] [bp-2F0h]@3
Ritor1
parents:
diff changeset
143 FrameTableTxtLine v44; // [sp+36Ch] [bp-FCh]@4
Ritor1
parents:
diff changeset
144 FrameTableTxtLine v45; // [sp+3E8h] [bp-80h]@4
Ritor1
parents:
diff changeset
145 FILE *File; // [sp+464h] [bp-4h]@1
Ritor1
parents:
diff changeset
146 unsigned int Argsa; // [sp+470h] [bp+8h]@3
Ritor1
parents:
diff changeset
147 int Argsb; // [sp+470h] [bp+8h]@15
Ritor1
parents:
diff changeset
148
Ritor1
parents:
diff changeset
149 v2 = this;
Ritor1
parents:
diff changeset
150 free(this->pObjects);
Ritor1
parents:
diff changeset
151 v3 = 0;
Ritor1
parents:
diff changeset
152 v2->pObjects = nullptr;
Ritor1
parents:
diff changeset
153 v2->uNumObjects = 0;
Ritor1
parents:
diff changeset
154 v4 = fopen(Args, "r");
Ritor1
parents:
diff changeset
155 File = v4;
Ritor1
parents:
diff changeset
156 if ( !v4 )
Ritor1
parents:
diff changeset
157 Error("ObjectDescriptionList::load - Unable to open file: %s.");
Ritor1
parents:
diff changeset
158
Ritor1
parents:
diff changeset
159 v5 = 0;
Ritor1
parents:
diff changeset
160 Argsa = 0;
Ritor1
parents:
diff changeset
161 if ( fgets(&Buf, 490, v4) )
Ritor1
parents:
diff changeset
162 {
Ritor1
parents:
diff changeset
163 do
Ritor1
parents:
diff changeset
164 {
Ritor1
parents:
diff changeset
165 *strchr(&Buf, 10) = 0;
Ritor1
parents:
diff changeset
166 memcpy(&v45, frame_table_txt_parser(&Buf, &v44), sizeof(v45));
Ritor1
parents:
diff changeset
167 if ( v45.uPropCount && *v45.pProperties[0] != '/' )
Ritor1
parents:
diff changeset
168 ++Argsa;
Ritor1
parents:
diff changeset
169 }
Ritor1
parents:
diff changeset
170 while ( fgets(&Buf, 490, File) );
Ritor1
parents:
diff changeset
171 v5 = Argsa;
Ritor1
parents:
diff changeset
172 v3 = 0;
Ritor1
parents:
diff changeset
173 }
Ritor1
parents:
diff changeset
174 v2->uNumObjects = v5;
Ritor1
parents:
diff changeset
175 v6 = malloc(56 * v5);
Ritor1
parents:
diff changeset
176 v2->pObjects = (ObjectDesc *)v6;
Ritor1
parents:
diff changeset
177 if ( v6 == (void *)v3 )
Ritor1
parents:
diff changeset
178 Error("ObjectDescriptionList::load - Out of Memory!");
Ritor1
parents:
diff changeset
179
Ritor1
parents:
diff changeset
180 memset(v6, v3, 56 * v2->uNumObjects);
Ritor1
parents:
diff changeset
181 v7 = File;
Ritor1
parents:
diff changeset
182 v2->uNumObjects = v3;
Ritor1
parents:
diff changeset
183 fseek(v7, v3, v3);
Ritor1
parents:
diff changeset
184 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
Ritor1
parents:
diff changeset
185 {
Ritor1
parents:
diff changeset
186 *strchr(&Buf, 10) = 0;
Ritor1
parents:
diff changeset
187 memcpy(&v45, frame_table_txt_parser(&Buf, &v41), sizeof(v45));
Ritor1
parents:
diff changeset
188 if ( v45.uPropCount && *v45.pProperties[0] != 47 )
Ritor1
parents:
diff changeset
189 {
Ritor1
parents:
diff changeset
190 strcpy(v2->pObjects[v2->uNumObjects].field_0, v45.pProperties[0]);
Ritor1
parents:
diff changeset
191 v9 = pSpriteFrameTable->FastFindSprite((char *)v45.pProperties[1]);
Ritor1
parents:
diff changeset
192 v10 = v45.pProperties[2];
Ritor1
parents:
diff changeset
193 v2->pObjects[v2->uNumObjects].uSpriteID = v9;
Ritor1
parents:
diff changeset
194 v11 = atoi(v10);
Ritor1
parents:
diff changeset
195 v12 = v45.pProperties[3];
Ritor1
parents:
diff changeset
196 v2->pObjects[v2->uNumObjects].uObjectID = v11;
Ritor1
parents:
diff changeset
197 v13 = atoi(v12);
Ritor1
parents:
diff changeset
198 v14 = v45.pProperties[4];
Ritor1
parents:
diff changeset
199 v2->pObjects[v2->uNumObjects].uRadius = v13;
Ritor1
parents:
diff changeset
200 v15 = atoi(v14);
Ritor1
parents:
diff changeset
201 v16 = v45.pProperties[5];
Ritor1
parents:
diff changeset
202 v2->pObjects[v2->uNumObjects].uHeight = v15;
Ritor1
parents:
diff changeset
203 v17 = atoi(v16);
Ritor1
parents:
diff changeset
204 v18 = v45.pProperties[6];
Ritor1
parents:
diff changeset
205 v2->pObjects[v2->uNumObjects].uLifetime = v17;
Ritor1
parents:
diff changeset
206 v19 = atoi(v18);
Ritor1
parents:
diff changeset
207 v20 = v45.pProperties[7];
Ritor1
parents:
diff changeset
208 v2->pObjects[v2->uNumObjects].uSpeed = v19;
Ritor1
parents:
diff changeset
209 strcpy(&Dest, v20);
Ritor1
parents:
diff changeset
210 memcpy(&v44, frame_table_txt_parser(&Dest, &v40), sizeof(v44));
Ritor1
parents:
diff changeset
211 if ( v45.uPropCount > 7 )
Ritor1
parents:
diff changeset
212 {
Ritor1
parents:
diff changeset
213 for ( Argsb = 0; Argsb < v44.uPropCount; ++Argsb )
Ritor1
parents:
diff changeset
214 {
Ritor1
parents:
diff changeset
215 v21 = Argsb;
Ritor1
parents:
diff changeset
216 v22 = v44.pProperties[Argsb];
Ritor1
parents:
diff changeset
217 if ( !_stricmp(v44.pProperties[Argsb], "NoDraw") )
Ritor1
parents:
diff changeset
218 {
Ritor1
parents:
diff changeset
219 v23 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
220 *(char *)v23 |= 1u;
Ritor1
parents:
diff changeset
221 }
Ritor1
parents:
diff changeset
222 if ( !_stricmp(v22, "Lifetime") )
Ritor1
parents:
diff changeset
223 {
Ritor1
parents:
diff changeset
224 v24 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
225 *(char *)v24 |= 4u;
Ritor1
parents:
diff changeset
226 }
Ritor1
parents:
diff changeset
227 if ( !_stricmp(v22, "FTLifetime") )
Ritor1
parents:
diff changeset
228 {
Ritor1
parents:
diff changeset
229 v25 = (int)&v2->pObjects[v2->uNumObjects];
Ritor1
parents:
diff changeset
230 *(short *)(v25 + 42) = 8 * pSpriteFrameTable->pSpriteSFrames[*(short *)(v25 + 40)].uAnimLength;
Ritor1
parents:
diff changeset
231 v26 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
232 *(char *)v26 |= 8u;
Ritor1
parents:
diff changeset
233 v27 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
234 *(char *)v27 |= 4u;
Ritor1
parents:
diff changeset
235 }
Ritor1
parents:
diff changeset
236 if ( !_stricmp(v22, "NoPickup") )
Ritor1
parents:
diff changeset
237 {
Ritor1
parents:
diff changeset
238 v28 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
239 *(char *)v28 |= 0x10u;
Ritor1
parents:
diff changeset
240 }
Ritor1
parents:
diff changeset
241 if ( !_stricmp(v22, "NoGravity") )
Ritor1
parents:
diff changeset
242 {
Ritor1
parents:
diff changeset
243 v29 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
244 *(char *)v29 |= 0x20u;
Ritor1
parents:
diff changeset
245 }
Ritor1
parents:
diff changeset
246 if ( !_stricmp(v22, "FlagOnIntercept") )
Ritor1
parents:
diff changeset
247 {
Ritor1
parents:
diff changeset
248 v30 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
249 *(char *)v30 |= 0x40u;
Ritor1
parents:
diff changeset
250 }
Ritor1
parents:
diff changeset
251 if ( !_stricmp(v22, "Bounce") )
Ritor1
parents:
diff changeset
252 {
Ritor1
parents:
diff changeset
253 v31 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
254 *(char *)v31 |= 0x80u;
Ritor1
parents:
diff changeset
255 }
Ritor1
parents:
diff changeset
256 v32 = v45.pProperties[v21];
Ritor1
parents:
diff changeset
257 if ( !_stricmp(v45.pProperties[v21], "Fire") )
Ritor1
parents:
diff changeset
258 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 2u;
Ritor1
parents:
diff changeset
259 if ( !_stricmp(v32, "Lines") )
Ritor1
parents:
diff changeset
260 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 4u;
Ritor1
parents:
diff changeset
261 if ( !_stricmp(v44.pProperties[v21], "bits") )
Ritor1
parents:
diff changeset
262 {
Ritor1
parents:
diff changeset
263 v33 = v44.pProperties[v21 + 1];
Ritor1
parents:
diff changeset
264 v34 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
Ritor1
parents:
diff changeset
265 *(char *)(v34 + 1) |= 1u;
Ritor1
parents:
diff changeset
266 v35 = atoi(v33);
Ritor1
parents:
diff changeset
267 v36 = v44.pProperties[v21 + 2];
Ritor1
parents:
diff changeset
268 v2->pObjects[v2->uNumObjects].uParticleTrailColorR = v35;
Ritor1
parents:
diff changeset
269 v37 = atoi(v36);
Ritor1
parents:
diff changeset
270 v38 = v44.pProperties[v21 + 3];
Ritor1
parents:
diff changeset
271 v2->pObjects[v2->uNumObjects].uParticleTrailColorG = v37;
Ritor1
parents:
diff changeset
272 v2->pObjects[v2->uNumObjects].uParticleTrailColorB = atoi(v38);
Ritor1
parents:
diff changeset
273 }
Ritor1
parents:
diff changeset
274 }
Ritor1
parents:
diff changeset
275 }
Ritor1
parents:
diff changeset
276 ++v2->uNumObjects;
Ritor1
parents:
diff changeset
277 }
Ritor1
parents:
diff changeset
278 }
Ritor1
parents:
diff changeset
279 fclose(File);
Ritor1
parents:
diff changeset
280 return 1;
Ritor1
parents:
diff changeset
281 }