Game Development Community

Q: Please explain this Engine idiom for me

by Jarrod Roberson · in Torque Game Engine · 05/14/2002 (4:03 pm) · 6 replies

Ok I just can't see why there is a PlayerData struct and a Player class, same with ShapeBaseData struct and ShapeBase class, etc. Not knocking, just don't understand!

Does it have to do with the datablock support?
What is this coding idiom accomplishing?

editing staring at Java code for 12 hours then trying to learn Torque AND re-adjust my brain to C++ == typos

#1
05/14/2002 (4:10 pm)
im sure you meant Player class and PlayerData struct..

the *Data structs are used to define the object
properties in the script.

thus enabling quick tweaking, as well the ability to use one class for many object's

Edit:
yes they are the datablock's, simply view the inheritance
#2
05/14/2002 (4:21 pm)
ok I figured that the structs were implementations of the datablocks, thanks for the confirmation, what is their relationship to the class then?

association or aggregation?

I mean if I create a subclass of Player say Player2 to make it scriptable I have to create Player2Data also?

What are the dependancies between the Class and the struct?

Does the Class use the struct in some indirect way that I am just not seeing?
#3
05/14/2002 (4:24 pm)
If you think of the datablock as "class static" in that its meant to be data used only for that type of object (the class) not simply 1 instance, but ALL instances will use the same datablock.

Why its not simply a network serialised static member I dont know.

Yep, hard to get your head round.. me too.

Phil.
#4
05/14/2002 (5:01 pm)
ok I see how it works now, it is a whacky implemention of a Factory Pattern using a template that is compiled at game run time.

Please correct me if this is wrong.

The script defines a datablock that is implemented by the struct. When the class is instantiated the struct is refered to intiliaze that particular instance with the datablock / stuct defined values. So it is not static in the purest sense, it is "static" for all instances that are defined by that datablock / struct.

so ...

datablock ShapeBaseImageData(RifleImage)
{
...
}

defines a new instance of ShapeBaseImage with defaults values passed in thru the datablock / struct.

the datablock / struct is only "static" for the types of "RifleImage", correct?

So this idiom is so that the engine can create new specialized versions of classes without directly implementing them in C++! Pretty sweet!

Please correct me if any of this is wrong!!!!
#5
05/14/2002 (5:04 pm)
thats right ..
:)
guess I was not very clear?

at least you understand it now.
#6
05/14/2002 (5:49 pm)
thanks to both of you, maybe someone else can benefit from this little exchange once the "serach body text" is enabled! :(