0

I am new to JavaFX, sorry if this question has been answered before. But to the best of my knowlage it has not :)

I am making a grid based simulation of a swarm intelligence system. For each time tick i am storing the current state of the simulation, and calculating the next one. The simulation can potentially take quite some time to finish.

I want to be able to display the current state of the simulation, as it occurs, using JavaFX. I would also like to do a "playback" of the entire simulation after it is complete.

Now as i have understood it large portions of work should be done in a Task as to not freeze up the JavaFX Application thread. But i am not able to see how i can achieve the desired functionality using the updateValue() and the return statement of the call() function in Task.

In addition i would like to throttle both the "live" display of the simulation and the playback, as to display each tick in a suitable speed.

What I imagen would work is to have some kind of observable result queue that the background Task could populate with states, and the JavaFX Application thread could pop states of and display as needed. But this i don't know how to do.

Thanks in advance :)

MoeRum
  • 15
  • 2
  • http://stackoverflow.com/questions/22772379/updating-ui-from-different-threads-in-javafx – fabian Oct 18 '16 at 13:04
  • Stephen van Impe has a very good two-part blog post on game/simulation loops in JavaFX which might be useful. You might need to combine it with some background thread work to keep the UI responsive, but it should be useful material to read nonetheless. [Part 1](http://svanimpe.be/blog/game-loops.html) and [Part 2](http://svanimpe.be/blog/game-loops-fx.html). – James_D Oct 18 '16 at 13:49

0 Answers0