From 07a515f960ad1a1eed4c861f763ab56842fd016a Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 27 Oct 2014 13:21:47 -0500 Subject: [PATCH] Core/Phases: Some changes to how phasing works (cherry picked from commit e4f6cb39a2652455b78ae2416627954956c8964f) --- src/server/game/Entities/Object/Object.cpp | 11 ++++ src/server/game/Entities/Object/Object.h | 1 + src/server/game/Entities/Player/Player.cpp | 18 +---- src/server/game/Entities/Player/Player.h | 2 +- src/server/game/Globals/ObjectMgr.cpp | 66 +++---------------- src/server/game/Globals/ObjectMgr.h | 38 ++--------- src/server/game/Instances/InstanceScript.cpp | 2 +- .../game/Spells/Auras/SpellAuraEffects.cpp | 4 +- 8 files changed, 34 insertions(+), 108 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 38ad803d177..3f3a320a1d3 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2726,10 +2726,21 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update) void WorldObject::SetInPhase(uint32 id, bool update, bool apply) { + std::list terrainSwaps = sObjectMgr->GetPhaseTerrainSwaps(id); + if (apply) + { _phases.insert(id); + _terrainSwaps.insert(terrainSwaps.begin(), terrainSwaps.end()); + } else + { _phases.erase(id); + // Remove the terrain swaps that were applied by this phase + // Iterator pointing to the start of the sequence of elements that we're going to delete + std::set::iterator endRange = std::set_difference(_terrainSwaps.begin(), _terrainSwaps.end(), terrainSwaps.begin(), terrainSwaps.end(), _terrainSwaps.begin()); + terrainSwaps.erase(endRange, _terrainSwaps.end()); + } if (update && IsInWorld()) UpdateObjectVisibility(); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index b8410ec307c..b2464b5e6c6 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -770,6 +770,7 @@ class WorldObject : public Object, public WorldLocation uint32 m_InstanceId; // in map copy with instance id uint32 m_phaseMask; // in area phase state std::set _phases; + std::set _terrainSwaps; uint16 m_notifyflags; uint16 m_executed_notifies; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 86400232a9d..386f52f1b14 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -27984,25 +27984,13 @@ void Player::ReadMovementInfo(WorldPacket& data, MovementInfo* mi, Movement::Ext #undef REMOVE_VIOLATING_FLAGS } -void Player::UpdatePhasing() +void Player::SendUpdatePhasing() { if (!IsInWorld()) return; - std::set phaseIds; - std::set terrainswaps; - std::set worldAreaSwaps; - - for (auto phase : GetPhases()) - { - PhaseInfo const* info = sObjectMgr->GetPhaseInfo(phase); - if (!info) - continue; - terrainswaps.insert(info->terrainSwapMap); - worldAreaSwaps.insert(info->worldMapAreaSwap); - } - - GetSession()->SendSetPhaseShift(GetPhases(), terrainswaps, worldAreaSwaps); + std::set worldAreaSwaps; // @ToDo + GetSession()->SendSetPhaseShift(GetPhases(), _terrainSwaps, worldAreaSwaps); } void Player::SendSupercededSpell(uint32 oldSpell, uint32 newSpell) diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 2d4d5183a92..49b99a894c0 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2394,7 +2394,7 @@ class Player : public Unit, public GridObject void UpdateVisibilityOf(WorldObject* target); void UpdateTriggerVisibility(); - void UpdatePhasing(); + void SendUpdatePhasing(); template void UpdateVisibilityOf(T* target, UpdateData& data, std::set& visibleNow); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 0a9eadd525f..100687e74df 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -9226,60 +9226,16 @@ void ObjectMgr::LoadFactionChangeTitles() TC_LOG_INFO("server.loading", ">> Loaded %u faction change title pairs in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -void ObjectMgr::LoadPhaseDefinitions() +void ObjectMgr::LoadTerrainPhaseInfo() { - _PhaseDefinitionStore.clear(); - uint32 oldMSTime = getMSTime(); - // 0 1 2 3 - QueryResult result = WorldDatabase.Query("SELECT zoneId, entry, phaseId, phaseGroup FROM `phase_definitions` ORDER BY `entry` ASC"); + // 0 1 + QueryResult result = WorldDatabase.Query("SELECT id, terrainswapmap FROM `terrain_phase_info`"); if (!result) { - TC_LOG_INFO("server.loading", ">> Loaded 0 phasing definitions. DB table `phase_definitions` is empty."); - return; - } - - uint32 count = 0; - - do - { - Field* fields = result->Fetch(); - - PhaseDefinition PhaseDefinition; - - PhaseDefinition.zoneId = fields[0].GetUInt32(); - PhaseDefinition.entry = fields[1].GetUInt32(); - PhaseDefinition.phaseId = fields[2].GetUInt32(); - PhaseDefinition.phaseGroup = fields[3].GetUInt32(); - - if (PhaseDefinition.phaseGroup && PhaseDefinition.phaseId) - { - TC_LOG_ERROR("sql.sql", "Phase definition for zone %u (Entry: %u) has phaseGroup and phaseId set, phaseGroup set to 0", PhaseDefinition.zoneId, PhaseDefinition.entry); - PhaseDefinition.phaseGroup = 0; - } - _PhaseDefinitionStore[PhaseDefinition.zoneId].push_back(PhaseDefinition); - - ++count; - } - while (result->NextRow()); - - TC_LOG_INFO("server.loading", ">> Loaded %u phasing definitions in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); -} - -void ObjectMgr::LoadPhaseInfo() -{ - _PhaseInfoStore.clear(); - - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = WorldDatabase.Query("SELECT id, worldmapareaswap, terrainswapmap FROM `phase_info`"); - - if (!result) - { - TC_LOG_INFO("server.loading", ">> Loaded 0 phase infos. DB table `phase_info` is empty."); + TC_LOG_INFO("server.loading", ">> Loaded 0 terrain phase infos. DB table `terrain_phase_info` is empty."); return; } @@ -9288,25 +9244,23 @@ void ObjectMgr::LoadPhaseInfo() { Field* fields = result->Fetch(); - PhaseInfo phaseInfo; - phaseInfo.phaseId = fields[0].GetUInt32(); + uint32 phaseId = fields[0].GetUInt32(); - PhaseEntry const* phase = sPhaseStore.LookupEntry(phaseInfo.phaseId); + PhaseEntry const* phase = sPhaseStore.LookupEntry(phaseId); if (!phase) { - TC_LOG_ERROR("sql.sql", "Phase %u defined in `phase_info` does not exists, skipped.", phaseInfo.phaseId); + TC_LOG_ERROR("sql.sql", "Phase %u defined in `terrain_phase_info` does not exists, skipped.", phaseId); continue; } - phaseInfo.worldMapAreaSwap = fields[1].GetUInt32(); - phaseInfo.terrainSwapMap = fields[2].GetUInt32(); + uint32 terrainSwap = fields[1].GetUInt32(); - _PhaseInfoStore[phaseInfo.phaseId] = phaseInfo; + _terrainPhaseInfoStore[phaseId].push_back(terrainSwap); ++count; } while (result->NextRow()); - TC_LOG_INFO("server.loading", ">> Loaded %u phase infos in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); + TC_LOG_INFO("server.loading", ">> Loaded %u terrain phase infos in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); } GameObjectTemplate const* ObjectMgr::GetGameObjectTemplate(uint32 entry) diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index abd452eaeb0..41bfeb9f8a1 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -129,34 +129,6 @@ typedef std::map PageTextContainer; // Benchmarked: Faster than std::map (insert/find) typedef std::unordered_map InstanceTemplateContainer; -// Phasing (visibility) -enum PhasingFlags -{ - PHASE_FLAG_OVERWRITE_EXISTING = 0x01, // don't stack with existing phases, overwrites existing phases - PHASE_FLAG_NO_MORE_PHASES = 0x02, // stop calculating phases after this phase was applied (no more phases will be applied) - PHASE_FLAG_NEGATE_PHASE = 0x04 // negate instead to add the phasemask -}; - -struct PhaseInfo -{ - uint32 phaseId; - uint32 worldMapAreaSwap; - uint32 terrainSwapMap; -}; - -typedef std::unordered_map PhaseInfoContainer; - -struct PhaseDefinition -{ - uint32 zoneId; - uint32 entry; - uint32 phaseId; - uint32 phaseGroup; -}; - -typedef std::list PhaseDefinitionContainer; -typedef std::unordered_map PhaseDefinitionStore; - struct GameTele { float position_x; @@ -714,6 +686,8 @@ struct HotfixInfo typedef std::vector HotfixData; +typedef std::unordered_map> TerrainPhaseInfo; + class PlayerDumpReader; class ObjectMgr @@ -1054,8 +1028,7 @@ class ObjectMgr void LoadTrainerSpell(); void AddSpellToTrainer(uint32 entry, uint32 spell, uint32 spellCost, uint32 reqSkill, uint32 reqSkillValue, uint32 reqLevel); - void LoadPhaseDefinitions(); - void LoadPhaseInfo(); + void LoadTerrainPhaseInfo(); std::string GeneratePetName(uint32 entry); uint32 GetBaseXP(uint8 level); @@ -1312,7 +1285,7 @@ class ObjectMgr return _gossipMenuItemsStore.equal_range(uiMenuId); } - PhaseInfo const* GetPhaseInfo(uint32 phase) { return _PhaseInfoStore.find(phase) != _PhaseInfoStore.end() ? &_PhaseInfoStore[phase] : nullptr; } + std::list& GetPhaseTerrainSwaps(uint32 phaseid) { return _terrainPhaseInfoStore[phaseid]; } // for wintergrasp only GraveYardContainer GraveYardStore; @@ -1429,8 +1402,7 @@ class ObjectMgr PageTextContainer _pageTextStore; InstanceTemplateContainer _instanceTemplateStore; - PhaseDefinitionStore _PhaseDefinitionStore; - PhaseInfoContainer _PhaseInfoStore; + TerrainPhaseInfo _terrainPhaseInfoStore; private: void LoadScripts(ScriptsType type); diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index bb02b114e48..d240d0767e2 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -631,5 +631,5 @@ void InstanceScript::UpdatePhasing() Map::PlayerList const& players = instance->GetPlayers(); for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) if (Player* player = itr->GetSource()) - player->UpdatePhasing(); + player->SendUpdatePhasing(); } diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 48ab8448369..4d4b2d6163f 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -1623,7 +1623,7 @@ void AuraEffect::HandlePhase(AuraApplication const* aurApp, uint8 mode, bool app { if (player->IsInWorld()) player->GetMap()->SendUpdateTransportVisibility(player, oldPhases); - player->UpdatePhasing(); + player->SendUpdatePhasing(); } // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases) @@ -1655,7 +1655,7 @@ void AuraEffect::HandlePhaseGroup(AuraApplication const* aurApp, uint8 mode, boo { if (player->IsInWorld()) player->GetMap()->SendUpdateTransportVisibility(player, oldPhases); - player->UpdatePhasing(); + player->SendUpdatePhasing(); } // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)