]> git.draconx.ca Git - rrace.git/blobdiff - src/motif_ui.c
Report changed positions from game_do_move.
[rrace.git] / src / motif_ui.c
index eca3e797605d5f42d910439144ac425782a31b4c..85241d8803c2de539427e41eea19b79c4d003945 100644 (file)
@@ -217,23 +217,25 @@ static void goal_resize(Widget w, void *data, void *cb_data)
 
 static void do_input_move(struct app_state *state, int x, int y)
 {
-       uint_least32_t *gp = state->board.game, prev[4];
-
-       memcpy(prev, gp, sizeof prev);
-       if (game_do_move(&state->board, x, y) == 0) {
-               uint_least32_t mask;
+       uint_fast32_t mask;
 
-               if (game_check_goal(&state->board)) {
-                       printf("You win!\n");
-                       game_finish(&state->board);
+       if ((mask = game_do_move(&state->board, x, y)) != 0) {
+               if (game_check_goal(&state->board) == 0) {
+                       int_fast32_t ms = game_finish(&state->board);
+                       unsigned min, sec;
+
+                       /* Negative time just means clock jumps and
+                        * display headaches. */
+                       if (ms < 0)
+                               ms = 0;
+
+                       sec = ms / 1000, ms %= 1000;
+                       min = sec / 60, sec %= 60;
+                       printf("You won!  Time was %u:%.2u:%.3u\n",
+                              min, sec, (unsigned)ms);
+                       mask |= ~GOAL_MASK;
                }
 
-               /* Figure out which tiles changed */
-               prev[0] ^= gp[0];
-               prev[1] ^= gp[1];
-               prev[2] ^= gp[2];
-               mask = prev[0] | prev[1] | prev[2];
-
                x11_redraw_game(state, mask);
        }
 }
@@ -241,7 +243,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)