Conductor: refactor ReportBeat

this fixes issues with using crop stomp alongside tempo changes
This commit is contained in:
minenice55 2022-06-08 22:45:21 -04:00
parent c5e0f53c4a
commit ecb7b3d16e
3 changed files with 19 additions and 22 deletions

View file

@ -189,23 +189,20 @@ namespace HeavenStudio
{
Util.Jukebox.PlayOneShot("metronome");
}
else if (songPosition <= lastReportedBeat)
else if (songPositionInBeats < lastReportedBeat)
{
lastReportedBeat = (songPosition - (songPosition % secPerBeat));
lastReportedBeat = Mathf.Round(songPositionInBeats);
}
}
}
}
public bool ReportBeat(ref float lastReportedBeat, float offset = 0, bool shiftBeatToOffset = false)
public bool ReportBeat(ref float lastReportedBeat, float offset = 0, bool shiftBeatToOffset = true)
{
bool result = songPosition > (lastReportedBeat + offset) + secPerBeat;
if (result == true)
bool result = songPositionInBeats + (shiftBeatToOffset ? offset : 0f) >= (lastReportedBeat) + 1f;
if (result)
{
lastReportedBeat = (songPosition - (songPosition % secPerBeat));
if (!shiftBeatToOffset)
lastReportedBeat += offset;
lastReportedBeat += 1f;
}
return result;
}

View file

@ -159,6 +159,18 @@ namespace HeavenStudio
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
List<float> tempoChanges = Beatmap.tempoChanges.Select(c => c.beat).ToList();
if (currentTempoEvent < Beatmap.tempoChanges.Count && currentTempoEvent >= 0)
{
// Debug.Log("Checking Tempo Change at " + tempoChanges[currentTempoEvent] + ", current beat " + Conductor.instance.songPositionInBeats);
if (Conductor.instance.songPositionInBeats >= tempoChanges[currentTempoEvent])
{
// Debug.Log("Tempo Change at " + Conductor.instance.songPositionInBeats + " of bpm " + Beatmap.tempoChanges[currentTempoEvent].tempo);
Conductor.instance.SetBpm(Beatmap.tempoChanges[currentTempoEvent].tempo);
Conductor.instance.timeSinceLastTempoChange = Time.time;
currentTempoEvent++;
}
}
if (currentEvent < Beatmap.entities.Count && currentEvent >= 0)
{
if (Conductor.instance.songPositionInBeats >= entities[currentEvent] /*&& SongPosLessThanClipLength(Conductor.instance.songPositionInBeats)*/)
@ -194,18 +206,6 @@ namespace HeavenStudio
// currentEvent += gameManagerEntities.Count;
}
}
if (currentTempoEvent < Beatmap.tempoChanges.Count && currentTempoEvent >= 0)
{
// Debug.Log("Checking Tempo Change at " + tempoChanges[currentTempoEvent] + ", current beat " + Conductor.instance.songPositionInBeats);
if (Conductor.instance.songPositionInBeats >= tempoChanges[currentTempoEvent])
{
// Debug.Log("Tempo Change at " + Conductor.instance.songPositionInBeats + " of bpm " + Beatmap.tempoChanges[currentTempoEvent].tempo);
Conductor.instance.SetBpm(Beatmap.tempoChanges[currentTempoEvent].tempo);
Conductor.instance.timeSinceLastTempoChange = Time.time;
currentTempoEvent++;
}
}
}
public void ToggleInputs(bool inputs)

View file

@ -270,7 +270,7 @@ namespace HeavenStudio.Games
public void StartMarching(float beat)
{
marchStartBeat = beat;
marchOffset = (marchStartBeat % 1) * Conductor.instance.secPerBeat / Conductor.instance.musicSource.pitch;
marchOffset = marchStartBeat % 1;
currentMarchBeat = 0;
stepCount = 0;