shithub: puzzles

Download patch

ref: e0f5e4926549e6c0715f7438ec6b2fd07e9be3c2
parent: 8a7dad6d2d3bca56b2473bed6b70e184cf7dced5
author: Simon Tatham <anakin@pobox.com>
date: Sat Jan 19 13:56:07 EST 2013

Stop the analysis pass in Loopy's redraw routine from being
conditionalised on !ds->started, so that we still do all the looping
over everything even if we know it's all going to be redrawn. This is
because deciding how much needs redrawing is not the only important
thing in those loops - they also set up arrays like ds->clue_error,
which tell the individual redraw functions _what_ to draw.

Fixes a bug in which, if you start a Loopy game and make moves causing
a clue to light up red for an error and then save your game, loading
the same save file at the start of a Loopy run would fail to highlight
the erroneous clue.

(This commit diff looks large, but actually it changes almost nothing
but whitespace.)

[originally from svn r9751]

--- a/loopy.c
+++ b/loopy.c
@@ -3193,60 +3193,63 @@
      * what needs doing, and the second actually does it.
      */
 
-    if (!ds->started)
+    if (!ds->started) {
 	redraw_everything = TRUE;
-    else {
+        /*
+         * But we must still go through the upcoming loops, so that we
+         * set up stuff in ds correctly for the initial redraw.
+         */
+    }
 
-	/* First, trundle through the faces. */
-	for (i = 0; i < g->num_faces; i++) {
-	    grid_face *f = g->faces + i;
-	    int sides = f->order;
-	    int clue_mistake;
-	    int clue_satisfied;
-	    int n = state->clues[i];
-	    if (n < 0)
-		continue;
+    /* First, trundle through the faces. */
+    for (i = 0; i < g->num_faces; i++) {
+        grid_face *f = g->faces + i;
+        int sides = f->order;
+        int clue_mistake;
+        int clue_satisfied;
+        int n = state->clues[i];
+        if (n < 0)
+            continue;
 
-	    clue_mistake = (face_order(state, i, LINE_YES) > n ||
-			    face_order(state, i, LINE_NO ) > (sides-n));
-	    clue_satisfied = (face_order(state, i, LINE_YES) == n &&
-			      face_order(state, i, LINE_NO ) == (sides-n));
+        clue_mistake = (face_order(state, i, LINE_YES) > n ||
+                        face_order(state, i, LINE_NO ) > (sides-n));
+        clue_satisfied = (face_order(state, i, LINE_YES) == n &&
+                          face_order(state, i, LINE_NO ) == (sides-n));
 
-	    if (clue_mistake != ds->clue_error[i] ||
-		clue_satisfied != ds->clue_satisfied[i]) {
-		ds->clue_error[i] = clue_mistake;
-		ds->clue_satisfied[i] = clue_satisfied;
-		if (nfaces == REDRAW_OBJECTS_LIMIT)
-		    redraw_everything = TRUE;
-		else
-		    faces[nfaces++] = i;
-	    }
-	}
+        if (clue_mistake != ds->clue_error[i] ||
+            clue_satisfied != ds->clue_satisfied[i]) {
+            ds->clue_error[i] = clue_mistake;
+            ds->clue_satisfied[i] = clue_satisfied;
+            if (nfaces == REDRAW_OBJECTS_LIMIT)
+                redraw_everything = TRUE;
+            else
+                faces[nfaces++] = i;
+        }
+    }
 
-	/* Work out what the flash state needs to be. */
-	if (flashtime > 0 &&
-	    (flashtime <= FLASH_TIME/3 ||
-	     flashtime >= FLASH_TIME*2/3)) {
-	    flash_changed = !ds->flashing;
-	    ds->flashing = TRUE;
-	} else {
-	    flash_changed = ds->flashing;
-	    ds->flashing = FALSE;
-	}
+    /* Work out what the flash state needs to be. */
+    if (flashtime > 0 &&
+        (flashtime <= FLASH_TIME/3 ||
+         flashtime >= FLASH_TIME*2/3)) {
+        flash_changed = !ds->flashing;
+        ds->flashing = TRUE;
+    } else {
+        flash_changed = ds->flashing;
+        ds->flashing = FALSE;
+    }
 
-	/* Now, trundle through the edges. */
-	for (i = 0; i < g->num_edges; i++) {
-	    char new_ds =
-		state->line_errors[i] ? DS_LINE_ERROR : state->lines[i];
-	    if (new_ds != ds->lines[i] ||
-		(flash_changed && state->lines[i] == LINE_YES)) {
-		ds->lines[i] = new_ds;
-		if (nedges == REDRAW_OBJECTS_LIMIT)
-		    redraw_everything = TRUE;
-		else
-		    edges[nedges++] = i;
-	    }
-	}
+    /* Now, trundle through the edges. */
+    for (i = 0; i < g->num_edges; i++) {
+        char new_ds =
+            state->line_errors[i] ? DS_LINE_ERROR : state->lines[i];
+        if (new_ds != ds->lines[i] ||
+            (flash_changed && state->lines[i] == LINE_YES)) {
+            ds->lines[i] = new_ds;
+            if (nedges == REDRAW_OBJECTS_LIMIT)
+                redraw_everything = TRUE;
+            else
+                edges[nedges++] = i;
+        }
     }
 
     /* Pass one is now done.  Now we do the actual drawing. */