From 23aee3322744aa3c65de28c3ebe1509e291b8702 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 12 Mar 2022 16:11:02 -0500 Subject: [PATCH] Only redraw changed tiles when right clicking. By changing the definition of game_check_goal to return a bit-mask of mismatched positions, we can just pass that to the redraw mask to reduce the amount of rendering needed. --- src/game.c | 11 +++++++---- src/game.h | 5 +++-- src/motif_ui.c | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/game.c b/src/game.c index c478eef..bdd8f2b 100644 --- a/src/game.c +++ b/src/game.c @@ -199,13 +199,16 @@ int game_do_move(struct board *board, int x, int y) return 0; } -int game_check_goal(struct board *board) +uint_fast32_t game_check_goal(struct board *board) { - int i, ret = 1; + uint_least32_t *game = board->game; + uint_least16_t *goal = board->goal; + uint_least32_t mask = 0; + int i; for (i = 0; i < 3; i++) - ret &= ((board->game[i] & GOAL_MASK) >> 6) == board->goal[i]; - return ret; + mask |= goal[i] ^ (game[i] >> GOAL_SHIFT); + return (mask << GOAL_SHIFT) & GOAL_MASK; } void game_begin(struct board *board) diff --git a/src/game.h b/src/game.h index 99b5133..a734e22 100644 --- a/src/game.h +++ b/src/game.h @@ -166,9 +166,10 @@ static inline uint_fast32_t board_right(int x) int game_do_move(struct board *board, int x, int y); /* - * Returns 1 if the game is in a winning position, or 0 otherwise. + * Returns the board bitmap setting game locations that differ from the goal. + * A return value of 0 therefore indicates a winning position. */ -int game_check_goal(struct board *board); +uint_fast32_t game_check_goal(struct board *board); /* * Initialize the game RNG such that the next call to game_reset will produce a diff --git a/src/motif_ui.c b/src/motif_ui.c index c31d839..dfe4e82 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -223,7 +223,7 @@ static void do_input_move(struct app_state *state, int x, int y) if (game_do_move(&state->board, x, y) == 0) { uint_least32_t mask; - if (game_check_goal(&state->board)) { + if (game_check_goal(&state->board) == 0) { int_fast32_t ms = game_finish(&state->board); unsigned min, sec; @@ -251,7 +251,7 @@ static void do_input_move(struct app_state *state, int x, int y) static void set_view_goal(struct app_state *state, int view_goal) { state->view_goal_on_game = view_goal; - x11_redraw_game(state, GOAL_MASK); + x11_redraw_game(state, game_check_goal(&state->board)); } static void game_input(Widget w, void *data, void *cb_data) -- 2.43.2