Game Development Community

dev|Pro Game Development Curriculum

Things learn't from 3DGPAI1: Ch4

by Amr Bekhit · 06/13/2006 (10:22 am) · 3 comments

Back again with another list of things learnt from the book. Initially I though that the book had a tendancy to put things down and not explain them. After reading on I get the impression that some things will be explained later on in the book. What's more, the book is very comprehensive: it seems to cover all aspects of making again except audio--even goes thorugh how to texture, UV map, model weapons, characters and static world objects, how to rig them and animate them. If the book were to go indepth on code it'd be massive. I recently ordered the Game Programmer's Guide to Torque so that'll hopefully give me more indepth info on the code and the Advanced 3DGPAI1 is worth looking into too...

-The OnStart and OnExit functions of a class seem to act like constructors and destructors in other programming languages, except the OnStart doesn't get called when the class is exec'd.

-nextToken is a very useful function for parsing a list of tokens in a string that are seperated by a particular character, e.g "one,two,three,four,five". What it will do is take the tokenised string, then extrtact the first token from it, and return to you the original string WITHOUT that token and its seperator character. You can then use this new string to extract the next token, and so on. So in this case, the extracted token would be "one" and the returned string would be "two,three,four,five".

-SetModPaths: The wiki states that this function sets the current mod path to the value specified in the parameter. I think this means that if I set a mod path to "common", then I can exec a script by calling its name and the engine will automatically look in the 'common' folder for it. It turns out by experimentation that this doesn't work for scripts-apparently used by the resource manager. I guess scripts don't come under that then.

-Packages: A package is collection of functions only. When a package is loaded using the ActivatePackage function, the functions in the package will override any existing loaded functions that have the same name. A package is unloaded using the DeactivatePackage function. This also unloads any packages that were activated after this one. A function can call is predecessor by using the Parent:: namespace.
I can see how this is useful: one might have a group of core functions that need to behave differently during different states in a game. When a new state takes place, its corresponding package can be loaded and the same core functions can be called in exactly the same way, but will behave differently. Now why does the book use a package in the control/main.cs file? Removing the package and placing the functions inline causes TGE to crash, so it clearly has a reason. From what I understand about packages, any subsequent calls to OnStart and OnExit will refer to the functions in the package.

-The functions InitBaseServer and initBaseClient are written by the author and they simply exec some files that setup the server and client respectively.

-The createServer function is another of the common routines and seems to simply load a mission. However, if you specify a multiplayer server, it will do a little bit more and setup network ports and allow the game to accept external connections.

-Initcanvas seems pretty self explanatory; it creates a window which is ready for stuff to be drawn to. The functions first sorts out some preferences that the scripter specifies in code (or maybe derived from an options menu), loads the common guis the engine uses and some scripts related to the gui and then initializes the sound system.

-GameConnection seems to be a C++ class, but had some trouble finding more detailed info about it. Information derived so far is that it handles anything related to the network connection: Spawning players, handling client connections are the examples used in the book.

-I think ActionMap is another C++ object. Used to map input methods like the keyboard and mouse to functions using the Bind function, where you state the particular input and the function you would like it to trigger.

-GameTSCtrl is a subclass of the GUI and is tailored to render the 3D scenes required in the game.

-onWake is a GUI related event, but can't find any details on WHEN it occurs. Book says it occurs when 'the control becomes active'. Hmm...what do you mean by active?

On to chapter 5...

--Amr

#1
06/13/2006 (1:48 pm)
onWake is called when the GUI the component is in is pushed to the canvas.
#2
06/13/2006 (7:47 pm)
Amr you're on the right track. youll have tge nailed in no time. =) hopefully this post will save you time and headaches later on...

- youre incorrect about OnStart and OnExit. OnStart is just a regular function. it was added to compliment OnExit which is called directly from C++ code when the engine is shut down. OnExit is just a callback. neither acts like a constructor.

- nextToken is useful but theres a few things you should know about it. the second parameter must be passed by reference so you must omit the $ or %. you must pass an empty string for this function to continue to operate on the same string. also, this function will NOT return the last token in a list which makes it difficult to use this function effectively in a loop. 99 times out of 100 youll probably want to just use getWord() instead.

- setModPaths simply specifies which directories your scripts can access. you must call this before you can exec any other files.

- your description of packages is correct. also keep understand that packages can create a hierarchy of functions. this is exactly what happens in main.cs.

- most of the functions at startup either exec files or set globals. theres ALOT of flexibility here. yes you could theoretically throw all of it into one big function. it wouldnt be as fun as it sounds.

- gameconnection is network related but its REQUIRED to do anything in tge. tge is always networked regardless of whether youre doing a single or multiplayer game. rather than just for multiplayer, you should think of gameconnection as an interface required for 3d rendering.
#3
06/20/2006 (12:24 pm)
Once again guys, thanks for the enlightening comments!