Client-side touch prediction is disabled in the standard SDK. I had some
need for it, so I stuck it in. Since it's non-trivial, and something
that shouldn't have to be written twice, I'm posting it here for
opinions and corrections. It's mostly just copied from the equivalent
server code. This patch is from my version control system, so it might
not fit so cleanly into the patch utility. And those line numbers might
not be totally accurate, if I've edited those files before.

cl_dll/movehelper_client.cpp
===================================================================
--- cl_dll/movehelper_client.cpp
+++ cl_dll/movehelper_client.cpp
@@ -128,6 +128,38 @@

void CMoveHelperClient::ProcessImpacts( void )
{
+    // Don't bother if the player ain't solid
+    if ( g_pLocalPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
+        return;
+
+    // Save off the velocity, cause we need to temporarily reset it
+    Vector vel = g_pLocalPlayer->GetAbsVelocity();
+
+    // Touch other objects that were intersected during the movement.
+    for (int i = 0 ; i < m_TouchList.Size(); i++)
+    {
+        C_BaseEntity *pEnt = ClientEntityList().GetEnt(
m_TouchList[i].trace.m_pEnt->entindex() );
+        if (!pEnt)
+            continue;
+
+        // Don't ever collide with self!!!!
+        if ( pEnt == g_pLocalPlayer )
+            continue;
+
+        // Reconstruct trace results.
+        m_TouchList[i].trace.m_pEnt = pEnt;
+
+        // Use the velocity we had when we collided, so boxes will
move, etc.
+        g_pLocalPlayer->SetAbsVelocity( m_TouchList[i].deltavelocity );
+
+        pEnt->PhysicsImpact( g_pLocalPlayer, m_TouchList[i].trace );
+    }
+
+    // Restore the velocity
+    g_pLocalPlayer->SetAbsVelocity( vel );
+
+    // So no stuff is ever left over, sigh...
+    ResetTouchList();
}

void CMoveHelperClient::StartSound( const Vector& origin, const char
*soundname )

cl_dll/prediction.cpp
===================================================================
--- cl_dll/prediction.cpp
+++ cl_dll/prediction.cpp
@@ -837,9 +837,7 @@

    RunPostThink( player );

-// TODO:  Predict impacts?
-//    // Let server invoke any needed impact functions
-//    moveHelper->ProcessImpacts();
+    moveHelper->ProcessImpacts();

    FinishCommand( player );

So far this code works for my purposes. Has anybody else done this, or
want to try this and provide some input? Maybe Valve has some pointers,
or a reason why they didn't do it in the first place?

Thanks.

--
Jorge "Vino" Rodriguez


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to