event caller refactoring

change operation order of minigame loading
This commit is contained in:
minenice55
2024-01-25 12:29:05 -05:00
parent ba3960d142
commit 9f0a48e9ff
8 changed files with 94 additions and 106 deletions

View File

@ -32,30 +32,31 @@ namespace HeavenStudio
[NonSerialized] public Games.Global.Filter filter;
[Header("Games")]
[NonSerialized] public string currentGame;
Coroutine currentGameSwitchIE;
[Header("Properties")]
[NonSerialized] public string txt = null;
[NonSerialized] public string ext = null;
[NonSerialized]
public int currentEvent, currentTempoEvent, currentVolumeEvent, currentSectionEvent,
currentPreEvent, currentPreSwitch, currentPreSequence;
[NonSerialized] public double endBeat;
[NonSerialized] public float startOffset;
[NonSerialized] public bool playMode;
[NonSerialized] public double startBeat;
[NonSerialized] public GameObject currentGameO;
private Minigame _currentMinigame;
[NonSerialized] public bool autoplay;
[NonSerialized] public bool canInput = true;
[NonSerialized] public RiqEntity lastSection, currentSection;
[NonSerialized] public double nextSectionBeat;
public string currentGame { get; private set; }
public GameObject minigameObj { get; private set; }
public Minigame minigame { get; private set; }
public RiqEntity lastSection { get; private set; }
public RiqEntity currentSection { get; private set; }
public double endBeat { get; private set; }
public double startBeat { get; private set; }
public double nextSectionBeat { get; private set; }
public double SectionProgress { get; private set; }
public float MarkerWeight { get; private set; }
public int MarkerCategory { get; private set; }
public bool playMode { get; private set; }
public bool autoplay { get; private set; }
public bool canInput { get; private set; }
public bool GameHasSplitColours
{
get
@ -138,7 +139,9 @@ namespace HeavenStudio
eventCaller = this.gameObject.AddComponent<EventCaller>();
eventCaller.GamesHolder = GamesHolder.transform;
eventCaller.Init();
eventCaller.Init(this);
canInput = true;
// note: serialize this shit in the inspector //
GameObject textbox = Instantiate(Resources.Load<GameObject>("Prefabs/Common/Textbox"));
@ -429,9 +432,10 @@ namespace HeavenStudio
{
if (currentPreSequence < Beatmap.Entities.Count && currentPreSequence >= 0)
{
if (start >= preSequenceBeats[currentPreSequence])
List<RiqEntity> entitiesInRange = ListPool<RiqEntity>.Get();
while (currentPreSequence < preSequenceBeats.Count && start >= preSequenceBeats[currentPreSequence])
{
List<RiqEntity> entitiesInRange = ListPool<RiqEntity>.Get();
entitiesInRange.Clear();
foreach (RiqEntity entity in Beatmap.Entities)
{
string[] entityDatamodel = entity.datamodel.Split('/');
@ -449,14 +453,14 @@ namespace HeavenStudio
var inf = GetGameInfo(gameName);
if (inf != null && inf.usesAssetBundle && inf.AssetsLoaded && !inf.SequencesPreloaded)
{
Debug.Log($"Preloading game {gameName}");
Debug.Log($"Preparing game {gameName}");
PreloadGameSequences(gameName);
}
eventCaller.CallPreEvent(entity);
currentPreSequence++;
}
ListPool<RiqEntity>.Release(entitiesInRange);
}
ListPool<RiqEntity>.Release(entitiesInRange);
}
}
@ -533,7 +537,7 @@ namespace HeavenStudio
if (cond.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _pulseTally)
{
if (_currentMinigame != null) _currentMinigame.OnBeatPulse(Math.Ceiling(_playStartBeat) + _pulseTally);
if (minigame != null) minigame.OnBeatPulse(Math.Ceiling(_playStartBeat) + _pulseTally);
onBeatPulse?.Invoke(Math.Ceiling(_playStartBeat) + _pulseTally);
_pulseTally++;
}
@ -545,12 +549,13 @@ namespace HeavenStudio
if (currentEvent < Beatmap.Entities.Count && currentEvent >= 0)
{
if (clampedBeat >= eventBeats[currentEvent])
List<RiqEntity> entitiesInRange = ListPool<RiqEntity>.Get();
List<RiqEntity> fxEntities = ListPool<RiqEntity>.Get();
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
while (currentEvent < eventBeats.Count && clampedBeat >= eventBeats[currentEvent] && Conductor.instance.isPlaying)
{
List<RiqEntity> entitiesInRange = ListPool<RiqEntity>.Get();
List<RiqEntity> fxEntities = ListPool<RiqEntity>.Get();
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
fxEntities.Clear();
entitiesInRange.Clear();
using (PooledObject<List<RiqEntity>> pool = ListPool<RiqEntity>.Get(out List<RiqEntity> currentBeatEntities))
{
currentBeatEntities = Beatmap.Entities.FindAll(c => c.beat == eventBeats[currentEvent]);
@ -592,10 +597,9 @@ namespace HeavenStudio
// Thank you to @shshwdr for bring this to my attention
currentEvent++;
}
ListPool<RiqEntity>.Release(entitiesInRange);
ListPool<RiqEntity>.Release(fxEntities);
}
ListPool<RiqEntity>.Release(entitiesInRange);
ListPool<RiqEntity>.Release(fxEntities);
}
if (currentSection == null)
@ -619,7 +623,7 @@ namespace HeavenStudio
if (Conductor.instance.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _latePulseTally)
{
if (_currentMinigame != null) _currentMinigame.OnLateBeatPulse(Math.Ceiling(_playStartBeat) + _latePulseTally);
if (minigame != null) minigame.OnLateBeatPulse(Math.Ceiling(_playStartBeat) + _latePulseTally);
onBeatPulse?.Invoke(Math.Ceiling(_playStartBeat) + _latePulseTally);
_latePulseTally++;
}
@ -630,6 +634,16 @@ namespace HeavenStudio
canInput = inputs;
}
public void ToggleAutoplay(bool auto)
{
autoplay = auto;
}
public void TogglePlayMode(bool mode)
{
playMode = mode;
}
#region Play Events
private double _playStartBeat = 0;
@ -701,7 +715,7 @@ namespace HeavenStudio
{
Conductor.instance.PlaySetup(beat);
Minigame miniGame = null;
if (currentGameO != null && currentGameO.TryGetComponent<Minigame>(out miniGame))
if (minigameObj != null && minigameObj.TryGetComponent<Minigame>(out miniGame))
{
if (miniGame != null)
{
@ -761,7 +775,7 @@ namespace HeavenStudio
}
Minigame miniGame;
if (currentGameO != null && currentGameO.TryGetComponent<Minigame>(out miniGame))
if (minigameObj != null && minigameObj.TryGetComponent<Minigame>(out miniGame))
{
if (miniGame != null)
{
@ -1065,7 +1079,7 @@ namespace HeavenStudio
SetGame(game, false);
Minigame miniGame;
if (currentGameO != null && currentGameO.TryGetComponent<Minigame>(out miniGame))
if (minigameObj != null && minigameObj.TryGetComponent<Minigame>(out miniGame))
{
if (miniGame != null)
{
@ -1095,19 +1109,19 @@ namespace HeavenStudio
GameObject prefab = GetGame(game);
if (prefab == null) return;
Destroy(currentGameO);
currentGameO = Instantiate(prefab);
if (currentGameO.TryGetComponent<Minigame>(out var minigame))
Destroy(minigameObj);
minigameObj = Instantiate(prefab);
if (minigameObj.TryGetComponent<Minigame>(out var minigame))
{
_currentMinigame = minigame;
this.minigame = minigame;
minigame.minigameName = game;
minigame.gameManager = this;
minigame.conductor = Conductor.instance;
}
Vector3 originalScale = currentGameO.transform.localScale;
currentGameO.transform.parent = eventCaller.GamesHolder.transform;
currentGameO.transform.localScale = originalScale;
currentGameO.name = game;
Vector3 originalScale = minigameObj.transform.localScale;
minigameObj.transform.parent = eventCaller.GamesHolder.transform;
minigameObj.transform.localScale = originalScale;
minigameObj.name = game;
SetCurrentGame(game, useMinigameColor);
}