@eva/plugin-stats 1.2.2-alpha.1 → 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/miniprogram.js +193 -0
- package/package.json +2 -2
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-stats",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
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.2-alpha.
|
|
21
|
+
"@eva/eva.js": "1.2.2-alpha.2",
|
|
22
22
|
"lodash-es": "^4.17.21"
|
|
23
23
|
}
|
|
24
24
|
}
|