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