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.
This commit is contained in:
Ben Harris
2023-07-29 16:06:19 +01:00
parent 3e7a6adce5
commit 76da6ec140
3 changed files with 40 additions and 54 deletions

View File

@ -41,6 +41,10 @@ var ctx;
// by js_canvas_end_draw.
var update_xmin, update_xmax, update_ymin, update_ymax;
// Colour strings to use when drawing, to save converting them from C
// every time.
var colours = [];
// Module object for Emscripten. We fill in these parameters to ensure
// that when main() returns nothing will get cleaned up so we remain
// able to call the puzzle's various callbacks.