Added input manager final version
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
#include <stdint.h>
|
||||
#include "../../engine/platform.h"
|
||||
#include "../../engine/game/game.h"
|
||||
#include "../../engine/input/input.h"
|
||||
#include "../../engine/display/render.h"
|
||||
|
||||
#define WINDOW_WIDTH_DEFAULT 480
|
||||
|
Reference in New Issue
Block a user