define(["./RuntimeError-346a3079","./when-4bbc8319","./createTaskProcessorWorker"],(function(e,t,i){"use strict";function r(t,i){if(r.passThroughDataForTesting)return i;var n=t.byteLength;if(0===n||n%4!=0)throw new e.RuntimeError("The length of key must be greater than 0 and a multiple of 4.");var a=new DataView(i),o=a.getUint32(0,!0);if(1953029805===o||2917034100===o)return i;for(var s,f=new DataView(t),l=0,d=i.byteLength,h=d-d%8,c=n,u=8;l=c&&(s=u=(u+8)%24);l>>16&65535|0,o=0;0!==i;){i-=o=i>2e3?2e3:i;do{a=a+(n=n+t[r++]|0)|0}while(--o);n%=65521,a%=65521}return n|a<<16|0};var l=function(){for(var e,t=[],i=0;i<256;i++){e=i;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}();var d=function(e,t,i,r){var n=l,a=r+i;e^=-1;for(var o=r;o>>8^n[255&(e^t[o])];return-1^e},h=function(e,t){var i,r,n,a,o,s,f,l,d,h,c,u,w,b,m,v,g,k,p,y,_,x,B,E,A;i=e.state,r=e.next_in,E=e.input,n=r+(e.avail_in-5),a=e.next_out,A=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),f=i.dmax,l=i.wsize,d=i.whave,h=i.wnext,c=i.window,u=i.hold,w=i.bits,b=i.lencode,m=i.distcode,v=(1<>>=p=k>>>24,w-=p,0===(p=k>>>16&255))A[a++]=65535&k;else{if(!(16&p)){if(0==(64&p)){k=b[(65535&k)+(u&(1<>>=p,w-=p),w<15&&(u+=E[r++]<>>=p=k>>>24,w-=p,!(16&(p=k>>>16&255))){if(0==(64&p)){k=m[(65535&k)+(u&(1<f){e.msg="invalid distance too far back",i.mode=30;break e}if(u>>>=p,w-=p,_>(p=a-o)){if((p=_-p)>d&&i.sane){e.msg="invalid distance too far back",i.mode=30;break e}if(x=0,B=c,0===h){if(x+=l-p,p2;)A[a++]=B[x++],A[a++]=B[x++],A[a++]=B[x++],y-=3;y&&(A[a++]=B[x++],y>1&&(A[a++]=B[x++]))}else{x=a-_;do{A[a++]=A[x++],A[a++]=A[x++],A[a++]=A[x++],y-=3}while(y>2);y&&(A[a++]=A[x++],y>1&&(A[a++]=A[x++]))}break}}break}}while(r>3,u&=(1<<(w-=y<<3))-1,e.next_in=r,e.next_out=a,e.avail_in=r=1&&0===P[T];T--);if(U>T&&(U=T),0===T)return n[a++]=20971520,n[a++]=20971520,f.bits=1,0;for(A=1;A0&&(0===e||1!==T))return-1;for(O[1]=0,B=1;B852||2===e&&I>592)return 1;for(;;){p=B-R,o[E]k?(y=M[j+o[E]],_=D[V+o[E]]):(y=96,_=0),l=1<>R)+(d-=l)]=p<<24|y<<16|_|0}while(0!==d);for(l=1<>=1;if(0!==l?(z&=l-1,z+=l):z=0,E++,0==--P[B]){if(B===T)break;B=t[i+o[E]]}if(B>U&&(z&v)!==h){for(0===R&&(R=U),g+=A,C=1<<(S=B-R);S+R852||2===e&&I>592)return 1;n[h=z&v]=U<<24|S<<16|g-a|0}}return 0!==z&&(n[g+z]=B-R<<24|64<<16|0),f.bits=U,0},g=-2,k=12,p=30;function y(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function _(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function x(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new s.Buf32(852),t.distcode=t.distdyn=new s.Buf32(592),t.sane=1,t.back=-1,0):g}function B(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,x(e)):g}function E(e,t){var i,r;return e&&e.state?(r=e.state,t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?g:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,B(e))):g}function A(e,t){var i,r;return e?(r=new _,e.state=r,r.window=null,0!==(i=E(e,t))&&(e.state=null),i):g}var T,U,S=!0;function R(e){if(S){var t;for(T=new s.Buf32(512),U=new s.Buf32(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(v(1,e.lens,0,288,T,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;v(2,e.lens,0,32,U,0,e.work,{bits:5}),S=!1}e.lencode=T,e.lenbits=9,e.distcode=U,e.distbits=5}function C(e,t,i,r){var n,a=e.state;return null===a.window&&(a.wsize=1<=a.wsize?(s.arraySet(a.window,t,i-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):((n=a.wsize-a.wnext)>r&&(n=r),s.arraySet(a.window,t,i-r,n,a.wnext),(r-=n)?(s.arraySet(a.window,t,i-r,r,0),a.wnext=r,a.whave=a.wsize):(a.wnext+=n,a.wnext===a.wsize&&(a.wnext=0),a.whave>>8&255,i.check=d(i.check,M,2,0),u=0,w=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",i.mode=p;break}if(8!=(15&u)){e.msg="unknown compression method",i.mode=p;break}if(w-=4,z=8+(15&(u>>>=4)),0===i.wbits)i.wbits=z;else if(z>i.wbits){e.msg="invalid window size",i.mode=p;break}i.dmax=1<>8&1),512&i.flags&&(M[0]=255&u,M[1]=u>>>8&255,i.check=d(i.check,M,2,0)),u=0,w=0,i.mode=3;case 3:for(;w<32;){if(0===l)break e;l--,u+=r[a++]<>>8&255,M[2]=u>>>16&255,M[3]=u>>>24&255,i.check=d(i.check,M,4,0)),u=0,w=0,i.mode=4;case 4:for(;w<16;){if(0===l)break e;l--,u+=r[a++]<>8),512&i.flags&&(M[0]=255&u,M[1]=u>>>8&255,i.check=d(i.check,M,2,0)),u=0,w=0,i.mode=5;case 5:if(1024&i.flags){for(;w<16;){if(0===l)break e;l--,u+=r[a++]<>>8&255,i.check=d(i.check,M,2,0)),u=0,w=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&((_=i.length)>l&&(_=l),_&&(i.head&&(z=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),s.arraySet(i.head.extra,r,a,_,z)),512&i.flags&&(i.check=d(i.check,r,_,a)),l-=_,a+=_,i.length-=_),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===l)break e;_=0;do{z=r[a+_++],i.head&&z&&i.length<65536&&(i.head.name+=String.fromCharCode(z))}while(z&&_>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=k;break;case 10:for(;w<32;){if(0===l)break e;l--,u+=r[a++]<>>=7&w,w-=7&w,i.mode=27;break}for(;w<3;){if(0===l)break e;l--,u+=r[a++]<>>=1)){case 0:i.mode=14;break;case 1:if(R(i),i.mode=20,6===t){u>>>=2,w-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=p}u>>>=2,w-=2;break;case 14:for(u>>>=7&w,w-=7&w;w<32;){if(0===l)break e;l--,u+=r[a++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=p;break}if(i.length=65535&u,u=0,w=0,i.mode=15,6===t)break e;case 15:i.mode=16;case 16:if(_=i.length){if(_>l&&(_=l),_>c&&(_=c),0===_)break e;s.arraySet(n,r,a,_,o),l-=_,a+=_,c-=_,o+=_,i.length-=_;break}i.mode=k;break;case 17:for(;w<14;){if(0===l)break e;l--,u+=r[a++]<>>=5,w-=5,i.ndist=1+(31&u),u>>>=5,w-=5,i.ncode=4+(15&u),u>>>=4,w-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=p;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,w-=3}for(;i.have<19;)i.lens[j[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,V={bits:i.lenbits},D=v(0,i.lens,0,19,i.lencode,0,i.work,V),i.lenbits=V.bits,D){e.msg="invalid code lengths set",i.mode=p;break}i.have=0,i.mode=19;case 19:for(;i.have>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=r[a++]<>>=E,w-=E,i.lens[i.have++]=T;else{if(16===T){for(P=E+2;w>>=E,w-=E,0===i.have){e.msg="invalid bit length repeat",i.mode=p;break}z=i.lens[i.have-1],_=3+(3&u),u>>>=2,w-=2}else if(17===T){for(P=E+3;w>>=E)),u>>>=3,w-=3}else{for(P=E+7;w>>=E)),u>>>=7,w-=7}if(i.have+_>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=p;break}for(;_--;)i.lens[i.have++]=z}}if(i.mode===p)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=p;break}if(i.lenbits=9,V={bits:i.lenbits},D=v(1,i.lens,0,i.nlen,i.lencode,0,i.work,V),i.lenbits=V.bits,D){e.msg="invalid literal/lengths set",i.mode=p;break}if(i.distbits=6,i.distcode=i.distdyn,V={bits:i.distbits},D=v(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,V),i.distbits=V.bits,D){e.msg="invalid distances set",i.mode=p;break}if(i.mode=20,6===t)break e;case 20:i.mode=21;case 21:if(l>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=l,i.hold=u,i.bits=w,h(e,m),o=e.next_out,n=e.output,c=e.avail_out,a=e.next_in,r=e.input,l=e.avail_in,u=i.hold,w=i.bits,i.mode===k&&(i.back=-1);break}for(i.back=0;A=(O=i.lencode[u&(1<>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=r[a++]<>U)])>>>16&255,T=65535&O,!(U+(E=O>>>24)<=w);){if(0===l)break e;l--,u+=r[a++]<>>=U,w-=U,i.back+=U}if(u>>>=E,w-=E,i.back+=E,i.length=T,0===A){i.mode=26;break}if(32&A){i.back=-1,i.mode=k;break}if(64&A){e.msg="invalid literal/length code",i.mode=p;break}i.extra=15&A,i.mode=22;case 22:if(i.extra){for(P=i.extra;w>>=i.extra,w-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;A=(O=i.distcode[u&(1<>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=r[a++]<>U)])>>>16&255,T=65535&O,!(U+(E=O>>>24)<=w);){if(0===l)break e;l--,u+=r[a++]<>>=U,w-=U,i.back+=U}if(u>>>=E,w-=E,i.back+=E,64&A){e.msg="invalid distance code",i.mode=p;break}i.offset=T,i.extra=15&A,i.mode=24;case 24:if(i.extra){for(P=i.extra;w>>=i.extra,w-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=p;break}i.mode=25;case 25:if(0===c)break e;if(_=m-c,i.offset>_){if((_=i.offset-_)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=p;break}_>i.wnext?(_-=i.wnext,x=i.wsize-_):x=i.wnext-_,_>i.length&&(_=i.length),B=i.window}else B=n,x=o-i.offset,_=i.length;_>c&&(_=c),c-=_,i.length-=_;do{n[o++]=B[x++]}while(--_);0===i.length&&(i.mode=21);break;case 26:if(0===c)break e;n[o++]=i.length,c--,i.mode=21;break;case 27:if(i.wrap){for(;w<32;){if(0===l)break e;l--,u|=r[a++]<=252?6:P>=248?5:P>=240?4:P>=224?3:P>=192?2:1;V[254]=V[254]=1;function O(e,t){if(t<65534&&(e.subarray&&D||!e.subarray&&z))return String.fromCharCode.apply(null,s.shrinkBuf(e,t));for(var i="",r=0;r>>6,t[a++]=128|63&i):i<65536?(t[a++]=224|i>>>12,t[a++]=128|i>>>6&63,t[a++]=128|63&i):(t[a++]=240|i>>>18,t[a++]=128|i>>>12&63,t[a++]=128|i>>>6&63,t[a++]=128|63&i);return t},j=function(e){for(var t=new s.Buf8(e.length),i=0,r=t.length;i4)s[r++]=65533,i+=a-1;else{for(n&=2===a?31:3===a?15:7;a>1&&i1?s[r++]=65533:n<65536?s[r++]=n:(n-=65536,s[r++]=55296|n>>10&1023,s[r++]=56320|1023&n)}return O(s,r)},N=function(e,t){var i;for((t=t||e.length)>e.length&&(t=e.length),i=t-1;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+V[e[i]]>t?i:t},L=0,Y=2,F=4,G=0,K=1,Q=2,q=-5,W={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var J=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};var X=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1},Z=Object.prototype.toString;function $(e){if(!(this instanceof $))return new $(e);this.options=s.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new J,this.strm.avail_out=0;var i=I.inflateInit2(this.strm,t.windowBits);if(i!==G)throw new Error(W[i]);if(this.header=new X,I.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=M(t.dictionary):"[object ArrayBuffer]"===Z.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=I.inflateSetDictionary(this.strm,t.dictionary))!==G))throw new Error(W[i])}function ee(e,t){var i=new $(t);if(i.push(e,!0),i.err)throw i.msg||W[i.err];return i.result}$.prototype.push=function(e,t){var i,r,n,a,o,f=this.strm,l=this.options.chunkSize,d=this.options.dictionary,h=!1;if(this.ended)return!1;r=t===~~t?t:!0===t?F:L,"string"==typeof e?f.input=j(e):"[object ArrayBuffer]"===Z.call(e)?f.input=new Uint8Array(e):f.input=e,f.next_in=0,f.avail_in=f.input.length;do{if(0===f.avail_out&&(f.output=new s.Buf8(l),f.next_out=0,f.avail_out=l),(i=I.inflate(f,L))===Q&&d&&(i=I.inflateSetDictionary(this.strm,d)),i===q&&!0===h&&(i=G,h=!1),i!==K&&i!==G)return this.onEnd(i),this.ended=!0,!1;f.next_out&&(0!==f.avail_out&&i!==K&&(0!==f.avail_in||r!==F&&r!==Y)||("string"===this.options.to?(n=N(f.output,f.next_out),a=f.next_out-n,o=H(f.output,n),f.next_out=a,f.avail_out=l-a,a&&s.arraySet(f.output,f.output,n,a,0),this.onData(o)):this.onData(s.shrinkBuf(f.output,f.next_out)))),0===f.avail_in&&0===f.avail_out&&(h=!0)}while((f.avail_in>0||0===f.avail_out)&&i!==K);return i===K&&(r=F),r===F?(i=I.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===G):r!==Y||(this.onEnd(G),f.avail_out=0,!0)},$.prototype.onData=function(e){this.chunks.push(e)},$.prototype.onEnd=function(e){e===G&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var te={Inflate:$,inflate:ee,inflateRaw:function(e,t){return(t=t||{}).raw=!0,ee(e,t)},ungzip:ee},ie=Uint16Array.BYTES_PER_ELEMENT,re=Int32Array.BYTES_PER_ELEMENT,ne=Uint32Array.BYTES_PER_ELEMENT,ae={METADATA:0,TERRAIN:1,DBROOT:2};ae.fromString=function(e){return"Metadata"===e?ae.METADATA:"Terrain"===e?ae.TERRAIN:"DbRoot"===e?ae.DBROOT:void 0};var oe=1953029805,se=2917034100;return i((function(t,i){var n=ae.fromString(t.type),a=t.buffer;r(t.key,a);var s=function(t){var i=new DataView(t),r=0,n=i.getUint32(r,!0);if(r+=ne,n!==oe&&n!==se)throw new e.RuntimeError("Invalid magic");var a=i.getUint32(r,n===oe);r+=ne;var o=new Uint8Array(t,r),s=te.inflate(o);if(s.length!==a)throw new e.RuntimeError("Size of packet doesn't match header");return s}(a);a=s.buffer;var f=s.length;switch(n){case ae.METADATA:return function(t,i,r){var n=new DataView(t),a=0,s=n.getUint32(a,!0);if(a+=ne,32301!==s)throw new e.RuntimeError("Invalid magic");var f=n.getUint32(a,!0);if(a+=ne,1!==f)throw new e.RuntimeError("Invalid data type. Must be 1 for QuadTreePacket");var l=n.getUint32(a,!0);if(a+=ne,2!==l)throw new e.RuntimeError("Invalid QuadTreePacket version. Only version 2 is supported.");var d=n.getInt32(a,!0);a+=re;var h=n.getInt32(a,!0);if(a+=re,32!==h)throw new e.RuntimeError("Invalid instance size.");var c=n.getInt32(a,!0);a+=re;var u=n.getInt32(a,!0);a+=re;var w=n.getInt32(a,!0);if(c!==d*h+(a+=re))throw new e.RuntimeError("Invalid dataBufferOffset");if(c+u+w!==i)throw new e.RuntimeError("Invalid packet offsets");for(var b=[],m=0;mi)throw new e.RuntimeError("Malformed terrain packet found.")}return t},o=0,s=[];for(;s.length<5;){var f=o;o=a(o);var l=t.slice(f,o);r.push(l),s.push(l)}return s}(a,f,i);case ae.DBROOT:return i.push(a),{buffer:a}}}))}));