Added input manager final version

This commit is contained in:
2021-02-25 00:00:49 +11:00
parent 700a1b8c7f
commit 90fa9d8314
9 changed files with 84 additions and 40 deletions

View File

@ -5,19 +5,18 @@
#include "glwfwplatform.h"
GLFWwindow *window;
game_t *runningGame;
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 = 0,
.inputValues = NULL,
.inputSource = NULL
.inputSourceCount = 400
};
// Attempt to init GLFW
@ -46,9 +45,13 @@ int32_t main() {
engine_t *engine = gameGetEngine(runningGame);
glfwSetWindowTitle(window, engine->name);
// Bind inputs
inputBind(engine->input, INPUT_NULL, (inputsource_t *)GLFW_KEY_ESCAPE);
// Main Render Loop
while(!glfwWindowShouldClose(window)) {
gameUpdate(runningGame);
glfwSwapBuffers(window);
glfwPollEvents();
}
@ -73,8 +76,12 @@ void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
void glfwOnKey(GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
) {
float force = action == GLFW_PRESS ? 1 : 0;
if(runningGame == NULL) return;
engine_t *engine = gameGetEngine(runningGame);
engine->input->current[scancode] = force;
if(action == GLFW_PRESS) {
engine->input->buffer[key] = 1;
} else if(action == GLFW_RELEASE) {
engine->input->buffer[key] = 0;
}
}