Interface ITimerService
ITimerService manages the Subscribe(ITimerListener) and Unsubscribe(ITimerListener) of ITimerListeners and notify them when time updates or timed events happen.
Namespace: IdleKit.Framework
Assembly: cs.temp.dll.dll
Syntax
public interface ITimerService : IService, IInjectable
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 |
systemTime
Get the absolute UTC current DateTime of the app used in non-game specific functionality such as calculating the time the user is offline. Override this function to provide an alternate source for the system time such as an unified time from a backend service.
It is important to make sure this time is always up-to-date for every frame if this property is overriden as this value is used to set the gameTime every frame.
Declaration
DateTime systemTime { get; }
Property Value
Type | Description |
---|---|
DateTime |
systemTimestamp
Get the timestamp derived from systemTime in milliseconds.
Declaration
long systemTimestamp { get; }
Property Value
Type | Description |
---|---|
Int64 |
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)
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 |