fixed rate player physics
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2045 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
@@ -219,7 +219,7 @@ void movelocalplayer()
|
||||
}
|
||||
else if(!intermission)
|
||||
{
|
||||
moveplayer(player1, 20, true);
|
||||
moveplayer(player1, 10, true);
|
||||
checkitems(player1);
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ void moveotherplayers()
|
||||
d->o = d->newpos;
|
||||
d->yaw = d->newyaw;
|
||||
d->pitch = d->newpitch;
|
||||
moveplayer(d, 2, false);
|
||||
moveplayer(d, 1, false);
|
||||
d->newpos = d->o;
|
||||
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
|
||||
if(k>0)
|
||||
@@ -259,9 +259,9 @@ void moveotherplayers()
|
||||
d->pitch += d->deltapitch*k;
|
||||
}
|
||||
}
|
||||
else moveplayer(d, 2, false);
|
||||
else moveplayer(d, 1, false);
|
||||
}
|
||||
else if(d->state==CS_DEAD && lastmillis-d->lastpain<2000) moveplayer(d, 2, false);
|
||||
else if(d->state==CS_DEAD && lastmillis-d->lastpain<2000) moveplayer(d, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-30
@@ -476,53 +476,30 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime)
|
||||
// End add
|
||||
}
|
||||
|
||||
const int MINFRAMETIME = 5;
|
||||
const int PHYSFPS = 200;
|
||||
const int PHYSFRAMETIME = 1000 / PHYSFPS;
|
||||
int physicsfraction = 0, physicsrepeat = 0;
|
||||
|
||||
void playerphysicsframe() // optimally schedule physics frames inside the graphics frames
|
||||
{
|
||||
if(curtime>=MINFRAMETIME)
|
||||
{
|
||||
int faketime = curtime+physicsfraction;
|
||||
physicsrepeat = faketime/MINFRAMETIME;
|
||||
physicsfraction = faketime%MINFRAMETIME;
|
||||
}
|
||||
else
|
||||
{
|
||||
physicsrepeat = curtime>0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
const int PHYSFPS = 100;
|
||||
const int PHYSFRAMETIME = 1000 / PHYSFPS;
|
||||
int fixedphysrepeat = 0;
|
||||
|
||||
void entityphysicsframe() // entity physics at fixed fps
|
||||
{
|
||||
static int lastframemillis = 0;
|
||||
static int fract = 0;
|
||||
|
||||
int elapsed = lastmillis-lastframemillis+fract;
|
||||
fixedphysrepeat = elapsed/PHYSFRAMETIME;
|
||||
fract = elapsed%PHYSFRAMETIME;
|
||||
|
||||
if(fixedphysrepeat > 0) lastframemillis = lastmillis;
|
||||
int faketime = curtime+physicsfraction;
|
||||
physicsrepeat = faketime/PHYSFRAMETIME;
|
||||
physicsfraction = faketime%PHYSFRAMETIME;
|
||||
}
|
||||
|
||||
void physicsframe()
|
||||
{
|
||||
playerphysicsframe();
|
||||
entityphysicsframe();
|
||||
}
|
||||
|
||||
void moveplayer(physent *p, int moveres, bool local)
|
||||
{
|
||||
loopi(physicsrepeat) moveplayer(p, moveres, local, min(curtime, MINFRAMETIME));
|
||||
loopi(physicsrepeat) moveplayer(p, moveres, local, PHYSFRAMETIME);
|
||||
}
|
||||
|
||||
void movebounceent(bounceent *p, int moveres, bool local)
|
||||
{
|
||||
loopi(fixedphysrepeat) moveplayer(p, moveres, local, PHYSFRAMETIME);
|
||||
loopi(physicsrepeat) moveplayer(p, moveres, local, PHYSFRAMETIME);
|
||||
}
|
||||
|
||||
// movement input code
|
||||
|
||||
Reference in New Issue
Block a user