From c0da615a933a6676e2c6b957368067ca1bc10abd Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 25 Apr 2021 11:24:40 +0100 Subject: [PATCH] Centralise initial clearing of the puzzle window. I don't know how I've never thought of this before! Pretty much every game in this collection has to have a mechanism for noticing when game_redraw is called for the first time on a new drawstate, and if so, start by covering the whole window with a filled rectangle of the background colour. This is a pain for implementers, and also awkward because the drawstate often has to _work out_ its own pixel size (or else remember it from when its size method was called). The backends all do that so that the frontends don't have to guarantee anything about the initial window contents. But that's a silly tradeoff to begin with (there are way more backends than frontends, so this _adds_ work rather than saving it), and also, in this code base there's a standard way to handle things you don't want to have to do in every backend _or_ every frontend: do them just once in the midend! So now that rectangle-drawing operation happens in midend_redraw, and I've been able to remove it from almost every puzzle. (A couple of puzzles have other approaches: Slant didn't have a rectangle-draw because it handles even the game borders using its per-tile redraw function, and Untangle clears the whole window on every redraw _anyway_ because it would just be too confusing not to.) In some cases I've also been able to remove the 'started' flag from the drawstate. But in many cases that has to stay because it also triggers drawing of static display furniture other than the background. --- blackbox.c | 4 ---- bridges.c | 3 --- dominosa.c | 10 ---------- fifteen.c | 7 ------- filling.c | 11 +---------- flip.c | 3 --- flood.c | 7 ------- galaxies.c | 1 - guess.c | 1 - inertia.c | 9 --------- keen.c | 8 -------- lightup.c | 4 ---- magnets.c | 7 +------ map.c | 13 +------------ midend.c | 29 +++++++++++++++++++++++++++++ mines.c | 7 ------- mosaic.c | 15 --------------- net.c | 19 ------------------- netslide.c | 11 +---------- palisade.c | 1 - pattern.c | 8 -------- pearl.c | 11 +---------- pegs.c | 4 ---- range.c | 9 --------- rect.c | 3 --- samegame.c | 7 ------- signpost.c | 1 - singles.c | 1 - sixteen.c | 7 ------- slant.c | 10 ---------- solo.c | 8 -------- tents.c | 16 ++-------------- towers.c | 16 ---------------- tracks.c | 9 --------- twiddle.c | 7 ------- undead.c | 2 -- unfinished/group.c | 8 -------- unfinished/separate.c | 7 ------- unfinished/slide.c | 13 ------------- unfinished/sokoban.c | 9 --------- unruly.c | 3 --- 41 files changed, 36 insertions(+), 293 deletions(-) diff --git a/blackbox.c b/blackbox.c index 5a6be4e..2721142 100644 --- a/blackbox.c +++ b/blackbox.c @@ -1377,10 +1377,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x0 = TODRAW(0)-1, y0 = TODRAW(0)-1; int x1 = TODRAW(state->w+2), y1 = TODRAW(state->h+2); - draw_rect(dr, 0, 0, - TILE_SIZE * (state->w+3), TILE_SIZE * (state->h+3), - COL_BACKGROUND); - /* clockwise around the outline starting at pt behind (1,1). */ draw_line(dr, x0+ts, y0+ts, x0+ts, y0, COL_HIGHLIGHT); draw_line(dr, x0+ts, y0, x1-ts, y0, COL_HIGHLIGHT); diff --git a/bridges.c b/bridges.c index 83086c9..03b0623 100644 --- a/bridges.c +++ b/bridges.c @@ -2987,9 +2987,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, /* Clear screen, if required. */ if (!ds->started) { - draw_rect(dr, 0, 0, - TILE_SIZE * ds->w + 2 * BORDER, - TILE_SIZE * ds->h + 2 * BORDER, COL_BACKGROUND); #ifdef DRAW_GRID draw_rect_outline(dr, COORD(0)-1, COORD(0)-1, diff --git a/dominosa.c b/dominosa.c index 758db4f..2f8638c 100644 --- a/dominosa.c +++ b/dominosa.c @@ -2746,7 +2746,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, #define FROMCOORD(x) ( ((x) - BORDER + TILESIZE) / TILESIZE - 1 ) struct game_drawstate { - bool started; int w, h, tilesize; unsigned long *visible; }; @@ -3059,7 +3058,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) struct game_drawstate *ds = snew(struct game_drawstate); int i; - ds->started = false; ds->w = state->w; ds->h = state->h; ds->visible = snewn(ds->w * ds->h, unsigned long); @@ -3225,14 +3223,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x, y, i; unsigned char *used; - if (!ds->started) { - int pw, ph; - game_compute_size(&state->params, TILESIZE, &pw, &ph); - draw_rect(dr, 0, 0, pw, ph, COL_BACKGROUND); - draw_update(dr, 0, 0, pw, ph); - ds->started = true; - } - /* * See how many dominoes of each type there are, so we can * highlight clashes in red. diff --git a/fifteen.c b/fifteen.c index 4b877dc..41f9d41 100644 --- a/fifteen.c +++ b/fifteen.c @@ -904,13 +904,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/filling.c b/filling.c index 06f6982..80a3c6e 100644 --- a/filling.c +++ b/filling.c @@ -2021,17 +2021,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds, (flashtime <= FLASH_TIME/3 || flashtime >= FLASH_TIME*2/3); if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ - draw_rect(dr, 0, 0, w*TILE_SIZE + 2*BORDER, h*TILE_SIZE + 2*BORDER, - COL_BACKGROUND); - /* - * Smaller black rectangle which is the main grid. + * Black rectangle which is the main grid. */ draw_rect(dr, BORDER - BORDER_WIDTH, BORDER - BORDER_WIDTH, w*TILE_SIZE + 2*BORDER_WIDTH + 1, diff --git a/flip.c b/flip.c index 5d4f225..010fe61 100644 --- a/flip.c +++ b/flip.c @@ -1202,9 +1202,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int i, flashframe; if (!ds->started) { - draw_rect(dr, 0, 0, TILE_SIZE * w + 2 * BORDER, - TILE_SIZE * h + 2 * BORDER, COL_BACKGROUND); - /* * Draw the grid lines. */ diff --git a/flood.c b/flood.c index ea43302..3d7eaa2 100644 --- a/flood.c +++ b/flood.c @@ -1128,13 +1128,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILESIZE * w + 2 * BORDER, - TILESIZE * h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILESIZE * w + 2 * BORDER, - TILESIZE * h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/galaxies.c b/galaxies.c index 9172b90..4c9b8b5 100644 --- a/galaxies.c +++ b/galaxies.c @@ -3285,7 +3285,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, } if (!ds->started) { - draw_rect(dr, 0, 0, DRAW_WIDTH, DRAW_HEIGHT, COL_BACKGROUND); draw_rect(dr, BORDER - EDGE_THICKNESS + 1, BORDER - EDGE_THICKNESS + 1, w*TILE_SIZE + EDGE_THICKNESS*2 - 1, h*TILE_SIZE + EDGE_THICKNESS*2 - 1, COL_EDGE); diff --git a/guess.c b/guess.c index a501579..4784db3 100644 --- a/guess.c +++ b/guess.c @@ -1349,7 +1349,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, new_move = (state->next_go != ds->next_go) || !ds->started; if (!ds->started) { - draw_rect(dr, 0, 0, ds->w, ds->h, COL_BACKGROUND); draw_rect(dr, SOLN_OX, SOLN_OY - ds->gapsz - 1, SOLN_W, 2, COL_FRAME); draw_update(dr, 0, 0, ds->w, ds->h); } diff --git a/inertia.c b/inertia.c index 5d50b8a..ab90323 100644 --- a/inertia.c +++ b/inertia.c @@ -2008,15 +2008,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, * Initialise a fresh drawstate. */ if (!ds->started) { - int wid, ht; - - /* - * Blank out the window initially. - */ - game_compute_size(&ds->p, TILESIZE, &wid, &ht); - draw_rect(dr, 0, 0, wid, ht, COL_BACKGROUND); - draw_update(dr, 0, 0, wid, ht); - /* * Draw the grid lines. */ diff --git a/keen.c b/keen.c index 6b9610d..558c549 100644 --- a/keen.c +++ b/keen.c @@ -2133,14 +2133,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x, y; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all - * games should start by drawing a big background-colour - * rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, SIZE(w), SIZE(w), COL_BACKGROUND); - /* * Big containing rectangle. */ diff --git a/lightup.c b/lightup.c index ab4be9e..bd1dc68 100644 --- a/lightup.c +++ b/lightup.c @@ -2176,10 +2176,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (flashtime) flashing = (int)(flashtime * 3 / FLASH_TIME) != 1; if (!ds->started) { - draw_rect(dr, 0, 0, - TILE_SIZE * ds->w + 2 * BORDER, - TILE_SIZE * ds->h + 2 * BORDER, COL_BACKGROUND); - draw_rect_outline(dr, COORD(0)-1, COORD(0)-1, TILE_SIZE * ds->w + 2, TILE_SIZE * ds->h + 2, diff --git a/magnets.c b/magnets.c index edbb849..bca54c5 100644 --- a/magnets.c +++ b/magnets.c @@ -2205,12 +2205,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, flash = (int)(flashtime * 5 / FLASH_TIME) % 2; if (!ds->started) { - /* draw background, corner +-. */ - draw_rect(dr, 0, 0, - TILE_SIZE * (w+2) + 2 * BORDER, - TILE_SIZE * (h+2) + 2 * BORDER, - COL_BACKGROUND); - + /* draw corner +-. */ draw_sym(dr, ds, -1, -1, POSITIVE, COL_TEXT); draw_sym(dr, ds, state->w, state->h, NEGATIVE, COL_TEXT); diff --git a/map.c b/map.c index 412305c..1cd80b6 100644 --- a/map.c +++ b/map.c @@ -2872,21 +2872,10 @@ static void game_redraw(drawing *dr, game_drawstate *ds, ds->drag_visible = false; } - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ if (!ds->started) { - int ww, wh; - - game_compute_size(&state->p, TILESIZE, &ww, &wh); - draw_rect(dr, 0, 0, ww, wh, COL_BACKGROUND); draw_rect(dr, COORD(0), COORD(0), w*TILESIZE+1, h*TILESIZE+1, COL_GRID); - - draw_update(dr, 0, 0, ww, wh); + draw_update(dr, COORD(0), COORD(0), w*TILESIZE+1, h*TILESIZE+1); ds->started = true; } diff --git a/midend.c b/midend.c index 15636d4..0b51c10 100644 --- a/midend.c +++ b/midend.c @@ -73,6 +73,7 @@ struct midend { game_params *params, *curparams; game_drawstate *drawstate; + bool first_draw; game_ui *ui; game_state *oldstate; @@ -196,6 +197,7 @@ midend *midend_new(frontend *fe, const game *ourgame, me->aux_info = NULL; me->genmode = GOT_NOTHING; me->drawstate = NULL; + me->first_draw = true; me->oldstate = NULL; me->preset_menu = NULL; me->anim_time = me->anim_pos = 0.0F; @@ -318,6 +320,7 @@ void midend_size(midend *me, int *x, int *y, bool user_size) me->ourgame->free_drawstate(me->drawing, me->drawstate); me->drawstate = me->ourgame->new_drawstate(me->drawing, me->states[0].state); + me->first_draw = true; } /* @@ -1140,7 +1143,24 @@ void midend_redraw(midend *me) assert(me->drawing); if (me->statepos > 0 && me->drawstate) { + bool first_draw = me->first_draw; + me->first_draw = false; + start_draw(me->drawing); + + if (first_draw) { + /* + * The initial contents of the window are not guaranteed + * by the front end. But we also don't want to require + * every single game to go to the effort of clearing the + * window on setup. So we centralise here the operation of + * covering the whole window with colour 0 (assumed to be + * the puzzle's background colour) the first time we do a + * redraw operation with a new drawstate. + */ + draw_rect(me->drawing, 0, 0, me->winwidth, me->winheight, 0); + } + if (me->oldstate && me->anim_time > 0 && me->anim_pos < me->anim_time) { assert(me->dir != 0); @@ -1152,6 +1172,15 @@ void midend_redraw(midend *me) me->states[me->statepos-1].state, +1 /*shrug*/, me->ui, 0.0, me->flash_pos); } + + if (first_draw) { + /* + * Call a big draw_update on the whole window, in case the + * game backend didn't. + */ + draw_update(me->drawing, 0, 0, me->winwidth, me->winheight); + } + end_draw(me->drawing); } } diff --git a/mines.c b/mines.c index b48dc30..51ec483 100644 --- a/mines.c +++ b/mines.c @@ -2978,13 +2978,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/mosaic.c b/mosaic.c index bceafd9..20a56cf 100644 --- a/mosaic.c +++ b/mosaic.c @@ -127,7 +127,6 @@ struct game_ui { struct game_drawstate { int tilesize; - bool started; int *state; int cur_x, cur_y; /* -1, -1 for no cursor displayed. */ int prev_cur_x, prev_cur_y; @@ -1413,7 +1412,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) int i; ds->tilesize = 0; - ds->started = false; ds->state = NULL; ds->state = snewn(state->width * state->height, int); for (i = 0; i < state->width * state->height; i++) @@ -1474,19 +1472,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, bool flashing = (flashtime > 0 && (flashtime <= FLASH_TIME / 3 || flashtime > 2*FLASH_TIME / 3)); - if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ - draw_rect(dr, 0, 0, (state->width + 1) * ds->tilesize, - (state->height + 1) * ds->tilesize, COL_BACKGROUND); - draw_update(dr, 0, 0, (state->width + 1) * ds->tilesize, - (state->height + 1) * ds->tilesize); - ds->started = true; - } for (y = 0; y < state->height; y++) { for (x = 0; x < state->width; x++) { int cell = state->cells_contents[(y * state->width) + x]; diff --git a/net.c b/net.c index 5796e95..140494e 100644 --- a/net.c +++ b/net.c @@ -2054,7 +2054,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, } struct game_drawstate { - bool started; int width, height; int tilesize; unsigned long *visible, *to_draw; @@ -2441,7 +2440,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) game_drawstate *ds = snew(game_drawstate); int i, ncells; - ds->started = false; ds->width = state->width; ds->height = state->height; ncells = (state->width+2) * (state->height+2); @@ -2838,23 +2836,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int *loops; float angle = 0.0; - /* - * Clear the screen on our first call. - */ - if (!ds->started) { - int w, h; - game_params params; - - ds->started = true; - - params.width = ds->width; - params.height = ds->height; - game_compute_size(¶ms, TILE_SIZE, &w, &h); - - draw_rect(dr, 0, 0, w, h, COL_BACKGROUND); - draw_update(dr, 0, 0, w, h); - } - tx = ty = -1; last_rotate_dir = dir==-1 ? oldstate->last_rotate_dir : state->last_rotate_dir; diff --git a/netslide.c b/netslide.c index 7465d70..88d0944 100644 --- a/netslide.c +++ b/netslide.c @@ -1589,22 +1589,13 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int cur_x = -1, cur_y = -1; /* - * Clear the screen and draw the exterior barrier lines if this - * is our first call. + * Draw the exterior barrier lines if this is our first call. */ if (!ds->started) { int phase; ds->started = true; - draw_rect(dr, 0, 0, - BORDER * 2 + WINDOW_OFFSET * 2 + TILE_SIZE * state->width + TILE_BORDER, - BORDER * 2 + WINDOW_OFFSET * 2 + TILE_SIZE * state->height + TILE_BORDER, - COL_BACKGROUND); - draw_update(dr, 0, 0, - BORDER * 2 + WINDOW_OFFSET*2 + TILE_SIZE*state->width + TILE_BORDER, - BORDER * 2 + WINDOW_OFFSET*2 + TILE_SIZE*state->height + TILE_BORDER); - for (phase = 0; phase < 2; phase++) { for (x = 0; x < ds->width; x++) { diff --git a/palisade.c b/palisade.c index 317fb7b..a82a8c1 100644 --- a/palisade.c +++ b/palisade.c @@ -1174,7 +1174,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->grid) { char buf[40]; int bgw = (w+1) * ds->tilesize, bgh = (h+1) * ds->tilesize; - draw_rect(dr, 0, 0, bgw, bgh, COL_BACKGROUND); for (r = 0; r <= h; ++r) for (c = 0; c <= w; ++c) diff --git a/pattern.c b/pattern.c index b9a3d6e..278bc33 100644 --- a/pattern.c +++ b/pattern.c @@ -1805,14 +1805,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, bool cmoved; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed - * and can vary with front ends. To be on the safe side, - * all games should start by drawing a big background- - * colour rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, SIZE(ds->w), SIZE(ds->h), COL_BACKGROUND); - /* * Draw the grid outline. */ diff --git a/pearl.c b/pearl.c index 2657d45..e2abdd4 100644 --- a/pearl.c +++ b/pearl.c @@ -2458,18 +2458,9 @@ static void game_redraw(drawing *dr, game_drawstate *ds, bool force = false; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ - draw_rect(dr, 0, 0, w*TILE_SIZE + 2*BORDER, h*TILE_SIZE + 2*BORDER, - COL_BACKGROUND); - if (get_gui_style() == GUI_MASYU) { /* - * Smaller black rectangle which is the main grid. + * Black rectangle which is the main grid. */ draw_rect(dr, BORDER - BORDER_WIDTH, BORDER - BORDER_WIDTH, w*TILE_SIZE + 2*BORDER_WIDTH + 1, diff --git a/pegs.c b/pegs.c index ec12aa9..61fc38a 100644 --- a/pegs.c +++ b/pegs.c @@ -1135,10 +1135,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, } if (!ds->started) { - draw_rect(dr, 0, 0, - TILESIZE * state->w + 2 * BORDER, - TILESIZE * state->h + 2 * BORDER, COL_BACKGROUND); - /* * Draw relief marks around all the squares that aren't * GRID_OBST. diff --git a/range.c b/range.c index fc0a540..4106b15 100644 --- a/range.c +++ b/range.c @@ -1253,7 +1253,6 @@ typedef struct drawcell { struct game_drawstate { int tilesize; drawcell *grid; - bool started; }; #define TILESIZE (ds->tilesize) @@ -1655,7 +1654,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) int i; ds->tilesize = 0; - ds->started = false; ds->grid = snewn(n, drawcell); for (i = 0; i < n; ++i) @@ -1690,7 +1688,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, float animtime, float flashtime) { int const w = state->params.w, h = state->params.h, n = w * h; - int const wpx = (w+1) * ds->tilesize, hpx = (h+1) * ds->tilesize; int const flash = ((int) (flashtime * 5 / FLASH_TIME)) % 2; int r, c, i; @@ -1701,12 +1698,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, assert (oldstate == NULL); /* only happens if animating moves */ - if (!ds->started) { - ds->started = true; - draw_rect(dr, 0, 0, wpx, hpx, COL_BACKGROUND); - draw_update(dr, 0, 0, wpx, hpx); - } - for (i = r = 0; r < h; ++r) { for (c = 0; c < w; ++c, ++i) { drawcell cell = makecell(state->grid[i], errors[i], false, flash); diff --git a/rect.c b/rect.c index 3cb67bd..a262708 100644 --- a/rect.c +++ b/rect.c @@ -2793,9 +2793,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, } if (!ds->started) { - draw_rect(dr, 0, 0, - state->w * TILE_SIZE + 2*BORDER + 1, - state->h * TILE_SIZE + 2*BORDER + 1, COL_BACKGROUND); draw_rect(dr, COORD(0)-1, COORD(0)-1, ds->w*TILE_SIZE+3, ds->h*TILE_SIZE+3, COL_LINE); ds->started = true; diff --git a/samegame.c b/samegame.c index 615c60e..22b4316 100644 --- a/samegame.c +++ b/samegame.c @@ -1512,13 +1512,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILE_SIZE * state->params.w + 2 * BORDER, - TILE_SIZE * state->params.h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILE_SIZE * state->params.w + 2 * BORDER, - TILE_SIZE * state->params.h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/signpost.c b/signpost.c index d7344c8..b06b9fd 100644 --- a/signpost.c +++ b/signpost.c @@ -2081,7 +2081,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int aw = TILE_SIZE * state->w; int ah = TILE_SIZE * state->h; - draw_rect(dr, 0, 0, aw + 2 * BORDER, ah + 2 * BORDER, COL_BACKGROUND); draw_rect_outline(dr, BORDER - 1, BORDER - 1, aw + 2, ah + 2, COL_GRID); draw_update(dr, 0, 0, aw + 2 * BORDER, ah + 2 * BORDER); } diff --git a/singles.c b/singles.c index 202ce08..2440513 100644 --- a/singles.c +++ b/singles.c @@ -1708,7 +1708,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int wsz = TILE_SIZE * state->w + 2 * BORDER; int hsz = TILE_SIZE * state->h + 2 * BORDER; - draw_rect(dr, 0, 0, wsz, hsz, COL_BACKGROUND); draw_rect_outline(dr, COORD(0)-1, COORD(0)-1, TILE_SIZE * state->w + 2, TILE_SIZE * state->h + 2, COL_GRID); diff --git a/sixteen.c b/sixteen.c index d153e50..7a622a4 100644 --- a/sixteen.c +++ b/sixteen.c @@ -936,13 +936,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/slant.c b/slant.c index ed290fe..151e36f 100644 --- a/slant.c +++ b/slant.c @@ -1638,7 +1638,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, struct game_drawstate { int tilesize; - bool started; long *grid; long *todraw; }; @@ -1832,7 +1831,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) struct game_drawstate *ds = snew(struct game_drawstate); ds->tilesize = 0; - ds->started = false; ds->grid = snewn((w+2)*(h+2), long); ds->todraw = snewn((w+2)*(h+2), long); for (i = 0; i < (w+2)*(h+2); i++) @@ -1972,14 +1970,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, else flashing = false; - if (!ds->started) { - int ww, wh; - game_compute_size(&state->p, TILESIZE, &ww, &wh); - draw_rect(dr, 0, 0, ww, wh, COL_BACKGROUND); - draw_update(dr, 0, 0, ww, wh); - ds->started = true; - } - /* * Loop over the grid and work out where all the slashes are. * We need to do this because a slash in one square affects the diff --git a/solo.c b/solo.c index 49753f4..aabfe39 100644 --- a/solo.c +++ b/solo.c @@ -5174,14 +5174,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x, y; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed - * and can vary with front ends. To be on the safe side, - * all games should start by drawing a big - * background-colour rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, SIZE(cr), SIZE(cr), COL_BACKGROUND); - /* * Draw the grid. We draw it as a big thick rectangle of * COL_GRID initially; individual calls to draw_number() diff --git a/tents.c b/tents.c index ee06172..c4a7d35 100644 --- a/tents.c +++ b/tents.c @@ -1461,7 +1461,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, struct game_drawstate { int tilesize; - bool started; game_params p; int *drawn, *numbersdrawn; int cx, cy; /* last-drawn cursor pos, or (-1,-1) if absent. */ @@ -1940,7 +1939,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) int i; ds->tilesize = 0; - ds->started = false; ds->p = state->p; /* structure copy */ ds->drawn = snewn(w*h, int); for (i = 0; i < w*h; i++) @@ -2410,21 +2408,11 @@ static void int_redraw(drawing *dr, game_drawstate *ds, if (cx != ds->cx || cy != ds->cy) cmoved = true; } - if (printing || !ds->started) { - if (!printing) { - int ww, wh; - game_compute_size(&state->p, TILESIZE, &ww, &wh); - draw_rect(dr, 0, 0, ww, wh, COL_BACKGROUND); - draw_update(dr, 0, 0, ww, wh); - ds->started = true; - } - - if (printing) - print_line_width(dr, TILESIZE/64); - + if (printing) { /* * Draw the grid. */ + print_line_width(dr, TILESIZE/64); for (y = 0; y <= h; y++) draw_line(dr, COORD(0), COORD(y), COORD(w), COORD(y), COL_GRID); for (x = 0; x <= w; x++) diff --git a/towers.c b/towers.c index 13c652b..dd3a09d 100644 --- a/towers.c +++ b/towers.c @@ -1222,7 +1222,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, struct game_drawstate { int tilesize; bool three_d; /* default 3D graphics are user-disableable */ - bool started; long *tiles; /* (w+2)*(w+2) temp space */ long *drawn; /* (w+2)*(w+2)*4: current drawn data */ bool *errtmp; @@ -1615,7 +1614,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) ds->tilesize = 0; ds->three_d = !getenv("TOWERS_2D"); - ds->started = false; ds->tiles = snewn((w+2)*(w+2), long); ds->drawn = snewn((w+2)*(w+2)*4, long); for (i = 0; i < (w+2)*(w+2)*4; i++) @@ -1821,20 +1819,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int w = state->par.w /*, a = w*w */; int i, x, y; - if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all - * games should start by drawing a big background-colour - * rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, SIZE(w), SIZE(w), COL_BACKGROUND); - - draw_update(dr, 0, 0, SIZE(w), SIZE(w)); - - ds->started = true; - } - check_errors(state, ds->errtmp); /* diff --git a/tracks.c b/tracks.c index 9149c2a..ae013ac 100644 --- a/tracks.c +++ b/tracks.c @@ -2782,15 +2782,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, const game_state *oldst game_state *drag_state = NULL; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ - draw_rect(dr, 0, 0, (w+2)*TILE_SIZE + 2*BORDER, (h+2)*TILE_SIZE + 2*BORDER, - COL_BACKGROUND); - draw_loop_ends(dr, ds, state, COL_CLUE); draw_rect(dr, COORD(0) - GRID_LINE_BR, COORD(0) - GRID_LINE_BR, diff --git a/twiddle.c b/twiddle.c index 32716e5..0a4ee17 100644 --- a/twiddle.c +++ b/twiddle.c @@ -1133,13 +1133,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (!ds->started) { int coords[10]; - draw_rect(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND); - draw_update(dr, 0, 0, - TILE_SIZE * state->w + 2 * BORDER, - TILE_SIZE * state->h + 2 * BORDER); - /* * Recessed area containing the whole puzzle. */ diff --git a/undead.c b/undead.c index 4dba828..8d29be8 100644 --- a/undead.c +++ b/undead.c @@ -2605,8 +2605,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, /* Draw static grid components at startup */ if (!ds->started) { - draw_rect(dr, 0, 0, 2*BORDER+(ds->w+2)*TILESIZE, - 2*BORDER+(ds->h+3)*TILESIZE, COL_BACKGROUND); draw_rect(dr, BORDER+TILESIZE-1, BORDER+2*TILESIZE-1, (ds->w)*TILESIZE +3, (ds->h)*TILESIZE +3, COL_GRID); for (i=0;iw;i++) diff --git a/unfinished/group.c b/unfinished/group.c index 8e01857..562dcbb 100644 --- a/unfinished/group.c +++ b/unfinished/group.c @@ -2056,14 +2056,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x, y, i, j; if (!ds->started) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all - * games should start by drawing a big background-colour - * rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, SIZE(w), SIZE(w), COL_BACKGROUND); - /* * Big containing rectangle. */ diff --git a/unfinished/separate.c b/unfinished/separate.c index 39243af..daa03c7 100644 --- a/unfinished/separate.c +++ b/unfinished/separate.c @@ -778,13 +778,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int dir, const game_ui *ui, float animtime, float flashtime) { - /* - * The initial contents of the window are not guaranteed and - * can vary with front ends. To be on the safe side, all games - * should start by drawing a big background-colour rectangle - * covering the whole window. - */ - draw_rect(dr, 0, 0, 10*ds->tilesize, 10*ds->tilesize, COL_BACKGROUND); } static float game_anim_length(const game_state *oldstate, diff --git a/unfinished/slide.c b/unfinished/slide.c index 8c25340..9c26acc 100644 --- a/unfinished/slide.c +++ b/unfinished/slide.c @@ -1242,7 +1242,6 @@ struct game_drawstate { int tilesize; int w, h; unsigned long *grid; /* what's currently displayed */ - bool started; }; static char *interpret_move(const game_state *state, game_ui *ui, @@ -1680,7 +1679,6 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) ds->tilesize = 0; ds->w = w; ds->h = h; - ds->started = false; ds->grid = snewn(wh, unsigned long); for (i = 0; i < wh; i++) ds->grid[i] = ~(unsigned long)0; @@ -2129,17 +2127,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int *dsf; int x, y, mainanchor, mainpos, dragpos, solvepos, solvesrc, solvedst; - if (!ds->started) { - /* - * The initial contents of the window are not guaranteed - * and can vary with front ends. To be on the safe side, - * all games should start by drawing a big - * background-colour rectangle covering the whole window. - */ - draw_rect(dr, 0, 0, 10*ds->tilesize, 10*ds->tilesize, COL_BACKGROUND); - ds->started = true; - } - /* * Construct the board we'll be displaying (which may be * different from the one in state if ui describes a drag in diff --git a/unfinished/sokoban.c b/unfinished/sokoban.c index ecc222c..4f37085 100644 --- a/unfinished/sokoban.c +++ b/unfinished/sokoban.c @@ -1353,15 +1353,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, * Initialise a fresh drawstate. */ if (!ds->started) { - int wid, ht; - - /* - * Blank out the window initially. - */ - game_compute_size(&ds->p, TILESIZE, &wid, &ht); - draw_rect(dr, 0, 0, wid, ht, COL_BACKGROUND); - draw_update(dr, 0, 0, wid, ht); - /* * Draw the grid lines. */ diff --git a/unruly.c b/unruly.c index a1f0633..3e5463f 100644 --- a/unruly.c +++ b/unruly.c @@ -1788,9 +1788,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, int x, y, i; if (!ds->started) { - /* Main window background */ - draw_rect(dr, 0, 0, TILE_SIZE * (w2+1), TILE_SIZE * (h2+1), - COL_BACKGROUND); /* Outer edge of grid */ draw_rect(dr, COORD(0)-TILE_SIZE/10, COORD(0)-TILE_SIZE/10, TILE_SIZE*w2 + 2*(TILE_SIZE/10) - 1,