- Thread simulationThread = new Thread(() ->
- {
- // TODO find a better condition
- while (!ui.isDisposed())
- {
- // always execute to keep timeline from "hanging behind" for too long
- Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
- long sleepTime;
- if (Simulation.TIMELINE.hasNext())
- sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
- else
- sleepTime = 10;
- try
- {
- if (sleepTime > 0)
- Thread.sleep(sleepTime);
- }
- catch (InterruptedException e)
- {
- } // it is normal execution flow to be interrupted
- }
- });
- simulationThread.start();
+
+ // initialize executer
+ LogicExecuter exec = new LogicExecuter(timeline);
+
+ // run it
+ exec.startLiveExecution();
+
+ // TODO find a better condition when to stop
+ ui.addDisposeListener(e -> exec.stopLiveExecution());