mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Phasing: Rewrite GetTerrainMapId
This commit is contained in:
@@ -94,8 +94,6 @@ namespace VMAP
|
||||
*/
|
||||
virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0;
|
||||
virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0;
|
||||
|
||||
virtual int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -306,15 +306,6 @@ namespace VMAP
|
||||
return false;
|
||||
}
|
||||
|
||||
int32 VMapManager2::GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const
|
||||
{
|
||||
auto instanceTree = GetMapTree(mapId);
|
||||
if (instanceTree != iInstanceMapTrees.end())
|
||||
return instanceTree->second->GetDistanceToClosestPrimaryTile(x, y);
|
||||
|
||||
return std::numeric_limits<int32>::max();
|
||||
}
|
||||
|
||||
WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename)
|
||||
{
|
||||
//! Critical section, thread safe access to iLoadedModelFiles
|
||||
|
||||
@@ -123,8 +123,6 @@ namespace VMAP
|
||||
bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override;
|
||||
bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const override;
|
||||
|
||||
int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const override;
|
||||
|
||||
WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename);
|
||||
void releaseModelInstance(const std::string& filename);
|
||||
|
||||
|
||||
@@ -242,7 +242,6 @@ namespace VMAP
|
||||
TileFileOpenResult result;
|
||||
result.Name = basePath + getTileFileName(mapID, tileX, tileY);
|
||||
result.File = fopen(result.Name.c_str(), "rb");
|
||||
result.IsPrimary = true;
|
||||
if (!result.File)
|
||||
{
|
||||
int32 parentMapId = vm->getParentMapId(mapID);
|
||||
@@ -250,7 +249,6 @@ namespace VMAP
|
||||
{
|
||||
result.Name = basePath + getTileFileName(parentMapId, tileX, tileY);
|
||||
result.File = fopen(result.Name.c_str(), "rb");
|
||||
result.IsPrimary = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +370,6 @@ namespace VMAP
|
||||
}
|
||||
iLoadedSpawns.clear();
|
||||
iLoadedTiles.clear();
|
||||
iLoadedPrimaryTiles.clear();
|
||||
}
|
||||
|
||||
//=========================================================
|
||||
@@ -447,8 +444,6 @@ namespace VMAP
|
||||
}
|
||||
}
|
||||
iLoadedTiles[packTileID(tileX, tileY)] = true;
|
||||
if (fileResult.IsPrimary)
|
||||
iLoadedPrimaryTiles.emplace_back(tileX, tileY);
|
||||
fclose(fileResult.File);
|
||||
}
|
||||
else
|
||||
@@ -512,8 +507,6 @@ namespace VMAP
|
||||
}
|
||||
}
|
||||
iLoadedTiles.erase(tile);
|
||||
iLoadedPrimaryTiles.erase(std::remove_if(iLoadedPrimaryTiles.begin(), iLoadedPrimaryTiles.end(),
|
||||
[tileX, tileY](std::pair<uint32, uint32> const& p) { return p.first == tileX && p.second == tileY; }), iLoadedPrimaryTiles.end());
|
||||
TC_METRIC_EVENT("map_events", "UnloadMapTile",
|
||||
"Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
|
||||
}
|
||||
@@ -523,13 +516,4 @@ namespace VMAP
|
||||
models = iTreeValues;
|
||||
count = iNTreeValues;
|
||||
}
|
||||
|
||||
int32 StaticMapTree::GetDistanceToClosestPrimaryTile(int32 x, int32 y) const
|
||||
{
|
||||
int32 minDistance = std::numeric_limits<int32>::max();
|
||||
for (std::pair<int32, int32> const& primaryTile : iLoadedPrimaryTiles)
|
||||
minDistance = std::min(minDistance, (primaryTile.first - x) * (primaryTile.first - x) + (primaryTile.second - y) * (primaryTile.second - y));
|
||||
|
||||
return minDistance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ namespace VMAP
|
||||
{
|
||||
FILE* File;
|
||||
std::string Name;
|
||||
bool IsPrimary;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -92,8 +91,6 @@ namespace VMAP
|
||||
uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
|
||||
void getModelInstances(ModelInstance* &models, uint32 &count);
|
||||
|
||||
int32 GetDistanceToClosestPrimaryTile(int32 x, int32 y) const;
|
||||
|
||||
private:
|
||||
StaticMapTree(StaticMapTree const& right) = delete;
|
||||
StaticMapTree& operator=(StaticMapTree const& right) = delete;
|
||||
|
||||
@@ -2822,7 +2822,8 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
|
||||
}
|
||||
|
||||
destz = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ());
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetPhaseShift().GetTerrainMapId(GetMapId(), pos.m_positionX, pos.m_positionY), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY),
|
||||
pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// collision occured
|
||||
if (col)
|
||||
|
||||
@@ -2550,13 +2550,19 @@ GridMap* Map::GetGrid(uint32 mapId, float x, float y)
|
||||
EnsureGridCreated(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy));
|
||||
|
||||
GridMap* grid = GridMaps[gx][gy];
|
||||
auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) {return childTerrainMap->GetId() == mapId; });
|
||||
auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) { return childTerrainMap->GetId() == mapId; });
|
||||
if (childMapItr != m_childTerrainMaps->end() && (*childMapItr)->GridMaps[gx][gy]->fileExists())
|
||||
grid = (*childMapItr)->GridMaps[gx][gy];
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
bool Map::HasGrid(uint32 mapId, int32 gx, int32 gy) const
|
||||
{
|
||||
auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) { return childTerrainMap->GetId() == mapId; });
|
||||
return childMapItr != m_childTerrainMaps->end() && (*childMapItr)->GridMaps[gx][gy] && (*childMapItr)->GridMaps[gx][gy]->fileExists();
|
||||
}
|
||||
|
||||
float Map::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, float y, float z, float* ground /*= nullptr*/, bool /*swim = false*/) const
|
||||
{
|
||||
if (const_cast<Map*>(this)->GetGrid(x, y))
|
||||
@@ -2579,7 +2585,7 @@ float Map::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float
|
||||
{
|
||||
// find raw .map surface under Z coordinates
|
||||
float mapHeight = VMAP_INVALID_HEIGHT_VALUE;
|
||||
uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
|
||||
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(terrainMapId, x, y))
|
||||
{
|
||||
float gridHeight = gmap->getHeight(x, y);
|
||||
@@ -2672,7 +2678,7 @@ bool Map::IsOutdoors(PhaseShift const& phaseShift, float x, float y, float z) co
|
||||
bool Map::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
|
||||
{
|
||||
float vmap_z = z;
|
||||
uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
|
||||
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
|
||||
VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
|
||||
if (vmgr->getAreaInfo(terrainMapId, x, y, vmap_z, flags, adtId, rootId, groupId))
|
||||
{
|
||||
@@ -2711,7 +2717,7 @@ uint32 Map::GetAreaId(PhaseShift const& phaseShift, float x, float y, float z, b
|
||||
|
||||
if (!areaId)
|
||||
{
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
|
||||
areaId = gmap->getArea(x, y);
|
||||
|
||||
// this used while not all *.map files generated (instances)
|
||||
@@ -2754,7 +2760,7 @@ void Map::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32&
|
||||
|
||||
uint8 Map::GetTerrainType(PhaseShift const& phaseShift, float x, float y) const
|
||||
{
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
|
||||
return gmap->getTerrainType(x, y);
|
||||
else
|
||||
return 0;
|
||||
@@ -2767,7 +2773,7 @@ ZLiquidStatus Map::getLiquidStatus(PhaseShift const& phaseShift, float x, float
|
||||
float liquid_level = INVALID_HEIGHT;
|
||||
float ground_level = INVALID_HEIGHT;
|
||||
uint32 liquid_type = 0;
|
||||
uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
|
||||
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
|
||||
if (vmgr->GetLiquidLevel(terrainMapId, x, y, z, ReqLiquidType, liquid_level, ground_level, liquid_type))
|
||||
{
|
||||
TC_LOG_DEBUG("maps", "getLiquidStatus(): vmap liquid level: %f ground: %f type: %u", liquid_level, ground_level, liquid_type);
|
||||
@@ -2848,7 +2854,7 @@ ZLiquidStatus Map::getLiquidStatus(PhaseShift const& phaseShift, float x, float
|
||||
|
||||
float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const
|
||||
{
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
|
||||
return gmap->getLiquidLevel(x, y);
|
||||
else
|
||||
return 0;
|
||||
@@ -2856,7 +2862,7 @@ float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const
|
||||
|
||||
bool Map::isInLineOfSight(PhaseShift const& phaseShift, float x1, float y1, float z1, float x2, float y2, float z2) const
|
||||
{
|
||||
return VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(phaseShift.GetTerrainMapId(GetId(), x1, x2), x1, y1, z1, x2, y2, z2)
|
||||
return VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(PhasingHandler::GetTerrainMapId(phaseShift, this, x1, y1), x1, y1, z1, x2, y2, z2)
|
||||
&& _dynamicTree.isInLineOfSight({ x1, y1, z1 }, { x2, y2, z2 }, phaseShift);
|
||||
}
|
||||
|
||||
|
||||
@@ -324,6 +324,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
|
||||
|
||||
time_t GetGridExpiry() const { return i_gridExpiry; }
|
||||
|
||||
bool HasGrid(uint32 mapId, int32 gx, int32 gy) const;
|
||||
static bool ExistMap(uint32 mapid, int gx, int gy);
|
||||
static bool ExistVMap(uint32 mapid, int gx, int gy);
|
||||
|
||||
@@ -631,8 +632,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
|
||||
void setNGrid(NGridType* grid, uint32 x, uint32 y);
|
||||
void ScriptsProcess();
|
||||
|
||||
void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff);
|
||||
|
||||
void SendObjectUpdates();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ObjectAccessor.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "PhasingHandler.h"
|
||||
#include "Player.h"
|
||||
#include "VMapFactory.h"
|
||||
|
||||
@@ -51,11 +52,9 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T* owner)
|
||||
|
||||
// Add LOS check for target point
|
||||
Position mypos = owner->GetPosition();
|
||||
bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(owner->GetPhaseShift().GetTerrainMapId(owner->GetMapId(), mypos.m_positionX, mypos.m_positionY),
|
||||
mypos.m_positionX,
|
||||
mypos.m_positionY,
|
||||
mypos.m_positionZ + 2.0f,
|
||||
x, y, z + 2.0f);
|
||||
bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(
|
||||
PhasingHandler::GetTerrainMapId(owner->GetPhaseShift(), owner->GetMap(), mypos.m_positionX, mypos.m_positionY),
|
||||
mypos.m_positionX, mypos.m_positionY, mypos.m_positionZ + 2.0f, x, y, z + 2.0f);
|
||||
if (!isInLOS)
|
||||
{
|
||||
i_nextCheckTime.Reset(200);
|
||||
|
||||
@@ -18,15 +18,16 @@
|
||||
*/
|
||||
|
||||
#include "PathGenerator.h"
|
||||
#include "Map.h"
|
||||
#include "Creature.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "Log.h"
|
||||
#include "DisableMgr.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourNavMeshQuery.h"
|
||||
#include "DisableMgr.h"
|
||||
#include "Log.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "Map.h"
|
||||
#include "Metric.h"
|
||||
#include "PhasingHandler.h"
|
||||
|
||||
////////////////// PathGenerator //////////////////
|
||||
PathGenerator::PathGenerator(const Unit* owner) :
|
||||
@@ -39,7 +40,7 @@ PathGenerator::PathGenerator(const Unit* owner) :
|
||||
|
||||
TC_LOG_DEBUG("maps", "++ PathGenerator::PathGenerator for %s", _sourceUnit->GetGUID().ToString().c_str());
|
||||
|
||||
uint32 mapId = _sourceUnit->GetPhaseShift().GetTerrainMapId(_sourceUnit->GetMapId(), _sourceUnit->GetPositionX(), _sourceUnit->GetPositionY());
|
||||
uint32 mapId = PhasingHandler::GetTerrainMapId(_sourceUnit->GetPhaseShift(), _sourceUnit->GetMap(), _sourceUnit->GetPositionX(), _sourceUnit->GetPositionY());
|
||||
if (DisableMgr::IsPathfindingEnabled(_sourceUnit->GetMapId()))
|
||||
{
|
||||
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
#include "PhaseShift.h"
|
||||
#include "Containers.h"
|
||||
#include "GridDefines.h"
|
||||
#include "VMapFactory.h"
|
||||
|
||||
bool PhaseShift::AddPhase(uint32 phaseId, PhaseFlags flags, std::vector<Condition*> const* areaConditions, int32 references /*= 1*/)
|
||||
{
|
||||
@@ -147,33 +145,6 @@ bool PhaseShift::CanSee(PhaseShift const& other) const
|
||||
return checkInversePhaseShift(other, *this);
|
||||
}
|
||||
|
||||
uint32 PhaseShift::GetTerrainMapId(uint32 realMapId, float x, float y) const
|
||||
{
|
||||
if (VisibleMapIds.empty())
|
||||
return realMapId;
|
||||
|
||||
if (VisibleMapIds.size() == 1)
|
||||
return VisibleMapIds.begin()->first;
|
||||
|
||||
GridCoord gridCoord = Trinity::ComputeGridCoord(x, y);
|
||||
int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
|
||||
int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
|
||||
|
||||
int32 minDistance = std::numeric_limits<int32>::max();
|
||||
uint32 terrainMapId;
|
||||
for (auto itr = VisibleMapIds.begin(); itr != VisibleMapIds.end(); ++itr)
|
||||
{
|
||||
int32 dist = VMAP::VMapFactory::createOrGetVMapManager()->GetDistanceToClosestPrimaryTile(itr->first, gx, gy);
|
||||
if (dist < minDistance)
|
||||
{
|
||||
minDistance = dist;
|
||||
terrainMapId = itr->first;
|
||||
}
|
||||
}
|
||||
|
||||
return terrainMapId;
|
||||
}
|
||||
|
||||
void PhaseShift::ModifyPhasesReferences(PhaseContainer::iterator itr, int32 references)
|
||||
{
|
||||
itr->References += references;
|
||||
|
||||
@@ -101,7 +101,6 @@ public:
|
||||
void ClearPhases();
|
||||
|
||||
bool CanSee(PhaseShift const& other) const;
|
||||
uint32 GetTerrainMapId(uint32 realMapId, float x, float y) const;
|
||||
|
||||
protected:
|
||||
friend class PhasingHandler;
|
||||
|
||||
@@ -469,6 +469,32 @@ bool PhasingHandler::InDbPhaseShift(WorldObject const* object, uint8 phaseUseFla
|
||||
return object->GetPhaseShift().CanSee(phaseShift);
|
||||
}
|
||||
|
||||
uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, Map const* map, float x, float y)
|
||||
{
|
||||
if (phaseShift.VisibleMapIds.empty())
|
||||
return map->GetId();
|
||||
|
||||
if (phaseShift.VisibleMapIds.size() == 1)
|
||||
return phaseShift.VisibleMapIds.begin()->first;
|
||||
|
||||
GridCoord gridCoord = Trinity::ComputeGridCoord(x, y);
|
||||
int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
|
||||
int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
|
||||
|
||||
int32 gxbegin = std::max(gx - 1, 0);
|
||||
int32 gxend = std::min(gx + 1, MAX_NUMBER_OF_GRIDS);
|
||||
int32 gybegin = std::max(gy - 1, 0);
|
||||
int32 gyend = std::min(gy + 1, MAX_NUMBER_OF_GRIDS);
|
||||
|
||||
for (auto itr = phaseShift.VisibleMapIds.rbegin(); itr != phaseShift.VisibleMapIds.rend(); ++itr)
|
||||
for (int32 gxi = gxbegin; gxi < gxend; ++gxi)
|
||||
for (int32 gyi = gybegin; gyi < gyend; ++gyi)
|
||||
if (map->HasGrid(itr->first, gxi, gyi))
|
||||
return itr->first;
|
||||
|
||||
return map->GetId();
|
||||
}
|
||||
|
||||
void PhasingHandler::SetAlwaysVisible(PhaseShift& phaseShift, bool apply)
|
||||
{
|
||||
if (apply)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <string>
|
||||
|
||||
class ChatHandler;
|
||||
class Map;
|
||||
class PhaseShift;
|
||||
class Player;
|
||||
class WorldObject;
|
||||
@@ -60,6 +61,8 @@ public:
|
||||
static void InitDbVisibleMapId(PhaseShift& phaseShift, int32 visibleMapId);
|
||||
static bool InDbPhaseShift(WorldObject const* object, uint8 phaseUseFlags, uint16 phaseId, uint32 phaseGroupId);
|
||||
|
||||
static uint32 GetTerrainMapId(PhaseShift const& phaseShift, Map const* map, float x, float y);
|
||||
|
||||
static void SetAlwaysVisible(PhaseShift& phaseShift, bool apply);
|
||||
static void SetInversed(PhaseShift& phaseShift, bool apply);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user