Mercurial > mm7
annotate IconFrameTable.cpp @ 2316:25f771e528f0
Draw terrain
author | Ritor1 |
---|---|
date | Wed, 19 Mar 2014 17:30:14 +0600 |
parents | 42b6a910b5d8 |
children | d6887ee81068 |
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:
2098
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
1295 | 2 #include "IconFrameTable.h" |
3 #include "LOD.h" | |
4 #include "mm7_data.h" | |
5 #include "FrameTableInc.h" | |
6 | |
7 //----- (00494F3A) -------------------------------------------------------- | |
8 unsigned int IconFrameTable::FindIcon(const char *pIconName) | |
9 { | |
2273 | 10 for ( uint i = 0; i < (signed int)this->uNumIcons; i++ ) |
1295 | 11 { |
2273 | 12 if ( !_stricmp(pIconName, this->pIcons[i].pAnimationName) ) |
13 return i; | |
1295 | 14 } |
2273 | 15 return 0; |
1295 | 16 } |
17 | |
18 //----- (00494F70) -------------------------------------------------------- | |
19 IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID) | |
20 { | |
21 int v6; // edx@3 | |
2273 | 22 uint i; |
1295 | 23 |
2273 | 24 if ( this->pIcons[uIconID].uFlags & 1 && this->pIcons[uIconID].uAnimLength != 0 ) |
1295 | 25 { |
2273 | 26 v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)this->pIcons[uIconID].uAnimLength; |
27 for ( i = uIconID; v6 > this->pIcons[i].uAnimTime; i++ ) | |
28 v6 -= this->pIcons[i].uAnimTime; | |
29 return &this->pIcons[i]; | |
1295 | 30 } |
31 else | |
2273 | 32 return &this->pIcons[uIconID]; |
1295 | 33 } |
34 | |
35 //----- (00494FBF) -------------------------------------------------------- | |
36 void IconFrameTable::InitializeAnimation(unsigned int uIconID) | |
37 { | |
38 unsigned int v3; // edi@3 | |
39 const char *i; // eax@3 | |
40 | |
41 if ( (signed int)uIconID <= (signed int)this->uNumIcons && (uIconID & 0x80000000u) == 0 ) | |
42 { | |
43 v3 = uIconID; | |
2273 | 44 for ( i = this->pIcons[uIconID].pTextureName; ; i = this->pIcons[v3].pTextureName ) |
1295 | 45 { |
2273 | 46 this->pIcons[v3].uTextureID = pIcons_LOD->LoadTexture(i, TEXTURE_16BIT_PALETTE); |
47 if ( !(this->pIcons[v3].uFlags & 1) ) | |
1295 | 48 break; |
49 ++v3; | |
50 } | |
51 } | |
52 } | |
53 | |
54 //----- (0049500A) -------------------------------------------------------- | |
55 void IconFrameTable::ToFile() | |
56 { | |
2273 | 57 //IconFrameTable *v1; // esi@1 |
1295 | 58 FILE *v2; // eax@1 |
2273 | 59 //FILE *v3; // edi@1 |
1295 | 60 |
2273 | 61 //IconFrameTable* Str = this; |
1295 | 62 |
2273 | 63 //v1 = Str; |
1295 | 64 v2 = fopen("data\\dift.bin", "wb"); |
2273 | 65 //v3 = v2; |
1295 | 66 if ( !v2 ) |
1545 | 67 Error("Unable to save dift.bin!"); |
2273 | 68 fwrite(this, 4, 1, v2); |
69 fwrite(this->pIcons, 0x20u, this->uNumIcons, v2); | |
70 fclose(v2); | |
1295 | 71 } |
72 | |
73 //----- (00495056) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
74 void IconFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1295 | 75 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
76 uint num_mm6_frames = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
77 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
78 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
79 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
80 uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
1545 | 81 Assert(uNumIcons); |
82 Assert(!num_mm8_frames); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
83 |
1583 | 84 pIcons = (IconFrame *)malloc(uNumIcons * sizeof(IconFrame)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
85 memcpy(pIcons, (char *)data_mm7 + 4, num_mm7_frames * sizeof(IconFrame)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
86 memcpy(pIcons + num_mm7_frames, (char *)data_mm6 + 4, num_mm6_frames * sizeof(IconFrame)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1296
diff
changeset
|
87 memcpy(pIcons + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(IconFrame)); |
1295 | 88 } |
89 | |
90 //----- (0049509D) -------------------------------------------------------- | |
91 int IconFrameTable::FromFileTxt(const char *Args) | |
92 { | |
2273 | 93 //IconFrameTable *v2; // ebx@1 |
1295 | 94 FILE *v3; // eax@1 |
95 int v4; // esi@3 | |
96 void *v5; // eax@10 | |
97 FILE *v6; // ST0C_4@12 | |
98 char *i; // eax@12 | |
99 const char *v8; // ST00_4@15 | |
100 int v9; // eax@16 | |
101 int v10; // edx@20 | |
102 int v11; // ecx@21 | |
103 int v12; // eax@22 | |
104 signed int j; // edx@25 | |
105 IconFrame *v14; // ecx@26 | |
106 int v15; // esi@26 | |
107 int k; // eax@27 | |
108 signed int result; // eax@11 | |
109 char Buf; // [sp+Ch] [bp-2F8h]@3 | |
110 FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4 | |
111 FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4 | |
112 int v21; // [sp+2F8h] [bp-Ch]@3 | |
113 int v22; // [sp+2FCh] [bp-8h]@3 | |
114 FILE *File; // [sp+300h] [bp-4h]@1 | |
115 int Argsa; // [sp+30Ch] [bp+8h]@26 | |
116 | |
2273 | 117 //v2 = this; |
1295 | 118 //TileTable::dtor((TileTable *)this); |
2273 | 119 __debugbreak();//Ritor1: this function not used |
1295 | 120 v3 = fopen(Args, "r"); |
121 File = v3; | |
122 if ( !v3 ) | |
1545 | 123 Error("IconFrameTable::load - Unable to open file: %s.", Args); |
1295 | 124 v4 = 0; |
125 v21 = 0; | |
126 v22 = 1; | |
127 if ( fgets(&Buf, 490, v3) ) | |
128 { | |
129 do | |
130 { | |
131 *strchr(&Buf, 10) = 0; | |
132 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
133 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
134 { | |
135 if ( v20.uPropCount < 3 ) | |
1545 | 136 Error("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22); |
1295 | 137 ++v21; |
138 } | |
139 ++v22; | |
140 } | |
141 while ( fgets(&Buf, 490, File) ); | |
142 v4 = v21; | |
143 } | |
2273 | 144 this->uNumIcons = v4; |
1583 | 145 v5 = malloc(32 * v4);//, "I Frames"); |
2273 | 146 this->pIcons = (IconFrame *)v5; |
1295 | 147 if ( v5 ) |
148 { | |
149 v6 = File; | |
2273 | 150 this->uNumIcons = 0; |
1295 | 151 fseek(v6, 0, 0); |
152 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
153 { | |
154 *strchr(&Buf, 10) = 0; | |
155 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20)); | |
156 if ( v20.uPropCount && *v20.pProperties[0] != 47 ) | |
157 { | |
2273 | 158 strcpy(this->pIcons[this->uNumIcons].pAnimationName, v20.pProperties[0]); |
159 strcpy(this->pIcons[this->uNumIcons].pTextureName, v20.pProperties[1]); | |
1295 | 160 v8 = v20.pProperties[2]; |
2273 | 161 this->pIcons[this->uNumIcons].uFlags = 0; |
1295 | 162 if ( !_stricmp(v8, "new") ) |
163 { | |
2273 | 164 v9 = (int)&this->pIcons[this->uNumIcons].uFlags; |
1295 | 165 *(char *)v9 |= 4u; |
166 } | |
2273 | 167 this->pIcons[this->uNumIcons].uAnimTime = atoi(v20.pProperties[3]); |
168 this->pIcons[this->uNumIcons].uAnimLength = 0; | |
169 this->pIcons[this->uNumIcons++].uTextureID = 0; | |
1295 | 170 } |
171 } | |
172 fclose(File); | |
173 v10 = 0; | |
2273 | 174 if ( (signed int)(this->uNumIcons - 1) > 0 ) |
1295 | 175 { |
176 v11 = 0; | |
177 do | |
178 { | |
2273 | 179 v12 = (int)&this->pIcons[v11]; |
1295 | 180 if ( !(*(char *)(v12 + 60) & 4) ) |
181 *(char *)(v12 + 28) |= 1u; | |
182 ++v10; | |
183 ++v11; | |
184 } | |
2273 | 185 while ( v10 < (signed int)(this->uNumIcons - 1) ); |
1295 | 186 } |
2273 | 187 for ( j = 0; j < (signed int)this->uNumIcons; *(short *)(Argsa + 26) = v15 ) |
1295 | 188 { |
2273 | 189 v14 = this->pIcons; |
1295 | 190 Argsa = (int)&v14[j]; |
191 v15 = *(short *)(Argsa + 24); | |
192 if ( *(char *)(Argsa + 28) & 1 ) | |
193 { | |
194 ++j; | |
195 for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 ) | |
196 { | |
197 v15 += *(short *)(k + 24); | |
198 ++j; | |
199 } | |
200 LOWORD(v15) = v14[j].uAnimTime + v15; | |
201 } | |
202 ++j; | |
203 } | |
204 result = 1; | |
205 } | |
206 else | |
207 { | |
208 fclose(File); | |
209 result = 0; | |
210 } | |
211 return result; | |
1296 | 212 } |
213 //----- (0042EB78) -------------------------------------------------------- | |
214 int IconFrameTable::GetIconAnimLength(unsigned int uIconID) | |
215 { | |
216 return 8 * this->pIcons[uIconID].uAnimLength; | |
1295 | 217 } |