move "rolling numbers" functionality out of ScoreDisplayNormal

This commit is contained in:
Chris Danford
2005-02-15 00:49:22 +00:00
parent e51d338922
commit 0ab2447027
7 changed files with 177 additions and 67 deletions
+2 -1
View File
@@ -275,7 +275,8 @@ Actor.cpp Actor.h ActorCollision.h ActorFrame.cpp ActorFrame.h \
ActorScroller.cpp ActorScroller.h ActorUtil.cpp ActorUtil.h \
AutoActor.cpp AutoActor.h \
BitmapText.cpp BitmapText.h Model.cpp Model.h \
ModelManager.cpp ModelManager.h ModelTypes.cpp ModelTypes.h Quad.h Sprite.cpp Sprite.h
ModelManager.cpp ModelManager.h ModelTypes.cpp ModelTypes.h Quad.h \
RollingNumbers.cpp RollingNumbers.h Sprite.cpp Sprite.h
GlobalSingletons = \
AnnouncerManager.cpp AnnouncerManager.h Bookkeeper.cpp Bookkeeper.h CryptManager.cpp CryptManager.h \
+72
View File
@@ -0,0 +1,72 @@
#include "global.h"
#include "RollingNumbers.h"
#include "RageUtil.h"
#include "XmlFile.h"
RollingNumbers::RollingNumbers()
{
m_sFormat = "%9.0f";
m_fApproachSeconds = 0.2f;
m_fCurrentNumber = 0;
m_fTargetNumber = 0;
m_fScoreVelocity = 0;
}
void RollingNumbers::LoadFromNode( const CString& sDir, const XNode* pNode )
{
BitmapText::LoadFromNode( sDir, pNode );
pNode->GetAttrValue( "Format", m_sFormat );
pNode->GetAttrValue( "ApproachSeconds", m_fApproachSeconds );
UpdateText();
}
void RollingNumbers::Update( float fDeltaTime )
{
if( m_fCurrentNumber != m_fTargetNumber )
{
fapproach( m_fCurrentNumber, m_fTargetNumber, m_fScoreVelocity * fDeltaTime );
UpdateText();
}
BitmapText::Update( fDeltaTime );
}
void RollingNumbers::SetTargetNumber( float fTargetNumber )
{
m_fTargetNumber = fTargetNumber;
m_fScoreVelocity = (m_fTargetNumber-m_fCurrentNumber) / m_fApproachSeconds;
}
void RollingNumbers::UpdateText()
{
SetText( ssprintf(m_sFormat, m_fCurrentNumber) );
}
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
+63
View File
@@ -0,0 +1,63 @@
/* RollingNumbers - animates from one number to another by scrolling its digits. */
#ifndef RollingNumbers_H
#define RollingNumbers_H
#include "BitmapText.h"
class RollingNumbers : public BitmapText
{
public:
RollingNumbers();
void LoadFromNode( const CString& sDir, const XNode* pNode );
virtual void Update( float fDeltaTime );
void SetTargetNumber( float fTargetNumber );
void UpdateText();
private:
// Loaded attributes
//
// Time between the call to SetTargetNumber and m_fCurrentNumber ==
// m_fTargetNumber. Used to calculate m_fScoreVelocity.
float m_fApproachSeconds;
CString m_sFormat;
//
// Calculated
//
float m_fCurrentNumber; // currently showing this
float m_fTargetNumber; // approach this
float m_fScoreVelocity; // approach target at this speed
};
#endif
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
+23 -57
View File
@@ -24,16 +24,7 @@ ScoreDisplayNormal::ScoreDisplayNormal()
// init the text
m_text.LoadFromFont( THEME->GetPathF("ScoreDisplayNormal","numbers") );
m_text.SetShadowLength( 0 );
m_iScore = 0;
m_iTrailingScore = 0;
m_iScoreVelocity = 0;
CString s;
for( int i=0; i<NUM_SCORE_DIGITS; i++ )
s += ' ';
m_text.SetText( s );
m_text.UpdateText();
this->AddChild( &m_text );
}
@@ -49,63 +40,38 @@ void ScoreDisplayNormal::Init( const PlayerState* pPlayerState )
void ScoreDisplayNormal::SetScore( int iNewScore )
{
m_iScore = iNewScore;
// play some games to display the correct score -- the actual internal score does not change at all
// but the displayed one can (ie: displayed score for subtracrive is MaxScore - score)
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
// Play some games to display the correct score -- the actual internal
// score does not change at all but the displayed one can (ie: displayed
// score for subtracrive is MaxScore - score).
if( m_pPlayerState->m_CurrentPlayerOptions.m_ScoreDisplay == PlayerOptions::SCORING_SUBTRACT )
int iMaxScore = g_CurStageStats.m_player[pn].iMaxScore;
int iCurMaxScore = g_CurStageStats.m_player[pn].iCurMaxScore;
switch( m_pPlayerState->m_CurrentPlayerOptions.m_ScoreDisplay )
{
m_iScore = g_CurStageStats.m_player[pn].iMaxScore - ( g_CurStageStats.m_player[pn].iCurMaxScore - iNewScore );
}
else if( m_pPlayerState->m_CurrentPlayerOptions.m_ScoreDisplay == PlayerOptions::SCORING_AVERAGE )
{
if( g_CurStageStats.m_player[pn].iCurMaxScore == 0 ) // don't divide by zero fats
m_iScore = 0;
case PlayerOptions::SCORING_ADD:
// nothing to do
break;
case PlayerOptions::SCORING_SUBTRACT:
iNewScore = iMaxScore - ( iCurMaxScore - iNewScore );
break;
case PlayerOptions::SCORING_AVERAGE:
if( iCurMaxScore == 0 ) // don't divide by zero fats
{
iNewScore = 0;
}
else
{
float scoreRatio = (float) iNewScore / (float) g_CurStageStats.m_player[pn].iCurMaxScore;
m_iScore = (int) ( scoreRatio * g_CurStageStats.m_player[pn].iMaxScore );
float fScoreRatio = iNewScore / (float)iCurMaxScore;
iNewScore = fScoreRatio * iMaxScore;
}
}
int iDelta = m_iScore - m_iTrailingScore;
m_iScoreVelocity = int(float(iDelta) / SCORE_TWEEN_TIME); // in score units per second
}
void ScoreDisplayNormal::SetText( CString s )
{
m_text.SetText( s );
}
void ScoreDisplayNormal::Update( float fDeltaTime )
{
ScoreDisplay::Update( fDeltaTime );
if( m_iTrailingScore != m_iScore )
{
// adjust for when player fails
int increment = int(m_iScoreVelocity * fDeltaTime);
if (m_iScoreVelocity != 0 && increment == 0) increment = 1;
int iDeltaBefore = m_iScore - m_iTrailingScore;
m_iTrailingScore += increment;
int iDeltaAfter = m_iScore - m_iTrailingScore;
if( (iDeltaBefore < 0 && iDeltaAfter > 0) ||
(iDeltaBefore > 0 && iDeltaAfter < 0) ) // the sign changed
{
m_iTrailingScore = m_iScore;
m_iScoreVelocity = 0;
}
m_text.SetText( ssprintf("%*.0i", NUM_SCORE_DIGITS, m_iTrailingScore) );
}
m_text.SetTargetNumber( iNewScore );
}
/*
+3 -9
View File
@@ -4,7 +4,7 @@
#define SCORE_DISPLAY_NORMAL_H
#include "ScoreDisplay.h"
#include "BitmapText.h"
#include "RollingNumbers.h"
#include "Sprite.h"
class ScoreDisplayNormal : public ScoreDisplay
@@ -14,18 +14,12 @@ public:
virtual void Init( const PlayerState* pPlayerState );
virtual void Update( float fDeltaTime );
virtual void SetScore( int iNewScore );
virtual void SetText( CString s );
virtual void SetText( CString s ) { m_text.SetText(s); }
protected:
Sprite m_sprFrame;
BitmapText m_text;
int m_iScore; // the actual score
int m_iTrailingScore; // what is displayed temporarily
int m_iScoreVelocity; // how fast trailing approaches real score
RollingNumbers m_text;
};
#endif
+8
View File
@@ -1766,6 +1766,14 @@ SOURCE=.\Quad.h
# End Source File
# Begin Source File
SOURCE=.\RollingNumbers.cpp
# End Source File
# Begin Source File
SOURCE=.\RollingNumbers.h
# End Source File
# End Group
SOURCE=.\Sprite.cpp
# End Source File
# Begin Source File
+6
View File
@@ -2285,6 +2285,12 @@ cl /Zl /nologo /c verstub.cpp /Fo&quot;$(IntDir)&quot;\
<File
RelativePath="Quad.h">
</File>
<File
RelativePath="RollingNumbers.cpp">
</File>
<File
RelativePath="RollingNumbers.h">
</File>
<File
RelativePath=".\Sprite.cpp">
</File>