Textures are now fully ID'd by a single struct.

This commit is contained in:
Glenn Maynard
2002-12-30 02:43:52 +00:00
parent c85593bf07
commit e0b472f33e
18 changed files with 172 additions and 176 deletions
+18 -18
View File
@@ -59,14 +59,14 @@ BGAnimationLayer::BGAnimationLayer()
void BGAnimationLayer::LoadFromStaticGraphic( CString sPath ) void BGAnimationLayer::LoadFromStaticGraphic( CString sPath )
{ {
m_iNumSprites = 1; 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) ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
} }
void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind ) void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind )
{ {
m_iNumSprites = 1; 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].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
m_Sprites[0].GetTexture()->Play(); m_Sprites[0].GetTexture()->Play();
::Sleep( 50 ); // decode a frame so we don't see a black flash at the beginning ::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 ) void BGAnimationLayer::LoadFromVisualization( CString sMoviePath )
{ {
m_iNumSprites = 1; 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].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
m_Sprites[0].SetBlendModeAdd(); m_Sprites[0].SetBlendModeAdd();
} }
@@ -142,12 +142,12 @@ found_effect:
{ {
case EFFECT_CENTER: case EFFECT_CENTER:
m_iNumSprites = 1; m_iNumSprites = 1;
m_Sprites[0].Load( sPath ); m_Sprites[0].LoadBG( sPath );
m_Sprites[0].SetXY( CENTER_X, CENTER_Y ); m_Sprites[0].SetXY( CENTER_X, CENTER_Y );
break; break;
case EFFECT_STRETCH_STILL: case EFFECT_STRETCH_STILL:
m_iNumSprites = 1; 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) ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
break; break;
case EFFECT_STRETCH_SCROLL_LEFT: case EFFECT_STRETCH_SCROLL_LEFT:
@@ -159,9 +159,9 @@ found_effect:
case EFFECT_STRETCH_TWIST: case EFFECT_STRETCH_TWIST:
{ {
m_iNumSprites = 1; m_iNumSprites = 1;
RageTexturePrefs prefs; RageTextureID ID(sPath);
prefs.bStretch = true; ID.bStretch = true;
m_Sprites[0].Load( sPath, prefs ); m_Sprites[0].LoadBG( ID );
m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) ); m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) );
@@ -184,9 +184,9 @@ found_effect:
case EFFECT_STRETCH_SCROLL_H: case EFFECT_STRETCH_SCROLL_H:
{ {
m_iNumSprites = 1; m_iNumSprites = 1;
RageTexturePrefs prefs; RageTextureID ID(sPath);
prefs.bStretch = true; ID.bStretch = true;
m_Sprites[0].Load( sPath, prefs ); m_Sprites[0].LoadBG( ID );
m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,0,SCREEN_RIGHT, int(m_Sprites[0].GetUnzoomedHeight())) ); 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_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) );
m_vTexCoordVelocity = RageVector2(+0.5f,0); m_vTexCoordVelocity = RageVector2(+0.5f,0);
@@ -195,20 +195,20 @@ found_effect:
break; break;
case EFFECT_STRETCH_SPIN: case EFFECT_STRETCH_SPIN:
m_iNumSprites = 1; 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_Sprites[0].ScaleToCover( RectI(SCREEN_LEFT-200,SCREEN_TOP-200,SCREEN_RIGHT+200,SCREEN_BOTTOM+200) );
m_fRotationalVelocity = 1; m_fRotationalVelocity = 1;
break; break;
case EFFECT_PARTICLES_SPIRAL_OUT: case EFFECT_PARTICLES_SPIRAL_OUT:
case EFFECT_PARTICLES_SPIRAL_IN: 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 iSpriteArea = int( m_Sprites[0].GetUnzoomedWidth()*m_Sprites[0].GetUnzoomedHeight() );
int iMaxArea = SCREEN_WIDTH*SCREEN_HEIGHT; int iMaxArea = SCREEN_WIDTH*SCREEN_HEIGHT;
m_iNumSprites = min( iMaxArea / iSpriteArea, MAX_SPRITES ); m_iNumSprites = min( iMaxArea / iSpriteArea, MAX_SPRITES );
for( int i=0; i<m_iNumSprites; i++ ) for( int i=0; i<m_iNumSprites; i++ )
{ {
m_Sprites[i].Load( sPath ); m_Sprites[i].LoadBG( sPath );
m_Sprites[i].SetZoom( randomf(0.2f,2) ); m_Sprites[i].SetZoom( randomf(0.2f,2) );
m_Sprites[i].SetRotation( randomf(0,PI*2) ); m_Sprites[i].SetRotation( randomf(0,PI*2) );
} }
@@ -220,13 +220,13 @@ found_effect:
case EFFECT_PARTICLES_FLOAT_RIGHT: case EFFECT_PARTICLES_FLOAT_RIGHT:
case EFFECT_PARTICLES_BOUNCE: case EFFECT_PARTICLES_BOUNCE:
{ {
m_Sprites[0].Load( sPath ); m_Sprites[0].LoadBG( sPath );
int iSpriteArea = int( m_Sprites[0].GetUnzoomedWidth()*m_Sprites[0].GetUnzoomedHeight() ); int iSpriteArea = int( m_Sprites[0].GetUnzoomedWidth()*m_Sprites[0].GetUnzoomedHeight() );
int iMaxArea = SCREEN_WIDTH*SCREEN_HEIGHT; int iMaxArea = SCREEN_WIDTH*SCREEN_HEIGHT;
m_iNumSprites = min( iMaxArea / iSpriteArea, MAX_SPRITES ); m_iNumSprites = min( iMaxArea / iSpriteArea, MAX_SPRITES );
for( int i=0; i<m_iNumSprites; i++ ) for( int i=0; i<m_iNumSprites; i++ )
{ {
m_Sprites[i].Load( sPath ); m_Sprites[i].LoadBG( sPath );
m_Sprites[i].SetZoom( 0.7f + 0.6f*i/(float)m_iNumSprites ); m_Sprites[i].SetZoom( 0.7f + 0.6f*i/(float)m_iNumSprites );
m_Sprites[i].SetX( randomf( GetGuardRailLeft(&m_Sprites[i]), GetGuardRailRight(&m_Sprites[i]) ) ); m_Sprites[i].SetX( randomf( GetGuardRailLeft(&m_Sprites[i]), GetGuardRailRight(&m_Sprites[i]) ) );
m_Sprites[i].SetY( randomf( GetGuardRailTop(&m_Sprites[i]), GetGuardRailBottom(&m_Sprites[i]) ) ); m_Sprites[i].SetY( randomf( GetGuardRailTop(&m_Sprites[i]), GetGuardRailBottom(&m_Sprites[i]) ) );
@@ -249,7 +249,7 @@ found_effect:
case EFFECT_TILE_FLIP_Y: case EFFECT_TILE_FLIP_Y:
case EFFECT_TILE_PULSE: case EFFECT_TILE_PULSE:
{ {
m_Sprites[0].Load( sPath ); m_Sprites[0].LoadBG( sPath );
int iNumTilesWide = 1+int(SCREEN_WIDTH /m_Sprites[0].GetUnzoomedWidth()); int iNumTilesWide = 1+int(SCREEN_WIDTH /m_Sprites[0].GetUnzoomedWidth());
int iNumTilesHigh = 1+int(SCREEN_HEIGHT/m_Sprites[0].GetUnzoomedHeight()); int iNumTilesHigh = 1+int(SCREEN_HEIGHT/m_Sprites[0].GetUnzoomedHeight());
if( m_Effect == EFFECT_TILE_SCROLL_LEFT || if( m_Effect == EFFECT_TILE_SCROLL_LEFT ||
@@ -271,7 +271,7 @@ found_effect:
for( int y=0; y<iNumTilesHigh; y++ ) for( int y=0; y<iNumTilesHigh; y++ )
{ {
int i = x+y*iNumTilesWide; int i = x+y*iNumTilesWide;
m_Sprites[i].Load( sPath ); m_Sprites[i].LoadBG( sPath );
m_Sprites[i].SetX( (x+0.5f)*m_Sprites[i].GetUnzoomedWidth() ); m_Sprites[i].SetX( (x+0.5f)*m_Sprites[i].GetUnzoomedWidth() );
m_Sprites[i].SetY( (y+0.5f)*m_Sprites[i].GetUnzoomedHeight() ); m_Sprites[i].SetY( (y+0.5f)*m_Sprites[i].GetUnzoomedHeight() );
} }
+1 -16
View File
@@ -161,23 +161,8 @@ void Background::LoadFromSong( Song* pSong )
// //
// Tricky! The song background looks terrible unless its loaded with no alpha
// and dithered. Create a dummy sprite that loads the texture with the proper
// hints so we don't have to hack up BGAnimation to handle this special
// case.
// XXX: This assumes the TextureManager doesn't track hints. Also, BGA
// backgrounds (bottom layer) should do this, too, for the same reason.
// We can probably handle this intelligently in the texture loader and get
// rid of bDither completely, but only if there aren't some weird BGAs out
// there that actually use the alpha channel. (In that case, the texture
// loader would have no way of knowing that the image, seeming to use the
// alpha layer, actually doesn't since it's the back-most image. Hmm.)
Sprite sprDummy; Sprite sprDummy;
RageTexturePrefs prefs; sprDummy.LoadBG( sSongBackgroundPath );
prefs.bForceReload = true;
prefs.iMipMaps = 1;
prefs.bDither = true;
sprDummy.Load( sSongBackgroundPath, prefs );
{ {
BGAnimation *pTempBGA = new BGAnimation; BGAnimation *pTempBGA = new BGAnimation;
+5 -5
View File
@@ -25,10 +25,10 @@ Banner::Banner()
Banner::Load( THEME->GetPathTo("Graphics","fallback banner") ); Banner::Load( THEME->GetPathTo("Graphics","fallback banner") );
} }
bool Banner::Load( CString sFilePath, RageTexturePrefs prefs ) bool Banner::Load( RageTextureID ID )
{ {
// note that the defaults are changes for faster loading // note that the defaults are changes for faster loading
return CroppedSprite::Load( sFilePath, prefs ); return CroppedSprite::Load( ID );
}; };
void Banner::Update( float fDeltaTime ) void Banner::Update( float fDeltaTime )
@@ -107,9 +107,9 @@ bool Banner::LoadFromCourse( Course* pCourse ) // NULL means no course
bool Banner::LoadRoulette() bool Banner::LoadRoulette()
{ {
RageTexturePrefs prefs; RageTextureID ID(THEME->GetPathTo("Graphics","select music roulette banner"));
prefs.iMipMaps = 0; ID.iMipMaps = 0;
Banner::Load( THEME->GetPathTo("Graphics","select music roulette banner"), prefs ); Banner::Load( ID );
m_bScrolling = true; m_bScrolling = true;
return true; return true;
+1 -2
View File
@@ -21,8 +21,7 @@ class Banner : public CroppedSprite
public: public:
Banner(); Banner();
virtual bool Load( CString sFilePath, RageTexturePrefs prefs ); virtual bool Load( RageTextureID ID );
virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); }
virtual void Update( float fDeltaTime ); virtual void Update( float fDeltaTime );
+2 -2
View File
@@ -21,9 +21,9 @@ CroppedSprite::CroppedSprite()
m_fCropWidth = m_fCropHeight = 100; 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 ); CropToSize( m_fCropWidth, m_fCropHeight );
return true; return true;
+1 -1
View File
@@ -21,7 +21,7 @@ public:
CroppedSprite(); CroppedSprite();
virtual ~CroppedSprite() { } virtual ~CroppedSprite() { }
bool Load( CString sFilePath, RageTexturePrefs prefs ); bool Load( RageTextureID ID );
void SetCroppedSize( float fWidth, float fHeight ); void SetCroppedSize( float fWidth, float fHeight );
protected: protected:
+2 -2
View File
@@ -38,7 +38,7 @@ Font::Font( const CString &sASCIITexturePath )
// load texture // load texture
m_sTexturePath = sASCIITexturePath; m_sTexturePath = sASCIITexturePath;
m_sTexturePath.MakeLower(); m_sTexturePath.MakeLower();
m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, RageTexturePrefs() ); m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath );
ASSERT( m_pTexture != NULL ); ASSERT( m_pTexture != NULL );
if( m_pTexture->GetNumFrames() != 16*16 ) 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() ); 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_sTexturePath.MakeLower();
m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, RageTexturePrefs() ); m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath );
ASSERT( m_pTexture != NULL ); ASSERT( m_pTexture != NULL );
m_iLineSpacing = m_pTexture->GetSourceFrameHeight(); m_iLineSpacing = m_pTexture->GetSourceFrameHeight();
+24 -24
View File
@@ -31,8 +31,6 @@
#include "RageTimer.h" #include "RageTimer.h"
/* Definitions for various texture formats. We'll probably want RGBA /* Definitions for various texture formats. We'll probably want RGBA
* in OpenGL, not ARGB ... All of these are in local (little) endian; * in OpenGL, not ARGB ... All of these are in local (little) endian;
* this may or may not need adjustment for OpenGL. */ * this may or may not need adjustment for OpenGL. */
@@ -74,8 +72,8 @@ int PixFmtMaskNo(GLenum fmt)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// RageBitmapTexture constructor // RageBitmapTexture constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
RageBitmapTexture::RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs ) : RageBitmapTexture::RageBitmapTexture( RageTextureID name ) :
RageTexture( sFilePath, prefs ) RageTexture( name )
{ {
// LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" ); // LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
@@ -90,7 +88,7 @@ RageBitmapTexture::~RageBitmapTexture()
glDeleteTextures(1, &m_uGLTextureID); glDeleteTextures(1, &m_uGLTextureID);
} }
void RageBitmapTexture::Reload( RageTexturePrefs prefs ) void RageBitmapTexture::Reload( RageTextureID name )
{ {
DISPLAY->SetTexture(0); DISPLAY->SetTexture(0);
@@ -117,20 +115,22 @@ void RageBitmapTexture::Reload( RageTexturePrefs prefs )
void RageBitmapTexture::Create() void RageBitmapTexture::Create()
{ {
// look in the file name for a format hints // 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; if( HintString.Find("no alpha") != -1 ) m_ActualID.iAlphaBits = 0;
else if( m_sFilePath.Find("1 alpha") != -1 ) m_prefs.iAlphaBits = 1; else if( HintString.Find("1 alpha") != -1 ) m_ActualID.iAlphaBits = 1;
else if( m_sFilePath.Find("1alpha") != -1 ) m_prefs.iAlphaBits = 1; else if( HintString.Find("1alpha") != -1 ) m_ActualID.iAlphaBits = 1;
else if( m_sFilePath.Find("0alpha") != -1 ) m_prefs.iAlphaBits = 0; else if( HintString.Find("0alpha") != -1 ) m_ActualID.iAlphaBits = 0;
if( m_sFilePath.Find("dither") != -1 ) m_prefs.bDither = true; if( HintString.Find("dither") != -1 ) m_ActualID.bDither = true;
/* Load the image into an SDL surface. */ /* 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 /* XXX: Wait, we don't want to throw for all images; in particular, we
* want to tolerate corrupt/unknown background images. */ * want to tolerate corrupt/unknown background images. */
if(img == NULL) 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. */ /* Figure out which texture format to use. */
GLenum fmtTexture; GLenum fmtTexture;
@@ -149,7 +149,7 @@ void RageBitmapTexture::Create()
src_alpha_bits = max( 1, src_alpha_bits ); src_alpha_bits = max( 1, src_alpha_bits );
/* Don't use more than we were hinted to. */ /* 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 /* 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. */ * (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() ); RageException::Throw( "Invalid color depth: %d bits", TEXTUREMAN->GetTextureColorDepth() );
/* Cap the max texture size to the hardware max. */ /* 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. */ /* Save information about the source. */
m_iSourceWidth = img->w; m_iSourceWidth = img->w;
m_iSourceHeight = img->h; m_iSourceHeight = img->h;
/* image size cannot exceed max size */ /* image size cannot exceed max size */
m_iImageWidth = min( m_iSourceWidth, m_prefs.iMaxSize ); m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize );
m_iImageHeight = min( m_iSourceHeight, m_prefs.iMaxSize ); m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize );
/* Texture dimensions need to be a power of two; jump to the next. */ /* Texture dimensions need to be a power of two; jump to the next. */
m_iTextureWidth = power_of_two(m_iImageWidth); m_iTextureWidth = power_of_two(m_iImageWidth);
m_iTextureHeight = power_of_two(m_iImageHeight); m_iTextureHeight = power_of_two(m_iImageHeight);
ASSERT( m_iTextureWidth <= m_prefs.iMaxSize ); ASSERT( m_iTextureWidth <= m_ActualID.iMaxSize );
ASSERT( m_iTextureHeight <= m_prefs.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, /* The hints asked for the image to be stretched to the texture size,
* probably for tiling. */ * 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 /* If the source is larger than the texture, we have to scale it down; that's
* "stretching", I guess. */ * "stretching", I guess. */
if(m_iSourceWidth != m_iImageWidth || m_iSourceHeight > m_iImageHeight) if(m_iSourceWidth != m_iImageWidth || m_iSourceHeight > m_iImageHeight)
m_prefs.bStretch = true; m_ActualID.bStretch = true;
int target = PixFmtMaskNo(fmtTexture); int target = PixFmtMaskNo(fmtTexture);
/* Dither only when the target is 16bpp, not when it's 32bpp. */ /* Dither only when the target is 16bpp, not when it's 32bpp. */
if( PixFmtMasks[target][4] /* XXX magic 4 */ == 32) 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 */ /* resize currently only does RGBA8888 */
int mask = 0; int mask = 0;
@@ -215,7 +215,7 @@ void RageBitmapTexture::Create()
zoomSurface(img, m_iImageWidth, m_iImageHeight ); zoomSurface(img, m_iImageWidth, m_iImageHeight );
} }
if( m_prefs.bDither ) if( m_ActualID.bDither )
{ {
/* Dither down to the destination format. */ /* Dither down to the destination format. */
SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h, PixFmtMasks[target][4], SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h, PixFmtMasks[target][4],
+2 -2
View File
@@ -18,11 +18,11 @@
class RageBitmapTexture : public RageTexture class RageBitmapTexture : public RageTexture
{ {
public: public:
RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs ); RageBitmapTexture( RageTextureID name );
virtual ~RageBitmapTexture(); virtual ~RageBitmapTexture();
/* only called by RageTextureManager::InvalidateTextures */ /* only called by RageTextureManager::InvalidateTextures */
virtual void Invalidate() { m_uGLTextureID = 0; } virtual void Invalidate() { m_uGLTextureID = 0; }
virtual void Reload( RageTexturePrefs prefs ); virtual void Reload( RageTextureID name );
protected: protected:
void Create(); // called by constructor and Reload void Create(); // called by constructor and Reload
+5 -6
View File
@@ -38,12 +38,11 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// RageMovieTexture constructor // RageMovieTexture constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
RageMovieTexture::RageMovieTexture( const CString &sFilePath, RageTexturePrefs prefs ) : RageMovieTexture::RageMovieTexture( RageTextureID ID ) :
RageTexture( sFilePath, prefs ) RageTexture( ID )
{ {
LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" ); LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
m_FilePath = sFilePath;
buffer_changed = false; buffer_changed = false;
m_uGLTextureID = 0; m_uGLTextureID = 0;
@@ -80,7 +79,7 @@ RageMovieTexture::~RageMovieTexture()
glDeleteTextures(1, &m_uGLTextureID); glDeleteTextures(1, &m_uGLTextureID);
} }
void RageMovieTexture::Reload( RageTexturePrefs prefs ) void RageMovieTexture::Reload( RageTextureID ID )
{ {
// do nothing // do nothing
} }
@@ -208,8 +207,8 @@ void RageMovieTexture::NewData(char *data)
bool RageMovieTexture::CreateTexture() bool RageMovieTexture::CreateTexture()
{ {
/* image size cannot exceed max size */ /* image size cannot exceed max size */
m_iImageWidth = min( m_iSourceWidth, m_prefs.iMaxSize ); m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize );
m_iImageHeight = min( m_iSourceHeight, m_prefs.iMaxSize ); m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize );
/* Texture dimensions need to be a power of two; jump to the next. */ /* Texture dimensions need to be a power of two; jump to the next. */
m_iTextureWidth = power_of_two(m_iImageWidth); m_iTextureWidth = power_of_two(m_iImageWidth);
+2 -6
View File
@@ -43,11 +43,11 @@ typedef char TCHAR, *PTCHAR;
class RageMovieTexture : public RageTexture class RageMovieTexture : public RageTexture
{ {
public: public:
RageMovieTexture( const CString &sFilePath, RageTexturePrefs prefs ); RageMovieTexture( RageTextureID ID );
virtual ~RageMovieTexture(); virtual ~RageMovieTexture();
void Update(float fDeltaTime); void Update(float fDeltaTime);
virtual void Reload( RageTexturePrefs prefs ); virtual void Reload( RageTextureID ID );
virtual void Play(); virtual void Play();
virtual void Pause(); virtual void Pause();
@@ -57,13 +57,9 @@ public:
virtual bool IsPlaying() const; virtual bool IsPlaying() const;
void SetLooping(bool looping=true) { m_bLoop = looping; } 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); void NewData(char *buffer);
protected: protected:
// LPDIRECT3DTEXTURE8 m_pd3dTexture[2]; // double buffered
int m_iIndexFrontBuffer; // index of the buffer that should be rendered from - either 0 or 1 int m_iIndexFrontBuffer; // index of the buffer that should be rendered from - either 0 or 1
char *buffer; char *buffer;
+3 -4
View File
@@ -21,12 +21,11 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// RageTexture constructor // RageTexture constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
RageTexture::RageTexture( CString sFilePath, RageTexturePrefs prefs ) RageTexture::RageTexture( RageTextureID name )
{ {
// LOG->Trace( "RageTexture::RageTexture()" ); // LOG->Trace( "RageTexture::RageTexture()" );
m_sFilePath = sFilePath; m_ID = m_ActualID = name;
m_prefs = prefs;
m_iRefCount = 1; m_iRefCount = 1;
m_iSourceWidth = m_iSourceHeight = 0; m_iSourceWidth = m_iSourceHeight = 0;
@@ -43,7 +42,7 @@ RageTexture::~RageTexture()
void RageTexture::CreateFrameRects() 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. // Fill in the m_FrameRects with the bounds of each frame in the animation.
+30 -15
View File
@@ -17,25 +17,31 @@
const int MAX_TEXTURE_FRAMES = 256; const int MAX_TEXTURE_FRAMES = 256;
/* A unique texture is identified by a RageTextureID. (Loading the
struct RageTexturePrefs * same file with two different dither settings is considered two
* different textures, for example.) */
struct RageTextureID
{ {
bool bForceReload; CString filename;
int iMaxSize; int iMaxSize;
int iMipMaps; int iMipMaps;
int iAlphaBits; int iAlphaBits;
bool bDither; bool bDither;
bool bStretch; 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; iMaxSize = 2048;
iMipMaps = 4; iMipMaps = 4;
iAlphaBits = 4; iAlphaBits = 4;
bDither = false; bDither = false;
bStretch = false; bStretch = false;
} }
RageTextureID() { Init(); }
RageTextureID(const CString &fn) { Init(); filename=fn; }
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -44,10 +50,10 @@ struct RageTexturePrefs
class RageTexture class RageTexture
{ {
public: public:
RageTexture( CString sFilePath, RageTexturePrefs prefs ); RageTexture( RageTextureID file );
virtual ~RageTexture() = 0; virtual ~RageTexture() = 0;
virtual void Update( float fDeltaTime ) {} 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 void Invalidate() { } /* only called by RageTextureManager::InvalidateTextures */
virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay
@@ -78,26 +84,35 @@ public:
int GetImageFrameHeight() const {return GetImageHeight() / GetFramesHigh();} int GetImageFrameHeight() const {return GetImageHeight() / GetFramesHigh();}
const RectF *GetTextureCoordRect( int frameNo ) const; const RectF *GetTextureCoordRect( int frameNo ) const;
int GetNumFrames() const {return m_iFramesWide*m_iFramesHigh;} int GetNumFrames() const { return m_iFramesWide*m_iFramesHigh; }
CString GetFilePath() const {return m_sFilePath;} const CString &GetFilePath() const { return GetID().filename; }
int m_iRefCount; int m_iRefCount;
int m_iTimeOfLastUnload; 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: protected:
/* We might change settings when loading (due to hints, hardware
virtual void CreateFrameRects(); * limitations, etc). The data actually loaded is here: */
virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const; RageTextureID m_ActualID;
CString m_sFilePath;
RageTexturePrefs m_prefs;
int m_iSourceWidth, m_iSourceHeight; // dimensions of the original image loaded from disk 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_iTextureWidth, m_iTextureHeight; // dimensions of the texture in memory
int m_iImageWidth, m_iImageHeight; // dimensions of the image in the texture 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 int m_iFramesWide, m_iFramesHigh; // The number of frames of animation in each row and column of this texture
CArray<RectF,RectF> m_TextureCoordRects; // size = m_iFramesWide * m_iFramesHigh CArray<RectF,RectF> m_TextureCoordRects; // size = m_iFramesWide * m_iFramesHigh
virtual void CreateFrameRects();
virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const;
}; };
#endif #endif
+39 -35
View File
@@ -33,19 +33,19 @@ RageTextureManager::RageTextureManager( int iTextureColorDepth, int iSecondsBefo
RageTextureManager::~RageTextureManager() RageTextureManager::~RageTextureManager()
{ {
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<RageTextureID, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i) i != m_mapPathToTexture.end(); ++i)
{ {
RageTexture* pTexture = i->second; RageTexture* pTexture = i->second;
if( pTexture->m_iRefCount ) 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 ); SAFE_DELETE( pTexture );
} }
} }
void RageTextureManager::Update( float fDeltaTime ) void RageTextureManager::Update( float fDeltaTime )
{ {
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<RageTextureID, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i) i != m_mapPathToTexture.end(); ++i)
{ {
RageTexture* pTexture = i->second; RageTexture* pTexture = i->second;
@@ -56,11 +56,11 @@ void RageTextureManager::Update( float fDeltaTime )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Load/Unload textures from disk // 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 // holder for the new texture
RageTexture* pTexture; RageTexture* pTexture;
@@ -70,7 +70,7 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, RageTextureP
// of the same bitmap if there are equivalent but different paths // of the same bitmap if there are equivalent but different paths
// (e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp" ). // (e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp" ).
std::map<CString, RageTexture*>::iterator p = m_mapPathToTexture.find(sTexturePath); std::map<RageTextureID, RageTexture*>::iterator p = m_mapPathToTexture.find(ID);
if(p != m_mapPathToTexture.end()) { if(p != m_mapPathToTexture.end()) {
pTexture = p->second; pTexture = p->second;
@@ -81,16 +81,16 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, RageTextureP
else // the texture is not already loaded else // the texture is not already loaded
{ {
CString sDrive, sDir, sFName, sExt; CString sDrive, sDir, sFName, sExt;
splitpath( false, sTexturePath, sDrive, sDir, sFName, sExt ); splitpath( false, ID.filename, sDrive, sDir, sFName, sExt );
if( sExt == "avi" ) if( sExt == "avi" )
pTexture = new RageMovieTexture( sTexturePath, prefs ); pTexture = new RageMovieTexture( ID );
else 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 ); // 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"); LOG->Trace("Performing texture garbage collection");
timeLastGarbageCollect = time(NULL); timeLastGarbageCollect = time(NULL);
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<RageTextureID, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ) i != m_mapPathToTexture.end(); )
{ {
std::map<CString, RageTexture*>::iterator j = i; std::map<RageTextureID, RageTexture*>::iterator j = i;
i++; i++;
CString sPath = j->first; CString sPath = j->first.filename;
RageTexture* pTexture = j->second; RageTexture* pTexture = j->second;
if( pTexture->m_iRefCount==0 && if( pTexture->m_iRefCount==0 &&
pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload < time(NULL) ) 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( ID.filename == "" )
if( sTexturePath == "" )
{ {
//LOG->Trace( "RageTextureManager::UnloadTexture(): tried to Unload a blank texture." ); //LOG->Trace( "RageTextureManager::UnloadTexture(): tried to Unload a blank texture." );
return; return;
} }
LOG->Trace( "RageTextureManager::UnloadTexture(%s).", ID.filename.GetString() );
std::map<CString, RageTexture*>::iterator p = m_mapPathToTexture.find(sTexturePath); std::map<RageTextureID, RageTexture*>::iterator p = m_mapPathToTexture.find(ID);
if(p == m_mapPathToTexture.end()) 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; RageTexture* pTexture = p->second;
pTexture->m_iRefCount--; UnloadTexture(p->second);
pTexture->m_iTimeOfLastUnload = time(NULL); //LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath.GetString(), pTexture->m_iRefCount );
ASSERT( pTexture->m_iRefCount >= 0 ); }
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. /* 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 * Also, if texture caching is off, just remove it now instead of doing
* garbage collection. */ * garbage collection. */
if( pTexture->m_iRefCount == 0 && m_iSecondsBeforeUnload = 0;
(pTexture->IsAMovie() || !m_iSecondsBeforeUnload )) 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 ); // 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(t->GetID()); // and remove the key in the map
m_mapPathToTexture.erase(p); // and remove the key in the map SAFE_DELETE( t ); // free the texture
} }
GCTextures(); GCTextures();
//LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath.GetString(), pTexture->m_iRefCount );
} }
void RageTextureManager::ReloadAll() void RageTextureManager::ReloadAll()
{ {
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<RageTextureID, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i) i != m_mapPathToTexture.end(); ++i)
{ {
RageTexture* pTexture = i->second; 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, /* 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, * 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 * 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 * doesn't try to free it later when we really do reload (since that ID might be
* associated with a different texture). Ack. */ * associated with a different texture). Ack. */
void RageTextureManager::InvalidateTextures() void RageTextureManager::InvalidateTextures()
{ {
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<RageTextureID, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i) i != m_mapPathToTexture.end(); ++i)
{ {
RageTexture* pTexture = i->second; RageTexture* pTexture = i->second;
+5 -4
View File
@@ -25,9 +25,10 @@ public:
virtual void Update( float fDeltaTime ); virtual void Update( float fDeltaTime );
~RageTextureManager(); ~RageTextureManager();
RageTexture* LoadTexture( CString sTexturePath, RageTexturePrefs prefs ); RageTexture* LoadTexture( RageTextureID ID );
bool IsTextureLoaded( CString sTexturePath ); bool IsTextureLoaded( CString sTexturePath ); // XXX
void UnloadTexture( CString sTexturePath ); void UnloadTexture( RageTextureID ID );
void UnloadTexture( RageTexture *t );
void ReloadAll(); void ReloadAll();
bool SetPrefs( int iTextureColorDepth, int iSecsBeforeUnload ); bool SetPrefs( int iTextureColorDepth, int iSecsBeforeUnload );
@@ -42,7 +43,7 @@ protected:
int m_iTextureColorDepth; int m_iTextureColorDepth;
int m_iSecondsBeforeUnload; int m_iSecondsBeforeUnload;
std::map<CString, RageTexture*> m_mapPathToTexture; std::map<RageTextureID, RageTexture*> m_mapPathToTexture;
}; };
extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program
+1 -3
View File
@@ -92,8 +92,6 @@ in the scrolling list
*************************************/ *************************************/
void ScrollingList::Load( const CStringArray& asGraphicPaths ) void ScrollingList::Load( const CStringArray& asGraphicPaths )
{ {
RageTexturePrefs prefs;
Unload(); Unload();
if(m_iSpriteType == SPRITE_TYPE_SPRITE) 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->SetCroppedSize( EZ2_BANNER_WIDTH*2, EZ2_BANNER_HEIGHT*2 );
} }
pNewCSprite->Load( asGraphicPaths[i], prefs ); pNewCSprite->Load( asGraphicPaths[i] );
m_apCSprites.push_back( pNewCSprite ); m_apCSprites.push_back( pNewCSprite );
} }
} }
+13 -19
View File
@@ -37,9 +37,7 @@ Sprite::Sprite()
Sprite::~Sprite() Sprite::~Sprite()
{ {
// LOG->Trace( "Sprite Destructor" ); UnloadTexture();
TEXTUREMAN->UnloadTexture( m_sTexturePath );
} }
@@ -52,13 +50,13 @@ Sprite::~Sprite()
// Delay0000=1.0 // Delay0000=1.0
// Frame0001=3 // Frame0001=3
// Delay0000=2.0 // 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(); //Init();
m_sSpritePath = sSpritePath; m_sSpritePath = ID.filename;
// Split for the directory. We'll need it below // Split for the directory. We'll need it below
@@ -80,14 +78,13 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs )
if( sTextureFile == "" ) if( sTextureFile == "" )
RageException::Throw( "Error reading value 'Texture' from %s.", m_sSpritePath.GetString() ); RageException::Throw( "Error reading value 'Texture' from %s.", m_sSpritePath.GetString() );
CString sTexturePath = sFontDir + sTextureFile; // save the path of the new texture ID.filename = sFontDir + sTextureFile; // save the path of the real texture
if( !DoesFileExist(sTexturePath) )
RageException::Throw( "The sprite file '%s' points to a texture '%s' which doesn't exist.", m_sSpritePath.GetString(), sTexturePath.GetString() );
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 // Load the texture
LoadFromTexture( sTexturePath, prefs ); LoadFromTexture( ID );
// Read in frames and delays from the sprite file, // Read in frames and delays from the sprite file,
// overwriting the states that LoadFromTexture created. // overwriting the states that LoadFromTexture created.
@@ -101,7 +98,7 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs )
break; break;
if( m_iStateToFrame[i] >= m_pTexture->GetNumFrames() ) if( m_iStateToFrame[i] >= m_pTexture->GetNumFrames() )
RageException::Throw( "In '%s', %s is %d, but the texture %s only has %d frames.", 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; m_fDelay[i] = 0.2f;
if( !ini.GetValueF( "Sprite", sDelayKey, m_fDelay[i] ) ) if( !ini.GetValueF( "Sprite", sDelayKey, m_fDelay[i] ) )
break; break;
@@ -126,19 +123,16 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs )
void Sprite::UnloadTexture() void Sprite::UnloadTexture()
{ {
if( m_pTexture != NULL ) // If there was a previous bitmap... 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_pTexture = NULL;
m_sTexturePath = "";
} }
bool Sprite::LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs ) bool Sprite::LoadFromTexture( RageTextureID ID )
{ {
UnloadTexture(); UnloadTexture();
m_sTexturePath = sTexturePath; m_pTexture = TEXTUREMAN->LoadTexture( ID );
ASSERT( m_pTexture != NULL );
m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath, prefs );
assert( m_pTexture != NULL );
// the size of the sprite is the size of the image before it was scaled // the size of the sprite is the size of the image before it was scaled
Sprite::m_size.x = (float)m_pTexture->GetSourceFrameWidth(); Sprite::m_size.x = (float)m_pTexture->GetSourceFrameWidth();
+17 -11
View File
@@ -28,14 +28,22 @@ public:
Sprite(); Sprite();
virtual ~Sprite(); virtual ~Sprite();
virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); } /* Just a convenience function; load an image that'll be used in the
virtual bool Load( CString sFilePath, RageTexturePrefs prefs ) * background. */
virtual bool LoadBG( RageTextureID ID )
{ {
ASSERT( sFilePath != "" ); ID.iMipMaps = 1;
if( sFilePath.Right(7) == ".sprite" ) ID.bDither = true;
return LoadFromSpriteFile( sFilePath, prefs ); return Load(ID);
}
virtual bool Load( RageTextureID ID )
{
ASSERT( ID.filename != "" );
if( ID.filename.Right(7) == ".sprite" )
return LoadFromSpriteFile( ID );
else else
return LoadFromTexture( sFilePath, prefs ); return LoadFromTexture( ID );
}; };
void UnloadTexture(); void UnloadTexture();
RageTexture* GetTexture() { return m_pTexture; }; RageTexture* GetTexture() { return m_pTexture; };
@@ -48,8 +56,7 @@ public:
virtual void SetState( int iNewState ); virtual void SetState( int iNewState );
int GetNumStates() { return m_iNumStates; }; 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 SetCustomTextureRect( const RectF &new_texcoord_frect );
void SetCustomTextureCoords( float fTexCoords[8] ); void SetCustomTextureCoords( float fTexCoords[8] );
@@ -60,14 +67,13 @@ public:
void StopUsingCustomCoords(); void StopUsingCustomCoords();
protected: protected:
virtual bool LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs ); virtual bool LoadFromTexture( RageTextureID ID );
virtual bool LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs ); virtual bool LoadFromSpriteFile( RageTextureID ID );
CString m_sSpritePath; CString m_sSpritePath;
RageTexture* m_pTexture; RageTexture* m_pTexture;
bool m_bDrawIfTextureNull; bool m_bDrawIfTextureNull;
CString m_sTexturePath;
int m_iStateToFrame[MAX_SPRITE_STATES]; // array of indicies into m_rectBitmapFrames int m_iStateToFrame[MAX_SPRITE_STATES]; // array of indicies into m_rectBitmapFrames
float m_fDelay[MAX_SPRITE_STATES]; float m_fDelay[MAX_SPRITE_STATES];