Skip to content

Don't emit PROJECT_RUN_START for edge activation check thread #2419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ class Runtime extends EventEmitter {
*/
this._nonMonitorThreadCount = 0;

/**
* Number of threads of edge-activated blocks that executes condition check.
* @type {number}
*/
this._edgeActivatedThreadCount = 0;

/**
* All threads that finished running and were removed from this.threads
* by behaviour in Sequencer.stepThreads.
Expand Down Expand Up @@ -1815,6 +1821,10 @@ class Runtime extends EventEmitter {
// For compatibility with Scratch 2, edge triggered hats need to be processed before
// threads are stepped. See ScratchRuntime.as for original implementation
newThreads.forEach(thread => {
// This is used to count how many edge-activated block condition check threads will exist
if (hatMeta.edgeActivated) {
this._edgeActivatedThreadCount++;
}
execute(this.sequencer, thread);
thread.goToNextBlock();
});
Expand Down Expand Up @@ -2011,6 +2021,7 @@ class Runtime extends EventEmitter {

// Clean up threads that were told to stop during or since the last step
this.threads = this.threads.filter(thread => !thread.isKilled);
this._edgeActivatedThreadCount = 0;

// Find all edge-activated hats, and add them to threads to be evaluated.
for (const hatType in this._hats) {
Expand All @@ -2035,9 +2046,11 @@ class Runtime extends EventEmitter {
this._updateGlows(doneThreads);
// Add done threads so that even if a thread finishes within 1 frame, the green
// flag will still indicate that a script ran.
const projectRunStatusThreads = [...this.threads, ...doneThreads];
this._emitProjectRunStatus(
this.threads.length + doneThreads.length -
this._getMonitorThreadCount([...this.threads, ...doneThreads]));
this._getMonitorThreadCount(projectRunStatusThreads) -
this._edgeActivatedThreadCount);
// Store threads that completed this iteration for testing and other
// internal purposes.
this._lastStepDoneThreads = doneThreads;
Expand Down Expand Up @@ -2179,7 +2192,8 @@ class Runtime extends EventEmitter {
}

/**
* Emit run start/stop after each tick. Emits when `this.threads.length` goes
* Emit run start/stop after each tick. Emits when `this.threads.length`
* (exclusing monitor threads and "edge activation checking threads") goes
* between non-zero and zero
*
* @param {number} nonMonitorThreadCount The new nonMonitorThreadCount
Expand Down