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