|
14 | 14 | #include <scratchcpp/stringptr.h> |
15 | 15 | #include <scratchcpp/string_functions.h> |
16 | 16 | #include <scratchcpp/string_pool.h> |
| 17 | +#include <scratchcpp/itimer.h> |
17 | 18 | #include <utf8.h> |
18 | 19 |
|
19 | 20 | #include "sensingblocks.h" |
@@ -52,6 +53,7 @@ void SensingBlocks::registerBlocks(IEngine *engine) |
52 | 53 | engine->addCompileFunction(this, "sensing_setdragmode", &compileSetDragMode); |
53 | 54 | engine->addCompileFunction(this, "sensing_loudness", &compileLoudness); |
54 | 55 | engine->addCompileFunction(this, "sensing_loud", &compileLoud); |
| 56 | + engine->addCompileFunction(this, "sensing_timer", &compileTimer); |
55 | 57 | } |
56 | 58 |
|
57 | 59 | void SensingBlocks::onInit(IEngine *engine) |
@@ -225,6 +227,13 @@ CompilerValue *SensingBlocks::compileLoud(Compiler *compiler) |
225 | 227 | return compiler->createCmpGT(loudness, treshold); |
226 | 228 | } |
227 | 229 |
|
| 230 | +CompilerValue *SensingBlocks::compileTimer(Compiler *compiler) |
| 231 | +{ |
| 232 | + ITimer *timer = compiler->engine()->timer(); |
| 233 | + CompilerValue *timerPtr = compiler->addConstValue(timer); |
| 234 | + return compiler->addFunctionCall("sensing_timer", Compiler::StaticType::Number, { Compiler::StaticType::Pointer }, { timerPtr }); |
| 235 | +} |
| 236 | + |
228 | 237 | void SensingBlocks::onAnswer(const std::string &answer) |
229 | 238 | { |
230 | 239 | // https://github.com/scratchfoundation/scratch-vm/blob/6055823f203a696165084b873e661713806583ec/src/blocks/scratch3_sensing.js#L99-L115 |
@@ -415,3 +424,8 @@ extern "C" double sensing_loudness() |
415 | 424 | auto audioLoudness = SensingBlocks::audioInput->audioLoudness(); |
416 | 425 | return audioLoudness->getLoudness(); |
417 | 426 | } |
| 427 | + |
| 428 | +extern "C" double sensing_timer(ITimer *timer) |
| 429 | +{ |
| 430 | + return timer->value(); |
| 431 | +} |
0 commit comments