Mouse-dragging idiom does not work
Create a model with a go (forever) button, and give it this code:
to go
if (mouse-down?) [
while [mouse-down?] []
show "No more Mr. Mouse"
]
end
Click on the View. In JVM NetLogo, you will see the message "No more Mr. Mouse". In Tortoise, the code for that line will never be reached. The mouse is never given a chance to update whether it's down or not, since the JS for while [mouse-down] [] is a while loop that dominates control of the system.
This could maybe be fixed by actually having while compile to recursive(esque) setTimeout calls. It's kind of gross, but... it would maybe get us better NetLogo semantics. I'm not sure if that would work out well with how we're currently throwing StopInterrupts, though. The whole things a big mess of wonky control flow that doesn't translate well into JavaScript.
This problem also prevents Mouse Drag One Example from working correctly (since it, too, goes into an endless while loop).
Discovered while investigating #150.
A better fix would be to off-load the engine to a web worker and then stream in ui events.
I'm not sure that actually fixes the problem. You're still going to have the issue of the webworker never relinquishing control to read the UI event, aren't you?
mouse-down? should check for incoming messages.
There are some Javascript compilers that are supposed to implement ES6 features (ECMAScript 6) via current Javascript. How do they implement such things? Maybe you should output ES6 and pass on output to such compiler to give current Javascript?
Instead of compiling to javascript a netlogo vm would maybe have made it easier to do such things
There's a useful thread here: http://stackoverflow.com/questions/714942/how-to-stop-intense-javascript-loop-from-freezing-the-browser
Btw, we're not speaking of mousedown event handlers, just that you'd keep some flags so that when polled you know the mouse state
Turboid core (standalone part from Turboid framework) mentioned at http://turboid.net/artikel/real-loops-in-javascript.php might be interesting to check out
I don't see "requestAnimationFrame" mentioned here as potential solution. See the Timer.js from seajax PivotViewer (port of Silverlight PivotViewer to javascript by programmers of the original version) and the comments/code it has on "requestAnimationFrame" and usage with various browsers. Search for "requestAnimationFrame" in https://github.com/seajax/seajax/blob/master/v2/src/utils/Timer.js
an example of PivotViewer if you haven't seen it before is at http://seajax.github.io