Core/VMaps: Implement loading phased tiles

This commit is contained in:
Ovahlord authored and Aokromes committed 2018-03-09 18:05:47 +01:00
1 parent 2281947ee9
commit 4bbdce57e2
21 files changed
+433 -142

No files matched your search

+43 -6
View File
@@ -79,13 +79,18 @@ char* GetExtension(char* FileName)
extern HANDLE WorldMpq;
ADTFile::ADTFile(char* filename) : ADT(WorldMpq, filename, false)
ADTFile::ADTFile(char* filename, bool cache) : ADT(WorldMpq, filename, false)
{
Adtfilename.append(filename);
cacheable = cache;
dirfileCache = nullptr;
}
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMapId)
{
if (dirfileCache)
return initFromCache(map_num, tileX, tileY, originalMapId);
if (ADT.isEof ())
return false;
@@ -107,14 +112,16 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
//printf("yMap = %s\n", yMap.c_str());
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile;
dirfile = fopen(dirname.c_str(), "ab");
FILE* dirfile = fopen(dirname.c_str(), "ab");
if (!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
if (cacheable)
dirfileCache = new std::vector<ADTOutputCache>();
while (!ADT.isEof())
{
char fourcc[5];
@@ -189,7 +196,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
uint32 id;
ADT.read(&id, 4);
ModelInstance inst(ADT, ModelInstanceNames[id].c_str(), map_num, tileX, tileY, dirfile);
ModelInstance inst(ADT, ModelInstanceNames[id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
}
delete[] ModelInstanceNames;
ModelInstanceNames = NULL;
@@ -204,7 +211,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
uint32 id;
ADT.read(&id, 4);
WMOInstance inst(ADT, WmoInstanceNames[id].c_str(), map_num, tileX, tileY, dirfile);
WMOInstance inst(ADT, WmoInstanceNames[id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
}
delete[] WmoInstanceNames;
@@ -221,7 +228,37 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
return true;
}
bool ADTFile::initFromCache(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMapId)
{
if (dirfileCache->empty())
return true;
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE* dirfile = fopen(dirname.c_str(), "ab");
if (!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
for (ADTOutputCache const& cached : *dirfileCache)
{
fwrite(&map_num, sizeof(uint32), 1, dirfile);
fwrite(&tileX, sizeof(uint32), 1, dirfile);
fwrite(&tileY, sizeof(uint32), 1, dirfile);
uint32 flags = cached.Flags;
if (map_num != originalMapId)
flags |= MOD_PARENT_SPAWN;
fwrite(&flags, sizeof(uint32), 1, dirfile);
fwrite(cached.Data.data(), cached.Data.size(), 1, dirfile);
}
fclose(dirfile);
return true;
}
ADTFile::~ADTFile()
{
ADT.close();
delete dirfileCache;
}