/* * 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. * * 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