X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftimeline%2FTimeline.java;h=12cf5bd15dca6796789cc8f8e92f782ea4a9d3b7;hb=HEAD;hp=5fcb111e78f26c42cfd8c2709f1da32bc732714c;hpb=8d10ce10f3f33a16b743e4be08634ac959aa9ca0;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/Timeline.java b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/Timeline.java index 5fcb111e..12cf5bd1 100644 --- a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/Timeline.java +++ b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/Timeline.java @@ -16,7 +16,7 @@ public class Timeline { private PriorityQueue events; private TimeFunction time; - private long lastTimeUpdated = 0; + private long processedUntil = 0; private long eventCounter = 0; private final List> eventAddedListener; @@ -27,13 +27,13 @@ public class Timeline @Override public void setTime(long time) { - lastTimeUpdated = time; + processedUntil = time; } @Override public long getTime() { - return lastTimeUpdated; + return processedUntil; } }; public final TimeFunction realTimeExec = new TimeFunction() @@ -119,7 +119,7 @@ public class Timeline { if (events.isEmpty()) { - lastTimeUpdated = getSimulationTime(); + processedUntil = getSimulationTime(); return ExecutionResult.NOTHING_DONE; } working(); @@ -131,19 +131,18 @@ public class Timeline { event = events.remove(); } - lastTimeUpdated = event.getTiming(); + processedUntil = event.getTiming(); event.run(); // Don't check after every run checkStop = (checkStop + 1) % 10; if (checkStop == 0 && System.currentTimeMillis() >= stopMillis) { notWorking(); - lastTimeUpdated = getSimulationTime(); return ExecutionResult.EXEC_OUT_OF_TIME; } } notWorking(); - lastTimeUpdated = getSimulationTime(); + processedUntil = getSimulationTime(); return hasNext() ? ExecutionResult.EXEC_UNTIL_EMPTY : ExecutionResult.EXEC_UNTIL_CONDITION; } @@ -165,7 +164,7 @@ public class Timeline */ public long getSimulationTime() { - return isWorking() ? lastTimeUpdated : time.getTime(); + return isWorking() ? processedUntil : time.getTime(); } /** @@ -189,7 +188,7 @@ public class Timeline { events.clear(); } - lastTimeUpdated = time.getTime(); + processedUntil = time.getTime(); } /** @@ -288,7 +287,7 @@ public class Timeline { eventsString = events.toString(); } - return String.format("Simulation time: %s, Last update: %d, Events: %s", getSimulationTime(), lastTimeUpdated, eventsString); + return String.format("Simulation time: %s, Last update: %d, Events: %s", getSimulationTime(), processedUntil, eventsString); } public static enum ExecutionResult @@ -302,4 +301,12 @@ public class Timeline void setTime(long time); } + + /** + * Sets the time of the {@link TimeFunction} to the timestamp of the latest processed event + */ + public void synchTime() + { + time.setTime(processedUntil); + } } \ No newline at end of file