Reduce perf hit of bullet trails by only spawning underwater bubbles actually underwater, instead of always spawning them and then relying on them despawning themselves after checking their own water level.

Further optimization could be possible if I found a way to divide the trace results into segments based on intersections with water volumes. This would save on countless calls to Vec3Offset and PointInSector. Something to keep in mind, I suppose.
While I was at it, I did make the underwater check into a new utility function. It is more or less based on how updating water level is done internally, but saves time by just checking a single point rather than an actor's full height.
Not sure if I'll need to use it elsewhere, but if that turns out to not be the case I'll change it to a private function of the SWWMBulletTrail class afterwards.
This commit is contained in:
Mari the Deer 2025-03-14 16:19:00 +01:00
commit 8d0a087e6c
3 changed files with 39 additions and 3 deletions

View file

@ -1,3 +1,3 @@
[default]
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r1198 \cu(vie 14 mar 2025 15:59:42 CET)\c-";
SWWM_SHORTVER="\cw1.3pre r1198 \cu(2025-03-14 15:59:42)\c-";
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r1200 \cu(vie 14 mar 2025 16:23:20 CET)\c-";
SWWM_SHORTVER="\cw1.3pre r1200 \cu(2025-03-14 16:23:20)\c-";

View file

@ -1400,11 +1400,18 @@ Class SWWMBulletTrail : LineTracer
b.target = target;
b.A_CheckTerrain();
}
Vector3 ppos;
SWWMAnimSprite b;
bool bInWater;
for ( int i=5; i<t.Results.Distance; i+=10 )
{
if ( Random[Boolet](0,bubblesparse) ) continue;
if ( !Random[Boolet](0,i/100) ) continue; // fall off w/ distance
let b = SWWMAnimSprite.SpawnAt(smoky?'SWWMHalfSmoke':'SWWMHalfBubble',level.Vec3Offset(pos,dir*i));
ppos = level.Vec3Offset(pos,dir*i);
bInWater = SWWMUtility.PointInWater(ppos);
if ( smoky && !bInWater ) b = SWWMAnimSprite.SpawnAt('SWWMHalfSmoke',ppos);
else if ( !smoky && bInWater ) b = SWWMAnimSprite.SpawnAt('SWWMHalfBubble',ppos);
else continue;
b.Scale *= FRandom[Boolet](.4,.6);
}
t.Destroy();

View file

@ -599,6 +599,35 @@ extend Class SWWMUtility
return HitNormal;
}
static bool PointInWater( Vector3 p )
{
Sector s = level.PointInSector(p.xy);
if ( s.moreflags&Sector.SECMF_UNDERWATER ) // check underwater sector
return true;
else if ( s.heightsec && (s.heightsec.moreflags&Sector.SECMF_UNDERWATERMASK) ) // check height transfer
{
let hsec = s.heightsec;
double fh = hsec.floorplane.ZAtPoint(p.xy);
if ( p.z <= fh )
return true;
if ( !(hsec.moreflags&Sector.SECMF_FAKEFLOORONLY) && (p.z > hsec.ceilingplane.ZAtPoint(p.xy)) )
return true;
}
else // check 3D floors
{
for ( int i=0; i<s.Get3DFloorCount(); i++ )
{
let ff = s.Get3DFloor(i);
if ( !(ff.flags&F3DFloor.FF_EXISTS) || (ff.flags&F3DFloor.FF_SOLID) || !(ff.flags&F3DFloor.FF_SWIMMABLE) ) continue;
double ff_bottom = ff.bottom.ZAtPoint(p.xy);
double ff_top = ff.top.ZAtPoint(p.xy);
if ( (ff_top <= p.z) || (ff_bottom > p.z) ) continue;
return true;
}
}
return false;
}
static bool, TextureID DefaceTexture( TextureID checkme )
{
String tn = TexMan.GetName(checkme);