]> git.draconx.ca Git - rrace.git/commitdiff
motif: State structure cleanup
authorNick Bowler <nbowler@draconx.ca>
Sat, 31 Dec 2022 01:52:23 +0000 (20:52 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 7 Jan 2023 16:43:12 +0000 (11:43 -0500)
- 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.

common
src/game.h
src/motif.c
src/motif.h
src/motif_ui.c
src/x11.c
t/boardmove.c

diff --git a/common b/common
index a56b84487bb43c85cb36e5995c84006be8b81011..8cda0a6cc9cc31edf0fe94c470038f12c8dcc905 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit a56b84487bb43c85cb36e5995c84006be8b81011
+Subproject commit 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905
index e5b9cbed3acffd72dec6bd1ecbdb6b7af090416d..efa7ef0fc95d229d1d045bde9ab45dce19348db4 100644 (file)
@@ -35,6 +35,7 @@ enum {
 
 #define GOAL_SHIFT 6
 #define GOAL_MASK 0x739c0ul
+#define GAME_MASK 0x1fffffful
 
 struct board {
        /*
index c4ea62dbbd25b5d5e4a4b7d6ceec50a3d8f4e40d..fbdc9a750a2e86cb934109de3d3e9aebbb8ec791 100644 (file)
@@ -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));
 }
 
index a008306f5bb44f69eaf63120674c333677341c58..b168c4e5708498e67a5af71e14f722f87d947627 100644 (file)
@@ -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];
 };
 
index 5941834c86ae8b7bcba3ef35290615e5a068ccc0..c6500311a8264017fd638490e44bd84cffd02cd1 100644 (file)
@@ -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);
 }
index 6d09a7dcfc09f7359db1daeba62d980bae65cfd4..459694a4d96a122e103f2e8883316744d1940d2c 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
 #  include <unistd.h>
 #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);
 }
index 089f7b89e9c83efe4606ccceffa835fcfe761f64..7ed1e667a37a60f9760634d69967961c0ccd9f9a 100644 (file)
@@ -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) {