Core/Maps: backport ed75b0649add23e082976fa4e5d504bc0c312602

** No reextraction of maps needed **
This commit is contained in:
ariel- committed 2016-01-19 22:25:27 -03:00
1 parent 67bb4c0c3c
commit 9d351b5878
4 files changed
+97 -110

No files matched your search

+28 -44
View File
@@ -24,7 +24,7 @@
namespace MMAP
{
static char const* const MAP_FILE_NAME_FORMAT = "%smmaps/%03i.mmap";
static char const* const TILE_FILE_NAME_FORMAT = "%smmaps/%03i%02i%02i.mmtile";
// ######################## MMapManager ########################
@@ -50,6 +50,8 @@ namespace MMAP
_phaseTiles.insert(PhaseTileMap::value_type(phasedMapId, PhaseTileContainer()));
}
}
thread_safe_environment = false;
}
MMapDataSet::const_iterator MMapManager::GetMMapData(uint32 mapId) const
@@ -80,26 +82,20 @@ namespace MMAP
}
// load and init dtNavMesh - read parameters from file
std::string dataDir = sConfigMgr->GetStringDefault("DataDir", "./");
uint32 pathLen = dataDir.length() + strlen("/mmaps/%03i.mmap") + 1;
char *fileName = new char[pathLen];
snprintf(fileName, pathLen, (dataDir + "/mmaps/%03i.mmap").c_str(), mapId);
FILE* file = fopen(fileName, "rb");
std::string fileName = Trinity::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetStringDefault("DataDir", "./").c_str(), mapId);
FILE* file = fopen(fileName.c_str(), "rb");
if (!file)
{
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName);
delete[] fileName;
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName.c_str());
return false;
}
dtNavMeshParams params;
int count = fread(&params, sizeof(dtNavMeshParams), 1, file);
uint32 count = uint32(fread(&params, sizeof(dtNavMeshParams), 1, file));
fclose(file);
if (count != 1)
{
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName);
delete[] fileName;
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName.c_str());
return false;
}
@@ -108,13 +104,10 @@ namespace MMAP
if (dtStatusFailed(mesh->init(&params)))
{
dtFreeNavMesh(mesh);
TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap %03u from file %s", mapId, fileName);
delete[] fileName;
TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap %03u from file %s", mapId, fileName.c_str());
return false;
}
delete[] fileName;
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Loaded %03i.mmap", mapId);
// store inside our map list
@@ -129,7 +122,7 @@ namespace MMAP
return uint32(x << 16 | y);
}
bool MMapManager::loadMap(const std::string& basePath, uint32 mapId, int32 x, int32 y)
bool MMapManager::loadMap(const std::string& /*basePath*/, uint32 mapId, int32 x, int32 y)
{
// make sure the mmap is loaded and ready to load tiles
if (!loadMapData(mapId))
@@ -145,19 +138,13 @@ namespace MMAP
return false;
// load this tile :: mmaps/MMMXXYY.mmtile
uint32 pathLen = basePath.length() + strlen("/%03i%02i%02i.mmtile") + 1;
char *fileName = new char[pathLen];
snprintf(fileName, pathLen, (basePath + "/%03i%02i%02i.mmtile").c_str(), mapId, x, y);
FILE* file = fopen(fileName, "rb");
std::string fileName = Trinity::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetStringDefault("DataDir", "./"), mapId, x, y);
FILE* file = fopen(fileName.c_str(), "rb");
if (!file)
{
TC_LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '%s'", fileName);
delete[] fileName;
TC_LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '%s'", fileName.c_str());
return false;
}
delete[] fileName;
// read header
MmapTileHeader fileHeader;
@@ -205,12 +192,10 @@ namespace MMAP
return true;
}
else
{
TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y);
dtFree(data);
return false;
}
TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y);
dtFree(data);
return false;
}
PhasedTile* MMapManager::LoadTile(uint32 mapId, int32 x, int32 y)
@@ -413,13 +398,13 @@ namespace MMAP
return true;
}
dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId, TerrainSet /*swaps*/)
dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId, TerrainSet swaps)
{
MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
return NULL;
return itr->second->navMesh;
return itr->second->GetNavMesh(swaps);
}
dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 mapId, uint32 instanceId, TerrainSet swaps)
@@ -533,12 +518,9 @@ namespace MMAP
return;
}
uint32 old_x = oldTile->header->x;
uint32 old_y = oldTile->header->y;
// header xy is based on the swap map's tile set, wich doesn't have all the same tiles as root map, so copy the xy from the orignal header
memcpy(ptile->data + 8, (char*)&old_x, 4);
memcpy(ptile->data + 12, (char*)&old_y, 4);
header->x = oldTile->header->x;
header->y = oldTile->header->y;
// the removed tile's data
PhasedTile* pt = new PhasedTile();
@@ -571,7 +553,8 @@ namespace MMAP
dtNavMesh* MMapData::GetNavMesh(TerrainSet swaps)
{
for (uint32 swap : _activeSwaps)
std::set<uint32> activeSwaps = _activeSwaps; // _activeSwaps is modified inside RemoveSwap
for (uint32 swap : activeSwaps)
{
if (!swaps.count(swap)) // swap not active
{
@@ -580,11 +563,11 @@ namespace MMAP
RemoveSwap(itr->second, swap, itr->first); // remove swap
}
}
if (!swaps.empty())
// for each of the calling unit's terrain swaps
for (uint32 swap : swaps)
{
// for each of the calling unit's terrain swaps
for (uint32 swap : swaps)
if (!_activeSwaps.count(swap)) // swap not active
{
// for each of the terrain swap's xy tiles
if (PhaseTileContainer const* ptc = MMAP::MMapFactory::createOrGetMMapManager()->GetPhaseTileContainer(swap))
@@ -592,6 +575,7 @@ namespace MMAP
AddSwap(itr->second, swap, itr->first); // add swap
}
}
return navMesh;
}
}
+11 -19
View File
@@ -71,33 +71,29 @@ Map::~Map()
bool Map::ExistMap(uint32 mapid, int gx, int gy)
{
int len = sWorld->GetDataPath().length() + strlen("maps/%03u%02u%02u.map") + 1;
char* fileName = new char[len];
snprintf(fileName, len, (char *)(sWorld->GetDataPath() + "maps/%03u%02u%02u.map").c_str(), mapid, gx, gy);
std::string fileName = Trinity::StringFormat("maps/%03u%02u%02u.map", mapid, gx, gy);
bool ret = false;
FILE* pf = fopen(fileName, "rb");
if (!pf)
FILE* file = fopen(fileName.c_str(), "rb");
if (!file)
{
TC_LOG_ERROR("maps", "Map file '%s' does not exist!", fileName);
TC_LOG_ERROR("maps", "Map file '%s' does not exist!", fileName.c_str());
TC_LOG_ERROR("maps", "Please place MAP-files (*.map) in the appropriate directory (%s), or correct the DataDir setting in your worldserver.conf file.", (sWorld->GetDataPath()+"maps/").c_str());
}
else
{
map_fileheader header;
if (fread(&header, sizeof(header), 1, pf) == 1)
if (fread(&header, sizeof(header), 1, file) == 1)
{
if (header.mapMagic.asUInt != MapMagic.asUInt || header.versionMagic.asUInt != MapVersionMagic.asUInt)
TC_LOG_ERROR("maps", "Map file '%s' is from an incompatible map version (%.*s %.*s), %.*s %.*s is expected. Please recreate using the mapextractor.",
fileName, 4, header.mapMagic.asChar, 4, header.versionMagic.asChar, 4, MapMagic.asChar, 4, MapVersionMagic.asChar);
fileName.c_str(), 4, header.mapMagic.asChar, 4, header.versionMagic.asChar, 4, MapMagic.asChar, 4, MapVersionMagic.asChar);
else
ret = true;
}
fclose(pf);
fclose(file);
}
delete[] fileName;
return ret;
}
@@ -184,16 +180,12 @@ void Map::LoadMap(int gx, int gy, bool reload)
}
// map file name
char* tmp = NULL;
int len = sWorld->GetDataPath().length() + strlen("maps/%03u%02u%02u.map") + 1;
tmp = new char[len];
snprintf(tmp, len, (char *)(sWorld->GetDataPath() + "maps/%03u%02u%02u.map").c_str(), GetId(), gx, gy);
TC_LOG_DEBUG("maps", "Loading map %s", tmp);
std::string fileName = Trinity::StringFormat("maps/%03u%02u%02u.map", GetId(), gx, gy);
TC_LOG_DEBUG("maps", "Loading map %s", fileName.c_str());
// loading data
GridMaps[gx][gy] = new GridMap();
if (!GridMaps[gx][gy]->loadData(tmp))
TC_LOG_ERROR("maps", "Error loading map file: \n %s\n", tmp);
delete[] tmp;
if (!GridMaps[gx][gy]->loadData(fileName.c_str()))
TC_LOG_ERROR("maps", "Error loading map file: %s", fileName.c_str());
sScriptMgr->OnLoadGridMap(this, GridMaps[gx][gy], gx, gy);
}
+5 -13
View File
@@ -12,7 +12,7 @@ file(GLOB_RECURSE mmap_gen_sources *.cpp *.h)
set(mmap_gen_Includes
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/dep/libmpq
${CMAKE_SOURCE_DIR}/dep/cppformat
${CMAKE_SOURCE_DIR}/dep/zlib
${CMAKE_SOURCE_DIR}/dep/bzip2
${CMAKE_SOURCE_DIR}/dep/g3dlite/include
@@ -20,25 +20,16 @@ set(mmap_gen_Includes
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Recast/Include
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Detour
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Detour/Include
${CMAKE_SOURCE_DIR}/src/server/shared
${CMAKE_SOURCE_DIR}/src/server/game/Conditions
${CMAKE_SOURCE_DIR}/src/common
${CMAKE_SOURCE_DIR}/src/common/Utilities
${CMAKE_SOURCE_DIR}/src/common/Threading
${CMAKE_SOURCE_DIR}/src/server/game/Conditions
${CMAKE_SOURCE_DIR}/src/common/Collision
${CMAKE_SOURCE_DIR}/src/common/Collision/Management
${CMAKE_SOURCE_DIR}/src/common/Collision/Maps
${CMAKE_SOURCE_DIR}/src/common/Collision/Models
${CMAKE_SOURCE_DIR}/src/common/Debugging
${CMAKE_SOURCE_DIR}/src/common/Threading
${CMAKE_SOURCE_DIR}/src/common/Utilities
)
if( WIN32 )
set(mmap_gen_Includes
${mmap_gen_Includes}
${CMAKE_SOURCE_DIR}/dep/libmpq/win
)
endif()
include_directories(${mmap_gen_Includes})
add_executable(mmaps_generator ${mmap_gen_sources})
@@ -48,6 +39,7 @@ target_link_libraries(mmaps_generator
g3dlib
Recast
Detour
format
${BZIP2_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
+53 -34
View File
@@ -22,6 +22,7 @@
#include "DetourNavMeshBuilder.h"
#include "DetourNavMesh.h"
#include "IntermediateValues.h"
#include "StringFormat.h"
#include <limits.h>
@@ -81,7 +82,6 @@ namespace MMAP
{
std::vector<std::string> files;
uint32 mapID, tileX, tileY, tileID, count = 0;
char filter[12];
printf("Discovering maps... ");
getDirContents(files, "maps");
@@ -115,9 +115,8 @@ namespace MMAP
std::set<uint32>* tiles = (*itr).m_tiles;
mapID = (*itr).m_mapId;
sprintf(filter, "%03u*.vmtile", mapID);
files.clear();
getDirContents(files, "vmaps", filter);
getDirContents(files, "vmaps", Trinity::StringFormat("%03u*.vmtile", mapID));
for (uint32 i = 0; i < files.size(); ++i)
{
tileX = uint32(atoi(files[i].substr(7,2).c_str()));
@@ -128,9 +127,8 @@ namespace MMAP
count++;
}
sprintf(filter, "%03u*", mapID);
files.clear();
getDirContents(files, "maps", filter);
getDirContents(files, "maps", Trinity::StringFormat("%03u*", mapID));
for (uint32 i = 0; i < files.size(); ++i)
{
tileY = uint32(atoi(files[i].substr(3,2).c_str()));
@@ -531,9 +529,8 @@ namespace MMAP
dtNavMesh* navMesh)
{
// console output
char tileString[20];
sprintf(tileString, "[Map %03i] [%02i,%02i]: ", mapID, tileX, tileY);
printf("%s Building movemap tiles...\n", tileString);
std::string tileString = Trinity::StringFormat("[Map %03i] [%02i,%02i]: ", mapID, tileX, tileY);
printf("%s Building movemap tiles...\n", tileString.c_str());
IntermediateValues iv;
@@ -614,7 +611,7 @@ namespace MMAP
tile.solid = rcAllocHeightfield();
if (!tile.solid || !rcCreateHeightfield(m_rcContext, *tile.solid, tileCfg.width, tileCfg.height, tileCfg.bmin, tileCfg.bmax, tileCfg.cs, tileCfg.ch))
{
printf("%s Failed building heightfield! \n", tileString);
printf("%s Failed building heightfield! \n", tileString.c_str());
continue;
}
@@ -635,33 +632,33 @@ namespace MMAP
tile.chf = rcAllocCompactHeightfield();
if (!tile.chf || !rcBuildCompactHeightfield(m_rcContext, tileCfg.walkableHeight, tileCfg.walkableClimb, *tile.solid, *tile.chf))
{
printf("%s Failed compacting heightfield! \n", tileString);
printf("%s Failed compacting heightfield! \n", tileString.c_str());
continue;
}
// build polymesh intermediates
if (!rcErodeWalkableArea(m_rcContext, config.walkableRadius, *tile.chf))
{
printf("%s Failed eroding area! \n", tileString);
printf("%s Failed eroding area! \n", tileString.c_str());
continue;
}
if (!rcBuildDistanceField(m_rcContext, *tile.chf))
{
printf("%s Failed building distance field! \n", tileString);
printf("%s Failed building distance field! \n", tileString.c_str());
continue;
}
if (!rcBuildRegions(m_rcContext, *tile.chf, tileCfg.borderSize, tileCfg.minRegionArea, tileCfg.mergeRegionArea))
{
printf("%s Failed building regions! \n", tileString);
printf("%s Failed building regions! \n", tileString.c_str());
continue;
}
tile.cset = rcAllocContourSet();
if (!tile.cset || !rcBuildContours(m_rcContext, *tile.chf, tileCfg.maxSimplificationError, tileCfg.maxEdgeLen, *tile.cset))
{
printf("%s Failed building contours! \n", tileString);
printf("%s Failed building contours! \n", tileString.c_str());
continue;
}
@@ -669,14 +666,14 @@ namespace MMAP
tile.pmesh = rcAllocPolyMesh();
if (!tile.pmesh || !rcBuildPolyMesh(m_rcContext, *tile.cset, tileCfg.maxVertsPerPoly, *tile.pmesh))
{
printf("%s Failed building polymesh! \n", tileString);
printf("%s Failed building polymesh! \n", tileString.c_str());
continue;
}
tile.dmesh = rcAllocPolyMeshDetail();
if (!tile.dmesh || !rcBuildPolyMeshDetail(m_rcContext, *tile.pmesh, *tile.chf, tileCfg.detailSampleDist, tileCfg.detailSampleMaxError, *tile.dmesh))
{
printf("%s Failed building polymesh detail! \n", tileString);
printf("%s Failed building polymesh detail! \n", tileString.c_str());
continue;
}
@@ -699,7 +696,7 @@ namespace MMAP
iv.polyMesh = rcAllocPolyMesh();
if (!iv.polyMesh)
{
printf("%s alloc iv.polyMesh FIALED!\n", tileString);
printf("%s alloc iv.polyMesh FIALED!\n", tileString.c_str());
delete[] pmmerge;
delete[] dmmerge;
delete[] tiles;
@@ -710,7 +707,7 @@ namespace MMAP
iv.polyMeshDetail = rcAllocPolyMeshDetail();
if (!iv.polyMeshDetail)
{
printf("%s alloc m_dmesh FIALED!\n", tileString);
printf("%s alloc m_dmesh FIALED!\n", tileString.c_str());
delete[] pmmerge;
delete[] dmmerge;
delete[] tiles;
@@ -774,12 +771,12 @@ namespace MMAP
// so we have a clear error message
if (params.nvp > DT_VERTS_PER_POLYGON)
{
printf("%s Invalid verts-per-polygon value! \n", tileString);
printf("%s Invalid verts-per-polygon value! \n", tileString.c_str());
break;
}
if (params.vertCount >= 0xffff)
{
printf("%s Too many vertices! \n", tileString);
printf("%s Too many vertices! \n", tileString.c_str());
break;
}
if (!params.vertCount || !params.verts)
@@ -788,7 +785,7 @@ namespace MMAP
// loaded but those models don't span into this tile
// message is an annoyance
//printf("%sNo vertices to build tile! \n", tileString);
//printf("%sNo vertices to build tile! \n", tileString.c_str());
break;
}
if (!params.polyCount || !params.polys ||
@@ -797,30 +794,30 @@ namespace MMAP
// we have flat tiles with no actual geometry - don't build those, its useless
// keep in mind that we do output those into debug info
// drop tiles with only exact count - some tiles may have geometry while having less tiles
printf("%s No polygons to build on tile! \n", tileString);
printf("%s No polygons to build on tile! \n", tileString.c_str());
break;
}
if (!params.detailMeshes || !params.detailVerts || !params.detailTris)
{
printf("%s No detail mesh to build tile! \n", tileString);
printf("%s No detail mesh to build tile! \n", tileString.c_str());
break;
}
printf("%s Building navmesh tile...\n", tileString);
printf("%s Building navmesh tile...\n", tileString.c_str());
if (!dtCreateNavMeshData(&params, &navData, &navDataSize))
{
printf("%s Failed building navmesh tile! \n", tileString);
printf("%s Failed building navmesh tile! \n", tileString.c_str());
break;
}
dtTileRef tileRef = 0;
printf("%s Adding tile to navmesh...\n", tileString);
printf("%s Adding tile to navmesh...\n", tileString.c_str());
// DT_TILE_FREE_DATA tells detour to unallocate memory when the tile
// is removed via removeTile()
dtStatus dtResult = navMesh->addTile(navData, navDataSize, DT_TILE_FREE_DATA, 0, &tileRef);
if (!tileRef || dtResult != DT_SUCCESS)
{
printf("%s Failed adding tile to navmesh! \n", tileString);
printf("%s Failed adding tile to navmesh! \n", tileString.c_str());
break;
}
@@ -837,7 +834,7 @@ namespace MMAP
break;
}
printf("%s Writing to file...\n", tileString);
printf("%s Writing to file...\n", tileString.c_str());
// write header
MmapTileHeader header;
@@ -916,6 +913,7 @@ namespace MMAP
case 597: // CraigTest.wdt
case 605: // development_nonweighted.wdt
case 606: // QA_DVD.wdt
case 651: // ElevatorSpawnTest.wdt
return true;
default:
if (isTransportMap(mapID))
@@ -926,13 +924,17 @@ namespace MMAP
if (m_skipBattlegrounds)
switch (mapID)
{
case 30: // AV
case 30: // Alterac Valley
case 37: // ?
case 489: // WSG
case 529: // AB
case 566: // EotS
case 607: // SotA
case 628: // IoC
case 489: // Warsong Gulch
case 529: // Arathi Basin
case 566: // Eye of the Storm
case 607: // Strand of the Ancients
case 628: // Isle of Conquest
case 726: // Twin Peaks
case 727: // Silvershard Mines
case 761: // The Battle for Gilneas
case 968: // Rated Eye of the Storm
return true;
default:
break;
@@ -970,11 +972,28 @@ namespace MMAP
case 641:
case 642:
case 647:
case 662:
case 672:
case 673:
case 674:
case 712:
case 713:
case 718:
case 738:
case 739:
case 740:
case 741:
case 742:
case 743:
case 747:
case 748:
case 749:
case 750:
case 762:
case 763:
case 765:
case 766:
case 767:
return true;
default:
return false;