import net.mograsim.logic.core.timeline.PauseableTimeFunction;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.Timeline.ExecutionResult;
//TODO maybe move to logic core?
public class LogicExecuter
{
while (shouldBeRunningLive.get())
{
- long current = tf.getAsLong();
- timeline.executeUntil(timeline.laterThan(current), System.currentTimeMillis() + 10);
+ long current = tf.getTime();
+ // The tf.isPaused() condition is justified, because timeline.getSimulationTime() returns the timestamp of the last
+ // processed event during executeUntil()
+ if (timeline.executeUntil(() -> timeline.laterThan(current).getAsBoolean() || tf.isPaused(),
+ System.currentTimeMillis() + 10) == ExecutionResult.EXEC_OUT_OF_TIME)
+ timeline.synchTime(); // TODO: should this also be called if tf.isPaused() condition is met?
long nextEventTime = timeline.nextEventTime();
long sleepTime;
if (timeline.hasNext())
}
}
catch (@SuppressWarnings("unused") InterruptedException e)
- {// do nothing; it is normal execution flow to be interrupted
+ { // do nothing; it is normal execution flow to be interrupted
}
}
}
timeline.addEventAddedListener(event ->
{
if (isRunningLive.get())
- if (Timeline.timeCmp(event.getTiming(), nextExecSimulTime.get()) < 0)
+ {
+ long nextExecSimulTime = this.nextExecSimulTime.get();
+ if (nextExecSimulTime == -1 || Timeline.timeCmp(event.getTiming(), nextExecSimulTime) < 0)
simulationThread.interrupt();
+ }
});
// not optimal; but we don't expect this to happen very often
tf.addSimulTimeToRealTimeFactorChangedListener(d -> simulationThread.interrupt());
return isPaused.get();
}
+ public double getSpeedFactor()
+ {
+ return tf.getSpeedFactor();
+ }
+
public void setSpeedFactor(double factor)
{
tf.setSpeedFactor(factor);