From 13fcf6f16696bf08509b7dd7857fe7e4cf0fb4c0 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Mon, 25 Mar 2019 10:58:07 -0300 Subject: [PATCH] (27eca7ad9) Some network optimization: - Don't create network events for hulls that are very far from all clients (e.g. ruin hulls). - Don't create network events for triggers that are set to limit the triggerer's velocity when there are no triggerers. --- Barotrauma/BarotraumaServer/Source/Map/Hull.cs | 10 ++++++++++ .../Source/Map/Levels/LevelObjects/LevelTrigger.cs | 14 +++++++++----- .../Source/Networking/NetConfig.cs | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaServer/Source/Map/Hull.cs b/Barotrauma/BarotraumaServer/Source/Map/Hull.cs index 5f9257b42..3b10a7a24 100644 --- a/Barotrauma/BarotraumaServer/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaServer/Source/Map/Hull.cs @@ -20,6 +20,16 @@ namespace Barotrauma partial void UpdateProjSpecific(float deltaTime, Camera cam) { if (IdFreed) { return; } + + //don't create updates if all clients are very far from the hull + float hullUpdateDistanceSqr = NetConfig.HullUpdateDistance * NetConfig.HullUpdateDistance; + if (!GameMain.Server.ConnectedClients.Any(c => + c.Character != null && + Vector2.DistanceSquared(c.Character.WorldPosition, WorldPosition) < hullUpdateDistanceSqr)) + { + return; + } + //update client hulls if the amount of water has changed by >10% //or if oxygen percentage has changed by 5% if (Math.Abs(lastSentVolume - waterVolume) > Volume * 0.1f || diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs index 83033e604..1c3ec2339 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs @@ -432,12 +432,16 @@ namespace Barotrauma { if (ForceFluctuationStrength > 0.0f) { - forceFluctuationTimer += deltaTime; - if (forceFluctuationTimer > ForceFluctuationInterval) + //no need for force fluctuation (or network updates) if the trigger limits velocity and there are no triggerers + if (forceMode != TriggerForceMode.LimitVelocity || triggerers.Any()) { - NeedsNetworkSyncing = true; - currentForceFluctuation = Rand.Range(1.0f - ForceFluctuationStrength, 1.0f); - forceFluctuationTimer = 0.0f; + forceFluctuationTimer += deltaTime; + if (forceFluctuationTimer > ForceFluctuationInterval) + { + NeedsNetworkSyncing = true; + currentForceFluctuation = Rand.Range(1.0f - ForceFluctuationStrength, 1.0f); + forceFluctuationTimer = 0.0f; + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs index 219b4d55e..74b6afcb2 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs @@ -37,6 +37,7 @@ namespace Barotrauma.Networking public const float ItemConditionUpdateInterval = 0.15f; public const float LevelObjectUpdateInterval = 0.5f; public const float HullUpdateInterval = 0.5f; + public const float HullUpdateDistance = 20000.0f; public const int MaxEventPacketsPerUpdate = 4;