]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - world.c
fix issues with V_CalcRefdef in CSQC and stereo view
[xonotic/darkplaces.git] / world.c
diff --git a/world.c b/world.c
index ec767e0415335322b39ccf87da497a7f9c12f1e9..39d851402c0d86d77771f79638b082774bc7955b 100644 (file)
--- a/world.c
+++ b/world.c
@@ -102,13 +102,14 @@ World_SetSize
 
 ===============
 */
-void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs)
+void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs, prvm_prog_t *prog)
 {
        int i;
 
        strlcpy(world->filename, filename, sizeof(world->filename));
        VectorCopy(mins, world->mins);
        VectorCopy(maxs, world->maxs);
+       world->prog = prog;
 
        // the areagrid_marknumber is not allowed to be 0
        if (world->areagrid_marknumber < 1)
@@ -144,6 +145,7 @@ World_UnlinkAll
 */
 void World_UnlinkAll(world_t *world)
 {
+       prvm_prog_t *prog = world->prog;
        int i;
        link_t *grid;
        // unlink all entities one by one
@@ -175,6 +177,7 @@ void World_UnlinkEdict(prvm_edict_t *ent)
 
 int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t requestmaxs, int maxlist, prvm_edict_t **list)
 {
+       prvm_prog_t *prog = world->prog;
        int numlist;
        link_t *grid;
        link_t *l;
@@ -208,7 +211,7 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
        numlist = 0;
        // add entities not linked into areagrid because they are too big or
        // outside the grid bounds
-       if (world->areagrid_outside.next != &world->areagrid_outside)
+       if (world->areagrid_outside.next)
        {
                grid = &world->areagrid_outside;
                for (l = grid->next;l != grid;l = l->next)
@@ -233,7 +236,7 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
                grid = world->areagrid + igrid[1] * AREA_GRID + igridmins[0];
                for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
                {
-                       if (grid->next != grid)
+                       if (grid->next)
                        {
                                for (l = grid->next;l != grid;l = l->next)
                                {
@@ -257,8 +260,9 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
        return numlist;
 }
 
-void World_LinkEdict_AreaGrid(world_t *world, prvm_edict_t *ent)
+static void World_LinkEdict_AreaGrid(world_t *world, prvm_edict_t *ent)
 {
+       prvm_prog_t *prog = world->prog;
        link_t *grid;
        int igrid[3], igridmins[3], igridmaxs[3], gridnum, entitynumber = PRVM_NUM_FOR_EDICT(ent);
 
@@ -298,6 +302,7 @@ World_LinkEdict
 */
 void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const vec3_t maxs)
 {
+       prvm_prog_t *prog = world->prog;
        // unlink from old position first
        if (ent->priv.server->areagrid[0].prev)
                World_UnlinkEdict(ent);
@@ -330,17 +335,14 @@ void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const
 #define USEODE 1
 #endif
 
-// recent ODE trunk has dWorldStepFast1 removed
-//#define ODE_USE_STEPFAST
-
 #ifdef USEODE
 cvar_t physics_ode_quadtree_depth = {0, "physics_ode_quadtree_depth","5", "desired subdivision level of quadtree culling space"};
 cvar_t physics_ode_contactsurfacelayer = {0, "physics_ode_contactsurfacelayer","1", "allows objects to overlap this many units to reduce jitter"};
-cvar_t physics_ode_worldstep = {0, "physics_ode_worldstep","2", "step function to use, 0 - dWorldStep, 1 - dWorldStepFast1, 2 - dWorldQuickStep"};
-cvar_t physics_ode_worldstep_iterations = {0, "physics_ode_worldstep_iterations", "20", "parameter to dWorldQuickStep and dWorldStepFast1"};
+cvar_t physics_ode_worldstep_iterations = {0, "physics_ode_worldstep_iterations", "20", "parameter to dWorldQuickStep"};
 cvar_t physics_ode_contact_mu = {0, "physics_ode_contact_mu", "1", "contact solver mu parameter - friction pyramid approximation 1 (see ODE User Guide)"};
 cvar_t physics_ode_contact_erp = {0, "physics_ode_contact_erp", "0.96", "contact solver erp parameter - Error Restitution Percent (see ODE User Guide)"};
 cvar_t physics_ode_contact_cfm = {0, "physics_ode_contact_cfm", "0", "contact solver cfm parameter - Constraint Force Mixing (see ODE User Guide)"};
+cvar_t physics_ode_contact_maxpoints = {0, "physics_ode_contact_maxpoints", "16", "maximal number of contact points between 2 objects, higher = stable (and slower), can be up to 32"};
 cvar_t physics_ode_world_erp = {0, "physics_ode_world_erp", "-1", "world solver erp parameter - Error Restitution Percent (see ODE User Guide); use defaults when set to -1"};
 cvar_t physics_ode_world_cfm = {0, "physics_ode_world_cfm", "-1", "world solver cfm parameter - Constraint Force Mixing (see ODE User Guide); not touched when -1"};
 cvar_t physics_ode_world_damping = {0, "physics_ode_world_damping", "1", "enabled damping scale (see ODE User Guide), this scales all damping values, be aware that behavior depends of step type"};
@@ -350,7 +352,7 @@ cvar_t physics_ode_world_damping_angular = {0, "physics_ode_world_damping_angula
 cvar_t physics_ode_world_damping_angular_threshold = {0, "physics_ode_world_damping_angular_threshold", "0.01", "world angular damping threshold (see ODE User Guide); use defaults when set to -1"};
 cvar_t physics_ode_world_gravitymod = {0, "physics_ode_world_gravitymod", "1", "multiplies gravity got from sv_gravity, this may be needed to tweak if strong damping is used"};
 cvar_t physics_ode_iterationsperframe = {0, "physics_ode_iterationsperframe", "1", "divisor for time step, runs multiple physics steps per frame"};
-cvar_t physics_ode_constantstep = {0, "physics_ode_constantstep", "1", "use constant step (sys_ticrate value) instead of variable step which tends to increase stability"};
+cvar_t physics_ode_constantstep = {0, "physics_ode_constantstep", "0", "use constant step instead of variable step which tends to increase stability, if set to 1 uses sys_ticrate, instead uses it's own value"};
 cvar_t physics_ode_autodisable = {0, "physics_ode_autodisable", "1", "automatic disabling of objects which dont move for long period of time, makes object stacking a lot faster"};
 cvar_t physics_ode_autodisable_steps = {0, "physics_ode_autodisable_steps", "10", "how many steps object should be dormant to be autodisabled"};
 cvar_t physics_ode_autodisable_time = {0, "physics_ode_autodisable_time", "0", "how many seconds object should be dormant to be autodisabled"};
@@ -550,7 +552,7 @@ typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
 #define dSAP_AXES_ZXY  ((2)|(0<<2)|(1<<4))
 #define dSAP_AXES_ZYX  ((2)|(1<<2)|(0<<4))
 
-//const char*     (ODE_API *dGetConfiguration)(void);
+const char*     (ODE_API *dGetConfiguration)(void);
 int             (ODE_API *dCheckConfiguration)( const char* token );
 int             (ODE_API *dInitODE)(void);
 //int             (ODE_API *dInitODE2)(unsigned int uiInitFlags);
@@ -584,7 +586,7 @@ void            (ODE_API *dWorldSetERP)(dWorldID, dReal erp);
 //dReal           (ODE_API *dWorldGetERP)(dWorldID);
 void            (ODE_API *dWorldSetCFM)(dWorldID, dReal cfm);
 //dReal           (ODE_API *dWorldGetCFM)(dWorldID);
-void            (ODE_API *dWorldStep)(dWorldID, dReal stepsize);
+//void            (ODE_API *dWorldStep)(dWorldID, dReal stepsize);
 //void            (ODE_API *dWorldImpulseToForce)(dWorldID, dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force);
 void            (ODE_API *dWorldQuickStep)(dWorldID w, dReal stepsize);
 void            (ODE_API *dWorldSetQuickStepNumIterations)(dWorldID, int num);
@@ -595,9 +597,7 @@ void            (ODE_API *dWorldSetQuickStepNumIterations)(dWorldID, int num);
 //dReal           (ODE_API *dWorldGetContactMaxCorrectingVel)(dWorldID);
 void            (ODE_API *dWorldSetContactSurfaceLayer)(dWorldID, dReal depth);
 //dReal           (ODE_API *dWorldGetContactSurfaceLayer)(dWorldID);
-#ifdef ODE_USE_STEPFAST
-void            (ODE_API *dWorldStepFast1)(dWorldID, dReal stepsize, int maxiterations);
-#endif
+//void            (ODE_API *dWorldStepFast1)(dWorldID, dReal stepsize, int maxiterations);
 //void            (ODE_API *dWorldSetAutoEnableDepthSF1)(dWorldID, int autoEnableDepth);
 //int             (ODE_API *dWorldGetAutoEnableDepthSF1)(dWorldID);
 //dReal           (ODE_API *dWorldGetAutoDisableLinearThreshold)(dWorldID);
@@ -660,12 +660,12 @@ const dReal *   (ODE_API *dBodyGetLinearVel)(dBodyID);
 const dReal *   (ODE_API *dBodyGetAngularVel)(dBodyID);
 void            (ODE_API *dBodySetMass)(dBodyID, const dMass *mass);
 //void            (ODE_API *dBodyGetMass)(dBodyID, dMass *mass);
-//void            (ODE_API *dBodyAddForce)(dBodyID, dReal fx, dReal fy, dReal fz);
-//void            (ODE_API *dBodyAddTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
+void            (ODE_API *dBodyAddForce)(dBodyID, dReal fx, dReal fy, dReal fz);
+void            (ODE_API *dBodyAddTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
 //void            (ODE_API *dBodyAddRelForce)(dBodyID, dReal fx, dReal fy, dReal fz);
-void            (ODE_API *dBodyAddRelTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
-//void            (ODE_API *dBodyAddForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
-void            (ODE_API *dBodyAddForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
+//void            (ODE_API *dBodyAddRelTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
+void            (ODE_API *dBodyAddForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
+//void            (ODE_API *dBodyAddForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
 //void            (ODE_API *dBodyAddRelForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
 //void            (ODE_API *dBodyAddRelForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
 //const dReal *   (ODE_API *dBodyGetForce)(dBodyID);
@@ -1018,7 +1018,7 @@ dGeomID         (ODE_API *dCreateTriMesh)(dSpaceID space, dTriMeshDataID Data, d
 
 static dllfunction_t odefuncs[] =
 {
-//     {"dGetConfiguration",                                                   (void **) &dGetConfiguration},
+       {"dGetConfiguration",                                                   (void **) &dGetConfiguration},
        {"dCheckConfiguration",                                                 (void **) &dCheckConfiguration},
        {"dInitODE",                                                                    (void **) &dInitODE},
 //     {"dInitODE2",                                                                   (void **) &dInitODE2},
@@ -1051,7 +1051,7 @@ static dllfunction_t odefuncs[] =
 //     {"dWorldGetERP",                                                                (void **) &dWorldGetERP},
        {"dWorldSetCFM",                                                                (void **) &dWorldSetCFM},
 //     {"dWorldGetCFM",                                                                (void **) &dWorldGetCFM},
-       {"dWorldStep",                                                                  (void **) &dWorldStep},
+//     {"dWorldStep",                                                                  (void **) &dWorldStep},
 //     {"dWorldImpulseToForce",                                                (void **) &dWorldImpulseToForce},
        {"dWorldQuickStep",                                                             (void **) &dWorldQuickStep},
        {"dWorldSetQuickStepNumIterations",                             (void **) &dWorldSetQuickStepNumIterations},
@@ -1062,9 +1062,7 @@ static dllfunction_t odefuncs[] =
 //     {"dWorldGetContactMaxCorrectingVel",                    (void **) &dWorldGetContactMaxCorrectingVel},
        {"dWorldSetContactSurfaceLayer",                                (void **) &dWorldSetContactSurfaceLayer},
 //     {"dWorldGetContactSurfaceLayer",                                (void **) &dWorldGetContactSurfaceLayer},
-#ifdef ODE_USE_STEPFAST
-       {"dWorldStepFast1",                                                             (void **) &dWorldStepFast1},
-#endif
+//     {"dWorldStepFast1",                                                             (void **) &dWorldStepFast1},
 //     {"dWorldSetAutoEnableDepthSF1",                                 (void **) &dWorldSetAutoEnableDepthSF1},
 //     {"dWorldGetAutoEnableDepthSF1",                                 (void **) &dWorldGetAutoEnableDepthSF1},
 //     {"dWorldGetAutoDisableLinearThreshold",                 (void **) &dWorldGetAutoDisableLinearThreshold},
@@ -1127,12 +1125,12 @@ static dllfunction_t odefuncs[] =
        {"dBodyGetAngularVel",                                                  (void **) &dBodyGetAngularVel},
        {"dBodySetMass",                                                                (void **) &dBodySetMass},
 //     {"dBodyGetMass",                                                                (void **) &dBodyGetMass},
-//     {"dBodyAddForce",                                                               (void **) &dBodyAddForce},
-//     {"dBodyAddTorque",                                                              (void **) &dBodyAddTorque},
+       {"dBodyAddForce",                                                               (void **) &dBodyAddForce},
+       {"dBodyAddTorque",                                                              (void **) &dBodyAddTorque},
 //     {"dBodyAddRelForce",                                                    (void **) &dBodyAddRelForce},
-       {"dBodyAddRelTorque",                                                   (void **) &dBodyAddRelTorque},
-//     {"dBodyAddForceAtPos",                                                  (void **) &dBodyAddForceAtPos},
-       {"dBodyAddForceAtRelPos",                                               (void **) &dBodyAddForceAtRelPos},
+//     {"dBodyAddRelTorque",                                                   (void **) &dBodyAddRelTorque},
+       {"dBodyAddForceAtPos",                                                  (void **) &dBodyAddForceAtPos},
+//     {"dBodyAddForceAtRelPos",                                               (void **) &dBodyAddForceAtRelPos},
 //     {"dBodyAddRelForceAtPos",                                               (void **) &dBodyAddRelForceAtPos},
 //     {"dBodyAddRelForceAtRelPos",                                    (void **) &dBodyAddRelForceAtRelPos},
 //     {"dBodyGetForce",                                                               (void **) &dBodyGetForce},
@@ -1491,11 +1489,11 @@ static void World_Physics_Init(void)
 
        Cvar_RegisterVariable(&physics_ode_quadtree_depth);
        Cvar_RegisterVariable(&physics_ode_contactsurfacelayer);
-       Cvar_RegisterVariable(&physics_ode_worldstep);
        Cvar_RegisterVariable(&physics_ode_worldstep_iterations);
        Cvar_RegisterVariable(&physics_ode_contact_mu);
        Cvar_RegisterVariable(&physics_ode_contact_erp);
        Cvar_RegisterVariable(&physics_ode_contact_cfm);
+       Cvar_RegisterVariable(&physics_ode_contact_maxpoints);
        Cvar_RegisterVariable(&physics_ode_world_erp);
        Cvar_RegisterVariable(&physics_ode_world_cfm);
        Cvar_RegisterVariable(&physics_ode_world_damping);
@@ -1547,6 +1545,7 @@ static void World_Physics_Init(void)
 # else
                        Con_Printf("ODE library loaded with double precision.\n");
 # endif
+                       Con_Printf("ODE configuration list: %s\n", dGetConfiguration());
                }
 #endif
        }
@@ -1730,13 +1729,13 @@ void World_Physics_ApplyCmd(prvm_edict_t *ed, edict_odefunc_t *f)
        case ODEFUNC_DISABLE:
                dBodyDisable(body);
                break;
-       case ODEFUNC_RELFORCEATPOS:
+       case ODEFUNC_FORCE:
                dBodyEnable(body);
-               dBodyAddForceAtRelPos(body, f->v1[0], f->v1[1], f->v1[2], f->v2[0], f->v2[1], f->v2[2]);
+               dBodyAddForceAtPos(body, f->v1[0], f->v1[1], f->v1[2], f->v2[0], f->v2[1], f->v2[2]);
                break;
-       case ODEFUNC_RELTORQUE:
+       case ODEFUNC_TORQUE:
                dBodyEnable(body);
-               dBodyAddRelTorque(body, f->v1[0], f->v1[1], f->v1[2]);
+               dBodyAddTorque(body, f->v1[0], f->v1[1], f->v1[2]);
                break;
        default:
                break;
@@ -1747,6 +1746,7 @@ void World_Physics_ApplyCmd(prvm_edict_t *ed, edict_odefunc_t *f)
 #ifdef USEODE
 static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
 {
+       prvm_prog_t *prog = world->prog;
        const dReal *avel;
        const dReal *o;
        const dReal *r; // for some reason dBodyGetRotation returns a [3][4] matrix
@@ -1812,13 +1812,13 @@ static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
 
        {
                float pitchsign = 1;
-               if(!strcmp(prog->name, "server")) // FIXME some better way?
+               if(prog == SVVM_prog) // FIXME some better way?
                {
-                       pitchsign = SV_GetPitchSign(ed);
+                       pitchsign = SV_GetPitchSign(prog, ed);
                }
-               else if(!strcmp(prog->name, "client"))
+               else if(prog == CLVM_prog)
                {
-                       pitchsign = CL_GetPitchSign(ed);
+                       pitchsign = CL_GetPitchSign(prog, ed);
                }
                angles[PITCH] *= pitchsign;
                avelocity[PITCH] *= pitchsign;
@@ -1840,15 +1840,55 @@ static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
        VectorCopy(avelocity, ed->priv.server->ode_avelocity);
        ed->priv.server->ode_gravity = dBodyGetGravityMode(body) != 0;
 
-       if(!strcmp(prog->name, "server")) // FIXME some better way?
+       if(prog == SVVM_prog) // FIXME some better way?
        {
                SV_LinkEdict(ed);
                SV_LinkEdict_TouchAreaGrid(ed);
        }
 }
 
+static void World_Physics_Frame_ForceFromEntity(world_t *world, prvm_edict_t *ed)
+{
+       prvm_prog_t *prog = world->prog;
+       int forcetype = 0, movetype = 0, enemy = 0;
+       vec3_t movedir, origin;
+
+       movetype = (int)PRVM_gameedictfloat(ed, movetype);
+       forcetype = (int)PRVM_gameedictfloat(ed, forcetype);
+       if (movetype == MOVETYPE_PHYSICS)
+               forcetype = FORCETYPE_NONE; // can't have both
+       if (!forcetype)
+               return;
+       enemy = PRVM_gameedictedict(ed, enemy);
+       if (enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
+               return;
+       VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
+       VectorCopy(PRVM_gameedictvector(ed, origin), origin);
+       dBodyEnable((dBodyID)prog->edicts[enemy].priv.server->ode_body);
+       switch(forcetype)
+       {
+               case FORCETYPE_FORCE:
+                       if (movedir[0] || movedir[1] || movedir[2])
+                               dBodyAddForce((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2]);
+                       break;
+               case FORCETYPE_FORCEATPOS:
+                       if (movedir[0] || movedir[1] || movedir[2])
+                               dBodyAddForceAtPos((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2], origin[0], origin[1], origin[2]);
+                       break;
+               case FORCETYPE_TORQUE:
+                       if (movedir[0] || movedir[1] || movedir[2])
+                               dBodyAddTorque((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2]);
+                       break;
+               case FORCETYPE_NONE:
+               default:
+                       // bad force
+                       break;
+       }
+}
+
 static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed)
 {
+       prvm_prog_t *prog = world->prog;
        dJointID j = 0;
        dBodyID b1 = 0;
        dBodyID b2 = 0;
@@ -1857,12 +1897,13 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
        int enemy = 0, aiment = 0;
        vec3_t origin, velocity, angles, forward, left, up, movedir;
        vec_t CFM, ERP, FMax, Stop, Vel;
+
+       movetype = (int)PRVM_gameedictfloat(ed, movetype);
+       jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
        VectorClear(origin);
        VectorClear(velocity);
        VectorClear(angles);
        VectorClear(movedir);
-       movetype = (int)PRVM_gameedictfloat(ed, movetype);
-       jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
        enemy = PRVM_gameedictedict(ed, enemy);
        aiment = PRVM_gameedictedict(ed, aiment);
        VectorCopy(PRVM_gameedictvector(ed, origin), origin);
@@ -1870,7 +1911,7 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
        VectorCopy(PRVM_gameedictvector(ed, angles), angles);
        VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
        if(movetype == MOVETYPE_PHYSICS)
-               jointtype = 0; // can't have both
+               jointtype = JOINTTYPE_NONE; // can't have both
        if(enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
                enemy = 0;
        if(aiment <= 0 || aiment >= prog->num_edicts || prog->edicts[aiment].priv.required->free || prog->edicts[aiment].priv.server->ode_body == 0)
@@ -1928,7 +1969,7 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
                case JOINTTYPE_FIXED:
                        j = dJointCreateFixed((dWorldID)world->physics.ode_world, 0);
                        break;
-               case 0:
+               case JOINTTYPE_NONE:
                default:
                        // no joint
                        j = 0;
@@ -2030,6 +2071,7 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
 
 static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
 {
+       prvm_prog_t *prog = world->prog;
        const float *iv;
        const int *ie;
        dBodyID body = (dBodyID)ed->priv.server->ode_body;
@@ -2037,7 +2079,6 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        dReal test;
        const dReal *ovelocity, *ospinvelocity;
        void *dataID;
-       dVector3 capsulerot[3];
        dp_model_t *model;
        float *ov;
        int *oe;
@@ -2046,7 +2087,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        int movetype = MOVETYPE_NONE;
        int numtriangles;
        int numvertices;
-       int solid = SOLID_NOT;
+       int solid = SOLID_NOT, geomtype = 0;
        int triangleindex;
        int vertexindex;
        mempool_t *mempool;
@@ -2071,6 +2112,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        vec_t scale = 1.0f;
        vec_t spinlimit;
        qboolean gravity;
+       vec3_t scalevec;
        edict_odefunc_t *func, *nextf;
 
 #ifdef ODE_DYNAMIC
@@ -2079,21 +2121,34 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
 #endif
        VectorClear(entmins);
        VectorClear(entmaxs);
+
        solid = (int)PRVM_gameedictfloat(ed, solid);
+       geomtype = (int)PRVM_gameedictfloat(ed, geomtype);
        movetype = (int)PRVM_gameedictfloat(ed, movetype);
        scale = PRVM_gameedictfloat(ed, scale);if (!scale) scale = 1.0f;
        modelindex = 0;
-       if (world == &sv.world)
-               mempool = sv_mempool;
-       else if (world == &cl.world)
-               mempool = cls.levelmempool;
-       else
-               mempool = NULL;
+       mempool = prog->progs_mempool;
        model = NULL;
-       switch(solid)
+       if (!geomtype)
+       {
+               // VorteX: keep support for deprecated solid fields to not break mods
+               if (solid == SOLID_PHYSICS_TRIMESH || solid == SOLID_BSP)
+                       geomtype = GEOMTYPE_TRIMESH;
+               else if (solid == SOLID_NOT || solid == SOLID_TRIGGER)
+                       geomtype = GEOMTYPE_NONE;
+               else if (solid == SOLID_PHYSICS_SPHERE)
+                       geomtype = GEOMTYPE_SPHERE;
+               else if (solid == SOLID_PHYSICS_CAPSULE)
+                       geomtype = GEOMTYPE_CAPSULE;
+               else if (solid == SOLID_PHYSICS_CYLINDER)
+                       geomtype = GEOMTYPE_CYLINDER;
+               else if (solid == SOLID_PHYSICS_BOX)
+                       geomtype = GEOMTYPE_BOX;
+               else
+                       geomtype = GEOMTYPE_BOX;
+       }
+       if (geomtype == GEOMTYPE_TRIMESH)
        {
-       case SOLID_BSP:
-       case SOLID_PHYSICS_TRIMESH:
                modelindex = (int)PRVM_gameedictfloat(ed, modelindex);
                if (world == &sv.world)
                        model = SV_GetModelByIndex(modelindex);
@@ -2112,18 +2167,16 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                        modelindex = 0;
                        massval = 1.0f;
                }
-               break;
-       case SOLID_BBOX:
-       //case SOLID_SLIDEBOX:
-       case SOLID_CORPSE:
-       case SOLID_PHYSICS_BOX:
-       case SOLID_PHYSICS_SPHERE:
-       case SOLID_PHYSICS_CAPSULE:
+       }
+       else if (geomtype && geomtype != GEOMTYPE_NONE)
+       {
                VectorCopy(PRVM_gameedictvector(ed, mins), entmins);
                VectorCopy(PRVM_gameedictvector(ed, maxs), entmaxs);
                massval = PRVM_gameedictfloat(ed, mass);
-               break;
-       default:
+       }
+       else
+       {
+               // geometry type not set, falling back
                if (ed->priv.server->ode_physics)
                        World_Physics_RemoveFromEntity(world, ed);
                return;
@@ -2170,19 +2223,25 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                if (massval * geomsize[0] * geomsize[1] * geomsize[2] == 0)
                {
                        if (movetype == MOVETYPE_PHYSICS)
-                               Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
+                               Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
                        massval = 1.0f;
                        VectorSet(geomsize, 1.0f, 1.0f, 1.0f);
                }
 
-               switch(solid)
+               switch(geomtype)
                {
-               case SOLID_BSP:
-               case SOLID_PHYSICS_TRIMESH:
+               case GEOMTYPE_TRIMESH:
                        ed->priv.server->ode_offsetmatrix = identitymatrix;
+                       // honor scale, support q3map2's/radiant's modelscale_vec
+                       VectorCopy(PRVM_gameedictvector(ed, modelscale_vec), scalevec); 
+                       if (scalevec[0] != 0.0 || scalevec[1] != 0.0 || scalevec[2] != 0.0)
+                               Matrix4x4_OriginScale3(&ed->priv.server->ode_offsetmatrix, scalevec[0], scalevec[1],scalevec[2]);
+                       else if (PRVM_gameedictfloat(ed, scale))
+                               Matrix4x4_OriginScale3(&ed->priv.server->ode_offsetmatrix, PRVM_gameedictfloat(ed, scale), PRVM_gameedictfloat(ed, scale), PRVM_gameedictfloat(ed, scale));
+                       // check model
                        if (!model)
                        {
-                               Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
+                               Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
                                goto treatasbox;
                        }
                        // add an optimized mesh to the model containing only the SUPERCONTENTS_SOLID surfaces
@@ -2190,7 +2249,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                                Mod_CreateCollisionMesh(model);
                        if (!model->brush.collisionmesh || !model->brush.collisionmesh->numtriangles)
                        {
-                               Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
+                               Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
                                goto treatasbox;
                        }
                        // ODE requires persistent mesh storage, so we need to copy out
@@ -2222,22 +2281,18 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                        ed->priv.server->ode_geom = (void *)dCreateTriMesh((dSpaceID)world->physics.ode_space, (dTriMeshDataID)dataID, NULL, NULL, NULL);
                        dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
                        break;
-               case SOLID_BBOX:
-               case SOLID_SLIDEBOX:
-               case SOLID_CORPSE:
-               case SOLID_PHYSICS_BOX:
+               case GEOMTYPE_BOX:
 treatasbox:
                        Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
                        ed->priv.server->ode_geom = (void *)dCreateBox((dSpaceID)world->physics.ode_space, geomsize[0], geomsize[1], geomsize[2]);
                        dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
                        break;
-               case SOLID_PHYSICS_SPHERE:
+               case GEOMTYPE_SPHERE:
                        Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
                        ed->priv.server->ode_geom = (void *)dCreateSphere((dSpaceID)world->physics.ode_space, geomsize[0] * 0.5f);
                        dMassSetSphereTotal(&mass, massval, geomsize[0] * 0.5f);
                        break;
-               case SOLID_PHYSICS_CAPSULE:
-               case SOLID_PHYSICS_CYLINDER:
+               case GEOMTYPE_CAPSULE:
                        axisindex = 0;
                        if (geomsize[axisindex] < geomsize[1])
                                axisindex = 1;
@@ -2247,31 +2302,125 @@ treatasbox:
                        // axis, since ODE doesn't like this idea we have to create a
                        // capsule which uses the standard orientation, and apply a
                        // transform to it
-                       memset(capsulerot, 0, sizeof(capsulerot));
                        if (axisindex == 0)
+                       {
                                Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
+                               radius = min(geomsize[1], geomsize[2]) * 0.5f;
+                       }
                        else if (axisindex == 1)
+                       {
                                Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
+                               radius = min(geomsize[0], geomsize[2]) * 0.5f;
+                       }
                        else
+                       {
                                Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
-                       radius = geomsize[!axisindex] * 0.5f; // any other axis is the radius
+                               radius = min(geomsize[0], geomsize[1]) * 0.5f;
+                       }
                        length = geomsize[axisindex] - radius*2;
                        // because we want to support more than one axisindex, we have to
                        // create a transform, and turn on its cleanup setting (which will
                        // cause the child to be destroyed when it is destroyed)
-                       if (solid == SOLID_PHYSICS_CAPSULE)
+                       ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCapsuleTotal(&mass, massval, axisindex+1, radius, length);
+                       break;
+               case GEOMTYPE_CAPSULE_X:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
+                       radius = min(geomsize[1], geomsize[2]) * 0.5f;
+                       length = geomsize[0] - radius*2;
+                       // check if length is not enough, reduce radius then
+                       if (length <= 0)
+                       {
+                               radius -= (1 - length)*0.5;
+                               length = 1;
+                       }
+                       ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCapsuleTotal(&mass, massval, 1, radius, length);
+                       break;
+               case GEOMTYPE_CAPSULE_Y:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
+                       radius = min(geomsize[0], geomsize[2]) * 0.5f;
+                       length = geomsize[1] - radius*2;
+                       // check if length is not enough, reduce radius then
+                       if (length <= 0)
                        {
-                               ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
-                               dMassSetCapsuleTotal(&mass, massval, axisindex+1, radius, length);
+                               radius -= (1 - length)*0.5;
+                               length = 1;
+                       }
+                       ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCapsuleTotal(&mass, massval, 2, radius, length);
+                       break;
+               case GEOMTYPE_CAPSULE_Z:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
+                       radius = min(geomsize[1], geomsize[0]) * 0.5f;
+                       length = geomsize[2] - radius*2;
+                       // check if length is not enough, reduce radius then
+                       if (length <= 0)
+                       {
+                               radius -= (1 - length)*0.5;
+                               length = 1;
+                       }
+                       ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCapsuleTotal(&mass, massval, 3, radius, length);
+                       break;
+               case GEOMTYPE_CYLINDER:
+                       axisindex = 0;
+                       if (geomsize[axisindex] < geomsize[1])
+                               axisindex = 1;
+                       if (geomsize[axisindex] < geomsize[2])
+                               axisindex = 2;
+                       // the qc gives us 3 axis radius, the longest axis is the capsule
+                       // axis, since ODE doesn't like this idea we have to create a
+                       // capsule which uses the standard orientation, and apply a
+                       // transform to it
+                       if (axisindex == 0)
+                       {
+                               Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
+                               radius = min(geomsize[1], geomsize[2]) * 0.5f;
+                       }
+                       else if (axisindex == 1)
+                       {
+                               Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
+                               radius = min(geomsize[0], geomsize[2]) * 0.5f;
                        }
                        else
                        {
-                               ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
-                               dMassSetCylinderTotal(&mass, massval, axisindex+1, radius, length);
+                               Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
+                               radius = min(geomsize[0], geomsize[1]) * 0.5f;
+                       }
+                       length = geomsize[axisindex];
+                       // check if length is not enough, reduce radius then
+                       if (length <= 0)
+                       {
+                               radius -= (1 - length)*0.5;
+                               length = 1;
                        }
+                       ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCylinderTotal(&mass, massval, axisindex+1, radius, length);
+                       break;
+               case GEOMTYPE_CYLINDER_X:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
+                       radius = min(geomsize[1], geomsize[2]) * 0.5f;
+                       length = geomsize[0];
+                       ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCylinderTotal(&mass, massval, 1, radius, length);
+                       break;
+               case GEOMTYPE_CYLINDER_Y:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
+                       radius = min(geomsize[0], geomsize[2]) * 0.5f;
+                       length = geomsize[1];
+                       ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCylinderTotal(&mass, massval, 2, radius, length);
+                       break;
+               case GEOMTYPE_CYLINDER_Z:
+                       Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
+                       radius = min(geomsize[0], geomsize[1]) * 0.5f;
+                       length = geomsize[2];
+                       ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
+                       dMassSetCylinderTotal(&mass, massval, 3, radius, length);
                        break;
                default:
-                       Sys_Error("World_Physics_BodyFromEntity: unrecognized solid value %i was accepted by filter\n", solid);
+                       Sys_Error("World_Physics_BodyFromEntity: unrecognized geomtype value %i was accepted by filter\n", solid);
                        // this goto only exists to prevent warnings from the compiler
                        // about uninitialized variables (mass), while allowing it to
                        // catch legitimate uninitialized variable warnings
@@ -2337,13 +2486,13 @@ treatasbox:
                VectorCopy(angles, qangles);
                VectorCopy(avelocity, qavelocity);
 
-               if(!strcmp(prog->name, "server")) // FIXME some better way?
+               if(prog == SVVM_prog) // FIXME some better way?
                {
-                       pitchsign = SV_GetPitchSign(ed);
+                       pitchsign = SV_GetPitchSign(prog, ed);
                }
-               else if(!strcmp(prog->name, "client"))
+               else if(prog == CLVM_prog)
                {
-                       pitchsign = CL_GetPitchSign(ed);
+                       pitchsign = CL_GetPitchSign(prog, ed);
                }
                qangles[PITCH] *= pitchsign;
                qavelocity[PITCH] *= pitchsign;
@@ -2377,7 +2526,7 @@ treatasbox:
                        modified = true;
                        //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
                        if (physics_ode_trick_fixnan.integer >= 2)
-                               Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
+                               Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
                        test = VectorLength2(origin);
                        if (IS_NAN(test))
                                VectorClear(origin);
@@ -2449,9 +2598,9 @@ treatasbox:
                r[0][2] = up[0];
                r[1][2] = up[1];
                r[2][2] = up[2];
-               if(body)
+               if (body)
                {
-                       if(movetype == MOVETYPE_PHYSICS)
+                       if (movetype == MOVETYPE_PHYSICS)
                        {
                                dGeomSetBody((dGeomID)ed->priv.server->ode_geom, body);
                                dBodySetPosition(body, origin[0], origin[1], origin[2]);
@@ -2480,7 +2629,7 @@ treatasbox:
                }
        }
 
-       if(body)
+       if (body)
        {
 
                // limit movement speed to prevent missed collisions at high speed
@@ -2518,10 +2667,11 @@ treatasbox:
        }
 }
 
-#define MAX_CONTACTS 16
+#define MAX_CONTACTS 32
 static void nearCallback (void *data, dGeomID o1, dGeomID o2)
 {
        world_t *world = (world_t *)data;
+       prvm_prog_t *prog = world->prog;
        dContact contact[MAX_CONTACTS]; // max contacts per collision pair
        dBodyID b1;
        dBodyID b2;
@@ -2532,6 +2682,7 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
        float bouncestop1 = 60.0f / 800.0f;
        float bouncefactor2 = 0.0f;
        float bouncestop2 = 60.0f / 800.0f;
+       float erp;
        dVector3 grav;
        prvm_edict_t *ed1, *ed2;
 
@@ -2552,7 +2703,7 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
        // at least one object has to be using MOVETYPE_PHYSICS or we just don't care
        if (!b1 && !b2)
                return;
-
+       
        // exit without doing anything if the two bodies are connected by a joint
        if (b1 && b2 && dAreConnectedExcluding(b1, b2, dJointTypeContact))
                return;
@@ -2579,7 +2730,7 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
                        bouncestop2 = 60.0f / 800.0f;
        }
 
-       if(!strcmp(prog->name, "server"))
+       if(prog == SVVM_prog)
        {
                if(ed1 && PRVM_serveredictfunction(ed1, touch))
                {
@@ -2611,14 +2762,27 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
        dWorldGetGravity((dWorldID)world->physics.ode_world, grav);
        bouncestop1 *= fabs(grav[2]);
 
+       // get erp
+       // select object that moves faster ang get it's erp
+       erp = (VectorLength2(PRVM_gameedictvector(ed1, velocity)) > VectorLength2(PRVM_gameedictvector(ed2, velocity))) ? PRVM_gameedictfloat(ed1, erp) : PRVM_gameedictfloat(ed2, erp);
+
+       // get max contact points for this collision
+       numcontacts = (int)PRVM_gameedictfloat(ed1, maxcontacts);
+       if (!numcontacts)
+               numcontacts = physics_ode_contact_maxpoints.integer;
+       if (PRVM_gameedictfloat(ed2, maxcontacts))
+               numcontacts = max(numcontacts, (int)PRVM_gameedictfloat(ed2, maxcontacts));
+       else
+               numcontacts = max(numcontacts, physics_ode_contact_maxpoints.integer);
+
        // generate contact points between the two non-space geoms
-       numcontacts = dCollide(o1, o2, MAX_CONTACTS, &(contact[0].geom), sizeof(contact[0]));
+       numcontacts = dCollide(o1, o2, min(MAX_CONTACTS, numcontacts), &(contact[0].geom), sizeof(contact[0]));
        // add these contact points to the simulation
        for (i = 0;i < numcontacts;i++)
        {
                contact[i].surface.mode = (physics_ode_contact_mu.value != -1 ? dContactApprox1 : 0) | (physics_ode_contact_erp.value != -1 ? dContactSoftERP : 0) | (physics_ode_contact_cfm.value != -1 ? dContactSoftCFM : 0) | (bouncefactor1 > 0 ? dContactBounce : 0);
                contact[i].surface.mu = physics_ode_contact_mu.value * ed1->priv.server->ode_friction * ed2->priv.server->ode_friction;
-               contact[i].surface.soft_erp = physics_ode_contact_erp.value;
+               contact[i].surface.soft_erp = physics_ode_contact_erp.value + erp;
                contact[i].surface.soft_cfm = physics_ode_contact_cfm.value;
                contact[i].surface.bounce = bouncefactor1;
                contact[i].surface.bounce_vel = bouncestop1;
@@ -2630,20 +2794,39 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
 
 void World_Physics_Frame(world_t *world, double frametime, double gravity)
 {
+       prvm_prog_t *prog = world->prog;
        double tdelta, tdelta2, tdelta3, simulationtime, collisiontime;
 
-       tdelta = Sys_DoubleTime();
+       tdelta = Sys_DirtyTime();
 #ifdef USEODE
        if (world->physics.ode && physics_ode.integer)
        {
                int i;
                prvm_edict_t *ed;
 
-               world->physics.ode_iterations = bound(1, physics_ode_iterationsperframe.integer, 1000);
-               if (physics_ode_constantstep.integer)
-                       world->physics.ode_step = sys_ticrate.value / world->physics.ode_iterations;
-               else
+               if (!physics_ode_constantstep.value)
+               {
+                       world->physics.ode_iterations = bound(1, physics_ode_iterationsperframe.integer, 1000);
                        world->physics.ode_step = frametime / world->physics.ode_iterations;
+               }
+               else
+               {
+                       world->physics.ode_time += frametime;
+                       // step size
+                       if (physics_ode_constantstep.value > 0 && physics_ode_constantstep.value < 1)
+                               world->physics.ode_step = physics_ode_constantstep.value;
+                       else
+                               world->physics.ode_step = sys_ticrate.value;
+                       if (world->physics.ode_time > 0.2f)
+                               world->physics.ode_time = world->physics.ode_step;
+                       // set number of iterations to process
+                       world->physics.ode_iterations = 0;
+                       while(world->physics.ode_time >= world->physics.ode_step)
+                       {
+                               world->physics.ode_iterations++;
+                               world->physics.ode_time -= world->physics.ode_step;
+                       }
+               }       
                world->physics.ode_movelimit = physics_ode_movelimit.value / world->physics.ode_step;
                World_Physics_UpdateODE(world);
 
@@ -2659,7 +2842,7 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                                        World_Physics_Frame_JointFromEntity(world, ed);
                }
 
-               tdelta2 = Sys_DoubleTime();
+               tdelta2 = Sys_DirtyTime();
                collisiontime = 0;
                for (i = 0;i < world->physics.ode_iterations;i++)
                {
@@ -2667,29 +2850,27 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                        dWorldSetGravity((dWorldID)world->physics.ode_world, 0, 0, -gravity * physics_ode_world_gravitymod.value);
                        // set the tolerance for closeness of objects
                        dWorldSetContactSurfaceLayer((dWorldID)world->physics.ode_world, max(0, physics_ode_contactsurfacelayer.value));
-
                        // run collisions for the current world state, creating JointGroup
-                       tdelta3 = Sys_DoubleTime();
+                       tdelta3 = Sys_DirtyTime();
                        dSpaceCollide((dSpaceID)world->physics.ode_space, (void *)world, nearCallback);
-                       collisiontime += (Sys_DoubleTime() - tdelta3)*10000;
-
-                       // run physics (move objects, calculate new velocities)
-                       if (physics_ode_worldstep.integer == 2)
+                       collisiontime += (Sys_DirtyTime() - tdelta3)*10000;
+                       // apply forces
+                       if (prog)
                        {
-                               dWorldSetQuickStepNumIterations((dWorldID)world->physics.ode_world, bound(1, physics_ode_worldstep_iterations.integer, 200));
-                               dWorldQuickStep((dWorldID)world->physics.ode_world, world->physics.ode_step);
+                               int j;
+                               for (j = 0, ed = prog->edicts + j;j < prog->num_edicts;j++, ed++)
+                                       if (!prog->edicts[j].priv.required->free)
+                                               World_Physics_Frame_ForceFromEntity(world, ed);
                        }
-#ifdef ODE_USE_STEPFAST
-                       else if (physics_ode_worldstep.integer == 1)
-                               dWorldStepFast1((dWorldID)world->physics.ode_world, world->physics.ode_step, bound(1, physics_ode_worldstep_iterations.integer, 200));
-#endif
-                       else
-                               dWorldStep((dWorldID)world->physics.ode_world, world->physics.ode_step);
-
+                       // run physics (move objects, calculate new velocities)
+                       // be sure not to pass 0 as step time because that causes an ODE error
+                       dWorldSetQuickStepNumIterations((dWorldID)world->physics.ode_world, bound(1, physics_ode_worldstep_iterations.integer, 200));
+                       if (world->physics.ode_step > 0)
+                               dWorldQuickStep((dWorldID)world->physics.ode_world, world->physics.ode_step);
                        // clear the JointGroup now that we're done with it
                        dJointGroupEmpty((dJointGroupID)world->physics.ode_contactgroup);
                }
-               simulationtime = (Sys_DoubleTime() - tdelta2)*10000;
+               simulationtime = (Sys_DirtyTime() - tdelta2)*10000;
 
                // copy physics properties from physics engine to entities and do some stats
                if (prog)
@@ -2716,7 +2897,7 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                                        if (dBodyIsEnabled(body))
                                                world->physics.ode_activeovjects++;
                                }
-                               Con_Printf("ODE Stats(%s): %3.01f (%3.01f collision) %3.01f total : %i objects %i active %i disabled\n", prog->name, simulationtime, collisiontime, (Sys_DoubleTime() - tdelta)*10000, world->physics.ode_numobjects, world->physics.ode_activeovjects, (world->physics.ode_numobjects - world->physics.ode_activeovjects));
+                               Con_Printf("ODE Stats(%s): %i iterations, %3.01f (%3.01f collision) %3.01f total : %i objects %i active %i disabled\n", prog->name, world->physics.ode_iterations, simulationtime, collisiontime, (Sys_DirtyTime() - tdelta)*10000, world->physics.ode_numobjects, world->physics.ode_activeovjects, (world->physics.ode_numobjects - world->physics.ode_activeovjects));
                        }
                }
        }