Skip to content

Commit 6584a62

Browse files
authored
Small Space Wind Optimization Hotfix (#1550)
# Description I realized only afterwards that there was another place I could have optimized this, by normalizing the throw vector before we iterate over every entity on the tile. Which significantly cuts down on what might otherwise be an internally very complicated step. # Changelog No changelog, this isn't player facing, just an optimizing hotfix.
1 parent 7428cd8 commit 6584a62

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmospher
105105
// Used by ExperiencePressureDifference to correct push/throw directions from tile-relative to physics world.
106106
var gridWorldRotation = _transformSystem.GetWorldRotation(gridAtmosphere);
107107

108+
// Atmos Directions only include NSEW cardinals, which means only 4 possible angles to throw at. If Monstermos is enabled, we'll instead do some
109+
// Vector shennanigans to smooth it out so that we can throw in increments of up to pi/32.
108110
var throwDirection = tile.PressureDirection.ToAngle().ToVec();
109-
// If we're using monstermos, smooth out the yeet direction to follow the flow
110111
if (MonstermosEqualization)
111112
foreach (var nextTile in tile.AdjacentTiles)
112113
if (nextTile is not null && nextTile.PressureDirection is not AtmosDirection.Invalid)
113114
throwDirection += nextTile.PressureDirection.ToAngle().ToVec();
114115

116+
// Before you ask, yes I did actually have to convert the angles to vectors, then add them together, then convert the end result back to a normalized vector.
117+
// We're normalizing this here and now so that we don't have to normalize it potentially hundreds of times during the next Foreach.
118+
var throwVector = (throwDirection.ToAngle() + gridWorldRotation).ToWorldVec().Normalized();
119+
115120
_entSet.Clear();
116121
_lookup.GetLocalEntitiesIntersecting(tile.GridIndex, tile.GridIndices, _entSet, 0f);
117122

@@ -131,8 +136,7 @@ private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmospher
131136
(entity, EnsureComp<MovedByPressureComponent>(entity)),
132137
gridAtmosphere.Comp.UpdateCounter,
133138
differentiatedPressure,
134-
throwDirection,
135-
gridWorldRotation,
139+
throwVector,
136140
xforms.GetComponent(entity),
137141
body);
138142
}
@@ -154,8 +158,7 @@ public void ExperiencePressureDifference(
154158
Entity<MovedByPressureComponent> ent,
155159
int cycle,
156160
float pressureDifference,
157-
Vector2 direction,
158-
Angle gridWorldRotation,
161+
Vector2 throwVector,
159162
TransformComponent? xform = null,
160163
PhysicsComponent? physics = null)
161164
{
@@ -171,11 +174,9 @@ public void ExperiencePressureDifference(
171174
if (pressureDifference < physics.Mass)
172175
return;
173176

174-
// Grid-rotation adjusted direction
175-
var dirVec = (direction.ToAngle() + gridWorldRotation).ToWorldVec();
176177
pressureDifference *= MathF.Max(physics.InvMass, SpaceWindMaximumCalculatedInverseMass);
177178

178-
_throwing.TryThrow(uid, dirVec.Normalized() * MathF.Min(pressureDifference, SpaceWindMaxVelocity), pressureDifference);
179+
_throwing.TryThrow(uid, throwVector * MathF.Min(pressureDifference, SpaceWindMaxVelocity), pressureDifference);
179180
component.LastHighPressureMovementAirCycle = cycle;
180181
}
181182
}

0 commit comments

Comments
 (0)