win_input.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idlib/precompiled.h"
  22. //#if defined( ID_VS2010 )
  23. //#include "../../../libs/dxsdk_June2010/include/xinput.h"
  24. //#else
  25. #include <Xinput.h>
  26. //#endif
  27. static const int MAX_JOYSTICKS = 4;
  28. /*
  29. ================================================================================================
  30. Joystick Win32
  31. ================================================================================================
  32. */
  33. struct controllerState_t {
  34. // the current states are updated by the input thread at 250 hz
  35. XINPUT_STATE current;
  36. // the previous state is latched at polling time
  37. XINPUT_STATE previous;
  38. // The current button bits are or'd into this at the high sampling rate, then
  39. // zero'd by the main thread when a usercmd_t is created. This prevents the
  40. // complete missing of a button press that went down and up between two usercmd_t
  41. // creations, although it can add sn extra frame of latency to sensing a release.
  42. int buttonBits;
  43. // Only valid controllers will have their rumble set
  44. bool valid;
  45. };
  46. class idJoystickWin32 : idJoystick {
  47. public:
  48. idJoystickWin32();
  49. virtual bool Init();
  50. virtual void SetRumble( int deviceNum, int rumbleLow, int rumbleHigh );
  51. virtual int PollInputEvents( int inputDeviceNum );
  52. virtual int ReturnInputEvent( const int n, int &action, int &value );
  53. virtual void EndInputEvents() {}
  54. protected:
  55. friend void JoystickSamplingThread( void *data );
  56. void PushButton( int inputDeviceNum, int key, bool value );
  57. void PostInputEvent( int inputDeviceNum, int event, int value, int range = 16384 );
  58. idSysMutex mutexXis; // lock this before using currentXis or stickIntegrations
  59. HANDLE timer; // fire every 4 msec
  60. int numEvents;
  61. struct {
  62. int event;
  63. int value;
  64. } events[ MAX_JOY_EVENT ];
  65. controllerState_t controllers[ MAX_JOYSTICKS ];
  66. // should these be per-controller?
  67. bool buttonStates[MAX_INPUT_DEVICES][K_LAST_KEY]; // For keeping track of button up/down events
  68. int joyAxis[MAX_INPUT_DEVICES][MAX_JOYSTICK_AXIS]; // For keeping track of joystick axises
  69. };