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:
int flash_laserno, isflash;
};
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;
int x, int y, int button)
{
int gx = -1, gy = -1, rangeno = -1, wouldflash = 0;
-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;
{
int ox, oy, dx, dy, i, currl, maxb;
struct island *is;
-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);
int x, int y, int button)
{
int gx = FROMCOORD(x), gy = FROMCOORD(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 direction, mask, i;
int x, int y, int button)
{
int direction, mask, i;
\S{backend-interpret-move} \cw{interpret_move()}
\c char *(*interpret_move)(game_state *state, game_ui *ui,
\S{backend-interpret-move} \cw{interpret_move()}
\c char *(*interpret_move)(game_state *state, game_ui *ui,
+\c const game_drawstate *ds,
\c int x, int y, int button);
This function receives user input and processes it. Its input
\c int x, int y, int button);
This function receives user input and processes it. Its input
coordinates of the mouse pointer relative to the top left of the
puzzle's drawing area.
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
\cw{interpret_move()} may return in three different ways:
\b Returning \cw{NULL} indicates that no action whatsoever occurred
unsigned long *visible;
};
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;
int x, int y, int button)
{
int w = state->w, h = state->h;
-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;
int x, int y, int button)
{
int gx, gy, dx, dy;
int *dsf_scratch, *border_scratch;
};
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;
int x, int y, int button)
{
const int w = state->shared->params.w;
-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;
int x, int y, int button)
{
int w = state->w, h = state->h, wh = w * h;
-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];
int x, int y, int button)
{
char buf[80];
-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):
int x, int y, int button)
{
/* UI operations (play mode):
-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 */
int x, int y, int button)
{
int over_col = 0; /* one-indexed */
#define COORD(x) ( (x) * TILESIZE + BORDER )
#define FROMCOORD(x) ( ((x) - BORDER + TILESIZE) / TILESIZE - 1 )
#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 */;
int x, int y, int button)
{
int w = state->p.w, h = state->p.h /*, wh = w*h */;
-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;
int x, int y, int button)
{
int w = state->par.w;
-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;
int x, int y, int button)
{
enum { NONE, FLIP_LIGHT, FLIP_IMPOSSIBLE } action = NONE;
* Drawing and mouse-handling
*/
* 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;
int x, int y, int button)
{
grid *g = state->game_grid;
#define COORD(x) ( (x+1) * TILE_SIZE + BORDER )
#define FROMCOORD(x) ( (x - BORDER) / TILE_SIZE - 1 )
#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;
int x, int y, int button)
{
int gx = FROMCOORD(x), gy = FROMCOORD(y), idx, curr;
((button) == CURSOR_UP) ? -1 : 0)
((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 */;
int x, int y)
{
int w = state->p.w, h = state->p.h, wh = w*h /*, n = state->p.n */;
return state->map->map[quadrant * wh + ty*w+tx];
}
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];
int x, int y, int button)
{
char *bufp, buf[256];
int cur_x, cur_y; /* -1, -1 for no cursor displayed. */
};
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;
int x, int y, int button)
{
int cx, cy;
* Process a move.
*/
static char *interpret_move(game_state *state, game_ui *ui,
* 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;
{
char *nullret;
int tx = -1, ty = -1, dir = 0;
};
static char *interpret_move(game_state *state, game_ui *ui,
};
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;
{
int cx, cy;
int dx, dy;
-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;
int x, int y, int button)
{
return NULL;
-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;
int x, int y, int button)
{
button &= ~MOD_MASK;
(btn) == CURSOR_DOWN ? D : (btn) == CURSOR_UP ? U :\
(btn) == CURSOR_LEFT ? L : R)
(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 */;
int x, int y, int button)
{
int w = state->shared->w, h = state->shared->h /*, sz = state->shared->sz */;
-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;
int x, int y, int button)
{
int w = state->w, h = state->h;
void (*decode_ui)(game_ui *ui, char *encoding);
void (*changed_state)(game_ui *ui, game_state *oldstate,
game_state *newstate);
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);
game_state *(*execute_move)(game_state *state, char *move);
int preferred_tilesize;
void (*compute_size)(game_params *params, int tilesize, int *x, int *y);
#define COORD(x) ((x) * TILESIZE + BORDER)
#define FROMCOORD(x) (((x) - BORDER) / TILESIZE)
#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};
int x, int y, int button)
{
enum {none, forwards, backwards, hint};
unsigned long *visible;
};
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;
int x, int y, int button)
{
int xc, yc;
int *tiles; /* contains colour and SELECTED. */
};
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;
int x, int y, int button)
{
int tx, ty;
-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;
int mx, int my, int button)
{
int x = FROMCOORD(mx), y = FROMCOORD(my), w = state->w;
-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;
int mx, int my, int button)
{
char buf[80], c;
-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;
int x, int y, int button)
{
int cx = -1, cy = -1, dx, dy;
-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;
int x, int y, int button)
{
int w = state->p.w, h = state->p.h;
int nregions, *entered_items;
};
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;
int x, int y, int button)
{
int cr = state->cr;
-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;
int x, int y, int button)
{
int w = state->p.w, h = state->p.h;
-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;
int x, int y, int button)
{
int w = state->par.w;
-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 */;
int x, int y, int button)
{
int w = state->w, h = state->h, n = state->n /* , wh = w*h */;
#define TILESIZE (ds->tilesize)
#define BORDER (TILESIZE/2)
#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];
int gx,gy;
int g,xi;
char buf[80];
gy = ((y-BORDER-2) / TILESIZE ) - 1;
if (button == 'a' || button == 'A') {
gy = ((y-BORDER-2) / TILESIZE ) - 1;
if (button == 'a' || button == 'A') {
- ds->ascii = ui->ascii ? FALSE : TRUE;
+ ui->ascii = !ui->ascii;
game_state *state, int dir, game_ui *ui,
float animtime, float flashtime) {
int i,j,x,y,xy;
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;
hflash = (int)(flashtime * 5 / FLASH_TIME) % 2;
ds->hshow != ui->hshow || ds->hpencil != ui->hpencil)
hchanged = TRUE;
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;
/* 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];
if (ds->count_errors[i] != state->count_errors[i]) {
stale = TRUE;
ds->count_errors[i] = state->count_errors[i];
if (!ds->started) stale = TRUE;
if (ds->hflash != hflash) stale = TRUE;
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) ||
if (hchanged) {
if ((x == ui->hx && y == ui->hy) ||
ds->hshow = ui->hshow;
ds->hpencil = ui->hpencil;
ds->hflash = hflash;
ds->hshow = ui->hshow;
ds->hpencil = ui->hpencil;
ds->hflash = hflash;
ds->started = TRUE;
return;
}
ds->started = TRUE;
return;
}
-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;
int ox, int oy, int button)
{
int x = FROMCOORD(ox), y = FROMCOORD(oy), n;
-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;
int x, int y, int button)
{
int n = state->params.n;