aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/mmaps_generator/MapBuilder.cpp2
-rw-r--r--src/tools/vmap4_extractor/adtfile.cpp49
-rw-r--r--src/tools/vmap4_extractor/adtfile.h23
-rw-r--r--src/tools/vmap4_extractor/model.cpp33
-rw-r--r--src/tools/vmap4_extractor/model.h3
-rw-r--r--src/tools/vmap4_extractor/vmapexport.cpp93
-rw-r--r--src/tools/vmap4_extractor/vmapexport.h5
-rw-r--r--src/tools/vmap4_extractor/wdtfile.cpp75
-rw-r--r--src/tools/vmap4_extractor/wdtfile.h25
-rw-r--r--src/tools/vmap4_extractor/wmo.cpp43
-rw-r--r--src/tools/vmap4_extractor/wmo.h3
11 files changed, 251 insertions, 103 deletions
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp
index a0f99ec6e5d..251df44dfa3 100644
--- a/src/tools/mmaps_generator/MapBuilder.cpp
+++ b/src/tools/mmaps_generator/MapBuilder.cpp
@@ -216,7 +216,7 @@ namespace MMAP
_workerThreads.push_back(std::thread(&MapBuilder::WorkerThread, this));
}
- m_tiles.sort([](MapTiles a, MapTiles b)
+ m_tiles.sort([](MapTiles const& a, MapTiles const& b)
{
return a.m_tiles->size() > b.m_tiles->size();
});
diff --git a/src/tools/vmap4_extractor/adtfile.cpp b/src/tools/vmap4_extractor/adtfile.cpp
index e70619f8d48..76292c33a1f 100644
--- a/src/tools/vmap4_extractor/adtfile.cpp
+++ b/src/tools/vmap4_extractor/adtfile.cpp
@@ -79,26 +79,33 @@ char* GetExtension(char* FileName)
extern CASC::StorageHandle CascStorage;
-ADTFile::ADTFile(char* filename) : ADT(CascStorage, filename, false), nWMO(0), nMDX(0)
+ADTFile::ADTFile(char* filename, bool cache) : ADT(CascStorage, filename, false), nWMO(0), nMDX(0)
{
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;
uint32 size;
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];
@@ -173,7 +180,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);
}
ModelInstanceNames.clear();
@@ -188,7 +195,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);
}
WmoInstanceNames.clear();
@@ -204,7 +211,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;
}
diff --git a/src/tools/vmap4_extractor/adtfile.h b/src/tools/vmap4_extractor/adtfile.h
index b388c8a581f..efe35647147 100644
--- a/src/tools/vmap4_extractor/adtfile.h
+++ b/src/tools/vmap4_extractor/adtfile.h
@@ -106,31 +106,28 @@ struct MapChunkHeader
uint32 effectId;
};
+struct ADTOutputCache
+{
+ uint32 Flags;
+ std::vector<uint8> Data;
+};
class ADTFile
{
private:
- //size_t mcnk_offsets[256], mcnk_sizes[256];
CASCFile ADT;
- //mcell Mcell;
std::string Adtfilename;
+ bool cacheable;
+ std::vector<ADTOutputCache>* dirfileCache;
public:
- ADTFile(char* filename);
+ ADTFile(char* filename, bool cache);
~ADTFile();
int nWMO;
int nMDX;
std::vector<std::string> WmoInstanceNames;
std::vector<std::string> ModelInstanceNames;
- bool init(uint32 map_num, uint32 tileX, uint32 tileY);
- //void LoadMapChunks();
-
- //uint32 wmo_count;
-/*
- const mcell& Getmcell() const
- {
- return Mcell;
- }
-*/
+ bool init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMapId);
+ bool initFromCache(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMapId);
};
char const* GetPlainName(char const* FileName);
diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp
index 12d7ee0ab2d..7ba041ef95e 100644
--- a/src/tools/vmap4_extractor/model.cpp
+++ b/src/tools/vmap4_extractor/model.cpp
@@ -19,6 +19,7 @@
#include "vmapexport.h"
#include "model.h"
#include "wmo.h"
+#include "adtfile.h"
#include "cascfile.h"
#include <cassert>
#include <algorithm>
@@ -154,7 +155,7 @@ Vec3D fixCoordSystem2(Vec3D v)
return Vec3D(v.x, v.z, v.y);
}
-ModelInstance::ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
+ModelInstance::ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
: id(0), scale(0), flags(0)
{
float ff[3];
@@ -190,6 +191,8 @@ ModelInstance::ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapI
uint32 tcflags = MOD_M2;
if (tileX == 65 && tileY == 65)
tcflags |= MOD_WORLDSPAWN;
+ if (mapID != originalMapId)
+ tcflags |= MOD_PARENT_SPAWN;
//write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, name
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
@@ -205,6 +208,34 @@ ModelInstance::ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapI
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
fwrite(ModelInstName, sizeof(char), nlen, pDirfile);
+ if (dirfileCache)
+ {
+ dirfileCache->emplace_back();
+ ADTOutputCache& cacheModelData = dirfileCache->back();
+ cacheModelData.Flags = tcflags & ~MOD_PARENT_SPAWN;
+ cacheModelData.Data.resize(
+ sizeof(uint16) + // adtId
+ sizeof(uint32) + // id
+ sizeof(float) * 3 + // pos
+ sizeof(float) * 3 + // rot
+ sizeof(float) + // sc
+ sizeof(uint32) + // nlen
+ nlen); // ModelInstName
+
+ uint8* cacheData = cacheModelData.Data.data();
+#define CACHE_WRITE(value, size, count, dest) memcpy(dest, value, size * count); dest += size * count;
+
+ CACHE_WRITE(&adtId, sizeof(uint16), 1, cacheData);
+ CACHE_WRITE(&id, sizeof(uint32), 1, cacheData);
+ CACHE_WRITE(&pos, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&rot, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&sc, sizeof(float), 1, cacheData);
+ CACHE_WRITE(&nlen, sizeof(uint32), 1, cacheData);
+ CACHE_WRITE(ModelInstName, sizeof(char), nlen, cacheData);
+
+#undef CACHE_WRITE
+ }
+
/* int realx1 = (int) ((float) pos.x / 533.333333f);
int realy1 = (int) ((float) pos.z / 533.333333f);
int realx2 = (int) ((float) pos.x / 533.333333f);
diff --git a/src/tools/vmap4_extractor/model.h b/src/tools/vmap4_extractor/model.h
index 312c1c8cf12..8e8a8c899d6 100644
--- a/src/tools/vmap4_extractor/model.h
+++ b/src/tools/vmap4_extractor/model.h
@@ -24,6 +24,7 @@
#include <vector>
class CASCFile;
+struct ADTOutputCache;
Vec3D fixCoordSystem(Vec3D v);
@@ -59,7 +60,7 @@ public:
float sc;
ModelInstance() : id(0), scale(0), flags(0), sc(0.0f) {}
- ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile);
+ ModelInstance(CASCFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
};
diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp
index 3f68a0c9fe4..80f10fd2af3 100644
--- a/src/tools/vmap4_extractor/vmapexport.cpp
+++ b/src/tools/vmap4_extractor/vmapexport.cpp
@@ -33,6 +33,7 @@
#include <list>
#include <map>
#include <unordered_map>
+#include <unordered_set>
#include <vector>
#include <cstdio>
#include <cerrno>
@@ -54,14 +55,14 @@
CASC::StorageHandle CascStorage;
-typedef struct
+struct map_info
{
char name[64];
- unsigned int id;
-}map_id;
+ int32 parent_id;
+};
-std::vector<map_id> map_ids;
-uint32 map_count;
+std::map<uint32, map_info> map_ids;
+std::unordered_set<uint32> maps_that_are_parents;
boost::filesystem::path input_path;
bool preciseVectorData = false;
@@ -108,7 +109,7 @@ struct MapLoadInfo
//static const char * szWorkDirMaps = ".\\Maps";
const char* szWorkDirWmo = "./Buildings";
-const char* szRawVMAPMagic = "VMAP045";
+const char* szRawVMAPMagic = "VMAP046";
#define CASC_LOCALES_COUNT 17
char const* CascLocaleNames[CASC_LOCALES_COUNT] =
@@ -274,26 +275,49 @@ bool ExtractSingleWmo(std::string& fname)
void ParsMapFiles()
{
- char fn[512];
- //char id_filename[64];
- char id[10];
- for (unsigned int i = 0; i < map_ids.size(); ++i)
+ std::unordered_map<uint32, WDTFile> wdts;
+ auto getWDT = [&wdts](uint32 mapId) -> WDTFile*
+ {
+ auto itr = wdts.find(mapId);
+ if (itr == wdts.end())
+ {
+ char fn[512];
+ char* name = map_ids[mapId].name;
+ sprintf(fn, "World\\Maps\\%s\\%s.wdt", name, name);
+ itr = wdts.emplace(std::piecewise_construct, std::forward_as_tuple(mapId), std::forward_as_tuple(fn, name, maps_that_are_parents.count(mapId) > 0)).first;
+ if (!itr->second.init(mapId))
+ {
+ wdts.erase(itr);
+ return nullptr;
+ }
+ }
+
+ return &itr->second;
+ };
+
+ for (auto itr = map_ids.begin(); itr != map_ids.end(); ++itr)
{
- sprintf(id, "%04u", map_ids[i].id);
- sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
- WDTFile WDT(fn,map_ids[i].name);
- if(WDT.init(id, map_ids[i].id))
+ if (WDTFile* WDT = getWDT(itr->first))
{
- printf("Processing Map %u\n[", map_ids[i].id);
- for (int x=0; x<64; ++x)
+ WDTFile* parentWDT = itr->second.parent_id >= 0 ? getWDT(itr->second.parent_id) : nullptr;
+ printf("Processing Map %u\n[", itr->first);
+ for (int32 x = 0; x < 64; ++x)
{
- for (int y=0; y<64; ++y)
+ for (int32 y = 0; y < 64; ++y)
{
- if (ADTFile *ADT = WDT.GetMap(x,y))
+ bool success = false;
+ if (ADTFile* ADT = WDT->GetMap(x, y))
+ {
+ success = ADT->init(itr->first, x, y, itr->first);
+ WDT->FreeADT(ADT);
+ }
+ if (!success && parentWDT)
{
- //sprintf(id_filename,"%02u %02u %04u",x,y,map_ids[i].id);//!!!!!!!!!
- ADT->init(map_ids[i].id, x, y);
- delete ADT;
+ if (ADTFile* ADT = parentWDT->GetMap(x, y))
+ {
+ ADT->init(itr->first, x, y, itr->second.parent_id);
+ parentWDT->FreeADT(ADT);
+ }
}
}
printf("#");
@@ -398,7 +422,7 @@ int main(int argc, char ** argv)
Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr);
bool success = true;
- const char *versionString = "V4.03 2015_05";
+ const char *versionString = "V4.06 2018_02";
// Use command line arguments, when some
if (!processArgv(argc, argv, versionString))
@@ -480,36 +504,35 @@ int main(int argc, char ** argv)
exit(1);
}
- map_ids.resize(db2.GetRecordCount());
- std::unordered_map<uint32, uint32> idToIndex;
for (uint32 x = 0; x < db2.GetRecordCount(); ++x)
{
DB2Record record = db2.GetRecord(x);
- map_ids[x].id = record.GetId();
+ map_info& m = map_ids[record.GetId()];
const char* map_name = record.GetString("Directory");
- size_t max_map_name_length = sizeof(map_ids[x].name);
+ size_t max_map_name_length = sizeof(m.name);
if (strlen(map_name) >= max_map_name_length)
{
printf("Fatal error: Map name too long!\n");
exit(1);
}
- strncpy(map_ids[x].name, map_name, max_map_name_length);
- map_ids[x].name[max_map_name_length - 1] = '\0';
- idToIndex[map_ids[x].id] = x;
+ strncpy(m.name, map_name, max_map_name_length);
+ m.name[max_map_name_length - 1] = '\0';
+ m.parent_id = int16(record.GetUInt16("ParentMapID"));
+ if (m.parent_id >= 0)
+ maps_that_are_parents.insert(m.parent_id);
}
for (uint32 x = 0; x < db2.GetRecordCopyCount(); ++x)
{
DB2RecordCopy copy = db2.GetRecordCopy(x);
- auto itr = idToIndex.find(copy.SourceRowId);
- if (itr != idToIndex.end())
+ auto itr = map_ids.find(copy.SourceRowId);
+ if (itr != map_ids.end())
{
- map_id id;
- id.id = copy.NewRowId;
- strcpy(id.name, map_ids[itr->second].name);
- map_ids.push_back(id);
+ map_info& id = map_ids[copy.NewRowId];
+ strcpy(id.name, itr->second.name);
+ id.parent_id = itr->second.parent_id;
}
}
diff --git a/src/tools/vmap4_extractor/vmapexport.h b/src/tools/vmap4_extractor/vmapexport.h
index a73d259d52b..c798fb496ba 100644
--- a/src/tools/vmap4_extractor/vmapexport.h
+++ b/src/tools/vmap4_extractor/vmapexport.h
@@ -24,8 +24,9 @@
enum ModelFlags
{
MOD_M2 = 1,
- MOD_WORLDSPAWN = 1<<1,
- MOD_HAS_BOUND = 1<<2
+ MOD_WORLDSPAWN = 1 << 1,
+ MOD_HAS_BOUND = 1 << 2,
+ MOD_PARENT_SPAWN = 1 << 3
};
extern const char * szWorkDirWmo;
diff --git a/src/tools/vmap4_extractor/wdtfile.cpp b/src/tools/vmap4_extractor/wdtfile.cpp
index c94775d7b0f..1f10e7883b0 100644
--- a/src/tools/vmap4_extractor/wdtfile.cpp
+++ b/src/tools/vmap4_extractor/wdtfile.cpp
@@ -19,6 +19,7 @@
#include "vmapexport.h"
#include "wdtfile.h"
#include "adtfile.h"
+#include "Common.h"
#include <cstdio>
char * wdtGetPlainName(char * FileName)
@@ -32,40 +33,45 @@ char * wdtGetPlainName(char * FileName)
extern CASC::StorageHandle CascStorage;
-WDTFile::WDTFile(char* file_name, char* file_name1):WDT(CascStorage, file_name), gnWMO(0)
+WDTFile::WDTFile(char const* storagePath, std::string mapName, bool cache)
+ : _file(CascStorage, storagePath), _mapName(std::move(mapName))
{
- filename.append(file_name1,strlen(file_name1));
+ if (cache)
+ {
+ _adtCache = Trinity::make_unique<ADTCache>();
+ memset(_adtCache->file, 0, sizeof(_adtCache->file));
+ }
+ else
+ _adtCache = nullptr;
}
-bool WDTFile::init(char* /*map_id*/, unsigned int mapID)
+WDTFile::~WDTFile() = default;
+
+bool WDTFile::init(uint32 mapId)
{
- if (WDT.isEof())
- {
- //printf("Can't find WDT file.\n");
+ if (_file.isEof())
return false;
- }
char fourcc[5];
uint32 size;
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
- FILE *dirfile;
- dirfile = fopen(dirname.c_str(), "ab");
- if(!dirfile)
+ FILE* dirfile = fopen(dirname.c_str(), "ab");
+ if (!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
- while (!WDT.isEof())
+ while (!_file.isEof())
{
- WDT.read(fourcc,4);
- WDT.read(&size, 4);
+ _file.read(fourcc,4);
+ _file.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
- size_t nextpos = WDT.getPos() + size;
+ size_t nextpos = _file.getPos() + size;
if (!strcmp(fourcc,"MAIN"))
{
@@ -76,7 +82,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID)
if (size)
{
char *buf = new char[size];
- WDT.read(buf, size);
+ _file.read(buf, size);
char *p = buf;
while (p < buf + size)
{
@@ -86,7 +92,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID)
FixNameCase(s, strlen(s));
FixNameSpaces(s, strlen(s));
p = p + strlen(p) + 1;
- gWmoInstansName.push_back(s);
+ _wmoNames.push_back(s);
ExtractSingleWmo(path);
}
@@ -98,36 +104,45 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID)
// global wmo instance data
if (size)
{
- gnWMO = (int)size / 64;
+ int32 gnWMO = (int)size / 64;
for (int i = 0; i < gnWMO; ++i)
{
int id;
- WDT.read(&id, 4);
- WMOInstance inst(WDT, gWmoInstansName[id].c_str(), mapID, 65, 65, dirfile);
+ _file.read(&id, 4);
+ WMOInstance inst(_file, _wmoNames[id].c_str(), mapId, 65, 65, mapId, dirfile, nullptr);
}
}
}
- WDT.seek((int)nextpos);
+ _file.seek((int)nextpos);
}
- WDT.close();
+ _file.close();
fclose(dirfile);
return true;
}
-WDTFile::~WDTFile(void)
+ADTFile* WDTFile::GetMap(int32 x, int32 y)
{
- WDT.close();
-}
+ if (!(x >= 0 && y >= 0 && x < 64 && y < 64))
+ return nullptr;
-ADTFile* WDTFile::GetMap(int x, int z)
-{
- if(!(x>=0 && z >= 0 && x<64 && z<64))
- return NULL;
+ if (_adtCache && _adtCache->file[x][y])
+ return _adtCache->file[x][y].get();
char name[512];
- sprintf(name,"World\\Maps\\%s\\%s_%d_%d_obj0.adt", filename.c_str(), filename.c_str(), x, z);
- return new ADTFile(name);
+ sprintf(name, "World\\Maps\\%s\\%s_%d_%d_obj0.adt", _mapName.c_str(), _mapName.c_str(), x, y);
+ ADTFile* adt = new ADTFile(name, _adtCache != nullptr);
+ if (_adtCache)
+ _adtCache->file[x][y].reset(adt);
+ return adt;
+}
+
+void WDTFile::FreeADT(ADTFile* adt)
+{
+ if (_adtCache)
+ return;
+
+ delete adt;
}
diff --git a/src/tools/vmap4_extractor/wdtfile.h b/src/tools/vmap4_extractor/wdtfile.h
index 89b71e9b99d..2fe09b94849 100644
--- a/src/tools/vmap4_extractor/wdtfile.h
+++ b/src/tools/vmap4_extractor/wdtfile.h
@@ -21,6 +21,7 @@
#include "cascfile.h"
#include "wmo.h"
+#include <memory>
#include <string>
#include <vector>
@@ -28,18 +29,22 @@ class ADTFile;
class WDTFile
{
-private:
- CASCFile WDT;
- std::string filename;
public:
- WDTFile(char* file_name, char* file_name1);
- ~WDTFile(void);
- bool init(char* map_id, unsigned int mapID);
-
- std::vector<std::string> gWmoInstansName;
- int gnWMO;
+ WDTFile(char const* storagePath, std::string mapName, bool cache);
+ ~WDTFile();
+ bool init(uint32 mapId);
- ADTFile* GetMap(int x, int z);
+ ADTFile* GetMap(int32 x, int32 y);
+ void FreeADT(ADTFile* adt);
+private:
+ CASCFile _file;
+ std::string _mapName;
+ std::vector<std::string> _wmoNames;
+ struct ADTCache
+ {
+ std::unique_ptr<ADTFile> file[64][64];
+ };
+ std::unique_ptr<ADTCache> _adtCache;
};
#endif
diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp
index 4607856d304..e24c95e6987 100644
--- a/src/tools/vmap4_extractor/wmo.cpp
+++ b/src/tools/vmap4_extractor/wmo.cpp
@@ -18,6 +18,7 @@
#include "vmapexport.h"
#include "wmo.h"
+#include "adtfile.h"
#include "vec3d.h"
#include <cstdio>
#include <cstdlib>
@@ -514,7 +515,7 @@ WMOGroup::~WMOGroup()
delete [] LiquBytes;
}
-WMOInstance::WMOInstance(CASCFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile)
+WMOInstance::WMOInstance(CASCFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
: currx(0), curry(0), wmo(NULL), doodadset(0), pos(), indx(0), id(0)
{
float ff[3];
@@ -578,7 +579,11 @@ WMOInstance::WMOInstance(CASCFile& f, char const* WmoInstName, uint32 mapID, uin
float scale = 1.0f;
uint32 flags = MOD_HAS_BOUND;
- if(tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN;
+ if (tileX == 65 && tileY == 65)
+ flags |= MOD_WORLDSPAWN;
+ if (mapID != originalMapId)
+ flags |= MOD_PARENT_SPAWN;
+
//write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
fwrite(&tileX, sizeof(uint32), 1, pDirfile);
@@ -591,10 +596,42 @@ WMOInstance::WMOInstance(CASCFile& f, char const* WmoInstName, uint32 mapID, uin
fwrite(&scale, sizeof(float), 1, pDirfile);
fwrite(&pos2, sizeof(float), 3, pDirfile);
fwrite(&pos3, sizeof(float), 3, pDirfile);
- uint32 nlen=strlen(WmoInstName);
+ uint32 nlen = strlen(WmoInstName);
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
fwrite(WmoInstName, sizeof(char), nlen, pDirfile);
+ if (dirfileCache)
+ {
+ dirfileCache->emplace_back();
+ ADTOutputCache& cacheModelData = dirfileCache->back();
+ cacheModelData.Flags = flags & ~MOD_PARENT_SPAWN;
+ cacheModelData.Data.resize(
+ sizeof(uint16) + // adtId
+ sizeof(uint32) + // id
+ sizeof(float) * 3 + // pos
+ sizeof(float) * 3 + // rot
+ sizeof(float) + // scale
+ sizeof(float) * 3 + // pos2
+ sizeof(float) * 3 + // pos3
+ sizeof(uint32) + // nlen
+ nlen); // WmoInstName
+
+ uint8* cacheData = cacheModelData.Data.data();
+#define CACHE_WRITE(value, size, count, dest) memcpy(dest, value, size * count); dest += size * count;
+
+ CACHE_WRITE(&adtId, sizeof(uint16), 1, cacheData);
+ CACHE_WRITE(&id, sizeof(uint32), 1, cacheData);
+ CACHE_WRITE(&pos, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&rot, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&scale, sizeof(float), 1, cacheData);
+ CACHE_WRITE(&pos2, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&pos3, sizeof(float), 3, cacheData);
+ CACHE_WRITE(&nlen, sizeof(uint32), 1, cacheData);
+ CACHE_WRITE(WmoInstName, sizeof(char), nlen, cacheData);
+
+#undef CACHE_WRITE
+ }
+
/* fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
MapName,
WmoInstName,
diff --git a/src/tools/vmap4_extractor/wmo.h b/src/tools/vmap4_extractor/wmo.h
index e9482f0d8d1..8bb147e986f 100644
--- a/src/tools/vmap4_extractor/wmo.h
+++ b/src/tools/vmap4_extractor/wmo.h
@@ -43,6 +43,7 @@ enum MopyFlags
class WMOInstance;
class WMOManager;
class CASCFile;
+struct ADTOutputCache;
/* for whatever reason a certain company just can't stick to one coordinate system... */
static inline Vec3D fixCoords(const Vec3D &v){ return Vec3D(v.z, v.x, v.y); }
@@ -138,7 +139,7 @@ public:
Vec3D pos2, pos3, rot;
uint32 indx, id;
- WMOInstance(CASCFile&f , char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile);
+ WMOInstance(CASCFile&f , char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
};
#endif