Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Cell.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_CELL_H
7#define SKYFIRE_CELL_H
8
9#include <cmath>
10
11#include "TypeContainer.h"
13
14#include "GridDefines.h"
15
16class Map;
17class WorldObject;
18
20{
22 CellArea(CellCoord low, CellCoord high) : low_bound(low), high_bound(high) { }
23
24 bool operator!() const { return low_bound == high_bound; }
25
26 void ResizeBorders(CellCoord& begin_cell, CellCoord& end_cell) const
27 {
28 begin_cell = low_bound;
29 end_cell = high_bound;
30 }
31
34};
35
36struct Cell
37{
38 Cell() { data.All = 0; }
39 Cell(Cell const& cell) { data.All = cell.data.All; }
40 explicit Cell(CellCoord const& p);
41 explicit Cell(float x, float y);
42
43 void Compute(uint32& x, uint32& y) const
44 {
45 x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
46 y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
47 }
48
49 bool DiffCell(const Cell& cell) const
50 {
51 return (data.Part.cell_x != cell.data.Part.cell_x ||
52 data.Part.cell_y != cell.data.Part.cell_y);
53 }
54
55 bool DiffGrid(const Cell& cell) const
56 {
57 return (data.Part.grid_x != cell.data.Part.grid_x ||
58 data.Part.grid_y != cell.data.Part.grid_y);
59 }
60
61 uint32 CellX() const { return data.Part.cell_x; }
62 uint32 CellY() const { return data.Part.cell_y; }
63 uint32 GridX() const { return data.Part.grid_x; }
64 uint32 GridY() const { return data.Part.grid_y; }
65 bool NoCreate() const { return data.Part.nocreate; }
66 void SetNoCreate() { data.Part.nocreate = 1; }
67
69 {
70 return CellCoord(
71 data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x,
72 data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y);
73 }
74
75 Cell& operator=(Cell const& cell)
76 {
77 this->data.All = cell.data.All;
78 return *this;
79 }
80
81 bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
82 bool operator != (Cell const& cell) const { return !operator == (cell); }
83 union
84 {
85 struct
86 {
87 unsigned grid_x : 6;
88 unsigned grid_y : 6;
89 unsigned cell_x : 6;
90 unsigned cell_y : 6;
91 unsigned nocreate : 1;
92 unsigned reserved : 7;
96
97 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, WorldObject const&, float) const;
98 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, float, float, float) const;
99
100 static CellArea CalculateCellArea(float x, float y, float radius);
101
102private:
103 template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER>&, Map&, CellCoord const&, CellCoord const&) const;
104};
105
106#endif
std::uint32_t uint32
Definition Define.h:77
#define MAX_NUMBER_OF_CELLS
Definition GridDefines.h:22
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition Map.h:238
CellCoord high_bound
Definition Cell.h:33
CellCoord low_bound
Definition Cell.h:32
bool operator!() const
Definition Cell.h:24
CellArea(CellCoord low, CellCoord high)
Definition Cell.h:22
CellArea()
Definition Cell.h:21
void ResizeBorders(CellCoord &begin_cell, CellCoord &end_cell) const
Definition Cell.h:26
Cell(Cell const &cell)
Definition Cell.h:39
CellCoord GetCellCoord() const
Definition Cell.h:68
uint32 GridX() const
Definition Cell.h:63
unsigned nocreate
Definition Cell.h:91
void SetNoCreate()
Definition Cell.h:66
Cell()
Definition Cell.h:38
unsigned grid_y
Definition Cell.h:88
unsigned reserved
Definition Cell.h:92
struct Cell::@253100141177133252213152253303204033205331220256::@054333305236276154171230343071320200077322155341 Part
bool NoCreate() const
Definition Cell.h:65
void Compute(uint32 &x, uint32 &y) const
Definition Cell.h:43
Cell & operator=(Cell const &cell)
Definition Cell.h:75
uint32 GridY() const
Definition Cell.h:64
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition CellImpl.h:109
unsigned cell_y
Definition Cell.h:90
bool operator==(Cell const &cell) const
Definition Cell.h:81
unsigned cell_x
Definition Cell.h:89
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition CellImpl.h:117
bool operator!=(Cell const &cell) const
Definition Cell.h:82
bool DiffGrid(const Cell &cell) const
Definition Cell.h:55
unsigned grid_x
Definition Cell.h:87
uint32 CellX() const
Definition Cell.h:61
uint32 CellY() const
Definition Cell.h:62
bool DiffCell(const Cell &cell) const
Definition Cell.h:49
union Cell::@253100141177133252213152253303204033205331220256 data
static CellArea CalculateCellArea(float x, float y, float radius)
Definition CellImpl.h:36
uint32 All
Definition Cell.h:94