home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 3 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  3.7 KB  |  108 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 "LinkedList.h"
  43. #include "ResourceManagement.h"
  44. #include "Geometry.h"
  45. #include "Input.h"
  46. #include "State.h"
  47.  
  48. //-----------------------------------------------------------------------------
  49. // Engine Setup Structure
  50. //-----------------------------------------------------------------------------
  51. struct EngineSetup
  52. {
  53.     HINSTANCE instance; // Application instance handle.
  54.     char *name; // Name of the application.
  55.     void (*StateSetup)(); // State setup function.
  56.  
  57.     //-------------------------------------------------------------------------
  58.     // The engine setup structure constructor.
  59.     //-------------------------------------------------------------------------
  60.     EngineSetup()
  61.     {
  62.         instance = NULL;
  63.         name = "Application";
  64.         StateSetup = NULL;
  65.     }
  66. };
  67.  
  68. //-----------------------------------------------------------------------------
  69. // Engine Class
  70. //-----------------------------------------------------------------------------
  71. class Engine
  72. {
  73. public:
  74.     Engine( EngineSetup *setup = NULL );
  75.     virtual ~Engine();
  76.  
  77.     void Run();
  78.  
  79.     HWND GetWindow();
  80.     void SetDeactiveFlag( bool deactive );
  81.  
  82.     void AddState( State *state, bool change = true );
  83.     void RemoveState( State *state );
  84.     void ChangeState( unsigned long id );
  85.     State *GetCurrentState();
  86.  
  87.     Input *GetInput();
  88.  
  89. private:
  90.     bool m_loaded; // Indicates if the engine is loading.
  91.     HWND m_window; // Main window handle.
  92.     bool m_deactive; // Indicates if the application is active or not.
  93.  
  94.     EngineSetup *m_setup; // Copy of the engine setup structure.
  95.  
  96.     LinkedList< State > *m_states; // Linked list of states.
  97.     State *m_currentState; // Pointer to the current state.
  98.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  99.  
  100.     Input *m_input; // Input object.
  101. };
  102.  
  103. //-----------------------------------------------------------------------------
  104. // Externals
  105. //-----------------------------------------------------------------------------
  106. extern Engine *g_engine;
  107.  
  108. #endif