[Maintenance] Make the locked condition handler macro publicly available

I've been thinking about a new directory for any core cross-platform
code that these game typically need. These range from stuff like the
hardware-independent pixel_t types (you shouldn't need to #include a
file named "pc98.h" for those), to stuff like this. "logic" might have
been a good directory name, but does it encompass rendering as well?
So, it'll just be "game" for now. 😶

Part of P0216, funded by JonathKane.
This commit is contained in:
nmlgc 2022-08-15 07:37:07 +02:00
parent 690b4df14b
commit 08fa2151ca
2 changed files with 15 additions and 14 deletions

12
game/input.hpp Normal file
View File

@ -0,0 +1,12 @@
// Shared input implementation macros.
#define on_condition_if_not_locked(condition, lock, func) { \
if(condition) { \
if(lock == false) { \
func \
} \
lock = true; \
} else { \
lock = false; \
} \
}

View File

@ -6,6 +6,7 @@
#include "planar.h"
#include "master.hpp"
#include "shiftjis.hpp"
#include "game/input.hpp"
#include "th01/rank.h"
extern "C" {
#include "th01/hardware/grppsafx.h"
@ -342,17 +343,6 @@ void near regist_name_enter(void)
} \
}
#define on_action(condition, lock, func) { \
if(condition) { \
if(lock == false) { \
func \
} \
lock = true; \
} else { \
lock = false; \
} \
}
struct input_hold_frames_t {
int up;
int down;
@ -417,7 +407,7 @@ void near regist_name_enter(void)
rerender = true;
});
on_action(
on_condition_if_not_locked(
((input_sp & INPUT_OK) || (input_sp & INPUT_SHOT)), enter_locked, {
if(regi == REGI_BS) {
cursor_backspace(cursor_backwards, top);
@ -435,7 +425,7 @@ void near regist_name_enter(void)
}
);
on_action((input_sp & INPUT_BOMB), back_locked, { \
on_condition_if_not_locked((input_sp & INPUT_BOMB), back_locked, { \
cursor_backspace(cursor_backwards, top);
rerender = true;
});
@ -465,6 +455,5 @@ void near regist_name_enter(void)
frame_delay(1);
}
#undef on_action
#undef on_direction
}