torque Torque Game Engine Documentation
TGE Version 1.5.2

GameBase Class Reference

#include <gameBase.h>

Inheritance diagram for GameBase:

Inheritance graph
[legend]

Detailed Description

Base class for game objects which use datablocks, networking, are editable, and need to process ticks.

GameBase and ProcessList

GameBase adds two kinds of time-based updates. Torque works off of a concept of ticks. Ticks are slices of time 32 milliseconds in length. There are three methods which are used to update GameBase objects that are registered with the ProcessLists:
  • processTick(Move*) is called on each object once for every tick, regardless of the "real" framerate.
  • interpolateTick(float) is called on client objects when they need to interpolate to match the next tick.
  • advanceTime(float) is called on client objects so they can do time-based behaviour, like updating animations.

Torque maintains a server and a client processing list; in a local game, both are populated, while in multiplayer situations, either one or the other is populated.

You can control whether an object is considered for ticking by means of the setProcessTick() method.

GameBase and Datablocks

GameBase adds support for datablocks. Datablocks are secondary classes which store static data for types of game elements. For instance, this means that all "light human male armor" type Players share the same datablock. Datablocks typically store not only raw data, but perform precalculations, like finding nodes in the game model, or validating movement parameters.

There are three parts to the datablock interface implemented in GameBase:

  • getDataBlock(), which gets a pointer to the current datablock. This is mostly for external use; for in-class use, it's better to directly access the mDataBlock member.
  • setDataBlock(), which sets mDataBlock to point to a new datablock; it uses the next part of the interface to inform subclasses of this.
  • onNewDataBlock() is called whenever a new datablock is assigned to a GameBase.

Datablocks are also usable through the scripting language.

See also:
SimDataBlock for more details.

GameBase and Networking

writePacketData() and readPacketData() are called to transfer information needed for client side prediction. They are usually used when updating a client of its control object state.

Subclasses of GameBase usually transmit positional and basic status data in the packUpdate() functions, while giving velocity, momentum, and similar state information in the writePacketData().

writePacketData()/readPacketData() are called in addition to packUpdate/unpackUpdate().


Datablock

GameBaseDatamDataBlock
StringTableEntry mNameTag

Tick Processing Internals

U32 mProcessTag
 Tag used to sort objects for processing.
Link mProcessLink
 Ordered process queue link.
SimObjectPtr< GameBasemAfterObject
void plUnlink ()
void plLinkAfter (GameBase *)
void plLinkBefore (GameBase *)
void plJoin (GameBase *)

Inherited Functionality.

bool onAdd ()
 Called when the object is added to the sim.
void onRemove ()
 Called when the object is removed from the sim.
void inspectPostApply ()
 Called after any property of the object is changed in the world editor.
static void initPersistFields ()
 Register dynamic fields in a subclass of ConsoleObject.
static void consoleInit ()
 Register global constant variables and do other one-time initialization tasks in a subclass of ConsoleObject.

Datablock

bool setDataBlock (GameBaseData *dptr)
 Assigns this object a datablock and loads attributes with onNewDataBlock.
GameBaseDatagetDataBlock ()
 Returns the datablock for this object.
virtual bool onNewDataBlock (GameBaseData *dptr)
 Called when a new datablock is set.

Script

The scriptOnXX methods are invoked by the leaf classes

void scriptOnAdd ()
 Executes the 'onAdd' script function for this object.
void scriptOnNewDataBlock ()
 Executes the 'onNewDataBlock' script function for this object.
void scriptOnRemove ()
 Executes the 'onRemove' script function for this object.

Tick Processing

void setProcessTick (bool t)
 Set the status of tick processing.
void processAfter (GameBase *obj)
 Force this object to process after some other object.
void clearProcessAfter ()
 Clears the effects of a call to processAfter().
GameBasegetProcessAfter ()
 Returns the object that this processes after.
void removeFromProcessList ()
 Removes this object from the tick-processing list.
virtual void processTick (const Move *move)
 Processes a move event and updates object state once every 32 milliseconds.
virtual void interpolateTick (F32 delta)
 Interpolates between tick events.
virtual void advanceTime (F32 dt)
 Advances simulation time for animations.
virtual void preprocessMove (Move *move)
 This is a component system thing, gotta ask Clark about it.

Network

See also:
NetObject, NetConnection


F32 getUpdatePriority (CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips)
 This returns a value which is used to prioritize which objects need to be updated.
U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream)
 Instructs this object to pack its state for transfer over the network.
void unpackUpdate (NetConnection *conn, BitStream *stream)
 Instructs this object to read state data previously packed with packUpdate.
virtual void writePacketData (GameConnection *conn, BitStream *stream)
 Write state information necessary to perform client side prediction of an object.
virtual void readPacketData (GameConnection *conn, BitStream *stream)
 Read data written with writePacketData() and update the object state.
virtual U32 getPacketDataChecksum (GameConnection *conn)
 Gets the checksum for packet data.

User control

GameConnectiongetControllingClient ()
 Returns the client controling this object.
virtual void setControllingClient (GameConnection *client)
 Sets the client controling this object.

Public Types

enum  GameBaseMasks {
  InitialUpdateMask = Parent::NextFreeMask,
  DataBlockMask = InitialUpdateMask << 1,
  ExtendedInfoMask = DataBlockMask << 1,
  ControlMask = ExtendedInfoMask << 1,
  NextFreeMask = ControlMask << 1
}

Public Member Functions

 GameBase ()
virtual ~GameBase ()
void drawBoundingBox (bool useRenderTransform=false)
 Draws a bounding box around this object.
 DECLARE_CONOBJECT (GameBase)

Static Public Attributes

static bool gShowBoundingBox
 Should we render bounding boxes?

Protected Attributes

bool mProcessTick
F32 mLastDelta
F32 mCameraFov

Private Types

typedef SceneObject Parent

Private Attributes

GameConnectionmControllingClient

Friends

class ProcessList

Data Structures

struct  Link


Member Typedef Documentation


Member Enumeration Documentation

Enumerator:
InitialUpdateMask 
DataBlockMask 
ExtendedInfoMask 
ControlMask 
NextFreeMask 


Constructor & Destructor Documentation

GameBase::GameBase (  ) 

virtual GameBase::~GameBase (  )  [virtual]


Member Function Documentation

void GameBase::plUnlink (  )  [private]

void GameBase::plLinkAfter ( GameBase  )  [private]

void GameBase::plLinkBefore ( GameBase  )  [private]

void GameBase::plJoin ( GameBase  )  [private]

void GameBase::inspectPostApply (  )  [virtual]

Called after any property of the object is changed in the world editor.

See also:
inspectPreApply

Reimplemented from SceneObject.

Reimplemented in fxLight, Precipitation, MissionMarker, SpawnSphere, StaticShape, sgLightObject, sgMissionLightingFilter, and volumeLight.

static void GameBase::consoleInit (  )  [static]

Register global constant variables and do other one-time initialization tasks in a subclass of ConsoleObject.

Deprecated:
You should use ConsoleMethod and ConsoleFunction, not this, to register methods or commands.
See also:
console

Reimplemented from ConsoleObject.

Reimplemented in Camera, Item, PathCamera, Player, ShapeBase, and volumeLight.

bool GameBase::setDataBlock ( GameBaseData dptr  ) 

Assigns this object a datablock and loads attributes with onNewDataBlock.

See also:
onNewDataBlock
Parameters:
dptr Datablock

GameBaseData* GameBase::getDataBlock (  )  [inline]

Returns the datablock for this object.

Reimplemented in ParticleEmitter.

virtual bool GameBase::onNewDataBlock ( GameBaseData dptr  )  [virtual]

Called when a new datablock is set.

This allows subclasses to appropriately handle new datablocks.

See also:
setDataBlock()
Parameters:
dptr New datablock

Reimplemented in Debris, FireballAtmosphere, Explosion, fxLight, Lightning, ParticleEmitterNode, ParticleEmitter, Precipitation, Splash, WeatherLightning, Item, MissionMarker, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, PathedInterior, sgLightObject, and sgMissionLightingFilter.

void GameBase::scriptOnAdd (  ) 

Executes the 'onAdd' script function for this object.

Note:
This must be called after everything is ready

void GameBase::scriptOnNewDataBlock (  ) 

Executes the 'onNewDataBlock' script function for this object.

Note:
This must be called after everything is loaded.

void GameBase::scriptOnRemove (  ) 

Executes the 'onRemove' script function for this object.

Note:
This must be called while the object is still valid

void GameBase::setProcessTick ( bool  t  )  [inline]

Set the status of tick processing.

If this is set to true, processTick will be called; if false, then it will be skipped.

See also:
processTick
Parameters:
t If true, tick processing is enabled.

void GameBase::processAfter ( GameBase obj  ) 

Force this object to process after some other object.

For example, a player mounted to a vehicle would want to process after the vehicle, to prevent a visible "lagging" from occuring when the vehicle motions, so the player would be set to processAfter(theVehicle);

Parameters:
obj Object to process after

void GameBase::clearProcessAfter (  ) 

Clears the effects of a call to processAfter().

GameBase* GameBase::getProcessAfter (  )  [inline]

Returns the object that this processes after.

See also:
processAfter

void GameBase::removeFromProcessList (  )  [inline]

Removes this object from the tick-processing list.

virtual void GameBase::processTick ( const Move move  )  [virtual]

Processes a move event and updates object state once every 32 milliseconds.

This takes place both on the client and server, every 32 milliseconds (1 tick).

See also:
ProcessList
Parameters:
move Move event corresponding to this tick, or NULL.

Reimplemented in Camera, Debris, Explosion, fxLight, Lightning, ParticleEmitter, Precipitation, Splash, WeatherLightning, Item, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, Vehicle, WheeledVehicle, PathedInterior, and sgLightObject.

virtual void GameBase::interpolateTick ( F32  delta  )  [virtual]

Interpolates between tick events.

This takes place on the CLIENT ONLY.

Parameters:
delta Time since last call to interpolate

Reimplemented in Camera, Lightning, Precipitation, Item, PathCamera, Player, Projectile, RigidShape, StaticShape, and Vehicle.

virtual void GameBase::advanceTime ( F32  dt  )  [virtual]

Advances simulation time for animations.

This is called every frame.

Parameters:
dt Time since last advance call

Reimplemented in Debris, FireballAtmosphere, Explosion, Lightning, ParticleEmitterNode, ParticleEmitter, Splash, WeatherLightning, Player, Projectile, RigidShape, ShapeBase, FlyingVehicle, HoverVehicle, Vehicle, and WheeledVehicle.

virtual void GameBase::preprocessMove ( Move move  )  [inline, virtual]

This is a component system thing, gotta ask Clark about it.

void GameBase::drawBoundingBox ( bool  useRenderTransform = false  ) 

Draws a bounding box around this object.

F32 GameBase::getUpdatePriority ( CameraScopeQuery focusObject,
U32  updateMask,
S32  updateSkips 
) [virtual]

This returns a value which is used to prioritize which objects need to be updated.

In NetObject, our returned priority is 0.1 * updateSkips, so that less recently updated objects are more likely to be updated.

In subclasses, this can be adjusted. For instance, ShapeBase provides priority based on proximity to the camera.

Parameters:
focusObject Information from a previous call to onCameraScopeQuery.
updateMask Current update mask.
updateSkips Number of ticks we haven't been updated for.
Returns:
A floating point value indicating priority. These are typically < 5.0.

Reimplemented from NetObject.

Reimplemented in Projectile, and ShapeBase.

U32 GameBase::packUpdate ( NetConnection conn,
U32  mask,
BitStream stream 
) [virtual]

Instructs this object to pack its state for transfer over the network.

Parameters:
conn Net connection being used
mask Mask indicating fields to transmit.
stream Bitstream to pack data to
Returns:
Any bits which were not dealt with. The value is stored by the networking system. Don't set bits you weren't passed.

Reimplemented from NetObject.

Reimplemented in Camera, FireballAtmosphere, fxLight, Lightning, ParticleEmitterNode, Precipitation, Splash, WeatherLightning, Item, MissionMarker, SpawnSphere, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, PathedInterior, sgLightObject, sgMissionLightingFilter, and volumeLight.

void GameBase::unpackUpdate ( NetConnection conn,
BitStream stream 
) [virtual]

Instructs this object to read state data previously packed with packUpdate.

Parameters:
conn Net connection being used
stream stream to read from

Reimplemented from NetObject.

Reimplemented in Camera, FireballAtmosphere, fxLight, Lightning, ParticleEmitterNode, Precipitation, Splash, WeatherLightning, Item, MissionMarker, SpawnSphere, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, PathedInterior, sgLightObject, sgMissionLightingFilter, and volumeLight.

virtual void GameBase::writePacketData ( GameConnection conn,
BitStream stream 
) [virtual]

Write state information necessary to perform client side prediction of an object.

This information is sent only to the controling object. For example, if you are a client controlling a Player, the server uses writePacketData() instead of packUpdate() to generate the data you receive.

Parameters:
conn Connection for which we're generating this data.
stream Bitstream for output.

Reimplemented in Camera, Player, RigidShape, ShapeBase, FlyingVehicle, Vehicle, and WheeledVehicle.

virtual void GameBase::readPacketData ( GameConnection conn,
BitStream stream 
) [virtual]

Read data written with writePacketData() and update the object state.

Parameters:
conn Connection for which we're generating this data.
stream Bitstream to read.

Reimplemented in Camera, Player, RigidShape, ShapeBase, FlyingVehicle, Vehicle, and WheeledVehicle.

virtual U32 GameBase::getPacketDataChecksum ( GameConnection conn  )  [virtual]

Gets the checksum for packet data.

Basically writes a packet, does a CRC check on it, and returns that CRC.

See also:
writePacketData
Parameters:
conn Game connection

Reimplemented in ShapeBase.

GameConnection* GameBase::getControllingClient (  )  [inline]

Returns the client controling this object.

virtual void GameBase::setControllingClient ( GameConnection client  )  [virtual]

Sets the client controling this object.

Parameters:
client Client that is now controling this object

Reimplemented in Player.

GameBase::DECLARE_CONOBJECT ( GameBase   ) 


Friends And Related Function Documentation

friend class ProcessList [friend]

Reimplemented from NetObject.


Field Documentation

Tag used to sort objects for processing.

Ordered process queue link.

Should we render bounding boxes?

bool GameBase::mProcessTick [protected]

Reimplemented in ShapeBase.




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