diff --git a/Makefile.emscripten b/Makefile.emscripten index 722434c84a..5fa4ff7e2e 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -23,7 +23,11 @@ ifneq ($(NATIVE_ZLIB),) endif LIBS := -LDFLAGS := -L. -s TOTAL_MEMORY=$(MEMORY) -s OUTLINING_LIMIT=50000 --js-library emscripten/library_rwebaudio.js --js-library emscripten/library_rwebinput.js --js-library emscripten/library_rwebcam.js --no-heap-copy +LDFLAGS := -L. --no-heap-copy -s USE_ZLIB=1 `-s TOTAL_MEMORY=$(MEMORY) -s OUTLINING_LIMIT=50000 \ + -s EXPORTED_FUNCTIONS="['_main', '_malloc', '_cmd_savefiles', '_cmd_save_state', '_cmd_load_state', '_cmd_take_screenshot']" \ + --js-library emscripten/library_rwebaudio.js \ + --js-library emscripten/library_rwebinput.js \ + --js-library emscripten/library_rwebcam.js include Makefile.common @@ -67,7 +71,8 @@ else CFLAGS += -O2 endif -CFLAGS += -Wall -Wno-unused-result -Wno-unused-variable -I. -Ilibretro-common/include -std=gnu99 +CFLAGS += -DWANT_RPNG -Wall -Wno-unused-result -Wno-unused-variable -I. -Ilibretro-common/include -std=gnu99 -s USE_ZLIB=1 \ + -s EXPORTED_FUNCTIONS="['_main', '_malloc', '_cmd_savefiles', '_cmd_save_state', '_cmd_take_screenshot']" all: $(TARGET) diff --git a/audio/audio_dsp_filter.c b/audio/audio_dsp_filter.c index 2f1a4ca34f..c26dc1ba15 100644 --- a/audio/audio_dsp_filter.c +++ b/audio/audio_dsp_filter.c @@ -246,8 +246,11 @@ rarch_dsp_filter_t *rarch_dsp_filter_new( if (!plugs) goto error; #endif + +#if defined(HAVE_DYLIB) if (!append_plugs(dsp, plugs)) goto error; +#endif if (plugs) string_list_free(plugs); diff --git a/emscripten/library_rwebaudio.js b/emscripten/library_rwebaudio.js index 23142a6b17..a4debaba4f 100644 --- a/emscripten/library_rwebaudio.js +++ b/emscripten/library_rwebaudio.js @@ -1,4 +1,4 @@ -//"use strict"; +"use strict"; var LibraryRWebAudio = { $RA__deps: ['$Browser', 'usleep'], @@ -11,19 +11,33 @@ var LibraryRWebAudio = { bufIndex: 0, bufOffset: 0, startTime: 0, + performance: null, nonblock: false, - currentTimeWorkaround: false, + performanceSupported: false, setStartTime: function() { + RA.performance = window['performance'] || window['webkitPerformance'] || window['msPerformance'] || window['mozPerformance']; + if (RA.performance) { + RA.performanceSupported = true; + } else { + RA.performanceSupported = false; + } + if (RA.context.currentTime) { - RA.startTime = window['performance']['now']() - RA.context.currentTime * 1000; - Module["resumeMainLoop"](); - } else window['setTimeout'](RA.setStartTime, 0); + var now = RA.performanceSupported ? RA.performance.now() : Date.now(); + RA.startTime = now - RA.context.currentTime * 1000; + Module["resumeMainLoop"]; + } else { + window.setTimeout(RA.setStartTime, 0); + } }, getCurrentPerfTime: function() { - if (RA.startTime) return (window['performance']['now']() - RA.startTime) / 1000; - else throw 'getCurrentPerfTime() called before start time set'; + if (true === RA.performanceSupported) { + return (RA.performance.now() - RA.startTime) / 1000; + } else { + return (Date.now() - RA.startTime) / 1000; + } }, process: function(queueBuffers) { @@ -78,11 +92,14 @@ var LibraryRWebAudio = { }, RWebAudioInit: function(latency) { - var ac = window['AudioContext'] || window['webkitAudioContext']; - - if (!ac) return 0; - - RA.context = new ac(); + Module.pauseMainLoop(); + if (!RA.context) { + var ac = window['AudioContext'] || window['webkitAudioContext']; + if (!ac) { + return 0; + } + RA.context = new ac(); + } RA.numBuffers = ((latency * RA.context.sampleRate) / (1000 * RA.BUFFER_SIZE))|0; if (RA.numBuffers < 2) RA.numBuffers = 2; @@ -93,8 +110,8 @@ var LibraryRWebAudio = { RA.startTime = 0; // chrome hack to get currentTime running RA.context.createGain(); - window['setTimeout'](RA.setStartTime, 0); - Module["pauseMainLoop"](); + RA.setStartTime(); + return 1; }, diff --git a/emscripten/library_rwebinput.js b/emscripten/library_rwebinput.js index 7b02bbd834..5d818f7805 100644 --- a/emscripten/library_rwebinput.js +++ b/emscripten/library_rwebinput.js @@ -5,22 +5,13 @@ var LibraryRWebInput = { $RI: { temp: null, contexts: [], + stateX: 0, + stateY: 0, + currentX: 0, + currentY: 0, - eventHandler: function(event) { - var i; + canvasEventHandler: function(event) { switch (event.type) { - case 'mousemove': - var x = event['movementX'] || event['mozMovementX'] || event['webkitMovementX']; - var y = event['movementY'] || event['mozMovementY'] || event['webkitMovementY']; - for (i = 0; i < RI.contexts.length; i++) { - var oldX = {{{ makeGetValue('RI.contexts[i].state', '32', 'i32') }}}; - var oldY = {{{ makeGetValue('RI.contexts[i].state', '36', 'i32') }}}; - x += oldX; - y += oldY; - {{{ makeSetValue('RI.contexts[i].state', '32', 'x', 'i32') }}}; - {{{ makeSetValue('RI.contexts[i].state', '36', 'y', 'i32') }}}; - } - break; case 'mouseup': case 'mousedown': var value; @@ -30,10 +21,53 @@ var LibraryRWebInput = { else break; if (event.type === 'mouseup') value = 0; else value = 1; - for (i = 0; i < RI.contexts.length; i++) { + for (var i = 0; i < RI.contexts.length; i++) { {{{ makeSetValue('RI.contexts[i].state', 'offset', 'value', 'i8') }}}; } break; + } + }, + + eventHandler: function(event) { + var i; + switch (event.type) { + case 'mousemove': + var x = 0; + var y = 0; + + var newX = event['clientX'] - Module.canvas.offsetLeft; + var newY = event['clientY'] - Module.canvas.offsetTop; + + if (newX < 0) { + newX = 0; + x = -Module.canvas.offsetWidth; + } else if (newX > Module.canvas.offsetWidth) { + newX = Module.canvas.offsetWidth; + x = Module.canvas.offsetWidth; + } else { + x = newX - RI.currentX; + } + + if (newY < 0) { + newY = 0; + y = -Module.canvas.offsetHeight; + } else if (newY > Module.canvas.offsetHeight) { + newY = Module.canvas.offsetHeight; + y = Module.canvas.offsetHeight; + } else { + y = newY - RI.currentY; + } + + RI.currentX = newX; + RI.currentY = newY; + + for (i = 0; i < RI.contexts.length; i++) { + {{{ makeSetValue('RI.contexts[i].state', '32', 'x', 'i32') }}}; + {{{ makeSetValue('RI.contexts[i].state', '36', 'y', 'i32') }}}; + } + + break; + case 'keyup': case 'keydown': var key = event.keyCode; @@ -48,6 +82,7 @@ var LibraryRWebInput = { } event.preventDefault(); break; + case 'blur': case 'visibilitychange': for (i = 0; i < RI.contexts.length; i++) { @@ -63,8 +98,8 @@ var LibraryRWebInput = { document.addEventListener('keyup', RI.eventHandler, false); document.addEventListener('keydown', RI.eventHandler, false); document.addEventListener('mousemove', RI.eventHandler, false); - document.addEventListener('mouseup', RI.eventHandler, false); - document.addEventListener('mousedown', RI.eventHandler, false); + Module.canvas.addEventListener('mouseup', RI.canvasEventHandler, false); + Module.canvas.addEventListener('mousedown', RI.canvasEventHandler, false); document.addEventListener('blur', RI.eventHandler, false); document.addEventListener('onvisbilitychange', RI.eventHandler, false); } @@ -95,8 +130,8 @@ var LibraryRWebInput = { document.removeEventListener('keyup', RI.eventHandler, false); document.removeEventListener('keydown', RI.eventHandler, false); document.removeEventListener('mousemove', RI.eventHandler, false); - document.removeEventListener('mouseup', RI.eventHandler, false); - document.removeEventListener('mousedown', RI.eventHandler, false); + Module.canvas.removeEventListener('mouseup', RI.canvasEventHandler, false); + Module.canvas.removeEventListener('mousedown', RI.canvasEventHandler, false); document.removeEventListener('blur', RI.eventHandler, false); document.removeEventListener('onvisbilitychange', RI.eventHandler, false); } diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index 702c96c149..fa6b5351a3 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -20,6 +20,8 @@ #include #include "../../content.h" #include "../frontend.h" +//#include "../../retroarch.h" +//#include "../../runloop.h" #include "../frontend_driver.h" #include "../runloop_data.h" @@ -34,6 +36,27 @@ static void emscripten_mainloop(void) exit(0); } +void cmd_savefiles() +{ + rarch_main_command(RARCH_CMD_SAVEFILES); +} + +void cmd_save_state() +{ + rarch_main_command(RARCH_CMD_SAVE_STATE); +} + +void cmd_load_state() +{ + rarch_main_command(RARCH_CMD_LOAD_STATE); +} + +void cmd_take_screenshot() +{ + rarch_main_command(RARCH_CMD_TAKE_SCREENSHOT); +} + + int main(int argc, char *argv[]) { settings_t *settings = config_get_ptr(); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index d19858eb40..2344dcf609 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -115,10 +115,10 @@ typedef struct video_poke_interface /* Update texture. */ void (*set_texture_frame)(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha); - +#endif /* Enable or disable rendering. */ void (*set_texture_enable)(void *data, bool enable, bool full_screen); -#endif + void (*set_osd_msg)(void *data, const char *msg, const struct font_params *params, void *font); diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index ac2ff56e87..e214d62c6b 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -20,6 +20,7 @@ #include "../input_autodetect.h" #include "../input_common.h" #include "../input_keymaps.h" +//#include "../input_joypad.h" #include "../../driver.h"