How did I manage to check this in without actually trying to build

on Windows at all?! Fix some departures from the C standard, mostly
declaring variables after a statement has already been issued in the
same block. MSVC is picky about this where gcc is forgiving, and TBH
I'd change the latter given the choice.

[originally from svn r8166]
This commit is contained in:
Simon Tatham
2008-09-07 08:35:52 +00:00
parent f7ab0a4996
commit 4033458aff
3 changed files with 35 additions and 23 deletions

6
grid.c
View File

@ -81,8 +81,9 @@ static double point_line_distance(int px, int py,
int bx, int by) int bx, int by)
{ {
int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py; int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
double len;
det = max(det, -det); det = max(det, -det);
double len = sqrt(SQ(ax - bx) + SQ(ay - by)); len = sqrt(SQ(ax - bx) + SQ(ay - by));
return det / len; return det / len;
} }
@ -136,9 +137,10 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
int j; int j;
if (!f) continue; if (!f) continue;
for (j = 0; j < f->order; j++) { for (j = 0; j < f->order; j++) {
int new_dist;
grid_dot *d = f->dots[j]; grid_dot *d = f->dots[j];
if (d == cur) continue; if (d == cur) continue;
int new_dist = SQ(d->x - x) + SQ(d->y - y); new_dist = SQ(d->x - x) + SQ(d->y - y);
if (new_dist < dist) { if (new_dist < dist) {
new = d; new = d;
break; /* found closer dot */ break; /* found closer dot */

2
grid.h
View File

@ -10,9 +10,7 @@
#define PUZZLES_GRID_H #define PUZZLES_GRID_H
/* Useful macros */ /* Useful macros */
#ifndef SQ
#define SQ(x) ( (x) * (x) ) #define SQ(x) ( (x) * (x) )
#endif
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
* Grid structures: * Grid structures:

48
loopy.c
View File

@ -711,13 +711,15 @@ static void game_compute_size(game_params *params, int tilesize,
int *x, int *y) int *x, int *y)
{ {
grid *g; grid *g;
int grid_width, grid_height, rendered_width, rendered_height;
params_generate_grid(params); params_generate_grid(params);
g = params->game_grid; g = params->game_grid;
int grid_width = g->highest_x - g->lowest_x; grid_width = g->highest_x - g->lowest_x;
int grid_height = g->highest_y - g->lowest_y; grid_height = g->highest_y - g->lowest_y;
/* multiply first to minimise rounding error on integer division */ /* multiply first to minimise rounding error on integer division */
int rendered_width = grid_width * tilesize / g->tilesize; rendered_width = grid_width * tilesize / g->tilesize;
int rendered_height = grid_height * tilesize / g->tilesize; rendered_height = grid_height * tilesize / g->tilesize;
*x = rendered_width + 2 * BORDER(tilesize) + 1; *x = rendered_width + 2 * BORDER(tilesize) + 1;
*y = rendered_height + 2 * BORDER(tilesize) + 1; *y = rendered_height + 2 * BORDER(tilesize) + 1;
} }
@ -865,13 +867,15 @@ static char *game_text_format(game_state *state)
/* Fill in clues */ /* Fill in clues */
for (i = 0; i < g->num_faces; i++) { for (i = 0; i < g->num_faces; i++) {
int x1, x2, y1, y2;
f = g->faces + i; f = g->faces + i;
assert(f->order == 4); assert(f->order == 4);
/* Cell coordinates, from (0,0) to (w-1,h-1) */ /* Cell coordinates, from (0,0) to (w-1,h-1) */
int x1 = (f->dots[0]->x - g->lowest_x) / cell_size; x1 = (f->dots[0]->x - g->lowest_x) / cell_size;
int x2 = (f->dots[2]->x - g->lowest_x) / cell_size; x2 = (f->dots[2]->x - g->lowest_x) / cell_size;
int y1 = (f->dots[0]->y - g->lowest_y) / cell_size; y1 = (f->dots[0]->y - g->lowest_y) / cell_size;
int y2 = (f->dots[2]->y - g->lowest_y) / cell_size; y2 = (f->dots[2]->y - g->lowest_y) / cell_size;
/* Midpoint, in canvas coordinates */ /* Midpoint, in canvas coordinates */
x = x1 + x2; x = x1 + x2;
y = y1 + y2; y = y1 + y2;
@ -1592,11 +1596,13 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
int n; int n;
const char *dp = desc; const char *dp = desc;
grid *g; grid *g;
int num_faces, num_edges;
params_generate_grid(params); params_generate_grid(params);
state->game_grid = g = params->game_grid; state->game_grid = g = params->game_grid;
g->refcount++; g->refcount++;
int num_faces = g->num_faces; num_faces = g->num_faces;
int num_edges = g->num_edges; num_edges = g->num_edges;
state->clues = snewn(num_faces, signed char); state->clues = snewn(num_faces, signed char);
state->lines = snewn(num_edges, char); state->lines = snewn(num_edges, char);
@ -2979,10 +2985,12 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
/* Draw clues */ /* Draw clues */
for (i = 0; i < g->num_faces; i++) { for (i = 0; i < g->num_faces; i++) {
grid_face *f;
int x, y;
c[0] = CLUE2CHAR(state->clues[i]); c[0] = CLUE2CHAR(state->clues[i]);
c[1] = '\0'; c[1] = '\0';
int x, y; f = g->faces + i;
grid_face *f = g->faces + i;
face_text_pos(ds, g, f, &x, &y); face_text_pos(ds, g, f, &x, &y);
draw_text(dr, x, y, FONT_VARIABLE, ds->tilesize/2, draw_text(dr, x, y, FONT_VARIABLE, ds->tilesize/2,
ALIGN_VCENTRE | ALIGN_HCENTRE, COL_FOREGROUND, c); ALIGN_VCENTRE | ALIGN_HCENTRE, COL_FOREGROUND, c);
@ -3236,14 +3244,18 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
double d = sqrt(SQ((double)x1 - x2) + SQ((double)y1 - y2)); double d = sqrt(SQ((double)x1 - x2) + SQ((double)y1 - y2));
double dx = (x2 - x1) / d; double dx = (x2 - x1) / d;
double dy = (y2 - y1) / d; double dy = (y2 - y1) / d;
int points[8];
dx = (dx * ds->tilesize) / thickness; dx = (dx * ds->tilesize) / thickness;
dy = (dy * ds->tilesize) / thickness; dy = (dy * ds->tilesize) / thickness;
int points[] = { points[0] = x1 + dy;
x1 + dy, y1 - dx, points[1] = y1 - dx;
x1 - dy, y1 + dx, points[2] = x1 - dy;
x2 - dy, y2 + dx, points[3] = y1 + dx;
x2 + dy, y2 - dx points[4] = x2 - dy;
}; points[5] = y2 + dx;
points[6] = x2 + dy;
points[7] = y2 - dx;
draw_polygon(dr, points, 4, ink, ink); draw_polygon(dr, points, 4, ink, ink);
} }
else else