comparison Engine/Tables/IconFrameTable.cpp @ 2499:68cdef6879a0

engine folder
author Ritor1
date Fri, 19 Sep 2014 02:57:42 +0600
parents
children a902abdfc7f2
comparison
equal deleted inserted replaced
2498:92eeeb5200f2 2499:68cdef6879a0
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include "../ErrorHandling.h"
7 #include "IconFrameTable.h"
8 #include "../LOD.h"
9 #include "../mm7_data.h"
10 #include "FrameTableInc.h"
11
12 //----- (00494F3A) --------------------------------------------------------
13 unsigned int IconFrameTable::FindIcon(const char *pIconName)
14 {
15 for ( uint i = 0; i < (signed int)this->uNumIcons; i++ )
16 {
17 if ( !_stricmp(pIconName, this->pIcons[i].pAnimationName) )
18 return i;
19 }
20 return 0;
21 }
22
23 //----- (00494F70) --------------------------------------------------------
24 IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID)
25 {
26 int v6; // edx@3
27 uint i;
28
29 if ( this->pIcons[uIconID].uFlags & 1 && this->pIcons[uIconID].uAnimLength != 0 )
30 {
31 v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)this->pIcons[uIconID].uAnimLength;
32 for ( i = uIconID; v6 > this->pIcons[i].uAnimTime; i++ )
33 v6 -= this->pIcons[i].uAnimTime;
34 return &this->pIcons[i];
35 }
36 else
37 return &this->pIcons[uIconID];
38 }
39
40 //----- (00494FBF) --------------------------------------------------------
41 void IconFrameTable::InitializeAnimation(unsigned int uIconID)
42 {
43 if ( uIconID && (signed int)uIconID <= (signed int)this->uNumIcons )
44 {
45 for ( uint i = uIconID; ; ++i )
46 {
47 this->pIcons[i].uTextureID = pIcons_LOD->LoadTexture(this->pIcons[i].pTextureName, TEXTURE_16BIT_PALETTE);
48 if ( !(this->pIcons[i].uFlags & 1) )
49 break;
50 }
51 }
52 }
53
54 //----- (0049500A) --------------------------------------------------------
55 void IconFrameTable::ToFile()
56 {
57 //IconFrameTable *v1; // esi@1
58 FILE *v2; // eax@1
59 //FILE *v3; // edi@1
60
61 //IconFrameTable* Str = this;
62
63 //v1 = Str;
64 v2 = fopen("data\\dift.bin", "wb");
65 //v3 = v2;
66 if ( !v2 )
67 Error("Unable to save dift.bin!");
68 fwrite(this, 4, 1, v2);
69 fwrite(this->pIcons, 0x20u, this->uNumIcons, v2);
70 fclose(v2);
71 }
72
73 //----- (00495056) --------------------------------------------------------
74 void IconFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
75 {
76 uint num_mm6_frames = data_mm6 ? *(int *)data_mm6 : 0,
77 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0,
78 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0;
79
80 uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames;
81 Assert(uNumIcons);
82 Assert(!num_mm8_frames);
83
84 pIcons = (IconFrame *)malloc(uNumIcons * sizeof(IconFrame));
85 memcpy(pIcons, (char *)data_mm7 + 4, num_mm7_frames * sizeof(IconFrame));
86 memcpy(pIcons + num_mm7_frames, (char *)data_mm6 + 4, num_mm6_frames * sizeof(IconFrame));
87 memcpy(pIcons + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(IconFrame));
88 }
89
90 //----- (0049509D) --------------------------------------------------------
91 int IconFrameTable::FromFileTxt(const char *Args)
92 {
93 //IconFrameTable *v2; // ebx@1
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
117 //v2 = this;
118 //TileTable::dtor((TileTable *)this);
119 __debugbreak();//Ritor1: this function not used
120 v3 = fopen(Args, "r");
121 File = v3;
122 if ( !v3 )
123 Error("IconFrameTable::load - Unable to open file: %s.", Args);
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 )
136 Error("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22);
137 ++v21;
138 }
139 ++v22;
140 }
141 while ( fgets(&Buf, 490, File) );
142 v4 = v21;
143 }
144 this->uNumIcons = v4;
145 v5 = malloc(32 * v4);//, "I Frames");
146 this->pIcons = (IconFrame *)v5;
147 if ( v5 )
148 {
149 v6 = File;
150 this->uNumIcons = 0;
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 {
158 strcpy(this->pIcons[this->uNumIcons].pAnimationName, v20.pProperties[0]);
159 strcpy(this->pIcons[this->uNumIcons].pTextureName, v20.pProperties[1]);
160 v8 = v20.pProperties[2];
161 this->pIcons[this->uNumIcons].uFlags = 0;
162 if ( !_stricmp(v8, "new") )
163 {
164 v9 = (int)&this->pIcons[this->uNumIcons].uFlags;
165 *(char *)v9 |= 4u;
166 }
167 this->pIcons[this->uNumIcons].uAnimTime = atoi(v20.pProperties[3]);
168 this->pIcons[this->uNumIcons].uAnimLength = 0;
169 this->pIcons[this->uNumIcons++].uTextureID = 0;
170 }
171 }
172 fclose(File);
173 v10 = 0;
174 if ( (signed int)(this->uNumIcons - 1) > 0 )
175 {
176 v11 = 0;
177 do
178 {
179 v12 = (int)&this->pIcons[v11];
180 if ( !(*(char *)(v12 + 60) & 4) )
181 *(char *)(v12 + 28) |= 1u;
182 ++v10;
183 ++v11;
184 }
185 while ( v10 < (signed int)(this->uNumIcons - 1) );
186 }
187 for ( j = 0; j < (signed int)this->uNumIcons; *(short *)(Argsa + 26) = v15 )
188 {
189 v14 = this->pIcons;
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;
212 }
213 //----- (0042EB78) --------------------------------------------------------
214 int IconFrameTable::GetIconAnimLength(unsigned int uIconID)
215 {
216 return 8 * this->pIcons[uIconID].uAnimLength;
217 }