This interface allows you to let any object be ticked. You use it like so:
{
private:
...
protected:
public:
...
};
Please note the three methods you must implement to use Tickable, but don't worry. If you forget, the compiler will tell you so. Also note that the typedef for Parent should NOT BE SET to Tickable, the compiler will probably also tell you if you forget that. Last, but assuridly not least is that you note the way that the inheritance is done: public virtual Tickable It is very important that you keep the virtual keyword in there, otherwise proper behavior is not guaranteed. You have been warned.
The point of a tickable object is that the object gets ticks at a fixed rate which is one tick every 32ms. This means, also, that if an object doesn't get updated for 64ms, that the next update it will get two-ticks. Basically it comes down to this. You are assured to get one tick per 32ms of time passing provided that isProcessingTicks returns true when Tickable calls it.
isProcessingTicks is a virtual method and you can (should you want to) override it and put some extended functionality to decide if you want to receive tick-notification or not.
The other half of this is that you get time-notification from advanceTime. advanceTime lets you know when time passes regardless of the return value of isProcessingTicks. The object WILL get the advanceTime call every single update. The argument passed to advanceTime is the time since the last call to advanceTime. Updates are not based on the 32ms tick time. Updates are dependant on frame-rate. So you may get 200 advanceTime calls in a second, or you may only get 20. There is no way of assuring consistent calls of advanceTime like there is with processTick. Both are useful for different things, and it is important to understand the differences between them.
Interpolation is the last part of the Tickable interface. It is called every update, as long as isProcessingTicks evaluates to true on the object. This is used to interpolate between 32ms ticks. The argument passed to interpolateTick is the time since the last call to processTick.
This is an extremely powerful interface when used properly. An example of a class that properly uses this interface is GuiTickCtrl. The documentation for that class describes why it was created and why it was important that it use a consistant update frequency for its effects.
- See Also
- GuiTickCtrl
- Todo:
- Support processBefore/After and move the GameBase processing over to use Tickable