Skip to content

Commit

Permalink
part 2 of the avoid slow functions when we dont need to use them to d…
Browse files Browse the repository at this point in the history
…etermine timeelapsed chronicles
  • Loading branch information
Sam Feeney committed Sep 5, 2016
1 parent 362bb59 commit 41aafa4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 74 deletions.
7 changes: 3 additions & 4 deletions src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
61 changes: 43 additions & 18 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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<int> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
51 changes: 6 additions & 45 deletions src/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> etar;
vector<float> etat;
Expand Down Expand Up @@ -786,48 +790,6 @@ class LunaSteps: public Luna<Steps>
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<int>(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<int>(std::round(et * 1000));
o.append(std::to_string(SS));

lua_pushstring(L, o);
return 1;
}

LunaSteps()
{
ADD_METHOD( GetAuthorCredit );
Expand All @@ -845,7 +807,6 @@ class LunaSteps: public Luna<Steps>
//ADD_METHOD( GetSMNoteData );
ADD_METHOD( GetStepsType );
ADD_METHOD( GetWifeChartKey );
ADD_METHOD( GetWifeChartKeyRecord );
ADD_METHOD( IsAnEdit );
ADD_METHOD( IsAutogen );
ADD_METHOD( IsAPlayerEdit );
Expand Down
21 changes: 14 additions & 7 deletions src/TimingData.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,28 +463,35 @@ class TimingData
vector<RString> 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<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
vector<TimingSegment *> &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;
}


Expand Down

0 comments on commit 41aafa4

Please sign in to comment.