a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit ceadbe46bfd6207eb6b6c73cd522257325352e71
parent 8cf5f09f24fbe29113afbbe8049d47c9330ab3de
Author: amin <dev@aminmesbah.com>
Date:   Mon,  1 Jul 2019 01:35:18 +0000

Move input stuff to separate files

FossilOrigin-Name: 4237460b588392b05e6d8ebaea30cafa51724d9919b74e44edc90bbc31c69314
Diffstat:
Msrc/game.c | 16+---------------
Msrc/game.h | 1+
Asrc/input.c | 14++++++++++++++
Asrc/input.h | 24++++++++++++++++++++++++
Msrc/platform.h | 25-------------------------
5 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -5,21 +5,7 @@ #include "collision.c" #include "render.c" #include "world.c" - -internal bool btn_is_down(u32 button_states, enum GameButton b) -{ - assert(b < NUM_GAME_BUTTONS); - bool result = button_states & (1 << b); - return result; -} - -internal bool btn_was_just_pressed(struct GameInput *game_input, enum GameButton b) -{ - assert(game_input); - assert(b < NUM_GAME_BUTTONS); - bool result = game_input->button_downs & (1 << b); - return result; -} +#include "input.c" internal void move_mode_print(enum MoveMode s) { diff --git a/src/game.h b/src/game.h @@ -23,6 +23,7 @@ #include "memory.h" #include "render.h" #include "world.h" +#include "input.h" #include "platform.h" static_assert(-1 == ~0, "Implementation doesn't use two's complement"); diff --git a/src/input.c b/src/input.c @@ -0,0 +1,14 @@ +internal inline bool btn_is_down(u32 button_states, enum GameButton b) +{ + assert(b < NUM_GAME_BUTTONS); + bool result = button_states & (1 << b); + return result; +} + +internal bool btn_was_just_pressed(struct GameInput *game_input, enum GameButton b) +{ + assert(game_input); + assert(b < NUM_GAME_BUTTONS); + bool result = game_input->button_downs & (1 << b); + return result; +} diff --git a/src/input.h b/src/input.h @@ -0,0 +1,24 @@ +enum GameButton +{ + BTN_LEFT, + BTN_RIGHT, + BTN_UP, + BTN_DOWN, + BTN_JUMP, + BTN_DEBUG_FLOAT, + + NUM_GAME_BUTTONS, + NULL_GAME_BUTTON, +}; + +// TODO: define static assert without string arg +static_assert(NUM_GAME_BUTTONS <= 32, ""); + +struct GameInput +{ + f32 dt; + u32 button_states; + u32 prev_button_states; + u32 button_ups; + u32 button_downs; +}; diff --git a/src/platform.h b/src/platform.h @@ -7,31 +7,6 @@ #define KIBIBYTES(n) (n) * 1024LL #define MEBIBYTES(n) KIBIBYTES((n) * 1024LL) -enum GameButton -{ - BTN_LEFT, - BTN_RIGHT, - BTN_UP, - BTN_DOWN, - BTN_JUMP, - BTN_DEBUG_FLOAT, - - NUM_GAME_BUTTONS, - NULL_GAME_BUTTON, -}; - -// TODO: define static assert without string arg -static_assert(NUM_GAME_BUTTONS <= 32, ""); - -struct GameInput -{ - f32 dt; - u32 button_states; - u32 prev_button_states; - u32 button_ups; - u32 button_downs; -}; - #define PLATFORM_READ_ENTIRE_FILE(name) char *(name)(char *file_path) typedef PLATFORM_READ_ENTIRE_FILE(platform_read_entire_file_func);