int tilesize, crad, rrad, w, h; /* w and h to make macros work... */
unsigned int *grid; /* as the game_state grid */
int started, reveal;
- int flash_laserno;
+ int flash_laserno, isflash;
};
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
memset(ds->grid, 0, (state->w+2)*(state->h+2)*sizeof(unsigned int));
ds->started = ds->reveal = 0;
ds->flash_laserno = LASER_EMPTY;
+ ds->isflash = 0;
return ds;
}
if (flashtime > 0) {
int frame = (int)(flashtime / FLASH_FRAME);
isflash = (frame % 2) == 0;
- force = 1;
debug(("game_redraw: flashtime = %f", flashtime));
}
ds->started = 1;
}
+ if (isflash != ds->isflash) force = 1;
+
/* draw the arena */
for (x = 0; x < state->w; x++) {
for (y = 0; y < state->h; y++) {
draw_update(fe, TODRAW(0), TODRAW(0), TILE_SIZE, TILE_SIZE);
ds->reveal = state->reveal;
ds->flash_laserno = ui->flash_laserno;
+ ds->isflash = isflash;
{
char buf[256];
}
struct game_drawstate {
- int w, h, started, tilesize;
+ int w, h, started, tilesize, bg;
signed char *grid;
/*
* Items in this `grid' array have all the same values as in
ds->started = FALSE;
ds->tilesize = 0; /* not decided yet */
ds->grid = snewn(ds->w * ds->h, signed char);
+ ds->bg = -1;
memset(ds->grid, -99, ds->w * ds->h);
(abs(x-ui->hx) <= ui->hradius && abs(y-ui->hy) <= ui->hradius))
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);
- 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)
mines = state->layout->n;
struct game_drawstate {
long tilesize;
+ int bg, dragpoint;
+ long *x, *y;
};
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
static game_drawstate *game_new_drawstate(game_state *state)
{
struct game_drawstate *ds = snew(struct game_drawstate);
+ int i;
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;
}
static void game_free_drawstate(game_drawstate *ds)
{
+ sfree(ds->y);
+ sfree(ds->x);
sfree(ds);
}
int w, h;
edge *e;
int i, j;
- int bg;
+ int bg, points_moved;
/*
* There's no terribly sensible way to do partial redraws of
else
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);
draw_rect(fe, 0, 0, w, h, bg);
*/
for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++) {
- point p1, p2;
- 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,
+ draw_line(fe, ds->x[e->a], ds->y[e->a], ds->x[e->b], ds->y[e->b],
#ifdef SHOW_CROSSINGS
(oldstate?oldstate:state)->crosses[i] ?
COL_CROSSEDLINE :
int thisc = (j == 0 ? COL_POINT :
j == 1 ? COL_NEIGHBOUR : COL_DRAGPOINT);
for (i = 0; i < state->params.n; i++) {
- long x, y;
int c;
- point p = state->pts[i];
if (ui->dragpoint == i) {
- p = ui->newpoint;
c = COL_DRAGPOINT;
} else if (ui->dragpoint >= 0 &&
isedge(state->graph->edges, ui->dragpoint, i)) {
c = COL_POINT;
}
- if (oldstate)
- p = mix(oldstate->pts[i], p, animtime / ui->anim_length);
-
if (c == thisc) {
- x = p.x * ds->tilesize / p.d;
- y = p.y * ds->tilesize / p.d;
-
#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];
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);
}
#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
}
}