gwnavruntime/visualdebug/visualdebugattributes.h Source File

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