File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ ControlBlocks::ControlBlocks()
1717 addCompileFunction (" control_if_else" , &compileIfElseStatement);
1818 addCompileFunction (" control_stop" , &compileStop);
1919 addCompileFunction (" control_wait" , &compileWait);
20+ addCompileFunction (" control_wait_until" , &compileWaitUntil);
2021
2122 // Inputs
2223 addInput (" SUBSTACK" , SUBSTACK);
@@ -132,6 +133,13 @@ void ControlBlocks::compileWait(Compiler *compiler)
132133 compiler->addFunctionCall (&wait);
133134}
134135
136+ void ControlBlocks::compileWaitUntil (Compiler *compiler)
137+ {
138+ compiler->addInstruction (vm::OP_CHECKPOINT);
139+ compiler->addInput (CONDITION);
140+ compiler->addFunctionCall (&waitUntil);
141+ }
142+
135143unsigned int ControlBlocks::stopAll (VirtualMachine *vm)
136144{
137145 vm->engine ()->stop ();
@@ -164,4 +172,13 @@ unsigned int ControlBlocks::wait(VirtualMachine *vm)
164172 return 0 ;
165173}
166174
175+ unsigned int ControlBlocks::waitUntil (VirtualMachine *vm)
176+ {
177+ if (!vm->getInput (0 , 1 )->toBool ()) {
178+ vm->moveToLastCheckpoint ();
179+ vm->stop (true , true , false );
180+ }
181+ return 1 ;
182+ }
183+
167184} // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -44,12 +44,14 @@ class LIBSCRATCHCPP_EXPORT ControlBlocks : public IBlockSection
4444 static void compileIfElseStatement (Compiler *compiler);
4545 static void compileStop (Compiler *compiler);
4646 static void compileWait (Compiler *compiler);
47+ static void compileWaitUntil (Compiler *compiler);
4748
4849 private:
4950 static unsigned int stopAll (VirtualMachine *vm);
5051 static unsigned int stopOtherScriptsInSprite (VirtualMachine *vm);
5152 static unsigned int startWait (VirtualMachine *vm);
5253 static unsigned int wait (VirtualMachine *vm);
54+ static unsigned int waitUntil (VirtualMachine *vm);
5355
5456 static inline std::unordered_map<VirtualMachine *, std::pair<std::chrono::steady_clock::time_point, int >> m_timeMap;
5557};
You can’t perform that action at this time.
0 commit comments