GameBase

Engine/source/T3D/gameBase/gameBase.h

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

More...

Datablock

bool

Assigns this object a datablock and loads attributes with onNewDataBlock.

Returns the datablock for this object.

bool
onNewDataBlock(GameBaseData * dptr, bool reload)

Called when a new datablock is set.

Inherited Functionality.

bool

Called when the object is added to the sim.

Called when the object is removed from the sim.

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

Script

The scriptOnXX methods are invoked by the leaf classes

Executes the 'onAdd' script function for this object.

Executes the 'onNewDataBlock' script function for this object.

Executes the 'onRemove' script function for this object.

GameBase NetFlags & Hifi-Net Interface

Set or clear the GhostUpdated bit in our NetFlags.

bool

Returns true if the GhostUpdated bit in our NetFlags is set.

setNewGhost(bool n)

Set or clear the NewGhost bit in our NetFlags.

bool

Returns true if the NewGhost bit in out NetFlags is set.

Set or clear the NetNearbyAdded bit in our NetFlags.

bool

Returns true if the NetNearby bit in our NetFlags is set.

bool

Returns true if the HiFiPassive bit in our NetFlags is set.

bool

Returns true if the TickLast bit in our NetFlags is set.

bool

Returns true if the NetOrdered bit in our NetFlags is set.

computeNetSmooth(F32 backDelta)

Called during client catchup under the hifi-net model.

Returns TickCache used under the hifi-net model.

Network

Interpolates between tick events.

getUpdatePriority(CameraScopeQuery * focusObject, U32 updateMask, S32 updateSkips)

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

packUpdate(NetConnection * conn, U32 mask, BitStream * stream)

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

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

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

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

Gets the checksum for packet data.

Mounted objects ( overrides )

onMount(SceneObject * obj, S32 node)

Callback when this object is mounted.

onUnmount(SceneObject * obj, S32 node)

Callback when this object is unmounted.

User control

Returns the client controlling this object.

Returns the MoveList of the client controlling this object.

Sets the client controlling this object.

Callbacks

DECLARE_CALLBACK(void , setControl , (bool controlled) )

Public Types

enum
_Anonymous_ {
  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 {
  DataBlockMask = Parent::NextFreeMask << 0
  ExtendedInfoMask = Parent::NextFreeMask << 1
  ScopeIdMask = Parent::NextFreeMask << 2
  NextFreeMask = Parent::NextFreeMask << 3
}

Private Types

Parent 

Public Static Attributes

bool

Should we render bounding boxes?

Protected Attributes

Protected Static Functions

bool
setDataBlockProperty(void * object, const char * index, const char * data)

Public Functions

Returns the water object we are colliding with, it is up to derived classes to actually set this object.

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

Private Functions

This is called by the reload signal in our datablock when it is modified in the editor.

Protected Functions

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:

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

setDataBlock(GameBaseData * dptr)

Assigns this object a datablock and loads attributes with onNewDataBlock.

Parameters:
dptr

Datablock

getDataBlock()

Returns the datablock for this object.

onNewDataBlock(GameBaseData * dptr, bool reload)

Called when a new datablock is set.

This allows subclasses to appropriately handle new datablocks.

Parameters:
dptr

New datablock

reload

Is this a new datablock or are we reloading one we already had.

Reimplemented by: Ribbon, afxChoreographer, afxEffectron, afxMagicMissile, afxMagicSpell, afxSelectron, afxSpellBook, afxBillboard, afxModel, afxMooring, afxParticleEmitter, afxParticleEmitterVector, afxParticleEmitterCone, afxParticleEmitterPath, afxParticleEmitterDisc, afxProjectile, afxStaticShape, afxZodiacPlane, afxParticlePool, OpenVRTrackedObject, Camera, Debris, Explosion, Lightning, ParticleEmitter, ParticleEmitterNode, Precipitation, RibbonNode, Splash, Item, MissionMarker, PathCamera, PathShape, PhysicsDebris, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, VHumanoidActor, VActor

GameBaseData * mDataBlock 

Inherited Functionality.

onAdd()

Reimplemented from: SceneObject

Reimplemented by: Item, MissionMarker, WayPoint, SpawnSphere, CameraBookmark, PathCamera, PathShape, PhysicsDebris, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, VActor

onRemove()

Reimplemented from: SceneObject

Reimplemented by: Item, MissionMarker, CameraBookmark, PathCamera, PathShape, PhysicsDebris, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, VActor

inspectPostApply()

Reimplemented from: SceneObject

Reimplemented by: MissionMarker, WayPoint, SpawnSphere, CameraBookmark, PhysicsShape, Trigger

initPersistFields()

consoleInit()

Script

The scriptOnXX methods are invoked by the leaf classes

scriptOnAdd()

Executes the 'onAdd' script function for this object.

note:

This must be called after everything is ready

scriptOnNewDataBlock()

Executes the 'onNewDataBlock' script function for this object.

note:

This must be called after everything is loaded.

scriptOnRemove()

Executes the 'onRemove' script function for this object.

note:

This must be called while the object is still valid

GameBase NetFlags & Hifi-Net Interface

setGhostUpdated(bool b)

Set or clear the GhostUpdated bit in our NetFlags.

isGhostUpdated()

Returns true if the GhostUpdated bit in our NetFlags is set.

setNewGhost(bool n)

Set or clear the NewGhost bit in our NetFlags.

isNewGhost()

Returns true if the NewGhost bit in out NetFlags is set.

setNetNearbyAdded(bool b)

Set or clear the NetNearbyAdded bit in our NetFlags.

isNetNearbyAdded()

Returns true if the NetNearby bit in our NetFlags is set.

isHifiPassive()

Returns true if the HiFiPassive bit in our NetFlags is set.

isTickLast()

Returns true if the TickLast bit in our NetFlags is set.

isNetOrdered()

Returns true if the NetOrdered bit in our NetFlags is set.

computeNetSmooth(F32 backDelta)

Called during client catchup under the hifi-net model.

getTickCache()

Returns TickCache used under the hifi-net model.

Network

interpolateTick(F32 delta)

Reimplemented from: ProcessObject

Reimplemented by: Item, PhysicsDebris, PhysicsShape, Player, Projectile, StaticShape, Trigger, PathCamera, PathShape, RigidShape, TurretShape, VHumanoidActor

getUpdatePriority(CameraScopeQuery * focusObject, U32 updateMask, S32 updateSkips)

Reimplemented from: NetObject

Reimplemented by: Projectile, ShapeBase

packUpdate(NetConnection * conn, U32 mask, BitStream * stream)

Reimplemented from: SceneObject

Reimplemented by: PathCamera, PathShape, Item, MissionMarker, WayPoint, SpawnSphere, CameraBookmark, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, VHumanoidActor, VActor

unpackUpdate(NetConnection * conn, BitStream * stream)

Reimplemented from: SceneObject

Reimplemented by: PathCamera, PathShape, Item, MissionMarker, WayPoint, SpawnSphere, CameraBookmark, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, FlyingVehicle, HoverVehicle, Vehicle, WheeledVehicle, VHumanoidActor, VActor

writePacketData(GameConnection * conn, BitStream * stream)

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

This information is sent only to the controlling 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 by: afxCamera, OpenVRTrackedObject, Camera, Player, RigidShape, ShapeBase, TurretShape, FlyingVehicle, Vehicle, WheeledVehicle

readPacketData(GameConnection * conn, BitStream * stream)

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 by: afxCamera, OpenVRTrackedObject, Camera, Player, RigidShape, ShapeBase, TurretShape, FlyingVehicle, Vehicle, WheeledVehicle

getPacketDataChecksum(GameConnection * conn)

Reimplemented from: ProcessObject

Mounted objects ( overrides )

onMount(SceneObject * obj, S32 node)

Reimplemented from: SceneObject

Reimplemented by: ShapeBase, VActor

onUnmount(SceneObject * obj, S32 node)

Reimplemented from: SceneObject

Reimplemented by: Player, ShapeBase, StaticShape, Trigger, TurretShape, VActor

User control

getControllingClient()

Reimplemented from: ProcessObject

getControllingClient()

getMoveList()

Returns the MoveList of the client controlling this object.

If there is no client it returns NULL;

setControllingClient(GameConnection * client)

Sets the client controlling this object.

Parameters:

client

Client that is now controlling this object

Reimplemented by: Player, afxCamera, ShapeBase

getControllingObject()

Reimplemented by: ShapeBase

getControlObject()

Reimplemented by: Player, ShapeBase

setControlObject(GameBase * )

Callbacks

DECLARE_CALLBACK(void , setControl , (bool controlled) )

Public Types

@188

Enumerator

NetOrdered = BIT(Parent::MaxNetFlagBit+1)
NetNearbyAdded = BIT(Parent::MaxNetFlagBit+2)

Process in same order on client and server.

GhostUpdated = BIT(Parent::MaxNetFlagBit+3)

Is set during client catchup when neighbors have been checked.

TickLast = BIT(Parent::MaxNetFlagBit+4)

Is set whenever ghost updated (and reset) on the client, for hifi objects.

NewGhost = BIT(Parent::MaxNetFlagBit+5)

Tick this object after all others.

HiFiPassive = BIT(Parent::MaxNetFlagBit+6)

This ghost was just added during the last update.

MaxNetFlagBit = Parent::MaxNetFlagBit+6

Do not interact with other hifi passive objects.

GameBaseMasks

Enumerator

DataBlockMask = Parent::NextFreeMask << 0
ExtendedInfoMask = Parent::NextFreeMask << 1
ScopeIdMask = Parent::NextFreeMask << 2
NextFreeMask = Parent::NextFreeMask << 3

Private Types

typedef SceneObject Parent 

Private Attributes

GameConnection * mControllingClient 
TickCache mTickCache 

Public Static Attributes

bool gShowBoundingBox 

Should we render bounding boxes?

Protected Attributes

F32 mCameraFov 
WaterObject * mCurrentWaterObject 

The WaterObject we are currently within.

Protected Static Functions

setDataBlockProperty(void * object, const char * index, const char * data)

Public Functions

GameBase()

~GameBase()

DECLARE_CONOBJECT(GameBase )

getCameraFov()

Reimplemented by: afxCamera, Camera, ShapeBase

getCameraTransform(F32 * pos, MatrixF * mat)

Reimplemented by: afxCamera, Camera, PathCamera, RigidShape, ShapeBase, TurretShape, Vehicle

getCurrentWaterObject()

Returns the water object we are colliding with, it is up to derived classes to actually set this object.

Reimplemented by: ShapeBase

getDamageFlash()

Reimplemented by: afxCamera, Camera, ShapeBase

getDefaultCameraFov()

Reimplemented by: afxCamera, Camera, ShapeBase

getEyeCameraTransform(IDisplayDevice * device, U32 eyeId, MatrixF * mat)

Reimplemented by: Camera, ShapeBase

getWhiteOut()

Reimplemented by: afxCamera, Camera, ShapeBase

isValidCameraFov(F32 fov)

Reimplemented by: afxCamera, Camera, ShapeBase

onlyFirstPerson()

Reimplemented by: ShapeBase

processTick(const Move * move)

Reimplemented from: ProcessObject

Reimplemented by: PathCamera, PathShape, Item, SpawnSphere, PhysicsDebris, PhysicsShape, Player, Projectile, ProximityMine, RigidShape, ShapeBase, StaticShape, Trigger, AITurretShape, TurretShape, Vehicle, WheeledVehicle, VHumanoidActor, VActor

setCameraFov(F32 fov)

Reimplemented by: afxCamera, Camera, ShapeBase

useObjsEyePoint()

Reimplemented by: ShapeBase

Private Functions

_onDatablockModified()

This is called by the reload signal in our datablock when it is modified in the editor.

This method is private and is not virtual. To handle a datablock-modified even in a child-class specific way you should override onNewDatablock and handle the reload( true ) case.

Warning: For local-client, editor situations only.

Warning: Do not attempt to call .remove or .notify on mDataBlock->mReloadSignal within this callback.

Protected Functions

onScopeIdChange()

Reimplemented from: NetObject