From: simon Date: Wed, 18 May 2005 17:41:53 +0000 (+0000) Subject: If you paste in a random seed with different ephemeral parameters X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/commitdiff_plain/f60f7e7c3f3589b57214fd76c6919bb4dafd8d2c?hp=5472ceb6138bff155fd29f06fb45aab657b966b4 If you paste in a random seed with different ephemeral parameters from the currently configured ones, and then bring the Random Seed box back up, the wrong parameters get shown, and the resulting random seed is incorrect for the current game. At least, it was, until this checkin. git-svn-id: svn://svn.tartarus.org/sgt/puzzles@5808 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/midend.c b/midend.c index 6e0a362..ce0a315 100644 --- a/midend.c +++ b/midend.c @@ -34,7 +34,7 @@ struct midend_data { char **preset_names; int npresets, presetsize; - game_params *params, *tmpparams; + game_params *params, *curparams; struct midend_state_entry *states; game_drawstate *drawstate; game_state *oldstate; @@ -68,7 +68,7 @@ midend_data *midend_new(frontend *fe, const game *ourgame) me->nstates = me->statesize = me->statepos = 0; me->states = NULL; me->params = ourgame->default_params(); - me->tmpparams = NULL; + me->curparams = NULL; me->desc = NULL; me->seedstr = NULL; me->aux_info = NULL; @@ -98,8 +98,8 @@ void midend_free(midend_data *me) if (me->aux_info) me->ourgame->free_aux_info(me->aux_info); me->ourgame->free_params(me->params); - if (me->tmpparams) - me->ourgame->free_params(me->tmpparams); + if (me->curparams) + me->ourgame->free_params(me->curparams); sfree(me); } @@ -143,6 +143,10 @@ void midend_new_game(midend_data *me) newseed[i] = '0' + random_upto(me->random, 10); sfree(me->seedstr); me->seedstr = dupstr(newseed); + + if (me->curparams) + me->ourgame->free_params(me->curparams); + me->curparams = me->ourgame->dup_params(me->params); } sfree(me->desc); @@ -151,14 +155,8 @@ void midend_new_game(midend_data *me) me->aux_info = NULL; rs = random_init(me->seedstr, strlen(me->seedstr)); - me->desc = me->ourgame->new_desc - (me->tmpparams ? me->tmpparams : me->params, rs, &me->aux_info); + me->desc = me->ourgame->new_desc(me->curparams, rs, &me->aux_info); random_free(rs); - - if (me->tmpparams) { - me->ourgame->free_params(me->tmpparams); - me->tmpparams = NULL; - } } ensure(me); @@ -657,7 +655,7 @@ config_item *midend_get_config(midend_data *me, int which, char **wintitle) * the former is likely to persist across many code * changes). */ - parstr = me->ourgame->encode_params(me->params, which == CFG_SEED); + parstr = me->ourgame->encode_params(me->curparams, which == CFG_SEED); if (which == CFG_DESC) { ret[0].sval = snewn(strlen(parstr) + strlen(me->desc) + 2, char); sprintf(ret[0].sval, "%s:%s", parstr, me->desc); @@ -737,9 +735,9 @@ static char *midend_game_id_int(midend_data *me, char *id, int defmode) me->ourgame->free_params(tmpparams); return error; } - if (me->tmpparams) - me->ourgame->free_params(me->tmpparams); - me->tmpparams = tmpparams; + if (me->curparams) + me->ourgame->free_params(me->curparams); + me->curparams = tmpparams; /* * Now filter only the persistent parts of this state into