gwnavruntime/database/navfloorstitcher.h Source File

navfloorstitcher.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 // ---------- Primary contact: JUBA - secondary contact: NOBODY
8 #ifndef Navigation_NavCellStitcher_H
9 #define Navigation_NavCellStitcher_H
10 
14 
15 
16 namespace Kaim
17 {
18 
19 class NavCell;
20 class NavCellGrid;
21 class NavCellPosInfo;
22 class NavFloor;
23 class Database;
24 class NavHalfEdgeRawPtr;
25 class Stitch1To1EdgeLink;
26 class NavFloorBlob;
27 class NavHalfEdge;
28 
29 class EdgeVertices
30 {
31  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
32 public:
33  Vec2i m_startVertex;
34  Vec2i m_endVertex;
35  KyFloat32 m_startAltitude;
36  KyFloat32 m_endAltitude;
37 };
38 
39 class NavFloorStitcherData
40 {
41 public:
42  NavFloorStitcherData();
43 
44  void Init(NavCell& navCell, NavFloorIdx floorIdx, bool getFutureActiveFloorBlob = false);
45  void Init(const Stitch1To1EdgeLink& stitch1To1EdgeLink, bool getFutureActiveFloorBlob = false);
46 
47 public:
48  NavFloor* m_navFloor;
49  KyUInt32 m_stitch1To1EdgeCount;
50  const NavFloorBlob* m_navFloorBlob;
51  const NavHalfEdge* m_halfEdges;
52  const NavVertex* m_navVertexBuffer;
53  const KyFloat32* m_navVertexAltBuffer;
54  NavHalfEdgeRawPtr* m_links;
55  const KyUInt16* m_stitch1To1EdgeIdxToFirstIdxBuffer;
56  const KyUInt16* m_stitch1To1EdgeIdxToCountBuffer;
57  const CompactNavHalfEdgeIdx* m_navHalfEdgeIdxBuffer;
58  const Stitch1To1EdgeLink* m_stitch1To1EdgeLinkBuffer;
59 };
60 
61 class NavFloorStitcher
62 {
63  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
64 public:
65  NavFloorStitcher(Database* database) : m_altitudeTolerance(0.5f), m_database(database) {}
66 
67  // --- stitch1To1Edge
68 public:
69  void UnStitchAll1To1EdgeInNavCell(NavCell& navCell);
70  void StitchAllNew1To1EdgeAndTagPotentialRunTimeStitchNeed(const CellPos& cellPos, NavCellPosInfo* navCellPosInfo);
71 
72 private :
73  void RetrieveNeighborCellCandidates(const CellPos& cellPos);
74  void StitchAll1To1EdgeInNavCell(NavCell& navCell);
75  void TryToLinkCellBoundaryStitch1To1EdgeWithCandidates(NavCell* navCell, KyUInt32 floorIdx, KyUInt32 stitch1To1EdgeIdx,
76  const EdgeVertices& edgeVertices, KyArrayPOD<NavCell*, MemStat_NavData>& neihgborCellCandidates, CardinalDir cardinalDirInNeighbor);
77  void TryToLinkFloorBoundaryStitch1To1EdgeWithCandidates(NavCell* navCell, KyUInt32 floorIdx, KyUInt32 stitch1To1EdgeIdx, const EdgeVertices& edgeVertices);
78  bool DoesFloorCauseRuntimeStitchInNeighbor(NavCell* navCell, KyUInt32 floorIdx);
79 public:
80  void StitchAllNavFloorsOfNavCell(NavCell& navCell);
81  void StitchAllNavFloorLink(NavCell& navCell, NavFloorIdx floorIdx);
82  bool CanEdgesStitch(EdgeVertices& currentEdgeVertices, EdgeVertices& candidateEdgeVertices, NavHalfEdgeType edgeType);
83 
84  void UnStitchAllNavFloorsOfNavCell(NavCell& navCell);
85 
86 
87  KyFloat32 m_altitudeTolerance;
88  Database* m_database;
89 
90  static bool AreVerticesEqualInAltitude(KyFloat32 edge1_startAlt, KyFloat32 edge1_endAlt, KyFloat32 edge2_startAlt, KyFloat32 edge2_endAlt, KyFloat32 altitudeTolerance);
91 
92 private:
93  KyArrayPOD<NavCell*, MemStat_NavData> m_neihgborCellCandidates[4];
94 };
95 
96 
97 KY_INLINE bool NavFloorStitcher::AreVerticesEqualInAltitude(KyFloat32 edge1_startAlt, KyFloat32 edge1_endAlt,
98  KyFloat32 edge2_startAlt, KyFloat32 edge2_endAlt, KyFloat32 altitudeTolerance)
99 {
100  const KyFloat32 altitudeDiff1 = fabsf(edge1_startAlt - edge2_endAlt);
101  const KyFloat32 altitudeDiff2 = fabsf(edge1_endAlt - edge2_startAlt);
102  const KyFloat32 operand1 = Fsel(altitudeDiff1 - altitudeTolerance, 0.f, 1.f);
103  const KyFloat32 operand2 = Fsel(altitudeDiff2 - altitudeTolerance, 0.f, 1.f);
104  return operand1 * operand2 > 0;
105 }
106 
107 template <class VertexComparator>
108 class EdgeComparator
109 {
110 public:
111  static bool CanEdgesStitch(const EdgeVertices& edge1, const EdgeVertices& edge2, KyFloat32 altitudeTolerance)
112  {
113  return
114  VertexComparator::AreVerticesEqual(edge1.m_startVertex, edge2.m_endVertex) &&
115  VertexComparator::AreVerticesEqual(edge1.m_endVertex, edge2.m_startVertex) &&
116  NavFloorStitcher::AreVerticesEqualInAltitude(edge1.m_startAltitude, edge1.m_endAltitude, edge2.m_startAltitude, edge2.m_endAltitude, altitudeTolerance);
117  }
118 };
119 
120 class Comparator_InFloor
121 {
122 public:
123  static bool AreVerticesEqual(const Vec2i& vertex1, const Vec2i& vertex2) { return vertex1 == vertex2; }
124 };
125 
126 class Comparator_OnCellBoundEASTorWEST
127 {
128 public:
129  static bool AreVerticesEqual(const Vec2i& vertex1, const Vec2i& vertex2) { return vertex1.y == vertex2.y; }
130 };
131 
132 class Comparator_OnCellBoundNORTHorSOUTH
133 {
134 public:
135  static bool AreVerticesEqual(const Vec2i& vertex1, const Vec2i& vertex2) { return vertex1.x == vertex2.x; }
136 };
137 
138 }
139 
140 #endif //Navigation_NavCellStitcher_H
141 
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:23
KyUInt32 NavFloorIdx
An index that uniquely identifies a single NavFloor within the set of NavFloors owned by a NavCell...
Definition: navmeshtypes.h:115
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned short KyUInt16
Type used internally to represent an unsigned 16-bit integer.
Definition: types.h:40
NavHalfEdgeType
Enumerates the possible types of boundary that can be represented by a NavHalfEdge.
Definition: navmeshtypes.h:52
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
KyFloat32 Fsel(KyFloat32 cmp, KyFloat32 v1, KyFloat32 v2)
Ifcmp is greater than 0, returnsv1. Otherwise, returnsv2.
Definition: fastmath.h:58