torque Torque Game Engine Documentation
TGE Version 1.5.2

ITickable Class Reference

#include <iTickable.h>

Inheritance diagram for ITickable:

Inheritance graph
[legend]

Detailed Description

This interface allows you to let any object be ticked.

You use it like so:

 class FooClass : public SimObject, public virtual ITickable
 {
    // You still mark SimObject as Parent
    typdef SimObject Parent;
 private:
 ...

 protected:
    // These three methods are the interface for ITickable
    virtual void interpolateTick( F32 delta );
    virtual void processTick();
    virtual void advanceTime( F32 timeDelta );

 public:
 ...
 };
Please note the three methods you must implement to use ITickable, 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 ITickable, the compiler will probably also tell you if you forget that. Last, but assuridly not least is that you note the way that the inheretance is done: public virtual ITickable It is very important that you keep the virtual keyword in there, otherwise proper behavior is not guarenteed. 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 ITickable 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 recieve 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 framerate. So you may get 200 advanceTime calls in a second, or you may only get 20. There is no way of assuring consistant 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 ITickable 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. You can see in the code for ITickable::advanceTime that before a tick occurs it calls interpolateTick(0) on every object. This is to tell objects which do interpolate between ticks to reset their interpolation because they are about to get a new tick.

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 ITickable


Public Member Functions

 ITickable ()
 Constructor This will add the object to the process list.
virtual ~ITickable ()
 Destructor Remove this object from the process list.
virtual bool isProcessingTicks () const
 Is this object wanting to receive tick notifications.
virtual void setProcessTicks (bool tick=true)
 Sets this object as either tick processing or not tick True if this object should process ticks.

Static Public Member Functions

static bool advanceTime (U32 timeDelta)
 This is called in clientProcess to advance the time for all ITickable objects.

Static Public Attributes

static const U32 smTickShift
 Shift value to control how often Ticks occur.
static const U32 smTickMs
 Number of milliseconds per tick, 32 in this case.
static const F32 smTickSec
 Fraction of a second per tick.
static const U32 smTickMask

Protected Member Functions

virtual void interpolateTick (F32 delta)=0
 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.
virtual void processTick ()=0
 This method is called once every 32ms if isProcessingTicks returns true when called on the object.
virtual void advanceTime (F32 timeDelta)=0
 This method is called once every frame regardless of the return value of isProcessingTicks and informs the object of the passage of time.

Protected Attributes

bool mProcessTick
 Set to true if this object wants tick processing.

Private Types

typedef Vector< ITickable
* >::iterator 
ProcessListIterator

Static Private Member Functions

static Vector< ITickable * > & getProcessList ()
 Returns a reference to the list of all ITickable objects.

Static Private Attributes

static U32 smLastTick
 Time of the last tick that occurred.
static U32 smLastTime
 Last time value at which advanceTime was called.
static U32 smLastDelta
 Last delta value for advanceTime.


Member Typedef Documentation

typedef Vector<ITickable *>::iterator ITickable::ProcessListIterator [private]


Constructor & Destructor Documentation

ITickable::ITickable (  ) 

Constructor This will add the object to the process list.

virtual ITickable::~ITickable (  )  [virtual]

Destructor Remove this object from the process list.


Member Function Documentation

static Vector<ITickable *>& ITickable::getProcessList (  )  [static, private]

Returns a reference to the list of all ITickable objects.

virtual void ITickable::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 GuiEffectCanvas, GuiTickCtrl, and GuiVectorFieldCtrl.

virtual void ITickable::processTick (  )  [protected, pure virtual]

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

Implemented in GuiInspectorGroup, GuiMenuBar, GuiEffectCanvas, GuiTickCtrl, and GuiVectorFieldCtrl.

virtual void ITickable::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 GuiEffectCanvas, GuiTickCtrl, and GuiVectorFieldCtrl.

virtual bool ITickable::isProcessingTicks (  )  const [inline, virtual]

Is this object wanting to receive tick notifications.

Returns:
True if object wants tick notifications

void ITickable::setProcessTicks ( bool  tick = true  )  [inline, virtual]

Sets this object as either tick processing or not tick True if this object should process ticks.

static bool ITickable::advanceTime ( U32  timeDelta  )  [static]

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

Returns:
True if any ticks were sent
See also:
clientProcess


Field Documentation

U32 ITickable::smLastTick [static, private]

Time of the last tick that occurred.

U32 ITickable::smLastTime [static, private]

Last time value at which advanceTime was called.

U32 ITickable::smLastDelta [static, private]

Last delta value for advanceTime.

bool ITickable::mProcessTick [protected]

Set to true if this object wants tick processing.

const U32 ITickable::smTickShift [static]

Shift value to control how often Ticks occur.

const U32 ITickable::smTickMs [static]

Number of milliseconds per tick, 32 in this case.

const F32 ITickable::smTickSec [static]

Fraction of a second per tick.

const U32 ITickable::smTickMask [static]




All Rights Reserved GarageGames.com, Inc. 1999-2005
Auto-magically Generated with Doxygen