Repository navigation
Expand file tree
/
Copy pathminecraft.cpp
More file actions
114 lines (81 loc) · 1.87 KB
/
Copy pathminecraft.cpp
File metadata and controls
114 lines (81 loc) · 1.87 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
#include <iostream>
#include "libs/glad/glad.h" //MUST be included before glfw (glfw checks for it)
#include <GLFW/glfw3.h>
//#define GLFW_EXPOSE_NATIVE_WIN32 //why. WHY DOES ORDER MATTER
//#include <GLFW/glfw3native.h>
#include "query.h"
#include "orchestrator.h"
#include "demoSys.h"
#include "system.h"
#include "window.h"
#include "input.h"
#include "time.h"
#include <thread>
#include <chrono>
#include "sys/cameraSys.h"
#include "demoCameraRenderingSys.h"
class Registry;
template <typename... Components>
class Query;
class Minecraft {
public:
void run() {
Debug::log("Start");
initEngine();
initGame();
time.recordStart();
while (!orch.hasEnded()) {
if (window.shouldEnd) {
orch.end();
}
mainLoop();
}
Debug::log("game loop ended, exiting");
}
Minecraft()
: orch(reg),
ec(EngineContext{ reg, orch, input, shaderLoader, window, time }),
window(&glfwWindow),
input(&glfwWindow)
{
}
private:
GLFWwindow* glfwWindow;
VertexShaderLoader vertexShaderLoader;
FragShaderLoader fragShaderLoader;
Time time;
Window window;
Input input;
Registry reg;
Orchestrator orch;
ShaderFileLoader shaderLoader{ vertexShaderLoader, fragShaderLoader };
EngineContext ec;
void initEngine() {
window.init();
}
void mainLoop() {
input.update();
window.update();
orch.update();
time.update(); //comes last, gives deltatime
//std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
void initGame() { //for now, systems are run in the order they're added
std::shared_ptr<CameraSys> cam(new CameraSys(ec));
orch.addSystem(cam);
std::shared_ptr<ISystem> s8(new DemoCameraRenderingSys(ec));
orch.addSystem(s8);
}
};
//yes, this needs to be at the end
int main() {
Minecraft app;
try {
app.run();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}