ref: 3d2c442bc42050af618706899314414248126476
parent: 145301d0dc5b75a89620ffe88bc8a890699eef59
author: Simon Tatham <anakin@pobox.com>
date: Sun Jul 10 06:17:13 EDT 2005
game_timing_state() now has access to the game_ui. This means that whether the timer is currently going is no longer solely dependent on the current game_state: it can be dependent on more persistent information stored in the game_ui. In particular, Mines now freezes the timer permanently once you complete a grid for the first time, so that you can then backtrack through your solution process without destroying the information about how long it took you the first time through. [originally from svn r6088]
--- a/cube.c
+++ b/cube.c
@@ -1687,7 +1687,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/fifteen.c
+++ b/fifteen.c
@@ -832,7 +832,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/flip.c
+++ b/flip.c
@@ -1239,7 +1239,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/guess.c
+++ b/guess.c
@@ -1262,7 +1262,7 @@
return FALSE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/midend.c
+++ b/midend.c
@@ -237,7 +237,8 @@
static void midend_set_timer(midend_data *me)
{
me->timing = (me->ourgame->is_timed &&
- me->ourgame->timing_state(me->states[me->statepos-1].state));
+ me->ourgame->timing_state(me->states[me->statepos-1].state,
+ me->ui));
if (me->timing || me->flash_time || me->anim_time)
activate_timer(me->frontend);
else
@@ -311,10 +312,10 @@
me->drawstate = me->ourgame->new_drawstate(me->states[0].state);
midend_size_new_drawstate(me);
me->elapsed = 0.0F;
- midend_set_timer(me);
if (me->ui)
me->ourgame->free_ui(me->ui);
me->ui = me->ourgame->new_ui(me->states[0].state);
+ midend_set_timer(me);
me->pressed_mouse_button = 0;
}
--- a/mines.c
+++ b/mines.c
@@ -2336,7 +2336,7 @@
int hx, hy, hradius; /* for mouse-down highlights */
int validradius;
int flash_is_death;
- int deaths;
+ int deaths, completed;
};
static game_ui *new_ui(game_state *state)
@@ -2345,6 +2345,7 @@
ui->hx = ui->hy = -1;
ui->hradius = ui->validradius = 0;
ui->deaths = 0;
+ ui->completed = FALSE;
ui->flash_is_death = FALSE; /* *shrug* */
return ui;
}
@@ -2358,20 +2359,28 @@
{
char buf[80];
/*
- * The deaths counter needs preserving across a serialisation.
+ * The deaths counter and completion status need preserving
+ * across a serialisation.
*/
sprintf(buf, "D%d", ui->deaths);
+ if (ui->completed)
+ strcat(buf, "C");
return dupstr(buf);
}
static void decode_ui(game_ui *ui, char *encoding)
{
- sscanf(encoding, "D%d", &ui->deaths);
+ int p;
+ sscanf(encoding, "D%d%n", &ui->deaths, &p);
+ if (encoding[p] == 'C')
+ ui->completed = TRUE;
}
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
+ if (newstate->won)
+ ui->completed = TRUE;
}
struct game_drawstate {
@@ -3015,9 +3024,9 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
- if (state->dead || state->won || !state->layout->mines)
+ if (state->dead || state->won || ui->completed || !state->layout->mines)
return FALSE;
return TRUE;
}
--- a/net.c
+++ b/net.c
@@ -2723,7 +2723,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/netslide.c
+++ b/netslide.c
@@ -1776,7 +1776,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return FALSE;
}
--- a/nullgame.c
+++ b/nullgame.c
@@ -238,7 +238,7 @@
return FALSE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/pattern.c
+++ b/pattern.c
@@ -1159,7 +1159,7 @@
return FALSE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/pegs.c
+++ b/pegs.c
@@ -1174,7 +1174,7 @@
return FALSE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/puzzles.h
+++ b/puzzles.h
@@ -305,7 +305,7 @@
game_ui *ui);
int (*wants_statusbar)(void);
int is_timed;
- int (*timing_state)(game_state *state);
+ int (*timing_state)(game_state *state, game_ui *ui);
int mouse_priorities;
};
--- a/rect.c
+++ b/rect.c
@@ -2758,7 +2758,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/samegame.c
+++ b/samegame.c
@@ -947,7 +947,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/sixteen.c
+++ b/sixteen.c
@@ -1008,7 +1008,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/solo.c
+++ b/solo.c
@@ -2599,7 +2599,7 @@
return FALSE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}
--- a/twiddle.c
+++ b/twiddle.c
@@ -1175,7 +1175,7 @@
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
}