@eva/plugin-stats 1.1.1-fix.1 → 1.1.1-fix.2

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.
@@ -0,0 +1,446 @@
1
+ window.EVA = window.EVA || {};
2
+ window.EVA.plugin = window.EVA.plugin || {};
3
+
4
+ var _EVA_IIFE_stats = function (exports, eva_js) {
5
+ 'use strict';
6
+
7
+ var _extendStatics = function extendStatics(d, b) {
8
+ _extendStatics = Object.setPrototypeOf || {
9
+ __proto__: []
10
+ } instanceof Array && function (d, b) {
11
+ d.__proto__ = b;
12
+ } || function (d, b) {
13
+ for (var p in b) {
14
+ if (b.hasOwnProperty(p)) d[p] = b[p];
15
+ }
16
+ };
17
+
18
+ return _extendStatics(d, b);
19
+ };
20
+
21
+ function __extends(d, b) {
22
+ _extendStatics(d, b);
23
+
24
+ function __() {
25
+ this.constructor = d;
26
+ }
27
+
28
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
+ }
30
+
31
+ var _assign = function __assign() {
32
+ _assign = Object.assign || function __assign(t) {
33
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
34
+ s = arguments[i];
35
+
36
+ for (var p in s) {
37
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
38
+ }
39
+ }
40
+
41
+ return t;
42
+ };
43
+
44
+ return _assign.apply(this, arguments);
45
+ };
46
+
47
+ var StatsComponent = function (_super) {
48
+ __extends(StatsComponent, _super);
49
+
50
+ function StatsComponent() {
51
+ return _super !== null && _super.apply(this, arguments) || this;
52
+ }
53
+
54
+ StatsComponent.prototype.update = function () {
55
+ this.stats && this.stats.begin();
56
+ };
57
+
58
+ StatsComponent.componentName = 'Stats';
59
+ return StatsComponent;
60
+ }(eva_js.Component);
61
+
62
+ var Stats$2 = StatsComponent;
63
+
64
+ var Stats = function Stats(style) {
65
+ style = _assign({
66
+ width: 20,
67
+ height: 12,
68
+ x: 0,
69
+ y: 0
70
+ }, style);
71
+ var width = style.width,
72
+ height = style.height,
73
+ x = style.x,
74
+ y = style.y;
75
+ var mode = 0;
76
+ var container = document.createElement('div');
77
+ container.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: " + width + "vw;height: " + height + "vw;left: " + x + "vw;top: " + y + "vw;";
78
+ container.addEventListener('click', function (event) {
79
+ event.preventDefault();
80
+ showPanel(++mode % container.children.length);
81
+ }, false);
82
+
83
+ function addPanel(panel) {
84
+ container.appendChild(panel.dom);
85
+ return panel;
86
+ }
87
+
88
+ function showPanel(id) {
89
+ for (var i = 0; i < container.children.length; i++) {
90
+ container.children[i].style.display = i === id ? 'block' : 'none';
91
+ }
92
+
93
+ mode = id;
94
+ }
95
+
96
+ var beginTime = (performance || Date).now(),
97
+ prevTime = beginTime,
98
+ frames = 0;
99
+ var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
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'));
103
+ var memPanel;
104
+
105
+ if (self.performance && self.performance.memory) {
106
+ memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
107
+ }
108
+
109
+ showPanel(0);
110
+ return {
111
+ REVISION: 16,
112
+ dom: container,
113
+ addPanel: addPanel,
114
+ showPanel: showPanel,
115
+ begin: function begin(time) {
116
+ beginTime = time || (performance || Date).now();
117
+ },
118
+ end: function end(hook) {
119
+ frames++;
120
+ var time = (performance || Date).now();
121
+ msPanel.update(time - beginTime, 200);
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
+
128
+ if (time >= prevTime + 1000) {
129
+ fpsPanel.update(frames * 1000 / (time - prevTime), 100);
130
+ prevTime = time;
131
+ frames = 0;
132
+
133
+ if (memPanel) {
134
+ var memory = performance.memory;
135
+ memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
136
+ }
137
+ }
138
+
139
+ return time;
140
+ },
141
+ update: function update() {
142
+ beginTime = this.end();
143
+ },
144
+ domElement: container,
145
+ setMode: showPanel
146
+ };
147
+ };
148
+
149
+ Stats.Panel = function (name, fg, bg) {
150
+ var min = Infinity,
151
+ max = 0;
152
+ var round = Math.round;
153
+ var PR = round(window.devicePixelRatio || 1);
154
+ var WIDTH = 80 * PR,
155
+ HEIGHT = 48 * PR,
156
+ TEXT_X = 3 * PR,
157
+ TEXT_Y = 2 * PR,
158
+ GRAPH_X = 3 * PR,
159
+ GRAPH_Y = 15 * PR,
160
+ GRAPH_WIDTH = 74 * PR,
161
+ GRAPH_HEIGHT = 30 * PR;
162
+ var canvas = document.createElement('canvas');
163
+ canvas.width = WIDTH;
164
+ canvas.height = HEIGHT;
165
+ canvas.style.cssText = 'width:100%;height:100%';
166
+ var context = canvas.getContext('2d');
167
+ context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';
168
+ context.textBaseline = 'top';
169
+ context.fillStyle = bg;
170
+ context.fillRect(0, 0, WIDTH, HEIGHT);
171
+ context.fillStyle = fg;
172
+ context.fillText(name, TEXT_X, TEXT_Y);
173
+ context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
174
+ context.fillStyle = bg;
175
+ context.globalAlpha = 0.9;
176
+ context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
177
+ return {
178
+ dom: canvas,
179
+ update: function update(value, maxValue) {
180
+ min = Math.min(min, value);
181
+ max = Math.max(max, value);
182
+ context.fillStyle = bg;
183
+ context.globalAlpha = 1;
184
+ context.fillRect(0, 0, WIDTH, GRAPH_Y);
185
+ context.fillStyle = fg;
186
+ context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);
187
+ context.drawImage(canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT);
188
+ context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);
189
+ context.fillStyle = bg;
190
+ context.globalAlpha = 0.9;
191
+ context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));
192
+ }
193
+ };
194
+ };
195
+
196
+ var Stats$1 = Stats;
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
+
385
+ var StatsSystem = function (_super) {
386
+ __extends(StatsSystem, _super);
387
+
388
+ function StatsSystem() {
389
+ var _this = _super !== null && _super.apply(this, arguments) || this;
390
+
391
+ _this.show = true;
392
+ return _this;
393
+ }
394
+
395
+ StatsSystem.prototype.init = function (param) {
396
+ if (param === void 0) {
397
+ param = {
398
+ show: true
399
+ };
400
+ }
401
+
402
+ this.show = param.show;
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
+ }
412
+ };
413
+
414
+ StatsSystem.prototype.start = function () {
415
+ if (!this.show) return;
416
+ this.component = this.game.scene.addComponent(new Stats$2());
417
+ this.stats = Stats$1(this.style);
418
+ this.component.stats = this.stats;
419
+ this.stats.showPanel(0);
420
+ document.body.appendChild(this.stats.dom);
421
+ };
422
+
423
+ StatsSystem.prototype.lateUpdate = function () {
424
+ if (!this.show) return;
425
+ this.stats && this.stats.end(this.hook);
426
+ };
427
+
428
+ StatsSystem.systemName = 'Stats';
429
+ return StatsSystem;
430
+ }(eva_js.System);
431
+
432
+ var StatsSystem$1 = StatsSystem;
433
+ var index = {
434
+ Components: [Stats$2],
435
+ Systems: [StatsSystem$1]
436
+ };
437
+ exports.Stats = Stats$2;
438
+ exports.StatsSystem = StatsSystem$1;
439
+ exports['default'] = index;
440
+ Object.defineProperty(exports, '__esModule', {
441
+ value: true
442
+ });
443
+ return exports;
444
+ }({}, EVA);
445
+
446
+ window.EVA.plugin.stats = window.EVA.plugin.stats || _EVA_IIFE_stats;
@@ -0,0 +1,2 @@
1
+ var t,e;t=this,e=function(t,e){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},a=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){var e=(t=i({width:20,height:12,x:0,y:0},t)).width,n=t.height,o=t.x,a=t.y,l=0,r=document.createElement("div");function f(t){return r.appendChild(t.dom),t}function p(t){for(var e=0;e<r.children.length;e++)r.children[e].style.display=e===t?"block":"none";l=t}r.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+n+"vw;left: "+o+"vw;top: "+a+"vw;",r.addEventListener("click",(function(t){t.preventDefault(),p(++l%r.children.length)}),!1);var c,h=(performance||Date).now(),u=h,d=0,y=f(s.Panel("FPS","#0ff","#002")),m=f(s.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(c=f(s.Panel("MB","#f08","#201"))),p(0),{REVISION:16,dom:r,addPanel:f,showPanel:p,begin:function(t){h=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-h,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,c)){var e=performance.memory;c.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){h=this.end()},domElement:r,setMode:p}};s.Panel=function(t,e,n){var o=1/0,i=0,a=Math.round,s=a(window.devicePixelRatio||1),l=80*s,r=48*s,f=3*s,p=2*s,c=3*s,h=15*s,u=74*s,d=30*s,y=document.createElement("canvas");y.width=l,y.height=r,y.style.cssText="width:100%;height:100%";var m=y.getContext("2d");return m.font="bold "+9*s+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,l,r),m.fillStyle=e,m.fillText(t,f,p),m.fillRect(c,h,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(c,h,u,d),{dom:y,update:function(r,v){o=Math.min(o,r),i=Math.max(i,r),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,l,h),m.fillStyle=e,m.fillText(a(r)+" "+t+" ("+a(o)+"-"+a(i)+")",f,p),m.drawImage(y,c+s,h,u-s,d,c,h,u-s,d),m.fillRect(c+u-s,h,s,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(c+u-s,h,s,a((1-r/v)*d))}}};var l=s,r=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){void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new a),this.stats=l(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()},e.systemName="Stats",e}(e.System),f={Components:[a],Systems:[r]};t.Stats=a,t.StatsSystem=r,t.default=f,Object.defineProperty(t,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@eva/eva.js")):"function"==typeof define&&define.amd?define(["exports","@eva/eva.js"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).EVA=t.EVA||{},t.EVA.plugin=t.EVA.plugin||{},t.EVA.plugin.stats={}),t.EVA);
2
+ //# sourceMappingURL=EVA.plugin.stats.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EVA.plugin.stats.min.js","sources":["../../../node_modules/tslib/tslib.es6.js","../lib/StatsComponent.ts","../lib/Stats.ts","../lib/StatsSystem.ts","../lib/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __createBinding(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","import { Component } from '@eva/eva.js';\n\nexport default class StatsComponent extends Component {\n static componentName: string = 'Stats';\n stats;\n\n update() {\n this.stats && this.stats.begin();\n }\n}\n","/**\n * @author mrdoob / http://mrdoob.com/\n */\n\nconst Stats = function (style) {\n style = { ...{ width: 20, height: 12, x: 0, y: 0 }, ...style };\n const { width, height, x, y } = style;\n let mode = 0;\n\n const container = document.createElement('div');\n container.style.cssText = `position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: ${width}vw;height: ${height}vw;left: ${x}vw;top: ${y}vw;`;\n container.addEventListener(\n 'click',\n function (event) {\n event.preventDefault();\n showPanel(++mode % container.children.length);\n },\n false,\n );\n\n function addPanel(panel) {\n container.appendChild(panel.dom);\n return panel;\n }\n\n function showPanel(id) {\n for (let i = 0; i < container.children.length; i++) {\n // @ts-ignore\n container.children[i].style.display = i === id ? 'block' : 'none';\n }\n\n mode = id;\n }\n\n let beginTime = (performance || Date).now(),\n prevTime = beginTime,\n frames = 0;\n\n const fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));\n const msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));\n let memPanel;\n // @ts-ignore\n if (self.performance && self.performance.memory) {\n memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));\n }\n\n showPanel(0);\n\n return {\n REVISION: 16,\n\n dom: container,\n\n addPanel: addPanel,\n showPanel: showPanel,\n\n begin: function (time) {\n beginTime = time || (performance || Date).now();\n },\n\n end: function () {\n frames++;\n\n const time = (performance || Date).now();\n\n msPanel.update(time - beginTime, 200);\n\n if (time >= prevTime + 1000) {\n fpsPanel.update((frames * 1000) / (time - prevTime), 100);\n\n prevTime = time;\n frames = 0;\n\n if (memPanel) {\n // @ts-ignore\n const memory = performance.memory;\n memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);\n }\n }\n\n return time;\n },\n\n update: function () {\n beginTime = this.end();\n },\n\n // Backwards Compatibility\n\n domElement: container,\n setMode: showPanel,\n };\n};\n\nStats.Panel = function (name, fg, bg) {\n let min = Infinity,\n max = 0;\n const round = Math.round;\n const PR = round(window.devicePixelRatio || 1);\n\n const WIDTH = 80 * PR,\n HEIGHT = 48 * PR,\n TEXT_X = 3 * PR,\n TEXT_Y = 2 * PR,\n GRAPH_X = 3 * PR,\n GRAPH_Y = 15 * PR,\n GRAPH_WIDTH = 74 * PR,\n GRAPH_HEIGHT = 30 * PR;\n\n const canvas = document.createElement('canvas');\n canvas.width = WIDTH;\n canvas.height = HEIGHT;\n canvas.style.cssText = 'width:100%;height:100%';\n\n const context = canvas.getContext('2d');\n context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';\n context.textBaseline = 'top';\n\n context.fillStyle = bg;\n context.fillRect(0, 0, WIDTH, HEIGHT);\n\n context.fillStyle = fg;\n context.fillText(name, TEXT_X, TEXT_Y);\n context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);\n\n context.fillStyle = bg;\n context.globalAlpha = 0.9;\n context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);\n\n return {\n dom: canvas,\n\n update: function (value, maxValue) {\n min = Math.min(min, value);\n max = Math.max(max, value);\n\n context.fillStyle = bg;\n context.globalAlpha = 1;\n context.fillRect(0, 0, WIDTH, GRAPH_Y);\n context.fillStyle = fg;\n context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);\n\n context.drawImage(\n canvas,\n GRAPH_X + PR,\n GRAPH_Y,\n GRAPH_WIDTH - PR,\n GRAPH_HEIGHT,\n GRAPH_X,\n GRAPH_Y,\n GRAPH_WIDTH - PR,\n GRAPH_HEIGHT,\n );\n\n context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);\n\n context.fillStyle = bg;\n context.globalAlpha = 0.9;\n context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));\n },\n };\n};\n\nexport default Stats;\n","import { System } from '@eva/eva.js';\nimport StatsComponent from './StatsComponent';\nimport Stats from './Stats';\n\ninterface StatsParams {\n show?: boolean;\n style?: {\n width: number;\n height: number;\n x: number;\n y: number;\n };\n}\n\nexport default class StatsSystem extends System {\n static systemName = 'Stats';\n show: boolean = true;\n stats;\n style;\n component: StatsComponent;\n init(param: StatsParams = { show: true }) {\n this.show = param.show;\n this.style = param.style;\n }\n start() {\n if (!this.show) return;\n this.component = this.game.scene.addComponent(new StatsComponent());\n this.stats = Stats(this.style);\n this.component.stats = this.stats;\n this.stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom\n document.body.appendChild(this.stats.dom);\n }\n lateUpdate() {\n if (!this.show) return;\n this.stats && this.stats.end();\n }\n}\n","import Stats from './StatsComponent';\nimport StatsSystem from './StatsSystem';\n\nexport default {\n Components: [Stats],\n Systems: [StatsSystem],\n};\n\nexport { Stats, StatsSystem };\n"],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","hasOwnProperty","__extends","__","this","constructor","prototype","create","__assign","assign","t","s","i","n","arguments","length","call","apply","StatsComponent","stats","begin","Component","Stats","style","width","height","x","y","mode","container","document","createElement","addPanel","panel","appendChild","dom","showPanel","id","children","display","cssText","addEventListener","event","preventDefault","memPanel","beginTime","performance","Date","now","prevTime","frames","fpsPanel","Panel","msPanel","self","memory","REVISION","time","end","update","usedJSHeapSize","jsHeapSizeLimit","domElement","setMode","name","fg","bg","min","Infinity","max","round","Math","PR","window","devicePixelRatio","WIDTH","HEIGHT","TEXT_X","TEXT_Y","GRAPH_X","GRAPH_Y","GRAPH_WIDTH","GRAPH_HEIGHT","canvas","context","getContext","font","textBaseline","fillStyle","fillRect","fillText","globalAlpha","value","maxValue","drawImage","_this","StatsSystem","param","show","component","game","scene","addComponent","body","System","Components","Systems"],"mappings":"4CAgBA,IAAIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB,CAAEC,UAAW,cAAgBC,OAAS,SAAUL,EAAGC,GAAKD,EAAEI,UAAYH,IACvE,SAAUD,EAAGC,GAAK,IAAK,IAAIK,KAAKL,EAAOA,EAAEM,eAAeD,KAAIN,EAAEM,GAAKL,EAAEK,MACpDN,EAAGC,IAGrB,SAASO,EAAUR,EAAGC,GAEzB,SAASQ,IAA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OAEvC6D,uBAAA,WACO5F,KAAK8F,MACV9F,KAAKe,OAASf,KAAKe,MAAMuC,OAnBpBsC,aAAa,WADmBQ,YCX1B,CACbC,WAAY,CAACnF,GACboF,QAAS,CAACV"}
@@ -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;
@@ -193,4 +374,4 @@ var index = {
193
374
 
194
375
  exports.Stats = Stats$2;
195
376
  exports.StatsSystem = StatsSystem$1;
196
- exports["default"] = index;
377
+ exports['default'] = index;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},e(t,n)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,n)};
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,5 @@ 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 n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},o.apply(this,arguments)},i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(t.Component),s=function(t){var e=(t=o({width:20,height:12,x:0,y:0},t)).width,n=t.height,i=t.x,a=t.y,r=0,l=document.createElement("div");function c(t){return l.appendChild(t.dom),t}function p(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";r=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+n+"vw;left: "+i+"vw;top: "+a+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),p(++r%l.children.length)}),!1);var f,h=(performance||Date).now(),u=h,d=0,y=c(s.Panel("FPS","#0ff","#002")),m=c(s.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(f=c(s.Panel("MB","#f08","#201"))),p(0),{REVISION:16,dom:l,addPanel:c,showPanel:p,begin:function(t){h=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-h,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,f)){var e=performance.memory;f.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){h=this.end()},domElement:l,setMode:p}};s.Panel=function(t,e,n){var o=1/0,i=0,s=Math.round,a=s(window.devicePixelRatio||1),r=80*a,l=48*a,c=3*a,p=2*a,f=3*a,h=15*a,u=74*a,d=30*a,y=document.createElement("canvas");y.width=r,y.height=l,y.style.cssText="width:100%;height:100%";var m=y.getContext("2d");return m.font="bold "+9*a+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,r,l),m.fillStyle=e,m.fillText(t,c,p),m.fillRect(f,h,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f,h,u,d),{dom:y,update:function(l,v){o=Math.min(o,l),i=Math.max(i,l),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,r,h),m.fillStyle=e,m.fillText(s(l)+" "+t+" ("+s(o)+"-"+s(i)+")",c,p),m.drawImage(y,f+a,h,u-a,d,f,h,u-a,d),m.fillRect(f+u-a,h,a,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f+u-a,h,a,s((1-l/v)*d))}}};var a=s,r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return n(e,t),e.prototype.init=function(t){void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style},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()},e.systemName="Stats",e}(t.System),l={Components:[i],Systems:[r]};exports.Stats=i,exports.StatsSystem=r,exports.default=l;
15
+ ***************************************************************************** */function n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(t.Component),s=function(t){var e=(t=o({width:20,height:12,x:0,y:0},t)).width,n=t.height,i=t.x,a=t.y,r=0,l=document.createElement("div");function c(t){return l.appendChild(t.dom),t}function p(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";r=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+n+"vw;left: "+i+"vw;top: "+a+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),p(++r%l.children.length)}),!1);var f,h=(performance||Date).now(),u=h,d=0,y=c(s.Panel("FPS","#0ff","#002")),m=c(s.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(f=c(s.Panel("MB","#f08","#201"))),p(0),{REVISION:16,dom:l,addPanel:c,showPanel:p,begin:function(t){h=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-h,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,f)){var e=performance.memory;f.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){h=this.end()},domElement:l,setMode:p}};s.Panel=function(t,e,n){var o=1/0,i=0,s=Math.round,a=s(window.devicePixelRatio||1),r=80*a,l=48*a,c=3*a,p=2*a,f=3*a,h=15*a,u=74*a,d=30*a,y=document.createElement("canvas");y.width=r,y.height=l,y.style.cssText="width:100%;height:100%";var m=y.getContext("2d");return m.font="bold "+9*a+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,r,l),m.fillStyle=e,m.fillText(t,c,p),m.fillRect(f,h,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f,h,u,d),{dom:y,update:function(l,v){o=Math.min(o,l),i=Math.max(i,l),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,r,h),m.fillStyle=e,m.fillText(s(l)+" "+t+" ("+s(o)+"-"+s(i)+")",c,p),m.drawImage(y,f+a,h,u-a,d,f,h,u-a,d),m.fillRect(f+u-a,h,a,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f+u-a,h,a,s((1-l/v)*d))}}};var a=s,r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return n(e,t),e.prototype.init=function(t){void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style},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()},e.systemName="Stats",e}(t.System),l={Components:[i],Systems:[r]};exports.Stats=i,exports.StatsSystem=r,exports.default=l;
16
+ //# sourceMappingURL=plugin-stats.cjs.prod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-stats.cjs.prod.js","sources":["../lib/StatsComponent.ts","../lib/Stats.ts","../lib/StatsSystem.ts","../lib/index.ts"],"sourcesContent":["import { Component } from '@eva/eva.js';\n\nexport default class StatsComponent extends Component {\n static componentName: string = 'Stats';\n stats;\n\n update() {\n this.stats && this.stats.begin();\n }\n}\n","/**\n * @author mrdoob / http://mrdoob.com/\n */\n\nconst Stats = function (style) {\n style = { ...{ width: 20, height: 12, x: 0, y: 0 }, ...style };\n const { width, height, x, y } = style;\n let mode = 0;\n\n const container = document.createElement('div');\n container.style.cssText = `position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: ${width}vw;height: ${height}vw;left: ${x}vw;top: ${y}vw;`;\n container.addEventListener(\n 'click',\n function (event) {\n event.preventDefault();\n showPanel(++mode % container.children.length);\n },\n false,\n );\n\n function addPanel(panel) {\n container.appendChild(panel.dom);\n return panel;\n }\n\n function showPanel(id) {\n for (let i = 0; i < container.children.length; i++) {\n // @ts-ignore\n container.children[i].style.display = i === id ? 'block' : 'none';\n }\n\n mode = id;\n }\n\n let beginTime = (performance || Date).now(),\n prevTime = beginTime,\n frames = 0;\n\n const fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));\n const msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));\n let memPanel;\n // @ts-ignore\n if (self.performance && self.performance.memory) {\n memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));\n }\n\n showPanel(0);\n\n return {\n REVISION: 16,\n\n dom: container,\n\n addPanel: addPanel,\n showPanel: showPanel,\n\n begin: function (time) {\n beginTime = time || (performance || Date).now();\n },\n\n end: function () {\n frames++;\n\n const time = (performance || Date).now();\n\n msPanel.update(time - beginTime, 200);\n\n if (time >= prevTime + 1000) {\n fpsPanel.update((frames * 1000) / (time - prevTime), 100);\n\n prevTime = time;\n frames = 0;\n\n if (memPanel) {\n // @ts-ignore\n const memory = performance.memory;\n memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);\n }\n }\n\n return time;\n },\n\n update: function () {\n beginTime = this.end();\n },\n\n // Backwards Compatibility\n\n domElement: container,\n setMode: showPanel,\n };\n};\n\nStats.Panel = function (name, fg, bg) {\n let min = Infinity,\n max = 0;\n const round = Math.round;\n const PR = round(window.devicePixelRatio || 1);\n\n const WIDTH = 80 * PR,\n HEIGHT = 48 * PR,\n TEXT_X = 3 * PR,\n TEXT_Y = 2 * PR,\n GRAPH_X = 3 * PR,\n GRAPH_Y = 15 * PR,\n GRAPH_WIDTH = 74 * PR,\n GRAPH_HEIGHT = 30 * PR;\n\n const canvas = document.createElement('canvas');\n canvas.width = WIDTH;\n canvas.height = HEIGHT;\n canvas.style.cssText = 'width:100%;height:100%';\n\n const context = canvas.getContext('2d');\n context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';\n context.textBaseline = 'top';\n\n context.fillStyle = bg;\n context.fillRect(0, 0, WIDTH, HEIGHT);\n\n context.fillStyle = fg;\n context.fillText(name, TEXT_X, TEXT_Y);\n context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);\n\n context.fillStyle = bg;\n context.globalAlpha = 0.9;\n context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);\n\n return {\n dom: canvas,\n\n update: function (value, maxValue) {\n min = Math.min(min, value);\n max = Math.max(max, value);\n\n context.fillStyle = bg;\n context.globalAlpha = 1;\n context.fillRect(0, 0, WIDTH, GRAPH_Y);\n context.fillStyle = fg;\n context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);\n\n context.drawImage(\n canvas,\n GRAPH_X + PR,\n GRAPH_Y,\n GRAPH_WIDTH - PR,\n GRAPH_HEIGHT,\n GRAPH_X,\n GRAPH_Y,\n GRAPH_WIDTH - PR,\n GRAPH_HEIGHT,\n );\n\n context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);\n\n context.fillStyle = bg;\n context.globalAlpha = 0.9;\n context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));\n },\n };\n};\n\nexport default Stats;\n","import { System } from '@eva/eva.js';\nimport StatsComponent from './StatsComponent';\nimport Stats from './Stats';\n\ninterface StatsParams {\n show?: boolean;\n style?: {\n width: number;\n height: number;\n x: number;\n y: number;\n };\n}\n\nexport default class StatsSystem extends System {\n static systemName = 'Stats';\n show: boolean = true;\n stats;\n style;\n component: StatsComponent;\n init(param: StatsParams = { show: true }) {\n this.show = param.show;\n this.style = param.style;\n }\n start() {\n if (!this.show) return;\n this.component = this.game.scene.addComponent(new StatsComponent());\n this.stats = Stats(this.style);\n this.component.stats = this.stats;\n this.stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom\n document.body.appendChild(this.stats.dom);\n }\n lateUpdate() {\n if (!this.show) return;\n this.stats && this.stats.end();\n }\n}\n","import Stats from './StatsComponent';\nimport StatsSystem from './StatsSystem';\n\nexport default {\n Components: [Stats],\n Systems: [StatsSystem],\n};\n\nexport { Stats, StatsSystem };\n"],"names":["__extends","StatsComponent","this","stats","begin","Component","Stats","style","width","height","x","y","mode","container","document","createElement","addPanel","panel","appendChild","dom","showPanel","id","i","children","length","display","cssText","addEventListener","event","preventDefault","memPanel","beginTime","performance","Date","now","prevTime","frames","fpsPanel","Panel","msPanel","self","memory","REVISION","time","end","update","usedJSHeapSize","jsHeapSizeLimit","domElement","setMode","name","fg","bg","min","Infinity","max","round","Math","PR","window","devicePixelRatio","WIDTH","HEIGHT","TEXT_X","TEXT_Y","GRAPH_X","GRAPH_Y","GRAPH_WIDTH","GRAPH_HEIGHT","canvas","context","getContext","font","textBaseline","fillStyle","fillRect","fillText","globalAlpha","value","maxValue","drawImage","_this","StatsSystem","param","show","component","game","scene","addComponent","body","System","Components","Systems"],"mappings":";;;;;;;;;;;;;;8aAEA,4DAOA,OAP4CA,OAI1CC,mBAAA,WACEC,KAAKC,OAASD,KAAKC,MAAMC,SAJpBH,gBAAwB,WADWI,aCEtCC,EAAQ,SAAUC,GAEd,IAAAC,GADRD,IAAa,CAAEC,MAAO,GAAIC,OAAQ,GAAIC,EAAG,EAAGC,EAAG,GAAQJ,UACxCE,EAAiBF,SAATG,EAASH,IAANI,EAAMJ,IAC5BK,EAAO,EAELC,EAAYC,SAASC,cAAc,OAWzC,SAASC,EAASC,GAEhB,OADAJ,EAAUK,YAAYD,EAAME,KACrBF,EAGT,SAASG,EAAUC,GACjB,IAAK,IAAIC,EAAI,EAAGA,EAAIT,EAAUU,SAASC,OAAQF,IAE7CT,EAAUU,SAASD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A,SAAKC,gBAAAA,GAAuBC,MAAM,IAChClF,KAAKkF,KAAOD,EAAMC,KAClBlF,KAAKK,MAAQ4E,EAAM5E,OAErB2E,kBAAA,WACOhF,KAAKkF,OACVlF,KAAKmF,UAAYnF,KAAKoF,KAAKC,MAAMC,aAAa,IAAIvF,GAClDC,KAAKC,MAAQG,EAAMJ,KAAKK,OACxBL,KAAKmF,UAAUlF,MAAQD,KAAKC,MAC5BD,KAAKC,MAAMiB,UAAU,GACrBN,SAAS2E,KAAKvE,YAAYhB,KAAKC,MAAMgB,OAEvC+D,uBAAA,WACOhF,KAAKkF,MACVlF,KAAKC,OAASD,KAAKC,MAAMyC,OAnBpBsC,aAAa,WADmBQ,YCX1B,CACbC,WAAY,CAACrF,GACbsF,QAAS,CAACV"}
@@ -0,0 +1,37 @@
1
+ import { Component } from '@eva/eva.js';
2
+ import { System } from '@eva/eva.js';
3
+
4
+ declare const _default: {
5
+ Components: (typeof Stats)[];
6
+ Systems: (typeof StatsSystem)[];
7
+ };
8
+ export default _default;
9
+
10
+ export declare class Stats extends Component {
11
+ static componentName: string;
12
+ stats: any;
13
+ update(): void;
14
+ }
15
+
16
+ declare interface StatsParams {
17
+ show?: boolean;
18
+ style?: {
19
+ width: number;
20
+ height: number;
21
+ x: number;
22
+ y: number;
23
+ };
24
+ }
25
+
26
+ export declare class StatsSystem extends System {
27
+ static systemName: string;
28
+ show: boolean;
29
+ stats: any;
30
+ style: any;
31
+ component: Stats;
32
+ init(param?: StatsParams): void;
33
+ start(): void;
34
+ lateUpdate(): void;
35
+ }
36
+
37
+ export { }
@@ -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.1.1-fix.1",
3
+ "version": "1.1.1-fix.2",
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.1.1-fix.1",
21
+ "@eva/eva.js": "1.1.1-fix.2",
22
22
  "lodash-es": "^4.17.21"
23
23
  }
24
24
  }