diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-06-28 07:33:49 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-06-28 07:33:49 +0000 |
| commit | cdb8433c0a5bf546ae2f4c55bad1be064d05df3b (patch) | |
| tree | 3e6026b5dde0edba0477de9d714b46c0f687e6cf | |
| parent | 08410651e05b0723073d53e7d75174767633bf87 (diff) | |
| download | puzzles-cdb8433c0a5bf546ae2f4c55bad1be064d05df3b.zip puzzles-cdb8433c0a5bf546ae2f4c55bad1be064d05df3b.tar.gz puzzles-cdb8433c0a5bf546ae2f4c55bad1be064d05df3b.tar.bz2 puzzles-cdb8433c0a5bf546ae2f4c55bad1be064d05df3b.tar.xz | |
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]
| -rw-r--r-- | cube.c | 11 | ||||
| -rw-r--r-- | fifteen.c | 11 | ||||
| -rw-r--r-- | flip.c | 11 | ||||
| -rw-r--r-- | guess.c | 11 | ||||
| -rw-r--r-- | mines.c | 17 | ||||
| -rw-r--r-- | net.c | 19 | ||||
| -rw-r--r-- | netslide.c | 11 | ||||
| -rw-r--r-- | nullgame.c | 11 | ||||
| -rw-r--r-- | pattern.c | 11 | ||||
| -rw-r--r-- | puzzles.h | 2 | ||||
| -rw-r--r-- | rect.c | 11 | ||||
| -rw-r--r-- | samegame.c | 11 | ||||
| -rw-r--r-- | sixteen.c | 11 | ||||
| -rw-r--r-- | solo.c | 11 | ||||
| -rw-r--r-- | twiddle.c | 11 |
15 files changed, 170 insertions, 0 deletions
@@ -1004,6 +1004,15 @@ static void free_ui(game_ui *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) { @@ -1714,6 +1723,8 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -436,6 +436,15 @@ static void free_ui(game_ui *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) { @@ -882,6 +891,8 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -871,6 +871,15 @@ static void free_ui(game_ui *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) { @@ -1229,6 +1238,8 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -404,6 +404,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -2357,6 +2357,21 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -1846,6 +1846,23 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -1005,6 +1005,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -142,6 +142,15 @@ static void free_ui(game_ui *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) { @@ -255,6 +264,8 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -773,6 +773,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -275,6 +275,8 @@ struct game { 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, @@ -2170,6 +2170,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -411,6 +411,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -564,6 +564,15 @@ static void free_ui(game_ui *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) { @@ -1060,6 +1069,8 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -1931,6 +1931,15 @@ static void free_ui(game_ui *ui) 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 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, @@ -608,6 +608,15 @@ static void free_ui(game_ui *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) { @@ -1224,6 +1233,8 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move, |