diff options
| author | Simon Tatham <anakin@pobox.com> | 2012-09-09 18:40:12 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2012-09-09 18:40:12 +0000 |
| commit | 3b250baa02a7332510685948bf17576c397b8ceb (patch) | |
| tree | db43c6ec326fee66d6612e363b83e021054ec87f | |
| parent | 55748a60cbd964f697f84ed57c8fc5299406fcdf (diff) | |
| download | puzzles-3b250baa02a7332510685948bf17576c397b8ceb.zip puzzles-3b250baa02a7332510685948bf17576c397b8ceb.tar.gz puzzles-3b250baa02a7332510685948bf17576c397b8ceb.tar.bz2 puzzles-3b250baa02a7332510685948bf17576c397b8ceb.tar.xz | |
New rule: interpret_move() is passed a pointer to the game_drawstate
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.
[originally from svn r9657]
| -rw-r--r-- | blackbox.c | 2 | ||||
| -rw-r--r-- | bridges.c | 6 | ||||
| -rw-r--r-- | cube.c | 2 | ||||
| -rw-r--r-- | devel.but | 7 | ||||
| -rw-r--r-- | dominosa.c | 2 | ||||
| -rw-r--r-- | fifteen.c | 2 | ||||
| -rw-r--r-- | filling.c | 2 | ||||
| -rw-r--r-- | flip.c | 2 | ||||
| -rw-r--r-- | galaxies.c | 4 | ||||
| -rw-r--r-- | guess.c | 2 | ||||
| -rw-r--r-- | inertia.c | 2 | ||||
| -rw-r--r-- | keen.c | 2 | ||||
| -rw-r--r-- | lightup.c | 2 | ||||
| -rw-r--r-- | loopy.c | 2 | ||||
| -rw-r--r-- | magnets.c | 2 | ||||
| -rw-r--r-- | map.c | 4 | ||||
| -rw-r--r-- | mines.c | 2 | ||||
| -rw-r--r-- | net.c | 2 | ||||
| -rw-r--r-- | netslide.c | 2 | ||||
| -rw-r--r-- | nullgame.c | 2 | ||||
| -rw-r--r-- | pattern.c | 2 | ||||
| -rw-r--r-- | pearl.c | 2 | ||||
| -rw-r--r-- | pegs.c | 2 | ||||
| -rw-r--r-- | puzzles.h | 4 | ||||
| -rw-r--r-- | range.c | 2 | ||||
| -rw-r--r-- | rect.c | 2 | ||||
| -rw-r--r-- | samegame.c | 2 | ||||
| -rw-r--r-- | signpost.c | 2 | ||||
| -rw-r--r-- | singles.c | 2 | ||||
| -rw-r--r-- | sixteen.c | 2 | ||||
| -rw-r--r-- | slant.c | 2 | ||||
| -rw-r--r-- | solo.c | 2 | ||||
| -rw-r--r-- | tents.c | 2 | ||||
| -rw-r--r-- | towers.c | 2 | ||||
| -rw-r--r-- | twiddle.c | 2 | ||||
| -rw-r--r-- | undead.c | 19 | ||||
| -rw-r--r-- | unequal.c | 2 | ||||
| -rw-r--r-- | untangle.c | 2 |
38 files changed, 59 insertions, 49 deletions
@@ -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; @@ -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); @@ -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; @@ -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 @@ -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; @@ -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; @@ -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; @@ -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; @@ -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): @@ -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 */ @@ -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 */; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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]; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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 */; @@ -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; @@ -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); @@ -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}; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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 */; @@ -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; } @@ -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; @@ -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; |