Counter Strike : Global Offensive Source Code
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.

159 lines
4.1 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "forcefeedback.h"
  8. #include "igamesystem.h"
  9. // NOTE: This has to be the last file included!
  10. #include "tier0/memdbgon.h"
  11. class CForceFeedback : public IForceFeedback, public CAutoGameSystem
  12. {
  13. public:
  14. virtual bool Init();
  15. virtual void Shutdown();
  16. // API
  17. virtual void StopAllEffects( CBasePlayer *player );
  18. virtual void StopEffect( CBasePlayer *player, FORCEFEEDBACK_t effect );
  19. virtual void StartEffect( CBasePlayer *player, FORCEFEEDBACK_t effect, const FFBaseParams_t& params );
  20. virtual void PauseAll( CBasePlayer *player );
  21. virtual void ResumeAll( CBasePlayer *player );
  22. };
  23. static CForceFeedback g_ForceFeedbackSingleton;
  24. IForceFeedback *forcefeedback = &g_ForceFeedbackSingleton;
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. // Output : Returns true on success, false on failure.
  28. //-----------------------------------------------------------------------------
  29. bool CForceFeedback::Init()
  30. {
  31. return true;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CForceFeedback::Shutdown()
  37. {
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. // Input : *player -
  42. //-----------------------------------------------------------------------------
  43. void CForceFeedback::StopAllEffects( CBasePlayer *player )
  44. {
  45. if ( !player )
  46. return;
  47. CSingleUserRecipientFilter user( player );
  48. UserMessageBegin( user, "ForceFeedback" );
  49. WRITE_BYTE( FFMSG_STOPALL ); // Reset effects
  50. MessageEnd();
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. // Input : *player -
  55. // effect -
  56. //-----------------------------------------------------------------------------
  57. void CForceFeedback::StopEffect( CBasePlayer *player, FORCEFEEDBACK_t effect )
  58. {
  59. if ( !player )
  60. return;
  61. CSingleUserRecipientFilter user( player );
  62. UserMessageBegin( user, "ForceFeedback" );
  63. WRITE_BYTE( FFMSG_STOP ); // Reset effect
  64. WRITE_BYTE( effect );
  65. MessageEnd();
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Input : *player -
  70. // effect -
  71. // params -
  72. //-----------------------------------------------------------------------------
  73. void CForceFeedback::StartEffect( CBasePlayer *player, FORCEFEEDBACK_t effect, const FFBaseParams_t& params )
  74. {
  75. if ( !player )
  76. {
  77. return;
  78. }
  79. CSingleUserRecipientFilter user( player );
  80. UserMessageBegin( user, "ForceFeedback" );
  81. WRITE_BYTE( FFMSG_START ); // Reset effects
  82. WRITE_BYTE( effect );
  83. // encode direction as a byte
  84. int dir = (int)( ( params.m_flDirection / 360.0f ) * 255.0f );
  85. WRITE_BYTE( dir );
  86. // encode duration as a signed int
  87. int duration = (int)params.m_flDuration * 1000.0f;
  88. WRITE_LONG( duration );
  89. // encode gain as a byte
  90. byte gain = (byte)clamp( params.m_flGain * 255.0f, 0.0f, 255.0f );
  91. WRITE_BYTE( gain );
  92. WRITE_BYTE( params.m_nPriority );
  93. WRITE_BYTE( params.m_bSolo ? 1 : 0 );
  94. MessageEnd();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. // Input : *player -
  99. //-----------------------------------------------------------------------------
  100. void CForceFeedback::PauseAll( CBasePlayer *player )
  101. {
  102. if ( !player )
  103. return;
  104. CSingleUserRecipientFilter user( player );
  105. UserMessageBegin( user, "ForceFeedback" );
  106. WRITE_BYTE( FFMSG_PAUSE ); // Pause effects
  107. MessageEnd();
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. // Input : *player -
  112. //-----------------------------------------------------------------------------
  113. void CForceFeedback::ResumeAll( CBasePlayer *player )
  114. {
  115. if ( !player )
  116. return;
  117. CSingleUserRecipientFilter user( player );
  118. UserMessageBegin( user, "ForceFeedback" );
  119. WRITE_BYTE( FFMSG_RESUME ); // Resume effects
  120. MessageEnd();
  121. }