Skip to content

Instantly share code, notes, and snippets.

@cyberium
Created December 31, 2013 17:56
Show Gist options
  • Save cyberium/8200245 to your computer and use it in GitHub Desktop.
Save cyberium/8200245 to your computer and use it in GitHub Desktop.
commit b6bd5dd9ef35ec2158c27a92ff215028e1493911
Author: Cyberium <cybermomo@techemail.com>
Date: Tue Dec 31 18:53:45 2013 +0100
add possibility to extract only some tile
diff --git a/contrib/mesh_extractor/src/ContinentBuilder.cpp b/contrib/mesh_extractor/src/ContinentBuilder.cpp
index 8321a79..867c777 100644
--- a/contrib/mesh_extractor/src/ContinentBuilder.cpp
+++ b/contrib/mesh_extractor/src/ContinentBuilder.cpp
@@ -124,7 +124,12 @@ void ContinentBuilder::Build()
printf("Map %s ( %u ) has %u tiles. Building them with %u threads\n", Continent.c_str(), MapId, uint32(TileMap->TileTable.size()), NumberOfThreads);
for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
+ {
+ if ((onlyTileX > 0) && (onlyTileY > 0) && ((onlyTileX != itr->X) || (onlyTileY != itr->Y)))
+ continue; // skip all undesired tiles
+
pool->Enqueue(new TileBuildRequest(this, Continent, itr->X, itr->Y, MapId, params));
+ }
for (uint32 i = 0; i < NumberOfThreads; ++i)
_threads.push_back(new BuilderThread(this, pool->Queue()));
diff --git a/contrib/mesh_extractor/src/ContinentBuilder.h b/contrib/mesh_extractor/src/ContinentBuilder.h
index ce1eef9..7302d5a 100644
--- a/contrib/mesh_extractor/src/ContinentBuilder.h
+++ b/contrib/mesh_extractor/src/ContinentBuilder.h
@@ -30,8 +30,8 @@
class ContinentBuilder
{
public:
- ContinentBuilder(std::string continent, uint32 mapId, WDT* wdt, uint32 tn) :
- Continent(continent), TileMap(wdt), MapId(mapId),
+ ContinentBuilder(std::string continent, uint32 mapId, WDT* wdt, uint32 tn, int tx, int ty) :
+ Continent(continent), TileMap(wdt), MapId(mapId), onlyTileX(tx), onlyTileY(ty),
NumberOfThreads(tn), tileXMin(64), tileYMin(64), tileXMax(0), tileYMax(0)
{}
@@ -49,6 +49,7 @@ private:
int tileYMin;
int tileXMax;
int tileYMax;
+ int onlyTileX; int onlyTileY; // if we only need to extract some tile
};
class TileBuildRequest : public ACE_Method_Request
diff --git a/contrib/mesh_extractor/src/MeshExtractor.cpp b/contrib/mesh_extractor/src/MeshExtractor.cpp
index b46f25f..2635fc9 100644
--- a/contrib/mesh_extractor/src/MeshExtractor.cpp
+++ b/contrib/mesh_extractor/src/MeshExtractor.cpp
@@ -34,6 +34,8 @@
MPQManager* MPQHandler;
CacheClass* Cache;
+typedef std::set<uint32> MapSet;
+
bool IgnoreMap(uint32 id)
{
switch (id)
@@ -56,7 +58,7 @@ bool IgnoreMap(uint32 id)
return false;
}
-void ExtractMMaps(std::set<uint32>& mapIds, uint32 threads)
+void ExtractMMaps(std::set<uint32>& mapIds, uint32 threads, int tileX, int tileY)
{
std::string basePath = "mmaps/";
Utils::CreateDir(basePath);
@@ -83,7 +85,7 @@ void ExtractMMaps(std::set<uint32>& mapIds, uint32 threads)
continue;
}
printf("Building %s MapId %u\n", name.c_str(), mapId);
- ContinentBuilder builder(name, mapId, &wdt, threads);
+ ContinentBuilder builder(name, mapId, &wdt, threads, tileX, tileY);
builder.Build();
}
}
@@ -289,7 +291,7 @@ void ExtractGameobjectModels()
Constants::ToWoWCoords = false;
}
-bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapList, bool& debugOutput, uint32& extractFlags)
+bool HandleArgs(int argc, char** argv, uint32& threads, MapSet& mapList, bool& debugOutput, uint32& extractFlags, int& tileX, int& tileY)
{
char* param = NULL;
extractFlags = 0;
@@ -303,7 +305,6 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapLis
return false;
threads = atoi(param);
- printf("Using %u threads\n", threads);
}
else if (strcmp(argv[i], "--maps") == 0)
{
@@ -320,8 +321,6 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapLis
}
free(copy);
-
- printf("Extracting only provided list of maps (%u).\n", uint32(mapList.size()));
}
else if (strcmp(argv[i], "--debug") == 0)
{
@@ -342,13 +341,28 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapLis
if (!(extractFlags & Constants::EXTRACT_FLAG_ALLOWED)) // Tried to use an invalid flag
return false;
+ }
+ else if (strcmp(argv[i], "--tile") == 0)
+ {
+ param = argv[++i];
+ if (!param)
+ return false;
+
+ char* stileX = strtok(param, ",");
+ char* stileY = strtok(NULL, ",");
+ int tilex = atoi(stileX);
+ int tiley = atoi(stileY);
+
+ if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX, "0") == 0))
+ tileX = tilex;
+ if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY, "0") == 0))
+ tileY = tiley;
- printf("Detected flags: \n");
- printf("* Extract DBCs: %s\n", (extractFlags & Constants::EXTRACT_FLAG_DBC) ? "Yes" : "No");
- printf("* Extract Maps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_MAPS) ? "Yes" : "No");
- printf("* Extract VMaps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_VMAPS) ? "Yes" : "No");
- printf("* Extract GameObject Models: %s\n", (extractFlags & Constants::EXTRACT_FLAG_GOB_MODELS) ? "Yes" : "No");
- printf("* Extract MMaps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_MMAPS) ? "Yes" : "No");
+ if (tileX < 0 || tileY < 0)
+ {
+ printf("invalid tile coords.\n");
+ return false;
+ }
}
}
return true;
@@ -359,6 +373,7 @@ void PrintUsage()
printf("MeshExtractor help.\n");
printf("* Use \"--threads <number>\" to specify <number> threads, default to 4 (Only available when extracting MMaps)\n");
printf("* Use \"--maps a,b,c,d,e\" to extract only the maps specified (Do not use spaces)\n");
+ printf("* Use \"--tile X,Y\" to build a specified tile number X,Y. One map id must be provided.\n");
printf("* Use \"--debug 1\" to generate debug information of the tiles (Only available when extracting MMaps)\n");
printf("* Use \"--extract X\" to extract the data specified by the flag X (Note: You can combine the flags with the bitwise OR operator |). Available flags are: \n");
{
@@ -390,9 +405,44 @@ void LoadTile(dtNavMesh*& navMesh, const char* tile)
}
// just for debug purposes
-bool AskUser()
+bool AskUser(uint32 threads, MapSet const& mapIds,bool debug, uint32 extractFlags, int tileX, int tileY)
{
- printf("Please push enter to continue or escape to exit.\n");
+ std::string str = "";
+ MapSet::iterator itr = mapIds.begin();
+ while (itr!=mapIds.end())
+ {
+ std::string s;
+ if (itr!=mapIds.begin())
+ str = str + " ," + std::to_string(*itr);
+ else
+ str = std::to_string(*itr);
+ itr++;
+ }
+ printf("*********************************************************************\n");
+ printf("********************** Mesh Extractor *******************************\n");
+ printf("*********************************************************************\n");
+ printf("*\n");
+ printf("* You want to :\n");
+ printf("*\n");
+ if (mapIds.empty())
+ printf("* - Extract all maps.\n");
+ else
+ printf("* - Extract map Id(s) : %s \n", str.c_str());
+ if ((tileX > 0) && (tileY > 0))
+ printf("* - Extract only tile [%i,%i]\n", tileX, tileY);
+ else
+ printf("* - Extract all tiles on these maps\n");
+ printf("* - Detected flags: \n");
+ printf("* Extract DBCs: %s\n", (extractFlags & Constants::EXTRACT_FLAG_DBC) ? "Yes" : "No");
+ printf("* Extract Maps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_MAPS) ? "Yes" : "No");
+ printf("* Extract VMaps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_VMAPS) ? "Yes" : "No");
+ printf("* Extract GameObject Models: %s\n", (extractFlags & Constants::EXTRACT_FLAG_GOB_MODELS) ? "Yes" : "No");
+ printf("* Extract MMaps: %s\n", (extractFlags & Constants::EXTRACT_FLAG_MMAPS) ? "Yes" : "No");
+ printf("* - Uses %u thread%s\n", threads, (threads > 1) ? "s" : "");
+ if (debug)
+ printf("* - Debug test\n");
+ printf("*********************************************************************\n");
+ printf("Please type 'y' to continue or enter to exit.\n");
std::string s;
std::getline(std::cin, s);
if (strcmp(s.c_str(), "y") == 0)
@@ -404,9 +454,10 @@ bool AskUser()
int main(int argc, char* argv[])
{
uint32 threads = 4, extractFlags = 0;
- std::set<uint32> mapIds;
+ MapSet mapIds;
+ int tilex = -1, tiley = -1;
- if (!HandleArgs(argc, argv, threads, mapIds, Constants::Debug, extractFlags))
+ if (!HandleArgs(argc, argv, threads, mapIds, Constants::Debug, extractFlags, tilex, tiley))
{
PrintUsage();
return -1;
@@ -418,10 +469,17 @@ int main(int argc, char* argv[])
PrintUsage();
return -1;
}
-
- if (!AskUser())
+
+ if (mapIds.empty() && ((tilex > 0) || (tiley >0)))
+ {
+ printf("You must provide map id with '--tile' parameters. Use '--maps' parameters.\n");
+ PrintUsage();
+ return -1;
+ }
+
+ if (!AskUser(threads, mapIds, Constants::Debug, extractFlags, tilex, tiley))
return 0;
-
+
Cache = new CacheClass();
MPQHandler = new MPQManager();
MPQHandler->Initialize();
@@ -430,7 +488,7 @@ int main(int argc, char* argv[])
ExtractDBCs();
if (extractFlags & Constants::EXTRACT_FLAG_MMAPS)
- ExtractMMaps(mapIds, threads);
+ ExtractMMaps(mapIds, threads, tilex, tiley);
if (extractFlags & Constants::EXTRACT_FLAG_GOB_MODELS)
ExtractGameobjectModels();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment