Game Development Community

Am I Missing Something? Startup/Shutdown Structure

by Joey Sturgis · in Torque Game Engine · 10/31/2007 (4:25 am) · 7 replies

Hello All,

First off, I am new to the community as I have just purchased the SDK and all of the necessary programs to begin my quest to create a video game!

But I digress, I have a simple problem that seems to be overlooked. I found out about torque by browsing a book store and seeing a "3d game programming all in one" book in the back. I bought the book and was amazed by the seemingly simplicity of the engine. So I bought the SDK. In the first 6 chapters, I thought the author was teaching me directly about torque, but then I soon realized he was teaching me his own way of using torque, specifically the initialization of a game, its start up, and basic (walk around in 3d) simulation. After getting this far, I decided to take a break from the book and search around to figure out just ALL of the ins and outs of the startup of a game using the torque engine...

The problem was I found nothing. It seems like every tutorial wants to get you into the 3d editor as quickly as possible. But what about all of the script and variable/parameter/settings that have to go through the engine first, even before a window is created?

I could not find much information on the topic, such as a list of all possible global values that could be set for a torque "game", and all of the functions (defined within the engine, accessed via scripting) that deal with a game starting up/shutting down... Every turotial uses a set of files/scripts/system the author has created/downloaded from somewhere for you to read through. Most of these examples contain the bare minimum to run that specific simulation/game/turotial.

I am in search of the resource or reference that explains the beginning and ending of the game execution.

Where can I find this information?

About the author

Recent Threads


#1
10/31/2007 (5:18 am)
I want to start off by saying that I don't intend this post to sound rude or condescending but after finishing it and reading it, it just might come off that way. However I'm too lazy to reword/retype this because the points are valid and I can type a single paragraph of disclaimer at the top :).


Why do you need it?

Wouldn't it be more efficient to search for what you need (i.e. a specific parameter) rather than learn all th ins and outs of startup.

Look into demoGame.cc and game.cc if you really want to know. If you want to make a game you should do game things. Creating a window, initializing log files and creating a virtual file system for your resources has nothing to do with a game (well it COULD but I'd be dang impressed if it was a fun game).

Then to continue, with the constantly changing list of global variables and functions, who's gonna pay somebody to keep this information up to date? Well, actually GG is now, but that is a recent development. Still, most of us would prefer they document the stuff that makes games work and not the stuff that makes the engine work within the OS.


I am all for knowledge but seriously I don't see why you are so concerned with the startup phase. Grab one of the starter kits and make a game. Then when you have a game and need to change the startup procedure you will have the knowledge, experience and possibly financial backing to look into this stuff yourself.


For me, I'll be happy with writing a game.



Edit: Lol, I just thought of a three word answer to your question: Level of importance.
#2
10/31/2007 (5:43 am)
Not quite the answer I expected, but beggers can't be choosers.

I didn't realize I would need a reason why I wanted to know what I wanted to know. I did pay money for the SDK, and I was given the option to ask questions in this public forum. So I did. Sorry if I came off as a bit uninformed, and I apologize if I offended anyone who took part in creating the tutorials.

I am the type of person that likes to know inside and out, and all around of what I am working with. I guess I will be diving into the source code if no one is available to answer the original question. I've looked in the reference docs, and so far have not found a single function that says anything like this (Call this function to start the engine) for example.
#3
10/31/2007 (6:41 am)
Check out engine/game/main.cc!
#4
10/31/2007 (6:43 am)
Did you read the engine.overview.txt file that came with the engine? It provides some very good starting points to finding the information you need:

For example:
Quote:Because different platforms can have different main() entry points for applications, the Torque Engine main() function resides in the target OS platform library. In the case of Windows, this is in file engine/platformWin32/winWindow.cc, where both main() (for console apps) and WinMain() are defined. These in turn call run() which calls Game->main(int argc, const char **argv). Game is a global object pointer referencing an instance of the GameInterface class that can be overridden for specific game behavior.

The Torque example program's main initialization occurs in engine/game/main.cc in DemoGame::main(). This function initializes libraries, initializes game functions and then cycles in the main game loop until the program is terminated. The main loop basically calls platform library functions (engine/platform/platform.h) to produce platform events, which then drive the main simulation.

The main.cc file also has DemoGame function overrides for some of the basic event procession functions: processMouseMoveEvent (which dispatches Windows mouse movements to the GUI), processInputEvent (which processes other input related events), and processTimeEvent which computes an elapsed time value based on the time scale setting of the simulation and then:

- Processes time for server objects (serverProcess() in engine/game/game.cc)
- Checks for server network packet sends (serverNetProcess() in engine/game/netDispatch.cc)
- Advances simulation event time (Sim::advanceTime() in engine/console/simManager.cc)
- Processes time for client objects (clientProcess() in engine/game/game.cc)
- Checks for client network packet sends (clientNetProcess() in engine/game/netDispatch.cc)
- Renders the current frame (GuiCanvas::render() in engine/gui/guiCanvas.cc)
- Checks for network timeouts (dispatchCheckTimeouts() in engine/game/netDispatch.cc)

Incoming UDP network packets are processed in DemoGame::processPacketReceiveEvent (defined in engine/game/netDispatch.cc), and incoming TCP connection data or information is processed in DemoGame::processConnected*Event (defined in engine/game/TCPObject.cc).

And then more on the Platform Layer, console, Simulations, etc.
#5
10/31/2007 (7:06 am)
Exactley what I was looking for. I didnt see that! Thanks.
#6
10/31/2007 (7:18 am)
I apologize again for sounding rude or coming off wrong. It just seemed like a VERY open ended question.
#7
10/31/2007 (9:52 am)
Quote:
I am the type of person that likes to know inside and out, and all around of what I am working with.

I am exactly the same way so I totally understand where you're coming from. The problem is that most torque users are comfortable just modding the existing script base. Scripting things from the ground up is considered reinventing the wheel because there's such a huge amount of script functionality already written. here is a short explanation of startup as I understand it.

The engine starts up by reading main.cs which should be located in the same directory as the engine executable. main.cs can do whatever you want, but it should at least, set the log mode, set up searchable directories by calling "setmodpaths()", and exec() whatever files are needed for startup. before you can render any guis, you need to define them. which functions need to be loaded is up to you, but its usually best to just load all functionality at startup. You also need to set the preferences like resolution, full-screen/windowed, d3d/opengl. so at the very least, your guis and $prefs should be loaded at start up which makes sense when u think about it. one quirk I noticed about torque is that you cannot load objects which reference textures until the canvas is created, so be sure to keep that in mind.

once your prefs are defined, canvas is created, guis are loaded, and all necessary functionality is loaded,
everything is kicked off by setting your first interface using canvas.setContent(guiName).

you may see different ways of starting up the torque engine, but in general it's always the process explained above.

also keep in mind that the sound system needs to be initialized at some point too. this is really easy to do but it isn't required which is why I omitted it above.