From 881746789a489fad85aae8317555f73dbe261556 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sat, 29 Apr 2017 18:21:56 -0400 Subject: puzzles: refactor and resync with upstream This brings puzzles up-to-date with upstream revision 2d333750272c3967cfd5cd3677572cddeaad5932, though certain changes made by me, including cursor-only Untangle and some compilation fixes remain. Upstream code has been moved to its separate subdirectory and future syncs can be done by simply copying over the new sources. Change-Id: Ia6506ca5f78c3627165ea6791d38db414ace0804 --- apps/plugins/puzzles/src/emccpre.js | 359 ++++++++++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 apps/plugins/puzzles/src/emccpre.js (limited to 'apps/plugins/puzzles/src/emccpre.js') diff --git a/apps/plugins/puzzles/src/emccpre.js b/apps/plugins/puzzles/src/emccpre.js new file mode 100644 index 0000000000..d715858883 --- /dev/null +++ b/apps/plugins/puzzles/src/emccpre.js @@ -0,0 +1,359 @@ +/* + * emccpre.js: one of the Javascript components of an Emscripten-based + * web/Javascript front end for Puzzles. + * + * The other parts of this system live in emcc.c and emcclib.js. It + * also depends on being run in the context of a web page containing + * an appropriate collection of bits and pieces (a canvas, some + * buttons and links etc), which is generated for each puzzle by the + * script html/jspage.pl. + * + * This file contains the Javascript code which is prefixed unmodified + * to Emscripten's output via the --pre-js option. It declares all our + * global variables, and provides the puzzle init function and a + * couple of other helper functions. + */ + +// To avoid flicker while doing complicated drawing, we use two +// canvases, the same size. One is actually on the web page, and the +// other is off-screen. We do all our drawing on the off-screen one +// first, and then copy rectangles of it to the on-screen canvas in +// response to draw_update() calls by the game backend. +var onscreen_canvas, offscreen_canvas; + +// A persistent drawing context for the offscreen canvas, to save +// constructing one per individual graphics operation. +var ctx; + +// Bounding rectangle for the copy to the onscreen canvas that will be +// done at drawing end time. Updated by js_canvas_draw_update and used +// by js_canvas_end_draw. +var update_xmin, update_xmax, update_ymin, update_ymax; + +// Module object for Emscripten. We fill in these parameters to ensure +// that Module.run() won't be called until we're ready (we want to do +// our own init stuff first), and that when main() returns nothing +// will get cleaned up so we remain able to call the puzzle's various +// callbacks. +var Module = { + 'noInitialRun': true, + 'noExitRuntime': true +}; + +// Variables used by js_canvas_find_font_midpoint(). +var midpoint_test_str = "ABCDEFGHIKLMNOPRSTUVWXYZ0123456789"; +var midpoint_cache = []; + +// Variables used by js_activate_timer() and js_deactivate_timer(). +var timer = null; +var timer_reference_date; + +// void timer_callback(double tplus); +// +// Called every 20ms while timing is active. +var timer_callback; + +// The status bar object, if we create one. +var statusbar = null; + +// Currently live blitters. We keep an integer id for each one on the +// JS side; the C side, which expects a blitter to look like a struct, +// simply defines the struct to contain that integer id. +var blittercount = 0; +var blitters = []; + +// State for the dialog-box mechanism. dlg_dimmer and dlg_form are the +// page-darkening overlay and the actual dialog box respectively; +// dlg_next_id is used to allocate each checkbox a unique id to use +// for linking its label to it (see js_dialog_boolean); +// dlg_return_funcs is a list of JS functions to be called when the OK +// button is pressed, to pass the results back to C. +var dlg_dimmer = null, dlg_form = null; +var dlg_next_id = 0; +var dlg_return_funcs = null; + +// void dlg_return_sval(int index, const char *val); +// void dlg_return_ival(int index, int val); +// +// C-side entry points called by functions in dlg_return_funcs, to +// pass back the final value in each dialog control. +var dlg_return_sval, dlg_return_ival; + +// The