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

    Fields
    Modifier and Type Field Description
    float fps
    The fixed frame rate when not in real time.
    double hdiff
    The hour difference from the last frame
    java.time.Instant time
    The current time of the clock
    double timeWarp
    Represents the time wrap multiplier.
  • Constructor Summary

    Constructors
    Constructor Description
    GlobalClock​(double timeWrap, java.time.Instant instant)
    Creates a new GlobalClock
  • Method Summary

    Modifier and Type Method Description
    double getDt()
    Provides the time difference in hours
    float getFixedRate()
    Returns the fixed frame rate if the mode is fixed frame rate.
    java.time.Instant getTime()
    Gets the current time
    double getWarpFactor()
    Gets the current warp factor
    boolean isFixedRateMode()
    Returns whether the frame rate is set to fixed or not
    boolean isTimeOn()
    Is the time on?
    void notify​(Events event, java.lang.Object... data)  
    void setTimeWarp​(double tw)  
    void update​(double dt)
    Update function

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • time

      public java.time.Instant time
      The current time of the clock
    • hdiff

      public double hdiff
      The hour difference from the last frame
    • timeWarp

      public double timeWarp
      Represents the time wrap multiplier. Scales the real time
    • fps

      public float fps
      The 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 multiplier
      instant - The instant with which to initialise the clock
  • Method Details

    • update

      public void update​(double dt)
      Update function
      Specified by:
      update in interface ITimeFrameProvider
      Parameters:
      dt - Delta time in seconds
    • getTime

      public java.time.Instant getTime()
      Description copied from interface: ITimeFrameProvider
      Gets the current time
      Specified by:
      getTime in interface ITimeFrameProvider
      Returns:
      The time as an instant
    • notify

      public void notify​(Events event, java.lang.Object... data)
      Specified by:
      notify in interface IObserver
    • setTimeWarp

      public void setTimeWarp​(double tw)
    • getDt

      public double getDt()
      Provides the time difference in hours
      Specified by:
      getDt in interface ITimeFrameProvider
      Returns:
      The time difference
    • getWarpFactor

      public double getWarpFactor()
      Description copied from interface: ITimeFrameProvider
      Gets the current warp factor
      Specified by:
      getWarpFactor in interface ITimeFrameProvider
      Returns:
      The warp factor
    • isFixedRateMode

      public boolean isFixedRateMode()
      Description copied from interface: ITimeFrameProvider
      Returns whether the frame rate is set to fixed or not
      Specified by:
      isFixedRateMode in interface ITimeFrameProvider
      Returns:
      Whether fix rate mode is on
    • getFixedRate

      public float getFixedRate()
      Description copied from interface: ITimeFrameProvider
      Returns the fixed frame rate if the mode is fixed frame rate. Returns -1 otherwise
      Specified by:
      getFixedRate in interface ITimeFrameProvider
      Returns:
      The fixed rate
    • isTimeOn

      public boolean isTimeOn()
      Description copied from interface: ITimeFrameProvider
      Is the time on?
      Specified by:
      isTimeOn in interface ITimeFrameProvider
      Returns:
      True if time is on