aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSubv <s.v.h21@hotmail.com>2012-09-28 17:09:44 -0500
committerSubv <s.v.h21@hotmail.com>2012-09-28 17:09:44 -0500
commit9b97a89ef8e1dd1694985d1fc8e88808da1550cd (patch)
treedac6f4e9aa1126db7800b5cef42651cca5ce3dd1 /src
parenteba6980b9a52f55859cb3bd93235e14866769514 (diff)
Tools/MeshExtractor: Fixed a crash and some other mistakes.
First glances of multithreading ( need to figure out a way around StormLib )
Diffstat (limited to 'src')
-rw-r--r--src/tools/mesh_extractor/ContinentBuilder.cpp88
-rw-r--r--src/tools/mesh_extractor/MapChunk.cpp1
-rw-r--r--src/tools/mesh_extractor/MeshExtractor.cpp2
-rw-r--r--src/tools/mesh_extractor/TileBuilder.cpp2
-rw-r--r--src/tools/mesh_extractor/TileBuilder.h3
5 files changed, 73 insertions, 23 deletions
diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp
index 7391ebb8767..02a4d3626b7 100644
--- a/src/tools/mesh_extractor/ContinentBuilder.cpp
+++ b/src/tools/mesh_extractor/ContinentBuilder.cpp
@@ -3,32 +3,29 @@
#include "WDT.h"
#include "Utils.h"
#include "DetourNavMesh.h"
+#include "ace/Task.h"
-void ContinentBuilder::Build()
+class BuilderThread : public ACE_Task<ACE_MT_SYNCH>
{
- char buff[50];
- sprintf(buff, "%03u.mmap", MapId);
- FILE* mmap = fopen(buff, "wb");
- dtNavMeshParams params;
- params.maxPolys = 32768;
- params.maxTiles = 4096;
- params.orig[0] = -17066.666f;
- params.orig[1] = 0.0f;
- params.orig[2] = -17066.666f;
- params.tileHeight = 533.33333f;
- params.tileWidth = 533.33333f;
- fwrite(&params, sizeof(dtNavMeshParams), 1, mmap);
- fclose(mmap);
- for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
+private:
+ int X, Y, MapId;
+ std::string Continent;
+public:
+ BuilderThread() : Free(true) {}
+ void SetData(int x, int y, int map, std::string cont) { X = x; Y = y; MapId = map; Continent = cont; }
+
+ int svc()
{
- TileBuilder builder(Continent, itr->X, itr->Y, TileMap, MapId);
+ Free = false;
+ TileBuilder builder(Continent, X, Y, MapId);
char buff[100];
- sprintf(buff, "%03u%02u%02u.mmtile", MapId, itr->X, itr->Y);
+ sprintf(buff, "%03u%02u%02u.mmtile", MapId, X, Y);
FILE* f = fopen(buff, "r");
if (f) // Check if file already exists.
{
fclose(f);
- continue;
+ Free = true;
+ return 0;
}
uint8* nav = builder.Build();
if (nav)
@@ -42,6 +39,59 @@ void ContinentBuilder::Build()
fclose(f);
}
dtFree(nav);
- printf("[%02u,%02u] Tile Built!\n", itr->X, itr->Y);
+ printf("[%02u,%02u] Tile Built!\n", X, Y);
+ Free = true;
+ return 0;
}
+
+ bool Free;
+};
+
+void ContinentBuilder::Build()
+{
+ char buff[50];
+ sprintf(buff, "%03u.mmap", MapId);
+ FILE* mmap = fopen(buff, "wb");
+ dtNavMeshParams params;
+ params.maxPolys = 32768;
+ params.maxTiles = 4096;
+ params.orig[0] = -17066.666f;
+ params.orig[1] = 0.0f;
+ params.orig[2] = -17066.666f;
+ params.tileHeight = 533.33333f;
+ params.tileWidth = 533.33333f;
+ fwrite(&params, sizeof(dtNavMeshParams), 1, mmap);
+ fclose(mmap);
+ std::vector<BuilderThread*> Threads;
+ /*for (uint32 i = 0; i < 1; ++i)
+ Threads.push_back(new BuilderThread());*/
+ for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
+ {
+ BuilderThread th;
+ th.SetData(itr->X, itr->Y, MapId, Continent);
+ th.svc();
+ /*bool next = false;
+ while (!next)
+ {
+ for (std::vector<BuilderThread*>::iterator _th = Threads.begin(); _th != Threads.end(); ++_th)
+ {
+ if ((*_th)->Free)
+ {
+ (*_th)->SetData(itr->X, itr->Y, MapId, Continent);
+ (*_th)->activate();
+ next = true;
+ break;
+ }
+ }
+ // Wait for 20 seconds
+ ACE_OS::sleep(ACE_Time_Value (0, 20000));
+ }*/
+ }
+
+ /*// Free memory
+ for (std::vector<BuilderThread*>::iterator _th = Threads.begin(); _th != Threads.end(); ++_th)
+ {
+ (*_th)->wait();
+ delete *_th;
+ }*/
}
diff --git a/src/tools/mesh_extractor/MapChunk.cpp b/src/tools/mesh_extractor/MapChunk.cpp
index 61c106f9766..debde08cda8 100644
--- a/src/tools/mesh_extractor/MapChunk.cpp
+++ b/src/tools/mesh_extractor/MapChunk.cpp
@@ -7,6 +7,7 @@ MapChunk::MapChunk( ADT* _adt, Chunk* chunk ) : Adt(_adt), Source(chunk)
FILE* stream = chunk->GetStream();
Header.Read(stream);
fseek(stream, chunk->Offset, SEEK_SET);
+ Index = Header.IndexX + Header.IndexY * 16;
GenerateVertices(stream);
}
diff --git a/src/tools/mesh_extractor/MeshExtractor.cpp b/src/tools/mesh_extractor/MeshExtractor.cpp
index a99cc4475a0..7ae6afadb84 100644
--- a/src/tools/mesh_extractor/MeshExtractor.cpp
+++ b/src/tools/mesh_extractor/MeshExtractor.cpp
@@ -23,7 +23,7 @@ void ExtractAllMaps(uint32 onlyMap)
WDT wdt("World\\maps\\" + name + "\\" + name + ".wdt");
if (!wdt.IsValid || wdt.IsGlobalModel)
continue;
- printf("Building %s MapId %u\n", name, mapId);
+ printf("Building %s MapId %u\n", name.c_str(), mapId);
ContinentBuilder builder(name, mapId, &wdt);
builder.Build();
}
diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp
index 8bbfd5afb69..baf1fa0375c 100644
--- a/src/tools/mesh_extractor/TileBuilder.cpp
+++ b/src/tools/mesh_extractor/TileBuilder.cpp
@@ -9,7 +9,7 @@
#include "RecastAlloc.h"
#include "DetourNavMeshBuilder.h"
-TileBuilder::TileBuilder(std::string world, int x, int y, WDT* wdt, uint32 mapId) : _Geometry(NULL), World(world), X(x), Y(y), MapId(mapId), DataSize(0), Wdt(wdt)
+TileBuilder::TileBuilder(std::string world, int x, int y, uint32 mapId) : _Geometry(NULL), World(world), X(x), Y(y), MapId(mapId), DataSize(0)
{
// Cell Size = TileSize / TileVoxelSize
// 1800 = TileVoxelSize
diff --git a/src/tools/mesh_extractor/TileBuilder.h b/src/tools/mesh_extractor/TileBuilder.h
index 261675af7e2..f91a732f70c 100644
--- a/src/tools/mesh_extractor/TileBuilder.h
+++ b/src/tools/mesh_extractor/TileBuilder.h
@@ -10,7 +10,7 @@ class WDT;
class TileBuilder
{
public:
- TileBuilder(std::string world, int x, int y, WDT* wdt, uint32 mapId);
+ TileBuilder(std::string world, int x, int y, uint32 mapId);
void CalculateTileBounds(float*& bmin, float*& bmax);
uint8* Build();
@@ -22,6 +22,5 @@ public:
rcContext* Context;
Geometry* _Geometry;
uint32 DataSize;
- WDT* Wdt;
};
#endif \ No newline at end of file