]> git.draconx.ca Git - rrace.git/blobdiff - src/x11.c
Pack/unpack the tile planes arithmetically.
[rrace.git] / src / x11.c
index b098d0ea7a43034c3e688ab737389e653b93e788..34f43a9e66de6cd28401ec1019eaaf93a6e96e37 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -174,11 +174,9 @@ static void clear_border(struct app_state *state, Display *display, Drawable d,
 
 static int
 redraw_tile(struct app_state *state, Display *display, Drawable d,
-            uint_fast32_t bit0, uint_fast32_t bit1, uint_fast32_t bit2,
-            int x, int y, Dimension w, Dimension h)
+            uint_least32_t *gp, int x, int y, Dimension w, Dimension h)
 {
-       uint_fast32_t pos = board_position(x, y);
-       unsigned char tile = 0;
+       unsigned tile = board_tile(gp, 5*y+x);
 
 #if X11_RENDER_DEBUG
        if (d == XtWindow(state->game) || d == XtWindow(state->goal)) {
@@ -189,12 +187,7 @@ redraw_tile(struct app_state *state, Display *display, Drawable d,
                usleep(70000);
        }
 #endif
-
-       if (bit0 & pos) tile |= 1;
-       if (bit1 & pos) tile |= 2;
-       if (bit2 & pos) tile |= 4;
        assert(tile < TILE_MAX);
-
        if (tile == TILE_EMPTY) {
                XClearArea(display, d, x*w, y*h, w, h, 0);
        } else {
@@ -208,9 +201,13 @@ static int
 redraw_goal_tile(struct app_state *state, Display *display, Drawable d,
                  int x, int y, Dimension w, Dimension h)
 {
-       uint_least16_t *gp = state->board.goal;
+       uint_least32_t gp[3] = {
+               state->board.goal[0],
+               state->board.goal[1],
+               state->board.goal[2]
+       };
 
-       return redraw_tile(state, display, d, gp[0], gp[1], gp[2], x, y, w, h);
+       return redraw_tile(state, display, d, gp, x, y, w, h);
 }
 
 void x11_redraw_goal(struct app_state *state, uint_fast32_t mask)
@@ -226,9 +223,8 @@ void x11_redraw_goal(struct app_state *state, uint_fast32_t mask)
        for (i = 0; i < 9; i++) {
                int x = i%3, y = i/3;
 
-               if (mask & 1) {
+               if (mask & 1)
                        redraw_goal_tile(state, display, goal, x, y, w, h);
-               }
 
                /*
                 * Goal bitmaps have a gap of 2 tiles between each row.
@@ -310,11 +306,8 @@ void x11_redraw_game(struct app_state *state, uint_fast32_t mask)
        }
 
        for (i = 0; i < 25; i++) {
-               if (mask & 1) {
-                       redraw_tile(state, display, game,
-                                   gp[0], gp[1], gp[2],
-                                   i%5, i/5, w, h);
-               }
+               if (mask & 1)
+                       redraw_tile(state, display, game, gp, i%5, i/5, w, h);
                mask >>= 1;
        }
 }