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