From f89eb7e4283f270a6cb8ff1c760f12df08bd0072 Mon Sep 17 00:00:00 2001 From: Grant Galitz Date: Thu, 3 Dec 2015 14:48:57 -0500 Subject: [PATCH] changes for the compat --- IodineGBA/includes/TypedArrayShim.js | 36 +++++++++++++++++++++++++++ user_scripts/IodineGBACoreGlueCode.js | 2 +- user_scripts/IodineGBAWorkerGlueCodeWorker.js | 12 ++++----- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/IodineGBA/includes/TypedArrayShim.js b/IodineGBA/includes/TypedArrayShim.js index ddf3971..3a4ae8e 100644 --- a/IodineGBA/includes/TypedArrayShim.js +++ b/IodineGBA/includes/TypedArrayShim.js @@ -32,6 +32,15 @@ function getUint8View(typed_array) { return null; } } +function getSharedUint8Array(size_t) { + try { + return new Uint8Array(new SharedArrayBuffer(size_t)); + } + catch (error) { + //Compatibility for older Firefox Nightlies: + return new SharedUint8Array(size_t); + } +} function getInt16Array(size_t) { try { return new Int16Array(size_t); @@ -87,6 +96,15 @@ function getInt32ViewCustom(typed_array, start, end) { } } } +function getSharedInt32Array(size_t) { + try { + return new Int32Array(new SharedArrayBuffer(size_t << 2)); + } + catch (error) { + //Compatibility for older Firefox Nightlies: + return new SharedInt32Array(size_t); + } +} function getUint8ViewCustom(typed_array, start, end) { try { typed_array = getUint8View(typed_array); @@ -118,6 +136,24 @@ function getFloat32Array(size_t) { return getArray(size_t); } } +function getSharedFloat32Array(size_t) { + try { + return new Float32Array(new SharedArrayBuffer(size_t << 2)); + } + catch (error) { + //Compatibility for older Firefox Nightlies: + return new SharedFloat32Array(size_t); + } +} +function getSharedFloat64Array(size_t) { + try { + return new Float64Array(new SharedArrayBuffer(size_t << 3)); + } + catch (error) { + //Compatibility for older Firefox Nightlies: + return new SharedFloat64Array(size_t); + } +} function getArray(size_t) { var genericArray = []; for (var size_index = 0; size_index < size_t; ++size_index) { diff --git a/user_scripts/IodineGBACoreGlueCode.js b/user_scripts/IodineGBACoreGlueCode.js index b2886b0..1e01d29 100644 --- a/user_scripts/IodineGBACoreGlueCode.js +++ b/user_scripts/IodineGBACoreGlueCode.js @@ -63,7 +63,7 @@ window.onload = function () { function registerIodineHandler() { try { //Will run like shit if missing some of this for the webworker copy: - if (!window.SharedInt32Array || !Atomics) { + if (!window.SharedArrayBuffer || !Atomics) { throw null; } //Try starting Iodine in a webworker: diff --git a/user_scripts/IodineGBAWorkerGlueCodeWorker.js b/user_scripts/IodineGBAWorkerGlueCodeWorker.js index c820562..2e2860d 100644 --- a/user_scripts/IodineGBAWorkerGlueCodeWorker.js +++ b/user_scripts/IodineGBAWorkerGlueCodeWorker.js @@ -55,15 +55,15 @@ var Iodine = new GameBoyAdvanceEmulator(); //Save callbacks waiting to be satisfied: var saveImportPool = []; //Graphics Buffer: -var gfxBuffer = new SharedUint8Array(160 * 240 * 3); -var gfxLock = new SharedInt32Array(2); +var gfxBuffer = getSharedUint8Array(160 * 240 * 3); +var gfxLock = getSharedInt32Array(2); //Audio Buffers: var audioBuffer = null; var audioBufferSize = 0; -var audioLock = new SharedInt32Array(2); -var audioMetrics = new SharedInt32Array(2); +var audioLock = getSharedInt32Array(2); +var audioMetrics = getSharedInt32Array(2); //Time Stamp tracking: -var timestamp = new SharedFloat64Array(1); +var timestamp = getSharedFloat64Array(1); //Pass the shared array buffers: postMessage({messageID:0, graphicsBuffer:gfxBuffer, gfxLock:gfxLock, audioLock:audioLock, audioMetrics:audioMetrics, timestamp:timestamp}, [gfxBuffer.buffer, gfxLock.buffer, audioLock.buffer, audioMetrics.buffer, timestamp.buffer]); //Event decoding: @@ -158,7 +158,7 @@ var audioHandler = { audioBufferSize = ((bufferLimit | 0) * (channels | 0)) | 0; //Only regen the buffer if we need to make it bigger: if (!audioBuffer || (audioBufferSize | 0) > (audioBuffer.length | 0)) { - audioBuffer = new SharedFloat32Array(audioBufferSize | 0); + audioBuffer = getSharedFloat32Array(audioBufferSize | 0); postMessage({messageID:1, audioBuffer:audioBuffer}, [audioBuffer.buffer]); } postMessage({messageID:2, channels:channels | 0, sampleRate:+sampleRate, bufferLimit:bufferLimit | 0});