TrinityCore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GridNotifiersImpl.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_GRIDNOTIFIERSIMPL_H
19#define TRINITY_GRIDNOTIFIERSIMPL_H
20
21#include "GridNotifiers.h"
22#include "Corpse.h"
23#include "CreatureAI.h"
24#include "Player.h"
25#include "SpellAuras.h"
26#include "UpdateData.h"
27#include "WorldPacket.h"
28#include "WorldSession.h"
29
30template<class T>
32{
33 for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
34 {
35 vis_guids.erase(iter->GetSource()->GetGUID());
37 }
38}
39
40// SEARCHERS & LIST SEARCHERS & WORKERS
41
42// WorldObject searchers & workers
43
44template <class Check, class Result>
45template <class T>
47{
48 if (!(i_mapTypeMask & GridMapTypeMaskForType<T>::value))
49 return;
50
51 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
52 return;
53
54 for (GridReference<T> const& ref : m)
55 {
56 if (i_check(ref.GetSource()))
57 {
58 this->Insert(ref.GetSource());
59
60 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
61 return;
62 }
63 }
64}
65
66// Gameobject searchers
67
68template <class Check, class Result>
70{
71 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
72 return;
73
74 for (GridReference<GameObject> const& ref : m)
75 {
76 if (!ref.GetSource()->InSamePhase(i_phaseMask))
77 continue;
78
79 if (i_check(ref.GetSource()))
80 {
81 this->Insert(ref.GetSource());
82
83 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
84 return;
85 }
86 }
87}
88
89// Unit searchers
90
91template <class Check, class Result>
92template <class T>
94{
95 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
96 return;
97
98 for (GridReference<T> const& ref : m)
99 {
100 if (!ref.GetSource()->InSamePhase(i_phaseMask))
101 continue;
102
103 if (i_check(ref.GetSource()))
104 {
105 this->Insert(ref.GetSource());
106
107 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
108 return;
109 }
110 }
111}
112
113// Creature searchers
114
115template <class Check, class Result>
117{
118 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
119 return;
120
121 for (GridReference<Creature> const& ref : m)
122 {
123 if (!ref.GetSource()->InSamePhase(i_phaseMask))
124 continue;
125
126 if (i_check(ref.GetSource()))
127 {
128 this->Insert(ref.GetSource());
129
130 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
131 return;
132 }
133 }
134}
135
136// Player searchers
137
138template <class Check, class Result>
140{
141 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
142 return;
143
144 for (GridReference<Player> const& ref : m)
145 {
146 if (!ref.GetSource()->InSamePhase(i_phaseMask))
147 continue;
148
149 if (i_check(ref.GetSource()))
150 {
151 this->Insert(ref.GetSource());
152
153 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
154 return;
155 }
156 }
157}
158
159template<class Builder>
161{
163 uint32 cache_idx = loc_idx+1;
164 WorldPacket* data;
165
166 // create if not cached yet
167 if (i_data_cache.size() < cache_idx + 1 || !i_data_cache[cache_idx])
168 {
169 if (i_data_cache.size() < cache_idx + 1)
170 i_data_cache.resize(cache_idx + 1);
171
172 data = new WorldPacket();
173
174 i_builder(*data, loc_idx);
175
176 i_data_cache[cache_idx] = data;
177 }
178 else
179 data = i_data_cache[cache_idx];
180
181 p->SendDirectMessage(data);
182}
183
184template<class Builder>
186{
188 uint32 cache_idx = loc_idx+1;
189 WorldPacketList* data_list;
190
191 // create if not cached yet
192 if (i_data_cache.size() < cache_idx+1 || i_data_cache[cache_idx].empty())
193 {
194 if (i_data_cache.size() < cache_idx+1)
195 i_data_cache.resize(cache_idx+1);
196
197 data_list = &i_data_cache[cache_idx];
198
199 i_builder(*data_list, loc_idx);
200 }
201 else
202 data_list = &i_data_cache[cache_idx];
203
204 for (size_t i = 0; i < data_list->size(); ++i)
205 p->SendDirectMessage((*data_list)[i]);
206}
207
208#endif // TRINITY_GRIDNOTIFIERSIMPL_H
LocaleConstant
Definition: Common.h:48
uint32_t uint32
Definition: Define.h:133
void resize(size_t newsize)
Definition: ByteBuffer.h:412
iterator end()
iterator begin()
Definition: Player.h:915
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:6242
void UpdateVisibilityOf(WorldObject *target)
Definition: Player.cpp:22326
WorldSession * GetSession() const
Definition: Player.h:1712
std::vector< WorldPacket * > WorldPacketList
LocaleConstant GetSessionDbLocaleIndex() const
Definition: WorldSession.h:644
bool Insert(ContainerUnorderedMap< TypeList< H, T >, KEY_TYPE > &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *obj)
void Visit(CreatureMapType &m)
void Visit(GameObjectMapType &m)
void Visit(PlayerMapType &m)
void VisitImpl(GridRefManager< T > &m)
GuidUnorderedSet vis_guids
Definition: GridNotifiers.h:49
void Visit(GridRefManager< T > &m)
std::set< Unit * > i_visibleNow
Definition: GridNotifiers.h:48
void Visit(GridRefManager< T > &)