From 904581c520058e5703ff2f7d4db3680046c6e15d Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 9 May 2023 21:27:48 +0800 Subject: [PATCH] Allows stopping during chart loading. --- Assets/Cryville/Crtr/ChartPlayer.cs | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/Assets/Cryville/Crtr/ChartPlayer.cs b/Assets/Cryville/Crtr/ChartPlayer.cs index 5e90bb8..bdf2fd0 100644 --- a/Assets/Cryville/Crtr/ChartPlayer.cs +++ b/Assets/Cryville/Crtr/ChartPlayer.cs @@ -190,7 +190,11 @@ namespace Cryville.Crtr { #endif } else if (texloaddone) { - prehandler = new Coroutine(Prehandle()); + if (texLoader == null) Stop(); + else { + prehandler = new Coroutine(Prehandle()); + texLoader = null; + } loadThread = null; } } @@ -260,12 +264,8 @@ namespace Cryville.Crtr { MotionNodePool.Shared.RentedCount ); } - if (loadThread != null) { - statusbuf.AppendFormat( - "\n(Loading textures) Progress: {0:P}\n(Loading files) Progress: {1:P}", - texLoader.Progress, loadPregress - ); - } + if (texLoader != null) statusbuf.AppendFormat("\n(Loading textures) Progress: {0:P}", texLoader.Progress); + if (loadThread != null) statusbuf.AppendFormat("\n(Loading files) Progress: {0:P}", loadPregress); if (prehandler != null) statusbuf.AppendFormat("\n(Prehandling) Progress: {0:P}", prehandler.Progress); if (started) { statusbuf.AppendFormat( @@ -331,9 +331,19 @@ namespace Cryville.Crtr { public void TogglePlay() { if (started) Stop(); + else if (prehandler != null) { + prehandler = null; + Stop(); + } + else if (texLoader != null || loadThread != null) { + texloaddone = true; + texLoader = null; + if (loadThread.IsAlive) { + Logger.Log("main", 2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit..."); + } + } else { - if (texLoader == null && loadThread == null && prehandler == null) Play(); - else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading"); + Play(); } } @@ -527,15 +537,19 @@ namespace Cryville.Crtr { Game.AudioClient.Start(); Game.AudioSession = Game.AudioSequencer.NewSession(); Camera.main.cullingMask &= ~1; - inputProxy.Deactivate(); - inputProxy = null; + if (inputProxy != null) { + inputProxy.Deactivate(); + inputProxy = null; + } judge = null; if (nbus != null) { nbus.Dispose(); nbus = null; } if (tbus != null) { tbus.Dispose(); tbus = null; } if (bbus != null) { bbus.Dispose(); bbus = null; } if (cbus != null) { cbus.Dispose(); cbus.DisposeAll(); cbus = null; } - effectManager.Dispose(); - effectManager = null; + if (effectManager != null) { + effectManager.Dispose(); + effectManager = null; + } etor = null; motionRegistry = null; Logger.Log("main", 1, "Game", "Stopped");