Add jobquest

This commit is contained in:
2024-02-23 17:04:33 -05:00
commit a68515a4ef
264 changed files with 82692 additions and 0 deletions

15
js/libs/fpsmeter.js Normal file
View File

@@ -0,0 +1,15 @@
/*! FPSMeter 0.3.1 - 9th May 2013 | https://github.com/Darsain/fpsmeter */
(function(m,j){function s(a,e){for(var g in e)try{a.style[g]=e[g]}catch(j){}return a}function H(a){return null==a?String(a):"object"===typeof a||"function"===typeof a?Object.prototype.toString.call(a).match(/\s([a-z]+)/i)[1].toLowerCase()||"object":typeof a}function R(a,e){if("array"!==H(e))return-1;if(e.indexOf)return e.indexOf(a);for(var g=0,j=e.length;g<j;g++)if(e[g]===a)return g;return-1}function I(){var a=arguments,e;for(e in a[1])if(a[1].hasOwnProperty(e))switch(H(a[1][e])){case "object":a[0][e]=
I({},a[0][e],a[1][e]);break;case "array":a[0][e]=a[1][e].slice(0);break;default:a[0][e]=a[1][e]}return 2<a.length?I.apply(null,[a[0]].concat(Array.prototype.slice.call(a,2))):a[0]}function N(a){a=Math.round(255*a).toString(16);return 1===a.length?"0"+a:a}function S(a,e,g,j){if(a.addEventListener)a[j?"removeEventListener":"addEventListener"](e,g,!1);else if(a.attachEvent)a[j?"detachEvent":"attachEvent"]("on"+e,g)}function D(a,e){function g(a,b,d,c){return y[0|a][Math.round(Math.min((b-d)/(c-d)*J,J))]}
function r(){f.legend.fps!==q&&(f.legend.fps=q,f.legend[T]=q?"FPS":"ms");K=q?b.fps:b.duration;f.count[T]=999<K?"999+":K.toFixed(99<K?0:d.decimals)}function m(){z=A();L<z-d.threshold&&(b.fps-=b.fps/Math.max(1,60*d.smoothing/d.interval),b.duration=1E3/b.fps);for(c=d.history;c--;)E[c]=0===c?b.fps:E[c-1],F[c]=0===c?b.duration:F[c-1];r();if(d.heat){if(w.length)for(c=w.length;c--;)w[c].el.style[h[w[c].name].heatOn]=q?g(h[w[c].name].heatmap,b.fps,0,d.maxFps):g(h[w[c].name].heatmap,b.duration,d.threshold,
0);if(f.graph&&h.column.heatOn)for(c=u.length;c--;)u[c].style[h.column.heatOn]=q?g(h.column.heatmap,E[c],0,d.maxFps):g(h.column.heatmap,F[c],d.threshold,0)}if(f.graph)for(p=0;p<d.history;p++)u[p].style.height=(q?E[p]?Math.round(O/d.maxFps*Math.min(E[p],d.maxFps)):0:F[p]?Math.round(O/d.threshold*Math.min(F[p],d.threshold)):0)+"px"}function k(){20>d.interval?(x=M(k),m()):(x=setTimeout(k,d.interval),P=M(m))}function G(a){a=a||window.event;a.preventDefault?(a.preventDefault(),a.stopPropagation()):(a.returnValue=
!1,a.cancelBubble=!0);b.toggle()}function U(){d.toggleOn&&S(f.container,d.toggleOn,G,1);a.removeChild(f.container)}function V(){f.container&&U();h=D.theme[d.theme];y=h.compiledHeatmaps||[];if(!y.length&&h.heatmaps.length){for(p=0;p<h.heatmaps.length;p++){y[p]=[];for(c=0;c<=J;c++){var b=y[p],e=c,g;g=0.33/J*c;var j=h.heatmaps[p].saturation,m=h.heatmaps[p].lightness,n=void 0,k=void 0,l=void 0,t=l=void 0,v=n=k=void 0,v=void 0,l=0.5>=m?m*(1+j):m+j-m*j;0===l?g="#000":(t=2*m-l,k=(l-t)/l,g*=6,n=Math.floor(g),
v=g-n,v*=l*k,0===n||6===n?(n=l,k=t+v,l=t):1===n?(n=l-v,k=l,l=t):2===n?(n=t,k=l,l=t+v):3===n?(n=t,k=l-v):4===n?(n=t+v,k=t):(n=l,k=t,l-=v),g="#"+N(n)+N(k)+N(l));b[e]=g}}h.compiledHeatmaps=y}f.container=s(document.createElement("div"),h.container);f.count=f.container.appendChild(s(document.createElement("div"),h.count));f.legend=f.container.appendChild(s(document.createElement("div"),h.legend));f.graph=d.graph?f.container.appendChild(s(document.createElement("div"),h.graph)):0;w.length=0;for(var q in f)f[q]&&
h[q].heatOn&&w.push({name:q,el:f[q]});u.length=0;if(f.graph){f.graph.style.width=d.history*h.column.width+(d.history-1)*h.column.spacing+"px";for(c=0;c<d.history;c++)u[c]=f.graph.appendChild(s(document.createElement("div"),h.column)),u[c].style.position="absolute",u[c].style.bottom=0,u[c].style.right=c*h.column.width+c*h.column.spacing+"px",u[c].style.width=h.column.width+"px",u[c].style.height="0px"}s(f.container,d);r();a.appendChild(f.container);f.graph&&(O=f.graph.clientHeight);d.toggleOn&&("click"===
d.toggleOn&&(f.container.style.cursor="pointer"),S(f.container,d.toggleOn,G))}"object"===H(a)&&a.nodeType===j&&(e=a,a=document.body);a||(a=document.body);var b=this,d=I({},D.defaults,e||{}),f={},u=[],h,y,J=100,w=[],W=0,B=d.threshold,Q=0,L=A()-B,z,E=[],F=[],x,P,q="fps"===d.show,O,K,c,p;b.options=d;b.fps=0;b.duration=0;b.isPaused=0;b.tickStart=function(){Q=A()};b.tick=function(){z=A();W=z-L;B+=(W-B)/d.smoothing;b.fps=1E3/B;b.duration=Q<L?B:z-Q;L=z};b.pause=function(){x&&(b.isPaused=1,clearTimeout(x),
C(x),C(P),x=P=0);return b};b.resume=function(){x||(b.isPaused=0,k());return b};b.set=function(a,c){d[a]=c;q="fps"===d.show;-1!==R(a,X)&&V();-1!==R(a,Y)&&s(f.container,d);return b};b.showDuration=function(){b.set("show","ms");return b};b.showFps=function(){b.set("show","fps");return b};b.toggle=function(){b.set("show",q?"ms":"fps");return b};b.hide=function(){b.pause();f.container.style.display="none";return b};b.show=function(){b.resume();f.container.style.display="block";return b};b.destroy=function(){b.pause();
U();b.tick=b.tickStart=function(){}};V();k()}var A,r=m.performance;A=r&&(r.now||r.webkitNow)?r[r.now?"now":"webkitNow"].bind(r):function(){return+new Date};for(var C=m.cancelAnimationFrame||m.cancelRequestAnimationFrame,M=m.requestAnimationFrame,r=["moz","webkit","o"],G=0,k=0,Z=r.length;k<Z&&!C;++k)M=(C=m[r[k]+"CancelAnimationFrame"]||m[r[k]+"CancelRequestAnimationFrame"])&&m[r[k]+"RequestAnimationFrame"];C||(M=function(a){var e=A(),g=Math.max(0,16-(e-G));G=e+g;return m.setTimeout(function(){a(e+
g)},g)},C=function(a){clearTimeout(a)});var T="string"===H(document.createElement("div").textContent)?"textContent":"innerText";D.extend=I;window.FPSMeter=D;D.defaults={interval:100,smoothing:10,show:"fps",toggleOn:"click",decimals:1,maxFps:60,threshold:100,position:"absolute",zIndex:10,left:"5px",top:"5px",right:"auto",bottom:"auto",margin:"0 0 0 0",theme:"dark",heat:0,graph:0,history:20};var X=["toggleOn","theme","heat","graph","history"],Y="position zIndex left top right bottom margin".split(" ")})(window);(function(m,j){j.theme={};var s=j.theme.base={heatmaps:[],container:{heatOn:null,heatmap:null,padding:"5px",minWidth:"95px",height:"30px",lineHeight:"30px",textAlign:"right",textShadow:"none"},count:{heatOn:null,heatmap:null,position:"absolute",top:0,right:0,padding:"5px 10px",height:"30px",fontSize:"24px",fontFamily:"Consolas, Andale Mono, monospace",zIndex:2},legend:{heatOn:null,heatmap:null,position:"absolute",top:0,left:0,padding:"5px 10px",height:"30px",fontSize:"12px",lineHeight:"32px",fontFamily:"sans-serif",
textAlign:"left",zIndex:2},graph:{heatOn:null,heatmap:null,position:"relative",boxSizing:"padding-box",MozBoxSizing:"padding-box",height:"100%",zIndex:1},column:{width:4,spacing:1,heatOn:null,heatmap:null}};j.theme.dark=j.extend({},s,{heatmaps:[{saturation:0.8,lightness:0.8}],container:{background:"#222",color:"#fff",border:"1px solid #1a1a1a",textShadow:"1px 1px 0 #222"},count:{heatOn:"color"},column:{background:"#3f3f3f"}});j.theme.light=j.extend({},s,{heatmaps:[{saturation:0.5,lightness:0.5}],
container:{color:"#666",background:"#fff",textShadow:"1px 1px 0 rgba(255,255,255,.5), -1px -1px 0 rgba(255,255,255,.5)",boxShadow:"0 0 0 1px rgba(0,0,0,.1)"},count:{heatOn:"color"},column:{background:"#eaeaea"}});j.theme.colorful=j.extend({},s,{heatmaps:[{saturation:0.5,lightness:0.6}],container:{heatOn:"backgroundColor",background:"#888",color:"#fff",textShadow:"1px 1px 0 rgba(0,0,0,.2)",boxShadow:"0 0 0 1px rgba(0,0,0,.1)"},column:{background:"#777",backgroundColor:"rgba(0,0,0,.2)"}});j.theme.transparent=
j.extend({},s,{heatmaps:[{saturation:0.8,lightness:0.5}],container:{padding:0,color:"#fff",textShadow:"1px 1px 0 rgba(0,0,0,.5)"},count:{padding:"0 5px",height:"40px",lineHeight:"40px"},legend:{padding:"0 5px",height:"40px",lineHeight:"42px"},graph:{height:"40px"},column:{width:5,background:"#999",heatOn:"backgroundColor",opacity:0.5}})})(window,FPSMeter);

View File

@@ -0,0 +1,3 @@
/*! npm.im/iphone-inline-video */
var makeVideoPlayableInline=function(){"use strict";/*! npm.im/intervalometer */
function e(e,n,r,i){function t(r){d=n(t,i),e(r-(a||r)),a=r}var d,a;return{start:function(){d||t(0)},stop:function(){r(d),d=null,a=0}}}function n(n){return e(n,requestAnimationFrame,cancelAnimationFrame)}function r(e,n,r,i){function t(n){Boolean(e[r])===Boolean(i)&&n.stopImmediatePropagation(),delete e[r]}return e.addEventListener(n,t,!1),t}function i(e,n,r,i){function t(){return r[n]}function d(e){r[n]=e}i&&d(e[n]),Object.defineProperty(e,n,{get:t,set:d})}function t(e,n,r){r.addEventListener(n,function(){return e.dispatchEvent(new Event(n))})}function d(e,n){Promise.resolve().then(function(){e.dispatchEvent(new Event(n))})}function a(e){var n=new Audio;return t(e,"play",n),t(e,"playing",n),t(e,"pause",n),n.crossOrigin=e.crossOrigin,n.src=e.src||e.currentSrc||"data:",n}function o(e,n,r){(m||0)+200<Date.now()&&(e[g]=!0,m=Date.now()),r||(e.currentTime=n),A[++k%3]=100*n|0}function u(e){return e.driver.currentTime>=e.video.duration}function s(e){var n=this;n.video.readyState>=n.video.HAVE_FUTURE_DATA?(n.hasAudio||(n.driver.currentTime=n.video.currentTime+e*n.video.playbackRate/1e3,n.video.loop&&u(n)&&(n.driver.currentTime=0)),o(n.video,n.driver.currentTime)):n.video.networkState!==n.video.NETWORK_IDLE||n.video.buffered.length||n.video.load(),n.video.ended&&(delete n.video[g],n.video.pause(!0))}function c(){var e=this,n=e[b];return e.webkitDisplayingFullscreen?void e[E]():("data:"!==n.driver.src&&n.driver.src!==e.src&&(o(e,0,!0),n.driver.src=e.src),void(e.paused&&(n.paused=!1,e.buffered.length||e.load(),n.driver.play(),n.updater.start(),n.hasAudio||(d(e,"play"),n.video.readyState>=n.video.HAVE_ENOUGH_DATA&&d(e,"playing")))))}function v(e){var n=this,r=n[b];r.driver.pause(),r.updater.stop(),n.webkitDisplayingFullscreen&&n[T](),r.paused&&!e||(r.paused=!0,r.hasAudio||d(n,"pause"),n.ended&&(n[g]=!0,d(n,"ended")))}function p(e,r){var i=e[b]={};i.paused=!0,i.hasAudio=r,i.video=e,i.updater=n(s.bind(i)),r?i.driver=a(e):(e.addEventListener("canplay",function(){e.paused||d(e,"playing")}),i.driver={src:e.src||e.currentSrc||"data:",muted:!0,paused:!0,pause:function(){i.driver.paused=!0},play:function(){i.driver.paused=!1,u(i)&&o(e,0)},get ended(){return u(i)}}),e.addEventListener("emptied",function(){var n=!i.driver.src||"data:"===i.driver.src;i.driver.src&&i.driver.src!==e.src&&(o(e,0,!0),i.driver.src=e.src,n?i.driver.play():i.updater.stop())},!1),e.addEventListener("webkitbeginfullscreen",function(){e.paused?r&&!i.driver.buffered.length&&i.driver.load():(e.pause(),e[E]())}),r&&(e.addEventListener("webkitendfullscreen",function(){i.driver.currentTime=e.currentTime}),e.addEventListener("seeking",function(){A.indexOf(100*e.currentTime|0)<0&&(i.driver.currentTime=e.currentTime)}))}function l(e){var n=e[b];e[E]=e.play,e[T]=e.pause,e.play=c,e.pause=v,i(e,"paused",n.driver),i(e,"muted",n.driver,!0),i(e,"playbackRate",n.driver,!0),i(e,"ended",n.driver),i(e,"loop",n.driver,!0),r(e,"seeking"),r(e,"seeked"),r(e,"timeupdate",g,!1),r(e,"ended",g,!1)}function f(e,n,r){void 0===n&&(n=!0),void 0===r&&(r=!0),r&&!h||e[b]||(p(e,n),l(e),e.classList.add("IIV"),!n&&e.autoplay&&e.play(),/iPhone|iPod|iPad/.test(navigator.platform)||console.warn("iphone-inline-video is not guaranteed to work in emulated environments"))}var m,y="undefined"==typeof Symbol?function(e){return"@"+(e||"@")+Math.random()}:Symbol,h="object-fit"in document.head.style&&/iPhone|iPod/i.test(navigator.userAgent)&&!matchMedia("(-webkit-video-playable-inline)").matches,b=y(),g=y(),E=y("nativeplay"),T=y("nativepause"),A=[],k=0;return f.isWhitelisted=h,f}();

1
js/libs/lz-string.js Normal file

File diff suppressed because one or more lines are too long

428
js/libs/pixi-picture.js Normal file
View File

@@ -0,0 +1,428 @@
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var shaderLib = [
{
vertUniforms: "",
vertCode: "vTextureCoord = aTextureCoord;",
fragUniforms: "uniform vec4 uTextureClamp;",
fragCode: "vec2 textureCoord = clamp(vTextureCoord, uTextureClamp.xy, uTextureClamp.zw);"
},
{
vertUniforms: "uniform mat3 uTransform;",
vertCode: "vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;",
fragUniforms: "",
fragCode: "vec2 textureCoord = vTextureCoord;"
},
{
vertUniforms: "uniform mat3 uTransform;",
vertCode: "vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;",
fragUniforms: "uniform mat3 uMapCoord;\nuniform vec4 uClampFrame;\nuniform vec2 uClampOffset;",
fragCode: "vec2 textureCoord = mod(vTextureCoord - uClampOffset, vec2(1.0, 1.0)) + uClampOffset;" +
"\ntextureCoord = (uMapCoord * vec3(textureCoord, 1.0)).xy;" +
"\ntextureCoord = clamp(textureCoord, uClampFrame.xy, uClampFrame.zw);"
}
];
var PictureShader = (function (_super) {
__extends(PictureShader, _super);
function PictureShader(gl, vert, frag, tilingMode) {
var lib = shaderLib[tilingMode];
_super.call(this, gl, vert.replace(/%SPRITE_UNIFORMS%/gi, lib.vertUniforms)
.replace(/%SPRITE_CODE%/gi, lib.vertCode), frag.replace(/%SPRITE_UNIFORMS%/gi, lib.fragUniforms)
.replace(/%SPRITE_CODE%/gi, lib.fragCode));
this.bind();
this.tilingMode = tilingMode;
this.tempQuad = new PIXI.Quad(gl);
this.tempQuad.initVao(this);
this.uniforms.uColor = new Float32Array([1, 1, 1, 1]);
this.uniforms.uSampler = [0, 1];
}
PictureShader.blendVert = "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\nuniform mat3 mapMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vMapCoord;\n%SPRITE_UNIFORMS%\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n %SPRITE_CODE%\n vMapCoord = (mapMatrix * vec3(aVertexPosition, 1.0)).xy;\n}\n";
return PictureShader;
}(PIXI.Shader));
extras.PictureShader = PictureShader;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var overlayFrag = "\nvarying vec2 vTextureCoord;\nvarying vec2 vMapCoord;\nvarying vec4 vColor;\n\nuniform sampler2D uSampler[2];\nuniform vec4 uColor;\n%SPRITE_UNIFORMS%\n\nvoid main(void)\n{\n %SPRITE_CODE%\n vec4 source = texture2D(uSampler[0], textureCoord) * uColor;\n vec4 target = texture2D(uSampler[1], vMapCoord);\n\n //reverse hardlight\n if (source.a == 0.0) {\n gl_FragColor = vec4(0, 0, 0, 0);\n return;\n }\n //yeah, premultiplied\n vec3 Cb = source.rgb/source.a, Cs;\n if (target.a > 0.0) {\n Cs = target.rgb / target.a;\n }\n vec3 multiply = Cb * Cs * 2.0;\n vec3 Cs2 = Cs * 2.0 - 1.0;\n vec3 screen = Cb + Cs2 - Cb * Cs2;\n vec3 B;\n if (Cb.r <= 0.5) {\n B.r = multiply.r;\n } else {\n B.r = screen.r;\n }\n if (Cb.g <= 0.5) {\n B.g = multiply.g;\n } else {\n B.g = screen.g;\n }\n if (Cb.b <= 0.5) {\n B.b = multiply.b;\n } else {\n B.b = screen.b;\n }\n vec4 res;\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n res.a = source.a + target.a * (1.0-source.a);\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n}\n";
var HardLightShader = (function (_super) {
__extends(HardLightShader, _super);
function HardLightShader(gl, tilingMode) {
_super.call(this, gl, extras.PictureShader.blendVert, overlayFrag, tilingMode);
}
return HardLightShader;
}(extras.PictureShader));
extras.HardLightShader = HardLightShader;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
function mapFilterBlendModesToPixi(gl, array) {
if (array === void 0) { array = []; }
array[PIXI.BLEND_MODES.OVERLAY] = [new extras.OverlayShader(gl, 0), new extras.OverlayShader(gl, 1), new extras.OverlayShader(gl, 2)];
array[PIXI.BLEND_MODES.HARD_LIGHT] = [new extras.HardLightShader(gl, 0), new extras.HardLightShader(gl, 1), new extras.HardLightShader(gl, 2)];
return array;
}
extras.mapFilterBlendModesToPixi = mapFilterBlendModesToPixi;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var normalFrag = "\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nuniform sampler2D uSampler[2];\nuniform vec4 uColor;\n%SPRITE_UNIFORMS%\n\nvoid main(void)\n{\n %SPRITE_CODE%\n\n vec4 sample = texture2D(uSampler[0], textureCoord);\n gl_FragColor = sample * uColor;\n}\n";
var normalVert = "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n%SPRITE_UNIFORMS%\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n %SPRITE_CODE%\n}\n";
var NormalShader = (function (_super) {
__extends(NormalShader, _super);
function NormalShader(gl, tilingMode) {
_super.call(this, gl, normalVert, normalFrag, tilingMode);
}
return NormalShader;
}(extras.PictureShader));
extras.NormalShader = NormalShader;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var overlayFrag = "\nvarying vec2 vTextureCoord;\nvarying vec2 vMapCoord;\nvarying vec4 vColor;\n\nuniform sampler2D uSampler[2];\nuniform vec4 uColor;\n%SPRITE_UNIFORMS%\n\nvoid main(void)\n{\n %SPRITE_CODE%\n vec4 source = texture2D(uSampler[0], textureCoord) * uColor;\n vec4 target = texture2D(uSampler[1], vMapCoord);\n\n //reverse hardlight\n if (source.a == 0.0) {\n gl_FragColor = vec4(0, 0, 0, 0);\n return;\n }\n //yeah, premultiplied\n vec3 Cb = source.rgb/source.a, Cs;\n if (target.a > 0.0) {\n Cs = target.rgb / target.a;\n }\n vec3 multiply = Cb * Cs * 2.0;\n vec3 Cb2 = Cb * 2.0 - 1.0;\n vec3 screen = Cb2 + Cs - Cb2 * Cs;\n vec3 B;\n if (Cs.r <= 0.5) {\n B.r = multiply.r;\n } else {\n B.r = screen.r;\n }\n if (Cs.g <= 0.5) {\n B.g = multiply.g;\n } else {\n B.g = screen.g;\n }\n if (Cs.b <= 0.5) {\n B.b = multiply.b;\n } else {\n B.b = screen.b;\n }\n vec4 res;\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n res.a = source.a + target.a * (1.0-source.a);\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n}\n";
var OverlayShader = (function (_super) {
__extends(OverlayShader, _super);
function OverlayShader(gl, tilingMode) {
_super.call(this, gl, extras.PictureShader.blendVert, overlayFrag, tilingMode);
}
return OverlayShader;
}(extras.PictureShader));
extras.OverlayShader = OverlayShader;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
function nextPow2(v) {
v += (v === 0) ? 1 : 0;
--v;
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
return v + 1;
}
var PictureRenderer = (function (_super) {
__extends(PictureRenderer, _super);
function PictureRenderer(renderer) {
_super.call(this, renderer);
}
PictureRenderer.prototype.onContextChange = function () {
var gl = this.renderer.gl;
this.drawModes = extras.mapFilterBlendModesToPixi(gl);
this.normalShader = [new extras.NormalShader(gl, 0), new extras.NormalShader(gl, 1), new extras.NormalShader(gl, 2)];
this._tempClamp = new Float32Array(4);
this._tempColor = new Float32Array(4);
this._tempRect = new PIXI.Rectangle();
this._tempRect2 = new PIXI.Rectangle();
this._tempRect3 = new PIXI.Rectangle();
this._tempMatrix = new PIXI.Matrix();
this._tempMatrix2 = new PIXI.Matrix();
this._bigBuf = new Uint8Array(1 << 20);
this._renderTexture = new PIXI.BaseRenderTexture(1024, 1024);
};
PictureRenderer.prototype.start = function () {
};
PictureRenderer.prototype.flush = function () {
};
PictureRenderer.prototype._getRenderTexture = function (minWidth, minHeight) {
if (this._renderTexture.width < minWidth ||
this._renderTexture.height < minHeight) {
minHeight = nextPow2(minWidth);
minHeight = nextPow2(minHeight);
this._renderTexture.resize(minWidth, minHeight);
}
return this._renderTexture;
};
PictureRenderer.prototype._getBuf = function (size) {
var buf = this._bigBuf;
if (buf.length < size) {
size = nextPow2(size);
buf = new Uint8Array(size);
this._bigBuf = buf;
}
return buf;
};
PictureRenderer.prototype.render = function (sprite) {
if (!sprite.texture.valid) {
return;
}
var tilingMode = 0;
if (sprite.tileTransform) {
tilingMode = this._isSimpleSprite(sprite) ? 1 : 2;
}
var blendShader = this.drawModes[sprite.blendMode];
if (blendShader) {
this._renderBlend(sprite, blendShader[tilingMode]);
}
else {
this._renderNormal(sprite, this.normalShader[tilingMode]);
}
};
PictureRenderer.prototype._renderNormal = function (sprite, shader) {
var renderer = this.renderer;
renderer.bindShader(shader);
renderer.state.setBlendMode(sprite.blendMode);
this._renderInner(sprite, shader);
};
PictureRenderer.prototype._renderBlend = function (sprite, shader) {
var renderer = this.renderer;
var spriteBounds = sprite.getBounds();
var renderTarget = renderer._activeRenderTarget;
var matrix = renderTarget.projectionMatrix;
var flipX = matrix.a < 0;
var flipY = matrix.d < 0;
var resolution = renderTarget.resolution;
var screen = this._tempRect;
var fr = renderTarget.sourceFrame || renderTarget.destinationFrame;
screen.x = 0;
screen.y = 0;
screen.width = fr.width;
screen.height = fr.height;
var bounds = this._tempRect2;
var fbw = fr.width * resolution, fbh = fr.height * resolution;
bounds.x = (spriteBounds.x + matrix.tx / matrix.a) * resolution + fbw / 2;
bounds.y = (spriteBounds.y + matrix.ty / matrix.d) * resolution + fbh / 2;
bounds.width = spriteBounds.width * resolution;
bounds.height = spriteBounds.height * resolution;
if (flipX) {
bounds.y = fbw - bounds.width - bounds.x;
}
if (flipY) {
bounds.y = fbh - bounds.height - bounds.y;
}
var screenBounds = this._tempRect3;
var x_1 = Math.floor(Math.max(screen.x, bounds.x));
var x_2 = Math.ceil(Math.min(screen.x + screen.width, bounds.x + bounds.width));
var y_1 = Math.floor(Math.max(screen.y, bounds.y));
var y_2 = Math.ceil(Math.min(screen.y + screen.height, bounds.y + bounds.height));
var pixelsWidth = x_2 - x_1;
var pixelsHeight = y_2 - y_1;
if (pixelsWidth <= 0 || pixelsHeight <= 0) {
return;
}
var rt = this._getRenderTexture(pixelsWidth, pixelsHeight);
renderer.bindTexture(rt, 1, true);
var gl = renderer.gl;
if (renderer.renderingToScreen && renderTarget.root) {
var buf = this._getBuf(pixelsWidth * pixelsHeight * 4);
gl.readPixels(x_1, y_1, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf);
}
else {
gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, x_1, y_1, pixelsWidth, pixelsHeight);
}
renderer.bindShader(shader);
renderer.state.setBlendMode(PIXI.BLEND_MODES.NORMAL);
if (shader.uniforms.mapMatrix) {
var mapMatrix = this._tempMatrix;
mapMatrix.a = bounds.width / rt.width / spriteBounds.width;
if (flipX) {
mapMatrix.a = -mapMatrix.a;
mapMatrix.tx = (bounds.x - x_1) / rt.width - (spriteBounds.x + spriteBounds.width) * mapMatrix.a;
}
else {
mapMatrix.tx = (bounds.x - x_1) / rt.width - spriteBounds.x * mapMatrix.a;
}
mapMatrix.d = bounds.height / rt.height / spriteBounds.height;
if (flipY) {
mapMatrix.d = -mapMatrix.d;
mapMatrix.ty = (bounds.y - y_1) / rt.height - (spriteBounds.y + spriteBounds.height) * mapMatrix.d;
}
else {
mapMatrix.ty = (bounds.y - y_1) / rt.height - spriteBounds.y * mapMatrix.d;
}
shader.uniforms.mapMatrix = mapMatrix.toArray(true);
}
this._renderInner(sprite, shader);
};
PictureRenderer.prototype._renderInner = function (sprite, shader) {
var renderer = this.renderer;
if (shader.tilingMode > 0) {
this._renderWithShader(sprite, shader.tilingMode === 1, shader);
}
else {
this._renderSprite(sprite, shader);
}
};
PictureRenderer.prototype._renderWithShader = function (ts, isSimple, shader) {
var quad = shader.tempQuad;
var renderer = this.renderer;
renderer.bindVao(quad.vao);
var vertices = quad.vertices;
var _width = ts._width;
var _height = ts._height;
var _anchorX = ts._anchor._x;
var _anchorY = ts._anchor._y;
var w0 = _width * (1 - _anchorX);
var w1 = _width * -_anchorX;
var h0 = _height * (1 - _anchorY);
var h1 = _height * -_anchorY;
var wt = ts.transform.worldTransform;
var a = wt.a;
var b = wt.b;
var c = wt.c;
var d = wt.d;
var tx = wt.tx;
var ty = wt.ty;
vertices[0] = (a * w1) + (c * h1) + tx;
vertices[1] = (d * h1) + (b * w1) + ty;
vertices[2] = (a * w0) + (c * h1) + tx;
vertices[3] = (d * h1) + (b * w0) + ty;
vertices[4] = (a * w0) + (c * h0) + tx;
vertices[5] = (d * h0) + (b * w0) + ty;
vertices[6] = (a * w1) + (c * h0) + tx;
vertices[7] = (d * h0) + (b * w1) + ty;
vertices = quad.uvs;
vertices[0] = vertices[6] = -ts.anchor.x;
vertices[1] = vertices[3] = -ts.anchor.y;
vertices[2] = vertices[4] = 1.0 - ts.anchor.x;
vertices[5] = vertices[7] = 1.0 - ts.anchor.y;
quad.upload();
var tex = ts._texture;
var lt = ts.tileTransform.localTransform;
var uv = ts.uvTransform;
var mapCoord = uv.mapCoord;
var uClampFrame = uv.uClampFrame;
var uClampOffset = uv.uClampOffset;
var w = tex.width;
var h = tex.height;
var W = _width;
var H = _height;
var tempMat = this._tempMatrix2;
tempMat.set(lt.a * w / W, lt.b * w / H, lt.c * h / W, lt.d * h / H, lt.tx / W, lt.ty / H);
tempMat.invert();
if (isSimple) {
tempMat.append(mapCoord);
}
else {
shader.uniforms.uMapCoord = mapCoord.toArray(true);
shader.uniforms.uClampFrame = uClampFrame;
shader.uniforms.uClampOffset = uClampOffset;
}
shader.uniforms.uTransform = tempMat.toArray(true);
var color = this._tempColor;
var alpha = ts.worldAlpha;
PIXI.utils.hex2rgb(ts.tint, color);
color[0] *= alpha;
color[1] *= alpha;
color[2] *= alpha;
color[3] = alpha;
shader.uniforms.uColor = color;
renderer.bindTexture(tex, 0, true);
quad.vao.draw(this.renderer.gl.TRIANGLES, 6, 0);
};
PictureRenderer.prototype._renderSprite = function (sprite, shader) {
var renderer = this.renderer;
var quad = shader.tempQuad;
renderer.bindVao(quad.vao);
var uvs = sprite.texture._uvs;
var vertices = quad.vertices;
var vd = sprite.vertexData;
for (var i = 0; i < 8; i++) {
quad.vertices[i] = vd[i];
}
quad.uvs[0] = uvs.x0;
quad.uvs[1] = uvs.y0;
quad.uvs[2] = uvs.x1;
quad.uvs[3] = uvs.y1;
quad.uvs[4] = uvs.x2;
quad.uvs[5] = uvs.y2;
quad.uvs[6] = uvs.x3;
quad.uvs[7] = uvs.y3;
quad.upload();
var frame = sprite.texture.frame;
var base = sprite.texture.baseTexture;
var clamp = this._tempClamp;
var eps = 0.5 / base.resolution;
clamp[0] = (frame.x + eps) / base.width;
clamp[1] = (frame.y + eps) / base.height;
clamp[2] = (frame.x + frame.width - eps) / base.width;
clamp[3] = (frame.y + frame.height - eps) / base.height;
shader.uniforms.uTextureClamp = clamp;
var color = this._tempColor;
PIXI.utils.hex2rgb(sprite.tint, color);
var alpha = sprite.worldAlpha;
color[0] *= alpha;
color[1] *= alpha;
color[2] *= alpha;
color[3] = alpha;
shader.uniforms.uColor = color;
renderer.bindTexture(base, 0, true);
quad.vao.draw(this.renderer.gl.TRIANGLES, 6, 0);
};
PictureRenderer.prototype._isSimpleSprite = function (ts) {
var renderer = this.renderer;
var tex = ts._texture;
var baseTex = tex.baseTexture;
var isSimple = baseTex.isPowerOfTwo && tex.frame.width === baseTex.width && tex.frame.height === baseTex.height;
if (isSimple) {
if (!baseTex._glTextures[renderer.CONTEXT_UID]) {
if (baseTex.wrapMode === PIXI.WRAP_MODES.CLAMP) {
baseTex.wrapMode = PIXI.WRAP_MODES.REPEAT;
}
}
else {
isSimple = baseTex.wrapMode !== PIXI.WRAP_MODES.CLAMP;
}
}
return isSimple;
};
return PictureRenderer;
}(PIXI.ObjectRenderer));
extras.PictureRenderer = PictureRenderer;
PIXI.WebGLRenderer.registerPlugin('picture', PictureRenderer);
PIXI.CanvasRenderer.registerPlugin('picture', PIXI.CanvasSpriteRenderer);
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var PictureSprite = (function (_super) {
__extends(PictureSprite, _super);
function PictureSprite(texture) {
_super.call(this, texture);
this.pluginName = 'picture';
}
return PictureSprite;
}(PIXI.Sprite));
extras.PictureSprite = PictureSprite;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var extras;
(function (extras) {
var PictureTilingSprite = (function (_super) {
__extends(PictureTilingSprite, _super);
function PictureTilingSprite(texture) {
_super.call(this, texture);
this.pluginName = 'picture';
}
return PictureTilingSprite;
}(extras.TilingSprite));
extras.PictureTilingSprite = PictureTilingSprite;
})(extras = PIXI.extras || (PIXI.extras = {}));
})(PIXI || (PIXI = {}));
//# sourceMappingURL=pixi-picture.js.map

887
js/libs/pixi-tilemap.js Normal file
View File

@@ -0,0 +1,887 @@
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var CanvasTileRenderer = (function () {
function CanvasTileRenderer(renderer) {
this.tileAnim = [0, 0];
this.dontUseTransform = false;
this.renderer = renderer;
this.tileAnim = [0, 0];
}
return CanvasTileRenderer;
}());
tilemap.CanvasTileRenderer = CanvasTileRenderer;
PIXI.CanvasRenderer.registerPlugin('tilemap', CanvasTileRenderer);
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var CompositeRectTileLayer = (function (_super) {
__extends(CompositeRectTileLayer, _super);
function CompositeRectTileLayer(zIndex, bitmaps, useSquare, texPerChild) {
var _this = _super.call(this) || this;
_this.shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]);
_this.modificationMarker = 0;
_this._globalMat = null;
_this._tempScale = null;
_this.initialize.apply(_this, arguments);
return _this;
}
CompositeRectTileLayer.prototype.updateTransform = function () {
_super.prototype.displayObjectUpdateTransform.call(this);
};
CompositeRectTileLayer.prototype.initialize = function (zIndex, bitmaps, useSquare, texPerChild) {
this.z = this.zIndex = zIndex;
this.useSquare = useSquare;
this.texPerChild = texPerChild || 16;
if (bitmaps) {
this.setBitmaps(bitmaps);
}
};
CompositeRectTileLayer.prototype.setBitmaps = function (bitmaps) {
var texPerChild = this.texPerChild;
var len1 = this.children.length;
var len2 = Math.ceil(bitmaps.length / texPerChild);
var i;
for (i = 0; i < len1; i++) {
this.children[i].textures = bitmaps.slice(i * texPerChild, (i + 1) * texPerChild);
}
for (i = len1; i < len2; i++) {
this.addChild(new tilemap.RectTileLayer(this.zIndex, bitmaps.slice(i * texPerChild, (i + 1) * texPerChild)));
}
};
CompositeRectTileLayer.prototype.clear = function () {
for (var i = 0; i < this.children.length; i++)
this.children[i].clear();
this.modificationMarker = 0;
};
CompositeRectTileLayer.prototype.addRect = function (num, u, v, x, y, tileWidth, tileHeight) {
if (this.children[num] && this.children[num].textures)
this.children[num].addRect(0, u, v, x, y, tileWidth, tileHeight);
};
CompositeRectTileLayer.prototype.addFrame = function (texture_, x, y, animX, animY) {
var texture;
var layer = null, ind = 0;
var children = this.children;
if (typeof texture_ === "number") {
var childIndex = texture_ / this.texPerChild >> 0;
layer = children[childIndex];
if (!layer) {
layer = children[0];
if (!layer) {
return false;
}
ind = 0;
}
else {
ind = texture_ % this.texPerChild;
}
texture = layer.textures[ind];
}
else if (typeof texture_ === "string") {
texture = PIXI.Texture.fromImage(texture_);
}
else {
texture = texture_;
for (var i = 0; i < children.length; i++) {
var child = children[i];
var tex = child.textures;
for (var j = 0; j < tex.length; j++) {
if (tex[j].baseTexture == texture.baseTexture) {
layer = child;
ind = j;
break;
}
}
if (layer) {
break;
}
}
if (!layer) {
for (i = 0; i < children.length; i++) {
var child = children[i];
if (child.textures.length < this.texPerChild) {
layer = child;
ind = child.textures.length;
child.textures.push(texture);
break;
}
}
if (!layer) {
children.push(layer = new tilemap.RectTileLayer(this.zIndex, texture));
ind = 0;
}
}
}
layer.addRect(ind, texture.frame.x, texture.frame.y, x, y, texture.frame.width, texture.frame.height, animX, animY);
return true;
};
;
CompositeRectTileLayer.prototype.renderCanvas = function (renderer) {
if (!renderer.plugins.tilemap.dontUseTransform) {
var wt = this.worldTransform;
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, wt.tx * renderer.resolution, wt.ty * renderer.resolution);
}
var layers = this.children;
for (var i = 0; i < layers.length; i++)
layers[i].renderCanvas(renderer);
};
;
CompositeRectTileLayer.prototype.renderWebGL = function (renderer) {
var gl = renderer.gl;
var shader = renderer.plugins.tilemap.getShader(this.useSquare);
renderer.setObjectRenderer(renderer.plugins.tilemap);
renderer.bindShader(shader);
this._globalMat = this._globalMat || new PIXI.Matrix();
renderer._activeRenderTarget.projectionMatrix.copy(this._globalMat).append(this.worldTransform);
shader.uniforms.projectionMatrix = this._globalMat.toArray(true);
shader.uniforms.shadowColor = this.shadowColor;
if (this.useSquare) {
var tempScale = this._tempScale = (this._tempScale || [0, 0]);
tempScale[0] = this._globalMat.a >= 0 ? 1 : -1;
tempScale[1] = this._globalMat.d < 0 ? 1 : -1;
var ps = shader.uniforms.pointScale = tempScale;
shader.uniforms.projectionScale = Math.abs(this.worldTransform.a) * renderer.resolution;
}
var af = shader.uniforms.animationFrame = renderer.plugins.tilemap.tileAnim;
var layers = this.children;
for (var i = 0; i < layers.length; i++)
layers[i].renderWebGL(renderer, this.useSquare);
};
CompositeRectTileLayer.prototype.isModified = function (anim) {
var layers = this.children;
if (this.modificationMarker != layers.length) {
return true;
}
for (var i = 0; i < layers.length; i++) {
var layer = layers[i];
if (layer.modificationMarker != layer.pointsBuf.length ||
anim && layer.hasAnim) {
return true;
}
}
return false;
};
CompositeRectTileLayer.prototype.clearModify = function () {
var layers = this.children;
this.modificationMarker = layers.length;
for (var i = 0; i < layers.length; i++) {
var layer = layers[i];
layer.modificationMarker = layer.pointsBuf.length;
}
};
return CompositeRectTileLayer;
}(PIXI.Container));
tilemap.CompositeRectTileLayer = CompositeRectTileLayer;
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var GraphicsLayer = (function (_super) {
__extends(GraphicsLayer, _super);
function GraphicsLayer(zIndex) {
var _this = _super.call(this) || this;
_this.z = _this.zIndex = zIndex;
return _this;
}
GraphicsLayer.prototype.renderCanvas = function (renderer) {
var wt = null;
if (renderer.plugins.tilemap.dontUseTransform) {
wt = this.transform.worldTransform;
this.transform.worldTransform = PIXI.Matrix.IDENTITY;
}
renderer.plugins.graphics.render(this);
if (renderer.plugins.tilemap.dontUseTransform) {
this.transform.worldTransform = wt;
}
renderer.context.globalAlpha = 1.0;
};
GraphicsLayer.prototype.renderWebGL = function (renderer) {
if (!this._webGL[renderer.CONTEXT_UID])
this.dirty = true;
_super.prototype.renderWebGL.call(this, renderer);
};
GraphicsLayer.prototype.isModified = function (anim) {
return false;
};
GraphicsLayer.prototype.clearModify = function () {
};
return GraphicsLayer;
}(PIXI.Graphics));
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var RectTileLayer = (function (_super) {
__extends(RectTileLayer, _super);
function RectTileLayer(zIndex, texture) {
var _this = _super.call(this) || this;
_this.z = 0;
_this.zIndex = 0;
_this.pointsBuf = [];
_this._tempSize = new Float32Array([0, 0]);
_this._tempTexSize = 1;
_this.modificationMarker = 0;
_this.hasAnim = false;
_this.vbId = 0;
_this.vbBuffer = null;
_this.vbArray = null;
_this.vbInts = null;
_this.initialize(zIndex, texture);
return _this;
}
RectTileLayer.prototype.initialize = function (zIndex, textures) {
if (!textures) {
textures = [];
}
else if (!(textures instanceof Array) && textures.baseTexture) {
textures = [textures];
}
this.textures = textures;
this.z = this.zIndex = zIndex;
this.visible = false;
};
RectTileLayer.prototype.clear = function () {
this.pointsBuf.length = 0;
this.modificationMarker = 0;
this.hasAnim = false;
};
RectTileLayer.prototype.renderCanvas = function (renderer) {
if (this.textures.length === 0)
return;
var points = this.pointsBuf;
renderer.context.fillStyle = '#000000';
for (var i = 0, n = points.length; i < n; i += 9) {
var x1 = points[i], y1 = points[i + 1];
var x2 = points[i + 2], y2 = points[i + 3];
var w = points[i + 4];
var h = points[i + 5];
x1 += points[i + 6] * renderer.plugins.tilemap.tileAnim[0];
y1 += points[i + 7] * renderer.plugins.tilemap.tileAnim[1];
var textureId = points[i + 8];
if (textureId >= 0) {
renderer.context.drawImage(this.textures[textureId].baseTexture.source, x1, y1, w, h, x2, y2, w, h);
}
else {
renderer.context.globalAlpha = 0.5;
renderer.context.fillRect(x2, y2, w, h);
renderer.context.globalAlpha = 1;
}
}
};
RectTileLayer.prototype.addRect = function (textureId, u, v, x, y, tileWidth, tileHeight, animX, animY) {
if (animX === void 0) { animX = 0; }
if (animY === void 0) { animY = 0; }
var pb = this.pointsBuf;
this.hasAnim = this.hasAnim || animX > 0 || animY > 0;
if (tileWidth == tileHeight) {
pb.push(u);
pb.push(v);
pb.push(x);
pb.push(y);
pb.push(tileWidth);
pb.push(tileHeight);
pb.push(animX | 0);
pb.push(animY | 0);
pb.push(textureId);
}
else {
var i;
if (tileWidth % tileHeight === 0) {
for (i = 0; i < tileWidth / tileHeight; i++) {
pb.push(u + i * tileHeight);
pb.push(v);
pb.push(x + i * tileHeight);
pb.push(y);
pb.push(tileHeight);
pb.push(tileHeight);
pb.push(animX | 0);
pb.push(animY | 0);
pb.push(textureId);
}
}
else if (tileHeight % tileWidth === 0) {
for (i = 0; i < tileHeight / tileWidth; i++) {
pb.push(u);
pb.push(v + i * tileWidth);
pb.push(x);
pb.push(y + i * tileWidth);
pb.push(tileWidth);
pb.push(tileWidth);
pb.push(animX | 0);
pb.push(animY | 0);
pb.push(textureId);
}
}
else {
pb.push(u);
pb.push(v);
pb.push(x);
pb.push(y);
pb.push(tileWidth);
pb.push(tileHeight);
pb.push(animX | 0);
pb.push(animY | 0);
pb.push(textureId);
}
}
};
;
RectTileLayer.prototype.renderWebGL = function (renderer, useSquare) {
if (useSquare === void 0) { useSquare = false; }
var points = this.pointsBuf;
if (points.length === 0)
return;
var rectsCount = points.length / 9;
var tile = renderer.plugins.tilemap;
var gl = renderer.gl;
if (!useSquare) {
tile.checkIndexBuffer(rectsCount);
}
var shader = tile.getShader(useSquare);
var textures = this.textures;
if (textures.length === 0)
return;
var len = textures.length;
if (this._tempTexSize < shader.maxTextures) {
this._tempTexSize = shader.maxTextures;
this._tempSize = new Float32Array(2 * shader.maxTextures);
}
for (var i = 0; i < len; i++) {
if (!textures[i] || !textures[i].valid)
return;
var texture = textures[i].baseTexture;
}
tile.bindTextures(renderer, shader, textures);
var vb = tile.getVb(this.vbId);
if (!vb) {
vb = tile.createVb(useSquare);
this.vbId = vb.id;
this.vbBuffer = null;
this.modificationMarker = 0;
}
var vao = vb.vao;
renderer.bindVao(vao);
var vertexBuf = vb.vb;
vertexBuf.bind();
var vertices = rectsCount * shader.vertPerQuad;
if (vertices === 0)
return;
if (this.modificationMarker != vertices) {
this.modificationMarker = vertices;
var vs = shader.stride * vertices;
if (!this.vbBuffer || this.vbBuffer.byteLength < vs) {
var bk = shader.stride;
while (bk < vs) {
bk *= 2;
}
this.vbBuffer = new ArrayBuffer(bk);
this.vbArray = new Float32Array(this.vbBuffer);
this.vbInts = new Uint32Array(this.vbBuffer);
vertexBuf.upload(this.vbBuffer, 0, true);
}
var arr = this.vbArray, ints = this.vbInts;
var sz = 0;
var textureId, shiftU, shiftV;
if (useSquare) {
for (i = 0; i < points.length; i += 9) {
textureId = (points[i + 8] >> 2);
shiftU = 1024 * (points[i + 8] & 1);
shiftV = 1024 * ((points[i + 8] >> 1) & 1);
arr[sz++] = points[i + 2];
arr[sz++] = points[i + 3];
arr[sz++] = points[i + 0] + shiftU;
arr[sz++] = points[i + 1] + shiftV;
arr[sz++] = points[i + 4];
arr[sz++] = points[i + 6];
arr[sz++] = points[i + 7];
arr[sz++] = textureId;
}
}
else {
var tint = -1;
for (i = 0; i < points.length; i += 9) {
var eps = 0.5;
textureId = (points[i + 8] >> 2);
shiftU = 1024 * (points[i + 8] & 1);
shiftV = 1024 * ((points[i + 8] >> 1) & 1);
var x = points[i + 2], y = points[i + 3];
var w = points[i + 4], h = points[i + 5];
var u = points[i] + shiftU, v = points[i + 1] + shiftV;
var animX = points[i + 6], animY = points[i + 7];
arr[sz++] = x;
arr[sz++] = y;
arr[sz++] = u;
arr[sz++] = v;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animX;
arr[sz++] = animY;
arr[sz++] = textureId;
arr[sz++] = x + w;
arr[sz++] = y;
arr[sz++] = u + w;
arr[sz++] = v;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animX;
arr[sz++] = animY;
arr[sz++] = textureId;
arr[sz++] = x + w;
arr[sz++] = y + h;
arr[sz++] = u + w;
arr[sz++] = v + h;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animX;
arr[sz++] = animY;
arr[sz++] = textureId;
arr[sz++] = x;
arr[sz++] = y + h;
arr[sz++] = u;
arr[sz++] = v + h;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animX;
arr[sz++] = animY;
arr[sz++] = textureId;
}
}
vertexBuf.upload(arr, 0, true);
}
if (useSquare)
gl.drawArrays(gl.POINTS, 0, vertices);
else
gl.drawElements(gl.TRIANGLES, rectsCount * 6, gl.UNSIGNED_SHORT, 0);
};
return RectTileLayer;
}(PIXI.Container));
tilemap.RectTileLayer = RectTileLayer;
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var rectShaderFrag = "varying vec2 vTextureCoord;\nvarying vec4 vFrame;\nvarying float vTextureId;\nuniform vec4 shadowColor;\nuniform sampler2D uSamplers[%count%];\nuniform vec2 uSamplerSize[%count%];\n\nvoid main(void){\n vec2 textureCoord = clamp(vTextureCoord, vFrame.xy, vFrame.zw);\n float textureId = floor(vTextureId + 0.5);\n\n vec4 color;\n %forloop%\n gl_FragColor = color;\n}";
var rectShaderVert = "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aFrame;\nattribute vec2 aAnim;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform vec2 animationFrame;\n\nvarying vec2 vTextureCoord;\nvarying float vTextureId;\nvarying vec4 vFrame;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vec2 anim = aAnim * animationFrame;\n vTextureCoord = aTextureCoord + anim;\n vFrame = aFrame + vec4(anim, anim);\n vTextureId = aTextureId;\n}\n";
var TilemapShader = (function (_super) {
__extends(TilemapShader, _super);
function TilemapShader(gl, maxTextures, shaderVert, shaderFrag) {
var _this = _super.call(this, gl, shaderVert, shaderFrag) || this;
_this.maxTextures = 0;
_this.maxTextures = maxTextures;
tilemap.shaderGenerator.fillSamplers(_this, _this.maxTextures);
return _this;
}
return TilemapShader;
}(PIXI.Shader));
tilemap.TilemapShader = TilemapShader;
var RectTileShader = (function (_super) {
__extends(RectTileShader, _super);
function RectTileShader(gl, maxTextures) {
var _this = _super.call(this, gl, maxTextures, rectShaderVert, tilemap.shaderGenerator.generateFragmentSrc(maxTextures, rectShaderFrag)) || this;
_this.vertSize = 11;
_this.vertPerQuad = 4;
_this.stride = _this.vertSize * 4;
tilemap.shaderGenerator.fillSamplers(_this, _this.maxTextures);
return _this;
}
RectTileShader.prototype.createVao = function (renderer, vb) {
var gl = renderer.gl;
return renderer.createVao()
.addIndex(this.indexBuffer)
.addAttribute(vb, this.attributes.aVertexPosition, gl.FLOAT, false, this.stride, 0)
.addAttribute(vb, this.attributes.aTextureCoord, gl.FLOAT, false, this.stride, 2 * 4)
.addAttribute(vb, this.attributes.aFrame, gl.FLOAT, false, this.stride, 4 * 4)
.addAttribute(vb, this.attributes.aAnim, gl.FLOAT, false, this.stride, 8 * 4)
.addAttribute(vb, this.attributes.aTextureId, gl.FLOAT, false, this.stride, 10 * 4);
};
return RectTileShader;
}(TilemapShader));
tilemap.RectTileShader = RectTileShader;
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var shaderGenerator;
(function (shaderGenerator) {
function fillSamplers(shader, maxTextures) {
var sampleValues = [];
for (var i = 0; i < maxTextures; i++) {
sampleValues[i] = i;
}
shader.bind();
shader.uniforms.uSamplers = sampleValues;
var samplerSize = [];
for (i = 0; i < maxTextures; i++) {
samplerSize.push(1.0 / 2048);
samplerSize.push(1.0 / 2048);
}
shader.uniforms.uSamplerSize = samplerSize;
}
shaderGenerator.fillSamplers = fillSamplers;
function generateFragmentSrc(maxTextures, fragmentSrc) {
return fragmentSrc.replace(/%count%/gi, maxTextures + "")
.replace(/%forloop%/gi, this.generateSampleSrc(maxTextures));
}
shaderGenerator.generateFragmentSrc = generateFragmentSrc;
function generateSampleSrc(maxTextures) {
var src = '';
src += '\n';
src += '\n';
src += 'if(vTextureId <= -1.0) {';
src += '\n\tcolor = shadowColor;';
src += '\n}';
for (var i = 0; i < maxTextures; i++) {
src += '\nelse ';
if (i < maxTextures - 1) {
src += 'if(textureId == ' + i + '.0)';
}
src += '\n{';
src += '\n\tcolor = texture2D(uSamplers[' + i + '], textureCoord * uSamplerSize[' + i + ']);';
src += '\n}';
}
src += '\n';
src += '\n';
return src;
}
shaderGenerator.generateSampleSrc = generateSampleSrc;
})(shaderGenerator = tilemap.shaderGenerator || (tilemap.shaderGenerator = {}));
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var squareShaderVert = "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aAnim;\nattribute float aTextureId;\nattribute float aSize;\n\nuniform mat3 projectionMatrix;\nuniform vec2 samplerSize;\nuniform vec2 animationFrame;\nuniform float projectionScale;\n\nvarying vec2 vTextureCoord;\nvarying float vSize;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition + aSize * 0.5, 1.0)).xy, 0.0, 1.0);\n gl_PointSize = aSize * projectionScale;\n vTextureCoord = aTextureCoord + aAnim * animationFrame;\n vTextureId = aTextureId;\n vSize = aSize;\n}\n";
var squareShaderFrag = "\nvarying vec2 vTextureCoord;\nvarying float vSize;\nvarying float vTextureId;\n\nuniform vec4 shadowColor;\nuniform sampler2D uSamplers[%count%];\nuniform vec2 uSamplerSize[%count%];\nuniform vec2 pointScale;\n\nvoid main(void){\n float margin = 0.5 / vSize;\n vec2 pointCoord = (gl_PointCoord - 0.5) * pointScale + 0.5;\n vec2 clamped = vec2(clamp(pointCoord.x, margin, 1.0 - margin), clamp(pointCoord.y, margin, 1.0 - margin));\n vec2 textureCoord = pointCoord * vSize + vTextureCoord;\n float textureId = vTextureId;\n vec4 color;\n %forloop%\n gl_FragColor = color;\n}\n\n";
var SquareTileShader = (function (_super) {
__extends(SquareTileShader, _super);
function SquareTileShader(gl, maxTextures) {
var _this = _super.call(this, gl, maxTextures, squareShaderVert, tilemap.shaderGenerator.generateFragmentSrc(maxTextures, squareShaderFrag)) || this;
_this.vertSize = 8;
_this.vertPerQuad = 1;
_this.stride = _this.vertSize * 4;
_this.maxTextures = maxTextures;
tilemap.shaderGenerator.fillSamplers(_this, _this.maxTextures);
return _this;
}
SquareTileShader.prototype.createVao = function (renderer, vb) {
var gl = renderer.gl;
return renderer.createVao()
.addIndex(this.indexBuffer)
.addAttribute(vb, this.attributes.aVertexPosition, gl.FLOAT, false, this.stride, 0)
.addAttribute(vb, this.attributes.aTextureCoord, gl.FLOAT, false, this.stride, 2 * 4)
.addAttribute(vb, this.attributes.aSize, gl.FLOAT, false, this.stride, 4 * 4)
.addAttribute(vb, this.attributes.aAnim, gl.FLOAT, false, this.stride, 5 * 4)
.addAttribute(vb, this.attributes.aTextureId, gl.FLOAT, false, this.stride, 7 * 4);
};
;
return SquareTileShader;
}(tilemap.TilemapShader));
tilemap.SquareTileShader = SquareTileShader;
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap) {
var glCore = PIXI.glCore;
function _hackSubImage(tex, sprite, clearBuffer, clearWidth, clearHeight) {
var gl = tex.gl;
var baseTex = sprite.texture.baseTexture;
if (clearBuffer && clearWidth > 0 && clearHeight > 0) {
gl.texSubImage2D(gl.TEXTURE_2D, 0, sprite.position.x, sprite.position.y, clearWidth, clearHeight, tex.format, tex.type, clearBuffer);
}
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
gl.texSubImage2D(gl.TEXTURE_2D, 0, sprite.position.x, sprite.position.y, tex.format, tex.type, baseTex.source);
}
var TileRenderer = (function (_super) {
__extends(TileRenderer, _super);
function TileRenderer(renderer) {
var _this = _super.call(this, renderer) || this;
_this.vbs = {};
_this.indices = new Uint16Array(0);
_this.lastTimeCheck = 0;
_this.tileAnim = [0, 0];
_this.maxTextures = 4;
_this.texLoc = [];
return _this;
}
TileRenderer.prototype.onContextChange = function () {
var gl = this.renderer.gl;
var maxTextures = this.maxTextures;
this.rectShader = new tilemap.RectTileShader(gl, maxTextures);
this.squareShader = new tilemap.SquareTileShader(gl, maxTextures);
this.checkIndexBuffer(2000);
this.rectShader.indexBuffer = this.indexBuffer;
this.squareShader.indexBuffer = this.indexBuffer;
this.vbs = {};
this.glTextures = [];
this.boundSprites = [];
this.initBounds();
};
TileRenderer.prototype.initBounds = function () {
var gl = this.renderer.gl;
var tempCanvas = document.createElement('canvas');
tempCanvas.width = 2048;
tempCanvas.height = 2048;
for (var i = 0; i < this.maxTextures; i++) {
var rt = PIXI.RenderTexture.create(2048, 2048);
rt.baseTexture.premultipliedAlpha = true;
rt.baseTexture.scaleMode = TileRenderer.SCALE_MODE;
rt.baseTexture.wrapMode = PIXI.WRAP_MODES.CLAMP;
this.renderer.textureManager.updateTexture(rt);
this.glTextures.push(rt);
var bs = [];
for (var j = 0; j < 4; j++) {
var spr = new PIXI.Sprite();
spr.position.x = 1024 * (j & 1);
spr.position.y = 1024 * (j >> 1);
bs.push(spr);
}
this.boundSprites.push(bs);
}
};
TileRenderer.prototype.bindTextures = function (renderer, shader, textures) {
var bounds = this.boundSprites;
var glts = this.glTextures;
var len = textures.length;
var maxTextures = this.maxTextures;
if (len > 4 * maxTextures) {
return;
}
var doClear = TileRenderer.DO_CLEAR;
if (doClear && !this._clearBuffer) {
this._clearBuffer = new Uint8Array(1024 * 1024 * 4);
}
var i;
for (i = 0; i < len; i++) {
var texture = textures[i];
if (!texture || !textures[i].valid)
continue;
var bs = bounds[i >> 2][i & 3];
if (!bs.texture ||
bs.texture.baseTexture !== texture.baseTexture) {
bs.texture = texture;
var glt = glts[i >> 2];
renderer.bindTexture(glt, 0, true);
if (doClear) {
_hackSubImage(glt.baseTexture._glTextures[renderer.CONTEXT_UID], bs, this._clearBuffer, 1024, 1024);
}
else {
_hackSubImage(glt.baseTexture._glTextures[renderer.CONTEXT_UID], bs);
}
}
}
this.texLoc.length = 0;
for (i = 0; i < maxTextures; i++) {
this.texLoc.push(renderer.bindTexture(glts[i], i, true));
}
shader.uniforms.uSamplers = this.texLoc;
};
TileRenderer.prototype.checkLeaks = function () {
var now = Date.now();
var old = now - 10000;
if (this.lastTimeCheck < old ||
this.lastTimeCheck > now) {
this.lastTimeCheck = now;
var vbs = this.vbs;
for (var key in vbs) {
if (vbs[key].lastTimeAccess < old) {
this.removeVb(key);
}
}
}
};
;
TileRenderer.prototype.start = function () {
this.renderer.state.setBlendMode(PIXI.BLEND_MODES.NORMAL);
};
TileRenderer.prototype.getVb = function (id) {
this.checkLeaks();
var vb = this.vbs[id];
if (vb) {
vb.lastAccessTime = Date.now();
return vb;
}
return null;
};
TileRenderer.prototype.createVb = function (useSquare) {
var id = ++TileRenderer.vbAutoincrement;
var shader = this.getShader(useSquare);
var gl = this.renderer.gl;
var vb = PIXI.glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW);
var stuff = {
id: id,
vb: vb,
vao: shader.createVao(this.renderer, vb),
lastTimeAccess: Date.now(),
useSquare: useSquare,
shader: shader
};
this.vbs[id] = stuff;
return stuff;
};
TileRenderer.prototype.removeVb = function (id) {
if (this.vbs[id]) {
this.vbs[id].vb.destroy();
this.vbs[id].vao.destroy();
delete this.vbs[id];
}
};
TileRenderer.prototype.checkIndexBuffer = function (size) {
var totalIndices = size * 6;
var indices = this.indices;
if (totalIndices <= indices.length) {
return;
}
var len = indices.length || totalIndices;
while (len < totalIndices) {
len <<= 1;
}
indices = new Uint16Array(len);
this.indices = indices;
for (var i = 0, j = 0; i + 5 < indices.length; i += 6, j += 4) {
indices[i + 0] = j + 0;
indices[i + 1] = j + 1;
indices[i + 2] = j + 2;
indices[i + 3] = j + 0;
indices[i + 4] = j + 2;
indices[i + 5] = j + 3;
}
if (this.indexBuffer) {
this.indexBuffer.upload(indices);
}
else {
var gl = this.renderer.gl;
this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW);
}
};
TileRenderer.prototype.getShader = function (useSquare) {
return useSquare ? this.squareShader : this.rectShader;
};
TileRenderer.prototype.destroy = function () {
_super.prototype.destroy.call(this);
this.rectShader.destroy();
this.squareShader.destroy();
this.rectShader = null;
this.squareShader = null;
};
;
return TileRenderer;
}(PIXI.ObjectRenderer));
TileRenderer.vbAutoincrement = 0;
TileRenderer.SCALE_MODE = PIXI.SCALE_MODES.LINEAR;
TileRenderer.DO_CLEAR = false;
tilemap.TileRenderer = TileRenderer;
PIXI.WebGLRenderer.registerPlugin('tilemap', TileRenderer);
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
var PIXI;
(function (PIXI) {
var tilemap;
(function (tilemap_1) {
var ZLayer = (function (_super) {
__extends(ZLayer, _super);
function ZLayer(tilemap, zIndex) {
var _this = _super.call(this) || this;
_this._lastAnimationFrame = -1;
_this.tilemap = tilemap;
_this.z = zIndex;
return _this;
}
ZLayer.prototype.clear = function () {
var layers = this.children;
for (var i = 0; i < layers.length; i++)
layers[i].clear();
this._previousLayers = 0;
};
ZLayer.prototype.cacheIfDirty = function () {
var tilemap = this.tilemap;
var layers = this.children;
var modified = this._previousLayers != layers.length;
this._previousLayers = layers.length;
var buf = this.canvasBuffer;
var tempRender = this._tempRender;
if (!buf) {
buf = this.canvasBuffer = document.createElement('canvas');
tempRender = this._tempRender = new PIXI.CanvasRenderer(100, 100, { view: buf });
tempRender.context = tempRender.rootContext;
tempRender.plugins.tilemap.dontUseTransform = true;
}
if (buf.width != tilemap._layerWidth ||
buf.height != tilemap._layerHeight) {
buf.width = tilemap._layerWidth;
buf.height = tilemap._layerHeight;
modified = true;
}
var i;
if (!modified) {
for (i = 0; i < layers.length; i++) {
if (layers[i].isModified(this._lastAnimationFrame != tilemap.animationFrame)) {
modified = true;
break;
}
}
}
this._lastAnimationFrame = tilemap.animationFrame;
if (modified) {
if (tilemap._hackRenderer) {
tilemap._hackRenderer(tempRender);
}
tempRender.context.clearRect(0, 0, buf.width, buf.height);
for (i = 0; i < layers.length; i++) {
layers[i].clearModify();
layers[i].renderCanvas(tempRender);
}
}
this.layerTransform = this.worldTransform;
for (i = 0; i < layers.length; i++) {
this.layerTransform = layers[i].worldTransform;
break;
}
};
;
ZLayer.prototype.renderCanvas = function (renderer) {
this.cacheIfDirty();
var wt = this.layerTransform;
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, wt.tx * renderer.resolution, wt.ty * renderer.resolution);
var tilemap = this.tilemap;
renderer.context.drawImage(this.canvasBuffer, 0, 0);
};
;
return ZLayer;
}(PIXI.Container));
tilemap_1.ZLayer = ZLayer;
})(tilemap = PIXI.tilemap || (PIXI.tilemap = {}));
})(PIXI || (PIXI = {}));
//# sourceMappingURL=pixi-tilemap.js.map

40318
js/libs/pixi.js Normal file

File diff suppressed because it is too large Load Diff