OBT/1.0.15
* Removed PF support again Fixed Object reference not set to an instance of an object exception in EnemyAIController.cs UpdateLimbAttack() * Reverted pervious fix on EnemyAIController bcuz the fix will not fix anything Reduced MaxDegreeOfParallelism by 1 bcuz already a task there * Re-removed all PF related stuff to fix issue Removed all RUN_PHYSICS_IN_SEPARATE_THREAD related code because these codes are no longer functional Removed a duplicated loop in GameScreen Removed mulitple unnessary parallel operations * Potentially fixed #44 and #43 * added a ToList for Gap.GapList
This commit is contained in:
@@ -3387,21 +3387,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
characterUpdateTick++;
|
characterUpdateTick++;
|
||||||
|
|
||||||
if (characterUpdateTick % CharacterUpdateInterval == 0)
|
for (int i = 0; i < CharacterList.Count; i++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < CharacterList.Count; i++)
|
CharacterList[i].Update(deltaTime, cam);
|
||||||
{
|
|
||||||
if (GameMain.LuaCs.Game.UpdatePriorityCharacters.Contains(CharacterList[i])) continue;
|
|
||||||
|
|
||||||
CharacterList[i].Update(deltaTime * CharacterUpdateInterval, cam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Character character in GameMain.LuaCs.Game.UpdatePriorityCharacters)
|
|
||||||
{
|
|
||||||
if (character.Removed) { continue; }
|
|
||||||
Debug.Assert(character is { Removed: false });
|
|
||||||
character.Update(deltaTime, cam);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
|
|||||||
@@ -814,6 +814,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
SingleThreadWorker.GlobalWorker.AddAction(() =>
|
SingleThreadWorker.GlobalWorker.AddAction(() =>
|
||||||
{
|
{
|
||||||
|
if (outsideCollisionBlocker == null) { return; }
|
||||||
outsideCollisionBlocker.Enabled = false;
|
outsideCollisionBlocker.Enabled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -650,7 +650,8 @@ namespace Barotrauma
|
|||||||
// Buffer lists to avoid repeated allocations
|
// Buffer lists to avoid repeated allocations
|
||||||
var hullList = Hull.HullList.ToList();
|
var hullList = Hull.HullList.ToList();
|
||||||
var structureList = Structure.WallList.ToList();
|
var structureList = Structure.WallList.ToList();
|
||||||
var gapList = Gap.GapList.ToList();
|
// First, WHY THIS LINQ GOT A NULL ERROR? Second, WHY??
|
||||||
|
List<Gap> shuffledGaps = Gap.GapList?.OrderBy(g => Rand.Int(int.MaxValue)).ToList() ?? Gap.GapList.ToList();
|
||||||
var itemList = Item.ItemList.ToList();
|
var itemList = Item.ItemList.ToList();
|
||||||
|
|
||||||
// First phase: parallel updates that have no order dependencies
|
// First phase: parallel updates that have no order dependencies
|
||||||
@@ -679,14 +680,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
// moved waterflow reset here to see if we can reduce at least some time
|
// moved waterflow reset here to see if we can reduce at least some time
|
||||||
{
|
{
|
||||||
// if crashed, go ask the god damn physics engine :(
|
if (shuffledGaps == null) { shuffledGaps = Gap.GapList; }
|
||||||
var shuffledGaps = gapList.OrderBy(g => Rand.Int(int.MaxValue)).ToList();
|
|
||||||
Parallel.ForEach(shuffledGaps, parallelOptions, gap =>
|
Parallel.ForEach(shuffledGaps, parallelOptions, gap =>
|
||||||
{
|
{
|
||||||
gap.ResetWaterFlowThisFrame();
|
gap.ResetWaterFlowThisFrame();
|
||||||
gap.Update(deltaTime, cam);
|
gap.Update(deltaTime, cam);
|
||||||
});
|
});
|
||||||
SingleThreadWorker.GlobalWorker.RunActions();
|
|
||||||
},
|
},
|
||||||
// Powered components update
|
// Powered components update
|
||||||
() =>
|
() =>
|
||||||
@@ -695,6 +694,8 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SingleThreadWorker.GlobalWorker.RunActions();
|
||||||
|
|
||||||
#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);
|
Hull.UpdateCheats(deltaTime, cam);
|
||||||
@@ -709,7 +710,6 @@ namespace Barotrauma
|
|||||||
// 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);
|
Item.UpdatePendingConditionUpdates(deltaTime);
|
||||||
|
|
||||||
float scaledDeltaTime = deltaTime * MapEntityUpdateInterval;
|
|
||||||
Item lastUpdatedItem = null;
|
Item lastUpdatedItem = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -717,7 +717,7 @@ namespace Barotrauma
|
|||||||
foreach (Item item in itemList)
|
foreach (Item item in itemList)
|
||||||
{
|
{
|
||||||
lastUpdatedItem = item;
|
lastUpdatedItem = item;
|
||||||
item.Update(scaledDeltaTime, cam);
|
item.Update(deltaTime, cam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException e)
|
catch (InvalidOperationException e)
|
||||||
@@ -729,7 +729,7 @@ namespace Barotrauma
|
|||||||
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
|
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateAllProjSpecific(scaledDeltaTime);
|
UpdateAllProjSpecific(deltaTime);
|
||||||
Spawner?.Update();
|
Spawner?.Update();
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
//#define RUN_PHYSICS_IN_SEPARATE_THREAD
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using FarseerPhysics.Dynamics;
|
using FarseerPhysics.Dynamics;
|
||||||
using FarseerPhysics;
|
using FarseerPhysics;
|
||||||
@@ -23,9 +21,10 @@ namespace Barotrauma
|
|||||||
private object updateLock = new object();
|
private object updateLock = new object();
|
||||||
private double physicsTime;
|
private double physicsTime;
|
||||||
|
|
||||||
|
// -2 here bcuz we alread have a SEEM thread there
|
||||||
private static readonly ParallelOptions parallelOptions = new ParallelOptions
|
private static readonly ParallelOptions parallelOptions = new ParallelOptions
|
||||||
{
|
{
|
||||||
MaxDegreeOfParallelism = Math.Max(4, Environment.ProcessorCount - 1)
|
MaxDegreeOfParallelism = Math.Max(4, Environment.ProcessorCount - 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
@@ -78,14 +77,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
MapEntity.ClearHighlightedEntities();
|
MapEntity.ClearHighlightedEntities();
|
||||||
|
|
||||||
#if RUN_PHYSICS_IN_SEPARATE_THREAD
|
|
||||||
var physicsThread = new Thread(ExecutePhysics)
|
|
||||||
{
|
|
||||||
Name = "Physics thread",
|
|
||||||
IsBackground = true
|
|
||||||
};
|
|
||||||
physicsThread.Start();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Deselect()
|
public override void Deselect()
|
||||||
@@ -114,15 +105,11 @@ namespace Barotrauma
|
|||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var submarines = Submarine.Loaded.ToList();
|
||||||
|
var physicsBodies = PhysicsBody.List.ToList();
|
||||||
|
|
||||||
#warning For now CL side performance counter is partly useless bucz multiple changes on such things. Need time to take care of it
|
#warning For now CL side performance counter is partly useless bucz multiple changes on such things. Need time to take care of it
|
||||||
|
|
||||||
#if RUN_PHYSICS_IN_SEPARATE_THREAD
|
|
||||||
physicsTime += deltaTime;
|
|
||||||
lock (updateLock)
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG && CLIENT
|
#if DEBUG && CLIENT
|
||||||
if (GameMain.GameSession != null && !DebugConsole.IsOpen && GUI.KeyboardDispatcher.Subscriber == null)
|
if (GameMain.GameSession != null && !DebugConsole.IsOpen && GUI.KeyboardDispatcher.Subscriber == null)
|
||||||
{
|
{
|
||||||
@@ -150,8 +137,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
GameTime += deltaTime;
|
GameTime += deltaTime;
|
||||||
|
|
||||||
var physicsBodies = PhysicsBody.List.ToList();
|
|
||||||
|
|
||||||
Parallel.ForEach(physicsBodies, parallelOptions, body =>
|
Parallel.ForEach(physicsBodies, parallelOptions, body =>
|
||||||
{
|
{
|
||||||
if ((body.Enabled || body.UserData is Character) &&
|
if ((body.Enabled || body.UserData is Character) &&
|
||||||
@@ -162,14 +147,6 @@ namespace Barotrauma
|
|||||||
});
|
});
|
||||||
GameMain.GameSession?.Update((float)deltaTime);
|
GameMain.GameSession?.Update((float)deltaTime);
|
||||||
|
|
||||||
Parallel.ForEach(physicsBodies, parallelOptions, body =>
|
|
||||||
{
|
|
||||||
if (body.Enabled && body.BodyType != BodyType.Static)
|
|
||||||
{
|
|
||||||
body.SetPrevTransform(body.SimPosition, body.Rotation);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
MapEntity.ClearHighlightedEntities();
|
MapEntity.ClearHighlightedEntities();
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
@@ -254,20 +231,19 @@ namespace Barotrauma
|
|||||||
StatusEffect.UpdateAll((float)deltaTime);
|
StatusEffect.UpdateAll((float)deltaTime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var submarines = Submarine.Loaded.ToList();
|
foreach (Submarine sub in submarines)
|
||||||
|
|
||||||
Parallel.ForEach(submarines, parallelOptions, sub =>
|
|
||||||
{
|
{
|
||||||
sub.SetPrevTransform(sub.Position);
|
sub.SetPrevTransform(sub.Position);
|
||||||
});
|
}
|
||||||
|
|
||||||
Parallel.ForEach(physicsBodies, parallelOptions, body =>
|
foreach (var body in physicsBodies)
|
||||||
{
|
{
|
||||||
if (body.Enabled && body.BodyType != FarseerPhysics.BodyType.Static)
|
if (body.Enabled && body.BodyType != FarseerPhysics.BodyType.Static)
|
||||||
{
|
{
|
||||||
body.SetPrevTransform(body.SimPosition, body.Rotation);
|
body.SetPrevTransform(body.SimPosition, body.Rotation);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
MapEntity.UpdateAll((float)deltaTime, cam, parallelOptions);
|
MapEntity.UpdateAll((float)deltaTime, cam, parallelOptions);
|
||||||
@@ -306,8 +282,6 @@ namespace Barotrauma
|
|||||||
GameMain.PerformanceCounter.AddElapsedTicks("Update:Submarine", sw.ElapsedTicks);
|
GameMain.PerformanceCounter.AddElapsedTicks("Update:Submarine", sw.ElapsedTicks);
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !RUN_PHYSICS_IN_SEPARATE_THREAD
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameMain.World.Step((float)Timing.Step);
|
GameMain.World.Step((float)Timing.Step);
|
||||||
@@ -318,17 +292,12 @@ namespace Barotrauma
|
|||||||
DebugConsole.ThrowError(errorMsg, e);
|
DebugConsole.ThrowError(errorMsg, e);
|
||||||
GameAnalyticsManager.AddErrorEventOnce("GameScreen.Update:WorldLockedException" + e.Message, GameAnalyticsManager.ErrorSeverity.Critical, errorMsg);
|
GameAnalyticsManager.AddErrorEventOnce("GameScreen.Update:WorldLockedException" + e.Message, GameAnalyticsManager.ErrorSeverity.Critical, errorMsg);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
GameMain.PerformanceCounter.AddElapsedTicks("Update:Physics", sw.ElapsedTicks);
|
GameMain.PerformanceCounter.AddElapsedTicks("Update:Physics", sw.ElapsedTicks);
|
||||||
#endif
|
#endif
|
||||||
UpdateProjSpecific(deltaTime);
|
UpdateProjSpecific(deltaTime);
|
||||||
|
|
||||||
#if RUN_PHYSICS_IN_SEPARATE_THREAD
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void UpdateProjSpecific(double deltaTime);
|
partial void UpdateProjSpecific(double deltaTime);
|
||||||
|
|||||||
@@ -9,16 +9,27 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static SingleThreadWorker GlobalWorker = new SingleThreadWorker();
|
public static SingleThreadWorker GlobalWorker = new SingleThreadWorker();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initilize a SingleThreadWorker
|
||||||
|
/// SingleThreadWorker or STW for short is a FIFO queue ensure single-thread execution of a series of actions.
|
||||||
|
/// </summary>
|
||||||
public SingleThreadWorker()
|
public SingleThreadWorker()
|
||||||
{
|
{
|
||||||
ActionQueue = new ConcurrentQueue<Action>();
|
ActionQueue = new ConcurrentQueue<Action>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a pending action in a STW queue
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action"></param>
|
||||||
public void AddAction(Action action)
|
public void AddAction(Action action)
|
||||||
{
|
{
|
||||||
ActionQueue.Enqueue(action);
|
ActionQueue.Enqueue(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Run all pending actions in the STW queue
|
||||||
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public void RunActions()
|
public void RunActions()
|
||||||
{
|
{
|
||||||
@@ -32,8 +43,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
// Just try-catch and do nothing but print errorlogs. We cannot afford crashing the game.
|
// Just try-catch and do nothing but print errorlogs. We cannot afford crashing the game.
|
||||||
ConsoleColor originalForeground = Console.ForegroundColor;
|
ConsoleColor originalForeground = Console.ForegroundColor;
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine($"WARNING: Error occurred when running Single Thread Actions \n{e}");
|
Console.WriteLine($"WARNING: Error occurred when running Single Thread Actions. " +
|
||||||
|
$"If the server didn't crash or stop responding then this should be fine \n{e}");
|
||||||
Console.ForegroundColor = Console.ForegroundColor;
|
Console.ForegroundColor = Console.ForegroundColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user