Refactored.

This commit is contained in:
2021-04-22 13:55:34 +10:00
parent c10754f31b
commit f7c1380f06
62 changed files with 1033 additions and 1391 deletions

View File

@ -9,19 +9,9 @@ GLFWwindow *window = NULL;
game_t *runningGame = NULL;
int32_t main() {
// Create out platform context
platform_t platform = {
.name = "glfw",
.screenWidth = WINDOW_WIDTH_DEFAULT,
.screenHeight = WINDOW_HEIGHT_DEFAULT,
.inputSourceCount = 400
};
// Attempt to init GLFW
if(!glfwInit()) return NULL;
window = glfwCreateWindow(platform.screenWidth, platform.screenHeight,
window = glfwCreateWindow(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT,
"", NULL, NULL
);
if(!window) {
@ -37,28 +27,28 @@ int32_t main() {
glfwSetWindowSizeCallback(window, &glfwOnResize);
glfwSetKeyCallback(window, &glfwOnKey);
// Create the game instance
runningGame = gameInit(&platform);
if(runningGame == NULL) return 1;
// Init the game
if(gameInit()) {
// Bind initial keys
inputBind(INPUT_NULL, (inputsource_t)GLFW_KEY_ESCAPE);
// Update the window title.
glfwSetWindowTitle(window, runningGame->engine->name);
// Init the render resolution
renderSetResolution(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT);
// Bind inputs
inputBind(runningGame->engine->input, INPUT_NULL,
(inputsource_t *)GLFW_KEY_ESCAPE
);
// Update the window title.
glfwSetWindowTitle(window, GAME_STATE.name);
// Main Render Loop
while(!glfwWindowShouldClose(window)) {
gameUpdate(runningGame);
// Main Render Loop
while(!glfwWindowShouldClose(window)) {
if(!gameUpdate()) break;
glfwSwapBuffers(window);
glfwPollEvents();
glfwSwapBuffers(window);
glfwPollEvents();
}
// Game has finished running, cleanup.
gameDispose();
}
// Game has finished running, cleanup.
gameDispose(runningGame);
// Terminate the GLFW context.
glfwSetWindowSizeCallback(window, NULL);
@ -68,19 +58,15 @@ int32_t main() {
}
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
runningGame->engine->platform->screenWidth = width;
runningGame->engine->platform->screenWidth = height;
renderSetResolution(runningGame->engine->render, width, height);
renderSetResolution(width, height);
}
void glfwOnKey(GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
) {
if(runningGame == NULL) return;
if(action == GLFW_PRESS) {
runningGame->engine->input->buffer[key] = 1;
INPUT_STATE.buffer[key] = 1;
} else if(action == GLFW_RELEASE) {
runningGame->engine->input->buffer[key] = 0;
INPUT_STATE.buffer[key] = 0;
}
}