gwnavruntime/visualdebug/visualdebugattributes.h Source File

visualdebugattributes.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 
12 
13 
14 namespace Kaim
15 {
16 
17 class FloatStat;
18 class SentBlobTypeStats;
19 class VisualDebugServer;
20 
21 enum VisualDebugStatType
22 {
23  VisualDebugStatType_UInt = Kaim::BlobField32::Type_KyUInt32,
24  VisualDebugStatType_Int = Kaim::BlobField32::Type_KyInt32,
25  VisualDebugStatType_Float = Kaim::BlobField32::Type_KyFloat32,
26  VisualDebugStatType_String
27 };
28 
29 class VisualDebugAttributeHeader
30 {
31  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualDebug)
32 public:
33  VisualDebugAttributeHeader(const char* name) : m_name(name) {}
34 
35  String m_name;
36  KyUInt32 m_index; // index of this header in VisualDebugAttributeGroup::m_headers
37 };
38 
39 class VisualDebugAttributeValues
40 {
41  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualDebug)
42 public:
43  VisualDebugAttributeValues(KyUInt32 value32Count)
44  {
45  m_values32.Resize(value32Count);
46  for (UPInt i = 0; i < value32Count; ++i)
47  m_values32[i] = 0;
48  }
49 
50  void AddInt32Value(KyInt32 val) { m_values32.PushBack(*(KyUInt32*)&val); }
51  void AddUInt32Value(KyUInt32 val) { m_values32.PushBack(val); }
52  void AddValue32(KyUInt32 val) { m_values32.PushBack(val); }
53  void AddFloat32Value(KyFloat32 val);
54 
55  void SetStringValue(const char* val) { m_stringValue = val; }
56  void SetInt32Value(KyInt32 val, KyUInt32 idx = 0) { if (OutOfValuesBound(idx) == false) m_values32[idx] = *(KyUInt32*)&val; }
57  void SetUInt32Value(KyUInt32 val, KyUInt32 idx = 0) { if (OutOfValuesBound(idx) == false) m_values32[idx] = val; }
58  void SetValue32(KyUInt32 val, KyUInt32 idx = 0) { if (OutOfValuesBound(idx) == false) m_values32[idx] = val; }
59  void SetFloat32Value(KyFloat32 val, KyUInt32 idx = 0);
60 
61  const String& GetStringValue() const { return m_stringValue; }
62  KyInt32 GetInt32Value(KyUInt32 idx) const { if (OutOfValuesBound(idx)) return 0; else return *(KyInt32*)(&m_values32[idx]); }
63  KyUInt32 GetUInt32Value(KyUInt32 idx) const { if (OutOfValuesBound(idx)) return 0; else return m_values32[idx]; }
64  KyFloat32 GetFloat32Value(KyUInt32 idx) const;
65 
66 private:
67  bool OutOfValuesBound(KyUInt32 valueIndex) const
68  {
69  KY_ASSERT(valueIndex < m_values32.GetSize());
70  if (valueIndex < m_values32.GetSize())
71  return false;
72  else
73  return true;
74  }
75 
76 public:
77  String m_stringValue;
78  KyArray<KyUInt32> m_values32;
79 };
80 
81 class VisualDebugAttribute
82 {
83  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualDebug)
84 public:
85  VisualDebugAttribute() : m_name(""), m_valueType(VisualDebugStatType_UInt) {}
86 
87  VisualDebugAttribute(const char* name) : m_name(name) {}
88 
89  String m_name;
90  VisualDebugStatType m_valueType;
91  VisualDebugAttributeValues* m_values; // pointer to the structure storing the item values
92  VisualDebugAttributeHeader* m_header; // pointer to the header (this could be shared between items)
93 };
94 
102 {
103  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualDebug)
104 public:
105  VisualDebugAttributeGroup() : m_name(""), m_descriptionSent(false) {}
106  VisualDebugAttributeGroup(const char* name) : m_name(name), m_descriptionSent(false) {}
107 
108  ~VisualDebugAttributeGroup() { Clear(); }
109 
110  void Clear();
111 
112  VisualDebugAttributeHeader* GetOrCreateHeader(const char* headerName);
113 
115  VisualDebugAttribute* CreateFloatAttribute (const char* name, KyUInt32 statValueEnum, KyUInt32 valueCount = 1, VisualDebugAttributeHeader* header = nullptr);
116  VisualDebugAttribute* CreateFloatStatAttribute (const char* name, KyUInt32 statValueEnum);
117  VisualDebugAttribute* CreateSentItemsAttribute(const char* name, KyUInt32 statValueEnum);
118  VisualDebugAttribute* CreateIntAttribute (const char* name, KyUInt32 statValueEnum, KyUInt32 valueCount = 1, VisualDebugAttributeHeader* header = nullptr);
119  VisualDebugAttribute* CreateUIntAttribute(const char* name, KyUInt32 statValueEnum, KyUInt32 valueCount = 1, VisualDebugAttributeHeader* header = nullptr);
120  VisualDebugAttribute* CreateStringAttribute(const char* name, KyUInt32 statValueEnum, VisualDebugAttributeHeader* header = nullptr);
121 
123  void UpdateStringValue (KyUInt32 valEnum, const char* val);
124  void UpdateFloatValue (KyUInt32 valEnum, KyFloat32 val , KyUInt32 valIdx = 0);
125  void UpdateUIntValue (KyUInt32 valEnum, KyUInt32 val , KyUInt32 valIdx = 0);
126  void UpdateIntValue (KyUInt32 valEnum, KyInt32 val , KyUInt32 valIdx = 0);
127  void UpdateFloatStatValue(KyUInt32 valEnum, const FloatStat& floatStat);
128  void UpdateSentItemsValues(KyUInt32 valEnum, const SentBlobTypeStats& stats);
129 
131  // VisualDebug
133 
135  bool IsDescriptionSent() { return m_descriptionSent; }
136  void SetDescriptionSent(bool descriptionSent) { m_descriptionSent = descriptionSent; }
137 
139  void SendGroupDescription(VisualDebugServer* visualDebugServer);
140 
142  void SendGroupValues(VisualDebugServer* visualDebugServer);
143 
144 private:
145  VisualDebugAttribute* CreateStatItem(const char* name, VisualDebugAttributeValues* statValue, VisualDebugStatType type
146  , KyUInt32 statValueEnum, VisualDebugAttributeHeader* header);
147 
148 public:
149  String m_name;
150  KyArray<VisualDebugAttribute*> m_items;
151  KyArray<VisualDebugAttributeValues*> m_itemsValues;
152  KyArray<VisualDebugAttributeHeader*> m_headers;
153  bool m_descriptionSent;
154 };
155 
156 }
157 
void SendGroupValues(VisualDebugServer *visualDebugServer)
Send the group values (items' values only)
Definition: visualdebugattributes.cpp:174
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
VisualDebugAttribute * CreateFloatAttribute(const char *name, KyUInt32 statValueEnum, KyUInt32 valueCount=1, VisualDebugAttributeHeader *header=nullptr)
Call these to build your stat group.
Definition: visualdebugattributes.cpp:124
void UpdateStringValue(KyUInt32 valEnum, const char *val)
Call this to update your stat group.
Definition: visualdebugattributes.cpp:81
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
void SendGroupDescription(VisualDebugServer *visualDebugServer)
Send the group description (items' names, types, headers)
Definition: visualdebugattributes.cpp:165
A group of Key / valuetype / arrayof values, where the keys and types are created once...
Definition: visualdebugattributes.h:101
FloatStat maintains current, average, min, max statistics in a sliding window of frames.
Definition: floatstat.h:19
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
bool IsDescriptionSent()
The decription must be sent only once on creation or on reconnection.
Definition: visualdebugattributes.h:135
float KyFloat32
float
Definition: types.h:32