mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-21 14:58:09 -04:00
Attempt to fix animation perf regression introduced by #4128 Parallel.ForEach(IList<T>) uses static range partitioning which may cause load imbalance on hybrid P/E-core CPUs. Use Partitioner.Create(list, loadBalance: true) instead to restore dynamic chunk stealing that aws already used when using Parallel.ForEach(IEnumerable<T>)
28 lines
747 B
C#
28 lines
747 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Simulates VerletRope components in parallel during PrePhysicsStep
|
|
/// </summary>
|
|
internal sealed class VerletRopeGameSystem : GameObjectSystem
|
|
{
|
|
private readonly List<VerletRope> _ropes = new();
|
|
|
|
public VerletRopeGameSystem( Scene scene ) : base( scene )
|
|
{
|
|
// Listen to StartFixedUpdate to run before physics
|
|
Listen( Stage.StartFixedUpdate, -100, UpdateRopes, "UpdateRopes" );
|
|
}
|
|
|
|
void UpdateRopes()
|
|
{
|
|
_ropes.Clear();
|
|
Scene.GetAll<VerletRope>( _ropes );
|
|
if ( _ropes.Count == 0 ) return;
|
|
|
|
var timeDelta = Time.Delta;
|
|
System.Threading.Tasks.Parallel.ForEach( Partitioner.Create( _ropes, loadBalance: true ), rope => rope.Simulate( timeDelta ) );
|
|
}
|
|
}
|