@eva/plugin-stats 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.stats.js +204 -2
- package/dist/EVA.plugin.stats.min.js +1 -1
- package/dist/miniprogram.js +204 -2
- package/dist/plugin-stats.cjs.js +183 -2
- package/dist/plugin-stats.cjs.prod.js +2 -2
- package/dist/plugin-stats.d.ts +5 -0
- package/dist/plugin-stats.esm.js +183 -2
- package/package.json +2 -2
package/dist/EVA.plugin.stats.js
CHANGED
|
@@ -98,6 +98,8 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
98
98
|
frames = 0;
|
|
99
99
|
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
100
100
|
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
101
|
+
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
102
|
+
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
101
103
|
var memPanel;
|
|
102
104
|
|
|
103
105
|
if (self.performance && self.performance.memory) {
|
|
@@ -113,11 +115,16 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
113
115
|
begin: function begin(time) {
|
|
114
116
|
beginTime = time || (performance || Date).now();
|
|
115
117
|
},
|
|
116
|
-
end: function end() {
|
|
118
|
+
end: function end(hook) {
|
|
117
119
|
frames++;
|
|
118
120
|
var time = (performance || Date).now();
|
|
119
121
|
msPanel.update(time - beginTime, 200);
|
|
120
122
|
|
|
123
|
+
if (hook) {
|
|
124
|
+
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
125
|
+
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
126
|
+
}
|
|
127
|
+
|
|
121
128
|
if (time >= prevTime + 1000) {
|
|
122
129
|
fpsPanel.update(frames * 1000 / (time - prevTime), 100);
|
|
123
130
|
prevTime = time;
|
|
@@ -188,6 +195,193 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
188
195
|
|
|
189
196
|
var Stats$1 = Stats;
|
|
190
197
|
|
|
198
|
+
var GLHook = function () {
|
|
199
|
+
function GLHook(_gl) {
|
|
200
|
+
this.drawPasses = 0;
|
|
201
|
+
this.isInit = false;
|
|
202
|
+
|
|
203
|
+
this.realGLDrawElements = function () {};
|
|
204
|
+
|
|
205
|
+
if (_gl) {
|
|
206
|
+
if (_gl.__proto__.drawElements) {
|
|
207
|
+
this.gl = _gl;
|
|
208
|
+
this.realGLDrawElements = _gl.__proto__.drawElements;
|
|
209
|
+
_gl.__proto__.drawElements = this.fakeGLdrawElements.bind(this);
|
|
210
|
+
this.isInit = true;
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
console.error("[GLHook] GL can't be NULL");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
218
|
+
this.drawPasses++;
|
|
219
|
+
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
GLHook.prototype.reset = function () {
|
|
223
|
+
this.drawPasses = 0;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
GLHook.prototype.release = function () {
|
|
227
|
+
if (this.isInit) {
|
|
228
|
+
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
this.isInit = false;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
return GLHook;
|
|
235
|
+
}();
|
|
236
|
+
|
|
237
|
+
var TextureHook = function () {
|
|
238
|
+
function TextureHook(_gl) {
|
|
239
|
+
this.createdTextures = new Array();
|
|
240
|
+
this.maxTexturesCount = 0;
|
|
241
|
+
this.isInit = false;
|
|
242
|
+
|
|
243
|
+
this.realGLCreateTexture = function () {};
|
|
244
|
+
|
|
245
|
+
this.realGLDeleteTexture = function () {};
|
|
246
|
+
|
|
247
|
+
if (_gl) {
|
|
248
|
+
if (_gl.__proto__.createTexture) {
|
|
249
|
+
this.gl = _gl;
|
|
250
|
+
this.realGLCreateTexture = _gl.__proto__.createTexture;
|
|
251
|
+
this.realGLDeleteTexture = _gl.__proto__.deleteTexture;
|
|
252
|
+
_gl.__proto__.createTexture = this.fakeGLCreateTexture.bind(this);
|
|
253
|
+
_gl.__proto__.deleteTexture = this.fakeGLDeleteTexture.bind(this);
|
|
254
|
+
this.isInit = true;
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
console.error("[TextureHook] GL can't be NULL");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
262
|
+
get: function get() {
|
|
263
|
+
return this.createdTextures.length;
|
|
264
|
+
},
|
|
265
|
+
enumerable: false,
|
|
266
|
+
configurable: true
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
TextureHook.prototype.registerTexture = function (texture) {
|
|
270
|
+
this.createdTextures.push(texture);
|
|
271
|
+
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
275
|
+
var texture = this.realGLCreateTexture.call(this.gl);
|
|
276
|
+
this.registerTexture(texture);
|
|
277
|
+
return texture;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
281
|
+
var index = this.createdTextures.indexOf(texture);
|
|
282
|
+
|
|
283
|
+
if (index > -1) {
|
|
284
|
+
this.createdTextures.splice(index, 1);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
this.realGLDeleteTexture.call(this.gl, texture);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
TextureHook.prototype.reset = function () {
|
|
291
|
+
this.createdTextures = new Array();
|
|
292
|
+
this.maxTexturesCount = 0;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
TextureHook.prototype.release = function () {
|
|
296
|
+
if (this.isInit) {
|
|
297
|
+
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
298
|
+
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
299
|
+
console.log('[TextureHook] Hook was removed!');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this.isInit = false;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
return TextureHook;
|
|
306
|
+
}();
|
|
307
|
+
|
|
308
|
+
var BaseHooks = function () {
|
|
309
|
+
function BaseHooks() {
|
|
310
|
+
this._drawCalls = -1;
|
|
311
|
+
this._maxDeltaDrawCalls = -1;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
BaseHooks.prototype.attach = function (gl) {
|
|
315
|
+
this.glhook = new GLHook(gl);
|
|
316
|
+
this.texturehook = new TextureHook(gl);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
320
|
+
get: function get() {
|
|
321
|
+
if (this.glhook && this.glhook.isInit) {
|
|
322
|
+
return this.glhook.drawPasses;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return -1;
|
|
326
|
+
},
|
|
327
|
+
enumerable: false,
|
|
328
|
+
configurable: true
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(BaseHooks.prototype, "maxDeltaDrawCalls", {
|
|
331
|
+
get: function get() {
|
|
332
|
+
return this._maxDeltaDrawCalls;
|
|
333
|
+
},
|
|
334
|
+
enumerable: false,
|
|
335
|
+
configurable: true
|
|
336
|
+
});
|
|
337
|
+
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
338
|
+
get: function get() {
|
|
339
|
+
if (this._drawCalls == -1) {
|
|
340
|
+
this._drawCalls = this.drawCalls;
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
var dc = this.drawCalls;
|
|
345
|
+
var delta = dc - this._drawCalls;
|
|
346
|
+
this._drawCalls = dc;
|
|
347
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
348
|
+
return delta;
|
|
349
|
+
},
|
|
350
|
+
enumerable: false,
|
|
351
|
+
configurable: true
|
|
352
|
+
});
|
|
353
|
+
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
354
|
+
get: function get() {
|
|
355
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.maxTexturesCount;
|
|
356
|
+
return 0;
|
|
357
|
+
},
|
|
358
|
+
enumerable: false,
|
|
359
|
+
configurable: true
|
|
360
|
+
});
|
|
361
|
+
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
362
|
+
get: function get() {
|
|
363
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.currentTextureCount;
|
|
364
|
+
return 0;
|
|
365
|
+
},
|
|
366
|
+
enumerable: false,
|
|
367
|
+
configurable: true
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
BaseHooks.prototype.reset = function () {
|
|
371
|
+
this._maxDeltaDrawCalls = -1;
|
|
372
|
+
this._drawCalls = -1;
|
|
373
|
+
if (this.glhook) this.glhook.reset();
|
|
374
|
+
if (this.texturehook) this.texturehook.reset();
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
BaseHooks.prototype.release = function () {
|
|
378
|
+
if (this.glhook) this.glhook.release();
|
|
379
|
+
if (this.texturehook) this.texturehook.release();
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
return BaseHooks;
|
|
383
|
+
}();
|
|
384
|
+
|
|
191
385
|
var StatsSystem = function (_super) {
|
|
192
386
|
__extends(StatsSystem, _super);
|
|
193
387
|
|
|
@@ -207,6 +401,14 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
207
401
|
|
|
208
402
|
this.show = param.show;
|
|
209
403
|
this.style = param.style;
|
|
404
|
+
this.renderSystem = this.game.getSystem('Renderer');
|
|
405
|
+
this.app = this.renderSystem.application;
|
|
406
|
+
|
|
407
|
+
if (this.app && this.show) {
|
|
408
|
+
var gl = this.app.renderer.gl;
|
|
409
|
+
this.hook = new BaseHooks();
|
|
410
|
+
this.hook.attach(gl);
|
|
411
|
+
}
|
|
210
412
|
};
|
|
211
413
|
|
|
212
414
|
StatsSystem.prototype.start = function () {
|
|
@@ -220,7 +422,7 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
220
422
|
|
|
221
423
|
StatsSystem.prototype.lateUpdate = function () {
|
|
222
424
|
if (!this.show) return;
|
|
223
|
-
this.stats && this.stats.end();
|
|
425
|
+
this.stats && this.stats.end(this.hook);
|
|
224
426
|
};
|
|
225
427
|
|
|
226
428
|
StatsSystem.systemName = 'Stats';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var _EVA_IIFE_stats=function(t,e){"use strict";var
|
|
1
|
+
window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_stats=function(t,e){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function o(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(e.Component),s=function t(e){var r=(e=n({width:20,height:12,x:0,y:0},e)).width,o=e.height,i=e.x,s=e.y,a=0,l=document.createElement("div");function h(t){return l.appendChild(t.dom),t}function u(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";a=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+r+"vw;height: "+o+"vw;left: "+i+"vw;top: "+s+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),u(++a%l.children.length)}),!1);var c,p=(performance||Date).now(),f=p,d=0,x=h(t.Panel("FPS","#0ff","#002")),w=h(t.Panel("MS","#0f0","#020")),m=h(t.Panel("DrawCall","#330570","#A69700")),_=h(t.Panel("TC:","#A62500","#00B454"));return self.performance&&self.performance.memory&&(c=h(t.Panel("MB","#f08","#201"))),u(0),{REVISION:16,dom:l,addPanel:h,showPanel:u,begin:function(t){p=t||(performance||Date).now()},end:function(t){d++;var e=(performance||Date).now();if(w.update(e-p,200),t&&(m.update(t.deltaDrawCalls,Math.max(50,t.maxDeltaDrawCalls)),_.update(t.texturesCount,Math.max(20,t.maxTextureCount))),e>=f+1e3&&(x.update(1e3*d/(e-f),100),f=e,d=0,c)){var r=performance.memory;c.update(r.usedJSHeapSize/1048576,r.jsHeapSizeLimit/1048576)}return e},update:function(){p=this.end()},domElement:l,setMode:u}};s.Panel=function(t,e,r){var o=1/0,n=0,i=Math.round,s=i(window.devicePixelRatio||1),a=80*s,l=48*s,h=3*s,u=2*s,c=3*s,p=15*s,f=74*s,d=30*s,x=document.createElement("canvas");x.width=a,x.height=l,x.style.cssText="width:100%;height:100%";var w=x.getContext("2d");return w.font="bold "+9*s+"px Helvetica,Arial,sans-serif",w.textBaseline="top",w.fillStyle=r,w.fillRect(0,0,a,l),w.fillStyle=e,w.fillText(t,h,u),w.fillRect(c,p,f,d),w.fillStyle=r,w.globalAlpha=.9,w.fillRect(c,p,f,d),{dom:x,update:function(l,m){o=Math.min(o,l),n=Math.max(n,l),w.fillStyle=r,w.globalAlpha=1,w.fillRect(0,0,a,p),w.fillStyle=e,w.fillText(i(l)+" "+t+" ("+i(o)+"-"+i(n)+")",h,u),w.drawImage(x,c+s,p,f-s,d,c,p,f-s,d),w.fillRect(c+f-s,p,s,d),w.fillStyle=r,w.globalAlpha=.9,w.fillRect(c+f-s,p,s,i((1-l/m)*d))}}};var a=s,l=function(){function t(t){this.drawPasses=0,this.isInit=!1,this.realGLDrawElements=function(){},t?t.__proto__.drawElements&&(this.gl=t,this.realGLDrawElements=t.__proto__.drawElements,t.__proto__.drawElements=this.fakeGLdrawElements.bind(this),this.isInit=!0):console.error("[GLHook] GL can't be NULL")}return t.prototype.fakeGLdrawElements=function(t,e,r,o){this.drawPasses++,this.realGLDrawElements.call(this.gl,t,e,r,o)},t.prototype.reset=function(){this.drawPasses=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.drawElements=this.realGLDrawElements),this.isInit=!1},t}(),h=function(){function t(t){this.createdTextures=new Array,this.maxTexturesCount=0,this.isInit=!1,this.realGLCreateTexture=function(){},this.realGLDeleteTexture=function(){},t?t.__proto__.createTexture&&(this.gl=t,this.realGLCreateTexture=t.__proto__.createTexture,this.realGLDeleteTexture=t.__proto__.deleteTexture,t.__proto__.createTexture=this.fakeGLCreateTexture.bind(this),t.__proto__.deleteTexture=this.fakeGLDeleteTexture.bind(this),this.isInit=!0):console.error("[TextureHook] GL can't be NULL")}return Object.defineProperty(t.prototype,"currentTextureCount",{get:function(){return this.createdTextures.length},enumerable:!1,configurable:!0}),t.prototype.registerTexture=function(t){this.createdTextures.push(t),this.maxTexturesCount=Math.max(this.createdTextures.length,this.maxTexturesCount)},t.prototype.fakeGLCreateTexture=function(){var t=this.realGLCreateTexture.call(this.gl);return this.registerTexture(t),t},t.prototype.fakeGLDeleteTexture=function(t){var e=this.createdTextures.indexOf(t);e>-1&&this.createdTextures.splice(e,1),this.realGLDeleteTexture.call(this.gl,t)},t.prototype.reset=function(){this.createdTextures=new Array,this.maxTexturesCount=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.createTexture=this.realGLCreateTexture,this.gl.__proto__.deleteTexture=this.realGLDeleteTexture,console.log("[TextureHook] Hook was removed!")),this.isInit=!1},t}(),u=function(){function t(){this._drawCalls=-1,this._maxDeltaDrawCalls=-1}return t.prototype.attach=function(t){this.glhook=new l(t),this.texturehook=new h(t)},Object.defineProperty(t.prototype,"drawCalls",{get:function(){return this.glhook&&this.glhook.isInit?this.glhook.drawPasses:-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxDeltaDrawCalls",{get:function(){return this._maxDeltaDrawCalls},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deltaDrawCalls",{get:function(){if(-1==this._drawCalls)return this._drawCalls=this.drawCalls,0;var t=this.drawCalls,e=t-this._drawCalls;return this._drawCalls=t,this._maxDeltaDrawCalls=Math.max(this._maxDeltaDrawCalls,e),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxTextureCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.maxTexturesCount:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"texturesCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.currentTextureCount:0},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this._maxDeltaDrawCalls=-1,this._drawCalls=-1,this.glhook&&this.glhook.reset(),this.texturehook&&this.texturehook.reset()},t.prototype.release=function(){this.glhook&&this.glhook.release(),this.texturehook&&this.texturehook.release()},t}(),c=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return o(e,t),e.prototype.init=function(t){if(void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style,this.renderSystem=this.game.getSystem("Renderer"),this.app=this.renderSystem.application,this.app&&this.show){var e=this.app.renderer.gl;this.hook=new u,this.hook.attach(e)}},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new i),this.stats=a(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))},e.prototype.lateUpdate=function(){this.show&&this.stats&&this.stats.end(this.hook)},e.systemName="Stats",e}(e.System),p={Components:[i],Systems:[c]};return t.Stats=i,t.StatsSystem=c,t.default=p,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);window.EVA.plugin.stats=window.EVA.plugin.stats||_EVA_IIFE_stats;
|
package/dist/miniprogram.js
CHANGED
|
@@ -56,6 +56,8 @@ var Stats = function Stats(style) {
|
|
|
56
56
|
frames = 0;
|
|
57
57
|
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
58
58
|
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
59
|
+
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
60
|
+
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
59
61
|
var memPanel;
|
|
60
62
|
|
|
61
63
|
if (self.performance && self.performance.memory) {
|
|
@@ -71,11 +73,16 @@ var Stats = function Stats(style) {
|
|
|
71
73
|
begin: function begin(time) {
|
|
72
74
|
beginTime = time || (performance || Date).now();
|
|
73
75
|
},
|
|
74
|
-
end: function end() {
|
|
76
|
+
end: function end(hook) {
|
|
75
77
|
frames++;
|
|
76
78
|
var time = (performance || Date).now();
|
|
77
79
|
msPanel.update(time - beginTime, 200);
|
|
78
80
|
|
|
81
|
+
if (hook) {
|
|
82
|
+
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
83
|
+
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
if (time >= prevTime + 1000) {
|
|
80
87
|
fpsPanel.update(frames * 1000 / (time - prevTime), 100);
|
|
81
88
|
prevTime = time;
|
|
@@ -146,6 +153,193 @@ Stats.Panel = function (name, fg, bg) {
|
|
|
146
153
|
|
|
147
154
|
var Stats$1 = Stats;
|
|
148
155
|
|
|
156
|
+
var GLHook = function () {
|
|
157
|
+
function GLHook(_gl) {
|
|
158
|
+
this.drawPasses = 0;
|
|
159
|
+
this.isInit = false;
|
|
160
|
+
|
|
161
|
+
this.realGLDrawElements = function () {};
|
|
162
|
+
|
|
163
|
+
if (_gl) {
|
|
164
|
+
if (_gl.__proto__.drawElements) {
|
|
165
|
+
this.gl = _gl;
|
|
166
|
+
this.realGLDrawElements = _gl.__proto__.drawElements;
|
|
167
|
+
_gl.__proto__.drawElements = this.fakeGLdrawElements.bind(this);
|
|
168
|
+
this.isInit = true;
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
console.error("[GLHook] GL can't be NULL");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
176
|
+
this.drawPasses++;
|
|
177
|
+
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
GLHook.prototype.reset = function () {
|
|
181
|
+
this.drawPasses = 0;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
GLHook.prototype.release = function () {
|
|
185
|
+
if (this.isInit) {
|
|
186
|
+
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.isInit = false;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return GLHook;
|
|
193
|
+
}();
|
|
194
|
+
|
|
195
|
+
var TextureHook = function () {
|
|
196
|
+
function TextureHook(_gl) {
|
|
197
|
+
this.createdTextures = new Array();
|
|
198
|
+
this.maxTexturesCount = 0;
|
|
199
|
+
this.isInit = false;
|
|
200
|
+
|
|
201
|
+
this.realGLCreateTexture = function () {};
|
|
202
|
+
|
|
203
|
+
this.realGLDeleteTexture = function () {};
|
|
204
|
+
|
|
205
|
+
if (_gl) {
|
|
206
|
+
if (_gl.__proto__.createTexture) {
|
|
207
|
+
this.gl = _gl;
|
|
208
|
+
this.realGLCreateTexture = _gl.__proto__.createTexture;
|
|
209
|
+
this.realGLDeleteTexture = _gl.__proto__.deleteTexture;
|
|
210
|
+
_gl.__proto__.createTexture = this.fakeGLCreateTexture.bind(this);
|
|
211
|
+
_gl.__proto__.deleteTexture = this.fakeGLDeleteTexture.bind(this);
|
|
212
|
+
this.isInit = true;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
console.error("[TextureHook] GL can't be NULL");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
220
|
+
get: function get() {
|
|
221
|
+
return this.createdTextures.length;
|
|
222
|
+
},
|
|
223
|
+
enumerable: false,
|
|
224
|
+
configurable: true
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
TextureHook.prototype.registerTexture = function (texture) {
|
|
228
|
+
this.createdTextures.push(texture);
|
|
229
|
+
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
233
|
+
var texture = this.realGLCreateTexture.call(this.gl);
|
|
234
|
+
this.registerTexture(texture);
|
|
235
|
+
return texture;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
239
|
+
var index = this.createdTextures.indexOf(texture);
|
|
240
|
+
|
|
241
|
+
if (index > -1) {
|
|
242
|
+
this.createdTextures.splice(index, 1);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
this.realGLDeleteTexture.call(this.gl, texture);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
TextureHook.prototype.reset = function () {
|
|
249
|
+
this.createdTextures = new Array();
|
|
250
|
+
this.maxTexturesCount = 0;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
TextureHook.prototype.release = function () {
|
|
254
|
+
if (this.isInit) {
|
|
255
|
+
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
256
|
+
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
257
|
+
console.log('[TextureHook] Hook was removed!');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
this.isInit = false;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return TextureHook;
|
|
264
|
+
}();
|
|
265
|
+
|
|
266
|
+
var BaseHooks = function () {
|
|
267
|
+
function BaseHooks() {
|
|
268
|
+
this._drawCalls = -1;
|
|
269
|
+
this._maxDeltaDrawCalls = -1;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
BaseHooks.prototype.attach = function (gl) {
|
|
273
|
+
this.glhook = new GLHook(gl);
|
|
274
|
+
this.texturehook = new TextureHook(gl);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
278
|
+
get: function get() {
|
|
279
|
+
if (this.glhook && this.glhook.isInit) {
|
|
280
|
+
return this.glhook.drawPasses;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return -1;
|
|
284
|
+
},
|
|
285
|
+
enumerable: false,
|
|
286
|
+
configurable: true
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(BaseHooks.prototype, "maxDeltaDrawCalls", {
|
|
289
|
+
get: function get() {
|
|
290
|
+
return this._maxDeltaDrawCalls;
|
|
291
|
+
},
|
|
292
|
+
enumerable: false,
|
|
293
|
+
configurable: true
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
296
|
+
get: function get() {
|
|
297
|
+
if (this._drawCalls == -1) {
|
|
298
|
+
this._drawCalls = this.drawCalls;
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
var dc = this.drawCalls;
|
|
303
|
+
var delta = dc - this._drawCalls;
|
|
304
|
+
this._drawCalls = dc;
|
|
305
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
306
|
+
return delta;
|
|
307
|
+
},
|
|
308
|
+
enumerable: false,
|
|
309
|
+
configurable: true
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
312
|
+
get: function get() {
|
|
313
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.maxTexturesCount;
|
|
314
|
+
return 0;
|
|
315
|
+
},
|
|
316
|
+
enumerable: false,
|
|
317
|
+
configurable: true
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
320
|
+
get: function get() {
|
|
321
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.currentTextureCount;
|
|
322
|
+
return 0;
|
|
323
|
+
},
|
|
324
|
+
enumerable: false,
|
|
325
|
+
configurable: true
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
BaseHooks.prototype.reset = function () {
|
|
329
|
+
this._maxDeltaDrawCalls = -1;
|
|
330
|
+
this._drawCalls = -1;
|
|
331
|
+
if (this.glhook) this.glhook.reset();
|
|
332
|
+
if (this.texturehook) this.texturehook.reset();
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
BaseHooks.prototype.release = function () {
|
|
336
|
+
if (this.glhook) this.glhook.release();
|
|
337
|
+
if (this.texturehook) this.texturehook.release();
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return BaseHooks;
|
|
341
|
+
}();
|
|
342
|
+
|
|
149
343
|
var StatsSystem = function (_super) {
|
|
150
344
|
__extends(StatsSystem, _super);
|
|
151
345
|
|
|
@@ -165,6 +359,14 @@ var StatsSystem = function (_super) {
|
|
|
165
359
|
|
|
166
360
|
this.show = param.show;
|
|
167
361
|
this.style = param.style;
|
|
362
|
+
this.renderSystem = this.game.getSystem('Renderer');
|
|
363
|
+
this.app = this.renderSystem.application;
|
|
364
|
+
|
|
365
|
+
if (this.app && this.show) {
|
|
366
|
+
var gl = this.app.renderer.gl;
|
|
367
|
+
this.hook = new BaseHooks();
|
|
368
|
+
this.hook.attach(gl);
|
|
369
|
+
}
|
|
168
370
|
};
|
|
169
371
|
|
|
170
372
|
StatsSystem.prototype.start = function () {
|
|
@@ -178,7 +380,7 @@ var StatsSystem = function (_super) {
|
|
|
178
380
|
|
|
179
381
|
StatsSystem.prototype.lateUpdate = function () {
|
|
180
382
|
if (!this.show) return;
|
|
181
|
-
this.stats && this.stats.end();
|
|
383
|
+
this.stats && this.stats.end(this.hook);
|
|
182
384
|
};
|
|
183
385
|
|
|
184
386
|
StatsSystem.systemName = 'Stats';
|
package/dist/plugin-stats.cjs.js
CHANGED
|
@@ -80,6 +80,8 @@ var Stats = function (style) {
|
|
|
80
80
|
var beginTime = (performance || Date).now(), prevTime = beginTime, frames = 0;
|
|
81
81
|
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
82
82
|
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
83
|
+
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
84
|
+
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
83
85
|
var memPanel;
|
|
84
86
|
if (self.performance && self.performance.memory) {
|
|
85
87
|
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
@@ -93,10 +95,14 @@ var Stats = function (style) {
|
|
|
93
95
|
begin: function (time) {
|
|
94
96
|
beginTime = time || (performance || Date).now();
|
|
95
97
|
},
|
|
96
|
-
end: function () {
|
|
98
|
+
end: function (hook) {
|
|
97
99
|
frames++;
|
|
98
100
|
var time = (performance || Date).now();
|
|
99
101
|
msPanel.update(time - beginTime, 200);
|
|
102
|
+
if (hook) {
|
|
103
|
+
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
104
|
+
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
105
|
+
}
|
|
100
106
|
if (time >= prevTime + 1000) {
|
|
101
107
|
fpsPanel.update((frames * 1000) / (time - prevTime), 100);
|
|
102
108
|
prevTime = time;
|
|
@@ -155,6 +161,174 @@ Stats.Panel = function (name, fg, bg) {
|
|
|
155
161
|
};
|
|
156
162
|
var Stats$1 = Stats;
|
|
157
163
|
|
|
164
|
+
var GLHook = (function () {
|
|
165
|
+
function GLHook(_gl) {
|
|
166
|
+
this.drawPasses = 0;
|
|
167
|
+
this.isInit = false;
|
|
168
|
+
this.realGLDrawElements = function () { };
|
|
169
|
+
if (_gl) {
|
|
170
|
+
if (_gl.__proto__.drawElements) {
|
|
171
|
+
this.gl = _gl;
|
|
172
|
+
this.realGLDrawElements = _gl.__proto__.drawElements;
|
|
173
|
+
_gl.__proto__.drawElements = this.fakeGLdrawElements.bind(this);
|
|
174
|
+
this.isInit = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.error("[GLHook] GL can't be NULL");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
182
|
+
this.drawPasses++;
|
|
183
|
+
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
184
|
+
};
|
|
185
|
+
GLHook.prototype.reset = function () {
|
|
186
|
+
this.drawPasses = 0;
|
|
187
|
+
};
|
|
188
|
+
GLHook.prototype.release = function () {
|
|
189
|
+
if (this.isInit) {
|
|
190
|
+
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
191
|
+
}
|
|
192
|
+
this.isInit = false;
|
|
193
|
+
};
|
|
194
|
+
return GLHook;
|
|
195
|
+
}());
|
|
196
|
+
|
|
197
|
+
var TextureHook = (function () {
|
|
198
|
+
function TextureHook(_gl) {
|
|
199
|
+
this.createdTextures = new Array();
|
|
200
|
+
this.maxTexturesCount = 0;
|
|
201
|
+
this.isInit = false;
|
|
202
|
+
this.realGLCreateTexture = function () { };
|
|
203
|
+
this.realGLDeleteTexture = function () { };
|
|
204
|
+
if (_gl) {
|
|
205
|
+
if (_gl.__proto__.createTexture) {
|
|
206
|
+
this.gl = _gl;
|
|
207
|
+
this.realGLCreateTexture = _gl.__proto__.createTexture;
|
|
208
|
+
this.realGLDeleteTexture = _gl.__proto__.deleteTexture;
|
|
209
|
+
_gl.__proto__.createTexture = this.fakeGLCreateTexture.bind(this);
|
|
210
|
+
_gl.__proto__.deleteTexture = this.fakeGLDeleteTexture.bind(this);
|
|
211
|
+
this.isInit = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.error("[TextureHook] GL can't be NULL");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
219
|
+
get: function () {
|
|
220
|
+
return this.createdTextures.length;
|
|
221
|
+
},
|
|
222
|
+
enumerable: false,
|
|
223
|
+
configurable: true
|
|
224
|
+
});
|
|
225
|
+
TextureHook.prototype.registerTexture = function (texture) {
|
|
226
|
+
this.createdTextures.push(texture);
|
|
227
|
+
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
228
|
+
};
|
|
229
|
+
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
230
|
+
var texture = this.realGLCreateTexture.call(this.gl);
|
|
231
|
+
this.registerTexture(texture);
|
|
232
|
+
return texture;
|
|
233
|
+
};
|
|
234
|
+
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
235
|
+
var index = this.createdTextures.indexOf(texture);
|
|
236
|
+
if (index > -1) {
|
|
237
|
+
this.createdTextures.splice(index, 1);
|
|
238
|
+
}
|
|
239
|
+
this.realGLDeleteTexture.call(this.gl, texture);
|
|
240
|
+
};
|
|
241
|
+
TextureHook.prototype.reset = function () {
|
|
242
|
+
this.createdTextures = new Array();
|
|
243
|
+
this.maxTexturesCount = 0;
|
|
244
|
+
};
|
|
245
|
+
TextureHook.prototype.release = function () {
|
|
246
|
+
if (this.isInit) {
|
|
247
|
+
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
248
|
+
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
249
|
+
console.log('[TextureHook] Hook was removed!');
|
|
250
|
+
}
|
|
251
|
+
this.isInit = false;
|
|
252
|
+
};
|
|
253
|
+
return TextureHook;
|
|
254
|
+
}());
|
|
255
|
+
|
|
256
|
+
var BaseHooks = (function () {
|
|
257
|
+
function BaseHooks() {
|
|
258
|
+
this._drawCalls = -1;
|
|
259
|
+
this._maxDeltaDrawCalls = -1;
|
|
260
|
+
}
|
|
261
|
+
BaseHooks.prototype.attach = function (gl) {
|
|
262
|
+
this.glhook = new GLHook(gl);
|
|
263
|
+
this.texturehook = new TextureHook(gl);
|
|
264
|
+
};
|
|
265
|
+
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
266
|
+
get: function () {
|
|
267
|
+
if (this.glhook && this.glhook.isInit) {
|
|
268
|
+
return this.glhook.drawPasses;
|
|
269
|
+
}
|
|
270
|
+
return -1;
|
|
271
|
+
},
|
|
272
|
+
enumerable: false,
|
|
273
|
+
configurable: true
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(BaseHooks.prototype, "maxDeltaDrawCalls", {
|
|
276
|
+
get: function () {
|
|
277
|
+
return this._maxDeltaDrawCalls;
|
|
278
|
+
},
|
|
279
|
+
enumerable: false,
|
|
280
|
+
configurable: true
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
283
|
+
get: function () {
|
|
284
|
+
if (this._drawCalls == -1) {
|
|
285
|
+
this._drawCalls = this.drawCalls;
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
var dc = this.drawCalls;
|
|
289
|
+
var delta = dc - this._drawCalls;
|
|
290
|
+
this._drawCalls = dc;
|
|
291
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
292
|
+
return delta;
|
|
293
|
+
},
|
|
294
|
+
enumerable: false,
|
|
295
|
+
configurable: true
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
298
|
+
get: function () {
|
|
299
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
300
|
+
return this.texturehook.maxTexturesCount;
|
|
301
|
+
return 0;
|
|
302
|
+
},
|
|
303
|
+
enumerable: false,
|
|
304
|
+
configurable: true
|
|
305
|
+
});
|
|
306
|
+
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
307
|
+
get: function () {
|
|
308
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
309
|
+
return this.texturehook.currentTextureCount;
|
|
310
|
+
return 0;
|
|
311
|
+
},
|
|
312
|
+
enumerable: false,
|
|
313
|
+
configurable: true
|
|
314
|
+
});
|
|
315
|
+
BaseHooks.prototype.reset = function () {
|
|
316
|
+
this._maxDeltaDrawCalls = -1;
|
|
317
|
+
this._drawCalls = -1;
|
|
318
|
+
if (this.glhook)
|
|
319
|
+
this.glhook.reset();
|
|
320
|
+
if (this.texturehook)
|
|
321
|
+
this.texturehook.reset();
|
|
322
|
+
};
|
|
323
|
+
BaseHooks.prototype.release = function () {
|
|
324
|
+
if (this.glhook)
|
|
325
|
+
this.glhook.release();
|
|
326
|
+
if (this.texturehook)
|
|
327
|
+
this.texturehook.release();
|
|
328
|
+
};
|
|
329
|
+
return BaseHooks;
|
|
330
|
+
}());
|
|
331
|
+
|
|
158
332
|
var StatsSystem = (function (_super) {
|
|
159
333
|
__extends(StatsSystem, _super);
|
|
160
334
|
function StatsSystem() {
|
|
@@ -166,6 +340,13 @@ var StatsSystem = (function (_super) {
|
|
|
166
340
|
if (param === void 0) { param = { show: true }; }
|
|
167
341
|
this.show = param.show;
|
|
168
342
|
this.style = param.style;
|
|
343
|
+
this.renderSystem = this.game.getSystem('Renderer');
|
|
344
|
+
this.app = this.renderSystem.application;
|
|
345
|
+
if (this.app && this.show) {
|
|
346
|
+
var gl = this.app.renderer.gl;
|
|
347
|
+
this.hook = new BaseHooks();
|
|
348
|
+
this.hook.attach(gl);
|
|
349
|
+
}
|
|
169
350
|
};
|
|
170
351
|
StatsSystem.prototype.start = function () {
|
|
171
352
|
if (!this.show)
|
|
@@ -179,7 +360,7 @@ var StatsSystem = (function (_super) {
|
|
|
179
360
|
StatsSystem.prototype.lateUpdate = function () {
|
|
180
361
|
if (!this.show)
|
|
181
362
|
return;
|
|
182
|
-
this.stats && this.stats.end();
|
|
363
|
+
this.stats && this.stats.end(this.hook);
|
|
183
364
|
};
|
|
184
365
|
StatsSystem.systemName = 'Stats';
|
|
185
366
|
return StatsSystem;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,r)};
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */function
|
|
15
|
+
***************************************************************************** */function r(t,r){function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)},s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(t.Component),n=function(t){var e=(t=o({width:20,height:12,x:0,y:0},t)).width,r=t.height,s=t.x,i=t.y,a=0,l=document.createElement("div");function h(t){return l.appendChild(t.dom),t}function u(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";a=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+r+"vw;left: "+s+"vw;top: "+i+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),u(++a%l.children.length)}),!1);var c,p=(performance||Date).now(),f=p,d=0,x=h(n.Panel("FPS","#0ff","#002")),m=h(n.Panel("MS","#0f0","#020")),w=h(n.Panel("DrawCall","#330570","#A69700")),y=h(n.Panel("TC:","#A62500","#00B454"));return self.performance&&self.performance.memory&&(c=h(n.Panel("MB","#f08","#201"))),u(0),{REVISION:16,dom:l,addPanel:h,showPanel:u,begin:function(t){p=t||(performance||Date).now()},end:function(t){d++;var e=(performance||Date).now();if(m.update(e-p,200),t&&(w.update(t.deltaDrawCalls,Math.max(50,t.maxDeltaDrawCalls)),y.update(t.texturesCount,Math.max(20,t.maxTextureCount))),e>=f+1e3&&(x.update(1e3*d/(e-f),100),f=e,d=0,c)){var r=performance.memory;c.update(r.usedJSHeapSize/1048576,r.jsHeapSizeLimit/1048576)}return e},update:function(){p=this.end()},domElement:l,setMode:u}};n.Panel=function(t,e,r){var o=1/0,s=0,n=Math.round,i=n(window.devicePixelRatio||1),a=80*i,l=48*i,h=3*i,u=2*i,c=3*i,p=15*i,f=74*i,d=30*i,x=document.createElement("canvas");x.width=a,x.height=l,x.style.cssText="width:100%;height:100%";var m=x.getContext("2d");return m.font="bold "+9*i+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=r,m.fillRect(0,0,a,l),m.fillStyle=e,m.fillText(t,h,u),m.fillRect(c,p,f,d),m.fillStyle=r,m.globalAlpha=.9,m.fillRect(c,p,f,d),{dom:x,update:function(l,w){o=Math.min(o,l),s=Math.max(s,l),m.fillStyle=r,m.globalAlpha=1,m.fillRect(0,0,a,p),m.fillStyle=e,m.fillText(n(l)+" "+t+" ("+n(o)+"-"+n(s)+")",h,u),m.drawImage(x,c+i,p,f-i,d,c,p,f-i,d),m.fillRect(c+f-i,p,i,d),m.fillStyle=r,m.globalAlpha=.9,m.fillRect(c+f-i,p,i,n((1-l/w)*d))}}};var i=n,a=function(){function t(t){this.drawPasses=0,this.isInit=!1,this.realGLDrawElements=function(){},t?t.__proto__.drawElements&&(this.gl=t,this.realGLDrawElements=t.__proto__.drawElements,t.__proto__.drawElements=this.fakeGLdrawElements.bind(this),this.isInit=!0):console.error("[GLHook] GL can't be NULL")}return t.prototype.fakeGLdrawElements=function(t,e,r,o){this.drawPasses++,this.realGLDrawElements.call(this.gl,t,e,r,o)},t.prototype.reset=function(){this.drawPasses=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.drawElements=this.realGLDrawElements),this.isInit=!1},t}(),l=function(){function t(t){this.createdTextures=new Array,this.maxTexturesCount=0,this.isInit=!1,this.realGLCreateTexture=function(){},this.realGLDeleteTexture=function(){},t?t.__proto__.createTexture&&(this.gl=t,this.realGLCreateTexture=t.__proto__.createTexture,this.realGLDeleteTexture=t.__proto__.deleteTexture,t.__proto__.createTexture=this.fakeGLCreateTexture.bind(this),t.__proto__.deleteTexture=this.fakeGLDeleteTexture.bind(this),this.isInit=!0):console.error("[TextureHook] GL can't be NULL")}return Object.defineProperty(t.prototype,"currentTextureCount",{get:function(){return this.createdTextures.length},enumerable:!1,configurable:!0}),t.prototype.registerTexture=function(t){this.createdTextures.push(t),this.maxTexturesCount=Math.max(this.createdTextures.length,this.maxTexturesCount)},t.prototype.fakeGLCreateTexture=function(){var t=this.realGLCreateTexture.call(this.gl);return this.registerTexture(t),t},t.prototype.fakeGLDeleteTexture=function(t){var e=this.createdTextures.indexOf(t);e>-1&&this.createdTextures.splice(e,1),this.realGLDeleteTexture.call(this.gl,t)},t.prototype.reset=function(){this.createdTextures=new Array,this.maxTexturesCount=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.createTexture=this.realGLCreateTexture,this.gl.__proto__.deleteTexture=this.realGLDeleteTexture,console.log("[TextureHook] Hook was removed!")),this.isInit=!1},t}(),h=function(){function t(){this._drawCalls=-1,this._maxDeltaDrawCalls=-1}return t.prototype.attach=function(t){this.glhook=new a(t),this.texturehook=new l(t)},Object.defineProperty(t.prototype,"drawCalls",{get:function(){return this.glhook&&this.glhook.isInit?this.glhook.drawPasses:-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxDeltaDrawCalls",{get:function(){return this._maxDeltaDrawCalls},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deltaDrawCalls",{get:function(){if(-1==this._drawCalls)return this._drawCalls=this.drawCalls,0;var t=this.drawCalls,e=t-this._drawCalls;return this._drawCalls=t,this._maxDeltaDrawCalls=Math.max(this._maxDeltaDrawCalls,e),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxTextureCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.maxTexturesCount:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"texturesCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.currentTextureCount:0},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this._maxDeltaDrawCalls=-1,this._drawCalls=-1,this.glhook&&this.glhook.reset(),this.texturehook&&this.texturehook.reset()},t.prototype.release=function(){this.glhook&&this.glhook.release(),this.texturehook&&this.texturehook.release()},t}(),u=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return r(e,t),e.prototype.init=function(t){if(void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style,this.renderSystem=this.game.getSystem("Renderer"),this.app=this.renderSystem.application,this.app&&this.show){var e=this.app.renderer.gl;this.hook=new h,this.hook.attach(e)}},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new s),this.stats=i(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))},e.prototype.lateUpdate=function(){this.show&&this.stats&&this.stats.end(this.hook)},e.systemName="Stats",e}(t.System),c={Components:[s],Systems:[u]};exports.Stats=s,exports.StatsSystem=u,exports.default=c;
|
package/dist/plugin-stats.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Application } from '@eva/renderer-adapter';
|
|
1
2
|
import { Component } from '@eva/eva.js';
|
|
3
|
+
import type { RendererSystem } from '@eva/plugin-renderer';
|
|
2
4
|
import { System } from '@eva/eva.js';
|
|
3
5
|
|
|
4
6
|
declare const _default: {
|
|
@@ -25,9 +27,12 @@ declare interface StatsParams {
|
|
|
25
27
|
|
|
26
28
|
export declare class StatsSystem extends System {
|
|
27
29
|
static systemName: string;
|
|
30
|
+
app: Application;
|
|
31
|
+
renderSystem: RendererSystem;
|
|
28
32
|
show: boolean;
|
|
29
33
|
stats: any;
|
|
30
34
|
style: any;
|
|
35
|
+
hook: any;
|
|
31
36
|
component: Stats;
|
|
32
37
|
init(param?: StatsParams): void;
|
|
33
38
|
start(): void;
|
package/dist/plugin-stats.esm.js
CHANGED
|
@@ -76,6 +76,8 @@ var Stats = function (style) {
|
|
|
76
76
|
var beginTime = (performance || Date).now(), prevTime = beginTime, frames = 0;
|
|
77
77
|
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
78
78
|
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
79
|
+
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
80
|
+
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
79
81
|
var memPanel;
|
|
80
82
|
if (self.performance && self.performance.memory) {
|
|
81
83
|
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
@@ -89,10 +91,14 @@ var Stats = function (style) {
|
|
|
89
91
|
begin: function (time) {
|
|
90
92
|
beginTime = time || (performance || Date).now();
|
|
91
93
|
},
|
|
92
|
-
end: function () {
|
|
94
|
+
end: function (hook) {
|
|
93
95
|
frames++;
|
|
94
96
|
var time = (performance || Date).now();
|
|
95
97
|
msPanel.update(time - beginTime, 200);
|
|
98
|
+
if (hook) {
|
|
99
|
+
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
100
|
+
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
101
|
+
}
|
|
96
102
|
if (time >= prevTime + 1000) {
|
|
97
103
|
fpsPanel.update((frames * 1000) / (time - prevTime), 100);
|
|
98
104
|
prevTime = time;
|
|
@@ -151,6 +157,174 @@ Stats.Panel = function (name, fg, bg) {
|
|
|
151
157
|
};
|
|
152
158
|
var Stats$1 = Stats;
|
|
153
159
|
|
|
160
|
+
var GLHook = (function () {
|
|
161
|
+
function GLHook(_gl) {
|
|
162
|
+
this.drawPasses = 0;
|
|
163
|
+
this.isInit = false;
|
|
164
|
+
this.realGLDrawElements = function () { };
|
|
165
|
+
if (_gl) {
|
|
166
|
+
if (_gl.__proto__.drawElements) {
|
|
167
|
+
this.gl = _gl;
|
|
168
|
+
this.realGLDrawElements = _gl.__proto__.drawElements;
|
|
169
|
+
_gl.__proto__.drawElements = this.fakeGLdrawElements.bind(this);
|
|
170
|
+
this.isInit = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.error("[GLHook] GL can't be NULL");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
178
|
+
this.drawPasses++;
|
|
179
|
+
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
180
|
+
};
|
|
181
|
+
GLHook.prototype.reset = function () {
|
|
182
|
+
this.drawPasses = 0;
|
|
183
|
+
};
|
|
184
|
+
GLHook.prototype.release = function () {
|
|
185
|
+
if (this.isInit) {
|
|
186
|
+
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
187
|
+
}
|
|
188
|
+
this.isInit = false;
|
|
189
|
+
};
|
|
190
|
+
return GLHook;
|
|
191
|
+
}());
|
|
192
|
+
|
|
193
|
+
var TextureHook = (function () {
|
|
194
|
+
function TextureHook(_gl) {
|
|
195
|
+
this.createdTextures = new Array();
|
|
196
|
+
this.maxTexturesCount = 0;
|
|
197
|
+
this.isInit = false;
|
|
198
|
+
this.realGLCreateTexture = function () { };
|
|
199
|
+
this.realGLDeleteTexture = function () { };
|
|
200
|
+
if (_gl) {
|
|
201
|
+
if (_gl.__proto__.createTexture) {
|
|
202
|
+
this.gl = _gl;
|
|
203
|
+
this.realGLCreateTexture = _gl.__proto__.createTexture;
|
|
204
|
+
this.realGLDeleteTexture = _gl.__proto__.deleteTexture;
|
|
205
|
+
_gl.__proto__.createTexture = this.fakeGLCreateTexture.bind(this);
|
|
206
|
+
_gl.__proto__.deleteTexture = this.fakeGLDeleteTexture.bind(this);
|
|
207
|
+
this.isInit = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
console.error("[TextureHook] GL can't be NULL");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
215
|
+
get: function () {
|
|
216
|
+
return this.createdTextures.length;
|
|
217
|
+
},
|
|
218
|
+
enumerable: false,
|
|
219
|
+
configurable: true
|
|
220
|
+
});
|
|
221
|
+
TextureHook.prototype.registerTexture = function (texture) {
|
|
222
|
+
this.createdTextures.push(texture);
|
|
223
|
+
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
224
|
+
};
|
|
225
|
+
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
226
|
+
var texture = this.realGLCreateTexture.call(this.gl);
|
|
227
|
+
this.registerTexture(texture);
|
|
228
|
+
return texture;
|
|
229
|
+
};
|
|
230
|
+
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
231
|
+
var index = this.createdTextures.indexOf(texture);
|
|
232
|
+
if (index > -1) {
|
|
233
|
+
this.createdTextures.splice(index, 1);
|
|
234
|
+
}
|
|
235
|
+
this.realGLDeleteTexture.call(this.gl, texture);
|
|
236
|
+
};
|
|
237
|
+
TextureHook.prototype.reset = function () {
|
|
238
|
+
this.createdTextures = new Array();
|
|
239
|
+
this.maxTexturesCount = 0;
|
|
240
|
+
};
|
|
241
|
+
TextureHook.prototype.release = function () {
|
|
242
|
+
if (this.isInit) {
|
|
243
|
+
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
244
|
+
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
245
|
+
console.log('[TextureHook] Hook was removed!');
|
|
246
|
+
}
|
|
247
|
+
this.isInit = false;
|
|
248
|
+
};
|
|
249
|
+
return TextureHook;
|
|
250
|
+
}());
|
|
251
|
+
|
|
252
|
+
var BaseHooks = (function () {
|
|
253
|
+
function BaseHooks() {
|
|
254
|
+
this._drawCalls = -1;
|
|
255
|
+
this._maxDeltaDrawCalls = -1;
|
|
256
|
+
}
|
|
257
|
+
BaseHooks.prototype.attach = function (gl) {
|
|
258
|
+
this.glhook = new GLHook(gl);
|
|
259
|
+
this.texturehook = new TextureHook(gl);
|
|
260
|
+
};
|
|
261
|
+
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
262
|
+
get: function () {
|
|
263
|
+
if (this.glhook && this.glhook.isInit) {
|
|
264
|
+
return this.glhook.drawPasses;
|
|
265
|
+
}
|
|
266
|
+
return -1;
|
|
267
|
+
},
|
|
268
|
+
enumerable: false,
|
|
269
|
+
configurable: true
|
|
270
|
+
});
|
|
271
|
+
Object.defineProperty(BaseHooks.prototype, "maxDeltaDrawCalls", {
|
|
272
|
+
get: function () {
|
|
273
|
+
return this._maxDeltaDrawCalls;
|
|
274
|
+
},
|
|
275
|
+
enumerable: false,
|
|
276
|
+
configurable: true
|
|
277
|
+
});
|
|
278
|
+
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
279
|
+
get: function () {
|
|
280
|
+
if (this._drawCalls == -1) {
|
|
281
|
+
this._drawCalls = this.drawCalls;
|
|
282
|
+
return 0;
|
|
283
|
+
}
|
|
284
|
+
var dc = this.drawCalls;
|
|
285
|
+
var delta = dc - this._drawCalls;
|
|
286
|
+
this._drawCalls = dc;
|
|
287
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
288
|
+
return delta;
|
|
289
|
+
},
|
|
290
|
+
enumerable: false,
|
|
291
|
+
configurable: true
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
294
|
+
get: function () {
|
|
295
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
296
|
+
return this.texturehook.maxTexturesCount;
|
|
297
|
+
return 0;
|
|
298
|
+
},
|
|
299
|
+
enumerable: false,
|
|
300
|
+
configurable: true
|
|
301
|
+
});
|
|
302
|
+
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
303
|
+
get: function () {
|
|
304
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
305
|
+
return this.texturehook.currentTextureCount;
|
|
306
|
+
return 0;
|
|
307
|
+
},
|
|
308
|
+
enumerable: false,
|
|
309
|
+
configurable: true
|
|
310
|
+
});
|
|
311
|
+
BaseHooks.prototype.reset = function () {
|
|
312
|
+
this._maxDeltaDrawCalls = -1;
|
|
313
|
+
this._drawCalls = -1;
|
|
314
|
+
if (this.glhook)
|
|
315
|
+
this.glhook.reset();
|
|
316
|
+
if (this.texturehook)
|
|
317
|
+
this.texturehook.reset();
|
|
318
|
+
};
|
|
319
|
+
BaseHooks.prototype.release = function () {
|
|
320
|
+
if (this.glhook)
|
|
321
|
+
this.glhook.release();
|
|
322
|
+
if (this.texturehook)
|
|
323
|
+
this.texturehook.release();
|
|
324
|
+
};
|
|
325
|
+
return BaseHooks;
|
|
326
|
+
}());
|
|
327
|
+
|
|
154
328
|
var StatsSystem = (function (_super) {
|
|
155
329
|
__extends(StatsSystem, _super);
|
|
156
330
|
function StatsSystem() {
|
|
@@ -162,6 +336,13 @@ var StatsSystem = (function (_super) {
|
|
|
162
336
|
if (param === void 0) { param = { show: true }; }
|
|
163
337
|
this.show = param.show;
|
|
164
338
|
this.style = param.style;
|
|
339
|
+
this.renderSystem = this.game.getSystem('Renderer');
|
|
340
|
+
this.app = this.renderSystem.application;
|
|
341
|
+
if (this.app && this.show) {
|
|
342
|
+
var gl = this.app.renderer.gl;
|
|
343
|
+
this.hook = new BaseHooks();
|
|
344
|
+
this.hook.attach(gl);
|
|
345
|
+
}
|
|
165
346
|
};
|
|
166
347
|
StatsSystem.prototype.start = function () {
|
|
167
348
|
if (!this.show)
|
|
@@ -175,7 +356,7 @@ var StatsSystem = (function (_super) {
|
|
|
175
356
|
StatsSystem.prototype.lateUpdate = function () {
|
|
176
357
|
if (!this.show)
|
|
177
358
|
return;
|
|
178
|
-
this.stats && this.stats.end();
|
|
359
|
+
this.stats && this.stats.end(this.hook);
|
|
179
360
|
};
|
|
180
361
|
StatsSystem.systemName = 'Stats';
|
|
181
362
|
return StatsSystem;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-stats",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "@eva/plugin-stats",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-stats.esm.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "1.2.
|
|
21
|
+
"@eva/eva.js": "1.2.7",
|
|
22
22
|
"lodash-es": "^4.17.21"
|
|
23
23
|
}
|
|
24
24
|
}
|