1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Merge pull request #644 from ocboogie/player-loader-restart

Memory increase on restart fix
This commit is contained in:
Dean Herbert 2017-04-18 17:11:55 +09:00 committed by GitHub
commit 5ca8737a73
2 changed files with 74 additions and 32 deletions

View File

@ -35,6 +35,8 @@ namespace osu.Game.Screens.Play
public BeatmapInfo BeatmapInfo;
public Action RestartRequested;
public bool IsPaused => !interpolatedSourceClock.IsRunning;
public bool HasFailed { get; private set; }
@ -246,20 +248,9 @@ namespace osu.Game.Screens.Play
public void Restart()
{
sourceClock.Stop(); // If the clock is running and Restart is called the game will lag until relaunch
var newPlayer = new Player();
ValidForResume = false;
LoadComponentAsync(newPlayer, delegate
{
newPlayer.RestartCount = RestartCount + 1;
if (!Push(newPlayer))
{
// Error(?)
}
});
RestartRequested?.Invoke();
Exit();
}
private ScheduledDelegate onCompletionEvent;
@ -324,24 +315,23 @@ namespace osu.Game.Screens.Play
protected override void OnSuspending(Screen next)
{
fadeOut();
base.OnSuspending(next);
}
protected override bool OnExiting(Screen next)
{
if (HasFailed || !ValidForResume)
return false;
if (pauseOverlay != null && !HitRenderer.HasReplayLoaded)
if (!HasFailed && ValidForResume)
{
//pause screen override logic.
if (pauseOverlay?.State == Visibility.Hidden && !canPause) return true;
if (!IsPaused) // For if the user presses escape quickly when entering the map
if (pauseOverlay != null && !HitRenderer.HasReplayLoaded)
{
Pause();
return true;
//pause screen override logic.
if (pauseOverlay?.State == Visibility.Hidden && !canPause) return true;
if (!IsPaused) // For if the user presses escape quickly when entering the map
{
Pause();
return true;
}
}
}

View File

@ -19,17 +19,25 @@ namespace osu.Game.Screens.Play
{
public class PlayerLoader : OsuScreen
{
private readonly Player player;
private Player player;
private readonly OsuLogo logo;
private BeatmapMetadataDisplay info;
private bool showOverlays = true;
internal override bool ShowOverlays => showOverlays;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public PlayerLoader(Player player)
{
ValidForResume = false;
this.player = player;
player.RestartRequested = () => {
showOverlays = false;
ValidForResume = true;
};
Children = new Drawable[]
{
logo = new OsuLogo
@ -53,6 +61,37 @@ namespace osu.Game.Screens.Play
LoadComponentAsync(player);
}
protected override void OnResuming(Screen last)
{
base.OnResuming(last);
contentIn();
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
LoadComponentAsync(player = new Player
{
RestartCount = player.RestartCount + 1,
RestartRequested = player.RestartRequested,
Beatmap = player.Beatmap,
});
Delay(400);
Schedule(pushWhenLoaded);
}
private void contentIn()
{
Content.ScaleTo(1, 650, EasingTypes.OutQuint);
Content.FadeInFromZero(400);
}
private void contentOut()
{
Content.ScaleTo(0.7f, 300, EasingTypes.InQuint);
Content.FadeOut(250);
}
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
@ -60,20 +99,27 @@ namespace osu.Game.Screens.Play
Background.FadeTo(0.4f, 250);
Content.ScaleTo(0.7f);
Content.ScaleTo(1, 750, EasingTypes.OutQuint);
Content.FadeInFromZero(500);
Delay(1000, true);
contentIn();
Delay(500, true);
logo.MoveToOffset(new Vector2(0, -180), 500, EasingTypes.InOutExpo);
Delay(250, true);
info.FadeIn(500);
Delay(2000, true);
Delay(1400, true);
Content.ScaleTo(0.7f, 300, EasingTypes.InQuint);
Content.FadeOut(250);
Schedule(pushWhenLoaded);
}
private void pushWhenLoaded()
{
if (!player.IsLoaded)
Schedule(pushWhenLoaded);
contentOut();
Delay(250);
@ -83,6 +129,12 @@ namespace osu.Game.Screens.Play
if (!Push(player))
Exit();
else
{
//By default, we want to load the player and never be returned to.
//Note that this may change if the player we load requested a re-run.
ValidForResume = false;
}
});
}