diff options
| author | ariel- <ariel-@users.noreply.github.com> | 2017-06-11 16:41:11 -0300 |
|---|---|---|
| committer | ariel- <ariel-@users.noreply.github.com> | 2017-06-11 17:02:01 -0300 |
| commit | 3e7b64b2f765bebc722c1194b7fc2f749fae77f7 (patch) | |
| tree | b0a7c819e98cf06585fbd5228f40daba4b9399f2 /src/server/game | |
| parent | c210b935942f8f2202f1436f2cf73821614c041d (diff) | |
Core/OutdoorPvP: refactor using Position and Quat to pack parameters
- Moved statics to cpp
- Save scriptids into an array
Diffstat (limited to 'src/server/game')
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 29 | ||||
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 4 | ||||
| -rw-r--r-- | src/server/game/OutdoorPvP/OutdoorPvP.cpp | 12 | ||||
| -rw-r--r-- | src/server/game/OutdoorPvP/OutdoorPvP.h | 45 | ||||
| -rw-r--r-- | src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp | 19 | ||||
| -rw-r--r-- | src/server/game/OutdoorPvP/OutdoorPvPMgr.h | 12 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 3 |
8 files changed, 48 insertions, 82 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index fbb238f8084..048eff35504 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -1934,7 +1934,7 @@ void ObjectMgr::RemoveCreatureFromGrid(ObjectGuid::LowType guid, CreatureData co } } -ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float z, float o, uint32 spawntimedelay, float rotation0, float rotation1, float rotation2, float rotation3) +ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, Position const& pos, G3D::Quat const& rot, uint32 spawntimedelay /*= 0*/) { GameObjectTemplate const* goinfo = GetGameObjectTemplate(entry); if (!goinfo) @@ -1949,14 +1949,10 @@ ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, fl GameObjectData& data = NewGOData(guid); data.id = entry; data.mapid = mapId; - data.posX = x; - data.posY = y; - data.posZ = z; - data.orientation = o; - data.rotation.x = rotation0; - data.rotation.y = rotation1; - data.rotation.z = rotation2; - data.rotation.w = rotation3; + + pos.GetPosition(data.posX, data.posY, data.posZ, data.orientation); + + data.rotation = rot; data.spawntimesecs = spawntimedelay; data.animprogress = 100; data.spawnMask = 1; @@ -1969,7 +1965,7 @@ ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, fl // Spawn if necessary (loaded grids only) // We use spawn coords to spawn - if (!map->Instanceable() && map->IsGridLoaded(x, y)) + if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY)) { GameObject* go = new GameObject; if (!go->LoadGameObjectFromDB(guid, map)) @@ -1980,13 +1976,13 @@ ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, fl } } - TC_LOG_DEBUG("maps", "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o); + TC_LOG_DEBUG("maps", "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, data.posX, data.posY, data.posZ, data.orientation); return guid; } -ObjectGuid::LowType ObjectMgr::AddCreatureData(uint32 entry, uint32 mapId, float x, float y, float z, float o, uint32 spawntimedelay /*= 0*/) +ObjectGuid::LowType ObjectMgr::AddCreatureData(uint32 entry, uint32 mapId, Position const& pos, uint32 spawntimedelay /*= 0*/) { CreatureTemplate const* cInfo = GetCreatureTemplate(entry); if (!cInfo) @@ -2004,10 +2000,9 @@ ObjectGuid::LowType ObjectMgr::AddCreatureData(uint32 entry, uint32 mapId, float data.mapid = mapId; data.displayid = 0; data.equipmentId = 0; - data.posX = x; - data.posY = y; - data.posZ = z; - data.orientation = o; + + pos.GetPosition(data.posX, data.posY, data.posZ, data.orientation); + data.spawntimesecs = spawntimedelay; data.spawndist = 0; data.currentwaypoint = 0; @@ -2024,7 +2019,7 @@ ObjectGuid::LowType ObjectMgr::AddCreatureData(uint32 entry, uint32 mapId, float AddCreatureToGrid(guid, &data); // We use spawn coords to spawn - if (!map->Instanceable() && !map->IsRemovalGrid(x, y)) + if (!map->Instanceable() && !map->IsRemovalGrid(data.posX, data.posY)) { Creature* creature = new Creature(); if (!creature->LoadCreatureFromDB(guid, map)) diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 63c0a8d6c55..d88dbc10167 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1238,8 +1238,8 @@ class TC_GAME_API ObjectMgr void RemoveCreatureFromGrid(ObjectGuid::LowType guid, CreatureData const* data); void AddGameobjectToGrid(ObjectGuid::LowType guid, GameObjectData const* data); void RemoveGameobjectFromGrid(ObjectGuid::LowType guid, GameObjectData const* data); - ObjectGuid::LowType AddGOData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0, float rotation0 = 0, float rotation1 = 0, float rotation2 = 0, float rotation3 = 0); - ObjectGuid::LowType AddCreatureData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0); + ObjectGuid::LowType AddGOData(uint32 entry, uint32 map, Position const& pos, G3D::Quat const& rot, uint32 spawntimedelay = 0); + ObjectGuid::LowType AddCreatureData(uint32 entry, uint32 map, Position const& pos, uint32 spawntimedelay = 0); // reserved names void LoadReservedPlayersNames(); diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.cpp b/src/server/game/OutdoorPvP/OutdoorPvP.cpp index 231622eac4d..c48badaba85 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvP.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvP.cpp @@ -113,9 +113,9 @@ void OPvPCapturePoint::AddCre(uint32 type, ObjectGuid::LowType guid, uint32 entr m_CreatureTypes[m_Creatures[type]] = type; } -bool OPvPCapturePoint::AddObject(uint32 type, uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) +bool OPvPCapturePoint::AddObject(uint32 type, uint32 entry, uint32 map, Position const& pos, G3D::Quat const& rot) { - if (ObjectGuid::LowType guid = sObjectMgr->AddGOData(entry, map, x, y, z, o, 0, rotation0, rotation1, rotation2, rotation3)) + if (ObjectGuid::LowType guid = sObjectMgr->AddGOData(entry, map, pos, rot, 0)) { AddGO(type, guid, entry); return true; @@ -124,9 +124,9 @@ bool OPvPCapturePoint::AddObject(uint32 type, uint32 entry, uint32 map, float x, return false; } -bool OPvPCapturePoint::AddCreature(uint32 type, uint32 entry, uint32 map, float x, float y, float z, float o, TeamId /*teamId = TEAM_NEUTRAL*/, uint32 spawntimedelay /*= 0*/) +bool OPvPCapturePoint::AddCreature(uint32 type, uint32 entry, uint32 map, Position const& pos, TeamId /*teamId = TEAM_NEUTRAL*/, uint32 spawntimedelay /*= 0*/) { - if (ObjectGuid::LowType guid = sObjectMgr->AddCreatureData(entry, map, x, y, z, o, spawntimedelay)) + if (ObjectGuid::LowType guid = sObjectMgr->AddCreatureData(entry, map, pos, spawntimedelay)) { AddCre(type, guid, entry); return true; @@ -135,7 +135,7 @@ bool OPvPCapturePoint::AddCreature(uint32 type, uint32 entry, uint32 map, float return false; } -bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) +bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, Position const& pos, G3D::Quat const& rot) { TC_LOG_DEBUG("outdoorpvp", "Creating capture point %u", entry); @@ -147,7 +147,7 @@ bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, float x, fl return false; } - m_capturePointSpawnId = sObjectMgr->AddGOData(entry, map, x, y, z, o, 0, rotation0, rotation1, rotation2, rotation3); + m_capturePointSpawnId = sObjectMgr->AddGOData(entry, map, pos, rot, 0); if (m_capturePointSpawnId == 0) return false; diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.h b/src/server/game/OutdoorPvP/OutdoorPvP.h index 94d475899b0..a918365b11d 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvP.h +++ b/src/server/game/OutdoorPvP/OutdoorPvP.h @@ -22,19 +22,19 @@ #include "SharedDefines.h" #include "ZoneScript.h" -class GameObject; +#include <G3D/Quat.h> enum OutdoorPvPTypes { OUTDOOR_PVP_HP = 1, - OUTDOOR_PVP_NA = 2, - OUTDOOR_PVP_TF = 3, - OUTDOOR_PVP_ZM = 4, - OUTDOOR_PVP_SI = 5, - OUTDOOR_PVP_EP = 6 -}; + OUTDOOR_PVP_NA, + OUTDOOR_PVP_TF, + OUTDOOR_PVP_ZM, + OUTDOOR_PVP_SI, + OUTDOOR_PVP_EP, -#define MAX_OUTDOORPVP_TYPES 7 + MAX_OUTDOORPVP_TYPES +}; enum ObjectiveStates { @@ -54,14 +54,8 @@ struct go_type { uint32 entry; uint32 map; - float x; - float y; - float z; - float o; - float rot0; - float rot1; - float rot2; - float rot3; + Position pos; + G3D::Quat rot; }; // struct for creature spawning @@ -69,10 +63,7 @@ struct creature_type { uint32 entry; uint32 map; - float x; - float y; - float z; - float o; + Position pos; }; // some class predefs @@ -135,17 +126,15 @@ class TC_GAME_API OPvPCapturePoint void AddGO(uint32 type, ObjectGuid::LowType guid, uint32 entry = 0); void AddCre(uint32 type, ObjectGuid::LowType guid, uint32 entry = 0); - bool SetCapturePointData(uint32 entry, uint32 map, float x, float y, float z, float o = 0, - float rotation0 = 0, float rotation1 = 0, float rotation2 = 0, float rotation3 = 0); + bool SetCapturePointData(uint32 entry, uint32 map, Position const& pos, G3D::Quat const& rot); protected: - bool AddObject(uint32 type, uint32 entry, uint32 map, float x, float y, float z, float o, - float rotation0, float rotation1, float rotation2, float rotation3); - virtual bool AddCreature(uint32 type, uint32 entry, uint32 map, float x, float y, float z, float o, TeamId teamId = TEAM_NEUTRAL, uint32 spawntimedelay = 0); + bool AddObject(uint32 type, uint32 entry, uint32 map, Position const& pos, G3D::Quat const& rot); + bool AddCreature(uint32 type, uint32 entry, uint32 map, Position const& pos, TeamId teamId = TEAM_NEUTRAL, uint32 spawntimedelay = 0); - bool DelCreature(uint32 type); bool DelObject(uint32 type); + bool DelCreature(uint32 type); bool DelCapturePoint(); @@ -292,12 +281,12 @@ class TC_GAME_API OutdoorPvP : public ZoneScript m_capturePoints[cp->m_capturePointSpawnId] = cp; } - OPvPCapturePoint * GetCapturePoint(ObjectGuid::LowType guid) const + OPvPCapturePoint* GetCapturePoint(ObjectGuid::LowType guid) const { OutdoorPvP::OPvPCapturePointMap::const_iterator itr = m_capturePoints.find(guid); if (itr != m_capturePoints.end()) return itr->second; - return NULL; + return nullptr; } void RegisterZone(uint32 zoneid); diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp index 70538c2f810..a1de152d9ae 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp @@ -24,21 +24,17 @@ OutdoorPvPMgr::OutdoorPvPMgr() { m_UpdateTimer = 0; - //TC_LOG_DEBUG("outdoorpvp", "Instantiating OutdoorPvPMgr"); } void OutdoorPvPMgr::Die() { - //TC_LOG_DEBUG("outdoorpvp", "Deleting OutdoorPvPMgr"); for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr) delete *itr; m_OutdoorPvPSet.clear(); - for (OutdoorPvPDataMap::iterator itr = m_OutdoorPvPDatas.begin(); itr != m_OutdoorPvPDatas.end(); ++itr) - delete itr->second; - - m_OutdoorPvPDatas.clear(); + for (uint32 i = 0; i < MAX_OUTDOORPVP_TYPES; ++i) + m_OutdoorPvPDatas[i] = 0; m_OutdoorPvPMap.clear(); } @@ -55,7 +51,6 @@ void OutdoorPvPMgr::InitOutdoorPvP() // 0 1 QueryResult result = WorldDatabase.Query("SELECT TypeId, ScriptName FROM outdoorpvp_template"); - if (!result) { TC_LOG_ERROR("server.loading", ">> Loaded 0 outdoor PvP definitions. DB table `outdoorpvp_template` is empty."); @@ -80,11 +75,8 @@ void OutdoorPvPMgr::InitOutdoorPvP() continue; } - OutdoorPvPData* data = new OutdoorPvPData(); OutdoorPvPTypes realTypeId = OutdoorPvPTypes(typeId); - data->TypeId = realTypeId; - data->ScriptId = sObjectMgr->GetScriptId(fields[1].GetString()); - m_OutdoorPvPDatas[realTypeId] = data; + m_OutdoorPvPDatas[realTypeId] = sObjectMgr->GetScriptId(fields[1].GetString()); ++count; } @@ -93,14 +85,13 @@ void OutdoorPvPMgr::InitOutdoorPvP() OutdoorPvP* pvp; for (uint8 i = 1; i < MAX_OUTDOORPVP_TYPES; ++i) { - OutdoorPvPDataMap::iterator iter = m_OutdoorPvPDatas.find(OutdoorPvPTypes(i)); - if (iter == m_OutdoorPvPDatas.end()) + if (!m_OutdoorPvPDatas[i]) { TC_LOG_ERROR("sql.sql", "Could not initialize OutdoorPvP object for type ID %u; no entry in database.", uint32(i)); continue; } - pvp = sScriptMgr->CreateOutdoorPvP(iter->second); + pvp = sScriptMgr->CreateOutdoorPvP(m_OutdoorPvPDatas[i]); if (!pvp) { TC_LOG_ERROR("outdoorpvp", "Could not initialize OutdoorPvP object for type ID %u; got NULL pointer from script.", uint32(i)); diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h index 25d21b27bae..e69d9482edd 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h +++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h @@ -28,12 +28,6 @@ class Creature; class ZoneScript; struct GossipMenuItems; -struct OutdoorPvPData -{ - OutdoorPvPTypes TypeId; - uint32 ScriptId; -}; - // class to handle player enter / leave / areatrigger / GO use events class TC_GAME_API OutdoorPvPMgr { @@ -84,8 +78,8 @@ class TC_GAME_API OutdoorPvPMgr private: typedef std::vector<OutdoorPvP*> OutdoorPvPSet; - typedef std::map<uint32 /* zoneid */, OutdoorPvP*> OutdoorPvPMap; - typedef std::map<OutdoorPvPTypes, OutdoorPvPData*> OutdoorPvPDataMap; + typedef std::unordered_map<uint32 /* zoneid */, OutdoorPvP*> OutdoorPvPMap; + typedef std::array<uint32, MAX_OUTDOORPVP_TYPES> OutdoorPvPScriptIds; // contains all initiated outdoor pvp events // used when initing / cleaning up @@ -96,7 +90,7 @@ class TC_GAME_API OutdoorPvPMgr OutdoorPvPMap m_OutdoorPvPMap; // Holds the outdoor PvP templates - OutdoorPvPDataMap m_OutdoorPvPDatas; + OutdoorPvPScriptIds m_OutdoorPvPDatas; // update interval uint32 m_UpdateTimer; diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 62be21d19b6..5d71b0ed33e 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1607,11 +1607,9 @@ Battleground* ScriptMgr::CreateBattleground(BattlegroundTypeId /*typeId*/) return NULL; } -OutdoorPvP* ScriptMgr::CreateOutdoorPvP(OutdoorPvPData const* data) +OutdoorPvP* ScriptMgr::CreateOutdoorPvP(uint32 scriptId) { - ASSERT(data); - - GET_SCRIPT_RET(OutdoorPvPScript, data->ScriptId, tmpscript, NULL); + GET_SCRIPT_RET(OutdoorPvPScript, scriptId, tmpscript, NULL); return tmpscript->GetOutdoorPvP(); } diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 1f553989253..ff89a1314a2 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -71,7 +71,6 @@ struct Condition; struct CreatureTemplate; struct CreatureData; struct ItemTemplate; -struct OutdoorPvPData; #define VISIBLE_RANGE 166.0f //MAX visible range (size of grid) @@ -919,7 +918,7 @@ class TC_GAME_API ScriptMgr public: /* OutdoorPvPScript */ - OutdoorPvP* CreateOutdoorPvP(OutdoorPvPData const* data); + OutdoorPvP* CreateOutdoorPvP(uint32 scriptId); public: /* CommandScript */ |
