diff options
-rw-r--r-- | src/library.js | 4 | ||||
-rw-r--r-- | src/library_sdl.js | 14 | ||||
-rw-r--r-- | src/preamble.js | 3 | ||||
-rw-r--r-- | system/include/emscripten.h | 5 | ||||
-rwxr-xr-x | tests/runner.py | 4 | ||||
-rw-r--r-- | tools/file_packager.py | 30 |
6 files changed, 51 insertions, 9 deletions
diff --git a/src/library.js b/src/library.js index cd18b566..cb94fccb 100644 --- a/src/library.js +++ b/src/library.js @@ -6203,6 +6203,10 @@ LibraryManager.library = { return eval(Pointer_stringify(ptr)); }, + emscripten_random: function() { + return Math.random(); + }, + $Profiling: { max_: 0, times: null, diff --git a/src/library_sdl.js b/src/library_sdl.js index 826f0201..b812fba7 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1024,8 +1024,12 @@ var LibrarySDL = { return 0; }, + 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; + } }, Mix_VolumeMusic: function(func) { @@ -1036,12 +1040,14 @@ var LibrarySDL = { Mix_FreeMusic: 'Mix_FreeChunk', + Mix_PlayMusic__deps: ['Mix_HaltMusic'], Mix_PlayMusic: function(id, loops) { loops = Math.max(loops, 1); var audio = SDL.audios[id].audio; if (!audio) return 0; audio.loop = loops != 1; // TODO: handle N loops for finite N audio.play(); + audio['onended'] = _Mix_HaltMusic; // will send callback SDL.music = audio; return 0; }, @@ -1076,6 +1082,14 @@ var LibrarySDL = { Mix_FadeOutMusic: 'Mix_HaltMusic', // XXX ignore fading out effect + Mix_PlayingMusic: function() { + return (SDL.music && !SDL.music.paused) ? 1 : 0; + }, + + Mix_PausedMusic: function() { + return (SDL.music && SDL.music.paused) ? 1 : 0; + }, + // SDL TTF TTF_Init: function() { return 0 }, diff --git a/src/preamble.js b/src/preamble.js index 541b4bb5..ae00b796 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -326,6 +326,7 @@ function ccall(ident, returnType, argTypes, args) { var stack = 0; function toC(value, type) { if (type == 'string') { + if (value === null || value === undefined || value === 0) return 0; // null string if (!stack) stack = Runtime.stackSave(); var ret = Runtime.stackAlloc(value.length+1); writeStringToMemory(value, ret); @@ -819,6 +820,7 @@ function addRunDependency() { Module['monitorRunDependencies'](runDependencies); } } +Module['addRunDependency'] = addRunDependency; function removeRunDependency() { runDependencies--; if (Module['monitorRunDependencies']) { @@ -826,6 +828,7 @@ function removeRunDependency() { } if (runDependencies == 0) run(); } +Module['removeRunDependency'] = removeRunDependency; // === Body === diff --git a/system/include/emscripten.h b/system/include/emscripten.h index 4da31ec3..70524835 100644 --- a/system/include/emscripten.h +++ b/system/include/emscripten.h @@ -80,6 +80,11 @@ void emscripten_set_canvas_size(int width, int height); float emscripten_get_now(); /* + * Simple random number generation in [0, 1), maps to Math.random(). + */ +float emscripten_random(); + +/* * This macro-looking function will cause Emscripten to * generate a comment in the generated code. * XXX This is deprecated for now, because it requires us to diff --git a/tests/runner.py b/tests/runner.py index 20034f95..306dd04c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6837,6 +6837,10 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt']).communicate() self.assertContained('|hello from a file wi|', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + # preload twice, should not err + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt', '--embed-file', 'somefile.txt']).communicate() + self.assertContained('|hello from a file wi|', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_multidynamic_link(self): # Linking the same dynamic library in will error, normally, since we statically link it, causing dupe symbols # A workaround is to use --ignore-dynamic-linking, see emcc --help for details diff --git a/tools/file_packager.py b/tools/file_packager.py index b4512938..4f24af28 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -62,7 +62,11 @@ for arg in sys.argv[1:]: Compression.js_name = arg in_compress = 0 -code = '' +code = ''' +function assert(check, msg) { + if (!check) throw msg; +} +''' if has_preloaded: code += ''' @@ -97,6 +101,14 @@ for file_ in data_files: file_['name'] = file_['name'].replace(os.path.sep, '/') file_['net_name'] = file_['name'] +# remove duplicates (can occur naively, for example preload dir/, preload dir/subdir/) +seen = {} +def was_seen(name): + if seen.get(name): return True + seen[name] = 1 + return False +data_files = filter(lambda file_: not was_seen(file_['name']), data_files) + data_target = sys.argv[1] # Set up folders @@ -167,7 +179,7 @@ for file_ in data_files: ctx.drawImage(img, 0, 0); Module["preloadedImages"]['%(filename)s'] = canvas; URLObject.revokeObjectURL(url); - removeRunDependency(); + Module['removeRunDependency'](); }; img.onerror = function(event) { console.log('Image %(filename)s could not be decoded'); @@ -186,14 +198,14 @@ for file_ in data_files: audio['oncanplaythrough'] = null; Module["preloadedAudios"]['%(filename)s'] = audio; if (!audio.removedDependency) { - removeRunDependency(); + Module['removeRunDependency'](); audio.removedDependency = true; } }; audio.onerror = function(event) { if (!audio.removedDependency) { console.log('Audio %(filename)s could not be decoded or timed out trying to decode'); - removeRunDependency(); + Module['removeRunDependency'](); audio.removedDependency = true; } }; @@ -201,11 +213,11 @@ for file_ in data_files: audio.src = url; } else { Module["preloadedAudios"]['%(filename)s'] = new Audio(); // empty shim - removeRunDependency(); + Module['removeRunDependency'](); } ''' % { 'filename': filename, 'mimetype': AUDIO_MIMETYPES[suffix(filename)] } else: - finish = 'removeRunDependency();\n' + finish = "Module['removeRunDependency']();\n" code += ''' var %(varname)s = new %(request)s(); @@ -218,7 +230,7 @@ for file_ in data_files: Module['FS_createDataFile']('/%(dirname)s', '%(basename)s', byteArray, true, true); %(finish)s }; - addRunDependency(); + Module['addRunDependency'](); %(varname)s.send(null); ''' % { 'request': 'DataRequest', # In the past we also supported XHRs here @@ -242,7 +254,7 @@ if has_preloaded: curr.response = byteArray.subarray(%d,%d); curr.onload(); ''' % (file_['name'], file_['data_start'], file_['data_end']) - use_data += ' removeRunDependency();\n' + use_data += " Module['removeRunDependency']();\n" if Compression.on: use_data = ''' @@ -263,7 +275,7 @@ if has_preloaded: var curr; %s }; - addRunDependency(); + Module['addRunDependency'](); dataFile.send(null); if (Module['setStatus']) Module['setStatus']('Downloading...'); ''' % (Compression.compressed_name(data_target) if Compression.on else data_target, use_data) |