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.

135 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "client_pch.h"
  8. #include "dt_recv_eng.h"
  9. #include "client_class.h"
  10. #include "serializedentity.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. static ConVar cl_showevents ( "cl_showevents", "0", FCVAR_CHEAT, "Print event firing info in the console" );
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Show descriptive info about an event in the numbered console area
  16. // Input : slot -
  17. // *eventname -
  18. //-----------------------------------------------------------------------------
  19. void CL_DescribeEvent( int slot, CEventInfo *event, const char *eventname )
  20. {
  21. int idx = (slot & 31);
  22. if ( !cl_showevents.GetInt() )
  23. return;
  24. if ( !eventname )
  25. return;
  26. con_nprint_t n;
  27. n.index = idx;
  28. n.fixed_width_font = true;
  29. n.time_to_live = 4.0f;
  30. n.color[0] = 0.8;
  31. n.color[1] = 0.8;
  32. n.color[2] = 1.0;
  33. CSerializedEntity *pEntity = (CSerializedEntity *)event->m_Packed;
  34. Con_NXPrintf( &n, "%02i %6.3ff %20s %03i bytes", slot, GetBaseLocalClient().GetTime(), eventname, pEntity ? Bits2Bytes( pEntity->GetFieldDataBitCount() ) : 0 );
  35. if ( cl_showevents.GetInt() == 2 )
  36. {
  37. DevMsg( "%02i %6.3ff %20s %03i bytes\n", slot, GetBaseLocalClient().GetTime(), eventname, pEntity ? Bits2Bytes( pEntity->GetFieldDataBitCount() ) : 0 );
  38. }
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Decode raw event data into underlying class structure using the specified data table
  42. // Input : *RawData -
  43. // *pToData -
  44. // *pRecvTable -
  45. //-----------------------------------------------------------------------------
  46. void CL_DecodeEventDelta( SerializedEntityHandle_t handle, void *pToData, RecvTable *pRecvTable )
  47. {
  48. // Make sure we have a decoder
  49. Assert(pRecvTable->m_pDecoder);
  50. // First, decode all properties as zeros since temp ents are delta'd from zeros.
  51. RecvTable_DecodeZeros( pRecvTable, pToData, -1 );
  52. RecvTable_Decode( pRecvTable, pToData, handle, -1 );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Once per frame, walk the client's event slots and look for any events
  56. // that are ready for playing.
  57. //-----------------------------------------------------------------------------
  58. void CL_FireEvents( void )
  59. {
  60. VPROF("CL_FireEvents");
  61. CClientState &cl = GetBaseLocalClient();
  62. if ( !cl.IsActive() )
  63. {
  64. cl.events.RemoveAll();
  65. return;
  66. }
  67. MDLCACHE_CRITICAL_SECTION_(g_pMDLCache);
  68. intp i, next;
  69. for ( i = cl.events.Head(); i != cl.events.InvalidIndex(); i = next )
  70. {
  71. next = cl.events.Next( i );
  72. CEventInfo *ei = &cl.events[ i ];
  73. if ( ei->classID == 0 )
  74. {
  75. cl.events.Remove( i );
  76. continue;
  77. }
  78. // Delayed event!
  79. if ( ei->fire_delay && ( ei->fire_delay > cl.GetTime() ) )
  80. continue;
  81. bool success = false;
  82. // Get the receive table if it exists
  83. Assert( ei->pClientClass );
  84. // Get pointer to the event.
  85. if( ei->pClientClass->m_pCreateEventFn )
  86. {
  87. IClientNetworkable *pCE = ei->pClientClass->m_pCreateEventFn();
  88. if(pCE)
  89. {
  90. // Prepare to copy in the data
  91. pCE->PreDataUpdate( DATA_UPDATE_CREATED );
  92. // Decode data into client event object
  93. CL_DecodeEventDelta( ei->m_Packed, pCE->GetDataTableBasePtr(), ei->pClientClass->m_pRecvTable );
  94. // Fire the event!!!
  95. pCE->PostDataUpdate( DATA_UPDATE_CREATED );
  96. // Spew to debug area if needed
  97. CL_DescribeEvent( i, ei, ei->pClientClass->m_pNetworkName );
  98. success = true;
  99. }
  100. }
  101. if ( !success )
  102. {
  103. ConDMsg( "Failed to execute event for classId %i\n", ei->classID - 1 );
  104. }
  105. cl.events.Remove( i );
  106. }
  107. }