aboutsummaryrefslogtreecommitdiff
path: root/pattern.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-06-30 09:07:00 +0000
committerSimon Tatham <anakin@pobox.com>2005-06-30 09:07:00 +0000
commit118abb4fc9365807ad4174588eeb9aefda550415 (patch)
treeea53c5b0a1c8600912a8806ff08e356c0f95faab /pattern.c
parent101324af67c5e7819849daeafb337dd4c1f45828 (diff)
downloadpuzzles-118abb4fc9365807ad4174588eeb9aefda550415.zip
puzzles-118abb4fc9365807ad4174588eeb9aefda550415.tar.gz
puzzles-118abb4fc9365807ad4174588eeb9aefda550415.tar.bz2
puzzles-118abb4fc9365807ad4174588eeb9aefda550415.tar.xz
General robustness patch from James Harvey:
- most game_size() functions now work in doubles internally and round to nearest, meaning that they have less tendency to try to alter a size they returned happily from a previous call - couple of fiddly fixes (memory leaks, precautionary casts in printf argument lists) - midend_deserialise() now constructs an appropriate drawstate, which I can't think how I overlooked myself since I _thought_ I went through the entire midend structure field by field! [originally from svn r6041]
Diffstat (limited to 'pattern.c')
-rw-r--r--pattern.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/pattern.c b/pattern.c
index 19d16ff..b7c5334 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;
}
@@ -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
@@ -947,13 +948,13 @@ static game_state *execute_move(game_state *from, char *move)
static void game_size(game_params *params, game_drawstate *ds,
int *x, int *y, int expand)
{
- int ts;
+ double ts;
ts = min(GETTILESIZE(params->w, *x), GETTILESIZE(params->h, *y));
if (expand)
- ds->tilesize = ts;
+ ds->tilesize = (int)(ts + 0.5);
else
- ds->tilesize = min(ts, PREFERRED_TILE_SIZE);
+ ds->tilesize = min((int)ts, PREFERRED_TILE_SIZE);
*x = SIZE(params->w);
*y = SIZE(params->h);