-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.hpp
120 lines (93 loc) · 3.36 KB
/
engine.hpp
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
#ifndef __ENGINE__
#define __ENGINE__
#include <memory>
#include <fmt/format.h>
#define GLEW_STATIC
#define GLM_FORCE_RADIANS
#include <GL/glew.h>
#include "app.hpp"
#include "meta.hpp"
#include "tools/logger.hpp"
#include "core/window/base.hpp"
#include "core/window/glfw.hpp"
#include "core/render/api.hpp"
using namespace Tool::Logger;
namespace Engine {
class Engine {
/**
* Main engine class.
*
* When used, the engine must have a custom user application.
* Further work of the engine comes down to starting
* main loop and updating managers and the user application.
*/
private:
EngineApplication *app;
public:
std::unique_ptr<Logger> logger = std::make_unique<Logger>("engine");
Engine(EngineApplication *application) {
logger->trace(std::string("constructor"));
this->app = application;
}
void Startup() {
/**
* Engine initialization.
*
* At this stage, the engine initializes the user application
* and all managers. Also at this stage, it is possible to check
* for the initialization of managers.
*/
// Initialize all managers and then initialize the application
// since the application can change the settings of managers.
app->window->Startup();
app->Startup();
logger->info(fmt::format("engine version: {}", ENGINE_VERSION));
logger->info(fmt::format("glsl version: {}", GLSL_VERSION));
switch (Render::Render::GetInstance()->GetBackendAPI()) {
case Render::Backend::OPENGL:
logger->info("backend API: OpenGL");
break;
default:
logger->critical("unknown render backend API");
}
}
void Run() {
/**
* Main engine loop.
*
* As long as the application window is open, engine
* continues updating user application and all managers.
*/
float deltaTime = 0.0f, lastFrame = 0.0f;
app->window->Create();
app->editor->Startup(app);
// TODO: Move all gl* functions to the render backend
glewExperimental = GL_TRUE;
glewInit();
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
app->render->Startup();
app->scene->startup();
app->Run();
while (app->window->IsOpen()) {
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
app->Update(deltaTime);
app->editor->Update();
// TODO: Uncomment after move camera as part of scene
// app->render->RenderScene(app->scene);
app->window->Update();
}
logger->info("shutdown...");
app->Shutdown();
app->render->Shutdown();
app->editor->Shutdown();
app->window->Shutdown();
}
};
}
#endif