]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_user.c
simplified dlight fading code
[xonotic/darkplaces.git] / sv_user.c
index 135a6d50abfb370bf1e7bd6ad3f8792d285b4546..23c31cbc27127402cf6460e2c9caa8881619ef47 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 edict_t *sv_player;
 
 cvar_t sv_edgefriction = {0, "edgefriction", "2"};
-cvar_t sv_predict = {0, "sv_predict", "1"};
 cvar_t sv_deltacompress = {0, "sv_deltacompress", "1"};
 cvar_t sv_idealpitchscale = {0, "sv_idealpitchscale","0.8"};
 cvar_t sv_maxspeed = {CVAR_NOTIFY, "sv_maxspeed", "320"};
@@ -472,11 +471,7 @@ void SV_ReadClientMove (usercmd_t *move)
                total += host_client->ping_times[i];
        // can be used for prediction
        host_client->ping = total / NUM_PING_TIMES;
-       host_client->latency = 0;
-       // if paused or a local game, don't predict
-       if (sv_predict.integer && (svs.maxclients > 1) && (!sv.paused))
-               host_client->latency = host_client->ping;
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ping)))
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_ping)))
                val->_float = host_client->ping * 1000.0;
 
        // read current angles
@@ -484,13 +479,13 @@ void SV_ReadClientMove (usercmd_t *move)
        for (i = 0;i < 3;i++)
                angle[i] = MSG_ReadFloat ();
 
-       VectorCopy (angle, host_client->edict->v->v_angle);
+       VectorCopy (angle, sv_player->v->v_angle);
 
        // read movement
        move->forwardmove = MSG_ReadShort ();
        move->sidemove = MSG_ReadShort ();
        move->upmove = MSG_ReadShort ();
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_movement)))
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_movement)))
        {
                val->vector[0] = move->forwardmove;
                val->vector[1] = move->sidemove;
@@ -499,131 +494,113 @@ void SV_ReadClientMove (usercmd_t *move)
 
        // read buttons
        bits = MSG_ReadByte ();
-       host_client->edict->v->button0 = bits & 1;
-       host_client->edict->v->button2 = (bits & 2)>>1;
+       sv_player->v->button0 = bits & 1;
+       sv_player->v->button2 = (bits & 2)>>1;
        // LordHavoc: added 6 new buttons
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button3))) val->_float = ((bits >> 2) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button4))) val->_float = ((bits >> 3) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button5))) val->_float = ((bits >> 4) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button6))) val->_float = ((bits >> 5) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button7))) val->_float = ((bits >> 6) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button8))) val->_float = ((bits >> 7) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button3))) val->_float = ((bits >> 2) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button4))) val->_float = ((bits >> 3) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button5))) val->_float = ((bits >> 4) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button6))) val->_float = ((bits >> 5) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button7))) val->_float = ((bits >> 6) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button8))) val->_float = ((bits >> 7) & 1);
 
        i = MSG_ReadByte ();
        if (i)
-               host_client->edict->v->impulse = i;
+               sv_player->v->impulse = i;
 }
 
 /*
 ===================
 SV_ReadClientMessage
-
-Returns false if the client should be killed
 ===================
 */
-extern void SV_SendServerinfo (client_t *client);
-qboolean SV_ReadClientMessage (void)
+extern void SV_SendServerinfo(client_t *client);
+void SV_ReadClientMessage(void)
 {
-       int             ret;
-       int             cmd;
-       char            *s;
+       int cmd;
+       char *s;
+
+       //MSG_BeginReading ();
 
-       do
+       for(;;)
        {
-nextmsg:
-               ret = NET_GetMessage (host_client->netconnection);
-               if (ret == -1)
+               if (!host_client->active)
                {
-                       Sys_Printf ("SV_ReadClientMessage: NET_GetMessage failed\n");
-                       return false;
+                       // a command caused an error
+                       SV_DropClient (false);
+                       return;
                }
-               if (!ret)
-                       return true;
 
-               MSG_BeginReading ();
+               if (msg_badread)
+               {
+                       Con_Printf ("SV_ReadClientMessage: badread\n");
+                       SV_DropClient (false);
+                       return;
+               }
 
-               while (1)
+               cmd = MSG_ReadChar ();
+               if (cmd == -1)
                {
-                       if (!host_client->active)
-                               // a command caused an error
-                               return false;
+                       // end of message
+                       break;
+               }
 
-                       if (msg_badread)
-                       {
-                               Sys_Printf ("SV_ReadClientMessage: badread\n");
-                               return false;
-                       }
+               switch (cmd)
+               {
+               default:
+                       Con_Printf ("SV_ReadClientMessage: unknown command char %i\n", cmd);
+                       SV_DropClient (false);
+                       return;
 
-                       cmd = MSG_ReadChar ();
+               case clc_nop:
+                       break;
 
-#ifndef NOROUTINGFIX
-                       if (cmd != -1 && host_client->waitingforconnect)
+               case clc_stringcmd:
+                       s = MSG_ReadString ();
+                       if (strncasecmp(s, "spawn", 5) == 0
+                        || strncasecmp(s, "begin", 5) == 0
+                        || strncasecmp(s, "prespawn", 8) == 0)
+                               Cmd_ExecuteString (s, src_client);
+                       else if (SV_ParseClientCommandQC)
                        {
-                               host_client->waitingforconnect = false;
-                               host_client->sendserverinfo = true;
+                               G_INT(OFS_PARM0) = PR_SetString(s);
+                               pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
+                               PR_ExecuteProgram ((func_t)(SV_ParseClientCommandQC - pr_functions), "");
                        }
-#endif
+                       else if (strncasecmp(s, "status", 6) == 0
+                        || strncasecmp(s, "name", 4) == 0
+                        || strncasecmp(s, "say", 3) == 0
+                        || strncasecmp(s, "say_team", 8) == 0
+                        || strncasecmp(s, "tell", 4) == 0
+                        || strncasecmp(s, "color", 5) == 0
+                        || strncasecmp(s, "kill", 4) == 0
+                        || strncasecmp(s, "pause", 5) == 0
+                        || strncasecmp(s, "kick", 4) == 0
+                        || strncasecmp(s, "ping", 4) == 0
+                        || strncasecmp(s, "ban", 3) == 0
+                        || strncasecmp(s, "pmodel", 6) == 0
+                        || (gamemode == GAME_NEHAHRA && (strncasecmp(s, "max", 3) == 0 || strncasecmp(s, "monster", 7) == 0 || strncasecmp(s, "scrag", 5) == 0 || strncasecmp(s, "gimme", 5) == 0 || strncasecmp(s, "wraith", 6) == 0))
+                        || (gamemode != GAME_NEHAHRA && (strncasecmp(s, "god", 3) == 0 || strncasecmp(s, "notarget", 8) == 0 || strncasecmp(s, "fly", 3) == 0 || strncasecmp(s, "give", 4) == 0 || strncasecmp(s, "noclip", 6) == 0)))
+                               Cmd_ExecuteString (s, src_client);
+                       else
+                               Con_Printf("%s tried to %s\n", host_client->name, s);
+                       break;
 
-                       switch (cmd)
-                       {
-                       case -1:
-                               // end of message
-                               goto nextmsg;
-
-                       default:
-                               Sys_Printf ("SV_ReadClientMessage: unknown command char %i\n", cmd);
-                               return false;
-
-                       case clc_nop:
-                               break;
-
-                       case clc_stringcmd:
-                               s = MSG_ReadString ();
-                               ret = 0;
-                               if (Q_strncasecmp(s, "status", 6) == 0
-                                || Q_strncasecmp(s, "name", 4) == 0
-                                || Q_strncasecmp(s, "say", 3) == 0
-                                || Q_strncasecmp(s, "say_team", 8) == 0
-                                || Q_strncasecmp(s, "tell", 4) == 0
-                                || Q_strncasecmp(s, "color", 5) == 0
-                                || Q_strncasecmp(s, "kill", 4) == 0
-                                || Q_strncasecmp(s, "pause", 5) == 0
-                                || Q_strncasecmp(s, "spawn", 5) == 0
-                                || Q_strncasecmp(s, "begin", 5) == 0
-                                || Q_strncasecmp(s, "prespawn", 8) == 0
-                                || Q_strncasecmp(s, "kick", 4) == 0
-                                || Q_strncasecmp(s, "ping", 4) == 0
-                                || Q_strncasecmp(s, "ban", 3) == 0
-                                || Q_strncasecmp(s, "pmodel", 6) == 0
-                                || (gamemode == GAME_NEHAHRA && (Q_strncasecmp(s, "max", 3) == 0 || Q_strncasecmp(s, "monster", 7) == 0 || Q_strncasecmp(s, "scrag", 5) == 0 || Q_strncasecmp(s, "gimme", 5) == 0 || Q_strncasecmp(s, "wraith", 6) == 0))
-                                || (gamemode != GAME_NEHAHRA && (Q_strncasecmp(s, "god", 3) == 0 || Q_strncasecmp(s, "notarget", 8) == 0 || Q_strncasecmp(s, "fly", 3) == 0 || Q_strncasecmp(s, "give", 4) == 0 || Q_strncasecmp(s, "noclip", 6) == 0)))
-                               {
-                                       ret = 1;
-                                       Cmd_ExecuteString (s, src_client);
-                               }
-                               else
-                                       Con_DPrintf("%s tried to %s\n", host_client->name, s);
-                               break;
-
-                       case clc_disconnect:
-                               return false;
-
-                       case clc_move:
-                               SV_ReadClientMove (&host_client->cmd);
-                               break;
-
-                       case clc_ackentities:
-                               EntityFrame_AckFrame(&host_client->entitydatabase, MSG_ReadLong());
-                               break;
-                       }
+               case clc_disconnect:
+                       SV_DropClient (false); // client wants to disconnect
+                       return;
+
+               case clc_move:
+                       SV_ReadClientMove (&host_client->cmd);
+                       break;
+
+               case clc_ackentities:
+                       EntityFrame_AckFrame(&host_client->entitydatabase, MSG_ReadLong());
+                       break;
                }
        }
-       while (ret == 1);
-
-       return true;
 }
 
-
 /*
 ==================
 SV_RunClients
@@ -640,13 +617,6 @@ void SV_RunClients (void)
 
                sv_player = host_client->edict;
 
-               if (!SV_ReadClientMessage ())
-               {
-                       // client misbehaved...
-                       SV_DropClient (false);
-                       continue;
-               }
-
                if (!host_client->spawned)
                {
                        // clear client movement until a new packet is received
@@ -665,6 +635,15 @@ void SV_RunClients (void)
                        }
                        else
                                SV_ClientThink ();
+
+                       SV_CheckVelocity (sv_player);
+
+                       // LordHavoc: a hack to ensure that the (rather silly) id1 quakec
+                       // player_run/player_stand1 does not horribly malfunction if the
+                       // velocity becomes a number that is both == 0 and != 0
+                       // (sounds to me like NaN but to be absolutely safe...)
+                       if (DotProduct(sv_player->v->velocity, sv_player->v->velocity) < 0.0001)
+                               VectorClear(sv_player->v->velocity);
                }
        }
 }