TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Cell Struct Reference

#include <Cell.h>

Public Member Functions

 Cell ()
 
 Cell (Cell const &cell)
 
 Cell (CellCoord const &p)
 
 Cell (float x, float y)
 
void Compute (uint32 &x, uint32 &y) const
 
bool DiffCell (const Cell &cell) const
 
bool DiffGrid (const Cell &cell) const
 
uint32 CellX () const
 
uint32 CellY () const
 
uint32 GridX () const
 
uint32 GridY () const
 
bool NoCreate () const
 
void SetNoCreate ()
 
CellCoord GetCellCoord () const
 
Celloperator= (Cell const &cell)
 
bool operator== (Cell const &cell) const
 
bool operator!= (Cell const &cell) const
 
template<class T , class CONTAINER >
void Visit (CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
 
template<class T , class CONTAINER >
void Visit (CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, float, float, float) const
 

Static Public Member Functions

static CellArea CalculateCellArea (float x, float y, float radius)
 

Public Attributes

union {
   struct {
      unsigned   grid_x: 6
 
      unsigned   grid_y: 6
 
      unsigned   cell_x: 6
 
      unsigned   cell_y: 6
 
      unsigned   nocreate: 1
 
      unsigned   reserved: 7
 
   }   Part
 
   uint32   All
 
data
 
float v9 [16 *8+1][16 *8+1]
 
float v8 [16 *8][16 *8]
 

Private Member Functions

template<class T , class CONTAINER >
void VisitCircle (TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
 

Constructor & Destructor Documentation

Cell::Cell ( )
inline
51 { data.All = 0; }
union Cell::@307 data
Cell::Cell ( Cell const cell)
inline
52 { data.All = cell.data.All; }
union Cell::@307 data
Cell::Cell ( CellCoord const p)
inlineexplicit
29 {
30  data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
31  data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
32  data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
33  data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
34  data.Part.nocreate = 0;
35  data.Part.reserved = 0;
36 }
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
union Cell::@307 data
Cell::Cell ( float  x,
float  y 
)
inlineexplicit
39 {
41  data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
42  data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
43  data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
44  data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
45  data.Part.nocreate = 0;
46  data.Part.reserved = 0;
47 }
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
union Cell::@307 data
uint32 y_coord
Definition: GridDefines.h:156
uint32 x_coord
Definition: GridDefines.h:155
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

Member Function Documentation

CellArea Cell::CalculateCellArea ( float  x,
float  y,
float  radius 
)
inlinestatic
50 {
51  if (radius <= 0.0f)
52  {
54  return CellArea(center, center);
55  }
56 
57  CellCoord centerX = Trinity::ComputeCellCoord(x - radius, y - radius).normalize();
58  CellCoord centerY = Trinity::ComputeCellCoord(x + radius, y + radius).normalize();
59 
60  return CellArea(centerX, centerY);
61 }
CoordPair & normalize()
Definition: GridDefines.h:143
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
Definition: Cell.h:32
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 Cell::CellX ( ) const
inline
74 { return data.Part.cell_x; }
union Cell::@307 data

+ Here is the caller graph for this function:

uint32 Cell::CellY ( ) const
inline
75 { return data.Part.cell_y; }
union Cell::@307 data

+ Here is the caller graph for this function:

void Cell::Compute ( uint32 x,
uint32 y 
) const
inline
57  {
58  x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
59  y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
60  }
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
union Cell::@307 data
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
bool Cell::DiffCell ( const Cell cell) const
inline
63  {
64  return(data.Part.cell_x != cell.data.Part.cell_x ||
65  data.Part.cell_y != cell.data.Part.cell_y);
66  }
struct Cell::@307::@308 Part
union Cell::@307 data

+ Here is the caller graph for this function:

bool Cell::DiffGrid ( const Cell cell) const
inline
69  {
70  return(data.Part.grid_x != cell.data.Part.grid_x ||
71  data.Part.grid_y != cell.data.Part.grid_y);
72  }
struct Cell::@307::@308 Part
union Cell::@307 data

+ Here is the caller graph for this function:

CellCoord Cell::GetCellCoord ( ) const
inline
82  {
83  return CellCoord(
84  data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
85  data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
86  }
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
union Cell::@307 data
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:172

+ Here is the caller graph for this function:

uint32 Cell::GridX ( ) const
inline
76 { return data.Part.grid_x; }
union Cell::@307 data

+ Here is the caller graph for this function:

uint32 Cell::GridY ( ) const
inline
77 { return data.Part.grid_y; }
union Cell::@307 data

+ Here is the caller graph for this function:

bool Cell::NoCreate ( ) const
inline
78 { return data.Part.nocreate; }
union Cell::@307 data

+ Here is the caller graph for this function:

bool Cell::operator!= ( Cell const cell) const
inline
95 { return !operator == (cell); }
bool operator==(Cell const &cell) const
Definition: Cell.h:94

+ Here is the call graph for this function:

Cell& Cell::operator= ( Cell const cell)
inline
89  {
90  this->data.All = cell.data.All;
91  return *this;
92  }
union Cell::@307 data
bool Cell::operator== ( Cell const cell) const
inline
94 { return (data.All == cell.data.All); }
union Cell::@307 data

+ Here is the caller graph for this function:

void Cell::SetNoCreate ( )
inline
79 { data.Part.nocreate = 1; }
union Cell::@307 data

+ Here is the caller graph for this function:

template<class T , class CONTAINER >
void Cell::Visit ( CellCoord const standing_cell,
TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
WorldObject const obj,
float  radius 
) const
inline
123 {
124  //we should increase search radius by object's radius, otherwise
125  //we could have problems with huge creatures, which won't attack nearest players etc
126  Visit(standing_cell, visitor, map, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY());
127 }
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition: CellImpl.h:122

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class CONTAINER >
void Cell::Visit ( CellCoord const standing_cell,
TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
float  radius,
float  x_off,
float  y_off 
) const
inline
65 {
66  if (!standing_cell.IsCoordValid())
67  return;
68 
69  //no jokes here... Actually placing ASSERT() here was good idea, but
70  //we had some problems with DynamicObjects, which pass radius = 0.0f (DB issue?)
71  //maybe it is better to just return when radius <= 0.0f?
72  if (radius <= 0.0f)
73  {
74  map.Visit(*this, visitor);
75  return;
76  }
77  //lets limit the upper value for search radius
78  if (radius > SIZE_OF_GRIDS)
79  radius = SIZE_OF_GRIDS;
80 
81  //lets calculate object coord offsets from cell borders.
82  CellArea area = Cell::CalculateCellArea(x_off, y_off, radius);
83  //if radius fits inside standing cell
84  if (!area)
85  {
86  map.Visit(*this, visitor);
87  return;
88  }
89 
90  //visit all cells, found in CalculateCellArea()
91  //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle
92  //currently this technique works with MAX_NUMBER_OF_CELLS 16 and higher, with lower values
93  //there are nothing to optimize because SIZE_OF_GRID_CELL is too big...
94  if ((area.high_bound.x_coord > (area.low_bound.x_coord + 4)) && (area.high_bound.y_coord > (area.low_bound.y_coord + 4)))
95  {
96  VisitCircle(visitor, map, area.low_bound, area.high_bound);
97  return;
98  }
99 
100  //ALWAYS visit standing cell first!!! Since we deal with small radiuses
101  //it is very essential to call visitor for standing cell firstly...
102  map.Visit(*this, visitor);
103 
104  // loop the cell range
105  for (uint32 x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x)
106  {
107  for (uint32 y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y)
108  {
109  CellCoord cellCoord(x, y);
110  //lets skip standing cell since we already visited it
111  if (cellCoord != standing_cell)
112  {
113  Cell r_zone(cellCoord);
114  r_zone.data.Part.nocreate = this->data.Part.nocreate;
115  map.Visit(r_zone, visitor);
116  }
117  }
118  }
119 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
union Cell::@307 data
uint32 y_coord
Definition: GridDefines.h:156
static CellArea CalculateCellArea(float x, float y, float radius)
Definition: CellImpl.h:49
uint32 x_coord
Definition: GridDefines.h:155
Definition: Cell.h:32
CellCoord low_bound
Definition: Cell.h:45
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition: CellImpl.h:130
Definition: Cell.h:49
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
Definition: Map.h:811
CellCoord high_bound
Definition: Cell.h:46
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

template<class T , class CONTAINER >
void Cell::VisitCircle ( TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
CellCoord const begin_cell,
CellCoord const end_cell 
) const
inlineprivate
131 {
132  //here is an algorithm for 'filling' circum-squared octagon
133  uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
134  //lets calculate x_start/x_end coords for central strip...
135  const uint32 x_start = begin_cell.x_coord + x_shift;
136  const uint32 x_end = end_cell.x_coord - x_shift;
137 
138  //visit central strip with constant width...
139  for (uint32 x = x_start; x <= x_end; ++x)
140  {
141  for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
142  {
143  CellCoord cellCoord(x, y);
144  Cell r_zone(cellCoord);
145  r_zone.data.Part.nocreate = this->data.Part.nocreate;
146  map.Visit(r_zone, visitor);
147  }
148  }
149 
150  //if x_shift == 0 then we have too small cell area, which were already
151  //visited at previous step, so just return from procedure...
152  if (x_shift == 0)
153  return;
154 
155  uint32 y_start = end_cell.y_coord;
156  uint32 y_end = begin_cell.y_coord;
157  //now we are visiting borders of an octagon...
158  for (uint32 step = 1; step <= (x_start - begin_cell.x_coord); ++step)
159  {
160  //each step reduces strip height by 2 cells...
161  y_end += 1;
162  y_start -= 1;
163  for (uint32 y = y_start; y >= y_end; --y)
164  {
165  //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom
166  //e.g. filling 2 trapezoids after filling central cell strip...
167  CellCoord cellCoord_left(x_start - step, y);
168  Cell r_zone_left(cellCoord_left);
169  r_zone_left.data.Part.nocreate = this->data.Part.nocreate;
170  map.Visit(r_zone_left, visitor);
171 
172  //right trapezoid cell visit
173  CellCoord cellCoord_right(x_end + step, y);
174  Cell r_zone_right(cellCoord_right);
175  r_zone_right.data.Part.nocreate = this->data.Part.nocreate;
176  map.Visit(r_zone_right, visitor);
177  }
178  }
179 }
union Cell::@307 data
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: Cell.h:49
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
Definition: Map.h:811
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

uint32 Cell::All
unsigned Cell::cell_x
unsigned Cell::cell_y
union { ... } Cell::data
unsigned Cell::grid_x
unsigned Cell::grid_y
unsigned Cell::nocreate
struct { ... } Cell::Part
unsigned Cell::reserved
float Cell::v8[16 *8][16 *8]
float Cell::v9[16 *8+1][16 *8+1]

The documentation for this struct was generated from the following files: