mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Cleanups to completion flashes: all four of these games used to
redraw the whole window _every_ time game_redraw() was called during a flash. Now they only redraw the whole window every time the background colour actually changes. Thanks to James H for much of the work. [originally from svn r6166]
This commit is contained in:
@ -859,7 +859,7 @@ struct game_drawstate {
|
|||||||
int tilesize, crad, rrad, w, h; /* w and h to make macros work... */
|
int tilesize, crad, rrad, w, h; /* w and h to make macros work... */
|
||||||
unsigned int *grid; /* as the game_state grid */
|
unsigned int *grid; /* as the game_state grid */
|
||||||
int started, reveal;
|
int started, reveal;
|
||||||
int flash_laserno;
|
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, game_drawstate *ds,
|
||||||
@ -1112,6 +1112,7 @@ static game_drawstate *game_new_drawstate(game_state *state)
|
|||||||
memset(ds->grid, 0, (state->w+2)*(state->h+2)*sizeof(unsigned int));
|
memset(ds->grid, 0, (state->w+2)*(state->h+2)*sizeof(unsigned int));
|
||||||
ds->started = ds->reveal = 0;
|
ds->started = ds->reveal = 0;
|
||||||
ds->flash_laserno = LASER_EMPTY;
|
ds->flash_laserno = LASER_EMPTY;
|
||||||
|
ds->isflash = 0;
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
@ -1266,7 +1267,6 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
if (flashtime > 0) {
|
if (flashtime > 0) {
|
||||||
int frame = (int)(flashtime / FLASH_FRAME);
|
int frame = (int)(flashtime / FLASH_FRAME);
|
||||||
isflash = (frame % 2) == 0;
|
isflash = (frame % 2) == 0;
|
||||||
force = 1;
|
|
||||||
debug(("game_redraw: flashtime = %f", flashtime));
|
debug(("game_redraw: flashtime = %f", flashtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1299,6 +1299,8 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
ds->started = 1;
|
ds->started = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isflash != ds->isflash) force = 1;
|
||||||
|
|
||||||
/* draw the arena */
|
/* draw the arena */
|
||||||
for (x = 0; x < state->w; x++) {
|
for (x = 0; x < state->w; x++) {
|
||||||
for (y = 0; y < state->h; y++) {
|
for (y = 0; y < state->h; y++) {
|
||||||
@ -1324,6 +1326,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
draw_update(fe, TODRAW(0), TODRAW(0), TILE_SIZE, TILE_SIZE);
|
draw_update(fe, TODRAW(0), TODRAW(0), TILE_SIZE, TILE_SIZE);
|
||||||
ds->reveal = state->reveal;
|
ds->reveal = state->reveal;
|
||||||
ds->flash_laserno = ui->flash_laserno;
|
ds->flash_laserno = ui->flash_laserno;
|
||||||
|
ds->isflash = isflash;
|
||||||
|
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
8
mines.c
8
mines.c
@ -2384,7 +2384,7 @@ static void game_changed_state(game_ui *ui, game_state *oldstate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct game_drawstate {
|
struct game_drawstate {
|
||||||
int w, h, started, tilesize;
|
int w, h, started, tilesize, bg;
|
||||||
signed char *grid;
|
signed char *grid;
|
||||||
/*
|
/*
|
||||||
* Items in this `grid' array have all the same values as in
|
* Items in this `grid' array have all the same values as in
|
||||||
@ -2723,6 +2723,7 @@ static game_drawstate *game_new_drawstate(game_state *state)
|
|||||||
ds->started = FALSE;
|
ds->started = FALSE;
|
||||||
ds->tilesize = 0; /* not decided yet */
|
ds->tilesize = 0; /* not decided yet */
|
||||||
ds->grid = snewn(ds->w * ds->h, signed char);
|
ds->grid = snewn(ds->w * ds->h, signed char);
|
||||||
|
ds->bg = -1;
|
||||||
|
|
||||||
memset(ds->grid, -99, ds->w * ds->h);
|
memset(ds->grid, -99, ds->w * ds->h);
|
||||||
|
|
||||||
@ -2963,11 +2964,12 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
(abs(x-ui->hx) <= ui->hradius && abs(y-ui->hy) <= ui->hradius))
|
(abs(x-ui->hx) <= ui->hradius && abs(y-ui->hy) <= ui->hradius))
|
||||||
v -= 20;
|
v -= 20;
|
||||||
|
|
||||||
if (ds->grid[y*ds->w+x] != v || bg != COL_BACKGROUND) {
|
if (ds->grid[y*ds->w+x] != v || bg != ds->bg) {
|
||||||
draw_tile(fe, ds, COORD(x), COORD(y), v, bg);
|
draw_tile(fe, ds, COORD(x), COORD(y), v, bg);
|
||||||
ds->grid[y*ds->w+x] = (bg == COL_BACKGROUND ? v : -10);
|
ds->grid[y*ds->w+x] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ds->bg = bg;
|
||||||
|
|
||||||
if (!state->layout->mines)
|
if (!state->layout->mines)
|
||||||
mines = state->layout->n;
|
mines = state->layout->n;
|
||||||
|
@ -1432,6 +1432,7 @@ static game_drawstate *game_new_drawstate(game_state *state)
|
|||||||
ds->started = 0;
|
ds->started = 0;
|
||||||
ds->tileinner = ds->tilegap = 0; /* not decided yet */
|
ds->tileinner = ds->tilegap = 0; /* not decided yet */
|
||||||
ds->tiles = snewn(state->n, int);
|
ds->tiles = snewn(state->n, int);
|
||||||
|
ds->bgcolour = -1;
|
||||||
for (i = 0; i < state->n; i++)
|
for (i = 0; i < state->n; i++)
|
||||||
ds->tiles[i] = -1;
|
ds->tiles[i] = -1;
|
||||||
|
|
||||||
@ -1564,7 +1565,6 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
* no animation); when we do we might well want to be looking
|
* no animation); when we do we might well want to be looking
|
||||||
* at the tile colours from oldstate, not state. */
|
* at the tile colours from oldstate, not state. */
|
||||||
if ((oldstate && COL(oldstate,x,y) != col) ||
|
if ((oldstate && COL(oldstate,x,y) != col) ||
|
||||||
(flashtime > 0.0) ||
|
|
||||||
(ds->bgcolour != bgcolour) ||
|
(ds->bgcolour != bgcolour) ||
|
||||||
(tile != ds->tiles[i])) {
|
(tile != ds->tiles[i])) {
|
||||||
tile_redraw(fe, ds, x, y, dright, dbelow, tile, bgcolour);
|
tile_redraw(fe, ds, x, y, dright, dbelow, tile, bgcolour);
|
||||||
|
89
untangle.c
89
untangle.c
@ -1063,6 +1063,8 @@ static void game_changed_state(game_ui *ui, game_state *oldstate,
|
|||||||
|
|
||||||
struct game_drawstate {
|
struct game_drawstate {
|
||||||
long tilesize;
|
long tilesize;
|
||||||
|
int bg, dragpoint;
|
||||||
|
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, game_drawstate *ds,
|
||||||
@ -1236,14 +1238,23 @@ static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
|||||||
static game_drawstate *game_new_drawstate(game_state *state)
|
static game_drawstate *game_new_drawstate(game_state *state)
|
||||||
{
|
{
|
||||||
struct game_drawstate *ds = snew(struct game_drawstate);
|
struct game_drawstate *ds = snew(struct game_drawstate);
|
||||||
|
int i;
|
||||||
|
|
||||||
ds->tilesize = 0;
|
ds->tilesize = 0;
|
||||||
|
ds->x = snewn(state->params.n, long);
|
||||||
|
ds->y = snewn(state->params.n, long);
|
||||||
|
for (i = 0; i < state->params.n; i++)
|
||||||
|
ds->x[i] = ds->y[i] = -1;
|
||||||
|
ds->bg = -1;
|
||||||
|
ds->dragpoint = -1;
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_free_drawstate(game_drawstate *ds)
|
static void game_free_drawstate(game_drawstate *ds)
|
||||||
{
|
{
|
||||||
|
sfree(ds->y);
|
||||||
|
sfree(ds->x);
|
||||||
sfree(ds);
|
sfree(ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1265,7 +1276,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
int w, h;
|
int w, h;
|
||||||
edge *e;
|
edge *e;
|
||||||
int i, j;
|
int i, j;
|
||||||
int bg;
|
int bg, points_moved;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There's no terribly sensible way to do partial redraws of
|
* There's no terribly sensible way to do partial redraws of
|
||||||
@ -1280,6 +1291,43 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
else
|
else
|
||||||
bg = COL_FLASH2;
|
bg = COL_FLASH2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To prevent excessive spinning on redraw during a completion
|
||||||
|
* flash, we first check to see if _either_ the flash
|
||||||
|
* background colour has changed _or_ at least one point has
|
||||||
|
* moved _or_ a drag has begun or ended, and abandon the redraw
|
||||||
|
* if neither is the case.
|
||||||
|
*
|
||||||
|
* Also in this loop we work out the coordinates of all the
|
||||||
|
* points for this redraw.
|
||||||
|
*/
|
||||||
|
points_moved = FALSE;
|
||||||
|
for (i = 0; i < state->params.n; i++) {
|
||||||
|
point p = state->pts[i];
|
||||||
|
long x, y;
|
||||||
|
|
||||||
|
if (ui->dragpoint == i)
|
||||||
|
p = ui->newpoint;
|
||||||
|
|
||||||
|
if (oldstate)
|
||||||
|
p = mix(oldstate->pts[i], p, animtime / ui->anim_length);
|
||||||
|
|
||||||
|
x = p.x * ds->tilesize / p.d;
|
||||||
|
y = p.y * ds->tilesize / p.d;
|
||||||
|
|
||||||
|
if (ds->x[i] != x || ds->y[i] != y)
|
||||||
|
points_moved = TRUE;
|
||||||
|
|
||||||
|
ds->x[i] = x;
|
||||||
|
ds->y[i] = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds->bg == bg && ds->dragpoint == ui->dragpoint && !points_moved)
|
||||||
|
return; /* nothing to do */
|
||||||
|
|
||||||
|
ds->dragpoint = ui->dragpoint;
|
||||||
|
ds->bg = bg;
|
||||||
|
|
||||||
game_compute_size(&state->params, ds->tilesize, &w, &h);
|
game_compute_size(&state->params, ds->tilesize, &w, &h);
|
||||||
draw_rect(fe, 0, 0, w, h, bg);
|
draw_rect(fe, 0, 0, w, h, bg);
|
||||||
|
|
||||||
@ -1288,27 +1336,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++) {
|
for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++) {
|
||||||
point p1, p2;
|
draw_line(fe, ds->x[e->a], ds->y[e->a], ds->x[e->b], ds->y[e->b],
|
||||||
long x1, y1, x2, y2;
|
|
||||||
|
|
||||||
p1 = state->pts[e->a];
|
|
||||||
p2 = state->pts[e->b];
|
|
||||||
if (ui->dragpoint == e->a)
|
|
||||||
p1 = ui->newpoint;
|
|
||||||
else if (ui->dragpoint == e->b)
|
|
||||||
p2 = ui->newpoint;
|
|
||||||
|
|
||||||
if (oldstate) {
|
|
||||||
p1 = mix(oldstate->pts[e->a], p1, animtime / ui->anim_length);
|
|
||||||
p2 = mix(oldstate->pts[e->b], p2, animtime / ui->anim_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
x1 = p1.x * ds->tilesize / p1.d;
|
|
||||||
y1 = p1.y * ds->tilesize / p1.d;
|
|
||||||
x2 = p2.x * ds->tilesize / p2.d;
|
|
||||||
y2 = p2.y * ds->tilesize / p2.d;
|
|
||||||
|
|
||||||
draw_line(fe, x1, y1, x2, y2,
|
|
||||||
#ifdef SHOW_CROSSINGS
|
#ifdef SHOW_CROSSINGS
|
||||||
(oldstate?oldstate:state)->crosses[i] ?
|
(oldstate?oldstate:state)->crosses[i] ?
|
||||||
COL_CROSSEDLINE :
|
COL_CROSSEDLINE :
|
||||||
@ -1326,12 +1354,9 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
int thisc = (j == 0 ? COL_POINT :
|
int thisc = (j == 0 ? COL_POINT :
|
||||||
j == 1 ? COL_NEIGHBOUR : COL_DRAGPOINT);
|
j == 1 ? COL_NEIGHBOUR : COL_DRAGPOINT);
|
||||||
for (i = 0; i < state->params.n; i++) {
|
for (i = 0; i < state->params.n; i++) {
|
||||||
long x, y;
|
|
||||||
int c;
|
int c;
|
||||||
point p = state->pts[i];
|
|
||||||
|
|
||||||
if (ui->dragpoint == i) {
|
if (ui->dragpoint == i) {
|
||||||
p = ui->newpoint;
|
|
||||||
c = COL_DRAGPOINT;
|
c = COL_DRAGPOINT;
|
||||||
} else if (ui->dragpoint >= 0 &&
|
} else if (ui->dragpoint >= 0 &&
|
||||||
isedge(state->graph->edges, ui->dragpoint, i)) {
|
isedge(state->graph->edges, ui->dragpoint, i)) {
|
||||||
@ -1340,23 +1365,19 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
c = COL_POINT;
|
c = COL_POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldstate)
|
|
||||||
p = mix(oldstate->pts[i], p, animtime / ui->anim_length);
|
|
||||||
|
|
||||||
if (c == thisc) {
|
if (c == thisc) {
|
||||||
x = p.x * ds->tilesize / p.d;
|
|
||||||
y = p.y * ds->tilesize / p.d;
|
|
||||||
|
|
||||||
#ifdef VERTEX_NUMBERS
|
#ifdef VERTEX_NUMBERS
|
||||||
draw_circle(fe, x, y, DRAG_THRESHOLD, bg, bg);
|
draw_circle(fe, ds->x[i], ds->y[i], DRAG_THRESHOLD, bg, bg);
|
||||||
{
|
{
|
||||||
char buf[80];
|
char buf[80];
|
||||||
sprintf(buf, "%d", i);
|
sprintf(buf, "%d", i);
|
||||||
draw_text(fe, x, y, FONT_VARIABLE, DRAG_THRESHOLD*3/2,
|
draw_text(fe, ds->x[i], ds->y[i], FONT_VARIABLE,
|
||||||
|
DRAG_THRESHOLD*3/2,
|
||||||
ALIGN_VCENTRE|ALIGN_HCENTRE, c, buf);
|
ALIGN_VCENTRE|ALIGN_HCENTRE, c, buf);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
draw_circle(fe, x, y, CIRCLE_RADIUS, c, COL_OUTLINE);
|
draw_circle(fe, ds->x[i], ds->y[i], CIRCLE_RADIUS,
|
||||||
|
c, COL_OUTLINE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user