diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 31fc6e9998..e7d9e87d95 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -28,6 +28,8 @@ void Actor::Reset() m_TweenStates.clear(); m_TweenInfo.clear(); + m_pTempState = NULL; + m_baseRotation = RageVector3( 0, 0, 0 ); m_baseScale = RageVector3( 1, 1, 1 ); m_size = RageVector2( 1, 1 ); @@ -74,117 +76,120 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties { DISPLAY->PushMatrix(); // we're actually going to do some drawing in this function - int i; - - m_temp = m_current; - /* XXX: recheck rotations in here (all in degrees?) */ // // set temporary drawing properties based on Effects // - float fPercentThroughEffect = m_fSecsIntoEffect / m_fEffectPeriodSeconds; - bool bBlinkOn = fPercentThroughEffect > 0.5f; - float fPercentBetweenColors = sinf( fPercentThroughEffect * 2 * PI ) / 2 + 0.5f; - ASSERT( fPercentBetweenColors >= 0 && fPercentBetweenColors <= 1 ); - float fOriginalAlpha = m_temp.diffuse[0].a; - - switch( m_Effect ) + if( m_Effect == no_effect ) { - case no_effect: - break; - case diffuse_blink: - for(i=0; i<4; i++) - m_temp.diffuse[i] = bBlinkOn ? m_effectColor1 : m_effectColor2; - break; - case diffuse_shift: - for(i=0; i<4; i++) - m_temp.diffuse[i] = m_effectColor1*fPercentBetweenColors + m_effectColor2*(1.0f-fPercentBetweenColors); - break; - case glow_blink: - m_temp.glow = bBlinkOn ? m_effectColor1 : m_effectColor2; - m_temp.glow.a *= fOriginalAlpha; // don't glow if the Actor is transparent! - break; - case glow_shift: - m_temp.glow = m_effectColor1*fPercentBetweenColors + m_effectColor2*(1.0f-fPercentBetweenColors); - m_temp.glow.a *= fOriginalAlpha; // don't glow if the Actor is transparent! - break; - case rainbow: - m_temp.diffuse[0] = RageColor( - cosf( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f, - cosf( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f, - cosf( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f, - fOriginalAlpha ); - for( i=1; i<4; i++ ) - m_temp.diffuse[i] = m_temp.diffuse[0]; - break; - case wag: - m_temp.rotation = m_vEffectMagnitude * sinf( fPercentThroughEffect * 2.0f * PI ); - break; - case spin: - // nothing needs to be here - break; - case vibrate: - m_temp.pos.x += m_vEffectMagnitude.x * randomf(-1.0f, 1.0f) * GetZoom(); - m_temp.pos.y += m_vEffectMagnitude.y * randomf(-1.0f, 1.0f) * GetZoom(); - m_temp.pos.z += m_vEffectMagnitude.z * randomf(-1.0f, 1.0f) * GetZoom(); - break; - case bounce: + m_pTempState = &m_current; + } + else + { + m_pTempState = &m_tempState; + m_tempState = m_current; + + float fPercentThroughEffect = m_fSecsIntoEffect / m_fEffectPeriodSeconds; + bool bBlinkOn = fPercentThroughEffect > 0.5f; + float fPercentBetweenColors = (fPercentThroughEffect==0) ? 0 : (sinf( fPercentThroughEffect * 2 * PI ) / 2 + 0.5f); + ASSERT( fPercentBetweenColors >= 0 && fPercentBetweenColors <= 1 ); + float fOriginalAlpha = m_tempState.diffuse[0].a; + + int i; + + switch( m_Effect ) { - float fPercentOffset = sinf( fPercentThroughEffect*PI ); - m_temp.pos += m_vEffectMagnitude * fPercentOffset; - m_temp.pos.x = roundf( m_temp.pos.x ); - m_temp.pos.y = roundf( m_temp.pos.y ); - m_temp.pos.z = roundf( m_temp.pos.z ); + case diffuse_blink: + for(i=0; i<4; i++) + m_tempState.diffuse[i] = bBlinkOn ? m_effectColor1 : m_effectColor2; + break; + case diffuse_shift: + for(i=0; i<4; i++) + m_tempState.diffuse[i] = m_effectColor1*fPercentBetweenColors + m_effectColor2*(1.0f-fPercentBetweenColors); + break; + case glow_blink: + m_tempState.glow = bBlinkOn ? m_effectColor1 : m_effectColor2; + m_tempState.glow.a *= fOriginalAlpha; // don't glow if the Actor is transparent! + break; + case glow_shift: + m_tempState.glow = m_effectColor1*fPercentBetweenColors + m_effectColor2*(1.0f-fPercentBetweenColors); + m_tempState.glow.a *= fOriginalAlpha; // don't glow if the Actor is transparent! + break; + case rainbow: + m_tempState.diffuse[0] = RageColor( + cosf( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f, + cosf( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f, + cosf( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f, + fOriginalAlpha ); + for( i=1; i<4; i++ ) + m_tempState.diffuse[i] = m_tempState.diffuse[0]; + break; + case wag: + m_tempState.rotation = m_vEffectMagnitude * sinf( fPercentThroughEffect * 2.0f * PI ); + break; + case spin: + // nothing needs to be here + break; + case vibrate: + m_tempState.pos.x += m_vEffectMagnitude.x * randomf(-1.0f, 1.0f) * GetZoom(); + m_tempState.pos.y += m_vEffectMagnitude.y * randomf(-1.0f, 1.0f) * GetZoom(); + m_tempState.pos.z += m_vEffectMagnitude.z * randomf(-1.0f, 1.0f) * GetZoom(); + break; + case bounce: + { + float fPercentOffset = sinf( fPercentThroughEffect*PI ); + m_tempState.pos += m_vEffectMagnitude * fPercentOffset; + m_tempState.pos.x = roundf( m_tempState.pos.x ); + m_tempState.pos.y = roundf( m_tempState.pos.y ); + m_tempState.pos.z = roundf( m_tempState.pos.z ); + } + break; + case bob: + { + float fPercentOffset = sinf( fPercentThroughEffect*PI*2 ); + m_tempState.pos += m_vEffectMagnitude * fPercentOffset; + m_tempState.pos.x = roundf( m_tempState.pos.x ); + m_tempState.pos.y = roundf( m_tempState.pos.y ); + m_tempState.pos.z = roundf( m_tempState.pos.z ); + } + break; + case pulse: + { + float fMinZoom = m_vEffectMagnitude[0]; + float fMaxZoom = m_vEffectMagnitude[1]; + float fPercentOffset = sinf( fPercentThroughEffect*PI ); + float fZoom = SCALE( fPercentOffset, 0.f, 1.f, fMinZoom, fMaxZoom ); + m_tempState.scale = RageVector3( fZoom, fZoom, fZoom ); + } + break; + default: + ASSERT(0); // invalid Effect } - break; - case bob: - { - float fPercentOffset = sinf( fPercentThroughEffect*PI*2 ); - m_temp.pos += m_vEffectMagnitude * fPercentOffset; - m_temp.pos.x = roundf( m_temp.pos.x ); - m_temp.pos.y = roundf( m_temp.pos.y ); - m_temp.pos.z = roundf( m_temp.pos.z ); - } - break; - case pulse: - { - float fMinZoom = m_vEffectMagnitude[0]; - float fMaxZoom = m_vEffectMagnitude[1]; - float fPercentOffset = sinf( fPercentThroughEffect*PI ); - float fZoom = SCALE( fPercentOffset, 0.f, 1.f, fMinZoom, fMaxZoom ); - m_temp.scale = RageVector3( fZoom, fZoom, fZoom ); - } - break; - default: - ASSERT(0); // invalid Effect } - - m_temp.scale.x *= m_baseScale.x; - m_temp.scale.y *= m_baseScale.y; - m_temp.scale.z *= m_baseScale.z; - m_temp.rotation.x += m_baseRotation.x; - m_temp.rotation.y += m_baseRotation.y; - m_temp.rotation.z += m_baseRotation.z; - - - DISPLAY->Translate( m_temp.pos.x, m_temp.pos.y, m_temp.pos.z ); - DISPLAY->Scale( m_temp.scale.x, m_temp.scale.y, m_temp.scale.z ); + DISPLAY->Translate( + m_pTempState->pos.x, + m_pTempState->pos.y, + m_pTempState->pos.z ); + DISPLAY->Scale( + m_pTempState->scale.x * m_baseScale.x, + m_pTempState->scale.y * m_baseScale.y, + m_pTempState->scale.z * m_baseScale.z ); /* The only time rotation and quat should normally be used simultaneously * is for m_baseRotation. */ - if( m_temp.rotation.x != 0 ) - DISPLAY->RotateX( m_temp.rotation.x ); - if( m_temp.rotation.y != 0 ) - DISPLAY->RotateY( m_temp.rotation.y ); - if( m_temp.rotation.z != 0 ) - DISPLAY->RotateZ( m_temp.rotation.z ); + if( m_pTempState->rotation.x + m_baseRotation.x != 0 ) + DISPLAY->RotateX( m_pTempState->rotation.x + m_baseRotation.x ); + if( m_pTempState->rotation.y + m_baseRotation.y != 0 ) + DISPLAY->RotateY( m_pTempState->rotation.y + m_baseRotation.y ); + if( m_pTempState->rotation.z + m_baseRotation.z != 0 ) + DISPLAY->RotateZ( m_pTempState->rotation.z + m_baseRotation.z ); - if( m_temp.quat.x != 0 || m_temp.quat.y != 0 || m_temp.quat.z != 0 || m_temp.quat.w != 1 ) + if( m_pTempState->quat.x != 0 || m_pTempState->quat.y != 0 || m_pTempState->quat.z != 0 || m_pTempState->quat.w != 1 ) { RageMatrix mat; - RageMatrixFromQuat( &mat, m_temp.quat ); + RageMatrixFromQuat( &mat, m_pTempState->quat ); DISPLAY->MultMatrix(mat); } diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index be9bc28959..c943b85f42 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -298,7 +298,8 @@ protected: // // Temporary variables that are filled just before drawing // - TweenState m_temp; + TweenState m_tempState; + TweenState *m_pTempState; bool m_bFirstUpdate; diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 6b2d4f33f2..c7e9194902 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -208,8 +208,8 @@ void BitmapText::BuildChars() void BitmapText::DrawChars() { unsigned uNumGlyphs = tex.size(); - unsigned uStartGlyph = (unsigned) SCALE( m_temp.crop.left, 0.f, 1.f, 0, (float) uNumGlyphs ); - unsigned uEndGlyph = (unsigned) SCALE( m_temp.crop.right, 0.f, 1.f, (float) uNumGlyphs, 0 ); + unsigned uStartGlyph = (unsigned) SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) uNumGlyphs ); + unsigned uEndGlyph = (unsigned) SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) uNumGlyphs, 0 ); ASSERT( uStartGlyph <= uNumGlyphs ); ASSERT( uEndGlyph <= uNumGlyphs ); @@ -304,7 +304,7 @@ void BitmapText::DrawPrimitives() DISPLAY->SetTextureModeModulate(); /* Draw if we're not fully transparent or the zbuffer is enabled */ - if( m_temp.diffuse[0].a != 0 ) + if( m_pTempState->diffuse[0].a != 0 ) { ////////////////////// // render the shadow @@ -314,7 +314,7 @@ void BitmapText::DrawPrimitives() DISPLAY->PushMatrix(); DISPLAY->TranslateWorld( m_fShadowLength, m_fShadowLength, 0 ); // shift by 5 units - RageColor dim(0,0,0,0.5f*m_temp.diffuse[0].a); // semi-transparent black + RageColor dim(0,0,0,0.5f*m_pTempState->diffuse[0].a); // semi-transparent black for( unsigned i=0; idiffuse[0]; // top left + verts[i+1].c = m_pTempState->diffuse[2]; // bottom left + verts[i+2].c = m_pTempState->diffuse[3]; // bottom right + verts[i+3].c = m_pTempState->diffuse[1]; // top right } } @@ -353,12 +353,12 @@ void BitmapText::DrawPrimitives() } /* render the glow pass */ - if( m_temp.glow.a > 0.0001f ) + if( m_pTempState->glow.a > 0.0001f ) { - DISPLAY->SetTextureModeGlow(m_temp.glowmode); + DISPLAY->SetTextureModeGlow(m_pTempState->glowmode); for( unsigned i=0; iglow; DrawChars(); } } diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 5dc067c628..24011ba80f 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -591,7 +591,7 @@ void Model::DrawPrimitives() return; // bail early /* Don't if we're fully transparent */ - if( m_temp.diffuse[0].a <= 0.001f ) + if( m_pTempState->diffuse[0].a <= 0.001f ) return; Actor::SetRenderStates(); // set Actor-specified render states @@ -671,7 +671,7 @@ void Model::DrawPrimitives() ////////////////////// // render the glow pass ////////////////////// - if( m_temp.glow.a > 0.0001f ) + if( m_pTempState->glow.a > 0.0001f ) { // TODO: Support glow. } diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index 2b4f5ef6ce..c91c7b55e7 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -277,19 +277,10 @@ void Sprite::DrawPrimitives() return; // 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 ) + if( m_pTempState->crop.left + m_pTempState->crop.right > 1 || + m_pTempState->crop.top + m_pTempState->crop.bottom > 1 ) 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 - // use m_temp_* variables to draw the object RectF quadVerticies; @@ -313,7 +304,7 @@ void Sprite::DrawPrimitives() 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 ); +#define IF_CROP_POS(side,opp_side) if(m_pTempState->crop.side>0) croppedQuadVerticies.side = SCALE( m_pTempState->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 ); @@ -348,35 +339,35 @@ void Sprite::DrawPrimitives() }; - if( m_temp.crop.left>0 ) + if( m_pTempState->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 ); + v[0].t.x = SCALE( m_pTempState->crop.left, 0.f, 1.f, texCoords[0].x, texCoords[3].x ); + v[1].t.x = SCALE( m_pTempState->crop.left, 0.f, 1.f, texCoords[1].x, texCoords[2].x ); } - if( m_temp.crop.right>0 ) + if( m_pTempState->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 ); + v[2].t.x = SCALE( m_pTempState->crop.right, 0.f, 1.f, texCoords[2].x, texCoords[1].x ); + v[3].t.x = SCALE( m_pTempState->crop.right, 0.f, 1.f, texCoords[3].x, texCoords[0].x ); } - if( m_temp.crop.top>0 ) + if( m_pTempState->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 ); + v[0].t.y = SCALE( m_pTempState->crop.top, 0.f, 1.f, texCoords[0].y, texCoords[1].y ); + v[3].t.y = SCALE( m_pTempState->crop.top, 0.f, 1.f, texCoords[3].y, texCoords[2].y ); } - if( m_temp.crop.bottom>0 ) + if( m_pTempState->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 ); + v[1].t.y = SCALE( m_pTempState->crop.bottom, 0.f, 1.f, texCoords[1].y, texCoords[0].y ); + v[2].t.y = SCALE( m_pTempState->crop.bottom, 0.f, 1.f, texCoords[2].y, texCoords[3].y ); } } DISPLAY->SetTextureModeModulate(); /* Draw if we're not fully transparent */ - if( m_temp.diffuse[0].a > 0 || - m_temp.diffuse[1].a > 0 || - m_temp.diffuse[2].a > 0 || - m_temp.diffuse[3].a > 0 ) + if( m_pTempState->diffuse[0].a > 0 || + m_pTempState->diffuse[1].a > 0 || + m_pTempState->diffuse[2].a > 0 || + m_pTempState->diffuse[3].a > 0 ) { ////////////////////// // render the shadow @@ -385,7 +376,7 @@ void Sprite::DrawPrimitives() { DISPLAY->PushMatrix(); 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*m_temp.diffuse[0].a); // semi-transparent black + v[0].c = v[1].c = v[2].c = v[3].c = RageColor(0,0,0,0.5f*m_pTempState->diffuse[0].a); // semi-transparent black DISPLAY->DrawQuad( v ); DISPLAY->PopMatrix(); } @@ -393,10 +384,10 @@ void Sprite::DrawPrimitives() ////////////////////// // render the diffuse pass ////////////////////// - v[0].c = m_temp.diffuse[0]; // top left - v[1].c = m_temp.diffuse[2]; // bottom left - v[2].c = m_temp.diffuse[3]; // bottom right - v[3].c = m_temp.diffuse[1]; // top right + v[0].c = m_pTempState->diffuse[0]; // top left + v[1].c = m_pTempState->diffuse[2]; // bottom left + v[2].c = m_pTempState->diffuse[3]; // bottom right + v[3].c = m_pTempState->diffuse[1]; // top right DISPLAY->DrawQuad( v ); // glEnable(GL_BLEND); } @@ -404,10 +395,10 @@ void Sprite::DrawPrimitives() ////////////////////// // render the glow pass ////////////////////// - if( m_temp.glow.a > 0.0001f ) + if( m_pTempState->glow.a > 0.0001f ) { - DISPLAY->SetTextureModeGlow(m_temp.glowmode); - v[0].c = v[1].c = v[2].c = v[3].c = m_temp.glow; + DISPLAY->SetTextureModeGlow(m_pTempState->glowmode); + v[0].c = v[1].c = v[2].c = v[3].c = m_pTempState->glow; DISPLAY->DrawQuad( v ); } }