-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyGame.cpp
More file actions
110 lines (87 loc) · 2.07 KB
/
MyGame.cpp
File metadata and controls
110 lines (87 loc) · 2.07 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
#include "pch.h"
#include "MyGame.h"
#include "Components.h"
#include "Serialize.h"
#include "AllComponents.h"
#include "ImGuiManager.h"
#include "Widgets.h"
int MyGame::Bench()
{
//constexpr long count = 100'000'000L;
//{
// std::cout << "Performance Test" << std::endl;
// auto t1 = std::chrono::high_resolution_clock::now();
// for (long i = 0; i < count; i++)
// {
// auto& camera = GameContext::Get<Camera>();
// }
// auto t2 = std::chrono::high_resolution_clock::now();
// auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
// std::cout << "Finish in " << duration / 1'000'000.f << " (" << duration / (float)count << "μs)" << std::endl;
//}
return 0;
}
MyGame::MyGame()
{
Components::InitializeEvents();
m_scene.name = "scene";
m_scene.location = m_scene.name + ".json";
m_scene.Load();
// Widgets
Widgets::AllWidgets::Initialize(m_scene);
GameContext::Register<TransformResolver>();
}
MyGame::~MyGame()
{
GameContext::Remove<TransformResolver>();
}
void MyGame::Update()
{
Updatable::Update(m_scene);
}
class MyGame::ImGuiPtr
{
public:
ImGuiPtr()
{
// ImGuiコンテキスト
auto imgui = GameContext::Register<ImGuiManager>();
// ImGui初期化
imgui.RenderInitialize();
}
~ImGuiPtr()
{
// ImGuiコンテキスト
auto& imgui = GameContext::Get<ImGuiManager>();
// ImGuiファイナライズ
imgui.RenderFinalize();
// ImGui削除
GameContext::Remove<ImGuiManager>();
}
};
void MyGame::RenderInitialize()
{
m_imgui = std::make_unique<ImGuiPtr>();
Renderable::RenderInitialize(m_scene);
}
void MyGame::Render(Camera& camera)
{
static int bench = Bench();
// トランスフォームのキャッシュをクリア
GameContext::Get<TransformResolver>().ClearCache();
// 描画イベント
Renderable::Render(m_scene, std::forward<Camera>(camera));
// ImGui
{
// ImGuiコンテキスト
auto& imgui = GameContext::Get<ImGuiManager>();
// ImGui描画開始
imgui.Begin();
// GUI描画イベント
Renderable::RenderGui(m_scene, std::forward<Camera>(camera));
// Widgets
Widgets::AllWidgets::Render(m_scene);
// ImGui描画終了
imgui.End();
}
}