From 1a6a8b52f7aa4e2da6f4c34a0c743c760b8cfd99 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sun, 20 Nov 2016 15:16:41 -0500 Subject: Port of Simon Tatham's Puzzle Collection Original revision: 5123b1bf68777ffa86e651f178046b26a87cf2d9 MIT Licensed. Some games still crash and others are unplayable due to issues with controls. Still need a "real" polygon filling algorithm. Currently builds one plugin per puzzle (about 40 in total, around 100K each on ARM), but can easily be made to build a single monolithic overlay (800K or so on ARM). The following games are at least partially broken for various reasons, and have been disabled on this commit: Cube: failed assertion with "Icosahedron" setting Keen: input issues Mines: weird stuff happens on target Palisade: input issues Solo: input issues, occasional crash on target Towers: input issues Undead: input issues Unequal: input and drawing issues (concave polys) Untangle: input issues Features left to do: - In-game help system - Figure out the weird bugs Change-Id: I7c69b6860ab115f973c8d76799502e9bb3d52368 --- apps/plugins/puzzles/emccpre.js | 364 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 apps/plugins/puzzles/emccpre.js (limited to 'apps/plugins/puzzles/emccpre.js') diff --git a/apps/plugins/puzzles/emccpre.js b/apps/plugins/puzzles/emccpre.js new file mode 100644 index 0000000000..ebf67d1fc6 --- /dev/null +++ b/apps/plugins/puzzles/emccpre.js @@ -0,0 +1,364 @@ +/* + * 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