Package gaiasky.util.time
Class GlobalClock
java.lang.Object
gaiasky.util.time.GlobalClock
- All Implemented Interfaces:
IObserver,ITimeFrameProvider
public class GlobalClock extends java.lang.Object implements IObserver, ITimeFrameProvider
Keeps pace of the simulation time vs real time and holds the global clock. It
uses a time warp factor which is a multiplier to real time.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description GlobalClock(double timeWrap, java.time.Instant instant)Creates a new GlobalClock -
Method Summary
Modifier and Type Method Description doublegetDt()Provides the time difference in hoursfloatgetFixedRate()Returns the fixed frame rate if the mode is fixed frame rate.java.time.InstantgetTime()Gets the current timedoublegetWarpFactor()Gets the current warp factorbooleanisFixedRateMode()Returns whether the frame rate is set to fixed or notbooleanisTimeOn()Is the time on?voidnotify(Events event, java.lang.Object... data)voidsetTimeWarp(double tw)voidupdate(double dt)Update functionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
time
public java.time.Instant timeThe current time of the clock -
hdiff
public double hdiffThe hour difference from the last frame -
timeWarp
public double timeWarpRepresents the time wrap multiplier. Scales the real time -
fps
public float fpsThe fixed frame rate when not in real time. Set negative to use real time
-
-
Constructor Details
-
GlobalClock
public GlobalClock(double timeWrap, java.time.Instant instant)Creates a new GlobalClock- Parameters:
timeWrap- The time wrap multiplierinstant- The instant with which to initialise the clock
-
-
Method Details
-
update
public void update(double dt)Update function- Specified by:
updatein interfaceITimeFrameProvider- Parameters:
dt- Delta time in seconds
-
getTime
public java.time.Instant getTime()Description copied from interface:ITimeFrameProviderGets the current time- Specified by:
getTimein interfaceITimeFrameProvider- Returns:
- The time as an instant
-
notify
-
setTimeWarp
public void setTimeWarp(double tw) -
getDt
public double getDt()Provides the time difference in hours- Specified by:
getDtin interfaceITimeFrameProvider- Returns:
- The time difference
-
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
-