diff --git a/WebAssembly/ZillaLibWasm.js b/WebAssembly/ZillaLibWasm.js index a6bb159..1273f81 100644 --- a/WebAssembly/ZillaLibWasm.js +++ b/WebAssembly/ZillaLibWasm.js @@ -135,7 +135,7 @@ function SYSCALLS_WASM_IMPORTS(env, wasi) var PAYLOAD = (ZL.files ? Base64Decode(ZL.files) : new Uint8Array(0)); delete ZL.files; - env.__syscall5 = function(which, varargs) // open (only used to open payload) + env.__sys_open = env.__syscall5 = function(which, varargs) // open (only used to open payload) { PAYLOAD_CURSOR = 0; //var getVarArgs; @@ -204,7 +204,7 @@ function SYSCALLS_WASM_IMPORTS(env, wasi) return 0; }; - env.__syscall221 = env.__syscall54 = function(which, varargs) // fcntl64, ioctl + env.__sys_fcntl64 = env.__sys_ioctl = env.__syscall221 = env.__syscall54 = function(which, varargs) // fcntl64, ioctl { return 0; }; @@ -1286,7 +1286,7 @@ env.sqrt = env.sqrtf = Math.sqrt; env.atan = env.atanf = Math.atan; env.atan2 = env.atan2f = Math.atan2; env.fabs = env.fabsf = env.abs = Math.abs; -env.round = env.roundf = env.rint = env.rintf = Math.round; +env.round = env.roundf = env.rint = env.rintf = Math.round; ZLJS_WASM_IMPORTS(env); GL_WASM_IMPORTS(env); @@ -1331,10 +1331,12 @@ WASM_HEAP = wasmHeapBase; WASM_MEMORY = env.memory = new WebAssembly.Memory({initial: wasmMemInitial>>16, maximum: WASM_HEAP_MAX>>16 }); updateGlobalBufferViews(); +// Instantiate the wasm module by passing the prepared env and wasi objects containing import functions for the wasm module WebAssembly.instantiate(wasmBytes, {env:env,wasi_unstable:wasi,wasi_snapshot_preview1:wasi,wasi:wasi}).then(function (output) { + // Store the list of the functions exported by the wasm module in ZL.asm ZL.asm = output.instance.exports; - + // Store the argument list with 1 entry at the far end of the stack to pass to main var argc = 1, argv = wasmStackTop, exe = 'zl'; stringToUTF8Array(exe, HEAP8, (HEAPU32[(argv+0)>>2] = (argv+8)), 256); HEAPU32[(argv+4) >> 2] = 0; @@ -1345,6 +1347,7 @@ WebAssembly.instantiate(wasmBytes, {env:env,wasi_unstable:wasi,wasi_snapshot_pre }) .catch(function (err) { + // On an exception, if the err is 'abort' the error was already processed in the abort function above if (err !== 'abort') abort('BOOT', 'WASM instiantate error: ' + err + (err.stack ? "\n" + err.stack : '')); }); diff --git a/WebAssembly/ZillaLibWasm.minified.js b/WebAssembly/ZillaLibWasm.minified.js index 4904009..c2f5fe3 100644 --- a/WebAssembly/ZillaLibWasm.minified.js +++ b/WebAssembly/ZillaLibWasm.minified.js @@ -1 +1 @@ -!function(){'use strict';function e(e,t){throw _=!0,ZL.error(e,t),'abort'}function t(){var e=m.buffer;f=new Int8Array(e),new Int16Array(e),l=new Int32Array(e),u=new Uint8Array(e),c=new Uint16Array(e),s=new Uint32Array(e),g=new Float32Array(e)}function n(e){var t,n;for(e=unescape(encodeURIComponent(e)),n=ZL.asm.malloc(e.length+1),t=0;t=r)return 0;for(a=e,o=t,f=i=n,u=i+r-1,c=0;c=55296&&57343>=l&&(l=65536+((1023&l)<<10)|1023&a.charCodeAt(++c)),l>127)if(l>2047)if(l>65535)if(l>2097151)if(l>67108863){if(i+5>=u)break;o[i++]=252|l>>30,o[i++]=128|l>>24&63,o[i++]=128|l>>18&63,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+4>=u)break;o[i++]=248|l>>24,o[i++]=128|l>>18&63,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+3>=u)break;o[i++]=240|l>>18,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+2>=u)break;o[i++]=224|l>>12,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+1>=u)break;o[i++]=192|l>>6,o[i++]=128|63&l}else{if(i>=u)break;o[i++]=l}return o[i]=0,i-f}function o(e,t){var n,r,a,o,i,f,c,l,s,g,m,d,h,L;if(0===t||!e)return'';for(n=0,a=0;n|=r=u[e+a>>0],(0!=r||t)&&(a++,!t||a!=t););if(t||(t=a),128&n)for(o=u,i=e,f=e+t,c=String.fromCharCode,h='';;){if(i==f||!(l=o[i++]))return h;128&l?(s=63&o[i++],192!=(224&l)?(a=63&o[i++],224==(240&l)?l=(15&l)<<12|s<<6|a:(g=63&o[i++],240==(248&l)?l=(7&l)<<18|s<<12|a<<6|g:(m=63&o[i++],l=248==(252&l)?(3&l)<<24|s<<18|a<<12|g<<6|m:(1&l)<<30|s<<24|a<<18|g<<12|m<<6|(r=63&o[i++]))),h+=65536>l?c(l):c(55296|(d=l-65536)>>10,56320|1023&d)):h+=c((31&l)<<6|s)):h+=c(l)}for(L='';t>0;e+=1024,t-=1024)L+=String.fromCharCode.apply(String,u.subarray(e,e+Math.min(t,1024)));return L}function i(e){var t,n,r,a,o,i,f,u=new Uint8Array(128),c=function(n){return u[e.charCodeAt(t+n)]};for(t=0;64>t;t++)u['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charCodeAt(t)]=t;for(u[45]=62,u[95]=63,n=e.length,r='='===e[n-2]?2:'='===e[n-1]?1:0,a=new Uint8Array(3*n/4-r),o=0,i=r>0?n-4:n,f=0,t=0;i>t;t+=4)f=c(0)<<18|c(1)<<12|c(2)<<6|c(3),a[o++]=f>>16&255,a[o++]=f>>8&255,a[o++]=255&f;return 1===r?(f=c(0)<<10|c(1)<<4|c(2)>>2,a[o]=f>>8&255,a[o+1]=255&f):2===r&&(a[o]=255&(c(0)<<2|c(1)>>4)),a}var f,u,c,l,s,g,m,d,h,L,b,v,Z,w,y,x,_=!1;ZL.print=ZL.print||function(e){console.log(e)},ZL.error=ZL.error||function(e,t){ZL.print('[ERROR] '+e+': '+t)},ZL.started=ZL.started||function(){},b={},(L={sbrk:function(n){var r=d,a=r+n,o=a-m.buffer.byteLength;return a>268435456&&e('MEM','Out of memory'),o>0&&(m.grow(o+65535>>16),t()),d=a,0|r},time:function(e){var t=Date.now()/1e3|0;return e&&(l[e>>2]=t),t},gettimeofday:function(e){var t=Date.now();l[e>>2]=t/1e3|0,l[e+4>>2]=t%1e3*1e3|0},__assert_fail:function(t,n,r,a){e('CRASH','Assert '+o(t)+', at: '+(n?o(n):'unknown filename'),a&&o(a))},__cxa_uncaught_exception:function(){e('CRASH','Uncaught exception!')},__cxa_pure_virtual:function(){e('CRASH','pure virtual')},abort:function(){e('CRASH','Abort called')},longjmp:function(){e('CRASH','Unsupported longjmp called')}}).setjmp=L.__cxa_atexit=L.__lock=L.__unlock=function(){},L.ceil=L.ceilf=Math.ceil,L.exp=L.expf=Math.exp,L.floor=L.floorf=Math.floor,L.log=L.logf=Math.log,L.pow=L.powf=Math.pow,L.cos=L.cosf=Math.cos,L.sin=L.sinf=Math.sin,L.tan=L.tanf=Math.tan,L.acos=L.acosf=Math.acos,L.asin=L.asinf=Math.asin,L.sqrt=L.sqrtf=Math.sqrt,L.atan=L.atanf=Math.atan,L.atan2=L.atan2f=Math.atan2,L.fabs=L.fabsf=L.abs=Math.abs,L.round=L.roundf=L.rint=L.rintf=Math.round,function(e){function t(e,t,n,r){return e[t+r]||e['moz'+n+r]||e['webkit'+n+r]||e['ms'+n+r]}function a(e){l=e;var n=e?ZL.canvas:document,r=e?t(n,'r','R','equestPointerLock'):t(n,'e','E','xitPointerLock');r&&r.call(n)}var i,f,c='ZL',l=0,s={};try{s=window.localStorage||{}}catch(e){}e.ZLJS_CreateWindow=function(e,n,r){var o,f,u,c,s,g,m,d,L,b,v,Z,w,y,x,p;ZL.requestWidth?(n=ZL.requestHeight?ZL.requestHeight:ZL.requestWidth*n/e,e=ZL.requestWidth):ZL.requestHeight&&(e=ZL.requestHeight*e/n,n=ZL.requestHeight),o=ZL.canvas,(f=function(){o.width=e,o.height=n,o.height=o.clientHeight,o.width=o.clientWidth})(),h(o)&&(u=!0,c=null,s=null,g=function(e){e.preventDefault?e.preventDefault(!0):e.stopPropagation?e.stopPropagation(!0):e.stopped=!0},m=function(e){u&&g(e)},d=function(e){return(void 0!==e.offsetX?e.offsetX:e.clientX-(s?0:o.getBoundingClientRect().left))*o.width/o.clientWidth},L=function(e){return(void 0!==e.offsetY?e.offsetY:e.clientY-(s?0:o.getBoundingClientRect().top))*o.height/o.clientHeight},b=function(e,t,n){n('moz'+e,t,1),n('webkit'+e,t,1),n('ms'+e,t,1)},Z=function(e,t){o.addEventListener(e,t,{capture:!0,passive:!1})},w=function(e,t,n){document.addEventListener(e,t),n||b(e,t,w)},(v=function(e,t){window.addEventListener(e,t,!0)})('keydown',function(e){var t;ZL.asm.ZLFNKey(!0,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey),void 0!==e.char?e.char||g(e):e.keyIdentifier&&(t=e.keyIdentifier.match(/^U\+(\S+)$/))&&Math.floor('0x'+t[1])>=32||g(e)}),v('keyup',function(e){ZL.asm.ZLFNKey(!1,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey),g(e)}),v('keypress',function(e){var t=e.charCode||e.char&&e.char.charCodeAt(0);32>t||ZL.asm.ZLFNText(t),g(e)}),Z('mousemove',function(e){c?ZL.asm.ZLFNMove(0,0,0|e.movementX,0|e.movementY,1):ZL.asm.ZLFNMove(d(e),L(e),0,0,1),m(e)}),y=function(e,t){ZL.asm.ZLFNMouse(e.button,t,d(e),L(e),1),m(e),l&&!c&&a(1)},x=function(e,t){for(var n=0,r=e.changedTouches;n!=r.length;n++)ZL.asm.ZLFNMouse(0,t,d(r[n]),L(r[n]),9+r[n].identifier);m(e)},Z('mousedown',function(e){y(e,!0)}),Z('mouseup',function(e){y(e,!1)}),Z('mousewheel',function(e){ZL.asm.ZLFNWheel(e.wheelDelta),m(e)}),Z('DOMMouseScroll',function(e){ZL.asm.ZLFNWheel(40*-e.detail),m(e)}),Z('mouseover',function(){c||s||(u=!0,ZL.asm.ZLFNWindow(1,0,0))}),Z('mouseout',function(){c||s||(u=!1,ZL.asm.ZLFNWindow(2,0,0))}),Z('touchstart',function(e){x(e,!0)}),Z('touchmove',function(e){for(var t=0,n=e.changedTouches;t!=n.length;t++)ZL.asm.ZLFNMove(d(n[t]),L(n[t]),0,0,9+n[t].identifier);m(e)}),Z('touchend',function(e){x(e,!1)}),Z('touchcancel',function(e){x(e,!1)}),v('focus',function(e){e.target==window&&ZL.asm.ZLFNWindow(3,0,0)}),v('blur',function(e){e.target==window&&ZL.asm.ZLFNWindow(4,0,0)}),v('resize',function(){32>o.clientWidth||32>o.clientHeight||o.width==o.clientWidth&&o.height==o.clientHeight||(o.height=o.clientHeight,o.width=o.clientWidth,ZL.asm.ZLFNWindow(6,o.width,o.height))}),w('fullscreenchange',function(){(s=t(document,'f','F','ullscreenElement')||t(document,'f','F','ullScreenElement'))?(o.orgStyle=o.style.cssText,o.style.cssText='background:black',o.height=screen.height,o.width=screen.width):(o.orgStyle&&(o.style.cssText=o.orgStyle),f()),ZL.asm.ZLFNWindow(s?5:6,o.width,o.height)}),w('pointerlockchange',function(){c=t(document,'p','P','ointerLockElement'),ZL.asm.ZLFNWindow(c?7:8,0,0)}),i=Date.now(),r>1e3/55?(window.requestAnimationFrame(ZL.asm.ZLFNDraw),setInterval(function(){window.requestAnimationFrame(ZL.asm.ZLFNDraw)},r)):(p=function(){_||(window.requestAnimationFrame(p),ZL.asm.ZLFNDraw())},window.requestAnimationFrame(p)))},e.ZLJS_GetWidth=function(){return ZL.canvas.width},e.ZLJS_GetHeight=function(){return ZL.canvas.height},e.ZLJS_GetTime=function(){return Date.now()-i},e.ZLJS_SetFullscreen=ZL.SetFullscreen=function(e){var n,r=e?ZL.canvas:document;(n=e?t(r,'r','R','equestFullscreen')||t(r,'r','R','equestFullScreen'):t(r,'e','E','xitFullscreen')||t(r,'c','C','ancelFullScreen'))&&n.call(r)},e.ZLJS_SetPointerLock=function(e){a(e)},e.ZLJS_AsyncLoad=function(e,t,n,a){var i=new XMLHttpRequest;if(i.open(a?'POST':'GET',o(e),!0),i.responseType='arraybuffer',i.onload=function(){if(200==i.status){var e=r(new Uint8Array(i.response));ZL.asm.ZLFNHTTP(t,200,e,i.response.byteLength),ZL.asm.free(e)}else ZL.asm.ZLFNHTTP(t,i.status,0,0)},i.onerror=function(){ZL.asm.ZLFNHTTP(t,i.status,0,0)},a)try{i.send(u.subarray(n,n+a))}catch(e){i.send(u.buffer.slice(n,n+a))}else i.send(null)},e.ZLJS_Websocket=function(e,t,a,i){if(1!=t)if(2!=t){if(t>=3)return f.close(t-3,i?o(a,i):void 0),void(f=void 0);var c=new WebSocket(o(a));c.binaryType='arraybuffer',c.onopen=function(){ZL.asm.ZLFNWebSocket(e,1)},c.onmessage=function(t){var a='string'==typeof t.data,o=a?t.data:new Uint8Array(t.data),i=a?n(o):r(o);ZL.asm.ZLFNWebSocket(e,a?2:3,i,o.length),ZL.asm.free(i)},c.onclose=function(){ZL.asm.ZLFNWebSocket(e,0),f=void 0},f=c}else f&&f.send(u.subarray(a,a+i));else f&&f.send(o(a,i))},e.ZLJS_StartAudio=function(){var e,n,r,a,o,i,f,u;try{e=new(t(window,'','','AudioContext'))}catch(e){}e?(n=0,a=(r=882)/44100,o=0,i=0,f=[{length:0}],u=0,setInterval(function(){var t,c,l,s;if(('suspended'!=e.state||(e.resume(),'suspended'!=e.state))&&(0==(t=e.currentTime)&&(n=0),a>=n-t)){if(f[0].length!=r)for(ZL.asm.free(o),i=(o=ZL.asm.malloc(r<<3))>>2,c=0;4!=c;c++)f[c]=e.createBuffer(2,r,44100);ZL.asm.ZLFNAudio(o,r)&&((l=f[u=(u+1)%4]).getChannelData(0).set(g.subarray(i,i+r)),l.getChannelData(1).set(g.subarray(i+r,i+(r<<1))),(s=e.createBufferSource()).connect(e.destination),s.buffer=l,s[s.start?'start':'noteOn'](.005+n)),t>n&&t>.5&&(10*a>t-n&&11025>r&&document.hasFocus()&&(a=(r+=441)/44100,ZL.print('Warning: Audio callback had starved sending audio by '+(t-n)+' seconds. (extending samples to: '+r+')')),n=t+(document.hasFocus()?0:1.5)),n+=a}},10)):ZL.print('Warning: WebAudio not supported')},e.ZLJS_OpenExternalUrl=function(e){e=o(e),ZL.openUrl?ZL.openUrl(e):window.open(e,'_newtab')},e.ZLJS_SettingsInit=function(e){c=ZL.settingsPrefix?ZL.settingsPrefix:o(e)},e.ZLJS_SettingsSet=function(e,t){s[c+' '+o(e)]=o(t)},e.ZLJS_SettingsDel=function(e){delete s[c+' '+o(e)]},e.ZLJS_SettingsHas=function(e){return void 0!==s[c+' '+o(e)]},e.ZLJS_SettingsGetMalloc=function(e){return e=o(e),void 0===s[c+' '+e]?0:n(s[c+' '+e])}}(L),function(t){function n(e){var t,n=L++;for(t=e.length;n>t;t++)e[t]=null;return n}function r(e){GLlastError||(GLlastError=e)}function i(e,t,n,a,o){var i,f,l,m,d;switch(t){case 6406:case 6409:case 6402:f=1;break;case 6410:f=2;break;case 6407:case 35904:f=3;break;case 6408:case 35906:f=4;break;default:return r(1280),null}switch(e){case 5121:i=1*f;break;case 5123:case 36193:i=2*f;break;case 5125:case 5126:i=4*f;break;case 34042:i=4;break;case 33635:case 32819:case 32820:i=2;break;default:return r(1280),null}switch(l=n*i,d=p,m=a>0?Math.floor((l+d-1)/d)*d*(a-1)+l:0,e){case 5121:return u.subarray(o,o+m);case 5126:return g.subarray(o>>2,o+m>>2);case 5125:case 34042:return s.subarray(o>>2,o+m>>2);case 5123:case 33635:case 32819:case 32820:case 36193:return c.subarray(o>>1,o+m>>1);default:return r(1280),null}}var m,d,L=1,b=[],v=[],Z=[],w=[],y=[],x=[],_={},p=4,S=null,A=[0];for(S=new Float32Array(256),d=0;256>d;d++)A[d]=S.subarray(0,d+1);h=function(t,n){var r,a,o,i,f,u,c,l;n={majorVersion:1,minorVersion:0,antialias:!0,alpha:!1},r='';try{let a=function(e){r=e.statusMessage||r};t.addEventListener('webglcontextcreationerror',a,!1);try{m=t.getContext('webgl',n)||t.getContext('experimental-webgl',n)}finally{t.removeEventListener('webglcontextcreationerror',a,!1)}if(!m)throw'Could not create context'}catch(t){e('WEBGL',t+(r?' ('+r+')':''))}return(a=m.getSupportedExtensions())&&a.length>0&&(l=[(i='OES_')+(u='texture_')+'float',i+u+'half_float',i+'standard_derivatives',i+'vertex_array_object',(o='WEBGL_')+(c='compressed_'+u)+'s3tc',o+'depth_texture',i+'element_index_uint',(f='EXT_')+u+'filter_anisotropic',f+'frag_depth',o+'draw_buffers','ANGLE_instanced_arrays',i+u+'float_linear',i+u+'half_float_linear',f+'blend_minmax',f+'shader_texture_lod',o+c+'pvrtc',f+'color_buffer_half_float',o+'color_buffer_float',f+'sRGB',o+c+'etc1',f+'disjoint_timer_query',o+c+'etc',o+c+'astc',f+'color_buffer_float',o+c+'s3tc_srgb',f+'disjoint_timer_query_webgl2'],a.forEach(function(e){-1!=l.indexOf(e)&&m.getExtension(e)})),!0},t.glActiveTexture=function(e){m.activeTexture(e)},t.glAttachShader=function(e,t){m.attachShader(v[e],x[t])},t.glBindAttribLocation=function(e,t,n){m.bindAttribLocation(v[e],t,o(n))},t.glBindBuffer=function(e,t){m.bindBuffer(e,t?b[t]:null)},t.glBindFramebuffer=function(e,t){m.bindFramebuffer(e,t?Z[t]:null)},t.glBindTexture=function(e,t){m.bindTexture(e,t?w[t]:null)},t.glBlendFunc=function(e,t){m.blendFunc(e,t)},t.glBlendFuncSeparate=function(e,t,n,r){m.blendFuncSeparate(e,t,n,r)},t.glBlendColor=function(e,t,n,r){m.blendColor(e,t,n,r)},t.glBlendEquation=function(e){m.blendEquation(e)},t.glBlendEquationSeparate=function(e,t){m.blendEquationSeparate(e,t)},t.glBufferData=function(e,t,n,r){n?m.bufferData(e,u.subarray(n,n+t),r):m.bufferData(e,t,r)},t.glBufferSubData=function(e,t,n,r){m.bufferSubData(e,t,u.subarray(r,r+n))},t.glClear=function(e){m.clear(e)},t.glClearColor=function(e,t,n,r){m.clearColor(e,t,n,r)},t.glColorMask=function(e,t,n,r){m.colorMask(!!e,!!t,!!n,!!r)},t.glCompileShader=function(e){m.compileShader(x[e])},t.glCreateProgram=function(){var e=n(v),t=m.createProgram();return t.name=e,v[e]=t,e},t.glCreateShader=function(e){var t=n(x);return x[t]=m.createShader(e),t},t.glDeleteBuffers=function(e,t){var n,r,a;for(n=0;e>n;n++)r=l[t+4*n>>2],(a=b[r])&&(m.deleteBuffer(a),a.name=0,b[r]=null)},t.glDeleteFramebuffers=function(e,t){var n,r,a;for(n=0;e>n;++n)r=l[t+4*n>>2],(a=Z[r])&&(m.deleteFramebuffer(a),a.name=0,Z[r]=null)},t.glDeleteProgram=function(e){if(e){var t=v[e];t?(m.deleteProgram(t),t.name=0,v[e]=null,_[e]=null):r(1281)}},t.glDeleteShader=function(e){if(e){var t=x[e];t?(m.deleteShader(t),x[e]=null):r(1281)}},t.glDeleteTextures=function(e,t){var n,r,a;for(n=0;e>n;n++)r=l[t+4*n>>2],(a=w[r])&&(m.deleteTexture(a),a.name=0,w[r]=null)},t.glDepthFunc=function(e){m.depthFunc(e)},t.glDepthMask=function(e){m.depthMask(!!e)},t.glDetachShader=function(e,t){m.detachShader(v[e],x[t])},t.glDisable=function(e){m.disable(e)},t.glDisableVertexAttribArray=function(e){m.disableVertexAttribArray(e)},t.glDrawArrays=function(e,t,n){m.drawArrays(e,t,n)},t.glDrawElements=function(e,t,n,r){m.drawElements(e,t,n,r)},t.glEnable=function(e){m.enable(e)},t.glEnableVertexAttribArray=function(e){m.enableVertexAttribArray(e)},t.glFramebufferTexture2D=function(e,t,n,r,a){m.framebufferTexture2D(e,t,n,w[r],a)},t.glGenBuffers=function(e,t){var a,o,i;for(a=0;e>a;a++){if(!(o=m.createBuffer())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(b),o.name=i,b[i]=o,l[t+4*a>>2]=i}},t.glGenFramebuffers=function(e,t){var a,o,i;for(a=0;e>a;++a){if(!(o=m.createFramebuffer())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(Z),o.name=i,Z[i]=o,l[t+4*a>>2]=i}},t.glGenTextures=function(e,t){var a,o,i;for(a=0;e>a;a++){if(!(o=m.createTexture())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(w),o.name=i,w[i]=o,l[t+4*a>>2]=i}},t.glGetActiveUniform=function(e,t,n,r,o,i,u){var c,s;e=v[e],(c=m.getActiveUniform(e,t))&&(n>0&&u?(s=a(c.name,f,u,n),r&&(l[r>>2]=s)):r&&(l[r>>2]=0),o&&(l[o>>2]=c.size),i&&(l[i>>2]=c.type))},t.glGetAttribLocation=function(e,t){return e=v[e],t=o(t),m.getAttribLocation(e,t)},t.glGetError=function(){if(GLlastError){var e=GLlastError;return GLlastError=0,e}return m.getError()},t.glGetIntegerv=function(e,t){!function(e,t){var n,a,o;if(t){switch(n=void 0,e){case 36346:n=1;break;case 36344:return;case 36345:n=0;break;case 34466:n=m.getParameter(34467).length}if(void 0===n)switch(typeof(a=m.getParameter(e))){case'number':n=a;break;case'boolean':n=a?1:0;break;case'string':return void r(1280);case'object':if(null===a)switch(e){case 34964:case 35725:case 34965:case 36006:case 36007:case 32873:case 34068:n=0;break;default:return void r(1280)}else{if(a instanceof Float32Array||a instanceof Uint32Array||a instanceof Int32Array||a instanceof Array){for(o=0;o>2]=a[o];return}if(!(a instanceof WebGLBuffer||a instanceof WebGLProgram||a instanceof WebGLFramebuffer||a instanceof WebGLRenderbuffer||a instanceof WebGLTexture))return void r(1280);n=0|a.name}break;default:return void r(1280)}l[t>>2]=n}else r(1281)}(e,t)},t.glGetProgramInfoLog=function(e,t,n,r){var o,i=m.getProgramInfoLog(v[e]);null===i&&(i='(unknown error)'),t>0&&r?(o=a(i,f,r,t),n&&(l[n>>2]=o)):n&&(l[n>>2]=0)},t.glGetProgramiv=function(e,t,n){var a,o,i,f,u,c,s;if(n)if(L>e)if(a=_[e])if(35716==t)null===(o=m.getProgramInfoLog(v[e]))&&(o='(unknown error)'),l[n>>2]=o.length+1;else if(35719==t)l[n>>2]=a.maxUniformLength;else if(35722==t){if(-1==a.maxAttributeLength)for(e=v[e],i=m.getProgramParameter(e,m.ACTIVE_ATTRIBUTES),a.maxAttributeLength=0,f=0;i>f;++f)u=m.getActiveAttrib(e,f),a.maxAttributeLength=Math.max(a.maxAttributeLength,u.name.length+1);l[n>>2]=a.maxAttributeLength}else if(35381==t){if(-1==a.maxUniformBlockNameLength)for(e=v[e],c=m.getProgramParameter(e,m.ACTIVE_UNIFORM_BLOCKS),a.maxUniformBlockNameLength=0,f=0;c>f;++f)s=m.getActiveUniformBlockName(e,f),a.maxUniformBlockNameLength=Math.max(a.maxUniformBlockNameLength,s.length+1);l[n>>2]=a.maxUniformBlockNameLength}else l[n>>2]=m.getProgramParameter(v[e],t);else r(1282);else r(1281);else r(1281)},t.glGetShaderInfoLog=function(e,t,n,r){var o,i=m.getShaderInfoLog(x[e]);null===i&&(i='(unknown error)'),t>0&&r?(o=a(i,f,r,t),n&&(l[n>>2]=o)):n&&(l[n>>2]=0)},t.glGetShaderiv=function(e,t,n){var a,o,i;n?35716==t?(null===(a=m.getShaderInfoLog(x[e]))&&(a='(unknown error)'),l[n>>2]=a.length+1):35720==t?(i=null===(o=m.getShaderSource(x[e]))||0==o.length?0:o.length+1,l[n>>2]=i):l[n>>2]=m.getShaderParameter(x[e],t):r(1281)},t.glGetUniformLocation=function(e,t){var n,r,a,i,f;if(n=0,-1!==(t=o(t)).indexOf(']',t.length-1)){if(r=t.lastIndexOf('['),(a=t.slice(r+1,-1)).length>0&&0>(n=parseInt(a)))return-1;t=t.slice(0,r)}return(i=_[e])&&(f=i.uniforms[t])&&no;++o)if(f=(i=m.getActiveUniform(d,o)).name,t.maxUniformLength=Math.max(t.maxUniformLength,f.length+1),-1!==f.indexOf(']',f.length-1)&&(u=f.lastIndexOf('['),f=f.slice(0,u)),null!=(c=m.getUniformLocation(d,f)))for(l=n(y),r[f]=[i.size,l],y[l]=c,s=1;sa;++a)f+=r?0>(i=l[r+4*a>>2])?o(l[n+4*a>>2]):o(l[n+4*a>>2],i):o(l[n+4*a>>2]);return f}(0,t,n,r);m.shaderSource(x[e],a)},t.glTexImage2D=function(e,t,n,r,a,o,f,u,c){var l=null;c&&(l=i(u,f,r,a,c)),m.texImage2D(e,t,n,r,a,o,f,u,l)},t.glTexParameteri=function(e,t,n){m.texParameteri(e,t,n)},t.glTexSubImage2D=function(e,t,n,r,a,o,f,u,c){var l=null;c&&(l=i(u,f,a,o,c)),m.texSubImage2D(e,t,n,r,a,o,f,u,l)},t.glUniform1f=function(e,t){m.uniform1f(y[e],t)},t.glUniform1i=function(e,t){m.uniform1i(y[e],t)},t.glUniform2f=function(e,t,n){m.uniform2f(y[e],t,n)},t.glUniform3f=function(e,t,n,r){m.uniform3f(y[e],t,n,r)},t.glUniform3fv=function(e,t,n){var r,a,o;if(3*t>256)r=g.subarray(n>>2,n+12*t>>2);else for(r=A[3*t-1],a=n>>2,o=0;o!=3*t;o++)r[o]=g[a+o];m.uniform3fv(y[e],r)},t.glUniform4f=function(e,t,n,r,a){m.uniform4f(y[e],t,n,r,a)},t.glUniformMatrix4fv=function(e,t,n,r){var a,o,i;if((t<<=4)>256)a=g.subarray(r>>2,r+4*t>>2);else for(a=A[t-1],o=r>>2,i=0;i!=t;i+=4)a[i]=g[o+i],a[i+1]=g[o+i+1],a[i+2]=g[o+i+2],a[i+3]=g[o+i+3];m.uniformMatrix4fv(y[e],!!n,a)},t.glUseProgram=function(e){m.useProgram(e?v[e]:null)},t.glVertexAttrib4f=function(e,t,n,r,a){m.vertexAttrib4f(e,t,n,r,a)},t.glVertexAttrib4fv=function(e,t){m.vertexAttrib4f(e,g[t>>2],g[t+4>>2],g[t+8>>2],g[t+12>>2])},t.glVertexAttribPointer=function(e,t,n,r,a,o){m.vertexAttribPointer(e,t,n,!!r,a,o)},t.glViewport=function(e,t,n,r){m.viewport(e,t,n,r)}}(L),function(e,t){var n=0,r=ZL.files?i(ZL.files):new Uint8Array(0);delete ZL.files,e.__syscall5=function(){return n=0,1},t.fd_read=function(e,t,a,o){var i,f,c,s,g=0;for(i=0;a>i;i++){if(f=l[t+8*i>>2],c=l[t+(8*i+4)>>2],s=Math.min(c,r.length-n),u.set(r.subarray(n,n+s),f),n+=s,0>s)return 5;if(g+=s,c>s)break}return l[o>>2]=g,0},t.fd_seek=function(e,t,a,o,i){return 0==o&&(n=t),1==o&&(n+=t),2==o&&(n=r.length-t),0>n&&(n=0),n>r.length&&(n=r.length),l[i+0>>2]=n,l[i+4>>2]=0,0},t.fd_write=function(e,t,n,r){var a,i,f,u=0,c='';if(0==n)return 0;for(a=0;n>a;a++){if(i=l[t+8*a>>2],0>(f=l[t+(8*a+4)>>2]))return-1;u+=f,c+=o(i,f)}return ZL.print(c),l[r>>2]=u,0},t.fd_close=function(){return 0},e.__syscall221=e.__syscall54=function(){return 0}}(L,b),ZL.wasm||e('BOOT','Missing Wasm data'),v=i(ZL.wasm),delete ZL.wasm;for(let e,t,n,r=8;rt||t>11||0>=n||e>v.length)break;if(6==t){S(),p(),p(),S();let e=S();S(),y=e}if(11==t)for(let t=S(),n=0;n!=t&&e>r;n++){p(),S();let e=S(),t=(S(),S());w=(Z=e+t)+15>>4<<4,r+=t}}Z>0&&y>w||e('BOOT','Invalid memory layout ('+Z+'/'+w+'/'+y+')'),x=262144+(y+65535>>16<<16),d=y,m=L.memory=new WebAssembly.Memory({initial:x>>16,maximum:4096}),t(),WebAssembly.instantiate(v,{env:L,wasi_unstable:b}).then(function(e){ZL.asm=e.instance.exports;var t=w;a('zl',f,l[t+0>>2]=t+8,256),l[t+4>>2]=0,ZL.asm.__wasm_call_ctors(),ZL.asm.main(1,t,0),ZL.started()}).catch(function(t){'abort'!==t&&e('BOOT','WASM instiantate error: '+t+(t.stack?'\n'+t.stack:''))})}(); \ No newline at end of file +!function(){'use strict';function e(e,t){throw x=!0,ZL.error(e,t),'abort'}function t(){var e=m.buffer;f=new Int8Array(e),new Int16Array(e),l=new Int32Array(e),u=new Uint8Array(e),c=new Uint16Array(e),s=new Uint32Array(e),g=new Float32Array(e)}function n(e){var t,n;for(e=unescape(encodeURIComponent(e)),n=ZL.asm.malloc(e.length+1),t=0;t=r)return 0;for(a=e,o=t,f=i=n,u=i+r-1,c=0;c=55296&&57343>=l&&(l=65536+((1023&l)<<10)|1023&a.charCodeAt(++c)),l>127)if(l>2047)if(l>65535)if(l>2097151)if(l>67108863){if(i+5>=u)break;o[i++]=252|l>>30,o[i++]=128|l>>24&63,o[i++]=128|l>>18&63,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+4>=u)break;o[i++]=248|l>>24,o[i++]=128|l>>18&63,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+3>=u)break;o[i++]=240|l>>18,o[i++]=128|l>>12&63,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+2>=u)break;o[i++]=224|l>>12,o[i++]=128|l>>6&63,o[i++]=128|63&l}else{if(i+1>=u)break;o[i++]=192|l>>6,o[i++]=128|63&l}else{if(i>=u)break;o[i++]=l}return o[i]=0,i-f}function o(e,t){var n,r,a,o,i,f,c,l,s,g,m,d,h,L;if(0===t||!e)return'';for(n=0,a=0;n|=r=u[e+a>>0],(0!=r||t)&&(a++,!t||a!=t););if(t||(t=a),128&n)for(o=u,i=e,f=e+t,c=String.fromCharCode,h='';;){if(i==f||!(l=o[i++]))return h;128&l?(s=63&o[i++],192!=(224&l)?(a=63&o[i++],224==(240&l)?l=(15&l)<<12|s<<6|a:(g=63&o[i++],240==(248&l)?l=(7&l)<<18|s<<12|a<<6|g:(m=63&o[i++],l=248==(252&l)?(3&l)<<24|s<<18|a<<12|g<<6|m:(1&l)<<30|s<<24|a<<18|g<<12|m<<6|(r=63&o[i++]))),h+=65536>l?c(l):c(55296|(d=l-65536)>>10,56320|1023&d)):h+=c((31&l)<<6|s)):h+=c(l)}for(L='';t>0;e+=1024,t-=1024)L+=String.fromCharCode.apply(String,u.subarray(e,e+Math.min(t,1024)));return L}function i(e){var t,n,r,a,o,i,f,u=new Uint8Array(128),c=function(n){return u[e.charCodeAt(t+n)]};for(t=0;64>t;t++)u['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charCodeAt(t)]=t;for(u[45]=62,u[95]=63,n=e.length,r='='===e[n-2]?2:'='===e[n-1]?1:0,a=new Uint8Array(3*n/4-r),o=0,i=r>0?n-4:n,f=0,t=0;i>t;t+=4)f=c(0)<<18|c(1)<<12|c(2)<<6|c(3),a[o++]=f>>16&255,a[o++]=f>>8&255,a[o++]=255&f;return 1===r?(f=c(0)<<10|c(1)<<4|c(2)>>2,a[o]=f>>8&255,a[o+1]=255&f):2===r&&(a[o]=255&(c(0)<<2|c(1)>>4)),a}var f,u,c,l,s,g,m,d,h,L,b,v,w,Z,y,_,x=!1;ZL.print=ZL.print||function(e){console.log(e)},ZL.error=ZL.error||function(e,t){ZL.print('[ERROR] '+e+': '+t)},ZL.started=ZL.started||function(){},b={},(L={sbrk:function(n){var r=d,a=r+n,o=a-m.buffer.byteLength;return a>268435456&&e('MEM','Out of memory'),o>0&&(m.grow(o+65535>>16),t()),d=a,0|r},time:function(e){var t=Date.now()/1e3|0;return e&&(s[e>>2]=t),t},gettimeofday:function(e){var t=Date.now();s[e>>2]=t/1e3|0,s[e+4>>2]=t%1e3*1e3|0},__assert_fail:function(t,n,r,a){e('CRASH','Assert '+o(t)+', at: '+(n?o(n):'unknown filename'),a&&o(a))},__cxa_uncaught_exception:function(){e('CRASH','Uncaught exception!')},__cxa_pure_virtual:function(){e('CRASH','pure virtual')},abort:function(){e('CRASH','Abort called')},longjmp:function(){e('CRASH','Unsupported longjmp called')}}).setjmp=L.__cxa_atexit=L.__lock=L.__unlock=function(){},L.ceil=L.ceilf=Math.ceil,L.exp=L.expf=Math.exp,L.floor=L.floorf=Math.floor,L.log=L.logf=Math.log,L.pow=L.powf=Math.pow,L.cos=L.cosf=Math.cos,L.sin=L.sinf=Math.sin,L.tan=L.tanf=Math.tan,L.acos=L.acosf=Math.acos,L.asin=L.asinf=Math.asin,L.sqrt=L.sqrtf=Math.sqrt,L.atan=L.atanf=Math.atan,L.atan2=L.atan2f=Math.atan2,L.fabs=L.fabsf=L.abs=Math.abs,L.round=L.roundf=L.rint=L.rintf=Math.round,function(e){function t(e,t,n,r){return e[t+r]||e['moz'+n+r]||e['webkit'+n+r]||e['ms'+n+r]}function a(e){l=e;var n=e?ZL.canvas:document,r=e?t(n,'r','R','equestPointerLock'):t(n,'e','E','xitPointerLock');r&&r.call(n)}var i,f,c='ZL',l=0,s={};try{s=window.localStorage||{}}catch(e){}e.ZLJS_CreateWindow=function(e,n,r){var o,f,u,c,s,g,m,d,L,b,v,w,Z,y,_,p;ZL.requestWidth?(n=ZL.requestHeight?ZL.requestHeight:ZL.requestWidth*n/e,e=ZL.requestWidth):ZL.requestHeight&&(e=ZL.requestHeight*e/n,n=ZL.requestHeight),o=ZL.canvas,(f=function(){o.width=e,o.height=n,o.height=o.clientHeight,o.width=o.clientWidth})(),h(o)&&(u=!0,c=null,s=null,g=function(e){e.preventDefault?e.preventDefault(!0):e.stopPropagation?e.stopPropagation(!0):e.stopped=!0},m=function(e){u&&g(e)},d=function(e){return(void 0!==e.offsetX?e.offsetX:e.clientX-(s?0:o.getBoundingClientRect().left))*o.width/o.clientWidth},L=function(e){return(void 0!==e.offsetY?e.offsetY:e.clientY-(s?0:o.getBoundingClientRect().top))*o.height/o.clientHeight},b=function(e,t,n){n('moz'+e,t,1),n('webkit'+e,t,1),n('ms'+e,t,1)},w=function(e,t){o.addEventListener(e,t,{capture:!0,passive:!1})},Z=function(e,t,n){document.addEventListener(e,t),n||b(e,t,Z)},(v=function(e,t){window.addEventListener(e,t,!0)})('keydown',function(e){var t;ZL.asm.ZLFNKey(!0,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey),void 0!==e.char?e.char||g(e):e.keyIdentifier&&(t=e.keyIdentifier.match(/^U\+(\S+)$/))&&('0x'+t[1]|0)>=32||g(e)}),v('keyup',function(e){ZL.asm.ZLFNKey(!1,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey),g(e)}),v('keypress',function(e){var t=e.charCode||e.char&&e.char.charCodeAt(0);32>t||ZL.asm.ZLFNText(t),g(e)}),w('mousemove',function(e){c?ZL.asm.ZLFNMove(0,0,0|e.movementX,0|e.movementY,1):ZL.asm.ZLFNMove(d(e),L(e),0,0,1),m(e)}),y=function(e,t){ZL.asm.ZLFNMouse(e.button,t,d(e),L(e),1),m(e),l&&!c&&a(1)},_=function(e,t){for(var n=0,r=e.changedTouches;n!=r.length;n++)ZL.asm.ZLFNMouse(0,t,d(r[n]),L(r[n]),9+r[n].identifier);m(e)},w('mousedown',function(e){y(e,!0)}),w('mouseup',function(e){y(e,!1)}),w('mousewheel',function(e){ZL.asm.ZLFNWheel(e.wheelDelta),m(e)}),w('DOMMouseScroll',function(e){ZL.asm.ZLFNWheel(40*-e.detail),m(e)}),w('mouseover',function(){c||s||(u=!0,ZL.asm.ZLFNWindow(1,0,0))}),w('mouseout',function(){c||s||(u=!1,ZL.asm.ZLFNWindow(2,0,0))}),w('touchstart',function(e){_(e,!0)}),w('touchmove',function(e){for(var t=0,n=e.changedTouches;t!=n.length;t++)ZL.asm.ZLFNMove(d(n[t]),L(n[t]),0,0,9+n[t].identifier);m(e)}),w('touchend',function(e){_(e,!1)}),w('touchcancel',function(e){_(e,!1)}),v('focus',function(e){e.target==window&&ZL.asm.ZLFNWindow(3,0,0)}),v('blur',function(e){e.target==window&&ZL.asm.ZLFNWindow(4,0,0)}),v('resize',function(){32>o.clientWidth||32>o.clientHeight||o.width==o.clientWidth&&o.height==o.clientHeight||(o.height=o.clientHeight,o.width=o.clientWidth,ZL.asm.ZLFNWindow(6,o.width,o.height))}),Z('fullscreenchange',function(){(s=t(document,'f','F','ullscreenElement')||t(document,'f','F','ullScreenElement'))?(o.orgStyle=o.style.cssText,o.style.cssText='background:black',o.height=screen.height,o.width=screen.width):(o.orgStyle&&(o.style.cssText=o.orgStyle),f()),ZL.asm.ZLFNWindow(s?5:6,o.width,o.height)}),Z('pointerlockchange',function(){c=t(document,'p','P','ointerLockElement'),ZL.asm.ZLFNWindow(c?7:8,0,0)}),i=Date.now(),r>1e3/55?(window.requestAnimationFrame(ZL.asm.ZLFNDraw),setInterval(function(){window.requestAnimationFrame(ZL.asm.ZLFNDraw)},r)):(p=function(){x||(window.requestAnimationFrame(p),ZL.asm.ZLFNDraw())},window.requestAnimationFrame(p)))},e.ZLJS_GetWidth=function(){return ZL.canvas.width},e.ZLJS_GetHeight=function(){return ZL.canvas.height},e.ZLJS_GetTime=function(){return Date.now()-i},e.ZLJS_SetFullscreen=ZL.SetFullscreen=function(e){var n,r=e?ZL.canvas:document;(n=e?t(r,'r','R','equestFullscreen')||t(r,'r','R','equestFullScreen'):t(r,'e','E','xitFullscreen')||t(r,'c','C','ancelFullScreen'))&&n.call(r)},e.ZLJS_SetPointerLock=function(e){a(e)},e.ZLJS_AsyncLoad=function(e,t,n,a,i){var f=new XMLHttpRequest,c=ZL.asm.ZLFNHTTP;if(f.open(a?'POST':'GET',o(e),!0),f.responseType='arraybuffer',f.timeout=i,f.onload=function(){if(200==f.status){var e=r(new Uint8Array(f.response));c(t,200,e,f.response.byteLength),ZL.asm.free(e)}else c(t,f.status,0,0)},f.ontimeout=f.onerror=function(){setTimeout(function(){c(t,f.status||-1,0,0)})},a)try{f.send(u.subarray(n,n+a))}catch(e){f.send(u.buffer.slice(n,n+a))}else f.send(null)},e.ZLJS_Websocket=function(e,t,a,i){var c,l=ZL.asm.ZLFNWebSocket;if(1!=t)if(2!=t){if(t>=3)return f&&f.close(t-3,i?o(a,i):void 0),void(f=void 0);try{c=new WebSocket(o(a))}catch(t){return void setTimeout(function(){l(e,1009)})}c.binaryType='arraybuffer',c.onopen=function(){l(e,0)},c.onmessage=function(t){var a='string'==typeof t.data,o=a?t.data:new Uint8Array(t.data),i=a?n(o):r(o);l(e,a?1:2,i,o.length),ZL.asm.free(i)},c.onclose=function(t){l(e,3+t.code),f=void 0},f=c}else f&&f.send(u.subarray(a,a+i));else f&&f.send(o(a,i))},e.ZLJS_StartAudio=function(){var e,n,r,a,o,i,f,u;try{e=new(t(window,'','','AudioContext'))}catch(e){}e?(n=0,a=(r=882)/44100,o=0,i=0,f=[{length:0}],u=0,setInterval(function(){var t,c,l,s;if(('suspended'!=e.state||(e.resume(),'suspended'!=e.state))&&(0==(t=e.currentTime)&&(n=0),a>=n-t)){if(f[0].length!=r)for(ZL.asm.free(o),i=(o=ZL.asm.malloc(r<<3))>>2,c=0;4!=c;c++)f[c]=e.createBuffer(2,r,44100);ZL.asm.ZLFNAudio(o,r)&&((l=f[u=(u+1)%4]).getChannelData(0).set(g.subarray(i,i+r)),l.getChannelData(1).set(g.subarray(i+r,i+(r<<1))),(s=e.createBufferSource()).connect(e.destination),s.buffer=l,s[s.start?'start':'noteOn'](.005+n)),t>n&&t>.5&&(10*a>t-n&&11025>r&&document.hasFocus()&&(a=(r+=441)/44100,ZL.print('Warning: Audio callback had starved sending audio by '+(t-n)+' seconds. (extending samples to: '+r+')')),n=t+(document.hasFocus()?0:1.5)),n+=a}},10)):ZL.print('Warning: WebAudio not supported')},e.ZLJS_OpenExternalUrl=function(e){e=o(e),ZL.openUrl?ZL.openUrl(e):window.open(e,'_newtab')},e.ZLJS_SettingsInit=function(e){c=ZL.settingsPrefix?ZL.settingsPrefix:o(e)},e.ZLJS_SettingsSet=function(e,t){s[c+' '+o(e)]=o(t)},e.ZLJS_SettingsDel=function(e){delete s[c+' '+o(e)]},e.ZLJS_SettingsHas=function(e){return void 0!==s[c+' '+o(e)]},e.ZLJS_SettingsGetMalloc=function(e){return e=o(e),void 0===s[c+' '+e]?0:n(s[c+' '+e])}}(L),function(t){function n(e){var t,n=L++;for(t=e.length;n>t;t++)e[t]=null;return n}function r(e){GLlastError||(GLlastError=e)}function i(e,t,n,a,o){var i,f,l,m,d;switch(t){case 6406:case 6409:case 6402:f=1;break;case 6410:f=2;break;case 6407:case 35904:f=3;break;case 6408:case 35906:f=4;break;default:return r(1280),null}switch(e){case 5121:i=1*f;break;case 5123:case 36193:i=2*f;break;case 5125:case 5126:i=4*f;break;case 34042:i=4;break;case 33635:case 32819:case 32820:i=2;break;default:return r(1280),null}switch(l=n*i,d=p,m=a>0?Math.floor((l+d-1)/d)*d*(a-1)+l:0,e){case 5121:return u.subarray(o,o+m);case 5126:return g.subarray(o>>2,o+m>>2);case 5125:case 34042:return s.subarray(o>>2,o+m>>2);case 5123:case 33635:case 32819:case 32820:case 36193:return c.subarray(o>>1,o+m>>1);default:return r(1280),null}}var m,d,L=1,b=[],v=[],w=[],Z=[],y=[],_=[],x={},p=4,A=null,S=[0];for(A=new Float32Array(256),d=0;256>d;d++)S[d]=A.subarray(0,d+1);h=function(t,n){var r,a,o,i,f,u,c,l;n={majorVersion:1,minorVersion:0,antialias:!0,alpha:!1},r='';try{let a=function(e){r=e.statusMessage||r};t.addEventListener('webglcontextcreationerror',a,!1);try{m=t.getContext('webgl',n)||t.getContext('experimental-webgl',n)}finally{t.removeEventListener('webglcontextcreationerror',a,!1)}if(!m)throw'Could not create context'}catch(t){e('WEBGL',t+(r?' ('+r+')':''))}return(a=m.getSupportedExtensions())&&a.length>0&&(l=[(i='OES_')+(u='texture_')+'float',i+u+'half_float',i+'standard_derivatives',i+'vertex_array_object',(o='WEBGL_')+(c='compressed_'+u)+'s3tc',o+'depth_texture',i+'element_index_uint',(f='EXT_')+u+'filter_anisotropic',f+'frag_depth',o+'draw_buffers','ANGLE_instanced_arrays',i+u+'float_linear',i+u+'half_float_linear',f+'blend_minmax',f+'shader_texture_lod',o+c+'pvrtc',f+'color_buffer_half_float',o+'color_buffer_float',f+'sRGB',o+c+'etc1',f+'disjoint_timer_query',o+c+'etc',o+c+'astc',f+'color_buffer_float',o+c+'s3tc_srgb',f+'disjoint_timer_query_webgl2'],a.forEach(function(e){-1!=l.indexOf(e)&&m.getExtension(e)})),!0},t.glActiveTexture=function(e){m.activeTexture(e)},t.glAttachShader=function(e,t){m.attachShader(v[e],_[t])},t.glBindAttribLocation=function(e,t,n){m.bindAttribLocation(v[e],t,o(n))},t.glBindBuffer=function(e,t){m.bindBuffer(e,t?b[t]:null)},t.glBindFramebuffer=function(e,t){m.bindFramebuffer(e,t?w[t]:null)},t.glBindTexture=function(e,t){m.bindTexture(e,t?Z[t]:null)},t.glBlendFunc=function(e,t){m.blendFunc(e,t)},t.glBlendFuncSeparate=function(e,t,n,r){m.blendFuncSeparate(e,t,n,r)},t.glBlendColor=function(e,t,n,r){m.blendColor(e,t,n,r)},t.glBlendEquation=function(e){m.blendEquation(e)},t.glBlendEquationSeparate=function(e,t){m.blendEquationSeparate(e,t)},t.glBufferData=function(e,t,n,r){n?m.bufferData(e,u.subarray(n,n+t),r):m.bufferData(e,t,r)},t.glBufferSubData=function(e,t,n,r){m.bufferSubData(e,t,u.subarray(r,r+n))},t.glClear=function(e){m.clear(e)},t.glClearColor=function(e,t,n,r){m.clearColor(e,t,n,r)},t.glColorMask=function(e,t,n,r){m.colorMask(!!e,!!t,!!n,!!r)},t.glCompileShader=function(e){m.compileShader(_[e])},t.glCreateProgram=function(){var e=n(v),t=m.createProgram();return t.name=e,v[e]=t,e},t.glCreateShader=function(e){var t=n(_);return _[t]=m.createShader(e),t},t.glDeleteBuffers=function(e,t){var n,r,a;for(n=0;e>n;n++)r=l[t+4*n>>2],(a=b[r])&&(m.deleteBuffer(a),a.name=0,b[r]=null)},t.glDeleteFramebuffers=function(e,t){var n,r,a;for(n=0;e>n;++n)r=l[t+4*n>>2],(a=w[r])&&(m.deleteFramebuffer(a),a.name=0,w[r]=null)},t.glDeleteProgram=function(e){if(e){var t=v[e];t?(m.deleteProgram(t),t.name=0,v[e]=null,x[e]=null):r(1281)}},t.glDeleteShader=function(e){if(e){var t=_[e];t?(m.deleteShader(t),_[e]=null):r(1281)}},t.glDeleteTextures=function(e,t){var n,r,a;for(n=0;e>n;n++)r=l[t+4*n>>2],(a=Z[r])&&(m.deleteTexture(a),a.name=0,Z[r]=null)},t.glDepthFunc=function(e){m.depthFunc(e)},t.glDepthMask=function(e){m.depthMask(!!e)},t.glDetachShader=function(e,t){m.detachShader(v[e],_[t])},t.glDisable=function(e){m.disable(e)},t.glDisableVertexAttribArray=function(e){m.disableVertexAttribArray(e)},t.glDrawArrays=function(e,t,n){m.drawArrays(e,t,n)},t.glDrawElements=function(e,t,n,r){m.drawElements(e,t,n,r)},t.glEnable=function(e){m.enable(e)},t.glEnableVertexAttribArray=function(e){m.enableVertexAttribArray(e)},t.glFramebufferTexture2D=function(e,t,n,r,a){m.framebufferTexture2D(e,t,n,Z[r],a)},t.glGenBuffers=function(e,t){var a,o,i;for(a=0;e>a;a++){if(!(o=m.createBuffer())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(b),o.name=i,b[i]=o,l[t+4*a>>2]=i}},t.glGenFramebuffers=function(e,t){var a,o,i;for(a=0;e>a;++a){if(!(o=m.createFramebuffer())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(w),o.name=i,w[i]=o,l[t+4*a>>2]=i}},t.glGenTextures=function(e,t){var a,o,i;for(a=0;e>a;a++){if(!(o=m.createTexture())){for(r(1282);e>a;)l[t+4*a++>>2]=0;return}i=n(Z),o.name=i,Z[i]=o,l[t+4*a>>2]=i}},t.glGetActiveUniform=function(e,t,n,r,o,i,u){var c,s;e=v[e],(c=m.getActiveUniform(e,t))&&(n>0&&u?(s=a(c.name,f,u,n),r&&(l[r>>2]=s)):r&&(l[r>>2]=0),o&&(l[o>>2]=c.size),i&&(l[i>>2]=c.type))},t.glGetAttribLocation=function(e,t){return e=v[e],t=o(t),m.getAttribLocation(e,t)},t.glGetError=function(){if(GLlastError){var e=GLlastError;return GLlastError=0,e}return m.getError()},t.glGetIntegerv=function(e,t){!function(e,t){var n,a,o;if(t){switch(n=void 0,e){case 36346:n=1;break;case 36344:return;case 36345:n=0;break;case 34466:n=m.getParameter(34467).length}if(void 0===n)switch(typeof(a=m.getParameter(e))){case'number':n=a;break;case'boolean':n=a?1:0;break;case'string':return void r(1280);case'object':if(null===a)switch(e){case 34964:case 35725:case 34965:case 36006:case 36007:case 32873:case 34068:n=0;break;default:return void r(1280)}else{if(a instanceof Float32Array||a instanceof Uint32Array||a instanceof Int32Array||a instanceof Array){for(o=0;o>2]=a[o];return}if(!(a instanceof WebGLBuffer||a instanceof WebGLProgram||a instanceof WebGLFramebuffer||a instanceof WebGLRenderbuffer||a instanceof WebGLTexture))return void r(1280);n=0|a.name}break;default:return void r(1280)}l[t>>2]=n}else r(1281)}(e,t)},t.glGetProgramInfoLog=function(e,t,n,r){var o,i=m.getProgramInfoLog(v[e]);null===i&&(i='(unknown error)'),t>0&&r?(o=a(i,f,r,t),n&&(l[n>>2]=o)):n&&(l[n>>2]=0)},t.glGetProgramiv=function(e,t,n){var a,o,i,f,u,c,s;if(n)if(L>e)if(a=x[e])if(35716==t)null===(o=m.getProgramInfoLog(v[e]))&&(o='(unknown error)'),l[n>>2]=o.length+1;else if(35719==t)l[n>>2]=a.maxUniformLength;else if(35722==t){if(-1==a.maxAttributeLength)for(e=v[e],i=m.getProgramParameter(e,m.ACTIVE_ATTRIBUTES),a.maxAttributeLength=0,f=0;i>f;++f)u=m.getActiveAttrib(e,f),a.maxAttributeLength=Math.max(a.maxAttributeLength,u.name.length+1);l[n>>2]=a.maxAttributeLength}else if(35381==t){if(-1==a.maxUniformBlockNameLength)for(e=v[e],c=m.getProgramParameter(e,m.ACTIVE_UNIFORM_BLOCKS),a.maxUniformBlockNameLength=0,f=0;c>f;++f)s=m.getActiveUniformBlockName(e,f),a.maxUniformBlockNameLength=Math.max(a.maxUniformBlockNameLength,s.length+1);l[n>>2]=a.maxUniformBlockNameLength}else l[n>>2]=m.getProgramParameter(v[e],t);else r(1282);else r(1281);else r(1281)},t.glGetShaderInfoLog=function(e,t,n,r){var o,i=m.getShaderInfoLog(_[e]);null===i&&(i='(unknown error)'),t>0&&r?(o=a(i,f,r,t),n&&(l[n>>2]=o)):n&&(l[n>>2]=0)},t.glGetShaderiv=function(e,t,n){var a,o,i;n?35716==t?(null===(a=m.getShaderInfoLog(_[e]))&&(a='(unknown error)'),l[n>>2]=a.length+1):35720==t?(i=null===(o=m.getShaderSource(_[e]))||0==o.length?0:o.length+1,l[n>>2]=i):l[n>>2]=m.getShaderParameter(_[e],t):r(1281)},t.glGetUniformLocation=function(e,t){var n,r,a,i,f;if(n=0,-1!==(t=o(t)).indexOf(']',t.length-1)){if(r=t.lastIndexOf('['),(a=t.slice(r+1,-1)).length>0&&0>(n=parseInt(a)))return-1;t=t.slice(0,r)}return(i=x[e])&&(f=i.uniforms[t])&&no;++o)if(f=(i=m.getActiveUniform(d,o)).name,t.maxUniformLength=Math.max(t.maxUniformLength,f.length+1),-1!==f.indexOf(']',f.length-1)&&(u=f.lastIndexOf('['),f=f.slice(0,u)),null!=(c=m.getUniformLocation(d,f)))for(l=n(y),r[f]=[i.size,l],y[l]=c,s=1;sa;++a)f+=r?0>(i=l[r+4*a>>2])?o(l[n+4*a>>2]):o(l[n+4*a>>2],i):o(l[n+4*a>>2]);return f}(0,t,n,r);m.shaderSource(_[e],a)},t.glTexImage2D=function(e,t,n,r,a,o,f,u,c){var l=null;c&&(l=i(u,f,r,a,c)),m.texImage2D(e,t,n,r,a,o,f,u,l)},t.glTexParameteri=function(e,t,n){m.texParameteri(e,t,n)},t.glTexSubImage2D=function(e,t,n,r,a,o,f,u,c){var l=null;c&&(l=i(u,f,a,o,c)),m.texSubImage2D(e,t,n,r,a,o,f,u,l)},t.glUniform1f=function(e,t){m.uniform1f(y[e],t)},t.glUniform1i=function(e,t){m.uniform1i(y[e],t)},t.glUniform2f=function(e,t,n){m.uniform2f(y[e],t,n)},t.glUniform3f=function(e,t,n,r){m.uniform3f(y[e],t,n,r)},t.glUniform3fv=function(e,t,n){var r,a,o;if(3*t>256)r=g.subarray(n>>2,n+12*t>>2);else for(r=S[3*t-1],a=n>>2,o=0;o!=3*t;o++)r[o]=g[a+o];m.uniform3fv(y[e],r)},t.glUniform4f=function(e,t,n,r,a){m.uniform4f(y[e],t,n,r,a)},t.glUniformMatrix4fv=function(e,t,n,r){var a,o,i;if((t<<=4)>256)a=g.subarray(r>>2,r+4*t>>2);else for(a=S[t-1],o=r>>2,i=0;i!=t;i+=4)a[i]=g[o+i],a[i+1]=g[o+i+1],a[i+2]=g[o+i+2],a[i+3]=g[o+i+3];m.uniformMatrix4fv(y[e],!!n,a)},t.glUseProgram=function(e){m.useProgram(e?v[e]:null)},t.glVertexAttrib4f=function(e,t,n,r,a){m.vertexAttrib4f(e,t,n,r,a)},t.glVertexAttrib4fv=function(e,t){m.vertexAttrib4f(e,g[t>>2],g[t+4>>2],g[t+8>>2],g[t+12>>2])},t.glVertexAttribPointer=function(e,t,n,r,a,o){m.vertexAttribPointer(e,t,n,!!r,a,o)},t.glViewport=function(e,t,n,r){m.viewport(e,t,n,r)}}(L),function(e,t){var n=0,r=ZL.files?i(ZL.files):new Uint8Array(0);delete ZL.files,e.__sys_open=e.__syscall5=function(){return n=0,1},t.fd_read=function(e,t,a,o){var i,f,c,g,m=0;for(i=0;a>i;i++){if(f=l[t+8*i>>2],c=l[t+(8*i+4)>>2],g=Math.min(c,r.length-n),u.set(r.subarray(n,n+g),f),n+=g,0>g)return 5;if(m+=g,c>g)break}return s[o>>2]=m,0},t.fd_seek=function(e,t,a,o,i){return 0==o&&(n=t),1==o&&(n+=t),2==o&&(n=r.length-t),0>n&&(n=0),n>r.length&&(n=r.length),s[i+0>>2]=n,s[i+4>>2]=0,0},t.fd_write=function(e,t,n,r){var a,i,f,u=0,c='';if(0==n)return 0;for(a=0;n>a;a++){if(i=l[t+8*a>>2],0>(f=l[t+(8*a+4)>>2]))return-1;u+=f,c+=o(i,f)}return ZL.print(c),s[r>>2]=u,0},t.fd_close=function(){return 0},e.__sys_fcntl64=e.__sys_ioctl=e.__syscall221=e.__syscall54=function(){return 0}}(L,b),ZL.wasm||e('BOOT','Missing Wasm data'),v=i(ZL.wasm),delete ZL.wasm;for(let e,t,n,r=8;rt||t>11||0>=n||e>v.length)break;if(6==t){A(),p(),p(),A();let e=A();A(),y=e}if(11==t)for(let t=A(),n=0;n!=t&&e>r;n++){p(),A();let e=A(),t=(A(),A());Z=(w=e+t)+15>>4<<4,r+=t}}w>0&&y>Z||e('BOOT','Invalid memory layout ('+w+'/'+Z+'/'+y+')'),_=262144+(y+65535>>16<<16),d=y,m=L.memory=new WebAssembly.Memory({initial:_>>16,maximum:4096}),t(),WebAssembly.instantiate(v,{env:L,wasi_unstable:b,wasi_snapshot_preview1:b,wasi:b}).then(function(e){ZL.asm=e.instance.exports;var t=Z;a('zl',f,s[t+0>>2]=t+8,256),s[t+4>>2]=0,ZL.asm.__wasm_call_ctors(),ZL.asm.main(1,t,0),ZL.started()}).catch(function(t){'abort'!==t&&e('BOOT','WASM instiantate error: '+t+(t.stack?'\n'+t.stack:''))})}(); \ No newline at end of file diff --git a/WebAssembly/ZillaLibWasm.mk b/WebAssembly/ZillaLibWasm.mk index efe82b7..bdffa04 100644 --- a/WebAssembly/ZillaLibWasm.mk +++ b/WebAssembly/ZillaLibWasm.mk @@ -219,7 +219,7 @@ $(if $(ZLWASM_ASSETS_EMBED),,$(ASSET_JS).gz) : $(ASSET_JS) $(APPOUTDIR)/$(ZillaApp).html : $(dir $(THIS_MAKEFILE))ZillaLibWasm.html $(info $(if $(wildcard $@),Warning: Template $^ is newer than $@ - delete the local build file to have it regenerated,Generating $@ ...)) - @$(if $(wildcard $@),,$(PYTHON) -c "open('$@','wb').write(file('$^','rb').read().replace('{{ZILLAAPP}}','$(ZillaApp)').replace('{{ZILLAAPPSCRIPT}}','$(subst ",'+chr(34)+',$(ZILLAAPPSCRIPT))'))") + @$(if $(wildcard $@),,$(PYTHON) -c "open('$@','w').write(open('$^','r').read().replace('{{ZILLAAPP}}','$(ZillaApp)').replace('{{ZILLAAPPSCRIPT}}','$(subst ",'+chr(34)+',$(ZILLAAPPSCRIPT))'))") run web : $(if $(RUNWITHOUTBUILD),,all) @$(PYTHON) "$(dir $(THIS_MAKEFILE))ZillaLibWasm.py" $@ "$(APPOUTDIR)" "$(ZillaApp).html" diff --git a/WebAssembly/ZillaLibWasm.py b/WebAssembly/ZillaLibWasm.py index 47c821e..df915c2 100644 --- a/WebAssembly/ZillaLibWasm.py +++ b/WebAssembly/ZillaLibWasm.py @@ -19,7 +19,7 @@ # 3. This notice may not be removed or altered from any source distribution. # -import sys,re,os,string,subprocess,fnmatch,SimpleHTTPServer,SocketServer +import sys,re,os,string,subprocess,fnmatch wasm_dir = os.path.dirname(os.path.realpath(sys.argv.pop(0))).replace('\\', '/') def get_makefile_str(param,m='Makefile',d=''): return ((re.findall(param+'\s*=\s*(.*?)\s*(?:\n|\r|$)',open(m).read())or[d])[0] if os.path.exists(m) else d) def get_makefile_int(param,m='Makefile',d=0): return (int((re.findall(param+'\s*=\s*(\d+)',open(m).read())or[str(d)])[0]) if os.path.exists(m) else d) @@ -32,10 +32,13 @@ def get_makefile_int(param,m='Makefile',d=0): return (int((re.findall(param+'\s* for ln in sys.argv: if re.match('-REL', ln, re.I): outdir = 'Release-wasm';sys.argv.pop(sys.argv.index(ln));break if sys.argv and os.path.exists(sys.argv[0]): outdir = sys.argv.pop(0) - htmlfile = (fnmatch.filter(os.walk(outdir).next()[2], "*.htm*") or [''])[0] + for root, dirs, files in os.walk(outdir): + htmlfile = (fnmatch.filter(files, "*.htm*") or [''])[0] + break if sys.argv and os.path.exists(outdir+os.sep+sys.argv[0]): htmlfile = sys.argv.pop(0) if cmd == 'WEB': + import SimpleHTTPServer,SocketServer HTTPRequestCount = 0 class OurHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def send_header(self, keyword, value): @@ -58,7 +61,7 @@ def send_head(self): browsercmd = get_makefile_str('BROWSER', wasm_dir+'/ZillaAppLocalConfig.mk'); if browsercmd == '': - def tryurl(p): a=1;exec "try:subprocess.call([p, htmlurl])\nexcept:a=0";return a + def tryurl(p): a=1;exec("try:subprocess.call([p, htmlurl])\nexcept:a=0");return a try:os.startfile(htmlurl) except:(tryurl('xdg-open') or tryurl('gnome-open') or tryurl('exo-open') or tryurl('open')) else: @@ -66,18 +69,18 @@ def tryurl(p): a=1;exec "try:subprocess.call([p, htmlurl])\nexcept:a=0";return a except: sys.stderr.write("\nCould not run browser with command line '"+browsercmd+"'\nSet custom path in "+wasm_dir+"/ZillaAppLocalConfig.mk with BROWSER = "+('D:' if sys.platform == 'win32' else '')+"/path/to/browser/browser"+('.exe' if sys.platform == 'win32' else '')+"\n\n") sys.exit(1) - print "Opening",htmlurl,"with",browsercmd + sys.stdout.write("Opening " + htmlurl + " with " +browsercmd) if cmd == 'WEB': MaxRequestCount = (2 if outdir == 'Release-wasm' and get_makefile_int('ZLWASM_ASSETS_EMBED') else 3) - print 'Serving', MaxRequestCount, 'files from directory', outdir, 'at port', httpdport + sys.stdout.write('Serving ' + MaxRequestCount + ' files from directory ' + outdir + ' at port ' + httpdport) try: while HTTPRequestCount < MaxRequestCount: httpd.handle_request() except:pass sys.exit(0) else: - print "No command in arguments specified." - print "Valid commands are: RUN, WEB" - print "RUN: run browser to output HTML" - print "WEB: start webserver in output dir run browser to output HTML" + sys.stdout.write("No command in arguments specified.") + sys.stdout.write("Valid commands are: RUN, WEB") + sys.stdout.write("RUN: run browser to output HTML") + sys.stdout.write("WEB: start webserver in output dir run browser to output HTML")