Skip to content

Commit

Permalink
Fixes for Furfur Rig
Browse files Browse the repository at this point in the history
- Stop all sounds on destroyed clones
- Fix redraws being requested on invisible sprites
- Fix the "stop all" block and rename Interpreter#stopAll to
  Interpreter#stopAllThreads to prevent further footguns and guide
  towards Runtime#stopAll instead
- Stop the project before unloading it
  • Loading branch information
valadaptive committed May 28, 2024
1 parent 0576c1b commit fec4e03
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,7 @@ export const pen_clear = new ProtoBlock({
inputs: {},
execute: function* (_, ctx) {
ctx.renderer?.penLayer.clear();
ctx.target.runtime.requestRedraw();
},
});

Expand All @@ -2092,6 +2093,7 @@ export const pen_stamp = new ProtoBlock({
inputs: {},
execute: function* (_, ctx) {
ctx.renderer?.stamp(ctx.target);
ctx.target.runtime.requestRedraw();
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/block-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class BlockContext {
}

*stopAll() {
this.interpreter.stopAll();
this.target.runtime.stopAll();
// We will never resume from this yield.
yield;
}
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Interpreter {
}

public setProject(project: Project | null) {
this.stopAll();
this.stopAllThreads();
this.project = project;

// This is obviously a lie, but with no project, blocks should not be executing anyway
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class Interpreter {
return thread;
}

public stopAll() {
public stopAllThreads() {
for (const thread of this.threads) {
thread.retire();
}
Expand Down
3 changes: 2 additions & 1 deletion src/interpreter/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export default class Thread {
* Scratch does.
*/
isRecursiveCall(procedure: ProtoBlock) {
for (let i = this.callStack.length - 1, j = 5; i >= 0 && j > 0; i--, j--) {
// We just pushed the procedure we're testing against to the stack, so skip over it
for (let i = this.callStack.length - 2, j = 5; i >= 0 && j > 0; i--, j--) {
if (this.callStack[i].procedure === procedure) return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default class Runtime {
}

public stopAll() {
this.interpreter.stopAll();
this.interpreter.stopAllThreads();
this.project?.stopAll();
}

Expand Down
17 changes: 10 additions & 7 deletions src/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export default class Target {
}

public destroy() {
this.reset();
this.scriptListenerCleanup();
this.runtime.stopTargetThreads(this);
}
Expand Down Expand Up @@ -290,7 +291,9 @@ export default class Target {
y = Math.floor(this._position.y + (stageTop - fenceBounds.bottom));
}

if (this.penState.down && !fromDrag) {
const shouldDrawPenLine = this.penState.down && !fromDrag;

if (shouldDrawPenLine) {
this.runtime.penLayer?.penLine(
this._position.x,
this._position.y,
Expand All @@ -307,7 +310,7 @@ export default class Target {
this.drawable.setTransformDirty();
}

this.runtime.requestRedraw();
if (this.visible || shouldDrawPenLine) this.runtime.requestRedraw();
}

/**
Expand Down Expand Up @@ -359,7 +362,7 @@ export default class Target {
if (this.drawable) {
this.drawable.setTransformDirty();
}
this.runtime.requestRedraw();
if (this.visible) this.runtime.requestRedraw();
}

get size(): number {
Expand All @@ -372,7 +375,7 @@ export default class Target {
if (this.drawable) {
this.drawable.setTransformDirty();
}
this.runtime.requestRedraw();
if (this.visible) this.runtime.requestRedraw();
}

get rotationStyle(): RotationStyle {
Expand All @@ -385,7 +388,7 @@ export default class Target {
if (this.drawable) {
this.drawable.setTransformDirty();
}
this.runtime.requestRedraw();
if (this.visible) this.runtime.requestRedraw();
}

get currentCostume(): number {
Expand All @@ -405,7 +408,7 @@ export default class Target {
if (this.drawable) {
this.drawable.setCostume(this.sprite.costumes[index]);
}
this.runtime.requestRedraw();
if (this.visible) this.runtime.requestRedraw();
}

get visible(): boolean {
Expand All @@ -415,7 +418,7 @@ export default class Target {
set visible(visible: boolean) {
if (this.sprite.isStage) return;
this._visible = visible;
this.runtime.requestRedraw();
if (visible) this.runtime.requestRedraw();
}

public isTouchingEdge(): boolean {
Expand Down

0 comments on commit fec4e03

Please sign in to comment.