diff options
-rw-r--r-- | apps/plugins/puzzles/rbcompat.h | 1 | ||||
-rw-r--r-- | apps/plugins/puzzles/rbwrappers.c | 6 | ||||
-rw-r--r-- | apps/plugins/puzzles/src/midend.c | 2 | ||||
-rw-r--r-- | apps/plugins/puzzles/src/net.c | 7 | ||||
-rw-r--r-- | apps/plugins/puzzles/src/netslide.c | 7 | ||||
-rw-r--r-- | apps/plugins/puzzles/src/rect.c | 7 |
6 files changed, 23 insertions, 7 deletions
diff --git a/apps/plugins/puzzles/rbcompat.h b/apps/plugins/puzzles/rbcompat.h index 4bb9f39ca7..66c86f1cf4 100644 --- a/apps/plugins/puzzles/rbcompat.h +++ b/apps/plugins/puzzles/rbcompat.h | |||
@@ -15,6 +15,7 @@ double cos_wrapper(double rads); | |||
15 | int vsprintf_wrapper(char *s, const char *fmt, va_list ap); | 15 | int vsprintf_wrapper(char *s, const char *fmt, va_list ap); |
16 | float fabs_wrapper(float n); | 16 | float fabs_wrapper(float n); |
17 | float floor_wrapper(float n); | 17 | float floor_wrapper(float n); |
18 | int ftoa(char *buf, int len, float f); | ||
18 | 19 | ||
19 | float atan_wrapper(float x); | 20 | float atan_wrapper(float x); |
20 | float atan2_wrapper(float y, float x); | 21 | float atan2_wrapper(float y, float x); |
diff --git a/apps/plugins/puzzles/rbwrappers.c b/apps/plugins/puzzles/rbwrappers.c index 95bc2fc5b1..2d857c1cc9 100644 --- a/apps/plugins/puzzles/rbwrappers.c +++ b/apps/plugins/puzzles/rbwrappers.c | |||
@@ -23,6 +23,12 @@ int puts_wrapper(const char *s) | |||
23 | return 0; | 23 | return 0; |
24 | } | 24 | } |
25 | 25 | ||
26 | int ftoa(char *buf, int len, float f) | ||
27 | { | ||
28 | /* biggest hack ever */ | ||
29 | return rb->snprintf(buf, len, "%d.%06d", (int)f, (int)((f - (int)f)*1e6)); | ||
30 | } | ||
31 | |||
26 | /* fixed-point wrappers */ | 32 | /* fixed-point wrappers */ |
27 | static long lastphase = 0, lastsin = 0, lastcos = 0x7fffffff; | 33 | static long lastphase = 0, lastsin = 0, lastcos = 0x7fffffff; |
28 | 34 | ||
diff --git a/apps/plugins/puzzles/src/midend.c b/apps/plugins/puzzles/src/midend.c index 2eb5ee93e8..6dbdd33905 100644 --- a/apps/plugins/puzzles/src/midend.c +++ b/apps/plugins/puzzles/src/midend.c | |||
@@ -1701,7 +1701,7 @@ void midend_serialise(midend *me, | |||
1701 | */ | 1701 | */ |
1702 | if (me->ourgame->is_timed) { | 1702 | if (me->ourgame->is_timed) { |
1703 | char buf[80]; | 1703 | char buf[80]; |
1704 | sprintf(buf, "%g", me->elapsed); | 1704 | ftoa(buf, 80, me->elapsed); |
1705 | wr("TIME", buf); | 1705 | wr("TIME", buf); |
1706 | } | 1706 | } |
1707 | 1707 | ||
diff --git a/apps/plugins/puzzles/src/net.c b/apps/plugins/puzzles/src/net.c index de51f82fd7..9289afb682 100644 --- a/apps/plugins/puzzles/src/net.c +++ b/apps/plugins/puzzles/src/net.c | |||
@@ -257,7 +257,10 @@ static char *encode_params(const game_params *params, int full) | |||
257 | if (params->wrapping) | 257 | if (params->wrapping) |
258 | ret[len++] = 'w'; | 258 | ret[len++] = 'w'; |
259 | if (full && params->barrier_probability) | 259 | if (full && params->barrier_probability) |
260 | len += sprintf(ret+len, "b%g", params->barrier_probability); | 260 | { |
261 | len += sprintf(ret+len, "b"); | ||
262 | len += ftoa(ret + len, 400, params->barrier_probability); | ||
263 | } | ||
261 | if (full && !params->unique) | 264 | if (full && !params->unique) |
262 | ret[len++] = 'a'; | 265 | ret[len++] = 'a'; |
263 | assert(len < lenof(ret)); | 266 | assert(len < lenof(ret)); |
@@ -292,7 +295,7 @@ static config_item *game_configure(const game_params *params) | |||
292 | 295 | ||
293 | ret[3].name = "Barrier probability"; | 296 | ret[3].name = "Barrier probability"; |
294 | ret[3].type = C_STRING; | 297 | ret[3].type = C_STRING; |
295 | sprintf(buf, "%g", params->barrier_probability); | 298 | ftoa(buf, 80, params->barrier_probability); |
296 | ret[3].sval = dupstr(buf); | 299 | ret[3].sval = dupstr(buf); |
297 | ret[3].ival = 0; | 300 | ret[3].ival = 0; |
298 | 301 | ||
diff --git a/apps/plugins/puzzles/src/netslide.c b/apps/plugins/puzzles/src/netslide.c index c56e1abd6a..663febc61a 100644 --- a/apps/plugins/puzzles/src/netslide.c +++ b/apps/plugins/puzzles/src/netslide.c | |||
@@ -241,7 +241,10 @@ static char *encode_params(const game_params *params, int full) | |||
241 | if (params->wrapping) | 241 | if (params->wrapping) |
242 | ret[len++] = 'w'; | 242 | ret[len++] = 'w'; |
243 | if (full && params->barrier_probability) | 243 | if (full && params->barrier_probability) |
244 | len += sprintf(ret+len, "b%g", params->barrier_probability); | 244 | { |
245 | len += sprintf(ret+len, "b"); | ||
246 | len += ftoa(ret + len, 400, params->barrier_probability); | ||
247 | } | ||
245 | /* Shuffle limit is part of the limited parameters, because we have to | 248 | /* Shuffle limit is part of the limited parameters, because we have to |
246 | * provide the target move count. */ | 249 | * provide the target move count. */ |
247 | if (params->movetarget) | 250 | if (params->movetarget) |
@@ -278,7 +281,7 @@ static config_item *game_configure(const game_params *params) | |||
278 | 281 | ||
279 | ret[3].name = "Barrier probability"; | 282 | ret[3].name = "Barrier probability"; |
280 | ret[3].type = C_STRING; | 283 | ret[3].type = C_STRING; |
281 | sprintf(buf, "%g", params->barrier_probability); | 284 | ftoa(buf, 80, params->barrier_probability); |
282 | ret[3].sval = dupstr(buf); | 285 | ret[3].sval = dupstr(buf); |
283 | ret[3].ival = 0; | 286 | ret[3].ival = 0; |
284 | 287 | ||
diff --git a/apps/plugins/puzzles/src/rect.c b/apps/plugins/puzzles/src/rect.c index 465e1436fa..0c06c74945 100644 --- a/apps/plugins/puzzles/src/rect.c +++ b/apps/plugins/puzzles/src/rect.c | |||
@@ -163,7 +163,10 @@ static char *encode_params(const game_params *params, int full) | |||
163 | 163 | ||
164 | sprintf(data, "%dx%d", params->w, params->h); | 164 | sprintf(data, "%dx%d", params->w, params->h); |
165 | if (full && params->expandfactor) | 165 | if (full && params->expandfactor) |
166 | sprintf(data + strlen(data), "e%g", params->expandfactor); | 166 | { |
167 | sprintf(data + strlen(data), "e"); | ||
168 | ftoa(data + strlen(data), 256, params->expandfactor); | ||
169 | } | ||
167 | if (full && !params->unique) | 170 | if (full && !params->unique) |
168 | strcat(data, "a"); | 171 | strcat(data, "a"); |
169 | 172 | ||
@@ -191,7 +194,7 @@ static config_item *game_configure(const game_params *params) | |||
191 | 194 | ||
192 | ret[2].name = "Expansion factor"; | 195 | ret[2].name = "Expansion factor"; |
193 | ret[2].type = C_STRING; | 196 | ret[2].type = C_STRING; |
194 | sprintf(buf, "%g", params->expandfactor); | 197 | ftoa(buf, 80, params->expandfactor); |
195 | ret[2].sval = dupstr(buf); | 198 | ret[2].sval = dupstr(buf); |
196 | ret[2].ival = 0; | 199 | ret[2].ival = 0; |
197 | 200 | ||