From 7c9740df17e6bf3a72242457e09eafc8a41680c5 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 29 Aug 2005 22:51:35 +0000 Subject: [PATCH] GraphDisplay with XML --- stepmania/src/GraphDisplay.cpp | 238 ++++++++++++++++++----------- stepmania/src/GraphDisplay.h | 31 ++-- stepmania/src/ScreenEvaluation.cpp | 30 ---- stepmania/src/ScreenEvaluation.h | 5 - 4 files changed, 169 insertions(+), 135 deletions(-) diff --git a/stepmania/src/GraphDisplay.cpp b/stepmania/src/GraphDisplay.cpp index 6c10a07d8d..9f32c3d5f8 100644 --- a/stepmania/src/GraphDisplay.cpp +++ b/stepmania/src/GraphDisplay.cpp @@ -3,51 +3,135 @@ #include "ThemeManager.h" #include "RageTextureManager.h" #include "RageDisplay.h" +#include "ActorUtil.h" #include "RageUtil.h" +#include "RageLog.h" #include "StageStats.h" #include "Foreach.h" #include "song.h" +#include "XmlFile.h" //#define DIVIDE_LINE_WIDTH THEME->GetMetricI(m_sName,"TexturedBottomHalf") +REGISTER_ACTOR_CLASS( GraphDisplay ) + +enum { VALUE_RESOLUTION=20 }; +class GraphLine: public Actor +{ +public: + GraphLine() + { + for( unsigned i = 0; i < ARRAYSIZE(m_LineStrip); ++i ) + { + m_LineStrip[i].c = RageColor( 1,1,1,1 ); + m_LineStrip[i].t = RageVector2( 0,0 ); + } + } + + void DrawPrimitives() + { + Actor::SetGlobalRenderStates(); // set Actor-specified render states + + DISPLAY->ClearAllTextures(); + + // Must call this after setting the texture or else texture + // parameters have no effect. + Actor::SetTextureRenderStates(); + + for( int i = 0; i < ARRAYSIZE(m_LineStrip); ++i ) + m_LineStrip[i].c = this->m_pTempState->diffuse[0]; + + // XXX: order: mask, sprite, line, others + DISPLAY->DrawLineStrip( m_LineStrip, ARRAYSIZE(m_LineStrip), 2 ); + } + + RageSpriteVertex m_LineStrip[VALUE_RESOLUTION]; +}; + +class GraphBody: public Actor +{ +public: + GraphBody() + { + for( int i = 0; i < 2*VALUE_RESOLUTION; ++i ) + { + m_Slices[i].c = RageColor(1,1,1,1); + m_Slices[i].t = RageVector2( 0,0 ); + } + } + + void DrawPrimitives() + { + Actor::SetGlobalRenderStates(); // set Actor-specified render states + + DISPLAY->ClearAllTextures(); + + // Must call this after setting the texture or else texture + // parameters have no effect. + Actor::SetTextureRenderStates(); + + DISPLAY->SetTextureModeModulate(); + DISPLAY->DrawQuadStrip( m_Slices, ARRAYSIZE(m_Slices) ); + } + + RageSpriteVertex m_Slices[2*VALUE_RESOLUTION]; +}; GraphDisplay::GraphDisplay() { - m_pTexture = NULL; + m_pGraphLine = new GraphLine; + m_pGraphBody = new GraphBody; } -void GraphDisplay::Load( const CString &TexturePath, const CString &sJustBarelyPath ) +GraphDisplay::~GraphDisplay() { - memset( m_Values, 0, sizeof(m_Values) ); - - Unload(); - m_pTexture = TEXTUREMAN->LoadTexture( TexturePath ); - m_size.x = (float) m_pTexture->GetSourceWidth(); - m_size.y = (float) m_pTexture->GetSourceHeight(); - - m_sprJustBarely.Load( sJustBarelyPath ); -} - -void GraphDisplay::Unload() -{ - if( m_pTexture != NULL ) - TEXTUREMAN->UnloadTexture( m_pTexture ); - - m_pTexture = NULL; - - FOREACH( AutoActor*, m_vpSongBoundaries, p ) + FOREACH( Actor*, m_vpSongBoundaries, p ) SAFE_DELETE( *p ); m_vpSongBoundaries.clear(); - - m_sprJustBarely.Unload(); - - ActorFrame::RemoveAllChildren(); + SAFE_DELETE( m_pGraphLine ); + SAFE_DELETE( m_pGraphBody ); } -void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageStats &pss, const CString &sSongBoundaryPath ) +void GraphDisplay::LoadFromNode( const CString& sDir, const XNode* pNode ) +{ + ActorFrame::LoadFromNode( sDir, pNode ); + + const XNode *pChild = pNode->GetChild( "Body" ); + if( pChild == NULL ) + RageException::Throw( ssprintf("ComboGraph in \"%s\" is missing the node \"Body\"", sDir.c_str()) ); + m_pGraphBody->LoadFromNode( sDir, pChild ); + this->AddChild( m_pGraphBody ); + + pChild = pNode->GetChild( "Texture" ); + if( pChild == NULL ) + RageException::Throw( ssprintf("ComboGraph in \"%s\" is missing the node \"Texture\"", sDir.c_str()) ); + m_sprTexture.LoadFromNode( sDir, pChild ); + m_size.x = m_sprTexture->GetUnzoomedWidth(); + m_size.y = m_sprTexture->GetUnzoomedHeight(); + this->AddChild( m_sprTexture ); + + pChild = pNode->GetChild( "Line" ); + if( pChild == NULL ) + RageException::Throw( ssprintf("ComboGraph in \"%s\" is missing the node \"Line\"", sDir.c_str()) ); + m_pGraphLine->LoadFromNode( sDir, pChild ); + this->AddChild( m_pGraphLine ); + + pChild = pNode->GetChild( "SongBoundary" ); + if( pChild == NULL ) + RageException::Throw( ssprintf("ComboGraph in \"%s\" is missing the node \"SongBoundary\"", sDir.c_str()) ); + m_sprSongBoundary.LoadFromNode( sDir, pChild ); + + pChild = pNode->GetChild( "Barely" ); + if( pChild == NULL ) + RageException::Throw( ssprintf("ComboGraph in \"%s\" is missing the node \"Barely\"", sDir.c_str()) ); + m_sprJustBarely.LoadFromNode( sDir, pChild ); +} + +void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageStats &pss ) { float fTotalStepSeconds = ss.GetTotalPossibleStepsSeconds(); - pss.GetLifeRecord( m_Values, VALUE_RESOLUTION, ss.GetTotalPossibleStepsSeconds() ); + m_Values.resize( VALUE_RESOLUTION ); + pss.GetLifeRecord( &m_Values[0], VALUE_RESOLUTION, ss.GetTotalPossibleStepsSeconds() ); for( unsigned i=0; iGetStepsSeconds(); - AutoActor *p = new AutoActor; + Actor *p = m_sprSongBoundary->Copy(); m_vpSongBoundaries.push_back( p ); - p->Load( sSongBoundaryPath ); float fX = SCALE( fSec, 0, fTotalStepSeconds, m_quadVertices.left, m_quadVertices.right ); - (*p)->SetX( fX ); - this->AddChild( *p ); + p->SetX( fX ); + this->AddChild( p ); } + UpdateVerts(); + if( !pss.bFailed && !pss.bGaveUp ) { // @@ -77,10 +162,10 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt float fMinLifeSoFar = 1.0f; int iMinLifeSoFarAt = 0; - int NumSlices = VALUE_RESOLUTION-1; - for( int i = 0; i < NumSlices; ++i ) + for( int i = 0; i < VALUE_RESOLUTION; ++i ) { float fLife = m_Values[i]; + LOG->Trace( "m %i: %f", i, fLife ); if( fLife < fMinLifeSoFar ) { fMinLifeSoFar = fLife; @@ -90,8 +175,8 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt if( fMinLifeSoFar > 0.0f && fMinLifeSoFar < 0.1f ) { - float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(NumSlices), m_quadVertices.left, m_quadVertices.right ); - m_sprJustBarely->SetXY( fX, 0 ); + float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right ); + m_sprJustBarely->SetX( fX ); } else { @@ -99,53 +184,24 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt } this->AddChild( m_sprJustBarely ); } - - UpdateVerts(); } void GraphDisplay::UpdateVerts() { - switch( m_HorizAlign ) + m_quadVertices.left = -m_size.x/2; + m_quadVertices.right = m_size.x/2; + m_quadVertices.top = -m_size.y/2; + m_quadVertices.bottom = m_size.y/2; + + for( int i = 0; i < VALUE_RESOLUTION; ++i ) { - case align_left: m_quadVertices.left = 0; m_quadVertices.right = m_size.x; break; - case align_center: m_quadVertices.left = -m_size.x/2; m_quadVertices.right = m_size.x/2; break; - case align_right: m_quadVertices.left = -m_size.x; m_quadVertices.right = 0; break; - default: ASSERT( false ); - } + const float fX = SCALE( float(i), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right ); + const float fY = SCALE( m_Values[i], 0.0f, 1.0f, m_quadVertices.bottom, m_quadVertices.top ); - switch( m_VertAlign ) - { - case align_top: m_quadVertices.top = 0; m_quadVertices.bottom = m_size.y; break; - case align_middle: m_quadVertices.top = -m_size.y/2; m_quadVertices.bottom = m_size.y/2; break; - case align_bottom: m_quadVertices.top = -m_size.y; m_quadVertices.bottom = 0; break; - default: ASSERT(0); - } + m_pGraphBody->m_Slices[i*2+0].p = RageVector3( fX, m_quadVertices.bottom, 0 ); + m_pGraphBody->m_Slices[i*2+1].p = RageVector3( fX, fY, 0 ); - int iNumSlices = VALUE_RESOLUTION-1; - - for( int i = 0; i < 4*iNumSlices; ++i ) - m_Slices[i].c = RageColor(1,1,1,1); - - for( int i = 0; i < iNumSlices; ++i ) - { - const float fLeft = SCALE( float(i), 0.0f, float(iNumSlices), m_quadVertices.left, m_quadVertices.right ); - const float fRight = SCALE( float(i+1), 0.0f, float(iNumSlices), m_quadVertices.left, m_quadVertices.right ); - const float fLeftBottom = SCALE( float(m_Values[i]), 0.0f, 1.0f, m_quadVertices.top, m_quadVertices.bottom ); - const float fRightBottom = SCALE( float(m_Values[i+1]), 0.0f, 1.0f, m_quadVertices.top, m_quadVertices.bottom ); - - m_Slices[i*4+0].p = RageVector3( fLeft, m_quadVertices.top, 0 ); // top left - m_Slices[i*4+1].p = RageVector3( fLeft, fLeftBottom, 0 ); // bottom left - m_Slices[i*4+2].p = RageVector3( fRight, fRightBottom, 0 ); // bottom right - m_Slices[i*4+3].p = RageVector3( fRight, m_quadVertices.top, 0 ); // top right - } - - const RectF *tex = m_pTexture->GetTextureCoordRect( 0 ); - for( unsigned i = 0; i < ARRAYSIZE(m_Slices); ++i ) - { - m_Slices[i].t = RageVector2( - SCALE( m_Slices[i].p.x, m_quadVertices.left, m_quadVertices.right, tex->left, tex->right ), - SCALE( m_Slices[i].p.y, m_quadVertices.top, m_quadVertices.bottom, tex->top, tex->bottom ) - ); + m_pGraphLine->m_LineStrip[i].p = RageVector3( fX, fY, 0 ); } } @@ -156,23 +212,31 @@ void GraphDisplay::Update( float fDeltaTime ) UpdateVerts(); } -void GraphDisplay::DrawPrimitives() +// lua start +#include "LuaBinding.h" + +class LunaGraphDisplay: public Luna { - Actor::SetGlobalRenderStates(); // set Actor-specified render states +public: + LunaGraphDisplay() { LUA->Register( Register ); } - DISPLAY->ClearAllTextures(); - DISPLAY->SetTexture( 0, m_pTexture ); + static int LoadFromStats( T* p, lua_State *L ) + { + StageStats *pStageStats = Luna::check( L, 1 ); + PlayerStageStats *pPlayerStageStats = Luna::check( L, 2 ); + p->LoadFromStageStats( *pStageStats, *pPlayerStageStats ); + return 0; + } - // Must call this after setting the texture or else texture - // parameters have no effect. - Actor::SetTextureRenderStates(); + static void Register(lua_State *L) + { + ADD_METHOD( LoadFromStats ) + Luna::Register( L ); + } +}; - DISPLAY->SetTextureModeModulate(); - DISPLAY->DrawQuads( m_Slices, ARRAYSIZE(m_Slices) ); - DISPLAY->SetTexture( 0, NULL ); - - ActorFrame::DrawPrimitives(); -} +LUA_REGISTER_DERIVED_CLASS( GraphDisplay, ActorFrame ) +// lua end /* * (c) 2003 Glenn Maynard diff --git a/stepmania/src/GraphDisplay.h b/stepmania/src/GraphDisplay.h index 2303ba1499..15ea9054d8 100644 --- a/stepmania/src/GraphDisplay.h +++ b/stepmania/src/GraphDisplay.h @@ -2,37 +2,42 @@ #define GRAPH_DISPLAY_H #include "ActorFrame.h" -#include "RageTexture.h" #include "AutoActor.h" class StageStats; class PlayerStageStats; - +class GraphLine; +class GraphBody; class GraphDisplay: public ActorFrame { public: GraphDisplay(); - ~GraphDisplay() { Unload(); } - void Load( const CString &sTexturePath, const CString &sJustBarelyPath ); - void Unload(); + ~GraphDisplay(); + virtual Actor *Copy() const; + virtual void LoadFromNode( const CString& sDir, const XNode* pNode ); - void LoadFromStageStats( const StageStats &ss, const PlayerStageStats &s, const CString &sSongBoundaryPath ); + void LoadFromStageStats( const StageStats &ss, const PlayerStageStats &s ); void Update( float fDeltaTime ); - void DrawPrimitives(); + + // + // Lua + // + virtual void PushSelf( lua_State *L ); private: void UpdateVerts(); - enum { VALUE_RESOLUTION=200 }; - float m_Values[VALUE_RESOLUTION]; + vector m_Values; RectF m_quadVertices; - RageSpriteVertex m_Slices[4*(VALUE_RESOLUTION-1)]; - RageTexture *m_pTexture; - - vector m_vpSongBoundaries; + vector m_vpSongBoundaries; AutoActor m_sprJustBarely; + AutoActor m_sprTexture; + AutoActor m_sprSongBoundary; + + GraphLine *m_pGraphLine; + GraphBody *m_pGraphBody; }; #endif diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index a18d60324d..f430294ef5 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -63,7 +63,6 @@ const char* STATS_STRING[NUM_STATS_LINES] = #define SHOW_SCORE_AREA THEME->GetMetricB(m_sName,"ShowScoreArea") #define SHOW_TOTAL_SCORE_AREA THEME->GetMetricB(m_sName,"ShowTotalScoreArea") #define SHOW_TIME_AREA THEME->GetMetricB(m_sName,"ShowTimeArea") -#define SHOW_GRAPH_AREA THEME->GetMetricB(m_sName,"ShowGraphArea") #define SHOW_PER_DIFFICULTY_AWARD THEME->GetMetricB(m_sName,"ShowPerDifficultyAward") #define SHOW_PEAK_COMBO_AWARD THEME->GetMetricB(m_sName,"ShowPeakComboAward") #define TYPE THEME->GetMetric (m_sName,"Type") @@ -417,26 +416,6 @@ void ScreenEvaluation::Init() } } - // - // init graph area - // - if( SHOW_GRAPH_AREA ) - { - FOREACH_EnabledPlayer( p ) - { - m_sprGraphFrame[p].Load( THEME->GetPathG(m_sName,ssprintf("graph frame p%d",p+1)) ); - m_sprGraphFrame[p]->SetName( ssprintf("GraphFrameP%d",p+1) ); - SET_XY_AND_ON_COMMAND( m_sprGraphFrame[p] ); - this->AddChild( m_sprGraphFrame[p] ); - - m_LifeGraph[p].SetName( ssprintf("LifeGraphP%i",p+1) ); - m_LifeGraph[p].Load( THEME->GetPathG(m_sName,ssprintf("LifeGraph p%i", p+1)), THEME->GetPathG(m_sName,"JustBarely") ); - m_LifeGraph[p].LoadFromStageStats( m_StageStats, m_StageStats.m_player[p], THEME->GetPathG(m_sName,"SongBoundary") ); - SET_XY_AND_ON_COMMAND( m_LifeGraph[p] ); - this->AddChild( &m_LifeGraph[p] ); - } - } - // // init grade area // @@ -1105,15 +1084,6 @@ void ScreenEvaluation::TweenOursOffScreen() } } - if( SHOW_GRAPH_AREA ) - { - FOREACH_EnabledPlayer( p ) - { - OFF_COMMAND( m_sprGraphFrame[p] ); - OFF_COMMAND( m_LifeGraph[p] ); - } - } - // points area if( SHOW_POINTS_AREA ) { diff --git a/stepmania/src/ScreenEvaluation.h b/stepmania/src/ScreenEvaluation.h index 41716a3fce..db00772098 100644 --- a/stepmania/src/ScreenEvaluation.h +++ b/stepmania/src/ScreenEvaluation.h @@ -11,7 +11,6 @@ #include "DifficultyIcon.h" #include "DifficultyMeter.h" #include "PercentageDisplay.h" -#include "GraphDisplay.h" #include "ActorUtil.h" #include "HighScore.h" #include "RageSound.h" @@ -77,10 +76,6 @@ protected: GradeDisplay m_Grades[NUM_PLAYERS]; AutoActor m_sprGrade[NUM_PLAYERS]; - // graph area - AutoActor m_sprGraphFrame[NUM_PLAYERS]; - GraphDisplay m_LifeGraph[NUM_PLAYERS]; - // points area bool m_bNewSongsUnlocked; PercentageDisplay m_Percent[NUM_PLAYERS];