Fix to oxygen distribution logic: gaps used to move a fixed amount of oxygen between hulls every frame, causing the oxygen levels to fluctuate constantly. While it wasn't noticeable in regular sized hulls, smaller hulls created excessive amounts of NetworkEvents due to large fluctuations in the oxygen percentage.

Now the gaps make the oxygen percentages settle to the average value, and hulls have a minimum delay of 0.5s between the creation of NetworkEvents.
This commit is contained in:
Regalis
2017-04-18 21:37:23 +03:00
parent f407a38c9e
commit 92a74808fe
2 changed files with 20 additions and 10 deletions

View File

@@ -629,9 +629,12 @@ namespace Barotrauma
float totalOxygen = hull1.Oxygen + hull2.Oxygen;
float totalVolume = (hull1.FullVolume + hull2.FullVolume);
float deltaOxygen = (totalOxygen * hull1.FullVolume / totalVolume) - hull1.Oxygen;
deltaOxygen = MathHelper.Clamp(deltaOxygen, -Hull.OxygenDistributionSpeed, Hull.OxygenDistributionSpeed);
hull1.Oxygen += Math.Sign(totalOxygen * hull1.FullVolume / (totalVolume) - hull1.Oxygen) * Hull.OxygenDistributionSpeed;
hull2.Oxygen += Math.Sign(totalOxygen * hull2.FullVolume / (totalVolume) - hull2.Oxygen) * Hull.OxygenDistributionSpeed;
hull1.Oxygen += deltaOxygen;
hull2.Oxygen -= deltaOxygen;
}
public static Gap FindAdjacent(List<Gap> gaps, Vector2 worldPos, float allowedOrthogonalDist)

View File

@@ -15,6 +15,8 @@ namespace Barotrauma
class Hull : MapEntity, IPropertyObject, IServerSerializable
{
const float NetworkUpdateInterval = 0.5f;
public static List<Hull> hullList = new List<Hull>();
private static List<EntityGrid> entityGrids = new List<EntityGrid>();
public static List<EntityGrid> EntityGrids
@@ -74,7 +76,7 @@ namespace Barotrauma
float[] rightDelta;
private float lastSentVolume, lastSentOxygen;
private float lastNetworkUpdate;
private float sendUpdateTimer;
public List<Gap> ConnectedGaps;
@@ -361,8 +363,6 @@ namespace Barotrauma
entityGrid.RemoveEntity(this);
}
}
}
public void AddFireSource(FireSource fireSource)
@@ -460,7 +460,17 @@ namespace Barotrauma
if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f ||
Math.Abs(lastSentOxygen - OxygenPercentage) > 5f)
{
if (GameMain.Server != null) GameMain.Server.CreateEntityEvent(this);
if (GameMain.Server != null)
{
sendUpdateTimer -= deltaTime;
if (sendUpdateTimer < 0.0f)
{
GameMain.Server.CreateEntityEvent(this);
lastSentVolume = volume;
lastSentOxygen = OxygenPercentage;
sendUpdateTimer = NetworkUpdateInterval;
}
}
}
if (!update)
@@ -622,7 +632,7 @@ namespace Barotrauma
isHighlighted ? Color.LightBlue * 0.5f : Color.Red * 0.5f, true, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
}
}
public void Render(GraphicsDevice graphicsDevice, Camera cam)
{
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
@@ -842,9 +852,6 @@ namespace Barotrauma
message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8);
}
}
lastSentVolume = volume;
lastSentOxygen = OxygenPercentage;
}
public void ClientRead(ServerNetObject type, NetBuffer message, float sendingTime)