From f90e4cdf42cee6bbf9b7f7fb04f15321cf455e8e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 30 Jun 2005 22:04:10 +0000 Subject: [PATCH] add RageTexturePreloader. This obsoletes Cached and Permanent textures, implementing them more simply: if you want to keep the texture loaded, just load it and keep the texture around as long as you want it. The old "texture policy" scheme of "keep the texture around for the duration of the screen" was ambiguous--we can have any number of screens loaded. --- stepmania/src/RageTexturePreloader.cpp | 57 ++++++++++++++++++++++++++ stepmania/src/RageTexturePreloader.h | 46 +++++++++++++++++++++ stepmania/src/SongManager.cpp | 12 ++++-- stepmania/src/SongManager.h | 2 + 4 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 stepmania/src/RageTexturePreloader.cpp create mode 100644 stepmania/src/RageTexturePreloader.h diff --git a/stepmania/src/RageTexturePreloader.cpp b/stepmania/src/RageTexturePreloader.cpp new file mode 100644 index 0000000000..5508ad5ea8 --- /dev/null +++ b/stepmania/src/RageTexturePreloader.cpp @@ -0,0 +1,57 @@ +/* + * Preemptively load textures before use, by loading it and keeping + * a reference to it. By putting a RageTexturePreloader inside the + * object doing the preloading, the preload will exist for the lifetime + * of that object. + */ + +#include "global.h" +#include "RageTexturePreloader.h" +#include "RageTextureManager.h" + +void RageTexturePreloader::Load( const RageTextureID &ID ) +{ + ASSERT( TEXTUREMAN ); + + RageTexture *pTexture = TEXTUREMAN->LoadTexture( ID ); + m_apTextures.push_back( pTexture ); +} + +void RageTexturePreloader::UnloadAll() +{ + ASSERT( TEXTUREMAN ); + + for( unsigned i = 0; i < m_apTextures.size(); ++i ) + TEXTUREMAN->UnloadTexture( m_apTextures[i] ); + m_apTextures.clear(); +} + +RageTexturePreloader::~RageTexturePreloader() +{ + UnloadAll(); +} + +/* + * (c) 2005 Glenn Maynard + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/RageTexturePreloader.h b/stepmania/src/RageTexturePreloader.h new file mode 100644 index 0000000000..3782f31302 --- /dev/null +++ b/stepmania/src/RageTexturePreloader.h @@ -0,0 +1,46 @@ +/* RageTexturePreloader - Load textures in advance, for use later. */ + +#ifndef RAGE_TEXTURE_PRELOADER_H +#define RAGE_TEXTURE_PRELOADER_H + +class RageTexture; +struct RageTextureID; + +class RageTexturePreloader +{ +public: + ~RageTexturePreloader(); + void Load( const RageTextureID &ID ); + void UnloadAll(); + void Swap( RageTexturePreloader &rhs ) { swap( m_apTextures, rhs.m_apTextures ); } + +private: + vector m_apTextures; +}; + +#endif + +/* + * (c) 2005 Glenn Maynard + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 863db9f50d..aafbde924b 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -16,7 +16,6 @@ #include "ThemeManager.h" #include "GameManager.h" #include "RageFile.h" -#include "RageTextureManager.h" #include "Sprite.h" #include "ProfileManager.h" #include "MemoryCardManager.h" @@ -266,10 +265,13 @@ void SongManager::LoadGroupSymLinks(CString sDir, CString sGroupFolder) void SongManager::PreloadSongImages() { - ASSERT( TEXTUREMAN ); if( PREFSMAN->m_BannerCache != PrefsManager::BNCACHE_FULL ) return; + /* Load textures before unloading old ones, so we don't reload textures + * that we don't need to. */ + RageTexturePreloader preload; + const vector &songs = SONGMAN->GetAllSongs(); for( unsigned i = 0; i < songs.size(); ++i ) { @@ -277,7 +279,7 @@ void SongManager::PreloadSongImages() continue; const RageTextureID ID = Sprite::SongBannerTexture( songs[i]->GetBannerPath() ); - TEXTUREMAN->PermanentTexture( ID ); + preload.Load( ID ); } vector courses; @@ -288,8 +290,10 @@ void SongManager::PreloadSongImages() continue; const RageTextureID ID = Sprite::SongBannerTexture( courses[i]->m_sBannerPath ); - TEXTUREMAN->PermanentTexture( ID ); + preload.Load( ID ); } + + preload.Swap( m_TexturePreload ); } void SongManager::FreeSongs() diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 20a12ed8d4..ee015f93c0 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -18,6 +18,7 @@ struct lua_State; #include "Difficulty.h" #include "Course.h" #include "ThemeMetric.h" +#include "RageTexturePreloader.h" class SongManager { @@ -128,6 +129,7 @@ protected: CStringArray m_sCourseGroupNames; CStringArray m_sCourseGroupBannerPaths; // each course group may have a banner associated with it + RageTexturePreloader m_TexturePreload; ThemeMetric NUM_SONG_GROUP_COLORS; ThemeMetric1D SONG_GROUP_COLOR;