Class GlobalClock
java.lang.Object
gaiasky.util.time.GlobalClock
- All Implemented Interfaces:
IObserver, ITimeFrameProvider
Implementation of a time frame provider that provides simulation times governed by a warp value, which informs
the speed at which time passes.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublefindNearestWarpSnapValue(double value, double dir) Finds the nearest value in thetimeWarpVectorarray in the given direction.double[]Generate the time warp vector with the default number of steps.double[]generateTimeWarpVector(int steps) Generate the time warp vector.doublegetDt()The frame time difference in seconds.floatReturns the fixed frame rate if the mode is fixed frame rate.doublegetHdiff()Provides the time difference in hoursgetTime()Gets the current time in UTC.doubleGets the time in seconds since 1970-01-01T00:00Z (ISO).doubleGets the current warp factorbooleanReturns whether the frame rate is set to fixed or notbooleanisTimeOn()Is the time on?doublenearestPowerOf2(double n, double dir) Finds the nearest power of two to n, in the given direction.voidEvent notification call.voidsetTimeWarp(double tw) voidupdate(double dt) Update function
-
Field Details
-
time
The current time of the clock -
fps
public float fpsThe fixed frame rate when not in real time. Set negative to use real time -
warpSteps
public final int warpSteps- See Also:
-
-
Constructor Details
-
GlobalClock
Creates a new GlobalClock- Parameters:
timeWrap- The time wrap multiplierinstant- The instant with which to initialise the clock
-
-
Method Details
-
generateTimeWarpVector
public double[] generateTimeWarpVector()Generate the time warp vector with the default number of steps.- Returns:
- The vector
-
generateTimeWarpVector
public double[] generateTimeWarpVector(int steps) Generate the time warp vector.- Parameters:
steps- The number of steps per side (positive and negative)- Returns:
- The vector
-
update
public void update(double dt) Update function- Specified by:
updatein interfaceITimeFrameProvider- Parameters:
dt- Delta time in seconds
-
getTime
Description copied from interface:ITimeFrameProviderGets the current time in UTC.- Specified by:
getTimein interfaceITimeFrameProvider- Returns:
- The time as an instant, in UTC.
-
getTimeSeconds
public double getTimeSeconds()Description copied from interface:ITimeFrameProviderGets the time in seconds since 1970-01-01T00:00Z (ISO).- Specified by:
getTimeSecondsin interfaceITimeFrameProvider- Returns:
- The seconds since 1970-01-01T00:00Z (ISO).
-
notify
-
findNearestWarpSnapValue
public double findNearestWarpSnapValue(double value, double dir) Finds the nearest value in thetimeWarpVectorarray in the given direction.- Parameters:
value- The value to use.dir- The direction, either 1 or -1.- Returns:
- The nearest snap value in the given direction.
-
nearestPowerOf2
public double nearestPowerOf2(double n, double dir) Finds the nearest power of two to n, in the given direction.- Parameters:
n- The number.dir- Direction. Either 1.0 or -1.0.- Returns:
- The nearest power of two to n.
-
setTimeWarp
public void setTimeWarp(double tw) -
getHdiff
public double getHdiff()Provides the time difference in hours- Specified by:
getHdiffin interfaceITimeFrameProvider- Returns:
- The simulation time difference in hours.
-
getDt
public double getDt()Description copied from interface:ITimeFrameProviderThe frame time difference in seconds.- Specified by:
getDtin interfaceITimeFrameProvider- Returns:
- The frame time difference in seconds.
-
getWarpFactor
public double getWarpFactor()Description copied from interface:ITimeFrameProviderGets the current warp factor- Specified by:
getWarpFactorin interfaceITimeFrameProvider- Returns:
- The warp factor
-
isFixedRateMode
public boolean isFixedRateMode()Description copied from interface:ITimeFrameProviderReturns whether the frame rate is set to fixed or not- Specified by:
isFixedRateModein interfaceITimeFrameProvider- Returns:
- Whether fix rate mode is on
-
getFixedRate
public float getFixedRate()Description copied from interface:ITimeFrameProviderReturns the fixed frame rate if the mode is fixed frame rate. Returns -1 otherwise- Specified by:
getFixedRatein interfaceITimeFrameProvider- Returns:
- The fixed rate
-
isTimeOn
public boolean isTimeOn()Description copied from interface:ITimeFrameProviderIs the time on?- Specified by:
isTimeOnin interfaceITimeFrameProvider- Returns:
- True if time is on
-