diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 5 | ||||
-rw-r--r-- | src/library.js | 13 | ||||
-rw-r--r-- | src/library_gc.js | 14 | ||||
-rw-r--r-- | src/library_gl.js | 13 | ||||
-rw-r--r-- | src/library_sdl.js | 18 | ||||
-rw-r--r-- | src/postamble.js | 4 | ||||
-rw-r--r-- | src/preamble.js | 3 | ||||
-rw-r--r-- | src/settings.js | 2 |
8 files changed, 48 insertions, 24 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 1d18f292..e76407b2 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -71,10 +71,7 @@ function JSify(data, functionsOnly, givenFunctions) { } } } else { - libFuncsToInclude = ['memcpy', 'memset', 'malloc', 'free']; - } - if (GENERATING_HTML) { - libFuncsToInclude.push('$Browser'); + libFuncsToInclude = ['memcpy', 'memset', 'malloc', 'free', '$Browser']; } libFuncsToInclude.forEach(function(ident) { data.functionStubs.push({ diff --git a/src/library.js b/src/library.js index 9ebe926a..cb94fccb 100644 --- a/src/library.js +++ b/src/library.js @@ -28,7 +28,14 @@ LibraryManager.library = { $FS__deps: ['$ERRNO_CODES', '__setErrNo', 'stdin', 'stdout', 'stderr', '_impure_ptr'], $FS__postset: '__ATINIT__.unshift({ func: function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() } });' + '__ATMAIN__.push({ func: function() { FS.ignorePermissions = false } });' + - '__ATEXIT__.push({ func: function() { FS.quit() } });', + '__ATEXIT__.push({ func: function() { FS.quit() } });' + + // export some names through closure + 'Module["FS_createFolder"] = FS.createFolder;' + + 'Module["FS_createPath"] = FS.createPath;' + + 'Module["FS_createDataFile"] = FS.createDataFile;' + + 'Module["FS_createLazyFile"] = FS.createLazyFile;' + + 'Module["FS_createLink"] = FS.createLink;' + + 'Module["FS_createDevice"] = FS.createDevice;', $FS: { // The path to the current folder. currentPath: '/', @@ -6196,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_gc.js b/src/library_gc.js index ccf6656d..bf0a6aff 100644 --- a/src/library_gc.js +++ b/src/library_gc.js @@ -16,13 +16,15 @@ if (GC_SUPPORT) { init: function() { assert(!GC.initted); GC.initted = true; -#if GENERATING_HTML - setInterval(function() { - GC.maybeCollect(); - }, 1000); -#else - // No HTML intervals, so you need to call GC.maybeCollect() or GC.collect() manually + if (ENVIRONMENT_IS_WEB) { + setInterval(function() { + GC.maybeCollect(); + }, 1000); + } else { +#if ASSERTIONS + Module.print('No HTML intervals, so you need to call GC.maybeCollect() or GC.collect() manually'); #endif + } }, malloc: function(bytes, clear, scannable) { diff --git a/src/library_gl.js b/src/library_gl.js index 153473f1..1b6ec5c0 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -897,13 +897,14 @@ var LibraryGL = { // XXX some of these ignored capabilities may lead to incorrect rendering, if we do not emulate them in shaders var ignoredCapabilities = { - 0x0DE1: 1, // GL_TEXTURE_2D 0x0B20: 1, // GL_LINE_SMOOTH 0x0B60: 1, // GL_FOG - 0x8513: 1, // GL_TEXTURE_CUBE_MAP 0x0BA1: 1, // GL_NORMALIZE 0x0C60: 1, // GL_TEXTURE_GEN_S - 0x0C61: 1 // GL_TEXTURE_GEN_T + 0x0C61: 1, // GL_TEXTURE_GEN_T + 0x0DE1: 1, // GL_TEXTURE_2D + 0x8513: 1, // GL_TEXTURE_CUBE_MAP + 0x2A02: 1 // GL_POLYGON_OFFSET_LINE }; _glEnable = function(cap) { // Clean up the renderer on any change to the rendering state. The optimization of @@ -1683,7 +1684,9 @@ var LibraryGL = { // Initialize matrix library GL.immediate.matrix['m'] = GL.immediate.matrix.lib.mat4.create(); + GL.immediate.matrix.lib.mat4.identity(GL.immediate.matrix['m']); GL.immediate.matrix['p'] = GL.immediate.matrix.lib.mat4.create(); + GL.immediate.matrix.lib.mat4.identity(GL.immediate.matrix['p']); for (var i = 0; i < GL.immediate.MAX_TEXTURES; i++) { GL.immediate.matrix['t' + i] = GL.immediate.matrix.lib.mat4.create(); } @@ -2220,8 +2223,8 @@ var LibraryGL = { // Simple pass-through functions. Starred ones have return values. [X] ones have X in the C name but not in the JS name [[0, 'shadeModel getError* finish flush'], - [1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation polygonOffset sampleCoverage isEnabled*'], - [2, 'blendFunc blendEquationSeparate depthRange depthRange[f] stencilMaskSeparate hint'], + [1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation sampleCoverage isEnabled*'], + [2, 'blendFunc blendEquationSeparate depthRange depthRange[f] stencilMaskSeparate hint polygonOffset'], [3, 'texParameteri texParameterf drawArrays vertexAttrib2f stencilFunc stencilOp'], [4, 'viewport clearColor scissor vertexAttrib3f colorMask drawElements renderbufferStorage blendFuncSeparate blendColor stencilFuncSeparate stencilOpSeparate'], [5, 'vertexAttrib4f'], diff --git a/src/library_sdl.js b/src/library_sdl.js index 7011e679..6250d6e3 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -934,7 +934,7 @@ var LibrarySDL = { // Convert the path to relative filename = filename.substr(1); } - var raw = preloadedImages[filename]; + var raw = Module["preloadedImages"][filename]; if (!raw) { Runtime.warnOnce('Cannot find preloaded image ' + filename); return 0; @@ -1058,7 +1058,7 @@ var LibrarySDL = { Mix_LoadWAV_RW: function(filename, freesrc) { filename = FS.standardizePath(Pointer_stringify(filename)); - var raw = preloadedAudios[filename]; + var raw = Module["preloadedAudios"][filename]; if (!raw) { Runtime.warnOnce('Cannot find preloaded audio ' + filename); return 0; @@ -1117,8 +1117,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) { @@ -1129,12 +1133,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; }, @@ -1169,6 +1175,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/postamble.js b/src/postamble.js index ea03391c..56586487 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -56,7 +56,6 @@ function run(args) { return ret; } -#if GENERATING_HTML if (Module['setStatus']) { Module['setStatus']('Running...'); setTimeout(function() { @@ -69,9 +68,6 @@ function run(args) { } else { return doRun(); } -#else - return doRun(); -#endif } Module['run'] = run; 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/src/settings.js b/src/settings.js index e0286213..2526081b 100644 --- a/src/settings.js +++ b/src/settings.js @@ -205,8 +205,6 @@ var LINKABLE = 0; // If set to 1, this file can be linked with others, either as // LINKABLE of 0 is very useful in that we can reduce the size of the // generated code very significantly, by removing everything not actually used. -var GENERATING_HTML = 0; // Set to 1 when generating .html and not just .js - var RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time. This // increases the size of the generated script, but allows you // to more easily perform operations from handwritten JS on |