From 1f02518b3bd521d4d22090c0fba072fa981f38e6 Mon Sep 17 00:00:00 2001 From: AliceLR Date: Wed, 13 Jan 2021 19:07:47 -0700 Subject: [PATCH 1/3] Add experimental player key buffering. --- src/game_update.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/game_update.c b/src/game_update.c index 70e2dfc71..4d6a53c77 100644 --- a/src/game_update.c +++ b/src/game_update.c @@ -331,6 +331,42 @@ static void update_player_input(struct world *mzx_world) int left_pressed = get_key_status(keycode_internal_wrt_numlock, IKEY_LEFT); int del_pressed = get_key_status(keycode_internal_wrt_numlock, IKEY_DELETE); + // Experimental buffering. + int key_pressed = get_key(keycode_internal); + switch(key_pressed) + { + case IKEY_SPACE: + if(!space_pressed) + trace("Buffered space press!\n"); + space_pressed = 1; + break; + case IKEY_DELETE: + if(!del_pressed) + trace("Buffered delete press!\n"); + del_pressed = 1; + break; + case IKEY_UP: + if(!up_pressed) + trace("Buffered up press!\n"); + up_pressed = 1; + break; + case IKEY_DOWN: + if(!down_pressed) + trace("Buffered down press!\n"); + down_pressed = 1; + break; + case IKEY_RIGHT: + if(!right_pressed) + trace("Buffered right press!\n"); + right_pressed = 1; + break; + case IKEY_LEFT: + if(!left_pressed) + trace("Buffered left press!\n"); + left_pressed = 1; + break; + } + // Shoot if(space_pressed && mzx_world->bi_shoot_status) { From a37bfe6096cfbae3aee1b661d630600fdbfa80da Mon Sep 17 00:00:00 2001 From: AliceLR Date: Thu, 14 Jan 2021 18:41:30 -0700 Subject: [PATCH 2/3] Move player input 'buffering' handling to get_key_status. --- docs/changelog.txt | 4 ++++ src/event.c | 21 +++++++++++++++++++-- src/game.c | 3 ++- src/game_update.c | 36 ------------------------------------ 4 files changed, 25 insertions(+), 39 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 69f4aeb76..e82c302ec 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,10 @@ GIT USERS ++ Added experimental player "input buffering". When a player key + is pressed and released on the same cycle, the player will now + respond to that key press. This also affects IF UPPRESSED and + similar (but currently not the KEYn counters). + Protected worlds are now decrypted to RAM or a temporary file when 'auto_decrypt_worlds' is enabled and the original file is left unmodified. This setting is now enabled by default. diff --git a/src/event.c b/src/event.c index 6a9c40b27..b1df2ee5a 100644 --- a/src/event.c +++ b/src/event.c @@ -831,8 +831,25 @@ Uint32 get_key_status(enum keycode_type type, Uint32 index) return status->keymap[index]; case keycode_internal_wrt_numlock: - return status->keymap[index] || - status->keymap[reverse_keysym_numlock(index)]; + { + enum keycode alt = reverse_keysym_numlock(index); + + if(status->keymap[index]) + return status->keymap[index]; + if(status->keymap[alt]) + return status->keymap[alt]; + + /* This is used mainly for UI and built-in player controls so, finally, + * if the keymap isn't set but this value is the pressed key (meaning it + * was pressed and released during the same cycle), treat it as 1 (pressed). + */ + if(status->key == index) + trace("Buffered press for key # %d\n", index); + if(status->key == alt && alt != index) + trace("Buffered press for key # %d\n", alt); + + return status->key == index || status->key == alt; + } default: return 0; diff --git a/src/game.c b/src/game.c index 2e3ee9f17..2220f693a 100644 --- a/src/game.c +++ b/src/game.c @@ -629,7 +629,6 @@ static boolean game_key(context *ctx, int *key) struct board *cur_board = mzx_world->current_board; char keylbl[] = "KEY?"; - int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean confirm_exit = false; @@ -795,6 +794,7 @@ static boolean game_key(context *ctx, int *key) case IKEY_RETURN: { + int key_status = get_key_status(keycode_internal_wrt_numlock, IKEY_RETURN); send_robot_all_def(mzx_world, "KeyEnter"); // Ignore if this isn't a fresh press @@ -813,6 +813,7 @@ static boolean game_key(context *ctx, int *key) { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick action. + //int key_status = get_key_status(keycode_internal_wrt_numlock, IKEY_ESCAPE); //if(key_status != 1) //return true; diff --git a/src/game_update.c b/src/game_update.c index 4d6a53c77..70e2dfc71 100644 --- a/src/game_update.c +++ b/src/game_update.c @@ -331,42 +331,6 @@ static void update_player_input(struct world *mzx_world) int left_pressed = get_key_status(keycode_internal_wrt_numlock, IKEY_LEFT); int del_pressed = get_key_status(keycode_internal_wrt_numlock, IKEY_DELETE); - // Experimental buffering. - int key_pressed = get_key(keycode_internal); - switch(key_pressed) - { - case IKEY_SPACE: - if(!space_pressed) - trace("Buffered space press!\n"); - space_pressed = 1; - break; - case IKEY_DELETE: - if(!del_pressed) - trace("Buffered delete press!\n"); - del_pressed = 1; - break; - case IKEY_UP: - if(!up_pressed) - trace("Buffered up press!\n"); - up_pressed = 1; - break; - case IKEY_DOWN: - if(!down_pressed) - trace("Buffered down press!\n"); - down_pressed = 1; - break; - case IKEY_RIGHT: - if(!right_pressed) - trace("Buffered right press!\n"); - right_pressed = 1; - break; - case IKEY_LEFT: - if(!left_pressed) - trace("Buffered left press!\n"); - left_pressed = 1; - break; - } - // Shoot if(space_pressed && mzx_world->bi_shoot_status) { From 7ff7c6f9a0212e28786a110b51f1b1f78d628551 Mon Sep 17 00:00:00 2001 From: AliceLR Date: Thu, 14 Jan 2021 19:15:19 -0700 Subject: [PATCH 3/3] Enable input "buffering" for all keycode types. --- docs/changelog.txt | 3 +-- src/counter.c | 2 +- src/event.c | 55 ++++++++++++++++++++++++++-------------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index e82c302ec..a74ad293b 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -4,8 +4,7 @@ USERS + Added experimental player "input buffering". When a player key is pressed and released on the same cycle, the player will now - respond to that key press. This also affects IF UPPRESSED and - similar (but currently not the KEYn counters). + respond to that key press. This also affects Robotic. + Protected worlds are now decrypted to RAM or a temporary file when 'auto_decrypt_worlds' is enabled and the original file is left unmodified. This setting is now enabled by default. diff --git a/src/counter.c b/src/counter.c index f8b65a2c0..321fd7386 100644 --- a/src/counter.c +++ b/src/counter.c @@ -1191,7 +1191,7 @@ static int keyn_read(struct world *mzx_world, const struct function_counter *counter, const char *name, int id) { int key_num = strtol(name + 3, NULL, 10); - return get_key_status(keycode_pc_xt, key_num); + return get_key_status(keycode_pc_xt, key_num) != 0; } static int key_code_read(struct world *mzx_world, diff --git a/src/event.c b/src/event.c index b1df2ee5a..17385add4 100644 --- a/src/event.c +++ b/src/event.c @@ -816,44 +816,51 @@ Uint32 get_key(enum keycode_type type) Uint32 get_key_status(enum keycode_type type, Uint32 index) { const struct buffered_status *status = load_status(); + enum keycode first; + enum keycode second; + index = MIN((Uint32)index, STATUS_NUM_KEYCODES - 1); switch(type) { case keycode_pc_xt: - { - enum keycode first, second; first = convert_xt_internal(index, &second); - return (status->keymap[first] || status->keymap[second]); - } + break; case keycode_internal: - return status->keymap[index]; + first = index; + second = IKEY_UNKNOWN; + break; case keycode_internal_wrt_numlock: - { - enum keycode alt = reverse_keysym_numlock(index); - - if(status->keymap[index]) - return status->keymap[index]; - if(status->keymap[alt]) - return status->keymap[alt]; - - /* This is used mainly for UI and built-in player controls so, finally, - * if the keymap isn't set but this value is the pressed key (meaning it - * was pressed and released during the same cycle), treat it as 1 (pressed). - */ - if(status->key == index) - trace("Buffered press for key # %d\n", index); - if(status->key == alt && alt != index) - trace("Buffered press for key # %d\n", alt); - - return status->key == index || status->key == alt; - } + first = index; + second = reverse_keysym_numlock(index); + break; default: return 0; } + + if(first && status->keymap[first]) + return status->keymap[first]; + if(second && status->keymap[second]) + return status->keymap[second]; + + /** + * If the keymap isn't set but this value is the pressed key (meaning it + * was pressed and released during the same cycle), treat it as 1 (pressed). + */ + if(first && status->key == first) + { + trace("Buffered press for key # %d\n", first); + return 1; + } + if(second && status->key == second) + { + trace("Buffered press for key # %d\n", second); + return 1; + } + return 0; } Uint32 get_last_key(enum keycode_type type)