This commit is contained in:
Steve Checkoway
2005-10-29 12:22:43 +00:00
parent 3c0deebeba
commit 4ce7d47899
+24 -22
View File
@@ -175,13 +175,13 @@ retry:
CString sDelayKey = ssprintf( "Delay%04d", i ); CString sDelayKey = ssprintf( "Delay%04d", i );
State newState; State newState;
if( !pNode->GetAttrValue( sFrameKey, newState.iFrameIndex ) ) if( !pNode->GetAttrValue(sFrameKey, newState.iFrameIndex) )
break; break;
if( newState.iFrameIndex >= m_pTexture->GetNumFrames() ) if( newState.iFrameIndex >= 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.c_str(), sFrameKey.c_str(), newState.iFrameIndex, sPath.c_str(), m_pTexture->GetNumFrames() ); m_sSpritePath.c_str(), sFrameKey.c_str(), newState.iFrameIndex, sPath.c_str(), m_pTexture->GetNumFrames() );
if( !pNode->GetAttrValue( sDelayKey, newState.fDelay ) ) if( !pNode->GetAttrValue(sDelayKey, newState.fDelay) )
break; break;
if( i == 0 ) // the ini file defines at least one frame if( i == 0 ) // the ini file defines at least one frame
@@ -265,7 +265,7 @@ void Sprite::LoadFromTexture( RageTextureID ID )
// Assume the frames of this animation play in sequential order with 0.1 second delay. // Assume the frames of this animation play in sequential order with 0.1 second delay.
m_States.clear(); m_States.clear();
for( int i=0; i<m_pTexture->GetNumFrames(); i++ ) for( int i=0; i<m_pTexture->GetNumFrames(); ++i )
{ {
State newState = { i, 0.1f }; State newState = { i, 0.1f };
m_States.push_back( newState ); m_States.push_back( newState );
@@ -371,7 +371,7 @@ void Sprite::Update( float fDelta )
} }
} }
static void TexCoordsFromArray(RageSpriteVertex *v, const float *f) static void TexCoordsFromArray( RageSpriteVertex *v, const float *f )
{ {
v[0].t = RageVector2( f[0], f[1] ); // top left v[0].t = RageVector2( f[0], f[1] ); // top left
v[1].t = RageVector2( f[2], f[3] ); // bottom left v[1].t = RageVector2( f[2], f[3] ); // bottom left
@@ -379,7 +379,7 @@ static void TexCoordsFromArray(RageSpriteVertex *v, const float *f)
v[3].t = RageVector2( f[6], f[7] ); // top right v[3].t = RageVector2( f[6], f[7] ); // top right
} }
void TexCoordArrayFromRect(float fImageCoords[8], const RectF &rect) void TexCoordArrayFromRect( float fImageCoords[8], const RectF &rect )
{ {
fImageCoords[0] = rect.left; fImageCoords[1] = rect.top; // top left fImageCoords[0] = rect.left; fImageCoords[1] = rect.top; // top left
fImageCoords[2] = rect.left; fImageCoords[3] = rect.bottom; // bottom left fImageCoords[2] = rect.left; fImageCoords[3] = rect.bottom; // bottom left
@@ -430,7 +430,7 @@ void Sprite::DrawTexture( const TweenState *state )
#define IF_CROP_POS(side,opp_side) \ #define IF_CROP_POS(side,opp_side) \
if(state->crop.side!=0) \ if(state->crop.side!=0) \
croppedQuadVerticies.side = \ croppedQuadVerticies.side = \
SCALE( crop.side, 0.f, 1.f, quadVerticies.side, quadVerticies.opp_side ); SCALE( crop.side, 0.f, 1.f, quadVerticies.side, quadVerticies.opp_side )
IF_CROP_POS( left, right ); IF_CROP_POS( left, right );
IF_CROP_POS( top, bottom ); IF_CROP_POS( top, bottom );
IF_CROP_POS( right, left ); IF_CROP_POS( right, left );
@@ -452,8 +452,8 @@ void Sprite::DrawTexture( const TweenState *state )
if( m_pTexture ) if( m_pTexture )
{ {
float f[8]; float f[8];
GetActiveTextureCoords(f); GetActiveTextureCoords( f );
TexCoordsFromArray(v, f); TexCoordsFromArray( v, f );
RageVector2 texCoords[4] = { RageVector2 texCoords[4] = {
@@ -507,7 +507,7 @@ void Sprite::DrawTexture( const TweenState *state )
{ {
DISPLAY->PushMatrix(); DISPLAY->PushMatrix();
DISPLAY->TranslateWorld( m_fShadowLength, m_fShadowLength, 0 ); // shift by 5 units DISPLAY->TranslateWorld( m_fShadowLength, m_fShadowLength, 0 ); // shift by 5 units
v[0].c = v[1].c = v[2].c = v[3].c = RageColor(0,0,0,0.5f*state->diffuse[0].a); // semi-transparent black v[0].c = v[1].c = v[2].c = v[3].c = RageColor( 0, 0, 0, 0.5f*state->diffuse[0].a ); // semi-transparent black
DISPLAY->DrawQuad( v ); DISPLAY->DrawQuad( v );
DISPLAY->PopMatrix(); DISPLAY->PopMatrix();
} }
@@ -740,7 +740,7 @@ void Sprite::SetCustomTextureRect( const RectF &new_texcoord_frect )
{ {
m_bUsingCustomTexCoords = true; m_bUsingCustomTexCoords = true;
m_bTextureWrapping = true; m_bTextureWrapping = true;
TexCoordArrayFromRect(m_CustomTexCoords, new_texcoord_frect); TexCoordArrayFromRect( m_CustomTexCoords, new_texcoord_frect );
} }
void Sprite::SetCustomTextureCoords( float fTexCoords[8] ) // order: top left, bottom left, bottom right, top right void Sprite::SetCustomTextureCoords( float fTexCoords[8] ) // order: top left, bottom left, bottom right, top right
@@ -785,7 +785,7 @@ const RectF *Sprite::GetCurrentTextureCoordRect() const
/* If we're using custom coordinates, return them; otherwise return the coordinates /* If we're using custom coordinates, return them; otherwise return the coordinates
* for the current state. */ * for the current state. */
void Sprite::GetActiveTextureCoords(float fTexCoordsOut[8]) const void Sprite::GetActiveTextureCoords( float fTexCoordsOut[8] ) const
{ {
if(m_bUsingCustomTexCoords) if(m_bUsingCustomTexCoords)
{ {
@@ -797,7 +797,7 @@ void Sprite::GetActiveTextureCoords(float fTexCoordsOut[8]) const
{ {
// GetCurrentTextureCoords // GetCurrentTextureCoords
const RectF *pTexCoordRect = GetCurrentTextureCoordRect(); const RectF *pTexCoordRect = GetCurrentTextureCoordRect();
TexCoordArrayFromRect(fTexCoordsOut, *pTexCoordRect); TexCoordArrayFromRect( fTexCoordsOut, *pTexCoordRect );
} }
} }
@@ -833,18 +833,20 @@ void Sprite::ScaleToClipped( float fWidth, float fHeight )
}; };
Sprite::SetCustomImageCoords( fCustomImageCoords ); Sprite::SetCustomImageCoords( fCustomImageCoords );
if( fWidth != -1 && fHeight != -1) if( fWidth != -1 && fHeight != -1 )
{
m_size = RageVector2( fWidth, fHeight ); m_size = RageVector2( fWidth, fHeight );
}
else else
{ {
/* If no crop size is set, then we're only being used to crop diagonal /* 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 * 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. */ * the size of the image, only that it has an aspect ratio of 4:1. */
m_size = RageVector2(256, 64); m_size = RageVector2( 256, 64 );
} }
SetZoom( 1 ); SetZoom( 1 );
} }
else if( m_pTexture->GetID().filename.find( "(was rotated)" ) != m_pTexture->GetID().filename.npos && else if( m_pTexture->GetID().filename.find("(was rotated)") != m_pTexture->GetID().filename.npos &&
fWidth != -1 && fHeight != -1 ) fWidth != -1 && fHeight != -1 )
{ {
/* Dumb hack. Normally, we crop all sprites except for diagonal banners, /* Dumb hack. Normally, we crop all sprites except for diagonal banners,
@@ -864,7 +866,7 @@ void Sprite::ScaleToClipped( float fWidth, float fHeight )
Sprite::StopUsingCustomCoords(); Sprite::StopUsingCustomCoords();
// first find the correct zoom // first find the correct zoom
Sprite::ScaleToCover( RectF(0,0,fWidth,fHeight) ); Sprite::ScaleToCover( RectF(0, 0, fWidth, fHeight) );
// find which dimension is larger // find which dimension is larger
bool bXDimNeedsToBeCropped = GetZoomedWidth() > fWidth+0.01; bool bXDimNeedsToBeCropped = GetZoomedWidth() > fWidth+0.01;
@@ -922,9 +924,9 @@ void Sprite::StretchTexCoords( float fX, float fY )
SetCustomTextureCoords( fTexCoords ); SetCustomTextureCoords( fTexCoords );
} }
void Sprite::SetPosition( float f ) { GetTexture()->SetPosition(f); } void Sprite::SetPosition( float f ) { GetTexture()->SetPosition( f ); }
void Sprite::SetLooping( bool b ) { GetTexture()->SetLooping(b); } void Sprite::SetLooping( bool b ) { GetTexture()->SetLooping( b ); }
void Sprite::SetPlaybackRate( float f ) { GetTexture()->SetPlaybackRate(f); } void Sprite::SetPlaybackRate( float f ) { GetTexture()->SetPlaybackRate( f ); }
// lua start // lua start
@@ -967,9 +969,9 @@ public:
* not an Actor) if these are needed for other things that use textures. * not an Actor) if these are needed for other things that use textures.
* We'd need to break the command helpers into a separate function; RageTexture * We'd need to break the command helpers into a separate function; RageTexture
* shouldn't depend on Actor. */ * shouldn't depend on Actor. */
static int position( T* p, lua_State *L ) { p->SetPosition(FArg(1)); return 0; } static int position( T* p, lua_State *L ) { p->SetPosition( FArg(1) ); return 0; }
static int loop( T* p, lua_State *L ) { p->SetLooping(!!IArg(1)); return 0; } static int loop( T* p, lua_State *L ) { p->SetLooping( !!IArg(1) ); return 0; }
static int rate( T* p, lua_State *L ) { p->SetPlaybackRate(FArg(1)); return 0; } static int rate( T* p, lua_State *L ) { p->SetPlaybackRate( FArg(1) ); return 0; }
static void Register(lua_State *L) { static void Register(lua_State *L) {
ADD_METHOD( Load ); ADD_METHOD( Load );