GraphDisplay with XML

This commit is contained in:
Glenn Maynard
2005-08-29 22:51:35 +00:00
parent 2320913000
commit 7c9740df17
4 changed files with 169 additions and 135 deletions
+152 -88
View File
@@ -3,51 +3,135 @@
#include "ThemeManager.h" #include "ThemeManager.h"
#include "RageTextureManager.h" #include "RageTextureManager.h"
#include "RageDisplay.h" #include "RageDisplay.h"
#include "ActorUtil.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h"
#include "StageStats.h" #include "StageStats.h"
#include "Foreach.h" #include "Foreach.h"
#include "song.h" #include "song.h"
#include "XmlFile.h"
//#define DIVIDE_LINE_WIDTH THEME->GetMetricI(m_sName,"TexturedBottomHalf") //#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() 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) ); FOREACH( Actor*, m_vpSongBoundaries, p )
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 )
SAFE_DELETE( *p ); SAFE_DELETE( *p );
m_vpSongBoundaries.clear(); m_vpSongBoundaries.clear();
SAFE_DELETE( m_pGraphLine );
m_sprJustBarely.Unload(); SAFE_DELETE( m_pGraphBody );
ActorFrame::RemoveAllChildren();
} }
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(); 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; i<ARRAYSIZE(m_Values); i++ ) for( unsigned i=0; i<ARRAYSIZE(m_Values); i++ )
CLAMP( m_Values[i], 0.f, 1.f ); CLAMP( m_Values[i], 0.f, 1.f );
@@ -61,14 +145,15 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
continue; continue;
fSec += (*song)->GetStepsSeconds(); fSec += (*song)->GetStepsSeconds();
AutoActor *p = new AutoActor; Actor *p = m_sprSongBoundary->Copy();
m_vpSongBoundaries.push_back( p ); m_vpSongBoundaries.push_back( p );
p->Load( sSongBoundaryPath );
float fX = SCALE( fSec, 0, fTotalStepSeconds, m_quadVertices.left, m_quadVertices.right ); float fX = SCALE( fSec, 0, fTotalStepSeconds, m_quadVertices.left, m_quadVertices.right );
(*p)->SetX( fX ); p->SetX( fX );
this->AddChild( *p ); this->AddChild( p );
} }
UpdateVerts();
if( !pss.bFailed && !pss.bGaveUp ) if( !pss.bFailed && !pss.bGaveUp )
{ {
// //
@@ -77,10 +162,10 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
float fMinLifeSoFar = 1.0f; float fMinLifeSoFar = 1.0f;
int iMinLifeSoFarAt = 0; int iMinLifeSoFarAt = 0;
int NumSlices = VALUE_RESOLUTION-1; for( int i = 0; i < VALUE_RESOLUTION; ++i )
for( int i = 0; i < NumSlices; ++i )
{ {
float fLife = m_Values[i]; float fLife = m_Values[i];
LOG->Trace( "m %i: %f", i, fLife );
if( fLife < fMinLifeSoFar ) if( fLife < fMinLifeSoFar )
{ {
fMinLifeSoFar = fLife; fMinLifeSoFar = fLife;
@@ -90,8 +175,8 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
if( fMinLifeSoFar > 0.0f && fMinLifeSoFar < 0.1f ) if( fMinLifeSoFar > 0.0f && fMinLifeSoFar < 0.1f )
{ {
float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(NumSlices), m_quadVertices.left, m_quadVertices.right ); float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
m_sprJustBarely->SetXY( fX, 0 ); m_sprJustBarely->SetX( fX );
} }
else else
{ {
@@ -99,53 +184,24 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
} }
this->AddChild( m_sprJustBarely ); this->AddChild( m_sprJustBarely );
} }
UpdateVerts();
} }
void GraphDisplay::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; const float fX = SCALE( float(i), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
case align_center: m_quadVertices.left = -m_size.x/2; m_quadVertices.right = m_size.x/2; break; const float fY = SCALE( m_Values[i], 0.0f, 1.0f, m_quadVertices.bottom, m_quadVertices.top );
case align_right: m_quadVertices.left = -m_size.x; m_quadVertices.right = 0; break;
default: ASSERT( false );
}
switch( m_VertAlign ) 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 );
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);
}
int iNumSlices = VALUE_RESOLUTION-1; m_pGraphLine->m_LineStrip[i].p = RageVector3( fX, fY, 0 );
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 )
);
} }
} }
@@ -156,24 +212,32 @@ void GraphDisplay::Update( float fDeltaTime )
UpdateVerts(); UpdateVerts();
} }
void GraphDisplay::DrawPrimitives() // lua start
#include "LuaBinding.h"
class LunaGraphDisplay: public Luna<GraphDisplay>
{ {
Actor::SetGlobalRenderStates(); // set Actor-specified render states public:
LunaGraphDisplay() { LUA->Register( Register ); }
DISPLAY->ClearAllTextures(); static int LoadFromStats( T* p, lua_State *L )
DISPLAY->SetTexture( 0, m_pTexture ); {
StageStats *pStageStats = Luna<StageStats>::check( L, 1 );
// Must call this after setting the texture or else texture PlayerStageStats *pPlayerStageStats = Luna<PlayerStageStats>::check( L, 2 );
// parameters have no effect. p->LoadFromStageStats( *pStageStats, *pPlayerStageStats );
Actor::SetTextureRenderStates(); return 0;
DISPLAY->SetTextureModeModulate();
DISPLAY->DrawQuads( m_Slices, ARRAYSIZE(m_Slices) );
DISPLAY->SetTexture( 0, NULL );
ActorFrame::DrawPrimitives();
} }
static void Register(lua_State *L)
{
ADD_METHOD( LoadFromStats )
Luna<T>::Register( L );
}
};
LUA_REGISTER_DERIVED_CLASS( GraphDisplay, ActorFrame )
// lua end
/* /*
* (c) 2003 Glenn Maynard * (c) 2003 Glenn Maynard
* All rights reserved. * All rights reserved.
+18 -13
View File
@@ -2,37 +2,42 @@
#define GRAPH_DISPLAY_H #define GRAPH_DISPLAY_H
#include "ActorFrame.h" #include "ActorFrame.h"
#include "RageTexture.h"
#include "AutoActor.h" #include "AutoActor.h"
class StageStats; class StageStats;
class PlayerStageStats; class PlayerStageStats;
class GraphLine;
class GraphBody;
class GraphDisplay: public ActorFrame class GraphDisplay: public ActorFrame
{ {
public: public:
GraphDisplay(); GraphDisplay();
~GraphDisplay() { Unload(); } ~GraphDisplay();
void Load( const CString &sTexturePath, const CString &sJustBarelyPath ); virtual Actor *Copy() const;
void Unload(); 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 Update( float fDeltaTime );
void DrawPrimitives();
//
// Lua
//
virtual void PushSelf( lua_State *L );
private: private:
void UpdateVerts(); void UpdateVerts();
enum { VALUE_RESOLUTION=200 }; vector<float> m_Values;
float m_Values[VALUE_RESOLUTION];
RectF m_quadVertices; RectF m_quadVertices;
RageSpriteVertex m_Slices[4*(VALUE_RESOLUTION-1)];
RageTexture *m_pTexture; vector<Actor*> m_vpSongBoundaries;
vector<AutoActor*> m_vpSongBoundaries;
AutoActor m_sprJustBarely; AutoActor m_sprJustBarely;
AutoActor m_sprTexture;
AutoActor m_sprSongBoundary;
GraphLine *m_pGraphLine;
GraphBody *m_pGraphBody;
}; };
#endif #endif
-30
View File
@@ -63,7 +63,6 @@ const char* STATS_STRING[NUM_STATS_LINES] =
#define SHOW_SCORE_AREA THEME->GetMetricB(m_sName,"ShowScoreArea") #define SHOW_SCORE_AREA THEME->GetMetricB(m_sName,"ShowScoreArea")
#define SHOW_TOTAL_SCORE_AREA THEME->GetMetricB(m_sName,"ShowTotalScoreArea") #define SHOW_TOTAL_SCORE_AREA THEME->GetMetricB(m_sName,"ShowTotalScoreArea")
#define SHOW_TIME_AREA THEME->GetMetricB(m_sName,"ShowTimeArea") #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_PER_DIFFICULTY_AWARD THEME->GetMetricB(m_sName,"ShowPerDifficultyAward")
#define SHOW_PEAK_COMBO_AWARD THEME->GetMetricB(m_sName,"ShowPeakComboAward") #define SHOW_PEAK_COMBO_AWARD THEME->GetMetricB(m_sName,"ShowPeakComboAward")
#define TYPE THEME->GetMetric (m_sName,"Type") #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 // 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 // points area
if( SHOW_POINTS_AREA ) if( SHOW_POINTS_AREA )
{ {
-5
View File
@@ -11,7 +11,6 @@
#include "DifficultyIcon.h" #include "DifficultyIcon.h"
#include "DifficultyMeter.h" #include "DifficultyMeter.h"
#include "PercentageDisplay.h" #include "PercentageDisplay.h"
#include "GraphDisplay.h"
#include "ActorUtil.h" #include "ActorUtil.h"
#include "HighScore.h" #include "HighScore.h"
#include "RageSound.h" #include "RageSound.h"
@@ -77,10 +76,6 @@ protected:
GradeDisplay m_Grades[NUM_PLAYERS]; GradeDisplay m_Grades[NUM_PLAYERS];
AutoActor m_sprGrade[NUM_PLAYERS]; AutoActor m_sprGrade[NUM_PLAYERS];
// graph area
AutoActor m_sprGraphFrame[NUM_PLAYERS];
GraphDisplay m_LifeGraph[NUM_PLAYERS];
// points area // points area
bool m_bNewSongsUnlocked; bool m_bNewSongsUnlocked;
PercentageDisplay m_Percent[NUM_PLAYERS]; PercentageDisplay m_Percent[NUM_PLAYERS];