mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -17,11 +17,13 @@
|
||||
#include "GridRefManager.h"
|
||||
#include "MapRefManager.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "Timer.h"
|
||||
#include <bitset>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
@@ -54,9 +56,9 @@ namespace acore
|
||||
|
||||
struct ScriptAction
|
||||
{
|
||||
uint64 sourceGUID;
|
||||
uint64 targetGUID;
|
||||
uint64 ownerGUID; // owner of source if source is item
|
||||
ObjectGuid sourceGUID;
|
||||
ObjectGuid targetGUID;
|
||||
ObjectGuid ownerGUID; // owner of source if source is item
|
||||
ScriptInfo const* script; // pointer to static script data
|
||||
};
|
||||
|
||||
@@ -340,8 +342,6 @@ public:
|
||||
// pussywizard: movemaps, mmaps
|
||||
[[nodiscard]] std::shared_mutex& GetMMapLock() const { return *(const_cast<std::shared_mutex*>(&MMapLock)); }
|
||||
// pussywizard:
|
||||
std::unordered_set<Object*> i_objectsToUpdate;
|
||||
void BuildAndSendUpdateForObjects(); // definition in ObjectAccessor.cpp, below ObjectAccessor::Update, because it does the same for a map
|
||||
std::unordered_set<Unit*> i_objectsForDelayedVisibility;
|
||||
void HandleDelayedVisibility();
|
||||
|
||||
@@ -451,13 +451,39 @@ public:
|
||||
TempSummon* SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties = nullptr, uint32 duration = 0, Unit* summoner = nullptr, uint32 spellId = 0, uint32 vehId = 0);
|
||||
GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime, bool checkTransport = true);
|
||||
void SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list = nullptr);
|
||||
Player* GetPlayer(uint64 guid);
|
||||
Creature* GetCreature(uint64 guid);
|
||||
GameObject* GetGameObject(uint64 guid);
|
||||
Transport* GetTransport(uint64 guid);
|
||||
DynamicObject* GetDynamicObject(uint64 guid);
|
||||
Pet* GetPet(uint64 guid);
|
||||
Corpse* GetCorpse(uint64 guid);
|
||||
|
||||
Corpse* GetCorpse(ObjectGuid const guid);
|
||||
Creature* GetCreature(ObjectGuid const guid);
|
||||
GameObject* GetGameObject(ObjectGuid const guid);
|
||||
Transport* GetTransport(ObjectGuid const guid);
|
||||
DynamicObject* GetDynamicObject(ObjectGuid const guid);
|
||||
Pet* GetPet(ObjectGuid const guid);
|
||||
|
||||
MapStoredObjectTypesContainer& GetObjectsStore() { return _objectsStore; }
|
||||
|
||||
typedef std::unordered_multimap<ObjectGuid::LowType, Creature*> CreatureBySpawnIdContainer;
|
||||
CreatureBySpawnIdContainer& GetCreatureBySpawnIdStore() { return _creatureBySpawnIdStore; }
|
||||
|
||||
typedef std::unordered_multimap<ObjectGuid::LowType, GameObject*> GameObjectBySpawnIdContainer;
|
||||
GameObjectBySpawnIdContainer& GetGameObjectBySpawnIdStore() { return _gameobjectBySpawnIdStore; }
|
||||
|
||||
std::unordered_set<Corpse*> const* GetCorpsesInCell(uint32 cellId) const
|
||||
{
|
||||
auto itr = _corpsesByCell.find(cellId);
|
||||
if (itr != _corpsesByCell.end())
|
||||
return &itr->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Corpse* GetCorpseByPlayer(ObjectGuid const& ownerGuid) const
|
||||
{
|
||||
auto itr = _corpsesByPlayer.find(ownerGuid);
|
||||
if (itr != _corpsesByPlayer.end())
|
||||
return itr->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MapInstanced* ToMapInstanced() { if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); else return nullptr; }
|
||||
[[nodiscard]] const MapInstanced* ToMapInstanced() const { if (Instanceable()) return (const MapInstanced*)((MapInstanced*)this); else return nullptr; }
|
||||
@@ -488,33 +514,40 @@ public:
|
||||
/*
|
||||
RESPAWN TIMES
|
||||
*/
|
||||
[[nodiscard]] time_t GetLinkedRespawnTime(uint64 guid) const;
|
||||
[[nodiscard]] time_t GetCreatureRespawnTime(uint32 dbGuid) const
|
||||
[[nodiscard]] time_t GetLinkedRespawnTime(ObjectGuid guid) const;
|
||||
[[nodiscard]] time_t GetCreatureRespawnTime(ObjectGuid::LowType dbGuid) const
|
||||
{
|
||||
std::unordered_map<uint32 /*dbGUID*/, time_t>::const_iterator itr = _creatureRespawnTimes.find(dbGuid);
|
||||
std::unordered_map<ObjectGuid::LowType /*dbGUID*/, time_t>::const_iterator itr = _creatureRespawnTimes.find(dbGuid);
|
||||
if (itr != _creatureRespawnTimes.end())
|
||||
return itr->second;
|
||||
|
||||
return time_t(0);
|
||||
}
|
||||
|
||||
[[nodiscard]] time_t GetGORespawnTime(uint32 dbGuid) const
|
||||
[[nodiscard]] time_t GetGORespawnTime(ObjectGuid::LowType dbGuid) const
|
||||
{
|
||||
std::unordered_map<uint32 /*dbGUID*/, time_t>::const_iterator itr = _goRespawnTimes.find(dbGuid);
|
||||
std::unordered_map<ObjectGuid::LowType /*dbGUID*/, time_t>::const_iterator itr = _goRespawnTimes.find(dbGuid);
|
||||
if (itr != _goRespawnTimes.end())
|
||||
return itr->second;
|
||||
|
||||
return time_t(0);
|
||||
}
|
||||
|
||||
void SaveCreatureRespawnTime(uint32 dbGuid, time_t& respawnTime);
|
||||
void RemoveCreatureRespawnTime(uint32 dbGuid);
|
||||
void SaveGORespawnTime(uint32 dbGuid, time_t& respawnTime);
|
||||
void RemoveGORespawnTime(uint32 dbGuid);
|
||||
void SaveCreatureRespawnTime(ObjectGuid::LowType dbGuid, time_t& respawnTime);
|
||||
void RemoveCreatureRespawnTime(ObjectGuid::LowType dbGuid);
|
||||
void SaveGORespawnTime(ObjectGuid::LowType dbGuid, time_t& respawnTime);
|
||||
void RemoveGORespawnTime(ObjectGuid::LowType dbGuid);
|
||||
void LoadRespawnTimes();
|
||||
void DeleteRespawnTimes();
|
||||
[[nodiscard]] time_t GetInstanceResetPeriod() const { return _instanceResetPeriod; }
|
||||
|
||||
void LoadCorpseData();
|
||||
void DeleteCorpseData();
|
||||
void AddCorpse(Corpse* corpse);
|
||||
void RemoveCorpse(Corpse* corpse);
|
||||
Corpse* ConvertCorpseToBones(ObjectGuid const ownerGuid, bool insignia = false);
|
||||
void RemoveOldCorpses();
|
||||
|
||||
static void DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId);
|
||||
|
||||
void SendInitTransports(Player* player);
|
||||
@@ -539,6 +572,23 @@ public:
|
||||
|
||||
DataMap CustomData;
|
||||
|
||||
template<HighGuid high>
|
||||
inline ObjectGuid::LowType GenerateLowGuid()
|
||||
{
|
||||
static_assert(ObjectGuidTraits<high>::MapSpecific, "Only map specific guid can be generated in Map context");
|
||||
return GetGuidSequenceGenerator<high>().Generate();
|
||||
}
|
||||
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
_updateObjects.insert(obj);
|
||||
}
|
||||
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
_updateObjects.erase(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadMapAndVMap(int gx, int gy);
|
||||
void LoadVMap(int gx, int gy);
|
||||
@@ -579,6 +629,8 @@ private:
|
||||
|
||||
void UpdateActiveCells(const float& x, const float& y, const uint32 t_diff);
|
||||
|
||||
void SendObjectUpdates();
|
||||
|
||||
protected:
|
||||
std::mutex Lock;
|
||||
std::mutex GridLock;
|
||||
@@ -611,7 +663,7 @@ private:
|
||||
Creature* _GetScriptCreature(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
|
||||
WorldObject* _GetScriptWorldObject(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
|
||||
void _ScriptProcessDoor(Object* source, Object* target, const ScriptInfo* scriptInfo) const;
|
||||
GameObject* _FindGameObject(WorldObject* pWorldObject, uint32 guid) const;
|
||||
GameObject* _FindGameObject(WorldObject* pWorldObject, ObjectGuid::LowType guid) const;
|
||||
|
||||
//used for fast base_map (e.g. MapInstanced class object) search for
|
||||
//InstanceMaps and BattlegroundMaps...
|
||||
@@ -658,11 +710,31 @@ private:
|
||||
m_activeNonPlayers.erase(obj);
|
||||
}
|
||||
|
||||
std::unordered_map<uint32 /*dbGUID*/, time_t> _creatureRespawnTimes;
|
||||
std::unordered_map<uint32 /*dbGUID*/, time_t> _goRespawnTimes;
|
||||
std::unordered_map<ObjectGuid::LowType /*dbGUID*/, time_t> _creatureRespawnTimes;
|
||||
std::unordered_map<ObjectGuid::LowType /*dbGUID*/, time_t> _goRespawnTimes;
|
||||
|
||||
ZoneDynamicInfoMap _zoneDynamicInfo;
|
||||
uint32 _defaultLight;
|
||||
|
||||
template<HighGuid high>
|
||||
inline ObjectGuidGeneratorBase& GetGuidSequenceGenerator()
|
||||
{
|
||||
auto itr = _guidGenerators.find(high);
|
||||
if (itr == _guidGenerators.end())
|
||||
itr = _guidGenerators.insert(std::make_pair(high, std::unique_ptr<ObjectGuidGenerator<high>>(new ObjectGuidGenerator<high>()))).first;
|
||||
|
||||
return *itr->second;
|
||||
}
|
||||
|
||||
std::map<HighGuid, std::unique_ptr<ObjectGuidGeneratorBase>> _guidGenerators;
|
||||
MapStoredObjectTypesContainer _objectsStore;
|
||||
CreatureBySpawnIdContainer _creatureBySpawnIdStore;
|
||||
GameObjectBySpawnIdContainer _gameobjectBySpawnIdStore;
|
||||
std::unordered_map<uint32/*cellId*/, std::unordered_set<Corpse*>> _corpsesByCell;
|
||||
std::unordered_map<ObjectGuid, Corpse*> _corpsesByPlayer;
|
||||
std::unordered_set<Corpse*> _corpseBones;
|
||||
|
||||
std::unordered_set<Object*> _updateObjects;
|
||||
};
|
||||
|
||||
enum InstanceResetMethod
|
||||
@@ -684,7 +756,7 @@ public:
|
||||
void AfterPlayerUnlinkFromMap() override;
|
||||
void Update(const uint32, const uint32, bool thread = true) override;
|
||||
void CreateInstanceScript(bool load, std::string data, uint32 completedEncounterMask);
|
||||
bool Reset(uint8 method, std::list<uint32>* globalSkipList = nullptr);
|
||||
bool Reset(uint8 method, GuidList* globalSkipList = nullptr);
|
||||
[[nodiscard]] uint32 GetScriptId() const { return i_script_id; }
|
||||
[[nodiscard]] std::string const& GetScriptName() const;
|
||||
[[nodiscard]] InstanceScript* GetInstanceScript() { return instance_data; }
|
||||
|
||||
Reference in New Issue
Block a user