Files
sbox-public/engine/Sandbox.Engine/Scene/GameObjectSystems/VerletRopeSystem.cs
Lorenz Junglas 453e16c1d6 Use load balanced partitioner in parallel for (#4132)
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>)
2026-02-23 21:19:01 +00:00

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 ) );
}
}