ref: acf5c55d355b49fec8fb5376737d606be0cd8d4f
parent: 018fa4053da9fddbf6a410210cb4f493945d046f
author: Simon Tatham <[email protected]>
date: Wed Sep 10 17:44:23 EDT 2008
Patch from James H to make new-Loopy port more easily. [originally from svn r8174]
--- a/grid.c
+++ b/grid.c
@@ -50,7 +50,7 @@
/* Used by the other grid generators. Create a brand new grid with nothing
* initialised (all lists are NULL) */
-static grid *grid_new()
+static grid *grid_new(void)
{
grid *g = snew(grid);
g->faces = NULL;
@@ -76,11 +76,11 @@
*
* Combining gives: distance = determinant / line-length(a,b)
*/
-static double point_line_distance(int px, int py,
- int ax, int ay,
- int bx, int by)
+static double point_line_distance(long px, long py,
+ long ax, long ay,
+ long bx, long by)
{
- int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
+ long det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
double len;
det = max(det, -det);
len = sqrt(SQ(ax - bx) + SQ(ay - by));
@@ -125,7 +125,7 @@
for (;;) {
/* Target to beat */
- int dist = SQ(cur->x - x) + SQ(cur->y - y);
+ long dist = SQ((long)cur->x - (long)x) + SQ((long)cur->y - (long)y);
/* Look for nearer dot - if found, store in 'new'. */
grid_dot *new = cur;
int i;
@@ -137,10 +137,10 @@
int j;
if (!f) continue;
for (j = 0; j < f->order; j++) {
- int new_dist;
+ long new_dist;
grid_dot *d = f->dots[j];
if (d == cur) continue;
- new_dist = SQ(d->x - x) + SQ(d->y - y);
+ new_dist = SQ((long)d->x - (long)x) + SQ((long)d->y - (long)y);
if (new_dist < dist) {
new = d;
break; /* found closer dot */
@@ -157,14 +157,13 @@
cur = new;
}
}
-
/* 'cur' is nearest dot, so find which of the dot's edges is closest. */
best_edge = NULL;
for (i = 0; i < cur->order; i++) {
grid_edge *e = cur->edges[i];
- int e2; /* squared length of edge */
- int a2, b2; /* squared lengths of other sides */
+ long e2; /* squared length of edge */
+ long a2, b2; /* squared lengths of other sides */
double dist;
/* See if edge e is eligible - the triangle must have acute angles
@@ -171,9 +170,9 @@
* at the edge's dots.
* Pythagoras formula h^2 = a^2 + b^2 detects right-angles,
* so detect acute angles by testing for h^2 < a^2 + b^2 */
- e2 = SQ(e->dot1->x - e->dot2->x) + SQ(e->dot1->y - e->dot2->y);
- a2 = SQ(e->dot1->x - x) + SQ(e->dot1->y - y);
- b2 = SQ(e->dot2->x - x) + SQ(e->dot2->y - y);
+ e2 = SQ((long)e->dot1->x - (long)e->dot2->x) + SQ((long)e->dot1->y - (long)e->dot2->y);
+ a2 = SQ((long)e->dot1->x - (long)x) + SQ((long)e->dot1->y - (long)y);
+ b2 = SQ((long)e->dot2->x - (long)x) + SQ((long)e->dot2->y - (long)y);
if (a2 >= e2 + b2) continue;
if (b2 >= e2 + a2) continue;
@@ -187,9 +186,9 @@
* Alternatively, we could check that the angle at the point is obtuse.
* That would amount to testing a circular region with the edge as
* diameter. */
- dist = point_line_distance(x, y,
- e->dot1->x, e->dot1->y,
- e->dot2->x, e->dot2->y);
+ dist = point_line_distance((long)x, (long)y,
+ (long)e->dot1->x, (long)e->dot1->y,
+ (long)e->dot2->x, (long)e->dot2->y);
/* Is dist more than half edge length ? */
if (4 * SQ(dist) > e2)
continue;
--- a/loopy.c
+++ b/loopy.c
@@ -236,7 +236,7 @@
static char const *const gridnames[] = { GRIDLIST(GRID_NAME) };
#define GRID_CONFIGS GRIDLIST(GRID_CONFIG)
static grid * (*(grid_fns[]))(int w, int h) = { GRIDLIST(GRID_FN) };
-static const int NUM_GRID_TYPES = sizeof(grid_fns) / sizeof(grid_fns[0]);
+#define NUM_GRID_TYPES (sizeof(grid_fns) / sizeof(grid_fns[0]))
/* Generates a (dynamically allocated) new grid, according to the
* type and size requested in params. Does nothing if the grid is already
@@ -464,7 +464,19 @@
}
static const game_params presets[] = {
+#ifdef SMALL_SCREEN
{ 7, 7, DIFF_EASY, 0, NULL },
+ { 7, 7, DIFF_NORMAL, 0, NULL },
+ { 7, 7, DIFF_HARD, 0, NULL },
+ { 7, 7, DIFF_HARD, 1, NULL },
+ { 7, 7, DIFF_HARD, 2, NULL },
+ { 5, 5, DIFF_HARD, 3, NULL },
+ { 7, 7, DIFF_HARD, 4, NULL },
+ { 5, 4, DIFF_HARD, 5, NULL },
+ { 5, 5, DIFF_HARD, 6, NULL },
+ { 5, 5, DIFF_HARD, 7, NULL },
+#else
+ { 7, 7, DIFF_EASY, 0, NULL },
{ 10, 10, DIFF_EASY, 0, NULL },
{ 7, 7, DIFF_NORMAL, 0, NULL },
{ 10, 10, DIFF_NORMAL, 0, NULL },
@@ -477,6 +489,7 @@
{ 5, 4, DIFF_HARD, 5, NULL },
{ 7, 7, DIFF_HARD, 6, NULL },
{ 5, 5, DIFF_HARD, 7, NULL },
+#endif
};
static int game_fetch_preset(int i, char **name, game_params **params)
@@ -3291,14 +3304,14 @@
dx = (dx * ds->tilesize) / thickness;
dy = (dy * ds->tilesize) / thickness;
- 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;
+ points[0] = x1 + (int)dy;
+ points[1] = y1 - (int)dx;
+ points[2] = x1 - (int)dy;
+ points[3] = y1 + (int)dx;
+ points[4] = x2 - (int)dy;
+ points[5] = y2 + (int)dx;
+ points[6] = x2 + (int)dy;
+ points[7] = y2 - (int)dx;
draw_polygon(dr, points, 4, ink, ink);
}
else