From: Nick Bowler Date: Sat, 31 Dec 2022 01:52:23 +0000 (-0500) Subject: motif: State structure cleanup X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/ca97af514870895e228df0443adc5a16be4d9a78 motif: State structure cleanup - We don't actually need to store the render task IDs in the state structure; the only thing we actually care about is to avoid multiple registration. We can use two otherwise-unused bits of the render mask to track this. - The window size tracking is no longer used, so these members are just a waste of space and can be removed. - The remaining members can be rearranged to avoid padding. --- diff --git a/common b/common index a56b844..8cda0a6 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit a56b84487bb43c85cb36e5995c84006be8b81011 +Subproject commit 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905 diff --git a/src/game.h b/src/game.h index e5b9cbe..efa7ef0 100644 --- a/src/game.h +++ b/src/game.h @@ -35,6 +35,7 @@ enum { #define GOAL_SHIFT 6 #define GOAL_MASK 0x739c0ul +#define GAME_MASK 0x1fffffful struct board { /* diff --git a/src/motif.c b/src/motif.c index c4ea62d..fbdc9a7 100644 --- a/src/motif.c +++ b/src/motif.c @@ -178,7 +178,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; + state->view_goal_on_game = !!view_goal; x11_redraw_game(state, game_check_goal(&state->board)); } diff --git a/src/motif.h b/src/motif.h index a008306..b168c4e 100644 --- a/src/motif.h +++ b/src/motif.h @@ -27,29 +27,22 @@ struct app_state { struct board board; Widget game, goal; - struct xcounter *timer; - /* Current window width/height for resize handling. */ - Dimension game_sz[2], goal_sz[2]; - XtIntervalId timer_tick; - - XtIntervalId render_tick; - XtWorkProcId render_proc; + Pixmap icon_pixmap; + GC tile_gc; uint_least32_t render_game_mask; uint_least16_t render_goal_mask; uint_least16_t game_tile_sz, goal_tile_sz; /* If true, the goal will be displayed over the main play area. */ - int view_goal_on_game; + uint_least8_t view_goal_on_game; /* Whether to set _NET_WM_ICON property on WMShell */ - int use_ewmh_icons; + uint_least8_t use_ewmh_icons; - GC tile_gc; - Pixmap icon_pixmap; uint_least32_t tile_colour[TILE_MAX-1][3]; }; diff --git a/src/motif_ui.c b/src/motif_ui.c index 5941834..c650031 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -275,15 +275,8 @@ void ui_initialize(struct app_state *state, Widget shell) configure_mainwin(state, XtNameToWidget(shell, "*game")); - XtVaGetValues(state->game, XmNwidth, &state->game_sz[0], - XmNheight, &state->game_sz[1], - (char *)NULL); 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, resize, state); XtAddCallback(state->goal, XmNexposeCallback, expose, state); } diff --git a/src/x11.c b/src/x11.c index 6d09a7d..459694a 100644 --- a/src/x11.c +++ b/src/x11.c @@ -38,6 +38,11 @@ # include #endif +/* status flags in the upper bits are ORed into the game mask which only + * needs the lower 25 bits */ +#define X11_TICK_INSTALLED (1ul << 31) +#define X11_PROC_INSTALLED (1ul << 30) + enum { NUM_TILE_COLOURS = COLOUR_MAX*(TILE_MAX-1), COLOUR_UI_GAMEBG = NUM_TILE_COLOURS, @@ -321,8 +326,6 @@ static Boolean do_render(void *data) x11_redraw_game(state, state->render_game_mask); state->render_goal_mask = state->render_game_mask = 0; - state->render_proc = 0; - state->render_tick = 0; return True; } @@ -331,11 +334,12 @@ static void start_render(void *data, XtIntervalId *id) struct app_state *state = data; XtAppContext app; - if (state->render_proc) + if (state->render_game_mask & X11_PROC_INSTALLED) return; + state->render_game_mask |= X11_PROC_INSTALLED; app = XtWidgetToApplicationContext(state->game); - state->render_proc = XtAppAddWorkProc(app, do_render, state); + XtAppAddWorkProc(app, do_render, state); } void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode) @@ -343,14 +347,16 @@ void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode) uint_fast32_t changed = 0; XtAppContext app; + mask &= GAME_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) + if (changed & X11_TICK_INSTALLED || !changed) return; + state->render_game_mask |= X11_TICK_INSTALLED; app = XtWidgetToApplicationContext(state->game); - state->render_tick = XtAppAddTimeOut(app, 3, start_render, state); + XtAppAddTimeOut(app, 3, start_render, state); } diff --git a/t/boardmove.c b/t/boardmove.c index 089f7b8..7ed1e66 100644 --- a/t/boardmove.c +++ b/t/boardmove.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) board.x = get_seq(seq[i++]); board.y = get_seq(seq[i++]); - board.game[0] = 0x1ffffff ^ board_position(board.x, board.y); + board.game[0] = GAME_MASK ^ board_position(board.x, board.y); board.game[1] = board.game[2] = board.game[3] = board.game[0]; while (1) {