World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Класс HWLContainer

#include <HWLContainer.h>

+ Граф связей класса HWLContainer:

Открытые члены

 HWLContainer ()
 
virtual ~HWLContainer ()
 
bool Open (const String &pFilename)
 
HWLTextureLoadTexture (const String &pName)
 

Защищенные данные

FILE * pFile
 
Loglog
 
std::map< String, size_tmNodes
 

Подробное описание

См. определение в файле HWLContainer.h строка 26

Конструктор(ы)

◆ HWLContainer()

HWLContainer::HWLContainer ( )

См. определение в файле HWLContainer.cpp строка 17

17  {
18  pFile = nullptr;
20 }

Перекрестные ссылки log, pFile и Engine_::IocContainer::ResolveLogger().

+ Граф вызовов:

◆ ~HWLContainer()

HWLContainer::~HWLContainer ( )
virtual

См. определение в файле HWLContainer.cpp строка 22

22  {
23  if (pFile != nullptr) {
24  fclose(this->pFile);
25  }
26 }

Перекрестные ссылки pFile.

Методы

◆ Open()

bool HWLContainer::Open ( const String pFilename)

См. определение в файле HWLContainer.cpp строка 28

28  {
29  pFile = fopen(pFilename.c_str(), "rb");
30  if (!pFile) {
31  log->Warning(L"Failed to open file: %S", pFilename.c_str());
32  return false;
33  }
34 
35  HWLHeader header;
36  fread(&header, sizeof(HWLHeader), 1, pFile);
37  if (header.uSignature != 'TD3D') {
38  log->Warning(L"Invalid format: %S", pFilename.c_str());
39  return false;
40  }
41  fseek(pFile, header.uDataOffset, SEEK_SET);
42 
43  typedef struct HWLNode {
44  String sName;
45  size_t uOffset;
46  } HWLNode;
47  std::vector<HWLNode> vNodes;
48 
49  uint32_t uNumItems = 0;
50  fread(&uNumItems, 4, 1, pFile);
51  char tmpName[21];
52  for (unsigned int i = 0; i < uNumItems; ++i) {
53  fread(tmpName, 20, 1, pFile);
54  tmpName[20] = 0;
55  HWLNode node;
56  node.sName = MakeLower(String(tmpName));
57  node.uOffset = 0;
58  vNodes.push_back(node);
59  }
60 
61  for (unsigned int i = 0; i < uNumItems; ++i) {
62  uint32_t uOffset = 0;
63  fread(&uOffset, 4, 1, pFile);
64  vNodes[i].uOffset = uOffset;
65  }
66 
67  for (HWLNode &node : vNodes) {
68  mNodes[node.sName] = node.uOffset;
69  }
70 
71  return true;
72 }

Перекрестные ссылки log, MakeLower(), mNodes, pFile, HWLHeader::uDataOffset, HWLHeader::uSignature и Log::Warning().

Используется в RenderBase::Initialize().

+ Граф вызовов:
+ Граф вызова функции:

◆ LoadTexture()

HWLTexture * HWLContainer::LoadTexture ( const String pName)

См. определение в файле HWLContainer.cpp строка 88

88  {
89  if (mNodes.size() == 0) {
90  return nullptr;
91  }
92 
93  std::map<String, size_t>::iterator it = mNodes.find(MakeLower(pName));
94  if (it == mNodes.end()) {
95  return nullptr;
96  }
97  size_t uOffset = it->second;
98 
99  fseek(pFile, uOffset, SEEK_SET);
100 
101  HWLTextureHeader textureHeader;
102  fread(&textureHeader, sizeof(HWLTextureHeader), 1, pFile);
103 
104  HWLTexture *pTex = new HWLTexture;
105  pTex->uBufferWidth = textureHeader.uBufferWidth;
106  pTex->uBufferHeight = textureHeader.uBufferHeight;
107  pTex->uAreaWidth = textureHeader.uAreaWidth;
108  pTex->uAreaHeigth = textureHeader.uAreaHeigth;
109  pTex->uWidth = textureHeader.uWidth;
110  pTex->uHeight = textureHeader.uHeight;
111  pTex->uAreaX = textureHeader.uAreaX;
112  pTex->uAreaY = textureHeader.uAreaY;
113 
114  pTex->pPixels = new uint16_t[pTex->uWidth * pTex->uHeight];
115  if (textureHeader.uCompressedSize) {
117  fread((void*)buffer->GetData(), textureHeader.uCompressedSize, 1, pFile);
119  memcpy(pTex->pPixels, buffer->GetData(), buffer->GetSize());
120  } else {
121  fread(pTex->pPixels, 2, pTex->uWidth * pTex->uHeight, pFile);
122  }
123 
124  return pTex;
125 }

Перекрестные ссылки AllocMemBuffer(), MakeLower(), mNodes, pFile, HWLTexture::pPixels, HWLTexture::uAreaHeigth, HWLTextureHeader::uAreaHeigth, HWLTexture::uAreaWidth, HWLTextureHeader::uAreaWidth, HWLTexture::uAreaX, HWLTextureHeader::uAreaX, HWLTexture::uAreaY, HWLTextureHeader::uAreaY, HWLTexture::uBufferHeight, HWLTextureHeader::uBufferHeight, HWLTexture::uBufferWidth, HWLTextureHeader::uBufferWidth, HWLTextureHeader::uCompressedSize, HWLTexture::uHeight, HWLTextureHeader::uHeight, zlib::Uncompress(), HWLTexture::uWidth и HWLTextureHeader::uWidth.

Используется в RenderBase::LoadHwlBitmap(), Render::LoadHwlBitmap(), RenderBase::LoadHwlSprite() и Render::LoadHwlSprite().

+ Граф вызовов:
+ Граф вызова функции:

Данные класса

◆ pFile

FILE* HWLContainer::pFile
protected

См. определение в файле HWLContainer.h строка 36

Используется в HWLContainer(), LoadTexture(), Open() и ~HWLContainer().

◆ log

Log* HWLContainer::log
protected

См. определение в файле HWLContainer.h строка 37

Используется в HWLContainer() и Open().

◆ mNodes

std::map<String, size_t> HWLContainer::mNodes
protected

См. определение в файле HWLContainer.h строка 38

Используется в LoadTexture() и Open().


Объявления и описания членов классов находятся в файлах:
uint16_t
unsigned __int16 uint16_t
Definition: SDL_config.h:37
HWLTextureHeader::uHeight
uint32_t uHeight
Definition: HWLContainer.cpp:82
HWLTextureHeader::uBufferWidth
uint32_t uBufferWidth
Definition: HWLContainer.cpp:77
Engine_::IocContainer::ResolveLogger
static Log * ResolveLogger()
Definition: IocContainer.cpp:51
HWLTextureHeader::uWidth
uint32_t uWidth
Definition: HWLContainer.cpp:81
HWLTextureHeader::uAreaY
uint32_t uAreaY
Definition: HWLContainer.cpp:84
HWLTexture::uAreaWidth
int uAreaWidth
Definition: HWLContainer.h:15
HWLTexture
Definition: HWLContainer.h:9
HWLTexture::uBufferWidth
int uBufferWidth
Definition: HWLContainer.h:13
buffer
EGLContext EGLenum EGLClientBuffer buffer
Definition: SDL_egl.h:952
AllocMemBuffer
PMemBuffer AllocMemBuffer(size_t size)
Definition: MemBuffer.cpp:20
HWLHeader::uSignature
uint32_t uSignature
Definition: HWLContainer.cpp:12
HWLHeader::uDataOffset
uint32_t uDataOffset
Definition: HWLContainer.cpp:13
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
HWLTexture::uHeight
unsigned int uHeight
Definition: HWLContainer.h:18
HWLTextureHeader
Definition: HWLContainer.cpp:75
HWLTexture::uBufferHeight
int uBufferHeight
Definition: HWLContainer.h:14
HWLContainer::pFile
FILE * pFile
Definition: HWLContainer.h:36
HWLTexture::uWidth
unsigned int uWidth
Definition: HWLContainer.h:17
HWLHeader
Definition: HWLContainer.cpp:11
HWLTextureHeader::uAreaWidth
uint32_t uAreaWidth
Definition: HWLContainer.cpp:79
HWLTexture::pPixels
uint16_t * pPixels
Definition: HWLContainer.h:21
zlib::Uncompress
int Uncompress(void *dest, unsigned int *destLen, const void *source, unsigned int sourceLen)
Definition: ZlibWrapper.cpp:7
HWLContainer::log
Log * log
Definition: HWLContainer.h:37
HWLTextureHeader::uAreaHeigth
uint32_t uAreaHeigth
Definition: HWLContainer.cpp:80
HWLTextureHeader::uAreaX
uint32_t uAreaX
Definition: HWLContainer.cpp:83
HWLTextureHeader::uCompressedSize
uint32_t uCompressedSize
Definition: HWLContainer.cpp:76
HWLContainer::mNodes
std::map< String, size_t > mNodes
Definition: HWLContainer.h:38
HWLTextureHeader::uBufferHeight
uint32_t uBufferHeight
Definition: HWLContainer.cpp:78
MakeLower
String MakeLower(const String &text)
Definition: Strings.cpp:43
HWLTexture::uAreaX
int uAreaX
Definition: HWLContainer.h:19
HWLTexture::uAreaY
int uAreaY
Definition: HWLContainer.h:20
PMemBuffer
std::shared_ptr< IMemBuffer > PMemBuffer
Definition: MemBuffer.h:13
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
String
std::string String
Definition: Strings.h:10
HWLTexture::uAreaHeigth
int uAreaHeigth
Definition: HWLContainer.h:16