-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (100 loc) · 3.44 KB
/
main.cpp
File metadata and controls
123 lines (100 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "FEEditor.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ENGINE.InitWindow();
EDITOR.InitializeResources();
THREAD_POOL.SetConcurrentThreadCount(10);
NODE_SYSTEM.Initialize();
const int FrameCountTillMeasure = 20;
double CPUFrameDurations[FrameCountTillMeasure] = { 0.0f };
double GPUFrameDurations[FrameCountTillMeasure] = { 0.0f };
int FrameCounter = 0;
double AverageCpuFrameDuration = 0.0;
double AverageGpuFrameDuration = 0.0;
bool bPutThisFrameToTimeline = false;
while (ENGINE.IsNotTerminated())
{
PROFILING.StartProfiling();
ENGINE.BeginFrame();
EDITOR.UpdateBeforeRender();
ENGINE.Render();
#ifdef EDITOR_SELECTION_DEBUG_MODE
if (EDITOR.GetFocusedScene() != nullptr)
{
FESelectionData* SelectedData = SELECTED.GetSceneData(EDITOR.GetFocusedScene()->GetObjectID());
if (SelectedData != nullptr)
{
std::string ObjectsUnderMouse = "Count of considered entities: " + std::to_string(SelectedData->SceneEntitiesUnderMouse.size());
ImGui::Text(ObjectsUnderMouse.c_str());
std::string ColorIndex = "ColorIndex: " + std::to_string(SelectedData->ColorIndex);
ImGui::Text(ColorIndex.c_str());
std::string EntityUnderMouse = "Entity under mouse: ";
if (SelectedData->ColorIndex != -1 && SelectedData->ColorIndex < SelectedData->SceneEntitiesUnderMouse.size())
{
EntityUnderMouse += SelectedData->SceneEntitiesUnderMouse[SelectedData->ColorIndex]->GetName();
}
else
{
EntityUnderMouse += "None";
}
ImGui::Text(EntityUnderMouse.c_str());
ImGui::Image((void*)(intptr_t)SelectedData->PixelAccurateSelectionFB->GetColorAttachment()->GetTextureID(), ImVec2(256 * 4, 256 * 4), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f));
}
}
#endif
if (ImGui::Button("Put This Frame To Timeline"))
{
bPutThisFrameToTimeline = true;
}
if (PROJECT_MANAGER.GetCurrent() != nullptr)
{
if (ImGui::Button("Build"))
{
EDITOR_PROJECT_BUILD_SYSTEM.BuildExecutable(PROJECT_MANAGER.GetCurrent());
}
}
//ImGui::ShowDemoWindow();
EDITOR.Render();
ENGINE.EndFrame();
// CPU and GPU Time
CPUFrameDurations[FrameCounter] = ENGINE.GetCpuTime();
GPUFrameDurations[FrameCounter] = ENGINE.GetGpuTime();
FrameCounter++;
if (FrameCounter > FrameCountTillMeasure - 1)
{
AverageCpuFrameDuration = 0.0f;
AverageGpuFrameDuration = 0.0f;
for (size_t i = 0; i < FrameCountTillMeasure; i++)
{
AverageCpuFrameDuration += CPUFrameDurations[i];
AverageGpuFrameDuration += GPUFrameDurations[i];
}
AverageCpuFrameDuration /= FrameCountTillMeasure;
AverageGpuFrameDuration /= FrameCountTillMeasure;
FrameCounter = 0;
}
std::string CPUMs = std::to_string(AverageCpuFrameDuration);
CPUMs.erase(CPUMs.begin() + 4, CPUMs.end());
std::string GPUMs = std::to_string(AverageGpuFrameDuration);
GPUMs.erase(GPUMs.begin() + 4, GPUMs.end());
std::string FrameMs = std::to_string(AverageCpuFrameDuration + AverageGpuFrameDuration);
FrameMs.erase(FrameMs.begin() + 4, FrameMs.end());
std::string caption = "CPU time : ";
caption += CPUMs;
caption += " ms";
caption += " GPU time : ";
caption += GPUMs;
caption += " ms";
caption += " Frame time : ";
caption += FrameMs;
caption += " ms";
ENGINE.SetWindowCaption(caption.c_str());
PROFILING.StopProfiling();
if (bPutThisFrameToTimeline)
{
PROFILING.SaveTimelineToJSON("timeline.json");
bPutThisFrameToTimeline = false;
}
}
return 0;
}