From 4465c2dced752a029a78248d5d20a15008b9dbc9 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Tue, 7 Nov 2006 01:43:25 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@512 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/physics.cpp | 56 +++++++++++++++++++++--------------------- source/src/sound.cpp | 4 +-- source/src/weapon.cpp | 10 +++----- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 5ebb9cba..aedecec0 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -189,27 +189,8 @@ bool collide(dynent *d, bool spawn, float drop, float rise) return true; } -float rad(float x) { return x*3.14159f/180; }; - VAR(maxroll, 0, 3, 20); -int physicsfraction = 0, physicsrepeat = 0; -const int MINFRAMETIME = 20; // physics always simulated at 50fps or better - -void physicsframe() // optimally schedule physics frames inside the graphics frames -{ - if(curtime>=MINFRAMETIME) - { - int faketime = curtime+physicsfraction; - physicsrepeat = faketime/MINFRAMETIME; - physicsfraction = faketime-physicsrepeat*MINFRAMETIME; - } - else - { - physicsrepeat = 1; - }; -}; - void selfdamage(dynent *d, int dm) { if(d==player1) selfdamage(dm, -1, d); @@ -234,19 +215,19 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) int move = pl->onladder && !pl->onfloor && pl->move == -1 ? 0 : pl->move; // fix movement on ladder - d.x = (float)(move*cos(rad(pl->yaw-90))); - d.y = (float)(move*sin(rad(pl->yaw-90))); + d.x = (float)(move*cos(RAD*(pl->yaw-90))); + d.y = (float)(move*sin(RAD*(pl->yaw-90))); d.z = (float) pl->isphysent ? pl->vel.z : 0; if(floating || water) { - d.x *= (float)cos(rad(pl->pitch)); - d.y *= (float)cos(rad(pl->pitch)); - d.z = (float)(move*sin(rad(pl->pitch))); + d.x *= (float)cos(RAD*(pl->pitch)); + d.y *= (float)cos(RAD*(pl->pitch)); + d.z = (float)(move*sin(RAD*(pl->pitch))); }; - d.x += (float)(pl->strafe*cos(rad(pl->yaw-180))); - d.y += (float)(pl->strafe*sin(rad(pl->yaw-180))); + d.x += (float)(pl->strafe*cos(RAD*(pl->yaw-180))); + d.y += (float)(pl->strafe*sin(RAD*(pl->yaw-180))); const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : (pl->onladder ? 1.5f : 30.0f)); @@ -390,9 +371,27 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) // End add }; +VAR(minframetime, 5, 10, 20); + +int physicsfraction = 0, physicsrepeat = 0; + +void physicsframe() // optimally schedule physics frames inside the graphics frames +{ + if(curtime>=minframetime) + { + int faketime = curtime+physicsfraction; + physicsrepeat = faketime/minframetime; + physicsfraction = faketime%minframetime; + } + else + { + physicsrepeat = 1; + }; +}; + void moveplayer(dynent *pl, int moveres, bool local) { - loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime/physicsrepeat : curtime-curtime/physicsrepeat*(physicsrepeat-1)); + loopi(physicsrepeat) moveplayer(pl, moveres, local, min(curtime, minframetime)); }; vector physents; @@ -464,4 +463,5 @@ void mphysents() void clearphysents() { loopv(physents) if(physents[i]) { delete physents[i]; physents.remove(i); }; -} \ No newline at end of file +} + diff --git a/source/src/sound.cpp b/source/src/sound.cpp index 059b9e47..c9ee6248 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -166,8 +166,8 @@ void updatechanvol(int chan, vec *loc) if(vol<0) vol = 0; if(stereo && (v.x != 0 || v.y != 0)) { - float yaw = -atan2(v.x, v.y) - player1->yaw*(PI / 180.0f); // relative angle of sound along X-Y axis - pan = int(255.9f*(0.5*sin(yaw)+0.5f)); // range is from 0 (left) to 255 (right) + float yaw = -atan2(v.x, v.y) - player1->yaw*RAD; // relative angle of sound along X-Y axis + pan = int(255.9f*(0.5f*sin(yaw)+0.5f)); // range is from 0 (left) to 255 (right) }; }; vol = (vol*MAXVOL)/255; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index bdf140d7..f5cfa3d6 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -433,8 +433,6 @@ void moveprojectiles(float time) }; }; -extern float rad(float x); - void throw_nade(dynent *d, vec &to, physent *p) { if(!p || !d) return; @@ -448,10 +446,10 @@ void throw_nade(dynent *d, vec &to, physent *p) p->onfloor = false; p->o = d->o; - p->vel.z = sin(rad(d->pitch)); - float speed = cos(rad(d->pitch)); - p->vel.x = sin(rad(d->yaw))*speed; - p->vel.y = -cos(rad(d->yaw))*speed; + p->vel.z = sin(RAD*d->pitch); + float speed = cos(RAD*d->pitch); + p->vel.x = sin(RAD*d->yaw)*speed; + p->vel.y = -cos(RAD*d->yaw)*speed; vmul(p->vel, 1.7f);