diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-06-01 17:47:56 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-06-01 17:47:56 +0000 |
| commit | 50edaa578b614eb74c57a38faa2d05ab628ff81b (patch) | |
| tree | a48afa49172e113d2f867f33bb8f1c216b4bda8f /net.c | |
| parent | ad3abd9867962c94feeb09956e53c6fde886df0e (diff) | |
| download | puzzles-50edaa578b614eb74c57a38faa2d05ab628ff81b.zip puzzles-50edaa578b614eb74c57a38faa2d05ab628ff81b.tar.gz puzzles-50edaa578b614eb74c57a38faa2d05ab628ff81b.tar.bz2 puzzles-50edaa578b614eb74c57a38faa2d05ab628ff81b.tar.xz | |
Miscellaneous fixes from James Harvey's PalmOS porting work:
- fixed numerous memory leaks (not Palm-specific)
- corrected a couple of 32-bit-int assumptions (vital for Palm but
generally a good thing anyway)
- lifted a few function pointer types into explicit typedefs
(neutral for me but convenient for the source-munging Perl
scripts he uses to deal with Palm code segment rules)
- lifted a few function-level static arrays into global static
arrays (neutral for me but apparently works round a Palm tools
bug)
- a couple more presets in Rectangles (so that Palm, or any other
slow platform which can't handle the larger sizes easily, can
still have some variety available)
- in Solo, arranged a means of sharing scratch space between calls
to nsolve to prevent a lot of redundant malloc/frees (gives a 10%
speed increase even on existing platforms)
[originally from svn r5897]
Diffstat (limited to 'net.c')
| -rw-r--r-- | net.c | 47 |
1 files changed, 22 insertions, 25 deletions
@@ -149,32 +149,29 @@ static game_params *default_params(void) return ret; } +static const struct game_params net_presets[] = { + {5, 5, FALSE, TRUE, 0.0}, + {7, 7, FALSE, TRUE, 0.0}, + {9, 9, FALSE, TRUE, 0.0}, + {11, 11, FALSE, TRUE, 0.0}, + {13, 11, FALSE, TRUE, 0.0}, + {5, 5, TRUE, TRUE, 0.0}, + {7, 7, TRUE, TRUE, 0.0}, + {9, 9, TRUE, TRUE, 0.0}, + {11, 11, TRUE, TRUE, 0.0}, + {13, 11, TRUE, TRUE, 0.0}, +}; + static int game_fetch_preset(int i, char **name, game_params **params) { game_params *ret; char str[80]; - static const struct { int x, y, wrap; } values[] = { - {5, 5, FALSE}, - {7, 7, FALSE}, - {9, 9, FALSE}, - {11, 11, FALSE}, - {13, 11, FALSE}, - {5, 5, TRUE}, - {7, 7, TRUE}, - {9, 9, TRUE}, - {11, 11, TRUE}, - {13, 11, TRUE}, - }; - - if (i < 0 || i >= lenof(values)) + + if (i < 0 || i >= lenof(net_presets)) return FALSE; ret = snew(game_params); - ret->width = values[i].x; - ret->height = values[i].y; - ret->wrapping = values[i].wrap; - ret->unique = TRUE; - ret->barrier_probability = 0.0; + *ret = net_presets[i]; sprintf(str, "%dx%d%s", ret->width, ret->height, ret->wrapping ? " wrapping" : ""); @@ -302,12 +299,8 @@ static game_params *custom_params(config_item *cfg) static char *validate_params(game_params *params) { - if (params->width <= 0 && params->height <= 0) + if (params->width <= 0 || params->height <= 0) return "Width and height must both be greater than zero"; - if (params->width <= 0) - return "Width must be greater than zero"; - if (params->height <= 0) - return "Height must be greater than zero"; if (params->width <= 1 && params->height <= 1) return "At least one of width and height must be greater than one"; if (params->barrier_probability < 0) @@ -968,6 +961,7 @@ static void perturb(int w, int h, unsigned char *tiles, int wrapping, break; } + sfree(perim2); if (i == nperim) return; /* nothing we can do! */ @@ -1944,7 +1938,10 @@ static game_state *make_move(game_state *state, game_ui *ui, ret->last_rotate_dir = 0; /* suppress animation */ ret->last_rotate_x = ret->last_rotate_y = 0; - } else assert(0); + } else { + ret = NULL; /* placate optimisers which don't understand assert(0) */ + assert(0); + } /* * Check whether the game has been completed. |