home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / source / gs_input.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-30  |  2.2 KB  |  110 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Module:    gsCInput
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    12/03/00
  8. //
  9. // Base:    None
  10. //
  11. // Derived:    gsCKeyboard
  12. //            gsCMouse
  13. //            gsCJoystick
  14. //
  15. //-------------------------------------------------------------
  16.  
  17. #include "gamesystem.h"
  18.  
  19. //-------------------------------------------------------------
  20.  
  21. gsLPDIRECTINPUT gsCInput::m_direct_input = 0;
  22. gsCList<gsCInput *> gsCInput::m_active_inputs;
  23.  
  24. //-------------------------------------------------------------
  25.  
  26. bool gsCInput::initialize()
  27. {
  28.     if (m_direct_input == 0) {
  29.         if (gsCApplication::getInstance() == 0) {
  30.             gsREPORT("gsCInput::initialize called with no application instance");
  31.             return false;
  32.             }
  33.  
  34.         HRESULT hr;
  35.  
  36. #ifdef gsDIRECTX_NT_COMPATIBLE
  37.  
  38.         hr = DirectInputCreate(gsCApplication::getInstance(),
  39.                                  DIRECTINPUT_VERSION,
  40.                                  &m_direct_input,
  41.                                  NULL);
  42.  
  43. #else
  44.  
  45.         hr = DirectInputCreateEx(gsCApplication::getInstance(),
  46.                                  DIRECTINPUT_VERSION,
  47.                                  gsID_DIRECTINPUT,
  48.                                  (void **) &m_direct_input,
  49.                                  NULL);
  50. #endif
  51.         
  52.         if (hr != DI_OK) {
  53.             gsREPORT("gsCInput::initialize couldn't create direct input");
  54.             return false;
  55.             }
  56.         }
  57.     return true;
  58. }
  59.  
  60. //-------------------------------------------------------------
  61.  
  62. bool gsCInput::shutdown()
  63. {
  64.     if (m_direct_input) {
  65.         m_direct_input->Release();
  66.         m_direct_input = 0;
  67.         }
  68.  
  69.     return true;
  70. }
  71.  
  72. //-------------------------------------------------------------
  73.  
  74. bool gsCInput::acquireAll()
  75. {
  76.     for (int i = 0; i < m_active_inputs.getSize(); i++) {
  77.         if (!m_active_inputs[i]->acquire())
  78.             gsREPORT("failed to acquire input");
  79.         }
  80.  
  81.     return true;
  82. }
  83.  
  84. //-------------------------------------------------------------
  85.  
  86. bool gsCInput::updateAll()
  87. {
  88.     for (int i = 0; i < m_active_inputs.getSize(); i++) {
  89.         if (!m_active_inputs[i]->update())
  90.             gsREPORT("failed to update input");
  91.         }
  92.  
  93.     return true;
  94. }
  95.  
  96. //-------------------------------------------------------------
  97.  
  98. gsCInput::gsCInput()
  99. {
  100. }
  101.  
  102. //-------------------------------------------------------------
  103.  
  104. gsCInput::~gsCInput()
  105. {
  106. }
  107.  
  108. //-------------------------------------------------------------
  109.  
  110.