2008-08-02 22:00:00 +02:00
|
|
|
|
//=======================================================================
|
|
|
|
|
// Copyright XashXT Group 2008 <20>
|
|
|
|
|
// cl_frame.c - client world snapshot
|
|
|
|
|
//=======================================================================
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-09 22:00:00 +02:00
|
|
|
|
#include "common.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=========================================================================
|
|
|
|
|
|
|
|
|
|
FRAME PARSING
|
|
|
|
|
|
|
|
|
|
=========================================================================
|
|
|
|
|
*/
|
2008-12-25 22:00:00 +01:00
|
|
|
|
void CL_UpdateEntityFields( edict_t *ent )
|
2008-06-30 22:00:00 +02:00
|
|
|
|
{
|
2009-01-03 22:00:00 +01:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
// always keep an actual
|
|
|
|
|
ent->serialnumber = ent->pvClientData->current.number;
|
|
|
|
|
|
2008-08-02 22:00:00 +02:00
|
|
|
|
// copy state to progs
|
2008-12-26 22:00:00 +01:00
|
|
|
|
ent->v.classname = cl.edict_classnames[ent->pvClientData->current.classname];
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.modelindex = ent->pvClientData->current.modelindex;
|
|
|
|
|
ent->v.weaponmodel = ent->pvClientData->current.weaponmodel;
|
|
|
|
|
ent->v.model = MAKE_STRING( cl.configstrings[CS_MODELS+ent->pvClientData->current.modelindex] );
|
|
|
|
|
ent->v.frame = ent->pvClientData->current.frame;
|
|
|
|
|
ent->v.sequence = ent->pvClientData->current.sequence;
|
|
|
|
|
ent->v.gaitsequence = ent->pvClientData->current.gaitsequence;
|
|
|
|
|
ent->v.body = ent->pvClientData->current.body;
|
|
|
|
|
ent->v.skin = ent->pvClientData->current.skin;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
VectorCopy( ent->pvClientData->current.rendercolor, ent->v.rendercolor );
|
|
|
|
|
VectorCopy( ent->pvClientData->current.velocity, ent->v.velocity );
|
2008-12-26 22:00:00 +01:00
|
|
|
|
VectorCopy( ent->pvClientData->current.origin, ent->v.origin );
|
|
|
|
|
VectorCopy( ent->pvClientData->current.angles, ent->v.angles );
|
2009-01-03 22:00:00 +01:00
|
|
|
|
VectorCopy( ent->pvClientData->prev.origin, ent->v.oldorigin );
|
|
|
|
|
VectorCopy( ent->pvClientData->prev.angles, ent->v.oldangles );
|
|
|
|
|
VectorCopy( ent->pvClientData->current.mins, ent->v.mins );
|
|
|
|
|
VectorCopy( ent->pvClientData->current.maxs, ent->v.maxs );
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.framerate = ent->pvClientData->current.framerate;
|
|
|
|
|
ent->v.colormap = ent->pvClientData->current.colormap;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
ent->v.rendermode = ent->pvClientData->current.rendermode;
|
|
|
|
|
ent->v.renderamt = ent->pvClientData->current.renderamt;
|
|
|
|
|
ent->v.renderfx = ent->pvClientData->current.renderfx;
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.scale = ent->pvClientData->current.scale;
|
2009-01-02 22:00:00 +01:00
|
|
|
|
ent->v.weapons = ent->pvClientData->current.weapons;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
ent->v.gravity = ent->pvClientData->current.gravity;
|
|
|
|
|
ent->v.health = ent->pvClientData->current.health;
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.solid = ent->pvClientData->current.solid;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
ent->v.movetype = ent->pvClientData->current.movetype;
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.flags = ent->pvClientData->current.flags;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
if( ent->v.scale == 0.0f ) ent->v.scale = 1.0f;
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < MAXSTUDIOBLENDS; i++ )
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.blending[i] = ent->pvClientData->current.blending[i];
|
2009-01-03 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAXSTUDIOCONTROLLERS; i++ )
|
2009-01-05 22:00:00 +01:00
|
|
|
|
ent->v.controller[i] = ent->pvClientData->current.controller[i];
|
2009-01-03 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
if( ent->pvClientData->current.aiment )
|
|
|
|
|
ent->v.aiment = EDICT_NUM( ent->pvClientData->current.aiment );
|
|
|
|
|
else ent->v.aiment = NULL;
|
|
|
|
|
|
|
|
|
|
ent->v.pContainingEntity = ent;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
CL_DeltaEntity
|
|
|
|
|
|
|
|
|
|
Parses deltas from the given base and adds the resulting entity
|
|
|
|
|
to the current frame
|
|
|
|
|
==================
|
|
|
|
|
*/
|
2008-07-15 22:00:00 +02:00
|
|
|
|
void CL_DeltaEntity( sizebuf_t *msg, frame_t *frame, int newnum, entity_state_t *old, bool unchanged )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *ent;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
entity_state_t *state;
|
|
|
|
|
|
2008-12-25 22:00:00 +01:00
|
|
|
|
ent = EDICT_NUM( newnum );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
state = &cl_parse_entities[cl.parse_entities & (MAX_PARSE_ENTITIES-1)];
|
2008-07-15 22:00:00 +02:00
|
|
|
|
|
2008-11-14 22:00:00 +01:00
|
|
|
|
if( unchanged ) *state = *old;
|
|
|
|
|
else MSG_ReadDeltaEntity( msg, old, state, newnum );
|
2008-07-15 22:00:00 +02:00
|
|
|
|
|
2009-01-14 22:00:00 +01:00
|
|
|
|
if( state->number == -1 ) return; // entity was delta removed
|
2008-07-15 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cl.parse_entities++;
|
|
|
|
|
frame->num_entities++;
|
|
|
|
|
|
|
|
|
|
// some data changes will force no lerping
|
2009-01-14 22:00:00 +01:00
|
|
|
|
if( state->ed_flags & ESF_NODELTA )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-12-26 22:00:00 +01:00
|
|
|
|
ent->pvClientData->serverframe = -99;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 22:00:00 +01:00
|
|
|
|
if( ent->pvClientData->serverframe != cl.frame.serverframe - 1 )
|
2008-06-30 22:00:00 +02:00
|
|
|
|
{
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// duplicate the current state so lerping doesn't hurt anything
|
2008-12-26 22:00:00 +01:00
|
|
|
|
ent->pvClientData->prev = *state;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // shuffle the last state to previous
|
2008-12-26 22:00:00 +01:00
|
|
|
|
ent->pvClientData->prev = ent->pvClientData->current;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 22:00:00 +01:00
|
|
|
|
ent->pvClientData->serverframe = cl.frame.serverframe;
|
|
|
|
|
ent->pvClientData->current = *state;
|
2008-08-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// update prvm fields
|
2008-12-25 22:00:00 +01:00
|
|
|
|
CL_UpdateEntityFields( ent );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
CL_ParsePacketEntities
|
|
|
|
|
|
|
|
|
|
An svc_packetentities has just been parsed, deal with the
|
|
|
|
|
rest of the data stream.
|
|
|
|
|
==================
|
|
|
|
|
*/
|
2008-05-20 22:00:00 +02:00
|
|
|
|
void CL_ParsePacketEntities( sizebuf_t *msg, frame_t *oldframe, frame_t *newframe )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-05-20 22:00:00 +02:00
|
|
|
|
int newnum;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
entity_state_t *oldstate;
|
2008-05-20 22:00:00 +02:00
|
|
|
|
int oldindex, oldnum;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
newframe->parse_entities = cl.parse_entities;
|
|
|
|
|
newframe->num_entities = 0;
|
|
|
|
|
|
|
|
|
|
// delta from the entities present in oldframe
|
|
|
|
|
oldindex = 0;
|
2008-07-15 22:00:00 +02:00
|
|
|
|
oldstate = NULL;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( !oldframe ) oldnum = MAX_ENTNUMBER;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldindex >= oldframe->num_entities )
|
|
|
|
|
{
|
|
|
|
|
oldnum = MAX_ENTNUMBER;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
|
|
|
|
|
oldnum = oldstate->number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
while( 1 )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-07-15 22:00:00 +02:00
|
|
|
|
// read the entity index number
|
|
|
|
|
newnum = MSG_ReadShort( msg );
|
2008-08-11 22:00:00 +02:00
|
|
|
|
if( !newnum ) break; // end of packet entities
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-15 22:00:00 +02:00
|
|
|
|
if( msg->readcount > msg->cursize )
|
|
|
|
|
Host_Error("CL_ParsePacketEntities: end of message[%d > %d]\n", msg->readcount, msg->cursize );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-01-04 22:00:00 +01:00
|
|
|
|
while( newnum >= clgame.numEntities ) CL_AllocEdict();
|
|
|
|
|
|
2008-07-15 22:00:00 +02:00
|
|
|
|
while( oldnum < newnum )
|
2007-09-10 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
// one or more entities from the old packet are unchanged
|
2008-07-15 22:00:00 +02:00
|
|
|
|
CL_DeltaEntity( msg, newframe, oldnum, oldstate, true );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
oldindex++;
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldindex >= oldframe->num_entities )
|
|
|
|
|
{
|
|
|
|
|
oldnum = MAX_ENTNUMBER;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
|
|
|
|
|
oldnum = oldstate->number;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldnum == newnum )
|
|
|
|
|
{
|
|
|
|
|
// delta from previous state
|
2008-07-15 22:00:00 +02:00
|
|
|
|
CL_DeltaEntity( msg, newframe, newnum, oldstate, false );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
oldindex++;
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldindex >= oldframe->num_entities )
|
|
|
|
|
{
|
|
|
|
|
oldnum = MAX_ENTNUMBER;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
|
|
|
|
|
oldnum = oldstate->number;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldnum > newnum )
|
2008-05-20 22:00:00 +02:00
|
|
|
|
{
|
2009-01-04 22:00:00 +01:00
|
|
|
|
// delta from baseline ?
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *ent = EDICT_NUM( newnum );
|
2009-01-04 22:00:00 +01:00
|
|
|
|
if( ent->free ) CL_InitEdict( ent ); // FIXME: get rid of this
|
2008-12-26 22:00:00 +01:00
|
|
|
|
CL_DeltaEntity( msg, newframe, newnum, &ent->pvClientData->baseline, false );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// any remaining entities in the old frame are copied over
|
2008-06-30 22:00:00 +02:00
|
|
|
|
while( oldnum != MAX_ENTNUMBER )
|
|
|
|
|
{
|
|
|
|
|
// one or more entities from the old packet are unchanged
|
2008-07-15 22:00:00 +02:00
|
|
|
|
CL_DeltaEntity( msg, newframe, oldnum, oldstate, true );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
oldindex++;
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldindex >= oldframe->num_entities )
|
|
|
|
|
{
|
|
|
|
|
oldnum = MAX_ENTNUMBER;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
|
|
|
|
|
oldnum = oldstate->number;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-04 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
for( ; EDICT_NUM( clgame.numEntities - 1 )->free; clgame.numEntities-- );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
CL_ParseFrame
|
|
|
|
|
================
|
|
|
|
|
*/
|
2008-05-20 22:00:00 +02:00
|
|
|
|
void CL_ParseFrame( sizebuf_t *msg )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-09-09 22:00:00 +02:00
|
|
|
|
int cmd, len, idx;
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *clent;
|
2008-08-02 22:00:00 +02:00
|
|
|
|
frame_t *old;
|
2008-07-12 22:00:00 +02:00
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
memset( &cl.frame, 0, sizeof(cl.frame));
|
2008-08-01 22:00:00 +02:00
|
|
|
|
cl.frame.serverframe = MSG_ReadLong( msg );
|
|
|
|
|
cl.frame.deltaframe = MSG_ReadLong( msg );
|
2008-07-31 22:00:00 +02:00
|
|
|
|
cl.frame.servertime = cl.frame.serverframe * Host_FrameTime();
|
2008-07-15 22:00:00 +02:00
|
|
|
|
cl.surpressCount = MSG_ReadByte( msg );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// If the frame is delta compressed from data that we
|
|
|
|
|
// no longer have available, we must suck up the rest of
|
|
|
|
|
// the frame, but not use it, then ask for a non-compressed
|
|
|
|
|
// message
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( cl.frame.deltaframe <= 0 )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
cl.frame.valid = true; // uncompressed frame
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cls.demowaiting = false; // we can start recording now
|
2008-06-30 22:00:00 +02:00
|
|
|
|
old = NULL;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
old = &cl.frames[cl.frame.deltaframe & UPDATE_MASK];
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( !old->valid )
|
2007-10-29 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
// should never happen
|
2008-06-30 22:00:00 +02:00
|
|
|
|
MsgDev( D_INFO, "delta from invalid frame (not supposed to happen!).\n" );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( old->serverframe != cl.frame.deltaframe )
|
2007-10-19 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
// The frame that the server did the delta from
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// is too old, so we can't reconstruct it properly.
|
2008-06-30 22:00:00 +02:00
|
|
|
|
MsgDev( D_INFO, "Delta frame too old.\n" );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
else if( cl.parse_entities - old->parse_entities > MAX_PARSE_ENTITIES - 128 )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
MsgDev( D_INFO, "delta parse_entities too old.\n" );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2007-10-19 22:00:00 +02:00
|
|
|
|
else cl.frame.valid = true; // valid delta parse
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clamp time
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( cl.time > cl.frame.servertime ) cl.time = cl.frame.servertime;
|
2008-07-31 22:00:00 +02:00
|
|
|
|
else if( cl.time < cl.frame.servertime - Host_FrameTime())
|
|
|
|
|
cl.time = cl.frame.servertime - Host_FrameTime();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// read areabits
|
2008-06-30 22:00:00 +02:00
|
|
|
|
len = MSG_ReadByte( msg );
|
|
|
|
|
MSG_ReadData( msg, &cl.frame.areabits, len );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-01-03 22:00:00 +01:00
|
|
|
|
// read clientindex
|
|
|
|
|
cmd = MSG_ReadByte( msg );
|
|
|
|
|
if( cmd != svc_playerinfo ) Host_Error( "CL_ParseFrame: not clientindex\n" );
|
|
|
|
|
idx = MSG_ReadByte( msg );
|
|
|
|
|
clent = EDICT_NUM( idx ); // get client
|
|
|
|
|
if(( idx - 1 ) != cl.playernum )
|
|
|
|
|
Host_Error("CL_ParseFrame: invalid playernum (%d should be %d)\n", idx-1, cl.playernum );
|
2008-09-09 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// read packet entities
|
2008-07-16 22:00:00 +02:00
|
|
|
|
cmd = MSG_ReadByte( msg );
|
|
|
|
|
if( cmd != svc_packetentities ) Host_Error("CL_ParseFrame: not packetentities[%d]\n", cmd );
|
2008-05-20 22:00:00 +02:00
|
|
|
|
CL_ParsePacketEntities( msg, old, &cl.frame );
|
2008-09-09 22:00:00 +02:00
|
|
|
|
|
2009-01-03 22:00:00 +01:00
|
|
|
|
// now we can reading delta player state
|
|
|
|
|
if( old ) cl.frame.ps = MSG_ParseDeltaPlayer( &old->ps, &clent->pvClientData->current );
|
|
|
|
|
else cl.frame.ps = MSG_ParseDeltaPlayer( NULL, &clent->pvClientData->current );
|
2008-09-09 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// save the frame off in the backup array for later delta comparisons
|
|
|
|
|
cl.frames[cl.frame.serverframe & UPDATE_MASK] = cl.frame;
|
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( cl.frame.valid )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( cls.state != ca_active )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
cls.state = ca_active;
|
|
|
|
|
cl.force_refdef = true;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
// getting a valid frame message ends the connection process
|
2008-07-31 22:00:00 +02:00
|
|
|
|
VectorCopy( cl.frame.ps.origin, cl.predicted_origin );
|
2008-07-10 22:00:00 +02:00
|
|
|
|
VectorCopy( cl.frame.ps.viewangles, cl.predicted_angles );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
CL_CheckPredictionError();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==========================================================================
|
|
|
|
|
|
|
|
|
|
INTERPOLATE BETWEEN FRAMES TO GET RENDERING PARMS
|
|
|
|
|
|
|
|
|
|
==========================================================================
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_AddPacketEntities
|
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-06-30 22:00:00 +02:00
|
|
|
|
void CL_AddPacketEntities( frame_t *frame )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
entity_state_t *s1;
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *ent;
|
2008-08-02 22:00:00 +02:00
|
|
|
|
int pnum;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
for( pnum = 0; pnum < frame->num_entities; pnum++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-08-02 22:00:00 +02:00
|
|
|
|
s1 = &cl_parse_entities[(frame->parse_entities + pnum)&(MAX_PARSE_ENTITIES-1)];
|
2008-12-25 22:00:00 +01:00
|
|
|
|
ent = EDICT_NUM( s1->number );
|
2009-01-03 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
re->AddRefEntity( ent, s1->ed_type, cl.refdef.lerpfrac );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==============
|
|
|
|
|
CL_AddViewWeapon
|
|
|
|
|
==============
|
|
|
|
|
*/
|
2008-08-02 22:00:00 +02:00
|
|
|
|
void CL_AddViewWeapon( entity_state_t *ps )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
// allow the gun to be completely removed
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( !cl_gun->value ) return;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// don't draw gun if in wide angle view
|
2008-08-02 22:00:00 +02:00
|
|
|
|
if( ps->fov > 135 ) return;
|
2009-01-03 22:00:00 +01:00
|
|
|
|
if( !ps->viewmodel ) return;
|
|
|
|
|
|
|
|
|
|
cl.viewent.serialnumber = -1;
|
|
|
|
|
cl.viewent.v.effects |= EF_MINLIGHT;
|
|
|
|
|
cl.viewent.v.modelindex = ps->viewmodel;
|
|
|
|
|
VectorCopy( cl.refdef.vieworg, cl.viewent.v.origin );
|
|
|
|
|
VectorCopy( cl.refdef.viewangles, cl.viewent.v.angles );
|
|
|
|
|
VectorCopy( cl.refdef.vieworg, cl.viewent.v.oldorigin );
|
|
|
|
|
VectorCopy( cl.refdef.viewangles, cl.viewent.v.oldangles );
|
|
|
|
|
re->AddRefEntity( &cl.viewent, ED_VIEWMODEL, cl.refdef.lerpfrac );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_CalcViewValues
|
|
|
|
|
|
|
|
|
|
Sets cl.refdef view values
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-06-30 22:00:00 +02:00
|
|
|
|
void CL_CalcViewValues( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2007-10-31 22:00:00 +01:00
|
|
|
|
int i;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
float lerp, backlerp;
|
|
|
|
|
frame_t *oldframe;
|
2008-07-30 22:00:00 +02:00
|
|
|
|
entity_state_t *ps, *ops;
|
2008-12-27 22:00:00 +01:00
|
|
|
|
edict_t *clent;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-03 22:00:00 +02:00
|
|
|
|
// clamp time
|
|
|
|
|
if( cl.time > cl.frame.servertime )
|
|
|
|
|
{
|
|
|
|
|
if( cl_showclamp->value )
|
|
|
|
|
Msg ("high clamp %i\n", cl.time - cl.frame.servertime);
|
|
|
|
|
cl.time = cl.frame.servertime;
|
2008-12-26 22:00:00 +01:00
|
|
|
|
cl.refdef.lerpfrac = 1.0f;
|
2008-07-03 22:00:00 +02:00
|
|
|
|
}
|
2008-07-31 22:00:00 +02:00
|
|
|
|
else if (cl.time < cl.frame.servertime - Host_FrameTime())
|
2008-07-03 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
if (cl_showclamp->value)
|
2008-07-31 22:00:00 +02:00
|
|
|
|
Msg( "low clamp %i\n", cl.frame.servertime - Host_FrameTime() - cl.time);
|
|
|
|
|
cl.time = cl.frame.servertime - Host_FrameTime();
|
2008-12-26 22:00:00 +01:00
|
|
|
|
cl.refdef.lerpfrac = 0.0f;
|
2008-07-03 22:00:00 +02:00
|
|
|
|
}
|
2008-12-26 22:00:00 +01:00
|
|
|
|
else cl.refdef.lerpfrac = 1.0 - (cl.frame.servertime - cl.time) * 0.01f;
|
2008-07-03 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// find the previous frame to interpolate from
|
2008-07-10 22:00:00 +02:00
|
|
|
|
ps = &cl.frame.ps;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
i = (cl.frame.serverframe - 1) & UPDATE_MASK;
|
|
|
|
|
oldframe = &cl.frames[i];
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( oldframe->serverframe != cl.frame.serverframe-1 || !oldframe->valid )
|
2007-10-31 22:00:00 +01:00
|
|
|
|
oldframe = &cl.frame; // previous frame was dropped or invalid
|
2008-07-10 22:00:00 +02:00
|
|
|
|
ops = &oldframe->ps;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-01-05 22:00:00 +01:00
|
|
|
|
clent = EDICT_NUM( cl.playernum + 1 );
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// see if the player entity was teleported this frame
|
2009-01-14 22:00:00 +01:00
|
|
|
|
if( ps->ed_flags & ESF_NO_PREDICTION )
|
2007-10-31 22:00:00 +01:00
|
|
|
|
ops = ps; // don't interpolate
|
2008-12-26 22:00:00 +01:00
|
|
|
|
lerp = cl.refdef.lerpfrac;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// calculate the origin
|
2009-01-05 22:00:00 +01:00
|
|
|
|
if( cl_predict->integer && !cls.demoplayback )
|
2007-10-31 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
// use predicted values
|
2009-01-05 22:00:00 +01:00
|
|
|
|
int delta;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
backlerp = 1.0 - lerp;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
for( i = 0; i < 3; i++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
cl.refdef.vieworg[i] = cl.predicted_origin[i] + ops->viewoffset[i]
|
2008-12-26 22:00:00 +01:00
|
|
|
|
+ cl.refdef.lerpfrac * (ps->viewoffset[i] - ops->viewoffset[i]) - backlerp * cl.prediction_error[i];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// smooth out stair climbing
|
|
|
|
|
delta = cls.realtime - cl.predicted_step_time;
|
2008-07-31 22:00:00 +02:00
|
|
|
|
if( delta < Host_FrameTime()) cl.refdef.vieworg[2] -= cl.predicted_step * (Host_FrameTime() - delta) * 0.01f;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2008-07-04 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
// just use interpolated values
|
2008-06-30 22:00:00 +02:00
|
|
|
|
for( i = 0; i < 3; i++ )
|
2008-07-31 22:00:00 +02:00
|
|
|
|
cl.refdef.vieworg[i] = LerpView( ops->origin[i], ps->origin[i], ops->viewoffset[i], ps->viewoffset[i], lerp );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if not running a demo or on a locked frame, add the local angle movement
|
2008-05-20 22:00:00 +02:00
|
|
|
|
if( cls.demoplayback )
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2008-06-30 22:00:00 +02:00
|
|
|
|
cl.refdef.viewangles[i] = LerpAngle( ops->viewangles[i], ps->viewangles[i], lerp );
|
2008-05-20 22:00:00 +02:00
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
else
|
2007-10-31 22:00:00 +01:00
|
|
|
|
{
|
2008-05-20 22:00:00 +02:00
|
|
|
|
// in-game use predicted values
|
2007-10-31 22:00:00 +01:00
|
|
|
|
for (i = 0; i < 3; i++) cl.refdef.viewangles[i] = cl.predicted_angles[i];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-20 22:00:00 +02:00
|
|
|
|
for( i = 0; i < 3; i++ )
|
2008-07-30 22:00:00 +02:00
|
|
|
|
cl.refdef.viewangles[i] += LerpAngle( ops->punch_angles[i], ps->punch_angles[i], lerp );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-12-26 22:00:00 +01:00
|
|
|
|
AngleVectors( cl.refdef.viewangles, cl.refdef.forward, cl.refdef.right, cl.refdef.up );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// interpolate field of view
|
2009-01-05 22:00:00 +01:00
|
|
|
|
cl.data.fov = ops->fov + lerp * ( ps->fov - ops->fov );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// add the weapon
|
2008-08-02 22:00:00 +02:00
|
|
|
|
CL_AddViewWeapon( ps );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_AddEntities
|
|
|
|
|
|
|
|
|
|
Emits all entities, particles, and lights to the refresh
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-06-30 22:00:00 +02:00
|
|
|
|
void CL_AddEntities( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( cls.state != ca_active )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2008-05-20 22:00:00 +02:00
|
|
|
|
CL_CalcViewValues();
|
2008-06-30 22:00:00 +02:00
|
|
|
|
CL_AddPacketEntities( &cl.frame );
|
|
|
|
|
CL_AddParticles();
|
|
|
|
|
CL_AddDLights();
|
|
|
|
|
CL_AddLightStyles();
|
2008-11-27 22:00:00 +01:00
|
|
|
|
CL_AddDecals();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// sound engine implementation
|
|
|
|
|
//
|
|
|
|
|
|
2008-07-01 22:00:00 +02:00
|
|
|
|
void CL_GetEntitySoundSpatialization( int entnum, vec3_t origin, vec3_t velocity )
|
2008-06-12 22:00:00 +02:00
|
|
|
|
{
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *ent;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
cmodel_t *cmodel;
|
|
|
|
|
vec3_t midPoint;
|
|
|
|
|
|
2008-07-17 22:00:00 +02:00
|
|
|
|
if( entnum < 0 || entnum >= host.max_edicts )
|
2008-06-12 22:00:00 +02:00
|
|
|
|
{
|
2008-07-01 22:00:00 +02:00
|
|
|
|
MsgDev( D_ERROR, "CL_GetEntitySoundSpatialization: invalid entnum %d\n", entnum );
|
2008-06-12 22:00:00 +02:00
|
|
|
|
VectorCopy( vec3_origin, origin );
|
|
|
|
|
VectorCopy( vec3_origin, velocity );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-25 22:00:00 +01:00
|
|
|
|
ent = EDICT_NUM( entnum );
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
// calculate origin
|
2008-12-26 22:00:00 +01:00
|
|
|
|
origin[0] = ent->pvClientData->prev.origin[0] + (ent->pvClientData->current.origin[0] - ent->pvClientData->prev.origin[0]) * cl.refdef.lerpfrac;
|
|
|
|
|
origin[1] = ent->pvClientData->prev.origin[1] + (ent->pvClientData->current.origin[1] - ent->pvClientData->prev.origin[1]) * cl.refdef.lerpfrac;
|
|
|
|
|
origin[2] = ent->pvClientData->prev.origin[2] + (ent->pvClientData->current.origin[2] - ent->pvClientData->prev.origin[2]) * cl.refdef.lerpfrac;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
// calculate velocity
|
2008-12-26 22:00:00 +01:00
|
|
|
|
VectorSubtract( ent->pvClientData->current.origin, ent->pvClientData->prev.origin, velocity);
|
2008-06-30 22:00:00 +02:00
|
|
|
|
VectorScale(velocity, 10, velocity);
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// if a brush model, offset the origin
|
2008-06-14 22:00:00 +02:00
|
|
|
|
if( VectorIsNull( origin ))
|
2008-06-12 22:00:00 +02:00
|
|
|
|
{
|
2009-01-05 22:00:00 +01:00
|
|
|
|
cmodel = cl.models[ent->pvClientData->current.modelindex];
|
2008-11-15 22:00:00 +01:00
|
|
|
|
if( !cmodel ) return;
|
2008-07-16 22:00:00 +02:00
|
|
|
|
VectorAverage( cmodel->mins, cmodel->maxs, midPoint );
|
|
|
|
|
VectorAdd( origin, midPoint, origin );
|
2008-06-12 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
S_AddLoopingSounds
|
|
|
|
|
|
|
|
|
|
Entities with a sound field will generate looping sounds that are
|
|
|
|
|
automatically started and stopped as the entities are sent to the
|
|
|
|
|
client
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void CL_AddLoopingSounds( void )
|
|
|
|
|
{
|
|
|
|
|
entity_state_t *ent;
|
|
|
|
|
int num, i;
|
|
|
|
|
|
|
|
|
|
if( cls.state != ca_active ) return;
|
2008-06-21 22:00:00 +02:00
|
|
|
|
if( cl_paused->integer ) return;
|
2008-08-03 22:00:00 +02:00
|
|
|
|
if( !cl.audio_prepped ) return;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
for( i = 0; i < cl.frame.num_entities; i++ )
|
|
|
|
|
{
|
|
|
|
|
num = (cl.frame.parse_entities + i)&(MAX_PARSE_ENTITIES-1);
|
|
|
|
|
ent = &cl_parse_entities[num];
|
2008-11-15 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
switch( ent->ed_type )
|
|
|
|
|
{
|
|
|
|
|
case ED_MOVER:
|
|
|
|
|
case ED_AMBIENT:
|
|
|
|
|
case ED_NORMAL: break;
|
|
|
|
|
default: continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !ent->soundindex ) continue;
|
2008-12-03 22:00:00 +01:00
|
|
|
|
S_AddLoopingSound( ent->number, cl.sound_precache[ent->soundindex], 1.0f, ATTN_IDLE );
|
2008-06-12 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|