Tortoise icon indicating copy to clipboard operation
Tortoise copied to clipboard

Mouse-dragging idiom does not work

Open TheBizzle opened this issue 10 years ago • 9 comments

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.

TheBizzle avatar Jun 10 '15 18:06 TheBizzle

A better fix would be to off-load the engine to a web worker and then stream in ui events.

qiemem avatar Jun 10 '15 18:06 qiemem

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?

TheBizzle avatar Jun 10 '15 18:06 TheBizzle

mouse-down? should check for incoming messages.

qiemem avatar Jun 10 '15 18:06 qiemem

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?

birbilis avatar Jun 10 '15 20:06 birbilis

Instead of compiling to javascript a netlogo vm would maybe have made it easier to do such things

birbilis avatar Jul 23 '16 00:07 birbilis

There's a useful thread here: http://stackoverflow.com/questions/714942/how-to-stop-intense-javascript-loop-from-freezing-the-browser

birbilis avatar Jul 23 '16 00:07 birbilis

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

birbilis avatar Jul 23 '16 00:07 birbilis

Turboid core (standalone part from Turboid framework) mentioned at http://turboid.net/artikel/real-loops-in-javascript.php might be interesting to check out

birbilis avatar Jul 23 '16 00:07 birbilis

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

birbilis avatar Sep 04 '16 22:09 birbilis