Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs related to calibration mode and hid/sud #559

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions Beatmap/src/BeatmapPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,49 @@ void BeatmapPlayback::GetObjectsInViewRange(float numBeats, Vector<ObjectState*>
}
}

void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector<float>& 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<uint64>(static_cast<double>(offset) / tp.GetBarDuration());

return tp.time + static_cast<MapTime>(measureNo * tp.GetBarDuration());
}

// Arbitrary cutoff
constexpr uint64 MAX_DISP_BAR_COUNT = 1000;

void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector<float>& 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<MapTime>(++measureNo * ctp.GetBarDuration());

if (currTime - m_playbackTime >= ctp.beatDuration * numBeats)
{
return;
}
}

measureNo = static_cast<uint64>(static_cast<double>(offset) / tp->GetBarDuration());
return;
}

MapTime currTime = tp->time + static_cast<MapTime>(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));

Expand All @@ -419,13 +445,7 @@ void BeatmapPlayback::GetBarPositionsInViewRange(float numBeats, Vector<float>&
measureNo = 0;
}

// Arbitrary cutoff
if (measureNo >= 1000)
{
return;
}

if (m_beatmap->GetBeatCountWithScrollSpeedApplied(m_playbackTime, currTime, tp) >= numBeats)
if (GetViewDistance(m_playbackTime, currTime) >= numBeats)
{
return;
}
Expand Down Expand Up @@ -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);
}

Expand Down
22 changes: 17 additions & 5 deletions bin/skins/Default/shaders/button.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 18 additions & 4 deletions bin/skins/Default/shaders/holdbutton.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 18 additions & 4 deletions bin/skins/Default/shaders/laser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 17 additions & 4 deletions bin/skins/Default/shaders/trackCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down