Skip to content

Commit

Permalink
Implement transport loading on RecastDemoMod
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberium committed Feb 25, 2022
1 parent a3ed568 commit 8d33f8e
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 24 deletions.
73 changes: 72 additions & 1 deletion contrib/recastdemomod/Include/CMaNGOS_Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <set>
#include <vector>
#include <map>
#include "Tools.h"
#include "MapData.h"
#include "DetourNavMesh.h"
Expand All @@ -37,12 +38,80 @@

#define MAX_TILE_TO_LOAD 9

typedef std::map<std::string, std::string> TransportDataContainer;
static TransportDataContainer TransportMap =
{
// List of MO Transport gameobjects
{"3015", "Transportship.wmo.vmo"},
{"3031", "Transport_Zeppelin.wmo.vmo"},
{"7087", "Transportship_Ne.wmo.vmo"},
// List of Transport gameobjects
{"0360", "Elevatorcar.m2.vmo"},
{"0455", "Undeadelevator.m2.vmo"},
// buildGameObject("Undeadelevatordoor.m2.vmo", 462); // no model on which to path
{"0561", "Ironforgeelevator.m2.vmo"},
// buildGameObject("Ironforgeelevatordoor.m2.vmo", 562); // no model on which to path
{"0807", "Gnomeelevatorcar01.m2.vmo"},
{"0808", "Gnomeelevatorcar02.m2.vmo"},
{"0827", "Gnomeelevatorcar03.m2.vmo"},
{"0852", "Gnomeelevatorcar03.m2.vmo"},
{"1587", "Gnomehutelevator.m2.vmo"},
{"2454", "Burningsteppselevator.m2.vmo"},
{"3831", "Subwaycar.m2.vmo"},
// TBC+
{"7026", "Ancdrae_Elevatorpiece.m2.vmo"},
{"7028", "Mushroombase_Elevator.m2.vmo"},
{"7043", "Cf_Elevatorplatform.m2.vmo"},
{"7060", "Cf_Elevatorplatform_Small.m2.vmo"},
{"7077", "Factoryelevator.m2.vmo"},
{"7163", "Ancdrae_Elevatorpiece_Netherstorm.m2.vmo"},
// WOTLK+
{"6637", "Blackcitadel.wmo.vmo"},
{"7446", "Transport_Icebreaker_Ship.wmo.vmo"},
{"7451", "Vr_Elevator_Gate.m2.vmo"},
{"7452", "Vr_Elevator_Lift.m2.vmo"},
{"7491", "Vr_Elevator_Gears.m2.vmo"},
{"7519", "Hf_Elevator_Gate.m2.vmo"},
{"7520", "Hf_Elevator_Lift_02.m2.vmo"},
{"7521", "Hf_Elevator_Lift.m2.vmo"},
{"7546", "Transport_Horde_Zeppelin.wmo.vmo"},
{"7570", "Transport_Pirate_Ship.wmo.vmo"},
{"7636", "Transport_Tuskarr_Ship.wmo.vmo"},
{"7642", "Vrykul_Gondola.m2.vmo"},
{"7648", "Logrun_Pumpelevator01.m2.vmo"},
{"7767", "Vrykul_Gondola_02.m2.vmo"},
{"7793", "Nexus_Elevator_Basestructure_01.m2.vmo"},
{"7794", "Id_Elevator.m2.vmo"},
{"7797", "Orc_Fortress_Elevator01.m2.vmo"},
{"7966", "Org_Arena_Pillar.m2.vmo"},
{"7973", "Org_Arena_Elevator.m2.vmo"},
{"8079", "Logrun_Pumpelevator02.m2.vmo"},
{"8080", "Logrun_Pumpelevator03.m2.vmo"},
{"8253", "Nd_Hordegunship.wmo.vmo"},
{"8254", "Nd_Alliancegunship.wmo.vmo"},
{"8258", "Org_Arena_Yellow_Elevator.m2.vmo"},
{"8259", "Org_Arena_Axe_Pillar.m2.vmo"},
{"8260", "Org_Arena_Lightning_Pillar.m2.vmo"},
{"8261", "Org_Arena_Ivory_Pillar.m2.vmo"},
{"8277", "Gundrak_Elevator_01.m2.vmo"},
{"8409", "Nd_Icebreaker_Ship_Bg_Transport.wmo.vmo"},
{"8410", "Nd_Ship_Ud_Bg_Transport.wmo.vmo"},
{"8587", "Ulduarraid_Gnomewing_Transport_Wmo.wmo.vmo"},
{"9001", "Nd_Hordegunship_Bg.wmo.vmo"},
{"9002", "Nd_Alliancegunship_Bg.wmo.vmo"},
{"9136", "Icecrown_Elevator.m2.vmo"},
{"9150", "Nd_Alliancegunship_Icecrown.wmo.vmo"},
{"9151", "Nd_Hordegunship_Icecrown.wmo.vmo"},
{"9248", "Icecrown_Elevator02.m2.vmo"},
};

enum ShowLevels
{
SHOW_LEVEL_NONE,
SHOW_LEVEL_MAP,
SHOW_LEVEL_NEIGHBOR_TILES,
SHOW_LEVEL_TILES
SHOW_LEVEL_TILES,
SHOW_LEVEL_TRANSPORT
};

struct SelectedTile
Expand Down Expand Up @@ -125,6 +194,7 @@ class CMaNGOS_Map
std::set <uint32> m_MapsFound;
std::set <uint32> m_NeighborTiles;
string m_TileButtonStr;
string m_transportButtonStr;
bool m_GeomChanged;

BuildContext* m_ctx;
Expand Down Expand Up @@ -185,6 +255,7 @@ class CMaNGOS_Map
bool ShowMapLevel(int height, int width);
bool ShowNeighborTiles(int height, int width);
bool ShowTilesLevel(int height, int width);
bool ShowTransportLevel(int height, int width);
bool LoadTileData(unsigned int tx, unsigned int ty);
bool GeomChanged();
inline void GetGeomBounds(float const* &bmin, float const* &bmax) { bmin = m_MapInfos->BMin(); bmax = m_MapInfos->BMax(); }
Expand Down
21 changes: 20 additions & 1 deletion contrib/recastdemomod/Include/GeomData.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,47 @@ class MeshInfos

};

enum MeshObjectType
{
MESH_OBJECT_TYPE_TILE,
MESH_OBJECT_TYPE_OBJECT
};

class MeshObjects
{
public:
MeshObjects(unsigned int mapId, unsigned int tx, unsigned int ty, BuildContext* ctx);
MeshObjects(const std::string modelName, BuildContext* ctx);
~MeshObjects();

inline MeshInfos const* GetMap() const { return m_MapInfos; }
inline MeshInfos const* GetVMap() const { return m_VMapInfos; }
inline MeshInfos const* GetModel() const { return m_ModelInfos; }

inline unsigned int GetTileX() const { return m_TileX; }
inline unsigned int GetTileY() const { return m_TileY; }
inline float const* BMin() const { return m_BMin; }
inline float const* BMax() const { return m_BMax; }
bool GetMeshData(G3D::Array<float> &sVerts, G3D::Array<int> &sTris, G3D::Array<float> &lVerts, G3D::Array<int> &lTris, G3D::Array<unsigned char> &liquidFlags) const;
static void GetMeshBounds(float const* verts, int vertCount, float* bmin, float* bmax);
static void GetTileBounds(unsigned int tileX, unsigned int tileY, float const* verts, int vertCount, float* bmin, float* bmax);
MeshObjectType GetMeshObjectType() const { return m_meshType; }

private:
void LoadMap();
void LoadVMap();
void MergeMeshArrays(G3D::Array<float> &dstVerts, G3D::Array<int> &dstTris, G3D::Array<float> const& srcVerts, G3D::Array<int> const& srcTris) const;
void LoadObject();
void MergeMeshArrays(G3D::Array<float>& dstVerts, G3D::Array<int>& dstTris, G3D::Array<float> const& srcVerts, G3D::Array<int> const& srcTris) const;
void MergeIndices(G3D::Array<int> &dst, G3D::Array<int> const* src, unsigned int offset) const;
MeshInfos* m_MapInfos;
MeshInfos* m_VMapInfos;
MeshInfos* m_ModelInfos;
MMAP::MeshData m_MapMesh;
MMAP::MeshData m_VMapMesh;
MMAP::MeshData m_ModelMesh;
BuildContext* m_Ctx;
std::string m_modelName;
MeshObjectType m_meshType;
float m_BMin[3];
float m_BMax[3];
unsigned int m_MapId;
Expand All @@ -97,7 +113,9 @@ class GeomData
~GeomData();

void Init(unsigned int mapId, BuildContext* ctx);
void Init(const std::string modelName, BuildContext* ctx);
MeshObjects const* LoadTile(unsigned int tx, unsigned int ty);
MeshObjects const* LoadModel(const std::string modelName);
bool RemoveTile(unsigned int tx, unsigned int ty);
void RemoveAllTiles();
MeshObjects const* GetMeshObjects(unsigned int tx, unsigned int ty) const;
Expand All @@ -115,6 +133,7 @@ class GeomData
MeshObjectsMap m_MeshObjectsMap;
BuildContext* m_Ctx;
unsigned int m_MapId;
std::string m_modelName;
bool m_NoMapFile;
float m_BMin[3];
float m_BMax[3];
Expand Down
2 changes: 2 additions & 0 deletions contrib/recastdemomod/Include/MMapData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class MMapData
~MMapData();

dtNavMesh* Init(unsigned int mapId, BuildContext* ctx);
bool LoadNavmesh(const char* fileName, TileInfos& tInfos);
bool LoadObjectNavMesh(const std::string fileName);
bool LoadTile(unsigned int tx, unsigned int ty);
bool LoadTile(float const* bmin, float const* bmax);
bool RemoveTile(unsigned int tx, unsigned int ty);
Expand Down
1 change: 1 addition & 0 deletions contrib/recastdemomod/Include/MapData.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MapInfos
MapInfos() : m_Initilized(false){}
void Init(unsigned int mapId, BuildContext* ctx);
bool LoadTile(unsigned int tx, unsigned int ty, bool loadGeom = true, bool loadMmap = true);
bool LoadModel(const std::string modelName, const std::string objId);
void RemoveTile(unsigned int tx, unsigned int ty);
void ClearNavMeshOfTile(unsigned int tx, unsigned int ty) { m_MMapData.RemoveTile(tx, ty); };
bool LoadNavMeshOfTile(unsigned int tx, unsigned int ty);
Expand Down
67 changes: 63 additions & 4 deletions contrib/recastdemomod/Source/CMaNGOS_Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void CMaNGOS_Map::Init()
memset(m_tileBmax, 0, sizeof(m_tileBmax));
memset(m_tileFileName, 0, sizeof(m_tileFileName));
m_TileButtonStr = "Click to choose a tile";
m_transportButtonStr = "Click to choose a transport";
ScanFoldersForMaps();
if (m_mapID < 0)
return;
Expand Down Expand Up @@ -440,6 +441,41 @@ bool CMaNGOS_Map::ShowTilesLevel(int height, int width)
return mouseOverMenu;
}

bool CMaNGOS_Map::ShowTransportLevel(int height, int width)
{
bool mouseOverMenu = false;
static int levelScroll = 0;
unsigned int winHSize = height - 20;
const unsigned int winWSize = 300;
if (imguiBeginScrollArea("Choose transport", width - 10 - 250 - 10 - winWSize, height - 10 - winHSize, winWSize, winHSize, &levelScroll))
mouseOverMenu = true;

for (auto transportData : TransportMap)
{
if (imguiItem(transportData.second.c_str()))
{
if (!m_MapInfos->IsEmpty())
{
ClearAllGeoms();
m_MapInfos = new MapInfos();
m_MapInfos->Init(m_mapID, m_ctx);
m_navMesh = m_MapInfos->GetNavMesh();
m_navQuery = m_MapInfos->GetNavMeshQuery();
}

if (m_MapInfos->LoadModel(transportData.second, transportData.first))
m_showLevel = SHOW_LEVEL_NONE;

if (m_MapInfos->IsEmpty())
m_transportButtonStr = "Click to choose a transport";
else
m_transportButtonStr = transportData.second;
}
}
imguiEndScrollArea();
return mouseOverMenu;
}

bool CMaNGOS_Map::ShowLevel(int height, int width)
{
char text[80];
Expand All @@ -456,13 +492,14 @@ bool CMaNGOS_Map::ShowLevel(int height, int width)
case SHOW_LEVEL_MAP: return ShowMapLevel(height, width); break;
case SHOW_LEVEL_NEIGHBOR_TILES: return ShowNeighborTiles(height, width); break;
case SHOW_LEVEL_TILES: return ShowTilesLevel(height, width); break;
case SHOW_LEVEL_TRANSPORT: return ShowTransportLevel(height, width); break;
default: return false; break;
}
}

void CMaNGOS_Map::handleExtraSettings()
{
imguiLabel("Map Id");
imguiLabel("Map Id:");
char buff[4];
memset(buff, 0, sizeof(buff));
itoa(m_mapID, buff, 10);
Expand All @@ -478,10 +515,10 @@ void CMaNGOS_Map::handleExtraSettings()
}
}

imguiLabel("Tile");
imguiLabel("Tile:");
if (imguiButton(m_TileButtonStr.c_str()))
{
if (m_showLevel == SHOW_LEVEL_TILES || m_showLevel == SHOW_LEVEL_NEIGHBOR_TILES)
if (m_showLevel != SHOW_LEVEL_NONE)
{
m_showLevel = SHOW_LEVEL_NONE;
}
Expand All @@ -494,6 +531,17 @@ void CMaNGOS_Map::handleExtraSettings()
}
}

imguiLabel("Transport objects:");
if (imguiButton(m_transportButtonStr.c_str()))
{
if (m_showLevel != SHOW_LEVEL_NONE)
{
m_showLevel = SHOW_LEVEL_NONE;
}
else
m_showLevel = SHOW_LEVEL_TRANSPORT;
}

if (!m_MapInfos->IsEmpty())
{
imguiSeparatorLine();
Expand Down Expand Up @@ -1204,10 +1252,10 @@ void CMaNGOS_Map::handleRender()
{
MeshInfos const* mmi = itr->second->GetMap();
MeshInfos const* vmi = itr->second->GetVMap();
MeshInfos const* gmi = itr->second->GetModel();

if (m_DrawMapMesh && mmi)
{

MeshDetails const* mmd = mmi->GetSolidMesh();
MeshDetails const* mlmi = mmi->GetLiquidMesh();
if (mmd)
Expand All @@ -1231,6 +1279,17 @@ void CMaNGOS_Map::handleRender()
if (vlmi)
duDebugDrawLiquidTriMesh(&dd, vlmi->Verts(), vlmi->VertCount(), vlmi->Tris(), vlmi->Normals(), vlmi->TrisCount(), texScale);
}

if (m_DrawMapMesh && gmi)
{
MeshDetails const* mmd = gmi->GetSolidMesh();
//MeshDetails const* mlmi = mmi->GetLiquidMesh();
if (mmd)
{
duDebugDrawTriMeshSlope(&dd, mmd->Verts(), mmd->VertCount(), mmd->Tris(), mmd->Normals(), mmd->TrisCount(),
m_agentMaxSlope, texScale);
}
}
}
}

Expand Down

0 comments on commit 8d33f8e

Please sign in to comment.