summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
991d1e7)
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.
-int game_check_goal(struct board *board)
+uint_fast32_t game_check_goal(struct board *board)
+ uint_least32_t *game = board->game;
+ uint_least16_t *goal = board->goal;
+ uint_least32_t mask = 0;
+ int 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)
}
void game_begin(struct board *board)
int game_do_move(struct board *board, int x, int y);
/*
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
/*
* Initialize the game RNG such that the next call to game_reset will produce a
if (game_do_move(&state->board, x, y) == 0) {
uint_least32_t mask;
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;
int_fast32_t ms = game_finish(&state->board);
unsigned min, sec;
static void set_view_goal(struct app_state *state, int view_goal)
{
state->view_goal_on_game = view_goal;
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)
}
static void game_input(Widget w, void *data, void *cb_data)