aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSubv <s.v.h21@hotmail.com>2012-09-30 08:27:56 -0500
committerSubv <s.v.h21@hotmail.com>2012-09-30 08:27:56 -0500
commit14b304d4f726aeaf5f48fdac4cd9ce8aad66c5c9 (patch)
tree36991dd942f4abe4e5035a0dcb57a891d08bc668 /src
parent5c9e917e5e2a4c934aaa7d061624a46ff4269c8f (diff)
Tools/MeshExtractor:
* Removed the cache of ADTs * Add the correct geometry for neighbor ADTs * Fixes more crashes * Calculate the correct bounds for the map tiles.
Diffstat (limited to 'src')
-rw-r--r--src/tools/mesh_extractor/ADT.cpp1
-rw-r--r--src/tools/mesh_extractor/Cache.h11
-rw-r--r--src/tools/mesh_extractor/ContinentBuilder.cpp57
-rw-r--r--src/tools/mesh_extractor/TileBuilder.cpp30
4 files changed, 68 insertions, 31 deletions
diff --git a/src/tools/mesh_extractor/ADT.cpp b/src/tools/mesh_extractor/ADT.cpp
index c564d7193cf..1684d0636f4 100644
--- a/src/tools/mesh_extractor/ADT.cpp
+++ b/src/tools/mesh_extractor/ADT.cpp
@@ -2,6 +2,7 @@
#include "DoodadHandler.h"
#include "LiquidHandler.h"
#include "WorldModelHandler.h"
+#include "Cache.h"
ADT::ADT( std::string file ) : ObjectData(NULL), Data(NULL), _DoodadHandler(NULL), _WorldModelHandler(NULL), _LiquidHandler(NULL), HasObjectData(false)
{
diff --git a/src/tools/mesh_extractor/Cache.h b/src/tools/mesh_extractor/Cache.h
index 49e268ec507..36bf4a7a693 100644
--- a/src/tools/mesh_extractor/Cache.h
+++ b/src/tools/mesh_extractor/Cache.h
@@ -7,7 +7,6 @@
class WorldModelRoot;
class Model;
-class ADT;
template<class K, class T>
class GenericCache
@@ -19,21 +18,23 @@ public:
void Insert(K key, T* val)
{
+ ACE_GUARD(ACE_Thread_Mutex, g, mutex);
+
if (_items.size() > FlushLimit)
Clear();
- ACE_GUARD(ACE_Thread_Mutex, g, mutex);
_items[key] = val;
}
T* Get(K key)
{
+ ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL);
typename std::map<K, T*>::iterator itr = _items.find(key);
if (itr != _items.end())
return itr->second;
return NULL;
}
- void Clear()
+ void Clear()
{
for (typename std::map<K, T*>::iterator itr = _items.begin(); itr != _items.end(); ++itr)
delete itr->second;
@@ -50,10 +51,10 @@ public:
CacheClass() {}
GenericCache<std::string, Model> ModelCache;
GenericCache<std::string, WorldModelRoot> WorldModelCache;
- GenericCache<std::pair<int32,int32>, ADT> AdtCache;
+
void Clear()
{
- AdtCache.Clear();
+
}
};
diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp
index 96f9085de8c..cdfe0ca050a 100644
--- a/src/tools/mesh_extractor/ContinentBuilder.cpp
+++ b/src/tools/mesh_extractor/ContinentBuilder.cpp
@@ -5,6 +5,7 @@
#include "DetourNavMesh.h"
#include "Cache.h"
#include "ace/Task.h"
+#include "Recast.h"
class BuilderThread : public ACE_Task<ACE_MT_SYNCH>
{
@@ -21,18 +22,24 @@ public:
printf("[%02i,%02i] Building tile\n", X, Y);
TileBuilder builder(Continent, X, Y, MapId);
char buff[100];
- sprintf(buff, "%03u%02u%02u.mmtile", MapId, X, Y);
+ sprintf(buff, "mmaps/%03u%02u%02u.mmtile", MapId, X, Y);
FILE* f = fopen(buff, "r");
if (f) // Check if file already exists.
{
+ printf("[%02i,%02i] Tile skipped, file already exists\n", X, Y);
fclose(f);
Free = true;
- return 0;
+ return 1;
}
uint8* nav = builder.Build();
if (nav)
{
f = fopen(buff, "wb");
+ if (!f)
+ {
+ printf("Could not create file %s. Check that you have write permissions to the destination folder and try again\n", buff);
+ return -1;
+ }
MmapTileHeader header;
header.size = builder.DataSize;
fwrite(&header, sizeof(MmapTileHeader), 1, f);
@@ -48,17 +55,52 @@ public:
bool Free;
};
+void getTileBounds(uint32 tileX, uint32 tileY, float* verts, int vertCount, float* bmin, float* bmax)
+{
+ // this is for elevation
+ if (verts && vertCount)
+ rcCalcBounds(verts, vertCount, bmin, bmax);
+ else
+ {
+ bmin[1] = FLT_MIN;
+ bmax[1] = FLT_MAX;
+ }
+
+ // this is for width and depth
+ bmax[0] = (32 - int(tileX)) * Constants::TileSize;
+ bmax[2] = (32 - int(tileY)) * Constants::TileSize;
+ bmin[0] = bmax[0] - Constants::TileSize;
+ bmin[2] = bmax[2] - Constants::TileSize;
+}
+
void ContinentBuilder::Build()
{
char buff[50];
- sprintf(buff, "%03u.mmap", MapId);
+ sprintf(buff, "mmaps/%03u.mmap", MapId);
FILE* mmap = fopen(buff, "wb");
+ if (!mmap)
+ {
+ printf("Could not create file %s. Check that you have write permissions to the destination folder and try again\n", buff);
+ return;
+ }
+
+ int tileXMin = 64, tileYMin = 64, tileXMax = 0, tileYMax = 0;
+ for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
+ {
+ tileXMax = std::max(itr->X, tileXMax);
+ tileXMin = std::min(itr->X, tileXMin);
+
+ tileYMax = std::max(itr->Y, tileYMax);
+ tileYMin = std::min(itr->Y, tileYMin);
+ }
+
+ float bmin[3], bmax[3];
+ getTileBounds(tileXMax, tileYMax, NULL, 0, bmin, bmax);
+
dtNavMeshParams params;
params.maxPolys = 32768;
- params.maxTiles = 4096;
- params.orig[0] = -17066.666f;
- params.orig[1] = 0.0f;
- params.orig[2] = -17066.666f;
+ params.maxTiles = TileMap->TileTable.size();
+ rcVcopy(params.orig, bmin);
params.tileHeight = 533.33333f;
params.tileWidth = 533.33333f;
fwrite(&params, sizeof(dtNavMeshParams), 1, mmap);
@@ -66,6 +108,7 @@ void ContinentBuilder::Build()
std::vector<BuilderThread*> Threads;
for (uint32 i = 0; i < NumberOfThreads; ++i)
Threads.push_back(new BuilderThread());
+ printf("Map %s ( %i ) has %i tiles. Building them with %i threads\n", Continent.c_str(), MapId, TileMap->TileTable.size(), NumberOfThreads);
for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
{
bool next = false;
diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp
index 5c2c4faab80..83137258710 100644
--- a/src/tools/mesh_extractor/TileBuilder.cpp
+++ b/src/tools/mesh_extractor/TileBuilder.cpp
@@ -51,14 +51,10 @@ uint8* TileBuilder::Build()
{
_Geometry = new Geometry();
_Geometry->Transform = true;
- ADT* adt = Cache->AdtCache.Get(std::make_pair(X, Y));
- if (!adt)
- {
- adt = new ADT(Utils::GetAdtPath(World, X, Y));
- adt->Read();
- Cache->AdtCache.Insert(std::make_pair(X, Y), adt);
- }
+ ADT* adt = new ADT(Utils::GetAdtPath(World, X, Y));
+ adt->Read();
_Geometry->AddAdt(adt);
+ delete adt;
if (_Geometry->Vertices.empty() && _Geometry->Triangles.empty())
return NULL;
@@ -77,20 +73,16 @@ uint8* TileBuilder::Build()
if (tx == X && ty == Y)
continue;
- ADT* _adt = Cache->AdtCache.Get(std::make_pair(tx, ty));
- if (!_adt)
+ ADT* _adt = new ADT(Utils::GetAdtPath(World, tx, ty));
+ // If this condition is met, it means that this wdt does not contain the ADT
+ if (!_adt->Data->Stream)
{
- _adt = new ADT(Utils::GetAdtPath(World, tx, ty));
- // If this condition is met, it means that this wdt does not contain the ADT
- if (!_adt->Data->Stream)
- {
- delete _adt;
- continue;
- }
- _adt->Read();
- Cache->AdtCache.Insert(std::make_pair(tx, ty), _adt);
+ delete _adt;
+ continue;
}
- _Geometry->AddAdt(adt);
+ _adt->Read();
+ _Geometry->AddAdt(_adt);
+ delete _adt;
}
}
uint32 numVerts = _Geometry->Vertices.size();