@eva/plugin-stats 1.2.7-editor.9 → 1.2.7-fix.4
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 +13 -81
- package/dist/miniprogram.js +337 -0
- package/package.json +2 -2
package/dist/EVA.plugin.stats.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
window.EVA = window.EVA || {};
|
|
2
2
|
window.EVA.plugin = window.EVA.plugin || {};
|
|
3
|
-
|
|
4
3
|
var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
5
4
|
'use strict';
|
|
6
5
|
|
|
@@ -14,53 +13,39 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
14
13
|
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
|
-
|
|
18
16
|
return _extendStatics(d, b);
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
function __extends(d, b) {
|
|
22
19
|
_extendStatics(d, b);
|
|
23
|
-
|
|
24
20
|
function __() {
|
|
25
21
|
this.constructor = d;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
var _assign = function __assign() {
|
|
32
26
|
_assign = Object.assign || function __assign(t) {
|
|
33
27
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
28
|
s = arguments[i];
|
|
35
|
-
|
|
36
29
|
for (var p in s) {
|
|
37
30
|
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
return t;
|
|
42
34
|
};
|
|
43
|
-
|
|
44
35
|
return _assign.apply(this, arguments);
|
|
45
36
|
};
|
|
46
|
-
|
|
47
37
|
var StatsComponent = function (_super) {
|
|
48
38
|
__extends(StatsComponent, _super);
|
|
49
|
-
|
|
50
39
|
function StatsComponent() {
|
|
51
40
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
42
|
StatsComponent.prototype.update = function () {
|
|
55
43
|
this.stats && this.stats.begin();
|
|
56
44
|
};
|
|
57
|
-
|
|
58
45
|
StatsComponent.componentName = 'Stats';
|
|
59
46
|
return StatsComponent;
|
|
60
47
|
}(eva_js.Component);
|
|
61
|
-
|
|
62
48
|
var Stats$2 = StatsComponent;
|
|
63
|
-
|
|
64
49
|
var Stats = function Stats(style) {
|
|
65
50
|
style = _assign({
|
|
66
51
|
width: 20,
|
|
@@ -69,9 +54,9 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
69
54
|
y: 0
|
|
70
55
|
}, style);
|
|
71
56
|
var width = style.width,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
height = style.height,
|
|
58
|
+
x = style.x,
|
|
59
|
+
y = style.y;
|
|
75
60
|
var mode = 0;
|
|
76
61
|
var container = document.createElement('div');
|
|
77
62
|
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;";
|
|
@@ -79,33 +64,27 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
79
64
|
event.preventDefault();
|
|
80
65
|
showPanel(++mode % container.children.length);
|
|
81
66
|
}, false);
|
|
82
|
-
|
|
83
67
|
function addPanel(panel) {
|
|
84
68
|
container.appendChild(panel.dom);
|
|
85
69
|
return panel;
|
|
86
70
|
}
|
|
87
|
-
|
|
88
71
|
function showPanel(id) {
|
|
89
72
|
for (var i = 0; i < container.children.length; i++) {
|
|
90
73
|
container.children[i].style.display = i === id ? 'block' : 'none';
|
|
91
74
|
}
|
|
92
|
-
|
|
93
75
|
mode = id;
|
|
94
76
|
}
|
|
95
|
-
|
|
96
77
|
var beginTime = (performance || Date).now(),
|
|
97
|
-
|
|
98
|
-
|
|
78
|
+
prevTime = beginTime,
|
|
79
|
+
frames = 0;
|
|
99
80
|
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
100
81
|
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
101
82
|
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
102
83
|
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
103
84
|
var memPanel;
|
|
104
|
-
|
|
105
85
|
if (self.performance && self.performance.memory) {
|
|
106
86
|
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
107
87
|
}
|
|
108
|
-
|
|
109
88
|
showPanel(0);
|
|
110
89
|
return {
|
|
111
90
|
REVISION: 16,
|
|
@@ -119,23 +98,19 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
119
98
|
frames++;
|
|
120
99
|
var time = (performance || Date).now();
|
|
121
100
|
msPanel.update(time - beginTime, 200);
|
|
122
|
-
|
|
123
101
|
if (hook) {
|
|
124
102
|
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
125
103
|
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
126
104
|
}
|
|
127
|
-
|
|
128
105
|
if (time >= prevTime + 1000) {
|
|
129
106
|
fpsPanel.update(frames * 1000 / (time - prevTime), 100);
|
|
130
107
|
prevTime = time;
|
|
131
108
|
frames = 0;
|
|
132
|
-
|
|
133
109
|
if (memPanel) {
|
|
134
110
|
var memory = performance.memory;
|
|
135
111
|
memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
|
|
136
112
|
}
|
|
137
113
|
}
|
|
138
|
-
|
|
139
114
|
return time;
|
|
140
115
|
},
|
|
141
116
|
update: function update() {
|
|
@@ -145,20 +120,19 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
145
120
|
setMode: showPanel
|
|
146
121
|
};
|
|
147
122
|
};
|
|
148
|
-
|
|
149
123
|
Stats.Panel = function (name, fg, bg) {
|
|
150
124
|
var min = Infinity,
|
|
151
|
-
|
|
125
|
+
max = 0;
|
|
152
126
|
var round = Math.round;
|
|
153
127
|
var PR = round(window.devicePixelRatio || 1);
|
|
154
128
|
var WIDTH = 80 * PR,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
129
|
+
HEIGHT = 48 * PR,
|
|
130
|
+
TEXT_X = 3 * PR,
|
|
131
|
+
TEXT_Y = 2 * PR,
|
|
132
|
+
GRAPH_X = 3 * PR,
|
|
133
|
+
GRAPH_Y = 15 * PR,
|
|
134
|
+
GRAPH_WIDTH = 74 * PR,
|
|
135
|
+
GRAPH_HEIGHT = 30 * PR;
|
|
162
136
|
var canvas = document.createElement('canvas');
|
|
163
137
|
canvas.width = WIDTH;
|
|
164
138
|
canvas.height = HEIGHT;
|
|
@@ -192,16 +166,12 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
192
166
|
}
|
|
193
167
|
};
|
|
194
168
|
};
|
|
195
|
-
|
|
196
169
|
var Stats$1 = Stats;
|
|
197
|
-
|
|
198
170
|
var GLHook = function () {
|
|
199
171
|
function GLHook(_gl) {
|
|
200
172
|
this.drawPasses = 0;
|
|
201
173
|
this.isInit = false;
|
|
202
|
-
|
|
203
174
|
this.realGLDrawElements = function () {};
|
|
204
|
-
|
|
205
175
|
if (_gl) {
|
|
206
176
|
if (_gl.__proto__.drawElements) {
|
|
207
177
|
this.gl = _gl;
|
|
@@ -213,37 +183,28 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
213
183
|
console.error("[GLHook] GL can't be NULL");
|
|
214
184
|
}
|
|
215
185
|
}
|
|
216
|
-
|
|
217
186
|
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
218
187
|
this.drawPasses++;
|
|
219
188
|
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
220
189
|
};
|
|
221
|
-
|
|
222
190
|
GLHook.prototype.reset = function () {
|
|
223
191
|
this.drawPasses = 0;
|
|
224
192
|
};
|
|
225
|
-
|
|
226
193
|
GLHook.prototype.release = function () {
|
|
227
194
|
if (this.isInit) {
|
|
228
195
|
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
229
196
|
}
|
|
230
|
-
|
|
231
197
|
this.isInit = false;
|
|
232
198
|
};
|
|
233
|
-
|
|
234
199
|
return GLHook;
|
|
235
200
|
}();
|
|
236
|
-
|
|
237
201
|
var TextureHook = function () {
|
|
238
202
|
function TextureHook(_gl) {
|
|
239
203
|
this.createdTextures = new Array();
|
|
240
204
|
this.maxTexturesCount = 0;
|
|
241
205
|
this.isInit = false;
|
|
242
|
-
|
|
243
206
|
this.realGLCreateTexture = function () {};
|
|
244
|
-
|
|
245
207
|
this.realGLDeleteTexture = function () {};
|
|
246
|
-
|
|
247
208
|
if (_gl) {
|
|
248
209
|
if (_gl.__proto__.createTexture) {
|
|
249
210
|
this.gl = _gl;
|
|
@@ -257,7 +218,6 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
257
218
|
console.error("[TextureHook] GL can't be NULL");
|
|
258
219
|
}
|
|
259
220
|
}
|
|
260
|
-
|
|
261
221
|
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
262
222
|
get: function get() {
|
|
263
223
|
return this.createdTextures.length;
|
|
@@ -265,63 +225,50 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
265
225
|
enumerable: false,
|
|
266
226
|
configurable: true
|
|
267
227
|
});
|
|
268
|
-
|
|
269
228
|
TextureHook.prototype.registerTexture = function (texture) {
|
|
270
229
|
this.createdTextures.push(texture);
|
|
271
230
|
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
272
231
|
};
|
|
273
|
-
|
|
274
232
|
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
275
233
|
var texture = this.realGLCreateTexture.call(this.gl);
|
|
276
234
|
this.registerTexture(texture);
|
|
277
235
|
return texture;
|
|
278
236
|
};
|
|
279
|
-
|
|
280
237
|
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
281
238
|
var index = this.createdTextures.indexOf(texture);
|
|
282
|
-
|
|
283
239
|
if (index > -1) {
|
|
284
240
|
this.createdTextures.splice(index, 1);
|
|
285
241
|
}
|
|
286
|
-
|
|
287
242
|
this.realGLDeleteTexture.call(this.gl, texture);
|
|
288
243
|
};
|
|
289
|
-
|
|
290
244
|
TextureHook.prototype.reset = function () {
|
|
291
245
|
this.createdTextures = new Array();
|
|
292
246
|
this.maxTexturesCount = 0;
|
|
293
247
|
};
|
|
294
|
-
|
|
295
248
|
TextureHook.prototype.release = function () {
|
|
296
249
|
if (this.isInit) {
|
|
297
250
|
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
298
251
|
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
299
252
|
console.log('[TextureHook] Hook was removed!');
|
|
300
253
|
}
|
|
301
|
-
|
|
302
254
|
this.isInit = false;
|
|
303
255
|
};
|
|
304
|
-
|
|
305
256
|
return TextureHook;
|
|
306
257
|
}();
|
|
307
|
-
|
|
308
258
|
var BaseHooks = function () {
|
|
309
259
|
function BaseHooks() {
|
|
310
260
|
this._drawCalls = -1;
|
|
311
261
|
this._maxDeltaDrawCalls = -1;
|
|
312
262
|
}
|
|
313
|
-
|
|
314
263
|
BaseHooks.prototype.attach = function (gl) {
|
|
315
264
|
this.glhook = new GLHook(gl);
|
|
316
265
|
this.texturehook = new TextureHook(gl);
|
|
317
266
|
};
|
|
318
|
-
|
|
319
267
|
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
320
268
|
get: function get() {
|
|
321
269
|
if (this.glhook && this.glhook.isInit) {
|
|
322
270
|
return this.glhook.drawPasses;
|
|
323
271
|
}
|
|
324
|
-
|
|
325
272
|
return -1;
|
|
326
273
|
},
|
|
327
274
|
enumerable: false,
|
|
@@ -340,7 +287,6 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
340
287
|
this._drawCalls = this.drawCalls;
|
|
341
288
|
return 0;
|
|
342
289
|
}
|
|
343
|
-
|
|
344
290
|
var dc = this.drawCalls;
|
|
345
291
|
var delta = dc - this._drawCalls;
|
|
346
292
|
this._drawCalls = dc;
|
|
@@ -366,51 +312,41 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
366
312
|
enumerable: false,
|
|
367
313
|
configurable: true
|
|
368
314
|
});
|
|
369
|
-
|
|
370
315
|
BaseHooks.prototype.reset = function () {
|
|
371
316
|
this._maxDeltaDrawCalls = -1;
|
|
372
317
|
this._drawCalls = -1;
|
|
373
318
|
if (this.glhook) this.glhook.reset();
|
|
374
319
|
if (this.texturehook) this.texturehook.reset();
|
|
375
320
|
};
|
|
376
|
-
|
|
377
321
|
BaseHooks.prototype.release = function () {
|
|
378
322
|
if (this.glhook) this.glhook.release();
|
|
379
323
|
if (this.texturehook) this.texturehook.release();
|
|
380
324
|
};
|
|
381
|
-
|
|
382
325
|
return BaseHooks;
|
|
383
326
|
}();
|
|
384
|
-
|
|
385
327
|
var StatsSystem = function (_super) {
|
|
386
328
|
__extends(StatsSystem, _super);
|
|
387
|
-
|
|
388
329
|
function StatsSystem() {
|
|
389
330
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
390
|
-
|
|
391
331
|
_this.show = true;
|
|
392
332
|
return _this;
|
|
393
333
|
}
|
|
394
|
-
|
|
395
334
|
StatsSystem.prototype.init = function (param) {
|
|
396
335
|
if (param === void 0) {
|
|
397
336
|
param = {
|
|
398
337
|
show: true
|
|
399
338
|
};
|
|
400
339
|
}
|
|
401
|
-
|
|
402
340
|
this.show = param.show;
|
|
403
341
|
this.style = param.style;
|
|
404
342
|
this.renderSystem = this.game.getSystem('Renderer');
|
|
405
343
|
this.app = this.renderSystem.application;
|
|
406
|
-
|
|
407
344
|
if (this.app && this.show) {
|
|
408
345
|
var gl = this.app.renderer.gl;
|
|
409
346
|
this.hook = new BaseHooks();
|
|
410
347
|
this.hook.attach(gl);
|
|
411
348
|
}
|
|
412
349
|
};
|
|
413
|
-
|
|
414
350
|
StatsSystem.prototype.start = function () {
|
|
415
351
|
if (!this.show) return;
|
|
416
352
|
this.component = this.game.scene.addComponent(new Stats$2());
|
|
@@ -419,16 +355,13 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
419
355
|
this.stats.showPanel(0);
|
|
420
356
|
document.body.appendChild(this.stats.dom);
|
|
421
357
|
};
|
|
422
|
-
|
|
423
358
|
StatsSystem.prototype.lateUpdate = function () {
|
|
424
359
|
if (!this.show) return;
|
|
425
360
|
this.stats && this.stats.end(this.hook);
|
|
426
361
|
};
|
|
427
|
-
|
|
428
362
|
StatsSystem.systemName = 'Stats';
|
|
429
363
|
return StatsSystem;
|
|
430
364
|
}(eva_js.System);
|
|
431
|
-
|
|
432
365
|
var StatsSystem$1 = StatsSystem;
|
|
433
366
|
var index = {
|
|
434
367
|
Components: [Stats$2],
|
|
@@ -442,5 +375,4 @@ var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
|
442
375
|
});
|
|
443
376
|
return exports;
|
|
444
377
|
}({}, EVA);
|
|
445
|
-
|
|
446
378
|
window.EVA.plugin.stats = window.EVA.plugin.stats || _EVA_IIFE_stats;
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { __extends, __assign } from 'tslib';
|
|
2
|
+
import { Component, System } from '@eva/eva.js/dist/miniprogram';
|
|
3
|
+
import { documentAlias, performance, windowAlias } from '@eva/miniprogram-adapter';
|
|
4
|
+
var StatsComponent = function (_super) {
|
|
5
|
+
__extends(StatsComponent, _super);
|
|
6
|
+
function StatsComponent() {
|
|
7
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
8
|
+
}
|
|
9
|
+
StatsComponent.prototype.update = function () {
|
|
10
|
+
this.stats && this.stats.begin();
|
|
11
|
+
};
|
|
12
|
+
StatsComponent.componentName = 'Stats';
|
|
13
|
+
return StatsComponent;
|
|
14
|
+
}(Component);
|
|
15
|
+
var Stats$2 = StatsComponent;
|
|
16
|
+
var Stats = function Stats(style) {
|
|
17
|
+
style = __assign({
|
|
18
|
+
width: 20,
|
|
19
|
+
height: 12,
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0
|
|
22
|
+
}, style);
|
|
23
|
+
var width = style.width,
|
|
24
|
+
height = style.height,
|
|
25
|
+
x = style.x,
|
|
26
|
+
y = style.y;
|
|
27
|
+
var mode = 0;
|
|
28
|
+
var container = documentAlias.createElement('div');
|
|
29
|
+
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;";
|
|
30
|
+
container.addEventListener('click', function (event) {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
showPanel(++mode % container.children.length);
|
|
33
|
+
}, false);
|
|
34
|
+
function addPanel(panel) {
|
|
35
|
+
container.appendChild(panel.dom);
|
|
36
|
+
return panel;
|
|
37
|
+
}
|
|
38
|
+
function showPanel(id) {
|
|
39
|
+
for (var i = 0; i < container.children.length; i++) {
|
|
40
|
+
container.children[i].style.display = i === id ? 'block' : 'none';
|
|
41
|
+
}
|
|
42
|
+
mode = id;
|
|
43
|
+
}
|
|
44
|
+
var beginTime = (performance || Date).now(),
|
|
45
|
+
prevTime = beginTime,
|
|
46
|
+
frames = 0;
|
|
47
|
+
var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
48
|
+
var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
49
|
+
var dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
50
|
+
var tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
51
|
+
var memPanel;
|
|
52
|
+
if (self.performance && self.performance.memory) {
|
|
53
|
+
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
54
|
+
}
|
|
55
|
+
showPanel(0);
|
|
56
|
+
return {
|
|
57
|
+
REVISION: 16,
|
|
58
|
+
dom: container,
|
|
59
|
+
addPanel: addPanel,
|
|
60
|
+
showPanel: showPanel,
|
|
61
|
+
begin: function begin(time) {
|
|
62
|
+
beginTime = time || (performance || Date).now();
|
|
63
|
+
},
|
|
64
|
+
end: function end(hook) {
|
|
65
|
+
frames++;
|
|
66
|
+
var time = (performance || Date).now();
|
|
67
|
+
msPanel.update(time - beginTime, 200);
|
|
68
|
+
if (hook) {
|
|
69
|
+
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
70
|
+
tcPanel.update(hook.texturesCount, Math.max(20, hook.maxTextureCount));
|
|
71
|
+
}
|
|
72
|
+
if (time >= prevTime + 1000) {
|
|
73
|
+
fpsPanel.update(frames * 1000 / (time - prevTime), 100);
|
|
74
|
+
prevTime = time;
|
|
75
|
+
frames = 0;
|
|
76
|
+
if (memPanel) {
|
|
77
|
+
var memory = performance.memory;
|
|
78
|
+
memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return time;
|
|
82
|
+
},
|
|
83
|
+
update: function update() {
|
|
84
|
+
beginTime = this.end();
|
|
85
|
+
},
|
|
86
|
+
domElement: container,
|
|
87
|
+
setMode: showPanel
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
Stats.Panel = function (name, fg, bg) {
|
|
91
|
+
var min = Infinity,
|
|
92
|
+
max = 0;
|
|
93
|
+
var round = Math.round;
|
|
94
|
+
var PR = round(windowAlias.devicePixelRatio || 1);
|
|
95
|
+
var WIDTH = 80 * PR,
|
|
96
|
+
HEIGHT = 48 * PR,
|
|
97
|
+
TEXT_X = 3 * PR,
|
|
98
|
+
TEXT_Y = 2 * PR,
|
|
99
|
+
GRAPH_X = 3 * PR,
|
|
100
|
+
GRAPH_Y = 15 * PR,
|
|
101
|
+
GRAPH_WIDTH = 74 * PR,
|
|
102
|
+
GRAPH_HEIGHT = 30 * PR;
|
|
103
|
+
var canvas = documentAlias.createElement('canvas');
|
|
104
|
+
canvas.width = WIDTH;
|
|
105
|
+
canvas.height = HEIGHT;
|
|
106
|
+
canvas.style.cssText = 'width:100%;height:100%';
|
|
107
|
+
var context = canvas.getContext('2d');
|
|
108
|
+
context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';
|
|
109
|
+
context.textBaseline = 'top';
|
|
110
|
+
context.fillStyle = bg;
|
|
111
|
+
context.fillRect(0, 0, WIDTH, HEIGHT);
|
|
112
|
+
context.fillStyle = fg;
|
|
113
|
+
context.fillText(name, TEXT_X, TEXT_Y);
|
|
114
|
+
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
115
|
+
context.fillStyle = bg;
|
|
116
|
+
context.globalAlpha = 0.9;
|
|
117
|
+
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
118
|
+
return {
|
|
119
|
+
dom: canvas,
|
|
120
|
+
update: function update(value, maxValue) {
|
|
121
|
+
min = Math.min(min, value);
|
|
122
|
+
max = Math.max(max, value);
|
|
123
|
+
context.fillStyle = bg;
|
|
124
|
+
context.globalAlpha = 1;
|
|
125
|
+
context.fillRect(0, 0, WIDTH, GRAPH_Y);
|
|
126
|
+
context.fillStyle = fg;
|
|
127
|
+
context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);
|
|
128
|
+
context.drawImage(canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT);
|
|
129
|
+
context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);
|
|
130
|
+
context.fillStyle = bg;
|
|
131
|
+
context.globalAlpha = 0.9;
|
|
132
|
+
context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
var Stats$1 = Stats;
|
|
137
|
+
var GLHook = function () {
|
|
138
|
+
function GLHook(_gl) {
|
|
139
|
+
this.drawPasses = 0;
|
|
140
|
+
this.isInit = false;
|
|
141
|
+
this.realGLDrawElements = function () {};
|
|
142
|
+
if (_gl) {
|
|
143
|
+
if (_gl.__proto__.drawElements) {
|
|
144
|
+
this.gl = _gl;
|
|
145
|
+
this.realGLDrawElements = _gl.__proto__.drawElements;
|
|
146
|
+
_gl.__proto__.drawElements = this.fakeGLdrawElements.bind(this);
|
|
147
|
+
this.isInit = true;
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
console.error("[GLHook] GL can't be NULL");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
GLHook.prototype.fakeGLdrawElements = function (mode, count, type, offset) {
|
|
154
|
+
this.drawPasses++;
|
|
155
|
+
this.realGLDrawElements.call(this.gl, mode, count, type, offset);
|
|
156
|
+
};
|
|
157
|
+
GLHook.prototype.reset = function () {
|
|
158
|
+
this.drawPasses = 0;
|
|
159
|
+
};
|
|
160
|
+
GLHook.prototype.release = function () {
|
|
161
|
+
if (this.isInit) {
|
|
162
|
+
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
163
|
+
}
|
|
164
|
+
this.isInit = false;
|
|
165
|
+
};
|
|
166
|
+
return GLHook;
|
|
167
|
+
}();
|
|
168
|
+
var TextureHook = function () {
|
|
169
|
+
function TextureHook(_gl) {
|
|
170
|
+
this.createdTextures = new Array();
|
|
171
|
+
this.maxTexturesCount = 0;
|
|
172
|
+
this.isInit = false;
|
|
173
|
+
this.realGLCreateTexture = function () {};
|
|
174
|
+
this.realGLDeleteTexture = function () {};
|
|
175
|
+
if (_gl) {
|
|
176
|
+
if (_gl.__proto__.createTexture) {
|
|
177
|
+
this.gl = _gl;
|
|
178
|
+
this.realGLCreateTexture = _gl.__proto__.createTexture;
|
|
179
|
+
this.realGLDeleteTexture = _gl.__proto__.deleteTexture;
|
|
180
|
+
_gl.__proto__.createTexture = this.fakeGLCreateTexture.bind(this);
|
|
181
|
+
_gl.__proto__.deleteTexture = this.fakeGLDeleteTexture.bind(this);
|
|
182
|
+
this.isInit = true;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
console.error("[TextureHook] GL can't be NULL");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
Object.defineProperty(TextureHook.prototype, "currentTextureCount", {
|
|
189
|
+
get: function get() {
|
|
190
|
+
return this.createdTextures.length;
|
|
191
|
+
},
|
|
192
|
+
enumerable: false,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
TextureHook.prototype.registerTexture = function (texture) {
|
|
196
|
+
this.createdTextures.push(texture);
|
|
197
|
+
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
198
|
+
};
|
|
199
|
+
TextureHook.prototype.fakeGLCreateTexture = function () {
|
|
200
|
+
var texture = this.realGLCreateTexture.call(this.gl);
|
|
201
|
+
this.registerTexture(texture);
|
|
202
|
+
return texture;
|
|
203
|
+
};
|
|
204
|
+
TextureHook.prototype.fakeGLDeleteTexture = function (texture) {
|
|
205
|
+
var index = this.createdTextures.indexOf(texture);
|
|
206
|
+
if (index > -1) {
|
|
207
|
+
this.createdTextures.splice(index, 1);
|
|
208
|
+
}
|
|
209
|
+
this.realGLDeleteTexture.call(this.gl, texture);
|
|
210
|
+
};
|
|
211
|
+
TextureHook.prototype.reset = function () {
|
|
212
|
+
this.createdTextures = new Array();
|
|
213
|
+
this.maxTexturesCount = 0;
|
|
214
|
+
};
|
|
215
|
+
TextureHook.prototype.release = function () {
|
|
216
|
+
if (this.isInit) {
|
|
217
|
+
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
218
|
+
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
219
|
+
console.log('[TextureHook] Hook was removed!');
|
|
220
|
+
}
|
|
221
|
+
this.isInit = false;
|
|
222
|
+
};
|
|
223
|
+
return TextureHook;
|
|
224
|
+
}();
|
|
225
|
+
var BaseHooks = function () {
|
|
226
|
+
function BaseHooks() {
|
|
227
|
+
this._drawCalls = -1;
|
|
228
|
+
this._maxDeltaDrawCalls = -1;
|
|
229
|
+
}
|
|
230
|
+
BaseHooks.prototype.attach = function (gl) {
|
|
231
|
+
this.glhook = new GLHook(gl);
|
|
232
|
+
this.texturehook = new TextureHook(gl);
|
|
233
|
+
};
|
|
234
|
+
Object.defineProperty(BaseHooks.prototype, "drawCalls", {
|
|
235
|
+
get: function get() {
|
|
236
|
+
if (this.glhook && this.glhook.isInit) {
|
|
237
|
+
return this.glhook.drawPasses;
|
|
238
|
+
}
|
|
239
|
+
return -1;
|
|
240
|
+
},
|
|
241
|
+
enumerable: false,
|
|
242
|
+
configurable: true
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(BaseHooks.prototype, "maxDeltaDrawCalls", {
|
|
245
|
+
get: function get() {
|
|
246
|
+
return this._maxDeltaDrawCalls;
|
|
247
|
+
},
|
|
248
|
+
enumerable: false,
|
|
249
|
+
configurable: true
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
252
|
+
get: function get() {
|
|
253
|
+
if (this._drawCalls == -1) {
|
|
254
|
+
this._drawCalls = this.drawCalls;
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
var dc = this.drawCalls;
|
|
258
|
+
var delta = dc - this._drawCalls;
|
|
259
|
+
this._drawCalls = dc;
|
|
260
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
261
|
+
return delta;
|
|
262
|
+
},
|
|
263
|
+
enumerable: false,
|
|
264
|
+
configurable: true
|
|
265
|
+
});
|
|
266
|
+
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
267
|
+
get: function get() {
|
|
268
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.maxTexturesCount;
|
|
269
|
+
return 0;
|
|
270
|
+
},
|
|
271
|
+
enumerable: false,
|
|
272
|
+
configurable: true
|
|
273
|
+
});
|
|
274
|
+
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
275
|
+
get: function get() {
|
|
276
|
+
if (this.texturehook && this.texturehook.isInit) return this.texturehook.currentTextureCount;
|
|
277
|
+
return 0;
|
|
278
|
+
},
|
|
279
|
+
enumerable: false,
|
|
280
|
+
configurable: true
|
|
281
|
+
});
|
|
282
|
+
BaseHooks.prototype.reset = function () {
|
|
283
|
+
this._maxDeltaDrawCalls = -1;
|
|
284
|
+
this._drawCalls = -1;
|
|
285
|
+
if (this.glhook) this.glhook.reset();
|
|
286
|
+
if (this.texturehook) this.texturehook.reset();
|
|
287
|
+
};
|
|
288
|
+
BaseHooks.prototype.release = function () {
|
|
289
|
+
if (this.glhook) this.glhook.release();
|
|
290
|
+
if (this.texturehook) this.texturehook.release();
|
|
291
|
+
};
|
|
292
|
+
return BaseHooks;
|
|
293
|
+
}();
|
|
294
|
+
var StatsSystem = function (_super) {
|
|
295
|
+
__extends(StatsSystem, _super);
|
|
296
|
+
function StatsSystem() {
|
|
297
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
298
|
+
_this.show = true;
|
|
299
|
+
return _this;
|
|
300
|
+
}
|
|
301
|
+
StatsSystem.prototype.init = function (param) {
|
|
302
|
+
if (param === void 0) {
|
|
303
|
+
param = {
|
|
304
|
+
show: true
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
this.show = param.show;
|
|
308
|
+
this.style = param.style;
|
|
309
|
+
this.renderSystem = this.game.getSystem('Renderer');
|
|
310
|
+
this.app = this.renderSystem.application;
|
|
311
|
+
if (this.app && this.show) {
|
|
312
|
+
var gl = this.app.renderer.gl;
|
|
313
|
+
this.hook = new BaseHooks();
|
|
314
|
+
this.hook.attach(gl);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
StatsSystem.prototype.start = function () {
|
|
318
|
+
if (!this.show) return;
|
|
319
|
+
this.component = this.game.scene.addComponent(new Stats$2());
|
|
320
|
+
this.stats = Stats$1(this.style);
|
|
321
|
+
this.component.stats = this.stats;
|
|
322
|
+
this.stats.showPanel(0);
|
|
323
|
+
documentAlias.body.appendChild(this.stats.dom);
|
|
324
|
+
};
|
|
325
|
+
StatsSystem.prototype.lateUpdate = function () {
|
|
326
|
+
if (!this.show) return;
|
|
327
|
+
this.stats && this.stats.end(this.hook);
|
|
328
|
+
};
|
|
329
|
+
StatsSystem.systemName = 'Stats';
|
|
330
|
+
return StatsSystem;
|
|
331
|
+
}(System);
|
|
332
|
+
var StatsSystem$1 = StatsSystem;
|
|
333
|
+
var index = {
|
|
334
|
+
Components: [Stats$2],
|
|
335
|
+
Systems: [StatsSystem$1]
|
|
336
|
+
};
|
|
337
|
+
export { Stats$2 as Stats, StatsSystem$1 as StatsSystem, index as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-stats",
|
|
3
|
-
"version": "1.2.7-
|
|
3
|
+
"version": "1.2.7-fix.4",
|
|
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.7-
|
|
21
|
+
"@eva/eva.js": "1.2.7-fix.4",
|
|
22
22
|
"lodash-es": "^4.17.21"
|
|
23
23
|
}
|
|
24
24
|
}
|