diff options
-rwxr-xr-x | tests/runner.py | 2 | ||||
-rw-r--r-- | tools/crunch-worker.js (renamed from tools/crunch.js) | 13 | ||||
-rw-r--r-- | tools/file_packager.py | 40 |
3 files changed, 43 insertions, 12 deletions
diff --git a/tests/runner.py b/tests/runner.py index 995cd770..5372034e 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7337,7 +7337,7 @@ elif 'browser' in str(sys.argv): }; Module['postRun'] = doReftest; Module['preRun'].push(function() { - setTimeout(doReftest, 0); // if run() throws an exception and postRun is not called, this will kick in + setTimeout(doReftest, 1000); // if run() throws an exception and postRun is not called, this will kick in }); ''' % basename) diff --git a/tools/crunch.js b/tools/crunch-worker.js index 36e2517a..dd39c5ca 100644 --- a/tools/crunch.js +++ b/tools/crunch-worker.js @@ -6,8 +6,6 @@ // This combines crunch-worker.js and crn_decomp.js. Minor changes // to make it work that way, and to return all levels in one array -var deCrunch = (function(Module) { - /* * Copyright (c) 2012 Brandon Jones * @@ -55,7 +53,7 @@ var deCrunch = (function(Module) { dst.set(src.subarray(0, numBytes), dstByteOffset); } - function deCrunch_(bytes) { + function deCrunch(bytes) { var srcSize = bytes.length; var src = Module._malloc(srcSize), format, internalFormat, dst, dstSize, @@ -105,7 +103,10 @@ function a(b){throw b}var aa=void 0,l=!0,pa=null,n=!1,za=[],Da="object"===typeof //=== - return deCrunch_; - -}).call({}, {}); +onmessage = function(msg) { + postMessage({ + data: deCrunch(new Uint8Array(msg.data.data)), + callbackID: msg.data.callbackID + }); +}; diff --git a/tools/file_packager.py b/tools/file_packager.py index 0cef3bcb..0832c1b3 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -16,6 +16,8 @@ Notes: --crunch=X Will compress dxt files to crn with quality level X. The crunch commandline tool must be present and CRUNCH should be defined in ~/.emscripten that points to it. JS crunch decompressing code will be added to convert the crn to dds in the browser. + crunch-worker.js will be generated in the current directory. You should include that file when + packaging your site. TODO: You can also provide .crn files yourself, pre-crunched. With this option, they will be decompressed to dds files in the browser, exactly the same as if this tool compressed them. @@ -134,7 +136,22 @@ data_files = filter(lambda file_: not was_seen(file_['name']), data_files) # Crunch files if crunch: - print open(shared.path_from_root('tools', 'crunch.js')).read() + shutil.copyfile(shared.path_from_root('tools', 'crunch-worker.js'), 'crunch-worker.js') + print ''' + var decrunchWorker = new Worker('crunch-worker.js'); + var decrunchCallbacks = []; + decrunchWorker.onmessage = function(msg) { + decrunchCallbacks[msg.data.callbackID](msg.data.data); + decrunchCallbacks[msg.data.callbackID] = null; + }; + function requestDecrunch(data, callback) { + decrunchWorker.postMessage({ + data: data, + callbackID: decrunchCallbacks.length + }); + decrunchCallbacks.push(callback); + } +''' for file_ in data_files: if file_['name'].endswith(CRUNCH_INPUT_SUFFIX): @@ -263,12 +280,17 @@ for file_ in data_files: # decompress crunch format into dds prepare = ''' var ddsHeader = byteArray.subarray(0, %(dds_header_size)d); - var ddsData = deCrunch(byteArray.subarray(%(dds_header_size)d)); - byteArray = new Uint8Array(ddsHeader.length + ddsData.length); - byteArray.set(ddsHeader, 0); - byteArray.set(ddsData, %(dds_header_size)d); + requestDecrunch(byteArray.subarray(%(dds_header_size)d), function(ddsData) { + byteArray = new Uint8Array(ddsHeader.length + ddsData.length); + byteArray.set(ddsHeader, 0); + byteArray.set(ddsData, %(dds_header_size)d); ''' % { 'dds_header_size': DDS_HEADER_SIZE } + finish = ''' + Module['removeRunDependency'](); + }); +''' + code += ''' var %(varname)s = new %(request)s(); %(varname)s.open('GET', '%(filename)s', true); @@ -343,3 +365,11 @@ print code if pre_run: print ' });\n' +if crunch: + print ''' + if (!Module['postRun']) Module['postRun'] = []; + Module["postRun"].push(function() { + decrunchWorker.terminate(); + }); +''' + |