gwnavruntime/world/worldelement.h Source File

worldelement.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 
13 
14 namespace Kaim
15 {
16 
17 class World;
18 class VisualDebugServer;
19 
20 
23 {
24  VisualDebugLOD_None = 0,
25  VisualDebugLOD_Default,
26  VisualDebugLOD_Maximal,
27  VisualDebugLOD_Undefined = KyUInt32MAXVAL
28 };
29 
30 
31 enum VisualDebugSendChangeEvent
32 {
33  VisualDebugSendChangeEvent_NoChange = 0, // Happens most of the time and means you can send your data only when they have changed
34  VisualDebugSendChangeEvent_OnLODChanged, // Happens when the level of detail has changed and means you must send or remove (send a VisualDebugDataRemovalBlob) all data according to the LOD change
35  VisualDebugSendChangeEvent_ForceSendAll // Happens on connection with a visual debug client (eg: NavigationLab) or when WorldElement::ForceSendAllvisualDebug is called. Means you must send all data describing your element for current LOD.
36 };
37 
38 
41 class WorldElement : public RefCountBase<WorldElement, Stat_Default_Mem>
42 {
43 public:
44  // ---------------------------------- Main API Functions ----------------------------------
45 
46  WorldElement(World* world = nullptr)
47  : m_currentVisualDebugLOD(VisualDebugLOD_Undefined)
48  , m_previousVisualDebugLOD(VisualDebugLOD_Undefined)
49  { MakeZeroWorldElement(); m_world = world; }
50 
51  virtual ~WorldElement() {}
52 
53  virtual WorldElementType GetType() const = 0;
54  virtual const char* GetTypeName() const = 0;
55 
56  bool IsAddedToWorld() const { return m_indexInCollection != KyUInt32MAXVAL; }
57  World* GetWorld() const { return m_world; }
58  KyUInt32 GetVisualDebugId() const { return m_visualDebugId; }
59  void* GetUserData() const { return m_userData; }
60 
61  void SetUserData(void* userData) { m_userData = userData; }
62 
63 
64  // ---------------------------------- Visual Debug ----------------------------------
65 
72 
73  VisualDebugLOD GetCurrentVisualDebugLOD() const { return m_currentVisualDebugLOD; }
74  VisualDebugLOD GetPreviousVisualDebugLod() const { return m_previousVisualDebugLOD; }
75  void SendVisualDebug(VisualDebugServer& server);
76 
81 
82 
83 public: // internal
84 
85  // Called at each update on all registered WorldElement. Consider the event
86  // to decide what to send.
87  virtual void DoSendVisualDebug(VisualDebugServer&, VisualDebugSendChangeEvent) {}
88  void SendForMaxLevelOfDetail(VisualDebugServer& server, const Vec3f& shapePosition);
89 
90  // visual debug registry
91  void RegisterToVisualDebug();
92  void UnRegisterFromVisualDebug();
93 
94  // for O(1) remove from world collections
95  KyUInt32 GetIndexInCollection() const { return m_indexInCollection; }
96  void SetIndexInCollection(KyUInt32 indexInCollection) { m_indexInCollection = indexInCollection; }
97 
98 protected:
99  void MakeZeroWorldElement();
100 
101 protected:
102  World* m_world;
103  KyUInt32 m_indexInCollection; // for O(1) remove from world collections
104  KyUInt32 m_visualDebugId; // TODO: 30 bits is enough merge it into 1 UINT32
105  VisualDebugLOD m_currentVisualDebugLOD; // TODO: 4 bits are enough merge it into 1 UINT32
106  VisualDebugLOD m_previousVisualDebugLOD; // TODO: 4 bits are enough merge it into 1 UINT32
107  bool m_forceSendAllVisualDebugData;
108  void* m_userData;
109 
110 friend class VisualDebugRegistry;
111 };
112 
113 
114 #if defined(KY_CONFIG_DEBUG_OR_DEV)
115 KY_INLINE void WorldElement::SetCurrentVisualDebugLOD(VisualDebugLOD lod) { m_currentVisualDebugLOD = lod; }
116 
117 #else // VisualDebug is disabled in Release mode
118 
120 
121 KY_INLINE void WorldElement::RegisterToVisualDebug() {}
122 KY_INLINE void WorldElement::UnRegisterFromVisualDebug() {}
124 KY_INLINE void WorldElement::SendVisualDebug(VisualDebugServer&) {}
125 KY_INLINE void WorldElement::SendForMaxLevelOfDetail(VisualDebugServer&, const Vec3f&) {}
126 #endif
127 
128 
129 }
130 
void SetCurrentVisualDebugLOD(VisualDebugLOD lod)
Set the visual debug level of details to use for this WorldElement instance.
Definition: worldelement.h:119
void ForceSendAllVisualDebug()
Call this when something impacts all your visual debug data.
Definition: worldelement.h:123
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
This class is a runtime container for Autodesk Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:52
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:41
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
VisualDebugLOD
Enumerates the visual debug levels of details.
Definition: worldelement.h:22
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
3d vector using 32bits floating points.
Definition: vec3f.h:16