X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2FLogicExecuter.java;h=a7f8c83144d639c0c9f329c5e1cc4867f3fad149;hb=b456eecf8d1563c7e0ca64a5bc2cf146173dc3ff;hp=c0cfeb11c55d56639a784cd9ffa97bc1f37ef1d2;hpb=f554922e3f6ff7bf776101039f30c1e5a2106b2c;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicExecuter.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicExecuter.java index c0cfeb11..a7f8c831 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicExecuter.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicExecuter.java @@ -5,6 +5,7 @@ import java.util.concurrent.atomic.AtomicLong; 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 @@ -42,7 +43,11 @@ public class LogicExecuter while (shouldBeRunningLive.get()) { long current = tf.getTime(); - timeline.executeUntil(timeline.laterThan(current), System.currentTimeMillis() + 10); + // 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()) @@ -62,7 +67,7 @@ public class LogicExecuter } } 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 } } } @@ -78,8 +83,11 @@ public class LogicExecuter 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()); @@ -132,6 +140,11 @@ public class LogicExecuter return isPaused.get(); } + public double getSpeedFactor() + { + return tf.getSpeedFactor(); + } + public void setSpeedFactor(double factor) { tf.setSpeedFactor(factor);