diff options
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r-- | src/library_sdl.js | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index e940cffa..41898056 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -16,9 +16,14 @@ var LibrarySDL = { surfaces: {}, events: [], - audios: [null], fonts: [null], + audios: [null], + music: { + audio: null, + volume: 1.0 + }, + keyboardState: null, shiftKey: false, ctrlKey: false, @@ -498,6 +503,16 @@ var LibrarySDL = { } }, + setGetVolume: function(info, volume) { + if (!info) return 0; + var ret = info.volume * 128; // MIX_MAX_VOLUME + if (volume != -1) { + info.volume = volume / 128; + if (info.audio) info.audio.volume = info.volume; + } + return ret; + }, + // Debugging debugSurface: function(surfData) { @@ -600,6 +615,10 @@ var LibrarySDL = { return SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen'); }, + SDL_GetVideoSurface: function() { + return SDL.screen; + }, + SDL_QuitSubSystem: function(flags) { Module.print('SDL_QuitSubSystem called (and ignored)'); }, @@ -1039,6 +1058,9 @@ var LibrarySDL = { SDL_CondWait: function() {}, SDL_DestroyCond: function() {}, + SDL_StartTextInput: function() {}, // TODO + SDL_StopTextInput: function() {}, // TODO + // SDL Mixer Mix_OpenAudio: function(frequency, format, channels, chunksize) { @@ -1058,11 +1080,13 @@ var LibrarySDL = { }, Mix_Volume: function(channel, volume) { - var info = SDL.channels[channel]; - var ret = info.volume * 128; - info.volume = volume / 128; - if (info.audio) info.audio.volume = info.volume; - return ret; + if (channel == -1) { + for (var i = 0; i < SDL.numChannels-1; i++) { + _Mix_Volume(i, volume); + } + return _Mix_Volume(SDL.numChannels-1, volume); + } + return SDL.setGetVolume(SDL.channels[channel], volume); }, Mix_SetPanning: function() { @@ -1133,13 +1157,13 @@ var LibrarySDL = { Mix_HookMusicFinished__deps: ['Mix_HaltMusic'], Mix_HookMusicFinished: function(func) { SDL.hookMusicFinished = func; - if (SDL.music) { // ensure the callback will be called, if a music is already playing - SDL.music['onended'] = _Mix_HaltMusic; + if (SDL.music.audio) { // ensure the callback will be called, if a music is already playing + SDL.music.audio['onended'] = _Mix_HaltMusic; } }, - Mix_VolumeMusic: function(func) { - return 0; // TODO + Mix_VolumeMusic: function(volume) { + return SDL.setGetVolume(SDL.music, volume); }, Mix_LoadMUS: 'Mix_LoadWAV_RW', @@ -1153,31 +1177,32 @@ var LibrarySDL = { if (!audio) return 0; audio.loop = loops != 1; // TODO: handle N loops for finite N audio.play(); + audio.volume = SDL.music.volume; audio['onended'] = _Mix_HaltMusic; // will send callback - SDL.music = audio; + SDL.music.audio = audio; return 0; }, - Mix_PauseMusic: function(id) { - var audio = SDL.audios[id]; + Mix_PauseMusic: function() { + var audio = SDL.music.audio; if (!audio) return 0; - audio.audio.pause(); + audio.pause(); return 0; }, - Mix_ResumeMusic: function(id) { - var audio = SDL.audios[id]; + Mix_ResumeMusic: function() { + var audio = SDL.music.audio; if (!audio) return 0; - audio.audio.play(); + audio.play(); return 0; }, Mix_HaltMusic: function() { - var audio = SDL.music; + var audio = SDL.music.audio; if (!audio) return 0; audio.src = audio.src; // rewind audio.pause(); - SDL.music = null; + SDL.music.audio = null; if (SDL.hookMusicFinished) { FUNCTION_TABLE[SDL.hookMusicFinished](); } @@ -1189,11 +1214,11 @@ var LibrarySDL = { Mix_FadeOutMusic: 'Mix_HaltMusic', // XXX ignore fading out effect Mix_PlayingMusic: function() { - return (SDL.music && !SDL.music.paused) ? 1 : 0; + return (SDL.music.audio && !SDL.music.audio.paused) ? 1 : 0; }, Mix_PausedMusic: function() { - return (SDL.music && SDL.music.paused) ? 1 : 0; + return (SDL.music.audio && SDL.music.audio.paused) ? 1 : 0; }, // SDL TTF |