whs.js/examples/assets/modules/StatsModule.js
2017-02-02 17:40:39 +02:00

1 line
3.7 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("WHS")):"function"==typeof define&&define.amd?define(["WHS"],t):"object"==typeof exports?exports.StatsModule=t(require("WHS")):e.StatsModule=t(e.WHS)}(this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,n){!function(t,n){e.exports=n()}(this,function(){var e=function(){function t(e){return r.appendChild(e.dom),e}function n(e){for(var t=0;t<r.children.length;t++)r.children[t].style.display=t===e?"block":"none";o=e}var o=0,r=document.createElement("div");r.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",r.addEventListener("click",function(e){e.preventDefault(),n(++o%r.children.length)},!1);var i=(performance||Date).now(),l=i,a=0,u=t(new e.Panel("FPS","#0ff","#002")),f=t(new e.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var s=t(new e.Panel("MB","#f08","#201"));return n(0),{REVISION:16,dom:r,addPanel:t,showPanel:n,begin:function(){i=(performance||Date).now()},end:function(){a++;var e=(performance||Date).now();if(f.update(e-i,200),e>l+1e3&&(u.update(1e3*a/(e-l),100),l=e,a=0,s)){var t=performance.memory;s.update(t.usedJSHeapSize/1048576,t.jsHeapSizeLimit/1048576)}return e},update:function(){i=this.end()},domElement:r,setMode:n}};return e.Panel=function(e,t,n){var o=1/0,r=0,i=Math.round,l=i(window.devicePixelRatio||1),a=80*l,u=48*l,f=3*l,s=2*l,c=3*l,p=15*l,d=74*l,h=30*l,m=document.createElement("canvas");m.width=a,m.height=u,m.style.cssText="width:80px;height:48px";var v=m.getContext("2d");return v.font="bold "+9*l+"px Helvetica,Arial,sans-serif",v.textBaseline="top",v.fillStyle=n,v.fillRect(0,0,a,u),v.fillStyle=t,v.fillText(e,f,s),v.fillRect(c,p,d,h),v.fillStyle=n,v.globalAlpha=.9,v.fillRect(c,p,d,h),{dom:m,update:function(u,y){o=Math.min(o,u),r=Math.max(r,u),v.fillStyle=n,v.globalAlpha=1,v.fillRect(0,0,a,p),v.fillStyle=t,v.fillText(i(u)+" "+e+" ("+i(o)+"-"+i(r)+")",f,s),v.drawImage(m,c+l,p,d-l,h,c,p,d-l,h),v.fillRect(c+d-l,p,l,h),v.fillStyle=n,v.globalAlpha=.9,v.fillRect(c+d-l,p,l,i((1-u/y)*h))}}},e})},function(t,n){t.exports=e},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),l=n(1),a=n(0),u=o(a),f=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;r(this,e),this.stats=new u.default,this.stats.showPanel(t)}return i(e,[{key:"manager",value:function(e){e.get("container").appendChild(this.stats.dom),e.add("stats",this.stats,{alias:"$stats"})}},{key:"integrate",value:function(e){var t=e.stats,n=new l.Loop(function(){return t.begin()}),o=new l.Loop(function(){return t.end()});this.loops.unshift(n),this.loops.push(o),e.addLoop=function(e){var t=this;return new Promise(function(n){t.loops[t.loops.length-1]===o&&t.loops.pop(),t.loops.push(e),t.loops.push(o),n(e)})},n.start(),o.start()}}]),e}();f.codes={fps:0,ms:1,mb:2,custom:3},t.default=f,e.exports=t.default}])});