home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 13 / Game / Main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  2.5 KB  |  65 lines

  1. //-----------------------------------------------------------------------------
  2. // Main.h implementation.
  3. // Refer to the Main.h interface for more details.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #include "Main.h"
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Application specific network message handler.
  12. //-----------------------------------------------------------------------------
  13. void HandleNetworkMessage( ReceivedMessage *msg )
  14. {
  15.     // Only allow network messages to be processed while in the game state.
  16.     if( g_engine->GetCurrentState()->GetID() != STATE_GAME )
  17.         return;
  18.  
  19.     // Pass control over to the game state's network message handler.
  20.     ( (Game*)g_engine->GetCurrentState() )->HandleNetworkMessage( msg );
  21. }
  22.  
  23. //-----------------------------------------------------------------------------
  24. // Application specific state setup.
  25. //-----------------------------------------------------------------------------
  26. void StateSetup()
  27. {
  28.     g_engine->AddState( new Menu, true );
  29.     g_engine->AddState( new Game, false );
  30. }
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Application specific material creation.
  34. //-----------------------------------------------------------------------------
  35. void CreateMaterialResource( Material **resource, char *name, char *path = "./" )
  36. {
  37.     *resource = new GameMaterial( name, path );
  38. }
  39.  
  40. //-----------------------------------------------------------------------------
  41. // Entry point for the application.
  42. //-----------------------------------------------------------------------------
  43. int WINAPI WinMain( HINSTANCE instance, HINSTANCE prev, LPSTR cmdLine, int cmdShow )
  44. {
  45.     // A unique id for the application so it can be identified on a network.
  46.     GUID guid = { 0xd6c55c78, 0x5030, 0x43b7, { 0x85, 0xa9, 0xc, 0x8b, 0xbe, 0x77, 0x5a, 0x62 } };
  47.  
  48.     // Create the engine setup structure.
  49.     EngineSetup setup;
  50.     setup.instance = instance;
  51.     setup.guid = guid;
  52.     setup.name = "Cityscape";
  53.     setup.scale = 0.01f;
  54.     setup.totalBackBuffers = 1;
  55.     setup.HandleNetworkMessage = HandleNetworkMessage;
  56.     setup.StateSetup = StateSetup;
  57.     setup.CreateMaterialResource = CreateMaterialResource;
  58.     setup.spawnerPath = "./Assets/Objects/";
  59.  
  60.     // Create the engine (using the setup structure), then run it.
  61.     new Engine( &setup );
  62.     g_engine->Run();
  63.  
  64.     return true;
  65. }