]> git.draconx.ca Git - rrace.git/commitdiff
Only redraw changed tiles when right clicking.
authorNick Bowler <nbowler@draconx.ca>
Sat, 12 Mar 2022 21:11:02 +0000 (16:11 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 12 Mar 2022 21:20:34 +0000 (16:20 -0500)
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
src/game.h
src/motif_ui.c

index c478eef5b55e97bb2043fcc936640914c7bcb93a..bdd8f2b3ac103c6e2974fe138c1b23f342a81673 100644 (file)
@@ -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)
index 99b51338a00078a2349b69bb352c3b0fd72de2a0..a734e229058f5182f96c28c3512c19c06fec6965 100644 (file)
@@ -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
index c31d8392ac7a828694128c2ec6e617a4faff9e85..dfe4e82911434a59695646e14736a0c3546d547c 100644 (file)
@@ -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)