@eva/plugin-stats 2.0.0-beta.1 → 2.0.0-beta.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.
- package/dist/EVA.plugin.stats.js +113 -176
- package/dist/EVA.plugin.stats.min.js +1 -1
- package/dist/plugin-stats.cjs.js +107 -185
- package/dist/plugin-stats.cjs.prod.js +1 -15
- package/dist/plugin-stats.esm.js +106 -184
- package/package.json +2 -2
package/dist/plugin-stats.cjs.js
CHANGED
|
@@ -4,65 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var eva_js = require('@eva/eva.js');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
19
|
-
and limitations under the License.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise */
|
|
22
|
-
|
|
23
|
-
var extendStatics = function(d, b) {
|
|
24
|
-
extendStatics = Object.setPrototypeOf ||
|
|
25
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
27
|
-
return extendStatics(d, b);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function __extends(d, b) {
|
|
31
|
-
extendStatics(d, b);
|
|
32
|
-
function __() { this.constructor = d; }
|
|
33
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var __assign = function() {
|
|
37
|
-
__assign = Object.assign || function __assign(t) {
|
|
38
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
-
s = arguments[i];
|
|
40
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
-
}
|
|
42
|
-
return t;
|
|
43
|
-
};
|
|
44
|
-
return __assign.apply(this, arguments);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
var StatsComponent = (function (_super) {
|
|
48
|
-
__extends(StatsComponent, _super);
|
|
49
|
-
function StatsComponent() {
|
|
50
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
51
|
-
}
|
|
52
|
-
StatsComponent.prototype.update = function () {
|
|
7
|
+
class StatsComponent extends eva_js.Component {
|
|
8
|
+
update() {
|
|
53
9
|
this.stats && this.stats.begin();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}(eva_js.Component));
|
|
58
|
-
var Stats$2 = StatsComponent;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
StatsComponent.componentName = 'Stats';
|
|
59
13
|
|
|
60
|
-
|
|
61
|
-
style =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
container.style.cssText =
|
|
14
|
+
const Stats = function (style) {
|
|
15
|
+
style = Object.assign({ width: 20, height: 12, x: 0, y: 0 }, style);
|
|
16
|
+
const { width, height, x, y } = style;
|
|
17
|
+
let mode = 0;
|
|
18
|
+
const container = document.createElement('div');
|
|
19
|
+
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;`;
|
|
66
20
|
container.addEventListener('click', function (event) {
|
|
67
21
|
event.preventDefault();
|
|
68
22
|
showPanel(++mode % container.children.length);
|
|
@@ -72,17 +26,17 @@ var Stats = function (style) {
|
|
|
72
26
|
return panel;
|
|
73
27
|
}
|
|
74
28
|
function showPanel(id) {
|
|
75
|
-
for (
|
|
29
|
+
for (let i = 0; i < container.children.length; i++) {
|
|
76
30
|
container.children[i].style.display = i === id ? 'block' : 'none';
|
|
77
31
|
}
|
|
78
32
|
mode = id;
|
|
79
33
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
34
|
+
let beginTime = (performance || Date).now(), prevTime = beginTime, frames = 0;
|
|
35
|
+
const fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
|
|
36
|
+
const msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
|
|
37
|
+
const dcPanel = addPanel(Stats.Panel('DrawCall', '#330570', '#A69700'));
|
|
38
|
+
const tcPanel = addPanel(Stats.Panel('TC:', '#A62500', '#00B454'));
|
|
39
|
+
let memPanel;
|
|
86
40
|
if (self.performance && self.performance.memory) {
|
|
87
41
|
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
88
42
|
}
|
|
@@ -97,7 +51,7 @@ var Stats = function (style) {
|
|
|
97
51
|
},
|
|
98
52
|
end: function (hook) {
|
|
99
53
|
frames++;
|
|
100
|
-
|
|
54
|
+
const time = (performance || Date).now();
|
|
101
55
|
msPanel.update(time - beginTime, 200);
|
|
102
56
|
if (hook) {
|
|
103
57
|
dcPanel.update(hook.deltaDrawCalls, Math.max(50, hook.maxDeltaDrawCalls));
|
|
@@ -108,7 +62,7 @@ var Stats = function (style) {
|
|
|
108
62
|
prevTime = time;
|
|
109
63
|
frames = 0;
|
|
110
64
|
if (memPanel) {
|
|
111
|
-
|
|
65
|
+
const memory = performance.memory;
|
|
112
66
|
memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
|
|
113
67
|
}
|
|
114
68
|
}
|
|
@@ -122,15 +76,15 @@ var Stats = function (style) {
|
|
|
122
76
|
};
|
|
123
77
|
};
|
|
124
78
|
Stats.Panel = function (name, fg, bg) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
79
|
+
let min = Infinity, max = 0;
|
|
80
|
+
const round = Math.round;
|
|
81
|
+
const PR = round(window.devicePixelRatio || 1);
|
|
82
|
+
const WIDTH = 80 * PR, HEIGHT = 48 * PR, TEXT_X = 3 * PR, TEXT_Y = 2 * PR, GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR, GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR;
|
|
83
|
+
const canvas = document.createElement('canvas');
|
|
130
84
|
canvas.width = WIDTH;
|
|
131
85
|
canvas.height = HEIGHT;
|
|
132
86
|
canvas.style.cssText = 'width:100%;height:100%';
|
|
133
|
-
|
|
87
|
+
const context = canvas.getContext('2d');
|
|
134
88
|
context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';
|
|
135
89
|
context.textBaseline = 'top';
|
|
136
90
|
context.fillStyle = bg;
|
|
@@ -161,8 +115,8 @@ Stats.Panel = function (name, fg, bg) {
|
|
|
161
115
|
};
|
|
162
116
|
var Stats$1 = Stats;
|
|
163
117
|
|
|
164
|
-
|
|
165
|
-
|
|
118
|
+
class GLHook {
|
|
119
|
+
constructor(_gl) {
|
|
166
120
|
this.drawPasses = 0;
|
|
167
121
|
this.isInit = false;
|
|
168
122
|
this.realGLDrawElements = function () { };
|
|
@@ -178,26 +132,25 @@ var GLHook = (function () {
|
|
|
178
132
|
console.error("[GLHook] GL can't be NULL");
|
|
179
133
|
}
|
|
180
134
|
}
|
|
181
|
-
|
|
135
|
+
fakeGLdrawElements(context) {
|
|
182
136
|
return function (mode, count, type, offset) {
|
|
183
137
|
context.drawPasses++;
|
|
184
138
|
context.realGLDrawElements.call(this, mode, count, type, offset);
|
|
185
139
|
};
|
|
186
|
-
}
|
|
187
|
-
|
|
140
|
+
}
|
|
141
|
+
reset() {
|
|
188
142
|
this.drawPasses = 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
143
|
+
}
|
|
144
|
+
release() {
|
|
191
145
|
if (this.isInit) {
|
|
192
146
|
this.gl.__proto__.drawElements = this.realGLDrawElements;
|
|
193
147
|
}
|
|
194
148
|
this.isInit = false;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
}());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
198
151
|
|
|
199
|
-
|
|
200
|
-
|
|
152
|
+
class TextureHook {
|
|
153
|
+
constructor(_gl) {
|
|
201
154
|
this.createdTextures = new Array();
|
|
202
155
|
this.maxTexturesCount = 0;
|
|
203
156
|
this.isInit = false;
|
|
@@ -217,25 +170,21 @@ var TextureHook = (function () {
|
|
|
217
170
|
console.error("[TextureHook] GL can't be NULL");
|
|
218
171
|
}
|
|
219
172
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
enumerable: false,
|
|
225
|
-
configurable: true
|
|
226
|
-
});
|
|
227
|
-
TextureHook.prototype.registerTexture = function (texture) {
|
|
173
|
+
get currentTextureCount() {
|
|
174
|
+
return this.createdTextures.length;
|
|
175
|
+
}
|
|
176
|
+
registerTexture(texture) {
|
|
228
177
|
this.createdTextures.push(texture);
|
|
229
178
|
this.maxTexturesCount = Math.max(this.createdTextures.length, this.maxTexturesCount);
|
|
230
|
-
}
|
|
231
|
-
|
|
179
|
+
}
|
|
180
|
+
fakeGLCreateTexture(context) {
|
|
232
181
|
return function () {
|
|
233
182
|
var texture = context.realGLCreateTexture.call(this);
|
|
234
183
|
context.registerTexture(texture);
|
|
235
184
|
return texture;
|
|
236
185
|
};
|
|
237
|
-
}
|
|
238
|
-
|
|
186
|
+
}
|
|
187
|
+
fakeGLDeleteTexture(context) {
|
|
239
188
|
return function (texture) {
|
|
240
189
|
var index = context.createdTextures.indexOf(texture);
|
|
241
190
|
if (index > -1) {
|
|
@@ -243,141 +192,114 @@ var TextureHook = (function () {
|
|
|
243
192
|
}
|
|
244
193
|
context.realGLDeleteTexture.call(this, texture);
|
|
245
194
|
};
|
|
246
|
-
}
|
|
247
|
-
|
|
195
|
+
}
|
|
196
|
+
reset() {
|
|
248
197
|
this.createdTextures = new Array();
|
|
249
198
|
this.maxTexturesCount = 0;
|
|
250
|
-
}
|
|
251
|
-
|
|
199
|
+
}
|
|
200
|
+
release() {
|
|
252
201
|
if (this.isInit) {
|
|
253
202
|
this.gl.__proto__.createTexture = this.realGLCreateTexture;
|
|
254
203
|
this.gl.__proto__.deleteTexture = this.realGLDeleteTexture;
|
|
255
204
|
console.log('[TextureHook] Hook was removed!');
|
|
256
205
|
}
|
|
257
206
|
this.isInit = false;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
}());
|
|
207
|
+
}
|
|
208
|
+
}
|
|
261
209
|
|
|
262
|
-
|
|
263
|
-
|
|
210
|
+
class BaseHooks {
|
|
211
|
+
constructor() {
|
|
264
212
|
this._drawCalls = -1;
|
|
265
213
|
this._maxDeltaDrawCalls = -1;
|
|
266
214
|
}
|
|
267
|
-
|
|
215
|
+
attach(gl) {
|
|
268
216
|
this.glhook = new GLHook(gl);
|
|
269
217
|
this.texturehook = new TextureHook(gl);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return this._maxDeltaDrawCalls;
|
|
284
|
-
},
|
|
285
|
-
enumerable: false,
|
|
286
|
-
configurable: true
|
|
287
|
-
});
|
|
288
|
-
Object.defineProperty(BaseHooks.prototype, "deltaDrawCalls", {
|
|
289
|
-
get: function () {
|
|
290
|
-
if (this._drawCalls == -1) {
|
|
291
|
-
this._drawCalls = this.drawCalls;
|
|
292
|
-
return 0;
|
|
293
|
-
}
|
|
294
|
-
var dc = this.drawCalls;
|
|
295
|
-
var delta = dc - this._drawCalls;
|
|
296
|
-
this._drawCalls = dc;
|
|
297
|
-
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
298
|
-
return delta;
|
|
299
|
-
},
|
|
300
|
-
enumerable: false,
|
|
301
|
-
configurable: true
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(BaseHooks.prototype, "maxTextureCount", {
|
|
304
|
-
get: function () {
|
|
305
|
-
if (this.texturehook && this.texturehook.isInit)
|
|
306
|
-
return this.texturehook.maxTexturesCount;
|
|
307
|
-
return 0;
|
|
308
|
-
},
|
|
309
|
-
enumerable: false,
|
|
310
|
-
configurable: true
|
|
311
|
-
});
|
|
312
|
-
Object.defineProperty(BaseHooks.prototype, "texturesCount", {
|
|
313
|
-
get: function () {
|
|
314
|
-
if (this.texturehook && this.texturehook.isInit)
|
|
315
|
-
return this.texturehook.currentTextureCount;
|
|
218
|
+
}
|
|
219
|
+
get drawCalls() {
|
|
220
|
+
if (this.glhook && this.glhook.isInit) {
|
|
221
|
+
return this.glhook.drawPasses;
|
|
222
|
+
}
|
|
223
|
+
return -1;
|
|
224
|
+
}
|
|
225
|
+
get maxDeltaDrawCalls() {
|
|
226
|
+
return this._maxDeltaDrawCalls;
|
|
227
|
+
}
|
|
228
|
+
get deltaDrawCalls() {
|
|
229
|
+
if (this._drawCalls == -1) {
|
|
230
|
+
this._drawCalls = this.drawCalls;
|
|
316
231
|
return 0;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
232
|
+
}
|
|
233
|
+
var dc = this.drawCalls;
|
|
234
|
+
var delta = dc - this._drawCalls;
|
|
235
|
+
this._drawCalls = dc;
|
|
236
|
+
this._maxDeltaDrawCalls = Math.max(this._maxDeltaDrawCalls, delta);
|
|
237
|
+
return delta;
|
|
238
|
+
}
|
|
239
|
+
get maxTextureCount() {
|
|
240
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
241
|
+
return this.texturehook.maxTexturesCount;
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
get texturesCount() {
|
|
245
|
+
if (this.texturehook && this.texturehook.isInit)
|
|
246
|
+
return this.texturehook.currentTextureCount;
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
reset() {
|
|
322
250
|
this._maxDeltaDrawCalls = -1;
|
|
323
251
|
this._drawCalls = -1;
|
|
324
252
|
if (this.glhook)
|
|
325
253
|
this.glhook.reset();
|
|
326
254
|
if (this.texturehook)
|
|
327
255
|
this.texturehook.reset();
|
|
328
|
-
}
|
|
329
|
-
|
|
256
|
+
}
|
|
257
|
+
release() {
|
|
330
258
|
if (this.glhook)
|
|
331
259
|
this.glhook.release();
|
|
332
260
|
if (this.texturehook)
|
|
333
261
|
this.texturehook.release();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
}());
|
|
262
|
+
}
|
|
263
|
+
}
|
|
337
264
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
_this.show = true;
|
|
343
|
-
return _this;
|
|
265
|
+
class StatsSystem extends eva_js.System {
|
|
266
|
+
constructor() {
|
|
267
|
+
super(...arguments);
|
|
268
|
+
this.show = true;
|
|
344
269
|
}
|
|
345
|
-
|
|
346
|
-
if (param === void 0) { param = { show: true }; }
|
|
270
|
+
init(param = { show: true }) {
|
|
347
271
|
this.show = param.show;
|
|
348
272
|
this.style = param.style;
|
|
349
273
|
this.renderSystem = this.game.getSystem('Renderer');
|
|
350
274
|
this.app = this.renderSystem.application;
|
|
351
275
|
if (this.app && this.show) {
|
|
352
|
-
|
|
276
|
+
const gl = this.app.renderer.gl;
|
|
353
277
|
this.hook = new BaseHooks();
|
|
354
278
|
this.hook.attach(gl);
|
|
355
279
|
}
|
|
356
|
-
}
|
|
357
|
-
|
|
280
|
+
}
|
|
281
|
+
start() {
|
|
358
282
|
if (!this.show)
|
|
359
283
|
return;
|
|
360
|
-
this.component = this.game.scene.addComponent(new
|
|
284
|
+
this.component = this.game.scene.addComponent(new StatsComponent());
|
|
361
285
|
this.stats = Stats$1(this.style);
|
|
362
286
|
this.component.stats = this.stats;
|
|
363
287
|
this.stats.showPanel(0);
|
|
364
288
|
document.body.appendChild(this.stats.dom);
|
|
365
|
-
}
|
|
366
|
-
|
|
289
|
+
}
|
|
290
|
+
lateUpdate() {
|
|
367
291
|
if (!this.show)
|
|
368
292
|
return;
|
|
369
293
|
this.stats && this.stats.end(this.hook);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}(eva_js.System));
|
|
374
|
-
var StatsSystem$1 = StatsSystem;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
StatsSystem.systemName = 'Stats';
|
|
375
297
|
|
|
376
298
|
var index = {
|
|
377
|
-
Components: [
|
|
378
|
-
Systems: [StatsSystem
|
|
299
|
+
Components: [StatsComponent],
|
|
300
|
+
Systems: [StatsSystem],
|
|
379
301
|
};
|
|
380
302
|
|
|
381
|
-
exports.Stats =
|
|
382
|
-
exports.StatsSystem = StatsSystem
|
|
303
|
+
exports.Stats = StatsComponent;
|
|
304
|
+
exports.StatsSystem = StatsSystem;
|
|
383
305
|
exports["default"] = index;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */function r(t,r){function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}var o=function(){return o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},o.apply(this,arguments)},n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(t.Component),s=function(t){var e=(t=o({width:20,height:12,x:0,y:0},t)).width,r=t.height,n=t.x,i=t.y,a=0,l=document.createElement("div");function u(t){return l.appendChild(t.dom),t}function h(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";a=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+r+"vw;left: "+n+"vw;top: "+i+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),h(++a%l.children.length)}),!1);var c,p=(performance||Date).now(),f=p,d=0,x=u(s.Panel("FPS","#0ff","#002")),m=u(s.Panel("MS","#0f0","#020")),w=u(s.Panel("DrawCall","#330570","#A69700")),y=u(s.Panel("TC:","#A62500","#00B454"));return self.performance&&self.performance.memory&&(c=u(s.Panel("MB","#f08","#201"))),h(0),{REVISION:16,dom:l,addPanel:u,showPanel:h,begin:function(t){p=t||(performance||Date).now()},end:function(t){d++;var e=(performance||Date).now();if(m.update(e-p,200),t&&(w.update(t.deltaDrawCalls,Math.max(50,t.maxDeltaDrawCalls)),y.update(t.texturesCount,Math.max(20,t.maxTextureCount))),e>=f+1e3&&(x.update(1e3*d/(e-f),100),f=e,d=0,c)){var r=performance.memory;c.update(r.usedJSHeapSize/1048576,r.jsHeapSizeLimit/1048576)}return e},update:function(){p=this.end()},domElement:l,setMode:h}};s.Panel=function(t,e,r){var o=1/0,n=0,s=Math.round,i=s(window.devicePixelRatio||1),a=80*i,l=48*i,u=3*i,h=2*i,c=3*i,p=15*i,f=74*i,d=30*i,x=document.createElement("canvas");x.width=a,x.height=l,x.style.cssText="width:100%;height:100%";var m=x.getContext("2d");return m.font="bold "+9*i+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=r,m.fillRect(0,0,a,l),m.fillStyle=e,m.fillText(t,u,h),m.fillRect(c,p,f,d),m.fillStyle=r,m.globalAlpha=.9,m.fillRect(c,p,f,d),{dom:x,update:function(l,w){o=Math.min(o,l),n=Math.max(n,l),m.fillStyle=r,m.globalAlpha=1,m.fillRect(0,0,a,p),m.fillStyle=e,m.fillText(s(l)+" "+t+" ("+s(o)+"-"+s(n)+")",u,h),m.drawImage(x,c+i,p,f-i,d,c,p,f-i,d),m.fillRect(c+f-i,p,i,d),m.fillStyle=r,m.globalAlpha=.9,m.fillRect(c+f-i,p,i,s((1-l/w)*d))}}};var i=s,a=function(){function t(t){this.drawPasses=0,this.isInit=!1,this.realGLDrawElements=function(){},t?t.__proto__.drawElements&&(this.gl=t,this.realGLDrawElements=t.__proto__.drawElements,t.__proto__.drawElements=this.fakeGLdrawElements(this),this.isInit=!0):console.error("[GLHook] GL can't be NULL")}return t.prototype.fakeGLdrawElements=function(t){return function(e,r,o,n){t.drawPasses++,t.realGLDrawElements.call(this,e,r,o,n)}},t.prototype.reset=function(){this.drawPasses=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.drawElements=this.realGLDrawElements),this.isInit=!1},t}(),l=function(){function t(t){this.createdTextures=new Array,this.maxTexturesCount=0,this.isInit=!1,this.realGLCreateTexture=function(){},this.realGLDeleteTexture=function(){},t?t.__proto__.createTexture&&(this.gl=t,this.realGLCreateTexture=t.__proto__.createTexture,this.realGLDeleteTexture=t.__proto__.deleteTexture,t.__proto__.createTexture=this.fakeGLCreateTexture(this),t.__proto__.deleteTexture=this.fakeGLDeleteTexture(this),this.isInit=!0):console.error("[TextureHook] GL can't be NULL")}return Object.defineProperty(t.prototype,"currentTextureCount",{get:function(){return this.createdTextures.length},enumerable:!1,configurable:!0}),t.prototype.registerTexture=function(t){this.createdTextures.push(t),this.maxTexturesCount=Math.max(this.createdTextures.length,this.maxTexturesCount)},t.prototype.fakeGLCreateTexture=function(t){return function(){var e=t.realGLCreateTexture.call(this);return t.registerTexture(e),e}},t.prototype.fakeGLDeleteTexture=function(t){return function(e){var r=t.createdTextures.indexOf(e);r>-1&&t.createdTextures.splice(r,1),t.realGLDeleteTexture.call(this,e)}},t.prototype.reset=function(){this.createdTextures=new Array,this.maxTexturesCount=0},t.prototype.release=function(){this.isInit&&(this.gl.__proto__.createTexture=this.realGLCreateTexture,this.gl.__proto__.deleteTexture=this.realGLDeleteTexture,console.log("[TextureHook] Hook was removed!")),this.isInit=!1},t}(),u=function(){function t(){this._drawCalls=-1,this._maxDeltaDrawCalls=-1}return t.prototype.attach=function(t){this.glhook=new a(t),this.texturehook=new l(t)},Object.defineProperty(t.prototype,"drawCalls",{get:function(){return this.glhook&&this.glhook.isInit?this.glhook.drawPasses:-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxDeltaDrawCalls",{get:function(){return this._maxDeltaDrawCalls},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deltaDrawCalls",{get:function(){if(-1==this._drawCalls)return this._drawCalls=this.drawCalls,0;var t=this.drawCalls,e=t-this._drawCalls;return this._drawCalls=t,this._maxDeltaDrawCalls=Math.max(this._maxDeltaDrawCalls,e),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxTextureCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.maxTexturesCount:0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"texturesCount",{get:function(){return this.texturehook&&this.texturehook.isInit?this.texturehook.currentTextureCount:0},enumerable:!1,configurable:!0}),t.prototype.reset=function(){this._maxDeltaDrawCalls=-1,this._drawCalls=-1,this.glhook&&this.glhook.reset(),this.texturehook&&this.texturehook.reset()},t.prototype.release=function(){this.glhook&&this.glhook.release(),this.texturehook&&this.texturehook.release()},t}(),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return r(e,t),e.prototype.init=function(t){if(void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style,this.renderSystem=this.game.getSystem("Renderer"),this.app=this.renderSystem.application,this.app&&this.show){var e=this.app.renderer.gl;this.hook=new u,this.hook.attach(e)}},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new n),this.stats=i(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))},e.prototype.lateUpdate=function(){this.show&&this.stats&&this.stats.end(this.hook)},e.systemName="Stats",e}(t.System),c={Components:[n],Systems:[h]};exports.Stats=n,exports.StatsSystem=h,exports.default=c;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js");class t extends e.Component{update(){this.stats&&this.stats.begin()}}t.componentName="Stats";const s=function(e){e=Object.assign({width:20,height:12,x:0,y:0},e);const{width:t,height:r,x:a,y:i}=e;let l=0;const o=document.createElement("div");function n(e){return o.appendChild(e.dom),e}function h(e){for(let t=0;t<o.children.length;t++)o.children[t].style.display=t===e?"block":"none";l=e}o.style.cssText=`position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: ${t}vw;height: ${r}vw;left: ${a}vw;top: ${i}vw;`,o.addEventListener("click",(function(e){e.preventDefault(),h(++l%o.children.length)}),!1);let u=(performance||Date).now(),c=u,d=0;const x=n(s.Panel("FPS","#0ff","#002")),m=n(s.Panel("MS","#0f0","#020")),p=n(s.Panel("DrawCall","#330570","#A69700")),w=n(s.Panel("TC:","#A62500","#00B454"));let f;return self.performance&&self.performance.memory&&(f=n(s.Panel("MB","#f08","#201"))),h(0),{REVISION:16,dom:o,addPanel:n,showPanel:h,begin:function(e){u=e||(performance||Date).now()},end:function(e){d++;const t=(performance||Date).now();if(m.update(t-u,200),e&&(p.update(e.deltaDrawCalls,Math.max(50,e.maxDeltaDrawCalls)),w.update(e.texturesCount,Math.max(20,e.maxTextureCount))),t>=c+1e3&&(x.update(1e3*d/(t-c),100),c=t,d=0,f)){const e=performance.memory;f.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){u=this.end()},domElement:o,setMode:h}};s.Panel=function(e,t,s){let r=1/0,a=0;const i=Math.round,l=i(window.devicePixelRatio||1),o=80*l,n=48*l,h=3*l,u=2*l,c=3*l,d=15*l,x=74*l,m=30*l,p=document.createElement("canvas");p.width=o,p.height=n,p.style.cssText="width:100%;height:100%";const w=p.getContext("2d");return w.font="bold "+9*l+"px Helvetica,Arial,sans-serif",w.textBaseline="top",w.fillStyle=s,w.fillRect(0,0,o,n),w.fillStyle=t,w.fillText(e,h,u),w.fillRect(c,d,x,m),w.fillStyle=s,w.globalAlpha=.9,w.fillRect(c,d,x,m),{dom:p,update:function(n,f){r=Math.min(r,n),a=Math.max(a,n),w.fillStyle=s,w.globalAlpha=1,w.fillRect(0,0,o,d),w.fillStyle=t,w.fillText(i(n)+" "+e+" ("+i(r)+"-"+i(a)+")",h,u),w.drawImage(p,c+l,d,x-l,m,c,d,x-l,m),w.fillRect(c+x-l,d,l,m),w.fillStyle=s,w.globalAlpha=.9,w.fillRect(c+x-l,d,l,i((1-n/f)*m))}}};var r=s;class a{constructor(e){this.drawPasses=0,this.isInit=!1,this.realGLDrawElements=function(){},e?e.__proto__.drawElements&&(this.gl=e,this.realGLDrawElements=e.__proto__.drawElements,e.__proto__.drawElements=this.fakeGLdrawElements(this),this.isInit=!0):console.error("[GLHook] GL can't be NULL")}fakeGLdrawElements(e){return function(t,s,r,a){e.drawPasses++,e.realGLDrawElements.call(this,t,s,r,a)}}reset(){this.drawPasses=0}release(){this.isInit&&(this.gl.__proto__.drawElements=this.realGLDrawElements),this.isInit=!1}}class i{constructor(e){this.createdTextures=new Array,this.maxTexturesCount=0,this.isInit=!1,this.realGLCreateTexture=function(){},this.realGLDeleteTexture=function(){},e?e.__proto__.createTexture&&(this.gl=e,this.realGLCreateTexture=e.__proto__.createTexture,this.realGLDeleteTexture=e.__proto__.deleteTexture,e.__proto__.createTexture=this.fakeGLCreateTexture(this),e.__proto__.deleteTexture=this.fakeGLDeleteTexture(this),this.isInit=!0):console.error("[TextureHook] GL can't be NULL")}get currentTextureCount(){return this.createdTextures.length}registerTexture(e){this.createdTextures.push(e),this.maxTexturesCount=Math.max(this.createdTextures.length,this.maxTexturesCount)}fakeGLCreateTexture(e){return function(){var t=e.realGLCreateTexture.call(this);return e.registerTexture(t),t}}fakeGLDeleteTexture(e){return function(t){var s=e.createdTextures.indexOf(t);s>-1&&e.createdTextures.splice(s,1),e.realGLDeleteTexture.call(this,t)}}reset(){this.createdTextures=new Array,this.maxTexturesCount=0}release(){this.isInit&&(this.gl.__proto__.createTexture=this.realGLCreateTexture,this.gl.__proto__.deleteTexture=this.realGLDeleteTexture,console.log("[TextureHook] Hook was removed!")),this.isInit=!1}}class l{constructor(){this._drawCalls=-1,this._maxDeltaDrawCalls=-1}attach(e){this.glhook=new a(e),this.texturehook=new i(e)}get drawCalls(){return this.glhook&&this.glhook.isInit?this.glhook.drawPasses:-1}get maxDeltaDrawCalls(){return this._maxDeltaDrawCalls}get deltaDrawCalls(){if(-1==this._drawCalls)return this._drawCalls=this.drawCalls,0;var e=this.drawCalls,t=e-this._drawCalls;return this._drawCalls=e,this._maxDeltaDrawCalls=Math.max(this._maxDeltaDrawCalls,t),t}get maxTextureCount(){return this.texturehook&&this.texturehook.isInit?this.texturehook.maxTexturesCount:0}get texturesCount(){return this.texturehook&&this.texturehook.isInit?this.texturehook.currentTextureCount:0}reset(){this._maxDeltaDrawCalls=-1,this._drawCalls=-1,this.glhook&&this.glhook.reset(),this.texturehook&&this.texturehook.reset()}release(){this.glhook&&this.glhook.release(),this.texturehook&&this.texturehook.release()}}class o extends e.System{constructor(){super(...arguments),this.show=!0}init(e={show:!0}){if(this.show=e.show,this.style=e.style,this.renderSystem=this.game.getSystem("Renderer"),this.app=this.renderSystem.application,this.app&&this.show){const e=this.app.renderer.gl;this.hook=new l,this.hook.attach(e)}}start(){this.show&&(this.component=this.game.scene.addComponent(new t),this.stats=r(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))}lateUpdate(){this.show&&this.stats&&this.stats.end(this.hook)}}o.systemName="Stats";var n={Components:[t],Systems:[o]};exports.Stats=t,exports.StatsSystem=o,exports.default=n;
|