Interface SimulationClock


  • public interface SimulationClock
    The simulation clock is responsible for producing the game and render ticks.
    Version:
    1.0
    Author:
    Tim Neumann, Tobias Wältken
    • Field Detail

      • RENDER_TICKS_PER_SIMULATION_TICK

        static final int RENDER_TICKS_PER_SIMULATION_TICK
        The number of render ticks per one simulation tick.
        See Also:
        Constant Field Values
      • DEFAULT_RENDER_TICK_PERIOD

        static final int DEFAULT_RENDER_TICK_PERIOD
        The render period, that is set by default.
        See Also:
        Constant Field Values
    • Method Detail

      • setPeriod

        void setPeriod​(int millis)
        Set the period of the render ticks. The game ticks will have this period times 8.
        Parameters:
        millis - The new period in milliseconds.
      • getRenderTickPeriod

        int getRenderTickPeriod()
        Get the period of the render ticks.
        Returns:
        The number of milliseconds per render tick period.
      • getGameTickPeriod

        int getGameTickPeriod()
        Get the period of the game ticks.
        Returns:
        The number of milliseconds per game tick period.
      • isRunning

        boolean isRunning()
        Query the clock if its running
        Returns:
        if the clock is running
      • start

        void start()
        Start ticking.
      • stop

        void stop()
        Stop ticking.

        Ticking can be started again with start()

      • step

        void step()
        Execute one single tick
      • registerTickListener

        void registerTickListener​(Function<Long,​Boolean> listener)
        Register a listener for simulation ticks.

        The listener get's the current tick count as an argument and must return whether it wants to continue to listen.

        Parameters:
        listener - The listener to be called.
      • registerPostTickListener

        void registerPostTickListener​(Function<Long,​Boolean> listener)
        Register a listener for the end of simulation ticks.

        The listener get's the current tick count as an argument and must return whether it wants to continue to listen.

        Parameters:
        listener - The listener to be called.
      • getLastTickNumber

        long getLastTickNumber()
        Returns:
        the number of the last simulation tick
      • getLastRenderTickNumber

        long getLastRenderTickNumber()
        Returns:
        the number of the last render tick
      • scheduleOperationAtTick

        void scheduleOperationAtTick​(long tick,
                                     CompletableFuture<Void> endOfOperation)
        Schedule an operation, to happen during the given tick. This method will block until that tick. Then the tick processing will halt until the given end of operation is completed.

        If the given tick is in the past, the operation will be scheduled for the next tick.

        Parameters:
        tick - The absolute number of the tick at which the operation will be run
        endOfOperation - Tick processing will be halted until this future is completed; must not complete exceptionally
        Throws:
        IllegalStateException - if the end of operation completes exceptionally
      • scheduleOperationInTicks

        void scheduleOperationInTicks​(long ticks,
                                      CompletableFuture<Void> endOfOperation)
        Schedule an operation, to happen during the tick a given number of ticks in the future. This method will block until that tick. Then the tick processing will halt until the given end of operation is completed.

        If the given number of ticks is less or equal to one, the operation is scheduled for the next tick.

        Parameters:
        ticks - The number of ticks until the tick, for which to schedule the operation
        endOfOperation - Tick processing will be halted until this future is completed; must not complete exceptionally
        Throws:
        IllegalStateException - if the end of operation completes exceptionally
      • scheduleOperationAtNextTick

        void scheduleOperationAtNextTick​(CompletableFuture<Void> endOfOperation)
        Schedule an operation, to happen during the next tick. This method will block until that tick. Then the tick processing will halt until the given end of operation is completed.
        Parameters:
        endOfOperation - Tick processing will be halted until this future is completed; must not complete exceptionally
        Throws:
        IllegalStateException - if the end of operation completes exceptionally