Game Development Community

Source code's start

by Alpha-Kand · in Torque Game Builder · 09/07/2012 (5:44 pm) · 2 replies

I could probably find it myself but there are SO many source code files, just to be sure I'll ask here. Where does the game start, which function does it start in or in what file does it start? If I know anything about programming it HAS to start somewhere but that isn't always clear. :)

About the author

I have always loved video games and computer games so decided to try making my own. Spent a little more than a year on a program simply named Game Maker which really got me interested. Finally decided to get "professional" by getting Torque 2D.


#1
09/07/2012 (7:02 pm)
Hi Alpha-Kand,
usually you should search for function called main or something similar. There's a simple method to find an entry point: just use an ide (visual studio for Windows or X-Code if you use Mac) to put some break points here and there. When the execution is stopped, search for a window called Call Stack. There you will find all calls the program used to reach the break point, entry point included.

In my case, running on a Windows machine, you can consider the entry point the following method:

[/engine/source/platformWin32winWindow.cc] S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)

Aside from this very technical (window handling) entry point, here is the calls stack to reach the classic main loop. Please consider from here on I removed /engine/source in front of all the file path.

[/platformWin32/winWindow.cc] S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
[/platformWin32/winWindow.cc] static S32 run(S32 argc, const char **argv)
[/platform/gameInterface.cc] int GameInterface::main(int argc, const char** argv)

Now begins the init process...

[/game/main.cc] bool DemoGame::mainInit(int argc, const char **argv)
[/game/main.cc] bool initGame(int argc, const char **argv)
[/game/main.cc] bool runEntryScript(int argc, const char **argv)

This is the moment when program loads its first .cs file. If all is completed correctly, all functions returns true, init process is completed, and we return to

[/platform/gameInterface.cc] int GameInterface::main(int argc, const char** argv)

and finally the real main loop is called

[/game/main.cc] void DemoGame::mainLoop()

Happy coding.
#2
09/08/2012 (7:30 pm)
Your answer is a fantastic answer. Thank you so much!
Silly me searched the solution and such for "int main". I thought "Surely even a project this big must start like every other project in c++ I have created" (when learning c++). Obviously I was wrong. :)

Also I didn't know you could use VS for debugging with break points. It doesn't do that YET though because it wants stuff in special spots and they aren't there so I have to work with it to set it up properly...