mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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:
169
sixteen.c
169
sixteen.c
@ -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,111 +587,100 @@ 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;
|
/*
|
||||||
/*
|
* Figure out what should be displayed at this
|
||||||
* Figure out what should be displayed at this
|
* location. It's either a simple tile, or it's a
|
||||||
* location. It's either a simple tile, or it's a
|
* transition between two tiles (in which case we say
|
||||||
* transition between two tiles (in which case we say
|
* -1 because it must always be drawn).
|
||||||
* -1 because it must always be drawn).
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
if (oldstate && oldstate->tiles[i] != state->tiles[i])
|
if (oldstate && oldstate->tiles[i] != state->tiles[i])
|
||||||
t = -1;
|
t = -1;
|
||||||
else
|
else
|
||||||
t = state->tiles[i];
|
t = state->tiles[i];
|
||||||
|
|
||||||
t0 = t;
|
t0 = t;
|
||||||
|
|
||||||
if (ds->bgcolour != bgcolour || /* always redraw when flashing */
|
if (ds->bgcolour != bgcolour || /* always redraw when flashing */
|
||||||
ds->tiles[i] != t || ds->tiles[i] == -1 || t == -1) {
|
ds->tiles[i] != t || ds->tiles[i] == -1 || t == -1) {
|
||||||
int x, y, x2, y2;
|
int x, y, x2, y2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out what to _actually_ draw, and where to
|
* Figure out what to _actually_ draw, and where to
|
||||||
* draw it.
|
* draw it.
|
||||||
*/
|
*/
|
||||||
if (t == -1) {
|
if (t == -1) {
|
||||||
int x0, y0, x1, y1, dx, dy;
|
int x0, y0, x1, y1, dx, dy;
|
||||||
int j;
|
int j;
|
||||||
|
float c;
|
||||||
|
int sense;
|
||||||
|
|
||||||
/*
|
if (oldstate && state->movecount < oldstate->movecount)
|
||||||
* On the first pass, just blank the tile.
|
sense = -oldstate->last_movement_sense;
|
||||||
*/
|
else
|
||||||
if (pass == 0) {
|
sense = state->last_movement_sense;
|
||||||
x = COORD(X(state, i));
|
|
||||||
y = COORD(Y(state, i));
|
|
||||||
x2 = y2 = -1;
|
|
||||||
t = 0;
|
|
||||||
} else {
|
|
||||||
float c;
|
|
||||||
|
|
||||||
t = state->tiles[i];
|
t = state->tiles[i];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: must be prepared to draw a double
|
* FIXME: must be prepared to draw a double
|
||||||
* tile in some situations.
|
* tile in some situations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the coordinates of this tile in the old and
|
* Find the coordinates of this tile in the old and
|
||||||
* new states.
|
* new states.
|
||||||
*/
|
*/
|
||||||
x1 = COORD(X(state, i));
|
x1 = COORD(X(state, i));
|
||||||
y1 = COORD(Y(state, i));
|
y1 = COORD(Y(state, i));
|
||||||
for (j = 0; j < oldstate->n; j++)
|
for (j = 0; j < oldstate->n; j++)
|
||||||
if (oldstate->tiles[j] == state->tiles[i])
|
if (oldstate->tiles[j] == state->tiles[i])
|
||||||
break;
|
break;
|
||||||
assert(j < oldstate->n);
|
assert(j < oldstate->n);
|
||||||
x0 = COORD(X(state, j));
|
x0 = COORD(X(state, j));
|
||||||
y0 = COORD(Y(state, j));
|
y0 = COORD(Y(state, j));
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
c = (animtime / ANIM_TIME);
|
c = (animtime / ANIM_TIME);
|
||||||
if (c < 0.0F) c = 0.0F;
|
if (c < 0.0F) c = 0.0F;
|
||||||
if (c > 1.0F) c = 1.0F;
|
if (c > 1.0F) c = 1.0F;
|
||||||
|
|
||||||
x = x0 + (int)(c * dx);
|
x = x0 + (int)(c * dx);
|
||||||
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 {
|
||||||
|
x = COORD(X(state, i));
|
||||||
|
y = COORD(Y(state, i));
|
||||||
|
x2 = y2 = -1;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
draw_tile(fe, state, x, y, t, bgcolour);
|
||||||
if (pass == 0)
|
if (x2 != -1 || y2 != -1)
|
||||||
continue;
|
draw_tile(fe, state, x2, y2, t, bgcolour);
|
||||||
x = COORD(X(state, i));
|
}
|
||||||
y = COORD(Y(state, i));
|
ds->tiles[i] = t0;
|
||||||
x2 = y2 = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_tile(fe, state, x, y, t, bgcolour);
|
|
||||||
if (x2 != -1 || y2 != -1)
|
|
||||||
draw_tile(fe, state, x2, y2, t, bgcolour);
|
|
||||||
}
|
|
||||||
ds->tiles[i] = t0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unclip(fe);
|
unclip(fe);
|
||||||
|
Reference in New Issue
Block a user