Timers are an integral part of any game, and AGE provides flexibility to create many different use cases.
Timers are Game Objects, so they must go through the Install Pipeline to connect with the timer service (and any other services).
Every timer has the following properties:
The timer service uses a time base tick (TBT) to control the passage of time on outstanding timers. A timer should make its duration a multiple of TBT. The TBT is the minimum time resolution of the service, and all timers are updated in batch each TBT period.
GOs opt-in to the timer service by implementing the IRequireTimerService interface. The Install Pipeline automatically calls the register() method and passes the GO.
The timer service uses the properties indicated in the timer GO to trigger the timer callback as specified. All timer callbacks are sent to the Game Cycle thread for execution.
Since the timer service can generate a continuous stream of many of messages, it accepts "used" messages back for recycling, to avoid excessive object creation. The Game Cycle thread automatically recycles timer event messages back to the Timer thread.
The Game Cycle receives all timer events. Since the primary purpose of timer events is to modify the game state at regular intervals, timer events are always executed with the update lock active.
The execute() method is where the work happens. If continuous this is called every time base tick, otherwise it is called on expiration. The execute() method has this signature:
Timer event callbacks do not directly reference any GOs; instead they are passed the Locator interface, so they can obtain GOs that they wish to read/write properties and/or invoke methods on.
Since all timer events are serialized, updates performed in a timer event callback can be considered atomic and isolated, i.e. another model update event cannot see "partial" updates of the game state.