Hacked implementation of broadcasts

This commit is contained in:
Tim Mickel 2016-05-03 14:57:10 -04:00
parent 326e03b5d2
commit 9363432456
4 changed files with 86 additions and 8 deletions
src/engine

View file

@ -137,6 +137,32 @@ Sequencer.prototype.stepThread = function (thread) {
thread.stackFrames.pop();
};
/**
* A callback for the primitive to start hats.
* @todo very hacked...
*/
var startHats = function(callback) {
for (var i = 0; i < instance.runtime.stacks.length; i++) {
var stack = instance.runtime.stacks[i];
var stackBlock = instance.runtime.blocks[stack];
var result = callback(stackBlock);
if (result) {
// Check if the stack is already running
var stackRunning = false;
for (var j = 0; j < instance.runtime.threads.length; j++) {
if (instance.runtime.threads[j].topBlock == stack) {
stackRunning = true;
break;
}
}
if (!stackRunning) {
instance.runtime._pushThread(stack);
}
}
}
};
/**
* Record whether we have switched stack,
* to avoid proceeding the thread automatically.
@ -191,7 +217,8 @@ Sequencer.prototype.stepThread = function (thread) {
done: threadDoneCallback,
timeout: YieldTimers.timeout,
stackFrame: currentStackFrame,
startSubstack: threadStartSubstack
startSubstack: threadStartSubstack,
startHats: startHats
});
}
catch(e) {