Skip to content

Commit

Permalink
that feel when no idea whats going on or why this fixes anything
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Feeney committed Dec 5, 2016
1 parent 1156975 commit 56609bc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 55 deletions.
72 changes: 27 additions & 45 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void MusicWheel::BeginScreen()
}

if(g_bPrecacheAllSorts) {
readyWheelItemsData(so, false);
readyWheelItemsData(so, false, "");
times += ssprintf( "%i:%.3f ", so, timer.GetDeltaTime() );
}
}
Expand Down Expand Up @@ -261,15 +261,14 @@ MusicWheel::~MusicWheel()
}
}

void MusicWheel::ReloadSongList()
void MusicWheel::ReloadSongList(bool searching, RString findme)
{
int songIdxToPreserve = m_iSelection;
// Remove the song from any sorting caches:
FOREACH_ENUM( SortOrder, so ) {
FOREACH_ENUM( SortOrder, so )
m_WheelItemDatasStatus[so]=INVALID;
}
// rebuild the info associated with this sort order
readyWheelItemsData(GAMESTATE->m_SortOrder, false);
readyWheelItemsData(GAMESTATE->m_SortOrder, searching, findme);
// re-open the section to refresh song counts, etc.
SetOpenSection(m_sExpandedSectionName);
// navigate to the song nearest to what was previously selected
Expand All @@ -279,19 +278,6 @@ void MusicWheel::ReloadSongList()
SCREENMAN->PostMessageToTopScreen( SM_SongChanged, 0 );
}

void MusicWheel::ScootyMcPoot(RString findme)
{
int songIdxToPreserve = m_iSelection;
FOREACH_ENUM(SortOrder, so)
m_WheelItemDatasStatus[so] = INVALID;

readyWheelItemsData(GAMESTATE->m_SortOrder, true, findme);
SetOpenSection(m_sExpandedSectionName, true);
m_iSelection = songIdxToPreserve;
RebuildWheelItems();
SCREENMAN->PostMessageToTopScreen(SM_SongChanged, 0);
}

/* If a song or course is set in GAMESTATE and available, select it. Otherwise, choose the
* first available song or course. Return true if an item was set, false if no items are
* available. */
Expand Down Expand Up @@ -598,7 +584,7 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
vector<Song*> arraySongs;
GetSongList( arraySongs, so );

if (searching) // i guess this should really go in the filter function huh -mina
if (searching)
FilterBySearch(arraySongs, findme);

bool bUseSections = true;
Expand Down Expand Up @@ -931,12 +917,9 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
}
}

vector<MusicWheelItemData *> & MusicWheel::getWheelItemsData(SortOrder so, bool searching) {
vector<MusicWheelItemData *> & MusicWheel::getWheelItemsData(SortOrder so) {
// Update the popularity and init icons.
if (!searching) {
readyWheelItemsData(so, false);
return m__WheelItemDatas[so];
}
readyWheelItemsData(so, false, "");
return m__WheelItemDatas[so];
}

Expand All @@ -945,10 +928,11 @@ void MusicWheel::readyWheelItemsData(SortOrder so, bool searching, RString findm
RageTimer timer;

vector<MusicWheelItemData *> &aUnFilteredDatas=m__UnFilteredWheelItemDatas[so];

if(m_WheelItemDatasStatus[so]==INVALID) {
BuildWheelItemDatas( aUnFilteredDatas, so , searching, findme);
BuildWheelItemDatas( aUnFilteredDatas, so, searching, findme);
}
FilterWheelItemDatas( aUnFilteredDatas, m__WheelItemDatas[so], so );
FilterWheelItemDatas( aUnFilteredDatas, m__WheelItemDatas[so], so);
m_WheelItemDatasStatus[so]=VALID;

LOG->Trace( "MusicWheel sorting took: %f", timer.GetTimeSinceStart() );
Expand Down Expand Up @@ -1402,7 +1386,7 @@ void MusicWheel::StartRandom()
RebuildWheelItems();
}

void MusicWheel::SetOpenSection( const RString &group, bool searching )
void MusicWheel::SetOpenSection( const RString &group )
{
//LOG->Trace( "SetOpenSection %s", group.c_str() );
m_sExpandedSectionName = group;
Expand All @@ -1421,8 +1405,7 @@ void MusicWheel::SetOpenSection( const RString &group, bool searching )
GAMEMAN->GetCompatibleStyles( GAMESTATE->m_pCurGame, GAMESTATE->GetNumPlayersEnabled(), vpPossibleStyles );

m_CurWheelItemData.clear();
vector<MusicWheelItemData*>& from = getWheelItemsData(GAMESTATE->m_SortOrder, searching);

vector<MusicWheelItemData *> &from = getWheelItemsData(GAMESTATE->m_SortOrder);
m_CurWheelItemData.reserve( from.size() );
for( unsigned i = 0; i < from.size(); ++i )
{
Expand Down Expand Up @@ -1708,55 +1691,54 @@ void MusicWheel::FinishChangingSorts()
// lua start
#include "LuaBinding.h"

class LunaMusicWheel: public Luna<MusicWheel>
class LunaMusicWheel : public Luna<MusicWheel>
{
public:
static int ChangeSort( T* p, lua_State *L )
static int ChangeSort(T* p, lua_State *L)
{
if( lua_isnil(L,1) ) { lua_pushboolean( L, false ); }
if (lua_isnil(L, 1)) { lua_pushboolean(L, false); }
else
{
SortOrder so = Enum::Check<SortOrder>(L, 1);
lua_pushboolean( L, p->ChangeSort( so ) );
lua_pushboolean(L, p->ChangeSort(so));
}
return 1;
}
DEFINE_METHOD(GetSelectedSection, GetSelectedSection());
static int IsRouletting( T* p, lua_State *L ){ lua_pushboolean( L, p->IsRouletting() ); return 1; }
static int SelectSong( T* p, lua_State *L )
static int IsRouletting(T* p, lua_State *L) { lua_pushboolean(L, p->IsRouletting()); return 1; }
static int SelectSong(T* p, lua_State *L)
{
if( lua_isnil(L,1) ) { lua_pushboolean( L, false ); }
if (lua_isnil(L, 1)) { lua_pushboolean(L, false); }
else
{
Song *pS = Luna<Song>::check( L, 1, true );
lua_pushboolean( L, p->SelectSong( pS ) );
Song *pS = Luna<Song>::check(L, 1, true);
lua_pushboolean(L, p->SelectSong(pS));
}
return 1;
}
static int SelectCourse( T* p, lua_State *L )
static int SelectCourse(T* p, lua_State *L)
{
if( lua_isnil(L,1) ) { lua_pushboolean( L, false ); }
if (lua_isnil(L, 1)) { lua_pushboolean(L, false); }
else
{
Course *pC = Luna<Course>::check( L, 1, true );
lua_pushboolean( L, p->SelectCourse( pC ) );
Course *pC = Luna<Course>::check(L, 1, true);
lua_pushboolean(L, p->SelectCourse(pC));
}
return 1;
}
static int SongSearch(T* p, lua_State *L) {
p->ScootyMcPoot(SArg(1));
p->ReloadSongList(true, SArg(1));
return 1;
}


LunaMusicWheel()
{
ADD_METHOD( ChangeSort );
ADD_METHOD( GetSelectedSection );
ADD_METHOD( IsRouletting );
ADD_METHOD( SelectSong );
ADD_METHOD( SelectCourse );
ADD_METHOD( SongSearch);
ADD_METHOD( SongSearch );
}
};

Expand Down
16 changes: 7 additions & 9 deletions src/MusicWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MusicWheel : public WheelBase
bool SelectSong( const Song *p );
bool SelectCourse( const Course *p );
bool SelectSection( const RString & SectionName );
void SetOpenSection( const RString &group, bool searching = false );
void SetOpenSection( const RString &group );
SortOrder GetSortOrder() const { return m_SortOrder; }
virtual void ChangeMusic( int dist ); /* +1 or -1 */ //CHECK THIS
void FinishChangingSorts();
Expand All @@ -50,8 +50,7 @@ class MusicWheel : public WheelBase
RString JumpToPrevGroup();
const MusicWheelItemData *GetCurWheelItemData( int i ) { return (const MusicWheelItemData *) m_CurWheelItemData[i]; }

virtual void ReloadSongList();
void ScootyMcPoot(RString findme);
virtual void ReloadSongList(bool searching, RString findme);

// Lua
void PushSelf( lua_State *L );
Expand All @@ -60,16 +59,16 @@ class MusicWheel : public WheelBase
MusicWheelItem *MakeItem();

void GetSongList( vector<Song*> &arraySongs, SortOrder so );
void FilterBySearch(vector<Song*>& inv, RString findme);
bool SelectSongOrCourse();
bool SelectModeMenuItem();


void FilterBySearch(vector<Song*>& inv, RString findme);
RString lastvalidsearch;

virtual void UpdateSwitch();

vector<MusicWheelItemData*>& getWheelItemsData(SortOrder so, bool searching = false);
void readyWheelItemsData(SortOrder so, bool searching, RString findme = "");
vector<MusicWheelItemData *> & getWheelItemsData(SortOrder so);
void readyWheelItemsData(SortOrder so, bool searching, RString findme);

RString m_sLastModeMenuItem;
SortOrder m_SortOrder;
Expand Down Expand Up @@ -112,10 +111,9 @@ class MusicWheel : public WheelBase
enum {INVALID,NEEDREFILTER,VALID} m_WheelItemDatasStatus[NUM_SortOrder];
vector<MusicWheelItemData *> m__WheelItemDatas[NUM_SortOrder];
vector<MusicWheelItemData *> m__UnFilteredWheelItemDatas[NUM_SortOrder];
RString lastvalidsearch = "";

void BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItems, SortOrder so, bool searching, RString findme );
void FilterWheelItemDatas(vector<MusicWheelItemData *> &aUnFilteredDatas, vector<MusicWheelItemData *> &aFilteredData, SortOrder so );
void FilterWheelItemDatas(vector<MusicWheelItemData*>& aUnFilteredDatas, vector<MusicWheelItemData*>& aFilteredData, SortOrder so);
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ void ScreenSelectMusic::OnConfirmSongDeletion()
// flush the deleted song from any caches
SONGMAN->UnlistSong(deletedSong);
// refresh the song list
m_MusicWheel.ReloadSongList();
m_MusicWheel.ReloadSongList(false, "");
LOG->Trace("Deleting song: '%s'\n", deleteDir.c_str());
// delete the song directory from disk
FILEMAN->DeleteRecursive(deleteDir);
Expand Down

0 comments on commit 56609bc

Please sign in to comment.