Cleaned some code, drastically reduced memory footprint.
This commit is contained in:
@ -6,7 +6,6 @@
|
||||
#include "glwfwplatform.h"
|
||||
|
||||
game_t *GAME_STATE;
|
||||
|
||||
GLFWwindow *window = NULL;
|
||||
|
||||
int32_t main() {
|
||||
@ -51,34 +50,22 @@ int32_t main() {
|
||||
// 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);
|
||||
inputBind(input, INPUT_MOUSE_X, GLFW_PLATFORM_INPUT_MOUSE_X);
|
||||
inputBind(input, INPUT_MOUSE_Y, GLFW_PLATFORM_INPUT_MOUSE_Y);
|
||||
inputBind(input, INPUT_NULL, glfwGetInputSourceForKey(GLFW_KEY_ESCAPE));
|
||||
inputBind(input, INPUT_UP, glfwGetInputSourceForKey(GLFW_KEY_UP));
|
||||
inputBind(input, INPUT_DOWN, glfwGetInputSourceForKey(GLFW_KEY_DOWN));
|
||||
inputBind(input, INPUT_LEFT, glfwGetInputSourceForKey(GLFW_KEY_LEFT));
|
||||
inputBind(input, INPUT_RIGHT, glfwGetInputSourceForKey(GLFW_KEY_RIGHT));
|
||||
inputBind(input, INPUT_UP, glfwGetInputSourceForKey(GLFW_KEY_W));
|
||||
inputBind(input, INPUT_DOWN, glfwGetInputSourceForKey(GLFW_KEY_S));
|
||||
inputBind(input, INPUT_LEFT, glfwGetInputSourceForKey(GLFW_KEY_A));
|
||||
inputBind(input, INPUT_RIGHT, glfwGetInputSourceForKey(GLFW_KEY_D));
|
||||
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_E));
|
||||
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_ENTER));
|
||||
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_SPACE));
|
||||
|
||||
// Bind the fake inputs
|
||||
inputBind(input, INPUT_MOUSE_X, (inputsource_t)INPUT_MOUSE_X);
|
||||
inputBind(input, INPUT_MOUSE_Y, (inputsource_t)INPUT_MOUSE_Y);
|
||||
inputBind(input, INPUT_MOUSE_X, GLFW_PLATFORM_INPUT_MOUSE_X);
|
||||
inputBind(input, INPUT_MOUSE_Y, GLFW_PLATFORM_INPUT_MOUSE_Y);
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
|
||||
// Update the window title.
|
||||
@ -122,9 +109,9 @@ void glfwOnKey(GLFWwindow *window,
|
||||
) {
|
||||
input_t *input = &GAME_STATE->engine.input;
|
||||
if(action == GLFW_PRESS) {
|
||||
input->buffer[(inputsource_t)key] = 1;
|
||||
input->buffer[glfwGetInputSourceForKey(key)] = 1;
|
||||
} else if(action == GLFW_RELEASE) {
|
||||
input->buffer[(inputsource_t)key] = 0;
|
||||
input->buffer[glfwGetInputSourceForKey(key)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,4 +123,14 @@ void glfwOnCursor(GLFWwindow *window, double x, double y) {
|
||||
input_t *input = &GAME_STATE->engine.input;
|
||||
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_X] = (float)x;
|
||||
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_Y] = (float)y;
|
||||
}
|
||||
|
||||
|
||||
inputsource_t glfwGetInputSourceForKey(int32_t key) {
|
||||
// return (inputsource_t)((
|
||||
// key <= GLFW_KEY_GRAVE_ACCENT ? key - GLFW_KEY_SPACE :
|
||||
// key <= GLFW_KEY_MENU ? key - GLFW_KEY_ESCAPE + GLFW_KEY_GRAVE_ACCENT :
|
||||
// key
|
||||
// ) % INPUT_SOURCE_COUNT);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user