Control Main


The main.cs module for the control code is next on our tour. Its primary purposes in Emaga4 are to define the control package and to call the control code initialization functions. (In later chapters we will expand on the role of this module.) Following is the control/main.cs module. Type it in and save it as Emaga4\control\main.cs.

 //------------------------------------------------------------------------ // control/main.cs //  main control module for 3DGPAI1 emaga4 tutorial game // //  Copyright (c) 2003 by Kenneth C. Finney. //------------------------------------------------------------------------ // //----------------------------------------------------------------------------- // Load up defaults console values. // Defaults console values //----------------------------------------------------------------------------- // Package overrides to initialize the mod. package control { function OnStart() //------------------------------------------------------------------------ // Called by root main when package is loaded //------------------------------------------------------------------------ {    Parent::OnStart();    Echo("\n--------- Initializing control module ---------");    // The following scripts contain the preparation code for    // both the client and server code. A client can also host    // games, so they need to be able to act as servers if the    // user wants to host a game. That means we always prepare    // to be a server at anytime, unless we are launched as a    // dedicated server.    Exec("./initialize.cs");    InitializeServer(); // Prepare the server-specific aspects    InitializeClient(); // Prepare the client-specific aspects } function OnExit() //------------------------------------------------------------------------ // Called by root main when package is unloaded //------------------------------------------------------------------------ {    Parent::onExit(); } }; // Client package ActivatePackage(control); // Tell TGE to make the client package active 

Not a whole lot happens in here at the moment, but it is a necessary module because it defines our control package.

First, the parent OnStart() function is called. This would be the version that resides in root main, which we can see doesn't have anything to do.

Then the initialize.cs module is loaded, after which the two initialization functions are called.

Finally, there is the OnExit() function, which does nothing more than pass the buck to the OnExit() function in the root main module.

All in all, control/main.cs is a fairly lazy, though important, little module.

start sidebar
Debugging Scripts Using the trace() Function

The engine adds extra commentary to the log file. Extremely useful are the notations that tell you when the engine execution has just begun executing in a particular function or is just about to leave a particular function.The trace lines include the values of any arguments used when the function is entered and the contents of the return value when leaving a function.

Here is a fragmentary example of what the trace output can look like:

 Entering GameConnection::InitialControlSet(1207) Setting Initial Control Object    Entering Editor::checkActiveLoadDone()    Leaving Editor::checkActiveLoadDone - return 0    Entering GuiCanvas::setContent(Canvas, PlayGui)       Entering PlayGui::onWake(1195)    Activating DirectInput...    keyboard0 input device acquired.       Leaving PlayGui::onWake - return       Entering GuiCanvas::checkCursor(Canvas)          Entering (null)::cursorOff()          Leaving (null)::cursorOff - return       Leaving GuiCanvas::checkCursor - return    Leaving GuiCanvas::setContent - return Leaving GameConnection::InitialControlSet - return Entering (null)::DoYaw(-9) Leaving (null)::DoYaw - return -0.18 Entering (null)::DoPitch(7) Leaving (null)::DoPitch - return 0.14 Entering (null)::DoYaw(-6) 

To turn on the trace function, add the following statement to the first line of your root main.cs file:

 trace(true); 

To turn off the trace function, insert this statement at the place in the code where you would like to turn tracing off:

 Trace(false); 
end sidebar




3D Game Programming All in One
3D Game Programming All in One (Course Technology PTR Game Development Series)
ISBN: 159200136X
EAN: 2147483647
Year: 2006
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net