Game Development Community

Torque Scripting question

by Dwayne Brown · in Technical Issues · 11/01/2005 (11:07 am) · 6 replies

Hello community, I have a question regarding datablocks in torque script. Obviously, datablocks create's a new object, but I am so used to OOP in C++ I get confused with those habbits of using classes. Is datablocks like a class, but only you create an instance of the object with in the datablock vs an object of that class in root main?

I am trying to ask this question with out confusing you guys. :(

#1
11/01/2005 (12:30 pm)
Datablocks are designed for one purpose: maximizing network utlization by collecting a lot of data about a specific type of object and then sending it once and only once across the network.

The best way to consider a datablock is to think of it as a collection of static data related to one or more object instantiations you will use in your project. Since this data is designed to be static, it's better to transmit the datablock once for the entire session, instead of transmitting it each time a new object that will reference that information is instantiated (and therefore needs to be networked).

For example, think about a game where you have to instantiate a platoon of tanks. Each of these tanks are Abrahms A-1's, so a very large set of data regarding how this type of tank operates can be contained in a datablock, and that datablock can be referenced by each and every tank in your platoon. Now, each of the tanks in your platoon are going to have dynamic data that is unique to that particular tank, so the datablock won't hold all of the information (it won't hold the tank's position, or velocity, or damage state, or current animation, etc.), but nonetheless a very large set of data is within the datablock.

Now, a use example. Let's say that our datablock contains 5k worth of static, non-unique data (well, unique to Abrahm's A1 tanks in general, but not Abrahms_Tank_13, Abrahms_Tank_11, etc.). We have two options for having the client learn about this data:

Send it with each tank:
--send Abrahms_Tank_01:
---transmit datablock info (5k)
---transmit unique info
--send Abrahms_Tank_02:
---transmit datablock info (5k)
---transmit unique info
--send Abrahms_Tank_03:
---transmit datablock info (5k)
---transmit unique info

OR, we can send it once at start of game:
--send Abrahms_Tank_Data info during mission startup (5k)

and then:

--send Abrahms_Tank_01:
---send datablock name (20 bytes maybe?)
---send unique info
--send Abrahms_Tank_02:
---send datablock name (20 bytes)
---send unique info

etc.

As you can see, buy consolidating all the information that is consistent and static with regards to Abrahms Tanks in general into a single datablock, we can save a lot of networking bandwidth over the term of our session.
#2
11/01/2005 (12:38 pm)
Never mind, datablocks are confusing :-)

Datablocks don't create a new object. They create a one and only new datablock. Objects will point to this datablock.

A playerData datablock isn't a player. It's how the player should look and act like. A player object will point to the PlayerData datablock in order to behave like a player.
#3
11/01/2005 (4:35 pm)
Ahhhh Thanks alot for the detailed information......
That opened up light in the dark tunnel I was walking in!!!!!
#4
11/01/2005 (5:11 pm)
Heh cool, I never saw datablocks from a networking perspective. Thanks for the insight.
#5
11/08/2005 (5:07 pm)
So is databloc analagous to class data, that is in c++ all the data members with the "static" qualifiers?


class MyClass
{
int m_iAlpha;
int m_iBeta;

static int m_iInstanceCount;
}

here MyClass::m_iInstanceCount is a potential candidate for datablock?
#6
11/08/2005 (5:38 pm)
Yes, static class data that is only transmitted across the network once (changing the data on the server will not automatically cause it to change on the client and can lead to bizarre behavior - like when the client and server disagree about the max speed of the player).