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.

192 lines
4.4 KiB

  1. #include "cbase.h"
  2. #ifdef CLIENT_DLL
  3. #include "tier3/tier3.h"
  4. #include "iviewrender.h"
  5. #include "inputsystem/iinputsystem.h"
  6. #include "vgui/IInputInternal.h"
  7. #include "c_basecombatweapon.h"
  8. #include "c_baseplayer.h"
  9. #include "hud_macros.h"
  10. #include "iclientvehicle.h"
  11. #include "c_prop_vehicle.h"
  12. #include "prediction.h"
  13. #include "activitylist.h"
  14. #ifdef TERROR
  15. #include "ClientTerrorPlayer.h"
  16. #endif
  17. extern vgui::IInputInternal *g_InputInternal;
  18. #else
  19. #include "usermessages.h"
  20. #endif
  21. #include "haptics/haptic_msgs.h"
  22. void RegisterHapticMessages(void)
  23. {
  24. usermessages->Register( "SPHapWeapEvent", 4 );
  25. usermessages->Register( "HapDmg", -1 );
  26. usermessages->Register( "HapPunch", -1 );
  27. usermessages->Register( "HapSetDrag", -1 );
  28. usermessages->Register( "HapSetConst", -1 );
  29. usermessages->Register( "HapMeleeContact", 0);
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Server
  33. //-----------------------------------------------------------------------------
  34. #ifndef CLIENT_DLL
  35. void HapticMsg_SendWeaponAnim( CBasePlayer *pPlayer, int iActivity )
  36. {
  37. //Send the haptics message
  38. CSingleUserRecipientFilter user( pPlayer );
  39. user.MakeReliable();
  40. UserMessageBegin( user, "SPHapWeapEvent" );
  41. WRITE_LONG(iActivity);
  42. MessageEnd();
  43. }
  44. void HapticMsg_SetDrag(CBasePlayer* pPlayer, float drag)
  45. {
  46. CSingleUserRecipientFilter user( pPlayer );
  47. user.MakeReliable();
  48. UserMessageBegin( user, "HapSetDrag" );
  49. WRITE_FLOAT(drag);
  50. MessageEnd();
  51. }
  52. void HapticMsg_SetConstantForce(CBasePlayer* pPlayer, Vector force)
  53. {
  54. // portal does not network this.
  55. CSingleUserRecipientFilter user( pPlayer );
  56. user.MakeReliable();
  57. UserMessageBegin( user, "HapSetConst" );
  58. WRITE_SHORT(force.x);
  59. WRITE_SHORT(force.y);
  60. WRITE_SHORT(force.z);
  61. MessageEnd();
  62. }
  63. void HapticMsg_HapDmg(CBasePlayer* pPlayer, float pitch, float yaw, float dmg, float dmgType )
  64. {
  65. CSingleUserRecipientFilter user(pPlayer);
  66. user.MakeReliable();
  67. UserMessageBegin(user,"HapDmg");
  68. WRITE_FLOAT(pitch);
  69. WRITE_FLOAT(yaw);
  70. WRITE_FLOAT(dmg);
  71. WRITE_LONG(dmgType);
  72. MessageEnd();
  73. }
  74. void HapticMsg_Punch(CBasePlayer* pPlayer, float x, float y, float z)
  75. {
  76. CSingleUserRecipientFilter user(pPlayer);
  77. user.MakeReliable();
  78. UserMessageBegin(user,"HapPunch");
  79. WRITE_FLOAT(x);
  80. WRITE_FLOAT(y);
  81. WRITE_FLOAT(z);
  82. MessageEnd();
  83. }
  84. void HapticMsg_MeleeContact(CBasePlayer* pPlayer)
  85. {
  86. CSingleUserRecipientFilter user(pPlayer);
  87. user.MakeReliable();
  88. UserMessageBegin(user,"HapMeleeContact");
  89. MessageEnd();
  90. }
  91. #endif //!CLIENT_DLL
  92. //-----------------------------------------------------------------------------
  93. // Client
  94. //-----------------------------------------------------------------------------
  95. #ifdef CLIENT_DLL
  96. void HookHapticMessages(void)
  97. {
  98. HOOK_MESSAGE(SPHapWeapEvent);
  99. HOOK_MESSAGE(HapDmg);
  100. HOOK_MESSAGE(HapPunch);
  101. HOOK_MESSAGE(HapSetDrag);
  102. HOOK_MESSAGE(HapSetConst);
  103. HOOK_MESSAGE(HapMeleeContact);
  104. }
  105. // Defined in haptics_utils
  106. #ifdef WIN32
  107. void HapticsHandleMsg_HapSetDrag( float drag );
  108. void HapticsHandleMsg_HapSetConst( Vector const &constant );
  109. void HapticsHandleMsg_SPHapWeapEvent( int iActivity );
  110. void HapticsHandleMsg_HapPunch( QAngle const &angle );
  111. void HapticsHandleMsg_HapDmg( float pitch, float yaw, float damage, int damageType );
  112. void HapticsHandleMsg_HapMeleeContact();
  113. #endif // WIN32
  114. void __MsgFunc_HapSetDrag( bf_read &msg )
  115. {
  116. #ifdef WIN32
  117. float drag = msg.ReadFloat();
  118. HapticsHandleMsg_HapSetDrag( drag );
  119. #endif // WIN32
  120. }
  121. //Might be able to handle this better...
  122. void __MsgFunc_HapSetConst( bf_read &msg )
  123. {
  124. #ifdef WIN32
  125. Vector constant;
  126. constant.x = msg.ReadShort();
  127. constant.y = msg.ReadShort();
  128. constant.z = msg.ReadShort();
  129. HapticsHandleMsg_HapSetConst( constant );
  130. #endif // WIN32
  131. }
  132. void __MsgFunc_SPHapWeapEvent( bf_read &msg )
  133. {
  134. #ifdef WIN32
  135. int iActivity = msg.ReadLong();
  136. HapticsHandleMsg_SPHapWeapEvent( iActivity );
  137. #endif // WIN32
  138. }
  139. void __MsgFunc_HapPunch( bf_read &msg )
  140. {
  141. #ifdef WIN32
  142. float x = msg.ReadFloat();
  143. float y = msg.ReadFloat();
  144. float z = msg.ReadFloat();
  145. HapticsHandleMsg_HapPunch( QAngle(x,y,z) );
  146. #endif // WIN32
  147. }
  148. void __MsgFunc_HapDmg( bf_read &msg )
  149. {
  150. #ifdef WIN32
  151. float pitch = msg.ReadFloat();
  152. float yaw = msg.ReadFloat();
  153. float damage = msg.ReadFloat();
  154. int damageType = msg.ReadLong();
  155. HapticsHandleMsg_HapDmg( pitch, yaw, damage, damageType );
  156. #endif // WIN32
  157. }
  158. void __MsgFunc_HapMeleeContact( bf_read &msg )
  159. {
  160. #ifdef WIN32
  161. HapticsHandleMsg_HapMeleeContact();
  162. #endif // WIN32
  163. }
  164. #endif // CLIENT_DLL