From 08fa2151caddb32c33c4872ec6df243d74921ea9 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 15 Aug 2022 07:37:07 +0200 Subject: [PATCH] [Maintenance] Make the locked condition handler macro publicly available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- game/input.hpp | 12 ++++++++++++ th03/hiscore/regist.cpp | 17 +++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 game/input.hpp diff --git a/game/input.hpp b/game/input.hpp new file mode 100644 index 00000000..7ff600ab --- /dev/null +++ b/game/input.hpp @@ -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; \ + } \ +} diff --git a/th03/hiscore/regist.cpp b/th03/hiscore/regist.cpp index 9ed221af..3ba843d3 100644 --- a/th03/hiscore/regist.cpp +++ b/th03/hiscore/regist.cpp @@ -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 }