-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppWindow.cpp
More file actions
112 lines (87 loc) · 2.5 KB
/
AppWindow.cpp
File metadata and controls
112 lines (87 loc) · 2.5 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
#include "AppWindow.h"
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
#include "Cube.h"
#include "Vector3D.h"
#include "EngineTime.h"
#include "GameObjectManager.h"
#include "GraphicsEngine.h"
#include "InputSystem.h"
#include "MathUtils.h"
#include "Matrix4x4.h"
#include "SceneCameraHandler.h"
#include "imgui.h"
#include "imgui_impl_win32.h"
#include "imgui_impl_dx11.h"
#include "UIManager.h"
#include <reactphysics3d/reactphysics3d.h>
#include "PhysicsSystem.h"
#include "ShaderLibrary.h"
#include "TextureManager.h"
using namespace reactphysics3d;
void AppWindow::onCreate()
{
initializeEngine();
initializeUI();
}
void AppWindow::onUpdate()
{
ticks += EngineTime::getDeltaTime() * 1.0f;
InputSystem::getInstance()->update();
GraphicsEngine::get()->getImmediateDeviceContext()->clearRenderTargetColor(m_swap_chain, 0.2f, 0.2f, 0.2f, 1);
RECT rc = getClientWindowRect();
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
GraphicsEngine::get()->getImmediateDeviceContext()->setViewportSize(width, height);
// Update rest of the systems
GameObjectManager::getInstance()->updateAll();
BaseComponentSystem::getInstance()->getPhysicsSystem()->updateAllComponents();
GameObjectManager::getInstance()->renderAll(width, height);
SceneCameraHandler::getInstance()->update();
UIManager::getInstance()->drawAllUI();
m_swap_chain->present(true);
}
void AppWindow::onDestroy()
{
Window::onDestroy();
m_swap_chain->release();
m_vertex_buffer->release();
m_index_buffer->release();
m_constant_buffer->release();
m_vertex_shader->release();
m_pixel_shader->release();
InputSystem::destroy();
ShaderLibrary::destroy();
TextureManager::destroy();
BaseComponentSystem::destroy();
GameObjectManager::destroy();
GraphicsEngine::get()->release();
UIManager::destroy();
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
}
void AppWindow::initializeEngine()
{
GraphicsEngine::get()->init();
EngineTime::initialize();
TextureManager::initialize();
ShaderLibrary::initialize();
InputSystem::initialize();
m_swap_chain = GraphicsEngine::get()->createSwapChain();
RECT rc = getClientWindowRect();
std::cout << "hwnd: " << this->m_hwnd;
m_swap_chain->init(this->m_hwnd, rc.right - rc.left, rc.bottom - rc.top);
GameObjectManager::initialize();
BaseComponentSystem::initialize();
SceneCameraHandler::initialize();
}
void AppWindow::initializeUI()
{
UIManager::initialize(this->m_hwnd);
}
AppWindow::AppWindow()
= default;
AppWindow::~AppWindow()
= default;