Polyphase Game Engine
Loading...
Searching...
No Matches
ProfilingWindow.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <deque>
6#include <vector>
7#include <string>
9#include "EngineTypes.h"
10#include "imgui.h"
11
12// Frame history buffer size (~2 seconds at 60fps)
13constexpr uint32_t kFrameHistorySize = 120;
14
15// Custom stat registered by addons
16struct CustomProfilingStat
17{
18 uint64_t mHookId = 0;
19 std::string mName;
20 std::string mCategory;
21 float mValue = 0.0f;
22 float mMaxValue = 16.67f;
23 bool mShowAsBar = true;
24};
25
26// Custom section registered by addons
27struct CustomProfilingSection
28{
29 uint64_t mHookId = 0;
30 std::string mName;
31 void (*mDrawCallback)(void*) = nullptr;
32 void* mUserData = nullptr;
33};
34
35class ProfilingWindow
36{
37public:
38 void Draw();
39 void DrawContent();
40 void Tick();
41
42 // Addon extension API
43 void RegisterCustomStat(uint64_t hookId, const char* name, const char* category, float maxValue, bool showAsBar);
44 void UnregisterCustomStat(uint64_t hookId, const char* name);
45 void SetCustomStatValue(const char* name, float value);
46
47 void RegisterCustomSection(uint64_t hookId, const char* name, void (*drawFunc)(void*), void* userData);
48 void UnregisterCustomSection(uint64_t hookId, const char* name);
49
50 void RemoveAllHooks(uint64_t hookId);
51
52 // Section visibility toggles
53 bool mShowFPS = true;
54 bool mShowCpuStats = true;
55 bool mShowGpuStats = true;
56 bool mShowMemory = true;
57 bool mShowFrameGraph = true;
58
59private:
60 // Frame time history for graph
61 std::deque<float> mFrameTimeHistory;
62
63 // Smoothed values
64 float mSmoothedFPS = 60.0f;
65 float mSmoothedFrameTime = 16.67f;
66 float mMinFrameTime = 16.67f;
67 float mMaxFrameTime = 16.67f;
68 float mAvgFrameTime = 16.67f;
69
70 // Frame graph scale (0=Auto, 1=16.67ms, 2=33.33ms, 3=50ms, 4=100ms, 5=200ms)
71 int mFrameGraphScaleIndex = 0;
72
73 // Custom addon stats and sections
74 std::vector<CustomProfilingStat> mCustomStats;
75 std::vector<CustomProfilingSection> mCustomSections;
76
77 // Drawing helpers
78 void DrawFPSSection();
79 void DrawCpuStatsSection();
80 void DrawGpuStatsSection();
81 void DrawMemorySection();
82 void DrawFrameGraph();
83 void DrawCustomStatsSection();
84 void DrawCustomSections();
85
86 void DrawStatBar(const char* name, float value, float maxValue, const ImVec4& color);
87 void DrawMemoryBar(const char* label, uint64_t used, uint64_t total, const ImVec4& color);
88
89 uint64_t GetPlatformTotalMemoryBytes() const;
90 const char* GetPlatformName() const;
91
92 // Estimated memory calculation for target platform
93 struct EstimatedMemory
94 {
95 uint64_t mTextures = 0;
96 uint64_t mMeshes = 0;
97 uint64_t mSkeletalMeshes = 0;
98 uint64_t mAudio = 0;
99 uint64_t mRenderTargets = 0;
100 uint64_t mOther = 0;
101
102 uint64_t Total() const { return mTextures + mMeshes + mSkeletalMeshes + mAudio + mRenderTargets + mOther; }
103 };
104
105 EstimatedMemory EstimateMemoryForPlatform(Platform platform) const;
106 uint64_t GetBytesPerPixelForPlatform(Platform platform) const;
107 uint32_t GetIndexSizeForPlatform(Platform platform) const;
108};
109
110ProfilingWindow* GetProfilingWindow();
111
112#endif
Platform
Definition EngineTypes.h:31
void Tick()
Definition HttpClient.cpp:202