Core/Maps: Fixed loading vmaps and mmaps in instances

(ported commit b773d9997bdd723cad8c646170e025a48f140f1d)
This commit is contained in:
Ovahlord committed 2018-05-06 18:47:51 +02:00
1 parent 0e5be63528
commit cfee8a09a1
15 files changed
+56 -105

No files matched your search

@@ -2026,12 +2026,6 @@ void WorldObject::ResetMap()
//m_InstanceId = 0;
}
Map const* WorldObject::GetBaseMap() const
{
ASSERT(m_currMap);
return m_currMap->GetParent();
}
void WorldObject::AddObjectToRemoveList()
{
ASSERT(m_uint32Values);
-3
View File
@@ -385,9 +385,6 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
Map* FindMap() const { return m_currMap; }
//used to check all object's GetMap() calls when object is not in world!
//this function should be removed in nearest time...
Map const* GetBaseMap() const;
void SetZoneScript();
void ClearZoneScript();
ZoneScript* GetZoneScript() const { return m_zoneScript; }
+4 -4
View File
@@ -1317,7 +1317,7 @@ void Player::Update(uint32 p_time)
}
// not auto-free ghost from body in instances
if (m_deathTimer > 0 && !GetBaseMap()->Instanceable() && !HasAuraType(SPELL_AURA_PREVENT_RESURRECTION))
if (m_deathTimer > 0 && !GetMap()->Instanceable() && !HasAuraType(SPELL_AURA_PREVENT_RESURRECTION))
{
if (p_time >= m_deathTimer)
{
@@ -2466,7 +2466,7 @@ GameObject* Player::GetGameObjectIfCanInteractWith(ObjectGuid const& guid, Gameo
bool Player::IsUnderWater() const
{
return IsInWater() &&
GetPositionZ() < (GetBaseMap()->GetWaterLevel(GetPhaseShift(), GetPositionX(), GetPositionY())-2);
GetPositionZ() < (GetMap()->GetWaterLevel(GetPhaseShift(), GetPositionX(), GetPositionY())-2);
}
void Player::SetInWater(bool apply)
@@ -5731,7 +5731,7 @@ void Player::GiveXpForGather(uint32 const& skillId, uint32 const& reqSkillValue)
if (skillId != SKILL_HERBALISM && skillId != SKILL_MINING && skillId != SKILL_ARCHAEOLOGY)
return;
uint32 areaId = GetBaseMap()->GetAreaId(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
uint32 areaId = GetMap()->GetAreaId(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(areaId);
if (!areaEntry)
@@ -6426,7 +6426,7 @@ void Player::CheckAreaExploreAndOutdoor()
return;
bool isOutdoor;
uint32 areaId = GetBaseMap()->GetAreaId(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ(), &isOutdoor);
uint32 areaId = GetMap()->GetAreaId(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ(), &isOutdoor);
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(areaId);
if (sWorld->getBoolConfig(CONFIG_VMAP_INDOOR_CHECK) && !isOutdoor)
+2 -2
View File
@@ -3170,12 +3170,12 @@ bool Unit::isInAccessiblePlaceFor(Creature const* c) const
bool Unit::IsInWater() const
{
return GetBaseMap()->IsInWater(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
return GetMap()->IsInWater(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
}
bool Unit::IsUnderWater() const
{
return GetBaseMap()->IsUnderWater(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
return GetMap()->IsUnderWater(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ());
}
void Unit::UpdateUnderwaterState(Map* m, float x, float y, float z)
+2 -2
View File
@@ -20,12 +20,12 @@
GridInfo::GridInfo()
: i_timer(0), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)),
i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false)
i_unloadActiveLockCount(0), i_unloadExplicitLock(false)
{
}
GridInfo::GridInfo(time_t expiry, bool unload /*= true*/)
: i_timer(expiry), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)),
i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false)
i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload)
{
}
+1 -4
View File
@@ -35,9 +35,8 @@ public:
GridInfo();
GridInfo(time_t expiry, bool unload = true);
TimeTracker const& getTimeTracker() const { return i_timer; }
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; }
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock; }
void setUnloadExplicitLock(bool on) { i_unloadExplicitLock = on; }
void setUnloadReferenceLock(bool on) { i_unloadReferenceLock = on; }
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
void decUnloadActiveLock() { if (i_unloadActiveLockCount) --i_unloadActiveLockCount; }
@@ -51,7 +50,6 @@ private:
uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading)
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
bool i_unloadReferenceLock : 1; // lock from instance map copy
};
typedef enum
@@ -109,7 +107,6 @@ class NGrid
TimeTracker const& getTimeTracker() const { return i_GridInfo.getTimeTracker(); }
bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); }
void setUnloadExplicitLock(bool on) { i_GridInfo.setUnloadExplicitLock(on); }
void setUnloadReferenceLock(bool on) { i_GridInfo.setUnloadReferenceLock(on); }
void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); }
void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); }
void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); }
+1 -1
View File
@@ -373,7 +373,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvPacket)
if (plrMover && ((movementInfo.flags & MOVEMENTFLAG_SWIMMING) != 0) != plrMover->IsInWater())
{
// now client not include swimming flag in case jumping under water
plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetBaseMap()->IsUnderWater(plrMover->GetPhaseShift(), movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY(), movementInfo.pos.GetPositionZ()));
plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetMap()->IsUnderWater(plrMover->GetPhaseShift(), movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY(), movementInfo.pos.GetPositionZ()));
}
uint32 mstime = GameTime::GetGameTimeMS();
+37 -55
View File
@@ -172,41 +172,30 @@ void Map::LoadVMap(int gx, int gy)
}
}
void Map::LoadMap(int gx, int gy, bool reload)
void Map::LoadMap(int gx, int gy)
{
LoadMapImpl(this, gx, gy, reload);
LoadMapImpl(this, gx, gy);
for (Map* childBaseMap : *m_childTerrainMaps)
childBaseMap->LoadMap(gx, gy, reload);
childBaseMap->LoadMap(gx, gy);
}
void Map::LoadMapImpl(Map* map, int gx, int gy, bool reload)
void Map::LoadMapImpl(Map* map, int gx, int gy)
{
if (map->i_InstanceId != 0)
{
if (map->GridMaps[gx][gy])
return;
// load grid map for base map
GridCoord ngridCoord = GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy);
if (!map->m_parentMap->getNGrid(ngridCoord.x_coord, ngridCoord.y_coord))
map->m_parentMap->EnsureGridCreated(ngridCoord);
static_cast<MapInstanced*>(map->m_parentMap)->AddGridMapReference(GridCoord(gx, gy));
map->GridMaps[gx][gy] = map->m_parentMap->GridMaps[gx][gy];
return;
}
if (map->GridMaps[gx][gy] && !reload)
return;
//map already load, delete it before reloading (Is it necessary? Do we really need the ability the reload maps during runtime?)
if (map->GridMaps[gx][gy])
{
TC_LOG_DEBUG("maps", "Unloading previously loaded map %u before reloading.", map->GetId());
sScriptMgr->OnUnloadGridMap(map, map->GridMaps[gx][gy], gx, gy);
return;
delete map->GridMaps[gx][gy];
map->GridMaps[gx][gy] = nullptr;
Map* parent = map->m_parentMap;
++parent->GridMapReference[gx][gy];
// load grid map for base map
if (parent != map)
{
GridCoord ngridCoord = GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy);
if (!parent->GridMaps[gx][gy])
parent->EnsureGridCreated(ngridCoord);
map->GridMaps[gx][gy] = parent->GridMaps[gx][gy];
return;
}
// map file name
@@ -230,29 +219,25 @@ void Map::UnloadMap(int gx, int gy)
void Map::UnloadMapImpl(Map* map, int gx, int gy)
{
if (map->i_InstanceId == 0)
if (map->GridMaps[gx][gy])
{
if (map->GridMaps[gx][gy])
Map* parent = map->m_parentMap;
if (!--parent->GridMapReference[gx][gy])
{
map->GridMaps[gx][gy]->unloadData();
delete map->GridMaps[gx][gy];
parent->GridMaps[gx][gy]->unloadData();
delete parent->GridMaps[gx][gy];
parent->GridMaps[gx][gy] = nullptr;
}
}
else
static_cast<MapInstanced*>(map->m_parentMap)->RemoveGridMapReference(GridCoord(gx, gy));
map->GridMaps[gx][gy] = nullptr;
}
void Map::LoadMapAndVMap(int gx, int gy)
{
m_parentTerrainMap->LoadMap(gx, gy);
// Only load the data for the base map
if (i_InstanceId == 0)
{
LoadVMap(gx, gy);
LoadMMap(gx, gy);
}
LoadMap(gx, gy);
LoadVMap(gx, gy);
LoadMMap(gx, gy);
}
void Map::LoadAllCells()
@@ -306,6 +291,7 @@ i_scriptLock(false), _defaultLight(GetDefaultMapLight(id))
{
//z code
GridMaps[x][y] = nullptr;
GridMapReference[x][y] = 0;
setNGrid(nullptr, x, y);
}
}
@@ -512,20 +498,20 @@ void Map::EnsureGridCreated_i(const GridCoord &p)
{
TC_LOG_DEBUG("maps", "Creating grid[%u, %u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId);
setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD)),
p.x_coord, p.y_coord);
NGridType* ngrid = new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD));
setNGrid(ngrid, p.x_coord, p.y_coord);
// build a linkage between this map and NGridType
buildNGridLinkage(getNGrid(p.x_coord, p.y_coord));
buildNGridLinkage(ngrid);
getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE);
ngrid->SetGridState(GRID_STATE_IDLE);
//z coord
int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord;
int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord;
if (!GridMaps[gx][gy])
LoadMapAndVMap(gx, gy);
m_parentTerrainMap->LoadMapAndVMap(gx, gy);
}
}
@@ -1657,17 +1643,13 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll)
int gy = (MAX_NUMBER_OF_GRIDS - 1) - y;
// delete grid map, but don't delete if it is from parent map (and thus only reference)
//+++if (GridMaps[gx][gy]) don't check for GridMaps[gx][gy], we might have to unload vmaps
if (GridMaps[gx][gy])
{
if (m_parentTerrainMap == this)
m_parentTerrainMap->UnloadMap(gx, gy);
if (i_InstanceId == 0)
{
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gx, gy);
MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId(), gx, gy);
}
m_parentTerrainMap->UnloadMap(gx, gy);
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(m_parentTerrainMap->GetId(), gx, gy);
MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(m_parentTerrainMap->GetId(), gx, gy);
}
TC_LOG_DEBUG("maps", "Unloading grid[%u, %u] for map %u finished", x, y, GetId());
return true;
}
+3 -5
View File
@@ -327,7 +327,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
static void InitStateMachine();
static void DeleteStateMachine();
Map const* GetParent() const { return m_parentMap; }
void AddChildTerrainMap(Map* map) { m_childTerrainMaps->push_back(map); map->m_parentTerrainMap = this; }
void UnlinkAllChildTerrainMaps() { m_childTerrainMaps->clear(); }
@@ -574,8 +573,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void LoadMapAndVMap(int gx, int gy);
void LoadVMap(int gx, int gy);
void LoadMap(int gx, int gy, bool reload = false);
static void LoadMapImpl(Map* map, int gx, int gy, bool reload);
void LoadMap(int gx, int gy);
static void LoadMapImpl(Map* map, int gx, int gy);
void UnloadMap(int gx, int gy);
static void UnloadMapImpl(Map* map, int gx, int gy);
void LoadMMap(int gx, int gy);
@@ -630,8 +629,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void SendObjectUpdates();
protected:
void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
std::mutex _mapLock;
std::mutex _gridLock;
@@ -676,6 +673,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
NGridType* i_grids[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
GridMap* GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
std::bitset<TOTAL_NUMBER_OF_CELLS_PER_MAP*TOTAL_NUMBER_OF_CELLS_PER_MAP> marked_cells;
//these functions used to process player/mob aggro reactions and
-2
View File
@@ -31,8 +31,6 @@
MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DUNGEON_DIFFICULTY_NORMAL)
{
// fill with zero
memset(&GridMapReference, 0, MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_GRIDS*sizeof(uint16));
}
void MapInstanced::InitVisibilityDistance()
-15
View File
@@ -47,19 +47,6 @@ class TC_GAME_API MapInstanced : public Map
}
bool DestroyInstance(InstancedMaps::iterator &itr);
void AddGridMapReference(const GridCoord &p)
{
++GridMapReference[p.x_coord][p.y_coord];
SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), true);
}
void RemoveGridMapReference(GridCoord const& p)
{
--GridMapReference[p.x_coord][p.y_coord];
if (!GridMapReference[p.x_coord][p.y_coord])
SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), false);
}
InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; }
virtual void InitVisibilityDistance() override;
@@ -68,7 +55,5 @@ class TC_GAME_API MapInstanced : public Map
BattlegroundMap* CreateBattleground(uint32 InstanceId, Battleground* bg);
InstancedMaps m_InstancedMaps;
uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
};
#endif
@@ -38,7 +38,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;
creature->GetHomePosition(respX, respY, respZ, respO);
Map const* map = creature->GetBaseMap();
Map const* map = creature->GetMap();
// For 2D/3D system selection
//bool is_land_ok = creature.CanWalk(); // not used?
+3 -3
View File
@@ -186,7 +186,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
// Check both start and end points, if they're both in water, then we can *safely* let the creature move
for (uint32 i = 0; i < _pathPoints.size(); ++i)
{
ZLiquidStatus status = _sourceUnit->GetBaseMap()->GetLiquidStatus(_sourceUnit->GetPhaseShift(), _pathPoints[i].x, _pathPoints[i].y, _pathPoints[i].z, MAP_ALL_LIQUIDS, nullptr);
ZLiquidStatus status = _sourceUnit->GetMap()->GetLiquidStatus(_sourceUnit->GetPhaseShift(), _pathPoints[i].x, _pathPoints[i].y, _pathPoints[i].z, MAP_ALL_LIQUIDS, nullptr);
// One of the points is not in the water, cancel movement.
if (status == LIQUID_MAP_NO_WATER)
{
@@ -212,7 +212,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
Creature* owner = (Creature*)_sourceUnit;
G3D::Vector3 const& p = (distToStartPoly > 7.0f) ? startPos : endPos;
if (_sourceUnit->GetBaseMap()->IsUnderWater(_sourceUnit->GetPhaseShift(), p.x, p.y, p.z))
if (_sourceUnit->GetMap()->IsUnderWater(_sourceUnit->GetPhaseShift(), p.x, p.y, p.z))
{
TC_LOG_DEBUG("maps", "++ BuildPolyPath :: underWater case\n");
if (owner->CanSwim())
@@ -649,7 +649,7 @@ void PathGenerator::UpdateFilter()
NavTerrainFlag PathGenerator::GetNavTerrain(float x, float y, float z)
{
LiquidData data;
ZLiquidStatus liquidStatus = _sourceUnit->GetBaseMap()->GetLiquidStatus(_sourceUnit->GetPhaseShift(), x, y, z, MAP_ALL_LIQUIDS, &data);
ZLiquidStatus liquidStatus = _sourceUnit->GetMap()->GetLiquidStatus(_sourceUnit->GetPhaseShift(), x, y, z, MAP_ALL_LIQUIDS, &data);
if (liquidStatus == LIQUID_MAP_NO_WATER)
return NAV_GROUND;
@@ -5054,7 +5054,7 @@ void AuraEffect::HandlePreventResurrection(AuraApplication const* aurApp, uint8
if (apply)
aurApp->GetTarget()->RemoveByteFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTES_OFFSET_FLAGS, PLAYER_FIELD_BYTE_RELEASE_TIMER);
else if (!aurApp->GetTarget()->GetBaseMap()->Instanceable())
else if (!aurApp->GetTarget()->GetMap()->Instanceable())
aurApp->GetTarget()->SetByteFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTES_OFFSET_FLAGS, PLAYER_FIELD_BYTE_RELEASE_TIMER);
}
@@ -323,7 +323,7 @@ class boss_foe_reaper_5000 : public CreatureScript
// and use our own position instead of our home position
float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;
me->GetPosition(respX, respY, respZ, respO);
Map const* map = me->GetBaseMap();
Map const* map = me->GetMap();
const float angle = float(rand_norm()) * static_cast<float>(M_PI * 2.0f);
const float range = 15.0f;
const float distanceX = range * std::cos(angle);