]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
SOLID_NOT is now linked into the areagrid, which fixed the bugs with corpses not...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2005 01:34:12 +0000 (01:34 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2005 01:34:12 +0000 (01:34 +0000)
reorganized and optimized the TOSS/FLY/BOUNCE/STEP physics for better handling of sv_gameplayfix_noairborncorpse

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5828 d7cf8633-e32d-0410-b094-e92efae38249

sv_phys.c
world.c

index 31f1e49125d660ef5ed83d9ea8f8ede2e8032a7a..9873eb2896400eb09ca57ec8a88f0521084206a5 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -1200,22 +1200,25 @@ void SV_Physics_Toss (prvm_edict_t *ent)
        trace_t trace;
        vec3_t move;
 
-       // don't stick to ground if onground and moving upward
-       if (ent->fields.server->velocity[2] >= (1.0 / 32.0) && ((int)ent->fields.server->flags & FL_ONGROUND))
-               ent->fields.server->flags = (int)ent->fields.server->flags & ~FL_ONGROUND;
-
 // if onground, return without moving
        if ((int)ent->fields.server->flags & FL_ONGROUND)
        {
-               if (ent->fields.server->groundentity == 0 || sv_gameplayfix_noairborncorpse.integer)
-                       return;
-               // if ent was supported by a brush model on previous frame,
-               // and groundentity is now freed, set groundentity to 0 (floating)
-               if (ent->priv.server->suspendedinairflag && PRVM_PROG_TO_EDICT(ent->fields.server->groundentity)->priv.server->free)
+               // don't stick to ground if onground and moving upward
+               if (ent->fields.server->velocity[2] >= (1.0 / 32.0))
+                       ent->fields.server->flags -= FL_ONGROUND;
+               else
                {
-                       // leave it suspended in the air
-                       ent->fields.server->groundentity = 0;
-                       return;
+                       prvm_edict_t *ground = PRVM_PROG_TO_EDICT(ent->fields.server->groundentity);
+                       if (ground->fields.server->solid == SOLID_BSP || !sv_gameplayfix_noairborncorpse.integer)
+                               return;
+                       // if ent was supported by a brush model on previous frame,
+                       // and groundentity is now freed, set groundentity to 0 (floating)
+                       if (ent->priv.server->suspendedinairflag && ground->priv.server->free)
+                       {
+                               // leave it suspended in the air
+                               ent->fields.server->groundentity = 0;
+                               return;
+                       }
                }
        }
        ent->priv.server->suspendedinairflag = false;
@@ -1315,23 +1318,38 @@ will fall if the floor is pulled out from under them.
 */
 void SV_Physics_Step (prvm_edict_t *ent)
 {
-       // don't stick to ground if onground and moving upward
-       if (ent->fields.server->velocity[2] >= (1.0 / 32.0) && ((int)ent->fields.server->flags & FL_ONGROUND))
-               ent->fields.server->flags = (int)ent->fields.server->flags & ~FL_ONGROUND;
-
-       // freefall if not onground/fly/swim
-       if (!((int)ent->fields.server->flags & (FL_ONGROUND | FL_FLY | FL_SWIM)))
+       int flags = (int)ent->fields.server->flags;
+       // don't fall at all if fly/swim
+       if (!(flags & (FL_FLY | FL_SWIM)))
        {
-               int hitsound = ent->fields.server->velocity[2] < sv_gravity.value * -0.1;
+               if (flags & FL_ONGROUND)
+               {
+                       // freefall if onground and moving upward
+                       // freefall if not standing on a world surface (it may be a lift)
+                       prvm_edict_t *ground = PRVM_PROG_TO_EDICT(ent->fields.server->groundentity);
+                       if (ent->fields.server->velocity[2] >= (1.0 / 32.0) || (ground->fields.server->solid != SOLID_BSP && sv_gameplayfix_noairborncorpse.integer))
+                       {
+                               ent->fields.server->flags -= FL_ONGROUND;
+                               SV_AddGravity(ent);
+                               SV_CheckVelocity(ent);
+                               SV_FlyMove(ent, sv.frametime, NULL);
+                               SV_LinkEdict(ent, true);
+                       }
+               }
+               else
+               {
+                       // freefall if not onground
+                       int hitsound = ent->fields.server->velocity[2] < sv_gravity.value * -0.1;
 
-               SV_AddGravity(ent);
-               SV_CheckVelocity(ent);
-               SV_FlyMove(ent, sv.frametime, NULL);
-               SV_LinkEdict(ent, true);
+                       SV_AddGravity(ent);
+                       SV_CheckVelocity(ent);
+                       SV_FlyMove(ent, sv.frametime, NULL);
+                       SV_LinkEdict(ent, true);
 
-               // just hit ground
-               if (hitsound && (int)ent->fields.server->flags & FL_ONGROUND && gamemode != GAME_NEXUIZ)
-                       SV_StartSound(ent, 0, "demon/dland2.wav", 255, 1);
+                       // just hit ground
+                       if (hitsound && (int)ent->fields.server->flags & FL_ONGROUND && gamemode != GAME_NEXUIZ)
+                               SV_StartSound(ent, 0, "demon/dland2.wav", 255, 1);
+               }
        }
 
 // regular thinking
diff --git a/world.c b/world.c
index b367221d5327737c9618acd5b1eeca682aa25ef2..0a9a58618c600d49105384988246abffe0925f4a 100644 (file)
--- a/world.c
+++ b/world.c
@@ -168,11 +168,11 @@ int SV_EntitiesInBox(vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
 
        sv_areagrid_stats_calls++;
        sv_areagrid_marknumber++;
-       igridmins[0] = (int) ((mins[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
-       igridmins[1] = (int) ((mins[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
+       igridmins[0] = (int) floor((mins[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
+       igridmins[1] = (int) floor((mins[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
        //igridmins[2] = (int) ((mins[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
-       igridmaxs[0] = (int) ((maxs[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
-       igridmaxs[1] = (int) ((maxs[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
+       igridmaxs[0] = (int) floor((maxs[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
+       igridmaxs[1] = (int) floor((maxs[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
        //igridmaxs[2] = (int) ((maxs[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
        igridmins[0] = max(0, igridmins[0]);
        igridmins[1] = max(0, igridmins[1]);
@@ -222,6 +222,7 @@ int SV_EntitiesInBox(vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
                                                                list[numlist] = ent;
                                                        numlist++;
                                                }
+                                               //      Con_Printf("%d %f %f %f %f %f %f : %d : %f %f %f %f %f %f\n", BoxesOverlap(mins, maxs, ent->fields.server->absmin, ent->fields.server->absmax), ent->fields.server->absmin[0], ent->fields.server->absmin[1], ent->fields.server->absmin[2], ent->fields.server->absmax[0], ent->fields.server->absmax[1], ent->fields.server->absmax[2], PRVM_NUM_FOR_EDICT(ent), mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
                                        }
                                        sv_areagrid_stats_entitychecks++;
                                }
@@ -274,11 +275,11 @@ void SV_LinkEdict_AreaGrid(prvm_edict_t *ent)
                return;
        }
 
-       igridmins[0] = (int) ((ent->fields.server->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
-       igridmins[1] = (int) ((ent->fields.server->absmin[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
+       igridmins[0] = (int) floor((ent->fields.server->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
+       igridmins[1] = (int) floor((ent->fields.server->absmin[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
        //igridmins[2] = (int) ((ent->fields.server->absmin[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
-       igridmaxs[0] = (int) ((ent->fields.server->absmax[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
-       igridmaxs[1] = (int) ((ent->fields.server->absmax[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
+       igridmaxs[0] = (int) floor((ent->fields.server->absmax[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
+       igridmaxs[1] = (int) floor((ent->fields.server->absmax[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
        //igridmaxs[2] = (int) ((ent->fields.server->absmax[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
        if (igridmins[0] < 0 || igridmaxs[0] > AREA_GRID || igridmins[1] < 0 || igridmaxs[1] > AREA_GRID || ((igridmaxs[0] - igridmins[0]) * (igridmaxs[1] - igridmins[1])) > ENTITYGRIDAREAS)
        {
@@ -385,8 +386,8 @@ void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers)
                ent->fields.server->absmax[2] += 1;
        }
 
-       if (ent->fields.server->solid == SOLID_NOT)
-               return;
+       //if (ent->fields.server->solid == SOLID_NOT)
+       //      return;
 
        SV_LinkEdict_AreaGrid(ent);