]> git.draconx.ca Git - rrace.git/commitdiff
Alter x11_queue_render interface to better match usage.
authorNick Bowler <nbowler@draconx.ca>
Wed, 7 Dec 2022 06:04:37 +0000 (01:04 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 9 Dec 2022 03:13:59 +0000 (22:13 -0500)
Every call to this function updates exactly one of the goal or game
render bitmaps.  Instead of two masks, update the function to take a
single mask and a new parameter selects the bitmap to update.

This change enables more rendering code paths for the game/goal
areas to be merged.

common
src/motif.h
src/motif_ui.c
src/x11.c

diff --git a/common b/common
index 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905..a56b84487bb43c85cb36e5995c84006be8b81011 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905
+Subproject commit a56b84487bb43c85cb36e5995c84006be8b81011
index c85e8a9a4dfea4ec68d078f6934af7b198e78889..076f4f60cfd58da466a9e8b78b02cc3b45a8b3cc 100644 (file)
@@ -57,7 +57,25 @@ void x11_initialize(struct app_state *state, Widget shell);
 void x11_redraw_icon(struct app_state *state, Widget shell);
 void x11_redraw_goal(struct app_state *state, uint_fast32_t mask);
 void x11_redraw_game(struct app_state *state, uint_fast32_t mask);
-void x11_queue_render(struct app_state *state, uint_fast32_t game_mask,
-                                               uint_fast16_t goal_mask);
+
+/*
+ * Mark tiles for redraw.  The redraw is not performed immediately, but
+ * rather a background task is installed to perform the redraw at a later
+ * time.
+ *
+ * The mode parameter may be one of the following enumerated values:
+ *
+ *   * RENDER_MODE_GAME: mark game tiles for update.
+ *   * RENDER_MODE_GOAL: mark goal tiles for update.
+ *   * RENDER_MODE_BOTH: mark both game and goal tiles for update (probably
+ *                       only useful if mask has all bits set).
+ */
+void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode);
+
+enum {
+       RENDER_MODE_GOAL = 1,
+       RENDER_MODE_GAME = 2,
+       RENDER_MODE_BOTH = 3
+};
 
 #endif
index 5056d9c7e59f6135c3fe7ddc0bbb4e2b6a8689d1..3658615d917dc0870c02ca5109bb7e992f928f05 100644 (file)
@@ -266,14 +266,11 @@ static uint_fast32_t x11_expose_mask(XExposeEvent *e, int tile_w, int tile_h)
                          (e->y+e->height-1)/tile_h );
 }
 
-static void game_resize(Widget w, void *data, void *cb_data)
+static void resize(Widget w, void *data, void *cb_data)
 {
-       x11_queue_render(data, -1, 0);
-}
+       struct app_state *state = data;
 
-static void goal_resize(Widget w, void *data, void *cb_data)
-{
-       x11_queue_render(data, 0, -1);
+       x11_queue_render(data, -1, 1 << (w == state->game));
 }
 
 static void expose(Widget w, void *data, void *cb_data)
@@ -282,11 +279,11 @@ static void expose(Widget w, void *data, void *cb_data)
        XExposeEvent *e = &cbs->event->xexpose;
        struct app_state *state = data;
        Dimension tile_w, tile_h;
+       uint_fast32_t mask;
 
        XtVaGetValues(w, XmNwidth, &tile_w, XmNheight, &tile_h, (char *)NULL);
        if (w == state->game) {
                uint_least32_t *gp = state->board.game;
-               uint_fast32_t mask;
 
                if (!(tile_w /= 5) || !(tile_h /= 5))
                        return;
@@ -297,15 +294,16 @@ static void expose(Widget w, void *data, void *cb_data)
                 * spaces don't need to be drawn again.
                 */
                mask = gp[0] | gp[1] | gp[2];
-               mask &= x11_expose_mask(e, tile_w, tile_h);
-
-               x11_queue_render(state, mask, 0);
        } else {
                if (!(tile_w /= 3) || !(tile_h /= 3))
                        return;
 
-               x11_queue_render(state, 0, x11_expose_mask(e, tile_w, tile_h));
+               /* Goal area never has empty tiles. */
+               mask = -1;
        }
+
+       mask &= x11_expose_mask(e, tile_w, tile_h);
+       x11_queue_render(state, mask, 1<<(w == state->game));
 }
 
 void ui_initialize(struct app_state *state, Widget shell)
@@ -325,13 +323,13 @@ void ui_initialize(struct app_state *state, Widget shell)
        XtVaGetValues(state->game, XmNwidth, &state->game_sz[0],
                                   XmNheight, &state->game_sz[1],
                                   (char *)NULL);
-       XtAddCallback(state->game, XmNresizeCallback, game_resize, state);
+       XtAddCallback(state->game, XmNresizeCallback, resize, state);
        XtAddCallback(state->game, XmNexposeCallback, expose, state);
 
        XtVaGetValues(state->game, XmNwidth, &state->goal_sz[0],
                                   XmNheight, &state->goal_sz[1],
                                   (char *)NULL);
-       XtAddCallback(state->goal, XmNresizeCallback, goal_resize, state);
+       XtAddCallback(state->goal, XmNresizeCallback, resize, state);
        XtAddCallback(state->goal, XmNexposeCallback, expose, state);
 }
 
index 0a34feee7a9b10f97bd02110ad4d8645c95d1bf8..f827965b8d8a4dc353df510a7bac1fdd44095dad 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -392,14 +392,15 @@ static void start_render(void *data, XtIntervalId *id)
        state->render_proc = XtAppAddWorkProc(app, do_render, state);
 }
 
-void x11_queue_render(struct app_state *state, uint_fast32_t game_mask,
-                                               uint_fast16_t goal_mask)
+void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode)
 {
        uint_fast32_t changed = 0;
        XtAppContext app;
 
-       changed |= state->render_game_mask |= game_mask;
-       changed |= state->render_goal_mask |= goal_mask;
+       if (mode & RENDER_MODE_GOAL)
+               changed |= state->render_goal_mask |= mask;
+       if (mode & RENDER_MODE_GAME)
+               changed |= state->render_game_mask |= mask;
 
        if (state->render_tick || !changed)
                return;