ref: 1d661ec46b8d7216bc6f2e34a4d6b9cc9fdc6f96
parent: 5ead207060a3e1f74ad6200fdf02934457394bc2
author: Simon Tatham <[email protected]>
date: Sat Sep 13 14:29:20 EDT 2008
Patch from James H providing lots more paranoid casting. Also one actual behaviour change: Untangle now permits dragging with the right mouse button, which has exactly the same effect as it does with the left. (Harmless on desktop platforms, but helpful when "right-click" is achieved by press-and-hold; now the drag takes place even if you hesitate first.) [originally from svn r8177]
--- a/cube.c
+++ b/cube.c
@@ -1115,8 +1115,8 @@
int cx, cy;
double angle;
- cx = state->squares[state->current].x * GRID_SCALE + ds->ox;
- cy = state->squares[state->current].y * GRID_SCALE + ds->oy;
+ cx = (int)(state->squares[state->current].x * GRID_SCALE) + ds->ox;
+ cy = (int)(state->squares[state->current].y * GRID_SCALE) + ds->oy;
if (x == cx && y == cy)
return NULL; /* clicked in exact centre! */
@@ -1476,7 +1476,7 @@
{
struct bbox bb = find_bbox(params);
- ds->gridscale = tilesize;
+ ds->gridscale = (float)tilesize;
ds->ox = (int)(-(bb.l - solids[params->solid]->border) * ds->gridscale);
ds->oy = (int)(-(bb.u - solids[params->solid]->border) * ds->gridscale);
}
@@ -1503,7 +1503,8 @@
{
struct game_drawstate *ds = snew(struct game_drawstate);
- ds->ox = ds->oy = ds->gridscale = 0.0F;/* not decided yet */
+ ds->ox = ds->oy = 0;
+ ds->gridscale = 0.0F; /* not decided yet */
return ds;
}
--- a/drawing.c
+++ b/drawing.c
@@ -281,5 +281,5 @@
* _square root_ of the main puzzle scale. Double the puzzle
* size, and the line width multiplies by 1.4.
*/
- dr->api->line_width(dr->handle, sqrt(dr->scale) * width);
+ dr->api->line_width(dr->handle, (float)sqrt(dr->scale) * width);
}
--- a/flip.c
+++ b/flip.c
@@ -1099,12 +1099,12 @@
coords[0] = bx + TILE_SIZE;
coords[1] = by;
- coords[2] = bx + TILE_SIZE * animtime;
- coords[3] = by + TILE_SIZE * animtime;
+ coords[2] = bx + (int)((float)TILE_SIZE * animtime);
+ coords[3] = by + (int)((float)TILE_SIZE * animtime);
coords[4] = bx;
coords[5] = by + TILE_SIZE;
- coords[6] = bx + TILE_SIZE - TILE_SIZE * animtime;
- coords[7] = by + TILE_SIZE - TILE_SIZE * animtime;
+ coords[6] = bx + TILE_SIZE - (int)((float)TILE_SIZE * animtime);
+ coords[7] = by + TILE_SIZE - (int)((float)TILE_SIZE * animtime);
colour = (tile & 1 ? COL_WRONG : COL_RIGHT);
if (animtime < 0.5)
@@ -1185,7 +1185,7 @@
}
if (flashtime)
- flashframe = flashtime / FLASH_FRAME;
+ flashframe = (int)(flashtime / FLASH_FRAME);
else
flashframe = -1;
--- a/guess.c
+++ b/guess.c
@@ -992,9 +992,9 @@
/* We also want to be able to tell the difference between BACKGROUND
* and EMPTY, for similar distinguishing-hint reasons. */
- ret[COL_EMPTY * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
- ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
- ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
+ ret[COL_EMPTY * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0F / 3.0F;
+ ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0F / 3.0F;
+ ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0F / 3.0F;
*ncolours = NCOLOURS;
return ret;
--- a/lightup.c
+++ b/lightup.c
@@ -2171,8 +2171,8 @@
* I'll use 6mm squares by default.
*/
game_compute_size(params, 600, &pw, &ph);
- *x = pw / 100.0;
- *y = ph / 100.0;
+ *x = pw / 100.0F;
+ *y = ph / 100.0F;
}
static void game_print(drawing *dr, game_state *state, int tilesize)
--- a/midend.c
+++ b/midend.c
@@ -335,9 +335,9 @@
char newseed[16];
int i;
newseed[15] = '\0';
- newseed[0] = '1' + random_upto(me->random, 9);
+ newseed[0] = '1' + (char)random_upto(me->random, 9);
for (i = 1; i < 15; i++)
- newseed[i] = '0' + random_upto(me->random, 10);
+ newseed[i] = '0' + (char)random_upto(me->random, 10);
sfree(me->seedstr);
me->seedstr = dupstr(newseed);
@@ -832,9 +832,9 @@
buf[k] = '\0';
if ((e = getenv(buf)) != NULL &&
sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) {
- ret[i*3 + 0] = r / 255.0;
- ret[i*3 + 1] = g / 255.0;
- ret[i*3 + 2] = b / 255.0;
+ ret[i*3 + 0] = r / 255.0F;
+ ret[i*3 + 1] = g / 255.0F;
+ ret[i*3 + 2] = b / 255.0F;
}
}
}
@@ -1304,7 +1304,7 @@
char timebuf[100], *ret;
int min, sec;
- sec = me->elapsed;
+ sec = (int)me->elapsed;
min = sec / 60;
sec %= 60;
sprintf(timebuf, "[%d:%02d] ", min, sec);
@@ -1608,7 +1608,7 @@
uistr = val;
val = NULL;
} else if (!strcmp(key, "TIME")) {
- elapsed = atof(val);
+ elapsed = (float)atof(val);
} else if (!strcmp(key, "NSTATES")) {
nstates = atoi(val);
if (nstates <= 0) {
--- a/net.c
+++ b/net.c
@@ -232,7 +232,7 @@
ret->wrapping = TRUE;
} else if (*p == 'b') {
p++;
- ret->barrier_probability = atof(p);
+ ret->barrier_probability = (float)atof(p);
while (*p && (*p == '.' || isdigit((unsigned char)*p))) p++;
} else if (*p == 'a') {
p++;
@@ -2863,8 +2863,8 @@
* I'll use 8mm squares by default.
*/
game_compute_size(params, 800, &pw, &ph);
- *x = pw / 100.0;
- *y = ph / 100.0;
+ *x = pw / 100.0F;
+ *y = ph / 100.0F;
}
static void draw_diagram(drawing *dr, game_drawstate *ds, int x, int y,
--- a/samegame.c
+++ b/samegame.c
@@ -1126,7 +1126,7 @@
if (ui->tiles[i] & TILE_SELECTED) {
sprintf(buf, "%s%d", sep, i);
sep = ",";
- if (retlen + strlen(buf) >= retsize) {
+ if (retlen + (int)strlen(buf) >= retsize) {
retsize = retlen + strlen(buf) + 256;
ret = sresize(ret, retsize, char);
}
@@ -1419,9 +1419,9 @@
ret[COL_HIGHLIGHT * 3 + 1] = 1.0F;
ret[COL_HIGHLIGHT * 3 + 2] = 1.0F;
- ret[COL_LOWLIGHT * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
- ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
- ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
+ ret[COL_LOWLIGHT * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0F / 3.0F;
+ ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0F / 3.0F;
+ ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0F / 3.0F;
*ncolours = NCOLOURS;
return ret;
--- a/untangle.c
+++ b/untangle.c
@@ -1000,8 +1000,8 @@
pts[i].d = 2;
ox *= pts[i].d;
oy *= pts[i].d;
- pts[i].x = ox + 0.5;
- pts[i].y = oy + 0.5;
+ pts[i].x = (long)(ox + 0.5F);
+ pts[i].y = (long)(oy + 0.5F);
extra = sprintf(buf, ";P%d:%ld,%ld/%ld", i,
pts[i].x, pts[i].y, pts[i].d);
@@ -1077,7 +1077,7 @@
{
int n = state->params.n;
- if (button == LEFT_BUTTON) {
+ if (IS_MOUSE_DOWN(button)) {
int i, best;
long bestd;
@@ -1111,12 +1111,12 @@
return "";
}
- } else if (button == LEFT_DRAG && ui->dragpoint >= 0) {
+ } else if (IS_MOUSE_DRAG(button) && ui->dragpoint >= 0) {
ui->newpoint.x = x;
ui->newpoint.y = y;
ui->newpoint.d = ds->tilesize;
return "";
- } else if (button == LEFT_RELEASE && ui->dragpoint >= 0) {
+ } else if (IS_MOUSE_RELEASE(button) && ui->dragpoint >= 0) {
int p = ui->dragpoint;
char buf[80];
@@ -1268,8 +1268,8 @@
point ret;
ret.d = a.d * b.d;
- ret.x = a.x * b.d + distance * (b.x * a.d - a.x * b.d);
- ret.y = a.y * b.d + distance * (b.y * a.d - a.y * b.d);
+ ret.x = (long)(a.x * b.d + distance * (b.x * a.d - a.x * b.d));
+ ret.y = (long)(a.y * b.d + distance * (b.y * a.d - a.y * b.d));
return ret;
}