Game Development Community

Explanation of TX code flow...

by Ty Newton · in Torque X 2D · 01/09/2007 (3:56 am) · 4 replies

Hi,
Can someone explain the code flow for the StarterGame starter kit.

It seems that the Game class is instantiated and _mygame.Run() is called from the Main() method. I can't see this method's source but I assume it calls _mygame.BeginRun() before doing something.

_mygame.BeginRun() loads the scene that is created using TGBX and then I don't know what happens.

I assume that there is an event pump somewhere hidden away driving the ticker I read about in the Overview.html documentation.

I had a look inside the MovementComponent class and this is another mystery. I assume ProcessTick() is being called from the hidden event pump and the _InitComponent() method was called when _mygame.BeginRun() loaded the scene.

Can anyone shed some more light on this?

Thanks,
T

#1
01/09/2007 (8:10 am)
Yes to almost everything. _InitComponent is called when the owner of the component is registered to the scene with a call similar to TorqueObjectDatabase.Instance.Register(theOwner);
#2
01/09/2007 (10:16 am)
Ty, _InitComponent is called on each component as its owner is actually registered with the SceneGraph.

You are passed a reference to the owning object, which you can then (if you choose to), cache within your component for future use.

For example,

_ownerObject = Owner as T2DSceneObject;

(where _ownerObject is defined as a T2DSceneObject).

As far as what's going on in the SceneLoader.Load method, basically the XML file (.txscene file) is deserialized. Each object / material, etc. is loaded up and either registered with the scene (in the case of objects whose IsTemplate flag is false), or for templates at least loaded into the TorqueObjectDatabase for future lookup / cloning.

Hope this sheds SOME light on things :)
#3
01/09/2007 (3:36 pm)
Thanks. The extra detail helps.
#4
01/09/2007 (4:56 pm)
Thanks. The extra detail helps.