From e1a447cc369d9d41fca556b76c8931eda7f80f31 Mon Sep 17 00:00:00 2001 From: Mark Cannon Date: Sat, 6 Aug 2011 21:33:49 +0000 Subject: [PATCH] revert henke's loadingwindow "improvements"; if you're reading this, henke, you do *NOT* sacrifice readability for misguided optimization, and you do *NOT* use a globally externed variable for something with a useful lifetime of part of one function --- src/CommandLineActions.cpp | 2 +- src/CommandLineActions.h | 5 +- src/Makefile.am | 1 - src/ScreenInstallOverlay.cpp | 2 +- src/ScreenReloadSongs.cpp | 67 ++++++++++++++++++------ src/ScreenReloadSongs.h | 14 ++--- src/SongManager.cpp | 57 ++++++++++---------- src/SongManager.h | 11 ++-- src/StepMania-net2010.vcxproj.filters | 6 --- src/StepMania.cpp | 12 ++--- src/ThemeManager.cpp | 3 -- src/arch/LoadingWindow/LoadingWindow.cpp | 2 - src/arch/LoadingWindow/LoadingWindow.h | 2 - 13 files changed, 105 insertions(+), 79 deletions(-) diff --git a/src/CommandLineActions.cpp b/src/CommandLineActions.cpp index 3a45380b87..ef5f26b10c 100644 --- a/src/CommandLineActions.cpp +++ b/src/CommandLineActions.cpp @@ -108,7 +108,7 @@ static void Version() #endif // WIN32 } -void CommandLineActions::Handle() +void CommandLineActions::Handle(LoadingWindow* pLW) { CommandLineArgs args; for(int i=0; iReload( false ); + SONGMAN->Reload( false, NULL ); if( !playAfterLaunchInfo.sSongDir.empty() ) { diff --git a/src/ScreenReloadSongs.cpp b/src/ScreenReloadSongs.cpp index 837a407e1a..27a737cb2c 100644 --- a/src/ScreenReloadSongs.cpp +++ b/src/ScreenReloadSongs.cpp @@ -6,8 +6,38 @@ #include "RageLog.h" #include "ThemeManager.h" #include "ScreenDimensions.h" + #include "arch/LoadingWindow/LoadingWindow.h" -#include "InGameLoadingWindow.h" + +static const int DrawFrameRate = 20; +class ScreenReloadSongsLoadingWindow: public LoadingWindow +{ + RageTimer m_LastDraw; + BitmapText &m_BitmapText; + +public: + ScreenReloadSongsLoadingWindow( BitmapText &bt ): + m_BitmapText(bt) + { + } + + void SetText( RString str ) + { + m_BitmapText.SetText( str ); + Paint(); + } + + void Paint() + { + /* We load songs much faster than we draw frames. Cap the draw rate, + * so we don't slow down the reload. */ + if( m_LastDraw.PeekDeltaTime() < 1.0f/DrawFrameRate ) + return; + m_LastDraw.GetDeltaTime(); + + SCREENMAN->Draw(); + } +}; /* This could be cleaned up: show progress, for example. Let's not use * this for the initial load, since we don't want to start up the display @@ -21,30 +51,35 @@ void ScreenReloadSongs::Init() { Screen::Init(); - loadWin=new InGameLoadingWindow( ); + m_iUpdates = 0; - AddChild( loadWin ); + m_Loading.SetName( "LoadingText" ); + m_Loading.LoadFromFont( THEME->GetPathF(m_sName, "LoadingText") ); + m_Loading.SetXY( SCREEN_CENTER_X, SCREEN_CENTER_Y ); + this->AddChild( &m_Loading ); - loadWin->SetXY( SCREEN_CENTER_X, SCREEN_CENTER_Y ); - - pLoadingWindow=loadWin; - - m_loadingThread.SetName("Song reload work thread"); - m_loadingThread.Create(loadingThreadProc,this); -} + m_pLoadingWindow = new ScreenReloadSongsLoadingWindow( m_Loading ); + } ScreenReloadSongs::~ScreenReloadSongs() { - m_loadingThread.Wait(); - RemoveChild(loadWin); - delete loadWin; + delete m_pLoadingWindow; } -int ScreenReloadSongs::loadingThreadProc(void *thisAsVoidPtr) +void ScreenReloadSongs::Update( float fDeltaTime ) { - SONGMAN->Reload( false ); + Screen::Update( fDeltaTime ); + + /* Start the reload on the second update. On the first (0), SCREENMAN->Draw won't draw. */ + ++m_iUpdates; + if( m_iUpdates != 2 ) + return; + + ASSERT( !IsFirstUpdate() ); + + SONGMAN->Reload( false, m_pLoadingWindow ); + SCREENMAN->PostMessageToTopScreen( SM_GoToNextScreen, 0 ); - return 0; } /* diff --git a/src/ScreenReloadSongs.h b/src/ScreenReloadSongs.h index 39676e8dff..176c3e0bdc 100644 --- a/src/ScreenReloadSongs.h +++ b/src/ScreenReloadSongs.h @@ -2,20 +2,22 @@ #define SCREEN_RELOAD_SONGS_H #include "Screen.h" -#include "RageThreads.h" +#include "BitmapText.h" -class InGameLoadingWindow; +class LoadingWindow; class ScreenReloadSongs: public Screen { public: ScreenReloadSongs(); - virtual void Init(); ~ScreenReloadSongs(); + + virtual void Init(); + void Update( float fDeltaTime ); private: - InGameLoadingWindow *loadWin; - RageThread m_loadingThread; - static int loadingThreadProc(void *thisAsVoidPtr); + int m_iUpdates; + LoadingWindow *m_pLoadingWindow; + BitmapText m_Loading; }; #endif diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 618fa0ef0d..948bc16033 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -88,11 +88,10 @@ SongManager::~SongManager() FreeSongs(); } -void SongManager::InitAll() +void SongManager::InitAll( LoadingWindow *ld ) { - InitSongsFromDisk(); - - InitCoursesFromDisk(); + InitSongsFromDisk( ld ); + InitCoursesFromDisk( ld ); InitAutogenCourses(); InitRandomAttacks(); } @@ -100,7 +99,8 @@ void SongManager::InitAll() static LocalizedString RELOADING ( "SongManager", "Reloading..." ); static LocalizedString UNLOADING_SONGS ( "SongManager", "Unloading songs..." ); static LocalizedString UNLOADING_COURSES ( "SongManager", "Unloading courses..." ); -void SongManager::Reload( bool bAllowFastLoad ) + +void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld ) { FILEMAN->FlushDirCache( SpecialFiles::SONGS_DIR ); FILEMAN->FlushDirCache( ADDITIONAL_SONGS_DIR ); @@ -108,26 +108,27 @@ void SongManager::Reload( bool bAllowFastLoad ) FILEMAN->FlushDirCache( ADDITIONAL_COURSES_DIR ); FILEMAN->FlushDirCache( EDIT_SUBDIR ); - if( pLoadingWindow ) - pLoadingWindow->SetText( RELOADING ); + if( ld ) + ld->SetText( RELOADING ); - // save scores before unloading songs, of the scores will be lost + // save scores before unloading songs, or the scores will be lost PROFILEMAN->SaveMachineProfile(); - if( pLoadingWindow ) - pLoadingWindow->SetText( UNLOADING_COURSES ); + if( ld ) + ld->SetText( UNLOADING_COURSES ); FreeCourses(); - if( pLoadingWindow ) - pLoadingWindow->SetText( UNLOADING_SONGS ); + if( ld ) + ld->SetText( UNLOADING_SONGS ); + FreeSongs(); const bool OldVal = PREFSMAN->m_bFastLoad; if( !bAllowFastLoad ) PREFSMAN->m_bFastLoad.Set( false ); - InitAll(); + InitAll( ld ); // reload scores and unlocks afterward PROFILEMAN->LoadMachineProfile(); @@ -139,14 +140,14 @@ void SongManager::Reload( bool bAllowFastLoad ) UpdatePreferredSort(); } -void SongManager::InitSongsFromDisk() +void SongManager::InitSongsFromDisk( LoadingWindow *ld ) { RageTimer tm; - LoadStepManiaSongDir( SpecialFiles::SONGS_DIR); + LoadStepManiaSongDir( SpecialFiles::SONGS_DIR, ld ); const bool bOldVal = PREFSMAN->m_bFastLoad; PREFSMAN->m_bFastLoad.Set( PREFSMAN->m_bFastLoadAdditionalSongs ); - LoadStepManiaSongDir( ADDITIONAL_SONGS_DIR ); + LoadStepManiaSongDir( ADDITIONAL_SONGS_DIR, ld ); PREFSMAN->m_bFastLoad.Set( bOldVal ); LOG->Trace( "Found %d songs in %f seconds.", (int)m_pSongs.size(), tm.GetDeltaTime() ); @@ -233,7 +234,7 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName ) } static LocalizedString LOADING_SONGS ( "SongManager", "Loading songs..." ); -void SongManager::LoadStepManiaSongDir( RString sDir ) +void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ) { // Make sure sDir has a trailing slash. if( sDir.Right(1) != "/" ) @@ -270,9 +271,9 @@ void SongManager::LoadStepManiaSongDir( RString sDir ) if( songCount==0 ) return; - if( pLoadingWindow ) { - pLoadingWindow->SetIndeterminate( false ); - pLoadingWindow->SetTotalWork( songCount ); + if( ld ) { + ld->SetIndeterminate( false ); + ld->SetTotalWork( songCount ); } groupIndex = 0; @@ -293,10 +294,10 @@ void SongManager::LoadStepManiaSongDir( RString sDir ) RString sSongDirName = arraySongDirs[j]; // this is a song directory. Load a new song. - if( pLoadingWindow ) + if( ld ) { - pLoadingWindow->SetProgress(songIndex); - pLoadingWindow->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s", + ld->SetProgress(songIndex); + ld->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s", Basename(sGroupDirName).c_str(), Basename(sSongDirName).c_str())); } @@ -329,8 +330,8 @@ void SongManager::LoadStepManiaSongDir( RString sDir ) LoadGroupSymLinks(sDir, sGroupDirName); } - if( pLoadingWindow ) { - pLoadingWindow->SetIndeterminate( true ); + if( ld ) { + ld->SetIndeterminate( true ); } LoadEnabledSongsFromPref(); @@ -758,7 +759,7 @@ RString SongManager::ShortenGroupName( RString sLongGroupName ) } static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." ); -void SongManager::InitCoursesFromDisk() +void SongManager::InitCoursesFromDisk( LoadingWindow *ld ) { LOG->Trace( "Loading courses." ); @@ -788,9 +789,9 @@ void SongManager::InitCoursesFromDisk() FOREACH_CONST( RString, vsCoursePaths, sCoursePath ) { - if( pLoadingWindow ) + if( ld ) { - pLoadingWindow->SetText( LOADING_COURSES.GetValue()+ssprintf("\n%s\n%s", + ld->SetText( LOADING_COURSES.GetValue()+ssprintf("\n%s\n%s", Basename(*sCourseGroup).c_str(), Basename(*sCoursePath).c_str())); } diff --git a/src/SongManager.h b/src/SongManager.h index 54eaaa0cec..727f06fd8f 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -1,6 +1,7 @@ #ifndef SONGMANAGER_H #define SONGMANAGER_H +class LoadingWindow; class Song; class Style; class Steps; @@ -34,7 +35,7 @@ public: SongManager(); ~SongManager(); - void InitSongsFromDisk(); + void InitSongsFromDisk( LoadingWindow *ld ); void FreeSongs(); void Cleanup(); @@ -52,7 +53,7 @@ public: void LoadGroupSymLinks( RString sDir, RString sGroupFolder ); - void InitCoursesFromDisk(); + void InitCoursesFromDisk( LoadingWindow *ld ); void InitAutogenCourses(); void InitRandomAttacks(); void FreeCourses(); @@ -62,8 +63,8 @@ public: void DeleteAutogenCourses(); void InvalidateCachedTrails(); - void InitAll(); // songs, courses, groups - everything. - void Reload( bool bAllowFastLoad); // songs, courses, groups - everything. + void InitAll( LoadingWindow *ld ); // songs, courses, groups - everything. + void Reload( bool bAllowFastLoad, LoadingWindow *ld=NULL ); // songs, courses, groups - everything. void PreloadSongImages(); RString GetSongGroupBannerPath( RString sSongGroup ) const; @@ -169,7 +170,7 @@ public: void PushSelf( lua_State *L ); protected: - void LoadStepManiaSongDir( RString sDir ); + void LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ); void LoadDWISongDir( RString sDir ); bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut ); void SanityCheckGroupDir( RString sDir ) const; diff --git a/src/StepMania-net2010.vcxproj.filters b/src/StepMania-net2010.vcxproj.filters index 7837e8d436..23b5698cf5 100644 --- a/src/StepMania-net2010.vcxproj.filters +++ b/src/StepMania-net2010.vcxproj.filters @@ -1620,9 +1620,6 @@ Data Structures - - Actors used in Menus - @@ -3011,9 +3008,6 @@ Data Structures - - Actors used in Menus - diff --git a/src/StepMania.cpp b/src/StepMania.cpp index d866bf7e2d..3847233cef 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -902,7 +902,7 @@ static void WriteLogHeader() struct tm now; localtime_r( &cur_time, &now ); - LOG->Info( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d", + LOG->Info( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d", 1900+now.tm_year, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec ); LOG->Trace( " " ); @@ -1015,7 +1015,7 @@ int main(int argc, char* argv[]) GAMESTATE = new GameState; // This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow. - pLoadingWindow = LoadingWindow::Create(); + LoadingWindow *pLoadingWindow = LoadingWindow::Create(); if(pLoadingWindow == NULL) RageException::Throw("%s", COULDNT_OPEN_LOADING_WINDOW.GetValue().c_str()); @@ -1041,7 +1041,7 @@ int main(int argc, char* argv[]) // Switch to the last used game type, and set up the theme and announcer. SwitchToLastPlayedGame(); - CommandLineActions::Handle(); + CommandLineActions::Handle(pLoadingWindow); if( GetCommandlineArgument("dopefish") ) GAMESTATE->m_bDopefish = true; @@ -1078,7 +1078,7 @@ int main(int argc, char* argv[]) // depends on SONGINDEX: SONGMAN = new SongManager; - SONGMAN->InitAll(); // this takes a long time + SONGMAN->InitAll( pLoadingWindow ); // this takes a long time CRYPTMAN = new CryptManager; // need to do this before ProfileMan if( PREFSMAN->m_bSignProfileData ) CRYPTMAN->GenerateGlobalKeys(); @@ -1096,10 +1096,10 @@ int main(int argc, char* argv[]) // Initialize which courses are ranking courses here. SONGMAN->UpdateRankingCourses(); - SAFE_DELETE( pLoadingWindow ); // destroy this before init'ing Display + SAFE_DELETE( pLoadingWindow ); // destroy this before init'ing Display /* If the user has tried to quit during the loading, do it before creating - * the main window. This prevents going to full screen just to quit. */ + * the main window. This prevents going to full screen just to quit. */ if( ArchHooks::UserQuit() ) { ShutdownGame(); diff --git a/src/ThemeManager.cpp b/src/ThemeManager.cpp index 0e5764c4a6..0b3841869f 100644 --- a/src/ThemeManager.cpp +++ b/src/ThemeManager.cpp @@ -8,7 +8,6 @@ #include "RageTimer.h" #include "FontCharAliases.h" #include "arch/ArchHooks/ArchHooks.h" -#include "arch/LoadingWindow/LoadingWindow.h" #include "arch/Dialog/Dialog.h" #include "RageFile.h" #if !defined(SMPACKAGE) @@ -398,8 +397,6 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt if( bNothingChanging && !bForceThemeReload ) return; - if(pLoadingWindow) pLoadingWindow->SetText("Loading theme & language..."); - m_bPseudoLocalize = bPseudoLocalize; // Load theme metrics. If only the language is changing, this is all diff --git a/src/arch/LoadingWindow/LoadingWindow.cpp b/src/arch/LoadingWindow/LoadingWindow.cpp index c96afbff84..1c75ec774d 100644 --- a/src/arch/LoadingWindow/LoadingWindow.cpp +++ b/src/arch/LoadingWindow/LoadingWindow.cpp @@ -56,8 +56,6 @@ LoadingWindow *LoadingWindow::Create() return ret; } -LoadingWindow *pLoadingWindow; - /* * (c) 2002-2005 Glenn Maynard * All rights reserved. diff --git a/src/arch/LoadingWindow/LoadingWindow.h b/src/arch/LoadingWindow/LoadingWindow.h index ec92728e1f..8dc34d984e 100644 --- a/src/arch/LoadingWindow/LoadingWindow.h +++ b/src/arch/LoadingWindow/LoadingWindow.h @@ -24,8 +24,6 @@ protected: bool m_indeterminate; }; -extern LoadingWindow *pLoadingWindow; - #endif /**