revamp StreamDisplay: remove zbuffer tricks, replace with Sprite pills that can be used to make arbitrary shapes
This commit is contained in:
+60
-186
@@ -3,11 +3,18 @@
|
||||
#include "GameState.h"
|
||||
#include <float.h>
|
||||
#include "RageDisplay.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "EnumHelper.h"
|
||||
|
||||
static const char *StreamTypeNames[] = {
|
||||
"Normal",
|
||||
"Passing",
|
||||
"Hot",
|
||||
};
|
||||
XToString( StreamType );
|
||||
|
||||
StreamDisplay::StreamDisplay()
|
||||
{
|
||||
m_iNumStrips = 1;
|
||||
m_iNumChambers = 1;
|
||||
m_fPercent = 0;
|
||||
m_fTrailingPercent = 0;
|
||||
m_fVelocity = 0;
|
||||
@@ -15,63 +22,38 @@ StreamDisplay::StreamDisplay()
|
||||
m_fHotAlpha = 0;
|
||||
}
|
||||
|
||||
void StreamDisplay::Load(
|
||||
float fMeterWidth,
|
||||
float fMeterHeight,
|
||||
int iNumStrips,
|
||||
int iNumChambers,
|
||||
const RString &sNormalPath,
|
||||
const RString &sHotPath,
|
||||
const RString &sPassingPath,
|
||||
const apActorCommands &acNormalOnCommand,
|
||||
const apActorCommands &acHotOnCommand,
|
||||
const apActorCommands &acPassingOnCommand
|
||||
)
|
||||
void StreamDisplay::Load( const RString &_sMetricsGroup )
|
||||
{
|
||||
m_size.x = fMeterWidth;
|
||||
m_size.y = fMeterHeight;
|
||||
// XXX
|
||||
RString sMetricsGroup = "StreamDisplay";
|
||||
|
||||
m_iNumStrips = iNumStrips;
|
||||
m_iNumChambers = iNumChambers;
|
||||
m_transformPill.SetFromReference( THEME->GetMetricR(sMetricsGroup,"PillTransformFunction") );
|
||||
|
||||
m_quadMask.SetBlendMode( BLEND_NO_EFFECT );
|
||||
m_quadMask.SetZWrite( true );
|
||||
m_quadMask.ZoomToWidth( fMeterWidth );
|
||||
m_quadMask.ZoomToHeight( fMeterHeight );
|
||||
float fTextureCoordScaleX = THEME->GetMetricF(sMetricsGroup,"TextureCoordScaleX");
|
||||
int iNumPills = THEME->GetMetricF(sMetricsGroup,"NumPills");
|
||||
FOREACH_ENUM( StreamType, st )
|
||||
{
|
||||
ASSERT( m_vpSprPill[st].empty() );
|
||||
|
||||
RString sGraphicPath;
|
||||
RageTextureID ID;
|
||||
ID.bStretch = true;
|
||||
for( int i=0; i<iNumPills; i++ )
|
||||
{
|
||||
Sprite *pSpr = new Sprite;
|
||||
pSpr->Load( THEME->GetPathG(sMetricsGroup,StreamTypeToString(st)) );
|
||||
m_vpSprPill[st].push_back( pSpr );
|
||||
m_transformPill.PositionItem( pSpr, -1, i, iNumPills );
|
||||
|
||||
float fStripWidthInPercent = 1.0f/m_iNumStrips;
|
||||
float f = 1 / fTextureCoordScaleX;
|
||||
pSpr->SetCustomTextureRect( RectF(f*i,0,f*(i+1),1) );
|
||||
|
||||
ID.filename = sNormalPath;
|
||||
m_sprStreamNormal.Load( ID );
|
||||
m_sprStreamNormal.SetZTestMode( ZTEST_WRITE_ON_PASS );
|
||||
m_sprStreamNormal.SetHorizAlign( align_right );
|
||||
m_sprStreamNormal.ZoomToHeight( fMeterHeight );
|
||||
m_sprStreamNormal.ZoomToWidth( fMeterWidth*fStripWidthInPercent );
|
||||
m_sprStreamNormal.RunCommands( acNormalOnCommand );
|
||||
|
||||
ID.filename = sHotPath;
|
||||
m_sprStreamHot.Load( ID );
|
||||
m_sprStreamHot.SetZTestMode( ZTEST_WRITE_ON_PASS );
|
||||
m_sprStreamHot.SetHorizAlign( align_right );
|
||||
m_sprStreamHot.ZoomToHeight( fMeterHeight );
|
||||
m_sprStreamHot.ZoomToWidth( fMeterWidth*fStripWidthInPercent );
|
||||
m_sprStreamHot.RunCommands( acHotOnCommand );
|
||||
|
||||
ID.filename = sPassingPath;
|
||||
m_sprStreamPassing.Load( ID );
|
||||
m_sprStreamPassing.SetZTestMode( ZTEST_WRITE_ON_PASS );
|
||||
m_sprStreamPassing.SetHorizAlign( align_right );
|
||||
m_sprStreamPassing.ZoomToHeight( fMeterHeight );
|
||||
m_sprStreamPassing.ZoomToWidth( fMeterWidth*fStripWidthInPercent );
|
||||
m_sprStreamPassing.RunCommands( acPassingOnCommand );
|
||||
this->AddChild( pSpr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StreamDisplay::Update( float fDeltaSecs )
|
||||
{
|
||||
ActorFrame::Update( fDeltaSecs );
|
||||
|
||||
// HACK: Tweaking these values is very difficulty. Update the
|
||||
// "physics" many times so that the spring motion appears faster
|
||||
for( int i=0; i<10; i++ )
|
||||
@@ -104,35 +86,39 @@ void StreamDisplay::Update( float fDeltaSecs )
|
||||
// Don't clamp life percentage a little outside the visible range so
|
||||
// that the clamp doesn't dampen the "jiggle" of the meter.
|
||||
CLAMP( m_fTrailingPercent, -0.1f, 1.1f );
|
||||
}
|
||||
|
||||
void StreamDisplay::DrawPrimitives()
|
||||
{
|
||||
DrawMask( m_fTrailingPercent ); // this is the "right endcap" to the life
|
||||
|
||||
const float fChamberWidthInPercent = 1.0f/m_iNumChambers;
|
||||
float fPercentBetweenStrips = 1.0f/m_iNumStrips;
|
||||
|
||||
// round down so that the chamber overflows align
|
||||
if( m_iNumChambers > 10 )
|
||||
fPercentBetweenStrips = QuantizeDown( fPercentBetweenStrips, fChamberWidthInPercent );
|
||||
|
||||
|
||||
if( m_iNumChambers > 3 )
|
||||
fPercentBetweenStrips -= 2*fChamberWidthInPercent;
|
||||
|
||||
float fPercentOffset = fmodf( GAMESTATE->m_fSongBeat/4+1000, fPercentBetweenStrips );
|
||||
ASSERT( fPercentOffset >= 0 && fPercentOffset <= fPercentBetweenStrips );
|
||||
|
||||
// "+fPercentBetweenStrips" so that the whole area is overdrawn 2x
|
||||
for( float f=fPercentOffset+1+fPercentBetweenStrips; f>=0; f-=fPercentBetweenStrips )
|
||||
// set crop of pills
|
||||
const float fPillWidthPercent = 1.0f / m_vpSprPill[0].size();
|
||||
FOREACH_ENUM( StreamType, st )
|
||||
{
|
||||
DrawMask( f );
|
||||
DrawStrip( f );
|
||||
}
|
||||
for( int i=0; i<(int)m_vpSprPill[st].size(); i++ )
|
||||
{
|
||||
Sprite *pSpr = m_vpSprPill[st][i];
|
||||
float fPercentFilledThisPill = SCALE( m_fTrailingPercent, fPillWidthPercent*i, fPillWidthPercent*(i+1), 0.0f, 1.0f );
|
||||
CLAMP( fPercentFilledThisPill, 0.0f, 1.0f );
|
||||
pSpr->SetCropRight( 1.0f - fPercentFilledThisPill );
|
||||
// XXX scale by current song speed
|
||||
pSpr->SetTexCoordVelocity(-1,0);
|
||||
|
||||
// Don't leave the Zbuffer in a messy state for arrows and dancing characters
|
||||
DISPLAY->ClearZBuffer();
|
||||
// Optimization: Don't draw pills that are covered up
|
||||
switch( st )
|
||||
{
|
||||
DEFAULT_FAIL( st );
|
||||
case StreamType_Normal:
|
||||
pSpr->SetVisible( m_fPassingAlpha < 1 || m_fHotAlpha < 1 );
|
||||
pSpr->SetDiffuseAlpha( 1 );
|
||||
break;
|
||||
case StreamType_Passing:
|
||||
pSpr->SetDiffuseAlpha( m_fPassingAlpha );
|
||||
pSpr->SetVisible( m_fHotAlpha < 1 );
|
||||
break;
|
||||
case StreamType_Hot:
|
||||
pSpr->SetDiffuseAlpha( m_fHotAlpha );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StreamDisplay::SetPercent( float fPercent )
|
||||
@@ -154,118 +140,6 @@ void StreamDisplay::SetPercent( float fPercent )
|
||||
m_fPercent = fPercent;
|
||||
}
|
||||
|
||||
void StreamDisplay::SetPassingAlpha( float fPassingAlpha )
|
||||
{
|
||||
m_fPassingAlpha = fPassingAlpha;
|
||||
}
|
||||
|
||||
void StreamDisplay::SetHotAlpha( float fHotAlpha )
|
||||
{
|
||||
m_fHotAlpha = fHotAlpha;
|
||||
}
|
||||
|
||||
void StreamDisplay::GetChamberIndexAndOverflow( float fPercent, int& iChamberOut, float& fChamberOverflowPercentOut )
|
||||
{
|
||||
iChamberOut = (int)(fPercent*m_iNumChambers);
|
||||
fChamberOverflowPercentOut = fPercent*m_iNumChambers - iChamberOut;
|
||||
}
|
||||
|
||||
float StreamDisplay::GetChamberLeftPercent( int iChamber )
|
||||
{
|
||||
return (iChamber+0) / (float)m_iNumChambers;
|
||||
}
|
||||
|
||||
float StreamDisplay::GetChamberRightPercent( int iChamber )
|
||||
{
|
||||
return (iChamber+1) / (float)m_iNumChambers;
|
||||
}
|
||||
|
||||
float StreamDisplay::GetRightEdgePercent( int iChamber, float fChamberOverflowPercent )
|
||||
{
|
||||
if( (iChamber%2) == 0 )
|
||||
return (iChamber+fChamberOverflowPercent) / (float)m_iNumChambers;
|
||||
else
|
||||
return (iChamber+1) / (float)m_iNumChambers;
|
||||
}
|
||||
|
||||
float StreamDisplay::GetHeightPercent( int iChamber, float fChamberOverflowPercent )
|
||||
{
|
||||
if( (iChamber%2) == 1 )
|
||||
return 1-fChamberOverflowPercent;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StreamDisplay::DrawStrip( float fRightEdgePercent )
|
||||
{
|
||||
float fMeterWidth = this->GetUnzoomedWidth();
|
||||
m_sprStreamNormal.SetX( -fMeterWidth/2 + fMeterWidth*fRightEdgePercent );
|
||||
m_sprStreamPassing.SetX( -fMeterWidth/2 + fMeterWidth*fRightEdgePercent );
|
||||
m_sprStreamHot.SetX( -fMeterWidth/2 + fMeterWidth*fRightEdgePercent );
|
||||
|
||||
const float fMeterLeftEdgePixels = SCALE( 0.0f, 0.0f, 1.0f, -fMeterWidth/2, +fMeterWidth/2 );
|
||||
const float fMeterRightEdgePixels = SCALE( 1.0f, 0.0f, 1.0f, -fMeterWidth/2, +fMeterWidth/2 );
|
||||
|
||||
const float fStreamRightEdgePixels = SCALE( fRightEdgePercent, 0.0f, 1.0f, -fMeterWidth/2, +fMeterWidth/2 );
|
||||
const float fStreamLeftEdgePixels = fStreamRightEdgePixels - m_sprStreamNormal.GetZoomedWidth();
|
||||
|
||||
const float fLeftOverhangPixels = max( 0, fMeterLeftEdgePixels - fStreamLeftEdgePixels );
|
||||
const float fStreamCropLeftPercent = SCALE( fLeftOverhangPixels, 0.0f, m_sprStreamNormal.GetZoomedWidth(), 0.0f, 1.0f );
|
||||
|
||||
const float fRightOverhangPixels = max( 0, fStreamRightEdgePixels - fMeterRightEdgePixels );
|
||||
const float fStreamCropRightPercent = SCALE( fRightOverhangPixels, 0.0f, m_sprStreamNormal.GetZoomedWidth(), 0.0f, 1.0f );
|
||||
|
||||
m_sprStreamNormal.SetCropLeft( fStreamCropLeftPercent );
|
||||
m_sprStreamPassing.SetCropLeft( fStreamCropLeftPercent );
|
||||
m_sprStreamHot.SetCropLeft( fStreamCropLeftPercent );
|
||||
|
||||
m_sprStreamNormal.SetCropRight( fStreamCropRightPercent );
|
||||
m_sprStreamPassing.SetCropRight(fStreamCropRightPercent );
|
||||
m_sprStreamHot.SetCropRight( fStreamCropRightPercent );
|
||||
|
||||
|
||||
float fOrigPassingAlpha = m_sprStreamPassing.GetDiffuse().a;
|
||||
float fOrigHotAlpha = m_sprStreamHot.GetDiffuse().a;
|
||||
|
||||
m_sprStreamPassing.SetDiffuseAlpha( m_fPassingAlpha * fOrigPassingAlpha );
|
||||
m_sprStreamHot.SetDiffuseAlpha( m_fHotAlpha * fOrigHotAlpha );
|
||||
|
||||
if( m_fPassingAlpha < 1 && m_fHotAlpha < 1)
|
||||
m_sprStreamNormal.Draw();
|
||||
if( m_fHotAlpha < 1)
|
||||
m_sprStreamPassing.Draw();
|
||||
m_sprStreamHot.Draw();
|
||||
|
||||
m_sprStreamPassing.SetDiffuseAlpha( fOrigPassingAlpha );
|
||||
m_sprStreamHot.SetDiffuseAlpha( fOrigHotAlpha );
|
||||
}
|
||||
|
||||
void StreamDisplay::DrawMask( float fPercent )
|
||||
{
|
||||
int iChamber;
|
||||
float fChamberOverflowPercent;
|
||||
GetChamberIndexAndOverflow( fPercent, iChamber, fChamberOverflowPercent );
|
||||
|
||||
// draw mask for vertical chambers
|
||||
float fHeightPercent = GetHeightPercent( iChamber, fChamberOverflowPercent );
|
||||
float fChamberLeftPercent = GetChamberLeftPercent( iChamber );
|
||||
float fChamberRightPercent = GetChamberRightPercent( iChamber );
|
||||
m_quadMask.SetCropLeft( fChamberLeftPercent );
|
||||
m_quadMask.SetCropRight( 1-fChamberRightPercent );
|
||||
m_quadMask.SetCropTop( 0 );
|
||||
m_quadMask.SetCropBottom( 1-fHeightPercent );
|
||||
m_quadMask.Draw();
|
||||
|
||||
// draw mask for horizontal chambers
|
||||
float fRightPercent = GetRightEdgePercent( iChamber, fChamberOverflowPercent );
|
||||
m_quadMask.SetCropLeft( fRightPercent );
|
||||
m_quadMask.SetCropRight( 0 );
|
||||
m_quadMask.SetCropTop( 0 );
|
||||
m_quadMask.SetCropBottom( 0 );
|
||||
|
||||
m_quadMask.Draw();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (c) 2003-2004 Chris Danford
|
||||
|
||||
Reference in New Issue
Block a user