aboutsummaryrefslogtreecommitdiff
path: root/inertia.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2018-11-13 21:45:44 +0000
committerSimon Tatham <anakin@pobox.com>2018-11-13 21:48:24 +0000
commit5f5b284c0bddbe67de14b2d2bfb596bc7ba1298a (patch)
treef96b55a27088ae71d74dc83d7cc3731c5d5bf6dc /inertia.c
parenta550ea0a47374705a37f36b0f05ffe9e4c8161fb (diff)
downloadpuzzles-5f5b284c0bddbe67de14b2d2bfb596bc7ba1298a.zip
puzzles-5f5b284c0bddbe67de14b2d2bfb596bc7ba1298a.tar.gz
puzzles-5f5b284c0bddbe67de14b2d2bfb596bc7ba1298a.tar.bz2
puzzles-5f5b284c0bddbe67de14b2d2bfb596bc7ba1298a.tar.xz
Use C99 bool within source modules.
This is the main bulk of this boolification work, but although it's making the largest actual change, it should also be the least disruptive to anyone interacting with this code base downstream of me, because it doesn't modify any interface between modules: all the inter-module APIs were updated one by one in the previous commits. This just cleans up the code within each individual source file to use bool in place of int where I think that makes things clearer.
Diffstat (limited to 'inertia.c')
-rw-r--r--inertia.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/inertia.c b/inertia.c
index 528abff..3e1496f 100644
--- a/inertia.c
+++ b/inertia.c
@@ -77,8 +77,8 @@ struct game_state {
int gems;
char *grid;
int distance_moved;
- int dead;
- int cheated;
+ bool dead;
+ bool cheated;
int solnpos;
soln *soln;
};
@@ -220,7 +220,7 @@ static const char *validate_params(const game_params *params, bool full)
*/
struct solver_scratch {
- unsigned char *reachable_from, *reachable_to;
+ bool *reachable_from, *reachable_to;
int *positions;
};
@@ -228,8 +228,8 @@ static struct solver_scratch *new_scratch(int w, int h)
{
struct solver_scratch *sc = snew(struct solver_scratch);
- sc->reachable_from = snewn(w * h * DIRECTIONS, unsigned char);
- sc->reachable_to = snewn(w * h * DIRECTIONS, unsigned char);
+ sc->reachable_from = snewn(w * h * DIRECTIONS, bool);
+ sc->reachable_to = snewn(w * h * DIRECTIONS, bool);
sc->positions = snewn(w * h * DIRECTIONS, int);
return sc;
@@ -243,8 +243,8 @@ static void free_scratch(struct solver_scratch *sc)
sfree(sc);
}
-static int can_go(int w, int h, char *grid,
- int x1, int y1, int dir1, int x2, int y2, int dir2)
+static bool can_go(int w, int h, char *grid,
+ int x1, int y1, int dir1, int x2, int y2, int dir2)
{
/*
* Returns true if we can transition directly from (x1,y1)
@@ -317,8 +317,8 @@ static int find_gem_candidates(int w, int h, char *grid,
* flags set.
*/
- memset(sc->reachable_from, 0, wh * DIRECTIONS);
- memset(sc->reachable_to, 0, wh * DIRECTIONS);
+ memset(sc->reachable_from, 0, wh * DIRECTIONS * sizeof(bool));
+ memset(sc->reachable_to, 0, wh * DIRECTIONS * sizeof(bool));
/*
* Find the starting square.
@@ -334,8 +334,7 @@ static int find_gem_candidates(int w, int h, char *grid,
assert(sy < h);
for (pass = 0; pass < 2; pass++) {
- unsigned char *reachable = (pass == 0 ? sc->reachable_from :
- sc->reachable_to);
+ bool *reachable = (pass == 0 ? sc->reachable_from : sc->reachable_to);
int sign = (pass == 0 ? +1 : -1);
int dir;
@@ -392,7 +391,7 @@ static int find_gem_candidates(int w, int h, char *grid,
if (x2 >= 0 && x2 < w &&
y2 >= 0 && y2 < h &&
!reachable[i2]) {
- int ok;
+ bool ok;
#ifdef SOLVER_DIAGNOSTICS
printf(" trying point %d,%d,%d", x2, y2, d2);
#endif
@@ -1491,8 +1490,8 @@ struct game_ui {
float anim_length;
int flashtype;
int deaths;
- int just_made_move;
- int just_died;
+ bool just_made_move;
+ bool just_died;
};
static game_ui *new_ui(const game_state *state)
@@ -1549,10 +1548,11 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
struct game_drawstate {
game_params p;
int tilesize;
- int started;
+ bool started;
unsigned short *grid;
blitter *player_background;
- int player_bg_saved, pbgx, pbgy;
+ bool player_bg_saved;
+ int pbgx, pbgy;
};
#define PREFERRED_TILESIZE 32
@@ -1844,7 +1844,7 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds)
}
static void draw_player(drawing *dr, game_drawstate *ds, int x, int y,
- int dead, int hintdir)
+ bool dead, int hintdir)
{
if (dead) {
int coords[DIRECTIONS*4];