gwnavruntime/pathfollower/baseshortcuttrajectory.h Source File

baseshortcuttrajectory.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 namespace Kaim
14 {
15 
16 class VisualDebugServer;
17 class Bot;
18 class Trajectory;
19 class TargetOnPath;
20 
21 enum ShortcutMode
22 {
23  ShortcutMode_MustUpdateTargetOnPath, // classical shortcut, update TargetOnPath
24  ShortcutMode_UseCurrentTargetOnPath, // classical shortcut, no need to update the TargetOnPath
25  ShortcutMode_SnapOnPath, // snap on path
26 };
27 
33 class BaseShortcutTrajectory : public RefCountBase<BaseShortcutTrajectory, MemStat_PathFollowing>
34 {
35  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_PathFollowing)
37 public:
38  // ------------------------------ Functions -----------------------------
40 
41  virtual ~BaseShortcutTrajectory() = 0;
42 
43  void Compute(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx);
44 
45  void Clear(); // fully clear the trajectory and default its config
46  void ClearTrajectory(); // only clear the current computed trajectory
47 
48  const Vec3f& GetTrajectoryTarget() const { return m_target; }
49 
50  void ForceTargetToTargetOnPath() { m_useTargetProvidedByUser = false; }
51  void ForceTargetToPosition(const Vec3f& forcedTarget);
52 
53 public: // internal
54  Bot* GetBot() const;
55 
56  void SendVisualDebugBlob(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent);
57  void RemoveAllVisualDebugBeforeTrajectoryChange(VisualDebugServer& visualDebugServer);
58 
59  void InitTargetOnPathIfNeeded();
60  void UpdateTarget(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx); //< InitTargetOnPathIfNeeded() must have been called before calling UpdateTarget()
61 
62  ShortcutMode GetShortcutMode(KyUInt32 worldUpdateIdx);
63  bool CanUseTargetOnPath() const;
64 
65  virtual KyResult ComputeTargetOnPath(KyFloat32 simulationTimeInSeconds) = 0;
66 
67  // Used in Trajectory::CanResetTrajectory to instantiate a TargetOnPathComputer and compute a TargetOnPath calling ComputeTargetOnPathOnNavMeshOnly
68  // which disregards backward edge type, it only check forward edge type that must be on NavMesh and bot must have a valid triangle
69  virtual KyResult ComputeTargetOnPathOnNavMeshOnly(TargetOnPath& targetOnPath, KyFloat32 simulationTimeInSeconds, ComputeTargetOnPathSearchControl forwardSearchControl) const = 0;
70 
71  bool WillUpdatePathFollowThisFrame(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx, KyUInt32 updatePeriod)
72  {
73  bool willUpdate = WillUpdatePathFollowThisFrame_(simulationTimeInSeconds, worldUpdateIdx, updatePeriod);
74  if (willUpdate)
75  m_updateLastUpdateIdx = worldUpdateIdx;
76  return willUpdate;
77  }
78 
79 private:
80  void UpdateShortcutMode(KyUInt32 worldUpdateIdx);
81  void ComputeStraightTrajectory(KyFloat32 simulationTimeInSeconds);
82  void ComputeAvoidanceTrajectory(KyFloat32 simulationTimeInSeconds);
83  void ComputeSnapOnPathTrajectory(KyFloat32 simulationTimeInSeconds);
84 
85  virtual bool WillUpdatePathFollowThisFrame_(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx, KyUInt32 updatePeriod) = 0;
86 
87  ShortcutMode ComputeShortcutMode() const;
88 
89 public: // internal
90  Trajectory* m_trajectory;
91  ShortcutTrajectoryConfig m_config;
92  Ptr<IAvoidanceComputer> m_avoidanceComputer;
93  TargetOnPath m_targetOnPath;
94  Vec3f m_target;
95  KyUInt32 m_updateLastUpdateIdx;
96  ShortcutMode m_shortcutMode;
97  ShortcutMode m_prevShortcutMode;
98  KyUInt32 m_trajectoryComputeModeLastUpdateIdx;
99  bool m_useTargetProvidedByUser;
100  bool m_useMinimalTargetUpdate; // when TargetOnPath is updated only when the bot reaches the TargetOnPath, or if it becomes necessary to update it e.g. when avoiding other entities.
101  bool m_visualDebugBlobSent;
102 };
103 
104 
105 } // namespace Kaim
106 
107 
This class is the world element that represent an active character in Autodesk Navigation.
Definition: bot.h:128
This class computes minimal trajectory made of just one velocity.
Definition: baseshortcuttrajectory.h:33
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Set of parameters used by the ShortcutTrajectory and TargetOnPathComputer classes to update Bot targe...
Definition: shortcuttrajectoryconfig.h:89
This class computes the trajectory either with ShortcutTrajectory or with SplineTrajectory.
Definition: trajectory.h:26
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16