ref: cdb8433c0a5bf546ae2f4c55bad1be064d05df3b
parent: 08410651e05b0723073d53e7d75174767633bf87
author: Simon Tatham <anakin@pobox.com>
date: Tue Jun 28 03:33:49 EDT 2005
Another function pair required for serialisation; these ones save and restore anything vitally important in the game_ui. Most of the game_ui is expected to be stuff about cursor positions and currently active mouse drags, so it absolutely _doesn't_ want to be preserved over a serialisation; but one or two things would be disorienting or outright wrong to reset, such as the Net origin position and the Mines death counter. [originally from svn r6026]
--- a/cube.c
+++ b/cube.c
@@ -1004,6 +1004,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1714,6 +1723,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/fifteen.c
+++ b/fifteen.c
@@ -436,6 +436,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -882,6 +891,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/flip.c
+++ b/flip.c
@@ -871,6 +871,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1229,6 +1238,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/guess.c
+++ b/guess.c
@@ -404,6 +404,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1260,6 +1269,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/mines.c
+++ b/mines.c
@@ -2357,6 +2357,21 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ char buf[80];
+ /*
+ * The deaths counter needs preserving across a serialisation.
+ */
+ sprintf(buf, "D%d", ui->deaths);
+ return dupstr(buf);
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+ sscanf(encoding, "D%d", &ui->deaths);
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -3039,6 +3054,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/net.c
+++ b/net.c
@@ -1846,6 +1846,23 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ char buf[120];
+ /*
+ * We preserve the origin and centre-point coordinates over a
+ * serialise.
+ */
+ sprintf(buf, "O%d,%d;C%d,%d", ui->org_x, ui->org_y, ui->cx, ui->cy);
+ return dupstr(buf);
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+ sscanf(encoding, "O%d,%d;C%d,%d",
+ &ui->org_x, &ui->org_y, &ui->cx, &ui->cy);
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -2739,6 +2756,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/netslide.c
+++ b/netslide.c
@@ -1005,6 +1005,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
/* ----------------------------------------------------------------------
* Process a move.
*/
@@ -1822,6 +1831,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/nullgame.c
+++ b/nullgame.c
@@ -142,6 +142,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -255,6 +264,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/pattern.c
+++ b/pattern.c
@@ -773,6 +773,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1194,6 +1203,8 @@
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/puzzles.h
+++ b/puzzles.h
@@ -275,6 +275,8 @@
char *(*text_format)(game_state *state);
game_ui *(*new_ui)(game_state *state);
void (*free_ui)(game_ui *ui);
+ char *(*encode_ui)(game_ui *ui);
+ void (*decode_ui)(game_ui *ui, char *encoding);
void (*changed_state)(game_ui *ui, game_state *oldstate,
game_state *newstate);
char *(*interpret_move)(game_state *state, game_ui *ui, game_drawstate *ds,
--- a/rect.c
+++ b/rect.c
@@ -2170,6 +2170,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void coord_round(float x, float y, int *xr, int *yr)
{
float xs, ys, xv, yv, dx, dy, dist;
@@ -2799,6 +2808,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/samegame.c
+++ b/samegame.c
@@ -411,6 +411,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void sel_clear(game_ui *ui, game_state *state)
{
int i;
@@ -999,6 +1008,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/sixteen.c
+++ b/sixteen.c
@@ -564,6 +564,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1060,6 +1069,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/solo.c
+++ b/solo.c
@@ -1931,6 +1931,15 @@
sfree(ui);
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -2420,6 +2429,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,
--- a/twiddle.c
+++ b/twiddle.c
@@ -608,6 +608,15 @@
{
}
+char *encode_ui(game_ui *ui)
+{
+ return NULL;
+}
+
+void decode_ui(game_ui *ui, char *encoding)
+{
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
@@ -1224,6 +1233,8 @@
TRUE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,