46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$SchedulerSystem = function(global, require, module, exports) {
|
|
global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
|
|
var Ticker = require("module$node_modules$pixi_DOT_js$lib$ticker$Ticker");
|
|
"use strict";
|
|
let uid = 1;
|
|
class SchedulerSystem {
|
|
constructor() {
|
|
this._tasks = [];
|
|
this._offset = 0;
|
|
}
|
|
init() {
|
|
Ticker.Ticker.system.add(this._update, this);
|
|
}
|
|
repeat(func, duration, useOffset = !0) {
|
|
const id = uid++;
|
|
let offset = 0;
|
|
useOffset && (offset = this._offset += 1e3);
|
|
this._tasks.push({func, duration, start:performance.now(), offset, last:performance.now(), repeat:!0, id});
|
|
return id;
|
|
}
|
|
cancel(id) {
|
|
for (let i = 0; i < this._tasks.length; i++) {
|
|
if (this._tasks[i].id === id) {
|
|
this._tasks.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
_update() {
|
|
const now = performance.now();
|
|
for (let i = 0; i < this._tasks.length; i++) {
|
|
const task = this._tasks[i];
|
|
now - task.offset - task.last >= task.duration && (task.func(now - task.start), task.last = now);
|
|
}
|
|
}
|
|
destroy() {
|
|
Ticker.Ticker.system.remove(this._update, this);
|
|
this._tasks.length = 0;
|
|
}
|
|
}
|
|
SchedulerSystem.extension = {type:[global.ExtensionType.WebGLSystem, global.ExtensionType.WebGPUSystem, global.ExtensionType.CanvasSystem], name:"scheduler", priority:0};
|
|
exports.SchedulerSystem = SchedulerSystem;
|
|
};
|
|
|
|
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$SchedulerSystem.js.map
|