mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Add Thread.blockContainer
Store the thread's blocks at blockContainer letting execute quickly determine the block source. Monitor threads are a monitor thread. They do not become a target thread suddenly.
This commit is contained in:
parent
ab8d8e5f34
commit
4286e3e982
4 changed files with 13 additions and 7 deletions
|
@ -126,12 +126,7 @@ const execute = function (sequencer, thread, recursiveCall) {
|
||||||
const currentBlockId = thread.peekStack();
|
const currentBlockId = thread.peekStack();
|
||||||
const currentStackFrame = thread.peekStackFrame();
|
const currentStackFrame = thread.peekStackFrame();
|
||||||
|
|
||||||
let blockContainer;
|
let blockContainer = thread.blockContainer;
|
||||||
if (thread.updateMonitor) {
|
|
||||||
blockContainer = runtime.monitorBlocks;
|
|
||||||
} else {
|
|
||||||
blockContainer = target.blocks;
|
|
||||||
}
|
|
||||||
let block = blockContainer.getBlock(currentBlockId);
|
let block = blockContainer.getBlock(currentBlockId);
|
||||||
if (typeof block === 'undefined') {
|
if (typeof block === 'undefined') {
|
||||||
blockContainer = runtime.flyoutBlocks;
|
blockContainer = runtime.flyoutBlocks;
|
||||||
|
|
|
@ -861,6 +861,9 @@ class Runtime extends EventEmitter {
|
||||||
thread.target = target;
|
thread.target = target;
|
||||||
thread.stackClick = opts.stackClick;
|
thread.stackClick = opts.stackClick;
|
||||||
thread.updateMonitor = opts.updateMonitor;
|
thread.updateMonitor = opts.updateMonitor;
|
||||||
|
thread.blockContainer = opts.updateMonitor ?
|
||||||
|
this.monitorBlocks :
|
||||||
|
target.blocks;
|
||||||
|
|
||||||
thread.pushStack(id);
|
thread.pushStack(id);
|
||||||
this.threads.push(thread);
|
this.threads.push(thread);
|
||||||
|
@ -890,6 +893,7 @@ class Runtime extends EventEmitter {
|
||||||
newThread.target = thread.target;
|
newThread.target = thread.target;
|
||||||
newThread.stackClick = thread.stackClick;
|
newThread.stackClick = thread.stackClick;
|
||||||
newThread.updateMonitor = thread.updateMonitor;
|
newThread.updateMonitor = thread.updateMonitor;
|
||||||
|
newThread.blockContainer = thread.blockContainer;
|
||||||
newThread.pushStack(thread.topBlock);
|
newThread.pushStack(thread.topBlock);
|
||||||
const i = this.threads.indexOf(thread);
|
const i = this.threads.indexOf(thread);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
|
|
|
@ -42,6 +42,12 @@ class Thread {
|
||||||
*/
|
*/
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Blocks this thread will execute.
|
||||||
|
* @type {Blocks}
|
||||||
|
*/
|
||||||
|
this.blockContainer = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the thread requests its script to glow during this frame.
|
* Whether the thread requests its script to glow during this frame.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|
|
@ -91,6 +91,7 @@ const generateThread = function (runtime) {
|
||||||
rt.blocks.createBlock(generateBlock(next));
|
rt.blocks.createBlock(generateBlock(next));
|
||||||
th.pushStack(next);
|
th.pushStack(next);
|
||||||
th.target = rt;
|
th.target = rt;
|
||||||
|
th.blockContainer = rt.blocks;
|
||||||
|
|
||||||
runtime.threads.push(th);
|
runtime.threads.push(th);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue