Fixed #41/2

Removed min hard cap for MaxDegreeOfParallelism
This commit is contained in:
NotAlwaysTrue
2026-01-16 17:15:57 +08:00
parent e7e444e9b2
commit e24024cbb2
5 changed files with 14 additions and 7 deletions
@@ -25,7 +25,7 @@ namespace Barotrauma
private static readonly ParallelOptions parallelOptions = new ParallelOptions private static readonly ParallelOptions parallelOptions = new ParallelOptions
{ {
MaxDegreeOfParallelism = Math.Max(4,Environment.ProcessorCount - 1), MaxDegreeOfParallelism = Math.Max(1,Environment.ProcessorCount - 1),
}; };
#if CLIENT #if CLIENT
@@ -27,9 +27,10 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
*/ */
using System.Collections.Generic;
using FarseerPhysics.Collision; using FarseerPhysics.Collision;
using FarseerPhysics.Dynamics.Contacts; using FarseerPhysics.Dynamics.Contacts;
using System.Collections.Generic;
using System.Threading;
namespace FarseerPhysics.Dynamics namespace FarseerPhysics.Dynamics
{ {
@@ -61,6 +62,8 @@ namespace FarseerPhysics.Dynamics
public int CollideMultithreadThreshold = 64; public int CollideMultithreadThreshold = 64;
#endregion #endregion
// This will ensure only one thread will work on ContactList so that we wont mess up these stuff
private readonly SemaphoreSlim contactManagerSignal = new SemaphoreSlim(1);
/// <summary> /// <summary>
/// Fires when a contact is created /// Fires when a contact is created
@@ -249,6 +252,8 @@ namespace FarseerPhysics.Dynamics
internal void Destroy(Contact contact) internal void Destroy(Contact contact)
{ {
contactManagerSignal.Wait(100);
Fixture fixtureA = contact.FixtureA; Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB; Fixture fixtureB = contact.FixtureB;
Body bodyA = fixtureA.Body; Body bodyA = fixtureA.Body;
@@ -310,6 +315,8 @@ namespace FarseerPhysics.Dynamics
// Insert into the pool. // Insert into the pool.
contact.Next = _contactPoolList.Next; contact.Next = _contactPoolList.Next;
_contactPoolList.Next = contact; _contactPoolList.Next = contact;
contactManagerSignal.Release();
} }
internal void Collide() internal void Collide()
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Kastellanos Nikolaos // Copyright (c) 2017 Kastellanos Nikolaos
/* Original source Farseer Physics Engine: /* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com * Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com