mirror of
https://github.com/stride3d/stride.git
synced 2026-10-12 02:23:23 +00:00
[Physics] fix: MaxStepPerFrame now bounds steps per frame, -1 no longer freezes the simulation
The guard `stepCount < MaxStepPerFrame || MaxStepPerFrame != -1` did not depend on stepCount: any cap other than -1 never bounded the loop, and -1 never ran a step. Fixes #3522 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
committed by
xen2
co-authored by
Claude Opus 5.5
parent
50a4cbeeab
commit
7d685e8b46
@@ -591,6 +591,21 @@ namespace Stride.BepuPhysics.Tests
|
||||
RunGameTest(game);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(3, 10, 3)]
|
||||
[InlineData(3, 2, 2)]
|
||||
[InlineData(-1, 10, 10)]
|
||||
public static void MaxStepPerFrameTest(int maxStepPerFrame, int pendingSteps, int expectedSteps)
|
||||
{
|
||||
using var simulation = new BepuSimulation { MaxStepPerFrame = maxStepPerFrame };
|
||||
int steps = 0;
|
||||
simulation.Register(new SimUpdateListener { SimUpdate = () => steps++ });
|
||||
|
||||
simulation.Update(simulation.FixedTimeStep * pendingSteps);
|
||||
|
||||
Assert.Equal(expectedSteps, steps);
|
||||
}
|
||||
|
||||
private class SimUpdateListener : ScriptComponent, ISimulationUpdate
|
||||
{
|
||||
public Action? SimUpdate, AfterSimUpdate;
|
||||
|
||||
@@ -731,7 +731,7 @@ public sealed class BepuSimulation : IDisposable
|
||||
// TimeSpan multiplication is lossy, skipping mult when we can
|
||||
_remainingUpdateTime += TimeScale == 1f ? elapsed : elapsed * TimeScale;
|
||||
|
||||
for (int stepCount = 0; _remainingUpdateTime >= FixedTimeStep && (stepCount < MaxStepPerFrame || MaxStepPerFrame != -1); stepCount++, _remainingUpdateTime -= FixedTimeStep)
|
||||
for (int stepCount = 0; _remainingUpdateTime >= FixedTimeStep && (MaxStepPerFrame == -1 || stepCount < MaxStepPerFrame); stepCount++, _remainingUpdateTime -= FixedTimeStep)
|
||||
{
|
||||
if (_softStartScheduled)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Stride.Core.Reflection;
|
||||
[assembly: InternalsVisibleTo("Stride.BepuPhysics.Debug")]
|
||||
[assembly: InternalsVisibleTo("Stride.BepuPhysics.Navigation")]
|
||||
[assembly: InternalsVisibleTo("Stride.BepuPhysics.Soft")]
|
||||
[assembly: InternalsVisibleTo("Stride.BepuPhysics.Tests")]
|
||||
|
||||
namespace Stride.BepuPhysics;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user