Cleanup: remove the game_state parameter to game_colours(). No game
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 22 Oct 2005 16:44:38 +0000 (16:44 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 22 Oct 2005 16:44:38 +0000 (16:44 +0000)
was actually using it, and also it wasn't being called again for
different game states or different game parameters, so it would have
been a mistake to depend on anything in that game state. Games are
now expected to commit in advance to a single fixed list of all the
colours they will ever need, which was the case in practice already
and simplifies any later port to a colour-poor platform. Also this
change has removed a lot of unnecessary faff from midend_colours().

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@6416 cda61777-01e9-0310-a592-d414129be87e

28 files changed:
blackbox.c
bridges.c
cube.c
devel.but
dominosa.c
fifteen.c
flip.c
guess.c
inertia.c
lightup.c
loopy.c
map.c
midend.c
mines.c
net.c
netslide.c
nullgame.c
pattern.c
pegs.c
puzzles.h
rect.c
samegame.c
sixteen.c
slant.c
solo.c
tents.c
twiddle.c
untangle.c

index b8c6bc0..39957f8 100644 (file)
@@ -1060,7 +1060,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->rrad = (3*tilesize)/8;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
index a6cad87..071c111 100644 (file)
--- a/bridges.c
+++ b/bridges.c
@@ -2230,7 +2230,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
diff --git a/cube.c b/cube.c
index 99d5bb1..283750b 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -1476,7 +1476,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->oy = (int)(-(bb.u - solids[params->solid]->border) * ds->gridscale);
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index 66413ec..8696c83 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -1104,7 +1104,7 @@ create a fresh drawstate.
 
 \S{backend-colours} \cw{colours()}
 
-\c float *(*colours)(frontend *fe, game_state *state, int *ncolours);
+\c float *(*colours)(frontend *fe, int *ncolours);
 
 This function is responsible for telling the front end what colours
 the puzzle will need to draw itself.
@@ -1115,15 +1115,7 @@ array of three times that many \c{float}s, containing the red, green
 and blue components of each colour respectively as numbers in the
 range [0,1].
 
-It is passed a sample \c{game_state} in case it needs one, although
-currently no puzzle does need this. (In fact, colours are not
-reallocated when the game parameters change or a new game is
-started, so you can't reliably use this \c{game_state} to allocate a
-different number of colours depending on the game. It is probably
-actually a mistake to rely on this parameter at all. I ought to
-either remove it or fix it; probably the former.)
-
-The final parameter passed to this function is a front end handle.
+The second parameter passed to this function is a front end handle.
 The only things it is permitted to do with this handle are to call
 the front-end function called \cw{frontend_default_colour()} (see
 \k{frontend-default-colour}) or the utility function called
index f08cbf6..40fb47d 100644 (file)
@@ -1439,7 +1439,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index 9519f1a..b9ff617 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -580,7 +580,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
diff --git a/flip.c b/flip.c
index 16f8bc2..dc09a9a 100644 (file)
--- a/flip.c
+++ b/flip.c
@@ -1019,7 +1019,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
diff --git a/guess.c b/guess.c
index d31d061..67abe20 100644 (file)
--- a/guess.c
+++ b/guess.c
@@ -864,7 +864,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->blit_peg = blitter_new(dr, ds->pegsz, ds->pegsz);
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float), max;
     int i;
index 055d264..93345fe 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -1692,7 +1692,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->player_background = blitter_new(dr, TILESIZE, TILESIZE);
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
index 841458a..3a23af4 100644 (file)
--- a/lightup.c
+++ b/lightup.c
@@ -1956,7 +1956,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->crad = 3*(tilesize-1)/8;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
diff --git a/loopy.c b/loopy.c
index 406c72f..5bdb647 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -2363,7 +2363,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->linewidth = max(1,tilesize/16);
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(4 * NCOLOURS, float);
 
diff --git a/map.c b/map.c
index 5943683..f258b8a 100644 (file)
--- a/map.c
+++ b/map.c
@@ -2527,7 +2527,7 @@ const int map_hatching[FOUR] = {
     HATCH_VERT, HATCH_SLASH, HATCH_HORIZ, HATCH_BACKSLASH
 };
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index 979a3b6..0d19beb 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -767,20 +767,9 @@ void midend_timer(midend *me, float tplus)
 
 float *midend_colours(midend *me, int *ncolours)
 {
-    game_state *state = NULL;
     float *ret;
 
-    if (me->nstates == 0) {
-       char *aux = NULL;
-        char *desc = me->ourgame->new_desc(me->params, me->random,
-                                          &aux, TRUE);
-        state = me->ourgame->new_game(me, me->params, desc);
-        sfree(desc);
-        sfree(aux);
-    } else
-        state = me->states[0].state;
-
-    ret = me->ourgame->colours(me->frontend, state, ncolours);
+    ret = me->ourgame->colours(me->frontend, ncolours);
 
     {
         int i;
@@ -810,9 +799,6 @@ float *midend_colours(midend *me, int *ncolours)
         }
     }
 
-    if (me->nstates == 0)
-        me->ourgame->free_game(state);
-
     return ret;
 }
 
diff --git a/mines.c b/mines.c
index b9bb7c9..c500ac4 100644 (file)
--- a/mines.c
+++ b/mines.c
@@ -2638,7 +2638,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
diff --git a/net.c b/net.c
index 82d9ed0..47929ff 100644 (file)
--- a/net.c
+++ b/net.c
@@ -2138,7 +2138,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret;
 
index c710e71..75c9498 100644 (file)
@@ -1211,7 +1211,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret;
 
index 799a8a5..6ddc786 100644 (file)
@@ -183,7 +183,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index f034bd4..0dcac59 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -963,7 +963,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
diff --git a/pegs.c b/pegs.c
index 9b98c70..592bf8b 100644 (file)
--- a/pegs.c
+++ b/pegs.c
@@ -940,7 +940,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->drag_background = blitter_new(dr, TILESIZE, TILESIZE);
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index f4fc67f..e910b3c 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -383,7 +383,7 @@ struct game {
     void (*compute_size)(game_params *params, int tilesize, int *x, int *y);
     void (*set_size)(drawing *dr, game_drawstate *ds,
                     game_params *params, int tilesize);
-    float *(*colours)(frontend *fe, game_state *state, int *ncolours);
+    float *(*colours)(frontend *fe, int *ncolours);
     game_drawstate *(*new_drawstate)(drawing *dr, game_state *state);
     void (*free_drawstate)(drawing *dr, game_drawstate *ds);
     void (*redraw)(drawing *dr, game_drawstate *ds, game_state *oldstate,
diff --git a/rect.c b/rect.c
index 60c8e94..62b678e 100644 (file)
--- a/rect.c
+++ b/rect.c
@@ -2528,7 +2528,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index 387216d..08ac758 100644 (file)
@@ -1362,7 +1362,7 @@ static void game_compute_size(game_params *params, int tilesize,
     *y = TILE_SIZE * params->h + 2 * BORDER - TILE_GAP;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index fbed055..3c5ddbe 100644 (file)
--- a/sixteen.c
+++ b/sixteen.c
@@ -702,7 +702,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
diff --git a/slant.c b/slant.c
index ebc5bbb..8b4e414 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -1707,7 +1707,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
diff --git a/solo.c b/solo.c
index eb8ad80..0e24481 100644 (file)
--- a/solo.c
+++ b/solo.c
@@ -2712,7 +2712,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
diff --git a/tents.c b/tents.c
index 869ba5e..3788ae5 100644 (file)
--- a/tents.c
+++ b/tents.c
@@ -1810,7 +1810,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
index b366fd7..0de1c45 100644 (file)
--- a/twiddle.c
+++ b/twiddle.c
@@ -761,7 +761,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
     int i;
index 3d0918a..4e1067c 100644 (file)
@@ -1191,7 +1191,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
     ds->tilesize = tilesize;
 }
 
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);