var clipboard,plugins,wasm_memory,high_dpi,FS,GL,Module,wasm_exports,emscripten_shaders_hack,importObject,ctx,quad_socket,connected,received_buffer,uid,ongoing_requests;"use strict";const version="0.1.26",canvas=document.querySelector("#glcanvas"),gl=canvas.getContext("webgl");gl===null&&alert("Unable to initialize WebGL. Your browser or machine may not support it."),clipboard=null,plugins=[];high_dpi=!1,canvas.focus(),canvas.requestPointerLock=canvas.requestPointerLock||canvas.mozRequestPointerLock||function(){},document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||function(){};function assert(a,b){a==!1&&alert(b)}function acquireVertexArrayObjectExtension(a){var b=a.getExtension('OES_vertex_array_object');b?(a.createVertexArray=function(){return b.createVertexArrayOES()},a.deleteVertexArray=function(a){b.deleteVertexArrayOES(a)},a.bindVertexArray=function(a){b.bindVertexArrayOES(a)},a.isVertexArray=function(a){return b.isVertexArrayOES(a)}):alert("Unable to get OES_vertex_array_object extension")}function acquireInstancedArraysExtension(a){var b=a.getExtension('ANGLE_instanced_arrays');b&&(a.vertexAttribDivisor=function(a,c){b.vertexAttribDivisorANGLE(a,c)},a.drawArraysInstanced=function(a,c,d,e){b.drawArraysInstancedANGLE(a,c,d,e)},a.drawElementsInstanced=function(a,c,d,e,f){b.drawElementsInstancedANGLE(a,c,d,e,f)})}function acquireDisjointTimerQueryExtension(a){var b=a.getExtension('EXT_disjoint_timer_query');b&&(a.createQuery=function(){return b.createQueryEXT()},a.beginQuery=function(a,c){return b.beginQueryEXT(a,c)},a.endQuery=function(a){return b.endQueryEXT(a)},a.deleteQuery=function(a){b.deleteQueryEXT(a)},a.getQueryObject=function(a,c){return b.getQueryObjectEXT(a,c)})}acquireVertexArrayObjectExtension(gl),acquireInstancedArraysExtension(gl),acquireDisjointTimerQueryExtension(gl),gl.getExtension('WEBGL_depth_texture')==null&&alert("Cant initialize WEBGL_depth_texture extension");function getArray(a,b,c){return new b(wasm_memory.buffer,a,c)}function UTF8ToString(i,j){var b,h,c,a,d,f,g;let e=new Uint8Array(wasm_memory.buffer,i);for(b=0,h=b+j,c='';!(b>=h);){if(a=e[b++],!a)return c;if(!(a&128)){c+=String.fromCharCode(a);continue}if(d=e[b++]&63,(a&224)==192){c+=String.fromCharCode((a&31)<<6|d);continue}f=e[b++]&63,(a&240)==224?a=(a&15)<<12|d<<6|f:((a&248)!=240&&console.warn('Invalid UTF-8 leading byte 0x'+a.toString(16)+' encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!'),a=(a&7)<<18|d<<12|f<<6|e[b++]&63),a<65536?c+=String.fromCharCode(a):(g=a-65536,c+=String.fromCharCode(55296|g>>10,56320|g&1023))}return c}function stringToUTF8(f,c,b,g){for(var h=b,e=b+g,d=0,a,i;d=55296&&a<=57343&&(i=f.charCodeAt(++d),a=65536+((a&1023)<<10)|i&1023),a<=127){if(b>=e)break;c[b++]=a}else if(a<=2047){if(b+1>=e)break;c[b++]=192|a>>6,c[b++]=128|a&63}else if(a<=65535){if(b+2>=e)break;c[b++]=224|a>>12,c[b++]=128|a>>6&63,c[b++]=128|a&63}else{if(b+3>=e)break;a>=2097152&&console.warn('Invalid Unicode code point 0x'+a.toString(16)+' encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).'),c[b++]=240|a>>18,c[b++]=128|a>>12&63,c[b++]=128|a>>6&63,c[b++]=128|a&63}return b-h}FS={loaded_files:[],unique_id:0},GL={counter:1,buffers:[],mappedBuffers:{},programs:[],framebuffers:[],renderbuffers:[],textures:[],uniforms:[],shaders:[],vaos:[],timerQueries:[],contexts:{},programInfos:{},getNewId:function(b){for(var c=GL.counter++,a=b.length;a=0&&b=GL.counter){console.error("GL_INVALID_VALUE in glGetProgramiv");return}if(e=GL.programInfos[a],!e){console.error('GL_INVALID_OPERATION in glGetProgramiv(program='+a+', pname='+b+', p=0x'+c.toString(16)+'): The specified GL object name does not refer to a program object!');return}if(b==35716)d=gl.getProgramInfoLog(GL.programs[a]),assert(d!==null),getArray(c,Int32Array,1)[0]=d.length+1;else if(b==35719){console.error("unsupported operation");return}else if(b==35722){console.error("unsupported operation");return}else if(b==35381){console.error("unsupported operation");return}else getArray(c,Int32Array,1)[0]=gl.getProgramParameter(GL.programs[a],b)},glCreateShader:function(b){var a=GL.getNewId(GL.shaders);return GL.shaders[a]=gl.createShader(b),a},glStencilFuncSeparate:function(a,b,c,d){gl.stencilFuncSeparate(a,b,c,d)},glStencilMaskSeparate:function(a,b){gl.stencilMaskSeparate(a,b)},glStencilOpSeparate:function(a,b,c,d){gl.stencilOpSeparate(a,b,c,d)},glFrontFace:function(a){gl.frontFace(a)},glCullFace:function(a){gl.cullFace(a)},glCopyTexImage2D:function(a,b,c,d,e,f,g,h){gl.copyTexImage2D(a,b,c,d,e,f,g,h)},glShaderSource:function(b,d,e,f){var a,c;GL.validateGLObjectID(GL.shaders,b,'glShaderSource','shader'),a=GL.getSource(b,d,e,f),emscripten_shaders_hack&&(a=a.replace(/#extension GL_OES_standard_derivatives : enable/g,""),a=a.replace(/#extension GL_EXT_shader_texture_lod : enable/g,''),c='',a.indexOf('gl_FragColor')!=-1&&(c+='out mediump vec4 GL_FragColor;\n',a=a.replace(/gl_FragColor/g,'GL_FragColor')),a.indexOf('attribute')!=-1?(a=a.replace(/attribute/g,'in'),a=a.replace(/varying/g,'out')):a=a.replace(/varying/g,'in'),a=a.replace(/textureCubeLodEXT/g,'textureCubeLod'),a=a.replace(/texture2DLodEXT/g,'texture2DLod'),a=a.replace(/texture2DProjLodEXT/g,'texture2DProjLod'),a=a.replace(/texture2DGradEXT/g,'texture2DGrad'),a=a.replace(/texture2DProjGradEXT/g,'texture2DProjGrad'),a=a.replace(/textureCubeGradEXT/g,'textureCubeGrad'),a=a.replace(/textureCube/g,'texture'),a=a.replace(/texture1D/g,'texture'),a=a.replace(/texture2D/g,'texture'),a=a.replace(/texture3D/g,'texture'),a=a.replace(/#version 100/g,'#version 300 es\n'+c)),gl.shaderSource(GL.shaders[b],a)},glGetProgramInfoLog:function(d,c,g,e){var b,a;GL.validateGLObjectID(GL.programs,d,'glGetProgramInfoLog','program'),b=gl.getProgramInfoLog(GL.programs[d]),assert(b!==null);let f=getArray(e,Uint8Array,c);for(a=0;a>24&255,c=a>>16&255,d=a&65535;return b+"."+c+"."+d}function init_plugins(b){var a,c,d;if(b==void 0)return;for(a=0;a(add_missing_functions_stabs(a),WebAssembly.instantiate(a,importObject))).then(a=>{wasm_memory=a.exports.memory,wasm_exports=a.exports;var b=u32_to_semver(wasm_exports.crate_version());version!=b&&console.error("Version mismatch: gl.js version is: "+version+", rust sapp-wasm crate version is: "+b),init_plugins(plugins),a.exports.main()}).catch(a=>{console.error("WASM failed to load, probably incompatible gl.js version"),console.error(a)}):a.then(function(a){return a.arrayBuffer()}).then(function(a){return WebAssembly.compile(a)}).then(function(a){return add_missing_functions_stabs(a),WebAssembly.instantiate(a,importObject)}).then(function(a){wasm_memory=a.exports.memory,wasm_exports=a.exports;var b=u32_to_semver(wasm_exports.crate_version());version!=b&&console.error("Version mismatch: gl.js version is: "+version+", rust sapp-wasm crate version is: "+b),init_plugins(plugins),a.exports.main()}).catch(a=>{console.error("WASM failed to load, probably incompatible gl.js version"),console.error(a)})}const AudioContext=window.AudioContext||window.webkitAudioContext;let audio_context,sounds={},audio_next_handle=1;function audio_init(){if(audio_context==null){audio_context=new AudioContext,audio_listener=audio_context.listener;let a=audio_context.createBufferSource();a.buffer=audio_context.createBuffer(1,1,22050),a.connect(audio_context.destination),a.start(0)}}function audio_add_buffer(b,c){let d=wasm_memory.buffer.slice(b,b+c),a=audio_next_handle;return audio_next_handle+=1,sounds[a]={},audio_context.decodeAudioData(d,function(b){sounds[a].buffer=b},function(a){console.error("Failed to decode audio buffer",a)}),a}function audio_source_is_loaded(a){return a in sounds&&sounds[a].buffer!=void 0}function audio_play_buffer(f,g,h,j,i){audio_source_stop(f);var d=sounds[f];let a=audio_context.createBufferSource();a.loop=i;let b=null,c=null,e=null;if(g!=1||h!=1){b=audio_context.createGain(),a.connect(b),c=audio_context.createGain(),a.connect(c);let e=audio_context.createChannelMerger(2);b.connect(e,0,0),c.connect(e,0,1),e.connect(audio_context.destination),b.gain.value=g,c.gain.value=h,d.merger=e}else a.connect(audio_context.destination);a.playbackRate.value=j,d.source=a,d.gains=[b,c],a.onended=function(){a.disconnect(),b&&b.disconnect(),c&&c.disconnect(),e&&e.disconnect()},a.buffer=d.buffer;try{a.start(0)}catch(a){console.error("Error starting sound",a)}}function audio_source_set_volume(a,d,e){if(!(a in sounds))return;let b=sounds[a].gains,c=audio_context.currentTime+1/120;b[0].gain.linearRampToValueAtTime(d,c),b[1].gain.linearRampToValueAtTime(e,c)}function audio_source_stop(a){if(!(a in sounds)){console.log("stopping already remvoed sound");return}if(sounds[a].source==void 0)return;try{sounds[a].source.stop(),sounds[a].source.disconnect();for(node of sounds[a].gains)node!=null&&node.disconnect();sounds[a].merger&&sounds[a].merger.disconnect()}catch(a){console.error("Error stopping sound",a)}delete sounds[a].source,delete sounds[a].gains}function register_plugin(a){a.env.audio_init=audio_init,a.env.audio_add_buffer=audio_add_buffer,a.env.audio_play_buffer=audio_play_buffer,a.env.audio_source_is_loaded=audio_source_is_loaded,a.env.audio_source_set_volume=audio_source_set_volume,a.env.audio_source_stop=audio_source_stop}miniquad_add_plugin({register_plugin,version:"0.1.0",name:"macroquad_audio"}),ctx=null,js_objects={},unique_js_id=0,register_plugin=function(a){a.env.js_create_string=function(a,b){var c=UTF8ToString(a,b);return js_object(c)},a.env.js_create_buffer=function(c,d){var a=new Uint8Array(wasm_memory.buffer,c,d),b=new Uint8Array(new ArrayBuffer(a.byteLength));return b.set(new Uint8Array(a)),js_object(b)},a.env.js_create_object=function(){var a={};return js_object(a)},a.env.js_set_field_f32=function(a,b,c,d){var e=UTF8ToString(b,c);js_objects[a][e]=d},a.env.js_set_field_string=function(a,b,c,d,e){var f=UTF8ToString(b,c),g=UTF8ToString(d,e);js_objects[a][f]=g},a.env.js_unwrap_to_str=function(c,h,d){for(var e=js_objects[c],b=toUTF8Array(e),f=b.length,g=new Uint8Array(wasm_memory.buffer,h,d),a=0;a>6,128|a&63):a<55296||a>=57344?b.push(224|a>>12,128|a>>6&63,128|a&63):(c++,a=65536+((a&1023)<<10|d.charCodeAt(c)&1023),b.push(240|a>>18,128|a>>12&63,128|a>>6&63,128|a&63));return b}function js_object(b){var a=unique_js_id;return js_objects[a]=b,unique_js_id+=1,a}function consume_js_object(a){var b=js_objects[a];return delete js_objects[a],b}function get_js_object(a){return js_objects[a]}function on_init(){}register_plugin=function(a){a.env.ws_connect=ws_connect,a.env.ws_is_connected=ws_is_connected,a.env.ws_send=ws_send,a.env.ws_try_recv=ws_try_recv,a.env.http_make_request=http_make_request,a.env.http_try_recv=http_try_recv},miniquad_add_plugin({register_plugin,on_init,version:"0.1.1",name:"quad_net"});connected=0,received_buffer=[];function ws_is_connected(){return connected}function ws_connect(a){quad_socket=new WebSocket(consume_js_object(a)),quad_socket.binaryType='arraybuffer',quad_socket.onopen=function(){connected=1},quad_socket.onmessage=function(a){if(typeof a.data=="string")received_buffer.push({text:1,data:a.data});else{var b=new Uint8Array(a.data);received_buffer.push({text:0,data:b})}}}function ws_send(b){var a=consume_js_object(b);a.buffer!=void 0?quad_socket.send(a.buffer):quad_socket.send(a)}function ws_try_recv(){return received_buffer.length!=0?js_object(received_buffer.shift()):-1}uid=0,ongoing_requests={};function http_try_recv(a){if(ongoing_requests[a]!=void 0&&ongoing_requests[a]!=null){var b=ongoing_requests[a];return ongoing_requests[a]=null,js_object(b)}return-1}function http_make_request(c,f,i,j){var e=uid,b,g,h,d,a;uid+=1;c==0&&(b='POST'),c==1&&(b='PUT'),c==2&&(b='GET'),c==3&&(b='DELETE'),g=consume_js_object(f),h=consume_js_object(i),d=consume_js_object(j),a=new XMLHttpRequest,a.open(b,g,!0),a.responseType='arraybuffer';for(const b in d)a.setRequestHeader(b,d[b]);return a.onload=function(b){if(this.status==200){var a=new Uint8Array(this.response);ongoing_requests[e]=a}},a.onerror=function(a){console.error("Failed to make a request"),console.error(a)},a.send(h),e}