Guest User

Untitled

a guest
Oct 2nd, 2012
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. void CL_Move(float accumulated_extra_samples, bool bFinalTick )
  2. {
  3.     if ( !cl.IsConnected() )
  4.         return;
  5.  
  6.     if ( !Host_ShouldRun() )
  7.         return;
  8.  
  9.     // only send packets on the final tick in one engine frame
  10.     bool bSendPacket = true;   
  11.  
  12.     // Don't create usercmds here during playback, they were encoded into the packet already
  13.     if ( demoplayer->IsPlayingBack() )
  14.     {
  15.         if ( cl.ishltv )
  16.         {
  17.             // still do it when playing back a HLTV demo
  18.             bSendPacket = false;
  19.         }
  20.         else
  21.         {
  22.             return;
  23.         }
  24.     }
  25.  
  26.     // don't send packets if update time not reached or chnnel still sending
  27.     // in loopback mode don't send only if host_limitlocal is enabled
  28.  
  29.     if ( ( !cl.m_NetChannel->IsLoopback() || host_limitlocal.GetInt() ) &&
  30.          ( ( net_time < cl.m_flNextCmdTime ) || !cl.m_NetChannel->CanPacket()  || !bFinalTick ) )
  31.     {
  32.         bSendPacket = false;
  33.     }
  34.  
  35.     if ( cl.IsActive() )
  36.     {
  37.         VPROF( "CL_Move" );
  38.  
  39.         int nextcommandnr = cl.lastoutgoingcommand + cl.chokedcommands + 1;
  40.  
  41.         // Have client .dll create and store usercmd structure
  42.         g_ClientDLL->CreateMove(
  43.             nextcommandnr,
  44.             host_state.interval_per_tick - accumulated_extra_samples,
  45.             !cl.IsPaused() );
  46.  
  47.         // Store new usercmd to dem file
  48.         if ( demorecorder->IsRecording() )
  49.         {
  50.             // Back up one because we've incremented outgoing_sequence each frame by 1 unit
  51.             demorecorder->RecordUserInput( nextcommandnr );
  52.         }
  53.  
  54.         if ( bSendPacket )
  55.         {
  56.             CL_SendMove();
  57.         }
  58.         else
  59.         {
  60.             // netchanll will increase internal outgoing sequnce number too
  61.             cl.m_NetChannel->SetChoked();  
  62.             // Mark command as held back so we'll send it next time
  63.             cl.chokedcommands++;
  64.         }
  65.     }
  66.  
  67.     if ( !bSendPacket )
  68.         return;
  69.  
  70.         // Request non delta compression if high packet loss, show warning message
  71.     bool hasProblem = cl.m_NetChannel->IsTimingOut() && !demoplayer->IsPlayingBack() && cl.IsActive();
  72.  
  73.     // Request non delta compression if high packet loss, show warning message
  74.     if ( hasProblem )
  75.     {
  76.         con_nprint_t np;
  77.         np.time_to_live = 1.0;
  78.         np.index = 2;
  79.         np.fixed_width_font = false;
  80.         np.color[ 0 ] = 1.0;
  81.         np.color[ 1 ] = 0.2;
  82.         np.color[ 2 ] = 0.2;
  83.        
  84.         float flTimeOut = cl.m_NetChannel->GetTimeoutSeconds();
  85.         Assert( flTimeOut != -1.0f );
  86.         float flRemainingTime = flTimeOut - cl.m_NetChannel->GetTimeSinceLastReceived();
  87.         Con_NXPrintf( &np, "WARNING:  Connection Problem" );
  88.         np.index = 3;
  89.         Con_NXPrintf( &np, "Auto-disconnect in %.1f seconds", flRemainingTime );
  90.  
  91.         cl.ForceFullUpdate(); // sets m_nDeltaTick to -1
  92.     }
  93.  
  94.     if ( cl.IsActive() )
  95.     {
  96.         NET_Tick mymsg( cl.m_nDeltaTick, host_frametime_unbounded, host_frametime_stddeviation );
  97.         cl.m_NetChannel->SendNetMsg( mymsg );
  98.     }
  99.  
  100.     //COM_Log( "cl.log", "Sending command number %i(%i) to server\n", cl.m_NetChan->m_nOutSequenceNr, cl.m_NetChan->m_nOutSequenceNr & CL_UPDATE_MASK );
  101.  
  102.     // Remember outgoing command that we are sending
  103.     cl.lastoutgoingcommand = cl.m_NetChannel->SendDatagram( NULL );
  104.  
  105.     cl.chokedcommands = 0;
  106.  
  107.     // calc next packet send time
  108.  
  109.     if ( cl.IsActive() )
  110.     {
  111.         // use full update rate when active
  112.         float commandInterval = 1.0f / cl_cmdrate->GetFloat();
  113.         float maxDelta = min ( host_state.interval_per_tick, commandInterval );
  114.         float delta = clamp( net_time - cl.m_flNextCmdTime, 0.0f, maxDelta );
  115.         cl.m_flNextCmdTime = net_time + commandInterval - delta;
  116.     }
  117.     else
  118.     {
  119.         // during signon process send only 5 packets/second
  120.         cl.m_flNextCmdTime = net_time + ( 1.0f / 5.0f );
  121.     }
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment