gwnavruntime/database/navfloorstitcher.h Source File

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