2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cl_pred.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
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2001-05-15 05:27:14 +00:00
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
|
2001-09-11 05:18:15 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/bothdefs.h"
|
|
|
|
#include "qw/include/cl_ents.h"
|
|
|
|
#include "qw/include/cl_pred.h"
|
|
|
|
#include "qw/include/client.h"
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "qw/pmove.h"
|
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
|
|
|
int cl_predict;
|
|
|
|
static cvar_t cl_predict_cvar = {
|
|
|
|
.name = "cl_predict",
|
|
|
|
.description =
|
|
|
|
"Set to enable client prediction",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &cl_predict },
|
|
|
|
};
|
|
|
|
float cl_pushlatency;
|
|
|
|
static cvar_t cl_pushlatency_cvar = {
|
|
|
|
.name = "pushlatency",
|
|
|
|
.description =
|
|
|
|
"How much prediction should the client make",
|
|
|
|
.default_value = "-999",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &cl_pushlatency },
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_PredictUsercmd (player_state_t *from, player_state_t *to, usercmd_t *u,
|
2023-06-13 09:06:11 +00:00
|
|
|
bool clientplayer)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-07-27 00:44:54 +00:00
|
|
|
if (!clientplayer) {
|
2021-03-11 05:27:36 +00:00
|
|
|
if (VectorIsZero (from->pls.es.velocity)) {
|
|
|
|
VectorCopy (from->pls.es.origin, to->pls.es.origin);
|
2002-07-27 00:44:54 +00:00
|
|
|
VectorCopy (u->angles, to->viewangles);
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (from->pls.es.velocity, to->pls.es.velocity);
|
2002-07-27 00:44:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-14 03:08:24 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// split up very long moves
|
|
|
|
if (u->msec > 50) {
|
|
|
|
player_state_t temp;
|
|
|
|
usercmd_t split;
|
|
|
|
|
|
|
|
split = *u;
|
|
|
|
split.msec /= 2;
|
|
|
|
|
2002-07-27 00:44:54 +00:00
|
|
|
CL_PredictUsercmd (from, &temp, &split, clientplayer);
|
|
|
|
CL_PredictUsercmd (&temp, to, &split, clientplayer);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (from->pls.es.origin, pmove.origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (u->angles, pmove.angles);
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (from->pls.es.velocity, pmove.velocity);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pmove.oldbuttons = from->oldbuttons;
|
2002-09-13 04:30:18 +00:00
|
|
|
pmove.oldonground = from->oldonground;
|
2001-02-19 21:15:25 +00:00
|
|
|
pmove.waterjumptime = from->waterjumptime;
|
|
|
|
pmove.dead = cl.stats[STAT_HEALTH] <= 0;
|
2002-07-27 00:44:54 +00:00
|
|
|
if (clientplayer)
|
|
|
|
pmove.spectator = cl.spectator;
|
|
|
|
else
|
|
|
|
pmove.spectator = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
pmove.flying = cl.stats[STAT_FLYMODE];
|
|
|
|
|
|
|
|
pmove.cmd = *u;
|
|
|
|
|
|
|
|
PlayerMove ();
|
|
|
|
to->waterjumptime = pmove.waterjumptime;
|
|
|
|
to->oldbuttons = pmove.oldbuttons; // Tonik
|
2002-09-13 04:30:18 +00:00
|
|
|
to->oldonground = pmove.oldonground;
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (pmove.origin, to->pls.es.origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (pmove.angles, to->viewangles);
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (pmove.velocity, to->pls.es.velocity);
|
2001-02-19 21:15:25 +00:00
|
|
|
to->onground = onground;
|
2021-03-11 05:27:36 +00:00
|
|
|
to->pls.es.weaponframe = from->pls.es.weaponframe;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CL_PredictMove (void)
|
|
|
|
{
|
|
|
|
float f;
|
2001-08-28 23:05:45 +00:00
|
|
|
int oldphysent, i;
|
2001-09-10 17:32:22 +00:00
|
|
|
frame_t *from, *to = NULL;
|
2021-03-19 11:18:45 +00:00
|
|
|
entity_state_t *fromes;
|
|
|
|
entity_state_t *toes;
|
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
|
|
|
if (cl_pushlatency > 0)
|
|
|
|
Cvar_Set ("pushlatency", "0");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cl.paused)
|
|
|
|
return;
|
|
|
|
|
2001-09-11 05:18:15 +00:00
|
|
|
// assume on ground unless prediction says different
|
2021-03-19 15:58:37 +00:00
|
|
|
cl.viewstate.onground = 0;
|
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
|
|
|
cl.time = realtime - cls.latency - cl_pushlatency * 0.001;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cl.time > realtime)
|
|
|
|
cl.time = realtime;
|
2022-10-22 05:14:57 +00:00
|
|
|
cl.viewstate.time = cl.time;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-21 05:15:16 +00:00
|
|
|
if (cl.intermission) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2002-06-21 05:15:16 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!cl.validsequence)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cls.netchan.outgoing_sequence - cls.netchan.incoming_sequence >=
|
|
|
|
UPDATE_BACKUP - 1)
|
|
|
|
return;
|
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
//VectorCopy (cl.viewstate.angles, cl.viewstate.angles);
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_angles[ROLL] = 0; // FIXME @@@
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// this is the last frame received from the server
|
|
|
|
from = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK];
|
2021-03-19 11:18:45 +00:00
|
|
|
fromes = &from->playerstate[cl.playernum].pls.es;
|
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
|
|
|
if (!cl_predict) {
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.velocity = fromes->velocity;
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_origin = fromes->origin;
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
// predict forward until cl.time <= to->senttime
|
2001-02-19 21:15:25 +00:00
|
|
|
oldphysent = pmove.numphysent;
|
|
|
|
CL_SetSolidPlayers (cl.playernum);
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
// to = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 1; i < UPDATE_BACKUP - 1 && cls.netchan.incoming_sequence + i <
|
|
|
|
cls.netchan.outgoing_sequence; i++) {
|
|
|
|
to = &cl.frames[(cls.netchan.incoming_sequence + i) & UPDATE_MASK];
|
2001-09-11 05:18:15 +00:00
|
|
|
CL_PredictUsercmd (&from->playerstate[cl.playernum],
|
|
|
|
&to->playerstate[cl.playernum], &to->cmd,
|
2002-07-27 00:44:54 +00:00
|
|
|
true);
|
2021-03-19 15:58:37 +00:00
|
|
|
cl.viewstate.onground = onground;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (to->senttime >= cl.time)
|
|
|
|
break;
|
|
|
|
from = to;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmove.numphysent = oldphysent;
|
|
|
|
|
|
|
|
if (i == UPDATE_BACKUP - 1 || !to)
|
|
|
|
return; // net hasn't deliver packets in a
|
|
|
|
// long time...
|
2021-03-19 11:18:45 +00:00
|
|
|
toes = &to->playerstate[cl.playernum].pls.es;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// now interpolate some fraction of the final frame
|
|
|
|
if (to->senttime == from->senttime)
|
|
|
|
f = 0;
|
2012-07-12 10:33:51 +00:00
|
|
|
else {
|
|
|
|
f = (cl.time - from->senttime) / (to->senttime - from->senttime);
|
|
|
|
f = bound (0, f, 1);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2021-03-19 11:18:45 +00:00
|
|
|
if (fabs (fromes->origin[i] - toes->origin[i]) > 128) {
|
2001-05-14 03:08:24 +00:00
|
|
|
// teleported, so don't lerp
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.velocity = toes->velocity;
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_origin = toes->origin;
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_origin = fromes->origin
|
|
|
|
+ f * (toes->origin - fromes->origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CL_Prediction_Init_Cvars (void)
|
|
|
|
{
|
[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
|
|
|
Cvar_Register (&cl_predict_cvar, 0, 0);
|
|
|
|
Cvar_Register (&cl_pushlatency_cvar, 0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|