TrinityCore
Cell.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_CELL_H
19#define TRINITY_CELL_H
20
21#include "TypeContainer.h"
23
24#include "GridDefines.h"
25
26class Map;
27class WorldObject;
28
30{
32 CellArea(CellCoord low, CellCoord high) : low_bound(low), high_bound(high) { }
33
34 bool operator!() const { return low_bound == high_bound; }
35
36 void ResizeBorders(CellCoord& begin_cell, CellCoord& end_cell) const
37 {
38 begin_cell = low_bound;
39 end_cell = high_bound;
40 }
41
44};
45
46struct Cell
47{
48 Cell() { data.All = 0; }
49 Cell(Cell const& cell) { data.All = cell.data.All; }
50 explicit Cell(CellCoord const& p);
51 explicit Cell(float x, float y);
52
53 void Compute(uint32 &x, uint32 &y) const
54 {
55 x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
56 y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
57 }
58
59 bool DiffCell(Cell const& cell) const
60 {
61 return(data.Part.cell_x != cell.data.Part.cell_x ||
62 data.Part.cell_y != cell.data.Part.cell_y);
63 }
64
65 bool DiffGrid(Cell const& cell) const
66 {
67 return(data.Part.grid_x != cell.data.Part.grid_x ||
68 data.Part.grid_y != cell.data.Part.grid_y);
69 }
70
71 uint32 CellX() const { return data.Part.cell_x; }
72 uint32 CellY() const { return data.Part.cell_y; }
73 uint32 GridX() const { return data.Part.grid_x; }
74 uint32 GridY() const { return data.Part.grid_y; }
75 bool NoCreate() const { return data.Part.nocreate; }
76 void SetNoCreate() { data.Part.nocreate = 1; }
77
79 {
80 return CellCoord(
81 data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
82 data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
83 }
84
85 Cell& operator=(Cell const& cell)
86 {
87 this->data.All = cell.data.All;
88 return *this;
89 }
90
91 bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
92 union
93 {
94 struct
95 {
96 unsigned grid_x : 6;
97 unsigned grid_y : 6;
98 unsigned cell_x : 6;
99 unsigned cell_y : 6;
100 unsigned nocreate : 1;
101 unsigned reserved : 7;
105
106 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, WorldObject const& obj, float radius) const;
107 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, float x, float y, float radius) const;
108
109 static CellArea CalculateCellArea(float x, float y, float radius);
110
111 template<class T> static void VisitGridObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
112 template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
113 template<class T> static void VisitAllObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
114
115 template<class T> static void VisitGridObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
116 template<class T> static void VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
117 template<class T> static void VisitAllObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
118
119private:
120 template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
121};
122
123#endif
uint32_t uint32
Definition: Define.h:142
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:36
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:178
Definition: Map.h:189
Definition: Cell.h:30
CellCoord high_bound
Definition: Cell.h:43
CellCoord low_bound
Definition: Cell.h:42
bool operator!() const
Definition: Cell.h:34
CellArea(CellCoord low, CellCoord high)
Definition: Cell.h:32
CellArea()
Definition: Cell.h:31
void ResizeBorders(CellCoord &begin_cell, CellCoord &end_cell) const
Definition: Cell.h:36
Definition: Cell.h:47
Cell(Cell const &cell)
Definition: Cell.h:49
CellCoord GetCellCoord() const
Definition: Cell.h:78
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:203
uint32 GridX() const
Definition: Cell.h:73
unsigned nocreate
Definition: Cell.h:100
void SetNoCreate()
Definition: Cell.h:76
Cell()
Definition: Cell.h:48
unsigned grid_y
Definition: Cell.h:97
unsigned reserved
Definition: Cell.h:101
bool NoCreate() const
Definition: Cell.h:75
union Cell::@313 data
void Compute(uint32 &x, uint32 &y) const
Definition: Cell.h:53
Cell & operator=(Cell const &cell)
Definition: Cell.h:85
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:179
uint32 GridY() const
Definition: Cell.h:74
bool DiffGrid(Cell const &cell) const
Definition: Cell.h:65
bool DiffCell(Cell const &cell) const
Definition: Cell.h:59
unsigned cell_y
Definition: Cell.h:99
bool operator==(Cell const &cell) const
Definition: Cell.h:91
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:191
unsigned cell_x
Definition: Cell.h:98
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition: CellImpl.h:127
unsigned grid_x
Definition: Cell.h:96
uint32 CellX() const
Definition: Cell.h:71
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition: CellImpl.h:61
uint32 CellY() const
Definition: Cell.h:72
static CellArea CalculateCellArea(float x, float y, float radius)
Definition: CellImpl.h:46
uint32 All
Definition: Cell.h:103
struct Cell::@313::@314 Part