gwnavruntime/channel/stringpuller.h Source File

stringpuller.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 
14 
15 namespace Kaim
16 {
17 class DisplayListManager;
18 class BiTangentSorter_IncreasingAngleFromReferenceDirection;
19 
20 enum StringPullerResult
21 {
22  StringPuller_NotInitialized,
23  StringPuller_NotComputed,
24 
25  StringPuller_Done_Success,
26 
27  StringPuller_Done_InvalidInput,
28  StringPuller_Done_CurrentPivotOppositeBorderNotFound,
29  StringPuller_Done_BubbleToCornerFunnelFailure,
30  StringPuller_Done_NextPivotNotFound,
31  StringPuller_Done_NextPivotOppositeBorderNotFound,
32 };
33 
37 {
38 public:
39  StringPuller() { Clear(); }
40 
41  void Initialize(const BubbleArray& bubbleArray, DisplayListManager* displayListManager, FullDebug fullDebug);
42  void Clear();
43 
44  // Compute full StringPull, i.e. same as Advance with no slicing
45  KY_INLINE void Compute(StringPulledBubbleList& stringPulledBubbleList);
46 
47  // Advances the pivot at most by maxPivotPerAdvance
48  void Advance(StringPulledBubbleList& stringPulledBubbleList, KyUInt32 maxPivotPerAdvance = 1);
49 
50 
51 public: // internal. They are public only to be unit tested
52  KyResult RunFromCurrentPivot(StringPulledBubbleList& stringPulledBubbleList);
53 
54  KyResult ComputeClosedCorner();
55  KyResult ComputeNextPivot();
56  KyResult StringPullBetweenPivots(StringPulledBubbleList& stringPulledBubbleList);
57 
58  KyResult ComputeCurrentPivotEnterOrthoOppositeBorderIndex();
59  KyResult ComputeNextPivotEnterOrthoOppositeBorderIndex();
60 
61  KyResult ComputeCornerEnterOrthoOppositeBorderIndex(KyUInt32 cornerIndex, FunnelSide cornerSide, const Vec2f& enterDirection,
62  KyUInt32& oppositeBorderStartIdx, KyUInt32& oppositeBorderEndIdx, const Color& baseColor, const char* displayListName);
63 
64  KyResult ComputeOppositeBorderIndex(KyUInt32 cornerIdx, const Vec2f& direction, KyUInt32& oppositeBorderStartIdx, KyUInt32& oppositeBorderEndIdx);
65  KyResult CollectIntersectingBubblesInPivotTurn();
66 
67  KyResult CollectIntersectingBubblesUpToClosedCorner(RotationDirection collectedBubbleRotDir);
68  KyResult CollectIntersectingBubblesOverClosedCorner(RotationDirection collectedBubbleRotDir);
69 
70  KyUInt32 GetNextTangentBubbleIdx(FunnelSide funnelSide, const Vec2f& refDir);
71 
72  void InitVisualDebugRunFromCurrentPivot() const;
73  void VisualDebugGetNextTangentBubbleIdx(KyUInt32 bubbleCount, const Bubble& curPivotBubble, const Vec2f& refDir, BiTangentSorter_IncreasingAngleFromReferenceDirection& increasingAngleSorter) const;
74  void VisualDebugStringPullBetweenPivots() const;
75  void VisualDebugComputeCornerEnterOrtho_1(const Color& displayColor, const char* displayListName, KyUInt32 cornerIndex) const;
76  void VisualDebugComputeCornerEnterOrtho_2(const Color& displayColor, const char* displayListName, KyUInt32 cornerIndex, const Vec2f& curPivotEnterOrthoDir, const Vec2f& enterDirection) const;
77  void VisualDebugComputeCornerEnterOrtho_3(const char* displayListName, KyUInt32 oppositeBorderStartIdx, KyUInt32 oppositeBorderEndIdx, Color displayColor) const;
78 
79 private:
80  void DisplayOppositeBorderError(KyUInt32 cornerIdx, const Vec2f& direction, const char* text);
81 
82 public: // internal: public only for unit tests
83  // Inputs
84  const BubbleArray* m_bubbleArray;
85 
86  // Parameters
87  KyFloat32 m_fullTurnToleranceSin; // Very technical: default is 0.01 ( = sin(~s0.57 Degrees )), must be let very small
88 
89  // Internal
90 // StringPulledBubbleList m_localStringPull;
91  KyArrayPOD<KyUInt32> m_indicesOfTheSameSideCornersIncludedInCurrentPivotBubble;
92  BubbleFunnelBorder m_funnelClosedBorder;
93 
94  KyUInt32 m_bubbleCount;
95 
96  KyUInt32 m_currentPivotIndex;
97  FunnelSide m_currentPivotSide;
98  Vec2f m_currentPivotEnterDirection;
99  KyUInt32 m_currentPivotOrthoOppositeBorderStartIdx;
100  KyUInt32 m_currentPivotOrthoOppositeBorderEndIdx;
101 
102  KyUInt32 m_nextPivotIndex;
103  FunnelSide m_nextPivotSide;
104  Vec2f m_nextPivotEnterDirection;
105  KyUInt32 m_nextPivotOrthoOppositeBorderStartIdx;
106  KyUInt32 m_nextPivotOrthoOppositeBorderEndIdx;
107 
108  KyArrayPOD<KyUInt32> m_intersectingBubbles; // aka bubble subset
109  struct BiTangent
110  {
111  KyFloat32 GetSqLength2d() const { return SquareDistance2d(m_startPos, m_endPos); }
112  Vec3f m_startPos;
113  Vec3f m_endPos;
114  Vec2f m_dir;
115  };
116  KyArrayPOD<BiTangent> m_biTanArray;
117  KyArrayPOD<KyUInt32> m_sortedIndices;
118  KyArrayPOD<KyUInt32> m_localStringPullCornerIndices;
119 
120  // Outputs
121  StringPullerResult m_result;
122 
123  // VisualDebug
124  mutable KyUInt32 m_loopIndex;
125  mutable char m_loopGroupName[64];
126 
127 public:
128  FullDebug m_fullDebug;
129  bool m_visualDebugOneGroupPerLoop;
130  DisplayListManager* m_displayListManager;
131 };
132 
133 
134 KY_INLINE void StringPuller::Compute(StringPulledBubbleList& stringPulledBubbleList) { Advance(stringPulledBubbleList, KyUInt32MAXVAL); }
135 
136 } // namespace Kaim
137 
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:375
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
This class encapsulate an array of Bubbles.
Definition: bubblearray.h:22
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:15
This class represents a circle with potential rotation limitation.
Definition: bubble.h:31
2d vector using KyFloat32.
Definition: vec2f.h:18
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
RGBA color.
Definition: color.h:16
Computes a StringPulledBubbleList from the provided array of bubbles.
Definition: stringpuller.h:36
Gathers all runtime flags used to debug internal algorithms (mostly PathFinder).
Definition: fulldebug.h:14
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16