SimDataBlock

Engine/source/console/simDatablock.h

Root DataBlock class.

More...

Classes:

Datablock Internals

bool

Returns true if this is a client side only datablock (in other words a datablock allocated with 'new' instead of the 'datablock' keyword).

Get the modified key for this particular datablock.

bool

Called when the object is added to the sim.

onStaticModified(const char * slotName, const char * newValue)

Specifically, these are called by setDataField when a static or dynamic field is modified, see the console details.

Assign a new modified key.

Datablock Interface

bool
preload(bool server, String & errorStr)

Called to prepare the datablock for use, after it has been unpacked.

Private Types

Parent 

Protected Attributes

Public Static Attributes

const bool

Used by the console system to automatically tell datablock classes apart from non-datablock classes.

Protected Functions

Detailed Description

Root DataBlock class.

Introduction

Another powerful aspect of Torque's networking is the datablock. Datablocks are used to provide relatively static information about entities; for instance, what model a weapon should use to display itself, or how heavy a player class is.

This gives significant gains in network efficiency, because it means that all the datablocks on a server can be transferred over the network at client connect time, instead of being intertwined with the update code for NetObjects.

This makes the network code much simpler overall, as one-time initialization code is segregated from the standard object update code, as well as providing several powerful features, which we will discuss momentarily.

preload() and File Downloading

Because datablocks are sent over the wire, using SimDataBlockEvent, before gameplay starts in earnest, we gain in several areas. First, we don't have to try to keep up with the game state while working with incomplete information. Second, we can provide the user with a nice loading screen, instead of the more traditional "Connecting..." message. Finally, and most usefully, we can request missing files from the server as we become aware of them, since we are under no obligation to render anything for the user.

The mechanism for this is fairly basic. After a datablock is unpacked, the preload() method is called. If it returns false and sets an error, then the network code checks to see if a file (or files) failed to be located by the ResManager; if so, then it requests those files from the server. If preload returns true, then the datablock is considered loaded. If preload returns false and sets no error, then the connection is aborted.

Once the file(s) is downloaded, the datablock's preload() method is called again. If it fails with the same error, the connection is aborted. If a new error is returned, then the download-retry process is repeated until the preload works.

Guide To Datablock Code

To make a datablock subclass, you need to extend three functions:

packData() and unpackData() simply read or write data to a network stream. If you add any fields, you need to add appropriate calls to read or write. Make sure that the order of reads and writes is the same in both functions. Make sure to call the Parent's version of these methods in every subclass.

preload() is a bit more complex; it is responsible for taking the raw data read by unpackData() and processing it into a form useful by the datablock's owning object. For instance, the Player class' datablock, PlayerData, gets handles to commonly used nodes in the player model, as well as resolving handles to textures and other resources. Any code which loads files or performs other actions beyond simply reading the data from the packet, such as validation, must reside in preload().

To write your own preload() methods, see any of the existing methods in the codebase; for instance, PlayerData::preload() is an excellent example of error-reporting, data validation, and so forth.

note:

A useful trick, which is used in several places in the engine, is that of temporarily storing SimObjectIds in the variable which will eventually hold the "real" handle. ShapeImage uses this trick in several pllaces; so do the vehicle classes. See GameBaseData for more on using this trick.

see:

GameBaseData for some more information on the datablocks used throughout most of the engine.

see:

http://hosted.tribalwar.com/t2faq/datablocks.shtml for an excellent explanation of the basics of datablocks from script. Note that these comments mostly apply to GameBaseData and its children.

Datablock Internals

isClientOnly()

Returns true if this is a client side only datablock (in other words a datablock allocated with 'new' instead of the 'datablock' keyword).

getModifiedKey()

Get the modified key for this particular datablock.

onAdd()

Reimplemented from: SimObject

Reimplemented by: ForestItemData, TSForestItemData, OpenVRTrackedObjectData, SFXFMODEvent, SFXFMODEventGroup, SFXFMODProject, SFXAmbience, SFXDescription, SFXEnvironment, SFXProfile, SFXState, SFXTrack, DebrisData, DecalData, ExplosionData, LightningData, ParticleData, ParticleEmitterData, ParticleEmitterNodeData, RibbonData, SplashData, GameBaseData, LightDescription, PhysicsDebrisData, PhysicsShapeData, ProjectileData, RigidShapeData, ShapeBaseImageData, TriggerData, AITurretShapeData, HoverVehicleData

onStaticModified(const char * slotName, const char * newValue)

Reimplemented from: SimObject

Reimplemented by: afxAnimClipData, afxZodiacData, afxPathData, DecalData

assignId()

getNextModifiedKey()

Assign a new modified key.

Datablocks are assigned a modified key which is updated every time a static field of the datablock is changed. These are gotten from a global store.

S32 modifiedKey 
SimObjectId sNextObjectId 
S32 sNextModifiedKey 

Datablock Interface

packData(BitStream * stream)

Reimplemented by: afxChoreographerData, afxEffectGroupData, afxEffectronData, afxEffectWrapperData, afxMagicMissileData, afxMagicSpellData, afxSelectronData, afxSpellBookData, afxAnimClipData, afxAnimLockData, afxAreaDamageData, afxBillboardData, afxCameraPuppetData, afxCameraShakeData, afxConsoleMessageData, afxDamageData, afxFootSwitchData, afxGuiControllerData, afxGuiTextData, afxT3DLightBaseData, afxMachineGunData, afxMooringData, afxPhraseEffectData, afxPhysicalZoneData, afxPlayerMovementData, afxPlayerPuppetData, afxT3DPointLightData, afxT3DSpotLightData, afxZodiacData, afxZodiacPlaneData, afxRPGMagicSpellData, afxParticlePoolData, afxPathData, DecalData, LightningData, ParticleEmitterNodeData, RibbonData, ProjectileData, RigidShapeData, HoverVehicleData, VActorData, afxCameraData, afxAudioBank, afxCollisionEventData, afxModelData, afxParticleEmitterData, afxParticleEmitterVectorData, afxParticleEmitterConeData, afxParticleEmitterPathData, afxParticleEmitterDiscData, afxProjectileData, afxScriptEventData, afxStaticShapeData, afxF_DragData, afxF_GravityData, afxForceData, afxXM_ForceData, afxXM_BaseData, afxXM_WeightedBaseData, afxXM_AimData, afxXM_AltitudeConformData, afxXM_BoxAdaptData, afxXM_BoxConformData, afxXM_BoxHeightOffsetData, afxXM_FreezeData, afxXM_GroundConformData, afxXM_HeightSamplerData, afxXM_MountedImageNodeData, afxXM_LocalOffsetData, afxXM_WorldOffsetData, afxXM_OscillateData, afxXM_OscillateZodiacColorData, afxXM_PathConformData, afxXM_PivotNodeOffsetData, afxXM_RandomRotData, afxXM_ScaleData, afxXM_ShockwaveData, afxXM_SpinData, afxXM_VelocityOffsetData, afxXM_WaveBaseData, afxXM_WaveRiderBaseData, afxXM_WaveColorData, afxXM_WaveRiderColorData, afxXM_WaveScalarData, afxXM_WaveRiderScalarData, ForestItemData, OpenVRTrackedObjectData, ReflectorDesc, SFXFMODEvent, SFXFMODEventGroup, SFXFMODProject, SFXAmbience, SFXDescription, SFXEnvironment, SFXPlayList, SFXProfile, SFXState, SFXTrack, CameraData, DebrisData, ExplosionData, ParticleData, ParticleEmitterData, PrecipitationData, SplashData, ItemData, LightAnimData, LightDescription, LightFlareData, PathCameraData, PathShapeData, PhysicsDebrisData, PhysicsShapeData, PlayerData, ProximityMineData, ShapeBaseImageData, ShapeBaseData, StaticShapeData, TriggerData, AITurretShapeData, TurretShapeData, FlyingVehicleData, VehicleData, WheeledVehicleTire, WheeledVehicleSpring, WheeledVehicleData

unpackData(BitStream * stream)

Reimplemented by: afxChoreographerData, afxEffectGroupData, afxEffectronData, afxEffectWrapperData, afxMagicMissileData, afxMagicSpellData, afxSelectronData, afxSpellBookData, afxAnimClipData, afxAnimLockData, afxAreaDamageData, afxBillboardData, afxCameraPuppetData, afxCameraShakeData, afxConsoleMessageData, afxDamageData, afxFootSwitchData, afxGuiControllerData, afxGuiTextData, afxT3DLightBaseData, afxMachineGunData, afxMooringData, afxPhraseEffectData, afxPhysicalZoneData, afxPlayerMovementData, afxPlayerPuppetData, afxT3DPointLightData, afxT3DSpotLightData, afxZodiacData, afxZodiacPlaneData, afxRPGMagicSpellData, afxParticlePoolData, afxPathData, DecalData, LightningData, ParticleEmitterNodeData, RibbonData, ProjectileData, RigidShapeData, HoverVehicleData, VActorData, afxCameraData, afxAudioBank, afxCollisionEventData, afxModelData, afxParticleEmitterData, afxParticleEmitterVectorData, afxParticleEmitterConeData, afxParticleEmitterPathData, afxParticleEmitterDiscData, afxProjectileData, afxScriptEventData, afxStaticShapeData, afxF_DragData, afxF_GravityData, afxForceData, afxXM_ForceData, afxXM_BaseData, afxXM_WeightedBaseData, afxXM_AimData, afxXM_AltitudeConformData, afxXM_BoxAdaptData, afxXM_BoxConformData, afxXM_BoxHeightOffsetData, afxXM_FreezeData, afxXM_GroundConformData, afxXM_HeightSamplerData, afxXM_MountedImageNodeData, afxXM_LocalOffsetData, afxXM_WorldOffsetData, afxXM_OscillateData, afxXM_OscillateZodiacColorData, afxXM_PathConformData, afxXM_PivotNodeOffsetData, afxXM_RandomRotData, afxXM_ScaleData, afxXM_ShockwaveData, afxXM_SpinData, afxXM_VelocityOffsetData, afxXM_WaveBaseData, afxXM_WaveRiderBaseData, afxXM_WaveColorData, afxXM_WaveRiderColorData, afxXM_WaveScalarData, afxXM_WaveRiderScalarData, ForestItemData, OpenVRTrackedObjectData, ReflectorDesc, SFXFMODEvent, SFXFMODEventGroup, SFXFMODProject, SFXAmbience, SFXDescription, SFXEnvironment, SFXPlayList, SFXProfile, SFXState, SFXTrack, CameraData, DebrisData, ExplosionData, ParticleData, ParticleEmitterData, PrecipitationData, SplashData, GameBaseData, ItemData, LightAnimData, LightDescription, LightFlareData, PathCameraData, PathShapeData, PhysicsDebrisData, PhysicsShapeData, PlayerData, ProximityMineData, ShapeBaseImageData, ShapeBaseData, StaticShapeData, TriggerData, AITurretShapeData, TurretShapeData, FlyingVehicleData, VehicleData, WheeledVehicleTire, WheeledVehicleSpring, WheeledVehicleData

preload(bool server, String & errorStr)

Called to prepare the datablock for use, after it has been unpacked.

Parameters:

server

Set if we're running on the server (and therefore don't need to load things like textures or sounds).

errorStr

If an error occurs in loading, this is set to a short string describing the error.

return:

True if all went well; false if something failed.

Reimplemented by: VHumanoidActorData, TSForestItemData, RibbonData, PhysicsShapeData, afxChoreographerData, afxEffectGroupData, afxEffectronData, afxEffectWrapperData, afxMagicMissileData, afxMagicSpellData, afxSelectronData, afxSpellBookData, afxAudioBank, afxBillboardData, afxT3DLightBaseData, afxModelData, afxParticleEmitterData, afxParticleEmitterVectorData, afxParticleEmitterConeData, afxParticleEmitterPathData, afxParticleEmitterDiscData, afxPhraseEffectData, afxZodiacData, afxZodiacPlaneData, afxXM_ForceData, afxPathData, afxXM_PathConformData, OpenVRTrackedObjectData, ReflectorDesc, SFXFMODEvent, SFXFMODEventGroup, SFXFMODProject, SFXAmbience, SFXEnvironment, SFXPlayList, SFXProfile, SFXState, SFXTrack, DebrisData, DecalData, ExplosionData, LightningData, ParticleData, ParticleEmitterData, ParticleEmitterNodeData, PrecipitationData, SplashData, GameBaseData, LightAnimData, LightDescription, LightFlareData, PathShapeData, PhysicsDebrisData, PlayerData, ProjectileData, ProximityMineData, RigidShapeData, ShapeBaseImageData, ShapeBaseData, AITurretShapeData, TurretShapeData, FlyingVehicleData, HoverVehicleData, VehicleData, WheeledVehicleTire, WheeledVehicleData

Private Types

typedef SimObject Parent 

Protected Attributes

Vector< SubstitutionStatement * > substitutions 

Public Static Attributes

const bool __smIsDatablock 

Used by the console system to automatically tell datablock classes apart from non-datablock classes.