//"use strict";
// To use emscripten's SDL library here, you need to define
// Module.canvas.
//
// More specifically, our SDL implementation will look for
// Module.canvas. You should fill it using something like
//
// function onLoad() {
// // Pass canvas and context to the generated code
// Module.canvas = document.getElementById('canvas');
// }
//
// Note that this must be called during onload, since you will
// only be able to access the canvas element in the page after
// it loads. You will likely also want to disable running by
// default, with something like
//
// var Module = {
// noInitialRun: true
// };
//
// which is defined BEFORE you load the compiled code.
// The test_emcc test in the tests/runner.py will test this
// in its last phase, where it generates HTML. You can see
// a concrete example there. The HTML source is in src/shell.html.
// Here is a more comprehensive example:
/*
<html>
<head>
<title>Demo</title>
<script type='text/javascript'>
var Module = {
noInitialRun: true
};
// implement print
var print = function(text) {
var element = document.getElementById('output')
element.innerHTML = text.replace('\n', '<br>', 'g') + element.innerHTML;
}
</script>
<script src='doom.ccsimple.js' type='text/javascript'></script>
<script type='text/javascript'>
function onLoad() {
// Pass canvas and context to the generated code, and do the actual run() here
Module.canvas = document.getElementById('canvas');
Module.run();
}
</script>
<body onload='onLoad()' style='background-color: black; color: white'>
<center>
<canvas id='canvas' width='320' height='200'></canvas>
</center>
<div id='output'></div>
</body>
</html>
*/
// Other stuff to take into account:
//
// * Make sure alpha values are proper in your input. If they are all 0, everything will be transparent!
//
// * Your code should not write a 32-bit value and expect that to set an RGBA pixel.
// The reason is that that data will be read as 8-bit values, and according to the
// load-store consistency assumption, it should be written that way (see docs/paper.pdf).
// Instead, do something like *ptr++ = R; *ptr++ = G; *ptr++ = B;
//
// * A normal C++ main loop with SDL_Delay will not work in JavaScript - there is no way
// to wait for a short time without locking up the web page entirely. The simplest
// solution here is to have a singleIteration() function which is a single loop
// iteration, and from JS to do something like setInterval(_singleIteration, 1/30)
//
// * SDL_Quit does nothing.
var LibrarySDL = {
$SDL__deps: ['$FS', '$Browser'],
$SDL: {
defaults: {
width: 320,
height: 200,
copyOnLock: true
},
version: null,
surfaces: {},
events: [],
audios: [null],
fonts: [null],
keyboardState: null,
startTime: null,
mouseX: 0,
mouseY: 0,
DOMEventToSDLEvent: {
'keydown': 0x300,
'keyup': 0x301,
'mousedown': 0x401,
'mouseup': 0x402,
'mousemove': 0x400
},
keyCodes: { // DOM code ==> SDL code. See https://developer.mozilla.org/en/Document_Object_Model_%28DOM%29/KeyboardEvent and SDL_keycode.h
38: 1106, // up arrow
40: 1105, // down arrow
37: 1104, // left arrow
39: 1103, // right arrow
33: 1099, // pagedup
34: 1102, // pagedown
17: 305, // control (right, or left)
18: 308, // alt
109: 45, // minus
16: 304, // shift
96: 88 | 1<<10, // keypad 0
97: 89 | 1<<10, // keypad 1
98: 90 | 1<<10, // keypad 2
99: 91 | 1<<10, // keypad 3
100: 92 | 1<<10, // keypad 4
101: 93 | 1<<10, // keypad 5
102: 94 | 1<<10, // keypad 6
103: 95 | 1<<10, // keypad 7
104: 96 | 1<<10, // keypad 8
105: 97 | 1<<10, // keypad 9
112: 58 | 1<<10, // F1
113: 59 | 1<<10, // F2
114: 60 | 1<<10, // F3
115: 61 | 1<<10, // F4
116: 62 | 1<<10, // F5
117: 63 | 1<<10, // F6
118: 64 | 1<<10, // F7
119: 65 | 1<<10, // F8
120: 66 | 1<<10, // F9
121: 67 | 1<<10, // F10
122: 68 | 1<<10