aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js3
-rw-r--r--src/library_gl.js6
-rw-r--r--src/library_html5.js1257
-rw-r--r--src/library_openal.js306
-rw-r--r--src/modules.js2
-rw-r--r--src/relooper/Relooper.cpp26
-rw-r--r--src/shell.html43
-rw-r--r--src/struct_info.json185
8 files changed, 1777 insertions, 51 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 726a5eda..f4819584 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1844,7 +1844,7 @@ function JSify(data, functionsOnly) {
// rest of the output that we started to print out earlier (see comment on the
// "Final shape that will be created").
if (PRECISE_I64_MATH && Types.preciseI64MathUsed) {
- if (!INCLUDE_FULL_LIBRARY) {
+ if (!INCLUDE_FULL_LIBRARY && !SIDE_MODULE) {
// first row are utilities called from generated code, second are needed from fastLong
['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr',
'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) {
@@ -1866,6 +1866,7 @@ function JSify(data, functionsOnly) {
}
});
}
+ // these may be duplicated in side modules and the main module without issue
print(read('fastLong.js'));
print('// EMSCRIPTEN_END_FUNCS\n');
print(read('long.js'));
diff --git a/src/library_gl.js b/src/library_gl.js
index 3055309b..0a30292a 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -957,7 +957,11 @@ var LibraryGL = {
usage = 0x88E8; // GL_DYNAMIC_DRAW
break;
}
- GLctx.bufferData(target, HEAPU8.subarray(data, data+size), usage);
+ if (!data) {
+ GLctx.bufferData(target, size, usage);
+ } else {
+ GLctx.bufferData(target, HEAPU8.subarray(data, data+size), usage);
+ }
},
glBufferSubData__sig: 'viiii',
diff --git a/src/library_html5.js b/src/library_html5.js
new file mode 100644
index 00000000..703f9a74
--- /dev/null
+++ b/src/library_html5.js
@@ -0,0 +1,1257 @@
+var LibraryJSEvents = {
+ $JSEvents: {
+ // pointers to structs malloc()ed to Emscripten HEAP for JS->C interop.
+ keyEvent: 0,
+ mouseEvent: 0,
+ wheelEvent: 0,
+ uiEvent: 0,
+ focusEvent: 0,
+ deviceOrientationEvent: 0,
+ deviceMotionEvent: 0,
+ fullscreenChangeEvent: 0,
+ pointerlockChangeEvent: 0,
+ visibilityChangeEvent: 0,
+ touchEvent: 0,
+
+ // When the C runtime exits via exit(), we unregister all event handlers added by this library to be nice and clean.
+ // Track in this field whether we have yet registered that __ATEXIT__ handler.
+ removeEventListenersRegistered: false,
+
+ registerRemoveEventListeners: function() {
+ if (!JSEvents.removeEventListenersRegistered) {
+ __ATEXIT__.push({ func: function() {
+ for(var i = JSEvents.eventHandlers.length-1; i >= 0; --i) {
+ JSEvents._removeHandler(i);
+ }
+ } });
+ JSEvents.removeEventListenersRegistered = true;
+ }
+ },
+
+ findEventTarget: function(target) {
+ if (target) {
+ if (typeof target == "number") {
+ target = Pointer_stringify(target);
+ }
+ if (target == '#window') return window;
+ else if (target == '#document') return document;
+ else if (target == '#screen') return window.screen;
+ else if (target == '#canvas') return Module['canvas'];
+
+ if (typeof target == 'string') return document.getElementById(target);
+ else return target;
+ } else {
+ // The sensible target varies between events, but use window as the default
+ // since DOM events mostly can default to that. Specific callback registrations
+ // override their own defaults.
+ return window;
+ }
+ },
+
+ deferredCalls: [],
+
+ // Queues the given function call to occur the next time we enter an event handler.
+ // Existing implementations of pointerlock apis have required that
+ // the target element is active in fullscreen mode first. Thefefore give
+ // fullscreen mode request a precedence of 1 and pointer lock a precedence of 2
+ // and sort by that to always request fullscreen before pointer lock.
+ deferCall: function(targetFunction, precedence, argsList) {
+ function arraysHaveEqualContent(arrA, arrB) {
+ if (arrA.length != arrB.length) return false;
+
+ for(var i in arrA) {
+ if (arrA[i] != arrB[i]) return false;
+ }
+ return true;
+ }
+ // Test if the given call was already queued, and if so, don't add it again.
+ for(var i in JSEvents.deferredCalls) {
+ var call = JSEvents.deferredCalls[i];
+ if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) {
+ return;
+ }
+ }
+ JSEvents.deferredCalls.push({
+ targetFunction: targetFunction,
+ precedence: precedence,
+ argsList: argsList
+ });
+
+ JSEvents.deferredCalls.sort(function(x,y) { return x.precedence < y.precedence; });
+ },
+
+ // Erases all deferred calls to the given target function from the queue list.
+ removeDeferredCalls: function(targetFunction) {
+ for(var i = 0; i < JSEvents.deferredCalls.length; ++i) {
+ if (JSEvents.deferredCalls[i].targetFunction == targetFunction) {
+ JSEvents.deferredCalls.splice(i, 1);
+ --i;
+ }
+ }
+ },
+
+ canPerformEventHandlerRequests: function() {
+ return JSEvents.inEventHandler && JSEvents.currentEventHandler.allowsDeferredCalls;
+ },
+
+ runDeferredCalls: function() {
+ if (!JSEvents.canPerformEventHandlerRequests()) {
+ return;
+ }
+ for(var i = 0; i < JSEvents.deferredCalls.length; ++i) {
+ var call = JSEvents.deferredCalls[i];
+ JSEvents.deferredCalls.splice(i, 1);
+ --i;
+ call.targetFunction.apply(this, call.argsList);
+ }
+ },
+
+ // If positive, we are currently executing in a JS event handler.
+ inEventHandler: 0,
+ // If we are in an event handler, specifies the event handler object from the eventHandlers array that is currently running.
+ currentEventHandler: null,
+
+ // Stores objects representing each currently registered JS event handler.
+ eventHandlers: [],
+
+ _removeHandler: function(i) {
+ JSEvents.eventHandlers[i].target.removeEventListener(JSEvents.eventHandlers[i].eventTypeString, JSEvents.eventHandlers[i].handlerFunc, true);
+ JSEvents.eventHandlers.splice(i, 1);
+ },
+
+ registerOrRemoveHandler: function(eventHandler) {
+ var jsEventHandler = function jsEventHandler(event) {
+ // Increment nesting count for the event handler.
+ ++JSEvents.inEventHandler;
+ JSEvents.currentEventHandler = eventHandler;
+ // Process any old deferred calls the user has placed.
+ JSEvents.runDeferredCalls();
+ // Process the actual event, calls back to user C code handler.
+ eventHandler.handlerFunc(event);
+ // Process any new deferred calls that were placed right now from this event handler.
+ JSEvents.runDeferredCalls();
+ // Out of event handler - restore nesting count.
+ --JSEvents.inEventHandler;
+ }
+
+ if (eventHandler.callbackfunc) {
+ eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, eventHandler.useCapture);
+ JSEvents.eventHandlers.push(eventHandler);
+ JSEvents.registerRemoveEventListeners();
+ } else {
+ for(var i = 0; i < JSEvents.eventHandlers.length; ++i) {
+ if (JSEvents.eventHandlers[i].target == eventHandler.target
+ && JSEvents.eventHandlers[i].eventTypeString == eventHandler.eventTypeString) {
+ JSEvents._removeHandler(i--);
+ }
+ }
+ }
+ },
+
+ registerKeyEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.keyEvent) {
+ JSEvents.keyEvent = _malloc( {{{ C_STRUCTS.EmscriptenKeyboardEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+ writeStringToMemory(e.key ? e.key : "", JSEvents.keyEvent + {{{ C_STRUCTS.EmscriptenKeyboardEvent.key }}} );
+ writeStringToMemory(e.code ? e.code : "", JSEvents.keyEvent + {{{ C_STRUCTS.EmscriptenKeyboardEvent.code }}} );
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.location, 'e.location', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.ctrlKey, 'e.ctrlKey', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.shiftKey, 'e.shiftKey', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.altKey, 'e.altKey', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.metaKey, 'e.metaKey', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.repeat, 'e.repeat', 'i32') }}}
+ writeStringToMemory(e.locale ? e.locale : "", JSEvents.keyEvent + {{{ C_STRUCTS.EmscriptenKeyboardEvent.locale }}} );
+ writeStringToMemory(e.char ? e.char : "", JSEvents.keyEvent + {{{ C_STRUCTS.EmscriptenKeyboardEvent.charValue }}} );
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.charCode, 'e.charCode', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.keyCode, 'e.keyCode', 'i32') }}}
+ {{{ makeSetValue('JSEvents.keyEvent', C_STRUCTS.EmscriptenKeyboardEvent.which, 'e.which', 'i32') }}}
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.keyEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var isInternetExplorer = (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0);
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: isInternetExplorer ? false : true, // MSIE doesn't allow fullscreen and pointerlock requests from key handlers, others do.
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ fillMouseEventData: function(eventStruct, e) {
+ var rect = Module['canvas'].getBoundingClientRect();
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.timestamp, 'JSEvents.tick()', 'double') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.screenX, 'e.screenX', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.screenY, 'e.screenY', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.clientX, 'e.clientX', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.clientY, 'e.clientY', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.ctrlKey, 'e.ctrlKey', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.shiftKey, 'e.shiftKey', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.altKey, 'e.altKey', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.metaKey, 'e.metaKey', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.button, 'e.button', 'i16') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.buttons, 'e.buttons', 'i16') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.movementX, 'e.movementX', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.movementY, 'e.movementY', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.canvasX, 'e.clientX - rect.left', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.canvasY, 'e.clientY - rect.top', 'i32') }}}
+ },
+
+ registerMouseEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.mouseEvent) {
+ JSEvents.mouseEvent = _malloc( {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+ JSEvents.fillMouseEventData(JSEvents.mouseEvent, e);
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.mouseEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: eventTypeString != 'mousemove', // Mouse move events do not allow fullscreen/pointer lock requests to be handled in them!
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ registerWheelEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.wheelEvent) {
+ JSEvents.wheelEvent = _malloc( {{{ C_STRUCTS.EmscriptenWheelEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+ JSEvents.fillMouseEventData(JSEvents.wheelEvent, e);
+ {{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaX, 'e.deltaX', 'double') }}}
+ {{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaY, 'e.deltaY', 'double') }}}
+ {{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaZ, 'e.deltaZ', 'double') }}}
+ {{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaMode, 'e.deltaMode', 'i32') }}}
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.wheelEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: true,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ pageScrollPos: function() {
+ if (window.pageXOffset > 0 || window.pageYOffset > 0) {
+ return [window.pageXOffset, window.pageYOffset];
+ }
+ if (typeof document.documentElement.scrollLeft !== 'undefined' || typeof document.documentElement.scrollTop !== 'undefined') {
+ return [document.documentElement.scrollLeft, document.documentElement.scrollTop];
+ }
+ return [document.body.scrollLeft|0, document.body.scrollTop|0];
+ },
+
+ registerUiEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.uiEvent) {
+ JSEvents.uiEvent = _malloc( {{{ C_STRUCTS.EmscriptenUiEvent.__size__ }}} );
+ }
+
+ if (eventTypeString == "scroll" && !target) {
+ target = document; // By default read scroll events on document rather than window.
+ } else {
+ target = JSEvents.findEventTarget(target);
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+ if (e.target != target) {
+ // Never take ui events such as scroll via a 'bubbled' route, but always from the direct element that
+ // was targeted. Otherwise e.g. if app logs a message in response to a page scroll, the Emscripten log
+ // message box could cause to scroll, generating a new (bubbled) scroll message, causing a new log print,
+ // causing a new scroll, etc..
+ return;
+ }
+ var scrollPos = JSEvents.pageScrollPos();
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.detail, 'e.detail', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.documentBodyClientWidth, 'document.body.clientWidth', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.documentBodyClientHeight, 'document.body.clientHeight', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.windowInnerWidth, 'window.innerWidth', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.windowInnerHeight, 'window.innerHeight', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.windowOuterWidth, 'window.outerWidth', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.windowOuterHeight, 'window.outerHeight', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.scrollTop, 'scrollPos[0]', 'i32') }}}
+ {{{ makeSetValue('JSEvents.uiEvent', C_STRUCTS.EmscriptenUiEvent.scrollLeft, 'scrollPos[1]', 'i32') }}}
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.uiEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: target,
+ allowsDeferredCalls: false, // Neither scroll or resize events allow running requests inside them.
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ getNodeNameForTarget: function(target) {
+ if (!target) return '';
+ if (target == window) return '#window';
+ if (target == window.screen) return '#screen';
+ return (target && target.nodeName) ? target.nodeName : '';
+ },
+
+ registerFocusEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.focusEvent) {
+ JSEvents.focusEvent = _malloc( {{{ C_STRUCTS.EmscriptenFocusEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ var nodeName = JSEvents.getNodeNameForTarget(e.target);
+ var id = e.target.id ? e.target.id : '';
+ writeStringToMemory(nodeName, JSEvents.focusEvent + {{{ C_STRUCTS.EmscriptenFocusEvent.nodeName }}} );
+ writeStringToMemory(id, JSEvents.focusEvent + {{{ C_STRUCTS.EmscriptenFocusEvent.id }}} );
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.focusEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ tick: function() {
+ if (window['performance'] && window['performance']['now']) return window['performance']['now']();
+ else return Date.now();
+ },
+
+ registerDeviceOrientationEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.deviceOrientationEvent) {
+ JSEvents.deviceOrientationEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceOrientationEvent.timestamp, 'JSEvents.tick()', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceOrientationEvent.alpha, 'e.alpha', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceOrientationEvent.beta, 'e.beta', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceOrientationEvent.gamma, 'e.gamma', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceOrientationEvent.absolute, 'e.absolute', 'i32') }}}
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.deviceOrientationEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ registerDeviceMotionEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.deviceMotionEvent) {
+ JSEvents.deviceMotionEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}} );
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ {{{ makeSetValue('JSEvents.deviceOrientationEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.timestamp, 'JSEvents.tick()', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationX, 'e.acceleration.x', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationY, 'e.acceleration.y', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationZ, 'e.acceleration.z', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationIncludingGravityX, 'e.accelerationIncludingGravity.x', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationIncludingGravityY, 'e.accelerationIncludingGravity.y', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.accelerationIncludingGravityZ, 'e.accelerationIncludingGravity.z', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.rotationRateAlpha, 'e.rotationRate.alpha', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.rotationRateBeta, 'e.rotationRate.beta', 'double') }}}
+ {{{ makeSetValue('JSEvents.deviceMotionEvent', C_STRUCTS.EmscriptenDeviceMotionEvent.rotationRateGamma, 'e.rotationRate.gamma', 'double') }}}
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.deviceMotionEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ screenOrientation: function() {
+ if (!window.screen) return undefined;
+ return window.screen.orientation || window.screen.mozOrientation || window.screen.webkitOrientation || window.screen.msOrientation;
+ },
+
+ fillOrientationChangeEventData: function(eventStruct, e) {
+ var orientations = ["portrait-primary", "portrait-secondary", "landscape-primary", "landscape-secondary"];
+ var orientations2 = ["portrait", "portrait", "landscape", "landscape"];
+
+ var orientationString = JSEvents.screenOrientation();
+ var orientation = orientations.indexOf(orientationString);
+ if (orientation == -1) {
+ orientation = orientations2.indexOf(orientationString);
+ }
+
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenOrientationChangeEvent.orientationIndex, '1 << orientation', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenOrientationChangeEvent.orientationAngle, 'window.orientation', 'i32') }}}
+ },
+
+ registerOrientationChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.orientationChangeEvent) {
+ JSEvents.orientationChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenOrientationChangeEvent.__size__ }}} );
+ }
+
+ if (!target) {
+ target = window.screen; // Orientation events need to be captured from 'window.screen' instead of 'window'
+ } else {
+ target = JSEvents.findEventTarget(target);
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillOrientationChangeEventData(JSEvents.orientationChangeEvent, e);
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.orientationChangeEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ if (eventTypeString == "orientationchange" && window.screen.mozOrientation !== undefined) {
+ eventTypeString = "mozorientationchange";
+ }
+
+ var eventHandler = {
+ target: target,
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ fullscreenEnabled: function() {
+ return document.fullscreenEnabled || document.mozFullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled;
+ },
+
+ fillFullscreenChangeEventData: function(eventStruct, e) {
+ var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
+ var isFullscreen = !!fullscreenElement;
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenFullscreenChangeEvent.isFullscreen, 'isFullscreen', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenFullscreenChangeEvent.fullscreenEnabled, 'JSEvents.fullscreenEnabled()', 'i32') }}}
+ var nodeName = JSEvents.getNodeNameForTarget(fullscreenElement);
+ var id = (fullscreenElement && fullscreenElement.id) ? fullscreenElement.id : '';
+ writeStringToMemory(nodeName, eventStruct + {{{ C_STRUCTS.EmscriptenFullscreenChangeEvent.nodeName }}} );
+ writeStringToMemory(id, eventStruct + {{{ C_STRUCTS.EmscriptenFullscreenChangeEvent.id }}} );
+ },
+
+ registerFullscreenChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.fullscreenChangeEvent) {
+ JSEvents.fullscreenChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenFullscreenChangeEvent.__size__ }}} );
+ }
+
+ if (!target) {
+ target = document; // Fullscreen change events need to be captured from 'document' by default instead of 'window'
+ } else {
+ target = JSEvents.findEventTarget(target);
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillFullscreenChangeEventData(JSEvents.fullscreenChangeEvent, e);
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.fullscreenChangeEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: target,
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ requestFullscreen: function(target) {
+ if (target.requestFullscreen) {
+ target.requestFullscreen();
+ } else if (target.msRequestFullscreen) {
+ target.msRequestFullscreen();
+ } else if (target.mozRequestFullScreen) {
+ target.mozRequestFullScreen();
+ } else if (target.mozRequestFullscreen) {
+ target.mozRequestFullscreen();
+ } else if (target.webkitRequestFullscreen) {
+ target.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
+ } else {
+ if (typeof JSEvents.fullscreenEnabled() === 'undefined') {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_INVALID_TARGET') }}};
+ }
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ fillPointerlockChangeEventData: function(eventStruct, e) {
+ var pointerLockElement = document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement || document.msPointerLockElement;
+ var isPointerlocked = !!pointerLockElement;
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenPointerlockChangeEvent.isActive, 'isPointerlocked', 'i32') }}}
+ var nodeName = JSEvents.getNodeNameForTarget(pointerLockElement);
+ var id = (pointerLockElement && pointerLockElement.id) ? pointerLockElement.id : '';
+ writeStringToMemory(nodeName, eventStruct + {{{ C_STRUCTS.EmscriptenPointerlockChangeEvent.nodeName }}} );
+ writeStringToMemory(id, eventStruct + {{{ C_STRUCTS.EmscriptenPointerlockChangeEvent.id }}});
+ },
+
+ registerPointerlockChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.pointerlockChangeEvent) {
+ JSEvents.pointerlockChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenPointerlockChangeEvent.__size__ }}} );
+ }
+
+ if (!target) {
+ target = document; // Pointer lock change events need to be captured from 'document' by default instead of 'window'
+ } else {
+ target = JSEvents.findEventTarget(target);
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillPointerlockChangeEventData(JSEvents.pointerlockChangeEvent, e);
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.pointerlockChangeEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: target,
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ requestPointerLock: function(target) {
+ if (target.requestPointerLock) {
+ target.requestPointerLock();
+ } else if (target.mozRequestPointerLock) {
+ target.mozRequestPointerLock();
+ } else if (target.webkitRequestPointerLock) {
+ target.webkitRequestPointerLock();
+ } else if (target.msRequestPointerLock) {
+ target.msRequestPointerLock();
+ } else {
+ // document.body is known to accept pointer lock, so use that to differentiate if the user passed a bad element,
+ // or if the whole browser just doesn't support the feature.
+ if (document.body.requestPointerLock || document.body.mozRequestPointerLock || document.body.webkitRequestPointerLock || document.body.msRequestPointerLock) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_INVALID_TARGET') }}};
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ fillVisibilityChangeEventData: function(eventStruct, e) {
+ var visibilityStates = [ "hidden", "visible", "prerender", "unloaded" ];
+ var visibilityState = visibilityStates.indexOf(document.visibilityState);
+
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenVisibilityChangeEvent.hidden, 'document.hidden', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenVisibilityChangeEvent.visibilityState, 'visibilityState', 'i32') }}}
+ },
+
+ registerVisibilityChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.visibilityChangeEvent) {
+ JSEvents.visibilityChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenVisibilityChangeEvent.__size__ }}} );
+ }
+
+ if (!target) {
+ target = document; // Visibility change events need to be captured from 'document' by default instead of 'window'
+ } else {
+ target = JSEvents.findEventTarget(target);
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillVisibilityChangeEventData(JSEvents.visibilityChangeEvent, e);
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.visibilityChangeEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: target,
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ registerTouchEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.touchEvent) {
+ JSEvents.touchEvent = _malloc( {{{ C_STRUCTS.EmscriptenTouchEvent.__size__ }}} );
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ var touches = {};
+ for(var i = 0; i < e.touches.length; ++i) {
+ var touch = e.touches[i];
+ touches[touch.identifier] = touch;
+ }
+ for(var i = 0; i < e.changedTouches.length; ++i) {
+ var touch = e.changedTouches[i];
+ touches[touch.identifier] = touch;
+ touch.changed = true;
+ }
+ for(var i = 0; i < e.targetTouches.length; ++i) {
+ var touch = e.targetTouches[i];
+ touches[touch.identifier].onTarget = true;
+ }
+
+ var ptr = JSEvents.touchEvent;
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchEvent.ctrlKey, 'e.ctrlKey', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchEvent.shiftKey, 'e.shiftKey', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchEvent.altKey, 'e.altKey', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchEvent.metaKey, 'e.metaKey', 'i32') }}}
+ ptr += {{{ C_STRUCTS.EmscriptenTouchEvent.touches }}}; // Advance to the start of the touch array.
+ var rect = Module['canvas'].getBoundingClientRect();
+ var numTouches = 0;
+ for(var i in touches) {
+ var t = touches[i];
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.identifier, 't.identifier', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.screenX, 't.screenX', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.screenY, 't.screenY', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.clientX, 't.clientX', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.clientY, 't.clientY', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.pageX, 't.pageX', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.pageY, 't.pageY', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.isChanged, 't.changed', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.onTarget, 't.onTarget', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.canvasX, 't.clientX - rect.left', 'i32') }}}
+ {{{ makeSetValue('ptr', C_STRUCTS.EmscriptenTouchPoint.canvasY, 't.clientY - rect.top', 'i32') }}}
+ ptr += {{{ C_STRUCTS.EmscriptenTouchPoint.__size__ }}};
+
+ if (++numTouches >= 32) {
+ break;
+ }
+ }
+ {{{ makeSetValue('JSEvents.touchEvent', C_STRUCTS.EmscriptenTouchEvent.numTouches, 'numTouches', 'i32') }}}
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.touchEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: true,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ fillGamepadEventData: function(eventStruct, e) {
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.timestamp, 'e.timestamp', 'double') }}}
+ for(var i = 0; i < e.axes.length; ++i) {
+ {{{ makeSetValue('eventStruct+i*8', C_STRUCTS.EmscriptenGamepadEvent.axis, 'e.axes[i]', 'double') }}}
+ }
+ for(var i = 0; i < e.buttons.length; ++i) {
+ {{{ makeSetValue('eventStruct+i*8', C_STRUCTS.EmscriptenGamepadEvent.analogButton, 'e.buttons[i].value', 'double') }}}
+ }
+ for(var i = 0; i < e.buttons.length; ++i) {
+ {{{ makeSetValue('eventStruct+i*4', C_STRUCTS.EmscriptenGamepadEvent.digitalButton, 'e.buttons[i].pressed', 'i32') }}}
+ }
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.connected, 'e.connected', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.index, 'e.index', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.numAxes, 'e.axes.length', 'i32') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.numButtons, 'e.buttons.length', 'i32') }}}
+ writeStringToMemory(e.id, eventStruct + {{{ C_STRUCTS.EmscriptenGamepadEvent.id }}} );
+ writeStringToMemory(e.mapping, eventStruct + {{{ C_STRUCTS.EmscriptenGamepadEvent.mapping }}} );
+ },
+
+ registerGamepadEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.gamepadEvent) {
+ JSEvents.gamepadEvent = _malloc( {{{ C_STRUCTS.EmscriptenGamepadEvent.__size__ }}} );
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillGamepadEventData(JSEvents.gamepadEvent, e.gamepad);
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.gamepadEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: true,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ registerBeforeUnloadEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ var confirmationMessage = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, 0, userData]);
+
+ confirmationMessage = Pointer_stringify(confirmationMessage);
+ if (confirmationMessage) {
+ e.preventDefault();
+ e.returnValue = confirmationMessage;
+ return confirmationMessage;
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ battery: function() { return navigator.battery || navigator.mozBattery || navigator.webkitBattery; },
+
+ fillBatteryEventData: function(eventStruct, e) {
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenBatteryEvent.chargingTime, 'e.chargingTime', 'double') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenBatteryEvent.dischargingTime, 'e.dischargingTime', 'double') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenBatteryEvent.level, 'e.level', 'double') }}}
+ {{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenBatteryEvent.charging, 'e.charging', 'i32') }}}
+ },
+
+ registerBatteryEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!JSEvents.batteryEvent) {
+ JSEvents.batteryEvent = _malloc( {{{ C_STRUCTS.EmscriptenBatteryEvent.__size__ }}} );
+ }
+
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ JSEvents.fillBatteryEventData(JSEvents.batteryEvent, JSEvents.battery());
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, JSEvents.batteryEvent, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+
+ registerWebGlEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString) {
+ if (!target) {
+ target = Module['canvas'];
+ }
+ var handlerFunc = function(event) {
+ var e = event || window.event;
+
+ var shouldCancel = Runtime.dynCall('iiii', callbackfunc, [eventTypeId, 0, userData]);
+ if (shouldCancel) {
+ e.preventDefault();
+ }
+ };
+
+ var eventHandler = {
+ target: JSEvents.findEventTarget(target),
+ allowsDeferredCalls: false,
+ eventTypeString: eventTypeString,
+ callbackfunc: callbackfunc,
+ handlerFunc: handlerFunc,
+ useCapture: useCapture
+ };
+ JSEvents.registerOrRemoveHandler(eventHandler);
+ },
+ },
+
+ emscripten_set_keypress_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerKeyEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_KEYPRESS') }}}, "keypress");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_keydown_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerKeyEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_KEYDOWN') }}}, "keydown");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_keyup_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerKeyEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_KEYUP') }}}, "keyup");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_click_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_CLICK') }}}, "click");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_mousedown_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_MOUSEDOWN') }}}, "mousedown");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_mouseup_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_MOUSEUP') }}}, "mouseup");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_dblclick_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_DBLCLICK') }}}, "dblclick");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_mousemove_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_MOUSEMOVE') }}}, "mousemove");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_mouse_status: function(mouseState) {
+ if (!JSEvents.mouseEvent) return {{{ cDefine('EMSCRIPTEN_RESULT_NO_DATA') }}};
+ // HTML5 does not really have a polling API for mouse events, so implement one manually by
+ // returning the data from the most recently received event. This requires that user has registered
+ // at least some no-op function as an event handler to any of the mouse function.
+ HEAP32.set(HEAP32.subarray(JSEvents.mouseEvent, {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}}), mouseState);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_wheel_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerWheelEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_WHEEL') }}}, "wheel");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_resize_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerUiEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_RESIZE') }}}, "resize");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_scroll_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerUiEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_SCROLL') }}}, "scroll");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_blur_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerFocusEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BLUR') }}}, "blur");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_focus_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerFocusEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FOCUS') }}}, "focus");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_focusin_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerFocusEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FOCUSIN') }}}, "focusin");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_focusout_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerFocusEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FOCUSOUT') }}}, "focusout");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_deviceorientation_callback: function(userData, useCapture, callbackfunc) {
+ JSEvents.registerDeviceOrientationEventCallback(window, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_DEVICEORIENTATION') }}}, "deviceorientation");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_deviceorientation_status: function(orientationState) {
+ if (!JSEvents.deviceOrientationEvent) return {{{ cDefine('EMSCRIPTEN_RESULT_NO_DATA') }}};
+ // HTML5 does not really have a polling API for device orientation events, so implement one manually by
+ // returning the data from the most recently received event. This requires that user has registered
+ // at least some no-op function as an event handler.
+ HEAP32.set(HEAP32.subarray(JSEvents.deviceOrientationEvent, {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}}), orientationState);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_devicemotion_callback: function(userData, useCapture, callbackfunc) {
+ JSEvents.registerDeviceMotionEventCallback(window, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_DEVICEMOTION') }}}, "devicemotion");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_devicemotion_status: function(motionState) {
+ if (!JSEvents.deviceMotionEvent) return {{{ cDefine('EMSCRIPTEN_RESULT_NO_DATA') }}};
+ // HTML5 does not really have a polling API for device motion events, so implement one manually by
+ // returning the data from the most recently received event. This requires that user has registered
+ // at least some no-op function as an event handler.
+ HEAP32.set(HEAP32.subarray(JSEvents.deviceMotionEvent, {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}}), motionState);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_orientationchange_callback: function(userData, useCapture, callbackfunc) {
+ if (!window.screen || !window.screen.addEventListener) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerOrientationChangeEventCallback(window.screen, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_ORIENTATIONCHANGE') }}}, "orientationchange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_orientation_status: function(orientationChangeEvent) {
+ if (!JSEvents.screenOrientation() && typeof window.orientation === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.fillOrientationChangeEventData(orientationChangeEvent);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_lock_orientation: function(allowedOrientations) {
+ var orientations = [];
+ if (allowedOrientations & 1) orientations.push("portrait-primary");
+ if (allowedOrientations & 2) orientations.push("portrait-secondary");
+ if (allowedOrientations & 4) orientations.push("landscape-primary");
+ if (allowedOrientations & 8) orientations.push("landscape-secondary");
+ if (window.screen.lockOrientation) {
+ window.screen.lockOrientation(orientations);
+ } else if (window.screen.mozLockOrientation) {
+ window.screen.mozLockOrientation(orientations);
+ } else if (window.screen.webkitLockOrientation) {
+ window.screen.webkitLockOrientation(orientations);
+ } else if (window.screen.msLockOrientation) {
+ window.screen.msLockOrientation(orientations);
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_unlock_orientation: function() {
+ if (window.screen.unlockOrientation) {
+ window.screen.unlockOrientation();
+ } else if (window.screen.mozUnlockOrientation) {
+ window.screen.mozUnlockOrientation();
+ } else if (window.screen.webkitUnlockOrientation) {
+ window.screen.webkitUnlockOrientation();
+ } else if (window.screen.msUnlockOrientation) {
+ window.screen.msUnlockOrientation();
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_fullscreenchange_callback: function(target, userData, useCapture, callbackfunc) {
+ if (typeof JSEvents.fullscreenEnabled() === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ if (!target) target = document;
+ else {
+ target = JSEvents.findEventTarget(target);
+ if (!target) return {{{ cDefine('EMSCRIPTEN_RESULT_UNKNOWN_TARGET') }}};
+ }
+ JSEvents.registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FULLSCREENCHANGE') }}}, "fullscreenchange");
+ JSEvents.registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FULLSCREENCHANGE') }}}, "mozfullscreenchange");
+ JSEvents.registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FULLSCREENCHANGE') }}}, "webkitfullscreenchange");
+ JSEvents.registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_FULLSCREENCHANGE') }}}, "msfullscreenchange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_fullscreen_status: function(fullscreenStatus) {
+ if (typeof JSEvents.fullscreenEnabled() === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.fillFullscreenChangeEventData(fullscreenStatus);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ // https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
+ emscripten_request_fullscreen: function(target, deferUntilInEventHandler) {
+ if (typeof JSEvents.fullscreenEnabled() === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ if (!JSEvents.fullscreenEnabled()) return {{{ cDefine('EMSCRIPTEN_RESULT_INVALID_TARGET') }}};
+ if (!target) target = '#canvas';
+ target = JSEvents.findEventTarget(target);
+ if (!target) return {{{ cDefine('EMSCRIPTEN_RESULT_UNKNOWN_TARGET') }}};
+
+ if (!target.requestFullscreen && !target.msRequestFullscreen && !target.mozRequestFullScreen && !target.mozRequestFullscreen && !target.webkitRequestFullscreen) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_INVALID_TARGET') }}};
+ }
+
+ var canPerformRequests = JSEvents.canPerformEventHandlerRequests();
+
+ // Queue this function call if we're not currently in an event handler and the user saw it appropriate to do so.
+ if (!canPerformRequests) {
+ if (deferUntilInEventHandler) {
+ JSEvents.deferCall(JSEvents.requestFullscreen, 1 /* priority over pointer lock */, [target]);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_DEFERRED') }}};
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED') }}};
+ }
+ }
+
+ return JSEvents.requestFullscreen(target);
+ },
+
+ emscripten_exit_fullscreen: function() {
+ if (typeof JSEvents.fullscreenEnabled() === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ // Make sure no queued up calls will fire after this.
+ JSEvents.removeDeferredCalls(JSEvents.requestFullscreen);
+
+ if (document.exitFullscreen) {
+ document.exitFullscreen();
+ } else if (document.msExitFullscreen) {
+ document.msExitFullscreen();
+ } else if (document.mozCancelFullScreen) {
+ document.mozCancelFullScreen();
+ } else if (document.webkitExitFullscreen) {
+ document.webkitExitFullscreen();
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_pointerlockchange_callback: function(target, userData, useCapture, callbackfunc) {
+ if (!document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ if (!target) target = document;
+ else {
+ target = JSEvents.findEventTarget(target);
+ if (!target) return {{{ cDefine('EMSCRIPTEN_RESULT_UNKNOWN_TARGET') }}};
+ }
+ JSEvents.registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_POINTERLOCKCHANGE') }}}, "pointerlockchange");
+ JSEvents.registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_POINTERLOCKCHANGE') }}}, "mozpointerlockchange");
+ JSEvents.registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_POINTERLOCKCHANGE') }}}, "webkitpointerlockchange");
+ JSEvents.registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_POINTERLOCKCHANGE') }}}, "mspointerlockchange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_pointerlock_status: function(pointerlockStatus) {
+ if (!document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ JSEvents.fillPointerlockChangeEventData(pointerlockStatus);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_request_pointerlock: function(target, deferUntilInEventHandler) {
+ if (!target) target = '#canvas';
+ target = JSEvents.findEventTarget(target);
+ if (!target) return {{{ cDefine('EMSCRIPTEN_RESULT_UNKNOWN_TARGET') }}};
+ if (!target.requestPointerLock && !target.mozRequestPointerLock && !target.webkitRequestPointerLock && !target.msRequestPointerLock) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+
+ var canPerformRequests = JSEvents.canPerformEventHandlerRequests();
+
+ // Queue this function call if we're not currently in an event handler and the user saw it appropriate to do so.
+ if (!canPerformRequests) {
+ if (deferUntilInEventHandler) {
+ JSEvents.deferCall(JSEvents.requestPointerLock, 2 /* priority below fullscreen */, [target]);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_DEFERRED') }}};
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED') }}};
+ }
+ }
+
+ return JSEvents.requestPointerLock(target);
+ },
+
+ emscripten_exit_pointerlock: function() {
+ // Make sure no queued up calls will fire after this.
+ JSEvents.removeDeferredCalls(JSEvents.requestPointerLock);
+
+ if (document.exitPointerLock) {
+ document.exitPointerLock();
+ } else if (document.msExitPointerLock) {
+ document.msExitPointerLock();
+ } else if (document.mozExitPointerLock) {
+ document.mozExitPointerLock();
+ } else if (document.webkitExitPointerLock) {
+ document.webkitExitPointerLock();
+ } else {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_vibrate: function(msecs) {
+ if (!navigator.vibrate) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ navigator.vibrate(msecs);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_vibrate_pattern: function(msecsArray, numEntries) {
+ if (!navigator.vibrate) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+
+ var vibrateList = [];
+ for(var i = 0; i < numEntries; ++i) {
+ var msecs = {{{ makeGetValue('msecsArray', 'i*4', 'i32') }}}
+ vibrateList.push(msecs);
+ }
+ navigator.vibrate(vibrateList);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_visibilitychange_callback: function(userData, useCapture, callbackfunc) {
+ JSEvents.registerVisibilityChangeEventCallback(document, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_VISIBILITYCHANGE') }}}, "visibilitychange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_visibility_status: function(visibilityStatus) {
+ if (typeof document.visibilityState === 'undefined' && typeof document.hidden === 'undefined') {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ }
+ JSEvents.fillVisibilityChangeEventData(visibilityStatus);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_touchstart_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerTouchEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_TOUCHSTART') }}}, "touchstart");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_touchend_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerTouchEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_TOUCHEND') }}}, "touchend");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_touchmove_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerTouchEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_TOUCHMOVE') }}}, "touchmove");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_touchcancel_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerTouchEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_TOUCHCANCEL') }}}, "touchcancel");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_gamepadconnected_callback: function(userData, useCapture, callbackfunc) {
+ if (!navigator.getGamepads) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerGamepadEventCallback(window, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_GAMEPADCONNECTED') }}}, "gamepadconnected");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_gamepaddisconnected_callback: function(userData, useCapture, callbackfunc) {
+ if (!navigator.getGamepads) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerGamepadEventCallback(window, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED') }}}, "gamepaddisconnected");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_num_gamepads: function() {
+ if (!navigator.getGamepads) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ return navigator.getGamepads().length;
+ },
+
+ emscripten_get_gamepad_status: function(index, gamepadState) {
+ if (!navigator.getGamepads) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ var gamepads = navigator.getGamepads();
+ if (index < 0 || index >= gamepads.length) {
+ return {{{ cDefine('EMSCRIPTEN_RESULT_INVALID_PARAM') }}};
+ }
+ JSEvents.fillGamepadEventData(gamepadState, gamepads[index]);
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_beforeunload_callback: function(userData, callbackfunc) {
+ if (typeof window.onbeforeunload === 'undefined') return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerBeforeUnloadEventCallback(window, userData, true, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BEFOREUNLOAD') }}}, "beforeunload");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_batterychargingchange_callback: function(userData, callbackfunc) {
+ if (!JSEvents.battery()) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerBatteryEventCallback(JSEvents.battery(), userData, true, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BATTERYCHARGINGCHANGE') }}}, "chargingchange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_batterylevelchange_callback: function(userData, callbackfunc) {
+ if (!JSEvents.battery()) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.registerBatteryEventCallback(JSEvents.battery(), userData, true, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE') }}}, "levelchange");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_get_battery_status: function(batteryState) {
+ if (!JSEvents.battery()) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
+ JSEvents.fillBatteryEventData(batteryState, JSEvents.battery());
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_webglcontextlost_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerWebGlEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST') }}}, "webglcontextlost");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+
+ emscripten_set_webglcontextrestored_callback: function(target, userData, useCapture, callbackfunc) {
+ JSEvents.registerWebGlEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED') }}}, "webglcontextrestored");
+ return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
+ },
+};
+
+autoAddDeps(LibraryJSEvents, '$JSEvents');
+mergeInto(LibraryManager.library, LibraryJSEvents);
diff --git a/src/library_openal.js b/src/library_openal.js
index eb152f62..bb3af8fb 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -201,12 +201,15 @@ var LibraryOpenAL = {
}
if (ctx) {
+ var gain = ctx.createGain();
+ gain.connect(ctx.destination);
var context = {
ctx: ctx,
err: 0,
src: [],
buf: [],
- interval: setInterval(function() { AL.updateSources(context); }, AL.QUEUE_INTERVAL)
+ interval: setInterval(function() { AL.updateSources(context); }, AL.QUEUE_INTERVAL),
+ gain: gain
};
AL.contexts.push(context);
return AL.contexts.length;
@@ -254,7 +257,7 @@ var LibraryOpenAL = {
}
for (var i = 0; i < count; ++i) {
var gain = AL.currentContext.ctx.createGain();
- gain.connect(AL.currentContext.ctx.destination);
+ gain.connect(AL.currentContext.gain);
AL.currentContext.src.push({
state: 0x1011 /* AL_INITIAL */,
queue: [],
@@ -294,6 +297,34 @@ var LibraryOpenAL = {
this._velocity = val;
if (this.panner) this.panner.setVelocity(val[0], val[1], val[2]);
},
+ get direction() {
+ return this._direction || [0, 0, 0];
+ },
+ set direction(val) {
+ this._direction = val;
+ if (this.panner) this.panner.setOrientation(val[0], val[1], val[2]);
+ },
+ get coneOuterGain() {
+ return this._coneOuterGain || 0.0;
+ },
+ set coneOuterGain(val) {
+ this._coneOuterGain = val;
+ if (this.panner) this.panner.coneOuterGain = val;
+ },
+ get coneInnerAngle() {
+ return this._coneInnerAngle || 360.0;
+ },
+ set coneInnerAngle(val) {
+ this._coneInnerAngle = val;
+ if (this.panner) this.panner.coneInnerAngle = val;
+ },
+ get coneOuterAngle() {
+ return this._coneOuterAngle || 360.0;
+ },
+ set coneOuterAngle(val) {
+ this._coneOuterAngle = val;
+ if (this.panner) this.panner.coneOuterAngle = val;
+ },
gain: gain,
panner: null,
buffersPlayed: 0,
@@ -320,6 +351,12 @@ var LibraryOpenAL = {
return;
}
switch (param) {
+ case 0x1001 /* AL_CONE_INNER_ANGLE */:
+ src.coneInnerAngle = value;
+ break;
+ case 0x1002 /* AL_CONE_OUTER_ANGLE */:
+ src.coneOuterAngle = value;
+ break;
case 0x1007 /* AL_LOOPING */:
src.loop = (value === 1 /* AL_TRUE */);
break;
@@ -406,12 +443,15 @@ var LibraryOpenAL = {
case 0x1021 /* AL_ROLLOFF_FACTOR */:
src.rolloffFactor = value;
break;
- // case 0x1022 /* AL_CONE_OUTER_GAIN */:
- // break;
- // case 0x1001 /* AL_CONE_INNER_ANGLE */:
- // break;
- // case 0x1002 /* AL_CONE_OUTER_ANGLE */:
- // break;
+ case 0x1022 /* AL_CONE_OUTER_GAIN */:
+ src.coneOuterGain = value;
+ break;
+ case 0x1001 /* AL_CONE_INNER_ANGLE */:
+ src.coneInnerAngle = value;
+ break;
+ case 0x1002 /* AL_CONE_OUTER_ANGLE */:
+ src.coneOuterAngle = value;
+ break;
case 0x1020 /* AL_REFERENCE_DISTANCE */:
src.refDistance = value;
break;
@@ -443,6 +483,9 @@ var LibraryOpenAL = {
case 0x1004 /* AL_POSITION */:
src.position = [v1, v2, v3];
break;
+ case 0x1005 /* AL_DIRECTION */:
+ src.direction = [v1, v2, v3];
+ break;
case 0x1006 /* AL_VELOCITY */:
src.velocity = [v1, v2, v3];
break;
@@ -594,6 +637,21 @@ var LibraryOpenAL = {
}
},
+ alIsBuffer: function(bufferId) {
+ if (!AL.currentContext) {
+ return false;
+ }
+ if (bufferId > AL.currentContext.buf.length) {
+ return false;
+ }
+
+ if (!AL.currentContext.buf[bufferId - 1]) {
+ return false;
+ } else {
+ return true;
+ }
+ },
+
alBufferData: function(buffer, format, data, size, freq) {
if (!AL.currentContext) {
#if OPENAL_DEBUG
@@ -743,6 +801,12 @@ var LibraryOpenAL = {
case 0x202 /* AL_SOURCE_RELATIVE */:
{{{ makeSetValue('value', '0', 'src.panner ? 1 : 0', 'i32') }}};
break;
+ case 0x1001 /* AL_CONE_INNER_ANGLE */:
+ {{{ makeSetValue('value', '0', 'src.coneInnerAngle', 'i32') }}};
+ break;
+ case 0x1002 /* AL_CONE_OUTER_ANGLE */:
+ {{{ makeSetValue('value', '0', 'src.coneOuterAngle', 'i32') }}};
+ break;
case 0x1009 /* AL_BUFFER */:
if (!src.queue.length) {
{{{ makeSetValue('value', '0', '0', 'i32') }}};
@@ -809,12 +873,15 @@ var LibraryOpenAL = {
case 0x1021 /* AL_ROLLOFF_FACTOR */:
{{{ makeSetValue('value', '0', 'src.rolloffFactor', 'float') }}}
break;
- // case 0x1022 /* AL_CONE_OUTER_GAIN */:
- // break;
- // case 0x1001 /* AL_CONE_INNER_ANGLE */:
- // break;
- // case 0x1002 /* AL_CONE_OUTER_ANGLE */:
- // break;
+ case 0x1022 /* AL_CONE_OUTER_GAIN */:
+ {{{ makeSetValue('value', '0', 'src.coneOuterGain', 'float') }}}
+ break;
+ case 0x1001 /* AL_CONE_INNER_ANGLE */:
+ {{{ makeSetValue('value', '0', 'src.coneInnerAngle', 'float') }}}
+ break;
+ case 0x1002 /* AL_CONE_OUTER_ANGLE */:
+ {{{ makeSetValue('value', '0', 'src.coneOuterAngle', 'float') }}}
+ break;
case 0x1020 /* AL_REFERENCE_DISTANCE */:
{{{ makeSetValue('value', '0', 'src.refDistance', 'float') }}}
break;
@@ -830,6 +897,49 @@ var LibraryOpenAL = {
}
},
+ alGetSourcefv: function(source, param, values) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alGetSourcefv called without a valid context");
+#endif
+ return;
+ }
+ var src = AL.currentContext.src[source - 1];
+ if (!src) {
+#if OPENAL_DEBUG
+ console.error("alGetSourcefv called with an invalid source");
+#endif
+ AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
+ return;
+ }
+ switch (param) {
+ case 0x1004 /* AL_POSITION */:
+ var position = src.position;
+ {{{ makeSetValue('values', '0', 'position[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'position[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'position[2]', 'float') }}}
+ break;
+ case 0x1005 /* AL_DIRECTION */:
+ var direction = src.direction;
+ {{{ makeSetValue('values', '0', 'direction[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'direction[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'direction[2]', 'float') }}}
+ break;
+ case 0x1006 /* AL_VELOCITY */:
+ var velocity = src.velocity;
+ {{{ makeSetValue('values', '0', 'velocity[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'velocity[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'velocity[2]', 'float') }}}
+ break;
+ default:
+#if OPENAL_DEBUG
+ console.error("alGetSourcefv with param " + param + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
alDistanceModel: function(model) {
if (model !== 0 /* AL_NONE */) {
#if OPENAL_DEBUG
@@ -838,6 +948,136 @@ var LibraryOpenAL = {
}
},
+ alGetListenerf: function(pname, values) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alGetListenerf called without a valid context");
+#endif
+ return;
+ }
+ switch (pname) {
+ case 0x100A /* AL_GAIN */:
+ {{{ makeSetValue('value', '0', 'AL.currentContext.gain.gain', 'float') }}}
+ break;
+ default:
+#if OPENAL_DEBUG
+ console.error("alGetListenerf with param " + pname + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+
+ },
+
+ alGetListenerfv: function(pname, values) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alGetListenerfv called without a valid context");
+#endif
+ return;
+ }
+ switch (pname) {
+ case 0x1004 /* AL_POSITION */:
+ var position = AL.currentContext.ctx.listener._position || [0,0,0];
+ {{{ makeSetValue('values', '0', 'position[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'position[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'position[2]', 'float') }}}
+ break;
+ case 0x1006 /* AL_VELOCITY */:
+ var velocity = AL.currentContext.ctx.listener._velocity || [0,0,0];
+ {{{ makeSetValue('values', '0', 'velocity[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'velocity[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'velocity[2]', 'float') }}}
+ break;
+ case 0x100F /* AL_ORIENTATION */:
+ var orientation = AL.currentContext.ctx.listener._orientation || [0,0,0,0,0,0];
+ {{{ makeSetValue('values', '0', 'orientation[0]', 'float') }}}
+ {{{ makeSetValue('values', '4', 'orientation[1]', 'float') }}}
+ {{{ makeSetValue('values', '8', 'orientation[2]', 'float') }}}
+ {{{ makeSetValue('values', '12', 'orientation[3]', 'float') }}}
+ {{{ makeSetValue('values', '16', 'orientation[4]', 'float') }}}
+ {{{ makeSetValue('values', '20', 'orientation[5]', 'float') }}}
+ break;
+ default:
+#if OPENAL_DEBUG
+ console.error("alGetListenerfv with param " + pname + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
+ alGetListeneri: function(pname, value) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alGetListeneri called without a valid context");
+#endif
+ return;
+ }
+ switch (pname) {
+ default:
+#if OPENAL_DEBUG
+ console.error("alGetListeneri with param " + pname + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
+ alListenerf: function(param, value) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alListenerf called without a valid context");
+#endif
+ return;
+ }
+ switch (param) {
+ case 0x100A /* AL_GAIN */:
+ AL.currentContext.gain.value = value;
+ break;
+ default:
+#if OPENAL_DEBUG
+ console.error("alListenerf with param " + param + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
+ alEnable: function(param) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alEnable called without a valid context");
+#endif
+ return;
+ }
+ switch (param) {
+ default:
+#if OPENAL_DEBUG
+ console.error("alEnable with param " + param + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
+ alDisable: function(param) {
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ console.error("alDisable called without a valid context");
+#endif
+ return;
+ }
+ switch (pname) {
+ default:
+#if OPENAL_DEBUG
+ console.error("alDisable with param " + param + " not implemented yet");
+#endif
+ AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
+ break;
+ }
+ },
+
alListenerfv: function(param, values) {
if (!AL.currentContext) {
#if OPENAL_DEBUG
@@ -847,32 +1087,32 @@ var LibraryOpenAL = {
}
switch (param) {
case 0x1004 /* AL_POSITION */:
- AL.currentContext.ctx.listener.setPosition(
- {{{ makeGetValue('values', '0', 'float') }}},
- {{{ makeGetValue('values', '4', 'float') }}},
- {{{ makeGetValue('values', '8', 'float') }}}
- );
+ var x = {{{ makeGetValue('value', '0', 'float') }}};
+ var y = {{{ makeGetValue('value', '4', 'float') }}};
+ var z = {{{ makeGetValue('value', '8', 'float') }}};
+ AL.currentContext.ctx.listener._position = [x,y,z];
+ AL.currentContext.ctx.listener.setPosition(x, y, z);
break;
case 0x1006 /* AL_VELOCITY */:
- AL.currentContext.ctx.listener.setVelocity(
- {{{ makeGetValue('values', '0', 'float') }}},
- {{{ makeGetValue('values', '4', 'float') }}},
- {{{ makeGetValue('values', '8', 'float') }}}
- );
+ var x = {{{ makeGetValue('value', '0', 'float') }}};
+ var y = {{{ makeGetValue('value', '4', 'float') }}};
+ var z = {{{ makeGetValue('value', '8', 'float') }}};
+ AL.currentContext.ctx.listener._velocity = [x,y,z];
+ AL.currentContext.ctx.listener.setVelocity(x, y, z);
break;
case 0x100F /* AL_ORIENTATION */:
- AL.currentContext.ctx.listener.setOrientation(
- {{{ makeGetValue('values', '0', 'float') }}},
- {{{ makeGetValue('values', '4', 'float') }}},
- {{{ makeGetValue('values', '8', 'float') }}},
- {{{ makeGetValue('values', '12', 'float') }}},
- {{{ makeGetValue('values', '16', 'float') }}},
- {{{ makeGetValue('values', '20', 'float') }}}
- );
+ var x = {{{ makeGetValue('value', '0', 'float') }}};
+ var y = {{{ makeGetValue('value', '4', 'float') }}};
+ var z = {{{ makeGetValue('value', '8', 'float') }}};
+ var x2 = {{{ makeGetValue('value', '12', 'float') }}};
+ var y2 = {{{ makeGetValue('value', '16', 'float') }}};
+ var z2 = {{{ makeGetValue('value', '20', 'float') }}};
+ AL.currentContext.ctx.listener._orientation = [x,y,z, x2, y2, z2];
+ AL.currentContext.ctx.listener.setOrientation(x,y,z,x2,y2,z2);
break;
default:
#if OPENAL_DEBUG
- console.log("alListenerfv with param " + param + " not implemented yet");
+ console.error("alListenerfv with param " + param + " not implemented yet");
#endif
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
break;
diff --git a/src/modules.js b/src/modules.js
index d1ef4243..2d2a75d0 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -424,7 +424,7 @@ var LibraryManager = {
load: function() {
if (this.library) return;
- var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js', 'library_uuid.js', 'library_glew.js'].concat(additionalLibraries);
+ var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js', 'library_uuid.js', 'library_glew.js', 'library_html5.js'].concat(additionalLibraries);
for (var i = 0; i < libraries.length; i++) {
var filename = libraries[i];
var src = read(filename);
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp
index 204986da..14c203e0 100644
--- a/src/relooper/Relooper.cpp
+++ b/src/relooper/Relooper.cpp
@@ -1,3 +1,7 @@
+// We are implementing the Relooper C API, so always export from this file.
+#ifndef RELOOPERDLL_EXPORTS
+#define RELOOPERDLL_EXPORTS
+#endif
#include "Relooper.h"
@@ -1269,7 +1273,7 @@ VoidIntMap __blockDebugMap__; // maps block pointers in currently running code t
extern "C" {
-void rl_set_output_buffer(char *buffer, int size) {
+RELOOPERDLL_API void rl_set_output_buffer(char *buffer, int size) {
#if DEBUG
printf("#include \"Relooper.h\"\n");
printf("int main() {\n");
@@ -1279,15 +1283,15 @@ void rl_set_output_buffer(char *buffer, int size) {
Relooper::SetOutputBuffer(buffer, size);
}
-void rl_make_output_buffer(int size) {
+RELOOPERDLL_API void rl_make_output_buffer(int size) {
Relooper::SetOutputBuffer((char*)malloc(size), size);
}
-void rl_set_asm_js_mode(int on) {
+RELOOPERDLL_API void rl_set_asm_js_mode(int on) {
Relooper::SetAsmJSMode(on);
}
-void *rl_new_block(const char *text, const char *branch_var) {
+RELOOPERDLL_API void *rl_new_block(const char *text, const char *branch_var) {
Block *ret = new Block(text, branch_var);
#if DEBUG
printf(" void *b%d = rl_new_block(\"// code %d\");\n", ret->Id, ret->Id);
@@ -1297,21 +1301,21 @@ void *rl_new_block(const char *text, const char *branch_var) {
return ret;
}
-void rl_delete_block(void *block) {
+RELOOPERDLL_API void rl_delete_block(void *block) {
#if DEBUG
printf(" rl_delete_block(block_map[%d]);\n", ((Block*)block)->Id);
#endif
delete (Block*)block;
}
-void rl_block_add_branch_to(void *from, void *to, const char *condition, const char *code) {
+RELOOPERDLL_API void rl_block_add_branch_to(void *from, void *to, const char *condition, const char *code) {
#if DEBUG
printf(" rl_block_add_branch_to(block_map[%d], block_map[%d], %s%s%s, %s%s%s);\n", ((Block*)from)->Id, ((Block*)to)->Id, condition ? "\"" : "", condition ? condition : "NULL", condition ? "\"" : "", code ? "\"" : "", code ? code : "NULL", code ? "\"" : "");
#endif
((Block*)from)->AddBranchTo((Block*)to, condition, code);
}
-void *rl_new_relooper() {
+RELOOPERDLL_API void *rl_new_relooper() {
#if DEBUG
printf(" void *block_map[10000];\n");
printf(" void *rl = rl_new_relooper();\n");
@@ -1319,18 +1323,18 @@ void *rl_new_relooper() {
return new Relooper;
}
-void rl_delete_relooper(void *relooper) {
+RELOOPERDLL_API void rl_delete_relooper(void *relooper) {
delete (Relooper*)relooper;
}
-void rl_relooper_add_block(void *relooper, void *block) {
+RELOOPERDLL_API void rl_relooper_add_block(void *relooper, void *block) {
#if DEBUG
printf(" rl_relooper_add_block(rl, block_map[%d]);\n", ((Block*)block)->Id);
#endif
((Relooper*)relooper)->AddBlock((Block*)block);
}
-void rl_relooper_calculate(void *relooper, void *entry) {
+RELOOPERDLL_API void rl_relooper_calculate(void *relooper, void *entry) {
#if DEBUG
printf(" rl_relooper_calculate(rl, block_map[%d]);\n", ((Block*)entry)->Id);
printf(" rl_relooper_render(rl);\n");
@@ -1342,7 +1346,7 @@ void rl_relooper_calculate(void *relooper, void *entry) {
((Relooper*)relooper)->Calculate((Block*)entry);
}
-void rl_relooper_render(void *relooper) {
+RELOOPERDLL_API void rl_relooper_render(void *relooper) {
((Relooper*)relooper)->Render();
}
diff --git a/src/shell.html b/src/shell.html
index efb9e91d..7a3a8d08 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -11,10 +11,44 @@
div.emscripten_border { border: 1px solid black; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; }
+
+ .spinner {
+ height: 50px;
+ width: 50px;
+ margin: 0px auto;
+ -webkit-animation: rotation .8s linear infinite;
+ -moz-animation: rotation .8s linear infinite;
+ -o-animation: rotation .8s linear infinite;
+ animation: rotation 0.8s linear infinite;
+ border-left: 10px solid rgb(0,150,240);
+ border-right: 10px solid rgb(0,150,240);
+ border-bottom: 10px solid rgb(0,150,240);
+ border-top: 10px solid rgb(100,0,200);
+ border-radius: 100%;
+ background-color: rgb(200,100,250);
+ }
+ @-webkit-keyframes rotation {
+ from {-webkit-transform: rotate(0deg);}
+ to {-webkit-transform: rotate(360deg);}
+ }
+ @-moz-keyframes rotation {
+ from {-moz-transform: rotate(0deg);}
+ to {-moz-transform: rotate(360deg);}
+ }
+ @-o-keyframes rotation {
+ from {-o-transform: rotate(0deg);}
+ to {-o-transform: rotate(360deg);}
+ }
+ @keyframes rotation {
+ from {transform: rotate(0deg);}
+ to {transform: rotate(360deg);}
+ }
+
</style>
</head>
<body>
<hr/>
+ <figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>emscripten</strong></center></figure>
<div class="emscripten" id="status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
@@ -35,7 +69,10 @@
<textarea class="emscripten" id="output" rows="8"></textarea>
<hr>
<script type='text/javascript'>
- // connect to canvas
+ var statusElement = document.getElementById('status');
+ var progressElement = document.getElementById('progress');
+ var spinnerElement = document.getElementById('spinner');
+
var Module = {
preRun: [],
postRun: [],
@@ -68,17 +105,17 @@
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Date.now() < 30) return; // if this is a progress update, skip it if too soon
- var statusElement = document.getElementById('status');
- var progressElement = document.getElementById('progress');
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
+ spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
+ if (!text) spinnerElement.hidden = true;
}
statusElement.innerHTML = text;
},
diff --git a/src/struct_info.json b/src/struct_info.json
index a22851b6..32261c0a 100644
--- a/src/struct_info.json
+++ b/src/struct_info.json
@@ -1073,5 +1073,188 @@
"UUID_TYPE_DCE_RANDOM"
],
"structs": {}
+ },
+ // ===========================================
+ // emscripten html5 library
+ // ===========================================
+ {
+ "file": "emscripten/html5.h",
+ "defines": [
+ "EMSCRIPTEN_EVENT_KEYPRESS",
+ "EMSCRIPTEN_EVENT_KEYDOWN",
+ "EMSCRIPTEN_EVENT_KEYUP",
+ "EMSCRIPTEN_EVENT_CLICK",
+ "EMSCRIPTEN_EVENT_MOUSEDOWN",
+ "EMSCRIPTEN_EVENT_MOUSEUP",
+ "EMSCRIPTEN_EVENT_DBLCLICK",
+ "EMSCRIPTEN_EVENT_MOUSEMOVE",
+ "EMSCRIPTEN_EVENT_WHEEL",
+ "EMSCRIPTEN_EVENT_RESIZE",
+ "EMSCRIPTEN_EVENT_SCROLL",
+ "EMSCRIPTEN_EVENT_BLUR",
+ "EMSCRIPTEN_EVENT_FOCUS",
+ "EMSCRIPTEN_EVENT_FOCUSIN",
+ "EMSCRIPTEN_EVENT_FOCUSOUT",
+ "EMSCRIPTEN_EVENT_DEVICEORIENTATION",
+ "EMSCRIPTEN_EVENT_DEVICEMOTION",
+ "EMSCRIPTEN_EVENT_ORIENTATIONCHANGE",
+ "EMSCRIPTEN_EVENT_FULLSCREENCHANGE",
+ "EMSCRIPTEN_EVENT_POINTERLOCKCHANGE",
+ "EMSCRIPTEN_EVENT_VISIBILITYCHANGE",
+ "EMSCRIPTEN_EVENT_TOUCHSTART",
+ "EMSCRIPTEN_EVENT_TOUCHEND",
+ "EMSCRIPTEN_EVENT_TOUCHMOVE",
+ "EMSCRIPTEN_EVENT_TOUCHCANCEL",
+ "EMSCRIPTEN_EVENT_GAMEPADCONNECTED",
+ "EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED",
+ "EMSCRIPTEN_EVENT_BEFOREUNLOAD",
+ "EMSCRIPTEN_EVENT_BATTERYCHARGINGCHANGE",
+ "EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE",
+ "EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST",
+ "EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED",
+
+ "EMSCRIPTEN_RESULT_SUCCESS",
+ "EMSCRIPTEN_RESULT_DEFERRED",
+ "EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED",
+ "EMSCRIPTEN_RESULT_INVALID_TARGET",
+ "EMSCRIPTEN_RESULT_UNKNOWN_TARGET",
+ "EMSCRIPTEN_RESULT_INVALID_PARAM",
+ "EMSCRIPTEN_RESULT_NOT_SUPPORTED",
+ "EMSCRIPTEN_RESULT_FAILED",
+ "EMSCRIPTEN_RESULT_NO_DATA"
+ ],
+ "structs": {
+ "EmscriptenKeyboardEvent": [
+ "key",
+ "code",
+ "location",
+ "ctrlKey",
+ "shiftKey",
+ "altKey",
+ "metaKey",
+ "repeat",
+ "locale",
+ "charValue",
+ "charCode",
+ "keyCode",
+ "which"
+ ],
+ "EmscriptenMouseEvent": [
+ "timestamp",
+ "screenX",
+ "screenY",
+ "clientX",
+ "clientY",
+ "ctrlKey",
+ "shiftKey",
+ "altKey",
+ "metaKey",
+ "button",
+ "buttons",
+ "movementX",
+ "movementY",
+ "canvasX",
+ "canvasY"
+ ],
+ "EmscriptenWheelEvent": [
+ "mouse",
+ "deltaX",
+ "deltaY",
+ "deltaZ",
+ "deltaMode"
+ ],
+ "EmscriptenUiEvent": [
+ "detail",
+ "documentBodyClientWidth",
+ "documentBodyClientHeight",
+ "windowInnerWidth",
+ "windowInnerHeight",
+ "windowOuterWidth",
+ "windowOuterHeight",
+ "scrollTop",
+ "scrollLeft"
+ ],
+ "EmscriptenFocusEvent": [
+ "nodeName",
+ "id"
+ ],
+ "EmscriptenDeviceOrientationEvent": [
+ "timestamp",
+ "alpha",
+ "beta",
+ "gamma",
+ "absolute"
+ ],
+ "EmscriptenDeviceMotionEvent": [
+ "timestamp",
+ "accelerationX",
+ "accelerationY",
+ "accelerationZ",
+ "accelerationIncludingGravityX",
+ "accelerationIncludingGravityY",
+ "accelerationIncludingGravityZ",
+ "rotationRateAlpha",
+ "rotationRateBeta",
+ "rotationRateGamma"
+ ],
+ "EmscriptenOrientationChangeEvent": [
+ "orientationIndex",
+ "orientationAngle"
+ ],
+ "EmscriptenFullscreenChangeEvent": [
+ "isFullscreen",
+ "fullscreenEnabled",
+ "nodeName",
+ "id"
+ ],
+ "EmscriptenPointerlockChangeEvent": [
+ "isActive",
+ "nodeName",
+ "id"
+ ],
+ "EmscriptenVisibilityChangeEvent": [
+ "hidden",
+ "visibilityState"
+ ],
+ "EmscriptenTouchPoint": [
+ "identifier",
+ "screenX",
+ "screenY",
+ "clientX",
+ "clientY",
+ "pageX",
+ "pageY",
+ "isChanged",
+ "onTarget",
+ "canvasX",
+ "canvasY"
+ ],
+ "EmscriptenTouchEvent": [
+ "numTouches",
+ "ctrlKey",
+ "shiftKey",
+ "altKey",
+ "metaKey",
+ "touches"
+ ],
+ "EmscriptenGamepadEvent": [
+ "timestamp",
+ "axis",
+ "analogButton",
+ "digitalButton",
+ "connected",
+ "index",
+ "numAxes",
+ "numButtons",
+ "id",
+ "mapping"
+ ],
+ "EmscriptenBatteryEvent": [
+ "chargingTime",
+ "dischargingTime",
+ "level",
+ "charging"
+ ]
+ }
}
-]
+ ]