Backport this - 58748da89d

This commit is contained in:
twinaphex 2015-07-27 00:08:14 +02:00
parent 4b234a4ed9
commit 4787c463b6
7 changed files with 119 additions and 39 deletions

View File

@ -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)
@ -111,4 +116,3 @@ clean:
rm -f *.d
.PHONY: all clean

View File

@ -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);

View File

@ -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;
},

View File

@ -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);
}

View File

@ -20,6 +20,8 @@
#include <file/config_file.h>
#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(void)
{
rarch_main_command(RARCH_CMD_SAVEFILES);
}
void cmd_save_state(void)
{
rarch_main_command(RARCH_CMD_SAVE_STATE);
}
void cmd_load_state(void)
{
rarch_main_command(RARCH_CMD_LOAD_STATE);
}
void cmd_take_screenshot(void)
{
rarch_main_command(RARCH_CMD_TAKE_SCREENSHOT);
}
int main(int argc, char *argv[])
{
settings_t *settings = config_get_ptr();

View File

@ -115,10 +115,9 @@ 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);

View File

@ -25,7 +25,6 @@
#include "../../general.h"
#include "../keyboard_line.h"
#include "../input_joypad.h"
typedef struct rwebinput_state
{