projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch threads into development
[Mograsim.git]
/
plugins
/
net.mograsim.logic.core
/
src
/
net
/
mograsim
/
logic
/
core
/
timeline
/
PauseableTimeFunction.java
diff --git
a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/PauseableTimeFunction.java
b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/PauseableTimeFunction.java
index
f086268
..
7a6185e
100644
(file)
--- a/
plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/PauseableTimeFunction.java
+++ b/
plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/timeline/PauseableTimeFunction.java
@@
-3,13
+3,14
@@
package net.mograsim.logic.core.timeline;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
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;
{
private boolean paused = false;
private long unpausedSysTime = 0, lastPausedInternalTime = 0;
- private double speedFactor =
1
;
+ private double speedFactor =
0
;
private final List<Consumer<Double>> simulTimeToRealTimeFactorChangedListeners = new ArrayList<>();
private final List<Consumer<Double>> simulTimeToRealTimeFactorChangedListeners = new ArrayList<>();
@@
-17,7
+18,7
@@
public class PauseableTimeFunction implements LongSupplier
{
if (!paused)
{
{
if (!paused)
{
- lastPausedInternalTime = get
AsLong
();
+ lastPausedInternalTime = get
Time
();
paused = true;
}
}
paused = true;
}
}
@@
-32,21
+33,33
@@
public class PauseableTimeFunction implements LongSupplier
}
@Override
}
@Override
- public long get
AsLong
()
+ public long get
Time
()
{
return (long) (paused ? lastPausedInternalTime
: lastPausedInternalTime + (System.nanoTime() / 1000 - unpausedSysTime) * speedFactor);
}
{
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 / 1000d / speedFactor;
}
public double getSimulTimeToRealTimeFactor()
{
return 1 / 1000d / speedFactor;
}
+ public double getSpeedFactor()
+ {
+ return speedFactor;
+ }
+
public void setSpeedFactor(double factor)
{
if (factor <= 0)
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();
if (!paused)
{
pause();