mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
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]
This commit is contained in:
@ -166,7 +166,8 @@ chronological order, the second one contains the direction field
|
|||||||
which corresponds to the actual difference between the states.
|
which corresponds to the actual difference between the states.
|
||||||
However, when it is passed a pair of states in the opposite order
|
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
|
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
|
the direction field.
|
||||||
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,
|
For this reason, in the redraw functions you are provided with an
|
||||||
and look in the right place for the direction field.
|
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.
|
||||||
|
6
cube.c
6
cube.c
@ -1351,7 +1351,7 @@ void game_free_drawstate(game_drawstate *ds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, game_ui *ui,
|
game_state *state, int dir, game_ui *ui,
|
||||||
float animtime, float flashtime)
|
float animtime, float flashtime)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -1510,12 +1510,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float game_anim_length(game_state *oldstate, game_state *newstate)
|
float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
|
||||||
{
|
{
|
||||||
return ROLLTIME;
|
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;
|
return 0.0F;
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ static void draw_tile(frontend *fe, game_state *state, int x, int y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, game_ui *ui,
|
game_state *state, int dir, game_ui *ui,
|
||||||
float animtime, float flashtime)
|
float animtime, float flashtime)
|
||||||
{
|
{
|
||||||
int i, pass, bgcolour;
|
int i, pass, bgcolour;
|
||||||
@ -702,12 +702,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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)
|
if (!oldstate->completed && newstate->completed)
|
||||||
return 2 * FLASH_FRAME;
|
return 2 * FLASH_FRAME;
|
||||||
|
20
midend.c
20
midend.c
@ -30,6 +30,7 @@ struct midend_data {
|
|||||||
game_ui *ui;
|
game_ui *ui;
|
||||||
float anim_time, anim_pos;
|
float anim_time, anim_pos;
|
||||||
float flash_time, flash_pos;
|
float flash_time, flash_pos;
|
||||||
|
int dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ensure(me) do { \
|
#define ensure(me) do { \
|
||||||
@ -57,6 +58,7 @@ midend_data *midend_new(frontend *fe, void *randseed, int randseedsize)
|
|||||||
me->npresets = me->presetsize = 0;
|
me->npresets = me->presetsize = 0;
|
||||||
me->anim_time = me->anim_pos = 0.0F;
|
me->anim_time = me->anim_pos = 0.0F;
|
||||||
me->flash_time = me->flash_pos = 0.0F;
|
me->flash_time = me->flash_pos = 0.0F;
|
||||||
|
me->dir = 0;
|
||||||
me->ui = NULL;
|
me->ui = NULL;
|
||||||
|
|
||||||
return me;
|
return me;
|
||||||
@ -119,6 +121,7 @@ static int midend_undo(midend_data *me)
|
|||||||
{
|
{
|
||||||
if (me->statepos > 1) {
|
if (me->statepos > 1) {
|
||||||
me->statepos--;
|
me->statepos--;
|
||||||
|
me->dir = -1;
|
||||||
return 1;
|
return 1;
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
@ -128,6 +131,7 @@ static int midend_redo(midend_data *me)
|
|||||||
{
|
{
|
||||||
if (me->statepos < me->nstates) {
|
if (me->statepos < me->nstates) {
|
||||||
me->statepos++;
|
me->statepos++;
|
||||||
|
me->dir = +1;
|
||||||
return 1;
|
return 1;
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
@ -140,7 +144,8 @@ static void midend_finish_move(midend_data *me)
|
|||||||
if (me->oldstate || me->statepos > 1) {
|
if (me->oldstate || me->statepos > 1) {
|
||||||
flashtime = game_flash_length(me->oldstate ? me->oldstate :
|
flashtime = game_flash_length(me->oldstate ? me->oldstate :
|
||||||
me->states[me->statepos-2],
|
me->states[me->statepos-2],
|
||||||
me->states[me->statepos-1]);
|
me->states[me->statepos-1],
|
||||||
|
me->oldstate ? me->dir : +1);
|
||||||
if (flashtime > 0) {
|
if (flashtime > 0) {
|
||||||
me->flash_pos = 0.0F;
|
me->flash_pos = 0.0F;
|
||||||
me->flash_time = flashtime;
|
me->flash_time = flashtime;
|
||||||
@ -151,6 +156,7 @@ static void midend_finish_move(midend_data *me)
|
|||||||
free_game(me->oldstate);
|
free_game(me->oldstate);
|
||||||
me->oldstate = NULL;
|
me->oldstate = NULL;
|
||||||
me->anim_pos = me->anim_time = 0;
|
me->anim_pos = me->anim_time = 0;
|
||||||
|
me->dir = 0;
|
||||||
|
|
||||||
if (me->flash_time == 0 && me->anim_time == 0)
|
if (me->flash_time == 0 && me->anim_time == 0)
|
||||||
deactivate_timer(me->frontend);
|
deactivate_timer(me->frontend);
|
||||||
@ -212,6 +218,7 @@ int midend_process_key(midend_data *me, int x, int y, int button)
|
|||||||
ensure(me);
|
ensure(me);
|
||||||
me->states[me->nstates] = s;
|
me->states[me->nstates] = s;
|
||||||
me->statepos = ++me->nstates;
|
me->statepos = ++me->nstates;
|
||||||
|
me->dir = +1;
|
||||||
} else {
|
} else {
|
||||||
free_game(oldstate);
|
free_game(oldstate);
|
||||||
return 1;
|
return 1;
|
||||||
@ -221,7 +228,7 @@ int midend_process_key(midend_data *me, int x, int y, int button)
|
|||||||
/*
|
/*
|
||||||
* See if this move requires an animation.
|
* 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;
|
me->oldstate = oldstate;
|
||||||
if (anim_time > 0) {
|
if (anim_time > 0) {
|
||||||
@ -245,13 +252,14 @@ void midend_redraw(midend_data *me)
|
|||||||
start_draw(me->frontend);
|
start_draw(me->frontend);
|
||||||
if (me->oldstate && me->anim_time > 0 &&
|
if (me->oldstate && me->anim_time > 0 &&
|
||||||
me->anim_pos < me->anim_time) {
|
me->anim_pos < me->anim_time) {
|
||||||
|
assert(me->dir != 0);
|
||||||
game_redraw(me->frontend, me->drawstate, me->oldstate,
|
game_redraw(me->frontend, me->drawstate, me->oldstate,
|
||||||
me->states[me->statepos-1], me->ui, me->anim_pos,
|
me->states[me->statepos-1], me->dir,
|
||||||
me->flash_pos);
|
me->ui, me->anim_pos, me->flash_pos);
|
||||||
} else {
|
} else {
|
||||||
game_redraw(me->frontend, me->drawstate, NULL,
|
game_redraw(me->frontend, me->drawstate, NULL,
|
||||||
me->states[me->statepos-1], me->ui, 0.0,
|
me->states[me->statepos-1], +1 /*shrug*/,
|
||||||
me->flash_pos);
|
me->ui, 0.0, me->flash_pos);
|
||||||
}
|
}
|
||||||
end_draw(me->frontend);
|
end_draw(me->frontend);
|
||||||
}
|
}
|
||||||
|
6
net.c
6
net.c
@ -1251,7 +1251,7 @@ static void draw_tile(frontend *fe, game_state *state, int x, int y, int tile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, 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;
|
int x, y, tx, ty, frame;
|
||||||
unsigned char *active;
|
unsigned char *active;
|
||||||
@ -1404,7 +1404,7 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
sfree(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;
|
int x, y;
|
||||||
|
|
||||||
@ -1421,7 +1421,7 @@ float game_anim_length(game_state *oldstate, game_state *newstate)
|
|||||||
return 0.0F;
|
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
|
* If the game has just been completed, we display a completion
|
||||||
|
@ -1287,7 +1287,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, 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;
|
int x, y, tx, ty, frame;
|
||||||
unsigned char *active;
|
unsigned char *active;
|
||||||
@ -1481,12 +1481,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
sfree(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;
|
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
|
* If the game has just been completed, we display a completion
|
||||||
|
@ -177,7 +177,7 @@ void game_free_drawstate(game_drawstate *ds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, game_ui *ui,
|
game_state *state, int dir, game_ui *ui,
|
||||||
float animtime, float flashtime)
|
float animtime, float flashtime)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -189,12 +189,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
draw_rect(fe, 0, 0, 200, 200, COL_BACKGROUND);
|
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;
|
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;
|
return 0.0F;
|
||||||
}
|
}
|
||||||
|
@ -184,10 +184,10 @@ float *game_colours(frontend *fe, game_state *state, int *ncolours);
|
|||||||
game_drawstate *game_new_drawstate(game_state *state);
|
game_drawstate *game_new_drawstate(game_state *state);
|
||||||
void game_free_drawstate(game_drawstate *ds);
|
void game_free_drawstate(game_drawstate *ds);
|
||||||
void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
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 flash_time);
|
||||||
float game_anim_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);
|
float game_flash_length(game_state *oldstate, game_state *newstate, int dir);
|
||||||
int game_wants_statusbar(void);
|
int game_wants_statusbar(void);
|
||||||
|
|
||||||
#endif /* PUZZLES_PUZZLES_H */
|
#endif /* PUZZLES_PUZZLES_H */
|
||||||
|
6
rect.c
6
rect.c
@ -1482,7 +1482,7 @@ void draw_tile(frontend *fe, game_state *state, int x, int y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, game_ui *ui,
|
game_state *state, int dir, game_ui *ui,
|
||||||
float animtime, float flashtime)
|
float animtime, float flashtime)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -1573,12 +1573,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
sfree(correct);
|
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;
|
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)
|
if (!oldstate->completed && newstate->completed)
|
||||||
return FLASH_TIME;
|
return FLASH_TIME;
|
||||||
|
@ -575,7 +575,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, game_ui *ui,
|
game_state *state, int dir, game_ui *ui,
|
||||||
float animtime, float flashtime)
|
float animtime, float flashtime)
|
||||||
{
|
{
|
||||||
int i, bgcolour;
|
int i, bgcolour;
|
||||||
@ -750,12 +750,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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)
|
if (!oldstate->completed && newstate->completed)
|
||||||
return 2 * FLASH_FRAME;
|
return 2 * FLASH_FRAME;
|
||||||
|
Reference in New Issue
Block a user