GameBase Class Reference

#include <gameBase.h>

Inheritance diagram for GameBase:

Inheritance graph
[legend]
List of all members.

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().


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.
ProcessObjectgetAfterObject ()
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)
 Allow object a chance to tweak move before it is sent to client and server.

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 controlling this object.
virtual void setControllingClient (GameConnection *client)
 Sets the client controlling this object.
virtual GameBasegetControllingObject ()
virtual GameBasegetControlObject ()
virtual void setControlObject (GameBase *)

Datablock

GameBaseDatamDataBlock
StringTableEntry mNameTag

Public Types

 InitialUpdateMask = Parent::NextFreeMask
 DataBlockMask = InitialUpdateMask << 1
 ExtendedInfoMask = DataBlockMask << 1
 ControlMask = ExtendedInfoMask << 1
 NextFreeMask = ControlMask << 1
 NetOrdered = BIT(Parent::MaxNetFlagBit+1)
 NetNearbyAdded = BIT(Parent::MaxNetFlagBit+2)
 GhostUpdated = BIT(Parent::MaxNetFlagBit+3)
 TickLast = BIT(Parent::MaxNetFlagBit+4)
 NewGhost = BIT(Parent::MaxNetFlagBit+5)
 HiFiPassive = BIT(Parent::MaxNetFlagBit+6)
 MaxNetFlagBit = Parent::MaxNetFlagBit+6
enum  GameBaseMasks {
  InitialUpdateMask = Parent::NextFreeMask,
  DataBlockMask = InitialUpdateMask << 1,
  ExtendedInfoMask = DataBlockMask << 1,
  ControlMask = ExtendedInfoMask << 1,
  NextFreeMask = ControlMask << 1
}
enum  {
  NetOrdered = BIT(Parent::MaxNetFlagBit+1),
  NetNearbyAdded = BIT(Parent::MaxNetFlagBit+2),
  GhostUpdated = BIT(Parent::MaxNetFlagBit+3),
  TickLast = BIT(Parent::MaxNetFlagBit+4),
  NewGhost = BIT(Parent::MaxNetFlagBit+5),
  HiFiPassive = BIT(Parent::MaxNetFlagBit+6),
  MaxNetFlagBit = Parent::MaxNetFlagBit+6
}

Public Member Functions

 GameBase ()
 ~GameBase ()
TickCachegetTickCache ()
void setGhostUpdated (bool b)
bool isGhostUpdated () const
void setNewGhost (bool n)
bool isNewGhost ()
virtual void computeNetSmooth (F32 backDelta)
virtual F32 getDefaultCameraFov ()
virtual F32 getCameraFov ()
virtual void setCameraFov (F32 fov)
virtual bool isValidCameraFov (F32 fov)
virtual bool useObjsEyePoint ()
virtual bool onlyFirstPerson ()
virtual F32 getDamageFlash ()
virtual F32 getWhiteOut ()
virtual void getCameraTransform (F32 *pos, MatrixF *mat)
 DECLARE_CONOBJECT (GameBase)

Static Public Attributes

static bool gShowBoundingBox
 Should we render bounding boxes?

Protected Attributes

bool mProcessTick
F32 mCameraFov

Private Types

typedef SceneObject Parent

Private Attributes

TickCache mTickCache
GameConnectionmControllingClient
SimObjectPtr< GameBasemAfterObject

Friends

class ClientProcessList
class ServerProcessList


Member Typedef Documentation


Member Enumeration Documentation

Enumerator:
InitialUpdateMask 
DataBlockMask 
ExtendedInfoMask 
ControlMask 
NextFreeMask 

anonymous enum

Enumerator:
NetOrdered 
NetNearbyAdded 
GhostUpdated 
TickLast 
NewGhost 
HiFiPassive 
MaxNetFlagBit 


Constructor & Destructor Documentation

GameBase::GameBase (  ) 

GameBase::~GameBase (  ) 


Member Function Documentation

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 sgLightObject, sgMissionLightingFilter, VolumeLight, fxLight, Precipitation, MissionMarker, SpawnSphere, and CameraBookmark.

static void GameBase::consoleInit (  )  [static]

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

See also:
console

Reimplemented from ConsoleObject.

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

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 PathedInterior, sgLightObject, sgMissionLightingFilter, VolumeLight, Debris, Explosion, fxLight, Lightning, ParticleEmitter, ParticleEmitterNode, Precipitation, Splash, Item, MissionMarker, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, and WheeledVehicle.

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 occurring 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

ProcessObject* GameBase::getAfterObject (  )  [inline, virtual]

Reimplemented from ProcessObject.

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 PathedInterior, sgLightObject, Camera, Debris, Explosion, fxLight, Lightning, ParticleEmitter, Precipitation, Splash, Item, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, Vehicle, and WheeledVehicle.

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, Explosion, Lightning, ParticleEmitter, ParticleEmitterNode, Splash, Item, Player, Projectile, RigidShape, ShapeBase, FlyingVehicle, HoverVehicle, Vehicle, and WheeledVehicle.

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

Allow object a chance to tweak move before it is sent to client and server.

TickCache& GameBase::getTickCache (  )  [inline]

void GameBase::setGhostUpdated ( bool  b  )  [inline]

bool GameBase::isGhostUpdated (  )  const [inline]

void GameBase::setNewGhost ( bool  n  )  [inline]

bool GameBase::isNewGhost (  )  [inline]

virtual void GameBase::computeNetSmooth ( F32  backDelta  )  [inline, virtual]

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 PathedInterior, sgLightObject, sgMissionLightingFilter, VolumeLight, Camera, fxLight, Lightning, ParticleEmitterNode, Precipitation, Splash, Item, MissionMarker, SpawnSphere, CameraBookmark, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, and WheeledVehicle.

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 PathedInterior, sgLightObject, sgMissionLightingFilter, VolumeLight, Camera, fxLight, Lightning, ParticleEmitterNode, Precipitation, Splash, Item, MissionMarker, SpawnSphere, CameraBookmark, PathCamera, Player, Projectile, RigidShape, ShapeBase, StaticShape, Trigger, FlyingVehicle, HoverVehicle, Vehicle, and WheeledVehicle.

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

GameConnection* GameBase::getControllingClient (  )  [inline]

Returns the client controlling this object.

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

Sets the client controlling this object.

Parameters:
client Client that is now controlling this object

Reimplemented in Player.

virtual GameBase* GameBase::getControllingObject (  )  [inline, virtual]

Reimplemented in ShapeBase.

virtual GameBase* GameBase::getControlObject (  )  [inline, virtual]

Reimplemented in Player, and ShapeBase.

virtual void GameBase::setControlObject ( GameBase  )  [inline, virtual]

virtual F32 GameBase::getDefaultCameraFov (  )  [inline, virtual]

Reimplemented in Camera, and ShapeBase.

virtual F32 GameBase::getCameraFov (  )  [inline, virtual]

Reimplemented in Camera, and ShapeBase.

virtual void GameBase::setCameraFov ( F32  fov  )  [inline, virtual]

Reimplemented in Camera, and ShapeBase.

virtual bool GameBase::isValidCameraFov ( F32  fov  )  [inline, virtual]

Reimplemented in Camera, and ShapeBase.

virtual bool GameBase::useObjsEyePoint (  )  [inline, virtual]

virtual bool GameBase::onlyFirstPerson (  )  [inline, virtual]

virtual F32 GameBase::getDamageFlash (  )  [inline, virtual]

virtual F32 GameBase::getWhiteOut (  )  [inline, virtual]

virtual void GameBase::getCameraTransform ( F32 pos,
MatrixF mat 
) [inline, virtual]

Reimplemented in Camera, PathCamera, RigidShape, ShapeBase, and Vehicle.

GameBase::DECLARE_CONOBJECT ( GameBase   ) 


Friends And Related Function Documentation

friend class ClientProcessList [friend]

Reimplemented from ProcessObject.

friend class ServerProcessList [friend]

Reimplemented from ProcessObject.


Member Data Documentation

Should we render bounding boxes?

Reimplemented in ShapeBase.