diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 8bdfbbe6..f2819366 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -263,7 +263,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) const float speed = curtime*pl->maxspeed/(water ? 2000.0f : 1000.0f); const float friction = water ? 20.0f : (pl->onfloor || editfly || specfly ? 6.0f : 30.0f); - const float fpsfric = friction/curtime*20.0f; + const float fpsfric = friction*20.0f/curtime; if(pl->onfloor) // apply friction { @@ -272,7 +272,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) } else // apply gravity { - const float gravity = 9.81f/1000.0f*bounce->maxspeed; + const float gravity = 9.81f*bounce->maxspeed/1000.0f; const float heightvel = (gravity)*pow(speed, 2.0f); bounce->vel.z -= heightvel; } @@ -476,17 +476,16 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) // End add } -const int minframetime = 5; - +const int MINFRAMETIME = 5; int physicsfraction = 0, physicsrepeat = 0; -void physicsframe() // optimally schedule physics frames inside the graphics frames +void playerphysicsframe() // optimally schedule physics frames inside the graphics frames { - if(curtime>=minframetime) + if(curtime>=MINFRAMETIME) { int faketime = curtime+physicsfraction; - physicsrepeat = faketime/minframetime; - physicsfraction = faketime%minframetime; + physicsrepeat = faketime/MINFRAMETIME; + physicsfraction = faketime%MINFRAMETIME; } else { @@ -494,9 +493,36 @@ void physicsframe() // optimally schedule physics frames inside the gra } } +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; +} + +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, min(curtime, MINFRAMETIME)); +} + +void movebounceent(bounceent *p, int moveres, bool local) +{ + loopi(fixedphysrepeat) moveplayer(p, moveres, local, PHYSFRAMETIME); } // movement input code diff --git a/source/src/protos.h b/source/src/protos.h index 0d35e505..6fb840dd 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -471,6 +471,7 @@ extern uchar *readmcfg(char *name, int *size); extern float raycube(const vec &o, const vec &ray, vec &surface); extern void moveplayer(physent *pl, int moveres, bool local); extern void moveplayer(physent *pl, int moveres, bool local, int curtime); +extern void movebounceent(bounceent *p, int moveres, bool local); extern bool collide(physent *d, bool spawn, float drop, float rise); extern void entinmap(physent *d); extern void physicsframe(); diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 6471d733..6ab78a1b 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -244,7 +244,7 @@ void movebounceents() loopv(bounceents) if(bounceents[i]) { bounceent *p = bounceents[i]; - if((p->bouncetype==BT_NADE || p->bouncetype==BT_GIB) && p->applyphysics()) moveplayer(p, 2, false); + if((p->bouncetype==BT_NADE || p->bouncetype==BT_GIB) && p->applyphysics()) movebounceent(p, 2, false); if(!p->isalive(lastmillis)) { p->destroy();