Previous Blog Next Blog
Prev/Next Blog
by date

Torque Game Engine Understanding Diary, part #3. Console

Torque Game Engine Understanding Diary, part #3. Console
Name:Vitla 
Date Posted:Oct 23, 2006
Rating:1.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Vitla

Blog post
Decide to continue due to interesting and tricky things understood.

23.

So, after realizing core scheme - TGE, I guess as any game engine, is like ready template game application that you tweak here and there to get FPS, RTS, Racing and other :) - next layer of abstraction came up: scene, objects, light, rendering. I started with RTSUnit, found that I should check ShapeBase, no, I should check GameBase (parent) first, ah, no, I should check SceneObject (GameBase parent)! No, SimObject (SceneObject parent), no...:)

Well, at the end I found ConsoleObject class, the father of all and First Adam of everything here.

24.

Obviously I started to wish to have the Knowledge of Console :). TGE Docs Engine Overview still is great help and first stop. C++ code resides in console/console.* files.

What if I try to make my own script (Console - is Torque Script world from C++ point of view) system? How to simulate a language? :) So when I asked myself this, I quickly started to understand what is for what in Console files.

Everything that concerns Console and Torque Script in C++ engine code is dev's attempts to simulate a nice programming language by the means of another programming language :) trying to create all cool features of that new language (compile and run in real-time, access to inner C++ structure, etc. ) As I saw, successfull attempts.

Now the most scary Namespace, AbstractClassRep, ConsoleConstructor and other Con namespace monsters became quiet and were sitting on their places.

25

Namespace and AbstractClassRep - is like simulation of class system :) inheritance, member methods and vars, overrinding etc. They have also something like a database of classes, and other things not very exciting for me at the moment :)


26

But with ConsoleConstructor class was one interesting trick in understanding. If I want to create new cool function in Torque Script or just make accessible my own C++ class - internally there happen a call to ConsoleConstructor to create function - it somehow make it in Torque Script world.

And there is err... Hard to explain, but instead of one layer, as I thought and expected - you just add and add things through interface - there is layer I totally miss. Coding, compiling & linking of initial C++ code process layer :)

Or from another side - why ConsoleConstructor has 2 initialization functions: one is called Init(), and another Setup() (Without diving in-depth Setup acts like static function called once and prepare all previously prepared in init() phase things) ?! I can understand the scheme, but actually don't see the goal.

Init() is called by constructor of ConsoleConstructor itself - i.e. each time we want to add a function or method to script world. On other hands, Setup() is called from Con:init() method - when we hit Enter over exec-file. Well, actually init() is called also when we hit enter. But, in other words in Init() they prepare to be prepared :). Or "preparing something already prepared" in Setup. :) Why such a things?

Extract from console.h code comments:

"Because it is defined as a global (my note - functions for Console in *.cc files), the constructor for the ConsoleConstructor is called before execution of main()".

I found the goal! Init() - for human, for programmer, for free coding, for not restricting to creation of new functions in one particular big class - for more easy coding process. On the other hand, Setup() - for script world itself, it is assembling-the-script-world phase.

This dividing brings me another small enlightment in the area of C++ coding tactics :)

That is all for now.

Recent Blog Posts
List:10/23/06 - Torque Game Engine Understanding Diary, part #3. Console
10/22/06 - Torque Game Engine Understanding Diary, part #2
10/22/06 - Torque Game Engine Understanding Diary, part #1

Submit ResourceSubmit your own resources!

Stephen Zepp   (Oct 23, 2006 at 05:58 GMT)
For a good understanding of the ConsoleObject implementation, realize that it's primary intent is two fold:

1) Allow script to be able to instantiate a c++ class, regardless of the underlying operating system.

2) Allow a server to tell a client to remotely instantiate a c++ class, regardless of the underlying operating system.

We do this by having two versions of a ClassRep: the abstraction layer version (AbstractClassRep), and the OS specific version, ConcreteClassRep. During startup, we build a list that associates the ConcreteClassReps with AbstractClassReps, so that a server can tell us to instantiate a specific class, even if the server is a different operating system.

You mentioned above that you feel you are missing an implementation layer--that's because due to cross-platform requirements, much of the actual creation of these class reps is performed at the pre-processor level by utilization of a class of pre-processor macros, the DECLARE_CONOBJECT() and IMPLEMENT_CONOBJECT() macros. This lets us do the necessary platform specific work while also maintaining a consistent framework for the abstraction layer. Note that there are many versions of these macros for many of your future research efforts--basically, they are used for every class in the engine that can be instantiated via script, and there are also different versions of the macros for networked objects, as well as datablocks.

Moderator note: I'm extremely pleased that you are spending the time to do all this, and I plan on using some of the things you've demonstrated in your learning process during future classes!

The only concern I have is that in some cases you are showing source code in your posts, and since this is a public area (the .plans can be read by everyone), we may need to move the source code out of your posts. I'll talk to the bosses tomorrow at work and see if we can come up with a good solution so you can continue to work on your diary!

Vitla   (Oct 23, 2006 at 18:22 GMT)
Thanks a lot!

"During startup, we build a list that associates the ConcreteClassReps with AbstractClassReps, so that a server can tell us to instantiate a specific class, even if the server is a different operating system."

Ha, this is the answer to my last hard question pair "how exactly are connected Concrete- and Absctract- ClassRep classes? And why doing such?"

And to clear the last chain part - the end-user intention of runtime instantiation of classes:

Is the intention of runtime instantiation of C++ classes is to let the script classes to be instantiated - to let create objects and destroy them in realtime - objects which represent units, objects which represent trees, animals, rocks , paths and such end-game layer things?

You must be a member and be logged in to either append comments or rate this resource.