This repository was archived by the owner on Dec 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDj-Engine.cpp
More file actions
160 lines (135 loc) · 3.79 KB
/
Dj-Engine.cpp
File metadata and controls
160 lines (135 loc) · 3.79 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
// SPDX-FileCopyrightText: 2021 MatteoGodzilla
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "DJEUtils.h"
#include "Game.h"
#include "MenuNavigator.h"
#include "stb_image.h"
#include <GLFW/glfw3.h>
#include <iostream>
#include <vector>
int WIDTH = 1280;
int HEIGHT = 720;
Game game;
MenuNavigator menu;
//decides if rendering game or menu
int scene = 0;
GLFWwindow* window;
double pastTick = 0.0;
double now = 0.0f;
double deltaTime = 0.0f;
//utility function to handle resizing
void resizeCallback(GLFWwindow* w, int width, int height) {
glViewport(0, 0, width, height);
}
void scrollCallback(GLFWwindow* w, double xoff, double yoff) {
game.getPlayer()->m_scrollX = xoff;
game.getPlayer()->m_scrollY = yoff;
game.getPlayer()->m_changedScroll = true;
}
void errorCallback(int code, const char* description) {
ErrorLog << "GLFW ERROR:(" << code << ")," << description << ENDL;
}
int main(int argc, char** argv) {
NormalLog << "Dj-Engine " << VERSION << ENDL;
if (glfwInit() == GLFW_FALSE) {
const char* description;
int errorCode = glfwGetError(&description);
NormalLog << "Engine Error:GLFW INIT ERROR" << ENDL;
NormalLog << "Error code:" << errorCode << ENDL;
NormalLog << "Error Message:" << description << ENDL;
return -1;
}
NormalLog << "Engine Message: GLFW INIT SUCCESS" << ENDL;
bool MSAActive = false;
if (argc > 1) {
for (int i = 0; i < argc - 1; ++i) {
if (strcmp(argv[i], "--msaa") == 0) {
int factor = std::stoi(argv[i + 1]);
NormalLog << "Engine Message: Creating window with MSAA x" << factor << ENDL;
glfwWindowHint(GLFW_SAMPLES, factor);
MSAActive = true;
}
}
}
//GLFW init functions (window and callbacks)
std::string title = std::string("Dj-Engine ") + VERSION;
window = glfwCreateWindow(WIDTH, HEIGHT, title.c_str(), nullptr, nullptr);
if (!window) {
NormalLog << "Engine Error:GLFW WINDOW CREATION ERROR" << ENDL;
glfwTerminate();
return -1;
}
glfwSetWindowSizeCallback(window, resizeCallback);
glfwSetWindowAspectRatio(window, WIDTH, HEIGHT);
glfwSetErrorCallback(&errorCallback);
//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
if (glfwRawMouseMotionSupported()) {
glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
}
glfwSetScrollCallback(window, scrollCallback);
glfwMakeContextCurrent(window);
int w;
int h;
int n;
unsigned char* data = stbi_load("res/GameIcon.png", &w, &h, &n, 0);
GLFWimage image = {w, h, data};
glfwSetWindowIcon(window, 1, &image);
if (MSAActive) {
glEnable(GL_MULTISAMPLE);
}
//imgui init
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 130");
//setting up menu and game
game.init(window);
menu.init(window, &game);
game.setActive(false);
menu.setActive(true);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
if (scene == 0) {
//change scene if not active
if (!menu.getActive()) {
scene = 1;
game.setActive(true);
}
//render menu
glClearColor(0.13f, 0.21f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
menu.pollInput();
menu.update();
menu.render();
} else if (scene == 1) {
//change scene if not active
if (!game.getActive()) {
scene = 0;
menu.setActive(true);
}
//render/update game
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
game.tick();
game.render();
}
glfwSwapBuffers(window);
if (menu.getShouldClose()) {
glfwSetWindowShouldClose(window, true);
}
}
//imgui shutdown
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
game.stopThread();
glfwTerminate();
}
/*
^ ^ V V < > < > B A Start
Oh no you found the hidden konami code
Please keep this hidden from others.
Do not share
*/