chiark / gitweb /
Cleanup: remove the game_state parameter to game_colours(). No game
authorSimon Tatham <anakin@pobox.com>
Sat, 22 Oct 2005 16:44:38 +0000 (16:44 +0000)
committerSimon Tatham <anakin@pobox.com>
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().

[originally from svn r6416]

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 b8c6bc045a0cff6444a83c0ba5d52564d5b0eaa0..39957f892a331f26711e69d5589e584ed944d738 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 a6cad8752609c4e18cb89653d2d8bc1e8a99b049..071c1115e5bff0d513a862c1acead9f4cfc50684 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 99d5bb1479544cb1976eb09ac284fff1d46f9264..283750bbd85ec3526ad088c21d4befbf7f7871e8 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 66413ecbbfee6f4bf19ed648673ec5b6de42f392..8696c83559d71c97c2897ce5084a5636e2bcff6c 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 f08cbf6e5c7a66e1bc85e58d1c91893f2781a73f..40fb47dd6eff63c3c6d535f1ec3fac535e4e8ef8 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 9519f1aa5e5b4c6b58dad6ccafe04de44802267e..b9ff6176479525541bcf01ae343aa2ea67b5a0a9 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 16f8bc283725f6e17f50fd1801c998073d083721..dc09a9a30113c24b7c90143351fa8e1207459922 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 d31d0613f723b70f192896fc6214cf1599b30b69..67abe2056970181cd29ee13d3bbca6cc528f04e4 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 055d264252b66b4b7feeb021ba98bd792912d9fe..93345fee5c988cde776c5d7f6b188cbf6d9db106 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 841458ad05f375a02156f0a3410862b3fb8ece77..3a23af44ad48d2a763c20392881ad01dbf704643 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 406c72fb6cb48999b6a5f6e82f7d4a55357ea79e..5bdb64751f5a8ff0d47dc8728e4bb0af4d0ab1df 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 5943683905e7f543f5fe7fe0ada976494de54fd4..f258b8a3910cae1a8d83f3e316fe69200c32a722 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 979a3b640ac6ec9931014949aeb34cf5324d89cf..0d19beb1d6b0112f1f29a5fcbfeb6af8920a1297 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 b9bb7c93b912b0fe8b5cb5c5f02ff8169ca687dc..c500ac43223323cb045cc456656a63429cfc2b92 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 82d9ed0b53256732f4fb59deeb93b5695ef515ca..47929ff55ded5deb3553309a3253e6bfe5f9b2b8 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 c710e71bf9a65d4784b9dd35340e4486f5c60d11..75c9498ba267e455289c953d4c2f42b7a488685e 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 799a8a5e70a64b8ebd62c86d025af0fc4502d24f..6ddc786a8c48681eca62aab1d9f62d05ea29fafb 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 f034bd41504d86fbb493ce4229023d23a220a2d2..0dcac5989a504a7ad2143b58deb81fc8e39d32c4 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 9b98c700fd93b561e66616ecb5f262c8b5b02e0d..592bf8bc46c6d14b317612202833fccfd8b8af19 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 f4fc67f3cbf6b6fc38ce43e1ef89f12212d06865..e910b3c096b182ef977e67f25736576bdbbe1067 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 60c8e943df35a74d56fa59442bbe45617ee8bcb3..62b678ebe2a8db630bf9eb2d71c7e310b14e237b 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 387216d1407bbf01cae2618d9eae7a0f4c2a8338..08ac75865b14fce4016d827027d065e4f8afe10e 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 fbed0554d60f20f6d5e2cd85699d997c99fa35e0..3c5ddbee5869a81c4ee04de9337cccacf79e2d23 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 ebc5bbb6d65be95d0f244fe1dd3de6005c109b8e..8b4e414bcddb8bfa0d926dc71dcd8abba53d3876 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 eb8ad8042fdccc0fc4ab5e91e7d16fbbbe7c7cdf..0e24481c90952e7c9a1e635899379fed4c46f61d 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 869ba5e314ed02f7051794ea5fbdf7bb9e79c119..3788ae5292156587517a0a8f05402670b48701e9 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 b366fd7c1378b5710aca6db4e6f46cfc3adaa392..0de1c45e2058178d314af5169e3b2e55325bd9d2 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 3d0918aa3a3e18dfcdec7c072d4bb0370ed652b0..4e1067c54a8f1ca670375a94442c6901d1101228 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);