Cleaned some code, drastically reduced memory footprint.

This commit is contained in:
2021-09-05 15:02:02 -07:00
parent cb447a6033
commit 2285568480
19 changed files with 263 additions and 108 deletions

View File

@ -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;
}

View File

@ -13,8 +13,8 @@
#define WINDOW_WIDTH_DEFAULT 1280
#define WINDOW_HEIGHT_DEFAULT WINDOW_WIDTH_DEFAULT/16*9
#define GLFW_PLATFORM_INPUT_MOUSE_X (inputsource_t)512
#define GLFW_PLATFORM_INPUT_MOUSE_Y (inputsource_t)513
#define GLFW_PLATFORM_INPUT_MOUSE_X (inputsource_t)0xFF
#define GLFW_PLATFORM_INPUT_MOUSE_Y (inputsource_t)0xFE
/** The current running game state. */
extern game_t *GAME_STATE;
@ -48,4 +48,13 @@ void glfwOnKey(GLFWwindow *window,
void glfwOnError(int error, const char* description);
void glfwOnCursor(GLFWwindow *window, double x, double y);
void glfwOnCursor(GLFWwindow *window, double x, double y);
/**
* Get the game engine specific input source for a given GLFW Key code.
*
* @param key Key to get the input source for.
* @return The input source.
*/
inputsource_t glfwGetInputSourceForKey(int32_t key);