---
i am unsure if there is a better variable name than "input_delay"? any ideas?
(in gameinput() and handle_inputs())
input_delay is fine, but you could also just shorten it to "delay" (this
also allows it to fit on one line while still being within 80 columns).
main.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/main.c b/main.c
index 4b0cdef..2a40cdc 100644
--- a/main.c
+++ b/main.c
@@ -122,7 +122,8 @@ enum option {
OPT_SAVE_HIGHSCORES,
OPT_SFX,
OPT_SPEED,
- OPT_LAST = OPT_SPEED,
+ OPT_INPUT_DELAY,
+ OPT_LAST = OPT_INPUT_DELAY,
This should be alphabetized, here and everywhere else it's used with
other options (sorry)
};
static char *options[OPT_LAST + 1];
@@ -1863,7 +1864,6 @@ static bool
lock_tetromino(uint8_t player)
{
struct game_state *g = &state.game.players[player];
-
Why remove this line?
g->dropdelay = 1;
run_mods(EV_PRE_LOCK, player, 0);
if (g->dropdelay == 0) {
@@ -2315,6 +2315,11 @@ option_string_values(enum option opt, const char *const **restrict values,
valbuf[21] = "8/1";
*nvalues = 22;
break;
+ case OPT_INPUT_DELAY:
+ valbuf[0] = "on";
+ valbuf[1] = "off";
+ *nvalues = 2;
+ break;
}
*values = valbuf;
@@ -2845,6 +2850,8 @@ set_option_string(const char *key, const char *val, const char **restrict err)
*err = parse_config_string(key, val, OPT_SFX);
} else if (strcmp(key, "speed") == 0) {
*err = parse_config_string(key, val, OPT_SPEED);
+ } else if (strcmp(key, "input_delay") == 0) {
+ *err = parse_config_string(key, val, OPT_INPUT_DELAY);
} else {
return set_lua_option(key, val, err);
}
@@ -2866,6 +2873,7 @@ parse_config(void)
options[OPT_SAVE_HIGHSCORES] = xstrdup("on");
options[OPT_SFX] = xstrdup("ntsc");
options[OPT_SPEED] = xstrdup("1/1");
+ options[OPT_INPUT_DELAY] = xstrdup("on");
input[0].left[0].device = BIND_KEY;
input[0].left[0].key = SDLK_LEFT;
@@ -3056,6 +3064,8 @@ save_config(void)
goto close_and_unlink;
if (write_config_string(f, "speed", options[OPT_SPEED]) == -1)
goto close_and_unlink;
+ if (write_config_string(f, "input_delay", options[OPT_INPUT_DELAY]) == -1)
+ goto close_and_unlink;
luahelper_resolvegamefield("__useroptions", NULL);
lua_geti(L, -1, 0);
@@ -3169,6 +3179,7 @@ draw_core_option(void)
case OPT_SAVE_HIGHSCORES:
case OPT_SFX:
case OPT_SPEED:
+ case OPT_INPUT_DELAY:
draw_option(options[opt], strlen(options[opt]), WHITE);
break;
}
@@ -3295,6 +3306,7 @@ draw_options_page(void)
writefg("SAVE HIGHSCORES", 2, y++, WHITE);
writefg("SFX", 2, y++, WHITE);
writefg("SPEED", 2, y++, WHITE);
+ writefg("INPUT DELAY", 2, y++, WHITE);
for (uint8_t i = (uint8_t)OPT_LAST + 1; i > 0; --i) {
state.options.pos = i - 1;
@@ -7570,9 +7582,11 @@ static int
gameinput(const uint8_t inputs[static 4][2], uint8_t i)
{
struct game_state *g = &state.game.players[i];
- uint8_t pressed = inputs[2][i] & ~inputs[3][i];
- uint8_t held = inputs[2][i] & inputs[3][i];
- uint8_t released = ~inputs[2][i] & inputs[3][i];
+ uint8_t input_delay = strcmp(options[OPT_INPUT_DELAY], "on") == 0 ?
+ 2 : 0;
style: this can just go on one line
+ uint8_t pressed = inputs[input_delay][i] & ~inputs[input_delay + 1][i];
+ uint8_t held = inputs[input_delay][i] & inputs[input_delay + 1][i];
+ uint8_t released = ~inputs[input_delay][i] & inputs[input_delay + 1][i];
if (g->over) {
if (pressed == INPUT_MASK_START) {
/* only start pressed; no other buttons */
@@ -7613,9 +7627,11 @@ gameinput(const uint8_t inputs[static 4][2], uint8_t i)
shift(g, inputs[2][i]);
}
}
+
if (released & INPUT_MASK_UP) {
/* TODO */
}
+
/* when both flip buttons are pressed, flip cw takes
* precedence */
if (pressed & INPUT_MASK_FLIP_CW) {
@@ -8348,7 +8364,9 @@ read_inputs(void))[2]
static void
handle_inputs(const uint8_t inputs[static 4][2])
{
- uint8_t pressed = inputs[2][0] & ~inputs[3][0];
+ uint8_t input_delay = strcmp(options[OPT_INPUT_DELAY], "on") == 0 ?
+ 2 : 0;
same here
+ uint8_t pressed = inputs[input_delay][0] & ~inputs[input_delay + 1][0];
switch (state.scr) {
case TITLE:
titleinput(pressed);
--
2.41.0
lol you called it dropdelay instead of input delay again
This option should be added to
https://generic-tetromino-game.sebsite.pw/docs/options/. This page is,
uh, very unfinished and probably not actually up to date, but this
option seems worth documenting nonetheless.