forked from WhitestormJS/whs.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerformanceModule.js
261 lines (221 loc) · 54.1 KB
/
PerformanceModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* Built for whs v2.2.0-beta.0 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('events')) :
typeof define === 'function' && define.amd ? define(['events'], factory) :
(global.PerformanceModule = factory(global.events));
}(this, (function (events) { 'use strict';
events = events && events.hasOwnProperty('default') ? events['default'] : events;
var inherits_1 = inherits;
function inherits (c, p, proto) {
proto = proto || {};
var e = {}
;[c.prototype, proto].forEach(function (s) {
Object.getOwnPropertyNames(s).forEach(function (k) {
e[k] = Object.getOwnPropertyDescriptor(s, k);
});
});
c.prototype = Object.create(p.prototype, e);
c.super = p;
}
var inherits$1 = /*#__PURE__*/Object.freeze({
default: inherits_1,
__moduleExports: inherits_1
});
var inherits$2 = ( inherits$1 && inherits_1 ) || inherits$1;
var EventEmitter = events.EventEmitter;
var index = fps;
// Try use performance.now(), otherwise try
// +new Date.
var now = (
(function(){ return this }()).performance &&
'function' === typeof performance.now
) ? function() { return performance.now() }
: Date.now || function() { return +new Date };
function fps(opts) {
if (!(this instanceof fps)) return new fps(opts)
EventEmitter.call(this);
opts = opts || {};
this.last = now();
this.rate = 0;
this.time = 0;
this.decay = opts.decay || 1;
this.every = opts.every || 1;
this.ticks = 0;
}
inherits$2(fps, EventEmitter);
fps.prototype.tick = function() {
var time = now()
, diff = time - this.last
, fps = diff;
this.ticks += 1;
this.last = time;
this.time += (fps - this.time) * this.decay;
this.rate = 1000 / this.time;
if (!(this.ticks % this.every)) this.emit('data', this.rate);
};
var minivents_commonjs = function Events(target){
var events$$1 = {}, empty = [];
target = target || this;
/**
* On: listen to events
*/
target.on = function(type, func, ctx){
(events$$1[type] = events$$1[type] || []).push([func, ctx]);
};
/**
* Off: stop listening to event / specific callback
*/
target.off = function(type, func){
type || (events$$1 = {});
var list = events$$1[type] || empty,
i = list.length = func ? list.length : 0;
while(i--) func == list[i][0] && list.splice(i,1);
};
/**
* Emit: send event, callbacks will be triggered
*/
target.emit = function(type){
var e = events$$1[type] || empty, list = e.length > 0 ? e.slice(0, e.length) : e, i=0, j;
while(j=list[i++]) j[0].apply(j[1], empty.slice.call(arguments, 1));
};
};
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
var PerformanceModule =
/*#__PURE__*/
function (_Events) {
function PerformanceModule(config) {
var _this;
var iterationStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 60;
var framesToUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 60;
var blockTimeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
_classCallCheck(this, PerformanceModule);
_this = _possibleConstructorReturn(this, _getPrototypeOf(PerformanceModule).call(this));
_this.config = config;
_this.enabled = {};
_this.iterationStart = iterationStart;
_this.framesToUpdate = framesToUpdate;
_this.blockTimeout = blockTimeout;
_this.iteration = 0;
_this.avgRate = 60;
_this.block = false;
for (var key in config) {
if (config[key]) _this.enabled[key] = true;
}
_this.ticker = index();
_this.rate = 60;
return _this;
}
_createClass(PerformanceModule, [{
key: "manager",
value: function manager(_manager) {
var _this2 = this;
_manager.define('performance');
var ticker = this.ticker,
config = this.config;
this.app = _manager.handler;
this.loop = new WHS.Loop(function () {
ticker.tick();
_this2.rate = ticker.rate;
_this2.avgRate = (_this2.iteration * _this2.avgRate + _this2.rate) / (_this2.iteration + 1);
if (_this2.iteration % _this2.framesToUpdate === 0 && _this2.iteration > _this2.iterationStart && !_this2.block) {
for (var key in config) {
if (config[key]) {
var erate = config[key];
_this2.enable(key);
if (_this2.enabled[key] && erate > _this2.avgRate) {
_this2.disable(key);
_this2.block = true;
_this2.iteration = 1;
_this2.avgRate = 60;
setTimeout(function () {
_this2.block = false;
}, _this2.blockTimeout);
delete config[key];
}
break;
}
}
}
_this2.iteration++;
});
}
}, {
key: "start",
value: function start() {
this.loop.start(this.app);
}
}, {
key: "disable",
value: function disable(key) {
this.enabled[key] = false;
this.emit(key, false);
}
}, {
key: "enable",
value: function enable(key) {
this.enabled[key] = true;
this.emit(key, true);
}
}]);
_inherits(PerformanceModule, _Events);
return PerformanceModule;
}(minivents_commonjs);
return PerformanceModule;
})));
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUGVyZm9ybWFuY2VNb2R1bGUuanMiLCJzb3VyY2VzIjpbIi4uL3NyYy9tb2R1bGVzL2V4dHJhL25vZGVfbW9kdWxlcy9pbmhlcml0cy9pbmhlcml0cy5qcyIsIi4uL3NyYy9tb2R1bGVzL2V4dHJhL25vZGVfbW9kdWxlcy9mcHMvaW5kZXguanMiLCIuLi9zcmMvbW9kdWxlcy9leHRyYS9ub2RlX21vZHVsZXMvbWluaXZlbnRzL2Rpc3QvbWluaXZlbnRzLmNvbW1vbmpzLmpzIiwiLi4vc3JjL21vZHVsZXMvZXh0cmEvcm9sbHVwUGx1Z2luQmFiZWxIZWxwZXJzIiwiLi4vc3JjL21vZHVsZXMvZXh0cmEvUGVyZm9ybWFuY2VNb2R1bGUuanMiXSwic291cmNlc0NvbnRlbnQiOlsibW9kdWxlLmV4cG9ydHMgPSBpbmhlcml0c1xuXG5mdW5jdGlvbiBpbmhlcml0cyAoYywgcCwgcHJvdG8pIHtcbiAgcHJvdG8gPSBwcm90byB8fCB7fVxuICB2YXIgZSA9IHt9XG4gIDtbYy5wcm90b3R5cGUsIHByb3RvXS5mb3JFYWNoKGZ1bmN0aW9uIChzKSB7XG4gICAgT2JqZWN0LmdldE93blByb3BlcnR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