2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
2002-08-13 23:26:46 +00:00
|
|
|
Class: ScreenManager
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
Desc: See header.
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2003-03-15 00:02:54 +00:00
|
|
|
Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved.
|
2002-08-13 23:26:46 +00:00
|
|
|
Chris Danford
|
2003-02-19 23:53:19 +00:00
|
|
|
Tim Hentenaar
|
2003-03-15 00:02:54 +00:00
|
|
|
Glenn Maynard
|
2002-05-20 08:59:37 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "GameConstantsAndTypes.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
#include "RageLog.h"
|
2002-08-13 23:26:46 +00:00
|
|
|
#include "GameState.h"
|
2002-08-27 03:59:22 +00:00
|
|
|
#include "RageException.h"
|
2002-10-24 07:11:21 +00:00
|
|
|
#include "RageTimer.h"
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "ThemeManager.h"
|
2002-12-30 00:13:47 +00:00
|
|
|
#include "RageDisplay.h"
|
2003-02-22 01:58:56 +00:00
|
|
|
#include "Screen.h"
|
2003-03-03 10:03:02 +00:00
|
|
|
#include "SongManager.h"
|
2003-03-28 00:49:01 +00:00
|
|
|
#include "BitmapText.h"
|
|
|
|
|
#include "Quad.h"
|
2003-04-18 23:55:20 +00:00
|
|
|
#include "RageTextureManager.h"
|
2003-09-08 07:21:41 +00:00
|
|
|
#include "ProfileManager.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
ScreenManager* SCREENMAN = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
|
|
|
|
|
2003-05-05 05:00:40 +00:00
|
|
|
#define STATS_X THEME->GetMetricF("ScreenSystemLayer","StatsX")
|
|
|
|
|
#define STATS_Y THEME->GetMetricF("ScreenSystemLayer","StatsY")
|
|
|
|
|
#define CREDITS_X( p ) THEME->GetMetricF("ScreenSystemLayer",ssprintf("CreditsP%dX",p+1))
|
|
|
|
|
#define CREDITS_Y( p ) THEME->GetMetricF("ScreenSystemLayer",ssprintf("CreditsP%dY",p+1))
|
|
|
|
|
#define CREDITS_COLOR THEME->GetMetricC("ScreenSystemLayer","CreditsColor")
|
|
|
|
|
#define CREDITS_SHADOW_LENGTH THEME->GetMetricF("ScreenSystemLayer","CreditsShadowLength")
|
|
|
|
|
#define CREDITS_ZOOM THEME->GetMetricF("ScreenSystemLayer","CreditsZoom")
|
|
|
|
|
#define CREDITS_TEXT_HOME_JOIN THEME->GetMetric ("ScreenSystemLayer","CreditsTextHomeJoin")
|
|
|
|
|
#define CREDITS_TEXT_HOME_JOINED THEME->GetMetric ("ScreenSystemLayer","CreditsTextHomeJoined")
|
|
|
|
|
#define CREDITS_TEXT_HOME_TOO_LATE THEME->GetMetric ("ScreenSystemLayer","CreditsTextHomeTooLate")
|
|
|
|
|
#define CREDITS_TEXT_PAY THEME->GetMetric ("ScreenSystemLayer","CreditsTextPay")
|
|
|
|
|
#define CREDITS_TEXT_FREE THEME->GetMetric ("ScreenSystemLayer","CreditsTextFree")
|
2002-08-13 23:26:46 +00:00
|
|
|
|
2003-03-15 02:44:54 +00:00
|
|
|
const int NUM_SKIPS = 5;
|
|
|
|
|
|
2003-03-15 00:02:54 +00:00
|
|
|
/* This screen is drawn on top of everything else, and receives updates,
|
|
|
|
|
* but not input. */
|
|
|
|
|
class ScreenSystemLayer: public Screen
|
|
|
|
|
{
|
|
|
|
|
BitmapText m_textStats;
|
|
|
|
|
BitmapText m_textSystemMessage;
|
|
|
|
|
BitmapText m_textCreditInfo[NUM_PLAYERS];
|
|
|
|
|
BitmapText m_textSysTime;
|
2003-03-15 02:44:54 +00:00
|
|
|
BitmapText m_Skips[NUM_SKIPS];
|
|
|
|
|
int m_LastSkip;
|
|
|
|
|
Quad m_SkipBackground;
|
|
|
|
|
|
|
|
|
|
RageTimer SkipTimer;
|
|
|
|
|
void UpdateTimestampAndSkips();
|
2003-03-15 00:02:54 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ScreenSystemLayer();
|
|
|
|
|
void SystemMessage( CString sMessage );
|
|
|
|
|
void RefreshCreditsMessages();
|
|
|
|
|
void Update( float fDeltaTime );
|
|
|
|
|
};
|
|
|
|
|
|
2003-04-12 06:16:12 +00:00
|
|
|
ScreenSystemLayer::ScreenSystemLayer() : Screen("ScreenSystemLayer")
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2003-04-12 17:39:27 +00:00
|
|
|
m_textSystemMessage.LoadFromFont( THEME->GetPathToF("Common normal") );
|
2002-05-20 08:59:37 +00:00
|
|
|
m_textSystemMessage.SetHorizAlign( Actor::align_left );
|
2002-08-23 20:18:29 +00:00
|
|
|
m_textSystemMessage.SetVertAlign( Actor::align_top );
|
|
|
|
|
m_textSystemMessage.SetXY( 4.0f, 4.0f );
|
2003-03-09 00:55:49 +00:00
|
|
|
m_textSystemMessage.SetZoom( 0.8f );
|
|
|
|
|
m_textSystemMessage.SetShadowLength( 2 );
|
2002-10-28 05:30:45 +00:00
|
|
|
m_textSystemMessage.SetDiffuse( RageColor(1,1,1,0) );
|
2003-03-15 00:02:54 +00:00
|
|
|
this->AddChild(&m_textSystemMessage);
|
|
|
|
|
|
2003-04-12 17:39:27 +00:00
|
|
|
m_textStats.LoadFromFont( THEME->GetPathToF("Common normal") );
|
2003-03-15 00:02:54 +00:00
|
|
|
m_textStats.SetXY( STATS_X, STATS_Y );
|
|
|
|
|
m_textStats.SetHorizAlign( Actor::align_right );
|
|
|
|
|
m_textStats.SetVertAlign( Actor::align_top );
|
|
|
|
|
m_textStats.SetZoom( 0.5f );
|
|
|
|
|
m_textStats.SetShadowLength( 2 );
|
|
|
|
|
this->AddChild(&m_textStats);
|
2003-03-07 04:48:13 +00:00
|
|
|
|
2003-04-12 17:39:27 +00:00
|
|
|
m_textSysTime.LoadFromFont( THEME->GetPathToF("Common normal") );
|
2003-03-07 04:48:13 +00:00
|
|
|
m_textSysTime.SetXY( 4.0f, 40.0f );
|
|
|
|
|
m_textSysTime.SetHorizAlign( Actor::align_left );
|
|
|
|
|
m_textSysTime.SetVertAlign( Actor::align_top );
|
|
|
|
|
m_textSysTime.SetZoom( 0.5f );
|
|
|
|
|
m_textSysTime.SetDiffuse( RageColor(1,0,1,1) );
|
|
|
|
|
m_textSysTime.EnableShadow(false);
|
2003-03-15 00:02:54 +00:00
|
|
|
this->AddChild(&m_textSysTime);
|
|
|
|
|
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
{
|
|
|
|
|
this->AddChild(&m_textCreditInfo[p]);
|
|
|
|
|
}
|
2003-03-15 02:44:54 +00:00
|
|
|
|
|
|
|
|
/* "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_SkipBackground.StretchTo(RectF(SKIP_LEFT-8, SKIP_TOP-8,
|
|
|
|
|
SKIP_LEFT+SKIP_WIDTH, SKIP_TOP+SKIP_Y_DIST*NUM_SKIPS));
|
|
|
|
|
m_SkipBackground.SetDiffuse( RageColor(0,0,0,0) );
|
|
|
|
|
this->AddChild(&m_SkipBackground);
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<NUM_SKIPS; i++ )
|
|
|
|
|
{
|
|
|
|
|
/* This is somewhat big. Let's put it on the right side, where it'll
|
|
|
|
|
* obscure the 2P side during gameplay; there's nowhere to put it that
|
|
|
|
|
* doesn't obscure something, and it's just a diagnostic. */
|
2003-04-12 17:39:27 +00:00
|
|
|
m_Skips[i].LoadFromFont( THEME->GetPathToF("Common normal") );
|
2003-03-15 02:44:54 +00:00
|
|
|
m_Skips[i].SetXY( SKIP_LEFT, SKIP_TOP + SKIP_Y_DIST*i );
|
|
|
|
|
m_Skips[i].SetHorizAlign( Actor::align_left );
|
|
|
|
|
m_Skips[i].SetVertAlign( Actor::align_top );
|
|
|
|
|
m_Skips[i].SetZoom( 0.5f );
|
|
|
|
|
m_Skips[i].SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
m_Skips[i].EnableShadow(false);
|
|
|
|
|
this->AddChild(&m_Skips[i]);
|
|
|
|
|
}
|
2003-03-15 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSystemLayer::SystemMessage( CString sMessage )
|
|
|
|
|
{
|
|
|
|
|
m_textSystemMessage.StopTweening();
|
|
|
|
|
m_textSystemMessage.SetText( sMessage );
|
|
|
|
|
m_textSystemMessage.SetDiffuse( RageColor(1,1,1,1) );
|
|
|
|
|
m_textSystemMessage.SetX( -640 );
|
2003-05-26 09:18:44 +00:00
|
|
|
m_textSystemMessage.BeginTweening( 0.5f );
|
2003-03-15 00:02:54 +00:00
|
|
|
m_textSystemMessage.SetX( 4 );
|
|
|
|
|
m_textSystemMessage.BeginTweening( 5 );
|
2003-05-26 09:18:44 +00:00
|
|
|
m_textSystemMessage.BeginTweening( 0.5f );
|
2003-03-15 00:02:54 +00:00
|
|
|
m_textSystemMessage.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSystemLayer::RefreshCreditsMessages()
|
|
|
|
|
{
|
|
|
|
|
// update joined
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
{
|
2003-05-05 05:18:37 +00:00
|
|
|
m_textCreditInfo[p].LoadFromFont( THEME->GetPathToF("ScreenManager credits") );
|
|
|
|
|
m_textCreditInfo[p].SetXY( CREDITS_X(p), CREDITS_Y(p) );
|
|
|
|
|
m_textCreditInfo[p].SetZoom( CREDITS_ZOOM );
|
|
|
|
|
m_textCreditInfo[p].SetDiffuse( CREDITS_COLOR );
|
|
|
|
|
m_textCreditInfo[p].SetShadowLength( CREDITS_SHADOW_LENGTH );
|
|
|
|
|
|
2003-04-19 19:05:25 +00:00
|
|
|
CString sText;
|
2003-04-13 04:50:08 +00:00
|
|
|
switch( PREFSMAN->m_iCoinMode )
|
2003-03-15 00:02:54 +00:00
|
|
|
{
|
2003-04-13 04:50:08 +00:00
|
|
|
case COIN_HOME:
|
2003-03-15 00:02:54 +00:00
|
|
|
if( GAMESTATE->m_bSideIsJoined[p] )
|
2003-05-05 05:00:40 +00:00
|
|
|
sText = CREDITS_TEXT_HOME_JOINED;
|
2003-03-15 00:02:54 +00:00
|
|
|
else if( GAMESTATE->m_bPlayersCanJoin ) // would (GAMESTATE->m_CurStyle!=STYLE_INVALID) do the same thing?
|
2003-05-05 05:00:40 +00:00
|
|
|
sText = CREDITS_TEXT_HOME_JOIN;
|
2003-03-15 00:02:54 +00:00
|
|
|
else
|
2003-05-05 05:00:40 +00:00
|
|
|
sText = CREDITS_TEXT_HOME_TOO_LATE;
|
2003-03-15 00:02:54 +00:00
|
|
|
break;
|
2003-04-13 04:50:08 +00:00
|
|
|
case COIN_PAY:
|
2003-03-15 00:02:54 +00:00
|
|
|
{
|
|
|
|
|
int Coins = GAMESTATE->m_iCoins % PREFSMAN->m_iCoinsPerCredit;
|
2003-05-05 05:00:40 +00:00
|
|
|
CString txt = ssprintf("%s %d", CREDITS_TEXT_PAY.c_str(), GAMESTATE->m_iCoins / PREFSMAN->m_iCoinsPerCredit);
|
2003-03-15 00:02:54 +00:00
|
|
|
if (Coins)
|
|
|
|
|
txt += ssprintf(" %d/%d", Coins, PREFSMAN->m_iCoinsPerCredit );
|
2003-04-19 19:05:25 +00:00
|
|
|
sText = txt;
|
2003-03-15 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2003-04-13 04:50:08 +00:00
|
|
|
case COIN_FREE:
|
2003-05-05 05:00:40 +00:00
|
|
|
sText = CREDITS_TEXT_FREE;
|
2003-04-13 04:50:08 +00:00
|
|
|
break;
|
2003-03-15 00:02:54 +00:00
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
2003-04-19 19:05:25 +00:00
|
|
|
|
2003-11-01 19:36:52 +00:00
|
|
|
Profile* pProfile = PROFILEMAN->GetProfile( (PlayerNumber)p );
|
|
|
|
|
if( pProfile )
|
|
|
|
|
sText += " " + pProfile->m_sName;
|
|
|
|
|
|
2003-04-19 19:05:25 +00:00
|
|
|
m_textCreditInfo[p].SetText( sText );
|
2003-03-15 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-15 02:44:54 +00:00
|
|
|
void ScreenSystemLayer::UpdateTimestampAndSkips()
|
|
|
|
|
{
|
|
|
|
|
if(!PREFSMAN->m_bTimestamping)
|
|
|
|
|
{
|
|
|
|
|
/* Hide: */
|
|
|
|
|
m_textSysTime.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
m_SkipBackground.SetDiffuse( RageColor(0,0,0,0) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_SkipBackground.SetDiffuse(RageColor(0,0,0,0.4f));
|
|
|
|
|
|
|
|
|
|
CString time(SecondsToTime(RageTimer::GetTimeSinceStart()));
|
|
|
|
|
|
|
|
|
|
/* 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())
|
|
|
|
|
{
|
|
|
|
|
/* 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)
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
};
|
|
|
|
|
m_Skips[m_LastSkip].SetText(ssprintf("%s: %.0fms (%.0f)",
|
2003-04-25 00:01:35 +00:00
|
|
|
time.c_str(), 1000*UpdateTime, UpdateTime/ExpectedUpdate));
|
2003-03-15 02:44:54 +00:00
|
|
|
m_Skips[m_LastSkip].StopTweening();
|
|
|
|
|
m_Skips[m_LastSkip].SetDiffuse(RageColor(1,1,1,1));
|
|
|
|
|
m_Skips[m_LastSkip].BeginTweening(0.2f);
|
|
|
|
|
m_Skips[m_LastSkip].SetDiffuse(colors[skip]);
|
|
|
|
|
m_Skips[m_LastSkip].BeginTweening(3.0f);
|
|
|
|
|
m_Skips[m_LastSkip].BeginTweening(0.2f);
|
|
|
|
|
m_Skips[m_LastSkip].SetDiffuse(RageColor(1,1,1,0));
|
|
|
|
|
|
|
|
|
|
m_LastSkip++;
|
|
|
|
|
m_LastSkip %= NUM_SKIPS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_textSysTime.SetText( time );
|
|
|
|
|
m_textSysTime.SetDiffuse( RageColor(1,0,1,1) );
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-15 00:02:54 +00:00
|
|
|
void ScreenSystemLayer::Update( float fDeltaTime )
|
|
|
|
|
{
|
|
|
|
|
Screen::Update(fDeltaTime);
|
|
|
|
|
|
|
|
|
|
if( PREFSMAN && PREFSMAN->m_bShowStats )
|
|
|
|
|
{
|
2003-05-24 05:44:31 +00:00
|
|
|
m_textStats.SetDiffuse( RageColor(1,1,1,0.7f) );
|
2003-03-15 00:02:54 +00:00
|
|
|
|
|
|
|
|
/* If FPS == 0, we don't have stats yet. */
|
|
|
|
|
if(DISPLAY->GetFPS())
|
|
|
|
|
m_textStats.SetText( ssprintf(
|
|
|
|
|
"%i FPS\n%i av FPS\n%i VPF",
|
|
|
|
|
DISPLAY->GetFPS(), DISPLAY->GetCumFPS(),
|
|
|
|
|
DISPLAY->GetVPF()) );
|
|
|
|
|
else
|
|
|
|
|
m_textStats.SetText( "-- FPS\n-- av FPS\n-- VPF" );
|
|
|
|
|
} else
|
|
|
|
|
m_textStats.SetDiffuse( RageColor(1,1,1,0) ); /* hide */
|
|
|
|
|
|
2003-03-15 02:44:54 +00:00
|
|
|
UpdateTimestampAndSkips();
|
2003-03-15 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScreenManager::ScreenManager()
|
|
|
|
|
{
|
|
|
|
|
m_SystemLayer = new ScreenSystemLayer;
|
|
|
|
|
|
|
|
|
|
m_ScreenBuffered = NULL;
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScreenManager::~ScreenManager()
|
|
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "ScreenManager::~ScreenManager()" );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-23 06:50:48 +00:00
|
|
|
EmptyDeleteQueue();
|
|
|
|
|
|
2003-03-09 00:55:49 +00:00
|
|
|
// delete current Screens
|
2002-10-31 02:20:11 +00:00
|
|
|
for( unsigned i=0; i<m_ScreenStack.size(); i++ )
|
2003-03-15 00:02:54 +00:00
|
|
|
delete m_ScreenStack[i];
|
|
|
|
|
delete m_ScreenBuffered;
|
|
|
|
|
delete m_SystemLayer;
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-23 06:50:48 +00:00
|
|
|
void ScreenManager::EmptyDeleteQueue()
|
|
|
|
|
{
|
2003-04-24 19:42:06 +00:00
|
|
|
if(!m_ScreensToDelete.size())
|
|
|
|
|
return;
|
|
|
|
|
|
2002-08-23 06:50:48 +00:00
|
|
|
// delete all ScreensToDelete
|
2002-10-31 02:20:11 +00:00
|
|
|
for( unsigned i=0; i<m_ScreensToDelete.size(); i++ )
|
2002-08-23 06:50:48 +00:00
|
|
|
SAFE_DELETE( m_ScreensToDelete[i] );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-10-24 20:15:24 +00:00
|
|
|
m_ScreensToDelete.clear();
|
2003-04-24 19:26:06 +00:00
|
|
|
|
2003-04-24 19:42:06 +00:00
|
|
|
/* Now that we've actually deleted a screen, it makes sense to clear out
|
2003-04-24 19:26:06 +00:00
|
|
|
* cached textures. */
|
|
|
|
|
TEXTUREMAN->DeleteCachedTextures();
|
2003-04-24 19:51:27 +00:00
|
|
|
TEXTUREMAN->DiagnosticOutput();
|
2002-08-23 06:50:48 +00:00
|
|
|
}
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2003-03-17 01:12:58 +00:00
|
|
|
/* XXX: Big hack:
|
|
|
|
|
* All screens must receive at least one update before they draw.
|
|
|
|
|
* However, no screen should ever receive an update until it's ready
|
|
|
|
|
* to be drawn; otherwise Gameplay will queue music to start even though
|
|
|
|
|
* Stage might still be delaying for a while, throwing off timing.
|
|
|
|
|
*
|
|
|
|
|
* This is tricky with prepped screens. We can't do an Update(0) in
|
|
|
|
|
* LoadPreppedScreen, since that'll cause the delete queue to be cleared
|
|
|
|
|
* while the screen is on the stack, and possibly other odd things.
|
|
|
|
|
* So, update before we draw, which is also a hack (rendering shouldn't
|
|
|
|
|
* change state!). Only do this when we have to, so we don't double
|
|
|
|
|
* the number of updates. */
|
|
|
|
|
static bool g_TopNeedsNeedsNullUpdate = false;
|
2003-04-25 03:41:38 +00:00
|
|
|
static bool g_SkipRendering = false;
|
2003-03-17 01:12:58 +00:00
|
|
|
|
2002-05-20 08:59:37 +00:00
|
|
|
void ScreenManager::Update( float fDeltaTime )
|
|
|
|
|
{
|
2003-01-19 21:51:46 +00:00
|
|
|
// Only update the topmost screen on the stack.
|
|
|
|
|
|
|
|
|
|
/* Screens take some time to load. If we don't do this, then screens
|
|
|
|
|
* receive an initial update that includes all of the time they spent
|
|
|
|
|
* loading, which will chop off their tweens.
|
|
|
|
|
*
|
|
|
|
|
* We don't want to simply cap update times; for example, the stage
|
|
|
|
|
* screen sets a 4 second timer, preps the gameplay screen, and then
|
|
|
|
|
* displays the prepped screen after the timer runs out; this lets the
|
|
|
|
|
* load time be masked (as long as the load takes less than 4 seconds).
|
|
|
|
|
* If we cap that large update delta from the screen load, the update
|
|
|
|
|
* to load the new screen will come after 4 seconds plus the load time.
|
|
|
|
|
*
|
2003-04-25 03:41:38 +00:00
|
|
|
* So, let's just zero the first update for every screen.
|
|
|
|
|
*
|
|
|
|
|
* XXX: If a new Screen is set during this Update, that new screen is Drawn
|
2003-09-15 05:27:34 +00:00
|
|
|
* before its first Update.
|
2003-01-19 21:51:46 +00:00
|
|
|
*/
|
2003-04-25 03:41:38 +00:00
|
|
|
ASSERT( !m_ScreenStack.empty() || m_DelayedScreen != "" ); // Why play the game if there is nothing showing?
|
|
|
|
|
|
|
|
|
|
if( !m_ScreenStack.empty() )
|
|
|
|
|
{
|
|
|
|
|
Screen* pScreen = m_ScreenStack[m_ScreenStack.size()-1];
|
|
|
|
|
if( pScreen->IsFirstUpdate() )
|
|
|
|
|
pScreen->Update( 0 );
|
|
|
|
|
else
|
|
|
|
|
pScreen->Update( fDeltaTime );
|
|
|
|
|
}
|
2003-03-15 00:02:54 +00:00
|
|
|
|
|
|
|
|
m_SystemLayer->Update( fDeltaTime );
|
2003-04-03 22:34:22 +00:00
|
|
|
|
|
|
|
|
EmptyDeleteQueue();
|
2003-04-25 03:41:38 +00:00
|
|
|
|
|
|
|
|
if(m_DelayedScreen.size() != 0)
|
|
|
|
|
{
|
|
|
|
|
/* We have a screen to display. Delete the current screens and load it. */
|
|
|
|
|
m_ScreensToDelete.insert(m_ScreensToDelete.end(), m_ScreenStack.begin(), m_ScreenStack.end());
|
|
|
|
|
m_ScreenStack.clear();
|
|
|
|
|
EmptyDeleteQueue();
|
2003-04-25 04:16:34 +00:00
|
|
|
|
|
|
|
|
/* This is the purpose of delayed screen loads: clear out the texture cache
|
|
|
|
|
* now, while there's (mostly) nothing loaded. */
|
|
|
|
|
TEXTUREMAN->DeleteCachedTextures();
|
|
|
|
|
TEXTUREMAN->DiagnosticOutput();
|
|
|
|
|
|
2003-04-25 03:41:38 +00:00
|
|
|
LoadDelayedScreen();
|
|
|
|
|
|
|
|
|
|
/* Ack. We can't Update(0), since we want to skip the *next* update
|
|
|
|
|
* (which is the one that will have all this load time in it). We
|
|
|
|
|
* can't draw it until we've updated it. Let's simply not render
|
|
|
|
|
* the next frame, so we'll come around quickly and handle it correctly. */
|
|
|
|
|
g_SkipRendering = true;
|
|
|
|
|
}
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Draw()
|
|
|
|
|
{
|
2003-05-24 05:44:31 +00:00
|
|
|
DISPLAY->BeginFrame();
|
2003-04-25 03:41:38 +00:00
|
|
|
|
|
|
|
|
if(g_SkipRendering)
|
|
|
|
|
{
|
|
|
|
|
/* Leave the frame there (if any). */
|
|
|
|
|
g_SkipRendering = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-17 01:12:58 +00:00
|
|
|
if(g_TopNeedsNeedsNullUpdate)
|
|
|
|
|
{
|
|
|
|
|
g_TopNeedsNeedsNullUpdate = false;
|
|
|
|
|
m_ScreenStack.back()->Update( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-20 21:22:18 +00:00
|
|
|
if( !m_ScreenStack.empty() && !m_ScreenStack.back()->IsTransparent() ) // top screen isn't transparent
|
|
|
|
|
m_ScreenStack.back()->Draw();
|
|
|
|
|
else
|
|
|
|
|
for( unsigned i=0; i<m_ScreenStack.size(); i++ ) // Draw all screens bottom to top
|
|
|
|
|
m_ScreenStack[i]->Draw();
|
2003-03-15 00:02:54 +00:00
|
|
|
m_SystemLayer->Draw();
|
2003-04-25 03:41:38 +00:00
|
|
|
|
2003-05-24 05:44:31 +00:00
|
|
|
DISPLAY->EndFrame();
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
|
|
|
|
{
|
2002-09-06 00:31:25 +00:00
|
|
|
// LOG->Trace( "ScreenManager::Input( %d-%d, %d-%d, %d-%d, %d-%d )",
|
|
|
|
|
// DeviceI.device, DeviceI.button, GameI.controller, GameI.button, MenuI.player, MenuI.button, StyleI.player, StyleI.col );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
// pass input only to topmost state
|
2002-10-31 02:20:11 +00:00
|
|
|
if( !m_ScreenStack.empty() )
|
|
|
|
|
m_ScreenStack.back()->Input( DeviceI, type, GameI, MenuI, StyleI );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-27 03:59:22 +00:00
|
|
|
|
2002-09-03 05:43:58 +00:00
|
|
|
Screen* ScreenManager::MakeNewScreen( CString sClassName )
|
|
|
|
|
{
|
2003-03-03 10:03:02 +00:00
|
|
|
Screen *ret = Screen::Create( sClassName );
|
2002-12-21 07:54:24 +00:00
|
|
|
|
2002-12-29 23:37:41 +00:00
|
|
|
/* Loading probably took a little while. Let's reset stats. This prevents us
|
2002-12-21 07:54:24 +00:00
|
|
|
* from displaying an unnaturally low FPS value, and the next FPS value we
|
|
|
|
|
* display will be accurate, which makes skips in the initial tween-ins more
|
|
|
|
|
* apparent. */
|
|
|
|
|
DISPLAY->ResetStats();
|
|
|
|
|
|
2002-12-21 18:23:37 +00:00
|
|
|
/* This is a convenient time to clean up our song cache. */
|
2003-08-06 05:28:58 +00:00
|
|
|
SONGMAN->CompressSongs();
|
2002-12-21 18:23:37 +00:00
|
|
|
|
2002-12-21 07:54:24 +00:00
|
|
|
return ret;
|
2002-09-03 05:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
2002-09-04 00:25:30 +00:00
|
|
|
void ScreenManager::PrepNewScreen( CString sClassName )
|
|
|
|
|
{
|
2002-09-04 23:40:01 +00:00
|
|
|
ASSERT(m_ScreenBuffered == NULL);
|
|
|
|
|
m_ScreenBuffered = MakeNewScreen(sClassName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::LoadPreppedScreen()
|
|
|
|
|
{
|
|
|
|
|
ASSERT( m_ScreenBuffered != NULL);
|
|
|
|
|
SetNewScreen( m_ScreenBuffered );
|
2003-03-12 01:26:44 +00:00
|
|
|
|
|
|
|
|
// Need to update the new screen once, or else it will be
|
|
|
|
|
// drawn before ever being Update()d.
|
2003-03-17 01:12:58 +00:00
|
|
|
g_TopNeedsNeedsNullUpdate = true;
|
2003-03-12 01:26:44 +00:00
|
|
|
|
2002-09-04 23:40:01 +00:00
|
|
|
m_ScreenBuffered = NULL;
|
2002-09-04 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-10 02:29:01 +00:00
|
|
|
void ScreenManager::DeletePreppedScreen()
|
|
|
|
|
{
|
|
|
|
|
SAFE_DELETE( m_ScreenBuffered );
|
2003-04-24 19:26:06 +00:00
|
|
|
TEXTUREMAN->DeleteCachedTextures();
|
2003-03-10 02:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
2002-09-04 00:25:30 +00:00
|
|
|
void ScreenManager::SetNewScreen( Screen *pNewScreen )
|
|
|
|
|
{
|
|
|
|
|
RefreshCreditsMessages();
|
2002-09-23 07:35:47 +00:00
|
|
|
|
2002-10-24 19:55:09 +00:00
|
|
|
// move current screen(s) to ScreenToDelete
|
|
|
|
|
m_ScreensToDelete.insert(m_ScreensToDelete.end(), m_ScreenStack.begin(), m_ScreenStack.end());
|
2002-10-24 20:15:24 +00:00
|
|
|
m_ScreenStack.clear();
|
2003-04-25 03:41:38 +00:00
|
|
|
|
2002-10-31 04:23:39 +00:00
|
|
|
m_ScreenStack.push_back( pNewScreen );
|
2002-09-04 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-27 03:59:22 +00:00
|
|
|
void ScreenManager::SetNewScreen( CString sClassName )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2003-04-25 03:41:38 +00:00
|
|
|
m_DelayedScreen = sClassName;
|
|
|
|
|
|
|
|
|
|
/* If we're not delaying screen loads, load it now. Otherwise, we'll load
|
|
|
|
|
* it on the next iteration. Only delay if we already have a screen
|
|
|
|
|
* loaded; otherwise, there's no reason to delay. */
|
|
|
|
|
if(!PREFSMAN->m_bDelayedScreenLoad) // || m_ScreenStack.empty() )
|
|
|
|
|
LoadDelayedScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::LoadDelayedScreen()
|
|
|
|
|
{
|
|
|
|
|
retry:
|
|
|
|
|
CString sClassName = m_DelayedScreen;
|
|
|
|
|
m_DelayedScreen = "";
|
|
|
|
|
|
2002-09-04 00:25:30 +00:00
|
|
|
/* If we prepped a screen but didn't use it, nuke it. */
|
|
|
|
|
SAFE_DELETE( m_ScreenBuffered );
|
2002-09-03 05:43:58 +00:00
|
|
|
|
2002-10-24 07:11:21 +00:00
|
|
|
RageTimer t;
|
2003-04-25 03:41:38 +00:00
|
|
|
|
2003-03-09 00:55:49 +00:00
|
|
|
Screen* pOldTopScreen = m_ScreenStack.empty() ? NULL : m_ScreenStack.back();
|
|
|
|
|
|
2002-08-27 03:59:22 +00:00
|
|
|
// It makes sense that ScreenManager should allocate memory for a new screen since it
|
|
|
|
|
// deletes it later on. This also convention will reduce includes because screens won't
|
|
|
|
|
// have to include each other's headers of other screens.
|
2003-10-19 23:19:02 +00:00
|
|
|
LOG->Trace( "Loading screen %s", sClassName.c_str() );
|
2002-09-03 05:43:58 +00:00
|
|
|
Screen* pNewScreen = MakeNewScreen(sClassName);
|
2003-04-25 00:01:35 +00:00
|
|
|
LOG->Trace( "Loaded %s in %f", sClassName.c_str(), t.GetDeltaTime());
|
2002-10-24 07:11:21 +00:00
|
|
|
|
2003-03-09 00:55:49 +00:00
|
|
|
if( pOldTopScreen!=NULL && m_ScreenStack.back()!=pOldTopScreen )
|
|
|
|
|
{
|
|
|
|
|
// While constructing this Screen, it's constructor called
|
|
|
|
|
// SetNewScreen again! That SetNewScreen Command should
|
|
|
|
|
// override this older one.
|
|
|
|
|
SAFE_DELETE( pNewScreen );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-25 03:41:38 +00:00
|
|
|
if( PREFSMAN->m_bDelayedScreenLoad && m_DelayedScreen != "" )
|
|
|
|
|
{
|
|
|
|
|
/* Same deal: the ctor called SetNewScreen again. Delete the screen
|
|
|
|
|
* we just made, but don't delay again. */
|
|
|
|
|
SAFE_DELETE( pNewScreen );
|
|
|
|
|
goto retry;
|
|
|
|
|
}
|
2002-09-04 00:25:30 +00:00
|
|
|
SetNewScreen( pNewScreen );
|
2003-02-12 06:25:51 +00:00
|
|
|
|
2003-02-12 11:43:08 +00:00
|
|
|
/* If this is a system menu, don't let the operator key touch it!
|
|
|
|
|
However, if you add an options screen, please include it here -- Miryokuteki */
|
2003-03-16 22:51:29 +00:00
|
|
|
if( sClassName == "ScreenOptionsMenu" ||
|
|
|
|
|
sClassName == "ScreenMachineOptions" ||
|
|
|
|
|
sClassName == "ScreenInputOptions" ||
|
|
|
|
|
sClassName == "ScreenGraphicOptions" ||
|
|
|
|
|
sClassName == "ScreenGameplayOptions" ||
|
|
|
|
|
sClassName == "ScreenMapControllers" ||
|
|
|
|
|
sClassName == "ScreenAppearanceOptions" ||
|
|
|
|
|
sClassName == "ScreenEdit" ||
|
|
|
|
|
sClassName == "ScreenEditMenu" ||
|
|
|
|
|
sClassName == "ScreenSoundOptions" )
|
2003-03-09 00:55:49 +00:00
|
|
|
GAMESTATE->m_bIsOnSystemMenu = true;
|
|
|
|
|
else
|
|
|
|
|
GAMESTATE->m_bIsOnSystemMenu = false;
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-19 05:46:09 +00:00
|
|
|
void ScreenManager::AddNewScreenToTop( CString sClassName )
|
|
|
|
|
{
|
|
|
|
|
Screen* pNewScreen = MakeNewScreen(sClassName);
|
|
|
|
|
m_ScreenStack.push_back( pNewScreen );
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 10:03:02 +00:00
|
|
|
#include "ScreenPrompt.h"
|
|
|
|
|
#include "ScreenTextEntry.h"
|
|
|
|
|
#include "ScreenMiniMenu.h"
|
|
|
|
|
|
2003-08-23 18:33:49 +00:00
|
|
|
void ScreenManager::Prompt( ScreenMessage SM_SendWhenDone, CString sText, bool bYesNo, bool bDefaultAnswer, void(*OnYes)(void*), void(*OnNo)(void*), void* pCallbackData )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-08-27 03:59:22 +00:00
|
|
|
// add the new state onto the back of the array
|
2003-08-23 18:33:49 +00:00
|
|
|
m_ScreenStack.push_back( new ScreenPrompt(SM_SendWhenDone, sText, bYesNo, bDefaultAnswer, OnYes, OnNo, pCallbackData) );
|
2002-08-27 03:59:22 +00:00
|
|
|
}
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-27 03:59:22 +00:00
|
|
|
void ScreenManager::TextEntry( ScreenMessage SM_SendWhenDone, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer), void(*OnCanel)() )
|
|
|
|
|
{
|
2002-05-20 08:59:37 +00:00
|
|
|
// add the new state onto the back of the array
|
2003-09-27 22:30:51 +00:00
|
|
|
m_ScreenStack.push_back( new ScreenTextEntry("ScreenTextEntry", SM_SendWhenDone, sQuestion, sInitialAnswer, OnOK, OnCanel) );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-15 19:25:37 +00:00
|
|
|
void ScreenManager::MiniMenu( Menu* pDef, ScreenMessage SM_SendOnOK, ScreenMessage SM_SendOnCancel )
|
2003-02-18 23:15:38 +00:00
|
|
|
{
|
|
|
|
|
// add the new state onto the back of the array
|
|
|
|
|
m_ScreenStack.push_back( new ScreenMiniMenu(pDef, SM_SendOnOK, SM_SendOnCancel) );
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
void ScreenManager::PopTopScreen( ScreenMessage SM )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-10-31 02:20:11 +00:00
|
|
|
Screen* pScreenToPop = m_ScreenStack.back(); // top menu
|
2002-05-20 08:59:37 +00:00
|
|
|
//pScreenToPop->HandleScreenMessage( SM_LosingInputFocus );
|
2002-10-31 04:11:08 +00:00
|
|
|
m_ScreenStack.erase(m_ScreenStack.end()-1, m_ScreenStack.end());
|
2002-10-31 04:23:39 +00:00
|
|
|
m_ScreensToDelete.push_back( pScreenToPop );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-10-31 02:20:11 +00:00
|
|
|
Screen* pNewTopScreen = m_ScreenStack[m_ScreenStack.size()-1];
|
2002-07-27 19:29:51 +00:00
|
|
|
pNewTopScreen->HandleScreenMessage( SM );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-25 21:17:29 +00:00
|
|
|
void ScreenManager::PostMessageToTopScreen( ScreenMessage SM, float fDelay )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-10-31 02:20:11 +00:00
|
|
|
Screen* pTopScreen = m_ScreenStack.back();
|
2003-03-25 21:17:29 +00:00
|
|
|
pTopScreen->PostScreenMessage( SM, fDelay );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::SendMessageToTopScreen( ScreenMessage SM )
|
|
|
|
|
{
|
|
|
|
|
Screen* pTopScreen = m_ScreenStack.back();
|
|
|
|
|
pTopScreen->HandleScreenMessage( SM );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::SystemMessage( CString sMessage )
|
|
|
|
|
{
|
2003-09-15 20:44:25 +00:00
|
|
|
LOG->Trace( "%s", sMessage.c_str() );
|
2003-03-15 00:02:54 +00:00
|
|
|
m_SystemLayer->SystemMessage( sMessage );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
void ScreenManager::RefreshCreditsMessages()
|
|
|
|
|
{
|
2003-03-15 00:02:54 +00:00
|
|
|
m_SystemLayer->RefreshCreditsMessages();
|
2003-02-12 07:52:20 +00:00
|
|
|
}
|
|
|
|
|
|