gwnavruntime/world/visualdebugregistry.h Source File

visualdebugregistry.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 World;
17 class WorldElement;
18 class VisualDebugServer;
19 
20 typedef Hash<KyUInt32, WorldElement*, FixedSizeHash<KyUInt32>, AllocatorGH<KyUInt32, MemStat_VisualDebugRegistry> > WorldElementHash;
21 
22 // This class is used as a component of Kaim::World
23 // If KY_CONFIG_RELEASE is enabled, this class is not functional, and Kaim::World does not instanciate it.
24 class VisualDebugRegistry
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualDebugRegistry)
27  KY_CLASS_WITHOUT_COPY(VisualDebugRegistry)
28 
29 public:
30  VisualDebugRegistry(World* world) : m_world(world), m_nextVisualDebugId(0) {}
31 
32  ~VisualDebugRegistry();
33 
34  void Register(WorldElement* worldElement);
35 
36  void UnRegister(WorldElement* worldElement);
37 
38  KyUInt32 GetNewVisualDebugId();
39 
40  WorldElement* Get(KyUInt32 visualDebugId);
41 
42  WorldElement* GetAs(KyUInt32 visualDebugId, WorldElementType worldElementType);
43 
44  template<class T>
45  T* GetAs(KyUInt32 visualDebugId);
46 
47  //const WorldElementHash& GetElements() const { return m_hash; }
48 
49  // Called every frame, this is where we send visual debug data associated to WorldElements
50  void SendVisualDebug(VisualDebugServer& visualDebugServer);
51 
52  void OnConnection();
53 
54 private:
55  World* m_world; // allows to browse directly the WorldElement collections in SendVisualDebug() instead of browsing m_hash
56  KyUInt32 m_nextVisualDebugId;
57  WorldElementHash m_hash; // visualDebugId => WorldElement
58 };
59 
60 
61 #if defined(KY_CONFIG_DEBUG_OR_DEV)
62 
63 template<class T>
64 KY_INLINE T* VisualDebugRegistry::GetAs(KyUInt32 visualDebugId) { return (T*)GetAs(visualDebugId, T::GetStaticType()); }
65 
66 #else // VisualDebug disabled in Release
67 
68 KY_INLINE VisualDebugRegistry::~VisualDebugRegistry() {}
69 KY_INLINE void VisualDebugRegistry::Register(WorldElement*) {}
70 KY_INLINE void VisualDebugRegistry::UnRegister(WorldElement*) {}
71 KY_INLINE KyUInt32 VisualDebugRegistry::GetNewVisualDebugId() { return KyUInt32MAXVAL; }
72 KY_INLINE WorldElement* VisualDebugRegistry::Get(KyUInt32) { return nullptr; }
73 KY_INLINE WorldElement* VisualDebugRegistry::GetAs(KyUInt32, WorldElementType) { return nullptr; }
74 template<class T>
75 KY_INLINE T* VisualDebugRegistry::GetAs(KyUInt32) { return nullptr; }
76 KY_INLINE void VisualDebugRegistry::SendVisualDebug(VisualDebugServer&) {}
77 KY_INLINE void VisualDebugRegistry::OnConnection() {}
78 
79 #endif
80 
81 }
82 
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
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68