aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2022-01-27 18:48:47 +0000
committerSimon Tatham <anakin@pobox.com>2022-01-27 18:48:47 +0000
commitc43a34fbfe430d235bafc379595761880a19ed9f (patch)
tree564059d97d3a8d8d25711116a72edfeeae1cc2a1
parentc44e91567cfdb92ba9fcc6272cf1997134c58239 (diff)
downloadpuzzles-c43a34fbfe430d235bafc379595761880a19ed9f.zip
puzzles-c43a34fbfe430d235bafc379595761880a19ed9f.tar.gz
puzzles-c43a34fbfe430d235bafc379595761880a19ed9f.tar.bz2
puzzles-c43a34fbfe430d235bafc379595761880a19ed9f.tar.xz
Pearl: reorder helper functions.
interpret_ui_drag is now called from update_ui_drag, so it makes more sense to have the former appear first in the file, together with its comment explaining the expected usage.
-rw-r--r--pearl.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/pearl.c b/pearl.c
index b3b8249..4817416 100644
--- a/pearl.c
+++ b/pearl.c
@@ -1891,10 +1891,55 @@ struct game_drawstate {
char *draglines; /* size w*h; lines flipped by current drag */
};
+/*
+ * Routine shared between multiple callers to work out the intended
+ * effect of a drag path on the grid.
+ *
+ * Call it in a loop, like this:
+ *
+ * bool clearing = true;
+ * for (i = 0; i < ui->ndragcoords - 1; i++) {
+ * int sx, sy, dx, dy, dir, oldstate, newstate;
+ * interpret_ui_drag(state, ui, &clearing, i, &sx, &sy, &dx, &dy,
+ * &dir, &oldstate, &newstate);
+ *
+ * [do whatever is needed to handle the fact that the drag
+ * wants the edge from sx,sy to dx,dy (heading in direction
+ * 'dir' at the sx,sy end) to be changed from state oldstate
+ * to state newstate, each of which equals either 0 or dir]
+ * }
+ */
static void interpret_ui_drag(const game_state *state, const game_ui *ui,
bool *clearing, int i, int *sx, int *sy,
int *dx, int *dy, int *dir,
- int *oldstate, int *newstate);
+ int *oldstate, int *newstate)
+{
+ int w = state->shared->w;
+ int sp = ui->dragcoords[i], dp = ui->dragcoords[i+1];
+ *sy = sp/w;
+ *sx = sp%w;
+ *dy = dp/w;
+ *dx = dp%w;
+ *dir = (*dy>*sy ? D : *dy<*sy ? U : *dx>*sx ? R : L);
+ *oldstate = state->lines[sp] & *dir;
+ if (*oldstate) {
+ /*
+ * The edge we've dragged over was previously
+ * present. Set it to absent, unless we've already
+ * stopped doing that.
+ */
+ *newstate = *clearing ? 0 : *dir;
+ } else {
+ /*
+ * The edge we've dragged over was previously
+ * absent. Set it to present, and cancel the
+ * 'clearing' flag so that all subsequent edges in
+ * the drag are set rather than cleared.
+ */
+ *newstate = *dir;
+ *clearing = false;
+ }
+}
static void update_ui_drag(const game_state *state, game_ui *ui,
int gx, int gy)
@@ -1992,56 +2037,6 @@ static void update_ui_drag(const game_state *state, game_ui *ui,
*/
}
-/*
- * Routine shared between interpret_move and game_redraw to work out
- * the intended effect of a drag path on the grid.
- *
- * Call it in a loop, like this:
- *
- * bool clearing = true;
- * for (i = 0; i < ui->ndragcoords - 1; i++) {
- * int sx, sy, dx, dy, dir, oldstate, newstate;
- * interpret_ui_drag(state, ui, &clearing, i, &sx, &sy, &dx, &dy,
- * &dir, &oldstate, &newstate);
- *
- * [do whatever is needed to handle the fact that the drag
- * wants the edge from sx,sy to dx,dy (heading in direction
- * 'dir' at the sx,sy end) to be changed from state oldstate
- * to state newstate, each of which equals either 0 or dir]
- * }
- */
-static void interpret_ui_drag(const game_state *state, const game_ui *ui,
- bool *clearing, int i, int *sx, int *sy,
- int *dx, int *dy, int *dir,
- int *oldstate, int *newstate)
-{
- int w = state->shared->w;
- int sp = ui->dragcoords[i], dp = ui->dragcoords[i+1];
- *sy = sp/w;
- *sx = sp%w;
- *dy = dp/w;
- *dx = dp%w;
- *dir = (*dy>*sy ? D : *dy<*sy ? U : *dx>*sx ? R : L);
- *oldstate = state->lines[sp] & *dir;
- if (*oldstate) {
- /*
- * The edge we've dragged over was previously
- * present. Set it to absent, unless we've already
- * stopped doing that.
- */
- *newstate = *clearing ? 0 : *dir;
- } else {
- /*
- * The edge we've dragged over was previously
- * absent. Set it to present, and cancel the
- * 'clearing' flag so that all subsequent edges in
- * the drag are set rather than cleared.
- */
- *newstate = *dir;
- *clearing = false;
- }
-}
-
static char *mark_in_direction(const game_state *state, int x, int y, int dir,
bool primary, char *buf)
{