X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/c566778e388091cbcdcf4be8c34ec317dde0ffad..4c02061d05c4d4047bb5a6ea064a95ec341b4bbe:/pattern.c diff --git a/pattern.c b/pattern.c index 671b56f..5ef032f 100644 --- a/pattern.c +++ b/pattern.c @@ -30,7 +30,7 @@ enum { ( ((x) - (BORDER + GUTTER + TILE_SIZE * TLBORDER(d))) / TILE_SIZE ) #define SIZE(d) (2*BORDER + GUTTER + TILE_SIZE * (TLBORDER(d) + (d))) -#define GETTILESIZE(d, w) (w / (2 + TLBORDER(d) + (d))) +#define GETTILESIZE(d, w) ((double)w / (2.0 + (double)TLBORDER(d) + (double)(d))) #define TOCOORD(d, x) (BORDER + GUTTER + TILE_SIZE * (TLBORDER(d) + (x))) @@ -549,6 +549,7 @@ static char *new_game_desc(game_params *params, random_state *rs, assert(desc[desclen-1] == '/'); desc[desclen-1] = '\0'; sfree(rowdata); + sfree(grid); return desc; } @@ -755,12 +756,12 @@ static void free_ui(game_ui *ui) sfree(ui); } -char *encode_ui(game_ui *ui) +static char *encode_ui(game_ui *ui) { return NULL; } -void decode_ui(game_ui *ui, char *encoding) +static void decode_ui(game_ui *ui, char *encoding) { } @@ -858,8 +859,8 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, if (move_needed) { char buf[80]; sprintf(buf, "%c%d,%d,%d,%d", - (ui->state == GRID_FULL ? 'F' : - ui->state == GRID_EMPTY ? 'E' : 'U'), + (char)(ui->state == GRID_FULL ? 'F' : + ui->state == GRID_EMPTY ? 'E' : 'U'), x1, y1, x2-x1+1, y2-y1+1); return dupstr(buf); } else @@ -944,21 +945,23 @@ static game_state *execute_move(game_state *from, char *move) * Drawing routines. */ -static void game_size(game_params *params, game_drawstate *ds, - int *x, int *y, int expand) +static void game_compute_size(game_params *params, int tilesize, + int *x, int *y) { - int ts; - - ts = min(GETTILESIZE(params->w, *x), GETTILESIZE(params->h, *y)); - if (expand) - ds->tilesize = ts; - else - ds->tilesize = min(ts, PREFERRED_TILE_SIZE); + /* Ick: fake up `ds->tilesize' for macro expansion purposes */ + struct { int tilesize; } ads, *ds = &ads; + ads.tilesize = tilesize; *x = SIZE(params->w); *y = SIZE(params->h); } +static void game_set_size(game_drawstate *ds, game_params *params, + int tilesize) +{ + ds->tilesize = tilesize; +} + static float *game_colours(frontend *fe, game_state *state, int *ncolours) { float *ret = snewn(3 * NCOLOURS, float); @@ -1189,7 +1192,7 @@ const struct game thegame = { game_changed_state, interpret_move, execute_move, - game_size, + PREFERRED_TILE_SIZE, game_compute_size, game_set_size, game_colours, game_new_drawstate, game_free_drawstate, @@ -1214,8 +1217,6 @@ void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, int align, int colour, char *text) {} void draw_rect(frontend *fe, int x, int y, int w, int h, int colour) {} void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour) {} -void draw_polygon(frontend *fe, int *coords, int npoints, - int fill, int colour) {} void clip(frontend *fe, int x, int y, int w, int h) {} void unclip(frontend *fe) {} void start_draw(frontend *fe) {}