From c47431d16af7a858b9774a5097c4cb966e898402 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Mon, 13 May 2024 16:16:36 -0400 Subject: [PATCH] actually fix lockstep fix game preloader not always preloading correctly --- Assets/Scripts/GameManager.cs | 6 ++-- Assets/Scripts/Games/Lockstep/Lockstep.cs | 29 +++++++++---------- .../Games/RhythmTweezers/RhythmTweezers.cs | 4 ++- Assets/Scripts/Minigames.cs | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 8d241bc57..a431eec9a 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -370,11 +370,13 @@ namespace HeavenStudio Minigames.Minigame inf; // seek ahead to preload games that have assetbundles + string[] split; if (currentPreSwitch < allGameSwitches.Count && currentPreSwitch >= 0) { - if (start + seekTime >= allGameSwitches[currentPreSwitch].beat) + while (currentPreSwitch < allGameSwitches.Count && allGameSwitches[currentPreSwitch].beat <= start + seekTime) { - string gameName = allGameSwitches[currentPreSwitch].datamodel.Split('/')[2]; + split = allGameSwitches[currentPreSwitch].datamodel.Split('/'); + string gameName = split[2]; inf = GetGameInfo(gameName); if (inf != null && !(inf.inferred || inf.fxOnly)) { diff --git a/Assets/Scripts/Games/Lockstep/Lockstep.cs b/Assets/Scripts/Games/Lockstep/Lockstep.cs index 8730c81c0..bcfd2de47 100644 --- a/Assets/Scripts/Games/Lockstep/Lockstep.cs +++ b/Assets/Scripts/Games/Lockstep/Lockstep.cs @@ -42,7 +42,7 @@ namespace HeavenStudio.Games.Loaders new Param("amount", new EntityTypes.Integer(1, 50, 1), "Amount", "Set how many sounds will play."), new Param("visual", true, "Background Visual", "Toggle if the background will automatically flip depending on if it's on or off beat.") }, - preFunctionLength = 1 + preFunctionLength = 2 }, new GameAction("offbeatSwitch", "Switch to Offbeat") { @@ -267,13 +267,6 @@ namespace HeavenStudio.Games cameraNear2.targetTexture = renderTextures[1]; cameraDV.targetTexture = renderTextures[2]; - // topT.texture = renderTextures[2]; - // topN.texture = renderTextures[0]; - // bottomL.texture = renderTextures[2]; - // bottomC.texture = renderTextures[2]; - // bottomR.texture = renderTextures[2]; - // bottomN.texture = renderTextures[1]; - topNear.SetTexture("_MainTex", renderTextures[0]); bottomNear.SetTexture("_MainTex", renderTextures[1]); distantView.SetTexture("_MainTex", renderTextures[2]); @@ -286,6 +279,10 @@ namespace HeavenStudio.Games rt.Release(); } queuedInputs.Clear(); + foreach (var evt in scheduledInputs) + { + evt.Disable(); + } } private static bool ForceStepOnBeat(double beat) @@ -308,18 +305,20 @@ namespace HeavenStudio.Games { return bachEvents.Find(x => beat >= x.beat && beat < x.beat + x.length) != null; } + public override void OnGameSwitch(double beat) { QueueSwitchBGs(beat); - + foreach (var evt in scheduledInputs) + { + evt.Disable(); + } } public override void OnPlay(double beat) { - queuedInputs.Clear(); QueueSwitchBGs(beat); - } private void QueueSwitchBGs(double beat) @@ -547,7 +546,7 @@ namespace HeavenStudio.Games { if (visual) ChangeBeatBackGroundColour(true); }), - new BeatAction.Action(beat + 1.75f, delegate { if (!marchRecursing && !ForceStepOnBeat(beat + 2f)) MarchRecursive(beat + 2f); }), + new BeatAction.Action(beat + 1.5f, delegate { if (!marchRecursing && !ForceStepOnBeat(beat + 2f)) MarchRecursive(beat + 2f); }), new BeatAction.Action(beat + 2f, delegate { if (visual) ChangeBeatBackGroundColour(false); }), }; List actions = new(); @@ -610,7 +609,7 @@ namespace HeavenStudio.Games { if (visual) ChangeBeatBackGroundColour(false); }), - new BeatAction.Action(beat + 3.25f, delegate { if (!marchRecursing && !ForceStepOnBeat(beat + 3.5)) MarchRecursive(beat + 3.5f); }), + new BeatAction.Action(beat + 3f, delegate { if (!marchRecursing && !ForceStepOnBeat(beat + 3.5)) MarchRecursive(beat + 3.5f); }), new BeatAction.Action(beat + 3.5f, delegate { if (visual) ChangeBeatBackGroundColour(true); }), }; List actions = new(); @@ -692,6 +691,7 @@ namespace HeavenStudio.Games BeatAction.New(this, steps); } + private bool marchRecursing; private void StartMarching(double beat, bool sound, int amount, bool visual) { if (marchRecursing) return; @@ -715,19 +715,18 @@ namespace HeavenStudio.Games MarchRecursive(beat); } - private bool marchRecursing; private void MarchRecursive(double beat) { marchRecursing = true; if (NextStepIsSwitch(beat)) beat -= 0.5; bool offBeat = beat % 1 != 0; bool bachOnBeat = BachOnBeat(beat); + ScheduleInput(beat - 0.5, 0.5, InputAction_BasicPress, offBeat ? JustOff : JustOn, offBeat ? MissOff : MissOn, Nothing); BeatAction.New(instance, new List() { new BeatAction.Action(beat, delegate { if (gameManager.currentGame != "lockstep") return; - ScheduleInput(beat - 1, 1, InputAction_BasicPress, offBeat ? JustOff : JustOn, offBeat ? MissOff : MissOn, Nothing); EvaluateMarch(offBeat); MarchRecursive(beat + 1); if (bachOnBeat) bach.DoScaledAnimationAsync(offBeat ? "BachOff" : "BachOn", 0.5f); diff --git a/Assets/Scripts/Games/RhythmTweezers/RhythmTweezers.cs b/Assets/Scripts/Games/RhythmTweezers/RhythmTweezers.cs index 16eee9878..399a16b4a 100644 --- a/Assets/Scripts/Games/RhythmTweezers/RhythmTweezers.cs +++ b/Assets/Scripts/Games/RhythmTweezers/RhythmTweezers.cs @@ -275,7 +275,7 @@ namespace HeavenStudio.Games private void OnDestroy() { - if (!Conductor.instance.isPlaying) + if (!conductor.isPlaying) { crHandlerInstance = null; } @@ -283,6 +283,8 @@ namespace HeavenStudio.Games { evt.Disable(); } + // note: this doesn't properly clear queued intervals if we don't switch to the game before stopping playback + queuedIntervals.Clear(); } private void SpawnHairInactive(double beat) diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 0ee59f2c7..589a04c5c 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -399,7 +399,7 @@ namespace HeavenStudio public bool UsesAssetBundle => (wantAssetBundle is not null or "") && (!badBundle); public bool HasLocales => supportedLocales.Count > 0; - public bool AssetsLoaded => (!badBundle) && ((HasLocales && audioLoaded && currentLoadedLocale == defaultLocale) || (!HasLocales)) && resourcesLoaded && loadComplete; + public bool AssetsLoaded => (!badBundle) && ((HasLocales && audioLoaded && currentLoadedLocale == defaultLocale) || (!HasLocales)) && (LoadedPrefab != null) && resourcesLoaded && loadComplete; public bool AlreadyLoading => alreadyLoading; public bool SequencesPreloaded => soundSequences != null;