Skip to content

Commit 906d358

Browse files
committed
Compiler: Add warp method
1 parent 6b8f1e2 commit 906d358

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/engine/compiler.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void Compiler::compile(std::shared_ptr<Block> topLevelBlock)
2121
m_bytecode.clear();
2222
m_procedurePrototype = nullptr;
2323
m_atomic = true;
24+
m_warp = false;
2425

2526
// Add start instruction
2627
addInstruction(OP_START);
@@ -184,12 +185,20 @@ void Compiler::moveToSubstack(std::shared_ptr<Block> substack, SubstackType type
184185
/*!
185186
* Adds the vm::OP_BREAK_ATOMIC instruction at the end of the current loop.
186187
* This can be used for example in motion blocks.
188+
* \note Nothing will happen if the script is set to run without screen refresh.
187189
*/
188190
void Compiler::breakAtomicScript()
189191
{
190192
m_atomic = false;
191193
}
192194

195+
/*! Makes current script run without screen refresh. */
196+
void Compiler::warp()
197+
{
198+
m_warp = true;
199+
addInstruction(vm::OP_WARP);
200+
}
201+
193202
/*! Returns the input with the given ID. */
194203
Input *Compiler::input(int id) const
195204
{
@@ -231,6 +240,7 @@ unsigned int Compiler::listIndex(std::shared_ptr<IEntity> listEntity)
231240
return m_lists.size() - 1;
232241
}
233242

243+
/*! Returns the index of the given constant input value. */
234244
unsigned int Compiler::constIndex(InputValue *value)
235245
{
236246
auto it = std::find(m_constValues.begin(), m_constValues.end(), value);
@@ -271,7 +281,8 @@ void Compiler::substackEnd()
271281
switch (parent.second) {
272282
case SubstackType::Loop:
273283
if (!m_atomic) {
274-
addInstruction(OP_BREAK_ATOMIC);
284+
if (!m_warp)
285+
addInstruction(OP_BREAK_ATOMIC);
275286
m_atomic = true;
276287
}
277288
addInstruction(OP_LOOP_END);

src/engine/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
4343
void moveToSubstack(std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2, SubstackType type);
4444
void moveToSubstack(std::shared_ptr<Block> substack, SubstackType type);
4545
void breakAtomicScript();
46+
void warp();
4647

4748
Input *input(int id) const;
4849
Field *field(int id) const;
@@ -75,6 +76,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
7576
std::unordered_map<std::string, std::vector<std::string>> m_procedureArgs;
7677
BlockPrototype *m_procedurePrototype = nullptr;
7778
bool m_atomic;
79+
bool m_warp;
7880
};
7981

8082
} // namespace libscratchcpp

0 commit comments

Comments
 (0)