simon-git: puzzles (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Sep 30 16:40:47 BST 2017


TL;DR:
  84d3fd2 Net: rewrite the drawing code for better scalability.

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: master
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2017-09-30 16:40:47

commit 84d3fd2bd8d3bd5db8cf61a134a4601307b9b7ea
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=84d3fd2bd8d3bd5db8cf61a134a4601307b9b7ea;hp=3aa4516a680f52e2e6c8a16234a7ecca0ec77233
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Sep 30 16:40:18 2017 +0100

    Net: rewrite the drawing code for better scalability.
    
    Previously, the network, grid edges and barriers were all drawn with
    fixed line thickness of one pixel, or three pixels in the case of
    wires (one central one in a lit-up colour and a black border pixel on
    each side). This worked badly on high-DPI displays, or in any other
    environment where you expand the window noticeably.
    
    I've tried a few times before to fix this, but the problem was always
    that the Net drawing code was complicated and confusing, because Net
    was one of the founding puzzles in this collection and its drawing
    code predated a lot of the sensible organisation and best-practice
    doctrines I've come up with since then and used in the later puzzles.
    (The best example of this was the way that redrawing a grid square
    always redrew _all_ the surrounding borders, which is very confusing
    in the light of my later practice of dividing up the grid into
    disjoint regions that are always redrawn with clipping.) It was hard
    to make any change to the Net graphics with the code in that state; I
    tried several times and decided I couldn't sensibly make it work
    without throwing it all away and rewriting from scratch, which I was
    always reluctant to do.
    
    But not any more! Since Ian sent some patches to improve the graphics
    scaling in Tracks, and since Net was at the top of my personal
    wishlist of games that needed the same treatment, I've decided it's
    time to do just that.
    
    So, this commit throws out all of Net's previous redraw code, and
    replaces it with something in the more modern style I usually adopt in
    new puzzles. The new draw_tile() doesn't read data out of the game
    state willy-nilly; instead it takes a single word of bit-flags
    describing everything about the tile it's drawing, and makes all its
    decisions based on that word. And the main redraw loop constructs a
    whole array of flags words describing what it would _like_ the grid to
    look like, and then calls draw_tile() for every square whose word
    doesn't match the one that was previously drawn there. (With the one
    exception that the presence of the TILE_ROTATING flag in either the
    old or new word forces a redraw _even_ if the two words are identical,
    because that's how the move animation works.)
    
    The new graphics look more or less the same at the default resolution
    (there may be a pixel difference here or there but I don't think it's
    noticeable if so), but now they scale up properly if you enlarge or
    maximise the puzzle window.

 net.c | 704 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 349 insertions(+), 355 deletions(-)



More information about the tartarus-commits mailing list