mirror of
https://codeberg.org/vlw/monkeydo.git
synced 2025-09-13 23:53:41 +02:00
dev21w45-a
This commit is contained in:
parent
22eda97800
commit
9de4811adf
1 changed files with 15 additions and 16 deletions
|
@ -17,32 +17,31 @@ class Monkey {
|
||||||
|
|
||||||
// Task scheduler
|
// Task scheduler
|
||||||
next() {
|
next() {
|
||||||
if(this.flags[0] === 0 || this.flags[2] === 0) return this.abort();
|
const start = performance.now();
|
||||||
const task = this.tasks[this.i];
|
const self = this;
|
||||||
|
let task = null;
|
||||||
|
|
||||||
// Run task after delay
|
// Run task after delay
|
||||||
this.queue.thisTask = setTimeout(() => {
|
function frame(time) {
|
||||||
// Dispatch task to main thread
|
if(self.flags[0] === 0 || self.flags[2] === 0) return self.abort();
|
||||||
postMessage(["TASK",task]);
|
postMessage(["TASK",task]);
|
||||||
this.i++;
|
self.i++;
|
||||||
},task[0]);
|
scheduleFrame(time);
|
||||||
|
|
||||||
// Loop until flag is 0 or infinite if 255
|
|
||||||
if(this.i === this.tasksLength) {
|
|
||||||
this.i = -1;
|
|
||||||
if(this.flags[1] < 255) this.flags[2]--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue the next task
|
// Queue the next task
|
||||||
this.queue.nextTask = setTimeout(() => this.next(),task[0]);
|
function scheduleFrame(time) {
|
||||||
|
task = self.tasks[self.i];
|
||||||
|
//const elapsed = Math.round(performance.now() - start);
|
||||||
|
const wait = task[0] + start;
|
||||||
|
setTimeout(() => requestAnimationFrame(frame),wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleFrame(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
abort() {
|
||||||
this.flags[2] = 0; // Playing: false
|
this.flags[2] = 0; // Playing: false
|
||||||
clearTimeout(this.queue.thisTask);
|
|
||||||
clearTimeout(this.queue.nextTask);
|
|
||||||
this.queue.thisTask = null;
|
|
||||||
this.queue.nextTask = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set or get a runtime flag
|
// Set or get a runtime flag
|
||||||
|
|
Loading…
Add table
Reference in a new issue