Game Development Community

Help getting a C++ guy started

by Chris Hunt · in Torque Game Engine · 03/28/2004 (7:48 am) · 7 replies

I've just bought torque and I'm desperate to get started. I'm still going through the docs, I already know C++ and intend to do most of my coding in C++ rather than script.
I'm not asking anyone to hold my hand, just I would like a little help getting a new project setup and running so I can start learning.


1 - Wheres the entry point? I assume there isnt one for C++, so I will have to lay out the basic framework in script and add in calls to my C++ code?

2 - How do I create my C++ project? Do I create a dll, or a win32 project, is there some kind of VC template file or something to create new projects from?

3 - How do i get an entry point into C++? I dont want to work from a demo fps or anything, I just want a nice empty project that I can run from VC.

#1
03/28/2004 (8:22 am)
1) Game.cc controls the main C++ program loop and main.cs starts the script side.
2) The download comes with various premade project files, including VS6 and Net.
3) I seem to recall there is a resource for an almost scriptless torque around here somewhere. Oh yes, it's at torque.feylab.com/index.php?c=ts

EDIt: Sorry, I can't find the Garagegames reference, so I'm posting website the garagegames link refers to.
#2
03/28/2004 (8:59 am)
I was wondering the same thing when I started Chris, the doxygen generated Torque documentation is actually pretty good in giving you an overview on the engine internals.

However if you want to see it for yourself I recommend creating a main.cs file in your example directory that simply contains 'quit();' and stepping through with a debugger. Here is what you'll find:

Torque 1.2.1 Engine Startup (Windows)
-------------------------------------

winWindow.cc:
  main()
  run()
  	winFont.cc: createFontInit();
  	Game->main();
  	createFontShutdown()
  	*END
  	
( Game is assigned in GameInterface constructor, 
  DemoGame inherits from GameInterface )
  	
DemoGame->main()
	main.cc::initLibraries()
		   Net::init();
		   PlatformAssert::Create()
		   FrameAllocator::init()
		   _StringTable::create()
		   TextureManager::create()
		   ResManager::create()
		   * Register resource manager extensions
		   RegisterCoreTypes();
		   RegisterMathTypes();
		   RegisterGuiTypes();
		   
		   Con::init();
		   NetStringTable::create();
		   
		   TelnetConsole::create();
		   TelnetDebugger::create();
		
		   Processor::init();
		   Math::init();
		   Platform::init();    // platform specific initialization
		   InteriorLMManager::init();
		   InteriorInstance::init();
		   TSShapeInstance::init();
		   RedBook::init();
	
	* Initializes global script argc, argvs
	main.cc::initGame()
		* Initializes global script variables
	        TerrainRender::init();
		netInit();
		GameInit();
		ShowInit();
		MoveManager::init();
		
		Sim::init();
		
		* create global actionmap
		* create global client and server scene graphs
		* create global decal manager
 	        
 	        DetailManager::init();
                PathManager::init();
                ParticleEngine::init();
		
		-> Execute "main.cs"		
		Con::executef(2, "eval", script);
	
	-> Main loop: the game remains in this loop forever unless the 
	   Game->isRunning state is changed ( e.g. quit() in the script );
							   	
   	while(Game->isRunning())
   	{
      	    PROFILE_START(MainLoop);
      	    Game->journalProcess();
            Net::process();      // read in all events
            Platform::process(); // keys, etc.
            TelConsole->process();
            TelDebugger->process();
            TimeManager::process(); // guaranteed to produce an event
            PROFILE_END();
        }

The actual entry point to the engine is within the cross-platform library, the main 'application' class is inherited from GameInterface, in the case of the example this is DemoGame.
#3
03/28/2004 (5:20 pm)
Thanks to you both, I have spent all day now reading docs and tutorials, although they're just teaching me the scripting language.

What I would like to do is make my game entirely in C++ and avoid any scripting. My plan is to base it on the Torque Demo project, in the torquesdk.sln. I dont mind all the existing scripts for starting up the game, I just dont want to make any more :)

So, if I want a main game loop, executed every frame, and I want a loop for each individual entity too, where would I put these? Presumably then the best place for the main loop is just before
PROFILE_END();
in main.cc?

but what about entities? I place a character model in the level, assign it a...datablock? can I define them in C++? And then what, how does it know what functions to run, does it have specific predefined functions like main and onCreate etc?

Also, if I am working in just C++ do I still have access to all the same functions etc as I would in script?

Thanks for all your help!
#4
03/28/2004 (6:56 pm)
Chris what you want is not really practical with Torque, it is designed to be driven by the scripting language. Well it is probably technically possible but so is moving a mountain with a plastic spoon. The scripting language and all this supporting infrastructure is very tighly coupled thru out the engine. It was never designed to NOT use the scripting facilities.
#5
03/29/2004 (9:07 am)
Chris, I've written a Checkers game that's 99% C++ code. In fact all the scripting I did do could be done from the GUI editor - all it consists of is the screen layout, and specifying the function call to make when you click a button. You just need to define some new script functions for yourself (for my game I only needed one). Here's the resource I found as a good starting point:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5103

Basically I added a new script method "StartCheckersGame" which sets up the game. I also created a custom GUI control to handle the board, and it traps all the mouse events and calls out to my Checkers code to handle it.

Jarrod is right in that removing the script altogether would be a huge undertaking. But it is possible to largely ignore the script and just write C++ code. My recommendation is to take a look at the MinApp tutorials, starting at:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5091

They start with a bare-bones app (i.e: minimum amount of script required), so if you want to write you game in C++, that's a good starting point.

As for having access to all the same functions - basically yes. You have the full source code, meaning you have the C++ code behind those functions. Just do search for the function name, and you'll find where it's exposed to the scipt, and what the C++ call(s) are behind it. Then ignore the script method, and make the C++ call(s) yourself.

So it is possible to at least largely ignore the scripting. The hardest part for me was the network code. I found the messages are tied pretty tightly to the script (or at least the $pref::server script variables). For myself, I wrote my own connection class instead of using GameConnection, so sidestepped that whole issue. For checkers that was pretty easy (there isn't a lot of messages required), but if you're looking at a real-time game (whether FPS or something else), you'll likely have a harder time - but not impossible!
#6
03/29/2004 (10:28 am)
Quote:Just do search for the function name, and you'll find where it's exposed to the scipt, and what the C++ call(s) are behind it. Then ignore the script method, and make the C++ call(s) yourself.

I am not so sure this will work in all cases. There was posts a while ago that this did not work in lots of cases because of statemachine issues where the scripting environment needed to be set up and that you were in "undefined behavior" territory when doing this.

I have never tried this, just because there really is no need burden myself with tracking down undefined behavior in such a large code base. It is no secret that I am not a fan of TorqueScript ( because of the syntax not the idea of scripting which I love ) but it is better than not having a scripting facility period.
#7
03/29/2004 (11:24 am)
It's hard to see how that's possible - I'd be curious to learn what kind of methods they're talking about. In any case, I haven't done a lot of that, so I can't really comment ...

However, I haven't had any problems yet using C++. Then again, I'm writing TBS games, so the kinds of things I need to do are very different from a real-time game (like a FPS).

As for the TorqueScript, I do like that it's there. I want to make my games mod-able to a degree, and I think script can be a great tool for that ... but only specific portions will be done that way. Most of my game code will be written strictly in C++.