123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- var t = require;
- var e = module;
- var i = exports;
- Object.defineProperty(i, "__esModule", {value: !0}),
- (i.TimerHandlerObj = i.TimerManager = void 0),
- (i.TimerManager = class {
- constructor() {
- (this.isPause = !1),
- (this._lastTime = 0),
- (this._handlers = []),
- ObjectPool.registerClass(s, "TimerHandlerObj"),
- (this._delHandlers = []),
- (this._currTime = this._lastTime = cc.director.getTotalTime()),
- (this._currFrame = 0),
- (this._count = 0),
- (this._timeScale = 1);
- }
- get currFrame() {
- return this._currFrame;
- }
- reset() {
- (this._handlers = []), (this._delHandlers = []), (this._timeScale = 1), (this._count = 0);
- }
- setTimeScale(t) {
- this._timeScale = t;
- }
- onGamePause() {}
- onGameResume() {}
- onEnterFrame(t) {
- for (
- this._currFrame++, t = Math.min(t, 0.3), this._currTime += 1e3 * t * this._timeScale;
- this._delHandlers.length;
- )
- this.removeHandle(this._delHandlers.pop());
- for (var e = 0; e < this._count; e++) {
- var i = this._handlers[e];
- if (
- -1 == this._delHandlers.indexOf(i) &&
- (i.userFrame ? this._currFrame : this._currTime) >= i.exeTime
- ) {
- try {
- i.method.call(i.methodObj, this._currTime - i.dealTime);
- } catch (t) {
- Log.error(t);
- }
- if (((i.dealTime = this._currTime), (i.exeTime += i.delay), !i.repeat))
- if (1 < i.repeatCount) i.repeatCount--;
- else {
- if (i.complateMethod)
- try {
- i.complateMethod.apply(i.complateMethodObj);
- } catch (t) {
- Log.error(t);
- }
- -1 == this._delHandlers.indexOf(i) && this._delHandlers.push(i);
- }
- }
- }
- return !0;
- }
- removeHandle(t) {
- var e = this._handlers.indexOf(t);
- -1 != e
- ? (this._handlers.splice(e, 1), t.clear(), ObjectPool.push(t), this._count--)
- : Log.warn("what????");
- }
- create(t, e, i, s, o, a, n) {
- var r;
- e < 0 ||
- i < 0 ||
- null == s ||
- (this.remove(s, o),
- ((r = ObjectPool.pop("TimerHandlerObj")).userFrame = t),
- (r.repeat = 0 == i),
- (r.repeatCount = i),
- (r.delay = e),
- (r.method = s),
- (r.methodObj = o),
- (r.complateMethod = a),
- (r.complateMethodObj = n),
- (r.exeTime = e + (t ? this._currFrame : this._currTime)),
- (r.dealTime = this._currTime),
- this._handlers.push(r),
- this._count++);
- }
- doTimer(t, e, i, s, o = null, a = null) {
- this.create(!1, t, e, i, s, o, a);
- }
- doFrame(t, e, i, s, o = null, a = null) {
- this.create(!0, t, e, i, s, o, a);
- }
- setTimeOut(t, e, i) {
- this.doTimer(t, 1, e, i);
- }
- setFrameOut(t, e, i) {
- this.doFrame(t, 1, e, i);
- }
- get count() {
- return this._count;
- }
- remove(t, e) {
- for (var i = 0; i < this._count; i++) {
- var s = this._handlers[i];
- if (s.method == t && s.methodObj == e && -1 == this._delHandlers.indexOf(s)) {
- this._delHandlers.push(s);
- break;
- }
- }
- }
- sleep(e, i) {
- return new Promise(t => {
- this.doTimer(e, 1, t, i);
- });
- }
- sleepFrame(e, i) {
- return new Promise(t => {
- this.doFrame(e, 1, t, i);
- });
- }
- removeAll(t) {
- for (var e = 0; e < this._count; e++) {
- var i = this._handlers[e];
- i.methodObj == t && -1 == this._delHandlers.indexOf(i) && this._delHandlers.push(i);
- }
- }
- isExists(t, e) {
- for (var i = 0; i < this._count; i++) {
- var s = this._handlers[i];
- if (s.method == t && s.methodObj == e && -1 == this._delHandlers.indexOf(s)) return !0;
- }
- return !1;
- }
- });
- class s {
- constructor() {
- (this.ObjectPoolKey = null), (this.delay = 0), (this.repeatCount = 0), (this.exeTime = 0), (this.dealTime = 0);
- }
- clear() {
- (this.method = null), (this.methodObj = null), (this.complateMethod = null), (this.complateMethodObj = null);
- }
- }
- i.TimerHandlerObj = s;
|