diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 4dc5828fe1..1c8c74931b 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -59,14 +59,14 @@ BGAnimationLayer::BGAnimationLayer() void BGAnimationLayer::LoadFromStaticGraphic( CString sPath ) { m_iNumSprites = 1; - m_Sprites[0].Load( sPath ); + m_Sprites[0].LoadBG( sPath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); } void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind ) { m_iNumSprites = 1; - m_Sprites[0].Load( sMoviePath ); + m_Sprites[0].LoadBG( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].GetTexture()->Play(); ::Sleep( 50 ); // decode a frame so we don't see a black flash at the beginning @@ -79,7 +79,7 @@ void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewi void BGAnimationLayer::LoadFromVisualization( CString sMoviePath ) { m_iNumSprites = 1; - m_Sprites[0].Load( sMoviePath ); + m_Sprites[0].LoadBG( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].SetBlendModeAdd(); } @@ -142,12 +142,12 @@ found_effect: { case EFFECT_CENTER: m_iNumSprites = 1; - m_Sprites[0].Load( sPath ); + m_Sprites[0].LoadBG( sPath ); m_Sprites[0].SetXY( CENTER_X, CENTER_Y ); break; case EFFECT_STRETCH_STILL: m_iNumSprites = 1; - m_Sprites[0].Load( sPath ); + m_Sprites[0].LoadBG( sPath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); break; case EFFECT_STRETCH_SCROLL_LEFT: @@ -159,9 +159,9 @@ found_effect: case EFFECT_STRETCH_TWIST: { m_iNumSprites = 1; - RageTexturePrefs prefs; - prefs.bStretch = true; - m_Sprites[0].Load( sPath, prefs ); + RageTextureID ID(sPath); + ID.bStretch = true; + m_Sprites[0].LoadBG( ID ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) ); @@ -184,9 +184,9 @@ found_effect: case EFFECT_STRETCH_SCROLL_H: { m_iNumSprites = 1; - RageTexturePrefs prefs; - prefs.bStretch = true; - m_Sprites[0].Load( sPath, prefs ); + RageTextureID ID(sPath); + ID.bStretch = true; + m_Sprites[0].LoadBG( ID ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,0,SCREEN_RIGHT, int(m_Sprites[0].GetUnzoomedHeight())) ); m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) ); m_vTexCoordVelocity = RageVector2(+0.5f,0); @@ -195,20 +195,20 @@ found_effect: break; case EFFECT_STRETCH_SPIN: m_iNumSprites = 1; - m_Sprites[0].Load( sPath ); + m_Sprites[0].LoadBG( sPath ); m_Sprites[0].ScaleToCover( RectI(SCREEN_LEFT-200,SCREEN_TOP-200,SCREEN_RIGHT+200,SCREEN_BOTTOM+200) ); m_fRotationalVelocity = 1; break; case EFFECT_PARTICLES_SPIRAL_OUT: case EFFECT_PARTICLES_SPIRAL_IN: { - m_Sprites[0].Load( sPath ); + m_Sprites[0].LoadBG( sPath ); int iSpriteArea = int( m_Sprites[0].GetUnzoomedWidth()*m_Sprites[0].GetUnzoomedHeight() ); int iMaxArea = SCREEN_WIDTH*SCREEN_HEIGHT; m_iNumSprites = min( iMaxArea / iSpriteArea, MAX_SPRITES ); for( int i=0; iGetPathTo("Graphics","fallback banner") ); } -bool Banner::Load( CString sFilePath, RageTexturePrefs prefs ) +bool Banner::Load( RageTextureID ID ) { // note that the defaults are changes for faster loading - return CroppedSprite::Load( sFilePath, prefs ); + return CroppedSprite::Load( ID ); }; void Banner::Update( float fDeltaTime ) @@ -107,9 +107,9 @@ bool Banner::LoadFromCourse( Course* pCourse ) // NULL means no course bool Banner::LoadRoulette() { - RageTexturePrefs prefs; - prefs.iMipMaps = 0; - Banner::Load( THEME->GetPathTo("Graphics","select music roulette banner"), prefs ); + RageTextureID ID(THEME->GetPathTo("Graphics","select music roulette banner")); + ID.iMipMaps = 0; + Banner::Load( ID ); m_bScrolling = true; return true; diff --git a/stepmania/src/Banner.h b/stepmania/src/Banner.h index ae6019a13b..a2463f02f3 100644 --- a/stepmania/src/Banner.h +++ b/stepmania/src/Banner.h @@ -21,8 +21,7 @@ class Banner : public CroppedSprite public: Banner(); - virtual bool Load( CString sFilePath, RageTexturePrefs prefs ); - virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); } + virtual bool Load( RageTextureID ID ); virtual void Update( float fDeltaTime ); diff --git a/stepmania/src/CroppedSprite.cpp b/stepmania/src/CroppedSprite.cpp index 82eeacfdf2..4b0472da46 100644 --- a/stepmania/src/CroppedSprite.cpp +++ b/stepmania/src/CroppedSprite.cpp @@ -21,9 +21,9 @@ CroppedSprite::CroppedSprite() m_fCropWidth = m_fCropHeight = 100; } -bool CroppedSprite::Load( CString sFilePath, RageTexturePrefs prefs ) +bool CroppedSprite::Load( RageTextureID ID ) { - Sprite::Load( sFilePath, prefs ); + Sprite::Load( ID ); CropToSize( m_fCropWidth, m_fCropHeight ); return true; diff --git a/stepmania/src/CroppedSprite.h b/stepmania/src/CroppedSprite.h index 9b4b7b80c8..eee47df9e9 100644 --- a/stepmania/src/CroppedSprite.h +++ b/stepmania/src/CroppedSprite.h @@ -21,7 +21,7 @@ public: CroppedSprite(); virtual ~CroppedSprite() { } - bool Load( CString sFilePath, RageTexturePrefs prefs ); + bool Load( RageTextureID ID ); void SetCroppedSize( float fWidth, float fHeight ); protected: diff --git a/stepmania/src/Font.cpp b/stepmania/src/Font.cpp index e2d29f03a2..3b393a570e 100644 --- a/stepmania/src/Font.cpp +++ b/stepmania/src/Font.cpp @@ -38,7 +38,7 @@ Font::Font( const CString &sASCIITexturePath ) // load texture m_sTexturePath = sASCIITexturePath; m_sTexturePath.MakeLower(); - m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, RageTexturePrefs() ); + m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath ); ASSERT( m_pTexture != NULL ); if( m_pTexture->GetNumFrames() != 16*16 ) RageException::Throw( "The font '%s' has only %d frames. All fonts must have 16*16 frames.", m_sTexturePath.GetString() ); @@ -115,7 +115,7 @@ Font::Font( const CString &sTexturePath, const CString& sCharacters ) m_sTexturePath.MakeLower(); - m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, RageTexturePrefs() ); + m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath ); ASSERT( m_pTexture != NULL ); m_iLineSpacing = m_pTexture->GetSourceFrameHeight(); diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index 54d60bfccf..84d6145416 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -31,8 +31,6 @@ #include "RageTimer.h" - - /* Definitions for various texture formats. We'll probably want RGBA * in OpenGL, not ARGB ... All of these are in local (little) endian; * this may or may not need adjustment for OpenGL. */ @@ -74,8 +72,8 @@ int PixFmtMaskNo(GLenum fmt) //----------------------------------------------------------------------------- // RageBitmapTexture constructor //----------------------------------------------------------------------------- -RageBitmapTexture::RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs ) : - RageTexture( sFilePath, prefs ) +RageBitmapTexture::RageBitmapTexture( RageTextureID name ) : + RageTexture( name ) { // LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" ); @@ -90,7 +88,7 @@ RageBitmapTexture::~RageBitmapTexture() glDeleteTextures(1, &m_uGLTextureID); } -void RageBitmapTexture::Reload( RageTexturePrefs prefs ) +void RageBitmapTexture::Reload( RageTextureID name ) { DISPLAY->SetTexture(0); @@ -117,20 +115,22 @@ void RageBitmapTexture::Reload( RageTexturePrefs prefs ) void RageBitmapTexture::Create() { // look in the file name for a format hints - m_sFilePath.MakeLower(); + CString HintString = GetFilePath(); + HintString.MakeLower(); - if( m_sFilePath.Find("no alpha") != -1 ) m_prefs.iAlphaBits = 0; - else if( m_sFilePath.Find("1 alpha") != -1 ) m_prefs.iAlphaBits = 1; - else if( m_sFilePath.Find("1alpha") != -1 ) m_prefs.iAlphaBits = 1; - else if( m_sFilePath.Find("0alpha") != -1 ) m_prefs.iAlphaBits = 0; - if( m_sFilePath.Find("dither") != -1 ) m_prefs.bDither = true; + if( HintString.Find("no alpha") != -1 ) m_ActualID.iAlphaBits = 0; + else if( HintString.Find("1 alpha") != -1 ) m_ActualID.iAlphaBits = 1; + else if( HintString.Find("1alpha") != -1 ) m_ActualID.iAlphaBits = 1; + else if( HintString.Find("0alpha") != -1 ) m_ActualID.iAlphaBits = 0; + if( HintString.Find("dither") != -1 ) m_ActualID.bDither = true; /* Load the image into an SDL surface. */ - SDL_Surface *img = IMG_Load(m_sFilePath); + /* XXX we were lowercasing this before */ + SDL_Surface *img = IMG_Load(GetFilePath()); /* XXX: Wait, we don't want to throw for all images; in particular, we * want to tolerate corrupt/unknown background images. */ if(img == NULL) - RageException::Throw( "Couldn't load %s: %s", m_sFilePath, SDL_GetError() ); + RageException::Throw( "Couldn't load %s: %s", GetFilePath(), SDL_GetError() ); /* Figure out which texture format to use. */ GLenum fmtTexture; @@ -149,7 +149,7 @@ void RageBitmapTexture::Create() src_alpha_bits = max( 1, src_alpha_bits ); /* Don't use more than we were hinted to. */ - src_alpha_bits = min( m_prefs.iAlphaBits, src_alpha_bits ); + src_alpha_bits = min( m_ActualID.iAlphaBits, src_alpha_bits ); /* XXX Scan the image, and see if it actually uses its alpha channel/color key * (if any). Reduce to 1 or 0 bits of alpha if possible. */ @@ -170,24 +170,24 @@ void RageBitmapTexture::Create() RageException::Throw( "Invalid color depth: %d bits", TEXTUREMAN->GetTextureColorDepth() ); /* Cap the max texture size to the hardware max. */ - m_prefs.iMaxSize = min( m_prefs.iMaxSize, DISPLAY->GetMaxTextureSize() ); + m_ActualID.iMaxSize = min( m_ActualID.iMaxSize, DISPLAY->GetMaxTextureSize() ); /* Save information about the source. */ m_iSourceWidth = img->w; m_iSourceHeight = img->h; /* image size cannot exceed max size */ - m_iImageWidth = min( m_iSourceWidth, m_prefs.iMaxSize ); - m_iImageHeight = min( m_iSourceHeight, m_prefs.iMaxSize ); + m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize ); + m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize ); /* Texture dimensions need to be a power of two; jump to the next. */ m_iTextureWidth = power_of_two(m_iImageWidth); m_iTextureHeight = power_of_two(m_iImageHeight); - ASSERT( m_iTextureWidth <= m_prefs.iMaxSize ); - ASSERT( m_iTextureHeight <= m_prefs.iMaxSize ); + ASSERT( m_iTextureWidth <= m_ActualID.iMaxSize ); + ASSERT( m_iTextureHeight <= m_ActualID.iMaxSize ); - if(m_prefs.bStretch) + if(m_ActualID.bStretch) { /* The hints asked for the image to be stretched to the texture size, * probably for tiling. */ @@ -198,15 +198,15 @@ void RageBitmapTexture::Create() /* If the source is larger than the texture, we have to scale it down; that's * "stretching", I guess. */ if(m_iSourceWidth != m_iImageWidth || m_iSourceHeight > m_iImageHeight) - m_prefs.bStretch = true; + m_ActualID.bStretch = true; int target = PixFmtMaskNo(fmtTexture); /* Dither only when the target is 16bpp, not when it's 32bpp. */ if( PixFmtMasks[target][4] /* XXX magic 4 */ == 32) - m_prefs.bDither = false; + m_ActualID.bDither = false; - if( m_prefs.bStretch ) + if( m_ActualID.bStretch ) { /* resize currently only does RGBA8888 */ int mask = 0; @@ -215,7 +215,7 @@ void RageBitmapTexture::Create() zoomSurface(img, m_iImageWidth, m_iImageHeight ); } - if( m_prefs.bDither ) + if( m_ActualID.bDither ) { /* Dither down to the destination format. */ SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h, PixFmtMasks[target][4], diff --git a/stepmania/src/RageBitmapTexture.h b/stepmania/src/RageBitmapTexture.h index d94b5c033c..387b25560e 100644 --- a/stepmania/src/RageBitmapTexture.h +++ b/stepmania/src/RageBitmapTexture.h @@ -18,11 +18,11 @@ class RageBitmapTexture : public RageTexture { public: - RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs ); + RageBitmapTexture( RageTextureID name ); virtual ~RageBitmapTexture(); /* only called by RageTextureManager::InvalidateTextures */ virtual void Invalidate() { m_uGLTextureID = 0; } - virtual void Reload( RageTexturePrefs prefs ); + virtual void Reload( RageTextureID name ); protected: void Create(); // called by constructor and Reload diff --git a/stepmania/src/RageMovieTexture.cpp b/stepmania/src/RageMovieTexture.cpp index d99a349b1c..0c44a8be9b 100644 --- a/stepmania/src/RageMovieTexture.cpp +++ b/stepmania/src/RageMovieTexture.cpp @@ -38,12 +38,11 @@ //----------------------------------------------------------------------------- // RageMovieTexture constructor //----------------------------------------------------------------------------- -RageMovieTexture::RageMovieTexture( const CString &sFilePath, RageTexturePrefs prefs ) : - RageTexture( sFilePath, prefs ) +RageMovieTexture::RageMovieTexture( RageTextureID ID ) : + RageTexture( ID ) { LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" ); - m_FilePath = sFilePath; buffer_changed = false; m_uGLTextureID = 0; @@ -80,7 +79,7 @@ RageMovieTexture::~RageMovieTexture() glDeleteTextures(1, &m_uGLTextureID); } -void RageMovieTexture::Reload( RageTexturePrefs prefs ) +void RageMovieTexture::Reload( RageTextureID ID ) { // do nothing } @@ -208,8 +207,8 @@ void RageMovieTexture::NewData(char *data) bool RageMovieTexture::CreateTexture() { /* image size cannot exceed max size */ - m_iImageWidth = min( m_iSourceWidth, m_prefs.iMaxSize ); - m_iImageHeight = min( m_iSourceHeight, m_prefs.iMaxSize ); + m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize ); + m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize ); /* Texture dimensions need to be a power of two; jump to the next. */ m_iTextureWidth = power_of_two(m_iImageWidth); diff --git a/stepmania/src/RageMovieTexture.h b/stepmania/src/RageMovieTexture.h index 4edafea535..5e590b5263 100644 --- a/stepmania/src/RageMovieTexture.h +++ b/stepmania/src/RageMovieTexture.h @@ -43,11 +43,11 @@ typedef char TCHAR, *PTCHAR; class RageMovieTexture : public RageTexture { public: - RageMovieTexture( const CString &sFilePath, RageTexturePrefs prefs ); + RageMovieTexture( RageTextureID ID ); virtual ~RageMovieTexture(); void Update(float fDeltaTime); - virtual void Reload( RageTexturePrefs prefs ); + virtual void Reload( RageTextureID ID ); virtual void Play(); virtual void Pause(); @@ -57,13 +57,9 @@ public: virtual bool IsPlaying() const; void SetLooping(bool looping=true) { m_bLoop = looping; } -// LPDIRECT3DTEXTURE8 GetBackBuffer() { return m_pd3dTexture[!m_iIndexFrontBuffer]; } -// void Flip() { m_iIndexFrontBuffer = !m_iIndexFrontBuffer; } - void NewData(char *buffer); protected: -// LPDIRECT3DTEXTURE8 m_pd3dTexture[2]; // double buffered int m_iIndexFrontBuffer; // index of the buffer that should be rendered from - either 0 or 1 char *buffer; diff --git a/stepmania/src/RageTexture.cpp b/stepmania/src/RageTexture.cpp index cd46ec0c33..45bc3d3ccb 100644 --- a/stepmania/src/RageTexture.cpp +++ b/stepmania/src/RageTexture.cpp @@ -21,12 +21,11 @@ //----------------------------------------------------------------------------- // RageTexture constructor //----------------------------------------------------------------------------- -RageTexture::RageTexture( CString sFilePath, RageTexturePrefs prefs ) +RageTexture::RageTexture( RageTextureID name ) { // LOG->Trace( "RageTexture::RageTexture()" ); - m_sFilePath = sFilePath; - m_prefs = prefs; + m_ID = m_ActualID = name; m_iRefCount = 1; m_iSourceWidth = m_iSourceHeight = 0; @@ -43,7 +42,7 @@ RageTexture::~RageTexture() void RageTexture::CreateFrameRects() { - GetFrameDimensionsFromFileName( m_sFilePath, &m_iFramesWide, &m_iFramesHigh ); + GetFrameDimensionsFromFileName( GetFilePath(), &m_iFramesWide, &m_iFramesHigh ); /////////////////////////////////// // Fill in the m_FrameRects with the bounds of each frame in the animation. diff --git a/stepmania/src/RageTexture.h b/stepmania/src/RageTexture.h index 5d0c7d36db..d854d33a06 100644 --- a/stepmania/src/RageTexture.h +++ b/stepmania/src/RageTexture.h @@ -17,25 +17,31 @@ const int MAX_TEXTURE_FRAMES = 256; - -struct RageTexturePrefs +/* A unique texture is identified by a RageTextureID. (Loading the + * same file with two different dither settings is considered two + * different textures, for example.) */ +struct RageTextureID { - bool bForceReload; + CString filename; int iMaxSize; int iMipMaps; int iAlphaBits; bool bDither; bool bStretch; - RageTexturePrefs() + /* Define an ordering so this can be used in a set<>. */ + bool operator< (const RageTextureID &rhs) const { return filename < rhs.filename; } + + void Init() { - bForceReload = false; iMaxSize = 2048; iMipMaps = 4; iAlphaBits = 4; bDither = false; bStretch = false; } + RageTextureID() { Init(); } + RageTextureID(const CString &fn) { Init(); filename=fn; } }; //----------------------------------------------------------------------------- @@ -44,10 +50,10 @@ struct RageTexturePrefs class RageTexture { public: - RageTexture( CString sFilePath, RageTexturePrefs prefs ); + RageTexture( RageTextureID file ); virtual ~RageTexture() = 0; virtual void Update( float fDeltaTime ) {} - virtual void Reload( RageTexturePrefs prefs ) = 0; + virtual void Reload( RageTextureID file ) = 0; virtual void Invalidate() { } /* only called by RageTextureManager::InvalidateTextures */ virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay @@ -78,26 +84,35 @@ public: int GetImageFrameHeight() const {return GetImageHeight() / GetFramesHigh();} const RectF *GetTextureCoordRect( int frameNo ) const; - int GetNumFrames() const {return m_iFramesWide*m_iFramesHigh;} - CString GetFilePath() const {return m_sFilePath;} + int GetNumFrames() const { return m_iFramesWide*m_iFramesHigh; } + const CString &GetFilePath() const { return GetID().filename; } int m_iRefCount; int m_iTimeOfLastUnload; + /* The ID that we were asked to load: */ + const RageTextureID &GetID() const { return m_ID; } + + /* The ID that we actually got: */ + const RageTextureID &GetActualID() const { return m_ActualID; } + +private: + /* The file we were asked to load. (This is never changed.) */ + RageTextureID m_ID; protected: - - virtual void CreateFrameRects(); - virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const; - - CString m_sFilePath; - RageTexturePrefs m_prefs; + /* We might change settings when loading (due to hints, hardware + * limitations, etc). The data actually loaded is here: */ + RageTextureID m_ActualID; int m_iSourceWidth, m_iSourceHeight; // dimensions of the original image loaded from disk int m_iTextureWidth, m_iTextureHeight; // dimensions of the texture in memory int m_iImageWidth, m_iImageHeight; // dimensions of the image in the texture int m_iFramesWide, m_iFramesHigh; // The number of frames of animation in each row and column of this texture CArray m_TextureCoordRects; // size = m_iFramesWide * m_iFramesHigh + + virtual void CreateFrameRects(); + virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const; }; #endif diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index 888a4eb35b..7463f4246c 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -33,19 +33,19 @@ RageTextureManager::RageTextureManager( int iTextureColorDepth, int iSecondsBefo RageTextureManager::~RageTextureManager() { - for( std::map::iterator i = m_mapPathToTexture.begin(); + for( std::map::iterator i = m_mapPathToTexture.begin(); i != m_mapPathToTexture.end(); ++i) { RageTexture* pTexture = i->second; if( pTexture->m_iRefCount ) - LOG->Trace( "TEXTUREMAN LEAK: '%s', RefCount = %d.", i->first.GetString(), pTexture->m_iRefCount ); + LOG->Trace( "TEXTUREMAN LEAK: '%s', RefCount = %d.", i->first.filename.GetString(), pTexture->m_iRefCount ); SAFE_DELETE( pTexture ); } } void RageTextureManager::Update( float fDeltaTime ) { - for( std::map::iterator i = m_mapPathToTexture.begin(); + for( std::map::iterator i = m_mapPathToTexture.begin(); i != m_mapPathToTexture.end(); ++i) { RageTexture* pTexture = i->second; @@ -56,11 +56,11 @@ void RageTextureManager::Update( float fDeltaTime ) //----------------------------------------------------------------------------- // Load/Unload textures from disk //----------------------------------------------------------------------------- -RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, RageTexturePrefs prefs ) +RageTexture* RageTextureManager::LoadTexture( RageTextureID ID ) { - sTexturePath.MakeLower(); + ID.filename.MakeLower(); -// LOG->Trace( "RageTextureManager::LoadTexture(%s).", sTexturePath.GetString() ); + LOG->Trace( "RageTextureManager::LoadTexture(%s).", ID.filename.GetString() ); // holder for the new texture RageTexture* pTexture; @@ -70,7 +70,7 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, RageTextureP // of the same bitmap if there are equivalent but different paths // (e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp" ). - std::map::iterator p = m_mapPathToTexture.find(sTexturePath); + std::map::iterator p = m_mapPathToTexture.find(ID); if(p != m_mapPathToTexture.end()) { pTexture = p->second; @@ -81,16 +81,16 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, RageTextureP else // the texture is not already loaded { CString sDrive, sDir, sFName, sExt; - splitpath( false, sTexturePath, sDrive, sDir, sFName, sExt ); + splitpath( false, ID.filename, sDrive, sDir, sFName, sExt ); if( sExt == "avi" ) - pTexture = new RageMovieTexture( sTexturePath, prefs ); + pTexture = new RageMovieTexture( ID ); else - pTexture = new RageBitmapTexture( sTexturePath, prefs ); + pTexture = new RageBitmapTexture( ID ); - LOG->Trace( "RageTextureManager: Loaded '%s'.", sTexturePath.GetString() ); + LOG->Trace( "RageTextureManager: Loaded '%s'.", ID.filename.GetString() ); - m_mapPathToTexture[sTexturePath] = pTexture; + m_mapPathToTexture[ID] = pTexture; } // LOG->Trace( "Display: %.2f KB video memory left", DISPLAY->GetDevice()->GetAvailableTextureMem()/1000000.0f ); @@ -121,13 +121,13 @@ void RageTextureManager::GCTextures() LOG->Trace("Performing texture garbage collection"); timeLastGarbageCollect = time(NULL); - for( std::map::iterator i = m_mapPathToTexture.begin(); + for( std::map::iterator i = m_mapPathToTexture.begin(); i != m_mapPathToTexture.end(); ) { - std::map::iterator j = i; + std::map::iterator j = i; i++; - CString sPath = j->first; + CString sPath = j->first.filename; RageTexture* pTexture = j->second; if( pTexture->m_iRefCount==0 && pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload < time(NULL) ) @@ -139,26 +139,31 @@ void RageTextureManager::GCTextures() } -void RageTextureManager::UnloadTexture( CString sTexturePath ) +void RageTextureManager::UnloadTexture( RageTextureID ID ) { - sTexturePath.MakeLower(); + ID.filename.MakeLower(); -// LOG->Trace( "RageTextureManager::UnloadTexture(%s).", sTexturePath.GetString() ); - - if( sTexturePath == "" ) + if( ID.filename == "" ) { //LOG->Trace( "RageTextureManager::UnloadTexture(): tried to Unload a blank texture." ); return; } - - std::map::iterator p = m_mapPathToTexture.find(sTexturePath); + LOG->Trace( "RageTextureManager::UnloadTexture(%s).", ID.filename.GetString() ); + + std::map::iterator p = m_mapPathToTexture.find(ID); if(p == m_mapPathToTexture.end()) - RageException::Throw( "Tried to Unload texture '%s' that wasn't loaded.", sTexturePath.GetString() ); + RageException::Throw( "Tried to Unload texture '%s' that wasn't loaded.", ID.filename.GetString() ); RageTexture* pTexture = p->second; - pTexture->m_iRefCount--; - pTexture->m_iTimeOfLastUnload = time(NULL); - ASSERT( pTexture->m_iRefCount >= 0 ); + UnloadTexture(p->second); + //LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath.GetString(), pTexture->m_iRefCount ); +} + +void RageTextureManager::UnloadTexture( RageTexture *t ) +{ + t->m_iRefCount--; + t->m_iTimeOfLastUnload = time(NULL); + ASSERT( t->m_iRefCount >= 0 ); /* Always unload movies, so we don't waste time decoding. * @@ -168,39 +173,38 @@ void RageTextureManager::UnloadTexture( CString sTexturePath ) * * Also, if texture caching is off, just remove it now instead of doing * garbage collection. */ - if( pTexture->m_iRefCount == 0 && - (pTexture->IsAMovie() || !m_iSecondsBeforeUnload )) + m_iSecondsBeforeUnload = 0; + if( t->m_iRefCount == 0 && + (t->IsAMovie() || !m_iSecondsBeforeUnload )) { // LOG->Trace( "RageTextureManager: '%s' will be deleted. It has %d references.", sTexturePath.GetString(), pTexture->m_iRefCount ); - SAFE_DELETE( pTexture ); // free the texture - m_mapPathToTexture.erase(p); // and remove the key in the map + m_mapPathToTexture.erase(t->GetID()); // and remove the key in the map + SAFE_DELETE( t ); // free the texture } GCTextures(); - - //LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath.GetString(), pTexture->m_iRefCount ); } void RageTextureManager::ReloadAll() { - for( std::map::iterator i = m_mapPathToTexture.begin(); + for( std::map::iterator i = m_mapPathToTexture.begin(); i != m_mapPathToTexture.end(); ++i) { RageTexture* pTexture = i->second; - pTexture->Reload( RageTexturePrefs() ); // this is not entirely correct. Hints are lost! XXX + pTexture->Reload( i->first ); } } /* In some cases, changing the display mode will reset the rendering context, * releasing all textures. We don't want to reload immediately if that happens, * since we might be changing texture preferences too, which also may have to reload - * textures. Instead, tell all textures that their texutre ID is invalid, so it + * textures. Instead, tell all textures that their texture ID is invalid, so it * doesn't try to free it later when we really do reload (since that ID might be * associated with a different texture). Ack. */ void RageTextureManager::InvalidateTextures() { - for( std::map::iterator i = m_mapPathToTexture.begin(); + for( std::map::iterator i = m_mapPathToTexture.begin(); i != m_mapPathToTexture.end(); ++i) { RageTexture* pTexture = i->second; diff --git a/stepmania/src/RageTextureManager.h b/stepmania/src/RageTextureManager.h index 4ed55f9f97..98fa4a425a 100644 --- a/stepmania/src/RageTextureManager.h +++ b/stepmania/src/RageTextureManager.h @@ -25,9 +25,10 @@ public: virtual void Update( float fDeltaTime ); ~RageTextureManager(); - RageTexture* LoadTexture( CString sTexturePath, RageTexturePrefs prefs ); - bool IsTextureLoaded( CString sTexturePath ); - void UnloadTexture( CString sTexturePath ); + RageTexture* LoadTexture( RageTextureID ID ); + bool IsTextureLoaded( CString sTexturePath ); // XXX + void UnloadTexture( RageTextureID ID ); + void UnloadTexture( RageTexture *t ); void ReloadAll(); bool SetPrefs( int iTextureColorDepth, int iSecsBeforeUnload ); @@ -42,7 +43,7 @@ protected: int m_iTextureColorDepth; int m_iSecondsBeforeUnload; - std::map m_mapPathToTexture; + std::map m_mapPathToTexture; }; extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program diff --git a/stepmania/src/ScrollingList.cpp b/stepmania/src/ScrollingList.cpp index 554b44c37f..09db81197d 100644 --- a/stepmania/src/ScrollingList.cpp +++ b/stepmania/src/ScrollingList.cpp @@ -92,8 +92,6 @@ in the scrolling list *************************************/ void ScrollingList::Load( const CStringArray& asGraphicPaths ) { - RageTexturePrefs prefs; - Unload(); if(m_iSpriteType == SPRITE_TYPE_SPRITE) { @@ -123,7 +121,7 @@ void ScrollingList::Load( const CStringArray& asGraphicPaths ) pNewCSprite->SetCroppedSize( EZ2_BANNER_WIDTH*2, EZ2_BANNER_HEIGHT*2 ); } - pNewCSprite->Load( asGraphicPaths[i], prefs ); + pNewCSprite->Load( asGraphicPaths[i] ); m_apCSprites.push_back( pNewCSprite ); } } diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index c69950c1e4..8dea1ced5a 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -37,9 +37,7 @@ Sprite::Sprite() Sprite::~Sprite() { -// LOG->Trace( "Sprite Destructor" ); - - TEXTUREMAN->UnloadTexture( m_sTexturePath ); + UnloadTexture(); } @@ -52,13 +50,13 @@ Sprite::~Sprite() // Delay0000=1.0 // Frame0001=3 // Delay0000=2.0 -bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ) +bool Sprite::LoadFromSpriteFile( RageTextureID ID ) { - LOG->Trace( ssprintf("Sprite::LoadFromSpriteFile(%s)", sSpritePath.GetString()) ); + LOG->Trace( ssprintf("Sprite::LoadFromSpriteFile(%s)", ID.filename.GetString()) ); //Init(); - m_sSpritePath = sSpritePath; + m_sSpritePath = ID.filename; // Split for the directory. We'll need it below @@ -80,14 +78,13 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ) if( sTextureFile == "" ) RageException::Throw( "Error reading value 'Texture' from %s.", m_sSpritePath.GetString() ); - CString sTexturePath = sFontDir + sTextureFile; // save the path of the new texture - - if( !DoesFileExist(sTexturePath) ) - RageException::Throw( "The sprite file '%s' points to a texture '%s' which doesn't exist.", m_sSpritePath.GetString(), sTexturePath.GetString() ); + ID.filename = sFontDir + sTextureFile; // save the path of the real texture + if( !DoesFileExist(ID.filename) ) + RageException::Throw( "The sprite file '%s' points to a texture '%s' which doesn't exist.", m_sSpritePath.GetString(), ID.filename.GetString() ); // Load the texture - LoadFromTexture( sTexturePath, prefs ); + LoadFromTexture( ID ); // Read in frames and delays from the sprite file, // overwriting the states that LoadFromTexture created. @@ -101,7 +98,7 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ) break; if( m_iStateToFrame[i] >= m_pTexture->GetNumFrames() ) RageException::Throw( "In '%s', %s is %d, but the texture %s only has %d frames.", - m_sSpritePath.GetString(), sFrameKey.GetString(), m_iStateToFrame[i], sTexturePath.GetString(), m_pTexture->GetNumFrames() ); + m_sSpritePath.GetString(), sFrameKey.GetString(), m_iStateToFrame[i], ID.filename.GetString(), m_pTexture->GetNumFrames() ); m_fDelay[i] = 0.2f; if( !ini.GetValueF( "Sprite", sDelayKey, m_fDelay[i] ) ) break; @@ -126,19 +123,16 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ) void Sprite::UnloadTexture() { if( m_pTexture != NULL ) // If there was a previous bitmap... - TEXTUREMAN->UnloadTexture( m_sTexturePath ); // Unload it. + TEXTUREMAN->UnloadTexture( m_pTexture ); // Unload it. m_pTexture = NULL; - m_sTexturePath = ""; } -bool Sprite::LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs ) +bool Sprite::LoadFromTexture( RageTextureID ID ) { UnloadTexture(); - m_sTexturePath = sTexturePath; - - m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, prefs ); - assert( m_pTexture != NULL ); + m_pTexture = TEXTUREMAN->LoadTexture( ID ); + ASSERT( m_pTexture != NULL ); // the size of the sprite is the size of the image before it was scaled Sprite::m_size.x = (float)m_pTexture->GetSourceFrameWidth(); diff --git a/stepmania/src/Sprite.h b/stepmania/src/Sprite.h index 58ec7ba549..7182d320ca 100644 --- a/stepmania/src/Sprite.h +++ b/stepmania/src/Sprite.h @@ -28,14 +28,22 @@ public: Sprite(); virtual ~Sprite(); - virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); } - virtual bool Load( CString sFilePath, RageTexturePrefs prefs ) + /* Just a convenience function; load an image that'll be used in the + * background. */ + virtual bool LoadBG( RageTextureID ID ) { - ASSERT( sFilePath != "" ); - if( sFilePath.Right(7) == ".sprite" ) - return LoadFromSpriteFile( sFilePath, prefs ); + ID.iMipMaps = 1; + ID.bDither = true; + return Load(ID); + } + + virtual bool Load( RageTextureID ID ) + { + ASSERT( ID.filename != "" ); + if( ID.filename.Right(7) == ".sprite" ) + return LoadFromSpriteFile( ID ); else - return LoadFromTexture( sFilePath, prefs ); + return LoadFromTexture( ID ); }; void UnloadTexture(); RageTexture* GetTexture() { return m_pTexture; }; @@ -48,8 +56,7 @@ public: virtual void SetState( int iNewState ); int GetNumStates() { return m_iNumStates; }; - CString GetTexturePath() { return m_sTexturePath; }; - + CString GetTexturePath() { ASSERT(m_pTexture); return m_pTexture->GetID().filename; }; void SetCustomTextureRect( const RectF &new_texcoord_frect ); void SetCustomTextureCoords( float fTexCoords[8] ); @@ -60,14 +67,13 @@ public: void StopUsingCustomCoords(); protected: - virtual bool LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs ); - virtual bool LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ); + virtual bool LoadFromTexture( RageTextureID ID ); + virtual bool LoadFromSpriteFile( RageTextureID ID ); CString m_sSpritePath; RageTexture* m_pTexture; bool m_bDrawIfTextureNull; - CString m_sTexturePath; int m_iStateToFrame[MAX_SPRITE_STATES]; // array of indicies into m_rectBitmapFrames float m_fDelay[MAX_SPRITE_STATES];