movement smoothing fix

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2255 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-07-29 22:42:07 +00:00
parent 41f4837b3e
commit cbf4983219
4 changed files with 33 additions and 21 deletions
+23 -17
View File
@@ -228,6 +228,28 @@ void movelocalplayer()
VARP(smoothmove, 0, 75, 100);
VARP(smoothdist, 0, 8, 16);
void predictplayer(playerent *d, bool move)
{
d->o = d->newpos;
d->yaw = d->newyaw;
d->pitch = d->newpitch;
if(move)
{
moveplayer(d, 1, false);
d->newpos = d->o;
}
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
if(k>0)
{
d->o.add(vec(d->deltapos).mul(k));
d->yaw += d->deltayaw*k;
if(d->yaw<0) d->yaw += 360;
else if(d->yaw>=360) d->yaw -= 360;
d->pitch += d->deltapitch*k;
}
d->lastpredict = lastmillis;
}
void moveotherplayers()
{
loopv(players) if(players[i] && players[i]->type==ENT_PLAYER)
@@ -242,23 +264,7 @@ void moveotherplayers()
}
if(d->state==CS_ALIVE || d->state==CS_EDITING)
{
if(smoothmove && d->smoothmillis>0)
{
d->o = d->newpos;
d->yaw = d->newyaw;
d->pitch = d->newpitch;
moveplayer(d, 1, false);
d->newpos = d->o;
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
if(k>0)
{
d->o.add(vec(d->deltapos).mul(k));
d->yaw += d->deltayaw*k;
if(d->yaw<0) d->yaw += 360;
else if(d->yaw>=360) d->yaw -= 360;
d->pitch += d->deltapitch*k;
}
}
if(smoothmove && d->smoothmillis>0) predictplayer(d, true);
else moveplayer(d, 1, false);
}
else if(d->state==CS_DEAD && lastmillis-d->lastpain<2000) moveplayer(d, 1, true);
+7 -2
View File
@@ -80,6 +80,8 @@ void parsepositions(ucharbuf &p)
int f = getuint(p), seqcolor = (f>>6)&1;
playerent *d = getclient(cn);
if(!d || seqcolor!=(d->lifesequence&1)) continue;
extern int smoothmove, smoothdist;
if(smoothmove && d->smoothmillis>=0 && d->lastpredict < lastmillis) predictplayer(d, false);
vec oldpos(d->o);
float oldyaw = d->yaw, oldpitch = d->pitch;
d->o = o;
@@ -98,7 +100,6 @@ void parsepositions(ucharbuf &p)
updatecrouch(d, f&1);
updatepos(d);
updatelagtime(d);
extern int smoothmove, smoothdist;
if(d->state==CS_DEAD)
{
d->resetinterp();
@@ -717,7 +718,11 @@ void receivefile(uchar *data, int len)
s_sprintfd(fname)("demos/%d.dmo", now_utc); //lastmillis);
path(fname);
FILE *demo = openfile(fname, "wb");
if(!demo) return;
if(!demo)
{
conoutf("failed writing to \"%s\"", fname);
return;
}
conoutf("received demo \"%s\"", fname);
fwrite(data, 1, len, demo);
fclose(demo);
+2 -2
View File
@@ -339,7 +339,7 @@ struct playerstate
struct playerent : dynent, playerstate
{
int clientnum, lastupdate, plag, ping;
int clientnum, lastupdate, lastpredict, plag, ping;
int lifesequence; // sequence id for each respawn, used in damage test
int frags, flagscore, deaths;
int lastaction, lastmove, lastpain, lastvoicecom;
@@ -362,7 +362,7 @@ struct playerent : dynent, playerstate
float deltayaw, deltapitch, newyaw, newpitch;
int smoothmillis;
playerent() : clientnum(-1), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT),
playerent() : clientnum(-1), lastupdate(0), lastpredict(0), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT),
skin(0), nextskin(0), spectatemode(SM_NONE), followplayercn(-1), eardamagemillis(0),
weaponsel(NULL), nextweaponsel(NULL), primweap(NULL), nextprimweap(NULL), lastattackweapon(NULL),
smoothmillis(-1)
+1
View File
@@ -293,6 +293,7 @@ extern char *getclientmap();
extern void zapplayer(playerent *&d);
extern playerent *getclient(int cn);
extern playerent *newclient(int cn);
extern void predictplayer(playerent *d, bool move);
extern void timeupdate(int timeremain);
extern void respawnself();
extern void setskin(playerent *pl, uint skin);