Initialization


The control/initialize.cs module will, in later chapters, become two different modules— one for the server code and one for the client code. Right now, we have a fairly limited amount of work to do, so we'll just house the initialization functions for the two ends in the same module. Here is the control/initialize.cs module. Type it in and save it as Emaga4\control\initialize.cs.

 //============================================================================ // control/initialize.cs // //  control initialization module for 3DGPAI1 emaga4 tutorial game // //  Copyright (c) 2003 by Kenneth C. Finney. //============================================================================ function InitializeServer() //---------------------------------------------------------------------------- // Prepare some global server information & load the game-specific module //---------------------------------------------------------------------------- {    Echo("\n--------- Initializing module: emaga server ---------");    // Specify where the mission files are.    $Server::MissionFileSpec = "*/missions/*.mis";    InitBaseServer(); // basic server features defined in the common modules    // Load up game server support script    Exec("./server.cs");    createServer("SinglePlayer", "control/data/maps/book_ch4.mis"); } function InitializeClient() //---------------------------------------------------------------------------- // Prepare some global client information, fire up the graphics engine, // and then connect to the server code that is already running in another // thread. //---------------------------------------------------------------------------- {    Echo("\n--------- Initializing module: emaga client ---------");    InitBaseClient(); // basic client features defined in the common modules  // these are necessary graphics settings  $pref::Video::allowOpenGL = true;  $pref::Video::displayDevice = "OpenGL";    // Make sure a canvas has been built before any gui scripts are    // executed because many of the controls depend on the canvas to    // already exist when they are loaded.    InitCanvas("Egama4 - 3DGPAi1 Sample Game"); // Start the graphics system.    Exec("./client.cs");    %conn = new GameConnection(ServerConnection);    %conn.connectLocal(); } 

First is the InitializeServer() function. This is where we set up a global variable that indicates to the game engine the folder tree where the map (also called mission) files will be located.

Next, we prepare the server for operation by performing the common code initialization using the InitBaseServer() function. This allows us to get the server code running full-bore, which we can do using the createServer() call. We tell the function that this will be a single-player game and that we are going to load up the map control/data/maps/book_ch4.mis.

After that, we load the module that contains the game code, which is server-side code.

Then we do the client-side initialization in the InitializeClient() function. This is a bit more involved. After performing the common code initialization with InitBaseClient(), we set up some global variables that the engine uses to prepare the graphics system for start-up.

And that happens with the InitCanvas() call. The parameter we pass in is a string that specifies the name of the window that the game will be running in.

Then we load the control/client.cs module, which we'll cover next in this chapter.

We're getting warm now!

Next, we create a connection object using the GameConnection() function. This gives us an object that we will use from now on when referring to the connection.

Now we use that connection object to connect to the server using a local connection. We don't ever actually use the network or any network ports.




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