Added settings to CMake
This commit is contained in:
@ -10,9 +10,6 @@
|
||||
bool pokerGameInit(game_t *game) {
|
||||
pokergame_t *pokerGame = &game->pokerGame;
|
||||
|
||||
// Init the game
|
||||
game->name = POKER_GAME_NAME;
|
||||
|
||||
// Load the Assets
|
||||
pokerGameAssetsInit(&pokerGame->assets);
|
||||
|
||||
|
@ -1,126 +0,0 @@
|
||||
// Copyright (c) 2021 Dominic Msters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "glwfwplatform.h"
|
||||
|
||||
game_t *GAME_STATE;
|
||||
|
||||
GLFWwindow *window = NULL;
|
||||
|
||||
int32_t main() {
|
||||
// Attempt to init GLFW
|
||||
if(!glfwInit()) return 1;
|
||||
|
||||
// Setup window hints
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
|
||||
|
||||
// Create Window
|
||||
window = glfwCreateWindow(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT,
|
||||
"", NULL, NULL
|
||||
);
|
||||
if(!window) {
|
||||
glfwTerminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Load GLAD
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(0);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
// Setup window listeners
|
||||
glfwSetWindowSizeCallback(window, &glfwOnResize);
|
||||
glfwSetKeyCallback(window, &glfwOnKey);
|
||||
|
||||
glfwSetErrorCallback(&glfwOnError);
|
||||
|
||||
// Prepare the game
|
||||
game_t *game = malloc(sizeof(game_t));
|
||||
GAME_STATE = game;
|
||||
input_t *input = &game->engine.input;
|
||||
|
||||
printf("Game is %zu bytes.\n", sizeof(game_t));
|
||||
|
||||
// Init the render resolution
|
||||
renderSetResolution(&game->engine.render,
|
||||
WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT
|
||||
);
|
||||
|
||||
// Init the game
|
||||
if(gameInit(game)) {
|
||||
// Bind initial keys
|
||||
inputBind(input, INPUT_NULL, (inputsource_t)GLFW_KEY_ESCAPE);
|
||||
inputBind(input, INPUT_DEBUG_UP, (inputsource_t)GLFW_KEY_W);
|
||||
inputBind(input, INPUT_DEBUG_DOWN, (inputsource_t)GLFW_KEY_S);
|
||||
inputBind(input, INPUT_DEBUG_LEFT, (inputsource_t)GLFW_KEY_A);
|
||||
inputBind(input, INPUT_DEBUG_RIGHT, (inputsource_t)GLFW_KEY_D);
|
||||
inputBind(input, INPUT_DEBUG_RAISE, (inputsource_t)GLFW_KEY_Q);
|
||||
inputBind(input, INPUT_DEBUG_LOWER, (inputsource_t)GLFW_KEY_E);
|
||||
inputBind(input, INPUT_DEBUG_FINE, (inputsource_t)GLFW_KEY_LEFT_CONTROL);
|
||||
inputBind(input, INPUT_DEBUG_PLUS, (inputsource_t)GLFW_KEY_EQUAL);
|
||||
inputBind(input, INPUT_DEBUG_MINUS, (inputsource_t)GLFW_KEY_MINUS);
|
||||
|
||||
inputBind(input, INPUT_UP, (inputsource_t)GLFW_KEY_UP);
|
||||
inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_DOWN);
|
||||
inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_LEFT);
|
||||
inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_RIGHT);
|
||||
inputBind(input, INPUT_UP, (inputsource_t)GLFW_KEY_W);
|
||||
inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_S);
|
||||
inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_A);
|
||||
inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_D);
|
||||
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_E);
|
||||
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_ENTER);
|
||||
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_SPACE);
|
||||
|
||||
// Update the window title.
|
||||
glfwSetWindowTitle(window, GAME_STATE->name);
|
||||
|
||||
double time = 0;
|
||||
|
||||
// Main Render Loop
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
// Determine the delta.
|
||||
double newTime = glfwGetTime();
|
||||
float fDelta = (float)(newTime - time);
|
||||
time = newTime;
|
||||
|
||||
// Tick the engine.
|
||||
if(!gameUpdate(game, fDelta)) break;
|
||||
glfwSwapBuffers(window);
|
||||
sleep(0);//Fixes some weird high CPU bug, not actually necessary.
|
||||
}
|
||||
|
||||
// Game has finished running, cleanup.
|
||||
gameDispose(game);
|
||||
}
|
||||
free(game);
|
||||
|
||||
// Terminate the GLFW context.
|
||||
glfwSetWindowSizeCallback(window, NULL);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
|
||||
renderSetResolution(&GAME_STATE->engine.render, width, height);
|
||||
}
|
||||
|
||||
void glfwOnKey(GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
) {
|
||||
input_t *input = &GAME_STATE->engine.input;
|
||||
if(action == GLFW_PRESS) {
|
||||
input->buffer[key] = 1;
|
||||
} else if(action == GLFW_RELEASE) {
|
||||
input->buffer[key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void glfwOnError(int error, const char* description) {
|
||||
fputs(description, stderr);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2021 Dominic Msters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
// I load GLAD and GLFW Here because they need to be included in specific orders
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <dawn/dawn.h>
|
||||
#include "../../display/render.h"
|
||||
#include "../../game/game.h"
|
||||
#include "../../input/input.h"
|
||||
|
||||
#define WINDOW_WIDTH_DEFAULT 1280
|
||||
#define WINDOW_HEIGHT_DEFAULT WINDOW_WIDTH_DEFAULT/16*9
|
||||
|
||||
/** The current running game state. */
|
||||
extern game_t *GAME_STATE;
|
||||
|
||||
/** The GLFW Window Context Pointer */
|
||||
extern GLFWwindow *window;
|
||||
|
||||
/**
|
||||
* Entry of the program
|
||||
* @return 0 if success, anything else for failure.
|
||||
*/
|
||||
int32_t main();
|
||||
|
||||
/**
|
||||
* Resize callbacks.
|
||||
*
|
||||
* @param window Window that was resized.
|
||||
* @param width New window width.
|
||||
* @param height New window height.
|
||||
*/
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
||||
|
||||
/**
|
||||
* Keyboard Input callbacks.
|
||||
*
|
||||
* @param window Window that was resized.
|
||||
*/
|
||||
void glfwOnKey(GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
);
|
||||
|
||||
|
||||
void glfwOnError(int error, const char* description);
|
Reference in New Issue
Block a user