@eva/plugin-stats 1.2.1-type.2 → 1.2.2-alpha.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
window.EVA = window.EVA || {};
|
|
2
|
+
window.EVA.plugin = window.EVA.plugin || {};
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var _EVA_IIFE_stats = function (exports, eva_js) {
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
7
|
var _extendStatics = function extendStatics(d, b) {
|
|
@@ -234,9 +234,11 @@ this.EVA.plugin.stats = function (exports, eva_js) {
|
|
|
234
234
|
};
|
|
235
235
|
exports.Stats = Stats$2;
|
|
236
236
|
exports.StatsSystem = StatsSystem$1;
|
|
237
|
-
exports[
|
|
237
|
+
exports['default'] = index;
|
|
238
238
|
Object.defineProperty(exports, '__esModule', {
|
|
239
239
|
value: true
|
|
240
240
|
});
|
|
241
241
|
return exports;
|
|
242
242
|
}({}, EVA);
|
|
243
|
+
|
|
244
|
+
window.EVA.plugin.stats = window.EVA.plugin.stats || _EVA_IIFE_stats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var _EVA_IIFE_stats=function(t,e){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(e.Component),s=function t(e){var n=(e=i({width:20,height:12,x:0,y:0},e)).width,o=e.height,a=e.x,s=e.y,l=0,r=document.createElement("div");function c(t){return r.appendChild(t.dom),t}function f(t){for(var e=0;e<r.children.length;e++)r.children[e].style.display=e===t?"block":"none";l=t}r.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+n+"vw;height: "+o+"vw;left: "+a+"vw;top: "+s+"vw;",r.addEventListener("click",(function(t){t.preventDefault(),f(++l%r.children.length)}),!1);var p,h=(performance||Date).now(),u=h,d=0,y=c(t.Panel("FPS","#0ff","#002")),m=c(t.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(p=c(t.Panel("MB","#f08","#201"))),f(0),{REVISION:16,dom:r,addPanel:c,showPanel:f,begin:function(t){h=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-h,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,p)){var e=performance.memory;p.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){h=this.end()},domElement:r,setMode:f}};s.Panel=function(t,e,n){var o=1/0,i=0,a=Math.round,s=a(window.devicePixelRatio||1),l=80*s,r=48*s,c=3*s,f=2*s,p=3*s,h=15*s,u=74*s,d=30*s,y=document.createElement("canvas");y.width=l,y.height=r,y.style.cssText="width:100%;height:100%";var m=y.getContext("2d");return m.font="bold "+9*s+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,l,r),m.fillStyle=e,m.fillText(t,c,f),m.fillRect(p,h,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(p,h,u,d),{dom:y,update:function(r,v){o=Math.min(o,r),i=Math.max(i,r),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,l,h),m.fillStyle=e,m.fillText(a(r)+" "+t+" ("+a(o)+"-"+a(i)+")",c,f),m.drawImage(y,p+s,h,u-s,d,p,h,u-s,d),m.fillRect(p+u-s,h,s,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(p+u-s,h,s,a((1-r/v)*d))}}};var l=s,r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return o(e,t),e.prototype.init=function(t){void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new a),this.stats=l(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))},e.prototype.lateUpdate=function(){this.show&&this.stats&&this.stats.end()},e.systemName="Stats",e}(e.System),c={Components:[a],Systems:[r]};return t.Stats=a,t.StatsSystem=r,t.default=c,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);
|
|
@@ -0,0 +1,193 @@
|
|
|
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 memPanel;
|
|
60
|
+
|
|
61
|
+
if (self.performance && self.performance.memory) {
|
|
62
|
+
memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
showPanel(0);
|
|
66
|
+
return {
|
|
67
|
+
REVISION: 16,
|
|
68
|
+
dom: container,
|
|
69
|
+
addPanel: addPanel,
|
|
70
|
+
showPanel: showPanel,
|
|
71
|
+
begin: function begin(time) {
|
|
72
|
+
beginTime = time || (performance || Date).now();
|
|
73
|
+
},
|
|
74
|
+
end: function end() {
|
|
75
|
+
frames++;
|
|
76
|
+
var time = (performance || Date).now();
|
|
77
|
+
msPanel.update(time - beginTime, 200);
|
|
78
|
+
|
|
79
|
+
if (time >= prevTime + 1000) {
|
|
80
|
+
fpsPanel.update(frames * 1000 / (time - prevTime), 100);
|
|
81
|
+
prevTime = time;
|
|
82
|
+
frames = 0;
|
|
83
|
+
|
|
84
|
+
if (memPanel) {
|
|
85
|
+
var memory = performance.memory;
|
|
86
|
+
memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return time;
|
|
91
|
+
},
|
|
92
|
+
update: function update() {
|
|
93
|
+
beginTime = this.end();
|
|
94
|
+
},
|
|
95
|
+
domElement: container,
|
|
96
|
+
setMode: showPanel
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Stats.Panel = function (name, fg, bg) {
|
|
101
|
+
var min = Infinity,
|
|
102
|
+
max = 0;
|
|
103
|
+
var round = Math.round;
|
|
104
|
+
var PR = round(windowAlias.devicePixelRatio || 1);
|
|
105
|
+
var WIDTH = 80 * PR,
|
|
106
|
+
HEIGHT = 48 * PR,
|
|
107
|
+
TEXT_X = 3 * PR,
|
|
108
|
+
TEXT_Y = 2 * PR,
|
|
109
|
+
GRAPH_X = 3 * PR,
|
|
110
|
+
GRAPH_Y = 15 * PR,
|
|
111
|
+
GRAPH_WIDTH = 74 * PR,
|
|
112
|
+
GRAPH_HEIGHT = 30 * PR;
|
|
113
|
+
var canvas = documentAlias.createElement('canvas');
|
|
114
|
+
canvas.width = WIDTH;
|
|
115
|
+
canvas.height = HEIGHT;
|
|
116
|
+
canvas.style.cssText = 'width:100%;height:100%';
|
|
117
|
+
var context = canvas.getContext('2d');
|
|
118
|
+
context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';
|
|
119
|
+
context.textBaseline = 'top';
|
|
120
|
+
context.fillStyle = bg;
|
|
121
|
+
context.fillRect(0, 0, WIDTH, HEIGHT);
|
|
122
|
+
context.fillStyle = fg;
|
|
123
|
+
context.fillText(name, TEXT_X, TEXT_Y);
|
|
124
|
+
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
125
|
+
context.fillStyle = bg;
|
|
126
|
+
context.globalAlpha = 0.9;
|
|
127
|
+
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
128
|
+
return {
|
|
129
|
+
dom: canvas,
|
|
130
|
+
update: function update(value, maxValue) {
|
|
131
|
+
min = Math.min(min, value);
|
|
132
|
+
max = Math.max(max, value);
|
|
133
|
+
context.fillStyle = bg;
|
|
134
|
+
context.globalAlpha = 1;
|
|
135
|
+
context.fillRect(0, 0, WIDTH, GRAPH_Y);
|
|
136
|
+
context.fillStyle = fg;
|
|
137
|
+
context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);
|
|
138
|
+
context.drawImage(canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT);
|
|
139
|
+
context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);
|
|
140
|
+
context.fillStyle = bg;
|
|
141
|
+
context.globalAlpha = 0.9;
|
|
142
|
+
context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
var Stats$1 = Stats;
|
|
148
|
+
|
|
149
|
+
var StatsSystem = function (_super) {
|
|
150
|
+
__extends(StatsSystem, _super);
|
|
151
|
+
|
|
152
|
+
function StatsSystem() {
|
|
153
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
154
|
+
|
|
155
|
+
_this.show = true;
|
|
156
|
+
return _this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
StatsSystem.prototype.init = function (param) {
|
|
160
|
+
if (param === void 0) {
|
|
161
|
+
param = {
|
|
162
|
+
show: true
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.show = param.show;
|
|
167
|
+
this.style = param.style;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
StatsSystem.prototype.start = function () {
|
|
171
|
+
if (!this.show) return;
|
|
172
|
+
this.component = this.game.scene.addComponent(new Stats$2());
|
|
173
|
+
this.stats = Stats$1(this.style);
|
|
174
|
+
this.component.stats = this.stats;
|
|
175
|
+
this.stats.showPanel(0);
|
|
176
|
+
documentAlias.body.appendChild(this.stats.dom);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
StatsSystem.prototype.lateUpdate = function () {
|
|
180
|
+
if (!this.show) return;
|
|
181
|
+
this.stats && this.stats.end();
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
StatsSystem.systemName = 'Stats';
|
|
185
|
+
return StatsSystem;
|
|
186
|
+
}(System);
|
|
187
|
+
|
|
188
|
+
var StatsSystem$1 = StatsSystem;
|
|
189
|
+
var index = {
|
|
190
|
+
Components: [Stats$2],
|
|
191
|
+
Systems: [StatsSystem$1]
|
|
192
|
+
};
|
|
193
|
+
export { Stats$2 as Stats, StatsSystem$1 as StatsSystem, index as default };
|
package/dist/plugin-stats.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,n){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,n)};
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */function n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return
|
|
15
|
+
***************************************************************************** */function n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(t.Component),s=function(t){var e=(t=o({width:20,height:12,x:0,y:0},t)).width,n=t.height,i=t.x,a=t.y,r=0,l=document.createElement("div");function c(t){return l.appendChild(t.dom),t}function p(t){for(var e=0;e<l.children.length;e++)l.children[e].style.display=e===t?"block":"none";r=t}l.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000;width: "+e+"vw;height: "+n+"vw;left: "+i+"vw;top: "+a+"vw;",l.addEventListener("click",(function(t){t.preventDefault(),p(++r%l.children.length)}),!1);var f,h=(performance||Date).now(),u=h,d=0,y=c(s.Panel("FPS","#0ff","#002")),m=c(s.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(f=c(s.Panel("MB","#f08","#201"))),p(0),{REVISION:16,dom:l,addPanel:c,showPanel:p,begin:function(t){h=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-h,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,f)){var e=performance.memory;f.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){h=this.end()},domElement:l,setMode:p}};s.Panel=function(t,e,n){var o=1/0,i=0,s=Math.round,a=s(window.devicePixelRatio||1),r=80*a,l=48*a,c=3*a,p=2*a,f=3*a,h=15*a,u=74*a,d=30*a,y=document.createElement("canvas");y.width=r,y.height=l,y.style.cssText="width:100%;height:100%";var m=y.getContext("2d");return m.font="bold "+9*a+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,r,l),m.fillStyle=e,m.fillText(t,c,p),m.fillRect(f,h,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f,h,u,d),{dom:y,update:function(l,v){o=Math.min(o,l),i=Math.max(i,l),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,r,h),m.fillStyle=e,m.fillText(s(l)+" "+t+" ("+s(o)+"-"+s(i)+")",c,p),m.drawImage(y,f+a,h,u-a,d,f,h,u-a,d),m.fillRect(f+u-a,h,a,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(f+u-a,h,a,s((1-l/v)*d))}}};var a=s,r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return n(e,t),e.prototype.init=function(t){void 0===t&&(t={show:!0}),this.show=t.show,this.style=t.style},e.prototype.start=function(){this.show&&(this.component=this.game.scene.addComponent(new i),this.stats=a(this.style),this.component.stats=this.stats,this.stats.showPanel(0),document.body.appendChild(this.stats.dom))},e.prototype.lateUpdate=function(){this.show&&this.stats&&this.stats.end()},e.systemName="Stats",e}(t.System),l={Components:[i],Systems:[r]};exports.Stats=i,exports.StatsSystem=r,exports.default=l;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-stats",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2-alpha.2",
|
|
4
4
|
"description": "@eva/plugin-stats",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-stats.esm.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "1.2.
|
|
21
|
+
"@eva/eva.js": "1.2.2-alpha.2",
|
|
22
22
|
"lodash-es": "^4.17.21"
|
|
23
23
|
}
|
|
24
24
|
}
|