mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 15:02:52 -05:00
yield a thread loop or tick in event_broadcastandwait
- yield a thread loop or tick in looks_switchbackdroptoandwait If all threads broadcastAndWait is watching are "waiting" for a future frame, yield until the next tick so event_broadcastandwait also defers to a future frame.
This commit is contained in:
parent
0a006dc981
commit
d161251a9b
2 changed files with 22 additions and 2 deletions
|
@ -100,10 +100,20 @@ class Scratch3EventBlocks {
|
||||||
const instance = this;
|
const instance = this;
|
||||||
const waiting = util.stackFrame.startedThreads.some(thread => instance.runtime.isActiveThread(thread));
|
const waiting = util.stackFrame.startedThreads.some(thread => instance.runtime.isActiveThread(thread));
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
// If all threads are waiting for the next tick or later yield
|
||||||
|
// for a tick as well. Otherwise yield until the next loop of
|
||||||
|
// the threads.
|
||||||
|
if (
|
||||||
|
util.stackFrame.startedThreads
|
||||||
|
.every(thread => instance.runtime.isWaitingThread(thread))
|
||||||
|
) {
|
||||||
|
util.yieldTick();
|
||||||
|
} else {
|
||||||
util.yield();
|
util.yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Scratch3EventBlocks;
|
module.exports = Scratch3EventBlocks;
|
||||||
|
|
|
@ -409,9 +409,19 @@ class Scratch3LooksBlocks {
|
||||||
const instance = this;
|
const instance = this;
|
||||||
const waiting = util.stackFrame.startedThreads.some(thread => instance.runtime.isActiveThread(thread));
|
const waiting = util.stackFrame.startedThreads.some(thread => instance.runtime.isActiveThread(thread));
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
// If all threads are waiting for the next tick or later yield
|
||||||
|
// for a tick as well. Otherwise yield until the next loop of
|
||||||
|
// the threads.
|
||||||
|
if (
|
||||||
|
util.stackFrame.startedThreads
|
||||||
|
.every(thread => instance.runtime.isWaitingThread(thread))
|
||||||
|
) {
|
||||||
|
util.yieldTick();
|
||||||
|
} else {
|
||||||
util.yield();
|
util.yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nextBackdrop () {
|
nextBackdrop () {
|
||||||
const stage = this.runtime.getTargetForStage();
|
const stage = this.runtime.getTargetForStage();
|
||||||
|
|
Loading…
Reference in a new issue