From 8980878a54709ed9f74d6c8f04c20e803019fb40 Mon Sep 17 00:00:00 2001 From: Jimin Park Date: Sat, 12 Feb 2022 18:49:28 +0900 Subject: [PATCH 1/2] Fix calibration mode crash caused by incorrect GetBarPositionsInViewRange impl --- Beatmap/src/BeatmapPlayback.cpp | 52 +++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/Beatmap/src/BeatmapPlayback.cpp b/Beatmap/src/BeatmapPlayback.cpp index 587a65484..ffd1289e0 100644 --- a/Beatmap/src/BeatmapPlayback.cpp +++ b/Beatmap/src/BeatmapPlayback.cpp @@ -389,23 +389,49 @@ void BeatmapPlayback::GetObjectsInViewRange(float numBeats, Vector } } -void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector& barPositions) const +inline MapTime GetLastBarPosition(const TimingPoint& tp, MapTime currTime, /* out*/ uint64& measureNo) { - Beatmap::TimingPointsIterator tp = m_SelectTimingPoint(m_playbackTime); - assert(!IsEndTiming(tp)); + MapTime offset = currTime - tp.time; + if (offset < 0) offset = 0; + + measureNo = static_cast(static_cast(offset) / tp.GetBarDuration()); + + return tp.time + static_cast(measureNo * tp.GetBarDuration()); +} + +// Arbitrary cutoff +constexpr uint64 MAX_DISP_BAR_COUNT = 1000; +void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector& barPositions) const +{ uint64 measureNo = 0; + MapTime currTime = 0; + if (m_isCalibration) { - MapTime offset = m_playbackTime - tp->time; - if (offset < 0) offset = 0; + const TimingPoint& ctp = m_calibrationTiming; + currTime = GetLastBarPosition(ctp, m_playbackTime, measureNo); + + while (barPositions.size() < MAX_DISP_BAR_COUNT) + { + barPositions.Add(TimeToViewDistance(currTime)); + currTime = ctp.time + static_cast(++measureNo * ctp.GetBarDuration()); + + if (currTime - m_playbackTime >= ctp.beatDuration * numBeats) + { + return; + } + } - measureNo = static_cast(static_cast(offset) / tp->GetBarDuration()); + return; } - MapTime currTime = tp->time + static_cast(measureNo * tp->GetBarDuration()); + Beatmap::TimingPointsIterator tp = m_SelectTimingPoint(m_playbackTime); + assert(!IsEndTiming(tp)); - while (true) + currTime = GetLastBarPosition(*tp, m_playbackTime, measureNo); + + while (barPositions.size() < MAX_DISP_BAR_COUNT) { barPositions.Add(TimeToViewDistance(currTime)); @@ -419,13 +445,7 @@ void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector& measureNo = 0; } - // Arbitrary cutoff - if (measureNo >= 1000) - { - return; - } - - if (m_beatmap->GetBeatCountWithScrollSpeedApplied(m_playbackTime, currTime, tp) >= numBeats) + if (GetViewDistance(m_playbackTime, currTime) >= numBeats) { return; } @@ -557,6 +577,8 @@ bool BeatmapPlayback::CheckIfManualTiltInstant() Beatmap::TimingPointsIterator BeatmapPlayback::m_SelectTimingPoint(MapTime time, bool allowReset) const { + assert(!m_isCalibration); + return m_beatmap->GetTimingPoint(time, m_currentTiming, !allowReset); } From 6d2cfc6a11464b891967103a31812df0bb46f6ec Mon Sep 17 00:00:00 2001 From: Jimin Park Date: Sat, 12 Feb 2022 21:18:20 +0900 Subject: [PATCH 2/2] [skip ci] Fix hid/sud not working properly when the fade window is 0 --- bin/skins/Default/shaders/button.fs | 22 +++++++++++++++++----- bin/skins/Default/shaders/holdbutton.fs | 22 ++++++++++++++++++---- bin/skins/Default/shaders/laser.fs | 22 ++++++++++++++++++---- bin/skins/Default/shaders/trackCover.fs | 21 +++++++++++++++++---- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/bin/skins/Default/shaders/button.fs b/bin/skins/Default/shaders/button.fs index 4ebd392d6..5b1d7c212 100644 --- a/bin/skins/Default/shaders/button.fs +++ b/bin/skins/Default/shaders/button.fs @@ -37,23 +37,35 @@ void main() #else +// The OpenGL standard leave the case when `edge0 >= edge1` undefined, +// so this function was made to remove the ambiguity when `edge0 >= edge1`. +// Note that the case when `edge0 > edge1` should be avoided. +float smoothstep_fix(float edge0, float edge1, float x) +{ + if(edge0 >= edge1) + { + return x < edge0 ? 0.0 : x > edge1 ? 1.0 : 0.5; + } + + return smoothstep(edge0, edge1, x); +} + float hide() { float off = trackPos + position.y * trackScale; if (hiddenCutoff > suddenCutoff) { - float sudden = smoothstep(suddenCutoff, suddenCutoff - suddenFadeWindow, off); - float hidden = smoothstep(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff - suddenFadeWindow, suddenCutoff, off); + float hidden = smoothstep_fix(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); return min(hidden + sudden, 1.0); } - float sudden = smoothstep(suddenCutoff + suddenFadeWindow, suddenCutoff, off); - float hidden = smoothstep(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff, suddenCutoff + suddenFadeWindow, off); + float hidden = smoothstep_fix(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); return hidden * sudden; } - void main() { vec4 mainColor = texture(mainTex, fsTex.xy); diff --git a/bin/skins/Default/shaders/holdbutton.fs b/bin/skins/Default/shaders/holdbutton.fs index 6568c28e3..68d904a61 100644 --- a/bin/skins/Default/shaders/holdbutton.fs +++ b/bin/skins/Default/shaders/holdbutton.fs @@ -29,20 +29,34 @@ void main() target.xyz = target.xyz * (1.0 + objectGlow * 0.3); target.a = min(1.0, target.a + target.a * objectGlow * 0.9); } + #else +// The OpenGL standard leave the case when `edge0 >= edge1` undefined, +// so this function was made to remove the ambiguity when `edge0 >= edge1`. +// Note that the case when `edge0 > edge1` should be avoided. +float smoothstep_fix(float edge0, float edge1, float x) +{ + if(edge0 >= edge1) + { + return x < edge0 ? 0.0 : x > edge1 ? 1.0 : 0.5; + } + + return smoothstep(edge0, edge1, x); +} + float hide() { float off = trackPos + position.y * trackScale; if (hiddenCutoff > suddenCutoff) { - float sudden = smoothstep(suddenCutoff, suddenCutoff - suddenFadeWindow, off); - float hidden = smoothstep(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff - suddenFadeWindow, suddenCutoff, off); + float hidden = smoothstep_fix(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); return min(hidden + sudden, 1.0); } - float sudden = smoothstep(suddenCutoff + suddenFadeWindow, suddenCutoff, off); - float hidden = smoothstep(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff, suddenCutoff + suddenFadeWindow, off); + float hidden = smoothstep_fix(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); return hidden * sudden; } diff --git a/bin/skins/Default/shaders/laser.fs b/bin/skins/Default/shaders/laser.fs index 0b297f1af..00b9733f2 100644 --- a/bin/skins/Default/shaders/laser.fs +++ b/bin/skins/Default/shaders/laser.fs @@ -43,20 +43,34 @@ void main() target = mainColor * color; target.xyz = target.xyz * (0.0 + objectGlow * 1.2); } + #else +// The OpenGL standard leave the case when `edge0 >= edge1` undefined, +// so this function was made to remove the ambiguity when `edge0 >= edge1`. +// Note that the case when `edge0 > edge1` should be avoided. +float smoothstep_fix(float edge0, float edge1, float x) +{ + if(edge0 >= edge1) + { + return x < edge0 ? 0.0 : x > edge1 ? 1.0 : 0.5; + } + + return smoothstep(edge0, edge1, x); +} + float hide() { float off = trackPos + position.y * trackScale; if (hiddenCutoff > suddenCutoff) { - float sudden = smoothstep(suddenCutoff, suddenCutoff - suddenFadeWindow, off); - float hidden = smoothstep(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff - suddenFadeWindow, suddenCutoff, off); + float hidden = smoothstep_fix(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); return min(hidden + sudden, 1.0); } - float sudden = smoothstep(suddenCutoff + suddenFadeWindow, suddenCutoff, off); - float hidden = smoothstep(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); + float sudden = 1.0 - smoothstep_fix(suddenCutoff, suddenCutoff + suddenFadeWindow, off); + float hidden = smoothstep_fix(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); return hidden * sudden; } diff --git a/bin/skins/Default/shaders/trackCover.fs b/bin/skins/Default/shaders/trackCover.fs index f56587d1d..ee47e0af8 100644 --- a/bin/skins/Default/shaders/trackCover.fs +++ b/bin/skins/Default/shaders/trackCover.fs @@ -12,6 +12,19 @@ uniform float hiddenFadeWindow; uniform float suddenCutoff; uniform float suddenFadeWindow; +// The OpenGL standard leave the case when `edge0 >= edge1` undefined, +// so this function was made to remove the ambiguity when `edge0 >= edge1`. +// Note that the case when `edge0 > edge1` should be avoided. +float smoothstep_fix(float edge0, float edge1, float x) +{ + if(edge0 >= edge1) + { + return x < edge0 ? 0.0 : x > edge1 ? 1.0 : 0.5; + } + + return smoothstep(edge0, edge1, x); +} + void main() { #ifdef EMBEDDED @@ -21,13 +34,13 @@ void main() float off = 1.0 - (fsTex.y * 2.0); if (hiddenCutoff < suddenCutoff) { - float hidden = 1.0 - smoothstep(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); - float sudden = 1.0 - smoothstep(suddenCutoff + suddenFadeWindow, suddenCutoff, off); + float hidden = 1.0 - smoothstep_fix(hiddenCutoff - hiddenFadeWindow, hiddenCutoff, off); + float sudden = smoothstep_fix(suddenCutoff, suddenCutoff + suddenFadeWindow, off); target.a = min(hidden + sudden, 1.0); } else { - float hidden = smoothstep(hiddenCutoff + hiddenFadeWindow, hiddenCutoff, off); - float sudden = smoothstep(suddenCutoff - suddenFadeWindow, suddenCutoff, off); + float hidden = 1.0 - smoothstep_fix(hiddenCutoff, hiddenCutoff + hiddenFadeWindow, off); + float sudden = smoothstep_fix(suddenCutoff - suddenFadeWindow, suddenCutoff, off); target.a = hidden * sudden; } #endif