mirror of https://github.com/ppy/osu
Fix regression in time jumping behaviour
This commit is contained in:
parent
ba237a0e3a
commit
2e3d1fe950
|
@ -69,13 +69,13 @@ public void TestTimeJumps()
|
|||
spewer.Clock = new FramedClock(testClock);
|
||||
});
|
||||
AddStep("start spewer", () => spewer.Active.Value = true);
|
||||
AddAssert("spawned first particle", () => spewer.TotalCreatedParticles == 1);
|
||||
AddAssert("spawned first particle", () => spewer.TotalCreatedParticles, () => Is.EqualTo(1));
|
||||
|
||||
AddStep("move clock forward", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * 3);
|
||||
AddAssert("spawned second particle", () => spewer.TotalCreatedParticles == 2);
|
||||
AddAssert("spawned second particle", () => spewer.TotalCreatedParticles, () => Is.EqualTo(2));
|
||||
|
||||
AddStep("move clock backwards", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * -1);
|
||||
AddAssert("spawned third particle", () => spewer.TotalCreatedParticles == 3);
|
||||
AddAssert("spawned third particle", () => spewer.TotalCreatedParticles, () => Is.EqualTo(3));
|
||||
}
|
||||
|
||||
private TestParticleSpewer createSpewer() =>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.EnumExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
|
@ -60,19 +61,43 @@ protected override void Update()
|
|||
return;
|
||||
}
|
||||
|
||||
while (lastParticleAdded == null || Math.Abs(Time.Current - lastParticleAdded.Value) > timeBetweenSpawns)
|
||||
// Always want to spawn the first particle in an activation immediately.
|
||||
if (lastParticleAdded == null)
|
||||
{
|
||||
lastParticleAdded ??= Time.Current;
|
||||
|
||||
var newParticle = CreateParticle();
|
||||
newParticle.StartTime = (float)lastParticleAdded;
|
||||
|
||||
particles[currentIndex] = newParticle;
|
||||
|
||||
currentIndex = (currentIndex + 1) % particles.Length;
|
||||
|
||||
lastParticleAdded += timeBetweenSpawns;
|
||||
lastParticleAdded = Time.Current;
|
||||
spawnParticle();
|
||||
}
|
||||
|
||||
double timeElapsed = Math.Abs(Time.Current - lastParticleAdded.Value);
|
||||
|
||||
// Avoid spawning too many particles if a long amount of time has passed.
|
||||
if (timeElapsed > maxDuration)
|
||||
{
|
||||
lastParticleAdded = Time.Current;
|
||||
spawnParticle();
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Assert(lastParticleAdded != null);
|
||||
|
||||
for (int i = 0; i < timeElapsed / timeBetweenSpawns; i++)
|
||||
{
|
||||
lastParticleAdded += timeBetweenSpawns;
|
||||
spawnParticle();
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnParticle()
|
||||
{
|
||||
Debug.Assert(lastParticleAdded != null);
|
||||
|
||||
var newParticle = CreateParticle();
|
||||
|
||||
newParticle.StartTime = (float)lastParticleAdded.Value;
|
||||
|
||||
particles[currentIndex] = newParticle;
|
||||
|
||||
currentIndex = (currentIndex + 1) % particles.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue