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