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.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
@@ -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<RageTexture*> 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.
|
||||
*/
|
||||
@@ -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<Song*> &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<Course*> 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()
|
||||
|
||||
@@ -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<int> NUM_SONG_GROUP_COLORS;
|
||||
ThemeMetric1D<RageColor> SONG_GROUP_COLOR;
|
||||
|
||||
Reference in New Issue
Block a user