From 7cb3a127229ab6fc3c6e6f0fef15bbabec47c13c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 4 Oct 2005 06:02:18 +0000 Subject: [PATCH] move stats and skips into ScreenStatsOverlay --- .../Fonts/ScreenStatsOverlay stats.redir | 1 + .../Fonts/ScreenStatsOverlay time.redir | 1 + stepmania/Themes/default/metrics.ini | 15 +- stepmania/src/Makefile.am | 1 + stepmania/src/ScreenStatsOverlay.cpp | 173 ++++++++++++++++++ stepmania/src/ScreenStatsOverlay.h | 58 ++++++ stepmania/src/ScreenSystemLayer.cpp | 118 ------------ stepmania/src/ScreenSystemLayer.h | 10 - stepmania/src/StepMania-net2003.vcproj | 6 + stepmania/src/StepMania.vcproj | 6 + 10 files changed, 254 insertions(+), 135 deletions(-) create mode 100644 stepmania/Themes/default/Fonts/ScreenStatsOverlay stats.redir create mode 100644 stepmania/Themes/default/Fonts/ScreenStatsOverlay time.redir create mode 100644 stepmania/src/ScreenStatsOverlay.cpp create mode 100644 stepmania/src/ScreenStatsOverlay.h diff --git a/stepmania/Themes/default/Fonts/ScreenStatsOverlay stats.redir b/stepmania/Themes/default/Fonts/ScreenStatsOverlay stats.redir new file mode 100644 index 0000000000..ca24092074 --- /dev/null +++ b/stepmania/Themes/default/Fonts/ScreenStatsOverlay stats.redir @@ -0,0 +1 @@ +Common normal diff --git a/stepmania/Themes/default/Fonts/ScreenStatsOverlay time.redir b/stepmania/Themes/default/Fonts/ScreenStatsOverlay time.redir new file mode 100644 index 0000000000..ca24092074 --- /dev/null +++ b/stepmania/Themes/default/Fonts/ScreenStatsOverlay time.redir @@ -0,0 +1 @@ +Common normal diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index 1e85fb9a07..cbb2dde067 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -11,7 +11,7 @@ CourseDifficultiesToShow=easy,regular,difficult StepsTypesToHide=dance-couple,dance-solo,pump-halfdouble,lights-cabinet ScreenWidth=640 ScreenHeight=480 -OverlayScreens=ScreenSystemLayer,ScreenSyncOverlay,ScreenDebugOverlay +OverlayScreens=ScreenSystemLayer,ScreenSyncOverlay,ScreenStatsOverlay,ScreenDebugOverlay MaxCourseEntriesBeforeShowVarious=6 [Gameplay] @@ -2128,9 +2128,6 @@ Line4=list,RandomModifiers [ScreenSystemLayer] Fallback=Screen Class=ScreenSystemLayer -StatsX=SCREEN_RIGHT-8 -StatsY=SCREEN_TOP+10 -StatsOnCommand=horizalign,right;vertalign,top;zoom,0.5;shadowlength,2 MessageX=0 MessageY=0 MessageOnCommand=wrapwidthpixels,800;finishtweening;horizalign,left;vertalign,top;x,SCREEN_LEFT+20;y,SCREEN_TOP+20;zoom,0.8;shadowlength,2;diffusealpha,1;addx,-SCREEN_WIDTH;linear,0.5;addx,SCREEN_WIDTH @@ -2139,9 +2136,6 @@ MessageFrameX=0 MessageFrameY=0 MessageFrameOnCommand= MessageFrameOffCommand= -TimeX=SCREEN_LEFT+4 -TimeY=SCREEN_TOP+40 -TimeOnCommand=horizalign,left;vertalign,top;zoom,0.5;shadowlength,0;diffuse,1,0,1,1 CreditsP1X=SCREEN_LEFT+120 CreditsP1Y=SCREEN_BOTTOM-6 CreditsP1OnCommand=shadowlength,0 @@ -2158,6 +2152,13 @@ Fallback=Screen Class=ScreenSyncOverlay Fallback=Screen +[ScreenStatsOverlay] +Class=ScreenStatsOverlay +Fallback=Screen +StatsX=SCREEN_RIGHT-8 +StatsY=SCREEN_TOP+10 +StatsOnCommand=horizalign,right;vertalign,top;zoom,0.6;shadowlength,2 + [WheelItemBase] TextOnCommand= TextX=0 diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index 2a3975d39c..7ae79b3b9a 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -60,6 +60,7 @@ ScreenPrompt.cpp ScreenPrompt.h ScreenRanking.cpp ScreenRanking.h \ ScreenReloadSongs.cpp ScreenReloadSongs.h \ ScreenSandbox.cpp ScreenSandbox.h \ ScreenSaveSync.cpp ScreenSaveSync.h \ +ScreenStatsOverlay.cpp ScreenStatsOverlay.h \ ScreenSelect.cpp ScreenSelect.h ScreenSelectCharacter.cpp ScreenSelectCharacter.h \ ScreenSelectDifficulty.cpp ScreenSelectDifficulty.h ScreenSelectGroup.cpp ScreenSelectGroup.h \ ScreenSelectMaster.cpp ScreenSelectMaster.h ScreenSelectMode.cpp ScreenSelectMode.h \ diff --git a/stepmania/src/ScreenStatsOverlay.cpp b/stepmania/src/ScreenStatsOverlay.cpp new file mode 100644 index 0000000000..945fb5965b --- /dev/null +++ b/stepmania/src/ScreenStatsOverlay.cpp @@ -0,0 +1,173 @@ +#include "global.h" +#include "ScreenStatsOverlay.h" +#include "ActorUtil.h" +#include "PrefsManager.h" +#include "RageDisplay.h" +#include "RageLog.h" +#include "ScreenDimensions.h" + +REGISTER_SCREEN_CLASS( ScreenStatsOverlay ); +ScreenStatsOverlay::ScreenStatsOverlay( const CString &sName ) : Screen(sName) +{ +} + +ScreenStatsOverlay::~ScreenStatsOverlay() +{ +} + +void ScreenStatsOverlay::Init() +{ + Screen::Init(); + + m_textStats.LoadFromFont( THEME->GetPathF(m_sName,"stats") ); + m_textStats.SetName( "Stats" ); + SET_XY_AND_ON_COMMAND( m_textStats ); + this->AddChild( &m_textStats ); + + /* "Was that a skip?" This displays a message when an update takes + * abnormally long, to quantify skips more precisely, verify them + * when they're subtle, and show the time it happened, so you can pinpoint + * the time in the log. */ + m_LastSkip = 0; + + const float SKIP_X = SCREEN_RIGHT - 100; + const float SKIP_Y = SCREEN_BOTTOM - 100; + const float SKIP_WIDTH = 190; + const float SKIP_SPACING_Y = 14; + + RectF rectSkips = RectF( + SKIP_X-SKIP_WIDTH/2, + SKIP_Y-(SKIP_SPACING_Y*NUM_SKIPS_TO_SHOW)/2 - 10, + SKIP_X+SKIP_WIDTH/2, + SKIP_Y+(SKIP_SPACING_Y*NUM_SKIPS_TO_SHOW)/2 + 10 + ); + m_quadSkipBackground.StretchTo( rectSkips ); + m_quadSkipBackground.SetDiffuse( RageColor(0,0,0,0.4f) ); + this->AddChild(&m_quadSkipBackground); + + for( int i=0; iGetPathF("Common","normal") ); + m_textSkips[i].SetX( SKIP_X ); + m_textSkips[i].SetY( + SCALE( i, 0, NUM_SKIPS_TO_SHOW-1, rectSkips.top + 10, rectSkips.bottom - 10 ) + ); + m_textSkips[i].SetZoom( 0.6f ); + m_textSkips[i].SetDiffuse( RageColor(1,1,1,0) ); + m_textSkips[i].SetShadowLength( 0 ); + this->AddChild( &m_textSkips[i] ); + } + + this->SubscribeToMessage( "ShowStatsChanged" ); +} + +void ScreenStatsOverlay::Update( float fDeltaTime ) +{ + Screen::Update(fDeltaTime); + + static bool bShowStatsWasOn = false; + + if( PREFSMAN->m_bShowStats && !bShowStatsWasOn ) + { + // Reset skip timer when we toggle Stats on so we don't show a large skip + // from the span when stats were turned off. + m_timerSkip.Touch(); + } + bShowStatsWasOn = PREFSMAN->m_bShowStats; + + this->SetVisible( PREFSMAN->m_bShowStats ); + if( PREFSMAN->m_bShowStats ) + { + m_textStats.SetText( DISPLAY->GetStats() ); + UpdateSkips(); + } +} + +void ScreenStatsOverlay::AddTimestampLine( const CString &txt, const RageColor &color ) +{ + m_textSkips[m_LastSkip].SetText( txt ); + m_textSkips[m_LastSkip].StopTweening(); + m_textSkips[m_LastSkip].SetDiffuse( RageColor(1,1,1,1) ); + m_textSkips[m_LastSkip].BeginTweening( 0.2f ); + m_textSkips[m_LastSkip].SetDiffuse( color ); + m_textSkips[m_LastSkip].BeginTweening( 3.0f ); + m_textSkips[m_LastSkip].BeginTweening( 0.2f ); + m_textSkips[m_LastSkip].SetDiffuse( RageColor(1,1,1,0) ); + + m_LastSkip++; + m_LastSkip %= NUM_SKIPS_TO_SHOW; +} + +void ScreenStatsOverlay::UpdateSkips() +{ + /* Use our own timer, so we ignore `/tab. */ + const float UpdateTime = m_timerSkip.GetDeltaTime(); + + /* FPS is 0 for a little while after we load a screen; don't report + * during this time. Do clear the timer, though, so we don't report + * a big "skip" after this period passes. */ + if( !DISPLAY->GetFPS() ) + return; + + /* We want to display skips. We expect to get updates of about 1.0/FPS ms. */ + const float ExpectedUpdate = 1.0f / DISPLAY->GetFPS(); + + /* These are thresholds for severity of skips. The smallest + * is slightly above expected, to tolerate normal jitter. */ + const float Thresholds[] = + { + ExpectedUpdate * 2.0f, ExpectedUpdate * 4.0f, 0.1f, -1 + }; + + int skip = 0; + while( Thresholds[skip] != -1 && UpdateTime > Thresholds[skip] ) + skip++; + + if( skip ) + { + CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast())); + + static const RageColor colors[] = + { + RageColor(0,0,0,0), /* unused */ + RageColor(1.0f,1.0f,1.0f,1), /* white*/ + RageColor(1.0f,1.0f,0.0f,1), /* yellow */ + RageColor(1.0f,0.4f,0.4f,1) /* light red */ + }; + + AddTimestampLine( ssprintf("%s: %.0fms (%.0f)", time.c_str(), 1000*UpdateTime, UpdateTime/ExpectedUpdate), colors[skip] ); + + if( PREFSMAN->m_bLogSkips ) + LOG->Trace( "Frame skip: %.0fms (%.0f)", 1000*UpdateTime, UpdateTime/ExpectedUpdate ); + } +} + + + +/* + * (c) 2001-2005 Chris Danford, Glenn Maynard + * 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. + */ diff --git a/stepmania/src/ScreenStatsOverlay.h b/stepmania/src/ScreenStatsOverlay.h new file mode 100644 index 0000000000..e22dbf39b6 --- /dev/null +++ b/stepmania/src/ScreenStatsOverlay.h @@ -0,0 +1,58 @@ +/* ScreenStatsOverlay - credits and statistics drawn on top of everything else. */ + +#ifndef ScreenStatsOverlay_H +#define ScreenStatsOverlay_H + +#include "Screen.h" +#include "BitmapText.h" +#include "Quad.h" + +const int NUM_SKIPS_TO_SHOW = 5; + +class ScreenStatsOverlay : public Screen +{ +public: + ScreenStatsOverlay( const CString &sName ); + virtual ~ScreenStatsOverlay(); + virtual void Init(); + + void Update( float fDeltaTime ); + +private: + void AddTimestampLine( const CString &txt, const RageColor &color ); + void UpdateSkips(); + + BitmapText m_textStats; + Quad m_quadSkipBackground; + BitmapText m_textSkips[NUM_SKIPS_TO_SHOW]; + RageTimer m_timerSkip; + int m_LastSkip; +}; + + +#endif + +/* + * (c) 2001-2005 Chris Danford, Glenn Maynard + * 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. + */ diff --git a/stepmania/src/ScreenSystemLayer.cpp b/stepmania/src/ScreenSystemLayer.cpp index 1fe7b45707..b37086ea61 100644 --- a/stepmania/src/ScreenSystemLayer.cpp +++ b/stepmania/src/ScreenSystemLayer.cpp @@ -46,42 +46,9 @@ void ScreenSystemLayer::Init() Screen::Init(); this->AddChild(&m_textMessage); - this->AddChild(&m_textStats); - this->AddChild(&m_textTime); FOREACH_PlayerNumber( p ) this->AddChild(&m_textCredits[p]); - - /* "Was that a skip?" This displays a message when an update takes - * abnormally long, to quantify skips more precisely, verify them - * when they're subtle, and show the time it happened, so you can pinpoint - * the time in the log. Put a dim quad behind it to make it easier to - * read. */ - m_LastSkip = 0; - const float SKIP_LEFT = 320.0f, SKIP_TOP = 60.0f, - SKIP_WIDTH = 160.0f, SKIP_Y_DIST = 16.0f; - - m_quadSkipBackground.StretchTo(RectF(SKIP_LEFT-8, SKIP_TOP-8, - SKIP_LEFT+SKIP_WIDTH, SKIP_TOP+SKIP_Y_DIST*NUM_SKIPS_TO_SHOW)); - m_quadSkipBackground.SetDiffuse( RageColor(0,0,0,0.4f) ); - m_quadSkipBackground.SetHidden( !PREFSMAN->m_bTimestamping ); - this->AddChild(&m_quadSkipBackground); - - for( int i=0; iGetPathF("Common","normal") ); - m_textSkips[i].SetXY( SKIP_LEFT, SKIP_TOP + SKIP_Y_DIST*i ); - m_textSkips[i].SetHorizAlign( Actor::align_left ); - m_textSkips[i].SetVertAlign( Actor::align_top ); - m_textSkips[i].SetZoom( 0.5f ); - m_textSkips[i].SetDiffuse( RageColor(1,1,1,0) ); - m_textSkips[i].SetShadowLength( 0 ); - this->AddChild(&m_textSkips[i]); - } - m_quadBrightnessAdd.StretchTo( RectF(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_quadBrightnessAdd.SetDiffuse( RageColor(1,1,1,PREFSMAN->m_fBrightnessAdd) ); m_quadBrightnessAdd.SetHidden( PREFSMAN->m_fBrightnessAdd == 0 ); @@ -110,14 +77,6 @@ void ScreenSystemLayer::ReloadCreditsText() SET_XY_AND_ON_COMMAND( m_textMessage ); m_textMessage.SetHidden( true ); - m_textStats.LoadFromFont( THEME->GetPathF(m_sName,"stats") ); - m_textStats.SetName( "Stats" ); - SET_XY_AND_ON_COMMAND( m_textStats ); - - m_textTime.LoadFromFont( THEME->GetPathF(m_sName,"time") ); - m_textTime.SetName( "Time" ); - m_textTime.SetHidden( !PREFSMAN->m_bTimestamping ); - SET_XY_AND_ON_COMMAND( m_textTime ); FOREACH_PlayerNumber( p ) { @@ -267,86 +226,9 @@ void ScreenSystemLayer::HandleMessage( const CString &sMessage ) Screen::HandleMessage( sMessage ); } -void ScreenSystemLayer::AddTimestampLine( const CString &txt, const RageColor &color ) -{ - m_textSkips[m_LastSkip].SetText( txt ); - m_textSkips[m_LastSkip].StopTweening(); - m_textSkips[m_LastSkip].SetDiffuse( RageColor(1,1,1,1) ); - m_textSkips[m_LastSkip].BeginTweening( 0.2f ); - m_textSkips[m_LastSkip].SetDiffuse( color ); - m_textSkips[m_LastSkip].BeginTweening( 3.0f ); - m_textSkips[m_LastSkip].BeginTweening( 0.2f ); - m_textSkips[m_LastSkip].SetDiffuse( RageColor(1,1,1,0) ); - - m_LastSkip++; - m_LastSkip %= NUM_SKIPS_TO_SHOW; -} - -void ScreenSystemLayer::UpdateSkips() -{ - if( !PREFSMAN->m_bTimestamping && !PREFSMAN->m_bLogSkips ) - return; - - /* Use our own timer, so we ignore `/tab. */ - const float UpdateTime = SkipTimer.GetDeltaTime(); - - /* FPS is 0 for a little while after we load a screen; don't report - * during this time. Do clear the timer, though, so we don't report - * a big "skip" after this period passes. */ - if( !DISPLAY->GetFPS() ) - return; - - /* We want to display skips. We expect to get updates of about 1.0/FPS ms. */ - const float ExpectedUpdate = 1.0f / DISPLAY->GetFPS(); - - /* These are thresholds for severity of skips. The smallest - * is slightly above expected, to tolerate normal jitter. */ - const float Thresholds[] = - { - ExpectedUpdate * 2.0f, ExpectedUpdate * 4.0f, 0.1f, -1 - }; - - int skip = 0; - while( Thresholds[skip] != -1 && UpdateTime > Thresholds[skip] ) - skip++; - - if( skip ) - { - CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast())); - - static const RageColor colors[] = - { - RageColor(0,0,0,0), /* unused */ - RageColor(0.2f,0.2f,1,1), /* light blue */ - RageColor(1,1,0,1), /* yellow */ - RageColor(1,0.2f,0.2f,1) /* light red */ - }; - - if( PREFSMAN->m_bTimestamping ) - AddTimestampLine( ssprintf("%s: %.0fms (%.0f)", time.c_str(), 1000*UpdateTime, UpdateTime/ExpectedUpdate), colors[skip] ); - if( PREFSMAN->m_bLogSkips ) - LOG->Trace( "Frame skip: %.0fms (%.0f)", 1000*UpdateTime, UpdateTime/ExpectedUpdate ); - } -} - void ScreenSystemLayer::Update( float fDeltaTime ) { Screen::Update(fDeltaTime); - - if( PREFSMAN && (bool)PREFSMAN->m_bShowStats ) - { - m_textStats.SetDiffuse( RageColor(1,1,1,0.7f) ); - m_textStats.SetText( DISPLAY->GetStats() ); - } - else - { - m_textStats.SetDiffuse( RageColor(1,1,1,0) ); /* hide */ - } - - UpdateSkips(); - - if( PREFSMAN->m_bTimestamping ) - m_textTime.SetText( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()) ); } /* diff --git a/stepmania/src/ScreenSystemLayer.h b/stepmania/src/ScreenSystemLayer.h index 60547e9a9e..e1946b1df3 100644 --- a/stepmania/src/ScreenSystemLayer.h +++ b/stepmania/src/ScreenSystemLayer.h @@ -9,8 +9,6 @@ #include "ThemeMetric.h" #include "AutoActor.h" -const int NUM_SKIPS_TO_SHOW = 5; - class ScreenSystemLayer : public Screen { public: @@ -23,19 +21,11 @@ public: void Update( float fDeltaTime ); private: - BitmapText m_textStats; AutoActor m_sprMessageFrame; BitmapText m_textMessage; BitmapText m_textCredits[NUM_PLAYERS]; - BitmapText m_textTime; - BitmapText m_textSkips[NUM_SKIPS_TO_SHOW]; - int m_LastSkip; - Quad m_quadSkipBackground; Quad m_quadBrightnessAdd; - RageTimer SkipTimer; - void AddTimestampLine( const CString &txt, const RageColor &color ); - void UpdateSkips(); CString GetCreditsMessage( PlayerNumber pn ) const; ThemeMetric CREDITS_PRESS_START; diff --git a/stepmania/src/StepMania-net2003.vcproj b/stepmania/src/StepMania-net2003.vcproj index 9770855bba..15cab812a2 100644 --- a/stepmania/src/StepMania-net2003.vcproj +++ b/stepmania/src/StepMania-net2003.vcproj @@ -639,6 +639,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 1bd3cf2a02..665deda09d 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -613,6 +613,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + +