From 64ab3b001bf030d5d881a1f1a192670ebf175fe7 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Mon, 31 Oct 2022 16:02:27 +0800 Subject: [PATCH] Code cleanup. --- Assets/Cryville/Crtr/ChartPlayer.cs | 107 +++++++++++++++------------- Assets/Cryville/Crtr/Judge.cs | 8 +-- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/Assets/Cryville/Crtr/ChartPlayer.cs b/Assets/Cryville/Crtr/ChartPlayer.cs index 319ebb4..6396fb6 100644 --- a/Assets/Cryville/Crtr/ChartPlayer.cs +++ b/Assets/Cryville/Crtr/ChartPlayer.cs @@ -24,8 +24,8 @@ namespace Cryville.Crtr { Skin skin; PdtSkin pskin; Ruleset ruleset; - public static PdtRuleset pruleset; - public static Dictionary texs; + PdtRuleset pruleset; + Dictionary texs; public static Dictionary frames; List plists; @@ -48,19 +48,18 @@ namespace Cryville.Crtr { static Text logs; Text status; + static Vector2 screenSize; public static Rect hitRect; - public static Vector2 screenSize; public static Plane[] frustumPlanes; - public static bool disableGC = true; - public static float clippingDist = 1f; - public static float judgeTolerance = 0.1f; - public static float renderDist = 6f; - public static float renderStep = 0.05f; + static bool disableGC = true; + static float clippingDist = 1f; + static float renderDist = 6f; + static float renderStep = 0.05f; public static float actualRenderStep = 0f; - public static bool autoRenderStep = false; + static bool autoRenderStep = false; public static float soundOffset = 0; - public static float startOffset = 0; + static float startOffset = 0; public static float sv = 16f; public static Dictionary motionRegistry = new Dictionary(); @@ -78,6 +77,7 @@ namespace Cryville.Crtr { if (texLoader != null) texLoader.Dispose(); } + #region MonoBehaviour void Start() { var logobj = GameObject.Find("Logs"); if (logobj != null) @@ -102,8 +102,11 @@ namespace Cryville.Crtr { // Camera.main.RenderToCubemap(); } + bool texloaddone; + diag::Stopwatch texloadtimer = new diag::Stopwatch(); + bool firstFrame; void Update() { - if (Input.GetKeyDown(KeyCode.Return)) TogglePlay(); + // if (Input.GetKeyDown(KeyCode.Return)) TogglePlay(); if (started) { try { if (Screen.width != screenSize.x || Screen.height != screenSize.y) @@ -249,7 +252,9 @@ namespace Cryville.Crtr { Game.MainLogger.Enumerate((level, module, msg) => { }); } } + #endregion + #region Triggers private void ReturnToMenu() { #if UNITY_EDITOR Invoke(nameof(_returnToMenu), 4); @@ -284,7 +289,9 @@ namespace Cryville.Crtr { else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading"); } } + #endregion + #region Load void Play() { disableGC = Settings.Default.DisableGC; clippingDist = Settings.Default.BackwardClippingDistance; @@ -395,18 +402,52 @@ namespace Cryville.Crtr { } } + public void Stop() { + try { + Logger.Log("main", 1, "Game", "Stopping"); + chart = null; + Game.AudioSession = Game.AudioSequencer.NewSession(); + if (cbus != null) cbus.Dispose(); + if (bbus != null) bbus.Dispose(); + if (tbus != null) tbus.Dispose(); + if (nbus != null) nbus.Dispose(); + // Game.InputManager.Deactivate(); + foreach (var t in texs) Texture.Destroy(t.Value); + Logger.Log("main", 1, "Game", "Stopped"); + } + catch (Exception ex) { + if (!logEnabled) ToggleLogs(); + Game.LogException("Game", "An error occured while stopping", ex); + } + finally { + if (started) { + if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Enabled; + GC.Collect(); + started = false; + } + } + Game.NetworkTaskWorker.ResumeBackgroundTasks(); +#if BUILD + ReturnToMenu(); +#endif + } + + void OnSettingsUpdate() { + Application.targetFrameRate = Settings.Default.TargetFrameRate; + QualitySettings.vSyncCount = Settings.Default.VSync ? 1 : 0; + } + #endregion + + #region Threaded struct LoadInfo { public FileInfo chartFile; public FileInfo rulesetFile; public FileInfo skinFile; } - diag::Stopwatch texloadtimer = new diag::Stopwatch(); - bool firstFrame; #if !NO_THREAD Thread loadThread = null; diag::Stopwatch workerTimer; - bool texloaddone; #endif void Load(object _info) { var info = (LoadInfo)_info; @@ -446,7 +487,7 @@ namespace Cryville.Crtr { cbus = batcher.Batch(); Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count); - judge = new Judge(); + judge = new Judge(pruleset); etor.ContextJudge = judge; LoadSkin(info.skinFile); @@ -520,40 +561,6 @@ namespace Cryville.Crtr { frames.Add(StringUtils.TrimExt(i.Key), i.Value); } } - - public void Stop() { - try { - Logger.Log("main", 1, "Game", "Stopping"); - chart = null; - Game.AudioSession = Game.AudioSequencer.NewSession(); - if (cbus != null) cbus.Dispose(); - if (bbus != null) bbus.Dispose(); - if (tbus != null) tbus.Dispose(); - if (nbus != null) nbus.Dispose(); - Game.InputManager.Deactivate(); - foreach (var t in texs) Texture.Destroy(t.Value); - Logger.Log("main", 1, "Game", "Stopped"); - } - catch (Exception ex) { - if (!logEnabled) ToggleLogs(); - Game.LogException("Game", "An error occured while stopping", ex); - } - finally { - if (started) { - if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Enabled; - GC.Collect(); - started = false; - } - } - Game.NetworkTaskWorker.ResumeBackgroundTasks(); -#if BUILD - ReturnToMenu(); -#endif - } - - void OnSettingsUpdate() { - Application.targetFrameRate = Settings.Default.TargetFrameRate; - QualitySettings.vSyncCount = Settings.Default.VSync ? 1 : 0; - } + #endregion } } diff --git a/Assets/Cryville/Crtr/Judge.cs b/Assets/Cryville/Crtr/Judge.cs index 1345d44..c94fbbb 100644 --- a/Assets/Cryville/Crtr/Judge.cs +++ b/Assets/Cryville/Crtr/Judge.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; namespace Cryville.Crtr { public class Judge { - readonly PdtRuleset rs; - public Judge() { - rs = ChartPlayer.pruleset; + readonly PdtRuleset _rs; + public Judge(PdtRuleset rs) { + _rs = rs; foreach (var s in rs.scores) scores.Add(s.Key, s.Value.init); } @@ -24,7 +24,7 @@ namespace Cryville.Crtr { public Dictionary GetFormattedScoreStrings() { if (ScoreCache.Count == 0) { foreach (var s in scores) - ScoreCache.Add(s.Key, s.Value.ToString(rs.scores[s.Key].format)); + ScoreCache.Add(s.Key, s.Value.ToString(_rs.scores[s.Key].format)); } return ScoreCache; }