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:
Michael "Z" Goddard 2018-06-06 09:59:38 -04:00
parent 0a006dc981
commit d161251a9b
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 22 additions and 2 deletions

View file

@ -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;

View file

@ -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();