OBT/1.0.14
Fixed parallelism count issue Added SingleThreadWorker to handle single-thread related works Fixed incorrect order when updating gaps Potentially Fixed #39
This commit is contained in:
@@ -812,7 +812,11 @@ namespace Barotrauma
|
|||||||
if (outsideCollisionBlocker == null) { return false; }
|
if (outsideCollisionBlocker == null) { return false; }
|
||||||
if (IsRoomToRoom || Submarine == null || open <= 0.0f || linkedTo.Count == 0 || linkedTo[0] is not Hull)
|
if (IsRoomToRoom || Submarine == null || open <= 0.0f || linkedTo.Count == 0 || linkedTo[0] is not Hull)
|
||||||
{
|
{
|
||||||
outsideCollisionBlocker.AddToDisableQueue();
|
SingleThreadWorker.GlobalWorker.AddAction(() =>
|
||||||
|
{
|
||||||
|
outsideCollisionBlocker.Enabled = false;
|
||||||
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -681,12 +681,12 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
// if crashed, go ask the god damn physics engine :(
|
// if crashed, go ask the god damn physics engine :(
|
||||||
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 =>
|
Parallel.ForEach(shuffledGaps, parallelOptions, gap =>
|
||||||
{
|
{
|
||||||
gap.ResetWaterFlowThisFrame();
|
gap.ResetWaterFlowThisFrame();
|
||||||
gap.Update(deltaTime, cam);
|
gap.Update(deltaTime, cam);
|
||||||
});
|
});
|
||||||
FarseerPhysics.Dynamics.Body.QueueDisable();
|
SingleThreadWorker.GlobalWorker.RunActions();
|
||||||
},
|
},
|
||||||
// Powered components update
|
// Powered components update
|
||||||
() =>
|
() =>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private static readonly ParallelOptions parallelOptions = new ParallelOptions
|
private static readonly ParallelOptions parallelOptions = new ParallelOptions
|
||||||
{
|
{
|
||||||
MaxDegreeOfParallelism = Environment.ProcessorCount > 0 ? Environment.ProcessorCount * 2 : 16,
|
MaxDegreeOfParallelism = Math.Max(4, Environment.ProcessorCount - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
@@ -287,6 +287,7 @@ namespace Barotrauma
|
|||||||
Ragdoll.UpdateAll((float)deltaTime, cam);
|
Ragdoll.UpdateAll((float)deltaTime, cam);
|
||||||
#elif SERVER
|
#elif SERVER
|
||||||
Ragdoll.UpdateAll((float)deltaTime, Camera.Instance);
|
Ragdoll.UpdateAll((float)deltaTime, Camera.Instance);
|
||||||
|
SingleThreadWorker.GlobalWorker.RunActions();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
@@ -295,7 +296,7 @@ namespace Barotrauma
|
|||||||
sw.Restart();
|
sw.Restart();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
foreach(Submarine sub in submarines)
|
foreach (Submarine sub in submarines)
|
||||||
{
|
{
|
||||||
sub.Update((float)deltaTime);
|
sub.Update((float)deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
public class SingleThreadWorker
|
||||||
|
{
|
||||||
|
private ConcurrentQueue<Action> ActionQueue;
|
||||||
|
|
||||||
|
public static SingleThreadWorker GlobalWorker = new SingleThreadWorker();
|
||||||
|
|
||||||
|
public SingleThreadWorker()
|
||||||
|
{
|
||||||
|
ActionQueue = new ConcurrentQueue<Action>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddAction(Action action)
|
||||||
|
{
|
||||||
|
ActionQueue.Enqueue(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
public void RunActions()
|
||||||
|
{
|
||||||
|
while (ActionQueue.TryDequeue(out Action action))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Just try-catch and do nothing but print errorlogs. We cannot afford crashing the game.
|
||||||
|
ConsoleColor originalForeground = Console.ForegroundColor;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"WARNING: Error occurred when running Single Thread Actions \n{e}");
|
||||||
|
Console.ForegroundColor = Console.ForegroundColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -350,20 +350,6 @@ namespace FarseerPhysics.Dynamics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConcurrentQueue<Body> DisableQueue = new ConcurrentQueue<Body>();
|
|
||||||
|
|
||||||
public static void QueueDisable()
|
|
||||||
{
|
|
||||||
while (DisableQueue.TryDequeue(out var pendingbody))
|
|
||||||
{
|
|
||||||
pendingbody.Enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddToDisableQueue()
|
|
||||||
{
|
|
||||||
DisableQueue.Enqueue(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create all proxies.
|
/// Create all proxies.
|
||||||
|
|||||||
Reference in New Issue
Block a user