This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/cl_pmove.c

744 lines
21 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
cl_pmove.c - client-side player physic
Copyright (C) 2010 Uncle Mike
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 3 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.
*/
2010-08-12 22:00:00 +02:00
#include "common.h"
#include "client.h"
#include "const.h"
2010-11-15 22:00:00 +01:00
#include "cl_tent.h"
2010-08-16 22:00:00 +02:00
#include "pm_local.h"
2011-02-20 22:00:00 +01:00
#include "particledef.h"
2010-08-12 22:00:00 +02:00
void CL_ClearPhysEnts( void )
{
clgame.pmove->numtouch = 0;
clgame.pmove->numvisent = 0;
clgame.pmove->nummoveent = 0;
clgame.pmove->numphysent = 0;
}
2010-10-26 22:00:00 +02:00
qboolean CL_CopyEntityToPhysEnt( physent_t *pe, cl_entity_t *ent )
2010-08-16 22:00:00 +02:00
{
2011-02-20 22:00:00 +01:00
model_t *mod = Mod_Handle( ent->curstate.modelindex );
2010-08-16 22:00:00 +02:00
2011-03-24 22:00:00 +01:00
if( !mod ) return false;
2010-08-19 22:00:00 +02:00
pe->player = ent->player;
2010-08-16 22:00:00 +02:00
2010-08-19 22:00:00 +02:00
if( pe->player )
2010-08-16 22:00:00 +02:00
{
// client or bot
2011-03-09 22:00:00 +01:00
Q_strncpy( pe->name, "player", sizeof( pe->name ));
2010-08-16 22:00:00 +02:00
}
else
{
// otherwise copy the modelname
2011-03-09 22:00:00 +01:00
Q_strncpy( pe->name, mod->name, sizeof( pe->name ));
2010-08-16 22:00:00 +02:00
}
2010-08-30 22:00:00 +02:00
if( mod->type == mod_studio )
2010-08-16 22:00:00 +02:00
{
pe->studiomodel = mod;
pe->model = NULL;
}
2010-08-30 22:00:00 +02:00
else
2011-01-08 22:00:00 +01:00
{
2010-08-16 22:00:00 +02:00
pe->studiomodel = NULL;
pe->model = mod;
}
2011-04-06 22:00:00 +02:00
pe->info = (int)(ent - clgame.entities);
2010-08-16 22:00:00 +02:00
VectorCopy( ent->curstate.origin, pe->origin );
VectorCopy( ent->curstate.angles, pe->angles );
VectorCopy( ent->curstate.mins, pe->mins );
VectorCopy( ent->curstate.maxs, pe->maxs );
pe->solid = ent->curstate.solid;
pe->rendermode = ent->curstate.rendermode;
pe->skin = ent->curstate.skin;
pe->frame = ent->curstate.frame;
pe->sequence = ent->curstate.sequence;
2011-03-10 22:00:00 +01:00
Q_memcpy( &pe->controller[0], &ent->curstate.controller[0], 4 * sizeof( byte ));
Q_memcpy( &pe->blending[0], &ent->curstate.blending[0], 2 * sizeof( byte ));
2010-08-16 22:00:00 +02:00
pe->movetype = ent->curstate.movetype;
2011-02-20 22:00:00 +01:00
pe->takedamage = ( pe->player ) ? DAMAGE_AIM : DAMAGE_YES;
2010-08-16 22:00:00 +02:00
pe->team = ent->curstate.team;
pe->classnumber = ent->curstate.playerclass;
2011-02-20 22:00:00 +01:00
pe->blooddecal = 0; // unused in GoldSrc
2010-08-16 22:00:00 +02:00
// for mods
pe->iuser1 = ent->curstate.iuser1;
pe->iuser2 = ent->curstate.iuser2;
pe->iuser3 = ent->curstate.iuser3;
pe->iuser4 = ent->curstate.iuser4;
2011-02-15 22:00:00 +01:00
pe->fuser1 = (clgame.movevars.studio_scale) ? ent->curstate.scale : ent->curstate.fuser1;
2010-08-16 22:00:00 +02:00
pe->fuser2 = ent->curstate.fuser2;
pe->fuser3 = ent->curstate.fuser3;
pe->fuser4 = ent->curstate.fuser4;
VectorCopy( ent->curstate.vuser1, pe->vuser1 );
VectorCopy( ent->curstate.vuser2, pe->vuser2 );
VectorCopy( ent->curstate.vuser3, pe->vuser3 );
VectorCopy( ent->curstate.vuser4, pe->vuser4 );
return true;
}
2010-08-19 22:00:00 +02:00
/*
====================
CL_AddLinksToPmove
collect solid entities
====================
*/
2010-11-15 22:00:00 +01:00
void CL_AddLinksToPmove( void )
2010-08-19 22:00:00 +02:00
{
cl_entity_t *check;
physent_t *pe;
2011-04-09 22:00:00 +02:00
int i, solid, idx;
2010-08-19 22:00:00 +02:00
2010-11-15 22:00:00 +01:00
for( i = 0; i < cl.frame.num_entities; i++ )
2010-08-19 22:00:00 +02:00
{
2010-11-15 22:00:00 +01:00
idx = cls.packet_entities[(cl.frame.first_entity + i) % cls.num_client_entities].number;
check = CL_GetEntityByIndex( idx );
2010-08-19 22:00:00 +02:00
// don't add the world and clients here
2011-02-20 22:00:00 +01:00
if( !check || check == &clgame.entities[0] )
continue;
if( clgame.pmove->numvisent < MAX_PHYSENTS )
{
pe = &clgame.pmove->visents[clgame.pmove->numvisent];
if( CL_CopyEntityToPhysEnt( pe, check ))
clgame.pmove->numvisent++;
}
2011-04-09 22:00:00 +02:00
// players will be added later
if( check->player ) continue;
2010-08-19 22:00:00 +02:00
2010-12-21 22:00:00 +01:00
// can't collide with zeroed hull
if( VectorIsNull( check->curstate.mins ) && VectorIsNull( check->curstate.maxs ))
continue;
2011-04-09 22:00:00 +02:00
solid = check->curstate.solid;
if( solid == SOLID_BSP || solid == SOLID_BBOX || solid == SOLID_SLIDEBOX )
2010-08-19 22:00:00 +02:00
{
2011-02-20 22:00:00 +01:00
// reserve slots for all the clients
if( clgame.pmove->numphysent < ( MAX_PHYSENTS - cl.maxclients ))
{
pe = &clgame.pmove->physents[clgame.pmove->numphysent];
if( CL_CopyEntityToPhysEnt( pe, check ))
clgame.pmove->numphysent++;
}
2010-08-19 22:00:00 +02:00
}
2011-04-09 22:00:00 +02:00
else if( solid == SOLID_NOT && check->curstate.skin != CONTENTS_NONE )
2010-11-15 22:00:00 +01:00
{
2011-02-20 22:00:00 +01:00
if( clgame.pmove->nummoveent < MAX_MOVEENTS )
{
pe = &clgame.pmove->moveents[clgame.pmove->nummoveent];
if( CL_CopyEntityToPhysEnt( pe, check ))
clgame.pmove->nummoveent++;
}
2010-11-15 22:00:00 +01:00
}
2010-08-19 22:00:00 +02:00
}
}
/*
===============
CL_SetSolid
Builds all the pmove physents for the current frame
Note that CL_SetUpPlayerPrediction() must be called first!
pmove must be setup with world and solid entity hulls before calling
(via CL_PredictMove)
===============
*/
void CL_SetSolidPlayers( int playernum )
{
int j;
extern vec3_t player_mins;
extern vec3_t player_maxs;
cl_entity_t *ent;
physent_t *pe;
if( !cl_solid_players->integer )
return;
2010-08-20 22:00:00 +02:00
for( j = 0; j < cl.maxclients; j++ )
2010-08-19 22:00:00 +02:00
{
// the player object never gets added
if( j == playernum ) continue;
ent = CL_GetEntityByIndex( j + 1 );
if( !ent || !ent->player )
continue; // not present this frame
pe = &clgame.pmove->physents[clgame.pmove->numphysent];
if( CL_CopyEntityToPhysEnt( pe, ent ))
clgame.pmove->numphysent++;
}
}
2011-02-20 22:00:00 +01:00
/*
=============
CL_TruePointContents
=============
*/
2010-11-15 22:00:00 +01:00
int CL_TruePointContents( const vec3_t p )
{
int i, contents;
2011-04-05 22:00:00 +02:00
int oldhull;
2010-11-15 22:00:00 +01:00
hull_t *hull;
vec3_t test;
physent_t *pe;
// sanity check
if( !p ) return CONTENTS_NONE;
2011-04-05 22:00:00 +02:00
oldhull = clgame.pmove->usehull;
2010-11-15 22:00:00 +01:00
// get base contents from world
contents = PM_HullPointContents( &cl.worldmodel->hulls[0], 0, p );
for( i = 0; i < clgame.pmove->nummoveent; i++ )
{
pe = &clgame.pmove->moveents[i];
if( pe->solid != SOLID_NOT ) // disabled ?
continue;
// only brushes can have special contents
2011-01-31 22:00:00 +01:00
if( !pe->model || pe->model->type != mod_brush )
2010-11-15 22:00:00 +01:00
continue;
// check water brushes accuracy
2011-04-05 22:00:00 +02:00
clgame.pmove->usehull = 2;
hull = PM_HullForBsp( pe, clgame.pmove, test );
clgame.pmove->usehull = oldhull;
2010-11-15 22:00:00 +01:00
// offset the test point appropriately for this hull.
VectorSubtract( p, test, test );
// test hull for intersection with this model
if( PM_HullPointContents( hull, hull->firstclipnode, test ) == CONTENTS_EMPTY )
continue;
2011-01-09 22:00:00 +01:00
// compare contents ranking
if( RankForContents( pe->skin ) > RankForContents( contents ))
contents = pe->skin; // new content has more priority
2010-11-15 22:00:00 +01:00
}
return contents;
}
2011-02-15 22:00:00 +01:00
/*
=============
CL_WaterEntity
=============
*/
int CL_WaterEntity( const float *rgflPos )
{
physent_t *pe;
hull_t *hull;
vec3_t test;
2011-04-05 22:00:00 +02:00
int i, oldhull;
2011-02-15 22:00:00 +01:00
if( !rgflPos ) return -1;
2011-04-05 22:00:00 +02:00
oldhull = clgame.pmove->usehull;
2011-02-15 22:00:00 +01:00
for( i = 0; i < clgame.pmove->nummoveent; i++ )
{
pe = &clgame.pmove->moveents[i];
if( pe->solid != SOLID_NOT ) // disabled ?
continue;
// only brushes can have special contents
if( !pe->model || pe->model->type != mod_brush )
continue;
// check water brushes accuracy
2011-04-05 22:00:00 +02:00
clgame.pmove->usehull = 2;
hull = PM_HullForBsp( pe, clgame.pmove, test );
clgame.pmove->usehull = oldhull;
2011-02-15 22:00:00 +01:00
// offset the test point appropriately for this hull.
VectorSubtract( rgflPos, test, test );
// test hull for intersection with this model
if( PM_HullPointContents( hull, hull->firstclipnode, test ) == CONTENTS_EMPTY )
continue;
// found water entity
return pe->info;
}
return -1;
}
/*
=============
2011-09-03 22:00:00 +02:00
CL_GetWaterEntity
2011-02-15 22:00:00 +01:00
returns water brush where inside pos
=============
*/
2011-09-03 22:00:00 +02:00
cl_entity_t *CL_GetWaterEntity( const float *rgflPos )
2011-02-15 22:00:00 +01:00
{
2011-09-03 22:00:00 +02:00
int entnum;
2011-02-15 22:00:00 +01:00
entnum = CL_WaterEntity( rgflPos );
if( entnum <= 0 ) return NULL; // world or not water
2011-09-03 22:00:00 +02:00
return CL_GetEntityByIndex( entnum );
2011-02-15 22:00:00 +01:00
}
2010-08-16 22:00:00 +02:00
static void pfnParticle( float *origin, int color, float life, int zpos, int zvel )
{
2011-02-20 22:00:00 +01:00
particle_t *p;
2010-08-16 22:00:00 +02:00
if( !origin )
{
MsgDev( D_ERROR, "CL_StartParticle: NULL origin. Ignored\n" );
return;
}
2011-02-20 22:00:00 +01:00
p = CL_AllocParticle( NULL );
if( !p ) return;
p->die += life;
p->color = color;
p->type = pt_static;
2010-08-16 22:00:00 +02:00
2011-02-20 22:00:00 +01:00
VectorCopy( origin, p->org );
VectorSet( p->vel, 0.0f, 0.0f, ( zpos * zvel ));
2010-08-16 22:00:00 +02:00
}
static int pfnTestPlayerPosition( float *pos, pmtrace_t *ptrace )
{
pmtrace_t trace;
2010-08-22 22:00:00 +02:00
trace = PM_PlayerTrace( clgame.pmove, pos, pos, PM_NORMAL, clgame.pmove->usehull, -1, NULL );
2010-08-16 22:00:00 +02:00
if( ptrace ) *ptrace = trace;
2011-04-05 22:00:00 +02:00
return PM_TestPlayerPosition( clgame.pmove, pos, NULL );
2010-08-16 22:00:00 +02:00
}
2011-02-20 22:00:00 +01:00
static void pfnStuckTouch( int hitent, pmtrace_t *tr )
2010-08-16 22:00:00 +02:00
{
2011-02-20 22:00:00 +01:00
physent_t *pe;
float *mins, *maxs;
int i;
ASSERT( hitent >= 0 && hitent < clgame.pmove->numphysent );
pe = &clgame.pmove->physents[hitent];
mins = clgame.pmove->player_mins[clgame.pmove->usehull];
maxs = clgame.pmove->player_maxs[clgame.pmove->usehull];
2011-04-08 22:00:00 +02:00
if( !PM_TraceModel( clgame.pmove, pe, clgame.pmove->origin, mins, maxs, clgame.pmove->origin, tr, 0 ))
2011-02-20 22:00:00 +01:00
return; // not stuck
tr->ent = hitent;
for( i = 0; i < clgame.pmove->numtouch; i++ )
{
if( clgame.pmove->touchindex[i].ent == tr->ent )
break;
}
if( i != clgame.pmove->numtouch ) return;
VectorCopy( clgame.pmove->velocity, tr->deltavelocity );
if( clgame.pmove->numtouch >= MAX_PHYSENTS )
{
MsgDev( D_ERROR, "PM_StuckTouch: MAX_TOUCHENTS limit exceeded\n" );
return;
}
clgame.pmove->touchindex[clgame.pmove->numtouch++] = *tr;
2010-08-16 22:00:00 +02:00
}
static int pfnPointContents( float *p, int *truecontents )
{
int cont, truecont;
truecont = cont = CL_TruePointContents( p );
if( truecontents ) *truecontents = truecont;
if( cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN )
cont = CONTENTS_WATER;
return cont;
}
static int pfnTruePointContents( float *p )
{
return CL_TruePointContents( p );
}
static int pfnHullPointContents( struct hull_s *hull, int num, float *p )
{
return PM_HullPointContents( hull, num, p );
}
static pmtrace_t pfnPlayerTrace( float *start, float *end, int traceFlags, int ignore_pe )
{
return PM_PlayerTrace( clgame.pmove, start, end, traceFlags, clgame.pmove->usehull, ignore_pe, NULL );
}
static pmtrace_t *pfnTraceLine( float *start, float *end, int flags, int usehull, int ignore_pe )
{
static pmtrace_t tr;
tr = PM_PlayerTrace( clgame.pmove, start, end, flags, usehull, ignore_pe, NULL );
return &tr;
}
static hull_t *pfnHullForBsp( physent_t *pe, float *offset )
{
2011-04-05 22:00:00 +02:00
return PM_HullForBsp( pe, clgame.pmove, offset );
2010-08-16 22:00:00 +02:00
}
2010-11-15 22:00:00 +01:00
static float pfnTraceModel( physent_t *pEnt, float *start, float *end, trace_t *trace )
2010-08-16 22:00:00 +02:00
{
2010-11-15 22:00:00 +01:00
pmtrace_t pmtrace;
2011-04-08 22:00:00 +02:00
PM_TraceModel( clgame.pmove, pEnt, start, vec3_origin, vec3_origin, end, &pmtrace, PM_STUDIO_BOX );
2010-11-15 22:00:00 +01:00
// copy pmtrace_t to trace_t
if( trace )
{
// NOTE: if pmtrace.h is changed is must be changed too
2011-03-10 22:00:00 +01:00
Q_memcpy( trace, &pmtrace, sizeof( *trace ));
2010-11-15 22:00:00 +01:00
trace->hitgroup = pmtrace.hitgroup;
trace->ent = NULL;
}
return pmtrace.fraction;
2010-08-16 22:00:00 +02:00
}
static const char *pfnTraceTexture( int ground, float *vstart, float *vend )
{
physent_t *pe;
if( ground < 0 || ground >= clgame.pmove->numphysent )
return NULL; // bad ground
pe = &clgame.pmove->physents[ground];
return PM_TraceTexture( pe, vstart, vend );
}
static void pfnPlaySound( int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch )
{
sound_t snd = S_RegisterSound( sample );
S_StartSound( NULL, clgame.pmove->player_index + 1, channel, snd, volume, attenuation, pitch, fFlags );
}
static void pfnPlaybackEventFull( int flags, int clientindex, word eventindex, float delay, float *origin,
float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 )
{
cl_entity_t *ent;
ent = CL_GetEntityByIndex( clientindex + 1 );
if( ent == NULL ) return;
2010-10-26 22:00:00 +02:00
CL_PlaybackEvent( flags, (edict_t *)ent, eventindex,
2010-08-16 22:00:00 +02:00
delay, origin, angles,
fparam1, fparam2,
iparam1, iparam2,
bparam1, bparam2 );
}
static pmtrace_t pfnPlayerTraceEx( float *start, float *end, int traceFlags, pfnIgnore pmFilter )
{
return PM_PlayerTrace( clgame.pmove, start, end, traceFlags, clgame.pmove->usehull, -1, pmFilter );
}
static int pfnTestPlayerPositionEx( float *pos, pmtrace_t *ptrace, pfnIgnore pmFilter )
{
pmtrace_t trace;
trace = PM_PlayerTrace( clgame.pmove, pos, pos, PM_STUDIO_BOX, clgame.pmove->usehull, -1, pmFilter );
if( ptrace ) *ptrace = trace;
2011-04-05 22:00:00 +02:00
return PM_TestPlayerPosition( clgame.pmove, pos, pmFilter );
2010-08-16 22:00:00 +02:00
}
static pmtrace_t *pfnTraceLineEx( float *start, float *end, int flags, int usehull, pfnIgnore pmFilter )
{
static pmtrace_t tr;
tr = PM_PlayerTrace( clgame.pmove, start, end, flags, usehull, -1, pmFilter );
return &tr;
}
2010-08-12 22:00:00 +02:00
/*
===============
CL_InitClientMove
===============
*/
void CL_InitClientMove( void )
{
int i;
2010-10-07 22:00:00 +02:00
Pmove_Init ();
2010-08-12 22:00:00 +02:00
clgame.pmove->server = false; // running at client
clgame.pmove->movevars = &clgame.movevars;
clgame.pmove->runfuncs = false;
2010-12-08 22:00:00 +01:00
Mod_SetupHulls( clgame.player_mins, clgame.player_maxs );
2010-10-20 22:00:00 +02:00
2010-08-12 22:00:00 +02:00
// enumerate client hulls
2010-08-15 22:00:00 +02:00
for( i = 0; i < 4; i++ )
2011-03-23 22:00:00 +01:00
{
if( clgame.dllFuncs.pfnGetHullBounds( i, clgame.player_mins[i], clgame.player_maxs[i] ))
2011-03-24 22:00:00 +01:00
MsgDev( D_NOTE, "CL: hull%i, player_mins: %g %g %g, player_maxs: %g %g %g\n", i,
2011-03-23 22:00:00 +01:00
clgame.player_mins[i][0], clgame.player_mins[i][1], clgame.player_mins[i][2],
clgame.player_maxs[i][0], clgame.player_maxs[i][1], clgame.player_maxs[i][2] );
}
2010-08-16 22:00:00 +02:00
2011-03-10 22:00:00 +01:00
Q_memcpy( clgame.pmove->player_mins, clgame.player_mins, sizeof( clgame.player_mins ));
Q_memcpy( clgame.pmove->player_maxs, clgame.player_maxs, sizeof( clgame.player_maxs ));
2010-08-12 22:00:00 +02:00
// common utilities
clgame.pmove->PM_Info_ValueForKey = Info_ValueForKey;
2010-08-16 22:00:00 +02:00
clgame.pmove->PM_Particle = pfnParticle;
clgame.pmove->PM_TestPlayerPosition = pfnTestPlayerPosition;
2010-10-20 22:00:00 +02:00
clgame.pmove->Con_NPrintf = Con_NPrintf;
clgame.pmove->Con_DPrintf = Con_DPrintf;
clgame.pmove->Con_Printf = Con_Printf;
2011-04-05 22:00:00 +02:00
clgame.pmove->Sys_FloatTime = Sys_DoubleTime;
2010-08-16 22:00:00 +02:00
clgame.pmove->PM_StuckTouch = pfnStuckTouch;
clgame.pmove->PM_PointContents = pfnPointContents;
clgame.pmove->PM_TruePointContents = pfnTruePointContents;
clgame.pmove->PM_HullPointContents = pfnHullPointContents;
clgame.pmove->PM_PlayerTrace = pfnPlayerTrace;
clgame.pmove->PM_TraceLine = pfnTraceLine;
2011-02-28 22:00:00 +01:00
clgame.pmove->RandomLong = Com_RandomLong;
clgame.pmove->RandomFloat = Com_RandomFloat;
2010-08-16 22:00:00 +02:00
clgame.pmove->PM_GetModelType = pfnGetModelType;
clgame.pmove->PM_GetModelBounds = pfnGetModelBounds;
clgame.pmove->PM_HullForBsp = pfnHullForBsp;
clgame.pmove->PM_TraceModel = pfnTraceModel;
2011-04-05 22:00:00 +02:00
clgame.pmove->COM_FileSize = COM_FileSize;
clgame.pmove->COM_LoadFile = COM_LoadFile;
clgame.pmove->COM_FreeFile = COM_FreeFile;
2011-04-06 22:00:00 +02:00
clgame.pmove->memfgets = COM_MemFgets;
2010-08-16 22:00:00 +02:00
clgame.pmove->PM_PlaySound = pfnPlaySound;
clgame.pmove->PM_TraceTexture = pfnTraceTexture;
clgame.pmove->PM_PlaybackEventFull = pfnPlaybackEventFull;
clgame.pmove->PM_PlayerTraceEx = pfnPlayerTraceEx;
clgame.pmove->PM_TestPlayerPositionEx = pfnTestPlayerPositionEx;
clgame.pmove->PM_TraceLineEx = pfnTraceLineEx;
2010-08-12 22:00:00 +02:00
// initalize pmove
2010-11-15 22:00:00 +01:00
clgame.dllFuncs.pfnPlayerMoveInit( clgame.pmove );
2010-08-19 22:00:00 +02:00
}
static void PM_CheckMovingGround( clientdata_t *cd, entity_state_t *state, float frametime )
{
if(!( cd->flags & FL_BASEVELOCITY ))
{
// apply momentum (add in half of the previous frame of velocity first)
VectorMA( cd->velocity, 1.0f + (frametime * 0.5f), state->basevelocity, cd->velocity );
VectorClear( state->basevelocity );
}
cd->flags &= ~FL_BASEVELOCITY;
}
void CL_SetSolidEntities( void )
{
// world not initialized
2011-08-14 22:00:00 +02:00
if( !clgame.entities )
2011-04-18 22:00:00 +02:00
return;
2010-08-19 22:00:00 +02:00
// setup physents
2011-02-20 22:00:00 +01:00
clgame.pmove->numvisent = 0;
2010-08-19 22:00:00 +02:00
clgame.pmove->numphysent = 0;
clgame.pmove->nummoveent = 0;
CL_CopyEntityToPhysEnt( &clgame.pmove->physents[0], &clgame.entities[0] );
2011-02-20 22:00:00 +01:00
clgame.pmove->visents[0] = clgame.pmove->physents[0];
2010-08-19 22:00:00 +02:00
clgame.pmove->numphysent = 1; // always have world
2011-02-20 22:00:00 +01:00
clgame.pmove->numvisent = 1;
2010-08-19 22:00:00 +02:00
2011-08-14 22:00:00 +02:00
if( cls.state == ca_active && cl.frame.valid )
{
CL_AddLinksToPmove();
}
2010-08-19 22:00:00 +02:00
}
2011-02-20 22:00:00 +01:00
void CL_SetupPMove( playermove_t *pmove, clientdata_t *cd, entity_state_t *state, usercmd_t *ucmd )
2010-08-19 22:00:00 +02:00
{
pmove->player_index = cl.playernum;
2010-08-20 22:00:00 +02:00
pmove->multiplayer = (cl.maxclients > 1) ? true : false;
2011-02-20 22:00:00 +01:00
pmove->time = cl.time; // probably never used
2010-08-19 22:00:00 +02:00
VectorCopy( cd->origin, pmove->origin );
VectorCopy( cl.refdef.cl_viewangles, pmove->angles );
VectorCopy( cl.refdef.cl_viewangles, pmove->oldangles );
VectorCopy( cd->velocity, pmove->velocity );
VectorCopy( state->basevelocity, pmove->basevelocity );
VectorCopy( cd->view_ofs, pmove->view_ofs );
VectorClear( pmove->movedir );
pmove->flDuckTime = cd->flDuckTime;
pmove->bInDuck = cd->bInDuck;
pmove->usehull = (cd->flags & FL_DUCKING) ? 1 : 0; // reset hull
pmove->flTimeStepSound = cd->flTimeStepSound;
pmove->iStepLeft = state->iStepLeft;
pmove->flFallVelocity = state->flFallVelocity;
pmove->flSwimTime = cd->flSwimTime;
VectorCopy( cd->punchangle, pmove->punchangle );
pmove->flSwimTime = cd->flSwimTime;
pmove->flNextPrimaryAttack = 0.0f; // not used by PM_ code
pmove->effects = state->effects;
pmove->flags = cd->flags;
pmove->gravity = state->gravity;
pmove->friction = state->friction;
pmove->oldbuttons = state->oldbuttons;
pmove->waterjumptime = cd->waterjumptime;
pmove->dead = (cd->health <= 0.0f ) ? true : false;
pmove->deadflag = cd->deadflag;
2011-02-20 22:00:00 +01:00
pmove->spectator = cl.spectator;
2010-08-19 22:00:00 +02:00
pmove->movetype = state->movetype;
pmove->onground = -1; // will be set by PM_ code
pmove->waterlevel = cd->waterlevel;
pmove->watertype = cd->watertype;
pmove->maxspeed = clgame.movevars.maxspeed;
pmove->clientmaxspeed = cd->maxspeed;
pmove->iuser1 = cd->iuser1;
pmove->iuser2 = cd->iuser2;
pmove->iuser3 = cd->iuser3;
pmove->iuser4 = cd->iuser4;
pmove->fuser1 = cd->fuser1;
pmove->fuser2 = cd->fuser2;
pmove->fuser3 = cd->fuser3;
pmove->fuser4 = cd->fuser4;
VectorCopy( cd->vuser1, pmove->vuser1 );
VectorCopy( cd->vuser2, pmove->vuser2 );
VectorCopy( cd->vuser3, pmove->vuser3 );
VectorCopy( cd->vuser4, pmove->vuser4 );
pmove->cmd = *ucmd; // setup current cmds
2011-03-09 22:00:00 +01:00
Q_strncpy( pmove->physinfo, cd->physinfo, MAX_INFO_STRING );
2011-04-09 22:00:00 +02:00
}
/*
===========
CL_PostRunCmd
Done after running a player command.
===========
*/
void CL_PostRunCmd( usercmd_t *ucmd, int random_seed )
{
local_state_t *from, *to;
// TODO: write real predicting code
from = &cl.predict[cl.predictcount & CL_UPDATE_MASK];
to = &cl.predict[(cl.predictcount + 1) & CL_UPDATE_MASK];
*to = *from;
clgame.dllFuncs.pfnPostRunCmd( from, to, ucmd, clgame.pmove->runfuncs, cl.time, random_seed );
cl.predictcount++;
}
/*
=================
CL_PredictMovement
Sets cl.predicted_origin and cl.predicted_angles
=================
*/
void CL_PredictMovement( void )
{
int frame = 1;
int ack, outgoing_command;
int current_command;
int current_command_mod;
cl_entity_t *player, *viewent;
clientdata_t *cd;
if( cls.state != ca_active ) return;
if( cl.refdef.paused || cls.key_dest == key_menu ) return;
player = CL_GetLocalPlayer ();
viewent = CL_GetEntityByIndex( cl.refdef.viewentity );
cd = &cl.frame.local.client;
if( cls.demoplayback && viewent )
{
// restore viewangles from angles
2011-10-09 22:00:00 +02:00
cl.refdef.cl_viewangles[PITCH] = viewent->angles[PITCH] * 6;
2011-04-09 22:00:00 +02:00
cl.refdef.cl_viewangles[YAW] = viewent->angles[YAW];
cl.refdef.cl_viewangles[ROLL] = 0; // roll will be computed in view.cpp
}
// unpredicted pure angled values converted into axis
AngleVectors( cl.refdef.cl_viewangles, cl.refdef.forward, cl.refdef.right, cl.refdef.up );
if( !CL_IsPredicted( ))
{
// run commands even if client predicting is disabled - client expected it
clgame.pmove->runfuncs = true;
CL_PostRunCmd( cl.refdef.cmd, cls.lastoutgoingcommand );
return;
}
ack = cls.netchan.incoming_acknowledged;
outgoing_command = cls.netchan.outgoing_sequence;
ASSERT( cl.refdef.cmd != NULL );
// setup initial pmove state
CL_SetupPMove( clgame.pmove, cd, &player->curstate, cl.refdef.cmd );
clgame.pmove->runfuncs = false;
while( 1 )
{
// we've run too far forward
if( frame >= CL_UPDATE_BACKUP - 1 )
break;
// Incoming_acknowledged is the last usercmd the server acknowledged having acted upon
current_command = ack + frame;
current_command_mod = current_command & CL_UPDATE_MASK;
// we've caught up to the current command.
if( current_command > outgoing_command )
break;
clgame.pmove->cmd = cl.cmds[frame];
// motor!
clgame.dllFuncs.pfnPlayerMove( clgame.pmove, false ); // run frames
clgame.pmove->runfuncs = ( current_command > outgoing_command - 1 ) ? true : false;
frame++;
}
CL_PostRunCmd( cl.refdef.cmd, frame );
// copy results out for rendering
VectorCopy( clgame.pmove->view_ofs, cl.predicted_viewofs );
VectorCopy( clgame.pmove->origin, cl.predicted_origin );
VectorCopy( clgame.pmove->velocity, cl.predicted_velocity );
2010-08-12 22:00:00 +02:00
}