Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
ObjectGridLoader.cpp
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
#include "
AreaTrigger.h
"
7
#include "
CellImpl.h
"
8
#include "
Corpse.h
"
9
#include "
Creature.h
"
10
#include "
CreatureAI.h
"
11
#include "
DynamicObject.h
"
12
#include "
GameObject.h
"
13
#include "
ObjectAccessor.h
"
14
#include "
ObjectGridLoader.h
"
15
#include "
ObjectMgr.h
"
16
#include "
Vehicle.h
"
17
#include "
World.h
"
18
19
void
ObjectGridEvacuator::Visit
(
CreatureMapType
& m)
20
{
21
// creature in unloading grid can have respawn point in another grid
22
// if it will be unloaded then it will not respawn in original grid until unload/load original grid
23
// move to respawn point to prevent this case. For player view in respawn grid this will be normal respawn.
24
for
(
CreatureMapType::iterator
iter = m.
begin
(); iter != m.
end
();)
25
{
26
Creature
* c = iter->GetSource();
27
++iter;
28
29
ASSERT
(!c->
IsPet
() &&
"ObjectGridRespawnMover must not be called for pets"
);
30
c->
GetMap
()->
CreatureRespawnRelocation
(c,
true
);
31
}
32
}
33
34
void
ObjectGridEvacuator::Visit
(
GameObjectMapType
& m)
35
{
36
// gameobject in unloading grid can have respawn point in another grid
37
// if it will be unloaded then it will not respawn in original grid until unload/load original grid
38
// move to respawn point to prevent this case. For player view in respawn grid this will be normal respawn.
39
for
(
GameObjectMapType::iterator
iter = m.
begin
(); iter != m.
end
();)
40
{
41
GameObject
* go = iter->GetSource();
42
++iter;
43
44
go->
GetMap
()->
GameObjectRespawnRelocation
(go,
true
);
45
}
46
}
47
48
// for loading world object at grid loading (Corpses)
50
class
ObjectWorldLoader
51
{
52
public
:
53
explicit
ObjectWorldLoader
(
ObjectGridLoader
& gloader)
54
:
i_cell
(gloader.
i_cell
),
i_map
(gloader.
i_map
),
i_corpses
(0)
55
{ }
56
57
void
Visit
(
CorpseMapType
& m);
58
59
template
<
class
T>
void
Visit
(
GridRefManager<T>
&) { }
60
61
private
:
62
Cell
i_cell
;
63
Map
*
i_map
;
64
public
:
65
uint32
i_corpses
;
66
};
67
68
template
<
class
T>
void
ObjectGridLoader::SetObjectCell
(T*
/*obj*/
,
CellCoord
const
&
/*cellCoord*/
) { }
69
70
template
<>
void
ObjectGridLoader::SetObjectCell
(
Creature
* obj,
CellCoord
const
& cellCoord)
71
{
72
Cell
cell(cellCoord);
73
obj->
SetCurrentCell
(cell);
74
}
75
76
template
<>
void
ObjectGridLoader::SetObjectCell
(
GameObject
* obj,
CellCoord
const
& cellCoord)
77
{
78
Cell
cell(cellCoord);
79
obj->
SetCurrentCell
(cell);
80
}
81
82
template
<
class
T>
83
void
AddObjectHelper
(
CellCoord
& cell,
GridRefManager<T>
& m,
uint32
& count,
Map
*
/*map*/
, T* obj)
84
{
85
obj->AddToGrid(m);
86
ObjectGridLoader::SetObjectCell
(obj, cell);
87
obj->AddToWorld();
88
++count;
89
}
90
91
template
<>
92
void
AddObjectHelper
(
CellCoord
& cell,
CreatureMapType
& m,
uint32
& count,
Map
* map,
Creature
* obj)
93
{
94
obj->
AddToGrid
(m);
95
ObjectGridLoader::SetObjectCell
(obj, cell);
96
obj->
AddToWorld
();
97
if
(obj->
isActiveObject
())
98
map->
AddToActive
(obj);
99
100
++count;
101
}
102
103
template
<
class
T>
104
void
LoadHelper
(
CellGuidSet
const
& guid_set,
CellCoord
& cell,
GridRefManager<T>
& m,
uint32
& count,
Map
* map)
105
{
106
for
(CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
107
{
108
T* obj =
new
T;
109
uint32
guid = *i_guid;
110
//SF_LOG_INFO("misc", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
111
if
(!obj->LoadFromDB(guid, map))
112
{
113
delete
obj;
114
continue
;
115
}
116
117
AddObjectHelper
(cell, m, count, map, obj);
118
}
119
}
120
121
void
LoadHelper
(
CellCorpseSet
const
& cell_corpses,
CellCoord
& cell,
CorpseMapType
& m,
uint32
& count,
Map
* map)
122
{
123
if
(cell_corpses.empty())
124
return
;
125
126
for
(CellCorpseSet::const_iterator itr = cell_corpses.begin(); itr != cell_corpses.end(); ++itr)
127
{
128
if
(itr->second != map->
GetInstanceId
())
129
continue
;
130
131
uint32
player_guid = itr->first;
132
133
Corpse
* obj =
sObjectAccessor
->GetCorpseForPlayerGUID(player_guid);
134
if
(!obj)
135
continue
;
136
138
// corpse's map should be reset when the map is unloaded
139
// but it may still exist when the grid is unloaded but map is not
140
// in that case map == currMap
141
obj->
SetMap
(map);
142
143
if
(obj->
IsInGrid
())
144
{
145
obj->
AddToWorld
();
146
continue
;
147
}
148
149
AddObjectHelper
(cell, m, count, map, obj);
150
}
151
}
152
153
void
ObjectGridLoader::Visit
(
GameObjectMapType
& m)
154
{
155
CellCoord
cellCoord =
i_cell
.GetCellCoord();
156
CellObjectGuids
const
& cell_guids =
sObjectMgr
->GetCellObjectGuids(
i_map
->GetId(),
i_map
->GetSpawnMode(), cellCoord.
GetId
());
157
LoadHelper
(cell_guids.
gameobjects
, cellCoord, m,
i_gameObjects
,
i_map
);
158
}
159
160
void
ObjectGridLoader::Visit
(
CreatureMapType
& m)
161
{
162
CellCoord
cellCoord =
i_cell
.GetCellCoord();
163
CellObjectGuids
const
& cell_guids =
sObjectMgr
->GetCellObjectGuids(
i_map
->GetId(),
i_map
->GetSpawnMode(), cellCoord.
GetId
());
164
LoadHelper
(cell_guids.
creatures
, cellCoord, m,
i_creatures
,
i_map
);
165
}
166
167
void
ObjectWorldLoader::Visit
(
CorpseMapType
& m)
168
{
169
CellCoord
cellCoord =
i_cell
.GetCellCoord();
170
// corpses are always added to spawn mode 0 and they are spawned by their instance id
171
CellObjectGuids
const
& cell_guids =
sObjectMgr
->GetCellObjectGuids(
i_map
->GetId(), 0, cellCoord.
GetId
());
172
LoadHelper
(cell_guids.
corpses
, cellCoord, m,
i_corpses
,
i_map
);
173
}
174
175
void
ObjectGridLoader::LoadN
(
void
)
176
{
177
i_gameObjects
= 0;
i_creatures
= 0;
i_corpses
= 0;
178
i_cell
.data.Part.cell_y = 0;
179
for
(
unsigned
int
x = 0; x <
MAX_NUMBER_OF_CELLS
; ++x)
180
{
181
i_cell
.data.Part.cell_x = x;
182
for
(
unsigned
int
y = 0; y <
MAX_NUMBER_OF_CELLS
; ++y)
183
{
184
i_cell
.data.Part.cell_y = y;
185
186
//Load creatures and game objects
187
{
188
TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer>
visitor(*
this
);
189
i_grid
.VisitGrid(x, y, visitor);
190
}
191
192
//Load corpses (not bones)
193
{
194
ObjectWorldLoader
worker(*
this
);
195
TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer>
visitor(worker);
196
i_grid
.VisitGrid(x, y, visitor);
197
i_corpses
+= worker.
i_corpses
;
198
}
199
}
200
}
201
SF_LOG_DEBUG
(
"maps"
,
"%u GameObjects, %u Creatures, and %u Corpses/Bones loaded for grid %u on map %u"
,
i_gameObjects
,
i_creatures
,
i_corpses
,
i_grid
.GetGridId(),
i_map
->GetId());
202
}
203
204
template
<
class
T>
205
void
ObjectGridUnloader::Visit
(
GridRefManager<T>
& m)
206
{
207
while
(!m.
isEmpty
())
208
{
209
T* obj = m.
getFirst
()->GetSource();
210
// if option set then object already saved at this moment
211
if
(!
sWorld
->GetBoolConfig(
WorldBoolConfigs::CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY
))
212
obj->SaveRespawnTime();
213
//Some creatures may summon other temp summons in CleanupsBeforeDelete()
214
//So we need this even after cleaner (maybe we can remove cleaner)
215
//Example: Flame Leviathan Turret 33139 is summoned when a creature is deleted
217
obj->CleanupsBeforeDelete();
219
delete
obj;
220
}
221
}
222
223
void
ObjectGridStoper::Visit
(
CreatureMapType
& m)
224
{
225
// stop any fights at grid de-activation and remove dynobjects created at cast by creatures
226
for
(
CreatureMapType::iterator
iter = m.
begin
(); iter != m.
end
(); ++iter)
227
{
228
iter->GetSource()->RemoveAllDynObjects();
229
if
(iter->GetSource()->IsInCombat())
230
{
231
iter->GetSource()->CombatStop();
232
iter->GetSource()->DeleteThreatList();
233
iter->GetSource()->AI()->EnterEvadeMode();
234
}
235
}
236
}
237
238
template
<
class
T>
239
void
ObjectGridCleaner::Visit
(
GridRefManager<T>
& m)
240
{
241
for
(
typename
GridRefManager<T>::iterator
iter = m.
begin
(); iter != m.
end
(); ++iter)
242
iter->GetSource()->CleanupsBeforeDelete();
243
}
244
245
template
void
ObjectGridUnloader::Visit
(
CreatureMapType
&);
246
template
void
ObjectGridUnloader::Visit
(
GameObjectMapType
&);
247
template
void
ObjectGridUnloader::Visit
(
DynamicObjectMapType
&);
248
template
void
ObjectGridUnloader::Visit
(
CorpseMapType
&);
249
template
void
ObjectGridUnloader::Visit
(
AreaTriggerMapType
&);
250
template
void
ObjectGridCleaner::Visit
(
CreatureMapType
&);
251
template
void
ObjectGridCleaner::Visit<GameObject>
(
GameObjectMapType
&);
252
template
void
ObjectGridCleaner::Visit<DynamicObject>
(
DynamicObjectMapType
&);
253
template
void
ObjectGridCleaner::Visit<Corpse>
(
CorpseMapType
&);
254
template
void
ObjectGridCleaner::Visit<AreaTrigger>
(
AreaTriggerMapType
&);
AreaTrigger.h
CellImpl.h
Corpse.h
Creature.h
CreatureAI.h
uint32
std::uint32_t uint32
Definition
Define.h:77
DynamicObject.h
ASSERT
#define ASSERT
Definition
Errors.h:29
GameObject.h
CorpseMapType
GridRefManager< Corpse > CorpseMapType
Definition
GridDefines.h:50
DynamicObjectMapType
GridRefManager< DynamicObject > DynamicObjectMapType
Definition
GridDefines.h:52
MAX_NUMBER_OF_CELLS
#define MAX_NUMBER_OF_CELLS
Definition
GridDefines.h:22
CreatureMapType
GridRefManager< Creature > CreatureMapType
Definition
GridDefines.h:51
AreaTriggerMapType
GridRefManager< AreaTrigger > AreaTriggerMapType
Definition
GridDefines.h:55
CellCoord
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition
GridDefines.h:158
GameObjectMapType
GridRefManager< GameObject > GameObjectMapType
Definition
GridDefines.h:53
SF_LOG_DEBUG
#define SF_LOG_DEBUG(filterType__,...)
Definition
Log.h:134
ObjectAccessor.h
sObjectAccessor
#define sObjectAccessor
Definition
ObjectAccessor.h:195
LoadHelper
void LoadHelper(CellGuidSet const &guid_set, CellCoord &cell, GridRefManager< T > &m, uint32 &count, Map *map)
Definition
ObjectGridLoader.cpp:104
AddObjectHelper
void AddObjectHelper(CellCoord &cell, GridRefManager< T > &m, uint32 &count, Map *, T *obj)
Definition
ObjectGridLoader.cpp:83
ObjectGridLoader.h
ObjectMgr.h
CellGuidSet
std::set< uint32 > CellGuidSet
Definition
ObjectMgr.h:413
CellCorpseSet
std::map< uint32, uint32 > CellCorpseSet
Definition
ObjectMgr.h:414
sObjectMgr
#define sObjectMgr
Definition
ObjectMgr.h:1617
Vehicle.h
World.h
Corpse
Definition
Corpse.h:37
Corpse::AddToWorld
void AddToWorld()
Definition
Corpse.cpp:26
Creature
Definition
Creature.h:427
Creature::AddToWorld
void AddToWorld() OVERRIDE
Definition
Creature.cpp:177
GameObject
Definition
GameObject.h:629
GridObject::IsInGrid
bool IsInGrid() const
Definition
Object.h:556
GridObject::AddToGrid
void AddToGrid(GridRefManager< T > &m)
Definition
Object.h:557
GridRefManager
Definition
GridRefManager.h:16
GridRefManager< Creature >::iterator
LinkedListHead::Iterator< GridReference< Creature > > iterator
Definition
GridRefManager.h:18
GridRefManager::end
iterator end()
Definition
GridRefManager.h:24
GridRefManager::getFirst
GridReference< OBJECT > * getFirst()
Definition
GridRefManager.h:20
GridRefManager::begin
iterator begin()
Definition
GridRefManager.h:23
LinkedListHead::isEmpty
bool isEmpty() const
Definition
LinkedList.h:86
Map
Definition
Map.h:238
Map::GameObjectRespawnRelocation
bool GameObjectRespawnRelocation(GameObject *go, bool diffGridOnly)
Definition
Map.cpp:1260
Map::AddToActive
void AddToActive(T *obj)
Definition
Map.cpp:2569
Map::GetInstanceId
uint32 GetInstanceId() const
Definition
Map.h:357
Map::CreatureRespawnRelocation
bool CreatureRespawnRelocation(Creature *c, bool diffGridOnly)
Definition
Map.cpp:1230
MapObject::SetCurrentCell
void SetCurrentCell(Cell const &cell)
Definition
Object.h:598
ObjectGridCleaner::Visit
void Visit(GridRefManager< T > &)
Definition
ObjectGridLoader.cpp:239
ObjectGridEvacuator::Visit
void Visit(CreatureMapType &m)
Definition
ObjectGridLoader.cpp:19
ObjectGridLoader
Definition
ObjectGridLoader.h:18
ObjectGridLoader::i_cell
Cell i_cell
Definition
ObjectGridLoader.h:37
ObjectGridLoader::i_creatures
uint32 i_creatures
Definition
ObjectGridLoader.h:41
ObjectGridLoader::i_map
Map * i_map
Definition
ObjectGridLoader.h:39
ObjectGridLoader::i_corpses
uint32 i_corpses
Definition
ObjectGridLoader.h:42
ObjectGridLoader::SetObjectCell
static void SetObjectCell(T *obj, CellCoord const &cellCoord)
Definition
ObjectGridLoader.cpp:68
ObjectGridLoader::i_gameObjects
uint32 i_gameObjects
Definition
ObjectGridLoader.h:40
ObjectGridLoader::Visit
void Visit(GameObjectMapType &m)
Definition
ObjectGridLoader.cpp:153
ObjectGridLoader::LoadN
void LoadN(void)
Definition
ObjectGridLoader.cpp:175
ObjectGridLoader::ObjectWorldLoader
friend class ObjectWorldLoader
Definition
ObjectGridLoader.h:19
ObjectGridLoader::i_grid
NGridType & i_grid
Definition
ObjectGridLoader.h:38
ObjectGridStoper::Visit
void Visit(CreatureMapType &m)
Definition
ObjectGridLoader.cpp:223
ObjectGridUnloader::Visit
void Visit(GridRefManager< T > &m)
Definition
ObjectGridLoader.cpp:205
ObjectWorldLoader::i_corpses
uint32 i_corpses
Definition
ObjectGridLoader.cpp:65
ObjectWorldLoader::ObjectWorldLoader
ObjectWorldLoader(ObjectGridLoader &gloader)
Definition
ObjectGridLoader.cpp:53
ObjectWorldLoader::Visit
void Visit(CorpseMapType &m)
Definition
ObjectGridLoader.cpp:167
ObjectWorldLoader::Visit
void Visit(GridRefManager< T > &)
Definition
ObjectGridLoader.cpp:59
ObjectWorldLoader::i_cell
Cell i_cell
Definition
ObjectGridLoader.cpp:62
ObjectWorldLoader::i_map
Map * i_map
Definition
ObjectGridLoader.cpp:63
TypeContainerVisitor
Definition
TypeContainerVisitor.h:80
Unit::IsPet
bool IsPet() const
Definition
Unit.h:1511
WorldObject::GetMap
Map * GetMap() const
Definition
Object.h:740
WorldObject::isActiveObject
bool isActiveObject() const
Definition
Object.h:776
WorldObject::SetMap
virtual void SetMap(Map *map)
Definition
Object.cpp:2514
sWorld
#define sWorld
Definition
World.h:910
WorldBoolConfigs::CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY
@ CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY
Definition
World.h:111
Cell
Definition
Cell.h:37
CellObjectGuids
Definition
ObjectMgr.h:416
CellObjectGuids::gameobjects
CellGuidSet gameobjects
Definition
ObjectMgr.h:418
CellObjectGuids::creatures
CellGuidSet creatures
Definition
ObjectMgr.h:417
CellObjectGuids::corpses
CellCorpseSet corpses
Definition
ObjectMgr.h:419
CoordPair::GetId
uint32 GetId() const
Definition
GridDefines.h:136
src
server
game
Grids
ObjectGridLoader.cpp
Generated on
for Project SkyFire Core by
1.17.0