2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: StepMania.cpp
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
Desc: Entry point for program.
|
2001-11-04 19:34:28 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-07-23 01:41:40 +00:00
|
|
|
Chris Danford
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-01-24 23:09:31 +00:00
|
|
|
#include "StepMania.h"
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
//
|
|
|
|
|
// Rage global classes
|
|
|
|
|
//
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "RageTextureManager.h"
|
2002-12-15 10:35:39 +00:00
|
|
|
#include "RageSoundManager.h"
|
2003-07-26 22:15:53 +00:00
|
|
|
#include "RageMusic.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageInput.h"
|
|
|
|
|
#include "RageTimer.h"
|
|
|
|
|
#include "RageException.h"
|
2002-10-28 05:30:45 +00:00
|
|
|
#include "RageMath.h"
|
2003-05-22 05:28:37 +00:00
|
|
|
#include "RageDisplay.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
|
2002-11-17 09:13:35 +00:00
|
|
|
#include "arch/arch.h"
|
2002-11-18 21:37:58 +00:00
|
|
|
#include "arch/LoadingWindow/LoadingWindow.h"
|
2002-12-16 02:11:31 +00:00
|
|
|
#include "arch/ErrorDialog/ErrorDialog.h"
|
2003-02-02 18:18:51 +00:00
|
|
|
#include "time.h"
|
2002-11-17 09:13:35 +00:00
|
|
|
|
2003-02-14 06:31:09 +00:00
|
|
|
#include "SDL_utils.h"
|
2002-10-24 03:56:46 +00:00
|
|
|
|
2002-04-16 17:31:00 +00:00
|
|
|
//
|
|
|
|
|
// StepMania global classes
|
|
|
|
|
//
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "ThemeManager.h"
|
2003-02-06 07:32:57 +00:00
|
|
|
#include "NoteSkinManager.h"
|
2002-02-28 19:40:40 +00:00
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "SongManager.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "GameState.h"
|
2002-05-19 01:59:48 +00:00
|
|
|
#include "AnnouncerManager.h"
|
|
|
|
|
#include "ScreenManager.h"
|
2002-03-19 07:09:49 +00:00
|
|
|
#include "GameManager.h"
|
2002-03-30 20:00:13 +00:00
|
|
|
#include "FontManager.h"
|
2002-04-16 17:31:00 +00:00
|
|
|
#include "InputFilter.h"
|
|
|
|
|
#include "InputMapper.h"
|
2002-05-19 01:59:48 +00:00
|
|
|
#include "InputQueue.h"
|
2002-08-21 02:13:08 +00:00
|
|
|
#include "SongCacheIndex.h"
|
2003-06-04 22:42:17 +00:00
|
|
|
#include "BannerCache.h"
|
2003-07-07 22:21:31 +00:00
|
|
|
#include "UnlockSystem.h"
|
2003-07-11 03:15:28 +00:00
|
|
|
#include "arch/ArchHooks/ArchHooks.h"
|
2003-07-22 07:47:27 +00:00
|
|
|
#include "RageFile.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_XBOX)
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/xboxSDLmaind.lib")
|
|
|
|
|
#else
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/xboxSDLmain.lib")
|
|
|
|
|
#endif
|
|
|
|
|
#elif defined(_WINDOWS)
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/SDLmaind.lib")
|
|
|
|
|
#else
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/SDLmain.lib")
|
|
|
|
|
#endif
|
2002-11-11 04:53:31 +00:00
|
|
|
#endif
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-07-22 07:47:27 +00:00
|
|
|
#ifdef _WINDOWS
|
2002-12-03 00:35:34 +00:00
|
|
|
HWND g_hWndMain = NULL;
|
|
|
|
|
#endif
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-07-15 00:47:53 +00:00
|
|
|
int g_argc = 0;
|
|
|
|
|
char **g_argv = NULL;
|
2003-07-06 22:13:56 +00:00
|
|
|
|
2003-01-19 11:00:53 +00:00
|
|
|
static bool g_bHasFocus = true;
|
2003-04-12 16:06:06 +00:00
|
|
|
static bool g_bQuitting = false;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-12-16 02:11:31 +00:00
|
|
|
static void ChangeToDirOfExecutable(const char *argv0)
|
2002-07-03 21:27:26 +00:00
|
|
|
{
|
2003-07-22 07:47:27 +00:00
|
|
|
#ifndef _XBOX
|
2002-12-16 02:11:31 +00:00
|
|
|
/* Make sure the current directory is the root program directory
|
|
|
|
|
* We probably shouldn't do this; rather, we should know where things
|
|
|
|
|
* are and use paths as needed, so we don't depend on the binary being
|
|
|
|
|
* in the same place as "Songs" ... */
|
2002-11-11 04:53:31 +00:00
|
|
|
if( !DoesFileExist("Songs") )
|
2002-11-08 08:17:59 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
// strip off executable name
|
2002-12-16 02:11:31 +00:00
|
|
|
CString dir = argv0;
|
|
|
|
|
unsigned n = dir.find_last_of("/\\");
|
|
|
|
|
if (n != dir.npos) dir.erase(n);
|
2002-08-30 01:06:23 +00:00
|
|
|
|
2003-04-25 00:27:30 +00:00
|
|
|
chdir( dir.c_str() );
|
2002-08-30 01:06:23 +00:00
|
|
|
}
|
2003-07-22 07:47:27 +00:00
|
|
|
#endif
|
2002-08-30 01:06:23 +00:00
|
|
|
}
|
2002-07-03 21:27:26 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
void ApplyGraphicOptions()
|
|
|
|
|
{
|
2003-02-02 09:09:29 +00:00
|
|
|
bool bNeedReload = false;
|
|
|
|
|
|
|
|
|
|
bNeedReload |= DISPLAY->SetVideoMode(
|
2003-06-05 19:29:27 +00:00
|
|
|
RageDisplay::VideoModeParams(
|
|
|
|
|
PREFSMAN->m_bWindowed,
|
|
|
|
|
PREFSMAN->m_iDisplayWidth,
|
|
|
|
|
PREFSMAN->m_iDisplayHeight,
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth,
|
|
|
|
|
PREFSMAN->m_iRefreshRate,
|
|
|
|
|
PREFSMAN->m_bVsync,
|
|
|
|
|
PREFSMAN->m_bAntiAliasing,
|
|
|
|
|
THEME->GetMetric("Common","WindowTitle"),
|
|
|
|
|
THEME->GetPathToG("Common window icon") ) );
|
2003-02-02 09:09:29 +00:00
|
|
|
bNeedReload |= TEXTUREMAN->SetPrefs(
|
2003-02-02 02:01:28 +00:00
|
|
|
PREFSMAN->m_iTextureColorDepth,
|
2003-07-09 02:28:56 +00:00
|
|
|
PREFSMAN->m_iMovieColorDepth,
|
2003-04-18 23:55:20 +00:00
|
|
|
PREFSMAN->m_bDelayedTextureDelete,
|
2003-02-02 02:01:28 +00:00
|
|
|
PREFSMAN->m_iMaxTextureResolution );
|
2002-11-12 09:31:08 +00:00
|
|
|
|
2003-02-02 09:09:29 +00:00
|
|
|
if( bNeedReload )
|
2003-05-26 09:18:44 +00:00
|
|
|
TEXTUREMAN->ReloadAll();
|
|
|
|
|
|
2003-06-05 19:29:27 +00:00
|
|
|
// find out what we actually got
|
|
|
|
|
PREFSMAN->m_bWindowed = DISPLAY->GetVideoModeParams().windowed;
|
|
|
|
|
PREFSMAN->m_iDisplayWidth = DISPLAY->GetVideoModeParams().width;
|
|
|
|
|
PREFSMAN->m_iDisplayHeight = DISPLAY->GetVideoModeParams().height;
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth = DISPLAY->GetVideoModeParams().bpp;
|
|
|
|
|
PREFSMAN->m_iRefreshRate = DISPLAY->GetVideoModeParams().rate;
|
|
|
|
|
PREFSMAN->m_bVsync = DISPLAY->GetVideoModeParams().vsync;
|
|
|
|
|
|
|
|
|
|
SCREENMAN->SystemMessage( ssprintf("%s %dx%d %d color %d texture %dHz %s %s",
|
2003-05-26 09:18:44 +00:00
|
|
|
PREFSMAN->m_bWindowed ? "Windowed" : "Fullscreen",
|
|
|
|
|
PREFSMAN->m_iDisplayWidth,
|
|
|
|
|
PREFSMAN->m_iDisplayHeight,
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth,
|
|
|
|
|
PREFSMAN->m_iTextureColorDepth,
|
|
|
|
|
PREFSMAN->m_iRefreshRate,
|
2003-06-05 19:29:27 +00:00
|
|
|
PREFSMAN->m_bVsync ? "Vsync" : "NoVsync",
|
|
|
|
|
PREFSMAN->m_bAntiAliasing? "AA" : "NoAA" ) );
|
2003-06-18 05:43:12 +00:00
|
|
|
|
|
|
|
|
/* Give the input handlers a chance to re-open devices as necessary. */
|
|
|
|
|
INPUTMAN->WindowReset();
|
2002-11-11 04:53:31 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-01-19 04:44:22 +00:00
|
|
|
void ExitGame()
|
2003-01-10 02:22:07 +00:00
|
|
|
{
|
2003-04-12 16:06:06 +00:00
|
|
|
g_bQuitting = true;
|
2003-01-10 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-19 04:44:22 +00:00
|
|
|
void ResetGame()
|
2003-01-10 02:22:07 +00:00
|
|
|
{
|
|
|
|
|
GAMESTATE->Reset();
|
|
|
|
|
PREFSMAN->ReadGamePrefsFromDisk();
|
|
|
|
|
INPUTMAPPER->ReadMappingsFromDisk();
|
|
|
|
|
|
2003-06-25 05:22:58 +00:00
|
|
|
NOTESKIN->RefreshNoteSkinData( GAMESTATE->m_CurGame );
|
|
|
|
|
|
2003-04-21 23:43:51 +00:00
|
|
|
/*
|
|
|
|
|
GameState::Reset() will switch the NoteSkin
|
2003-02-17 12:19:42 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
2003-01-10 02:22:07 +00:00
|
|
|
{
|
2003-02-17 12:19:42 +00:00
|
|
|
PlayerNumber pn = (PlayerNumber)p;
|
|
|
|
|
if( !NOTESKIN->DoesNoteSkinExist( NOTESKIN->GetCurNoteSkinName(pn) ) )
|
|
|
|
|
{
|
|
|
|
|
CStringArray asNoteSkinNames;
|
|
|
|
|
NOTESKIN->GetNoteSkinNames( asNoteSkinNames );
|
|
|
|
|
NOTESKIN->SwitchNoteSkin( pn, asNoteSkinNames[0] );
|
|
|
|
|
}
|
2003-01-10 02:22:07 +00:00
|
|
|
}
|
2003-04-21 23:43:51 +00:00
|
|
|
*/
|
2003-01-10 02:22:07 +00:00
|
|
|
if( !THEME->DoesThemeExist( THEME->GetCurThemeName() ) )
|
|
|
|
|
{
|
|
|
|
|
CString sGameName = GAMESTATE->GetCurrentGameDef()->m_szName;
|
|
|
|
|
if( THEME->DoesThemeExist( sGameName ) )
|
|
|
|
|
THEME->SwitchTheme( sGameName );
|
|
|
|
|
else
|
|
|
|
|
THEME->SwitchTheme( "default" );
|
2003-04-18 23:55:20 +00:00
|
|
|
TEXTUREMAN->DoDelayedDelete();
|
2003-01-10 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
PREFSMAN->SaveGamePrefsToDisk();
|
|
|
|
|
|
2003-06-06 21:58:40 +00:00
|
|
|
SCREENMAN->SetNewScreen( THEME->GetMetric("Common","InitialScreen") );
|
2003-05-26 09:18:44 +00:00
|
|
|
PREFSMAN->m_bFirstRun = false;
|
2003-05-28 02:35:05 +00:00
|
|
|
|
|
|
|
|
if( PREFSMAN->m_bAutoMapJoysticks )
|
|
|
|
|
INPUTMAPPER->AutoMapJoysticksForCurrentGame();
|
2003-01-10 02:22:07 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-12-19 23:26:50 +00:00
|
|
|
static void GameLoop();
|
2002-11-14 23:54:40 +00:00
|
|
|
|
2003-01-19 11:00:53 +00:00
|
|
|
static bool ChangeAppPri()
|
2003-01-18 04:27:33 +00:00
|
|
|
{
|
|
|
|
|
if(PREFSMAN->m_iBoostAppPriority == 0)
|
2003-01-19 11:00:53 +00:00
|
|
|
return false;
|
2003-01-18 04:27:33 +00:00
|
|
|
|
|
|
|
|
/* If -1 and this is a debug build, don't. It makes the debugger sluggish. */
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if(PREFSMAN->m_iBoostAppPriority == -1)
|
2003-01-19 11:00:53 +00:00
|
|
|
return false;
|
2003-01-18 04:27:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-01-19 11:00:53 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void BoostAppPri()
|
|
|
|
|
{
|
|
|
|
|
if(!ChangeAppPri())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-07-11 03:15:28 +00:00
|
|
|
#ifdef _WINDOWS
|
2003-01-18 04:27:33 +00:00
|
|
|
/* We just want a slight boost, so we don't skip needlessly if something happens
|
|
|
|
|
* in the background. We don't really want to be high-priority--above normal should
|
|
|
|
|
* be enough. However, ABOVE_NORMAL_PRIORITY_CLASS is only supported in Win2000
|
|
|
|
|
* and later. */
|
|
|
|
|
OSVERSIONINFO version;
|
|
|
|
|
version.dwOSVersionInfoSize=sizeof(version);
|
|
|
|
|
if(!GetVersionEx(&version))
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn(werr_ssprintf(GetLastError(), "GetVersionEx failed"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 21:05:03 +00:00
|
|
|
#ifndef ABOVE_NORMAL_PRIORITY_CLASS
|
|
|
|
|
#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-01-18 04:27:33 +00:00
|
|
|
DWORD pri = HIGH_PRIORITY_CLASS;
|
|
|
|
|
if(version.dwMajorVersion >= 5)
|
|
|
|
|
pri = ABOVE_NORMAL_PRIORITY_CLASS;
|
|
|
|
|
|
|
|
|
|
/* Be sure to boost the app, not the thread, to make sure the
|
|
|
|
|
* sound thread stays higher priority than the main thread. */
|
|
|
|
|
SetPriorityClass(GetCurrentProcess(), pri);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-10 23:50:31 +00:00
|
|
|
static void CheckSettings()
|
|
|
|
|
{
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
|
/* Has the amount of memory changed? */
|
|
|
|
|
MEMORYSTATUS mem;
|
|
|
|
|
GlobalMemoryStatus(&mem);
|
|
|
|
|
|
|
|
|
|
const int Memory = mem.dwTotalPhys / 1048576;
|
|
|
|
|
|
|
|
|
|
if( PREFSMAN->m_iLastSeenMemory == Memory )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOG->Trace( "Memory changed from %i to %i; settings changed", PREFSMAN->m_iLastSeenMemory, Memory );
|
|
|
|
|
PREFSMAN->m_iLastSeenMemory = Memory;
|
|
|
|
|
|
|
|
|
|
/* Let's consider 128-meg systems low-memory, and 256-meg systems high-memory.
|
|
|
|
|
* Cut off at 192. This is somewhat conservative; many 128-meg systems can
|
|
|
|
|
* deal with higher memory profile settings, but some can't.
|
|
|
|
|
*
|
|
|
|
|
* Actually, Windows lops off a meg or two; cut off a little lower to treat
|
|
|
|
|
* 192-meg systems as high-memory. */
|
|
|
|
|
const bool HighMemory = (Memory >= 190);
|
2003-06-11 02:58:13 +00:00
|
|
|
const bool LowMemory = (Memory < 100); /* 64 and 96-meg systems */
|
2003-06-10 23:50:31 +00:00
|
|
|
|
|
|
|
|
/* Two memory-consuming features that we can disable are texture caching and
|
|
|
|
|
* preloaded banners. Texture caching can use a lot of memory; disable it for
|
|
|
|
|
* low-memory systems. */
|
|
|
|
|
PREFSMAN->m_bDelayedTextureDelete = HighMemory;
|
|
|
|
|
|
2003-06-11 02:58:13 +00:00
|
|
|
/* Preloaded banners takes about 9k per song. Although it's smaller than the
|
|
|
|
|
* actual song data, it still adds up with a lot of songs. Disable it for 64-meg
|
|
|
|
|
* systems. */
|
|
|
|
|
PREFSMAN->m_bBannerCache = !LowMemory;
|
2003-06-10 23:50:31 +00:00
|
|
|
|
|
|
|
|
PREFSMAN->SaveGlobalPrefsToDisk();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-26 23:33:37 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
|
#include "RageDisplay_D3D.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !defined(_XBOX)
|
|
|
|
|
#include "RageDisplay_OGL.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "archutils/Win32/VideoDriverInfo.h"
|
2003-06-07 14:33:14 +00:00
|
|
|
#include "regex.h"
|
2003-05-28 05:58:24 +00:00
|
|
|
|
2003-06-22 17:45:19 +00:00
|
|
|
static const CString D3DURL = "http://search.microsoft.com/gomsuri.asp?n=1&c=rp_BestBets&siteid=us&target=http://www.microsoft.com/downloads/details.aspx?FamilyID=a19bed22-0b25-4e5d-a584-6389d8a3dad0&displaylang=en";
|
|
|
|
|
|
2003-07-22 07:47:27 +00:00
|
|
|
#define VIDEOCARDS_INI_PATH BASE_PATH "Data" SLASH "VideoCardDefaults.ini"
|
|
|
|
|
|
2003-05-26 23:33:37 +00:00
|
|
|
RageDisplay *CreateDisplay()
|
|
|
|
|
{
|
|
|
|
|
/* We never want to bother users with having to decide which API to use.
|
|
|
|
|
*
|
|
|
|
|
* Some cards simply are too troublesome with OpenGL to ever use it, eg. Voodoos.
|
|
|
|
|
* If D3D8 isn't installed on those, complain and refuse to run (by default).
|
|
|
|
|
* For others, always use OpenGL. Allow forcing to D3D as an advanced option.
|
|
|
|
|
*
|
|
|
|
|
* If we're missing acceleration when we load D3D8 due to a card being in the
|
|
|
|
|
* D3D list, it means we need drivers and that they do exist.
|
|
|
|
|
*
|
|
|
|
|
* If we try to load OpenGL and we're missing acceleration, it may mean:
|
|
|
|
|
* 1. We're missing drivers, and they just need upgrading.
|
|
|
|
|
* 2. The card doesn't have drivers, and it should be using D3D8. In other words,
|
|
|
|
|
* it needs an entry in this table.
|
|
|
|
|
* 3. The card doesn't have drivers for either. (Sorry, no S3 868s.) Can't play.
|
|
|
|
|
*
|
|
|
|
|
* In this case, fail to load; don't silently fall back on D3D. We don't want
|
|
|
|
|
* people unknowingly using D3D8 with old drivers (and reporting obscure bugs
|
|
|
|
|
* due to driver problems). We'll probably get bug reports for all three types.
|
|
|
|
|
* #2 is the only case that's actually a bug.
|
|
|
|
|
*
|
2003-05-28 05:58:24 +00:00
|
|
|
* Actually, right now we're falling back. I'm not sure which behavior is better.
|
2003-05-26 23:33:37 +00:00
|
|
|
*/
|
2003-05-31 21:34:07 +00:00
|
|
|
|
|
|
|
|
// Video card changed since last run
|
2003-07-22 07:47:27 +00:00
|
|
|
#if defined(_WINDOWS)
|
2003-05-31 21:34:07 +00:00
|
|
|
CString sVideoDriver = GetPrimaryVideoDriverName();
|
2003-07-22 07:47:27 +00:00
|
|
|
#else
|
2003-06-07 16:37:24 +00:00
|
|
|
CString sVideoDriver = "OpenGL";
|
|
|
|
|
#endif
|
2003-06-01 00:34:15 +00:00
|
|
|
if( PREFSMAN->m_sVideoRenderers == "" ||
|
|
|
|
|
PREFSMAN->m_sLastSeenVideoDriver != sVideoDriver )
|
2003-05-27 01:03:21 +00:00
|
|
|
{
|
2003-05-31 21:34:07 +00:00
|
|
|
// Apply default graphic settings for this card
|
|
|
|
|
IniFile ini;
|
2003-07-22 07:47:27 +00:00
|
|
|
ini.SetPath( VIDEOCARDS_INI_PATH );
|
2003-06-01 00:34:15 +00:00
|
|
|
if(!ini.ReadFile())
|
2003-07-24 05:34:27 +00:00
|
|
|
RageException::Throw( "Couldn't read '%s'.", VIDEOCARDS_INI_PATH );
|
2003-05-31 21:34:07 +00:00
|
|
|
|
2003-06-12 01:39:31 +00:00
|
|
|
IniFile::const_iterator i;
|
|
|
|
|
for( i = ini.begin(); i != ini.end(); ++i )
|
2003-05-31 21:34:07 +00:00
|
|
|
{
|
2003-06-12 01:39:31 +00:00
|
|
|
const CString &sKey = i->first;
|
2003-05-31 21:34:07 +00:00
|
|
|
|
|
|
|
|
CString sDriverRegex;
|
2003-06-07 10:36:39 +00:00
|
|
|
if( !ini.GetValue( sKey, "DriverRegex", sDriverRegex ) )
|
|
|
|
|
break;
|
2003-05-31 21:34:07 +00:00
|
|
|
Regex regex( sDriverRegex );
|
|
|
|
|
if( !regex.Compare(sVideoDriver) )
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
2003-06-13 18:42:06 +00:00
|
|
|
LOG->Trace( "Using default graphics settings for '%s'.", sDriverRegex.size()? sDriverRegex.c_str():"(unknown card)" );
|
2003-05-31 21:34:07 +00:00
|
|
|
|
|
|
|
|
ini.GetValue( sKey, "Renderers", PREFSMAN->m_sVideoRenderers );
|
|
|
|
|
ini.GetValueI( sKey, "Width", PREFSMAN->m_iDisplayWidth );
|
|
|
|
|
ini.GetValueI( sKey, "Height", PREFSMAN->m_iDisplayHeight );
|
|
|
|
|
ini.GetValueI( sKey, "DisplayColor", PREFSMAN->m_iDisplayColorDepth );
|
|
|
|
|
ini.GetValueI( sKey, "TextureColor", PREFSMAN->m_iTextureColorDepth );
|
2003-07-09 02:28:56 +00:00
|
|
|
ini.GetValueI( sKey, "MovieColor", PREFSMAN->m_iMovieColorDepth );
|
2003-06-05 19:29:27 +00:00
|
|
|
ini.GetValueB( sKey, "AntiAliasing", PREFSMAN->m_bAntiAliasing );
|
2003-05-31 21:34:07 +00:00
|
|
|
|
|
|
|
|
// Update last seen video card
|
2003-07-22 07:47:27 +00:00
|
|
|
#if defined(_WINDOWS)
|
2003-05-31 21:34:07 +00:00
|
|
|
PREFSMAN->m_sLastSeenVideoDriver = GetPrimaryVideoDriverName();
|
2003-07-22 07:47:27 +00:00
|
|
|
#else
|
2003-06-07 16:37:24 +00:00
|
|
|
PREFSMAN->m_sLastSeenVideoDriver = "OpenGL";
|
|
|
|
|
#endif
|
2003-05-31 21:34:07 +00:00
|
|
|
|
|
|
|
|
break; // stop looking
|
|
|
|
|
}
|
2003-05-27 01:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-05 19:29:27 +00:00
|
|
|
|
|
|
|
|
RageDisplay::VideoModeParams params(
|
|
|
|
|
PREFSMAN->m_bWindowed,
|
|
|
|
|
PREFSMAN->m_iDisplayWidth,
|
|
|
|
|
PREFSMAN->m_iDisplayHeight,
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth,
|
|
|
|
|
PREFSMAN->m_iRefreshRate,
|
|
|
|
|
PREFSMAN->m_bVsync,
|
|
|
|
|
PREFSMAN->m_bAntiAliasing,
|
|
|
|
|
THEME->GetMetric("Common","WindowTitle"),
|
|
|
|
|
THEME->GetPathToG("Common window icon") );
|
|
|
|
|
|
2003-05-31 21:34:07 +00:00
|
|
|
CString error = "There was an error while initializing your video card.\n\n"
|
|
|
|
|
" PLEASE DO NOT FILE THIS ERROR AS A BUG!\n\n"
|
|
|
|
|
"Video Driver: "+sVideoDriver+"\n\n";
|
2003-05-28 05:58:24 +00:00
|
|
|
|
2003-05-31 21:34:07 +00:00
|
|
|
CStringArray asRenderers;
|
|
|
|
|
split( PREFSMAN->m_sVideoRenderers, ",", asRenderers, true );
|
2003-06-12 01:35:54 +00:00
|
|
|
|
|
|
|
|
if( asRenderers.empty() )
|
|
|
|
|
RageException::Throw("No video renderers attempted.");
|
|
|
|
|
|
2003-06-01 00:34:15 +00:00
|
|
|
for( unsigned i=0; i<asRenderers.size(); i++ )
|
2003-05-26 23:33:37 +00:00
|
|
|
{
|
2003-05-31 21:34:07 +00:00
|
|
|
CString sRenderer = asRenderers[i];
|
|
|
|
|
|
|
|
|
|
if( sRenderer.CompareNoCase("opengl")==0 )
|
|
|
|
|
{
|
2003-07-23 21:20:12 +00:00
|
|
|
#if defined(SUPPORT_OPENGL)
|
2003-05-31 21:34:07 +00:00
|
|
|
error += "Initializing OpenGL...\n";
|
2003-06-25 20:44:49 +00:00
|
|
|
try {
|
|
|
|
|
return new RageDisplay_OGL( params, PREFSMAN->m_bAllowUnacceleratedRenderer );
|
|
|
|
|
} catch(RageException e) {
|
|
|
|
|
error += CString(e.what()) + "\n";
|
|
|
|
|
continue;
|
|
|
|
|
};
|
2003-06-05 19:29:27 +00:00
|
|
|
#endif
|
2003-05-31 21:34:07 +00:00
|
|
|
}
|
|
|
|
|
else if( sRenderer.CompareNoCase("d3d")==0 )
|
|
|
|
|
{
|
2003-07-23 21:20:12 +00:00
|
|
|
#if defined(SUPPORT_D3D)
|
2003-05-31 21:34:07 +00:00
|
|
|
error += "Initializing Direct3D...\n";
|
|
|
|
|
try {
|
2003-06-05 19:29:27 +00:00
|
|
|
return new RageDisplay_D3D( params );
|
2003-07-23 20:19:22 +00:00
|
|
|
} catch( const exception &e ) {
|
2003-06-25 20:44:49 +00:00
|
|
|
error += CString(e.what()) + "\n";
|
2003-05-31 21:34:07 +00:00
|
|
|
};
|
2003-06-05 19:29:27 +00:00
|
|
|
#endif
|
2003-05-31 21:34:07 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
RageException::Throw("Unknown video renderer value: %s", sRenderer.c_str() );
|
2003-05-26 23:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-28 05:58:24 +00:00
|
|
|
RageException::Throw( error );
|
2003-05-26 19:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-26 23:33:37 +00:00
|
|
|
|
2003-01-19 11:00:53 +00:00
|
|
|
static void RestoreAppPri()
|
|
|
|
|
{
|
|
|
|
|
if(!ChangeAppPri())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-07-11 03:15:28 +00:00
|
|
|
#ifdef _WINDOWS
|
2003-01-19 11:00:53 +00:00
|
|
|
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
|
2003-02-15 00:11:12 +00:00
|
|
|
#endif
|
2003-01-19 11:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-22 07:47:27 +00:00
|
|
|
#define UNLOCKS_PATH BASE_PATH "Data" SLASH "Unlocks.dat"
|
|
|
|
|
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
2003-07-12 19:51:40 +00:00
|
|
|
g_argc = argc;
|
|
|
|
|
g_argv = argv;
|
|
|
|
|
|
2003-01-24 23:09:31 +00:00
|
|
|
/* Set up arch hooks first. This may set up crash handling. */
|
|
|
|
|
HOOKS = MakeArchHooks();
|
|
|
|
|
|
2002-12-16 02:11:31 +00:00
|
|
|
ChangeToDirOfExecutable(argv[0]);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-01-27 01:05:19 +00:00
|
|
|
/* Set this up second. Do this early, since it's needed for RageException::Throw.
|
|
|
|
|
* Do it after ChangeToDirOfExecutable, so the log ends up in the right place. */
|
|
|
|
|
LOG = new RageLog();
|
2003-04-25 05:43:48 +00:00
|
|
|
|
2003-01-27 01:05:19 +00:00
|
|
|
/* Whew--we should be able to crash safely now! */
|
|
|
|
|
|
|
|
|
|
atexit(SDL_Quit); /* Clean up on exit */
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-04-25 05:43:48 +00:00
|
|
|
/* Fire up the SDL, but don't actually start any subsystems.
|
|
|
|
|
* We use our own error handlers. */
|
|
|
|
|
int SDL_flags = SDL_INIT_NOPARACHUTE;
|
2002-12-03 00:35:34 +00:00
|
|
|
SDL_Init(SDL_flags);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-12-19 23:24:06 +00:00
|
|
|
CString g_sErrorString = "";
|
|
|
|
|
|
2003-02-15 05:15:24 +00:00
|
|
|
#ifndef DEBUG
|
2002-11-11 04:53:31 +00:00
|
|
|
try{
|
|
|
|
|
#endif
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
|
2002-12-16 02:11:31 +00:00
|
|
|
LoadingWindow *loading_window = MakeLoadingWindow();
|
2003-04-06 00:33:35 +00:00
|
|
|
|
2002-12-16 02:11:31 +00:00
|
|
|
loading_window->Paint();
|
2001-12-11 11:25:37 +00:00
|
|
|
|
2003-02-02 18:18:51 +00:00
|
|
|
// changed to use time. GetTimeSinceStart is silly because it always return 0! -Chris
|
|
|
|
|
srand( time(NULL) ); // seed number generator
|
2003-01-24 22:28:23 +00:00
|
|
|
|
2003-02-17 03:09:25 +00:00
|
|
|
HOOKS->DumpDebugInfo();
|
|
|
|
|
|
2002-03-19 07:09:49 +00:00
|
|
|
//
|
2002-01-24 08:01:24 +00:00
|
|
|
// Create game objects
|
2002-03-19 07:09:49 +00:00
|
|
|
//
|
2002-07-23 01:41:40 +00:00
|
|
|
GAMESTATE = new GameState;
|
2002-05-27 08:23:27 +00:00
|
|
|
PREFSMAN = new PrefsManager;
|
2003-07-18 08:05:39 +00:00
|
|
|
|
2003-07-20 04:35:22 +00:00
|
|
|
if( PREFSMAN->m_bDebugMode )
|
2003-07-18 08:05:39 +00:00
|
|
|
LOG->ShowConsole();
|
|
|
|
|
|
2003-06-11 02:58:13 +00:00
|
|
|
CheckSettings();
|
|
|
|
|
|
2002-06-14 22:25:22 +00:00
|
|
|
GAMEMAN = new GameManager;
|
|
|
|
|
THEME = new ThemeManager;
|
2003-02-06 07:32:57 +00:00
|
|
|
NOTESKIN = new NoteSkinManager;
|
2003-01-19 21:51:46 +00:00
|
|
|
SOUNDMAN = new RageSoundManager(PREFSMAN->m_sSoundDrivers);
|
2003-01-19 19:55:24 +00:00
|
|
|
SOUNDMAN->SetPrefs(PREFSMAN->m_fSoundVolume);
|
2003-07-26 22:15:53 +00:00
|
|
|
MUSIC = new RageMusic;
|
2002-05-19 01:59:48 +00:00
|
|
|
ANNOUNCER = new AnnouncerManager;
|
2002-11-11 04:53:31 +00:00
|
|
|
INPUTFILTER = new InputFilter;
|
|
|
|
|
INPUTMAPPER = new InputMapper;
|
|
|
|
|
INPUTQUEUE = new InputQueue;
|
|
|
|
|
SONGINDEX = new SongCacheIndex;
|
2003-06-04 22:42:17 +00:00
|
|
|
BANNERCACHE = new BannerCache;
|
2003-06-11 00:23:24 +00:00
|
|
|
|
2002-08-21 02:13:08 +00:00
|
|
|
/* depends on SONGINDEX: */
|
2002-11-17 09:13:35 +00:00
|
|
|
SONGMAN = new SongManager( loading_window ); // this takes a long time to load
|
|
|
|
|
delete loading_window; // destroy this before init'ing Display
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2003-06-10 23:50:31 +00:00
|
|
|
/* XXX: Why do we reload global prefs? PREFSMAN loads them in the ctor. -glenn */
|
2002-11-11 04:53:31 +00:00
|
|
|
PREFSMAN->ReadGlobalPrefsFromDisk( true );
|
2003-05-25 22:39:23 +00:00
|
|
|
PREFSMAN->ReadGamePrefsFromDisk();
|
2001-12-11 11:25:37 +00:00
|
|
|
|
2003-05-26 19:42:04 +00:00
|
|
|
DISPLAY = CreateDisplay();
|
2003-04-18 23:55:20 +00:00
|
|
|
TEXTUREMAN = new RageTextureManager();
|
|
|
|
|
TEXTUREMAN->SetPrefs(
|
|
|
|
|
PREFSMAN->m_iTextureColorDepth,
|
2003-07-09 02:28:56 +00:00
|
|
|
PREFSMAN->m_iMovieColorDepth,
|
2003-04-18 23:55:20 +00:00
|
|
|
PREFSMAN->m_bDelayedTextureDelete,
|
|
|
|
|
PREFSMAN->m_iMaxTextureResolution );
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-04-12 16:06:06 +00:00
|
|
|
/* Now that we've started DISPLAY, we can set up event masks. */
|
2003-05-26 01:48:48 +00:00
|
|
|
mySDL_EventState(SDL_QUIT, SDL_ENABLE);
|
|
|
|
|
mySDL_EventState(SDL_ACTIVEEVENT, SDL_ENABLE);
|
2003-04-12 16:06:06 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Grab the window manager specific information */
|
|
|
|
|
SDL_SysWMinfo info;
|
|
|
|
|
SDL_VERSION(&info.version);
|
|
|
|
|
if ( SDL_GetWMInfo(&info) < 0 )
|
2002-12-21 19:34:02 +00:00
|
|
|
RageException::Throw( "SDL_GetWMInfo failed" );
|
2002-12-03 00:35:34 +00:00
|
|
|
|
2003-07-11 03:15:28 +00:00
|
|
|
#ifdef _WINDOWS
|
2002-12-03 00:35:34 +00:00
|
|
|
g_hWndMain = info.window;
|
|
|
|
|
#endif
|
2002-09-21 16:29:14 +00:00
|
|
|
|
2003-04-12 16:06:06 +00:00
|
|
|
/* This initializes objects that change the SDL event mask, and has other
|
|
|
|
|
* dependencies on the SDL video subsystem, so it must be initialized after
|
|
|
|
|
* DISPLAY and setting the default SDL event mask. */
|
2003-04-25 05:43:48 +00:00
|
|
|
INPUTMAN = new RageInput;
|
2002-07-27 19:29:51 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
// These things depend on the TextureManager, so do them after!
|
2002-05-28 20:01:22 +00:00
|
|
|
FONT = new FontManager;
|
|
|
|
|
SCREENMAN = new ScreenManager;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-01-18 04:27:33 +00:00
|
|
|
/* People may want to do something else while songs are loading, so do
|
|
|
|
|
* this after loading songs. */
|
|
|
|
|
BoostAppPri();
|
|
|
|
|
|
2003-01-19 04:44:22 +00:00
|
|
|
ResetGame();
|
2002-11-08 08:17:59 +00:00
|
|
|
|
2003-05-09 05:56:05 +00:00
|
|
|
/* Load the unlocks into memory */
|
2003-07-22 07:47:27 +00:00
|
|
|
GAMESTATE->m_pUnlockingSys->LoadFromDATFile( UNLOCKS_PATH );
|
2003-05-09 05:56:05 +00:00
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
/* Run the main loop. */
|
|
|
|
|
GameLoop();
|
|
|
|
|
|
2002-12-09 22:31:21 +00:00
|
|
|
PREFSMAN->SaveGlobalPrefsToDisk();
|
|
|
|
|
PREFSMAN->SaveGamePrefsToDisk();
|
|
|
|
|
|
2003-02-15 05:15:24 +00:00
|
|
|
#ifndef DEBUG
|
2002-11-14 23:54:40 +00:00
|
|
|
}
|
|
|
|
|
catch( RageException e )
|
|
|
|
|
{
|
|
|
|
|
g_sErrorString = e.what();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-12-19 14:56:22 +00:00
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( SCREENMAN );
|
2003-07-14 06:23:15 +00:00
|
|
|
/* Delete INPUTMAN before the other INPUTFILTER handlers, or an input
|
|
|
|
|
* driver may try to send a message to INPUTFILTER after we delete it. */
|
|
|
|
|
SAFE_DELETE( INPUTMAN );
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( INPUTQUEUE );
|
|
|
|
|
SAFE_DELETE( INPUTMAPPER );
|
|
|
|
|
SAFE_DELETE( INPUTFILTER );
|
|
|
|
|
SAFE_DELETE( SONGMAN );
|
2003-06-04 22:42:17 +00:00
|
|
|
SAFE_DELETE( BANNERCACHE );
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( SONGINDEX );
|
|
|
|
|
SAFE_DELETE( PREFSMAN );
|
|
|
|
|
SAFE_DELETE( GAMESTATE );
|
|
|
|
|
SAFE_DELETE( GAMEMAN );
|
2003-02-06 07:32:57 +00:00
|
|
|
SAFE_DELETE( NOTESKIN );
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( THEME );
|
|
|
|
|
SAFE_DELETE( ANNOUNCER );
|
2003-07-26 22:15:53 +00:00
|
|
|
SAFE_DELETE( MUSIC );
|
2002-12-15 10:35:39 +00:00
|
|
|
SAFE_DELETE( SOUNDMAN );
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( FONT );
|
|
|
|
|
SAFE_DELETE( TEXTUREMAN );
|
|
|
|
|
SAFE_DELETE( DISPLAY );
|
|
|
|
|
SAFE_DELETE( LOG );
|
2003-01-24 23:09:31 +00:00
|
|
|
SAFE_DELETE( HOOKS );
|
|
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
if( g_sErrorString != "" )
|
|
|
|
|
{
|
|
|
|
|
// throw up a pretty error dialog
|
2002-12-16 02:11:31 +00:00
|
|
|
ErrorDialog *d = MakeErrorDialog();
|
|
|
|
|
d->SetErrorText(g_sErrorString);
|
|
|
|
|
d->ShowError();
|
|
|
|
|
delete d;
|
2002-11-14 23:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
/* Returns true if the key has been handled and should be discarded, false if
|
|
|
|
|
* the key should be sent on to screens. */
|
|
|
|
|
bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput GameI, MenuInput MenuI, StyleInput StyleI )
|
2002-12-15 20:16:14 +00:00
|
|
|
{
|
2003-03-09 00:55:49 +00:00
|
|
|
/* None of the globals keys act on types other than FIRST_PRESS */
|
2003-03-09 03:28:34 +00:00
|
|
|
if( type != IET_FIRST_PRESS )
|
2003-03-09 00:55:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
switch( MenuI.button )
|
2002-12-15 20:16:14 +00:00
|
|
|
{
|
2003-02-12 17:36:54 +00:00
|
|
|
case MENU_BUTTON_OPERATOR:
|
2003-02-12 11:43:08 +00:00
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
/* Global operator key, to get quick access to the options menu. Don't
|
|
|
|
|
* do this if we're on a "system menu", which includes the editor
|
|
|
|
|
* (to prevent quitting without storing changes). */
|
|
|
|
|
if( !GAMESTATE->m_bIsOnSystemMenu )
|
|
|
|
|
{
|
|
|
|
|
SCREENMAN->SystemMessage( "OPERATOR" );
|
|
|
|
|
SCREENMAN->SetNewScreen( "ScreenOptionsMenu" );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2003-02-12 11:43:08 +00:00
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
case MENU_BUTTON_COIN:
|
|
|
|
|
/* Handle a coin insertion. */
|
2003-03-09 00:55:49 +00:00
|
|
|
if( GAMESTATE->m_bEditing ) // no coins while editing
|
2003-02-19 05:46:09 +00:00
|
|
|
break;
|
2003-03-09 00:55:49 +00:00
|
|
|
GAMESTATE->m_iCoins++;
|
|
|
|
|
SCREENMAN->RefreshCreditsMessages();
|
2003-04-12 17:39:27 +00:00
|
|
|
SOUNDMAN->PlayOnce( THEME->GetPathToS("Common coin") );
|
2003-03-09 00:55:49 +00:00
|
|
|
return false; // Attract need to know because they go to TitleMenu on > 1 credit
|
2003-02-12 17:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-18 09:33:22 +00:00
|
|
|
#ifndef DARWIN
|
2003-02-12 17:36:54 +00:00
|
|
|
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_F4))
|
|
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
|
|
|
|
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
2002-12-15 20:16:14 +00:00
|
|
|
{
|
2003-02-12 17:36:54 +00:00
|
|
|
// pressed Alt+F4
|
2003-04-12 16:06:06 +00:00
|
|
|
ExitGame();
|
2003-02-12 17:36:54 +00:00
|
|
|
return true;
|
2002-12-15 20:16:14 +00:00
|
|
|
}
|
2003-02-12 17:36:54 +00:00
|
|
|
}
|
2003-06-18 09:33:22 +00:00
|
|
|
#else
|
2003-07-09 06:36:00 +00:00
|
|
|
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_q))
|
|
|
|
|
{
|
|
|
|
|
if(INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_RMETA)) ||
|
|
|
|
|
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_LMETA)))
|
|
|
|
|
{
|
|
|
|
|
// pressed CMD-Q
|
|
|
|
|
ExitGame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-18 09:33:22 +00:00
|
|
|
#endif
|
2003-05-22 05:28:37 +00:00
|
|
|
|
2003-06-18 09:33:22 +00:00
|
|
|
#ifndef DARWIN
|
2003-07-09 06:36:00 +00:00
|
|
|
/* XXX: Er, this doesn't work; Windows traps this key and takes a screenshot
|
|
|
|
|
* into the clipboard. I don't want to disable that, though; it's useful. */
|
2003-06-07 10:58:31 +00:00
|
|
|
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_SYSREQ))
|
2003-06-18 09:33:22 +00:00
|
|
|
#else
|
2003-07-09 06:36:00 +00:00
|
|
|
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_KP_MULTIPLY))
|
2003-06-18 09:33:22 +00:00
|
|
|
#endif
|
2003-07-09 06:36:00 +00:00
|
|
|
{
|
2003-05-22 05:28:37 +00:00
|
|
|
// Save Screenshot.
|
2003-02-12 17:36:54 +00:00
|
|
|
CString sPath;
|
2003-06-18 09:33:22 +00:00
|
|
|
for( int i=0; i<10000; i++ )
|
2003-02-12 17:36:54 +00:00
|
|
|
{
|
|
|
|
|
sPath = ssprintf("screen%04d.bmp",i);
|
|
|
|
|
if( !DoesFileExist(sPath) )
|
|
|
|
|
break;
|
2003-01-31 22:34:04 +00:00
|
|
|
}
|
2003-02-12 17:36:54 +00:00
|
|
|
DISPLAY->SaveScreenshot( sPath );
|
|
|
|
|
SCREENMAN->SystemMessage( "Saved screenshot: " + sPath );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-12-15 20:16:14 +00:00
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_RETURN))
|
|
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
if( INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
|
|
|
|
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
2002-12-15 20:16:14 +00:00
|
|
|
{
|
2003-02-12 17:36:54 +00:00
|
|
|
/* alt-enter */
|
|
|
|
|
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
return true;
|
2002-12-15 20:16:14 +00:00
|
|
|
}
|
2003-02-12 17:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-12-15 20:16:14 +00:00
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
static void HandleInputEvents(float fDeltaTime)
|
|
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
INPUTFILTER->Update( fDeltaTime );
|
|
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
static InputEventArray ieArray;
|
|
|
|
|
ieArray.clear(); // empty the array
|
2003-02-16 01:35:48 +00:00
|
|
|
INPUTFILTER->GetInputEvents( ieArray );
|
2003-07-14 20:09:50 +00:00
|
|
|
|
|
|
|
|
/* If we don't have focus, discard input. */
|
|
|
|
|
if( !g_bHasFocus )
|
|
|
|
|
return;
|
|
|
|
|
|
2003-02-12 17:36:54 +00:00
|
|
|
for( unsigned i=0; i<ieArray.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
DeviceInput DeviceI = (DeviceInput)ieArray[i];
|
|
|
|
|
InputEventType type = ieArray[i].type;
|
2002-12-15 20:16:14 +00:00
|
|
|
GameInput GameI;
|
|
|
|
|
MenuInput MenuI;
|
|
|
|
|
StyleInput StyleI;
|
|
|
|
|
|
|
|
|
|
INPUTMAPPER->DeviceToGame( DeviceI, GameI );
|
|
|
|
|
|
|
|
|
|
if( GameI.IsValid() && type == IET_FIRST_PRESS )
|
|
|
|
|
INPUTQUEUE->RememberInput( GameI );
|
|
|
|
|
if( GameI.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
INPUTMAPPER->GameToMenu( GameI, MenuI );
|
|
|
|
|
INPUTMAPPER->GameToStyle( GameI, StyleI );
|
|
|
|
|
}
|
2003-02-12 17:36:54 +00:00
|
|
|
|
|
|
|
|
// HACK: Numlock is read is being pressed if the NumLock light is on.
|
|
|
|
|
// Filter out all NumLock repeat messages
|
|
|
|
|
if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == SDLK_NUMLOCK && type != IET_FIRST_PRESS )
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
|
|
|
|
if( HandleGlobalInputs(DeviceI, type, GameI, MenuI, StyleI ) )
|
|
|
|
|
continue; // skip
|
2003-02-12 11:43:08 +00:00
|
|
|
|
2002-12-15 20:16:14 +00:00
|
|
|
SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-12 16:06:06 +00:00
|
|
|
static void HandleSDLEvents()
|
2002-11-14 23:54:40 +00:00
|
|
|
{
|
2003-03-17 06:20:57 +00:00
|
|
|
// process all queued events
|
|
|
|
|
SDL_Event event;
|
2003-04-12 19:03:02 +00:00
|
|
|
while(SDL_GetEvent(event, SDL_QUITMASK|SDL_ACTIVEEVENTMASK))
|
2002-10-28 05:30:45 +00:00
|
|
|
{
|
2003-03-17 06:20:57 +00:00
|
|
|
switch(event.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
|
LOG->Trace("SDL_QUIT: shutting down");
|
2003-04-12 16:06:06 +00:00
|
|
|
ExitGame();
|
2003-03-17 06:20:57 +00:00
|
|
|
break;
|
2003-04-12 16:06:06 +00:00
|
|
|
|
2003-03-17 06:20:57 +00:00
|
|
|
case SDL_ACTIVEEVENT:
|
2003-05-26 09:18:44 +00:00
|
|
|
{
|
|
|
|
|
/* We don't care about mouse focus. */
|
|
|
|
|
if(event.active.state == SDL_APPMOUSEFOCUS)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
Uint8 i = SDL_GetAppState();
|
|
|
|
|
|
|
|
|
|
g_bHasFocus = i&SDL_APPINPUTFOCUS && i&SDL_APPACTIVE;
|
|
|
|
|
LOG->Trace("App %s focus (%i%i)", g_bHasFocus? "has":"doesn't have",
|
|
|
|
|
i&SDL_APPINPUTFOCUS, i&SDL_APPACTIVE);
|
|
|
|
|
|
|
|
|
|
if(g_bHasFocus)
|
|
|
|
|
BoostAppPri();
|
|
|
|
|
else
|
2003-06-25 06:31:13 +00:00
|
|
|
{
|
2003-05-26 09:18:44 +00:00
|
|
|
RestoreAppPri();
|
2003-06-25 06:31:13 +00:00
|
|
|
|
|
|
|
|
/* If we lose focus, we may lose input events, especially key
|
|
|
|
|
* releases. */
|
|
|
|
|
INPUTFILTER->Reset();
|
|
|
|
|
}
|
2003-05-26 09:18:44 +00:00
|
|
|
}
|
2002-10-28 05:30:45 +00:00
|
|
|
}
|
2003-03-17 06:20:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void GameLoop()
|
|
|
|
|
{
|
|
|
|
|
RageTimer timer;
|
2003-04-12 16:06:06 +00:00
|
|
|
while(!g_bQuitting)
|
2003-03-17 06:20:57 +00:00
|
|
|
{
|
2003-04-12 16:06:06 +00:00
|
|
|
/* This needs to be called before anything that handles SDL events. */
|
|
|
|
|
SDL_PumpEvents();
|
|
|
|
|
HandleSDLEvents();
|
2001-12-19 01:50:57 +00:00
|
|
|
|
2002-11-01 20:01:59 +00:00
|
|
|
/*
|
2002-11-11 04:53:31 +00:00
|
|
|
* Update
|
|
|
|
|
*/
|
2002-12-19 23:13:52 +00:00
|
|
|
float fDeltaTime = timer.GetDeltaTime();
|
2002-11-11 04:53:31 +00:00
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_TAB) ) ) {
|
|
|
|
|
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
2002-11-11 08:52:07 +00:00
|
|
|
fDeltaTime = 0; /* both; stop time */
|
|
|
|
|
else
|
|
|
|
|
fDeltaTime *= 4;
|
|
|
|
|
} else
|
2003-02-16 01:35:48 +00:00
|
|
|
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
2002-11-11 08:52:07 +00:00
|
|
|
fDeltaTime /= 4;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-04-12 16:06:06 +00:00
|
|
|
DISPLAY->Update( fDeltaTime );
|
2002-11-28 20:48:00 +00:00
|
|
|
TEXTUREMAN->Update( fDeltaTime );
|
2003-02-26 23:26:57 +00:00
|
|
|
GAMESTATE->Update( fDeltaTime );
|
2002-11-11 04:53:31 +00:00
|
|
|
SCREENMAN->Update( fDeltaTime );
|
2002-12-15 10:35:39 +00:00
|
|
|
SOUNDMAN->Update( fDeltaTime );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-03-17 06:20:57 +00:00
|
|
|
/* Important: Process input AFTER updating game logic, or input will be acting on song beat from last frame */
|
2003-02-17 02:45:30 +00:00
|
|
|
HandleInputEvents( fDeltaTime );
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/*
|
|
|
|
|
* Render
|
|
|
|
|
*/
|
2003-03-17 06:20:57 +00:00
|
|
|
SCREENMAN->Draw();
|
2002-09-18 20:42:33 +00:00
|
|
|
|
2003-01-19 11:00:53 +00:00
|
|
|
if(g_bHasFocus)
|
2003-04-21 07:43:39 +00:00
|
|
|
SDL_Delay( 1 ); // give some time to other processes and threads
|
2003-01-19 11:00:53 +00:00
|
|
|
else
|
2003-03-06 23:08:21 +00:00
|
|
|
SDL_Delay( 10 );// give some time to other processes and threads
|
2002-11-11 04:53:31 +00:00
|
|
|
}
|
2003-02-15 00:11:46 +00:00
|
|
|
}
|