gwnavruntime/navmesh/worldintegerpos.h Source File

worldintegerpos.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
9 
10 
12 
13 
14 namespace Kaim
15 {
16 
17 
20 {
21  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
22 
23 public:
25  WorldIntegerPos(const CellPos& cellPos, const CoordPos& posInCell);
26 
27  // ------------------------------ Functions -----------------------------
28 
29  void Set(const CellPos& cellPos, const CoordPos& posInCell);
30  void Set(CellCoord cellCoordX, CellCoord cellCoordY, KyInt32 coordPosX, KyInt32 coordPosY);
31 
32  void Clear();
33 
34  bool operator==(const WorldIntegerPos& rhs) const;
35  bool operator!=(const WorldIntegerPos& rhs) const;
36  bool operator<(const WorldIntegerPos& rhs) const;
37  bool operator>(const WorldIntegerPos& rhs) const;
38 
39 public: //internal
40  void Add1OnCoordPosX(KyInt32 cellSizeInCoord);
41  void Remove1OnCoordPosX(KyInt32 cellSizeInCoord);
42  void Add1OnCoordPosY(KyInt32 cellSizeInCoord);
43  void Remove1OnCoordPosY(KyInt32 cellSizeInCoord);
44 
45 public:
46  CellPos m_cellPos;
47  CoordPos m_coordPosInCell;
48 };
49 
50 KY_INLINE void SwapEndianness(Kaim::Endianness::Target e, WorldIntegerPos& self)
51 {
52  SwapEndianness(e, self.m_cellPos);
53  SwapEndianness(e, self.m_coordPosInCell);
54 }
55 
56 
57 KY_INLINE WorldIntegerPos::WorldIntegerPos() : m_cellPos(InvalidCellCoord, InvalidCellCoord), m_coordPosInCell(InvalidCoord, InvalidCoord) {}
58 KY_INLINE WorldIntegerPos::WorldIntegerPos(const CellPos& cellPos, const CoordPos& posInCell) : m_cellPos(cellPos), m_coordPosInCell(posInCell) {}
59 
60 KY_INLINE void WorldIntegerPos::Clear()
61 {
63  m_coordPosInCell.Set(InvalidCoord, InvalidCoord);
64 }
65 
66 KY_INLINE void WorldIntegerPos::Set(const CellPos& cellPos, const CoordPos& posInCell) { m_cellPos = cellPos; m_coordPosInCell = posInCell; }
67 KY_INLINE void WorldIntegerPos::Set(CellCoord cellCoordX, CellCoord cellCoordY, KyInt32 coordPosX, KyInt32 coordPosY)
68 {
69  m_cellPos.Set(cellCoordX, cellCoordY);
70  m_coordPosInCell.Set(coordPosX, coordPosY);
71 }
72 
73 KY_INLINE bool WorldIntegerPos::operator==(const WorldIntegerPos& rhs) const { return m_cellPos == rhs.m_cellPos && m_coordPosInCell == rhs.m_coordPosInCell; }
74 KY_INLINE bool WorldIntegerPos::operator!=(const WorldIntegerPos& rhs) const { return !operator==(rhs);/*x != v.x || y != v.y;*/ }
75 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; }
76 KY_INLINE bool WorldIntegerPos::operator>(const WorldIntegerPos& rhs) const { return !operator<(rhs) && operator!=(rhs); }
77 
78 KY_INLINE void WorldIntegerPos::Add1OnCoordPosX(KyInt32 cellSizeInCoord)
79 {
80  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
81  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
82  if (m_coordPosInCell.x == cellSizeInCoord)
83  {
84  m_coordPosInCell.x = 1;
85  ++m_cellPos.x;
86  }
87  else
88  ++m_coordPosInCell.x;
89 }
90 
91 KY_INLINE void WorldIntegerPos::Remove1OnCoordPosX(KyInt32 cellSizeInCoord)
92 {
93  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
94  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
95  if (m_coordPosInCell.x == 1)
96  {
97  m_coordPosInCell.x = cellSizeInCoord;
98  --m_cellPos.x;
99  }
100  else
101  --m_coordPosInCell.x;
102 }
103 
104 KY_INLINE void WorldIntegerPos::Add1OnCoordPosY(KyInt32 cellSizeInCoord)
105 {
106  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
107  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
108  if (m_coordPosInCell.y + 1 == cellSizeInCoord)
109  {
110  m_coordPosInCell.y = 0;
111  ++m_cellPos.y;
112  }
113  else
114  ++m_coordPosInCell.y;
115 }
116 
117 KY_INLINE void WorldIntegerPos::Remove1OnCoordPosY(KyInt32 cellSizeInCoord)
118 {
119  KY_DEBUG_ASSERTN(m_coordPosInCell.x > 0 || m_coordPosInCell.x <= cellSizeInCoord, ("Invalid Object"));
120  KY_DEBUG_ASSERTN(m_coordPosInCell.y >= 0 || m_coordPosInCell.y < cellSizeInCoord, ("Invalid Object"));
121  if (m_coordPosInCell.y == 0)
122  {
123  m_coordPosInCell.y = cellSizeInCoord - 1;
124  --m_cellPos.y;
125  }
126  else
127  --m_coordPosInCell.y;
128 }
129 
130 } // namespace Kaim
131 
132 
133 
134 
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
static const KyInt32 InvalidCoord
Represents an invalidCoord object.
Definition: navmeshtypes.h:22
void Set(KyInt32 _x, KyInt32 _y)
Sets x=_x and y=_y.
Definition: vec2i.h:29
void Clear()
Clears all information maintained by this object.
Definition: worldintegerpos.h:60
static const KyInt32 InvalidCellCoord
Represents an invalidCellCoord object.
Definition: navmeshtypes.h:32
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Vec2i CoordPos
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:20
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
Utilities for dealing with NavData coordinates, which are expressed in a world space based on integer...
Definition: worldintegerpos.h:19
void Set(const CellPos &cellPos, const CoordPos &posInCell)
Sets the coordinates of the vector to match the specified values.
Definition: worldintegerpos.h:66
KyInt32 CellCoord
A type that represents the placement of a cell on one axis of a 2D grid.
Definition: navmeshtypes.h:29