KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
KarmaGuiMesa.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "Karma.h"
13
14extern "C" {
15#include "dmidecode.h"
16}
17
18namespace Karma
19{
21 {
22 std::function< void(std::string) > openSceneCallback;
23 };
24
25 struct KarmaLogMesa
26 {
27 static KarmaGuiTextBuffer TextBuffer;
28 static KarmaGuiTextFilter TextFilter;
29 static KGVector<int> LineOffsets; // Index to lines offset. We maintain this with AddLog() calls.
30 static bool AutoScroll; // Keep scrolling if already at the bottom.
31 static std::shared_ptr<spdlog::logger> s_MesaCoreLogger;
32 static std::shared_ptr<spdlog::logger> s_MesaClientLogger;
33 static std::shared_ptr<spdlog::pattern_formatter> s_MesaLogFormatter;
34
35 KarmaLogMesa()
36 {
37 AutoScroll = true;
38 Clear();
39 }
40
41 static void Clear()
42 {
43 TextBuffer.clear();
44 LineOffsets.clear();
45 LineOffsets.push_back(0);
46 }
47
48 static void AddLog(const char* fmt, ...) /*KG_FMTARGS(2) */// <- what in the name of WYSIWYG is this?
49 {
50 int cacheSize = TextBuffer.size();
51 va_list args;
52 va_start(args, fmt);
53 TextBuffer.appendfv(fmt, args);
54 va_end(args);
55
56 for (int newSize = TextBuffer.size(); cacheSize < newSize; cacheSize++)
57 {
58 if (TextBuffer[cacheSize] == '\n')
59 {
60 LineOffsets.push_back(cacheSize + 1);
61 }
62 }
63 }
64
65 static void Draw(const char* title, bool* pOpen = nullptr)
66 {
67 if (!KarmaGui::Begin(title, pOpen))
68 {
69 KarmaGui::End();
70 return;
71 }
72
73 // Options menu
74 if (KarmaGui::BeginPopup("Options"))
75 {
76 KarmaGui::Checkbox("Auto-scroll", &AutoScroll);
77 KarmaGui::EndPopup();
78 }
79
80 // Main window
81 if (KarmaGui::Button("Options"))
82 {
83 KarmaGui::OpenPopup("Options");
84 }
85
86 KarmaGui::SameLine();
87 bool clear = KarmaGui::Button("Clear");
88 KarmaGui::SameLine();
89 bool copy = KarmaGui::Button("Copy");
90 KarmaGui::SameLine();
91
92 TextFilter.Draw("Filter", -100.0f);
93
94 KarmaGui::Separator();
95 KarmaGui::BeginChild("scrolling", KGVec2(0, 0), false, KGGuiWindowFlags_HorizontalScrollbar);
96
97 if (clear)
98 {
99 Clear();
100 }
101 if (copy)
102 {
103 KarmaGui::LogToClipboard();
104 }
105
106 KarmaGui::PushStyleVar(KGGuiStyleVar_ItemSpacing, KGVec2(0, 0));
107
108 const char* buAlpha = TextBuffer.begin();
109 const char* buOmega = TextBuffer.end();
110
111 if (TextFilter.IsActive())
112 {
113 // In this example we don't use the clipper when TextFilter is enabled.
114 // This is because we don't have a random access on the result on our filter.
115 // A real application processing logs with ten of thousands of entries may want to store the result of
116 // search/filter.. especially if the filtering function is not trivial (e.g. reg-exp).
117 for (int lineNumber = 0; lineNumber < LineOffsets.Size; lineNumber++)
118 {
119 const char* lineStart = buAlpha + LineOffsets[lineNumber];
120 const char* lineEnd = (lineNumber + 1 < LineOffsets.Size) ? (buAlpha + LineOffsets[lineNumber + 1] - 1) : buOmega;
121 if (TextFilter.PassFilter(lineStart, lineEnd))
122 {
123 KarmaGui::TextUnformatted(lineStart, lineEnd);
124 }
125 }
126 }
127 else
128 {
129 // The simplest and easy way to display the entire buffer:
130 // ImGui::TextUnformatted(buBegin, buEnd);
131 // And it'll just work. TextUnformatted() has specialization for large blob of text and will fast-forward
132 // to skip non-visible lines. Here we instead demonstrate using the clipper to only process lines that are
133 // within the visible area.
134 // If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them
135 // on your side is recommended. Using ImGuiListClipper requires
136 // - A) random access into your data
137 // - B) items all being the same height,
138 // both of which we can handle since we have an array pointing to the beginning of each line of text.
139 // When using the filter (in the block of code above) we don't have random access into the data to display
140 // anymore, which is why we don't use the clipper. Storing or skimming through the search result would make
141 // it possible (and would be recommended if you want to search through tens of thousands of entries).
142 KarmaGuiListClipper clipper;
143 clipper.Begin(LineOffsets.Size);
144
145 while (clipper.Step())
146 {
147 for (int lineNumber = clipper.DisplayStart; lineNumber < clipper.DisplayEnd; lineNumber++)
148 {
149 const char* lineStart = buAlpha + LineOffsets[lineNumber];
150 const char* lineEnd = (lineNumber + 1 < LineOffsets.Size) ? (buAlpha + LineOffsets[lineNumber + 1] - 1) : buOmega;
151 KarmaGui::TextUnformatted(lineStart, lineEnd);
152 }
153 }
154 clipper.End();
155 }
156 KarmaGui::PopStyleVar();
157
158 if (AutoScroll && KarmaGui::GetScrollY() >= KarmaGui::GetScrollMaxY())
159 {
160 KarmaGui::SetScrollHereY(1.0f);
161 }
162
163 KarmaGui::EndChild();
164 KarmaGui::End();
165 }
166 };
167
168 struct KarmaGuiDockPreviewData
169 {
170 KGGuiDockNode FutureNode;
171 bool IsDropAllowed;
172 bool IsCenterAvailable;
173 bool IsSidesAvailable; // Hold your breath, grammar freaks..
174 bool IsSplitDirExplicit; // Set when hovered the drop rect (vs. implicit SplitDir==None when hovered the window)
175 KGGuiDockNode* SplitNode;
176 KarmaGuiDir SplitDir;
177 float SplitRatio;
178 KGRect DropRectsDraw[KGGuiDir_COUNT + 1]; // May be slightly different from hit-testing drop rects used in DockNodeCalcDropRects()
179
180 KarmaGuiDockPreviewData();
181 };
182
183 struct KarmaTuringMachineElectronics
184 {
185 bool bHasQueried;
186
187 // Bios Information
188 std::string biosVendorName;
189 std::string biosVersion;
190 std::string biosReleaseDate;
191 std::string biosCharacteristics;
192 std::string biosROMSize;
193 std::string biosCurrentSetLanguage;
194 std::string biosRestOfTheSupportedLanguages;
195
196 // System Memory (RAM) overview
197 uint32_t numberOfMemoryDevices;// An estimation. I shall manually introduce logical checks
198
199 // I named estimated because of the lies
200 // https://github.com/ravimohan1991/BiosReader/wiki/The-Life-and-Lies-of-the-BIOS
201 std::string estimatedCapacity;
202 std::string supportingArea;
203
205 {
206 std::string formFactor;
207 std::string ramSize;
208 std::string locator;
209 std::string ramType;
210 std::string bankLocator;
211 std::string manufacturer;
212
213 std::string serialNumber;
214 std::string partNumber;
215 std::string assetTag;
216
217 std::string memorySpeed;
218 std::string configuredMemorySpeed;
219
220 std::string operatingVoltage;
221 std::string rank;
222 };
223 SystemRAM* ramInformation;
224
225 // Let me tell the story of naming. Since the physical slots are the ones
226 // present on board, the array slots in software side, getting filled on a query to BIOS,
227 // naturally get the name "...SoftSlots" from BiosReader's allocation POV
228 std::vector<uint32_t> ramSoftSlots;
229
230 uint32_t totalRamSize;
231 std::string ramSizeDimensions;
232
233 // Processor information
234 // Asssuming only 1 processor
235 std::string cpuDesignation;// Socket designation
236 std::string cpuType; // In order to distinguish from GPU processor :) or DSP https://en.wikipedia.org/wiki/Digital_signal_processor
237 std::string cpuProcessingfamily;
238 std::string cpuManufacturer;
239 std::string cpuFlags;
240 // Kind of the most important element of this struct. eg Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz (completeprocessingunitidentifier)
241 std::string cpuVersion;
242
243 std::string cpuOperatingVoltage;
244 std::string cpuExternalClock;
245 std::string cpuMaximumSpeed;
246 std::string cpuCurrentSpeed;
247
248 // Some OEM specific numbers
249 std::string cpuSerialNumber;
250 std::string cpuPartNumber;
251 std::string cpuAssettag;
252
253 std::string cpuCorescount;
254 std::string cpuEnabledCoresCount;
255 std::string cpuThreadCount;
256 std::string cpuTheCharacterstics;
257
258 // The Cpu ID field contains processor - specific information that describes the processor’s features.
259 std::string cpuid; // in the context of motherboard components
260 std::string cpuSignature;
261
262 // For now, with due respect, let there be enough content with just model number
263 // und vendor. Would be dope to read the GPU just like RAM or CPU, from SMBIOS!!
264 std::string gpuVendor;
265 std::string gpuModelIdentification;
266 std::string gpuVMemory;
267
268 KarmaTuringMachineElectronics()
269 {
270 bHasQueried = false;
271 numberOfMemoryDevices = 0;
272 ramInformation = nullptr;
273 }
274
276
277 // Gauging Ram devices
278 static void GaugeSystemMemoryDevices(random_access_memory* ramCluster);
279
280 // Obtain the real RAM information
281 static void FindRealCapacityOfRam();
282
283 // No-ram conditions. Bit'o hacky stuff
284 static bool IsPhysicalRamPresent(const random_access_memory& ramScam);
285
286 // Filling the SystemRAM structure with relevant information
287 static void FillTheSystemRamStructure(SystemRAM& destinationStructure, random_access_memory& sourceStructure);
288 };
289
291 {
292 float widthCache;
293 float heightCache;
294 float startXCache;
295 float startYCache;
296 float ioDisplayXCache;
297 float ioDisplayYCache;
298 float scrollX;
299 float scrollY;
300 };
301
302 struct UObjectsStatistics
303 {
304 void* objectPointer;
305 std::string beginAddress;
306 std::string endAddress;
307 size_t size;
308 size_t sizeInPool;
309 std::string uobjectName;
310 uint32_t alignment;
311 UClass* classObject;
312
313 // Placement in memory pool
314 KGVec2 placementCoordi;//nates
315
316 UObjectsStatistics()
317 {
318 placementCoordi.x = placementCoordi.y = 0.0f;
319 }
320 };
321
323 {
324 public:
325 // Showtime!
326 static void RevealMainFrame(KGGuiID mainMesaDockID, std::shared_ptr<Scene> scene, const CallbacksFromEditor& editorCallbacks);
327 static void DrawKarmaMainMenuBarMesa();
328 static void DrawMainMenuFileListMesa();
329 static void DrawKarmaLogMesa(KGGuiID mainMesaDockID);
330 static void DrawKarmaSceneHierarchyPanelMesa();
331 static void Draw3DModelExhibitorMesa(std::shared_ptr<Scene> scene);
332 static void DrawContentBrowser(const std::function< void(std::string) >& openSceneCallback);
333 static void DrawMemoryExhibitor();
334
335 // Mesas!
336 static void ShowAboutKarmaMesa(bool* pbOpen);
337
338 // Shiva the Mesa and rest
339 static void MesaShutDownRoutine();
340
341 static KGGuiDockNode* DockNodeTreeFindFallbackLeafNode(KGGuiDockNode* node);
342
343 // Getters
344 static KarmaTuringMachineElectronics& GetGatheredElectronicsInformationForModification() { return electronicsItems; }
345 static const KarmaTuringMachineElectronics& GetGatheredElectronicsInformation() { return electronicsItems; }
346
347 // Setters
348 static void SetElectronicsRamInformationToNull();
349
350 // Helpers
351 static int ImStrlenW(const KGWchar* str);
352 static void QueryForTuringMachineElectronics();
353 static uint32_t ChurnUint32FromString(const std::string& ramString);
354 static std::string ChurnDimensionsFromString(const std::string& ramString);
355 static double HexStringToDecimal(const std::string& hexString);
356
357 // Statistics
358 static void DumpUObjectStatistics(void* InObject, const std::string& InName, size_t InSize, size_t InAlignment, class UClass* InClass);
359
360 public:
361 static std::string notAvailableText;
362 static KarmaLogMesa m_KarmaLog;
363
364 private:
365 static KarmaTuringMachineElectronics electronicsItems;
366 static WindowManipulationGaugeData m_3DExhibitor;
367 static WindowManipulationGaugeData m_MemoryExhibitor;
368 static bool m_EditorInitialized;
369 static bool m_RefreshRenderingResources;
370
371 // Content browser
372 static std::filesystem::path m_CurrentDirectory;
373
374 // Need agnostic naming scheme
375 static uint32_t m_DirectoryIcon;
376 static uint32_t m_FileIcon;
377
378 // UObjects statistics
379 static KarmaVector<UObjectsStatistics> m_UObjectStatistics;
380
381 public:
382 static bool m_ViewportFocused;
383 static bool m_ViewportHovered;
384 };
385}
Definition KarmaGuiMesa.h:323
An object class.
Definition Class.h:158
Karma's std::vector wrapper.
Definition KarmaTypes.h:152
Definition KarmaGuiInternal.h:1447
Definition KarmaGuiInternal.h:397
Definition KarmaGui.h:156
Definition KarmaGui.h:1807
Definition KarmaGuiMesa.h:21
Definition KarmaGuiMesa.h:26
Definition KarmaGuiMesa.h:184
Definition KarmaGuiMesa.h:291
Definition KarmaGui.h:2372
Definition KarmaGui.h:2282
Definition KarmaGui.h:2255