2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sv_user.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
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.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-01-20 05:57:39 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-08-27 07:13:32 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/msg.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "world.h"
|
2001-03-03 08:31:58 +00:00
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "nq/include/host.h"
|
|
|
|
#include "nq/include/server.h"
|
|
|
|
#include "nq/include/sv_progs.h"
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int sv_nostep;
|
|
|
|
static cvar_t sv_nostep_cvar = {
|
|
|
|
.name = "sv_nostep",
|
|
|
|
.description =
|
|
|
|
"None",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &sv_nostep },
|
|
|
|
};
|
|
|
|
|
|
|
|
float sv_rollangle;
|
|
|
|
static cvar_t sv_rollangle_cvar = {
|
|
|
|
.name = "cl_rollangle",
|
|
|
|
.description =
|
|
|
|
"How much your screen tilts when strafing",
|
|
|
|
.default_value = "2.0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_rollangle },
|
|
|
|
};
|
|
|
|
float sv_rollspeed;
|
|
|
|
static cvar_t sv_rollspeed_cvar = {
|
|
|
|
.name = "cl_rollspeed",
|
|
|
|
.description =
|
|
|
|
"How quickly you straighten out after strafing",
|
|
|
|
.default_value = "200",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_rollspeed },
|
|
|
|
};
|
2001-10-28 04:23:37 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
edict_t *sv_player;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
float sv_edgefriction;
|
|
|
|
static cvar_t sv_edgefriction_cvar = {
|
|
|
|
.name = "edgefriction",
|
|
|
|
.description =
|
|
|
|
"None",
|
|
|
|
.default_value = "2",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_edgefriction },
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t forward, right, up;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t wishdir;
|
|
|
|
float wishspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// world
|
2001-02-26 06:48:02 +00:00
|
|
|
float *angles;
|
|
|
|
float *origin;
|
|
|
|
float *velocity;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean onground;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
usercmd_t cmd;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
float sv_idealpitchscale;
|
|
|
|
static cvar_t sv_idealpitchscale_cvar = {
|
|
|
|
.name = "sv_idealpitchscale",
|
|
|
|
.description =
|
|
|
|
"None",
|
|
|
|
.default_value = "0.8",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_idealpitchscale },
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MAX_FORWARD 6
|
2001-08-27 07:13:32 +00:00
|
|
|
|
2012-04-15 06:11:16 +00:00
|
|
|
/*
|
|
|
|
FIXME duplicates V_CalcRoll in cl_view.c
|
|
|
|
*/
|
|
|
|
static float
|
|
|
|
SV_CalcRoll (const vec3_t angles, const vec3_t velocity)
|
|
|
|
{
|
|
|
|
float side, sign, value;
|
|
|
|
|
|
|
|
AngleVectors (angles, forward, right, up);
|
|
|
|
side = DotProduct (velocity, right);
|
|
|
|
sign = side < 0 ? -1 : 1;
|
|
|
|
side = fabs (side);
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
value = sv_rollangle;
|
2012-04-15 06:11:16 +00:00
|
|
|
// if (cl.inwater)
|
|
|
|
// value *= 6;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (side < sv_rollspeed)
|
|
|
|
side = side * value / sv_rollspeed;
|
2012-04-15 06:11:16 +00:00
|
|
|
else
|
|
|
|
side = value;
|
|
|
|
|
|
|
|
return side * sign;
|
|
|
|
}
|
2001-08-27 07:13:32 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SV_SetIdealPitch (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-27 07:13:32 +00:00
|
|
|
int dir, step, steps, i, j;
|
2001-02-26 06:48:02 +00:00
|
|
|
float angleval, sinval, cosval;
|
2001-08-27 07:13:32 +00:00
|
|
|
float z[MAX_FORWARD];
|
2001-02-26 06:48:02 +00:00
|
|
|
trace_t tr;
|
|
|
|
vec3_t top, bottom;
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (!((int) SVfloat (sv_player, flags) & FL_ONGROUND))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
angleval = SVvector (sv_player, angles)[YAW] * M_PI * 2 / 360;
|
2001-02-26 06:48:02 +00:00
|
|
|
sinval = sin (angleval);
|
|
|
|
cosval = cos (angleval);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FORWARD; i++) {
|
2001-08-08 20:28:53 +00:00
|
|
|
top[0] = SVvector (sv_player, origin)[0] + cosval * (i + 3) * 12;
|
|
|
|
top[1] = SVvector (sv_player, origin)[1] + sinval * (i + 3) * 12;
|
2001-08-27 07:13:32 +00:00
|
|
|
top[2] = SVvector (sv_player, origin)[2] + SVvector (sv_player,
|
|
|
|
view_ofs)[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
bottom[0] = top[0];
|
|
|
|
bottom[1] = top[1];
|
|
|
|
bottom[2] = top[2] - 160;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
tr = SV_Move (top, vec3_origin, vec3_origin, bottom, 1, sv_player);
|
|
|
|
if (tr.allsolid)
|
2012-05-21 23:23:22 +00:00
|
|
|
return; // looking at a wall, leave ideal the
|
2001-08-27 07:13:32 +00:00
|
|
|
// way it was
|
2001-02-19 21:15:25 +00:00
|
|
|
if (tr.fraction == 1)
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // near a dropoff
|
|
|
|
|
|
|
|
z[i] = top[2] + tr.fraction * (bottom[2] - top[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
dir = 0;
|
|
|
|
steps = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 1; j < i; j++) {
|
|
|
|
step = z[j] - z[j - 1];
|
2001-02-19 21:15:25 +00:00
|
|
|
if (step > -ON_EPSILON && step < ON_EPSILON)
|
|
|
|
continue;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dir && (step - dir > ON_EPSILON || step - dir < -ON_EPSILON))
|
|
|
|
return; // mixed changes
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
steps++;
|
2001-02-19 21:15:25 +00:00
|
|
|
dir = step;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (!dir) {
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (sv_player, idealpitch) = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (steps < 2)
|
|
|
|
return;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
SVfloat (sv_player, idealpitch) = -dir * sv_idealpitchscale;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_UserFriction (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float *vel;
|
2001-08-27 07:13:32 +00:00
|
|
|
float control, friction, speed, newspeed;
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t start, stop;
|
|
|
|
trace_t trace;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
vel = velocity;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
speed = sqrt (vel[0] * vel[0] + vel[1] * vel[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!speed)
|
|
|
|
return;
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// if the leading edge is over a dropoff, increase friction
|
2001-02-26 06:48:02 +00:00
|
|
|
start[0] = stop[0] = origin[0] + vel[0] / speed * 16;
|
|
|
|
start[1] = stop[1] = origin[1] + vel[1] / speed * 16;
|
2001-08-08 20:28:53 +00:00
|
|
|
start[2] = origin[2] + SVvector (sv_player, mins)[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
stop[2] = start[2] - 34;
|
|
|
|
|
|
|
|
trace = SV_Move (start, vec3_origin, vec3_origin, stop, true, sv_player);
|
|
|
|
|
|
|
|
if (trace.fraction == 1.0)
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
friction = sv_friction * sv_edgefriction;
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
friction = sv_friction;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// apply friction
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
control = speed < sv_stopspeed ? sv_stopspeed : speed;
|
2001-02-26 06:48:02 +00:00
|
|
|
newspeed = speed - host_frametime * control * friction;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (newspeed < 0)
|
|
|
|
newspeed = 0;
|
|
|
|
newspeed /= speed;
|
|
|
|
|
|
|
|
vel[0] = vel[0] * newspeed;
|
|
|
|
vel[1] = vel[1] * newspeed;
|
|
|
|
vel[2] = vel[2] * newspeed;
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
float sv_maxspeed;
|
|
|
|
static cvar_t sv_maxspeed_cvar = {
|
|
|
|
.name = "sv_maxspeed",
|
|
|
|
.description =
|
|
|
|
"None",
|
|
|
|
.default_value = "320",
|
|
|
|
.flags = CVAR_SERVERINFO,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_maxspeed },
|
|
|
|
};
|
|
|
|
float sv_accelerate;
|
|
|
|
static cvar_t sv_accelerate_cvar = {
|
|
|
|
.name = "sv_accelerate",
|
|
|
|
.description =
|
|
|
|
"None",
|
|
|
|
.default_value = "10",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_accelerate },
|
|
|
|
};
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#if 0
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SV_Accelerate (vec3_t wishvel)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float addspeed, accelspeed;
|
|
|
|
vec3_t pushvec;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (wishspeed == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorSubtract (wishvel, velocity, pushvec);
|
|
|
|
addspeed = VectorNormalize (pushvec);
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
accelspeed = sv_accelerate * host_frametime * addspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
velocity[i] += accelspeed * pushvec[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-08-27 07:13:32 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_Accelerate (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float addspeed, accelspeed, currentspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
currentspeed = DotProduct (velocity, wishdir);
|
|
|
|
addspeed = wishspeed - currentspeed;
|
|
|
|
if (addspeed <= 0)
|
|
|
|
return;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
accelspeed = sv_accelerate * host_frametime * wishspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
velocity[i] += accelspeed * wishdir[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_AirAccelerate (vec3_t wishveloc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float addspeed, wishspd, accelspeed, currentspeed;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
wishspd = VectorNormalize (wishveloc);
|
|
|
|
if (wishspd > 30)
|
|
|
|
wishspd = 30;
|
|
|
|
currentspeed = DotProduct (velocity, wishveloc);
|
|
|
|
addspeed = wishspd - currentspeed;
|
|
|
|
if (addspeed <= 0)
|
|
|
|
return;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
// accelspeed = sv_accelerate * host_frametime;
|
|
|
|
accelspeed = sv_accelerate * wishspeed * host_frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
velocity[i] += accelspeed * wishveloc[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
DropPunchAngle (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float len;
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
len = VectorNormalize (SVvector (sv_player, punchangle));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
len -= 10 * host_frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
2001-08-27 07:13:32 +00:00
|
|
|
VectorScale (SVvector (sv_player, punchangle), len, SVvector (sv_player,
|
|
|
|
punchangle));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_WaterMove (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float speed, newspeed, wishspeed, addspeed, accelspeed;
|
2001-08-27 07:13:32 +00:00
|
|
|
vec3_t wishvel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// user intentions
|
2001-08-08 20:28:53 +00:00
|
|
|
AngleVectors (SVvector (sv_player, v_angle), forward, right, up);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
wishvel[i] = forward[i] * cmd.forwardmove + right[i] * cmd.sidemove;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!cmd.forwardmove && !cmd.sidemove && !cmd.upmove)
|
2001-02-26 06:48:02 +00:00
|
|
|
wishvel[2] -= 60; // drift towards bottom
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
wishvel[2] += cmd.upmove;
|
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
wishspeed = VectorLength (wishvel);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (wishspeed > sv_maxspeed) {
|
|
|
|
VectorScale (wishvel, sv_maxspeed / wishspeed, wishvel);
|
|
|
|
wishspeed = sv_maxspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
wishspeed *= 0.7;
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// water friction
|
2002-08-20 02:22:40 +00:00
|
|
|
speed = VectorLength (velocity);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (speed) {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
newspeed = speed - host_frametime * speed * sv_friction;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (newspeed < 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
newspeed = 0;
|
|
|
|
VectorScale (velocity, newspeed / speed, velocity);
|
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
newspeed = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// water acceleration
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!wishspeed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
addspeed = wishspeed - newspeed;
|
|
|
|
if (addspeed <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorNormalize (wishvel);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
accelspeed = sv_accelerate * wishspeed * host_frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
velocity[i] += accelspeed * wishvel[i];
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_WaterJump (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-27 07:13:32 +00:00
|
|
|
if (sv.time > SVfloat (sv_player, teleport_time) ||
|
|
|
|
!SVfloat (sv_player, waterlevel)) {
|
|
|
|
SVfloat (sv_player, flags) = (int) SVfloat (sv_player, flags) &
|
|
|
|
~FL_WATERJUMP;
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (sv_player, teleport_time) = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-08-08 20:28:53 +00:00
|
|
|
SVvector (sv_player, velocity)[0] = SVvector (sv_player, movedir)[0];
|
|
|
|
SVvector (sv_player, velocity)[1] = SVvector (sv_player, movedir)[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_AirMove (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float fmove, smove;
|
2001-08-27 07:13:32 +00:00
|
|
|
vec3_t wishvel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
AngleVectors (SVvector (sv_player, angles), forward, right, up);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
fmove = cmd.forwardmove;
|
|
|
|
smove = cmd.sidemove;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// hack to not let you back into teleporter
|
2001-08-08 20:28:53 +00:00
|
|
|
if (sv.time < SVfloat (sv_player, teleport_time) && fmove < 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
fmove = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
wishvel[i] = forward[i] * fmove + right[i] * smove;
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if ((int) SVfloat (sv_player, movetype) != MOVETYPE_WALK)
|
2001-02-19 21:15:25 +00:00
|
|
|
wishvel[2] = cmd.upmove;
|
|
|
|
else
|
|
|
|
wishvel[2] = 0;
|
|
|
|
|
|
|
|
VectorCopy (wishvel, wishdir);
|
2001-02-26 06:48:02 +00:00
|
|
|
wishspeed = VectorNormalize (wishdir);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (wishspeed > sv_maxspeed) {
|
|
|
|
VectorScale (wishvel, sv_maxspeed / wishspeed, wishvel);
|
|
|
|
wishspeed = sv_maxspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (sv_player, movetype) == MOVETYPE_NOCLIP) { // noclip
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (wishvel, velocity);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (onground) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_UserFriction ();
|
|
|
|
SV_Accelerate ();
|
2001-08-27 07:13:32 +00:00
|
|
|
} else { // not on ground, so little effect on velocity
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_AirAccelerate (wishvel);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-27 07:13:32 +00:00
|
|
|
SV_ClientThink
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
the move fields specify an intended velocity in pix/sec
|
|
|
|
the angle fields specify an exact angular motion in degrees
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SV_ClientThink (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t v_angle;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (sv_player, movetype) == MOVETYPE_NONE)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
onground = (int) SVfloat (sv_player, flags) & FL_ONGROUND;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
origin = SVvector (sv_player, origin);
|
|
|
|
velocity = SVvector (sv_player, velocity);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
DropPunchAngle ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// if dead, behave differently
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (sv_player, health) <= 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// angles
|
|
|
|
// show 1/3 the pitch angle and all the roll angle
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd = host_client->cmd;
|
2001-08-08 20:28:53 +00:00
|
|
|
angles = SVvector (sv_player, angles);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
VectorAdd (SVvector (sv_player, v_angle), SVvector (sv_player,
|
|
|
|
punchangle), v_angle);
|
2012-04-15 06:11:16 +00:00
|
|
|
angles[ROLL] = SV_CalcRoll (SVvector (sv_player, angles),
|
|
|
|
SVvector (sv_player, velocity)) * 4;
|
2001-08-08 20:28:53 +00:00
|
|
|
if (!SVfloat (sv_player, fixangle)) {
|
2001-02-26 06:48:02 +00:00
|
|
|
angles[PITCH] = -v_angle[PITCH] / 3;
|
2001-02-19 21:15:25 +00:00
|
|
|
angles[YAW] = v_angle[YAW];
|
|
|
|
}
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if ((int) SVfloat (sv_player, flags) & FL_WATERJUMP) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_WaterJump ();
|
|
|
|
return;
|
|
|
|
}
|
2001-08-27 07:13:32 +00:00
|
|
|
// walk
|
2001-08-08 20:28:53 +00:00
|
|
|
if ((SVfloat (sv_player, waterlevel) >= 2)
|
|
|
|
&& (SVfloat (sv_player, movetype) != MOVETYPE_NOCLIP)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_WaterMove ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_AirMove ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_ReadClientMove (usercmd_t *move)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-27 07:13:32 +00:00
|
|
|
int i, bits;
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t angle;
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// read ping time
|
2001-02-26 06:48:02 +00:00
|
|
|
host_client->ping_times[host_client->num_pings % NUM_PING_TIMES]
|
2001-02-23 23:16:13 +00:00
|
|
|
= sv.time - MSG_ReadFloat (net_message);
|
2001-02-19 21:15:25 +00:00
|
|
|
host_client->num_pings++;
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// read current angles
|
2010-08-24 00:53:54 +00:00
|
|
|
if (sv.protocol == PROTOCOL_NETQUAKE)
|
|
|
|
MSG_ReadAngleV (net_message, angle);
|
|
|
|
else
|
|
|
|
MSG_ReadAngle16V (net_message, angle);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
VectorCopy (angle, SVvector (host_client->edict, v_angle));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// read movement
|
2011-08-28 09:29:46 +00:00
|
|
|
move->forwardmove = (short) MSG_ReadShort (net_message);
|
|
|
|
move->sidemove = (short) MSG_ReadShort (net_message);
|
|
|
|
move->upmove = (short) MSG_ReadShort (net_message);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// read buttons
|
2001-02-23 23:16:13 +00:00
|
|
|
bits = MSG_ReadByte (net_message);
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (host_client->edict, button0) = bits & 1;
|
|
|
|
SVfloat (host_client->edict, button2) = (bits & 2) >> 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-23 23:16:13 +00:00
|
|
|
i = MSG_ReadByte (net_message);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (i)
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (host_client->edict, impulse) = i;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-27 07:13:32 +00:00
|
|
|
SV_ReadClientMessage
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
Returns false if the client should be killed
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static qboolean
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_ReadClientMessage (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-27 07:13:32 +00:00
|
|
|
int cmd, ret;
|
2001-10-18 04:44:58 +00:00
|
|
|
const char *s;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
nextmsg:
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = NET_GetMessage (host_client->netconnection);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ret == -1) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("SV_ReadClientMessage: NET_GetMessage failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
return true;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-23 23:16:13 +00:00
|
|
|
MSG_BeginReading (net_message);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
while (1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!host_client->active)
|
2001-02-26 06:48:02 +00:00
|
|
|
return false; // a command caused an error
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (net_message->badread) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("SV_ReadClientMessage: badread\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 03:43:20 +00:00
|
|
|
cmd = MSG_ReadByte (net_message);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
2001-08-27 07:13:32 +00:00
|
|
|
case -1:
|
2001-02-26 06:48:02 +00:00
|
|
|
goto nextmsg; // end of message
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
default:
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("SV_ReadClientMessage: unknown command char\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
case clc_nop:
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
case clc_stringcmd:
|
2001-02-23 23:16:13 +00:00
|
|
|
s = MSG_ReadString (net_message);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (host_client->privileged)
|
|
|
|
ret = 2;
|
|
|
|
else
|
|
|
|
ret = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (strncasecmp (s, "status", 6) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "god", 3) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "notarget", 8) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "fly", 3) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "name", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "noclip", 6) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "say", 3) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "say_team", 8) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "tell", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "color", 5) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "kill", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "pause", 5) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "spawn", 5) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "begin", 5) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "prespawn", 8) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "kick", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "ping", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "give", 4) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (strncasecmp (s, "ban", 3) == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = 1;
|
|
|
|
if (ret == 2)
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_InsertText (host_cbuf, s);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (ret == 1)
|
2001-02-22 04:46:59 +00:00
|
|
|
Cmd_ExecuteString (s, src_client);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "%s tried to %s\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
host_client->name, s);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
case clc_disconnect:
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
case clc_move:
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_ReadClientMove (&host_client->cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (ret == 1);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SV_RunClients (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-01-16 13:15:18 +00:00
|
|
|
unsigned i;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0, host_client = svs.clients; i < svs.maxclients;
|
|
|
|
i++, host_client++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!host_client->active)
|
|
|
|
continue;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
sv_player = host_client->edict;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!SV_ReadClientMessage ()) {
|
|
|
|
SV_DropClient (false); // client misbehaved...
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!host_client->spawned) {
|
|
|
|
// clear client movement until a new packet is received
|
|
|
|
memset (&host_client->cmd, 0, sizeof (host_client->cmd));
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-08-27 07:13:32 +00:00
|
|
|
// always pause in single player if in console or menus
|
2013-01-16 04:18:54 +00:00
|
|
|
if (!sv.paused && (svs.maxclients > 1 || host_in_game))
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_ClientThink ();
|
|
|
|
}
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
sv_rollspeed_f (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
sv_rollspeed = *(float *) cvar->value.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sv_rollangle_f (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
sv_rollangle = *(float *) cvar->value.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_User_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
//NOTE: the cl/sv clash is deliberate: dedicated server will use the right
|
|
|
|
//vars, but client/server combo will use the one.
|
|
|
|
if (isDedicated) {
|
|
|
|
Cvar_Register (&sv_rollspeed_cvar, 0, 0);
|
|
|
|
Cvar_Register (&sv_rollangle_cvar, 0, 0);
|
|
|
|
} else {
|
|
|
|
cvar_t *var;
|
|
|
|
var = Cvar_FindVar ("cl_rollspeed");
|
|
|
|
Cvar_AddListener (var, sv_rollspeed_f, 0);
|
|
|
|
sv_rollspeed = *(float *) var->value.value;
|
|
|
|
var = Cvar_FindVar ("cl_rollangle");
|
|
|
|
Cvar_AddListener (var, sv_rollangle_f, 0);
|
|
|
|
sv_rollangle = *(float *) var->value.value;
|
|
|
|
}
|
|
|
|
Cvar_Register (&sv_edgefriction_cvar, 0, 0);
|
|
|
|
Cvar_Register (&sv_maxspeed_cvar, Cvar_Info, &sv_maxspeed);
|
|
|
|
Cvar_Register (&sv_accelerate_cvar, 0, 0);
|
|
|
|
Cvar_Register (&sv_idealpitchscale_cvar, 0, 0);
|
|
|
|
|
|
|
|
Cvar_Register (&sv_nostep_cvar, 0, 0);
|
|
|
|
}
|