Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse-dragging idiom does not work #151

Open
TheBizzle opened this issue Jun 10, 2015 · 9 comments
Open

Mouse-dragging idiom does not work #151

TheBizzle opened this issue Jun 10, 2015 · 9 comments
Labels

Comments

@TheBizzle
Copy link
Member

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 TheBizzle added the bug label Jun 10, 2015
@qiemem
Copy link
Member

qiemem commented Jun 10, 2015

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

@TheBizzle
Copy link
Member Author

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?

@qiemem
Copy link
Member

qiemem commented Jun 10, 2015

mouse-down? should check for incoming messages.

@birbilis
Copy link

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
Copy link

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

@birbilis
Copy link

@birbilis
Copy link

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
Copy link

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
Copy link

birbilis commented Sep 4, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants