Skip to content

Commit 2bc7038

Browse files
committed
Rewrite the event loop
1 parent 81c6210 commit 2bc7038

File tree

9 files changed

+607
-439
lines changed

9 files changed

+607
-439
lines changed

include/scratchcpp/iengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class LIBSCRATCHCPP_EXPORT IEngine
6262
/*! Starts the script of the given broadcast. */
6363
virtual void broadcastByPtr(Broadcast *broadcast, VirtualMachine *sourceScript, bool wait = false) = 0;
6464

65+
/*! Starts the "when backdrop switches to" scripts for the given backdrop broadcast. */
66+
virtual void startBackdropScripts(Broadcast *broadcast) = 0;
67+
6568
/*! Stops the given script. */
6669
virtual void stopScript(VirtualMachine *vm) = 0;
6770

src/blocks/looksblocks.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ void LooksBlocks::compileSwitchBackdropToAndWait(Compiler *compiler)
388388
compiler->addFunctionCall(&switchBackdropToAndWait);
389389
}
390390

391+
compiler->addFunctionCall(&backdropNumber);
391392
compiler->addFunctionCall(&checkBackdropScripts);
392393
}
393394

@@ -750,7 +751,7 @@ void LooksBlocks::startBackdropScripts(VirtualMachine *vm, bool wait)
750751
{
751752
if (Stage *stage = vm->engine()->stage()) {
752753
if (stage->costumes().size() > 0)
753-
vm->engine()->broadcastByPtr(stage->currentCostume()->broadcast(), vm, wait);
754+
vm->engine()->startBackdropScripts(stage->currentCostume()->broadcast());
754755
}
755756
}
756757

@@ -894,11 +895,14 @@ unsigned int LooksBlocks::randomBackdropAndWait(VirtualMachine *vm)
894895
unsigned int LooksBlocks::checkBackdropScripts(VirtualMachine *vm)
895896
{
896897
if (Stage *stage = vm->engine()->stage()) {
897-
if ((stage->costumes().size() > 0) && vm->engine()->broadcastByPtrRunning(stage->currentCostume()->broadcast(), vm))
898+
long index = vm->getInput(0, 1)->toLong() - 1;
899+
assert(stage->costumes().size() == 0 || index >= 0);
900+
901+
if ((stage->costumes().size() > 0) && vm->engine()->broadcastByPtrRunning(stage->costumeAt(index)->broadcast(), vm))
898902
vm->stop(true, true, true);
899903
}
900904

901-
return 0;
905+
return 1;
902906
}
903907

904908
unsigned int LooksBlocks::goToFront(VirtualMachine *vm)

0 commit comments

Comments
 (0)