home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 5 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  4.5 KB  |  129 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 "State.h"
  51.  
  52. //-----------------------------------------------------------------------------
  53. // Engine Setup Structure
  54. //-----------------------------------------------------------------------------
  55. struct EngineSetup
  56. {
  57.     HINSTANCE instance; // Application instance handle.
  58.     char *name; // Name of the application.
  59.     float scale; // Unit scale in meters/unit.
  60.     unsigned char totalBackBuffers; // Number of back buffers to use.
  61.     void (*StateSetup)(); // State setup function.
  62.  
  63.     //-------------------------------------------------------------------------
  64.     // The engine setup structure constructor.
  65.     //-------------------------------------------------------------------------
  66.     EngineSetup()
  67.     {
  68.         instance = NULL;
  69.         name = "Application";
  70.         scale = 1.0f;
  71.         totalBackBuffers = 1;
  72.         StateSetup = NULL;
  73.     }
  74. };
  75.  
  76. //-----------------------------------------------------------------------------
  77. // Engine Class
  78. //-----------------------------------------------------------------------------
  79. class Engine
  80. {
  81. public:
  82.     Engine( EngineSetup *setup = NULL );
  83.     virtual ~Engine();
  84.  
  85.     void Run();
  86.  
  87.     HWND GetWindow();
  88.     void SetDeactiveFlag( bool deactive );
  89.  
  90.     float GetScale();
  91.     IDirect3DDevice9 *GetDevice();
  92.     D3DDISPLAYMODE *GetDisplayMode();
  93.     ID3DXSprite *GetSprite();
  94.  
  95.     void AddState( State *state, bool change = true );
  96.     void RemoveState( State *state );
  97.     void ChangeState( unsigned long id );
  98.     State *GetCurrentState();
  99.  
  100.     ResourceManager< Script > *GetScriptManager();
  101.  
  102.     Input *GetInput();
  103.  
  104. private:
  105.     bool m_loaded; // Indicates if the engine is loading.
  106.     HWND m_window; // Main window handle.
  107.     bool m_deactive; // Indicates if the application is active or not.
  108.  
  109.     EngineSetup *m_setup; // Copy of the engine setup structure.
  110.     IDirect3DDevice9 *m_device; // Direct3D device interface.
  111.     D3DDISPLAYMODE m_displayMode; // Display mode of the current Direct3D device.
  112.     ID3DXSprite *m_sprite; // Sprite interface for rendering 2D textured primitives.
  113.     unsigned char m_currentBackBuffer; // Keeps track of which back buffer is at the front of the swap chain.
  114.  
  115.     LinkedList< State > *m_states; // Linked list of states.
  116.     State *m_currentState; // Pointer to the current state.
  117.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  118.  
  119.     ResourceManager< Script > *m_scriptManager; // Script manager.
  120.  
  121.     Input *m_input; // Input object.
  122. };
  123.  
  124. //-----------------------------------------------------------------------------
  125. // Externals
  126. //-----------------------------------------------------------------------------
  127. extern Engine *g_engine;
  128.  
  129. #endif