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;
{
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 double getSpeedFactor()
+ {
+ return 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();