diff options
| author | Simon Tatham <anakin@pobox.com> | 2023-04-21 15:30:41 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2023-04-21 16:18:04 +0100 |
| commit | a4fca3286f3aa630a3641e50a8e1f44ab1504a29 (patch) | |
| tree | 43ff6e5c34d83b607b4ac3bc42b886a300cbaa5d | |
| parent | ec2e2f37703e1da4bb097c27ae5e7f1fa368624b (diff) | |
| download | puzzles-a4fca3286f3aa630a3641e50a8e1f44ab1504a29.zip puzzles-a4fca3286f3aa630a3641e50a8e1f44ab1504a29.tar.gz puzzles-a4fca3286f3aa630a3641e50a8e1f44ab1504a29.tar.bz2 puzzles-a4fca3286f3aa630a3641e50a8e1f44ab1504a29.tar.xz | |
Pass a game_ui to compute_size, print_size and print.
I'm about to move some of the bodgy getenv-based options so that they
become fields in game_ui. So these functions, which could previously
access those options directly via getenv, will now need to be given a
game_ui where they can look them up.
| -rw-r--r-- | blackbox.c | 2 | ||||
| -rw-r--r-- | bridges.c | 10 | ||||
| -rw-r--r-- | cube.c | 2 | ||||
| -rw-r--r-- | devel.but | 8 | ||||
| -rw-r--r-- | dominosa.c | 10 | ||||
| -rw-r--r-- | fifteen.c | 2 | ||||
| -rw-r--r-- | filling.c | 10 | ||||
| -rw-r--r-- | flip.c | 2 | ||||
| -rw-r--r-- | flood.c | 2 | ||||
| -rw-r--r-- | galaxies.c | 10 | ||||
| -rw-r--r-- | guess.c | 5 | ||||
| -rw-r--r-- | inertia.c | 2 | ||||
| -rw-r--r-- | keen.c | 10 | ||||
| -rw-r--r-- | lightup.c | 10 | ||||
| -rw-r--r-- | loopy.c | 10 | ||||
| -rw-r--r-- | magnets.c | 10 | ||||
| -rw-r--r-- | map.c | 10 | ||||
| -rw-r--r-- | midend.c | 12 | ||||
| -rw-r--r-- | mines.c | 2 | ||||
| -rw-r--r-- | mosaic.c | 2 | ||||
| -rw-r--r-- | net.c | 10 | ||||
| -rw-r--r-- | netslide.c | 2 | ||||
| -rw-r--r-- | nullgame.c | 2 | ||||
| -rw-r--r-- | palisade.c | 10 | ||||
| -rw-r--r-- | pattern.c | 10 | ||||
| -rw-r--r-- | pearl.c | 10 | ||||
| -rw-r--r-- | pegs.c | 2 | ||||
| -rw-r--r-- | printing.c | 17 | ||||
| -rw-r--r-- | puzzles.h | 8 | ||||
| -rw-r--r-- | range.c | 10 | ||||
| -rw-r--r-- | rect.c | 10 | ||||
| -rw-r--r-- | samegame.c | 2 | ||||
| -rw-r--r-- | signpost.c | 10 | ||||
| -rw-r--r-- | singles.c | 10 | ||||
| -rw-r--r-- | sixteen.c | 2 | ||||
| -rw-r--r-- | slant.c | 10 | ||||
| -rw-r--r-- | solo.c | 10 | ||||
| -rw-r--r-- | tents.c | 10 | ||||
| -rw-r--r-- | towers.c | 10 | ||||
| -rw-r--r-- | tracks.c | 10 | ||||
| -rw-r--r-- | twiddle.c | 2 | ||||
| -rw-r--r-- | undead.c | 2 | ||||
| -rw-r--r-- | unequal.c | 10 | ||||
| -rw-r--r-- | unfinished/group.c | 10 | ||||
| -rw-r--r-- | unfinished/separate.c | 8 | ||||
| -rw-r--r-- | unfinished/slide.c | 8 | ||||
| -rw-r--r-- | unfinished/sokoban.c | 8 | ||||
| -rw-r--r-- | unruly.c | 10 | ||||
| -rw-r--r-- | untangle.c | 4 |
49 files changed, 214 insertions, 144 deletions
@@ -1149,7 +1149,7 @@ static void game_get_cursor_location(const game_ui *ui, */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Border is ts/2, to make things easier. * Thus we have (width) + 2 (firing range*2) + 1 (border*2) tiles @@ -2665,7 +2665,7 @@ static char *solve_game(const game_state *state, const game_state *currstate, */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -3203,17 +3203,19 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* 10mm squares by default. */ - game_compute_size(params, 1000, &pw, &ph); + game_compute_size(params, 1000, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int ts) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int ts) { int ink = print_mono_colour(dr, 0); int paper = print_mono_colour(dr, 1); @@ -1489,7 +1489,7 @@ static struct bbox find_bbox(const game_params *params) ((int)(((bb).d - (bb).u + 2*(solid)->border) * gs)) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { struct bbox bb = find_bbox(params); @@ -1181,7 +1181,7 @@ explicitly requesting a resize). \S{backend-compute-size} \cw{compute_size()} \c void (*compute_size)(const game_params *params, int tilesize, -\c int *x, int *y); +\c const game_ui *ui, int *x, int *y); This function is passed a \c{game_params} structure and a tile size. It returns, in \c{*x} and \c{*y}, the size in pixels of the drawing @@ -1497,7 +1497,8 @@ ignored. \S{backend-print-size} \cw{print_size()} -\c void (*print_size)(const game_params *params, float *x, float *y); +\c void (*print_size)(const game_params *params, const game_ui *ui, +\c float *x, float *y); This function is passed a \c{game_params} structure and a tile size. It returns, in \c{*x} and \c{*y}, the preferred size in @@ -1508,7 +1509,8 @@ called. \S{backend-print} \cw{print()} -\c void (*print)(drawing *dr, const game_state *state, int tilesize); +\c void (*print)(drawing *dr, const game_state *state, +\c const game_ui *ui, int tilesize); This function is called when a puzzle is to be printed out on paper. It should use the drawing API functions (see \k{drawing}) to print @@ -3031,7 +3031,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { int n = params->n, w = n+2, h = n+1; @@ -3371,19 +3371,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->w, h = state->h; int c, x, y; @@ -804,7 +804,7 @@ static game_state *execute_move(const game_state *from, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1652,7 +1652,7 @@ enum { }; static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = (params->w + 1) * tilesize; *y = (params->h + 1) * tilesize; @@ -2092,19 +2092,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { const int w = state->shared->params.w; const int h = state->shared->params.h; @@ -1055,7 +1055,7 @@ static game_state *execute_move(const game_state *from, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -974,7 +974,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -3405,7 +3405,7 @@ badmove: */ static void game_compute_size(const game_params *params, int sz, - int *x, int *y) + const game_ui *ui, int *x, int *y) { struct { int tilesize, w, h; } ads, *ds = &ads; @@ -3926,7 +3926,8 @@ static int game_status(const game_state *state) } #ifndef EDITOR -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; @@ -3934,12 +3935,13 @@ static void game_print_size(const game_params *params, float *x, float *y) * 8mm squares by default. (There isn't all that much detail * that needs to go in each square.) */ - game_compute_size(params, 800, &pw, &ph); + game_compute_size(params, 800, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int sz) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int sz) { int w = state->w, h = state->h; int white, black, blackish; @@ -999,7 +999,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define BORDER 0.5 static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { double hmul, vmul_c, vmul_g, vmul; int hintw = (params->npegs+1)/2; @@ -1043,7 +1043,8 @@ static void game_set_size(drawing *dr, game_drawstate *ds, guessh = ((ds->pegsz + ds->gapsz) * params->nguesses); /* guesses */ guessh += ds->gapsz + ds->pegsz; /* solution */ - game_compute_size(params, tilesize, &ds->w, &ds->h); + /* We know we don't need anything from the game_ui we haven't got */ + game_compute_size(params, tilesize, NULL, &ds->w, &ds->h); ds->colx = ds->border; ds->coly = (ds->h - colh) / 2; @@ -1768,7 +1768,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1866,7 +1866,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define SIZE(w) ((w) * TILESIZE + 2*BORDER) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2222,14 +2222,15 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * We use 9mm squares by default, like Solo. */ - game_compute_size(params, 900, &pw, &ph); + game_compute_size(params, 900, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } @@ -2365,7 +2366,8 @@ static void outline_block_structure(drawing *dr, game_drawstate *ds, sfree(coords); } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->par.w; int ink = print_mono_colour(dr, 0); @@ -2021,7 +2021,7 @@ badmove: /* XXX entirely cloned from fifteen.c; separate out? */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2247,19 +2247,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->w, h = state->h; int ink = print_mono_colour(dr, 0); @@ -883,7 +883,7 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, } static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { int grid_width, grid_height, rendered_width, rendered_height; int g_tilesize; @@ -3554,19 +3554,21 @@ static int game_status(const game_state *state) return state->solved ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 7mm "squares" by default. */ - game_compute_size(params, 700, &pw, &ph); + game_compute_size(params, 700, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int ink = print_mono_colour(dr, 0); int i; @@ -1965,7 +1965,7 @@ badmove: */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2341,19 +2341,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->w, h = state->h; int ink = print_mono_colour(dr, 0); @@ -2630,7 +2630,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -3093,7 +3093,8 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; @@ -3102,12 +3103,13 @@ static void game_print_size(const game_params *params, float *x, float *y) * compute this size is to compute the pixel puzzle size at a * given tile size and then scale. */ - game_compute_size(params, 400, &pw, &ph); + game_compute_size(params, 400, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->p.w, h = state->p.h, wh = w*h, n = state->p.n; int ink, c[FOUR], i; @@ -303,7 +303,7 @@ static void midend_size_new_drawstate(midend *me) * anyway yet. */ if (me->tilesize > 0) { - me->ourgame->compute_size(me->params, me->tilesize, + me->ourgame->compute_size(me->params, me->tilesize, me->ui, &me->winwidth, &me->winheight); me->ourgame->set_size(me->drawing, me->drawstate, me->params, me->tilesize); @@ -328,19 +328,19 @@ static int convert_tilesize(midend *me, int old_tilesize, defaults = me->ourgame->default_params(); - me->ourgame->compute_size(defaults, old_tilesize, &x, &y); + me->ourgame->compute_size(defaults, old_tilesize, me->ui, &x, &y); x *= new_dpr / old_dpr; y *= new_dpr / old_dpr; min = max = 1; do { max *= 2; - me->ourgame->compute_size(defaults, max, &rx, &ry); + me->ourgame->compute_size(defaults, max, me->ui, &rx, &ry); } while (rx <= x && ry <= y); while (max - min > 1) { int mid = (max + min) / 2; - me->ourgame->compute_size(defaults, mid, &rx, &ry); + me->ourgame->compute_size(defaults, mid, me->ui, &rx, &ry); if (rx <= x && ry <= y) min = mid; else @@ -382,7 +382,7 @@ void midend_size(midend *me, int *x, int *y, bool user_size, max = 1; do { max *= 2; - me->ourgame->compute_size(me->params, max, &rx, &ry); + me->ourgame->compute_size(me->params, max, me->ui, &rx, &ry); } while (rx <= *x && ry <= *y); } else max = convert_tilesize(me, me->preferred_tilesize, @@ -398,7 +398,7 @@ void midend_size(midend *me, int *x, int *y, bool user_size, */ while (max - min > 1) { int mid = (max + min) / 2; - me->ourgame->compute_size(me->params, mid, &rx, &ry); + me->ourgame->compute_size(me->params, mid, me->ui, &rx, &ry); if (rx <= *x && ry <= *y) min = mid; else @@ -2694,7 +2694,7 @@ static game_state *execute_move(const game_state *from, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1398,7 +1398,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = (params->width + 1) * tilesize; *y = (params->height + 1) * tilesize; @@ -2488,7 +2488,7 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds) } static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -3112,14 +3112,15 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 8mm squares by default. */ - game_compute_size(params, 800, &pw, &ph); + game_compute_size(params, 800, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } @@ -3170,7 +3171,8 @@ static void draw_diagram(drawing *dr, game_drawstate *ds, int x, int y, } } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->width, h = state->height; int ink = print_mono_colour(dr, 0); @@ -1223,7 +1223,7 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds) } static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -148,7 +148,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = *y = 10 * tilesize; /* FIXME */ } @@ -1043,7 +1043,7 @@ static game_state *execute_move(const game_state *state, const char *move) /* --- Drawing routines --------------------------------------------- */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = (params->w + 1) * tilesize; *y = (params->h + 1) * tilesize; @@ -1291,11 +1291,12 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; - game_compute_size(params, 700, &pw, &ph); /* 7mm, like loopy */ + game_compute_size(params, 700, ui, &pw, &ph); /* 7mm, like loopy */ *x = pw / 100.0F; *y = ph / 100.0F; @@ -1314,7 +1315,8 @@ static void print_line(drawing *dr, int x1, int y1, int x2, int y2, } else draw_line(dr, x1, y1, x2, y2, colour); } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->shared->params.w, h = state->shared->params.h; int ink = print_mono_colour(dr, 0); @@ -1669,7 +1669,7 @@ static bool check_errors(const game_state *state, int i) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1990,19 +1990,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 5mm squares by default. */ - game_compute_size(params, 500, &pw, &ph); + game_compute_size(params, 500, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->common->w, h = state->common->h; int ink = print_mono_colour(dr, 0); @@ -2344,7 +2344,7 @@ badmove: #define FLASH_TIME 0.5F static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int halfsz; } ads, *ds = &ads; @@ -2633,19 +2633,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->shared->w, h = state->shared->h, x, y; int black = print_mono_colour(dr, 0); @@ -1048,7 +1048,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -96,7 +96,11 @@ static void get_puzzle_size(const document *doc, struct puzzle *pz, float ww, hh, ourscale; /* Get the preferred size of the game, in mm. */ - pz->game->print_size(pz->par, &ww, &hh); + { + game_ui *ui = pz->game->new_ui(pz->st); + pz->game->print_size(pz->par, ui, &ww, &hh); + pz->game->free_ui(ui); + } /* Adjust for user-supplied scale factor. */ ourscale = doc->userscale; @@ -270,9 +274,14 @@ void document_print_page(const document *doc, drawing *dr, int page_nr) * permit each game to choose its own?) */ tilesize = 512; - pz->game->compute_size(pz->par, tilesize, &pixw, &pixh); - print_begin_puzzle(dr, xm, xc, ym, yc, pixw, pixh, w, scale); - pz->game->print(dr, pass == 0 ? pz->st : pz->st2, tilesize); + { + game_ui *ui = pz->game->new_ui(pz->st); + pz->game->compute_size(pz->par, tilesize, ui, + &pixw, &pixh); + print_begin_puzzle(dr, xm, xc, ym, yc, pixw, pixh, w, scale); + pz->game->print(dr, pass == 0 ? pz->st : pz->st2, ui, tilesize); + pz->game->free_ui(ui); + } print_end_puzzle(dr); } @@ -689,7 +689,7 @@ struct game { game_state *(*execute_move)(const game_state *state, const char *move); int preferred_tilesize; void (*compute_size)(const game_params *params, int tilesize, - int *x, int *y); + const game_ui *ui, int *x, int *y); void (*set_size)(drawing *dr, game_drawstate *ds, const game_params *params, int tilesize); float *(*colours)(frontend *fe, int *ncolours); @@ -709,8 +709,10 @@ struct game { int *x, int *y, int *w, int *h); int (*status)(const game_state *state); bool can_print, can_print_in_colour; - void (*print_size)(const game_params *params, float *x, float *y); - void (*print)(drawing *dr, const game_state *state, int tilesize); + void (*print_size)(const game_params *params, const game_ui *ui, + float *x, float *y); + void (*print)(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize); bool wants_statusbar; bool is_timed; bool (*timing_state)(const game_state *state, game_ui *ui); @@ -1623,7 +1623,7 @@ enum { }; static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = (1 + params->w) * tilesize; *y = (1 + params->h) * tilesize; @@ -1766,15 +1766,17 @@ static void draw_cell(drawing *draw, game_drawstate *ds, int r, int c, * User interface: print */ -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int print_width, print_height; - game_compute_size(params, 800, &print_width, &print_height); + game_compute_size(params, 800, ui, &print_width, &print_height); *x = print_width / 100.0F; *y = print_height / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int const w = state->params.w, h = state->params.h; game_drawstate ds_obj, *ds = &ds_obj; @@ -2630,7 +2630,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define MAX4(x,y,z,w) ( max(max(x,y),max(z,w)) ) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2907,19 +2907,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 5mm squares by default. */ - game_compute_size(params, 500, &pw, &ph); + game_compute_size(params, 500, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->w, h = state->h; int ink = print_mono_colour(dr, 0); @@ -1373,7 +1373,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds, } static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up tile size variables for macro expansion purposes */ game_drawstate ads, *ds = &ads; @@ -1659,7 +1659,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize, order; } ads, *ds = &ads; @@ -2220,16 +2220,18 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; - game_compute_size(params, 1300, &pw, &ph); + game_compute_size(params, 1300, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int ink = print_mono_colour(dr, 0); int x, y; @@ -1594,7 +1594,7 @@ badmove: */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1783,17 +1783,19 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* 8mm squares by default. */ - game_compute_size(params, 800, &pw, &ph); + game_compute_size(params, 800, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int ink = print_mono_colour(dr, 0); int paper = print_mono_colour(dr, 1); @@ -802,7 +802,7 @@ static game_state *execute_move(const game_state *from, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1785,7 +1785,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* fool the macros */ struct dummy { int tilesize; } dummy, *ds = &dummy; @@ -2084,19 +2084,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->p.w, h = state->p.h, W = w+1; int ink = print_mono_colour(dr, 0); @@ -4810,7 +4810,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define GETTILESIZE(cr, w) ( (double)(w-1) / (double)(cr+1) ) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -5330,7 +5330,8 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; @@ -5339,7 +5340,7 @@ static void game_print_size(const game_params *params, float *x, float *y) * for this game, because players will want to jot down no end * of pencil marks in the squares. */ - game_compute_size(params, 900, &pw, &ph); + game_compute_size(params, 900, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } @@ -5513,7 +5514,8 @@ static void outline_block_structure(drawing *dr, game_drawstate *ds, sfree(coords); } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int cr = state->cr; int ink = print_mono_colour(dr, 0); @@ -1905,7 +1905,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* fool the macros */ struct dummy { int tilesize; } dummy, *ds = &dummy; @@ -2596,19 +2596,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * I'll use 6mm squares by default. */ - game_compute_size(params, 600, &pw, &ph); + game_compute_size(params, 600, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int c; @@ -1574,7 +1574,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define SIZE(w) ((w) * TILESIZE + 2*BORDER) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1954,19 +1954,21 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * We use 9mm squares by default, like Solo. */ - game_compute_size(params, 900, &pw, &ph); + game_compute_size(params, 900, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->par.w; int ink = print_mono_colour(dr, 0); @@ -2479,7 +2479,7 @@ static game_state *execute_move(const game_state *state, const char *move) #define FLASH_TIME 0.5F static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->sz6' and `ds->border` for macro expansion purposes */ struct { @@ -2976,17 +2976,19 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* The Times uses 7mm squares */ - game_compute_size(params, 700, &pw, &ph); + game_compute_size(params, 700, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->p.w, h = state->p.h; int black = print_mono_colour(dr, 0), grey = print_grey_colour(dr, 0.5F); @@ -800,7 +800,7 @@ static game_state *execute_move(const game_state *from, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2138,7 +2138,7 @@ static game_state *execute_move(const game_state *state, const char *move) #define PREFERRED_TILE_SIZE 64 static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1720,7 +1720,7 @@ badmove: #define DRAW_SIZE (TILE_SIZE*ds->order + GAP_SIZE*(ds->order-1) + BORDER*2) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize, order; } ads, *ds = &ads; @@ -2083,17 +2083,19 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* 10mm squares by default, roughly the same as Grauniad. */ - game_compute_size(params, 1000, &pw, &ph); + game_compute_size(params, 1000, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int ink = print_mono_colour(dr, 0); int x, y, o = state->order, ox, oy, n; diff --git a/unfinished/group.c b/unfinished/group.c index 7a2ffe6..dfa466d 100644 --- a/unfinished/group.c +++ b/unfinished/group.c @@ -1807,7 +1807,7 @@ static game_state *execute_move(const game_state *from, const char *move) #define SIZE(w) ((w) * TILESIZE + 2*BORDER + LEGEND) static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -2224,19 +2224,21 @@ static bool game_timing_state(const game_state *state, game_ui *ui) return true; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* * We use 9mm squares by default, like Solo. */ - game_compute_size(params, 900, &pw, &ph); + game_compute_size(params, 900, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w = state->par.w; int ink = print_mono_colour(dr, 0); diff --git a/unfinished/separate.c b/unfinished/separate.c index cc2a6c1..635d7c6 100644 --- a/unfinished/separate.c +++ b/unfinished/separate.c @@ -731,7 +731,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = *y = 10 * tilesize; /* FIXME */ } @@ -804,11 +804,13 @@ static bool game_timing_state(const game_state *state, game_ui *ui) return true; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { } diff --git a/unfinished/slide.c b/unfinished/slide.c index e091def..6368eba 100644 --- a/unfinished/slide.c +++ b/unfinished/slide.c @@ -1594,7 +1594,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* fool the macros */ struct dummy { int tilesize; } dummy, *ds = &dummy; @@ -2297,11 +2297,13 @@ static bool game_timing_state(const game_state *state, game_ui *ui) return true; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { } diff --git a/unfinished/sokoban.c b/unfinished/sokoban.c index 65d1fa6..3b847af 100644 --- a/unfinished/sokoban.c +++ b/unfinished/sokoban.c @@ -1178,7 +1178,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { /* Ick: fake up `ds->tilesize' for macro expansion purposes */ struct { int tilesize; } ads, *ds = &ads; @@ -1419,11 +1419,13 @@ static bool game_timing_state(const game_state *state, game_ui *ui) return true; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { } @@ -1727,7 +1727,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = tilesize * (params->w2 + 1); *y = tilesize * (params->h2 + 1); @@ -1965,17 +1965,19 @@ static int game_status(const game_state *state) return state->completed ? +1 : 0; } -static void game_print_size(const game_params *params, float *x, float *y) +static void game_print_size(const game_params *params, const game_ui *ui, + float *x, float *y) { int pw, ph; /* Using 7mm squares */ - game_compute_size(params, 700, &pw, &ph); + game_compute_size(params, 700, ui, &pw, &ph); *x = pw / 100.0F; *y = ph / 100.0F; } -static void game_print(drawing *dr, const game_state *state, int tilesize) +static void game_print(drawing *dr, const game_state *state, const game_ui *ui, + int tilesize) { int w2 = state->w2, h2 = state->h2; int x, y; @@ -1183,7 +1183,7 @@ static game_state *execute_move(const game_state *state, const char *move) */ static void game_compute_size(const game_params *params, int tilesize, - int *x, int *y) + const game_ui *ui, int *x, int *y) { *x = *y = COORDLIMIT(params->n) * tilesize; } @@ -1341,7 +1341,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, ds->dragpoint = ui->dragpoint; ds->bg = bg; - game_compute_size(&state->params, ds->tilesize, &w, &h); + game_compute_size(&state->params, ds->tilesize, ui, &w, &h); draw_rect(dr, 0, 0, w, h, bg); /* |