Game Development Community

Where Does TGE Begin (C++ Question)?

by Brian C. · in Torque Game Engine · 01/21/2006 (9:28 pm) · 10 replies

Hi,

I've just spent the past 30 minutes trying to find the starting point in the TGE source code. I was taught long ago that a Windows C/C++ program begins with WinMain, but this is apparently not the case with TGE! I discovered this by debugging, and noticed the WinMain is not called during startup (or ever afaik). I want to find it in order to trace the code from the beginning to some undetermined point, so that I may learn how it works at a lower level.

Thanks much!

#1
01/21/2006 (9:34 pm)
I'm no Windows programming guru, but I don't think it has a WinMain() because its a console app.

I just checked the code...looks like it has both main() and a WinMain()

Look in engine\platformWin3\winWindow.cc

This is what your looking for.

I'm thinking now maybe that because Torque can run either full-screen or in window mode that it needs both?

I'm not really sure how that works to be honest. It will be nice to hear the experts on this.

Steve
#2
01/21/2006 (9:47 pm)
If I'm not mistaken, you should find what you're looking for in the ..\engine\game\main.cc file. Specifically, do a search for the DemoGame::main() method.
#3
01/21/2006 (9:56 pm)
I think one of those main functions call the other in game/main.cc the demo one.

It gets confusing so I'm not 100% sure.

Hmm, yep, traced it a little more... run() in winWindow.cc calls Game->main()

Steve
#4
01/21/2006 (10:31 pm)
Thanks guys, I think the main in engine\platformWin32\winWindow.cc is what I'm looking for - that's where a console app would begin. Very interesting how there's both a main and a WinMain, never saw that before.
#5
01/22/2006 (9:04 am)
There's always a "main". In Windows, you link in the CRT (common run-time) and it's main does some work before calling "WinMain" which is what you implement. As far as C / C++ goes, the start of coding is always "main."

Not to be a jerk, couldn't you have solved this problem by just "stepping" into the execution of your game to see where the code starts?
#6
01/22/2006 (10:16 am)
Jason,

Just because we have the source code to TGE doesn't mean we are programming experts!

Everyone needs to start somewhere.

Thanks for the tip though on stepping through the execution of the engine and the fact all Windows apps have a main and WinMain(). Coming from UNIX myself I'm not all that familiar with (and don't really want to be) how Windows does things. :)

Steve
#7
01/22/2006 (12:46 pm)
You must want to be familiar with it if you're asking the question... ;)
#8
01/22/2006 (1:06 pm)
Mild curiosity on my part. Maybe more so for the original poster.

:)
#9
01/22/2006 (1:57 pm)
Just keep in mind that as a Torque developer, you really don't even want to know what's going on at that deep of a level. It's extremely rare to need to worry about the underlying systems--best instead to learn how to use those systems well.

From a Torque developer perspective, the important answer to your question is probably "onStart" in main.cs for the starter directory you are using, more specifically initServer() and initClient().

And from a pure game perspective (at least getting to know Torque), even more important is GameConnection::onClientEnterGame() in /server/scripts/game.cs--that's the first real point where a client is placed in the simulation after connecting.
#10
01/22/2006 (10:34 pm)
Stepping in was the first thing I tried. Instead of going to the first line of code, it ran as though I had pressed the Start command. I must have some setting off somewhere. I forgot about that regarding main and WinMain - I just always took for granted that execution (appears to) begin with WinMain in Windows and main in DOS and Unix (even though C/C++ is supposed to begin with main always, as you said).

Actually, sad to say I've been programming C/C++ on Windows for over a decade (since 3.1), though as a part-time hobbyist mostly, and focused on non-Windows related components. I am brand new to scripting though. I want to study the source code because I like knowing what's going on under the hood just for the sake of knowing. :)

Thanks for the script start info Stephen, and thanks everyone else too. :)