ref: 4033458aff500635a10c6659e6e1c6fe0db687e9
parent: f7ab0a4996deb231165257a502a023c3024c3151
author: Simon Tatham <[email protected]>
date: Sun Sep 7 04:35:52 EDT 2008
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]
--- a/grid.c
+++ b/grid.c
@@ -81,8 +81,9 @@
int bx, int by)
{
int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
+ double len;
det = max(det, -det);
- double len = sqrt(SQ(ax - bx) + SQ(ay - by));
+ len = sqrt(SQ(ax - bx) + SQ(ay - by));
return det / len;
}
@@ -136,9 +137,10 @@
int j;
if (!f) continue;
for (j = 0; j < f->order; j++) {
+ int new_dist;
grid_dot *d = f->dots[j];
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) {
new = d;
break; /* found closer dot */
--- a/grid.h
+++ b/grid.h
@@ -10,9 +10,7 @@
#define PUZZLES_GRID_H
/* Useful macros */
-#ifndef SQ
-# define SQ(x) ( (x) * (x) )
-#endif
+#define SQ(x) ( (x) * (x) )
/* ----------------------------------------------------------------------
* Grid structures:
--- a/loopy.c
+++ b/loopy.c
@@ -711,13 +711,15 @@
int *x, int *y)
{
grid *g;
+ int grid_width, grid_height, rendered_width, rendered_height;
+
params_generate_grid(params);
g = params->game_grid;
- int grid_width = g->highest_x - g->lowest_x;
- int grid_height = g->highest_y - g->lowest_y;
+ grid_width = g->highest_x - g->lowest_x;
+ grid_height = g->highest_y - g->lowest_y;
/* multiply first to minimise rounding error on integer division */
- int rendered_width = grid_width * tilesize / g->tilesize;
- int rendered_height = grid_height * tilesize / g->tilesize;
+ rendered_width = grid_width * tilesize / g->tilesize;
+ rendered_height = grid_height * tilesize / g->tilesize;
*x = rendered_width + 2 * BORDER(tilesize) + 1;
*y = rendered_height + 2 * BORDER(tilesize) + 1;
}
@@ -865,13 +867,15 @@
/* Fill in clues */
for (i = 0; i < g->num_faces; i++) {
+ int x1, x2, y1, y2;
+
f = g->faces + i;
assert(f->order == 4);
/* Cell coordinates, from (0,0) to (w-1,h-1) */
- int x1 = (f->dots[0]->x - g->lowest_x) / cell_size;
- int x2 = (f->dots[2]->x - g->lowest_x) / cell_size;
- int y1 = (f->dots[0]->y - g->lowest_y) / cell_size;
- int y2 = (f->dots[2]->y - g->lowest_y) / cell_size;
+ x1 = (f->dots[0]->x - g->lowest_x) / cell_size;
+ x2 = (f->dots[2]->x - g->lowest_x) / cell_size;
+ y1 = (f->dots[0]->y - g->lowest_y) / cell_size;
+ y2 = (f->dots[2]->y - g->lowest_y) / cell_size;
/* Midpoint, in canvas coordinates */
x = x1 + x2;
y = y1 + y2;
@@ -1592,11 +1596,13 @@
int n;
const char *dp = desc;
grid *g;
+ int num_faces, num_edges;
+
params_generate_grid(params);
state->game_grid = g = params->game_grid;
g->refcount++;
- int num_faces = g->num_faces;
- int num_edges = g->num_edges;
+ num_faces = g->num_faces;
+ num_edges = g->num_edges;
state->clues = snewn(num_faces, signed char);
state->lines = snewn(num_edges, char);
@@ -2979,10 +2985,12 @@
/* Draw clues */
for (i = 0; i < g->num_faces; i++) {
+ grid_face *f;
+ int x, y;
+
c[0] = CLUE2CHAR(state->clues[i]);
c[1] = '\0';
- int x, y;
- grid_face *f = g->faces + i;
+ f = g->faces + i;
face_text_pos(ds, g, f, &x, &y);
draw_text(dr, x, y, FONT_VARIABLE, ds->tilesize/2,
ALIGN_VCENTRE | ALIGN_HCENTRE, COL_FOREGROUND, c);
@@ -3236,14 +3244,18 @@
double d = sqrt(SQ((double)x1 - x2) + SQ((double)y1 - y2));
double dx = (x2 - x1) / d;
double dy = (y2 - y1) / d;
+ int points[8];
+
dx = (dx * ds->tilesize) / thickness;
dy = (dy * ds->tilesize) / thickness;
- int points[] = {
- x1 + dy, y1 - dx,
- x1 - dy, y1 + dx,
- x2 - dy, y2 + dx,
- x2 + dy, y2 - dx
- };
+ points[0] = x1 + dy;
+ points[1] = y1 - dx;
+ points[2] = x1 - dy;
+ points[3] = y1 + dx;
+ points[4] = x2 - dy;
+ points[5] = y2 + dx;
+ points[6] = x2 + dy;
+ points[7] = y2 - dx;
draw_polygon(dr, points, 4, ink, ink);
}
else