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.
}
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;
}
}
-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;
}
}
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;
}
}
-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;
game_ui *ui;
float anim_time, anim_pos;
float flash_time, flash_pos;
+ int dir;
};
#define ensure(me) do { \
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;
{
if (me->statepos > 1) {
me->statepos--;
+ me->dir = -1;
return 1;
} else
return 0;
{
if (me->statepos < me->nstates) {
me->statepos++;
+ me->dir = +1;
return 1;
} else
return 0;
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;
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);
ensure(me);
me->states[me->nstates] = s;
me->statepos = ++me->nstates;
+ me->dir = +1;
} else {
free_game(oldstate);
return 1;
/*
* 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) {
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);
}
}
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;
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;
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
}
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;
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
}
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)
{
/*
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;
}
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 */
}
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;
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;
}
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;
}
}
-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;