summaryrefslogtreecommitdiff
path: root/src/engine/physics.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-05 10:40:01 +0200
committerxolatile2025-08-05 10:40:01 +0200
commita2a16b85572b1d28b0cd4901ea7348750732a740 (patch)
tree6287cdf8331e821f9fe1e0adadc664a59634a812 /src/engine/physics.cpp
parent6762e292d02e37a69a807e01493d4e14319cca33 (diff)
downloadxolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.xz
xolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.zst
Few more changes, please do not compile...
Diffstat (limited to 'src/engine/physics.cpp')
-rw-r--r--src/engine/physics.cpp83
1 files changed, 28 insertions, 55 deletions
diff --git a/src/engine/physics.cpp b/src/engine/physics.cpp
index db30a43..b1b800a 100644
--- a/src/engine/physics.cpp
+++ b/src/engine/physics.cpp
@@ -313,11 +313,7 @@ float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity
{
if(isentirelysolid(c))
{
- if(c.texture[side]==DEFAULT_SKY && mode&RAY_SKIPSKY)
- {
- if(mode&RAY_SKYTEX) return radius;
- }
- else return dist;
+ return dist;
}
else
{
@@ -326,11 +322,7 @@ float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity
INTERSECTBOX(side = (i<<1) + 1 - lsizemask[i], goto nextcube);
if(exitdist >= 0)
{
- if(c.texture[side]==DEFAULT_SKY && mode&RAY_SKIPSKY)
- {
- if(mode&RAY_SKYTEX) return radius;
- }
- else return dist+max(enterdist+0.1f, 0.0f);
+ return dist+max(enterdist+0.1f, 0.0f);
}
}
}
@@ -385,11 +377,7 @@ float shadowray(ShadowRayCache *cache, const vec &o, const vec &ray, float radiu
{
if(isentirelysolid(c))
{
- if(c.texture[side]==DEFAULT_SKY && mode&RAY_SKIPSKY)
- {
- if(mode&RAY_SKYTEX) return radius;
- }
- else return dist;
+ return dist;
}
else
{
@@ -399,11 +387,7 @@ float shadowray(ShadowRayCache *cache, const vec &o, const vec &ray, float radiu
INTERSECTBOX(side = (i<<1) + 1 - lsizemask[i], goto nextcube);
if(exitdist >= 0)
{
- if(c.texture[side]==DEFAULT_SKY && mode&RAY_SKIPSKY)
- {
- if(mode&RAY_SKYTEX) return radius;
- }
- else return dist+max(enterdist+0.1f, 0.0f);
+ return dist+max(enterdist+0.1f, 0.0f);
}
}
}
@@ -1399,7 +1383,7 @@ bool move(physent *d, vec &dir)
return !collided;
}
-bool bounce(physent *d, float secs, float elasticity, float waterfric, float grav)
+bool bounce(physent *d, float secs, float elasticity, float grav)
{
// make sure bouncers don't start inside geometry
if(d->physstate!=PHYS_BOUNCE && collide(d, vec(0, 0, 0), 0, false)) return true;
@@ -1552,7 +1536,7 @@ FVAR(straferoll, 0, 0.033f, 90);
FVAR(faderoll, 0, 0.95f, 1);
VAR(floatspeed, 1, 100, 10000);
-void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curtime)
+void modifyvelocity(physent *pl, bool local, bool floating, int curtime)
{
bool allowmove = game::allowmove(pl);
if(floating)
@@ -1563,17 +1547,16 @@ void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curt
pl->vel.z = max(pl->vel.z, JUMPVEL);
}
}
- else if(pl->physstate >= PHYS_SLOPE || water)
+ else if(pl->physstate >= PHYS_SLOPE)
{
- if(water && !pl->inwater) pl->vel.div(8);
+ if(!pl->inwater) pl->vel.div(8);
if(pl->jumping && allowmove)
{
pl->jumping = false;
pl->vel.z = max(pl->vel.z, JUMPVEL); // physics impulse upwards
- if(water) { pl->vel.x /= 8.0f; pl->vel.y /= 8.0f; } // dampen velocity change even harder, gives correct water feel
- game::physicstrigger(pl, local, 1, 0);
+ game::physicstrigger(pl, local, 1);
}
}
if(!floating && pl->physstate == PHYS_FALL) pl->timeinair = min(pl->timeinair + curtime, 1000);
@@ -1581,16 +1564,10 @@ void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curt
vec m(0.0f, 0.0f, 0.0f);
if((pl->move || pl->strafe) && allowmove)
{
- vecfromyawpitch(pl->yaw, floating || water || pl->type==ENT_CAMERA ? pl->pitch : 0, pl->move, pl->strafe, m);
+ vecfromyawpitch(pl->yaw, floating || pl->type==ENT_CAMERA ? pl->pitch : 0, pl->move, pl->strafe, m);
if(!floating && pl->physstate >= PHYS_SLOPE)
- {
- /* move up or down slopes in air
- * but only move up slopes in water
- */
- float dz = -(m.x*pl->floor.x + m.y*pl->floor.y)/pl->floor.z;
- m.z = water ? max(m.z, dz) : dz;
- }
+ m.z = -(m.x*pl->floor.x + m.y*pl->floor.y)/pl->floor.z; // move up or down slopes in air
m.normalize();
}
@@ -1606,17 +1583,13 @@ void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curt
{
if(pl==player) d.mul(floatspeed/100.0f);
}
- else if(!water && allowmove) d.mul((pl->move && !pl->strafe ? 1.3f : 1.0f) * (pl->physstate < PHYS_SLOPE ? 1.3f : 1.0f));
+ else if(allowmove) d.mul((pl->move && !pl->strafe ? 1.3f : 1.0f) * (pl->physstate < PHYS_SLOPE ? 1.3f : 1.0f));
}
- float fric = water && !floating ? 20.0f : (pl->physstate >= PHYS_SLOPE || floating ? 6.0f : 30.0f);
+ float fric = !floating ? 20.0f : (pl->physstate >= PHYS_SLOPE || floating ? 6.0f : 30.0f);
pl->vel.lerp(d, pl->vel, pow(1 - 1/fric, curtime/20.0f));
-// old fps friction
-// float friction = water && !floating ? 20.0f : (pl->physstate >= PHYS_SLOPE || floating ? 6.0f : 30.0f);
-// float fpsfric = min(curtime/(20.0f*friction), 1.0f);
-// pl->vel.lerp(pl->vel, d, fpsfric);
}
-void modifygravity(physent *pl, bool water, int curtime)
+void modifygravity(physent *pl, int curtime)
{
float secs = curtime/1000.0f;
vec g(0, 0, 0);
@@ -1628,12 +1601,12 @@ void modifygravity(physent *pl, bool water, int curtime)
g.normalize();
g.mul(GRAVITY*secs);
}
- if(!water || !game::allowmove(pl) || (!pl->move && !pl->strafe)) pl->falling.add(g);
+ if(!game::allowmove(pl) || (!pl->move && !pl->strafe)) pl->falling.add(g);
- if(water || pl->physstate >= PHYS_SLOPE)
+ if(pl->physstate >= PHYS_SLOPE)
{
- float fric = water ? 2.0f : 6.0f,
- c = water ? 1.0f : clamp((pl->floor.z - SLOPEZ)/(FLOORZ-SLOPEZ), 0.0f, 1.0f);
+ float fric = 6.0f,
+ c = clamp((pl->floor.z - SLOPEZ)/(FLOORZ-SLOPEZ), 0.0f, 1.0f);
pl->falling.mul(pow(1 - c/fric, curtime/20.0f));
}
}
@@ -1649,12 +1622,12 @@ bool moveplayer(physent *pl, int moveres, bool local, int curtime)
float secs = curtime/1000.f;
// apply gravity
- if(!floating) modifygravity(pl, water, curtime);
+ if(!floating) modifygravity(pl, curtime);
// apply any player generated changes in velocity
- modifyvelocity(pl, local, water, floating, curtime);
+ modifyvelocity(pl, local, floating, curtime);
vec d(pl->vel);
- if(!floating && water) d.mul(0.5f);
+ if(!floating) d.mul(0.5f);
d.add(pl->falling);
d.mul(secs);
@@ -1678,9 +1651,9 @@ bool moveplayer(physent *pl, int moveres, bool local, int curtime)
d.mul(f);
loopi(moveres) if(!move(pl, d) && ++collisions<5) i--; // discrete steps collision detection & sliding
- if(timeinair > 800 && !pl->timeinair && !water) // if we land after long time must have been a high jump, make thud sound
+ if(timeinair > 800 && !pl->timeinair) // if we land after long time must have been a high jump, make thud sound
{
- game::physicstrigger(pl, local, -1, 0);
+ game::physicstrigger(pl, local, -1);
}
}
@@ -1691,8 +1664,8 @@ bool moveplayer(physent *pl, int moveres, bool local, int curtime)
if(pl->strafe && maxroll) pl->roll = clamp(pl->roll - pow(clamp(1.0f + pl->strafe*pl->roll/maxroll, 0.0f, 1.0f), 0.33f)*pl->strafe*curtime*straferoll, -maxroll, maxroll);
else pl->roll *= curtime == PHYSFRAMETIME ? faderoll : pow(faderoll, curtime/float(PHYSFRAMETIME));
- if(pl->inwater) game::physicstrigger(pl, local, 0, 1, pl->inwater);
- pl->inwater = water ? material&MATF_VOLUME : MAT_AIR;
+ if(pl->inwater) game::physicstrigger(pl, local, 0, pl->inwater);
+ pl->inwater = MAT_AIR;
if(pl->state==CS_ALIVE && (pl->o.z < 0 || material&MAT_DEATH)) game::suicide(pl);
@@ -1748,7 +1721,7 @@ void moveplayer(physent *pl, int moveres, bool local)
}
}
-bool bounce(physent *d, float elasticity, float waterfric, float grav)
+bool bounce(physent *d, float elasticity, float grav)
{
if(physsteps <= 0)
{
@@ -1760,10 +1733,10 @@ bool bounce(physent *d, float elasticity, float waterfric, float grav)
bool hitplayer = false;
loopi(physsteps-1)
{
- if(bounce(d, physframetime/1000.0f, elasticity, waterfric, grav)) hitplayer = true;
+ if(bounce(d, physframetime/1000.0f, elasticity, grav)) hitplayer = true;
}
d->deltapos = d->o;
- if(bounce(d, physframetime/1000.0f, elasticity, waterfric, grav)) hitplayer = true;
+ if(bounce(d, physframetime/1000.0f, elasticity, grav)) hitplayer = true;
d->newpos = d->o;
d->deltapos.sub(d->newpos);
interppos(d);