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.8 KiB

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