aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/game/Maps/Map.cpp9
-rwxr-xr-xsrc/server/game/Movement/MotionMaster.h4
-rw-r--r--src/tools/mmaps_generator/IntermediateValues.cpp2
-rw-r--r--src/tools/mmaps_generator/MapBuilder.cpp105
-rw-r--r--src/tools/mmaps_generator/MapBuilder.h1
-rw-r--r--src/tools/mmaps_generator/PathGenerator.cpp17
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.cpp23
7 files changed, 106 insertions, 55 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index b38f89eab8f..5e3699146f2 100755
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -71,8 +71,8 @@ Map::~Map()
if (!m_scriptSchedule.empty())
sScriptMgr->DecreaseScheduledScriptCount(m_scriptSchedule.size());
- MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId());
MMAP::MMapFactory::createOrGetMMapManager()->unloadMapInstance(GetId(), i_InstanceId);
+ MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId());
}
bool Map::ExistMap(uint32 mapid, int gx, int gy)
@@ -206,9 +206,12 @@ void Map::LoadMap(int gx, int gy, bool reload)
void Map::LoadMapAndVMap(int gx, int gy)
{
LoadMap(gx, gy);
- LoadMMap(gx, gy);
+ // Only load the data for the base map
if (i_InstanceId == 0)
- LoadVMap(gx, gy); // Only load the data for the base map
+ {
+ LoadVMap(gx, gy);
+ LoadMMap(gx, gy);
+ }
}
void Map::InitStateMachine()
diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h
index f10c6569cad..918896a5a81 100755
--- a/src/server/game/Movement/MotionMaster.h
+++ b/src/server/game/Movement/MotionMaster.h
@@ -154,13 +154,13 @@ class MotionMaster //: private std::stack<MovementGenerator *>
void MoveFleeing(Unit* enemy, uint32 time = 0);
void MovePoint(uint32 id, const Position &pos)
{ MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
- void MovePoint(uint32 id, float x, float y, float z, bool generatePath = false);
+ void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true);
// These two movement types should only be used with creatures having landing/takeoff animations
void MoveLand(uint32 id, Position const& pos);
void MoveTakeoff(uint32 id, Position const& pos);
- void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool generatePath = false);
+ void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool generatePath = true);
void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ);
void MoveJumpTo(float angle, float speedXY, float speedZ);
void MoveJump(float x, float y, float z, float speedXY, float speedZ, uint32 id = 0);
diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp
index 9eefb1e65f0..b473d6472a0 100644
--- a/src/tools/mmaps_generator/IntermediateValues.cpp
+++ b/src/tools/mmaps_generator/IntermediateValues.cpp
@@ -202,7 +202,7 @@ namespace MMAP
void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
{
char objFileName[255];
- sprintf(objFileName, "meshes/map%03u.obj", mapID);
+ sprintf(objFileName, "meshes/map%03u%02u%02u.obj", mapID, tileY, tileX);
FILE* objFile = fopen(objFileName, "wb");
if (!objFile)
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp
index 2987e6596dd..e47b2e5b44f 100644
--- a/src/tools/mmaps_generator/MapBuilder.cpp
+++ b/src/tools/mmaps_generator/MapBuilder.cpp
@@ -24,6 +24,7 @@
#include "LoginDatabase.h"
#include "DetourNavMeshBuilder.h"
+#include "DetourNavMesh.h"
#include "DetourCommon.h"
// These make the linker happy.
@@ -206,6 +207,56 @@ namespace MMAP
minX = 32 - bmax[0] / GRID_SIZE;
minY = 32 - bmax[2] / GRID_SIZE;
}
+
+ void MapBuilder::buildMeshFromFile(char* name)
+ {
+ FILE* file = fopen(name, "rb");
+ if (!file)
+ return;
+
+ printf("Building mesh from file\n");
+ int tileX, tileY, mapId;
+ fread(&mapId, sizeof(int), 1, file);
+ fread(&tileX, sizeof(int), 1, file);
+ fread(&tileY, sizeof(int), 1, file);
+
+ dtNavMesh* navMesh = NULL;
+ buildNavMesh(mapId, navMesh);
+ if (!navMesh)
+ {
+ printf("Failed creating navmesh! \n");
+ fclose(file);
+ return;
+ }
+
+
+ int verticesCount, indicesCount;
+ fread(&verticesCount, sizeof(int), 1, file);
+ fread(&indicesCount, sizeof(int), 1, file);
+
+ float* verts = new float[verticesCount];
+ int* inds = new int[indicesCount];
+
+ fread(verts, sizeof(float), verticesCount, file);
+ fread(inds, sizeof(int), indicesCount, file);
+
+ MeshData data;
+
+ for (int i = 0; i < verticesCount; ++i)
+ data.solidVerts.append(verts[i]);
+
+ for (int i = 0; i < indicesCount; ++i)
+ data.solidTris.append(inds[i]);
+
+ TerrainBuilder::cleanVertices(data.solidVerts, data.solidTris);
+ // get bounds of current tile
+ float bmin[3], bmax[3];
+ getTileBounds(tileX, tileY, data.solidVerts.getCArray(), data.solidVerts.size() / 3, bmin, bmax);
+
+ // build navmesh tile
+ buildMoveMapTile(mapId, tileX, tileY, data, bmin, bmax, navMesh);
+ fclose(file);
+ }
/**************************************************************************/
void MapBuilder::buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY)
@@ -451,17 +502,32 @@ namespace MMAP
Tile* tiles = new Tile[TILES_PER_MAP * TILES_PER_MAP];
// Initialize per tile config.
- rcConfig tileCfg;
- memcpy(&tileCfg, &config, sizeof(rcConfig));
+ rcConfig tileCfg = config;
tileCfg.width = config.tileSize + config.borderSize*2;
tileCfg.height = config.tileSize + config.borderSize*2;
+ // merge per tile poly and detail meshes
+ rcPolyMesh** pmmerge = new rcPolyMesh*[TILES_PER_MAP * TILES_PER_MAP];
+ if (!pmmerge)
+ {
+ printf("%s alloc pmmerge FIALED! \r", tileString);
+ return;
+ }
+
+ rcPolyMeshDetail** dmmerge = new rcPolyMeshDetail*[TILES_PER_MAP * TILES_PER_MAP];
+ if (!dmmerge)
+ {
+ printf("%s alloc dmmerge FIALED! \r", tileString);
+ return;
+ }
+
+ int nmerge = 0;
// build all tiles
for (int y = 0; y < TILES_PER_MAP; ++y)
{
for (int x = 0; x < TILES_PER_MAP; ++x)
{
- Tile& tile = tiles[x + y*TILES_PER_MAP];
+ Tile& tile = tiles[x + y * TILES_PER_MAP];
// Calculate the per tile bounding box.
tileCfg.bmin[0] = config.bmin[0] + (x*config.tileSize - config.borderSize)*config.cs;
@@ -469,12 +535,6 @@ namespace MMAP
tileCfg.bmax[0] = config.bmin[0] + ((x+1)*config.tileSize + config.borderSize)*config.cs;
tileCfg.bmax[2] = config.bmin[2] + ((y+1)*config.tileSize + config.borderSize)*config.cs;
- float tbmin[2], tbmax[2];
- tbmin[0] = tileCfg.bmin[0];
- tbmin[1] = tileCfg.bmin[2];
- tbmax[0] = tileCfg.bmax[0];
- tbmax[1] = tileCfg.bmax[2];
-
// build heightfield
tile.solid = rcAllocHeightfield();
if (!tile.solid || !rcCreateHeightfield(m_rcContext, *tile.solid, tileCfg.width, tileCfg.height, tileCfg.bmin, tileCfg.bmax, tileCfg.cs, tileCfg.ch))
@@ -488,7 +548,7 @@ namespace MMAP
memset(triFlags, NAV_GROUND, tTriCount*sizeof(unsigned char));
rcClearUnwalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, triFlags);
rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, config.walkableClimb);
- delete [] triFlags;
+ delete[] triFlags;
rcFilterLowHangingWalkableObstacles(m_rcContext, config.walkableClimb, *tile.solid);
rcFilterLedgeSpans(m_rcContext, tileCfg.walkableHeight, tileCfg.walkableClimb, *tile.solid);
@@ -554,30 +614,7 @@ namespace MMAP
tile.chf = NULL;
rcFreeContourSet(tile.cset);
tile.cset = NULL;
- }
- }
-
- // merge per tile poly and detail meshes
- rcPolyMesh** pmmerge = new rcPolyMesh*[TILES_PER_MAP * TILES_PER_MAP];
- if (!pmmerge)
- {
- printf("%s alloc pmmerge FIALED! \r", tileString);
- return;
- }
-
- rcPolyMeshDetail** dmmerge = new rcPolyMeshDetail*[TILES_PER_MAP * TILES_PER_MAP];
- if (!dmmerge)
- {
- printf("%s alloc dmmerge FIALED! \r", tileString);
- return;
- }
-
- int nmerge = 0;
- for (int y = 0; y < TILES_PER_MAP; ++y)
- {
- for (int x = 0; x < TILES_PER_MAP; ++x)
- {
- Tile& tile = tiles[x + y*TILES_PER_MAP];
+
if (tile.pmesh)
{
pmmerge[nmerge] = tile.pmesh;
diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h
index d0f33ce9a79..20789bf9bff 100644
--- a/src/tools/mmaps_generator/MapBuilder.h
+++ b/src/tools/mmaps_generator/MapBuilder.h
@@ -74,6 +74,7 @@ namespace MMAP
// builds all mmap tiles for the specified map id (ignores skip settings)
void buildMap(uint32 mapID);
+ void buildMeshFromFile(char* name);
// builds an mmap tile for the specified map and its mesh
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY);
diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp
index 2eb2c6545c4..7d9f59ed138 100644
--- a/src/tools/mmaps_generator/PathGenerator.cpp
+++ b/src/tools/mmaps_generator/PathGenerator.cpp
@@ -70,7 +70,8 @@ bool handleArgs(int argc, char** argv,
bool &debugOutput,
bool &silent,
bool &bigBaseUnit,
- char* &offMeshInputPath)
+ char* &offMeshInputPath,
+ char* &file)
{
char* param = NULL;
for (int i = 1; i < argc; ++i)
@@ -87,6 +88,13 @@ bool handleArgs(int argc, char** argv,
else
printf("invalid option for '--maxAngle', using default\n");
}
+ else if (strcmp(argv[i], "--file") == 0)
+ {
+ param = argv[++i];
+ if (!param)
+ return false;
+ file = param;
+ }
else if (strcmp(argv[i], "--tile") == 0)
{
param = argv[++i];
@@ -235,11 +243,12 @@ int main(int argc, char** argv)
silent = false,
bigBaseUnit = false;
char* offMeshInputPath = NULL;
+ char* file = NULL;
bool validParam = handleArgs(argc, argv, mapnum,
tileX, tileY, maxAngle,
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
- debugOutput, silent, bigBaseUnit, offMeshInputPath);
+ debugOutput, silent, bigBaseUnit, offMeshInputPath, file);
if (!validParam)
return silent ? -1 : finish("You have specified invalid parameters", -1);
@@ -262,7 +271,9 @@ int main(int argc, char** argv)
MapBuilder builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps,
skipBattlegrounds, debugOutput, bigBaseUnit, offMeshInputPath);
- if (tileX > -1 && tileY > -1 && mapnum >= 0)
+ if (file)
+ builder.buildMeshFromFile(file);
+ else if (tileX > -1 && tileY > -1 && mapnum >= 0)
builder.buildSingleTile(mapnum, tileX, tileY);
else if (mapnum >= 0)
builder.buildMap(uint32(mapnum));
diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp
index c696f6017a5..e16dd16707b 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.cpp
+++ b/src/tools/mmaps_generator/TerrainBuilder.cpp
@@ -767,25 +767,24 @@ namespace MMAP
int* t = tris.getCArray();
float* v = verts.getCArray();
+ G3D::Array<float> cleanVerts;
+ int index, count = 0;
// collect all the vertex indices from triangle
for (int i = 0; i < tris.size(); ++i)
{
if (vertMap.find(t[i]) != vertMap.end())
continue;
-
- vertMap.insert(std::pair<int, int>(t[i], 0));
- }
-
- // collect the vertices
- G3D::Array<float> cleanVerts;
- int index, count = 0;
- for (map<int, int>::iterator it = vertMap.begin(); it != vertMap.end(); ++it)
- {
- index = (*it).first;
- (*it).second = count;
- cleanVerts.append(v[index*3], v[index*3+1], v[index*3+2]);
+ std::pair<int, int> val;
+ val.first = t[i];
+
+ index = val.first;
+ val.second = count;
+
+ vertMap.insert(val);
+ cleanVerts.append(v[index * 3], v[index * 3 + 1], v[index * 3 + 2]);
count++;
}
+
verts.fastClear();
verts.append(cleanVerts);
cleanVerts.clear();