ref: daac529a9eded98181fdf2b0d79e7138195614ec
parent: f1e8a586b53535bad3e201a8cc42b514a8cb6e16
author: Jacob Nevins <jacobn@chiark.greenend.org.uk>
date: Mon Aug 16 12:29:54 EDT 2004
After discussion with Simon, the game redraw functions are now passed a new argument `dir' which tells them whether this redraw is due to an undo, rather than have them second-guess it from game state. Note that none of the actual games yet take advantage of this; so it hasn't been tested in anger (although it has been inspected by debugging). [originally from svn r4469]
--- a/HACKING.but
+++ b/HACKING.but
@@ -166,7 +166,8 @@
which corresponds to the actual difference between the states.
However, when it is passed a pair of states in the opposite order
due to an undo, it should be looking in the \e{first} one to find
-the direction field. Sixteen solves this by also storing the current
-move count in the game state, so that \cw{game_redraw()} can compare
-the two move counts to work out whether it's drawing an undo or not,
-and look in the right place for the direction field.
+the direction field.
+
+For this reason, in the redraw functions you are provided with an
+extra argument \c{dir} which tells you which state was chronologically
+first; \c{dir} is +1 for a normal move and -1 for an undo.
--- a/cube.c
+++ b/cube.c
@@ -1351,7 +1351,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui,
+ game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int i, j;
@@ -1510,12 +1510,12 @@
}
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return ROLLTIME;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
return 0.0F;
}
--- a/fifteen.c
+++ b/fifteen.c
@@ -553,7 +553,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui,
+ game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int i, pass, bgcolour;
@@ -702,12 +702,12 @@
}
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return ANIM_TIME;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
if (!oldstate->completed && newstate->completed)
return 2 * FLASH_FRAME;
--- a/midend.c
+++ b/midend.c
@@ -30,6 +30,7 @@
game_ui *ui;
float anim_time, anim_pos;
float flash_time, flash_pos;
+ int dir;
};
#define ensure(me) do { \
@@ -57,6 +58,7 @@
me->npresets = me->presetsize = 0;
me->anim_time = me->anim_pos = 0.0F;
me->flash_time = me->flash_pos = 0.0F;
+ me->dir = 0;
me->ui = NULL;
return me;
@@ -119,6 +121,7 @@
{
if (me->statepos > 1) {
me->statepos--;
+ me->dir = -1;
return 1;
} else
return 0;
@@ -128,6 +131,7 @@
{
if (me->statepos < me->nstates) {
me->statepos++;
+ me->dir = +1;
return 1;
} else
return 0;
@@ -140,7 +144,8 @@
if (me->oldstate || me->statepos > 1) {
flashtime = game_flash_length(me->oldstate ? me->oldstate :
me->states[me->statepos-2],
- me->states[me->statepos-1]);
+ me->states[me->statepos-1],
+ me->oldstate ? me->dir : +1);
if (flashtime > 0) {
me->flash_pos = 0.0F;
me->flash_time = flashtime;
@@ -151,6 +156,7 @@
free_game(me->oldstate);
me->oldstate = NULL;
me->anim_pos = me->anim_time = 0;
+ me->dir = 0;
if (me->flash_time == 0 && me->anim_time == 0)
deactivate_timer(me->frontend);
@@ -212,6 +218,7 @@
ensure(me);
me->states[me->nstates] = s;
me->statepos = ++me->nstates;
+ me->dir = +1;
} else {
free_game(oldstate);
return 1;
@@ -221,7 +228,7 @@
/*
* See if this move requires an animation.
*/
- anim_time = game_anim_length(oldstate, me->states[me->statepos-1]);
+ anim_time = game_anim_length(oldstate, me->states[me->statepos-1], me->dir);
me->oldstate = oldstate;
if (anim_time > 0) {
@@ -245,13 +252,14 @@
start_draw(me->frontend);
if (me->oldstate && me->anim_time > 0 &&
me->anim_pos < me->anim_time) {
+ assert(me->dir != 0);
game_redraw(me->frontend, me->drawstate, me->oldstate,
- me->states[me->statepos-1], me->ui, me->anim_pos,
- me->flash_pos);
+ me->states[me->statepos-1], me->dir,
+ me->ui, me->anim_pos, me->flash_pos);
} else {
game_redraw(me->frontend, me->drawstate, NULL,
- me->states[me->statepos-1], me->ui, 0.0,
- me->flash_pos);
+ me->states[me->statepos-1], +1 /*shrug*/,
+ me->ui, 0.0, me->flash_pos);
}
end_draw(me->frontend);
}
--- a/net.c
+++ b/net.c
@@ -1251,7 +1251,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui, float t, float ft)
+ game_state *state, int dir, game_ui *ui, float t, float ft)
{
int x, y, tx, ty, frame;
unsigned char *active;
@@ -1404,7 +1404,7 @@
sfree(active);
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
int x, y;
@@ -1421,7 +1421,7 @@
return 0.0F;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
/*
* If the game has just been completed, we display a completion
--- a/netslide.c
+++ b/netslide.c
@@ -1287,7 +1287,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui, float t, float ft)
+ game_state *state, int dir, game_ui *ui, float t, float ft)
{
int x, y, tx, ty, frame;
unsigned char *active;
@@ -1481,12 +1481,12 @@
sfree(active);
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return ANIM_TIME;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
/*
* If the game has just been completed, we display a completion
--- a/nullgame.c
+++ b/nullgame.c
@@ -177,7 +177,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui,
+ game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
/*
@@ -189,12 +189,12 @@
draw_rect(fe, 0, 0, 200, 200, COL_BACKGROUND);
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return 0.0F;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
return 0.0F;
}
--- a/puzzles.h
+++ b/puzzles.h
@@ -184,10 +184,10 @@
game_drawstate *game_new_drawstate(game_state *state);
void game_free_drawstate(game_drawstate *ds);
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *newstate, game_ui *ui, float anim_time,
+ game_state *newstate, int dir, game_ui *ui, float anim_time,
float flash_time);
-float game_anim_length(game_state *oldstate, game_state *newstate);
-float game_flash_length(game_state *oldstate, game_state *newstate);
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir);
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir);
int game_wants_statusbar(void);
#endif /* PUZZLES_PUZZLES_H */
--- a/rect.c
+++ b/rect.c
@@ -1482,7 +1482,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui,
+ game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int x, y;
@@ -1573,12 +1573,12 @@
sfree(correct);
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return 0.0F;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
if (!oldstate->completed && newstate->completed)
return FLASH_TIME;
--- a/sixteen.c
+++ b/sixteen.c
@@ -575,7 +575,7 @@
}
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *state, game_ui *ui,
+ game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int i, bgcolour;
@@ -750,12 +750,12 @@
}
}
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
{
return ANIM_TIME;
}
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
{
if (!oldstate->completed && newstate->completed)
return 2 * FLASH_FRAME;