[PATCH] add option for input delay
Export this patch
---
haha, this time it is input delay ;)
i hope the grammer for the docs is not to horrible
main.c | 28 +++++++++++++++++++++++-----
website/docs/options/index.html | 9 +++++++++
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/main.c b/main.c
index 4b0cdef..2b42bc4 100644
--- a/main.c
+++ b/main.c
@@ -114,6 +114,7 @@ enum option {
OPT_COLORS,
OPT_GARBAGE_PILING,
OPT_HARD_DROP,
+ OPT_INPUT_DELAY,
OPT_INPUT_HANDLER,
OPT_LINES_PER_LEVEL,
OPT_MUSIC,
@@ -1863,7 +1864,6 @@ static bool
lock_tetromino(uint8_t player)
{
struct game_state *g = &state.game.players[player];
-
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;
@@ -2829,6 +2834,8 @@ set_option_string(const char *key, const char *val, const char **restrict err)
*err = parse_config_string(key, val, OPT_GARBAGE_PILING);
} else if (strcmp(key, "hard_drop") == 0) {
*err = parse_config_string(key, val, OPT_HARD_DROP);
+ } else if (strcmp(key, "input_delay") == 0) {
+ *err = parse_config_string(key, val, OPT_INPUT_DELAY);
} else if (strcmp(key, "input_handler") == 0) {
*err = parse_config_string(key, val, OPT_INPUT_HANDLER);
} else if (strcmp(key, "lines_per_level") == 0) {
@@ -2858,6 +2865,7 @@ parse_config(void)
options[OPT_COLORS] = xstrdup("classic");
options[OPT_GARBAGE_PILING] = xstrdup("on");
options[OPT_HARD_DROP] = xstrdup("off");
+ options[OPT_INPUT_DELAY] = xstrdup("on");
options[OPT_INPUT_HANDLER] = xstrdup("vanilla");
options[OPT_LINES_PER_LEVEL] = xstrdup("vanilla");
options[OPT_MUSIC] = xstrdup("random");
@@ -3040,6 +3048,8 @@ save_config(void)
goto close_and_unlink;
if (write_config_string(f, "hard_drop", options[OPT_HARD_DROP]) == -1)
goto close_and_unlink;
+ if (write_config_string(f, "input_delay", options[OPT_INPUT_DELAY]) == -1)
+ goto close_and_unlink;
if (write_config_string(f, "input_handler", options[OPT_INPUT_HANDLER]) == -1)
goto close_and_unlink;
if (write_config_string(f, "lines_per_level", options[OPT_LINES_PER_LEVEL]) == -1)
@@ -3165,6 +3175,7 @@ draw_core_option(void)
case OPT_COLORS:
case OPT_GARBAGE_PILING:
case OPT_HARD_DROP:
+ case OPT_INPUT_DELAY:
case OPT_PAUSE:
case OPT_SAVE_HIGHSCORES:
case OPT_SFX:
@@ -3287,6 +3298,7 @@ draw_options_page(void)
writefg("COLORS", 2, y++, WHITE);
writefg("GARBAGE PILING", 2, y++, WHITE);
writefg("HARD DROP", 2, y++, WHITE);
+ writefg("INPUT DELAY", 2, y++, WHITE);
writefg("INPUT HANDLER", 2, y++, WHITE);
writefg("LINES PER LEVEL", 2, y++, WHITE);
writefg("MUSIC", 2, y++, WHITE);
@@ -7570,9 +7582,12 @@ 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 delay = strcmp(options[OPT_INPUT_DELAY], "on") == 0 ? 2 : 0;
+ uint8_t pressed = inputs[delay][i] & ~inputs[delay + 1][i];
+ uint8_t held = inputs[delay][i] & inputs[delay + 1][i];
+ uint8_t released = ~inputs[delay][i] & inputs[delay + 1][i];
+
if (g->over) {
if (pressed == INPUT_MASK_START) {
/* only start pressed; no other buttons */
@@ -7613,9 +7628,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 +8365,8 @@ 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 delay = strcmp(options[OPT_INPUT_DELAY], "on") == 0 ? 2 : 0;
+ uint8_t pressed = inputs[delay][0] & ~inputs[delay + 1][0];
switch (state.scr) {
case TITLE:
titleinput(pressed);
diff --git a/website/docs/options/index.html b/website/docs/options/index.html
index 3969ba4..3bdb3d2 100644
--- a/website/docs/options/index.html
+++ b/website/docs/options/index.html
@@ -61,6 +61,15 @@
<dd>Pressing the up button will snap the tetromino to the bottom of the board and immediately lock it.</dd>
</dl>
</section>
+ <section>
+ <h3 class="option">Input Delay</h3>
+ <dl>
+ <dt class="optval">On</dt>
+ <dd><span class="i">(default)</span> The input delay of NES Tetris will be emulated.</dd>
+ <dt class="optval">Off</dt>
+ <dd>The inputs will be processed as soon as they are available.</dd>
+ </dl>
+ </section>
<!-- TODO: finish me -->
<section>
<h3 class="option">Lines per level</h3>
--
2.41.0