-
Notifications
You must be signed in to change notification settings - Fork 7
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
paintCanvas is called continuously #62
Comments
And here's the offending code in // Checks if the galtonBoard has been initially painted and if not then paint it.
if ( !this.galtonBoardNode.isInitiallyPainted ) {
this.galtonBoardNode.invalidatePaint();
}
// update view on model step
this.ballsNode.invalidatePaint(); |
|
2 fundamental problems with this sim: (1) It doesn't adhere to the MVC pattern. For the balls, the view isn't notified when the model has changed. Instead, the view redraws itself on every frame (by calling (2) The sim is relying on the call to |
Fixed fundamental problem (2) above, so that the |
…bins were being drawn when histogram mode === 'fraction', '#62
Fundamental problem (1) above was not possible to fix. Doing so would have involved fundamental changes to the model, would have surely destabilized the sim, and was ultimately not worth the effort. Instead, I added a workaround, summarized as follows: • The model So the sim still isn't following the MVC pattern - the model isn't notifying the view when it has changed. But at least the view can consult the model on each time step, and ask it whether the balls need to be redrawn. |
The above fixes are demonstrated in this dev version: |
Tested on iPad2 (mobile Safari) and Mac OS X (Chrome, Safari, Firefox). With the exception of the Play button (#26) everything feels smooth and responsive. Closing this issue. |
Reopening because I had another thought about a different way to address this that is more MVC-like. Instead of setting a flag in the model, have an emitter in the model that fires whenever at least 1 ball has moved. BallNode would observe this emitter and call invalidatePaint when it fires. So the model would be informing the view, rather than the view polling the model. |
There's also a bug in the previous approach. The erase button is not erasing the ball, it needs to call BallsNode.invalidatePaint. |
New approach implemented in above commit. The model now uses an Emitter to notify the view when the balls have moved, and thus need to be redrawn. This approach conforms to the MVC pattern. (Also fixed the issue with the erase button.) Demonstrated in this dev version: Closing. |
As soon as a screen is selected on the Home screen,
BallsLayerNode.paintCanvas
andGaltonBoardNode.paintCanvas
are called continuously. This occurs without having otherwise interacted with the sim, and there's nothing visibly changing on the screen.The text was updated successfully, but these errors were encountered: