@eva/plugin-stats 1.2.0-alpha.5 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-stats",
3
- "version": "1.2.0-alpha.5",
3
+ "version": "1.2.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.0-alpha.5",
21
+ "@eva/eva.js": "1.2.0",
22
22
  "lodash-es": "^4.17.21"
23
23
  }
24
24
  }
@@ -1,242 +0,0 @@
1
- this.EVA = this.EVA || {};
2
- this.EVA.plugin = this.EVA.plugin || {};
3
-
4
- this.EVA.plugin.stats = function (exports, eva_js) {
5
- 'use strict';
6
-
7
- var _extendStatics = function extendStatics(d, b) {
8
- _extendStatics = Object.setPrototypeOf || {
9
- __proto__: []
10
- } instanceof Array && function (d, b) {
11
- d.__proto__ = b;
12
- } || function (d, b) {
13
- for (var p in b) {
14
- if (b.hasOwnProperty(p)) d[p] = b[p];
15
- }
16
- };
17
-
18
- return _extendStatics(d, b);
19
- };
20
-
21
- function __extends(d, b) {
22
- _extendStatics(d, b);
23
-
24
- function __() {
25
- this.constructor = d;
26
- }
27
-
28
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
- }
30
-
31
- var _assign = function __assign() {
32
- _assign = Object.assign || function __assign(t) {
33
- for (var s, i = 1, n = arguments.length; i < n; i++) {
34
- s = arguments[i];
35
-
36
- for (var p in s) {
37
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
38
- }
39
- }
40
-
41
- return t;
42
- };
43
-
44
- return _assign.apply(this, arguments);
45
- };
46
-
47
- var StatsComponent = function (_super) {
48
- __extends(StatsComponent, _super);
49
-
50
- function StatsComponent() {
51
- return _super !== null && _super.apply(this, arguments) || this;
52
- }
53
-
54
- StatsComponent.prototype.update = function () {
55
- this.stats && this.stats.begin();
56
- };
57
-
58
- StatsComponent.componentName = 'Stats';
59
- return StatsComponent;
60
- }(eva_js.Component);
61
-
62
- var Stats$2 = StatsComponent;
63
-
64
- var Stats = function Stats(style) {
65
- style = _assign({
66
- width: 20,
67
- height: 12,
68
- x: 0,
69
- y: 0
70
- }, style);
71
- var width = style.width,
72
- height = style.height,
73
- x = style.x,
74
- y = style.y;
75
- var mode = 0;
76
- var container = document.createElement('div');
77
- 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;";
78
- container.addEventListener('click', function (event) {
79
- event.preventDefault();
80
- showPanel(++mode % container.children.length);
81
- }, false);
82
-
83
- function addPanel(panel) {
84
- container.appendChild(panel.dom);
85
- return panel;
86
- }
87
-
88
- function showPanel(id) {
89
- for (var i = 0; i < container.children.length; i++) {
90
- container.children[i].style.display = i === id ? 'block' : 'none';
91
- }
92
-
93
- mode = id;
94
- }
95
-
96
- var beginTime = (performance || Date).now(),
97
- prevTime = beginTime,
98
- frames = 0;
99
- var fpsPanel = addPanel(Stats.Panel('FPS', '#0ff', '#002'));
100
- var msPanel = addPanel(Stats.Panel('MS', '#0f0', '#020'));
101
- var memPanel;
102
-
103
- if (self.performance && self.performance.memory) {
104
- memPanel = addPanel(Stats.Panel('MB', '#f08', '#201'));
105
- }
106
-
107
- showPanel(0);
108
- return {
109
- REVISION: 16,
110
- dom: container,
111
- addPanel: addPanel,
112
- showPanel: showPanel,
113
- begin: function begin(time) {
114
- beginTime = time || (performance || Date).now();
115
- },
116
- end: function end() {
117
- frames++;
118
- var time = (performance || Date).now();
119
- msPanel.update(time - beginTime, 200);
120
-
121
- if (time >= prevTime + 1000) {
122
- fpsPanel.update(frames * 1000 / (time - prevTime), 100);
123
- prevTime = time;
124
- frames = 0;
125
-
126
- if (memPanel) {
127
- var memory = performance.memory;
128
- memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
129
- }
130
- }
131
-
132
- return time;
133
- },
134
- update: function update() {
135
- beginTime = this.end();
136
- },
137
- domElement: container,
138
- setMode: showPanel
139
- };
140
- };
141
-
142
- Stats.Panel = function (name, fg, bg) {
143
- var min = Infinity,
144
- max = 0;
145
- var round = Math.round;
146
- var PR = round(window.devicePixelRatio || 1);
147
- var WIDTH = 80 * PR,
148
- HEIGHT = 48 * PR,
149
- TEXT_X = 3 * PR,
150
- TEXT_Y = 2 * PR,
151
- GRAPH_X = 3 * PR,
152
- GRAPH_Y = 15 * PR,
153
- GRAPH_WIDTH = 74 * PR,
154
- GRAPH_HEIGHT = 30 * PR;
155
- var canvas = document.createElement('canvas');
156
- canvas.width = WIDTH;
157
- canvas.height = HEIGHT;
158
- canvas.style.cssText = 'width:100%;height:100%';
159
- var context = canvas.getContext('2d');
160
- context.font = 'bold ' + 9 * PR + 'px Helvetica,Arial,sans-serif';
161
- context.textBaseline = 'top';
162
- context.fillStyle = bg;
163
- context.fillRect(0, 0, WIDTH, HEIGHT);
164
- context.fillStyle = fg;
165
- context.fillText(name, TEXT_X, TEXT_Y);
166
- context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
167
- context.fillStyle = bg;
168
- context.globalAlpha = 0.9;
169
- context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
170
- return {
171
- dom: canvas,
172
- update: function update(value, maxValue) {
173
- min = Math.min(min, value);
174
- max = Math.max(max, value);
175
- context.fillStyle = bg;
176
- context.globalAlpha = 1;
177
- context.fillRect(0, 0, WIDTH, GRAPH_Y);
178
- context.fillStyle = fg;
179
- context.fillText(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')', TEXT_X, TEXT_Y);
180
- context.drawImage(canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT);
181
- context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);
182
- context.fillStyle = bg;
183
- context.globalAlpha = 0.9;
184
- context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));
185
- }
186
- };
187
- };
188
-
189
- var Stats$1 = Stats;
190
-
191
- var StatsSystem = function (_super) {
192
- __extends(StatsSystem, _super);
193
-
194
- function StatsSystem() {
195
- var _this = _super !== null && _super.apply(this, arguments) || this;
196
-
197
- _this.show = true;
198
- return _this;
199
- }
200
-
201
- StatsSystem.prototype.init = function (param) {
202
- if (param === void 0) {
203
- param = {
204
- show: true
205
- };
206
- }
207
-
208
- this.show = param.show;
209
- this.style = param.style;
210
- };
211
-
212
- StatsSystem.prototype.start = function () {
213
- if (!this.show) return;
214
- this.component = this.game.scene.addComponent(new Stats$2());
215
- this.stats = Stats$1(this.style);
216
- this.component.stats = this.stats;
217
- this.stats.showPanel(0);
218
- document.body.appendChild(this.stats.dom);
219
- };
220
-
221
- StatsSystem.prototype.lateUpdate = function () {
222
- if (!this.show) return;
223
- this.stats && this.stats.end();
224
- };
225
-
226
- StatsSystem.systemName = 'Stats';
227
- return StatsSystem;
228
- }(eva_js.System);
229
-
230
- var StatsSystem$1 = StatsSystem;
231
- var index = {
232
- Components: [Stats$2],
233
- Systems: [StatsSystem$1]
234
- };
235
- exports.Stats = Stats$2;
236
- exports.StatsSystem = StatsSystem$1;
237
- exports['default'] = index;
238
- Object.defineProperty(exports, '__esModule', {
239
- value: true
240
- });
241
- return exports;
242
- }({}, EVA);
@@ -1 +0,0 @@
1
- this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.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 i(t,e){function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.update=function(){this.stats&&this.stats.begin()},e.componentName="Stats",e}(e.Component),a=function t(e){var n=(e=o({width:20,height:12,x:0,y:0},e)).width,i=e.height,s=e.x,a=e.y,l=0,r=document.createElement("div");function c(t){return r.appendChild(t.dom),t}function p(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: "+i+"vw;left: "+s+"vw;top: "+a+"vw;",r.addEventListener("click",(function(t){t.preventDefault(),p(++l%r.children.length)}),!1);var h,f=(performance||Date).now(),u=f,d=0,y=c(t.Panel("FPS","#0ff","#002")),m=c(t.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(h=c(t.Panel("MB","#f08","#201"))),p(0),{REVISION:16,dom:r,addPanel:c,showPanel:p,begin:function(t){f=t||(performance||Date).now()},end:function(){d++;var t=(performance||Date).now();if(m.update(t-f,200),t>=u+1e3&&(y.update(1e3*d/(t-u),100),u=t,d=0,h)){var e=performance.memory;h.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){f=this.end()},domElement:r,setMode:p}};a.Panel=function(t,e,n){var i=1/0,o=0,s=Math.round,a=s(window.devicePixelRatio||1),l=80*a,r=48*a,c=3*a,p=2*a,h=3*a,f=15*a,u=74*a,d=30*a,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*a+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=n,m.fillRect(0,0,l,r),m.fillStyle=e,m.fillText(t,c,p),m.fillRect(h,f,u,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(h,f,u,d),{dom:y,update:function(r,w){i=Math.min(i,r),o=Math.max(o,r),m.fillStyle=n,m.globalAlpha=1,m.fillRect(0,0,l,f),m.fillStyle=e,m.fillText(s(r)+" "+t+" ("+s(i)+"-"+s(o)+")",c,p),m.drawImage(y,h+a,f,u-a,d,h,f,u-a,d),m.fillRect(h+u-a,f,a,d),m.fillStyle=n,m.globalAlpha=.9,m.fillRect(h+u-a,f,a,s((1-r/w)*d))}}};var l=a,r=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.show=!0,e}return i(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 s),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:[s],Systems:[r]};return t.Stats=s,t.StatsSystem=r,t.default=c,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);