From 41aafa4cd3e0ebeb160569ef0ac12a17bdba09a8 Mon Sep 17 00:00:00 2001 From: Sam Feeney Date: Mon, 5 Sep 2016 07:32:49 -0400 Subject: [PATCH] part 2 of the avoid slow functions when we dont need to use them to determine timeelapsed chronicles --- src/GameState.cpp | 7 +++--- src/Player.cpp | 61 +++++++++++++++++++++++++++++++++-------------- src/Player.h | 2 ++ src/Steps.cpp | 51 +++++---------------------------------- src/TimingData.h | 21 ++++++++++------ 5 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/GameState.cpp b/src/GameState.cpp index d4030c4ae0..f2fcc4480b 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -2603,8 +2603,7 @@ MultiPlayer GetNextEnabledMultiPlayer( MultiPlayer mp ) float GameState::WhereUAtBro(PlayerNumber pn, float beat) { if (beat < 0) return 0; - const bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); - + bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); if (ValidSequentialAssumption) { return m_pCurSteps[pn]->GetElapsedTimeAtRow(BeatToNoteRow(beat)) - GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate * PREFSMAN->m_fGlobalOffsetSeconds; @@ -2619,7 +2618,7 @@ float GameState::WhereUAtBro(PlayerNumber pn, float beat) { float GameState::WhereUAtBro(PlayerNumber pn, float beat) const { if (beat < 0) return 0; - const bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); + bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); if (ValidSequentialAssumption) { @@ -2635,7 +2634,7 @@ float GameState::WhereUAtBro(PlayerNumber pn, float beat) const { float GameState::WhereUAtBro(PlayerNumber pn, int row) { if (row < 0) return 0; - const bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); + bool ValidSequentialAssumption = m_pCurSteps[pn]->GetTimingData()->IsSequentialAssumptionValid(); if (ValidSequentialAssumption) { diff --git a/src/Player.cpp b/src/Player.cpp index 5698cdeeb2..f3ff917b2a 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -666,6 +666,7 @@ void Player::Load() // if( m_pScore ) // m_pScore->Init( pn ); + // Mina garbage - Mina m_Timing = GAMESTATE->m_pCurSteps[pn]->GetTimingData(); m_Timing->NegStopAndBPMCheck(); @@ -1977,19 +1978,11 @@ void Player::Step( int col, int row, const RageTimer &tm, bool bHeld, bool bRele const float fPositionSeconds = m_pPlayerState->m_Position.m_fMusicSeconds - tm.Ago(); const float fTimeSinceStep = tm.Ago(); - LOG->Trace("%f", fPositionSeconds); - LOG->Trace("%f", tm.Ago()); - float fSongBeat = m_pPlayerState->m_Position.m_fSongBeat; - if( GAMESTATE->m_pCurSong ) - { - fSongBeat = GAMESTATE->m_pCurSong->m_SongTiming.GetBeatFromElapsedTime( fPositionSeconds ); - - if( GAMESTATE->m_pCurSteps[m_pPlayerState->m_PlayerNumber] ) - fSongBeat = m_Timing->GetBeatFromElapsedTime( fPositionSeconds ); - } - + if( GAMESTATE->m_pCurSteps[m_pPlayerState->m_PlayerNumber] ) + fSongBeat = m_Timing->GetBeatFromElapsedTime( fPositionSeconds ); + const int iSongRow = row == -1 ? BeatToNoteRow( fSongBeat ) : row; if( col != -1 && !bRelease ) @@ -2114,17 +2107,49 @@ void Player::Step( int col, int row, const RageTimer &tm, bool bHeld, bool bRele * Either option would fundamentally change the grading of two quick notes * "jack hammers." Hmm. */ + + int iStepSearchRows; static const float StepSearchDistance = GetMaxStepDistanceSeconds(); - LOG->Trace("%f", m_pPlayerState->m_Position.m_fMusicSeconds + tm.Ago()); + if (iSongRow < 1) { + iStepSearchRows = max(BeatToNoteRow(m_Timing->GetBeatFromElapsedTime(m_pPlayerState->m_Position.m_fMusicSeconds + StepSearchDistance)) - iSongRow, + iSongRow - BeatToNoteRow(m_Timing->GetBeatFromElapsedTime(m_pPlayerState->m_Position.m_fMusicSeconds - StepSearchDistance))) + ROWS_PER_BEAT; + } + else + { + /* Buncha bullshit that speeds up searching for the rows that we're concerned about judging taps within + by avoiding the invocation of the incredibly slow getbeatfromelapsedtime. Needs to be cleaned up a lot, + whole system does. Only in use if sequential assumption remains valid. - Mina */ + + vector nerv = GAMESTATE->m_pCurSteps[pn]->GetNonEmptyRowVector(); + if (nerv[nervpos] < iSongRow && nervpos < nerv.size()) + nervpos += 1; + + size_t SearchIndexBehind = nervpos; + size_t SearchIndexAhead = nervpos; + float SearchBeginTime = GAMESTATE->WhereUAtBro(pn, nerv[nervpos]); + + while (SearchIndexBehind > 1 && SearchBeginTime - GAMESTATE->WhereUAtBro(pn, nerv[SearchIndexBehind - 1]) < StepSearchDistance) + SearchIndexBehind -= 1; + + while (SearchIndexAhead > 1 && SearchIndexAhead + 1 > nerv.size() && GAMESTATE->WhereUAtBro(pn, nerv[SearchIndexAhead + 1]) - SearchBeginTime < StepSearchDistance) + SearchIndexAhead += 1; + + int MaxLookBehind = nerv[nervpos] - nerv[SearchIndexBehind]; + int MaxLookAhead = nerv[SearchIndexAhead] - nerv[nervpos]; + + if (nervpos > 0) + iStepSearchRows = (max(MaxLookBehind, MaxLookAhead) + ROWS_PER_BEAT); + + int iRowOfOverlappingNoteOrRow = row; + if (row == -1) + iRowOfOverlappingNoteOrRow = GetClosestNote(col, iSongRow, iStepSearchRows, iStepSearchRows, false); + + } - const int iStepSearchRows = max( - BeatToNoteRow( m_Timing->GetBeatFromElapsedTime( m_pPlayerState->m_Position.m_fMusicSeconds + StepSearchDistance ) ) - iSongRow, - iSongRow - BeatToNoteRow( m_Timing->GetBeatFromElapsedTime( m_pPlayerState->m_Position.m_fMusicSeconds - StepSearchDistance ) ) - ) + ROWS_PER_BEAT; int iRowOfOverlappingNoteOrRow = row; - if( row == -1 ) - iRowOfOverlappingNoteOrRow = GetClosestNote( col, iSongRow, iStepSearchRows, iStepSearchRows, false ); + if (row == -1) + iRowOfOverlappingNoteOrRow = GetClosestNote(col, iSongRow, iStepSearchRows, iStepSearchRows, false); // calculate TapNoteScore TapNoteScore score = TNS_None; diff --git a/src/Player.h b/src/Player.h index 7da08352c9..7db8aa9a46 100644 --- a/src/Player.h +++ b/src/Player.h @@ -106,6 +106,8 @@ class Player: public ActorFrame void ScoreAllActiveHoldsLetGo(); void DoTapScoreNone(); + size_t nervpos = 0; // hacky way to keep track of where we are in the non-empty row vector - Mina + void Step( int col, int row, const RageTimer &tm, bool bHeld, bool bRelease ); void FadeToFail(); diff --git a/src/Steps.cpp b/src/Steps.cpp index 8706bdba03..e625b1e659 100644 --- a/src/Steps.cpp +++ b/src/Steps.cpp @@ -438,9 +438,13 @@ void Steps::Decompress() the chart key generated on song load. -Mina */ NoteData nd = Steps::GetNoteData(); - NonEmptyRowVector = nd.LogNonEmptyRows(); + if (nd.GetLastRow() > size_t(500000)) // Ignore really long stuff for the moment + return; - if (NonEmptyRowVector.size() <= 4 || nd.IsEmpty()) return; // don't care about anything with under 4 rows of taps + NonEmptyRowVector = nd.LogNonEmptyRows(); + // don't care about anything with under 4 rows of taps + if (NonEmptyRowVector.size() <= 4 || nd.IsEmpty()) + return; vector etar; vector etat; @@ -786,48 +790,6 @@ class LunaSteps: public Luna return 1; } - /* Muddy way to get the pre-hashed string value, going to leave this in for now - in case I need it for debugging. -Mina */ - static int GetWifeChartKeyRecord(T* p, lua_State *L) - { - RString o = ""; - NoteData nd = p->GetNoteData(); - TimingData *td = p->GetTimingData(); - - int sr = nd.GetFirstRow(); - int lr = sr; - float et = 0; - float bps; - float beatspan; - - for (int r = sr; nd.GetNextTapNoteRowForAllTracks(r); ) - { - for (int t = 0; t < nd.GetNumTracks(); ++t) - { - const TapNote &tn = nd.GetTapNote(t, r); - o.append(std::to_string(tn.type)); - } - - o.append(";"); - - int SS = static_cast(std::round(et * 1000)); - o.append(std::to_string(SS)); - - o.append(" "); - - bps = td->GetBPMAtRow(lr) / 60.f; - beatspan = NoteRowToBeat(r) - NoteRowToBeat(lr); - et = et + (beatspan / bps); - lr = r; - } - - int SS = static_cast(std::round(et * 1000)); - o.append(std::to_string(SS)); - - lua_pushstring(L, o); - return 1; - } - LunaSteps() { ADD_METHOD( GetAuthorCredit ); @@ -845,7 +807,6 @@ class LunaSteps: public Luna //ADD_METHOD( GetSMNoteData ); ADD_METHOD( GetStepsType ); ADD_METHOD( GetWifeChartKey ); - ADD_METHOD( GetWifeChartKeyRecord ); ADD_METHOD( IsAnEdit ); ADD_METHOD( IsAutogen ); ADD_METHOD( IsAPlayerEdit ); diff --git a/src/TimingData.h b/src/TimingData.h index 0cc80cec3c..87fdcdafd9 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -463,28 +463,35 @@ class TimingData vector ToVectorString(TimingSegmentType tst, int dec = 6) const; // Wow it's almost like this should have been done a decade ago. - Mina. - bool ValidSequentialAssumption = HasWarps(); + bool ValidSequentialAssumption = !HasWarps(); void InvalidateSequentialAssmption() { ValidSequentialAssumption = false;}; bool IsSequentialAssumptionValid() { return ValidSequentialAssumption; } - bool TimingData::NegStopAndBPMCheck() { + void TimingData::NegStopAndBPMCheck() { vector &bpms = m_avpTimingSegments[SEGMENT_BPM]; vector &stops = m_avpTimingSegments[SEGMENT_STOP]; for (size_t i = 0, l = bpms.size(); i < l; ++i) { BPMSegment *bpm = ToBPM(bpms[i]); - if (0 > bpm->GetBPM()) - return false; + if (0 > bpm->GetBPM()) { + LOG->Warn("Sequential Assumption Invalidated."); + ValidSequentialAssumption = false; + return; + } + } for (size_t i = 0, l = stops.size(); i < l; ++i) { StopSegment *s = ToStop(stops[i]); - if (0 > s->GetPause()) - return false; + if (0 > s->GetPause()) { + LOG->Warn("Sequential Assumption Invalidated."); + ValidSequentialAssumption = false; + return; + } } - return true; + ValidSequentialAssumption = true && ValidSequentialAssumption; }