1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Fix regression in time jumping behaviour

This commit is contained in:
Dean Herbert 2023-07-19 13:38:04 +09:00
parent ba237a0e3a
commit 2e3d1fe950
2 changed files with 39 additions and 14 deletions

View File

@ -69,13 +69,13 @@ namespace osu.Game.Tests.Visual.Gameplay
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() =>

View File

@ -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 @@ namespace osu.Game.Graphics
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>