gwnavruntime/queries/makenavfloorstitchquery.h Source File

makenavfloorstitchquery.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 
14 
15 namespace Kaim
16 {
17 class NavCell;
18 class NavFloorBlob;
19 class DynamicTriangulation;
20 class DynamicNavFloor;
21 class NavFloorStitcherData;
22 
25 {
28 
29  RUNTIMESTITCH_PROCESSING,
30 
33 
35 };
36 
37 class MakeNavFloorStitchQuery : public ITimeSlicedQuery
38 {
39 
40 public:
41  static QueryType GetStaticType() { return TypeMakeNavFloorStitchQuery; }
42  virtual QueryType GetType() const { return TypeMakeNavFloorStitchQuery; }
43 
44  MakeNavFloorStitchQuery();
45  virtual ~MakeNavFloorStitchQuery();
46 
50  void BindToDatabase(Database* database);
51  void Initialize(NavCell* navCell);
52 
53  virtual void Advance(WorkingMemory* workingMemory);
54  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = nullptr);
56  MakeNavFloorStitchQueryResult GetResult() const { return m_result; };
57 
58  // ---------------------------------- Accessors ----------------------------------
59  void SetResult(MakeNavFloorStitchQueryResult result) { m_result = result; };
60  static void FillEdgeExtremities(const NavFloorBlob* navFloorBlob, NavHalfEdgeIdx halfEdgeIdx, Vec2i& start, Vec2i& end);
61 
62 private:
63  void ProcessNavFloor();
64 
65  class NewCutAlongStaticEdge
66  {
67  public:
68  NewCutAlongStaticEdge() {}
69  NewCutAlongStaticEdge(const Vec2i& pos, KyFloat32 alt) : m_pos(pos), m_altitude(alt) {}
70  bool operator==(const NewCutAlongStaticEdge& other) const { return m_pos == other.m_pos; }
71  bool operator!=(const NewCutAlongStaticEdge& other) const { return m_pos != other.m_pos; }
72 
73  public:
74  Vec2i m_pos;
75  KyFloat32 m_altitude;
76  };
77 
78  class RunTimeStitchCutSorter
79  {
80  public:
81  RunTimeStitchCutSorter(const Vec2i& stitch1To1EndVertex, KyInt32 currentEdgeDir) :
82  m_stitch1To1EndVertex(stitch1To1EndVertex), m_coordIdx(currentEdgeDir) {}
83 
84  bool operator() (const NewCutAlongStaticEdge& cut1, const NewCutAlongStaticEdge& cut2) const
85  {
86  KY_ASSERT(cut1.m_pos[m_coordIdx] != m_stitch1To1EndVertex[m_coordIdx]);
87  KY_ASSERT(cut2.m_pos[m_coordIdx] != m_stitch1To1EndVertex[m_coordIdx]);
88  const KyInt32 diff1 = cut1.m_pos[m_coordIdx] - m_stitch1To1EndVertex[m_coordIdx];
89  const KyInt32 diff2 = cut2.m_pos[m_coordIdx] - m_stitch1To1EndVertex[m_coordIdx];
90  const KyInt32 squareDist1 = diff1*diff1;
91  const KyInt32 squareDist2 = diff2*diff2;
92  return squareDist1 < squareDist2;
93  }
94 
95  Vec2i m_stitch1To1EndVertex;
96  KyInt32 m_coordIdx;
97  };
98 
99 
100  void ComputeAndInsertAllCuts(NavFloorStitcherData& currentData, KyUInt32 stitch1To1EdgeIdx, const Vec2i& stitch1To1EndVertex,
101  NavFloorStitcherData& neighborData, KyUInt32 neighborStitch1To1EdgeIdx, KyArray<NewCutAlongStaticEdge>& newCuts, DynamicTriangulation& dynTri);
102  void InsertexVertexInTriangulationOnEdge(DynamicTriangulation& dynTri, KyUInt32 halfEdgeIdx, NewCutAlongStaticEdge& newCut);
103  void BuildDynamicTriangulationFromStaticNavFloorBlob(const NavFloorBlob* floorBlob, DynamicTriangulation& dynTri);
104  void BuildDynamicNavFloorFromDynamicTriangulation(const NavFloorBlob* floorBlob, const NavFloor1To1StitchDataBlob& floor1To1StitchDataBlob,
105  const DynamicTriangulation& dynTri, DynamicNavFloor& dynaFloor);
106 
107  void SetFinish(WorkingMemory* workingMemory);
108  void ReleaseWorkingMemory() {}
109 
110 
111 public:
113  NavCell* m_navCell;
114  KyArray<Ptr<BlobHandler<NavFloorBlob> > > m_resultNavfloorHandlers;
116  KyInt32 m_coordIdx; // 0 for x, 1 for y
117  NavFloorIdx m_currentFloorIdx;
118  KyArray<KyUInt16> m_navHalfEdgeToTriangulationEdge;
119  bool m_dynamicTriangulationFromFloorIsBuilt;
120 };
121 
122 KY_INLINE void MakeNavFloorStitchQuery::SetFinish(WorkingMemory* /*workingMemory*/)
123 {
124  m_processStatus = QueryDone; // TODO - CHANGE THIS!
125  ReleaseWorkingMemory();
126 }
127 
128 
129 
130 }
131 
132 
133 
134 
135 
136 
Indicates that insufficient working memory caused the query to stop.
Definition: makenavfloorstitchquery.h:31
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyUInt32 NavHalfEdgeIdx
An index that uniquely identifies a single edge of a triangle within the set of edges owned by a NavF...
Definition: navmeshtypes.h:84
Indicates the query was successfully processed.
Definition: makenavfloorstitchquery.h:34
Indicates the query has not yet been initialized.
Definition: makenavfloorstitchquery.h:26
MakeNavFloorStitchQueryResult
Enumerates the possible results of a MakeNavFloorStitchQuery.
Definition: makenavfloorstitchquery.h:24
QueryType
Enumerates all the type of query.
Definition: iquery.h:25
Indicates an unknown error occurred during the query processing.
Definition: makenavfloorstitchquery.h:32
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
Indicates that the query has not yet been initialized.
Definition: iquery.h:295
std::int32_t KyInt32
int32_t
Definition: types.h:24
Indicates the query has not yet been launched.
Definition: makenavfloorstitchquery.h:27
Indicates that the query has not yet been launched.
Definition: iquery.h:296
void Initialize()
Should be called by the derived class before trying to perform the query or to push it in a QueryQueu...
Definition: iquery.h:273
float KyFloat32
float
Definition: types.h:32