From c3001ce26f2c2fd69caa6af345ccca1d4376f4e5 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 15 Feb 2006 03:09:37 +0000 Subject: [PATCH] improved server handling of multiple packets per client physics frame (as would be the case if the client sends more frames per second than the server sends to it) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5984 d7cf8633-e32d-0410-b094-e92efae38249 --- sv_phys.c | 2 ++ sv_user.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sv_phys.c b/sv_phys.c index d37dbbbf..3f91ff3e 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -1413,8 +1413,10 @@ static void SV_Physics_Entity (prvm_edict_t *ent, qboolean runmove) } } +void SV_ApplyClientMove (void); void SV_Physics_ClientEntity (prvm_edict_t *ent) { + SV_ApplyClientMove(); // make sure the velocity is sane (not a NaN) SV_CheckVelocity(ent); // LordHavoc: QuakeC replacement for SV_ClientThink (player movement) diff --git a/sv_user.c b/sv_user.c index 77fc45da..2525785a 100644 --- a/sv_user.c +++ b/sv_user.c @@ -602,7 +602,6 @@ void SV_ClientThink(void) SV_ReadClientMove =================== */ -void SV_ApplyClientMove (void); void SV_ReadClientMove (void) { int i; @@ -610,7 +609,6 @@ void SV_ReadClientMove (void) usercmd_t *move = &host_client->cmd; oldmovetime = move->time; - memset(move, 0, sizeof(usercmd_t)); if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__); @@ -642,10 +640,12 @@ void SV_ReadClientMove (void) if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__); // read buttons + // be sure to bitwise OR them into the move->buttons because we want to + // accumulate button presses from multiple packets per actual move if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5) - move->buttons = MSG_ReadByte (); + move->buttons |= MSG_ReadByte (); else - move->buttons = MSG_ReadLong (); + move->buttons |= MSG_ReadLong (); if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__); // read impulse @@ -682,7 +682,6 @@ void SV_ReadClientMove (void) else { // apply the latest accepted move to the entity fields - SV_ApplyClientMove(); host_client->movesequence = move->sequence; if (host_client->movesequence) { @@ -706,6 +705,9 @@ void SV_ApplyClientMove (void) prvm_eval_t *val; usercmd_t *move = &host_client->cmd; + if (!move->receivetime) + return; + // calculate average ping time host_client->ping = move->receivetime - move->time; #ifdef NUM_PING_TIMES @@ -745,6 +747,8 @@ void SV_ApplyClientMove (void) if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_trace_endpos))) VectorCopy(move->cursor_impact, val->vector); if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_trace_ent))) val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM(move->cursor_entitynumber)); if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ping))) val->_float = host_client->ping * 1000.0; + + memset(move, 0, sizeof(*move)); } void SV_FrameLost(int framenum) -- 2.39.2