mvds are interpolated properly now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@644 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2004-12-15 17:47:42 +00:00
parent 8ba4227cd9
commit bb8163406c

View file

@ -36,6 +36,12 @@ static struct predicted_player {
float lerptime; float lerptime;
qboolean active; qboolean active;
vec3_t origin; // predicted origin vec3_t origin; // predicted origin
vec3_t oldo;
vec3_t olda;
vec3_t oldv;
qboolean predict;
player_state_t *oldstate;
} predicted_players[MAX_CLIENTS]; } predicted_players[MAX_CLIENTS];
float newlerprate; float newlerprate;
@ -2275,7 +2281,7 @@ void CL_SetUpPlayerPrediction(qboolean dopred)
if (playertime > realtime) if (playertime > realtime)
playertime = realtime; playertime = realtime;
if (cl_nopred.value) if (cl_nopred.value || cls.demoplayback)
return; return;
frame = &cl.frames[cl.parsecount&UPDATE_MASK]; frame = &cl.frames[cl.parsecount&UPDATE_MASK];
@ -2450,7 +2456,7 @@ void CL_EmitEntities (void)
void CL_ParseClientdata (void); void CL_ParseClientdata (void);
/*
void MVD_Interpolate(void) void MVD_Interpolate(void)
{ {
player_state_t *self, *oldself; player_state_t *self, *oldself;
@ -2468,7 +2474,7 @@ void MVD_Interpolate(void)
cls.netchan.outgoing_sequence = cl.parsecount+1; cls.netchan.outgoing_sequence = cl.parsecount+1;
} }
/* */
int mvd_fixangle; int mvd_fixangle;
@ -2484,13 +2490,19 @@ static float MVD_AdjustAngle(float current, float ideal, float fraction) {
return current + fraction * move; return current + fraction * move;
} }
static void MVD_InitInterpolation(void) { extern float nextdemotime;
extern float olddemotime;
static void MVD_InitInterpolation(void)
{
player_state_t *state, *oldstate; player_state_t *state, *oldstate;
int i, tracknum; int i, tracknum;
frame_t *frame, *oldframe; frame_t *frame, *oldframe;
vec3_t dist; vec3_t dist;
struct predicted_player *pplayer; struct predicted_player *pplayer;
#define ISDEAD(i) ( (i) >= 41 && (i) <= 102 )
if (!cl.validsequence) if (!cl.validsequence)
return; return;
@ -2501,12 +2513,14 @@ static void MVD_InitInterpolation(void) {
oldframe = &cl.frames[(cl.parsecount-1) & UPDATE_MASK]; oldframe = &cl.frames[(cl.parsecount-1) & UPDATE_MASK];
// clients // clients
for (i = 0; i < MAX_CLIENTS; i++) { for (i = 0; i < MAX_CLIENTS; i++)
{
pplayer = &predicted_players[i]; pplayer = &predicted_players[i];
state = &frame->playerstate[i]; state = &frame->playerstate[i];
oldstate = &oldframe->playerstate[i]; oldstate = &oldframe->playerstate[i];
if (pplayer->predict) { if (pplayer->predict)
{
VectorCopy(pplayer->oldo, oldstate->origin); VectorCopy(pplayer->oldo, oldstate->origin);
VectorCopy(pplayer->olda, oldstate->command.angles); VectorCopy(pplayer->olda, oldstate->command.angles);
VectorCopy(pplayer->oldv, oldstate->velocity); VectorCopy(pplayer->oldv, oldstate->velocity);
@ -2514,11 +2528,14 @@ static void MVD_InitInterpolation(void) {
pplayer->predict = false; pplayer->predict = false;
tracknum = Cam_TrackNum(); tracknum = spec_track[0];
if ((mvd_fixangle & 1) << i) { if ((mvd_fixangle & 1) << i)
if (i == tracknum) { {
VectorCopy(cl.viewangles, state->command.angles); if (i == tracknum)
VectorCopy(cl.viewangles, state->viewangles); {
state->command.angles[0] = (state->viewangles[0] = cl.viewangles[0][0])*65535/360;
state->command.angles[1] = (state->viewangles[1] = cl.viewangles[0][1])*65535/360;
state->command.angles[2] = (state->viewangles[2] = cl.viewangles[0][2])*65535/360;
} }
// no angle interpolation // no angle interpolation
@ -2528,7 +2545,7 @@ static void MVD_InitInterpolation(void) {
} }
// we dont interpolate ourself if we are spectating // we dont interpolate ourself if we are spectating
if (i == cl.playernum && cl.spectator) if (i == cl.playernum[0] && cl.spectator)
continue; continue;
memset(state->velocity, 0, sizeof(state->velocity)); memset(state->velocity, 0, sizeof(state->velocity));
@ -2554,14 +2571,16 @@ static void MVD_InitInterpolation(void) {
pplayer->oldstate = oldstate; pplayer->oldstate = oldstate;
pplayer->predict = true; pplayer->predict = true;
} }
/*
// nails // nails
for (i = 0; i < cl_num_projectiles; i++) { for (i = 0; i < cl_num_projectiles; i++)
{
if (!cl.int_projectiles[i].interpolate) if (!cl.int_projectiles[i].interpolate)
continue; continue;
VectorCopy(cl.int_projectiles[i].origin, cl_projectiles[i].origin); VectorCopy(cl.int_projectiles[i].origin, cl_projectiles[i].origin);
} }
*/
} }
void MVD_Interpolate(void) void MVD_Interpolate(void)
@ -2574,8 +2593,8 @@ void MVD_Interpolate(void)
struct predicted_player *pplayer; struct predicted_player *pplayer;
static float old; static float old;
self = &cl.frames[cl.parsecount & UPDATE_MASK].playerstate[cl.playernum]; self = &cl.frames[cl.parsecount & UPDATE_MASK].playerstate[cl.playernum[0]];
oldself = &cl.frames[(cls.netchan.outgoing_sequence - 1) & UPDATE_MASK].playerstate[cl.playernum]; oldself = &cl.frames[(cls.netchan.outgoing_sequence - 1) & UPDATE_MASK].playerstate[cl.playernum[0]];
self->messagenum = cl.parsecount; self->messagenum = cl.parsecount;
@ -2583,7 +2602,8 @@ void MVD_Interpolate(void)
VectorCopy(oldself->velocity, self->velocity); VectorCopy(oldself->velocity, self->velocity);
VectorCopy(oldself->viewangles, self->viewangles); VectorCopy(oldself->viewangles, self->viewangles);
if (old != nextdemotime) { if (old != nextdemotime)
{
old = nextdemotime; old = nextdemotime;
MVD_InitInterpolation(); MVD_InitInterpolation();
} }
@ -2602,28 +2622,38 @@ void MVD_Interpolate(void)
oldframe = &cl.frames[cl.oldparsecount & UPDATE_MASK]; oldframe = &cl.frames[cl.oldparsecount & UPDATE_MASK];
oldents = oldframe->packet_entities.entities; oldents = oldframe->packet_entities.entities;
f = bound(0, (cls.demotime - olddemotime) / (nextdemotime - olddemotime), 1); f = (realtime - olddemotime) / (nextdemotime - olddemotime);
if (f < 0)
f = 0;
if (f > 1)
f = 1;
// interpolate nails // interpolate nails
for (i = 0; i < cl_num_projectiles; i++) { /* for (i = 0; i < cl_num_projectiles; i++)
{
if (!cl.int_projectiles[i].interpolate) if (!cl.int_projectiles[i].interpolate)
continue; continue;
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++)
{
cl_projectiles[i].origin[j] = cl_oldprojectiles[cl.int_projectiles[i].oldindex].origin[j] + cl_projectiles[i].origin[j] = cl_oldprojectiles[cl.int_projectiles[i].oldindex].origin[j] +
f * (cl.int_projectiles[i].origin[j] - cl_oldprojectiles[cl.int_projectiles[i].oldindex].origin[j]); f * (cl.int_projectiles[i].origin[j] - cl_oldprojectiles[cl.int_projectiles[i].oldindex].origin[j]);
} }
} }
*/
// interpolate clients // interpolate clients
for (i = 0; i < MAX_CLIENTS; i++) { for (i = 0; i < MAX_CLIENTS; i++)
{
pplayer = &predicted_players[i]; pplayer = &predicted_players[i];
state = &frame->playerstate[i]; state = &frame->playerstate[i];
oldstate = &oldframe->playerstate[i]; oldstate = &oldframe->playerstate[i];
if (pplayer->predict) { if (pplayer->predict)
for (j = 0; j < 3; j++) { {
state->viewangles[j] = MVD_AdjustAngle(oldstate->command.angles[j], pplayer->olda[j], f); for (j = 0; j < 3; j++)
{
state->viewangles[j] = MVD_AdjustAngle(oldstate->command.angles[j]/65535.0f*360, pplayer->olda[j]/65535.0f*360, f);
state->origin[j] = oldstate->origin[j] + f * (pplayer->oldo[j] - oldstate->origin[j]); state->origin[j] = oldstate->origin[j] + f * (pplayer->oldo[j] - oldstate->origin[j]);
state->velocity[j] = oldstate->velocity[j] + f * (pplayer->oldv[j] - oldstate->velocity[j]); state->velocity[j] = oldstate->velocity[j] + f * (pplayer->oldv[j] - oldstate->velocity[j]);
} }
@ -2631,9 +2661,9 @@ void MVD_Interpolate(void)
} }
} }
void CL_ClearPredict(void) { void CL_ClearPredict(void)
{
memset(predicted_players, 0, sizeof(predicted_players)); memset(predicted_players, 0, sizeof(predicted_players));
mvd_fixangle = 0; mvd_fixangle = 0;
} }
*/