From 86abb005c1109dfb7ac55f0d38474c5fdcb52b78 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 7 Dec 2022 01:04:37 -0500 Subject: [PATCH] Alter x11_queue_render interface to better match usage. 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 | 2 +- src/motif.h | 22 ++++++++++++++++++++-- src/motif_ui.c | 24 +++++++++++------------- src/x11.c | 9 +++++---- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/common b/common index 8cda0a6..a56b844 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905 +Subproject commit a56b84487bb43c85cb36e5995c84006be8b81011 diff --git a/src/motif.h b/src/motif.h index c85e8a9..076f4f6 100644 --- a/src/motif.h +++ b/src/motif.h @@ -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 diff --git a/src/motif_ui.c b/src/motif_ui.c index 5056d9c..3658615 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -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); } diff --git a/src/x11.c b/src/x11.c index 0a34fee..f827965 100644 --- 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; -- 2.43.2