Book Image

Torque 3D Game Development Cookbook

By : DAVID WYAND
Book Image

Torque 3D Game Development Cookbook

By: DAVID WYAND

Overview of this book

Torque 3D is a popular game engine that supports you in every step along the way to making your game a reality. Even with all of the power and tools that Torque 3D provides, finishing a high quality 3D game requires time and knowledge."Torque 3D Game Development Cookbook" is a practical guide that takes you through each of the major steps on the journey to creating your game, while learning a few tricks along the way.The recipes in this book start off with learning some of the finer points about TorqueScript. The book then moves on to each of Torque 3D's subsystems and ends with a variety of game play recipes.The various topics covered include activating level-specific game code and scheduling game events, dragging and dropping items between windows to work with an in-game inventory system, and covering the seams between objects with well placed decals. Some of the advanced topics include writing custom shaders and postFX, using zones to improve rendering performance, and enhancing your game's ambience through sound.Once you are done with Torque 3D Game Development Cookbook you'll be on your way to creating amazing 3D games and gain expert knowledge of Torque 3D.
Table of Contents (17 chapters)
Torque 3D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a new Datablock object


Datablock objects have static properties and are used as a common data store between game objects that derive from the GameBase class. They are defined on the server and are passed to clients (by SimObject ID only) during the initial transmission of a game level. In this recipe we'll see how to build a new Datablock object.

How to do it...

Creating a Datablock instance is straight forward. Here we will create a StaticShapeData Datablock, one of many possible Datablock classes as follows:

datablock StaticShapeData(MyShapeData)
{
   category = "Scenic";
   shapeFile = "art/shapes/rocks/rock1.dts";
   computeCRC = true;
   isInvincible = true;
};

How it works...

We use the datablock keyword when creating a new Datablock class object and always give it a unique global name. This name is used by other objects to reference this Datablock through the use of datablock property of the GameBase class.

If we happen to create two Datablock instances with the same global name but of different classes, then a Cannot Re-declare data block with a different class error is output to the console and nothing is done with the second Datablock instance. However, if the two global names and classes match, then all of the properties from the second Datablock instance are copied into the first.

There's more...

There are a number of different things to keep in mind when it comes to creating a Datablock instance. Let's take a look at them.

Creating a new Datablock object based on another Datablock object

We can base the properties of one Datablock instance on a previously created Datablock instance through the use of a copy source during the creation of the Datablock object. The process is the same as when using the new keyword. See the Creating a new SimObject instance recipe for more information on using a copy source.

Limited total number of Datablocks

The SimObject ID of a Datablock instance comes from a special pool that is reserved for the Datablock class. This ID pool only allows 1024 Datablock instances to be defined per game level. This number may be increased by changing the source code of Torque 3D. It is this special SimObject ID that is transferred between the server and client in a multiplayer game, and is used by the GameBase derived classes to reference their Datablock object on the client.

The datablock keyword should only be used on the server

Use of the datablock keyword should be limited to the server script files. Only the server keeps a track of the special Datablock ID pool, and all the Datablock objects on the client are deleted just prior to a game level being loaded.

Datablock properties should be considered static

Once a Datablock object has been created, its properties should be considered static. It is possible to modify the properties of a Datablock object at any time, just as with any other SimObject, but this should be avoided. The modified Datablock properties are not retransmitted between the server and client and will result in strange errors during game play.

See also

  • Creating a new SimObject instance

  • Creating a new internal name only SimObject instance

  • Creating a new singleton recipes