Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
240 lines (192 loc) · 7.04 KB
/
Copy pathmain.cpp
File metadata and controls
240 lines (192 loc) · 7.04 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "FEEditor.h"
#include "SubSystems/PluginSystem/FEEditorPluginManager.h"
void OnTriggerRelease()
{
int y = 0;
y++;
FEOpenXR_INPUT.TriggerHapticFeedback(0.5f, 0.5f, 0.5f, false);
//std::string test = FEOpenXR_INPUT.CurrentlyActiveInteractionProfile(true);
//test = ";";
}
void OnSomething(float Value)
{
int y = 0;
y++;
FEOpenXR_INPUT.TriggerHapticFeedback(0.5f, 0.5f, 0.5f, false);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ENGINE.InitWindow();
EDITOR.InitializeResources();
THREAD_POOL.SetConcurrentThreadCount(THREAD_POOL.GetLogicalCoreCount());
NODE_SYSTEM.Initialize();
EDITOR_PLUGIN_MANAGER.Initialize();
const int FrameCountTillMeasure = 20;
double CPUFrameDurations[FrameCountTillMeasure] = { 0.0f };
double GPUFrameDurations[FrameCountTillMeasure] = { 0.0f };
double FrameDurations[FrameCountTillMeasure] = { 0.0 };
int FrameCounter = 0;
double AverageCpuFrameDuration = 0.0;
double AverageGpuFrameDuration = 0.0;
double AverageFrameDuration = 0.0;
bool bPutThisFrameToTimeline = false;
/*FEOpenXR_INPUT.SetLeftTriggerReleaseCallBack(OnTriggerRelease);
FEOpenXR_INPUT.SetRightTriggerReleaseCallBack(OnTriggerRelease);*/
FEOpenXR_INPUT.SetLeftValveSqueezeValueCallBack(OnSomething);
const std::string FrameTimeStampLabel = "EditorFrame";
TIME.BeginTimeStamp(FrameTimeStampLabel);
while (ENGINE.IsNotTerminated())
{
const double PreviousFrameDuration = TIME.EndTimeStamp(FrameTimeStampLabel);
TIME.BeginTimeStamp(FrameTimeStampLabel);
PROFILING.StartProfiling();
ENGINE.BeginFrame();
EDITOR.UpdateBeforeRender();
ENGINE.Render();
#ifdef EDITOR_SELECTION_DEBUG_MODE
if (EDITOR.GetFocusedScene() != nullptr)
{
FESelectionData* SelectedData = SELECTED.GetSceneData(EDITOR.GetFocusedScene()->GetID());
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: ";
FEEntity* HoveredEntity = nullptr;
if (SelectedData->ColorIndex != -1 && SelectedData->ColorIndex < SelectedData->SceneEntitiesUnderMouse.size())
HoveredEntity = EDITOR.GetFocusedScene()->GetEntity(SelectedData->SceneEntitiesUnderMouse[SelectedData->ColorIndex]);
if (HoveredEntity != nullptr)
{
EntityUnderMouse += HoveredEntity->GetName();
}
else
{
EntityUnderMouse += "None";
}
ImGui::Text(EntityUnderMouse.c_str());
ImGui::Image(SelectedData->PixelAccurateSelectionFB->GetColorAttachment()->GetTextureID(), ImVec2(256 * 4, 256 * 4), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f));
}
}
#endif
// Shown in the debug window, it is turned on in Window menu of the editor.
if (EDITOR.IsDebugWindowVisible())
{
if (ImGui::Button("Put This Frame To Timeline"))
{
bPutThisFrameToTimeline = true;
}
bool bVRMode = ENGINE.IsVREnabled();
if (ImGui::Checkbox("Enter VR mode", &bVRMode))
{
if (bVRMode)
{
if (ENGINE.EnableVR())
{
std::vector<FEOpenXRExtensionInfo> ExtensionsInfo = FEOpenXR_CORE.GetAvailableExtensionsInfo();
int y = 0;
y++;
//glm::vec2 VRResolution = OpenXR_MANAGER.EyeResolution();
//POINT_MANAGER.RenderTargetResize(static_cast<int>(VRResolution.x), static_cast<int>(VRResolution.y));
//AddVirtualUI();
}
}
else
{
ENGINE.DisableVR();
//POINT_MANAGER.RenderTargetResize(static_cast<int>(ENGINE.GetRenderTargetWidth()), static_cast<int>(ENGINE.GetRenderTargetHeight()));
}
}
if (bVRMode)
{
glm::vec3 ControllerPosition = FEOpenXR_INPUT.GetLeftControllerPosition();
ImGui::Text("Left Controller Position : ");
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##X Left Controller", &ControllerPosition[0], 0.01f);
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##Y Left Controller", &ControllerPosition[1], 0.01f);
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##Z Left Controller", &ControllerPosition[2], 0.01f);
ControllerPosition = FEOpenXR_INPUT.GetRightControllerPosition();
ImGui::Text("Right Controller Position : ");
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##X Right Controller", &ControllerPosition[0], 0.01f);
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##Y Right Controller", &ControllerPosition[1], 0.01f);
ImGui::SameLine();
ImGui::SetNextItemWidth(70);
ImGui::DragFloat("##Z Right Controller", &ControllerPosition[2], 0.01f);
if (ImGui::Button("Haptic"))
{
FEOpenXR_INPUT.TriggerHapticFeedback(0.5f, 0.5f, 0.5f, false);
}
}
}
//ImGui::ShowDemoWindow();
EDITOR.Render();
ENGINE.EndFrame();
// Engine time is BeginFrame with Render, present time is EndFrame.
CPUFrameDurations[FrameCounter] = ENGINE.GetCpuTime();
GPUFrameDurations[FrameCounter] = ENGINE.GetGpuTime();
FrameDurations[FrameCounter] = PreviousFrameDuration;
FrameCounter++;
if (FrameCounter > FrameCountTillMeasure - 1)
{
AverageCpuFrameDuration = 0.0f;
AverageGpuFrameDuration = 0.0f;
AverageFrameDuration = 0.0;
for (size_t i = 0; i < FrameCountTillMeasure; i++)
{
AverageCpuFrameDuration += CPUFrameDurations[i];
AverageGpuFrameDuration += GPUFrameDurations[i];
AverageFrameDuration += FrameDurations[i];
}
AverageCpuFrameDuration /= FrameCountTillMeasure;
AverageGpuFrameDuration /= FrameCountTillMeasure;
AverageFrameDuration /= FrameCountTillMeasure;
FrameCounter = 0;
}
const auto ToCaptionString = [](const double Milliseconds) {
std::string Result = std::to_string(Milliseconds);
const size_t DotPosition = Result.find('.');
if (DotPosition != std::string::npos)
Result.erase(DotPosition >= 3 ? DotPosition : 4);
return Result;
};
// What is left of the frame is the editor user interface.
double AverageEditorDuration = AverageFrameDuration - AverageCpuFrameDuration - AverageGpuFrameDuration;
if (AverageEditorDuration < 0.0)
AverageEditorDuration = 0.0;
const std::string CPUMs = ToCaptionString(AverageCpuFrameDuration);
const std::string GPUMs = ToCaptionString(AverageGpuFrameDuration);
const std::string FrameMs = ToCaptionString(AverageFrameDuration);
const std::string EditorMs = ToCaptionString(AverageEditorDuration);
std::string Caption = "Engine : ";
Caption += CPUMs;
Caption += " ms";
Caption += " Editor UI : ";
Caption += EditorMs;
Caption += " ms";
Caption += " Present : ";
Caption += GPUMs;
Caption += " ms";
Caption += " Frame : ";
Caption += FrameMs;
Caption += " ms";
ENGINE.SetWindowCaption(Caption.c_str());
PROFILING.StopProfiling();
if (bPutThisFrameToTimeline)
{
PROFILING.SaveTimelineToJSON("timeline.json");
bPutThisFrameToTimeline = false;
}
}
PLUGIN_MANAGER.Shutdown();
return 0;
}