mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
Merge pull request #667 from orsi/doublespeakgames
Major optimization of audio size and safari audio fix
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+29
-5
@@ -12,15 +12,21 @@ var AudioEngine = {
|
||||
_initialized: false,
|
||||
init: function () {
|
||||
AudioEngine._initAudioContext();
|
||||
// AudioEngine._preloadAudio(); // removed to save bandwidth
|
||||
AudioEngine._initialized = true;
|
||||
},
|
||||
_preloadAudio: function () {
|
||||
// start loading music and events early
|
||||
// ** could be used later if we specify a better set of
|
||||
// audio files to preload -- i.e. we probably don't need to load
|
||||
// the later villages or events audio, and esp. not the ending
|
||||
for (var key in AudioLibrary) {
|
||||
if (
|
||||
if (
|
||||
key.toString().indexOf('MUSIC_') > -1 ||
|
||||
key.toString().indexOf('EVENT_') > -1) {
|
||||
AudioEngine.loadAudioFile(AudioLibrary[key]);
|
||||
AudioEngine.loadAudioFile(AudioLibrary[key]);
|
||||
}
|
||||
}
|
||||
AudioEngine._initialized = true;
|
||||
},
|
||||
_initAudioContext: function () {
|
||||
AudioEngine._audioContext = new (window.AudioContext || window.webkitAudioContext);
|
||||
@@ -136,7 +142,9 @@ var AudioEngine = {
|
||||
var fadeTime = AudioEngine._audioContext.currentTime + AudioEngine.FADE_TIME * 2;
|
||||
|
||||
// fade out event music and stop
|
||||
if (AudioEngine._currentEventAudio) {
|
||||
if (AudioEngine._currentEventAudio &&
|
||||
AudioEngine._currentEventAudio.source &&
|
||||
AudioEngine._currentEventAudio.source.buffer) {
|
||||
var currentEventGainValue = AudioEngine._currentEventAudio.envelope.gain.value;
|
||||
AudioEngine._currentEventAudio.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
|
||||
AudioEngine._currentEventAudio.envelope.gain.setValueAtTime(currentEventGainValue, AudioEngine._audioContext.currentTime);
|
||||
@@ -212,10 +220,26 @@ var AudioEngine = {
|
||||
return AudioEngine._getMissingAudioBuffer();
|
||||
}
|
||||
|
||||
return AudioEngine._audioContext.decodeAudioData(buffer, function (decodedData) {
|
||||
var decodeAudioDataPromise = AudioEngine._audioContext.decodeAudioData(buffer, function (decodedData) {
|
||||
AudioEngine.AUDIO_BUFFER_CACHE[src] = decodedData;
|
||||
return AudioEngine.AUDIO_BUFFER_CACHE[src];
|
||||
});
|
||||
|
||||
// Safari WebAudio does not return a promise based API for
|
||||
// decodeAudioData, so we need to fake it if we want to play
|
||||
// audio immediately on first fetch
|
||||
if (decodeAudioDataPromise) {
|
||||
return decodeAudioDataPromise;
|
||||
} else {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var fakePromiseId = setInterval(function() {
|
||||
if (AudioEngine.AUDIO_BUFFER_CACHE[src]) {
|
||||
resolve(AudioEngine.AUDIO_BUFFER_CACHE[src]);
|
||||
clearInterval(fakePromiseId);
|
||||
}
|
||||
}, 20);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
+21
-15
@@ -104,6 +104,15 @@
|
||||
Engine.loadGame();
|
||||
}
|
||||
|
||||
// start loading music and events early
|
||||
for (var key in AudioLibrary) {
|
||||
if (
|
||||
key.toString().indexOf('MUSIC_') > -1 ||
|
||||
key.toString().indexOf('EVENT_') > -1) {
|
||||
AudioEngine.loadAudioFile(AudioLibrary[key]);
|
||||
}
|
||||
}
|
||||
|
||||
$('<div>').attr('id', 'locationSlider').appendTo('#main');
|
||||
|
||||
var menu = $('<div>')
|
||||
@@ -133,12 +142,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Disable this for now
|
||||
// $('<span>')
|
||||
// .addClass('volume menuBtn')
|
||||
// .text(_('sound on.'))
|
||||
// .click(() => Engine.toggleVolume())
|
||||
// .appendTo(menu);
|
||||
$('<span>')
|
||||
.addClass('volume menuBtn')
|
||||
.text(_('sound on.'))
|
||||
.click(() => Engine.toggleVolume())
|
||||
.appendTo(menu);
|
||||
|
||||
$('<span>')
|
||||
.addClass('appStore menuBtn')
|
||||
@@ -207,7 +215,7 @@
|
||||
$.Dispatch('stateUpdate').subscribe(Engine.handleStateUpdates);
|
||||
|
||||
$SM.init();
|
||||
// AudioEngine.init(); Disable this for now
|
||||
AudioEngine.init();
|
||||
Notifications.init();
|
||||
Events.init();
|
||||
Room.init();
|
||||
@@ -231,24 +239,22 @@
|
||||
Engine.triggerHyperMode();
|
||||
}
|
||||
|
||||
// Disable this for now
|
||||
// Engine.toggleVolume(Boolean($SM.get('config.soundOn')));
|
||||
// if(!AudioEngine.isAudioContextRunning()){
|
||||
// document.addEventListener('click', Engine.resumeAudioContext, true);
|
||||
// }
|
||||
Engine.toggleVolume(Boolean($SM.get('config.soundOn')));
|
||||
if(!AudioEngine.isAudioContextRunning()){
|
||||
document.addEventListener('click', Engine.resumeAudioContext, true);
|
||||
}
|
||||
|
||||
Engine.saveLanguage();
|
||||
Engine.travelTo(Room);
|
||||
|
||||
// Disable this for now
|
||||
// setTimeout(notifyAboutSound, 3000);
|
||||
setTimeout(notifyAboutSound, 3000);
|
||||
|
||||
},
|
||||
resumeAudioContext: function () {
|
||||
AudioEngine.tryResumingAudioContext();
|
||||
|
||||
// turn on music!
|
||||
AudioEngine.setMasterVolume($SM.get('config.soundOn') ? 1.0 : 0.0, 0);
|
||||
AudioEngine.setMasterVolume($SM.get('config.soundOn') ? 1.0 : 0.0, 0);
|
||||
|
||||
document.removeEventListener('click', Engine.resumeAudioContext);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user