World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
IconFrameTable.cpp
См. документацию.
2 
3 #include "Engine/Engine.h"
5 
6 #include "../LOD.h"
7 #include "FrameTableInc.h"
8 
10  if (!this->img) {
11  this->img = assets->GetImage_ColorKey(this->pTextureName, 0x7FF);
12  }
13 
14  return this->img;
15 }
16 
17 Icon *IconFrameTable::GetIcon(unsigned int idx) {
18  if (idx < this->uNumIcons) return &this->pIcons[idx];
19  return nullptr;
20 }
21 
22 Icon *IconFrameTable::GetIcon(const char *pIconName) {
23  for (unsigned int i = 0; i < this->uNumIcons; i++) {
24  if (!_stricmp(pIconName, this->pIcons[i].GetAnimationName()))
25  return &this->pIcons[i];
26  }
27  return nullptr;
28 }
29 
30 //----- (00494F3A) --------------------------------------------------------
31 unsigned int IconFrameTable::FindIcon(const char *pIconName) {
32  for (uint i = 0; i < (signed int)this->uNumIcons; i++) {
33  if (!_stricmp(pIconName, this->pIcons[i].GetAnimationName())) return i;
34  }
35  return 0;
36 }
37 
38 //----- (00494F70) --------------------------------------------------------
39 Icon *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int frame_time) {
40  // int v6; // edx@3
41  uint i;
42 
43  if (this->pIcons[uIconID].uFlags & 1 &&
44  this->pIcons[uIconID].GetAnimLength() != 0) {
45  uint t = frame_time;
46 
47  t = (t /*/ 8*/) %
48  (unsigned __int16)this->pIcons[uIconID].GetAnimLength();
49  t /= 8;
50  for (i = uIconID; t > this->pIcons[i].GetAnimTime(); i++)
51  t -= this->pIcons[i].GetAnimTime();
52  return &this->pIcons[i];
53  } else {
54  return &this->pIcons[uIconID];
55  }
56 }
57 
58 //----- (00494FBF) --------------------------------------------------------
59 void IconFrameTable::InitializeAnimation(unsigned int uIconID) {
60  if (uIconID && (signed int)uIconID <= (signed int)this->uNumIcons) {
61  for (uint i = uIconID;; ++i) {
62  if (!(this->pIcons[i].uFlags & 1)) {
63  break;
64  }
65  }
66  }
67 }
68 
69 //----- (0049500A) --------------------------------------------------------
71  // IconFrameTable *v1; // esi@1
72  FILE *v2; // eax@1
73  // FILE *v3; // edi@1
74 
75  // IconFrameTable* Str = this;
76 
77  // v1 = Str;
78  v2 = fopen("data\\dift.bin", "wb");
79  // v3 = v2;
80  if (!v2) Error("Unable to save dift.bin!");
81  fwrite(this, 4, 1, v2);
82  fwrite(this->pIcons, 0x20u, this->uNumIcons, v2);
83  fclose(v2);
84 }
85 
86 //----- (00495056) --------------------------------------------------------
87 void IconFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) {
88  uint num_mm6_frames = data_mm6 ? *(int *)data_mm6 : 0,
89  num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0,
90  num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0;
91 
92  uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames;
93  Assert(uNumIcons);
94  Assert(!num_mm6_frames);
95  Assert(!num_mm8_frames);
96 
98  (IconFrame_MM7 *)malloc(uNumIcons * sizeof(IconFrame_MM7));
99  if (pIcons == nullptr) {
100  logger->Warning(L"Malloc error");
101  Error("Malloc"); // is this recoverable
102  }
103 
104  memcpy(pIcons, (char *)data_mm7 + 4,
105  num_mm7_frames * sizeof(IconFrame_MM7));
106  // memcpy(pIcons + num_mm7_frames, (char *)data_mm6 + 4,
107  // num_mm6_frames * sizeof(IconFrame_MM7)); memcpy(pIcons + num_mm6_frames +
108  // num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames *
109  // sizeof(IconFrame_MM7));
110 
111  this->pIcons = new Icon[uNumIcons];
112  for (unsigned int i = 0; i < uNumIcons; ++i) {
113  pIcons[i].Deserialize(&this->pIcons[i]);
114 
115  this->pIcons[i].id = i;
116  }
117 }
118 
119 /*
120 //----- (0049509D) --------------------------------------------------------
121 int IconFrameTable::FromFileTxt(const char *Args)
122 {
123  //IconFrameTable *v2; // ebx@1
124  FILE *v3; // eax@1
125  int v4; // esi@3
126  void *v5; // eax@10
127  FILE *v6; // ST0C_4@12
128  char *i; // eax@12
129  const char *v8; // ST00_4@15
130  int v9; // eax@16
131  int v10; // edx@20
132  int v11; // ecx@21
133  int v12; // eax@22
134  signed int j; // edx@25
135  IconFrame_MM7 *v14; // ecx@26
136  int v15; // esi@26
137  int k; // eax@27
138  signed int result; // eax@11
139  char Buf; // [sp+Ch] [bp-2F8h]@3
140  FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4
141  FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4
142  int v21; // [sp+2F8h] [bp-Ch]@3
143  int v22; // [sp+2FCh] [bp-8h]@3
144  FILE *File; // [sp+300h] [bp-4h]@1
145  int Argsa; // [sp+30Ch] [bp+8h]@26
146 
147  //v2 = this;
148  //TileTable::dtor((TileTable *)this);
149  __debugbreak();//Ritor1: this function not used
150  v3 = fopen(Args, "r");
151  File = v3;
152  if ( !v3 )
153  Error("IconFrameTable::load - Unable to open file: %s.", Args);
154  v4 = 0;
155  v21 = 0;
156  v22 = 1;
157  if ( fgets(&Buf, 490, v3) )
158  {
159  do
160  {
161  *strchr(&Buf, 10) = 0;
162  memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
163  if ( v20.uPropCount && *v20.pProperties[0] != 47 )
164  {
165  if ( v20.uPropCount < 3 )
166  Error("IconFrameTable::loadText, too few arguments, %s line %i.",
167 Args, v22);
168  ++v21;
169  }
170  ++v22;
171  }
172  while ( fgets(&Buf, 490, File) );
173  v4 = v21;
174  }
175  this->uNumIcons = v4;
176  v5 = malloc(32 * v4);//, "I Frames");
177  this->pIcons = (IconFrame_MM7 *)v5;
178  if ( v5 )
179  {
180  v6 = File;
181  this->uNumIcons = 0;
182  fseek(v6, 0, 0);
183  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
184  {
185  *strchr(&Buf, 10) = 0;
186  memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
187  if ( v20.uPropCount && *v20.pProperties[0] != 47 )
188  {
189  strcpy(this->pIcons[this->uNumIcons].pAnimationName,
190 v20.pProperties[0]); strcpy(this->pIcons[this->uNumIcons].pTextureName,
191 v20.pProperties[1]); v8 = v20.pProperties[2];
192  this->pIcons[this->uNumIcons].uFlags = 0;
193  if ( !_stricmp(v8, "new") )
194  {
195  v9 = (int)&this->pIcons[this->uNumIcons].uFlags;
196  *(char *)v9 |= 4u;
197  }
198  this->pIcons[this->uNumIcons].uAnimTime = atoi(v20.pProperties[3]);
199  this->pIcons[this->uNumIcons].uAnimLength = 0;
200  this->pIcons[this->uNumIcons++].uTextureID = 0;
201  }
202  }
203  fclose(File);
204  v10 = 0;
205  if ( (signed int)(this->uNumIcons - 1) > 0 )
206  {
207  v11 = 0;
208  do
209  {
210  v12 = (int)&this->pIcons[v11];
211  if ( !(*(char *)(v12 + 60) & 4) )
212  *(char *)(v12 + 28) |= 1u;
213  ++v10;
214  ++v11;
215  }
216  while ( v10 < (signed int)(this->uNumIcons - 1) );
217  }
218  for ( j = 0; j < (signed int)this->uNumIcons; *(short *)(Argsa + 26) = v15 )
219  {
220  v14 = this->pIcons;
221  Argsa = (int)&v14[j];
222  v15 = *(short *)(Argsa + 24);
223  if ( *(char *)(Argsa + 28) & 1 )
224  {
225  ++j;
226  for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 )
227  {
228  v15 += *(short *)(k + 24);
229  ++j;
230  }
231  LOWORD(v15) = v14[j].uAnimTime + v15;
232  }
233  ++j;
234  }
235  result = 1;
236  }
237  else
238  {
239  fclose(File);
240  result = 0;
241  }
242  return result;
243 }*/
244 
245 /*
246 //----- (0042EB78) --------------------------------------------------------
247 int IconFrameTable::GetIconAnimLength(unsigned int uIconID)
248 {
249  return 8 * this->pIcons[uIconID].uAnimLength;
250 }*/
IconFrameTable.h
IconFrameTable::InitializeAnimation
void InitializeAnimation(unsigned int uIconID)
Definition: IconFrameTable.cpp:59
IconFrameTable::FromFile
void FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
Definition: IconFrameTable.cpp:87
LegacyImages.h
Icon::GetAnimLength
unsigned int GetAnimLength() const
Definition: IconFrameTable.h:20
Texture
Definition: Texture.h:4
Icon::GetTexture
Texture * GetTexture()
Definition: IconFrameTable.cpp:9
Engine.h
IconFrameTable::uNumIcons
unsigned int uNumIcons
Definition: IconFrameTable.h:64
IconFrameTable::ToFile
void ToFile()
Definition: IconFrameTable.cpp:70
IconFrameTable::GetIcon
Icon * GetIcon(unsigned int idx)
Definition: IconFrameTable.cpp:17
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
IconFrameTable::pIcons
Icon * pIcons
Definition: IconFrameTable.h:65
Icon::pTextureName
char pTextureName[12]
Definition: IconFrameTable.h:30
IconFrameTable::FindIcon
unsigned int FindIcon(const char *pIconName)
Definition: IconFrameTable.cpp:31
IconFrame_MM7
Definition: LegacyImages.h:562
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
IconFrameTable::GetFrame
Icon * GetFrame(unsigned int uIconID, unsigned int frame_time)
Definition: IconFrameTable.cpp:39
FrameTableInc.h
Icon
Definition: IconFrameTable.h:8
v2
GLfloat GLfloat GLfloat v2
Definition: SDL_opengl_glext.h:695
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
uint
unsigned int uint
Definition: MM7.h:4
Icon::GetAnimTime
unsigned int GetAnimTime() const
Definition: IconFrameTable.h:25
logger
Log * logger
Definition: IocContainer.cpp:47
Icon::img
Texture * img
Definition: IconFrameTable.h:46
img
GLint GLvoid * img
Definition: SDL_opengl.h:1980