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

This commit is contained in:
Mark Cannon
2011-08-06 21:33:49 +00:00
parent 76a167d91b
commit e1a447cc36
13 changed files with 105 additions and 79 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ static void Version()
#endif // WIN32 #endif // WIN32
} }
void CommandLineActions::Handle() void CommandLineActions::Handle(LoadingWindow* pLW)
{ {
CommandLineArgs args; CommandLineArgs args;
for(int i=0; i<g_argc; ++i) for(int i=0; i<g_argc; ++i)
+3 -2
View File
@@ -7,8 +7,9 @@ class LoadingWindow;
namespace CommandLineActions namespace CommandLineActions
{ {
/** /**
* @brief Perform a utility function, then exit. */ * @brief Perform a utility function, then exit.
void Handle(); * @param pLW the LoadingWindow that is presently not used? */
void Handle(LoadingWindow* pLW);
/** @brief The housing for the command line arguments. */ /** @brief The housing for the command line arguments. */
class CommandLineArgs class CommandLineArgs
-1
View File
@@ -338,7 +338,6 @@ DualScrollBar.cpp DualScrollBar.h \
EditMenu.cpp EditMenu.h FadingBanner.cpp FadingBanner.h \ EditMenu.cpp EditMenu.h FadingBanner.cpp FadingBanner.h \
GradeDisplay.cpp GradeDisplay.h GraphDisplay.cpp GraphDisplay.h \ GradeDisplay.cpp GradeDisplay.h GraphDisplay.cpp GraphDisplay.h \
GrooveRadar.cpp GrooveRadar.h HelpDisplay.cpp HelpDisplay.h \ GrooveRadar.cpp GrooveRadar.h HelpDisplay.cpp HelpDisplay.h \
InGameLoadingWindow.cpp InGameLoadingWindow.h \
MemoryCardDisplay.cpp MemoryCardDisplay.h \ MemoryCardDisplay.cpp MemoryCardDisplay.h \
MenuTimer.cpp MenuTimer.h \ MenuTimer.cpp MenuTimer.h \
ModIcon.cpp ModIcon.h ModIconRow.cpp ModIconRow.h \ ModIcon.cpp ModIcon.h ModIconRow.cpp ModIconRow.h \
+1 -1
View File
@@ -363,7 +363,7 @@ void ScreenInstallOverlay::Update( float fDeltaTime )
} }
if( playAfterLaunchInfo.bAnySongChanged ) if( playAfterLaunchInfo.bAnySongChanged )
SONGMAN->Reload( false ); SONGMAN->Reload( false, NULL );
if( !playAfterLaunchInfo.sSongDir.empty() ) if( !playAfterLaunchInfo.sSongDir.empty() )
{ {
+51 -16
View File
@@ -6,8 +6,38 @@
#include "RageLog.h" #include "RageLog.h"
#include "ThemeManager.h" #include "ThemeManager.h"
#include "ScreenDimensions.h" #include "ScreenDimensions.h"
#include "arch/LoadingWindow/LoadingWindow.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 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 * this for the initial load, since we don't want to start up the display
@@ -21,30 +51,35 @@ void ScreenReloadSongs::Init()
{ {
Screen::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 ); m_pLoadingWindow = new ScreenReloadSongsLoadingWindow( m_Loading );
}
pLoadingWindow=loadWin;
m_loadingThread.SetName("Song reload work thread");
m_loadingThread.Create(loadingThreadProc,this);
}
ScreenReloadSongs::~ScreenReloadSongs() ScreenReloadSongs::~ScreenReloadSongs()
{ {
m_loadingThread.Wait(); delete m_pLoadingWindow;
RemoveChild(loadWin);
delete loadWin;
} }
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 ); SCREENMAN->PostMessageToTopScreen( SM_GoToNextScreen, 0 );
return 0;
} }
/* /*
+8 -6
View File
@@ -2,20 +2,22 @@
#define SCREEN_RELOAD_SONGS_H #define SCREEN_RELOAD_SONGS_H
#include "Screen.h" #include "Screen.h"
#include "RageThreads.h" #include "BitmapText.h"
class InGameLoadingWindow; class LoadingWindow;
class ScreenReloadSongs: public Screen class ScreenReloadSongs: public Screen
{ {
public: public:
ScreenReloadSongs(); ScreenReloadSongs();
virtual void Init();
~ScreenReloadSongs(); ~ScreenReloadSongs();
virtual void Init();
void Update( float fDeltaTime );
private: private:
InGameLoadingWindow *loadWin; int m_iUpdates;
RageThread m_loadingThread; LoadingWindow *m_pLoadingWindow;
static int loadingThreadProc(void *thisAsVoidPtr); BitmapText m_Loading;
}; };
#endif #endif
+29 -28
View File
@@ -88,11 +88,10 @@ SongManager::~SongManager()
FreeSongs(); FreeSongs();
} }
void SongManager::InitAll() void SongManager::InitAll( LoadingWindow *ld )
{ {
InitSongsFromDisk(); InitSongsFromDisk( ld );
InitCoursesFromDisk( ld );
InitCoursesFromDisk();
InitAutogenCourses(); InitAutogenCourses();
InitRandomAttacks(); InitRandomAttacks();
} }
@@ -100,7 +99,8 @@ void SongManager::InitAll()
static LocalizedString RELOADING ( "SongManager", "Reloading..." ); static LocalizedString RELOADING ( "SongManager", "Reloading..." );
static LocalizedString UNLOADING_SONGS ( "SongManager", "Unloading songs..." ); static LocalizedString UNLOADING_SONGS ( "SongManager", "Unloading songs..." );
static LocalizedString UNLOADING_COURSES ( "SongManager", "Unloading courses..." ); 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( SpecialFiles::SONGS_DIR );
FILEMAN->FlushDirCache( ADDITIONAL_SONGS_DIR ); FILEMAN->FlushDirCache( ADDITIONAL_SONGS_DIR );
@@ -108,26 +108,27 @@ void SongManager::Reload( bool bAllowFastLoad )
FILEMAN->FlushDirCache( ADDITIONAL_COURSES_DIR ); FILEMAN->FlushDirCache( ADDITIONAL_COURSES_DIR );
FILEMAN->FlushDirCache( EDIT_SUBDIR ); FILEMAN->FlushDirCache( EDIT_SUBDIR );
if( pLoadingWindow ) if( ld )
pLoadingWindow->SetText( RELOADING ); 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(); PROFILEMAN->SaveMachineProfile();
if( pLoadingWindow ) if( ld )
pLoadingWindow->SetText( UNLOADING_COURSES ); ld->SetText( UNLOADING_COURSES );
FreeCourses(); FreeCourses();
if( pLoadingWindow ) if( ld )
pLoadingWindow->SetText( UNLOADING_SONGS ); ld->SetText( UNLOADING_SONGS );
FreeSongs(); FreeSongs();
const bool OldVal = PREFSMAN->m_bFastLoad; const bool OldVal = PREFSMAN->m_bFastLoad;
if( !bAllowFastLoad ) if( !bAllowFastLoad )
PREFSMAN->m_bFastLoad.Set( false ); PREFSMAN->m_bFastLoad.Set( false );
InitAll(); InitAll( ld );
// reload scores and unlocks afterward // reload scores and unlocks afterward
PROFILEMAN->LoadMachineProfile(); PROFILEMAN->LoadMachineProfile();
@@ -139,14 +140,14 @@ void SongManager::Reload( bool bAllowFastLoad )
UpdatePreferredSort(); UpdatePreferredSort();
} }
void SongManager::InitSongsFromDisk() void SongManager::InitSongsFromDisk( LoadingWindow *ld )
{ {
RageTimer tm; RageTimer tm;
LoadStepManiaSongDir( SpecialFiles::SONGS_DIR); LoadStepManiaSongDir( SpecialFiles::SONGS_DIR, ld );
const bool bOldVal = PREFSMAN->m_bFastLoad; const bool bOldVal = PREFSMAN->m_bFastLoad;
PREFSMAN->m_bFastLoad.Set( PREFSMAN->m_bFastLoadAdditionalSongs ); PREFSMAN->m_bFastLoad.Set( PREFSMAN->m_bFastLoadAdditionalSongs );
LoadStepManiaSongDir( ADDITIONAL_SONGS_DIR ); LoadStepManiaSongDir( ADDITIONAL_SONGS_DIR, ld );
PREFSMAN->m_bFastLoad.Set( bOldVal ); PREFSMAN->m_bFastLoad.Set( bOldVal );
LOG->Trace( "Found %d songs in %f seconds.", (int)m_pSongs.size(), tm.GetDeltaTime() ); 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..." ); 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. // Make sure sDir has a trailing slash.
if( sDir.Right(1) != "/" ) if( sDir.Right(1) != "/" )
@@ -270,9 +271,9 @@ void SongManager::LoadStepManiaSongDir( RString sDir )
if( songCount==0 ) return; if( songCount==0 ) return;
if( pLoadingWindow ) { if( ld ) {
pLoadingWindow->SetIndeterminate( false ); ld->SetIndeterminate( false );
pLoadingWindow->SetTotalWork( songCount ); ld->SetTotalWork( songCount );
} }
groupIndex = 0; groupIndex = 0;
@@ -293,10 +294,10 @@ void SongManager::LoadStepManiaSongDir( RString sDir )
RString sSongDirName = arraySongDirs[j]; RString sSongDirName = arraySongDirs[j];
// this is a song directory. Load a new song. // this is a song directory. Load a new song.
if( pLoadingWindow ) if( ld )
{ {
pLoadingWindow->SetProgress(songIndex); ld->SetProgress(songIndex);
pLoadingWindow->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s", ld->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s",
Basename(sGroupDirName).c_str(), Basename(sGroupDirName).c_str(),
Basename(sSongDirName).c_str())); Basename(sSongDirName).c_str()));
} }
@@ -329,8 +330,8 @@ void SongManager::LoadStepManiaSongDir( RString sDir )
LoadGroupSymLinks(sDir, sGroupDirName); LoadGroupSymLinks(sDir, sGroupDirName);
} }
if( pLoadingWindow ) { if( ld ) {
pLoadingWindow->SetIndeterminate( true ); ld->SetIndeterminate( true );
} }
LoadEnabledSongsFromPref(); LoadEnabledSongsFromPref();
@@ -758,7 +759,7 @@ RString SongManager::ShortenGroupName( RString sLongGroupName )
} }
static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." ); static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." );
void SongManager::InitCoursesFromDisk() void SongManager::InitCoursesFromDisk( LoadingWindow *ld )
{ {
LOG->Trace( "Loading courses." ); LOG->Trace( "Loading courses." );
@@ -788,9 +789,9 @@ void SongManager::InitCoursesFromDisk()
FOREACH_CONST( RString, vsCoursePaths, sCoursePath ) 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(*sCourseGroup).c_str(),
Basename(*sCoursePath).c_str())); Basename(*sCoursePath).c_str()));
} }
+6 -5
View File
@@ -1,6 +1,7 @@
#ifndef SONGMANAGER_H #ifndef SONGMANAGER_H
#define SONGMANAGER_H #define SONGMANAGER_H
class LoadingWindow;
class Song; class Song;
class Style; class Style;
class Steps; class Steps;
@@ -34,7 +35,7 @@ public:
SongManager(); SongManager();
~SongManager(); ~SongManager();
void InitSongsFromDisk(); void InitSongsFromDisk( LoadingWindow *ld );
void FreeSongs(); void FreeSongs();
void Cleanup(); void Cleanup();
@@ -52,7 +53,7 @@ public:
void LoadGroupSymLinks( RString sDir, RString sGroupFolder ); void LoadGroupSymLinks( RString sDir, RString sGroupFolder );
void InitCoursesFromDisk(); void InitCoursesFromDisk( LoadingWindow *ld );
void InitAutogenCourses(); void InitAutogenCourses();
void InitRandomAttacks(); void InitRandomAttacks();
void FreeCourses(); void FreeCourses();
@@ -62,8 +63,8 @@ public:
void DeleteAutogenCourses(); void DeleteAutogenCourses();
void InvalidateCachedTrails(); void InvalidateCachedTrails();
void InitAll(); // songs, courses, groups - everything. void InitAll( LoadingWindow *ld ); // songs, courses, groups - everything.
void Reload( bool bAllowFastLoad); // songs, courses, groups - everything. void Reload( bool bAllowFastLoad, LoadingWindow *ld=NULL ); // songs, courses, groups - everything.
void PreloadSongImages(); void PreloadSongImages();
RString GetSongGroupBannerPath( RString sSongGroup ) const; RString GetSongGroupBannerPath( RString sSongGroup ) const;
@@ -169,7 +170,7 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
protected: protected:
void LoadStepManiaSongDir( RString sDir ); void LoadStepManiaSongDir( RString sDir, LoadingWindow *ld );
void LoadDWISongDir( RString sDir ); void LoadDWISongDir( RString sDir );
bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut ); bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut );
void SanityCheckGroupDir( RString sDir ) const; void SanityCheckGroupDir( RString sDir ) const;
-6
View File
@@ -1620,9 +1620,6 @@
<ClCompile Include="SongPosition.cpp"> <ClCompile Include="SongPosition.cpp">
<Filter>Data Structures</Filter> <Filter>Data Structures</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="InGameLoadingWindow.cpp">
<Filter>Actors used in Menus</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Screen.h"> <ClInclude Include="Screen.h">
@@ -3011,9 +3008,6 @@
<ClInclude Include="SongPosition.h"> <ClInclude Include="SongPosition.h">
<Filter>Data Structures</Filter> <Filter>Data Structures</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="InGameLoadingWindow.h">
<Filter>Actors used in Menus</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="archutils\Win32\smzip.ico"> <None Include="archutils\Win32\smzip.ico">
+5 -5
View File
@@ -1015,7 +1015,7 @@ int main(int argc, char* argv[])
GAMESTATE = new GameState; GAMESTATE = new GameState;
// This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow. // This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow.
pLoadingWindow = LoadingWindow::Create(); LoadingWindow *pLoadingWindow = LoadingWindow::Create();
if(pLoadingWindow == NULL) if(pLoadingWindow == NULL)
RageException::Throw("%s", COULDNT_OPEN_LOADING_WINDOW.GetValue().c_str()); 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. // Switch to the last used game type, and set up the theme and announcer.
SwitchToLastPlayedGame(); SwitchToLastPlayedGame();
CommandLineActions::Handle(); CommandLineActions::Handle(pLoadingWindow);
if( GetCommandlineArgument("dopefish") ) if( GetCommandlineArgument("dopefish") )
GAMESTATE->m_bDopefish = true; GAMESTATE->m_bDopefish = true;
@@ -1078,7 +1078,7 @@ int main(int argc, char* argv[])
// depends on SONGINDEX: // depends on SONGINDEX:
SONGMAN = new SongManager; 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 CRYPTMAN = new CryptManager; // need to do this before ProfileMan
if( PREFSMAN->m_bSignProfileData ) if( PREFSMAN->m_bSignProfileData )
CRYPTMAN->GenerateGlobalKeys(); CRYPTMAN->GenerateGlobalKeys();
@@ -1096,10 +1096,10 @@ int main(int argc, char* argv[])
// Initialize which courses are ranking courses here. // Initialize which courses are ranking courses here.
SONGMAN->UpdateRankingCourses(); 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 /* 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() ) if( ArchHooks::UserQuit() )
{ {
ShutdownGame(); ShutdownGame();
-3
View File
@@ -8,7 +8,6 @@
#include "RageTimer.h" #include "RageTimer.h"
#include "FontCharAliases.h" #include "FontCharAliases.h"
#include "arch/ArchHooks/ArchHooks.h" #include "arch/ArchHooks/ArchHooks.h"
#include "arch/LoadingWindow/LoadingWindow.h"
#include "arch/Dialog/Dialog.h" #include "arch/Dialog/Dialog.h"
#include "RageFile.h" #include "RageFile.h"
#if !defined(SMPACKAGE) #if !defined(SMPACKAGE)
@@ -398,8 +397,6 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt
if( bNothingChanging && !bForceThemeReload ) if( bNothingChanging && !bForceThemeReload )
return; return;
if(pLoadingWindow) pLoadingWindow->SetText("Loading theme & language...");
m_bPseudoLocalize = bPseudoLocalize; m_bPseudoLocalize = bPseudoLocalize;
// Load theme metrics. If only the language is changing, this is all // Load theme metrics. If only the language is changing, this is all
-2
View File
@@ -56,8 +56,6 @@ LoadingWindow *LoadingWindow::Create()
return ret; return ret;
} }
LoadingWindow *pLoadingWindow;
/* /*
* (c) 2002-2005 Glenn Maynard * (c) 2002-2005 Glenn Maynard
* All rights reserved. * All rights reserved.
-2
View File
@@ -24,8 +24,6 @@ protected:
bool m_indeterminate; bool m_indeterminate;
}; };
extern LoadingWindow *pLoadingWindow;
#endif #endif
/** /**