projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
PauseableTimeFunction now supports non-integral speed factors
[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
86f4ce9
..
4a99310
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
@@
-6,7
+6,7
@@
public class PauseableTimeFunction implements LongSupplier
{
private boolean paused = false;
private long unpausedSysTime = 0, lastPausedInternalTime = 0;
{
private boolean paused = false;
private long unpausedSysTime = 0, lastPausedInternalTime = 0;
- private
int speedPercentage = 100
;
+ private
double speedFactor = 1
;
public void pause()
{
public void pause()
{
@@
-29,18
+29,25
@@
public class PauseableTimeFunction implements LongSupplier
@Override
public long getAsLong()
{
@Override
public long getAsLong()
{
- return paused ? lastPausedInternalTime
- : lastPausedInternalTime + (
(System.currentTimeMillis() - unpausedSysTime) * speedPercentage) / 100
;
+ return
(long) (
paused ? lastPausedInternalTime
+ : lastPausedInternalTime + (
System.currentTimeMillis() - unpausedSysTime) * speedFactor)
;
}
}
- public
void setSpeedPercentage(int percentag
e)
+ public
long simulTimeDeltaToRealTimeMillis(long simulTim
e)
{
{
+ return paused ? -1 : (long) (simulTime / speedFactor);
+ }
+
+ public void setSpeedFactor(double factor)
+ {
+ if (factor <= 0)
+ throw new IllegalArgumentException("time factor can't be smaller than 1");
if (!paused)
{
pause();
unpause();
}
if (!paused)
{
pause();
unpause();
}
- this.speed
Percentage = Integer.min(100, Integer.max(percentage, 1))
;
+ this.speed
Factor = factor
;
}
public boolean isPaused()
}
public boolean isPaused()