From b9b07f994cbd9b76c90060ebc54c5dbc7546690a Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 26 May 2003 09:34:54 +0000 Subject: [PATCH] On first run, run a gameplay benchmark and adjusts graphic options automatically for 60 fps. --- stepmania/src/ScreenAutoGraphicDetail.cpp | 152 ++++++++++++++++++++++ stepmania/src/ScreenAutoGraphicDetail.h | 35 +++++ 2 files changed, 187 insertions(+) create mode 100644 stepmania/src/ScreenAutoGraphicDetail.cpp create mode 100644 stepmania/src/ScreenAutoGraphicDetail.h diff --git a/stepmania/src/ScreenAutoGraphicDetail.cpp b/stepmania/src/ScreenAutoGraphicDetail.cpp new file mode 100644 index 0000000000..1f7348ed2a --- /dev/null +++ b/stepmania/src/ScreenAutoGraphicDetail.cpp @@ -0,0 +1,152 @@ +#include "global.h" +/* +----------------------------------------------------------------------------- + Class: ScreenAutoGraphicDetail + + Desc: See header. + + Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "ScreenAutoGraphicDetail.h" +#include "ThemeManager.h" +#include "GameState.h" +#include "GameDef.h" +#include "RageLog.h" +#include "SongManager.h" +#include "NoteFieldPositioning.h" +#include "GameManager.h" +#include "PrefsManager.h" +#include "StepMania.h" +#include "ScreenManager.h" +#include "RageTimer.h" +#include "RageDisplay.h" + +#define SONG_BPM THEME->GetMetricF("ScreenAutoGraphicDetail","SongBPM") +#define SECONDS_TO_SHOW THEME->GetMetricF("ScreenAutoGraphicDetail","SecondsToShow") + +enum Detail { low, medium, high, NUM_DETAIL_SETTINGS }; +struct DetailSettings +{ + int width, height, displaybpp, texturebpp; +}; +const DetailSettings g_DetailSettings[NUM_DETAIL_SETTINGS] = { + { 320, 240, 16, 16 }, + { 640, 480, 16, 16 }, + { 640, 480, 32, 32 }, +}; + +void ApplyDetailSetting( Detail detail ) +{ + PREFSMAN->m_bVsync = false; // TODO: preserve vsync pref + PREFSMAN->m_iDisplayWidth = g_DetailSettings[detail].width; + PREFSMAN->m_iDisplayHeight = g_DetailSettings[detail].height; + PREFSMAN->m_iDisplayColorDepth = g_DetailSettings[detail].displaybpp; + PREFSMAN->m_iTextureColorDepth = g_DetailSettings[detail].texturebpp; + + ApplyGraphicOptions(); +} + +ScreenAutoGraphicDetail::ScreenAutoGraphicDetail() : Screen("ScreenAutoGraphicDetail") +{ + ApplyDetailSetting( medium ); + + m_Background.LoadFromAniDir( THEME->GetPathToB("ScreenAutoGraphicDetail background") ); + this->AddChild( &m_Background ); + + GAMESTATE->m_CurStyle = STYLE_DANCE_VERSUS; + NotesType nt = GAMESTATE->GetCurrentStyleDef()->m_NotesType; + int iNumOfTracks = GAMEMAN->NotesTypeToNumTracks( nt ); + + ASSERT(iNumOfTracks > 0); // crazy to have less than 1 track.... + + NoteData* pND = new NoteData; + pND->SetNumTracks( iNumOfTracks ); + + float fSongBPM = SONG_BPM; + float fSongBPS = fSongBPM / 60.f; + int iBeatsToPlay = fSongBPS * SECONDS_TO_SHOW; + + for( int i=0; iAddHoldNote( HoldNote(iTrack, fBeat, fBeat+1) ); + else + { + pND->SetTapNote( iTrack, BeatToNoteRow(fBeat), TAP_TAP ); + pND->SetTapNote( iTrack, BeatToNoteRow(fBeat+0.5f), TAP_TAP ); + } + } + + m_pSong = new Song; + m_pSong->AddBPMSegment( BPMSegment(0,fSongBPM) ); + + GAMESTATE->m_pCurSong = m_pSong; + GAMESTATE->m_bPastHereWeGo = true; + + for( int p=0; pIsPlayerEnabled(p) ) + continue; // skip + + GAMESTATE->m_PlayerController[p] = PC_AUTOPLAY; + m_Player[p].Load( (PlayerNumber)p, pND, NULL, NULL, NULL, NULL ); + m_Player[p].SetX( GAMESTATE->GetCurrentStyleDef()->m_iCenterX[p] ); + this->AddChild( &m_Player[p] ); + } + + delete pND; + + + m_Overlay.LoadFromAniDir( THEME->GetPathToB("ScreenAutoGraphicDetail overlay") ); + this->AddChild( &m_Overlay ); + + m_textMessage.LoadFromFont( THEME->GetPathToF("Common normal") ); + m_textMessage.SetXY( CENTER_X, CENTER_Y ); + this->AddChild( &m_textMessage ); + + m_fFakeSecondsIntoSong = 0; + this->ClearMessageQueue(); + this->PostScreenMessage( SM_BeginFadingOut, SECONDS_TO_SHOW ); +} + +ScreenAutoGraphicDetail::~ScreenAutoGraphicDetail() +{ + delete m_pSong; +} + +void ScreenAutoGraphicDetail::Update( float fDelta ) +{ + m_fFakeSecondsIntoSong += fDelta; + GAMESTATE->UpdateSongPosition( m_fFakeSecondsIntoSong ); + + int iThisSecond = (int)RageTimer::GetTimeSinceStart(); + int iLastSecond = (int)(RageTimer::GetTimeSinceStart()-fDelta); + if( iThisSecond != iLastSecond ) + m_textMessage.SetText( ssprintf("Analyzing peformance... (FPS: %d)", DISPLAY->GetCumFPS()) ); + + Screen::Update( fDelta ); +} + +void ScreenAutoGraphicDetail::HandleScreenMessage( const ScreenMessage SM ) +{ + switch( SM ) + { + case SM_BeginFadingOut: + int cumFPS = DISPLAY->GetCumFPS(); + if( cumFPS > 120 ) + ApplyDetailSetting( high ); + else if( cumFPS < 60 ) + ApplyDetailSetting( low ); + else + ApplyDetailSetting( medium ); + GAMESTATE->m_pCurSong = NULL; + SCREENMAN->SetNewScreen( THEME->GetMetric("Common","InitialScreen") ); + break; + } +} diff --git a/stepmania/src/ScreenAutoGraphicDetail.h b/stepmania/src/ScreenAutoGraphicDetail.h new file mode 100644 index 0000000000..39240edc6c --- /dev/null +++ b/stepmania/src/ScreenAutoGraphicDetail.h @@ -0,0 +1,35 @@ +/* +----------------------------------------------------------------------------- + Class: ScreenAutoGraphicDetail + + Desc: Base class for all attraction screens. + + Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "Screen.h" +#include "Player.h" + +class ScreenAutoGraphicDetail : public Screen +{ +public: + ScreenAutoGraphicDetail(); + ~ScreenAutoGraphicDetail(); + + virtual void Update( float fDelta ); + virtual void HandleScreenMessage( const ScreenMessage SM ); + +protected: + BGAnimation m_Background; + Player m_Player[NUM_PLAYERS]; + BGAnimation m_Overlay; + BitmapText m_textMessage; + + Song* m_pSong; + float m_fFakeSecondsIntoSong; +}; + + +