diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 0ea364415e..621e94de9a 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -212,7 +212,7 @@ void BGAnimationLayer::LoadFromAniLayerFile( CString sPath ) ID.bStretch = true; m_Sprites.back()->LoadBG( ID ); m_Sprites.back()->StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); - m_Sprites.back()->SetCustomTextureCoords( RectF(0,0,1,1) ); + m_Sprites.back()->SetCustomTextureRect( RectF(0,0,1,1) ); switch( effect ) { @@ -546,7 +546,7 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer ) ID.bStretch = true; m_Sprites.back()->LoadBG( ID ); m_Sprites.back()->StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); - m_Sprites.back()->SetCustomTextureCoords( RectF(0,0,1,1) ); + m_Sprites.back()->SetCustomTextureRect( RectF(0,0,1,1) ); } break; case TYPE_PARTICLES: @@ -638,13 +638,16 @@ void BGAnimationLayer::Update( float fDeltaTime ) case TYPE_STRETCH: for( i=0; iGetActiveTextureCoords(); - texCoords.left += fDeltaTime*m_fStretchTexCoordVelocityX; - texCoords.right += fDeltaTime*m_fStretchTexCoordVelocityX; - texCoords.top += fDeltaTime*m_fStretchTexCoordVelocityY; - texCoords.bottom+= fDeltaTime*m_fStretchTexCoordVelocityY; + float fTexCoords[8]; + m_Sprites[i]->GetActiveTexCoords( fTexCoords ); - m_Sprites[i]->SetCustomTextureCoords( texCoords ); + for( int j=0; j<8; j+=2 ) + { + fTexCoords[j ] += fDeltaTime*m_fStretchTexCoordVelocityX; + fTexCoords[j+1] += fDeltaTime*m_fStretchTexCoordVelocityY; + } + + m_Sprites[i]->SetCustomTextureCoords( fTexCoords ); } break; /* case EFFECT_PARTICLES_SPIRAL_OUT: diff --git a/stepmania/src/Banner.cpp b/stepmania/src/Banner.cpp index 4fb1b20e21..d9224e012e 100644 --- a/stepmania/src/Banner.cpp +++ b/stepmania/src/Banner.cpp @@ -57,11 +57,16 @@ void Banner::Update( float fDeltaTime ) m_fPercentScrolling += fDeltaTime/2; m_fPercentScrolling -= (int)m_fPercentScrolling; - RectF texCoords = *m_pTexture->GetTextureCoordRect(0); - texCoords.left += m_fPercentScrolling; - texCoords.right += m_fPercentScrolling; - - Sprite::SetCustomTextureCoords( texCoords ); + const RectF *pTextureRect = m_pTexture->GetTextureCoordRect(0); + + float fTexCoords[8] = + { + 0+m_fPercentScrolling, pTextureRect->top, // top left + 0+m_fPercentScrolling, pTextureRect->bottom, // bottom left + 1+m_fPercentScrolling, pTextureRect->bottom, // bottom right + 1+m_fPercentScrolling, pTextureRect->top, // top right + }; + Sprite::SetCustomTextureCoords( fTexCoords ); } } diff --git a/stepmania/src/CroppedSprite.cpp b/stepmania/src/CroppedSprite.cpp index be7bd4e75b..753a602117 100644 --- a/stepmania/src/CroppedSprite.cpp +++ b/stepmania/src/CroppedSprite.cpp @@ -56,30 +56,28 @@ void CroppedSprite::CropToSize( float fWidth, float fHeight ) float fOriginalX = GetX(); float fOriginalY = GetY(); - // TODO: Add this back in -// if( IsDiagonalBanner(iSourceWidth, iSourceHeight) ) // this is a SSR/DWI CroppedSprite -// { -// float fCustomImageCoords[8] = { -// 0.02f, 0.78f, // top left -// 0.22f, 0.98f, // bottom left -// 0.98f, 0.22f, // bottom right -// 0.78f, 0.02f, // top right -// }; -// Sprite::SetCustomImageCoords( fCustomImageCoords ); -// -// if( m_fCropWidth != -1 && m_fCropHeight != -1) -// m_size = RageVector2( m_fCropWidth, m_fCropHeight ); -// else -// { -// /* If no crop size is set, then we're only being used to crop diagonal -// * banners so they look like regular ones. We don't actually care about -// * the size of the image, only that it has an aspect ratio of 4:1. */ -// m_size = RageVector2(256, 64); -// } -// SetZoom( 1 ); -// } -// else - if( m_pTexture->GetID().filename.find( "(was rotated)" ) != m_pTexture->GetID().filename.npos && + if( IsDiagonalBanner(iSourceWidth, iSourceHeight) ) // this is a SSR/DWI CroppedSprite + { + float fCustomImageCoords[8] = { + 0.02f, 0.78f, // top left + 0.22f, 0.98f, // bottom left + 0.98f, 0.22f, // bottom right + 0.78f, 0.02f, // top right + }; + Sprite::SetCustomImageCoords( fCustomImageCoords ); + + if( m_fCropWidth != -1 && m_fCropHeight != -1) + m_size = RageVector2( m_fCropWidth, m_fCropHeight ); + else + { + /* If no crop size is set, then we're only being used to crop diagonal + * banners so they look like regular ones. We don't actually care about + * the size of the image, only that it has an aspect ratio of 4:1. */ + m_size = RageVector2(256, 64); + } + SetZoom( 1 ); + } + else if( m_pTexture->GetID().filename.find( "(was rotated)" ) != m_pTexture->GetID().filename.npos && m_fCropWidth != -1 && m_fCropHeight != -1 ) { /* Dumb hack. Normally, we crop all sprites except for diagonal banners, @@ -112,12 +110,12 @@ void CroppedSprite::CropToSize( float fWidth, float fHeight ) float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates - RectF fCustomImageCoords( + RectF fCustomImageRect( fPercentageToCutOffEachSide, 0, 1 - fPercentageToCutOffEachSide, 1 ); - SetCustomImageCoords( fCustomImageCoords ); + SetCustomImageRect( fCustomImageRect ); } else // crop Y { @@ -125,12 +123,12 @@ void CroppedSprite::CropToSize( float fWidth, float fHeight ) float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates - RectF fCustomImageCoords( + RectF fCustomImageRect( 0, fPercentageToCutOffEachSide, 1, 1 - fPercentageToCutOffEachSide ); - SetCustomImageCoords( fCustomImageCoords ); + SetCustomImageRect( fCustomImageRect ); } m_size = RageVector2( m_fCropWidth, m_fCropHeight ); SetZoom( 1 ); diff --git a/stepmania/src/GradeDisplay.cpp b/stepmania/src/GradeDisplay.cpp index 2fa1c03b8a..3fcea98bea 100644 --- a/stepmania/src/GradeDisplay.cpp +++ b/stepmania/src/GradeDisplay.cpp @@ -71,7 +71,7 @@ void GradeDisplay::Update( float fDeltaTime ) m_frectCurTexCoords.right = m_frectStartTexCoords.right*(1-fPercentIntoScrolling) + m_frectDestTexCoords.right*fPercentIntoScrolling; m_frectCurTexCoords.bottom = m_frectStartTexCoords.bottom*(1-fPercentIntoScrolling) + m_frectDestTexCoords.bottom*fPercentIntoScrolling; - this->SetCustomTextureCoords( m_frectCurTexCoords ); + this->SetCustomTextureRect( m_frectCurTexCoords ); } } diff --git a/stepmania/src/LifeMeterBar.cpp b/stepmania/src/LifeMeterBar.cpp index c1a217bf00..b78d865d89 100644 --- a/stepmania/src/LifeMeterBar.cpp +++ b/stepmania/src/LifeMeterBar.cpp @@ -176,14 +176,14 @@ public: // set custom texture coords // float fPrecentOffset = fRightEdgePercent; - RectF frectCustomTexCoords( + RectF frectCustomTexRect( fPercentCroppedFromLeft, 0, 1-fPercentCroppedFromRight, 1); - m_sprStreamNormal.SetCustomTextureCoords( frectCustomTexCoords ); - m_sprStreamHot.SetCustomTextureCoords( frectCustomTexCoords ); + m_sprStreamNormal.SetCustomTextureRect( frectCustomTexRect ); + m_sprStreamHot.SetCustomTextureRect( frectCustomTexRect ); m_sprStreamHot.SetDiffuse( RageColor(1,1,1,m_fHotAlpha) ); diff --git a/stepmania/src/NoteDisplay.cpp b/stepmania/src/NoteDisplay.cpp index c25867c86d..1c95f16b55 100644 --- a/stepmania/src/NoteDisplay.cpp +++ b/stepmania/src/NoteDisplay.cpp @@ -422,7 +422,7 @@ void NoteDisplay::DrawHold( const HoldNote& hn, const bool bActive, const float // draw manually in small segments RageVertex *v = &queue[0]; RageTexture* pTexture = pBottomCap->GetTexture(); - const RectF *pRect = pBottomCap->GetCurrentTextureCoords(); + const RectF *pRect = pBottomCap->GetCurrentTextureCoordRect(); DISPLAY->SetTexture( pTexture ); DISPLAY->SetBlendMode( BLEND_NORMAL ); DISPLAY->SetBackfaceCull( false ); @@ -489,7 +489,7 @@ void NoteDisplay::DrawHold( const HoldNote& hn, const bool bActive, const float // draw manually in small segments RageVertex *v = &queue[0]; RageTexture* pTexture = pSprBody->GetTexture(); - const RectF *pRect = pSprBody->GetCurrentTextureCoords(); + const RectF *pRect = pSprBody->GetCurrentTextureCoordRect(); DISPLAY->SetTexture( pTexture ); DISPLAY->SetBlendMode( BLEND_NORMAL ); DISPLAY->SetBackfaceCull( false ); @@ -569,7 +569,7 @@ void NoteDisplay::DrawHold( const HoldNote& hn, const bool bActive, const float // draw manually in small segments RageVertex *v = &queue[0]; RageTexture* pTexture = pSprTopCap->GetTexture(); - const RectF *pRect = pSprTopCap->GetCurrentTextureCoords(); + const RectF *pRect = pSprTopCap->GetCurrentTextureCoordRect(); DISPLAY->SetTexture( pTexture ); DISPLAY->SetBlendMode( BLEND_NORMAL ); DISPLAY->SetBackfaceCull( false ); diff --git a/stepmania/src/NoteField.cpp b/stepmania/src/NoteField.cpp index 2fc1e54b8c..87e04a45d5 100644 --- a/stepmania/src/NoteField.cpp +++ b/stepmania/src/NoteField.cpp @@ -141,7 +141,7 @@ void NoteField::DrawBeatBar( const float fBeat ) m_sprBars.SetY( fYPos ); m_sprBars.SetDiffuse( RageColor(1,1,1,fAlpha) ); m_sprBars.SetState( iState ); - m_sprBars.SetCustomTextureCoords( RectF(0,SCALE(iState,0.f,4.f,0.f,1.f), fWidth/fFrameWidth, SCALE(iState+1,0.f,4.f,0.f,1.f)) ); + m_sprBars.SetCustomTextureRect( RectF(0,SCALE(iState,0.f,4.f,0.f,1.f), fWidth/fFrameWidth, SCALE(iState+1,0.f,4.f,0.f,1.f)) ); m_sprBars.SetZoomX( fWidth/m_sprBars.GetUnzoomedWidth() ); m_sprBars.Draw(); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 2b7ab8d190..6616077c20 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -53,9 +53,13 @@ static const ScreenMessage SM_AllowOptionsMenuRepeat = ScreenMessage(SM_User+1); * on Y by flipping texture coordinates. */ static void FlipSpriteHorizontally(Sprite &s) { - RectF texCoords = *s.GetCurrentTextureCoords(); - swap( texCoords.left, texCoords.right ); - s.SetCustomTextureCoords( texCoords ); + float Coords[8]; + s.GetCurrentTextureCoords(Coords); + swap(Coords[0], Coords[6]); /* top left X <-> top right X */ + swap(Coords[1], Coords[7]); /* top left Y <-> top right Y */ + swap(Coords[2], Coords[4]); /* bottom left X <-> bottom left X */ + swap(Coords[3], Coords[5]); /* bottom left Y <-> bottom left Y */ + s.SetCustomTextureCoords(Coords); } ScreenSelectMusic::ScreenSelectMusic() : Screen("ScreenSelectMusic") diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index e9958d0781..0f671edb14 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -219,9 +219,6 @@ void Sprite::Update( float fDeltaTime ) } } -/* - No longer needed. -Chris - static void TexCoordsFromArray(RageVertex *v, const float *f) { v[0].t = RageVector2( f[0], f[1] ); // top left @@ -237,25 +234,25 @@ void TexCoordArrayFromRect(float fImageCoords[8], const RectF &rect) fImageCoords[4] = rect.right; fImageCoords[5] = rect.bottom; // bottom right fImageCoords[6] = rect.right; fImageCoords[7] = rect.top; // top right } -*/ void Sprite::DrawPrimitives() { if( m_pTexture == NULL && !m_bDrawIfTextureNull ) return; - // bail if cropped all the way - if( m_temp.crop.left + m_temp.crop.right > 1 || + // bail if cropped all the way + if( m_temp.crop.left + m_temp.crop.right > 1 || m_temp.crop.top + m_temp.crop.bottom > 1 ) - return; + return; + // This is causing terrible movie performance on an Athlon 1.3+Voodoo3. - // With the default delay of 2ms, the frame rate of demonstration dives - // from 110fps to 84. SDL_Delay must behave differently than Win32's - // Sleep(). Leave this commented for now, and uncomment if we hear - // about problems with dropped movie frames. -Chris - //if( m_pTexture && m_pTexture->IsAMovie() && m_pTexture->IsPlaying() ) - // SDL_Delay( PREFSMAN->m_iMovieDecodeMS ); // let the movie decode a frame + // With the default delay of 2ms, the frame rate of demonstration dives + // from 110fps to 84.  SDL_Delay must behave differently than Win32's + // Sleep().  Leave this commented for now, and uncomment if we hear + // about problems with dropped movie frames.  -Chris + //if( m_pTexture  &&  m_pTexture->IsAMovie()  &&  m_pTexture->IsPlaying() ) + //      SDL_Delay( PREFSMAN->m_iMovieDecodeMS );        // let the movie decode a frame // use m_temp_* variables to draw the object RectF quadVerticies; @@ -277,12 +274,13 @@ void Sprite::DrawPrimitives() } - RectF croppedQuadVerticies = quadVerticies; + RectF croppedQuadVerticies = quadVerticies; #define IF_CROP_POS(side,opp_side) if(m_temp.crop.side>0) croppedQuadVerticies.side = SCALE( m_temp.crop.side, 0.f, 1.f, quadVerticies.side, quadVerticies.opp_side ); - IF_CROP_POS( left, right ); - IF_CROP_POS( top, bottom ); - IF_CROP_POS( right, left ); - IF_CROP_POS( bottom, top ); + IF_CROP_POS( left, right ); + IF_CROP_POS( top, bottom ); + IF_CROP_POS( right, left ); + IF_CROP_POS( bottom, top ); + static RageVertex v[4]; @@ -299,21 +297,39 @@ void Sprite::DrawPrimitives() if( m_pTexture ) { - const RectF texCoords = *(m_bUsingCustomTexCoords ? - GetCustomTextureCoords() : - GetCurrentTextureCoords()); + float f[8]; + GetActiveTexCoords(f); + TexCoordsFromArray(v, f); - RectF croppedTexCoords = texCoords; -#define IF_CROP_TEX(side,opp_side) if(m_temp.crop.side>0) croppedTexCoords.side = SCALE( m_temp.crop.side, 0.f, 1.f, texCoords.side, texCoords.opp_side ); - IF_CROP_TEX( left, right ); - IF_CROP_TEX( top, bottom ); - IF_CROP_TEX( right, left ); - IF_CROP_TEX( bottom, top ); - v[0].t = RageVector2( croppedTexCoords.left, croppedTexCoords.top ); // top left - v[1].t = RageVector2( croppedTexCoords.left, croppedTexCoords.bottom ); // bottom left - v[2].t = RageVector2( croppedTexCoords.right, croppedTexCoords.bottom ); // bottom right - v[3].t = RageVector2( croppedTexCoords.right, croppedTexCoords.top ); // top right + RageVector2 texCoords[4] = { + RageVector2( f[0], f[1] ), // top left + RageVector2( f[2], f[3] ), // bottom left + RageVector2( f[4], f[5] ), // bottom right + RageVector2( f[6], f[7] ) // top right + }; + + + if( m_temp.crop.left>0 ) + { + v[0].t.x = SCALE( m_temp.crop.left, 0.f, 1.f, texCoords[0].x, texCoords[3].x ); + v[1].t.x = SCALE( m_temp.crop.left, 0.f, 1.f, texCoords[1].x, texCoords[2].x ); + } + if( m_temp.crop.right>0 ) + { + v[2].t.x = SCALE( m_temp.crop.right, 0.f, 1.f, texCoords[2].x, texCoords[1].x ); + v[3].t.x = SCALE( m_temp.crop.right, 0.f, 1.f, texCoords[3].x, texCoords[0].x ); + } + if( m_temp.crop.top>0 ) + { + v[0].t.y = SCALE( m_temp.crop.top, 0.f, 1.f, texCoords[0].y, texCoords[1].y ); + v[3].t.y = SCALE( m_temp.crop.top, 0.f, 1.f, texCoords[3].y, texCoords[2].y ); + } + if( m_temp.crop.bottom>0 ) + { + v[1].t.y = SCALE( m_temp.crop.bottom, 0.f, 1.f, texCoords[1].y, texCoords[0].y ); + v[2].t.y = SCALE( m_temp.crop.bottom, 0.f, 1.f, texCoords[2].y, texCoords[3].y ); + } } DISPLAY->SetTextureModeModulate(); @@ -371,44 +387,70 @@ void Sprite::SetState( int iNewState ) m_fSecsIntoState = 0.0; } -void Sprite::SetCustomTextureCoords( const RectF &new_texcoord_frect ) +void Sprite::SetCustomTextureRect( const RectF &new_texcoord_frect ) { m_bUsingCustomTexCoords = true; m_bTextureWrapping = true; - m_CustomTexCoords = new_texcoord_frect; + TexCoordArrayFromRect(m_CustomTexCoords, new_texcoord_frect); } -const RectF* Sprite::GetCustomTextureCoords() const +void Sprite::SetCustomTextureCoords( float fTexCoords[8] ) // order: top left, bottom left, bottom right, top right { - return &m_CustomTexCoords; + m_bUsingCustomTexCoords = true; + m_bTextureWrapping = true; + for( int i=0; i<8; i++ ) + m_CustomTexCoords[i] = fTexCoords[i]; } -void Sprite::SetCustomImageCoords( const RectF &newImageCoords ) +void Sprite::GetCustomTextureCoords( float fTexCoordsOut[8] ) const // order: top left, bottom left, bottom right, top right +{ + for( int i=0; i<8; i++ ) + fTexCoordsOut[i] = m_CustomTexCoords[i]; +} + + +void Sprite::SetCustomImageRect( RectF rectImageCoords ) { // Convert to a rectangle in texture coordinate space. - RectF texCoords; - texCoords.left = newImageCoords.left * m_pTexture->GetImageWidth() / (float)m_pTexture->GetTextureWidth(); - texCoords.right = newImageCoords.right * m_pTexture->GetImageWidth() / (float)m_pTexture->GetTextureWidth(); - texCoords.top = newImageCoords.top * m_pTexture->GetImageHeight()/ (float)m_pTexture->GetTextureHeight(); - texCoords.bottom = newImageCoords.bottom * m_pTexture->GetImageHeight()/ (float)m_pTexture->GetTextureHeight(); + rectImageCoords.left *= m_pTexture->GetImageWidth() / (float)m_pTexture->GetTextureWidth(); + rectImageCoords.right *= m_pTexture->GetImageWidth() / (float)m_pTexture->GetTextureWidth(); + rectImageCoords.top *= m_pTexture->GetImageHeight() / (float)m_pTexture->GetTextureHeight(); + rectImageCoords.bottom *= m_pTexture->GetImageHeight() / (float)m_pTexture->GetTextureHeight(); - SetCustomTextureCoords( texCoords ); + SetCustomTextureRect( rectImageCoords ); } -const RectF *Sprite::GetCurrentTextureCoords() const +void Sprite::SetCustomImageCoords( float fImageCoords[8] ) // order: top left, bottom left, bottom right, top right +{ + // convert image coords to texture coords in place + for( int i=0; i<8; i+=2 ) + { + fImageCoords[i+0] *= m_pTexture->GetImageWidth() / (float)m_pTexture->GetTextureWidth(); + fImageCoords[i+1] *= m_pTexture->GetImageHeight() / (float)m_pTexture->GetTextureHeight(); + } + + SetCustomTextureCoords( fImageCoords ); +} + +const RectF *Sprite::GetCurrentTextureCoordRect() const { unsigned int uFrameNo = m_States[m_iCurState].iFrameIndex; return m_pTexture->GetTextureCoordRect( uFrameNo ); } +void Sprite::GetCurrentTextureCoords(float fImageCoords[8]) const +{ + const RectF *pTexCoordRect = GetCurrentTextureCoordRect(); + TexCoordArrayFromRect(fImageCoords, *pTexCoordRect); +} + + /* If we're using custom coordinates, return them; otherwise return the coordinates * for the current state. */ -const RectF* Sprite::GetActiveTextureCoords() const +void Sprite::GetActiveTexCoords(float fImageCoords[8]) const { - if(m_bUsingCustomTexCoords) - return GetCustomTextureCoords(); - else - return GetCurrentTextureCoords(); + if(m_bUsingCustomTexCoords) GetCustomTextureCoords(fImageCoords); + else GetCurrentTextureCoords(fImageCoords); } diff --git a/stepmania/src/Sprite.h b/stepmania/src/Sprite.h index 8c32296f62..38de9bbaa1 100644 --- a/stepmania/src/Sprite.h +++ b/stepmania/src/Sprite.h @@ -40,12 +40,17 @@ public: virtual int GetNumStates() { return m_States.size(); }; CString GetTexturePath() { return m_pTexture==NULL ? "" : m_pTexture->GetID().filename; }; - void SetCustomTextureCoords( const RectF &newTexCoords ); - const RectF* GetCustomTextureCoords() const; - void SetCustomImageCoords( const RectF &newImageCoords ); // in image space (not texture space) + void SetCustomTextureRect( const RectF &new_texcoord_frect ); + void SetCustomTextureCoords( float fTexCoords[8] ); + void GetCustomTextureCoords( float fTexCoordsOut[8] ) const; + void SetCustomSourceRect( const RectF &rectSourceCoords ); // in source pixel space + void SetCustomImageRect( RectF rectImageCoords ); // in image pixel space + void SetCustomImageCoords( float fImageCoords[8] ); + const RectF *GetCurrentTextureCoordRect() const; void StopUsingCustomCoords(); - const RectF* GetActiveTextureCoords() const; // depends on m_bUsingCustomTexCoords - const RectF* GetCurrentTextureCoords() const; + + void GetActiveTexCoords(float fImageCoords[8]) const; + void GetCurrentTextureCoords(float fImageCoords[8]) const; protected: virtual bool LoadFromTexture( RageTextureID ID ); @@ -66,7 +71,7 @@ protected: float m_fSecsIntoState; // number of seconds that have elapsed since we switched to this frame bool m_bUsingCustomTexCoords; - RectF m_CustomTexCoords; + float m_CustomTexCoords[8]; // (x,y) * 4 }; #endif