Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental player key buffering. #289

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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 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.
Expand Down
2 changes: 1 addition & 1 deletion src/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 31 additions & 7 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,27 +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:
return status->keymap[index] ||
status->keymap[reverse_keysym_numlock(index)];
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)
Expand Down
3 changes: 2 additions & 1 deletion src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down