Merge pull request #17 from NotAlwaysTrue/revert-16-master-fix

Revert back to 1.0.3
This commit is contained in:
NotAlwaysTrue
2025-12-27 15:35:07 +08:00
committed by GitHub
5 changed files with 78 additions and 57 deletions
@@ -37,10 +37,6 @@ namespace Barotrauma
{ {
get { return PhysicsBody.List.Count; } get { return PhysicsBody.List.Count; }
} }
public int ConnectClients
{
get { return Client.ClientList.Count; }
}
public double RealTickRate public double RealTickRate
{ {
@@ -164,7 +160,6 @@ namespace Barotrauma
return $"Server Performence Info \n" + return $"Server Performence Info \n" +
$"Item Count: {ItemCount}\n" + $"Item Count: {ItemCount}\n" +
$"Character Count: {CharacterCount}\n" + $"Character Count: {CharacterCount}\n" +
$"Clients Count {ConnectClients}\n " +
$"PhysicsBody Count: {PhysicsBodyCount}\n" + $"PhysicsBody Count: {PhysicsBodyCount}\n" +
$"Tick Rate: {RealTickRate}\n" + $"Tick Rate: {RealTickRate}\n" +
$"Min Tick Rate: {TickRateLow}\n" + $"Min Tick Rate: {TickRateLow}\n" +
@@ -64,7 +64,7 @@ namespace Barotrauma
GameMain.ShouldRun = false; GameMain.ShouldRun = false;
}; };
#endif #endif
Console.WriteLine("Barotrauma Dedicated Server(EP) " + GameMain.Version + Console.WriteLine("Barotrauma Dedicated Server " + GameMain.Version +
" (" + AssemblyInfo.BuildString + ", branch " + AssemblyInfo.GitBranch + ", revision " + AssemblyInfo.GitRevision + ")"); " (" + AssemblyInfo.BuildString + ", branch " + AssemblyInfo.GitBranch + ", revision " + AssemblyInfo.GitRevision + ")");
if (Console.IsOutputRedirected) if (Console.IsOutputRedirected)
{ {
@@ -479,7 +479,7 @@ namespace Barotrauma
{ {
foreach (Fixture fixture in triggerBody.FarseerBody.FixtureList) foreach (Fixture fixture in triggerBody.FarseerBody.FixtureList)
{ {
ContactEdge contactEdge = fixture.Body.ContactList == null ? null: fixture.Body.ContactList.CreateCopy(); ContactEdge contactEdge = fixture.Body.ContactList.CreateCopy();
while (contactEdge != null) while (contactEdge != null)
{ {
if (contactEdge.Contact != null && if (contactEdge.Contact != null &&
@@ -642,34 +642,44 @@ namespace Barotrauma
/// </summary> /// </summary>
public static void UpdateAll(float deltaTime, Camera cam , ParallelOptions parallelOptions) public static void UpdateAll(float deltaTime, Camera cam , ParallelOptions parallelOptions)
{ {
mapEntityUpdateTick++;
#if CLIENT #if CLIENT
var sw = new System.Diagnostics.Stopwatch(); var sw = new System.Diagnostics.Stopwatch();
sw.Start(); sw.Start();
#endif #endif
bool shouldUpdateMapEntities = mapEntityUpdateTick % MapEntityUpdateInterval == 0;
bool shouldUpdatePower = mapEntityUpdateTick % PoweredUpdateInterval == 0;
// Buffer lists to avoid repeated allocations // Buffer lists to avoid repeated allocations
var hullList = Hull.HullList.ToList(); var hullList = shouldUpdateMapEntities ? Hull.HullList.ToList() : null;
var structureList = Structure.WallList.ToList(); var structureList = shouldUpdateMapEntities ? Structure.WallList.ToList() : null;
var gapList = Gap.GapList.ToList(); var gapList = Gap.GapList.ToList();
var itemList = Item.ItemList.ToList(); var itemList = shouldUpdateMapEntities ? Item.ItemList.ToList() : null;
// First phase: parallel updates that have no order dependencies // First phase: parallel updates that have no order dependencies
Parallel.Invoke(parallelOptions, Parallel.Invoke(parallelOptions,
// Hull parallel update // Hull parallel update
() => () =>
{ {
Parallel.ForEach(hullList, parallelOptions, hull => if (shouldUpdateMapEntities && hullList != null)
{ {
hull.Update(deltaTime, cam); Parallel.ForEach(hullList, parallelOptions, hull =>
}); {
hull.Update(deltaTime * MapEntityUpdateInterval, cam);
});
}
}, },
// Structure parallel update // Structure parallel update
() => () =>
{ {
Parallel.ForEach(structureList, parallelOptions, structure => if (shouldUpdateMapEntities && structureList != null)
{ {
structure.Update(deltaTime, cam); Parallel.ForEach(structureList, parallelOptions, structure =>
}); {
structure.Update(deltaTime * MapEntityUpdateInterval, cam);
});
}
}, },
// Gap reset (must be done before update) // Gap reset (must be done before update)
() => () =>
@@ -682,21 +692,27 @@ namespace Barotrauma
// Powered components update // Powered components update
() => () =>
{ {
Powered.UpdatePower(deltaTime); if (shouldUpdatePower)
{
Powered.UpdatePower(deltaTime * PoweredUpdateInterval);
}
} }
); );
#if CLIENT #if CLIENT
// Hull Cheats need to be executed after Hull update // Hull Cheats need to be executed after Hull update
Hull.UpdateCheats(deltaTime, cam); if (shouldUpdateMapEntities)
{
Hull.UpdateCheats(deltaTime * MapEntityUpdateInterval, cam);
}
#endif #endif
// Gap update (has order dependencies, keep random order but execute sequentially) // Gap update (has order dependencies, keep random order but execute sequentially)
var shuffledGaps = gapList.OrderBy(g => Rand.Int(int.MaxValue)).ToList(); var shuffledGaps = gapList.OrderBy(g => Rand.Int(int.MaxValue)).ToList();
Parallel.ForEach(gapList, parallelOptions, gap => foreach (Gap gap in shuffledGaps)
{ {
gap.Update(deltaTime, cam); gap.Update(deltaTime, cam);
}); }
#if CLIENT #if CLIENT
sw.Stop(); sw.Stop();
@@ -705,30 +721,33 @@ namespace Barotrauma
#endif #endif
// Item update (Item.Update() is not thread-safe and must be executed on the main thread) // Item update (Item.Update() is not thread-safe and must be executed on the main thread)
Item.UpdatePendingConditionUpdates(deltaTime); if (shouldUpdateMapEntities && itemList != null)
float scaledDeltaTime = deltaTime * MapEntityUpdateInterval;
Item lastUpdatedItem = null;
try
{ {
foreach (Item item in itemList) Item.UpdatePendingConditionUpdates(deltaTime);
float scaledDeltaTime = deltaTime * MapEntityUpdateInterval;
Item lastUpdatedItem = null;
try
{ {
lastUpdatedItem = item; foreach (Item item in itemList)
item.Update(scaledDeltaTime, cam); {
lastUpdatedItem = item;
item.Update(scaledDeltaTime, cam);
}
}
catch (InvalidOperationException e)
{
GameAnalyticsManager.AddErrorEventOnce(
"MapEntity.UpdateAll:ItemUpdateInvalidOperation",
GameAnalyticsManager.ErrorSeverity.Critical,
$"Error while updating item {lastUpdatedItem?.Name ?? "null"}: {e.Message}");
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
} }
}
catch (InvalidOperationException e)
{
GameAnalyticsManager.AddErrorEventOnce(
"MapEntity.UpdateAll:ItemUpdateInvalidOperation",
GameAnalyticsManager.ErrorSeverity.Critical,
$"Error while updating item {lastUpdatedItem?.Name ?? "null"}: {e.Message}");
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
}
UpdateAllProjSpecific(scaledDeltaTime); UpdateAllProjSpecific(scaledDeltaTime);
Spawner?.Update(); Spawner?.Update();
}
#if CLIENT #if CLIENT
sw.Stop(); sw.Stop();
@@ -7,7 +7,6 @@ using FarseerPhysics;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System;
#if DEBUG && CLIENT #if DEBUG && CLIENT
@@ -25,7 +24,7 @@ namespace Barotrauma
private static readonly ParallelOptions parallelOptions = new ParallelOptions private static readonly ParallelOptions parallelOptions = new ParallelOptions
{ {
MaxDegreeOfParallelism = Environment.ProcessorCount * 2, MaxDegreeOfParallelism = 16
}; };
#if CLIENT #if CLIENT
@@ -152,23 +151,31 @@ namespace Barotrauma
var physicsBodies = PhysicsBody.List.ToList(); var physicsBodies = PhysicsBody.List.ToList();
Parallel.ForEach(physicsBodies, parallelOptions, body => Parallel.Invoke(parallelOptions,
{ () =>
if ((body.Enabled || body.UserData is Character) &&
body.BodyType != BodyType.Static)
{ {
body.Update(); Parallel.ForEach(physicsBodies, parallelOptions, body =>
{
if ((body.Enabled || body.UserData is Character) &&
body.BodyType != BodyType.Static)
{
body.Update();
}
});
},
() =>
{
GameMain.GameSession?.Update((float)deltaTime);
} }
}); );
GameMain.GameSession?.Update((float)deltaTime);
Parallel.ForEach(physicsBodies, parallelOptions, body => foreach (PhysicsBody body in physicsBodies)
{ {
if (body.Enabled && body.BodyType != BodyType.Static) if (body.Enabled && body.BodyType != BodyType.Static)
{ {
body.SetPrevTransform(body.SimPosition, body.Rotation); body.SetPrevTransform(body.SimPosition, body.Rotation);
} }
}); }
MapEntity.ClearHighlightedEntities(); MapEntity.ClearHighlightedEntities();
@@ -245,14 +252,14 @@ namespace Barotrauma
Character.Controlled?.UpdateLocalCursor(cam); Character.Controlled?.UpdateLocalCursor(cam);
#elif SERVER #elif SERVER
Parallel.Invoke(parallelOptions, if (Level.Loaded != null)
() => { if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime, Camera.Instance); }, {
() => Character.UpdateAll((float)deltaTime, Camera.Instance) Level.Loaded.Update((float)deltaTime, Camera.Instance);
); }
Character.UpdateAll((float)deltaTime, Camera.Instance);
#endif #endif
var submarines = Submarine.Loaded.ToList(); var submarines = Submarine.Loaded.ToList();
Parallel.ForEach(submarines, parallelOptions, sub => Parallel.ForEach(submarines, parallelOptions, sub =>
{ {
sub.SetPrevTransform(sub.Position); sub.SetPrevTransform(sub.Position);
@@ -270,8 +277,8 @@ namespace Barotrauma
MapEntity.UpdateAll((float)deltaTime, cam, parallelOptions); MapEntity.UpdateAll((float)deltaTime, cam, parallelOptions);
#elif SERVER #elif SERVER
MapEntity.UpdateAll((float)deltaTime, Camera.Instance, parallelOptions);
MapEntity.UpdateAll((float)deltaTime, Camera.Instance, parallelOptions);
//StatusEffect.UpdateAll is not thread-safe and must be executed on the main thread //StatusEffect.UpdateAll is not thread-safe and must be executed on the main thread
StatusEffect.UpdateAll((float)deltaTime); StatusEffect.UpdateAll((float)deltaTime);