]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_user.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / sv_user.c
index ce0b8e07d1b81c7d4c6045689ba7ce16088a8978..e17108cbbceaa7e7ba6da06b5c2ffcade1e242d1 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -59,7 +59,7 @@ void SV_SetIdealPitch (void)
                bottom[1] = top[1];
                bottom[2] = top[2] - 160;
 
                bottom[1] = top[1];
                bottom[2] = top[2] - 160;
 
-               tr = SV_TraceLine(top, bottom, MOVE_NOMONSTERS, host_client->edict, SUPERCONTENTS_SOLID);
+               tr = SV_TraceLine(top, bottom, MOVE_NOMONSTERS, host_client->edict, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value);
                // if looking at a wall, leave ideal the way is was
                if (tr.startsolid)
                        return;
                // if looking at a wall, leave ideal the way is was
                if (tr.startsolid)
                        return;
@@ -126,7 +126,7 @@ static void SV_UserFriction (void)
        start[2] = PRVM_serveredictvector(host_client->edict, origin)[2] + PRVM_serveredictvector(host_client->edict, mins)[2];
        stop[2] = start[2] - 34;
 
        start[2] = PRVM_serveredictvector(host_client->edict, origin)[2] + PRVM_serveredictvector(host_client->edict, mins)[2];
        stop[2] = start[2] - 34;
 
-       trace = SV_TraceLine(start, stop, MOVE_NOMONSTERS, host_client->edict, SV_GenericHitSuperContentsMask(host_client->edict));
+       trace = SV_TraceLine(start, stop, MOVE_NOMONSTERS, host_client->edict, SV_GenericHitSuperContentsMask(host_client->edict), 0, 0, collision_extendmovelength.value);
 
        if (trace.fraction == 1.0)
                friction = sv_friction.value*sv_edgefriction.value;
 
        if (trace.fraction == 1.0)
                friction = sv_friction.value*sv_edgefriction.value;
@@ -194,26 +194,32 @@ static void SV_AirAccelerate (vec3_t wishveloc)
 static void DropPunchAngle (void)
 {
        prvm_prog_t *prog = SVVM_prog;
 static void DropPunchAngle (void)
 {
        prvm_prog_t *prog = SVVM_prog;
-       float len;
-       vec3_t v;
+       vec_t len;
+       vec3_t punchangle, punchvector;
 
 
-       len = VectorNormalizeLength (PRVM_serveredictvector(host_client->edict, punchangle));
+       VectorCopy(PRVM_serveredictvector(host_client->edict, punchangle), punchangle);
+       VectorCopy(PRVM_serveredictvector(host_client->edict, punchvector), punchvector);
 
 
-       len -= 10*sv.frametime;
-       if (len < 0)
-               len = 0;
-       VectorScale (PRVM_serveredictvector(host_client->edict, punchangle), len, PRVM_serveredictvector(host_client->edict, punchangle));
+       len = VectorNormalizeLength(punchangle);
+       if (len > 0)
+       {
+               len -= 10*sv.frametime;
+               if (len < 0)
+                       len = 0;
+               VectorScale(punchangle, len, punchangle);
+       }
 
 
-       VectorCopy(PRVM_serveredictvector(host_client->edict, punchvector), v);
-       len = VectorNormalizeLength(v);
+       len = VectorNormalizeLength(punchvector);
        if (len > 0)
        {
                len -= 20*sv.frametime;
                if (len < 0)
                        len = 0;
        if (len > 0)
        {
                len -= 20*sv.frametime;
                if (len < 0)
                        len = 0;
-               VectorScale(v, len, v);
+               VectorScale(punchvector, len, punchvector);
        }
        }
-       VectorCopy(v, PRVM_serveredictvector(host_client->edict, punchvector));
+
+       VectorCopy(punchangle, PRVM_serveredictvector(host_client->edict, punchangle));
+       VectorCopy(punchvector, PRVM_serveredictvector(host_client->edict, punchvector));
 }
 
 /*
 }
 
 /*
@@ -226,11 +232,12 @@ static void SV_WaterMove (void)
 {
        prvm_prog_t *prog = SVVM_prog;
        int i;
 {
        prvm_prog_t *prog = SVVM_prog;
        int i;
-       vec3_t wishvel;
-       float speed, newspeed, wishspeed, addspeed, accelspeed, temp;
+       vec3_t wishvel, v_angle;
+       vec_t speed, newspeed, fwishspeed, addspeed, accelspeed, temp;
 
        // user intentions
 
        // user intentions
-       AngleVectors (PRVM_serveredictvector(host_client->edict, v_angle), forward, right, up);
+       VectorCopy(PRVM_serveredictvector(host_client->edict, v_angle), v_angle);
+       AngleVectors(v_angle, forward, right, up);
 
        for (i=0 ; i<3 ; i++)
                wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove;
 
        for (i=0 ; i<3 ; i++)
                wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove;
@@ -240,14 +247,14 @@ static void SV_WaterMove (void)
        else
                wishvel[2] += cmd.upmove;
 
        else
                wishvel[2] += cmd.upmove;
 
-       wishspeed = VectorLength(wishvel);
-       if (wishspeed > sv_maxspeed.value)
+       fwishspeed = VectorLength(wishvel);
+       if (fwishspeed > sv_maxspeed.value)
        {
        {
-               temp = sv_maxspeed.value/wishspeed;
+               temp = sv_maxspeed.value/fwishspeed;
                VectorScale (wishvel, temp, wishvel);
                VectorScale (wishvel, temp, wishvel);
-               wishspeed = sv_maxspeed.value;
+               fwishspeed = sv_maxspeed.value;
        }
        }
-       wishspeed *= 0.7;
+       fwishspeed *= 0.7;
 
        // water friction
        speed = VectorLength(PRVM_serveredictvector(host_client->edict, velocity));
 
        // water friction
        speed = VectorLength(PRVM_serveredictvector(host_client->edict, velocity));
@@ -263,15 +270,15 @@ static void SV_WaterMove (void)
                newspeed = 0;
 
        // water acceleration
                newspeed = 0;
 
        // water acceleration
-       if (!wishspeed)
+       if (!fwishspeed)
                return;
 
                return;
 
-       addspeed = wishspeed - newspeed;
+       addspeed = fwishspeed - newspeed;
        if (addspeed <= 0)
                return;
 
        VectorNormalize (wishvel);
        if (addspeed <= 0)
                return;
 
        VectorNormalize (wishvel);
-       accelspeed = (sv_wateraccelerate.value < 0 ? sv_accelerate.value : sv_wateraccelerate.value) * wishspeed * sv.frametime;
+       accelspeed = (sv_wateraccelerate.value < 0 ? sv_accelerate.value : sv_wateraccelerate.value) * fwishspeed * sv.frametime;
        if (accelspeed > addspeed)
                accelspeed = addspeed;
 
        if (accelspeed > addspeed)
                accelspeed = addspeed;
 
@@ -360,7 +367,7 @@ the angle fields specify an exact angular motion in degrees
 void SV_ClientThink (void)
 {
        prvm_prog_t *prog = SVVM_prog;
 void SV_ClientThink (void)
 {
        prvm_prog_t *prog = SVVM_prog;
-       vec3_t v_angle;
+       vec3_t v_angle, angles, velocity;
 
        //Con_Printf("clientthink for %ims\n", (int) (sv.frametime * 1000));
 
 
        //Con_Printf("clientthink for %ims\n", (int) (sv.frametime * 1000));
 
@@ -394,7 +401,9 @@ void SV_ClientThink (void)
        // angles
        // show 1/3 the pitch angle and all the roll angle
        VectorAdd (PRVM_serveredictvector(host_client->edict, v_angle), PRVM_serveredictvector(host_client->edict, punchangle), v_angle);
        // angles
        // show 1/3 the pitch angle and all the roll angle
        VectorAdd (PRVM_serveredictvector(host_client->edict, v_angle), PRVM_serveredictvector(host_client->edict, punchangle), v_angle);
-       PRVM_serveredictvector(host_client->edict, angles)[ROLL] = V_CalcRoll (PRVM_serveredictvector(host_client->edict, angles), PRVM_serveredictvector(host_client->edict, velocity))*4;
+       VectorCopy(PRVM_serveredictvector(host_client->edict, angles), angles);
+       VectorCopy(PRVM_serveredictvector(host_client->edict, velocity), velocity);
+       PRVM_serveredictvector(host_client->edict, angles)[ROLL] = V_CalcRoll (angles, velocity)*4;
        if (!PRVM_serveredictfloat(host_client->edict, fixangle))
        {
                PRVM_serveredictvector(host_client->edict, angles)[PITCH] = -v_angle[PITCH]/3;
        if (!PRVM_serveredictfloat(host_client->edict, fixangle))
        {
                PRVM_serveredictvector(host_client->edict, angles)[PITCH] = -v_angle[PITCH]/3;
@@ -456,7 +465,7 @@ static void SV_ReadClientMove (void)
        move->receivetime = (float)sv.time;
 
 #if DEBUGMOVES
        move->receivetime = (float)sv.time;
 
 #if DEBUGMOVES
-       Con_Printf("%s move%i #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", move->time > move->receivetime ? "^3read future" : "^4read normal", sv_numreadmoves + 1, move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
+       Con_Printf("%s move%i #%u %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", move->time > move->receivetime ? "^3read future" : "^4read normal", sv_numreadmoves + 1, move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
 #endif
        // limit reported time to current time
        // (incase the client is trying to cheat)
 #endif
        // limit reported time to current time
        // (incase the client is trying to cheat)
@@ -542,9 +551,13 @@ static void SV_ReadClientMove (void)
                        if(host_client->movement_highestsequence_seen)
                        {
                                // mark moves in between as lost
                        if(host_client->movement_highestsequence_seen)
                        {
                                // mark moves in between as lost
-                               if(move->sequence - host_client->movement_highestsequence_seen - 1 < NETGRAPH_PACKETS)
-                                       for(i = host_client->movement_highestsequence_seen + 1; i < move->sequence; ++i)
-                                               host_client->movement_count[i % NETGRAPH_PACKETS] = -1;
+                               unsigned int delta = move->sequence - host_client->movement_highestsequence_seen - 1;
+                               if(delta < NETGRAPH_PACKETS)
+                               {
+                                       unsigned int u;
+                                       for(u = 0; u < delta; ++u)
+                                               host_client->movement_count[(host_client->movement_highestsequence_seen + 1 + u) % NETGRAPH_PACKETS] = -1;
+                               }
                                else
                                        memset(host_client->movement_count, -1, sizeof(host_client->movement_count));
                        }
                                else
                                        memset(host_client->movement_count, -1, sizeof(host_client->movement_count));
                        }
@@ -577,7 +590,7 @@ static void SV_ExecuteClientMoves(void)
        if (sv_numreadmoves < 1)
                return;
        // only start accepting input once the player is spawned
        if (sv_numreadmoves < 1)
                return;
        // only start accepting input once the player is spawned
-       if (!host_client->spawned)
+       if (!host_client->begun)
                return;
 #if DEBUGMOVES
        Con_Printf("SV_ExecuteClientMoves: read %i moves at sv.time %f\n", sv_numreadmoves, (float)sv.time);
                return;
 #if DEBUGMOVES
        Con_Printf("SV_ExecuteClientMoves: read %i moves at sv.time %f\n", sv_numreadmoves, (float)sv.time);
@@ -586,7 +599,7 @@ static void SV_ExecuteClientMoves(void)
        if (ceil(max(sv_readmoves[sv_numreadmoves-1].receivetime - sv_readmoves[sv_numreadmoves-1].time, 0) * 1000.0) < sv_clmovement_minping.integer)
                host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
        // several conditions govern whether clientside movement prediction is allowed
        if (ceil(max(sv_readmoves[sv_numreadmoves-1].receivetime - sv_readmoves[sv_numreadmoves-1].time, 0) * 1000.0) < sv_clmovement_minping.integer)
                host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
        // several conditions govern whether clientside movement prediction is allowed
-       if (sv_readmoves[sv_numreadmoves-1].sequence && sv_clmovement_enable.integer && sv_clmovement_inputtimeout.value > 0 && host_client->clmovement_disabletimeout <= realtime && PRVM_serveredictfloat(host_client->edict, movetype) == MOVETYPE_WALK && (!PRVM_serveredictfloat(host_client->edict, disableclientprediction)))
+       if (sv_readmoves[sv_numreadmoves-1].sequence && sv_clmovement_enable.integer && sv_clmovement_inputtimeout.value > 0 && host_client->clmovement_disabletimeout <= realtime && (PRVM_serveredictfloat(host_client->edict, disableclientprediction) == -1 || (PRVM_serveredictfloat(host_client->edict, movetype) == MOVETYPE_WALK && (!PRVM_serveredictfloat(host_client->edict, disableclientprediction)))))
        {
                // process the moves in order and ignore old ones
                // but always trust the latest move
        {
                // process the moves in order and ignore old ones
                // but always trust the latest move
@@ -599,7 +612,7 @@ static void SV_ExecuteClientMoves(void)
                        if (host_client->movesequence < move->sequence || moveindex == sv_numreadmoves - 1)
                        {
 #if DEBUGMOVES
                        if (host_client->movesequence < move->sequence || moveindex == sv_numreadmoves - 1)
                        {
 #if DEBUGMOVES
-                               Con_Printf("%smove #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", (move->time - host_client->cmd.time) > sv.frametime * 1.01 ? "^1" : "^2", move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
+                               Con_Printf("%smove #%u %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", (move->time - host_client->cmd.time) > sv.frametime * 1.01 ? "^1" : "^2", move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
 #endif
                                // this is a new move
                                move->time = bound(sv.time - 1, move->time, sv.time); // prevent slowhack/speedhack combos
 #endif
                                // this is a new move
                                move->time = bound(sv.time - 1, move->time, sv.time); // prevent slowhack/speedhack combos
@@ -755,13 +768,18 @@ void SV_ApplyClientMove (void)
        PRVM_serveredictfloat(host_client->edict, ping_movementloss) = movementloss / (float) NETGRAPH_PACKETS;
 }
 
        PRVM_serveredictfloat(host_client->edict, ping_movementloss) = movementloss / (float) NETGRAPH_PACKETS;
 }
 
-static void SV_FrameLost(int framenum)
+static qboolean SV_FrameLost(int framenum)
 {
        if (host_client->entitydatabase5)
        {
 {
        if (host_client->entitydatabase5)
        {
-               EntityFrame5_LostFrame(host_client->entitydatabase5, framenum);
-               EntityFrameCSQC_LostFrame(host_client, framenum);
+               if (framenum <= host_client->entitydatabase5->latestframenum)
+               {
+                       EntityFrame5_LostFrame(host_client->entitydatabase5, framenum);
+                       EntityFrameCSQC_LostFrame(host_client, framenum);
+                       return true;
+               }
        }
        }
+       return false;
 }
 
 static void SV_FrameAck(int framenum)
 }
 
 static void SV_FrameAck(int framenum)
@@ -782,7 +800,7 @@ SV_ReadClientMessage
 void SV_ReadClientMessage(void)
 {
        prvm_prog_t *prog = SVVM_prog;
 void SV_ReadClientMessage(void)
 {
        prvm_prog_t *prog = SVVM_prog;
-       int cmd, num, start;
+       int netcmd, num, start;
        char *s, *p, *q;
 
        if(sv_autodemo_perclient.integer >= 2)
        char *s, *p, *q;
 
        if(sv_autodemo_perclient.integer >= 2)
@@ -807,8 +825,8 @@ void SV_ReadClientMessage(void)
                        return;
                }
 
                        return;
                }
 
-               cmd = MSG_ReadByte(&sv_message);
-               if (cmd == -1)
+               netcmd = MSG_ReadByte(&sv_message);
+               if (netcmd == -1)
                {
                        // end of message
                        // apply the moves that were read this frame
                {
                        // end of message
                        // apply the moves that were read this frame
@@ -816,10 +834,10 @@ void SV_ReadClientMessage(void)
                        break;
                }
 
                        break;
                }
 
-               switch (cmd)
+               switch (netcmd)
                {
                default:
                {
                default:
-                       Con_Printf("SV_ReadClientMessage: unknown command char %i (at offset 0x%x)\n", cmd, sv_message.readcount);
+                       Con_Printf("SV_ReadClientMessage: unknown command char %i (at offset 0x%x)\n", netcmd, sv_message.readcount);
                        if (developer_networking.integer)
                                Com_HexDumpToConsole(sv_message.data, sv_message.cursize);
                        SV_DropClient (false);
                        if (developer_networking.integer)
                                Com_HexDumpToConsole(sv_message.data, sv_message.cursize);
                        SV_DropClient (false);
@@ -869,7 +887,7 @@ void SV_ReadClientMessage(void)
 clc_stringcmd_invalid:
                        Con_Printf("Received invalid stringcmd from %s\n", host_client->name);
                        if(developer.integer > 0)
 clc_stringcmd_invalid:
                        Con_Printf("Received invalid stringcmd from %s\n", host_client->name);
                        if(developer.integer > 0)
-                               Com_HexDumpToConsole((unsigned char *) s, strlen(s));
+                               Com_HexDumpToConsole((unsigned char *) s, (int)strlen(s));
                        break;
 
                case clc_disconnect:
                        break;
 
                case clc_disconnect:
@@ -941,11 +959,12 @@ clc_stringcmd_invalid:
                        // if the client hasn't progressed through signons yet,
                        // ignore any clc_ackframes we get (they're probably from the
                        // previous level)
                        // if the client hasn't progressed through signons yet,
                        // ignore any clc_ackframes we get (they're probably from the
                        // previous level)
-                       if (host_client->spawned && host_client->latestframenum < num)
+                       if (host_client->begun && host_client->latestframenum < num)
                        {
                                int i;
                                for (i = host_client->latestframenum + 1;i < num;i++)
                        {
                                int i;
                                for (i = host_client->latestframenum + 1;i < num;i++)
-                                       SV_FrameLost(i);
+                                       if (!SV_FrameLost(i))
+                                               break;
                                SV_FrameAck(num);
                                host_client->latestframenum = num;
                        }
                                SV_FrameAck(num);
                                host_client->latestframenum = num;
                        }