Skip to content

Commit 2e19198

Browse files
ShaurenOvahlord
authored andcommitted
Tools/mmaps_generator: Allow specifying custom offmesh area/flags
1 parent a8861be commit 2e19198

4 files changed

Lines changed: 71 additions & 44 deletions

File tree

src/tools/mmaps_generator/MapBuilder.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "IntermediateValues.h"
2121
#include "MMapDefines.h"
2222
#include "MapTree.h"
23+
#include "Memory.h"
2324
#include "ModelInstance.h"
2425
#include "PathCommon.h"
2526
#include "StringFormat.h"
@@ -60,7 +61,6 @@ namespace MMAP
6061
bool debugOutput, bool bigBaseUnit, int mapid, char const* offMeshFilePath, unsigned int threads) :
6162
m_terrainBuilder (nullptr),
6263
m_debugOutput (debugOutput),
63-
m_offMeshFilePath (offMeshFilePath),
6464
m_threads (threads),
6565
m_skipContinents (skipContinents),
6666
m_skipJunkMaps (skipJunkMaps),
@@ -83,6 +83,8 @@ namespace MMAP
8383
m_threads = std::max(1u, m_threads);
8484

8585
discoverTiles();
86+
87+
ParseOffMeshConnectionsFile(offMeshFilePath);
8688
}
8789

8890
/**************************************************************************/
@@ -193,6 +195,41 @@ namespace MMAP
193195
}
194196
}
195197

198+
/**************************************************************************/
199+
void MapBuilder::ParseOffMeshConnectionsFile(char const* offMeshFilePath)
200+
{
201+
// no meshfile input given?
202+
if (offMeshFilePath == nullptr)
203+
return;
204+
205+
auto fp = Trinity::make_unique_ptr_with_deleter(fopen(offMeshFilePath, "rb"), &::fclose);
206+
if (!fp)
207+
{
208+
printf(" loadOffMeshConnections:: input file %s not found!\n", offMeshFilePath);
209+
return;
210+
}
211+
212+
char buf[512] = { };
213+
while (fgets(buf, 512, fp.get()))
214+
{
215+
OffMeshData offMesh;
216+
int32 scanned = sscanf(buf, "%u %u,%u (%f %f %f) (%f %f %f) %f %hhu %hu", &offMesh.MapId, &offMesh.TileX, &offMesh.TileY,
217+
&offMesh.From[0], &offMesh.From[1], &offMesh.From[2], &offMesh.To[0], &offMesh.To[1], &offMesh.To[2],
218+
&offMesh.Radius, &offMesh.AreaId, &offMesh.Flags);
219+
if (scanned < 10)
220+
continue;
221+
222+
offMesh.Bidirectional = true;
223+
if (scanned < 12)
224+
offMesh.Flags = NAV_GROUND;
225+
226+
if (scanned < 11)
227+
offMesh.AreaId = NAV_AREA_GROUND;
228+
229+
m_offMeshConnections.push_back(offMesh);
230+
}
231+
}
232+
196233
/**************************************************************************/
197234
std::set<uint32>* MapBuilder::getTileList(uint32 mapID)
198235
{
@@ -508,7 +545,7 @@ namespace MMAP
508545
float bmin[3], bmax[3];
509546
m_mapBuilder->getTileBounds(tileX, tileY, allVerts.getCArray(), allVerts.size() / 3, bmin, bmax);
510547

511-
m_terrainBuilder->loadOffMeshConnections(mapID, tileX, tileY, meshData, m_mapBuilder->m_offMeshFilePath);
548+
m_terrainBuilder->loadOffMeshConnections(mapID, tileX, tileY, meshData, m_mapBuilder->m_offMeshConnections);
512549

513550
// build navmesh tile
514551
buildMoveMapTile(mapID, tileX, tileY, meshData, bmin, bmax, navMesh);

src/tools/mmaps_generator/MapBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ namespace MMAP
193193
uint32 percentageDone(uint32 totalTiles, uint32 totalTilesDone) const;
194194
uint32 currentPercentageDone() const;
195195

196+
void ParseOffMeshConnectionsFile(char const* offMeshFilePath);
197+
196198
TerrainBuilder* m_terrainBuilder;
197199
TileList m_tiles;
198200

199201
bool m_debugOutput;
200202

201-
char const* m_offMeshFilePath;
203+
std::vector<OffMeshData> m_offMeshConnections;
202204
unsigned int m_threads;
203205
bool m_skipContinents;
204206
bool m_skipJunkMaps;

src/tools/mmaps_generator/TerrainBuilder.cpp

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -836,51 +836,26 @@ namespace MMAP
836836
}
837837

838838
/**************************************************************************/
839-
void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, char const* offMeshFilePath)
839+
void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, std::vector<OffMeshData> const& offMeshConnections)
840840
{
841-
// no meshfile input given?
842-
if (offMeshFilePath == nullptr)
843-
return;
844-
845-
FILE* fp = fopen(offMeshFilePath, "rb");
846-
if (!fp)
847-
{
848-
printf(" loadOffMeshConnections:: input file %s not found!\n", offMeshFilePath);
849-
return;
850-
}
851-
852-
// pretty silly thing, as we parse entire file and load only the tile we need
853-
// but we don't expect this file to be too large
854-
char* buf = new char[512];
855-
while(fgets(buf, 512, fp))
841+
for (OffMeshData const& offMeshConnection : offMeshConnections)
856842
{
857-
float p0[3], p1[3];
858-
uint32 mid, tx, ty;
859-
float size;
860-
if (sscanf(buf, "%u %u,%u (%f %f %f) (%f %f %f) %f", &mid, &tx, &ty,
861-
&p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10)
843+
if (mapID != offMeshConnection.MapId || tileX != offMeshConnection.TileX || tileY != offMeshConnection.TileY)
862844
continue;
863845

864-
if (mapID == mid && tileX == tx && tileY == ty)
865-
{
866-
meshData.offMeshConnections.append(p0[1]);
867-
meshData.offMeshConnections.append(p0[2]);
868-
meshData.offMeshConnections.append(p0[0]);
869-
870-
meshData.offMeshConnections.append(p1[1]);
871-
meshData.offMeshConnections.append(p1[2]);
872-
meshData.offMeshConnections.append(p1[0]);
873-
874-
meshData.offMeshConnectionDirs.append(1); // 1 - both direction, 0 - one sided
875-
meshData.offMeshConnectionRads.append(size); // agent size equivalent
876-
// can be used same way as polygon flags
877-
meshData.offMeshConnectionsAreas.append((unsigned char)0xFF);
878-
meshData.offMeshConnectionsFlags.append((unsigned short)0xFF); // all movement masks can make this path
879-
}
846+
meshData.offMeshConnections.append(offMeshConnection.From[1]);
847+
meshData.offMeshConnections.append(offMeshConnection.From[2]);
848+
meshData.offMeshConnections.append(offMeshConnection.From[0]);
880849

881-
}
850+
meshData.offMeshConnections.append(offMeshConnection.To[1]);
851+
meshData.offMeshConnections.append(offMeshConnection.To[2]);
852+
meshData.offMeshConnections.append(offMeshConnection.To[0]);
882853

883-
delete [] buf;
884-
fclose(fp);
854+
meshData.offMeshConnectionDirs.append(offMeshConnection.Bidirectional ? 1 : 0);
855+
meshData.offMeshConnectionRads.append(offMeshConnection.Radius); // agent size equivalent
856+
// can be used same way as polygon flags
857+
meshData.offMeshConnectionsAreas.append(offMeshConnection.AreaId);
858+
meshData.offMeshConnectionsFlags.append(offMeshConnection.Flags);
859+
}
885860
}
886861
}

src/tools/mmaps_generator/TerrainBuilder.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ namespace MMAP
5858
// contrib/extractor/system.cpp
5959
// src/game/Map.cpp
6060

61+
struct OffMeshData
62+
{
63+
uint32 MapId;
64+
uint32 TileX;
65+
uint32 TileY;
66+
float From[3];
67+
float To[3];
68+
bool Bidirectional;
69+
float Radius;
70+
uint8 AreaId;
71+
uint16 Flags;
72+
};
73+
6174
struct MeshData
6275
{
6376
G3D::Array<float> solidVerts;
@@ -85,7 +98,7 @@ namespace MMAP
8598

8699
void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
87100
bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
88-
void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, char const* offMeshFilePath);
101+
void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, std::vector<OffMeshData> const& offMeshConnections);
89102

90103
bool usesLiquids() const { return !m_skipLiquid; }
91104

0 commit comments

Comments
 (0)