gwnavruntime/navmesh/worldintegerpos.h Source File

worldintegerpos.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef Navigation_WorldIntegerPos_H
10 #define Navigation_WorldIntegerPos_H
11 
12 
14 
15 
16 namespace Kaim
17 {
18 
19 
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 
25 public:
27  WorldIntegerPos(const CellPos& cellPos, const CoordPos& posInCell);
28 
29  // ---------------------------------- Public Member Functions ----------------------------------
30 
31  void Set(const CellPos& cellPos, const CoordPos& posInCell);
32  void Set(CellCoord cellCoordX, CellCoord cellCoordY, KyInt32 coordPosX, KyInt32 coordPosY);
33 
34  void Clear();
35 
36  bool operator==(const WorldIntegerPos& rhs) const;
37  bool operator!=(const WorldIntegerPos& rhs) const;
38  bool operator<(const WorldIntegerPos& rhs) const;
39  bool operator>(const WorldIntegerPos& rhs) const;
40 
41 public: //internal
42  void Add1OnCoordPosX(KyInt32 cellSizeInCoord);
43  void Remove1OnCoordPosX(KyInt32 cellSizeInCoord);
44  void Add1OnCoordPosY(KyInt32 cellSizeInCoord);
45  void Remove1OnCoordPosY(KyInt32 cellSizeInCoord);
46 
47 public:
48  CellPos m_cellPos;
49  CoordPos m_coordPosInCell;
50 };
51 
54 KY_INLINE void SwapEndianness(Kaim::Endianness::Target e, WorldIntegerPos& self)
55 {
56  SwapEndianness(e, self.m_cellPos);
57  SwapEndianness(e, self.m_coordPosInCell);
58 }
59 
60 
61 KY_INLINE WorldIntegerPos::WorldIntegerPos() : m_cellPos(InvalidCellCoord, InvalidCellCoord), m_coordPosInCell(InvalidCoord, InvalidCoord) {}
62 KY_INLINE WorldIntegerPos::WorldIntegerPos(const CellPos& cellPos, const CoordPos& posInCell) : m_cellPos(cellPos), m_coordPosInCell(posInCell) {}
63 
64 KY_INLINE void WorldIntegerPos::Clear()
65 {
67  m_coordPosInCell.Set(InvalidCoord, InvalidCoord);
68 }
69 
70 KY_INLINE void WorldIntegerPos::Set(const CellPos& cellPos, const CoordPos& posInCell) { m_cellPos = cellPos; m_coordPosInCell = posInCell; }
71 KY_INLINE void WorldIntegerPos::Set(CellCoord cellCoordX, CellCoord cellCoordY, KyInt32 coordPosX, KyInt32 coordPosY)
72 {
73  m_cellPos.Set(cellCoordX, cellCoordY);
74  m_coordPosInCell.Set(coordPosX, coordPosY);
75 }
76 
77 KY_INLINE bool WorldIntegerPos::operator==(const WorldIntegerPos& rhs) const { return m_cellPos == rhs.m_cellPos && m_coordPosInCell == rhs.m_coordPosInCell; }
78 KY_INLINE bool WorldIntegerPos::operator!=(const WorldIntegerPos& rhs) const { return !operator==(rhs);/*x != v.x || y != v.y;*/ }
79 KY_INLINE bool WorldIntegerPos::operator<(const WorldIntegerPos& rhs) const { return m_cellPos != rhs.m_cellPos ? m_cellPos < rhs.m_cellPos : m_coordPosInCell < rhs.m_coordPosInCell; }
80 KY_INLINE bool WorldIntegerPos::operator>(const WorldIntegerPos& rhs) const { return !operator<(rhs) && operator!=(rhs); }
81 
82 KY_INLINE void WorldIntegerPos::Add1OnCoordPosX(KyInt32 cellSizeInCoord)
83 {
84  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
85  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
86  if (m_coordPosInCell.x == cellSizeInCoord)
87  {
88  m_coordPosInCell.x = 1;
89  ++m_cellPos.x;
90  }
91  else
92  ++m_coordPosInCell.x;
93 }
94 
95 KY_INLINE void WorldIntegerPos::Remove1OnCoordPosX(KyInt32 cellSizeInCoord)
96 {
97  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
98  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
99  if (m_coordPosInCell.x == 1)
100  {
101  m_coordPosInCell.x = cellSizeInCoord;
102  --m_cellPos.x;
103  }
104  else
105  --m_coordPosInCell.x;
106 }
107 
108 KY_INLINE void WorldIntegerPos::Add1OnCoordPosY(KyInt32 cellSizeInCoord)
109 {
110  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
111  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
112  if (m_coordPosInCell.y + 1 == cellSizeInCoord)
113  {
114  m_coordPosInCell.y = 0;
115  ++m_cellPos.y;
116  }
117  else
118  ++m_coordPosInCell.y;
119 }
120 
121 KY_INLINE void WorldIntegerPos::Remove1OnCoordPosY(KyInt32 cellSizeInCoord)
122 {
123  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
124  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
125  if (m_coordPosInCell.y == 0)
126  {
127  m_coordPosInCell.y = cellSizeInCoord - 1;
128  --m_cellPos.y;
129  }
130  else
131  --m_coordPosInCell.y;
132 }
133 
134 } // namespace Kaim
135 
136 
137 
138 #endif
139 
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
static const KyInt32 InvalidCoord
Represents an invalidCoord object.
Definition: navmeshtypes.h:25
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
void Set(KyInt32 _x, KyInt32 _y)
Sets the coordinates of the vector to match the specified values.
Definition: vec2i.h:54
KyInt32 x
The size of the vector along the X axis.
Definition: vec2i.h:283
void Clear()
Clears all information maintained by this object.
Definition: worldintegerpos.h:74
static const KyInt32 InvalidCellCoord
Represents an invalidCellCoord object.
Definition: navmeshtypes.h:35
KyInt32 y
The size of the vector along the Y axis.
Definition: vec2i.h:284
Vec2i CoordPos
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:23
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
Utilities for dealing with NavData coordinates, which are expressed in a world space based on integer...
Definition: worldintegerpos.h:21
void Set(const CellPos &cellPos, const CoordPos &posInCell)
Sets the coordinates of the vector to match the specified values.
Definition: worldintegerpos.h:80
KyInt32 CellCoord
A type that represents the placement of a cell on one axis of a 2D grid.
Definition: navmeshtypes.h:32