actually fix lockstep

fix game preloader not always preloading correctly
This commit is contained in:
minenice55 2024-05-13 16:16:36 -04:00
parent cd0f921cda
commit 406c28ecb2
4 changed files with 22 additions and 19 deletions

View file

@ -370,11 +370,13 @@ namespace HeavenStudio
Minigames.Minigame inf; Minigames.Minigame inf;
// seek ahead to preload games that have assetbundles // seek ahead to preload games that have assetbundles
string[] split;
if (currentPreSwitch < allGameSwitches.Count && currentPreSwitch >= 0) 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); inf = GetGameInfo(gameName);
if (inf != null && !(inf.inferred || inf.fxOnly)) if (inf != null && !(inf.inferred || inf.fxOnly))
{ {

View file

@ -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("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.") 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") new GameAction("offbeatSwitch", "Switch to Offbeat")
{ {
@ -267,13 +267,6 @@ namespace HeavenStudio.Games
cameraNear2.targetTexture = renderTextures[1]; cameraNear2.targetTexture = renderTextures[1];
cameraDV.targetTexture = renderTextures[2]; 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]); topNear.SetTexture("_MainTex", renderTextures[0]);
bottomNear.SetTexture("_MainTex", renderTextures[1]); bottomNear.SetTexture("_MainTex", renderTextures[1]);
distantView.SetTexture("_MainTex", renderTextures[2]); distantView.SetTexture("_MainTex", renderTextures[2]);
@ -286,6 +279,10 @@ namespace HeavenStudio.Games
rt.Release(); rt.Release();
} }
queuedInputs.Clear(); queuedInputs.Clear();
foreach (var evt in scheduledInputs)
{
evt.Disable();
}
} }
private static bool ForceStepOnBeat(double beat) 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; return bachEvents.Find(x => beat >= x.beat && beat < x.beat + x.length) != null;
} }
public override void OnGameSwitch(double beat) public override void OnGameSwitch(double beat)
{ {
QueueSwitchBGs(beat); QueueSwitchBGs(beat);
foreach (var evt in scheduledInputs)
{
evt.Disable();
}
} }
public override void OnPlay(double beat) public override void OnPlay(double beat)
{ {
queuedInputs.Clear(); queuedInputs.Clear();
QueueSwitchBGs(beat); QueueSwitchBGs(beat);
} }
private void QueueSwitchBGs(double beat) private void QueueSwitchBGs(double beat)
@ -547,7 +546,7 @@ namespace HeavenStudio.Games
{ {
if (visual) ChangeBeatBackGroundColour(true); 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); }), new BeatAction.Action(beat + 2f, delegate { if (visual) ChangeBeatBackGroundColour(false); }),
}; };
List<BeatAction.Action> actions = new(); List<BeatAction.Action> actions = new();
@ -610,7 +609,7 @@ namespace HeavenStudio.Games
{ {
if (visual) ChangeBeatBackGroundColour(false); 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); }), new BeatAction.Action(beat + 3.5f, delegate { if (visual) ChangeBeatBackGroundColour(true); }),
}; };
List<BeatAction.Action> actions = new(); List<BeatAction.Action> actions = new();
@ -692,6 +691,7 @@ namespace HeavenStudio.Games
BeatAction.New(this, steps); BeatAction.New(this, steps);
} }
private bool marchRecursing;
private void StartMarching(double beat, bool sound, int amount, bool visual) private void StartMarching(double beat, bool sound, int amount, bool visual)
{ {
if (marchRecursing) return; if (marchRecursing) return;
@ -715,19 +715,18 @@ namespace HeavenStudio.Games
MarchRecursive(beat); MarchRecursive(beat);
} }
private bool marchRecursing;
private void MarchRecursive(double beat) private void MarchRecursive(double beat)
{ {
marchRecursing = true; marchRecursing = true;
if (NextStepIsSwitch(beat)) beat -= 0.5; if (NextStepIsSwitch(beat)) beat -= 0.5;
bool offBeat = beat % 1 != 0; bool offBeat = beat % 1 != 0;
bool bachOnBeat = BachOnBeat(beat); bool bachOnBeat = BachOnBeat(beat);
ScheduleInput(beat - 0.5, 0.5, InputAction_BasicPress, offBeat ? JustOff : JustOn, offBeat ? MissOff : MissOn, Nothing);
BeatAction.New(instance, new List<BeatAction.Action>() BeatAction.New(instance, new List<BeatAction.Action>()
{ {
new BeatAction.Action(beat, delegate new BeatAction.Action(beat, delegate
{ {
if (gameManager.currentGame != "lockstep") return; if (gameManager.currentGame != "lockstep") return;
ScheduleInput(beat - 1, 1, InputAction_BasicPress, offBeat ? JustOff : JustOn, offBeat ? MissOff : MissOn, Nothing);
EvaluateMarch(offBeat); EvaluateMarch(offBeat);
MarchRecursive(beat + 1); MarchRecursive(beat + 1);
if (bachOnBeat) bach.DoScaledAnimationAsync(offBeat ? "BachOff" : "BachOn", 0.5f); if (bachOnBeat) bach.DoScaledAnimationAsync(offBeat ? "BachOff" : "BachOn", 0.5f);

View file

@ -274,7 +274,7 @@ namespace HeavenStudio.Games
private void OnDestroy() private void OnDestroy()
{ {
if (!Conductor.instance.isPlaying) if (!conductor.isPlaying)
{ {
crHandlerInstance = null; crHandlerInstance = null;
} }
@ -282,6 +282,8 @@ namespace HeavenStudio.Games
{ {
evt.Disable(); 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) private void SpawnHairInactive(double beat)

View file

@ -399,7 +399,7 @@ namespace HeavenStudio
public bool UsesAssetBundle => (wantAssetBundle is not null or "") && (!badBundle); public bool UsesAssetBundle => (wantAssetBundle is not null or "") && (!badBundle);
public bool HasLocales => supportedLocales.Count > 0; 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 AlreadyLoading => alreadyLoading;
public bool SequencesPreloaded => soundSequences != null; public bool SequencesPreloaded => soundSequences != null;