From 147c1b4592b9f1d24680747469ebeba08df372de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 11 Mar 2019 13:51:01 +0100 Subject: [PATCH] [python/turtle] Make the turtle faster on emscripten It was slower than on the calculator --- python/port/mod/turtle/turtle.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/python/port/mod/turtle/turtle.cpp b/python/port/mod/turtle/turtle.cpp index 48d66c173..cb7cbb51e 100644 --- a/python/port/mod/turtle/turtle.cpp +++ b/python/port/mod/turtle/turtle.cpp @@ -323,11 +323,24 @@ bool Turtle::draw(bool force) { m_drawn = true; } - if (m_mileage > 1000) { + /* We sleep every time the turtle walks a mileageLimit amount, to allow user + * interruptions. The length of each sleep is determined by the speed of the + * turtle. + * With emscripten, sleep gives control to the web browser, which decides when + * to return from sleep: this makes the turtle significantly slower on the web + * emulator than on the calculator. We thus decided to sleep less often on the + * emscripten platform. */ +#if __EMSCRIPTEN__ + constexpr KDCoordinate mileageLimit = 10000; +#else + constexpr KDCoordinate mileageLimit = 1000; +#endif + + if (m_mileage > mileageLimit) { if (micropython_port_interruptible_msleep(1 + (m_speed == 0 ? 0 : 3 * (k_maxSpeed - m_speed)))) { return true; } - m_mileage -= 1000; + m_mileage -= mileageLimit; } return false; }