Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
authorFabian Stemmler <stemmler@in.tum.de>
Thu, 26 Sep 2019 21:49:15 +0000 (23:49 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Thu, 26 Sep 2019 21:49:15 +0000 (23:49 +0200)
1  2 
plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/PauseableTimeFunction.java

@@@ -3,10 -3,9 +3,10 @@@ package net.mograsim.logic.core.timelin
  import java.util.ArrayList;
  import java.util.List;
  import java.util.function.Consumer;
 -import java.util.function.LongSupplier;
  
 -public class PauseableTimeFunction implements LongSupplier
 +import net.mograsim.logic.core.timeline.Timeline.TimeFunction;
 +
 +public class PauseableTimeFunction implements TimeFunction
  {
        private boolean paused = false;
        private long unpausedSysTime = 0, lastPausedInternalTime = 0;
@@@ -18,7 -17,7 +18,7 @@@
        {
                if (!paused)
                {
 -                      lastPausedInternalTime = getAsLong();
 +                      lastPausedInternalTime = getTime();
                        paused = true;
                }
        }
        }
  
        @Override
 -      public long getAsLong()
 +      public long getTime()
        {
                return (long) (paused ? lastPausedInternalTime
                                : lastPausedInternalTime + (System.nanoTime() / 1000 - unpausedSysTime) * speedFactor);
        }
  
 +      @Override
 +      public void setTime(long time)
 +      {
 +              lastPausedInternalTime = time;
 +              unpausedSysTime = System.nanoTime() / 1000;
 +      }
 +
        public double getSimulTimeToRealTimeFactor()
        {
-               return 1 / 1000 / speedFactor;
+               return 1 / 1000d / speedFactor;
        }
  
        public void setSpeedFactor(double factor)
        {
                if (factor <= 0)
-                       throw new IllegalArgumentException("time factor can't be smaller than 1");
+                       throw new IllegalArgumentException("time factor can't be less than or equal to 0");
                if (!paused)
                {
                        pause();