From 09aa8de52cb962f1ceebfb1fd44f2c54a924fc5c Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 22 Jul 2024 21:43:25 -0400 Subject: puzzles: resync with upstream This brings the puzzles source in sync with Simon's branch, commit fd304c5 (from March 2024), with some added Rockbox-specific compatibility changes: https://www.franklinwei.com/git/puzzles/commit/?h=rockbox-devel&id=516830d9d76bdfe64fe5ccf2a9b59c33f5c7c078 There are quite a lot of backend changes, including a new "Mosaic" puzzle. In addition, some new frontend changes were necessary: - New "Preferences" menu to access the user preferences system. - Enabled spacebar input for several games. Change-Id: I94c7df674089c92f32d5f07025f6a1059068af1e --- apps/plugins/puzzles/src/inertia.c | 76 +++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'apps/plugins/puzzles/src/inertia.c') diff --git a/apps/plugins/puzzles/src/inertia.c b/apps/plugins/puzzles/src/inertia.c index 726c89c7dd..d120411f55 100644 --- a/apps/plugins/puzzles/src/inertia.c +++ b/apps/plugins/puzzles/src/inertia.c @@ -11,7 +11,12 @@ #include #include #include -#include +#include +#ifdef NO_TGMATH_H +# include +#else +# include +#endif #include "puzzles.h" @@ -202,6 +207,8 @@ static const char *validate_params(const game_params *params, bool full) */ if (params->w < 2 || params->h < 2) return "Width and height must both be at least two"; + if (params->w > INT_MAX / params->h) + return "Width times height must not be unreasonably large"; /* * The grid construction algorithm creates 1/5 as many gems as @@ -1520,7 +1527,8 @@ static char *encode_ui(const game_ui *ui) return dupstr(buf); } -static void decode_ui(game_ui *ui, const char *encoding) +static void decode_ui(game_ui *ui, const char *encoding, + const game_state *state) { int p = 0; sscanf(encoding, "D%d%n", &ui->deaths, &p); @@ -1545,6 +1553,15 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, ui->just_made_move = false; } +static const char *current_key_label(const game_ui *ui, + const game_state *state, int button) +{ + if (IS_CURSOR_SELECT(button) && + state->soln && state->solnpos < state->soln->len) + return "Advance"; + return ""; +} + struct game_drawstate { game_params p; int tilesize; @@ -1593,7 +1610,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, * end up the right way round. */ angle = atan2(dx, -dy); - angle = (angle + (PI/8)) / (PI/4); + angle = (angle + (float)(PI/8)) / (float)(PI/4); assert(angle > -16.0F); dir = (int)(angle + 16.0F) & 7; } @@ -1618,20 +1635,20 @@ static char *interpret_move(const game_state *state, game_ui *ui, dir = state->soln->list[state->solnpos]; if (dir < 0) - return NULL; + return MOVE_UNUSED; /* * Reject the move if we can't make it at all due to a wall * being in the way. */ if (AT(w, h, state->grid, state->px+DX(dir), state->py+DY(dir)) == WALL) - return NULL; + return MOVE_NO_EFFECT; /* * Reject the move if we're dead! */ if (state->dead) - return NULL; + return MOVE_NO_EFFECT; /* * Otherwise, we can make the move. All we need to specify is @@ -1685,6 +1702,7 @@ static game_state *execute_move(const game_state *state, const char *move) * This is a solve move, so we don't actually _change_ the * grid but merely set up a stored solution path. */ + if (move[1] == '\0') return NULL; /* Solution must be non-empty. */ ret = dup_game(state); install_new_solution(ret, move); return ret; @@ -1729,11 +1747,10 @@ static game_state *execute_move(const game_state *state, const char *move) if (ret->soln) { if (ret->dead || ret->gems == 0) discard_solution(ret); - else if (ret->soln->list[ret->solnpos] == dir) { + else if (ret->soln->list[ret->solnpos] == dir && + ret->solnpos+1 < ret->soln->len) ++ret->solnpos; - assert(ret->solnpos < ret->soln->len); /* or gems == 0 */ - assert(!ret->dead); /* or not a solution */ - } else { + else { const char *error = NULL; char *soln = solve_game(NULL, ret, NULL, &error); if (!error) { @@ -1751,7 +1768,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1869,11 +1886,6 @@ static void draw_player(drawing *dr, game_drawstate *ds, int x, int y, coords[d*4+2] = x + TILESIZE/2 + (int)((TILESIZE*3/7) * x2); coords[d*4+3] = y + TILESIZE/2 + (int)((TILESIZE*3/7) * y2); } - /* rockbox hack */ - int tmp[2] = { coords[0], coords[1] }; - memmove(coords, coords + 2, sizeof(int) * DIRECTIONS * 4 - 2); - memcpy(coords + DIRECTIONS * 4 - 2, tmp, 2 * sizeof(int)); - draw_polygon(dr, coords, DIRECTIONS*2, COL_DEAD_PLAYER, COL_OUTLINE); } else { draw_circle(dr, x + TILESIZE/2, y + TILESIZE/2, @@ -1889,6 +1901,8 @@ static void draw_player(drawing *dr, game_drawstate *ds, int x, int y, int coords[14], *c; c = coords; + *c++ = ox + px/9; + *c++ = oy + py/9; *c++ = ox + px/9 + ax*2/3; *c++ = oy + py/9 + ay*2/3; *c++ = ox + px/3 + ax*2/3; @@ -1901,8 +1915,6 @@ static void draw_player(drawing *dr, game_drawstate *ds, int x, int y, *c++ = oy - py/9 + ay*2/3; *c++ = ox - px/9; *c++ = oy - py/9; - *c++ = ox + px/9; - *c++ = oy + py/9; draw_polygon(dr, coords, 7, COL_HINT, COL_OUTLINE); } @@ -2013,15 +2025,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, * Initialise a fresh drawstate. */ if (!ds->started) { - int wid, ht; - - /* - * Blank out the window initially. - */ - game_compute_size(&ds->p, TILESIZE, &wid, &ht); - draw_rect(dr, 0, 0, wid, ht, COL_BACKGROUND); - draw_update(dr, 0, 0, wid, ht); - /* * Draw the grid lines. */ @@ -2207,19 +2210,6 @@ static int game_status(const game_state *state) return state->gems == 0 ? +1 : 0; } -static bool game_timing_state(const game_state *state, game_ui *ui) -{ - return true; -} - -static void game_print_size(const game_params *params, float *x, float *y) -{ -} - -static void game_print(drawing *dr, const game_state *state, int tilesize) -{ -} - #ifdef COMBINED #define thegame inertia #endif @@ -2241,12 +2231,14 @@ const struct game thegame = { free_game, true, solve_game, true, game_can_format_as_text_now, game_text_format, + NULL, NULL, /* get_prefs, set_prefs */ new_ui, free_ui, encode_ui, decode_ui, NULL, /* game_request_keys */ game_changed_state, + current_key_label, interpret_move, execute_move, PREFERRED_TILESIZE, game_compute_size, game_set_size, @@ -2258,8 +2250,8 @@ const struct game thegame = { game_flash_length, game_get_cursor_location, game_status, - false, false, game_print_size, game_print, + false, false, NULL, NULL, /* print_size, print */ true, /* wants_statusbar */ - false, game_timing_state, + false, NULL, /* timing_state */ 0, /* flags */ }; -- cgit v1.2.3