X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=sv_user.c;h=174aed9f14bd4bd519d01cfa8ff7728b2b713627;hb=f8b3aa66d600adec1c48753320d207b2817188d4;hp=8ddff9948e7a980a1d89973871eb62bd6f3a8c26;hpb=6a384398c93b7e2bc1936427797909eb60094160;p=xonotic%2Fdarkplaces.git diff --git a/sv_user.c b/sv_user.c index 8ddff994..174aed9f 100644 --- a/sv_user.c +++ b/sv_user.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -23,10 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. edict_t *sv_player; -extern cvar_t sv_friction; -cvar_t sv_edgefriction = {"edgefriction", "2"}; -cvar_t sv_predict = {"sv_predict", "1"}; -extern cvar_t sv_stopspeed; +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"}; +cvar_t sv_accelerate = {0, "sv_accelerate", "10"}; static vec3_t forward, right, up; @@ -42,8 +44,6 @@ qboolean onground; usercmd_t cmd; -cvar_t sv_idealpitchscale = {"sv_idealpitchscale","0.8"}; - /* =============== @@ -72,12 +72,12 @@ void SV_SetIdealPitch (void) top[0] = sv_player->v.origin[0] + cosval*(i+3)*12; top[1] = sv_player->v.origin[1] + sinval*(i+3)*12; top[2] = sv_player->v.origin[2] + sv_player->v.view_ofs[2]; - + bottom[0] = top[0]; bottom[1] = top[1]; bottom[2] = top[2] - 160; - - tr = SV_Move (top, vec3_origin, vec3_origin, bottom, 1, sv_player); + + tr = SV_Move (top, vec3_origin, vec3_origin, bottom, MOVE_NOMONSTERS, sv_player); if (tr.allsolid) return; // looking at a wall, leave ideal the way is was @@ -140,7 +140,7 @@ void SV_UserFriction (void) start[2] = origin[2] + sv_player->v.mins[2]; stop[2] = start[2] - 34; - trace = SV_Move (start, vec3_origin, vec3_origin, stop, true, sv_player); + trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, sv_player); if (trace.fraction == 1.0) friction = sv_friction.value*sv_edgefriction.value; @@ -149,8 +149,8 @@ void SV_UserFriction (void) // apply friction control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed; - newspeed = speed - host_frametime*control*friction; - + newspeed = speed - sv.frametime*control*friction; + if (newspeed < 0) newspeed = 0; else @@ -166,8 +166,6 @@ void SV_UserFriction (void) SV_Accelerate ============== */ -cvar_t sv_maxspeed = {"sv_maxspeed", "320", false, true}; -cvar_t sv_accelerate = {"sv_accelerate", "10"}; #if 0 void SV_Accelerate (vec3_t wishvel) { @@ -181,7 +179,7 @@ void SV_Accelerate (vec3_t wishvel) VectorSubtract (wishvel, velocity, pushvec); addspeed = VectorNormalize (pushvec); - accelspeed = sv_accelerate.value*host_frametime*addspeed; + accelspeed = sv_accelerate.value*sv.frametime*addspeed; if (accelspeed > addspeed) accelspeed = addspeed; @@ -198,7 +196,7 @@ void SV_Accelerate (void) addspeed = wishspeed - currentspeed; if (addspeed <= 0) return; - accelspeed = sv_accelerate.value*host_frametime*wishspeed; + accelspeed = sv_accelerate.value*sv.frametime*wishspeed; if (accelspeed > addspeed) accelspeed = addspeed; @@ -218,8 +216,8 @@ void SV_AirAccelerate (vec3_t wishveloc) addspeed = wishspd - currentspeed; if (addspeed <= 0) return; -// accelspeed = sv_accelerate.value * host_frametime; - accelspeed = sv_accelerate.value*wishspeed * host_frametime; +// accelspeed = sv_accelerate.value * sv.frametime; + accelspeed = sv_accelerate.value*wishspeed * sv.frametime; if (accelspeed > addspeed) accelspeed = addspeed; @@ -231,13 +229,24 @@ void SV_AirAccelerate (vec3_t wishveloc) void DropPunchAngle (void) { float len; + eval_t *val; len = VectorNormalizeLength (sv_player->v.punchangle); - - len -= 10*host_frametime; + + len -= 10*sv.frametime; if (len < 0) len = 0; VectorScale (sv_player->v.punchangle, len, sv_player->v.punchangle); + + if ((val = GETEDICTFIELDVALUE(sv_player, eval_punchvector))) + { + len = VectorNormalizeLength (val->vector); + + len -= 20*sv.frametime; + if (len < 0) + len = 0; + VectorScale (val->vector, len, val->vector); + } } /* @@ -250,7 +259,7 @@ void SV_WaterMove (void) { int i; vec3_t wishvel; - float speed, newspeed, wishspeed, addspeed, accelspeed; + float speed, newspeed, wishspeed, addspeed, accelspeed, temp; // // user intentions @@ -268,7 +277,8 @@ void SV_WaterMove (void) wishspeed = Length(wishvel); if (wishspeed > sv_maxspeed.value) { - VectorScale (wishvel, sv_maxspeed.value/wishspeed, wishvel); + temp = sv_maxspeed.value/wishspeed; + VectorScale (wishvel, temp, wishvel); wishspeed = sv_maxspeed.value; } wishspeed *= 0.7; @@ -279,10 +289,11 @@ void SV_WaterMove (void) speed = Length (velocity); if (speed) { - newspeed = speed - host_frametime * speed * sv_friction.value; + newspeed = speed - sv.frametime * speed * sv_friction.value; if (newspeed < 0) - newspeed = 0; - VectorScale (velocity, newspeed/speed, velocity); + newspeed = 0; + temp = newspeed/speed; + VectorScale (velocity, temp, velocity); } else newspeed = 0; @@ -298,7 +309,7 @@ void SV_WaterMove (void) return; VectorNormalize (wishvel); - accelspeed = sv_accelerate.value * wishspeed * host_frametime; + accelspeed = sv_accelerate.value * wishspeed * sv.frametime; if (accelspeed > addspeed) accelspeed = addspeed; @@ -329,7 +340,7 @@ void SV_AirMove (void) { int i; vec3_t wishvel; - float fmove, smove; + float fmove, smove, temp; // LordHavoc: correct quake movement speed bug when looking up/down wishvel[0] = wishvel[2] = 0; @@ -356,7 +367,8 @@ void SV_AirMove (void) wishspeed = VectorNormalizeLength(wishdir); if (wishspeed > sv_maxspeed.value) { - VectorScale (wishvel, sv_maxspeed.value/wishspeed, wishvel); + temp = sv_maxspeed.value/wishspeed; + VectorScale (wishvel, temp, wishvel); wishspeed = sv_maxspeed.value; } @@ -372,7 +384,7 @@ void SV_AirMove (void) else { // not on ground, so little effect on velocity SV_AirAccelerate (wishvel); - } + } } /* @@ -429,14 +441,13 @@ void SV_ClientThink (void) // // walk // - if ( (sv_player->v.waterlevel >= 2) - && (sv_player->v.movetype != MOVETYPE_NOCLIP) ) + if ( (sv_player->v.waterlevel >= 2) && (sv_player->v.movetype != MOVETYPE_NOCLIP) ) { SV_WaterMove (); return; } - SV_AirMove (); + SV_AirMove (); } @@ -452,34 +463,26 @@ void SV_ReadClientMove (usercmd_t *move) int bits; eval_t *val; float total; - + // read ping time - host_client->ping_times[host_client->num_pings%NUM_PING_TIMES] - = sv.time - MSG_ReadFloat (); + host_client->ping_times[host_client->num_pings % NUM_PING_TIMES] = sv.time - MSG_ReadFloat (); host_client->num_pings++; for (i=0, total = 0;i < NUM_PING_TIMES;i++) total += host_client->ping_times[i]; host_client->ping = total / NUM_PING_TIMES; // can be used for prediction host_client->latency = 0; - if (sv_predict.value && (svs.maxclients > 1) && (!sv.paused)) // if paused or a local game, don't predict + if (sv_predict.integer && (svs.maxclients > 1) && (!sv.paused)) // if paused or a local game, don't predict host_client->latency = host_client->ping; if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ping))) val->_float = host_client->ping * 1000.0; // read current angles - if (dpprotocol) - { - for (i=0 ; i<3 ; i++) - angle[i] = MSG_ReadPreciseAngle (); - } - else - { - for (i=0 ; i<3 ; i++) - angle[i] = MSG_ReadAngle (); - } + // dpprotocol version 2 + for (i = 0;i < 3;i++) + angle[i] = MSG_ReadFloat (); VectorCopy (angle, host_client->edict->v.v_angle); - + // read movement move->forwardmove = MSG_ReadShort (); move->sidemove = MSG_ReadShort (); @@ -490,7 +493,7 @@ void SV_ReadClientMove (usercmd_t *move) val->vector[1] = move->sidemove; val->vector[2] = move->upmove; } - + // read buttons bits = MSG_ReadByte (); host_client->edict->v.button0 = bits & 1; @@ -515,12 +518,13 @@ SV_ReadClientMessage Returns false if the client should be killed =================== */ +void SV_SendServerinfo (client_t *client); qboolean SV_ReadClientMessage (void) { int ret; int cmd; char *s; - + do { nextmsg: @@ -532,9 +536,9 @@ nextmsg: } if (!ret) return true; - + MSG_BeginReading (); - + while (1) { if (!host_client->active) @@ -544,24 +548,32 @@ nextmsg: { Sys_Printf ("SV_ReadClientMessage: badread\n"); return false; - } - + } + cmd = MSG_ReadChar (); - + +#ifndef NOROUTINGFIX + if (cmd != -1 && host_client->waitingforconnect) + { + host_client->waitingforconnect = false; + host_client->sendserverinfo = true; + } +#endif + switch (cmd) { case -1: goto nextmsg; // end of message - + default: - Sys_Printf ("SV_ReadClientMessage: unknown command char\n"); + Sys_Printf ("SV_ReadClientMessage: unknown command char %i\n", cmd); return false; - + case clc_nop: // Sys_Printf ("clc_nop\n"); break; - - case clc_stringcmd: + + case clc_stringcmd: s = MSG_ReadString (); ret = 0; if (Q_strncasecmp(s, "status", 6) == 0 @@ -579,8 +591,8 @@ nextmsg: || Q_strncasecmp(s, "ping", 4) == 0 || Q_strncasecmp(s, "ban", 3) == 0 || Q_strncasecmp(s, "pmodel", 6) == 0 - || (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)) - || (!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))) + || (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); @@ -596,18 +608,22 @@ nextmsg: Con_DPrintf("%s tried to %s\n", host_client->name, s); */ break; - + case clc_disconnect: // Sys_Printf ("SV_ReadClientMessage: client disconnected\n"); return false; - + 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; } @@ -617,7 +633,6 @@ nextmsg: SV_RunClients ================== */ -extern dfunction_t *SV_PlayerPhysicsQC; void SV_RunClients (void) { int i; @@ -650,7 +665,7 @@ void SV_RunClients (void) { pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); - PR_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - pr_functions)); + PR_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - pr_functions), ""); } else SV_ClientThink ();