Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "inputsystem.h"
  7. #include "key_translation.h"
  8. #include "inputsystem/ButtonCode.h"
  9. #include "inputsystem/AnalogCode.h"
  10. #include "tier1/convar.h"
  11. typedef void*(*NovintGetIHaptics_t)(void);
  12. typedef bool (*NovintAttemptHWND_t)(void *hWnd);
  13. typedef void (*NovintDisableHWND_t)(void);
  14. typedef void (*NovintPollDevices_t)(void);
  15. typedef bool (*NovintButtonState_t)(int nDevice,
  16. int &down,
  17. int &pressed,
  18. int &released);
  19. typedef int (*NovintDeviceCount_t)();
  20. typedef int (*NovintButtonCount_t)(int nDevice);
  21. typedef bool (__cdecl *NovintMouseModeCallback_t) (void);
  22. typedef void (*NovintInputActive_t)(bool bGameInput);
  23. typedef __int64 (*NovintGetDeviceID_t)(int nDevice);
  24. NovintGetIHaptics_t NovintGetIHaptics = NULL;
  25. NovintAttemptHWND_t NovintAttemptHWND = NULL;
  26. NovintDisableHWND_t NovintDisableHWND = NULL;
  27. NovintPollDevices_t NovintPollDevices = NULL;
  28. NovintButtonState_t NovintButtonState = NULL;
  29. NovintDeviceCount_t NovintDeviceCount = NULL;
  30. NovintButtonCount_t NovintButtonCount = NULL;
  31. NovintInputActive_t NovintInputActive = NULL;
  32. NovintGetDeviceID_t NovintGetDeviceID = NULL;
  33. static CInputSystem *pNovintInputSystem = 0;
  34. static bool bNovintPure = false;
  35. bool __cdecl NovintDevicesInputMode(void)
  36. {
  37. if(pNovintInputSystem)
  38. {
  39. return !bNovintPure;
  40. }
  41. return false;
  42. }
  43. void *CInputSystem::GetHapticsInterfaceAddress(void)const
  44. {
  45. if( NovintGetIHaptics )
  46. return NovintGetIHaptics();
  47. return NULL;
  48. }
  49. void CInputSystem::AttachWindowToNovintDevices( void * hWnd )
  50. {
  51. if( NovintAttemptHWND )
  52. NovintAttemptHWND( hWnd );
  53. }
  54. void CInputSystem::DetachWindowFromNovintDevices(void)
  55. {
  56. if( NovintDisableHWND )
  57. NovintDisableHWND();
  58. }
  59. void CInputSystem::InitializeNovintDevices()
  60. {
  61. pNovintInputSystem = this;
  62. // assume no novint devices
  63. m_bNovintDevices = false;
  64. m_nNovintDeviceCount = 0;
  65. if(!m_pNovintDLL)
  66. return;
  67. NovintGetIHaptics = (NovintGetIHaptics_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintGetIHaptics" );
  68. NovintAttemptHWND = (NovintAttemptHWND_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintAttemptHWND" );
  69. NovintDisableHWND = (NovintDisableHWND_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintDisableHWND" );
  70. NovintPollDevices = (NovintPollDevices_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintPollDevices" );
  71. NovintButtonState = (NovintButtonState_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintButtonState" );
  72. NovintDeviceCount = (NovintDeviceCount_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintDeviceCount" );
  73. NovintButtonCount = (NovintButtonCount_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintButtonCount" );
  74. NovintGetDeviceID = (NovintGetDeviceID_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintGetDeviceID" );
  75. NovintInputActive = (NovintInputActive_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintInputActive" );
  76. m_nNovintDeviceCount = NovintDeviceCount();
  77. if( m_nNovintDeviceCount > 0 )
  78. m_bNovintDevices = true;
  79. }
  80. void CInputSystem::PollNovintDevices()
  81. {
  82. if( NovintPollDevices )
  83. NovintPollDevices();
  84. for ( int i = 0; i < m_nNovintDeviceCount; i++ )
  85. {
  86. UpdateNovintDeviceButtonState(i);
  87. }
  88. }
  89. void CInputSystem::UpdateNovintDeviceButtonState(int nDevice)
  90. {
  91. int nDown;
  92. int nPressed;
  93. int nReleased;
  94. if(NovintButtonState(nDevice, nDown, nPressed, nReleased))
  95. {
  96. for ( int i = 0; i < 4; i++ )
  97. {
  98. ButtonCode_t code = (ButtonCode_t)( NOVINT_FIRST + ( nDevice * 4 ) + i );
  99. if( nPressed & (1 << i) )
  100. {
  101. PostButtonPressedEvent(IE_ButtonPressed, m_nLastSampleTick, code, KEY_NONE);
  102. }
  103. if( nReleased & (1 << i) )
  104. {
  105. PostButtonReleasedEvent(IE_ButtonReleased, m_nLastSampleTick, code, KEY_NONE);
  106. }
  107. }
  108. }
  109. }
  110. void CInputSystem::SetNovintPure( bool bPure )
  111. {
  112. bNovintPure = bPure;
  113. if(NovintInputActive)
  114. NovintInputActive(bNovintPure);
  115. }