make certain uses of the beat never go below 0

fix loop of superb music
This commit is contained in:
minenice55 2023-11-26 21:45:52 -05:00
parent aed594b427
commit 3f6fef7c9b
8 changed files with 29 additions and 33 deletions

View file

@ -86,6 +86,6 @@ Material:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _ColorAlpha: {r: 1, g: 1, b: 1, a: 1} - _ColorAlpha: {r: 1, g: 1, b: 1, a: 1}
- _ColorBravo: {r: 1, g: 0, b: 0, a: 1} - _ColorBravo: {r: 1, g: 0, b: 0, a: 1}
- _ColorDelta: {r: 0.7647867, g: 0.7568468, b: 0.8092505, a: 1} - _ColorDelta: {r: 0.82210875, g: 0.6714016, b: 0.7016807, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

View file

@ -444,32 +444,27 @@ namespace HeavenStudio
return result; return result;
} }
public float GetLoopPositionFromBeat(float beatOffset, float length) public float GetLoopPositionFromBeat(float beatOffset, float length, bool beatClamp = true)
{ {
return Mathf.Repeat((songPositionInBeats / length) + beatOffset, 1); float beat = songPositionInBeats;
if (beatClamp)
{
beat = Mathf.Max(beat, 0);
}
return Mathf.Repeat((beat / length) + beatOffset, 1);
} }
public float GetPositionFromBeat(double startBeat, double length) public float GetPositionFromBeat(double startBeat, double length, bool beatClamp = true)
{ {
float a = Mathp.Normalize(songPositionInBeats, (float)startBeat, (float)(startBeat + length)); float beat = songPositionInBeats;
if (beatClamp)
{
beat = Mathf.Max(beat, 0);
}
float a = Mathp.Normalize(beat, (float)startBeat, (float)(startBeat + length));
return a; return a;
} }
public float GetBeatFromPosition(float position, float startBeat, float length)
{
return Mathp.DeNormalize(position, (float)startBeat, (float)(startBeat + length));
}
public float GetPositionFromMargin(float targetBeat, float margin)
{
return GetPositionFromBeat(targetBeat - margin, margin);
}
public float GetBeatFromPositionAndMargin(float position, float targetBeat, float margin)
{
return GetBeatFromPosition(position, targetBeat - margin, margin);
}
private List<RiqEntity> GetSortedTempoChanges() private List<RiqEntity> GetSortedTempoChanges()
{ {
GameManager.instance.SortEventsList(); GameManager.instance.SortEventsList();

View file

@ -481,10 +481,11 @@ namespace HeavenStudio
if (!Conductor.instance.isPlaying) if (!Conductor.instance.isPlaying)
return; return;
Conductor cond = Conductor.instance; Conductor cond = Conductor.instance;
double beat = Math.Max(cond.songPositionInBeatsAsDouble, 0);
if (currentTempoEvent < Beatmap.TempoChanges.Count && currentTempoEvent >= 0) if (currentTempoEvent < Beatmap.TempoChanges.Count && currentTempoEvent >= 0)
{ {
if (cond.songPositionInBeatsAsDouble >= tempoBeats[currentTempoEvent]) if (beat >= tempoBeats[currentTempoEvent])
{ {
cond.SetBpm(Beatmap.TempoChanges[currentTempoEvent]["tempo"]); cond.SetBpm(Beatmap.TempoChanges[currentTempoEvent]["tempo"]);
currentTempoEvent++; currentTempoEvent++;
@ -493,7 +494,7 @@ namespace HeavenStudio
if (currentVolumeEvent < Beatmap.VolumeChanges.Count && currentVolumeEvent >= 0) if (currentVolumeEvent < Beatmap.VolumeChanges.Count && currentVolumeEvent >= 0)
{ {
if (cond.songPositionInBeatsAsDouble >= volumeBeats[currentVolumeEvent]) if (beat >= volumeBeats[currentVolumeEvent])
{ {
cond.SetVolume(Beatmap.VolumeChanges[currentVolumeEvent]["volume"]); cond.SetVolume(Beatmap.VolumeChanges[currentVolumeEvent]["volume"]);
currentVolumeEvent++; currentVolumeEvent++;
@ -502,7 +503,7 @@ namespace HeavenStudio
if (currentSectionEvent < Beatmap.SectionMarkers.Count && currentSectionEvent >= 0) if (currentSectionEvent < Beatmap.SectionMarkers.Count && currentSectionEvent >= 0)
{ {
if (cond.songPositionInBeatsAsDouble >= sectionBeats[currentSectionEvent]) if (beat >= sectionBeats[currentSectionEvent])
{ {
Debug.Log("Section " + Beatmap.SectionMarkers[currentSectionEvent]["sectionName"] + " started"); Debug.Log("Section " + Beatmap.SectionMarkers[currentSectionEvent]["sectionName"] + " started");
lastSection = currentSection; lastSection = currentSection;
@ -519,7 +520,7 @@ namespace HeavenStudio
} }
} }
if (cond.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _pulseTally) if (beat >= Math.Ceiling(_playStartBeat) + _pulseTally)
{ {
if (_currentMinigame != null) _currentMinigame.OnBeatPulse(Math.Ceiling(_playStartBeat) + _pulseTally); if (_currentMinigame != null) _currentMinigame.OnBeatPulse(Math.Ceiling(_playStartBeat) + _pulseTally);
onBeatPulse?.Invoke(Math.Ceiling(_playStartBeat) + _pulseTally); onBeatPulse?.Invoke(Math.Ceiling(_playStartBeat) + _pulseTally);
@ -528,12 +529,12 @@ namespace HeavenStudio
float seekTime = 8f; float seekTime = 8f;
//seek ahead to preload games that have assetbundles //seek ahead to preload games that have assetbundles
SeekAheadAndPreload(cond.songPositionInBeatsAsDouble, seekTime); SeekAheadAndPreload(beat, seekTime);
SeekAheadAndDoPreEvent(cond.songPositionInBeatsAsDouble); SeekAheadAndDoPreEvent(beat);
if (currentEvent < Beatmap.Entities.Count && currentEvent >= 0) if (currentEvent < Beatmap.Entities.Count && currentEvent >= 0)
{ {
if (cond.songPositionInBeatsAsDouble >= eventBeats[currentEvent]) if (beat >= eventBeats[currentEvent])
{ {
List<RiqEntity> entitiesAtSameBeat = ListPool<RiqEntity>.Get(); List<RiqEntity> entitiesAtSameBeat = ListPool<RiqEntity>.Get();
List<RiqEntity> fxEntities = ListPool<RiqEntity>.Get(); List<RiqEntity> fxEntities = ListPool<RiqEntity>.Get();
@ -975,7 +976,7 @@ namespace HeavenStudio
if (miniGame != null) if (miniGame != null)
miniGame.OnGameSwitch(beat); miniGame.OnGameSwitch(beat);
while (beat + 0.25 > Conductor.instance.songPositionInBeats) while (beat + 0.25 > Math.Max(Conductor.instance.songPositionInBeatsAsDouble, 0))
{ {
if (!Conductor.instance.isPlaying) if (!Conductor.instance.isPlaying)
{ {

View file

@ -113,7 +113,7 @@ namespace HeavenStudio.Games.Global
private void Update() private void Update()
{ {
var songPosBeat = Conductor.instance.songPositionInBeatsAsDouble; var songPosBeat = Math.Max(Conductor.instance.songPositionInBeatsAsDouble, 0);
foreach (var e in allFilterEvents) foreach (var e in allFilterEvents)
{ {

View file

@ -100,9 +100,8 @@ namespace HeavenStudio.Games.Global
private void Update() private void Update()
{ {
FindFadeFromBeat(Conductor.instance.songPositionInBeatsAsDouble); FindFadeFromBeat(Math.Max(Conductor.instance.songPositionInBeatsAsDouble, 0));
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, length); float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, length);
// normalizedBeat = Mathf.Clamp01(normalizedBeat);
currentCol = new Color(func(startColor.r, endColor.r, normalizedBeat), func(startColor.g, endColor.g, normalizedBeat), func(startColor.b, endColor.b, normalizedBeat), func(startColor.a, endColor.a, normalizedBeat)); currentCol = new Color(func(startColor.r, endColor.r, normalizedBeat), func(startColor.g, endColor.g, normalizedBeat), func(startColor.b, endColor.b, normalizedBeat), func(startColor.a, endColor.a, normalizedBeat));
spriteRenderer.color = currentCol; spriteRenderer.color = currentCol;

View file

@ -61,9 +61,9 @@ namespace HeavenStudio.Common
currentBlink++; currentBlink++;
} }
} }
else if (cond.songPositionInBeats < lastReportedBeat) else if (cond.songPositionInBeatsAsDouble < lastReportedBeat)
{ {
lastReportedBeat = Mathf.Round(cond.songPositionInBeats); lastReportedBeat = System.Math.Round(cond.songPositionInBeatsAsDouble);
} }
} }

View file

@ -57,6 +57,7 @@ namespace HeavenStudio.Common
isPaused = true; isPaused = true;
canPick = false; canPick = false;
optionSelected = 0; optionSelected = 0;
ChooseOption((Options)optionSelected, false);
} }
void UnPause(bool instant = false) void UnPause(bool instant = false)