Class GlobalClock

java.lang.Object
gaiasky.util.time.GlobalClock
All Implemented Interfaces:
IObserver, ITimeFrameProvider

public class GlobalClock extends Object implements 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 Details

    • time

      public Instant time
      The current time of the clock
    • fps

      public float fps
      The fixed frame rate when not in real time. Set negative to use real time
    • warpSteps

      public final int warpSteps
      See Also:
  • Constructor Details

    • GlobalClock

      public GlobalClock(double timeWrap, Instant instant)
      Creates a new GlobalClock
      Parameters:
      timeWrap - The time wrap multiplier
      instant - 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:
      update in interface ITimeFrameProvider
      Parameters:
      dt - Delta time in seconds
    • getTime

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

      public void notify(Event event, Object source, Object... data)
      Description copied from interface: IObserver
      Event notification call.
      Specified by:
      notify in interface IObserver
      Parameters:
      event - The event type.
      source - The source object, if any.
      data - The data associated with this event.
    • findNearestWarpSnapValue

      public double findNearestWarpSnapValue(double value, double dir)
      Finds the nearest value in the timeWarpVector array 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:
      getHdiff in interface ITimeFrameProvider
      Returns:
      The simulation time difference in hours.
    • getDt

      public double getDt()
      Description copied from interface: ITimeFrameProvider
      The frame time difference in seconds.
      Specified by:
      getDt in interface ITimeFrameProvider
      Returns:
      The frame time difference in seconds.
    • 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