simon-git: puzzles (main): Ben Harris

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sun Jul 30 11:52:52 BST 2023


TL;DR:
  76da6ec js: keep colour strings in JavaScript rather than in C
  58511aa Same Game: more efficient tile_redraw

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer:      Ben Harris <bjh21 at bjh21.me.uk>
Date:           2023-07-30 11:52:52

commit 76da6ec140cbbdac6136469ce50aab40e218f398
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=76da6ec140cbbdac6136469ce50aab40e218f398;hp=3e7a6adce5887db04d26438da64fdc4de308f4da
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date:   Sat Jul 29 16:06:19 2023 +0100

    js: keep colour strings in JavaScript rather than in C
    
    The drawing routines in JavaScript used to take pointers to a C string
    containing a CSS colour name.  That meant that JavaScript had to create
    a new JavaScript string on ever call to a drawing function, which seemed
    ugly.
    
    So now we instead pass colour numbers all the way down into JavaScript
    and keep an array of JavaScript strings there that can be re-used.  The
    conversion from RGB triples to strings is still done in C, though.
    
    This doesn't seem to have fixed either of the bugs I hoped it would, but
    it does measurably improve drawing performance so I think it's worth
    doing.

 emcc.c     | 44 ++++++++++++++------------------------------
 emcclib.js | 46 ++++++++++++++++++++++------------------------
 emccpre.js |  4 ++++
 3 files changed, 40 insertions(+), 54 deletions(-)

commit 58511aa009c672cc2ade783d537a5830806fd02c
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=58511aa009c672cc2ade783d537a5830806fd02c;hp=76da6ec140cbbdac6136469ce50aab40e218f398
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date:   Sun Jul 30 11:30:19 2023 +0100

    Same Game: more efficient tile_redraw
    
    I've rewritten tile_redraw to reduce the number of calls to
    draw_rect().  Before, it would generally make five calls to
    draw_rect() when drawing a tile.  Now it makes at most three, and
    usually two.  That's one draw_rect() for each colour that appears in
    the tile, which is as good as it can get.  This reduces the time to
    draw a large puzzle by about 35% on Firefox 102.
    
    This is of significance to me because CanvasRenderingContext2D on my
    test KaiOS device seems to have a limit on the number of fill() and
    fillRect() calls that it will tolerate in a short time.  This means
    that if you issue more than 1024 fillRect() calls in rapid succession,
    the later ones are simply ignored.
    
    Same Game's largest preset called draw_rect() so much that it hit this
    limit.  That meant that the right-hand side of the grid didn't get
    properly drawn when starting a new game.  Now that it is less
    profligate with draw_rect() it fits comfortably within the limit and I
    get to see the entire grid.

 samegame.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)



More information about the tartarus-commits mailing list