Show / Hide Table of Contents

    Interface ITimerService

    ITimerService manages the Subscribe(ITimerListener) and Unsubscribe(ITimerListener) of ITimerListeners and notify them when time updates or timed events happen.

    Namespace: IdleKit.Gameplay
    Assembly: cs.temp.dll.dll
    Syntax
    public interface ITimerService : IService
    Remarks

    We have decided to not use the IActionService to send time related IAction. As timed events can be frequent and they need to be precise, the sending of such events should be done with direct subscription with the instance of the ITimerService.

    Properties

    GameTime

    Get the DateTime used to evaluate every game specific functionality including all the ITimerListeners.

    Declaration
    DateTime GameTime { get; }
    Property Value
    Type Description
    DateTime

    GameTimestamp

    Get the time stamp derived from GameTime in milliseconds. Useful for serialization.

    Declaration
    long GameTimestamp { get; }
    Property Value
    Type Description
    Int64

    Paused

    Is the GameTime paused from updating automatically at the moment.

    Declaration
    bool Paused { get; }
    Property Value
    Type Description
    Boolean

    TimerListeners

    Return the current ITimerListener subscribed to the ITimerService.

    Declaration
    ITimerListener[] TimerListeners { get; }
    Property Value
    Type Description
    ITimerListener[]

    Methods

    IsSubscribed(ITimerListener)

    Returns whether an ITimerListener that has been Subscribe(ITimerListener) to the ITimerService

    Declaration
    bool IsSubscribed(ITimerListener timerListener)
    Parameters
    Type Name Description
    ITimerListener timerListener
    Returns
    Type Description
    Boolean

    Pause()

    Pause the ITimerService prevent time from automatically updating causing it to be Paused.

    This is useful when the app enters background and time sensitive calculations need to be done before the ITimerService updates again.

    Declaration
    void Pause()
    Remarks

    In the default implementation of ITimerService, it is possible for Pause() to be called multiple times by different objects.

    Resume()

    Resume the ITimerService from Paused enable time to automatically update..

    This is useful when the app enters foreground and time sensitive calculations need to be done before the ITimerService updates again.

    Declaration
    void Resume()
    Remarks

    In the default implementation of ITimerService, it is possible for Resume() to be called multiple times by different objects.

    Internally, we keep track of an integer Pause() counter that increases every time it is called. The counter would decrease when Resume() is called and upon it reaching 0, the ITimerService would be to receive timed update.

    SetGameTimestamp(Int64)

    Set GameTime to the new time stamp timestamp so we can override the GameTime

    Declaration
    void SetGameTimestamp(long timestamp)
    Parameters
    Type Name Description
    Int64 timestamp

    Subscribe(ITimerListener)

    Subscribe an ITimerListener to the ITimerService. The interface methods of the ITimerListener will be invoked at the appropriate moments during the Duration.

    Declaration
    bool Subscribe(ITimerListener timerListener)
    Parameters
    Type Name Description
    ITimerListener timerListener
    Returns
    Type Description
    Boolean

    Unsubscribe(ITimerListener)

    Unsubscribe an ITimerListener from the ITimerService. It will no longer receive timed updates.

    Declaration
    bool Unsubscribe(ITimerListener timerListener)
    Parameters
    Type Name Description
    ITimerListener timerListener
    Returns
    Type Description
    Boolean
    Back to top Copyright © 2020 East Side Games Inc.