mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Re-architecting of the game backend interface. make_move() has been
split into two functions. The first, interpret_move(), takes all the arguments that make_move() used to get and may have the usual side effects of modifying the game_ui, but instead of returning a modified game_state it instead returns a string description of the move to be made. This string description is then passed to a second function, execute_move(), together with an input game_state, which is responsible for actually producing the new state. (solve_game() also returns a string to be passed to execute_move().) The point of this is to work towards being able to serialise the whole of a game midend into a byte stream such as a disk file, which will eventually support save and load functions in the desktop puzzles, as well as restoring half-finished games after a quit and restart in James Harvey's Palm port. Making each game supply a convert-to-string function for its game_state format would have been an unreliable way to do this, since those functions would not have been used in normal play, so they'd only have been tested when you actually tried to save and load - a recipe for latent bugs if ever I heard one. This way, you won't even be able to _make_ a move if execute_move() doesn't work properly, which means that if you can play a game at all I can have pretty high confidence that serialising it will work first time. This is only the groundwork; there will be more checkins to come on this theme. But the major upheaval should now be done, and as far as I can tell everything's still working normally. [originally from svn r6024]
This commit is contained in:
@ -269,16 +269,17 @@ struct game {
|
||||
game_state *(*dup_game)(game_state *state);
|
||||
void (*free_game)(game_state *state);
|
||||
int can_solve;
|
||||
game_state *(*solve)(game_state *orig, game_state *curr,
|
||||
game_aux_info *aux, char **error);
|
||||
char *(*solve)(game_state *orig, game_state *curr,
|
||||
game_aux_info *aux, char **error);
|
||||
int can_format_as_text;
|
||||
char *(*text_format)(game_state *state);
|
||||
game_ui *(*new_ui)(game_state *state);
|
||||
void (*free_ui)(game_ui *ui);
|
||||
void (*changed_state)(game_ui *ui, game_state *oldstate,
|
||||
game_state *newstate);
|
||||
game_state *(*make_move)(game_state *from, game_ui *ui, game_drawstate *ds,
|
||||
int x, int y, int button);
|
||||
char *(*interpret_move)(game_state *state, game_ui *ui, game_drawstate *ds,
|
||||
int x, int y, int button);
|
||||
game_state *(*execute_move)(game_state *state, char *move);
|
||||
void (*size)(game_params *params, game_drawstate *ds, int *x, int *y,
|
||||
int expand);
|
||||
float *(*colours)(frontend *fe, game_state *state, int *ncolours);
|
||||
|
Reference in New Issue
Block a user