Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
ObjectAccessor.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRE_OBJECTACCESSOR_H
7#define SKYFIRE_OBJECTACCESSOR_H
8
9#include "Define.h"
10#include "UnorderedMap.h"
11
12#include "UpdateData.h"
13
14#include "GridDefines.h"
15#include "Object.h"
16#include "Platform/Singleton.h"
17
18#include "SharedMutex.h"
19#include <set>
20
21class Creature;
22class Corpse;
23class Unit;
24class GameObject;
25class DynamicObject;
26class WorldObject;
27class Vehicle;
28class Map;
29class WorldRunnable;
30class Transport;
31
32template <class T>
34{
35public:
37
38 static void Insert(T* o);
39
40 static void Remove(T* o);
41
42 static T* Find(uint64 guid);
43
44 static MapType& GetContainer();
45
46 static SF_SHARED_MUTEX* GetLock();
47
48
49private:
50 //Non instanceable only static
54};
55
57{
58 friend class Skyfire::Singleton<ObjectAccessor, Skyfire::NullMutex>;
59private:
62 ObjectAccessor(const ObjectAccessor&);
63 ObjectAccessor& operator=(const ObjectAccessor&);
64
65public:
67 template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
68 {
69 return HashMapHolder<T>::Find(guid);
70 }
71
72 static Unit* GetObjectInOrOutOfWorld(uint64 guid, Unit* /*typeSpecifier*/)
73 {
74 if (IS_PLAYER_GUID(guid))
75 return (Unit*)GetObjectInOrOutOfWorld(guid, (Player*)NULL);
76
77 if (IS_PET_GUID(guid))
78 return (Unit*)GetObjectInOrOutOfWorld(guid, (Pet*)NULL);
79
80 return (Unit*)GetObjectInOrOutOfWorld(guid, (Creature*)NULL);
81 }
82
83 // returns object if is in world
84 template<class T> static T* GetObjectInWorld(uint64 guid, T* /*typeSpecifier*/)
85 {
86 return HashMapHolder<T>::Find(guid);
87 }
88
89 // Player may be not in world while in ObjectAccessor
90 static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/);
91
92 static Unit* GetObjectInWorld(uint64 guid, Unit* /*typeSpecifier*/)
93 {
94 if (IS_PLAYER_GUID(guid))
95 return (Unit*)GetObjectInWorld(guid, (Player*)NULL);
96
97 if (IS_PET_GUID(guid))
98 return (Unit*)GetObjectInWorld(guid, (Pet*)NULL);
99
100 return (Unit*)GetObjectInWorld(guid, (Creature*)NULL);
101 }
102
103 // returns object if is in map
104 template<class T> static T* GetObjectInMap(uint64 guid, Map* map, T* /*typeSpecifier*/)
105 {
106 ASSERT(map);
107 if (T* obj = GetObjectInWorld(guid, (T*)NULL))
108 if (obj->GetMap() == map)
109 return obj;
110 return NULL;
111 }
112
113 template<class T> static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/);
114
115 // these functions return objects only if in map of specified object
117 static Object* GetObjectByTypeMask(WorldObject const&, uint64, uint32 typemask);
118 static Corpse* GetCorpse(WorldObject const& u, uint64 guid);
119 static GameObject* GetGameObject(WorldObject const& u, uint64 guid);
120 static Transport* GetTransport(WorldObject const& u, uint64 guid);
121 static DynamicObject* GetDynamicObject(WorldObject const& u, uint64 guid);
122 static AreaTrigger* GetAreaTrigger(WorldObject const& u, uint64 guid);
123 static Unit* GetUnit(WorldObject const&, uint64 guid);
124 static Creature* GetCreature(WorldObject const& u, uint64 guid);
125 static Pet* GetPet(WorldObject const&, uint64 guid);
126 static Player* GetPlayer(WorldObject const&, uint64 guid);
128
129 // these functions return objects if found in whole world
130 // ACCESS LIKE THAT IS NOT THREAD SAFE
131 static Pet* FindPet(uint64);
132 static Player* FindPlayer(uint64);
134 //static Creature* FindCreature(uint64);
135 static Unit* FindUnit(uint64);
136 static Player* FindPlayerByName(std::string const& name);
137
138 // when using this, you must use the hashmapholder's lock
143
144 // when using this, you must use the hashmapholder's lock
149
150 // when using this, you must use the hashmapholder's lock
155
156 template<class T> static void AddObject(T* object)
157 {
159 }
160
161 template<class T> static void RemoveObject(T* object)
162 {
164 }
165
166 static void SaveAllPlayers();
167
168 //non-static functions
169 void AddUpdateObject(Object* obj);
170 void RemoveUpdateObject(Object* obj);
171
172 //Thread safe
174 void RemoveCorpse(Corpse* corpse);
175 void AddCorpse(Corpse* corpse);
176 void AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map);
177 Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
178
179 //Thread unsafe
180 void Update(uint32 diff);
181 void RemoveOldCorpses();
182 void UnloadAll();
183
184private:
187
188 std::set<Object*> i_objects;
190
193};
194
195#define sObjectAccessor Skyfire::Singleton<ObjectAccessor, Skyfire::NullMutex>::instance()
196
197#endif
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
#define ASSERT
Definition Errors.h:29
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Grid< Player, AllWorldObjectTypes, AllGridObjectTypes > GridType
Definition GridDefines.h:68
bool IS_PET_GUID(uint64 guid)
bool IS_PLAYER_GUID(uint64 guid)
#define SF_SHARED_MUTEX
Definition SharedMutex.h:16
#define UNORDERED_MAP
static SF_SHARED_MUTEX * GetLock()
static T * Find(uint64 guid)
static void Remove(T *o)
static MapType m_objectMap
static MapType & GetContainer()
UNORDERED_MAP< uint64, T * > MapType
static void Insert(T *o)
static SF_SHARED_MUTEX i_lock
Definition Map.h:238
static Creature * GetCreature(WorldObject const &u, uint64 guid)
static AreaTrigger * GetAreaTrigger(WorldObject const &u, uint64 guid)
static HashMapHolder< GameObject >::MapType const & GetGameObjects()
static void SaveAllPlayers()
SF_SHARED_MUTEX i_objectLock
static Pet * FindPet(uint64)
static Creature * GetCreatureOrPetOrVehicle(WorldObject const &, uint64)
static Player * FindPlayerByName(std::string const &name)
static void AddObject(T *object)
void AddCorpse(Corpse *corpse)
static Unit * GetObjectInWorld(uint64 guid, Unit *)
static T * GetObjectInMap(uint64 guid, Map *map, T *)
static Object * GetObjectByTypeMask(WorldObject const &, uint64, uint32 typemask)
static Unit * GetObjectInOrOutOfWorld(uint64 guid, Unit *)
static Transport * GetTransport(WorldObject const &u, uint64 guid)
static Player * FindPlayerInOrOutOfWorld(uint64)
void RemoveCorpse(Corpse *corpse)
UNORDERED_MAP< Player *, UpdateData >::value_type UpdateDataValueType
static Player * GetPlayer(WorldObject const &, uint64 guid)
void AddUpdateObject(Object *obj)
SF_SHARED_MUTEX i_corpseLock
void RemoveUpdateObject(Object *obj)
static WorldObject * GetWorldObject(WorldObject const &, uint64)
static GameObject * GetGameObject(WorldObject const &u, uint64 guid)
static Unit * GetUnit(WorldObject const &, uint64 guid)
static HashMapHolder< Player >::MapType const & GetPlayers()
std::set< Object * > i_objects
static Corpse * GetCorpse(WorldObject const &u, uint64 guid)
static T * GetObjectInWorld(uint64 guid, T *)
UNORDERED_MAP< uint64, Corpse * > Player2CorpsesMapType
Corpse * ConvertCorpseForPlayer(uint64 player_guid, bool insignia=false)
void Update(uint32 diff)
Player2CorpsesMapType i_player2corpse
void AddCorpsesToGrid(GridCoord const &gridpair, GridType &grid, Map *map)
static HashMapHolder< Creature >::MapType const & GetCreatures()
static Player * FindPlayer(uint64)
static DynamicObject * GetDynamicObject(WorldObject const &u, uint64 guid)
static void RemoveObject(T *object)
static Unit * FindUnit(uint64)
Corpse * GetCorpseForPlayerGUID(uint64 guid)
static Pet * GetPet(WorldObject const &, uint64 guid)
static T * GetObjectInOrOutOfWorld(uint64 guid, T *)
Definition Pet.h:28
Definition Unit.h:1367
Heartbeat thread for the World.