New rule: interpret_move() is passed a pointer to the game_drawstate
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 9 Sep 2012 18:40:12 +0000 (18:40 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 9 Sep 2012 18:40:12 +0000 (18:40 +0000)
basically just so that it can divide mouse coordinates by the tile
size, but is definitely not expected to _write_ to it, and it hadn't
previously occurred to me that anyone might try. Therefore,
interpret_move() now gets a pointer to a _const_ game_drawstate
instead of a writable one.

All existing puzzles cope fine with this API change (as long as the
new const qualifier is also added to a couple of subfunctions to which
interpret_move delegates work), except for the just-committed Undead,
which somehow had ds->ascii and ui->ascii the wrong way round but is
otherwise unproblematic.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@9657 cda61777-01e9-0310-a592-d414129be87e

38 files changed:
blackbox.c
bridges.c
cube.c
devel.but
dominosa.c
fifteen.c
filling.c
flip.c
galaxies.c
guess.c
inertia.c
keen.c
lightup.c
loopy.c
magnets.c
map.c
mines.c
net.c
netslide.c
nullgame.c
pattern.c
pearl.c
pegs.c
puzzles.h
range.c
rect.c
samegame.c
signpost.c
singles.c
sixteen.c
slant.c
solo.c
tents.c
towers.c
twiddle.c
undead.c
unequal.c
untangle.c

index 3a85bd7..1546d91 100644 (file)
@@ -879,7 +879,7 @@ struct game_drawstate {
     int flash_laserno, isflash;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int gx = -1, gy = -1, rangeno = -1, wouldflash = 0;
index 0717a88..a5eef25 100644 (file)
--- a/bridges.c
+++ b/bridges.c
@@ -2157,8 +2157,8 @@ struct game_drawstate {
     int show_hints;
 };
 
-static char *update_drag_dst(game_state *state, game_ui *ui, game_drawstate *ds,
-                            int nx, int ny)
+static char *update_drag_dst(game_state *state, game_ui *ui,
+                             const game_drawstate *ds, int nx, int ny)
 {
     int ox, oy, dx, dy, i, currl, maxb;
     struct island *is;
@@ -2253,7 +2253,7 @@ static char *finish_drag(game_state *state, game_ui *ui)
     return dupstr(buf);
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int gx = FROMCOORD(x), gy = FROMCOORD(y);
diff --git a/cube.c b/cube.c
index cac4640..15c479b 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -1100,7 +1100,7 @@ static int find_move_dest(game_state *from, int direction,
     return dest;
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int direction, mask, i;
index 27ef5d7..970a73a 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -856,7 +856,7 @@ producing new \c{game_state}s.
 \S{backend-interpret-move} \cw{interpret_move()}
 
 \c char *(*interpret_move)(game_state *state, game_ui *ui,
-\c                         game_drawstate *ds,
+\c                         const game_drawstate *ds,
 \c                         int x, int y, int button);
 
 This function receives user input and processes it. Its input
@@ -868,6 +868,11 @@ indicating an arrow or function key or a mouse event; when
 coordinates of the mouse pointer relative to the top left of the
 puzzle's drawing area.
 
+(The pointer to the \c{game_drawstate} is marked \c{const}, because
+\c{interpret_move} should not write to it. The normal use of that
+pointer will be to read the game's tile size parameter in order to
+divide mouse coordinates by it.)
+
 \cw{interpret_move()} may return in three different ways:
 
 \b Returning \cw{NULL} indicates that no action whatsoever occurred
index 02e276c..2662410 100644 (file)
@@ -1001,7 +1001,7 @@ struct game_drawstate {
     unsigned long *visible;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->w, h = state->h;
index 5419f41..1a106e8 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -460,7 +460,7 @@ struct game_drawstate {
     int tilesize;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int gx, gy, dx, dy;
index df68ea7..a0c9fc4 100644 (file)
--- a/filling.c
+++ b/filling.c
@@ -1036,7 +1036,7 @@ struct game_drawstate {
     int *dsf_scratch, *border_scratch;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                             int x, int y, int button)
 {
     const int w = state->shared->params.w;
diff --git a/flip.c b/flip.c
index 6ba683b..c30e484 100644 (file)
--- a/flip.c
+++ b/flip.c
@@ -899,7 +899,7 @@ struct game_drawstate {
     int tilesize;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->w, h = state->h, wh = w * h;
index b9eb603..db89700 100644 (file)
@@ -2369,7 +2369,7 @@ static void coord_round_to_edge(float x, float y, int *xr, int *yr)
 #endif
 
 #ifdef EDITOR
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     char buf[80];
@@ -2404,7 +2404,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     return NULL;
 }
 #else
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     /* UI operations (play mode):
diff --git a/guess.c b/guess.c
index 88a0024..15cf0d9 100644 (file)
--- a/guess.c
+++ b/guess.c
@@ -632,7 +632,7 @@ static char *encode_move(game_state *from, game_ui *ui)
     return buf;
 }
 
-static char *interpret_move(game_state *from, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *from, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int over_col = 0;           /* one-indexed */
index 74fc3c1..eb850ac 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -1534,7 +1534,7 @@ struct game_drawstate {
 #define COORD(x)  ( (x) * TILESIZE + BORDER )
 #define FROMCOORD(x)  ( ((x) - BORDER + TILESIZE) / TILESIZE - 1 )
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->p.w, h = state->p.h /*, wh = w*h */;
diff --git a/keen.c b/keen.c
index 3776283..5087465 100644 (file)
--- a/keen.c
+++ b/keen.c
@@ -1512,7 +1512,7 @@ static int check_errors(game_state *state, long *errors)
     return errs;
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->par.w;
index 8f09263..5beacc7 100644 (file)
--- a/lightup.c
+++ b/lightup.c
@@ -1871,7 +1871,7 @@ struct game_drawstate {
             (pc)) -1 (nil)
         (nil))
  */
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     enum { NONE, FLIP_LIGHT, FLIP_IMPOSSIBLE } action = NONE;
diff --git a/loopy.c b/loopy.c
index 85590fa..5df13d5 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -2813,7 +2813,7 @@ static char *solve_game(game_state *state, game_state *currstate,
  * Drawing and mouse-handling
  */
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                             int x, int y, int button)
 {
     grid *g = state->game_grid;
index e49b7a5..e9b8c7d 100644 (file)
--- a/magnets.c
+++ b/magnets.c
@@ -1754,7 +1754,7 @@ struct game_drawstate {
 #define COORD(x) ( (x+1) * TILE_SIZE + BORDER )
 #define FROMCOORD(x) ( (x - BORDER) / TILE_SIZE - 1 )
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int gx = FROMCOORD(x), gy = FROMCOORD(y), idx, curr;
diff --git a/map.c b/map.c
index 5d170d1..af7c0af 100644 (file)
--- a/map.c
+++ b/map.c
@@ -2342,7 +2342,7 @@ struct game_drawstate {
                            ((button) == CURSOR_UP)    ? -1 : 0)
 
 
-static int region_from_coords(game_state *state, game_drawstate *ds,
+static int region_from_coords(game_state *state, const game_drawstate *ds,
                               int x, int y)
 {
     int w = state->p.w, h = state->p.h, wh = w*h /*, n = state->p.n */;
@@ -2361,7 +2361,7 @@ static int region_from_coords(game_state *state, game_drawstate *ds,
     return state->map->map[quadrant * wh + ty*w+tx];
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     char *bufp, buf[256];
diff --git a/mines.c b/mines.c
index 7801ab4..abd1ad8 100644 (file)
--- a/mines.c
+++ b/mines.c
@@ -2415,7 +2415,7 @@ struct game_drawstate {
     int cur_x, cur_y; /* -1, -1 for no cursor displayed. */
 };
 
-static char *interpret_move(game_state *from, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *from, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int cx, cy;
diff --git a/net.c b/net.c
index 667f939..2e19f1f 100644 (file)
--- a/net.c
+++ b/net.c
@@ -1922,7 +1922,7 @@ struct game_drawstate {
  * Process a move.
  */
 static char *interpret_move(game_state *state, game_ui *ui,
-                           game_drawstate *ds, int x, int y, int button)
+                           const game_drawstate *ds, int x, int y, int button)
 {
     char *nullret;
     int tx = -1, ty = -1, dir = 0;
index 076cad4..8d18652 100644 (file)
@@ -1056,7 +1056,7 @@ struct game_drawstate {
 };
 
 static char *interpret_move(game_state *state, game_ui *ui,
-                           game_drawstate *ds, int x, int y, int button)
+                           const game_drawstate *ds, int x, int y, int button)
 {
     int cx, cy;
     int dx, dy;
index 9e99109..5a0ba42 100644 (file)
@@ -161,7 +161,7 @@ struct game_drawstate {
     int FIXME;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     return NULL;
index b88edc5..ab5be76 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -833,7 +833,7 @@ struct game_drawstate {
     int cur_x, cur_y;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     button &= ~MOD_MASK;
diff --git a/pearl.c b/pearl.c
index 40c32eb..9670592 100644 (file)
--- a/pearl.c
+++ b/pearl.c
@@ -1962,7 +1962,7 @@ static char *mark_in_direction(game_state *state, int x, int y, int dir,
     (btn) == CURSOR_DOWN ? D : (btn) == CURSOR_UP ? U :\
     (btn) == CURSOR_LEFT ? L : R)
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->shared->w, h = state->shared->h /*, sz = state->shared->sz */;
diff --git a/pegs.c b/pegs.c
index d77860c..3dac5fc 100644 (file)
--- a/pegs.c
+++ b/pegs.c
@@ -814,7 +814,7 @@ struct game_drawstate {
     int bgcolour;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->w, h = state->h;
index 48b5b1a..c9cca05 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -499,8 +499,8 @@ struct game {
     void (*decode_ui)(game_ui *ui, char *encoding);
     void (*changed_state)(game_ui *ui, game_state *oldstate,
                           game_state *newstate);
-    char *(*interpret_move)(game_state *state, game_ui *ui, game_drawstate *ds,
-                           int x, int y, int button);
+    char *(*interpret_move)(game_state *state, game_ui *ui,
+                            const game_drawstate *ds, int x, int y, int button);
     game_state *(*execute_move)(game_state *state, char *move);
     int preferred_tilesize;
     void (*compute_size)(game_params *params, int tilesize, int *x, int *y);
diff --git a/range.c b/range.c
index 425259f..43231d9 100644 (file)
--- a/range.c
+++ b/range.c
@@ -1248,7 +1248,7 @@ struct game_drawstate {
 #define COORD(x) ((x) * TILESIZE + BORDER)
 #define FROMCOORD(x) (((x) - BORDER) / TILESIZE)
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                             int x, int y, int button)
 {
     enum {none, forwards, backwards, hint};
diff --git a/rect.c b/rect.c
index 72a00e1..25b2132 100644 (file)
--- a/rect.c
+++ b/rect.c
@@ -2365,7 +2365,7 @@ struct game_drawstate {
     unsigned long *visible;
 };
 
-static char *interpret_move(game_state *from, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *from, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int xc, yc;
index 49dd64e..65ebef7 100644 (file)
@@ -1267,7 +1267,7 @@ struct game_drawstate {
     int *tiles; /* contains colour and SELECTED. */
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int tx, ty;
index 5286b42..b5e22ed 100644 (file)
@@ -1418,7 +1418,7 @@ struct game_drawstate {
     blitter *dragb;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int mx, int my, int button)
 {
     int x = FROMCOORD(mx), y = FROMCOORD(my), w = state->w;
index 6d583aa..32449b6 100644 (file)
--- a/singles.c
+++ b/singles.c
@@ -1471,7 +1471,7 @@ struct game_drawstate {
     unsigned int *flags;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int mx, int my, int button)
 {
     char buf[80], c;
index 8079fac..88c7ef4 100644 (file)
--- a/sixteen.c
+++ b/sixteen.c
@@ -595,7 +595,7 @@ struct game_drawstate {
     int cur_x, cur_y;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int cx = -1, cy = -1, dx, dy;
diff --git a/slant.c b/slant.c
index 52f21d6..2f9de52 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -1666,7 +1666,7 @@ struct game_drawstate {
     long *todraw;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->p.w, h = state->p.h;
diff --git a/solo.c b/solo.c
index 43abc1f..d9bf18d 100644 (file)
--- a/solo.c
+++ b/solo.c
@@ -4511,7 +4511,7 @@ struct game_drawstate {
     int nregions, *entered_items;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int cr = state->cr;
diff --git a/tents.c b/tents.c
index cfdcdc3..ef5debc 100644 (file)
--- a/tents.c
+++ b/tents.c
@@ -1520,7 +1520,7 @@ static int drag_xform(game_ui *ui, int x, int y, int v)
     return v;
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->p.w, h = state->p.h;
index be0a730..bd39554 100644 (file)
--- a/towers.c
+++ b/towers.c
@@ -1255,7 +1255,7 @@ static int check_errors(game_state *state, int *errors)
     return errs;
 }
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->par.w;
index 51a21f0..b5b276f 100644 (file)
--- a/twiddle.c
+++ b/twiddle.c
@@ -640,7 +640,7 @@ struct game_drawstate {
     int cur_x, cur_y;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->w, h = state->h, n = state->n /* , wh = w*h */;
index 6ce6eaa..dab3f50 100644 (file)
--- a/undead.c
+++ b/undead.c
@@ -1646,8 +1646,9 @@ struct game_drawstate {
 #define TILESIZE (ds->tilesize)
 #define BORDER (TILESIZE/2)
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
-                            int x, int y, int button) {
+static char *interpret_move(game_state *state, game_ui *ui,
+                            const game_drawstate *ds, int x, int y, int button)
+{
     int gx,gy;
     int g,xi;
     char buf[80]; 
@@ -1656,7 +1657,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     gy = ((y-BORDER-2) / TILESIZE ) - 1;
 
     if (button == 'a' || button == 'A') {
-        ds->ascii = ui->ascii ? FALSE : TRUE;
+        ui->ascii = !ui->ascii;
         return "";      
     }
     
@@ -2395,7 +2396,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
             game_state *state, int dir, game_ui *ui,
             float animtime, float flashtime) {
     int i,j,x,y,xy;
-    int stale, xi, c, hflash, hchanged;
+    int stale, xi, c, hflash, hchanged, changed_ascii;
 
     hflash = (int)(flashtime * 5 / FLASH_TIME) % 2;
 
@@ -2419,13 +2420,18 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
         ds->hshow != ui->hshow || ds->hpencil != ui->hpencil)
         hchanged = TRUE;
 
+    if (ds->ascii != ui->ascii) {
+        ds->ascii = ui->ascii;
+        changed_ascii = TRUE;
+    }
+
     /* Draw monster count hints */
 
     for (i=0;i<3;i++) {
         stale = FALSE;
         if (!ds->started) stale = TRUE;
         if (ds->hflash != hflash) stale = TRUE;
-        if (ds->ascii != ui->ascii) stale = TRUE;
+        if (changed_ascii) stale = TRUE;
         if (ds->count_errors[i] != state->count_errors[i]) {
             stale = TRUE;
             ds->count_errors[i] = state->count_errors[i];
@@ -2481,7 +2487,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
     
         if (!ds->started) stale = TRUE;
         if (ds->hflash != hflash) stale = TRUE;
-        if (ds->ascii != ui->ascii) stale = TRUE;
+        if (changed_ascii) stale = TRUE;
         
         if (hchanged) {
             if ((x == ui->hx && y == ui->hy) ||
@@ -2520,7 +2526,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
     ds->hshow = ui->hshow;
     ds->hpencil = ui->hpencil;
     ds->hflash = hflash;
-    ui->ascii = ds->ascii;
     ds->started = TRUE;
     return;
 }
index 5dcca36..d16a572 100644 (file)
--- a/unequal.c
+++ b/unequal.c
@@ -1371,7 +1371,7 @@ struct game_drawstate {
     int hflash;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int ox, int oy, int button)
 {
     int x = FROMCOORD(ox), y = FROMCOORD(oy), n;
index c07c957..beb2871 100644 (file)
@@ -1072,7 +1072,7 @@ struct game_drawstate {
     long *x, *y;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int n = state->params.n;