@galacean/effects-plugin-stats 2.0.0-alpha.32
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/LICENSE +22 -0
- package/README.md +1 -0
- package/dist/core.d.ts +45 -0
- package/dist/hooks/drawcall-hook.d.ts +19 -0
- package/dist/hooks/program-hook.d.ts +14 -0
- package/dist/hooks/shader-hook.d.ts +15 -0
- package/dist/hooks/texture-hook.d.ts +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +674 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +8 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.mjs +670 -0
- package/dist/index.mjs.map +1 -0
- package/dist/monitor.d.ts +26 -0
- package/dist/stats-component.d.ts +10 -0
- package/dist/stats.d.ts +10 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Name: @galacean/effects-plugin-stats
|
|
3
|
+
* Description: Galacean Effects runtime stats for the web
|
|
4
|
+
* Author: Ant Group CO., Ltd.
|
|
5
|
+
* Contributors: 云垣
|
|
6
|
+
* Version: v2.0.0-alpha.32
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
12
|
+
|
|
13
|
+
var effects = require('@galacean/effects');
|
|
14
|
+
|
|
15
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
16
|
+
try {
|
|
17
|
+
var info = gen[key](arg);
|
|
18
|
+
var value = info.value;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
reject(error);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (info.done) resolve(value);
|
|
24
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
25
|
+
}
|
|
26
|
+
function _async_to_generator(fn) {
|
|
27
|
+
return function() {
|
|
28
|
+
var self = this, args = arguments;
|
|
29
|
+
return new Promise(function(resolve, reject) {
|
|
30
|
+
var gen = fn.apply(self, args);
|
|
31
|
+
function _next(value) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
33
|
+
}
|
|
34
|
+
function _throw(err) {
|
|
35
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
36
|
+
}
|
|
37
|
+
_next(undefined);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _instanceof1(left, right) {
|
|
43
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
44
|
+
return !!right[Symbol.hasInstance](left);
|
|
45
|
+
} else return _instanceof1(left, right);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function __generator(thisArg, body) {
|
|
49
|
+
var _ = {
|
|
50
|
+
label: 0,
|
|
51
|
+
sent: function sent() {
|
|
52
|
+
if (t[0] & 1) throw t[1];
|
|
53
|
+
return t[1];
|
|
54
|
+
},
|
|
55
|
+
trys: [],
|
|
56
|
+
ops: []
|
|
57
|
+
}, f, y, t, g;
|
|
58
|
+
return g = {
|
|
59
|
+
next: verb(0),
|
|
60
|
+
"throw": verb(1),
|
|
61
|
+
"return": verb(2)
|
|
62
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
63
|
+
return this;
|
|
64
|
+
}), g;
|
|
65
|
+
function verb(n) {
|
|
66
|
+
return function(v) {
|
|
67
|
+
return step([
|
|
68
|
+
n,
|
|
69
|
+
v
|
|
70
|
+
]);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function step(op) {
|
|
74
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
75
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
76
|
+
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;
|
|
77
|
+
if (y = 0, t) op = [
|
|
78
|
+
op[0] & 2,
|
|
79
|
+
t.value
|
|
80
|
+
];
|
|
81
|
+
switch(op[0]){
|
|
82
|
+
case 0:
|
|
83
|
+
case 1:
|
|
84
|
+
t = op;
|
|
85
|
+
break;
|
|
86
|
+
case 4:
|
|
87
|
+
_.label++;
|
|
88
|
+
return {
|
|
89
|
+
value: op[1],
|
|
90
|
+
done: false
|
|
91
|
+
};
|
|
92
|
+
case 5:
|
|
93
|
+
_.label++;
|
|
94
|
+
y = op[1];
|
|
95
|
+
op = [
|
|
96
|
+
0
|
|
97
|
+
];
|
|
98
|
+
continue;
|
|
99
|
+
case 7:
|
|
100
|
+
op = _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
default:
|
|
104
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
105
|
+
_ = 0;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
109
|
+
_.label = op[1];
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
113
|
+
_.label = t[1];
|
|
114
|
+
t = op;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (t && _.label < t[2]) {
|
|
118
|
+
_.label = t[2];
|
|
119
|
+
_.ops.push(op);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (t[2]) _.ops.pop();
|
|
123
|
+
_.trys.pop();
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
op = body.call(thisArg, _);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
op = [
|
|
129
|
+
6,
|
|
130
|
+
e
|
|
131
|
+
];
|
|
132
|
+
y = 0;
|
|
133
|
+
} finally{
|
|
134
|
+
f = t = 0;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] & 5) throw op[1];
|
|
137
|
+
return {
|
|
138
|
+
value: op[0] ? op[1] : void 0,
|
|
139
|
+
done: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
|
|
144
|
+
var e = new Error(message);
|
|
145
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
function _set_prototype_of(o, p) {
|
|
149
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
150
|
+
o.__proto__ = p;
|
|
151
|
+
return o;
|
|
152
|
+
};
|
|
153
|
+
return _set_prototype_of(o, p);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function _inherits(subClass, superClass) {
|
|
157
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
158
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
159
|
+
}
|
|
160
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
161
|
+
constructor: {
|
|
162
|
+
value: subClass,
|
|
163
|
+
writable: true,
|
|
164
|
+
configurable: true
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var DrawCallHook = /*#__PURE__*/ function() {
|
|
171
|
+
function DrawCallHook(gl) {
|
|
172
|
+
this.gl = gl;
|
|
173
|
+
this.drawCall = 0;
|
|
174
|
+
this.triangles = 0;
|
|
175
|
+
this.lines = 0;
|
|
176
|
+
this.points = 0;
|
|
177
|
+
this.hooked = true;
|
|
178
|
+
this.realDrawElements = gl.drawElements;
|
|
179
|
+
this.realDrawArrays = gl.drawArrays;
|
|
180
|
+
gl.drawElements = this.hookedDrawElements.bind(this);
|
|
181
|
+
gl.drawArrays = this.hookedDrawArrays.bind(this);
|
|
182
|
+
if (Stats.options.debug) {
|
|
183
|
+
console.debug("DrawCall is hooked.");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
var _proto = DrawCallHook.prototype;
|
|
187
|
+
_proto.hookedDrawElements = function hookedDrawElements(mode, count, type, offset) {
|
|
188
|
+
this.realDrawElements.call(this.gl, mode, count, type, offset);
|
|
189
|
+
this.update(count, mode);
|
|
190
|
+
};
|
|
191
|
+
_proto.hookedDrawArrays = function hookedDrawArrays(mode, first, count) {
|
|
192
|
+
this.realDrawArrays.call(this.gl, mode, first, count);
|
|
193
|
+
this.update(count, mode);
|
|
194
|
+
};
|
|
195
|
+
_proto.update = function update(count, mode) {
|
|
196
|
+
var gl = this.gl;
|
|
197
|
+
this.drawCall++;
|
|
198
|
+
switch(mode){
|
|
199
|
+
case gl.TRIANGLES:
|
|
200
|
+
this.triangles += count / 3;
|
|
201
|
+
break;
|
|
202
|
+
case gl.TRIANGLE_STRIP:
|
|
203
|
+
case gl.TRIANGLE_FAN:
|
|
204
|
+
this.triangles += count - 2;
|
|
205
|
+
break;
|
|
206
|
+
case gl.LINES:
|
|
207
|
+
this.lines += count / 2;
|
|
208
|
+
break;
|
|
209
|
+
case gl.LINE_STRIP:
|
|
210
|
+
this.lines += count - 1;
|
|
211
|
+
break;
|
|
212
|
+
case gl.LINE_LOOP:
|
|
213
|
+
this.lines += count;
|
|
214
|
+
break;
|
|
215
|
+
case gl.POINTS:
|
|
216
|
+
this.points += count;
|
|
217
|
+
break;
|
|
218
|
+
default:
|
|
219
|
+
console.error("Unknown draw mode: " + mode + ". Count: " + count);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
_proto.reset = function reset() {
|
|
224
|
+
this.drawCall = 0;
|
|
225
|
+
this.triangles = 0;
|
|
226
|
+
this.lines = 0;
|
|
227
|
+
this.points = 0;
|
|
228
|
+
};
|
|
229
|
+
_proto.release = function release() {
|
|
230
|
+
if (this.hooked) {
|
|
231
|
+
this.gl.drawElements = this.realDrawElements;
|
|
232
|
+
this.gl.drawArrays = this.realDrawArrays;
|
|
233
|
+
this.hooked = false;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return DrawCallHook;
|
|
237
|
+
}();
|
|
238
|
+
|
|
239
|
+
var ProgramHook = /*#__PURE__*/ function() {
|
|
240
|
+
function ProgramHook(gl) {
|
|
241
|
+
this.gl = gl;
|
|
242
|
+
this.programs = 0;
|
|
243
|
+
this.hooked = true;
|
|
244
|
+
this.realUseProgram = gl.useProgram;
|
|
245
|
+
gl.useProgram = this.hookedUseProgram.bind(this);
|
|
246
|
+
if (Stats.options.debug) {
|
|
247
|
+
console.debug("Program is hooked.");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
var _proto = ProgramHook.prototype;
|
|
251
|
+
_proto.hookedUseProgram = function hookedUseProgram(program) {
|
|
252
|
+
this.realUseProgram.call(this.gl, program);
|
|
253
|
+
this.programs++;
|
|
254
|
+
if (Stats.options.debug) {
|
|
255
|
+
console.debug("UseProgram: " + program + ", program: " + this.programs + ".");
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
_proto.reset = function reset() {
|
|
259
|
+
this.programs = 0;
|
|
260
|
+
};
|
|
261
|
+
_proto.release = function release() {
|
|
262
|
+
if (this.hooked) {
|
|
263
|
+
this.gl.useProgram = this.realUseProgram;
|
|
264
|
+
this.hooked = false;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
return ProgramHook;
|
|
268
|
+
}();
|
|
269
|
+
|
|
270
|
+
var ShaderHook = /*#__PURE__*/ function() {
|
|
271
|
+
function ShaderHook(gl) {
|
|
272
|
+
this.gl = gl;
|
|
273
|
+
this.shaders = 0;
|
|
274
|
+
this.hooked = true;
|
|
275
|
+
this.realAttachShader = gl.attachShader;
|
|
276
|
+
this.realDetachShader = gl.detachShader;
|
|
277
|
+
gl.attachShader = this.hookedAttachShader.bind(this);
|
|
278
|
+
gl.detachShader = this.hookedDetachShader.bind(this);
|
|
279
|
+
if (Stats.options.debug) {
|
|
280
|
+
console.debug("Shader is hooked.");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
var _proto = ShaderHook.prototype;
|
|
284
|
+
_proto.hookedAttachShader = function hookedAttachShader(program, shader) {
|
|
285
|
+
this.realAttachShader.call(this.gl, program, shader);
|
|
286
|
+
this.shaders++;
|
|
287
|
+
if (Stats.options.debug) {
|
|
288
|
+
console.debug("AttachShader: " + shader + ". shaders: " + this.shaders);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
_proto.hookedDetachShader = function hookedDetachShader(program, shader) {
|
|
292
|
+
this.realDetachShader.call(this.gl, program, shader);
|
|
293
|
+
this.shaders--;
|
|
294
|
+
if (Stats.options.debug) {
|
|
295
|
+
console.debug("DetachShader. shaders: " + this.shaders);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
_proto.reset = function reset() {
|
|
299
|
+
this.shaders = 0;
|
|
300
|
+
};
|
|
301
|
+
_proto.release = function release() {
|
|
302
|
+
if (this.hooked) {
|
|
303
|
+
this.gl.attachShader = this.realAttachShader;
|
|
304
|
+
this.gl.detachShader = this.realDetachShader;
|
|
305
|
+
this.hooked = false;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
return ShaderHook;
|
|
309
|
+
}();
|
|
310
|
+
|
|
311
|
+
var TextureHook = /*#__PURE__*/ function() {
|
|
312
|
+
function TextureHook(gl) {
|
|
313
|
+
this.gl = gl;
|
|
314
|
+
this.textures = 0;
|
|
315
|
+
this.hooked = true;
|
|
316
|
+
this.realCreateTexture = gl.createTexture;
|
|
317
|
+
this.realDeleteTexture = gl.deleteTexture;
|
|
318
|
+
gl.createTexture = this.hookedCreateTexture.bind(this);
|
|
319
|
+
gl.deleteTexture = this.hookedDeleteTexture.bind(this);
|
|
320
|
+
if (Stats.options.debug) {
|
|
321
|
+
console.debug("Texture is hooked.");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
var _proto = TextureHook.prototype;
|
|
325
|
+
_proto.hookedCreateTexture = function hookedCreateTexture() {
|
|
326
|
+
var texture = this.realCreateTexture.call(this.gl);
|
|
327
|
+
this.textures++;
|
|
328
|
+
if (Stats.options.debug) {
|
|
329
|
+
console.debug("CreateTexture: " + texture + ", textures: " + this.textures + ".");
|
|
330
|
+
}
|
|
331
|
+
return texture;
|
|
332
|
+
};
|
|
333
|
+
_proto.hookedDeleteTexture = function hookedDeleteTexture(texture) {
|
|
334
|
+
this.realDeleteTexture.call(this.gl, texture);
|
|
335
|
+
this.textures--;
|
|
336
|
+
if (Stats.options.debug) {
|
|
337
|
+
console.debug("DeleteTexture, textures: " + this.textures + ".");
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
_proto.reset = function reset() {
|
|
341
|
+
this.textures = 0;
|
|
342
|
+
};
|
|
343
|
+
_proto.release = function release() {
|
|
344
|
+
if (this.hooked) {
|
|
345
|
+
this.gl.createTexture = this.realCreateTexture;
|
|
346
|
+
this.gl.deleteTexture = this.realDeleteTexture;
|
|
347
|
+
this.hooked = false;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
return TextureHook;
|
|
351
|
+
}();
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Hook gl to calculate stats
|
|
355
|
+
*/ var Core = /*#__PURE__*/ function() {
|
|
356
|
+
function Core(gl) {
|
|
357
|
+
this.gl = gl;
|
|
358
|
+
this.samplingFrames = 60;
|
|
359
|
+
this.samplingIndex = 0;
|
|
360
|
+
this.updateCounter = 0;
|
|
361
|
+
this.updateTime = 0;
|
|
362
|
+
if (!gl) {
|
|
363
|
+
throw new Error("Unsupported WebGL context.");
|
|
364
|
+
}
|
|
365
|
+
this.hook(gl);
|
|
366
|
+
}
|
|
367
|
+
var _proto = Core.prototype;
|
|
368
|
+
_proto.hook = function hook(gl) {
|
|
369
|
+
this.drawCallHook = new DrawCallHook(gl);
|
|
370
|
+
this.textureHook = new TextureHook(gl);
|
|
371
|
+
this.shaderHook = new ShaderHook(gl);
|
|
372
|
+
this.programHook = new ProgramHook(gl);
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* reset draw call hook
|
|
376
|
+
*/ _proto.reset = function reset() {
|
|
377
|
+
var _this_drawCallHook, _this_programHook;
|
|
378
|
+
(_this_drawCallHook = this.drawCallHook) == null ? void 0 : _this_drawCallHook.reset();
|
|
379
|
+
(_this_programHook = this.programHook) == null ? void 0 : _this_programHook.reset();
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* release hook
|
|
383
|
+
*/ _proto.release = function release() {
|
|
384
|
+
var _this_drawCallHook, _this_textureHook, _this_shaderHook, _this_programHook;
|
|
385
|
+
(_this_drawCallHook = this.drawCallHook) == null ? void 0 : _this_drawCallHook.release();
|
|
386
|
+
(_this_textureHook = this.textureHook) == null ? void 0 : _this_textureHook.release();
|
|
387
|
+
(_this_shaderHook = this.shaderHook) == null ? void 0 : _this_shaderHook.release();
|
|
388
|
+
(_this_programHook = this.programHook) == null ? void 0 : _this_programHook.release();
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* update performance data
|
|
392
|
+
*/ _proto.update = function update(dt) {
|
|
393
|
+
var now = performance.now();
|
|
394
|
+
this.updateCounter++;
|
|
395
|
+
if (now - this.updateTime < 1000) {
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
if (this.samplingIndex !== this.samplingFrames) {
|
|
399
|
+
this.reset();
|
|
400
|
+
this.samplingIndex++;
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
this.samplingIndex = 0;
|
|
404
|
+
var data = {
|
|
405
|
+
fps: Math.round(this.updateCounter * 1000 / (now - this.updateTime)),
|
|
406
|
+
// eslint-disable-next-line compat/compat -- performance.memory is not standard
|
|
407
|
+
memory: performance.memory && performance.memory.usedJSHeapSize / 1048576 >> 0,
|
|
408
|
+
drawCall: this.drawCallHook.drawCall === 0 ? 0 : this.drawCallHook.drawCall - 1,
|
|
409
|
+
triangles: this.drawCallHook.triangles === 0 ? 0 : this.drawCallHook.triangles - 2,
|
|
410
|
+
lines: this.drawCallHook.lines,
|
|
411
|
+
points: this.drawCallHook.points,
|
|
412
|
+
textures: this.textureHook.textures,
|
|
413
|
+
shaders: this.shaderHook.shaders === 0 ? 0 : this.shaderHook.shaders + 1,
|
|
414
|
+
programs: this.programHook.programs,
|
|
415
|
+
webglContext: _instanceof1(this.gl, WebGL2RenderingContext) ? "2.0" : "1.0"
|
|
416
|
+
};
|
|
417
|
+
this.reset();
|
|
418
|
+
this.updateCounter = 0;
|
|
419
|
+
this.updateTime = now;
|
|
420
|
+
return data;
|
|
421
|
+
};
|
|
422
|
+
return Core;
|
|
423
|
+
}();
|
|
424
|
+
|
|
425
|
+
var tpl = '\n <dl>\n <dt>FPS</dt>\n <dd>0</dd>\n <dt>Memory <span class="unit">(MB)</span></dt>\n <dd>0</dd>\n <dt>DrawCall</dt>\n <dd>0</dd>\n <dt>Triangles</dt>\n <dd>0</dd>\n <dt>Textures</dt>\n <dd>0</dd>\n <dt>Shaders</dt>\n <dd>0</dd>\n <dt>Program</dt>\n <dd>0</dd>\n <dt>WebGL</dt>\n <dd></dd>\n </dl>\n';
|
|
426
|
+
var css = "\n .gl-perf {\n pointer-events: none;\n user-select: none;\n position: fixed;\n top: 0;\n left: 0;\n padding: " + 10 / 7.5 + "vh " + 10 / 7.5 + "vh 0 " + 10 / 7.5 + "vh;\n background: rgba(0, 0, 0, 0.3);\n color: #fff;\n font: " + 10 / 7.5 + "vh arial;\n }\n\n .gl-perf dl,\n .gl-perf dt,\n .gl-perf dd {\n padding: 0;\n margin: 0;\n }\n\n .gl-perf dt {\n color: #fff;\n text-shadow: #000 0 0 1px;\n }\n\n .gl-perf dt .unit{\n font-size: " + 10 / 7.5 + "vh;\n }\n\n .gl-perf dd {\n font-size: " + 20 / 7.5 + "vh;\n padding: " + 10 / 7.5 + "vh 0 " + 10 / 7.5 + "vh;\n }\n";
|
|
427
|
+
var Monitor = /*#__PURE__*/ function() {
|
|
428
|
+
function Monitor(gl) {
|
|
429
|
+
this.items = [
|
|
430
|
+
"fps",
|
|
431
|
+
"memory",
|
|
432
|
+
"drawCall",
|
|
433
|
+
"triangles",
|
|
434
|
+
"textures",
|
|
435
|
+
"shaders",
|
|
436
|
+
"programs",
|
|
437
|
+
"webglContext"
|
|
438
|
+
];
|
|
439
|
+
this.data = {
|
|
440
|
+
fps: 60,
|
|
441
|
+
memory: 0,
|
|
442
|
+
drawCall: 0,
|
|
443
|
+
triangles: 0,
|
|
444
|
+
lines: 0,
|
|
445
|
+
points: 0,
|
|
446
|
+
textures: 0,
|
|
447
|
+
shaders: 0,
|
|
448
|
+
programs: 0,
|
|
449
|
+
webglContext: "2.0"
|
|
450
|
+
};
|
|
451
|
+
this.core = new Core(gl);
|
|
452
|
+
this.createContainer();
|
|
453
|
+
this.update = this.update.bind(this);
|
|
454
|
+
}
|
|
455
|
+
var _proto = Monitor.prototype;
|
|
456
|
+
_proto.createContainer = function createContainer() {
|
|
457
|
+
var container = document.createElement("div");
|
|
458
|
+
container.classList.add("gl-perf");
|
|
459
|
+
container.innerHTML = tpl;
|
|
460
|
+
container.appendChild(this.createStyle());
|
|
461
|
+
document.body.appendChild(container);
|
|
462
|
+
this.doms = Array.prototype.slice.apply(container.querySelectorAll("dd"));
|
|
463
|
+
this.container = container;
|
|
464
|
+
};
|
|
465
|
+
_proto.createStyle = function createStyle() {
|
|
466
|
+
var style = document.createElement("style");
|
|
467
|
+
style.appendChild(document.createTextNode(css));
|
|
468
|
+
return style;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* Update per frame
|
|
472
|
+
*/ _proto.update = function update(dt) {
|
|
473
|
+
var _this, _loop = function(i, l) {
|
|
474
|
+
var dom = _this.doms[i];
|
|
475
|
+
var item = _this.items[i];
|
|
476
|
+
var value = data[item] || 0;
|
|
477
|
+
// see: http://wilsonpage.co.uk/preventing-layout-thrashing/
|
|
478
|
+
requestAnimationFrame(function() {
|
|
479
|
+
dom.innerText = String(value);
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
var data = this.core.update(dt);
|
|
483
|
+
if (!data || data.drawCall === 0 || data.triangles === 0) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
for(var i = 0, l = this.items.length; i < l; i++)_this = this, _loop(i);
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* reset all hooks
|
|
490
|
+
*/ _proto.reset = function reset() {
|
|
491
|
+
var _this, _loop = function(i, l) {
|
|
492
|
+
var dom = _this.doms[i];
|
|
493
|
+
var item = _this.items[i];
|
|
494
|
+
var value = _this.data[item] || 0;
|
|
495
|
+
// see: http://wilsonpage.co.uk/preventing-layout-thrashing/
|
|
496
|
+
requestAnimationFrame(function() {
|
|
497
|
+
dom.innerText = String(value);
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
this.core.reset();
|
|
501
|
+
for(var i = 0, l = this.items.length; i < l; i++)_this = this, _loop(i);
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* release all hooks
|
|
505
|
+
*/ _proto.release = function release() {
|
|
506
|
+
this.core.release();
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* destroy the instance
|
|
510
|
+
*/ _proto.destroy = function destroy() {
|
|
511
|
+
this.release();
|
|
512
|
+
document.body.removeChild(this.container);
|
|
513
|
+
};
|
|
514
|
+
return Monitor;
|
|
515
|
+
}();
|
|
516
|
+
|
|
517
|
+
var StatsComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
518
|
+
_inherits(StatsComponent, ItemBehaviour);
|
|
519
|
+
function StatsComponent() {
|
|
520
|
+
return ItemBehaviour.apply(this, arguments);
|
|
521
|
+
}
|
|
522
|
+
var _proto = StatsComponent.prototype;
|
|
523
|
+
_proto.start = function start() {
|
|
524
|
+
var renderer = this.engine.renderer;
|
|
525
|
+
var gl = renderer.pipelineContext.gl;
|
|
526
|
+
this.monitor = new Monitor(gl);
|
|
527
|
+
};
|
|
528
|
+
_proto.update = function update(dt) {
|
|
529
|
+
this.monitor.update(dt);
|
|
530
|
+
};
|
|
531
|
+
return StatsComponent;
|
|
532
|
+
}(effects.ItemBehaviour);
|
|
533
|
+
|
|
534
|
+
var json = {
|
|
535
|
+
"images": [],
|
|
536
|
+
"fonts": [],
|
|
537
|
+
"version": "3.0",
|
|
538
|
+
"shapes": [],
|
|
539
|
+
"plugins": [],
|
|
540
|
+
"type": "ge",
|
|
541
|
+
"compositions": [
|
|
542
|
+
{
|
|
543
|
+
"id": "2",
|
|
544
|
+
"name": "stats",
|
|
545
|
+
"duration": 5,
|
|
546
|
+
"startTime": 0,
|
|
547
|
+
"endBehavior": 2,
|
|
548
|
+
"previewSize": [
|
|
549
|
+
750,
|
|
550
|
+
1624
|
|
551
|
+
],
|
|
552
|
+
"items": [
|
|
553
|
+
{
|
|
554
|
+
"id": "05e1c616baf34cc084968a05703719cd"
|
|
555
|
+
}
|
|
556
|
+
],
|
|
557
|
+
"camera": {
|
|
558
|
+
"fov": 60,
|
|
559
|
+
"far": 40,
|
|
560
|
+
"near": 0.1,
|
|
561
|
+
"clipMode": 1,
|
|
562
|
+
"position": [
|
|
563
|
+
0,
|
|
564
|
+
0,
|
|
565
|
+
8
|
|
566
|
+
],
|
|
567
|
+
"rotation": [
|
|
568
|
+
0,
|
|
569
|
+
0,
|
|
570
|
+
0
|
|
571
|
+
]
|
|
572
|
+
},
|
|
573
|
+
"sceneBindings": []
|
|
574
|
+
}
|
|
575
|
+
],
|
|
576
|
+
"components": [],
|
|
577
|
+
"geometries": [],
|
|
578
|
+
"materials": [],
|
|
579
|
+
"items": [
|
|
580
|
+
{
|
|
581
|
+
"id": "05e1c616baf34cc084968a05703719cd",
|
|
582
|
+
"name": "component",
|
|
583
|
+
"duration": 99999,
|
|
584
|
+
"type": "1",
|
|
585
|
+
"visible": true,
|
|
586
|
+
"endBehavior": 0,
|
|
587
|
+
"delay": 0,
|
|
588
|
+
"renderLevel": "B+",
|
|
589
|
+
"components": [],
|
|
590
|
+
"transform": {
|
|
591
|
+
"position": {
|
|
592
|
+
"x": 0,
|
|
593
|
+
"y": 0,
|
|
594
|
+
"z": 0
|
|
595
|
+
},
|
|
596
|
+
"eulerHint": {
|
|
597
|
+
"x": 0,
|
|
598
|
+
"y": 0,
|
|
599
|
+
"z": 0
|
|
600
|
+
},
|
|
601
|
+
"anchor": {
|
|
602
|
+
"x": 0,
|
|
603
|
+
"y": 0
|
|
604
|
+
},
|
|
605
|
+
"size": {
|
|
606
|
+
"x": 1.2,
|
|
607
|
+
"y": 1.2
|
|
608
|
+
},
|
|
609
|
+
"scale": {
|
|
610
|
+
"x": 1,
|
|
611
|
+
"y": 1,
|
|
612
|
+
"z": 1
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
"dataType": "VFXItemData"
|
|
616
|
+
}
|
|
617
|
+
],
|
|
618
|
+
"shaders": [],
|
|
619
|
+
"bins": [],
|
|
620
|
+
"textures": [],
|
|
621
|
+
"animations": [],
|
|
622
|
+
"compositionId": "2"
|
|
623
|
+
};
|
|
624
|
+
var Stats = /*#__PURE__*/ function() {
|
|
625
|
+
function Stats(player, options) {
|
|
626
|
+
if (options === void 0) options = {
|
|
627
|
+
debug: false
|
|
628
|
+
};
|
|
629
|
+
this.player = player;
|
|
630
|
+
Stats.options = options;
|
|
631
|
+
void this.init();
|
|
632
|
+
}
|
|
633
|
+
var _proto = Stats.prototype;
|
|
634
|
+
_proto.init = function init() {
|
|
635
|
+
var _this = this;
|
|
636
|
+
return _async_to_generator(function() {
|
|
637
|
+
var composition, component, e;
|
|
638
|
+
return __generator(this, function(_state) {
|
|
639
|
+
switch(_state.label){
|
|
640
|
+
case 0:
|
|
641
|
+
_state.trys.push([
|
|
642
|
+
0,
|
|
643
|
+
2,
|
|
644
|
+
,
|
|
645
|
+
3
|
|
646
|
+
]);
|
|
647
|
+
return [
|
|
648
|
+
4,
|
|
649
|
+
_this.player.loadScene(json)
|
|
650
|
+
];
|
|
651
|
+
case 1:
|
|
652
|
+
composition = _state.sent();
|
|
653
|
+
component = composition.getItemByName("component");
|
|
654
|
+
component == null ? void 0 : component.addComponent(StatsComponent);
|
|
655
|
+
return [
|
|
656
|
+
3,
|
|
657
|
+
3
|
|
658
|
+
];
|
|
659
|
+
case 2:
|
|
660
|
+
e = _state.sent();
|
|
661
|
+
throw new Error("Failed to load stats scene: " + e.message + ".");
|
|
662
|
+
case 3:
|
|
663
|
+
return [
|
|
664
|
+
2
|
|
665
|
+
];
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
})();
|
|
669
|
+
};
|
|
670
|
+
return Stats;
|
|
671
|
+
}();
|
|
672
|
+
|
|
673
|
+
exports.Stats = Stats;
|
|
674
|
+
//# sourceMappingURL=index.js.map
|