home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 9 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-20  |  5.6 KB  |  156 lines

  1. //-----------------------------------------------------------------------------
  2. // The primary engine header file. This file links the entire engine together
  3. // and is the only header file that needs to be included in any project using
  4. // the engine.
  5. //
  6. // Programming a Multiplayer First Person Shooter in DirectX
  7. // Copyright (c) 2004 Vaughan Young
  8. //-----------------------------------------------------------------------------
  9. #ifndef ENGINE_H
  10. #define ENGINE_H
  11.  
  12. //-----------------------------------------------------------------------------
  13. // DirectInput Version Define
  14. //-----------------------------------------------------------------------------
  15. #define DIRECTINPUT_VERSION 0x0800
  16.  
  17. //-----------------------------------------------------------------------------
  18. // System Includes
  19. //-----------------------------------------------------------------------------
  20. #include <stdio.h>
  21. #include <tchar.h>
  22. #include <windowsx.h>
  23.  
  24. //-----------------------------------------------------------------------------
  25. // DirectX Includes
  26. //-----------------------------------------------------------------------------
  27. #include <d3dx9.h>
  28. #include <dinput.h>
  29. #include <dplay8.h>
  30. #include <dmusici.h>
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Macros
  34. //-----------------------------------------------------------------------------
  35. #define SAFE_DELETE( p )       { if( p ) { delete ( p );     ( p ) = NULL; } }
  36. #define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p );   ( p ) = NULL; } }
  37. #define SAFE_RELEASE( p )      { if( p ) { ( p )->Release(); ( p ) = NULL; } }
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Engine Includes
  41. //-----------------------------------------------------------------------------
  42. #include "Resource.h"
  43. #include "LinkedList.h"
  44. #include "ResourceManagement.h"
  45. #include "Geometry.h"
  46. #include "Font.h"
  47. #include "Scripting.h"
  48. #include "DeviceEnumeration.h"
  49. #include "Input.h"
  50. #include "Network.h"
  51. #include "SoundSystem.h"
  52. #include "BoundingVolume.h"
  53. #include "Material.h"
  54. #include "Mesh.h"
  55. #include "SceneObject.h"
  56. #include "AnimatedObject.h"
  57. #include "SpawnerObject.h"
  58. #include "RenderCache.h"
  59. #include "State.h"
  60.  
  61. //-----------------------------------------------------------------------------
  62. // Engine Setup Structure
  63. //-----------------------------------------------------------------------------
  64. struct EngineSetup
  65. {
  66.     HINSTANCE instance; // Application instance handle.
  67.     GUID guid; // Application GUID.
  68.     char *name; // Name of the application.
  69.     float scale; // Unit scale in meters/unit.
  70.     unsigned char totalBackBuffers; // Number of back buffers to use.
  71.     void (*HandleNetworkMessage)( ReceivedMessage *msg ); // Network message handler.
  72.     void (*StateSetup)(); // State setup function.
  73.     void (*CreateMaterialResource)( Material **resource, char *name, char *path ); // Material resource creation function.
  74.     char *spawnerPath; // Path for locating the spawner object scripts.
  75.  
  76.     //-------------------------------------------------------------------------
  77.     // The engine setup structure constructor.
  78.     //-------------------------------------------------------------------------
  79.     EngineSetup()
  80.     {
  81.         GUID defaultGUID = { 0x24215591, 0x24c0, 0x4316, { 0xb5, 0xb2, 0x67, 0x98, 0x2c, 0xb3, 0x82, 0x54 } };
  82.  
  83.         instance = NULL;
  84.         guid = defaultGUID;
  85.         name = "Application";
  86.         scale = 1.0f;
  87.         totalBackBuffers = 1;
  88.         HandleNetworkMessage = NULL;
  89.         StateSetup = NULL;
  90.         CreateMaterialResource = NULL;
  91.         spawnerPath = "./";
  92.     }
  93. };
  94.  
  95. //-----------------------------------------------------------------------------
  96. // Engine Class
  97. //-----------------------------------------------------------------------------
  98. class Engine
  99. {
  100. public:
  101.     Engine( EngineSetup *setup = NULL );
  102.     virtual ~Engine();
  103.  
  104.     void Run();
  105.  
  106.     HWND GetWindow();
  107.     void SetDeactiveFlag( bool deactive );
  108.  
  109.     float GetScale();
  110.     IDirect3DDevice9 *GetDevice();
  111.     D3DDISPLAYMODE *GetDisplayMode();
  112.     ID3DXSprite *GetSprite();
  113.  
  114.     void AddState( State *state, bool change = true );
  115.     void RemoveState( State *state );
  116.     void ChangeState( unsigned long id );
  117.     State *GetCurrentState();
  118.  
  119.     ResourceManager< Script > *GetScriptManager();
  120.     ResourceManager< Material > *GetMaterialManager();
  121.     ResourceManager< Mesh > *GetMeshManager();
  122.  
  123.     Input *GetInput();
  124.     Network *GetNetwork();
  125.     SoundSystem *GetSoundSystem();
  126.  
  127. private:
  128.     bool m_loaded; // Indicates if the engine is loading.
  129.     HWND m_window; // Main window handle.
  130.     bool m_deactive; // Indicates if the application is active or not.
  131.  
  132.     EngineSetup *m_setup; // Copy of the engine setup structure.
  133.     IDirect3DDevice9 *m_device; // Direct3D device interface.
  134.     D3DDISPLAYMODE m_displayMode; // Display mode of the current Direct3D device.
  135.     ID3DXSprite *m_sprite; // Sprite interface for rendering 2D textured primitives.
  136.     unsigned char m_currentBackBuffer; // Keeps track of which back buffer is at the front of the swap chain.
  137.  
  138.     LinkedList< State > *m_states; // Linked list of states.
  139.     State *m_currentState; // Pointer to the current state.
  140.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  141.  
  142.     ResourceManager< Script > *m_scriptManager; // Script manager.
  143.     ResourceManager< Material > *m_materialManager; // Material manager.
  144.     ResourceManager< Mesh > *m_meshManager; // Mesh manager.
  145.  
  146.     Input *m_input; // Input object.
  147.     Network *m_network; // Network object.
  148.     SoundSystem *m_soundSystem; // Sound system.
  149. };
  150.  
  151. //-----------------------------------------------------------------------------
  152. // Externals
  153. //-----------------------------------------------------------------------------
  154. extern Engine *g_engine;
  155.  
  156. #endif