Redraws during undo in Sixteen had been broken by my faffing about

with last_movement_sense (which was necessary to fix the animation
when the grid was only 2 squares wide in either dimension). Movement
sense is now inverted if the move being animated is an undo.

[originally from svn r4191]
This commit is contained in:
Simon Tatham
2004-05-03 12:12:30 +00:00
parent ccbf3ca6f1
commit 2a1b7e0dd3

View File

@ -536,7 +536,7 @@ static void draw_arrow(frontend *fe, int x, int y, int xdx, int xdy)
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
game_state *state, float animtime, float flashtime) game_state *state, float animtime, float flashtime)
{ {
int i, pass, bgcolour; int i, bgcolour;
if (flashtime > 0) { if (flashtime > 0) {
int frame = (int)(flashtime / FLASH_FRAME); int frame = (int)(flashtime / FLASH_FRAME);
@ -587,13 +587,11 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
} }
/* /*
* Now draw each tile. We do this in two passes to make * Now draw each tile.
* animation easy.
*/ */
clip(fe, COORD(0), COORD(0), TILE_SIZE*state->w, TILE_SIZE*state->h); clip(fe, COORD(0), COORD(0), TILE_SIZE*state->w, TILE_SIZE*state->h);
for (pass = 0; pass < 2; pass++) {
for (i = 0; i < state->n; i++) { for (i = 0; i < state->n; i++) {
int t, t0; int t, t0;
/* /*
@ -621,17 +619,13 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
if (t == -1) { if (t == -1) {
int x0, y0, x1, y1, dx, dy; int x0, y0, x1, y1, dx, dy;
int j; int j;
/*
* On the first pass, just blank the tile.
*/
if (pass == 0) {
x = COORD(X(state, i));
y = COORD(Y(state, i));
x2 = y2 = -1;
t = 0;
} else {
float c; float c;
int sense;
if (oldstate && state->movecount < oldstate->movecount)
sense = -oldstate->last_movement_sense;
else
sense = state->last_movement_sense;
t = state->tiles[i]; t = state->tiles[i];
@ -655,14 +649,14 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
dx = (x1 - x0); dx = (x1 - x0);
if (dx != 0 && if (dx != 0 &&
dx != TILE_SIZE * state->last_movement_sense) { dx != TILE_SIZE * sense) {
dx = (dx < 0 ? dx + TILE_SIZE * state->w : dx = (dx < 0 ? dx + TILE_SIZE * state->w :
dx - TILE_SIZE * state->w); dx - TILE_SIZE * state->w);
assert(abs(dx) == TILE_SIZE); assert(abs(dx) == TILE_SIZE);
} }
dy = (y1 - y0); dy = (y1 - y0);
if (dy != 0 && if (dy != 0 &&
dy != TILE_SIZE * state->last_movement_sense) { dy != TILE_SIZE * sense) {
dy = (dy < 0 ? dy + TILE_SIZE * state->h : dy = (dy < 0 ? dy + TILE_SIZE * state->h :
dy - TILE_SIZE * state->h); dy - TILE_SIZE * state->h);
assert(abs(dy) == TILE_SIZE); assert(abs(dy) == TILE_SIZE);
@ -676,11 +670,7 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
y = y0 + (int)(c * dy); y = y0 + (int)(c * dy);
x2 = x1 - dx + (int)(c * dx); x2 = x1 - dx + (int)(c * dx);
y2 = y1 - dy + (int)(c * dy); y2 = y1 - dy + (int)(c * dy);
}
} else { } else {
if (pass == 0)
continue;
x = COORD(X(state, i)); x = COORD(X(state, i));
y = COORD(Y(state, i)); y = COORD(Y(state, i));
x2 = y2 = -1; x2 = y2 = -1;
@ -692,7 +682,6 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
} }
ds->tiles[i] = t0; ds->tiles[i] = t0;
} }
}
unclip(fe); unclip(fe);