//"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.
mergeInto(LibraryManager.library, {
$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,
keyCodes: { // DOM code ==> SDL code
38: 1106, // up arrow
40: 1105, // down arrow
37: 1104, // left arrow
39: 1103, // right arrow
17: 305, // control (right, or left)
18: 308, // alt
109: 45, // minus
16: 304 // shift
},
scanCodes: { // SDL keycode ==> SDL scancode
97: 4, // A
98: 5,
99: 6,
100: 7,
101: 8,
102: 9,
103: 10,
104: 11,
105: 12,
106: 13,
107: 14,
108: 15,
109: 16,
110: 17,
111: 18,
112: 19,
113: 20,
114: 21,
115: 22,
116: 23,
117: 24,
118: 25,
119: 26,
120: 27,
121: 28,
122: 29, // Z
48: 30, // 0
49: 31,
50: 32,
51: 33,
52: 34,
53: 35,
54: 36,
55: 37,
56: 38,
57: 39, // 9
13: 40, // return
9: 43, // tab
32: 44, // space
92: 49, // backslash
47: 56, // slash
1106: 82, // up arrow
1105: 81, // down arrow
1104: 80, // left arrow
1103: 79 // right arrow
},
structs: {
Rect: Runtime.generateStructInfo([
['i32', 'x'], ['i32', 'y'], ['i32', 'w'], ['i32', 'h'],
]),
PixelFormat: Runtime.generateStructInfo([
['i32', 'format'],
['void*', 'palette'], ['i8', 'BitsPerPixel'], ['i8', 'BytesPerPixel'],
['i8', 'padding1'], ['i8', 'padding2'],
['i32', 'Rmask'], ['i32', 'Gmask'], ['i32', 'Bmask'], ['i32', 'Amask'],
['i8', 'Rloss'], ['i8', 'Gloss'], ['i8', 'Bloss'], ['i8', 'Aloss'],
['i8', 'Rshift'], ['i8', 'Gshift'], ['i8', 'Bshift'], ['i8', 'Ashift']
]),
KeyboardEvent: Runtime.generateStructInfo([
['i32', 'type'],
['i32', 'windowID'],
['i8', 'state'],
['i8', 'repeat'],
['i8', 'padding2'],
[