From ffd20aad3920487e178901d4215f0abccf19b830 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sun, 18 May 2008 22:37:23 +0000 Subject: [PATCH] fixed rate player physics git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2045 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 8 ++++---- source/src/physics.cpp | 37 +++++++------------------------------ 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 1f00fc91..9c2369f2 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -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); } } diff --git a/source/src/physics.cpp b/source/src/physics.cpp index f2819366..5d7658d1 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -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