Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Tickable Class Referenceabstract

`#include <Tickable.h>`

Inheritance diagram for Tickable:

## Public Member Functions
| Tickable ()
virtual | ~Tickable ()
virtual bool | isProcessingTicks () const
virtual void | setProcessTicks (bool tick=true)

## Static Public Member Functions
static bool | advanceTime (U32 timeDelta)

## Static Public Attributes
static const U32 | smTickShift = 4
| Shift value to control how often Ticks occur. More...
static const U32 | smTickMs = ( 1 << smTickShift )
| Number of milliseconds per tick, 32 in this case. More...
static const F32 | smTickSec = ( F32( Tickable::smTickMs ) / 1000.f )
| Fraction of a second per tick. More...
static const U32 | smTickMask = ( smTickMs - 1 )

## Protected Member Functions
virtual void | interpolateTick (F32 delta)=0
virtual void | processTick ()=0
virtual void | advanceTime (F32 timeDelta)=0

## Detailed Description

This interface allows you to let any object be ticked. You use it like so:

class FooClass : public SimObject, public virtual Tickable
{
// You still mark SimObject as Parent
typdef SimObject Parent;
private:
...
protected:
// These three methods are the interface for Tickable
virtual void interpolateTick( F32 delta );
virtual void processTick();
virtual void advanceTime( F32 timeDelta );
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

## Constructor & Destructor Documentation

Tickable | ( |  | ) |

Constructor This will add the object to the process list

~Tickable | ( |  | ) |
| virtual

Destructor Remove this object from the process list

## Member Function Documentation

virtual void advanceTime | ( | F32 | timeDelta | ) |
| protected pure virtual

This method is called once every frame regardless of the return value of isProcessingTicks and informs the object of the passage of time

Implemented in Scene, SceneWindow, ImageFrameProviderCore, RemoteDebuggerBase, GuiAutoScrollCtrl, GuiTickCtrl, and DefaultGame.

bool advanceTime | ( | U32 | timeDelta | ) |
| static

This is called in clientProcess to advance the time for all Tickable objects

Returns
  True if any ticks were sent

See also
  clientProcess

virtual void interpolateTick | ( | F32 | delta | ) |
| protected pure virtual

This method is called every frame and lets the control interpolate between ticks so you can smooth things as long as isProcessingTicks returns true when it is called on the object

Implemented in Scene, SceneWindow, ImageFrameProviderCore, RemoteDebuggerBase, GuiTickCtrl, and DefaultGame.

virtual bool isProcessingTicks | ( |  | ) | const
| inline virtual

Is this object wanting to receive tick notifications

Returns
  True if object wants tick notifications

virtual void processTick | ( |  | ) |
| protected pure virtual

This method is called once every 32ms if isProcessingTicks returns true when called on the object

Implemented in Scene, SceneWindow, GuiMenuBar, GuiRolloutCtrl, ImageFrameProviderCore, RemoteDebuggerBase, GuiAutoScrollCtrl, GuiTickCtrl, and DefaultGame.

void setProcessTicks | ( | bool | tick = `true` | ) |
| virtual

Sets this object as either tick processing or not

Parameters

  tick | True if this object should process ticks

Reimplemented in ImageFrameProviderCore.

## Member Data Documentation

const U32 smTickMask = ( smTickMs - 1 )
| static

const U32 smTickMs = ( 1 << smTickShift )
| static

Number of milliseconds per tick, 32 in this case.

const F32 smTickSec = ( F32( Tickable::smTickMs ) / 1000.f )
| static

Fraction of a second per tick.

const U32 smTickShift = 4
| static

Shift value to control how often Ticks occur.

The documentation for this class was generated from the following files:

- platform/Tickable.h
- platform/Tickable.cc