taking non-zero time, which is triggered by the making of a move and
is _not_ hurried to its conclusion by the start of the next move (so
the game redraw function is expected to be able to draw it in
parallel with continuing moves). The only thing that prematurely
terminates a flash is the start of a fresh flash. In particular,
this concept is used to display the completion flash in Net, because
at least _my_ playing instincts make me lock every piece I've
unambiguously placed, and hence the last turn move is instantly
followed by a lock move which was previously suppressing the
completion flash.
git-svn-id: svn://svn.tartarus.org/sgt/puzzles@4168
cda61777-01e9-0310-a592-
d414129be87e
}
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)
+ game_state *state, float animtime, float flashtime)
{
int i, j;
struct bbox bb = find_bbox(&state->params);
{
int i, j;
struct bbox bb = find_bbox(&state->params);
+
+float game_flash_length(game_state *oldstate, game_state *newstate)
+{
+ return 0.0F;
+}
game_drawstate *drawstate;
game_state *oldstate;
float anim_time, anim_pos;
game_drawstate *drawstate;
game_state *oldstate;
float anim_time, anim_pos;
+ float flash_time, flash_pos;
};
#define ensure(me) do { \
};
#define ensure(me) do { \
me->presets = NULL;
me->preset_names = NULL;
me->npresets = me->presetsize = 0;
me->presets = NULL;
me->preset_names = NULL;
me->npresets = me->presetsize = 0;
+ me->anim_time = me->anim_pos = 0.0F;
+ me->flash_time = me->flash_pos = 0.0F;
+static void midend_finish_move(midend_data *me)
+{
+ float flashtime;
+
+ if (me->oldstate || me->statepos > 1) {
+ flashtime = game_flash_length(me->oldstate ? me->oldstate :
+ me->states[me->statepos-2],
+ me->states[me->statepos-1]);
+ if (flashtime > 0) {
+ me->flash_pos = 0.0F;
+ me->flash_time = flashtime;
+ }
+ }
+
+ if (me->oldstate)
+ free_game(me->oldstate);
+ me->oldstate = NULL;
+ me->anim_pos = me->anim_time = 0;
+
+ if (me->flash_time == 0 && me->anim_time == 0)
+ deactivate_timer(me->frontend);
+ else
+ activate_timer(me->frontend);
+}
+
int midend_process_key(midend_data *me, int x, int y, int button)
{
game_state *oldstate = dup_game(me->states[me->statepos - 1]);
float anim_time;
if (me->oldstate || me->anim_time) {
int midend_process_key(midend_data *me, int x, int y, int button)
{
game_state *oldstate = dup_game(me->states[me->statepos - 1]);
float anim_time;
if (me->oldstate || me->anim_time) {
- if (me->oldstate)
- free_game(me->oldstate);
- me->oldstate = NULL;
- me->anim_pos = me->anim_time = 0;
- deactivate_timer(me->frontend);
+ midend_finish_move(me);
*/
anim_time = game_anim_length(oldstate, me->states[me->statepos-1]);
*/
anim_time = game_anim_length(oldstate, me->states[me->statepos-1]);
+ me->oldstate = oldstate;
- me->oldstate = oldstate;
me->anim_time = anim_time;
} else {
me->anim_time = anim_time;
} else {
- free_game(oldstate);
- me->oldstate = NULL;
+ midend_finish_move(me);
if (me->oldstate && me->anim_time > 0 &&
me->anim_pos < me->anim_time) {
game_redraw(me->frontend, me->drawstate, me->oldstate,
if (me->oldstate && me->anim_time > 0 &&
me->anim_pos < me->anim_time) {
game_redraw(me->frontend, me->drawstate, me->oldstate,
- me->states[me->statepos-1], me->anim_pos);
+ me->states[me->statepos-1], me->anim_pos,
+ me->flash_pos);
} else {
game_redraw(me->frontend, me->drawstate, NULL,
} else {
game_redraw(me->frontend, me->drawstate, NULL,
- me->states[me->statepos-1], 0.0);
+ me->states[me->statepos-1], 0.0, me->flash_pos);
}
end_draw(me->frontend);
}
}
end_draw(me->frontend);
}
me->anim_pos += tplus;
if (me->anim_pos >= me->anim_time ||
me->anim_time == 0 || !me->oldstate) {
me->anim_pos += tplus;
if (me->anim_pos >= me->anim_time ||
me->anim_time == 0 || !me->oldstate) {
- if (me->oldstate)
- free_game(me->oldstate);
- me->oldstate = NULL;
- me->anim_pos = me->anim_time = 0;
- deactivate_timer(me->frontend);
+ if (me->anim_time > 0)
+ midend_finish_move(me);
+ }
+ me->flash_pos += tplus;
+ if (me->flash_pos >= me->flash_time || me->flash_time == 0) {
+ me->flash_pos = me->flash_time = 0;
+ if (me->flash_time == 0 && me->anim_time == 0)
+ deactivate_timer(me->frontend);
}
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 t)
+ game_state *state, float t, float ft)
{
int x, y, tx, ty, frame;
unsigned char *active;
{
int x, y, tx, ty, frame;
unsigned char *active;
if (oldstate && (t < ROTATE_TIME)) {
/*
* We're animating a tile rotation. Find the turning tile,
if (oldstate && (t < ROTATE_TIME)) {
/*
* We're animating a tile rotation. Find the turning tile,
angle = state->last_rotate_dir * -90.0F * (t / ROTATE_TIME);
state = oldstate;
}
angle = state->last_rotate_dir * -90.0F * (t / ROTATE_TIME);
state = oldstate;
}
- } else if (t > ROTATE_TIME) {
+ }
+
+ frame = -1;
+ if (ft > 0) {
/*
* We're animating a completion flash. Find which frame
* we're at.
*/
/*
* We're animating a completion flash. Find which frame
* we're at.
*/
- frame = (int)((t - ROTATE_TIME) / FLASH_FRAME);
+ frame = (int)(ft / FLASH_FRAME);
float game_anim_length(game_state *oldstate, game_state *newstate)
{
float game_anim_length(game_state *oldstate, game_state *newstate)
{
for (x = 0; x < oldstate->width; x++)
for (y = 0; y < oldstate->height; y++)
if ((tile(oldstate, x, y) ^ tile(newstate, x, y)) & 0xF) {
for (x = 0; x < oldstate->width; x++)
for (y = 0; y < oldstate->height; y++)
if ((tile(oldstate, x, y) ^ tile(newstate, x, y)) & 0xF) {
- ret = ROTATE_TIME;
- goto break_label; /* leave both loops at once */
+ return 0.0F;
+}
+
+float game_flash_length(game_state *oldstate, game_state *newstate)
+{
- * Also, if the game has just been completed, allow time for a
- * completion flash.
+ * If the game has just been completed, we display a completion
+ * flash.
*/
if (!oldstate->completed && newstate->completed) {
int size;
*/
if (!oldstate->completed && newstate->completed) {
int size;
size = newstate->width - newstate->cx;
if (size < newstate->height - newstate->cy)
size = newstate->height - newstate->cy;
size = newstate->width - newstate->cx;
if (size < newstate->height - newstate->cy)
size = newstate->height - newstate->cy;
- ret += FLASH_FRAME * (size+4);
+ return FLASH_FRAME * (size+4);
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_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, float t);
+ game_state *newstate, float anim_time, float flash_time);
float game_anim_length(game_state *oldstate, game_state *newstate);
float game_anim_length(game_state *oldstate, game_state *newstate);
+float game_flash_length(game_state *oldstate, game_state *newstate);
#endif /* PUZZLES_PUZZLES_H */
#endif /* PUZZLES_PUZZLES_H */