2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.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
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Includes
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
//
|
|
|
|
|
// Rage global classes
|
|
|
|
|
//
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "RageDisplay.h"
|
|
|
|
|
#include "RageTextureManager.h"
|
|
|
|
|
#include "RageSound.h"
|
2002-11-11 08:52:07 +00:00
|
|
|
//#include "RageSoundManager.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageMusic.h"
|
|
|
|
|
#include "RageInput.h"
|
|
|
|
|
#include "RageTimer.h"
|
|
|
|
|
#include "RageException.h"
|
2002-10-28 05:30:45 +00:00
|
|
|
#include "RageNetwork.h"
|
|
|
|
|
#include "RageMath.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
|
2002-10-24 03:56:46 +00:00
|
|
|
#include "SDL.h"
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "SDL_syswm.h" // for SDL_SysWMinfo
|
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"
|
2002-02-28 19:40:40 +00:00
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "SongManager.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#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"
|
2002-04-16 17:31:00 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// StepMania common classes
|
|
|
|
|
//
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "GameConstantsAndTypes.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
//#include "tls.h"
|
|
|
|
|
//#include "crash.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
|
#include "SDL_opengl.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/SDLmaind.lib")
|
|
|
|
|
#else
|
|
|
|
|
#pragma comment(lib, "SDL-1.2.5/lib/SDLmain.lib")
|
|
|
|
|
#endif
|
|
|
|
|
#pragma comment(lib, "opengl32.lib")
|
2002-11-14 23:54:40 +00:00
|
|
|
#pragma comment(lib, "glu32.Lib")
|
2002-11-11 04:53:31 +00:00
|
|
|
#pragma comment(lib, "d3dx8.lib")
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-11-08 08:17:59 +00:00
|
|
|
// command line arguments
|
|
|
|
|
CString g_sSongPath = "";
|
|
|
|
|
bool g_bBeClient = false;
|
|
|
|
|
bool g_bBeServer = false;
|
|
|
|
|
CString g_sServerIP = "";
|
|
|
|
|
int g_iNumClients = 0;
|
|
|
|
|
|
|
|
|
|
const int SM_PORT = 26573; // Quake port + "Ko" + "na" + "mitsu"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/*------------------------------------------------
|
|
|
|
|
Common stuff
|
|
|
|
|
------------------------------------------------*/
|
|
|
|
|
int flags = 0; /* SDL video flags */
|
|
|
|
|
int bpp = 0; /* Preferred screen bpp */
|
|
|
|
|
int window_w = SCREEN_WIDTH, window_h = SCREEN_HEIGHT; /* window width and height */
|
|
|
|
|
SDL_Surface *loading_screen = NULL;
|
|
|
|
|
CString g_sErrorString = "";
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
void ChangeToDirOfExecutable()
|
2002-07-03 21:27:26 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
//
|
|
|
|
|
// Make sure the current directory is the root program directory
|
|
|
|
|
//
|
|
|
|
|
if( !DoesFileExist("Songs") )
|
2002-11-08 08:17:59 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
// change dir to path of the execuctable
|
|
|
|
|
TCHAR szFullAppPath[MAX_PATH];
|
|
|
|
|
GetModuleFileName(NULL, szFullAppPath, MAX_PATH);
|
|
|
|
|
|
|
|
|
|
// strip off executable name
|
|
|
|
|
LPSTR pLastBackslash = strrchr(szFullAppPath, '\\');
|
|
|
|
|
*pLastBackslash = '\0'; // terminate the string
|
2002-08-30 01:06:23 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SetCurrentDirectory( szFullAppPath );
|
2002-08-30 01:06:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2002-07-03 21:27:26 +00:00
|
|
|
|
2002-08-30 01:06:23 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
void PaintLoadingWindow()
|
|
|
|
|
{
|
|
|
|
|
SDL_UpdateRect(loading_screen, 0,0,0,0);
|
|
|
|
|
}
|
2002-10-02 01:58:03 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
void CreateLoadingWindow()
|
|
|
|
|
{
|
|
|
|
|
ASSERT( loading_screen == NULL );
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Initialize the SDL library */
|
|
|
|
|
if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 )
|
|
|
|
|
throw RageException( "Couldn't initialize SDL: %s\n", SDL_GetError() );
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SDL_Surface *image;
|
2002-07-03 21:27:26 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Load the BMP file into a surface */
|
|
|
|
|
image = SDL_LoadBMP("loading.bmp");
|
|
|
|
|
if( image == NULL )
|
|
|
|
|
throw RageException("Couldn't load loading.bmp: %s\n",SDL_GetError());
|
2002-03-06 08:25:09 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Initialize the display in a 640x480 16-bit mode */
|
|
|
|
|
loading_screen = SDL_SetVideoMode(image->w, image->h, 16, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_NOFRAME);
|
|
|
|
|
if( loading_screen == NULL )
|
|
|
|
|
throw RageException( "Couldn't initialize loading window: %s\n", SDL_GetError() );
|
2002-03-06 08:25:09 +00:00
|
|
|
|
2002-11-12 09:31:08 +00:00
|
|
|
SDL_WM_SetCaption("StepMania", "StepMania");
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Blit onto the screen surface */
|
|
|
|
|
SDL_Rect dest;
|
|
|
|
|
dest.x = 0;
|
|
|
|
|
dest.y = 0;
|
|
|
|
|
dest.w = (Uint16)image->w;
|
|
|
|
|
dest.h = (Uint16)image->h;
|
|
|
|
|
SDL_BlitSurface(image, NULL, loading_screen, NULL);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SDL_WM_SetCaption( "StepMania", NULL);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
PaintLoadingWindow();
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/* Free the allocated BMP surface */
|
|
|
|
|
SDL_FreeSurface(image);
|
2002-07-31 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DestroyLoadingWindow()
|
|
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
SDL_QuitSubSystem( SDL_INIT_VIDEO );
|
|
|
|
|
loading_screen = NULL;
|
2002-07-31 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-05 05:33:33 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Name: ErrorWndProc()
|
|
|
|
|
// Desc: Callback for all Windows messages
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
BOOL CALLBACK ErrorWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
|
|
|
|
|
{
|
|
|
|
|
switch( msg )
|
|
|
|
|
{
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
CString sMessage = g_sErrorString;
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2002-03-30 20:00:13 +00:00
|
|
|
sMessage.Replace( "\n", "\r\n" );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2002-02-05 05:33:33 +00:00
|
|
|
SendDlgItemMessage(
|
|
|
|
|
hWnd,
|
|
|
|
|
IDC_EDIT_ERROR,
|
|
|
|
|
WM_SETTEXT,
|
|
|
|
|
0,
|
2002-03-30 20:00:13 +00:00
|
|
|
(LPARAM)(LPCTSTR)sMessage
|
2002-02-05 05:33:33 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
case IDC_BUTTON_VIEW_LOG:
|
|
|
|
|
{
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
ZeroMemory( &si, sizeof(si) );
|
|
|
|
|
|
|
|
|
|
CreateProcess(
|
|
|
|
|
NULL, // pointer to name of executable module
|
|
|
|
|
"notepad.exe log.txt", // pointer to command line string
|
|
|
|
|
NULL, // process security attributes
|
|
|
|
|
NULL, // thread security attributes
|
|
|
|
|
false, // handle inheritance flag
|
|
|
|
|
0, // creation flags
|
|
|
|
|
NULL, // pointer to new environment block
|
|
|
|
|
NULL, // pointer to current directory name
|
|
|
|
|
&si, // pointer to STARTUPINFO
|
|
|
|
|
&pi // pointer to PROCESS_INFORMATION
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IDC_BUTTON_REPORT:
|
2002-05-01 19:14:55 +00:00
|
|
|
GotoURL( "http://sourceforge.net/tracker/?func=add&group_id=37892&atid=421366" );
|
2002-02-05 05:33:33 +00:00
|
|
|
break;
|
|
|
|
|
case IDC_BUTTON_RESTART:
|
|
|
|
|
{
|
2002-10-20 03:53:45 +00:00
|
|
|
/* Clear the startup mutex, since we're starting a new
|
2002-11-11 04:53:31 +00:00
|
|
|
* instance before ending ourself. */
|
2002-10-20 03:53:45 +00:00
|
|
|
TCHAR szFullAppPath[MAX_PATH];
|
|
|
|
|
GetModuleFileName(NULL, szFullAppPath, MAX_PATH);
|
|
|
|
|
|
2002-02-05 05:33:33 +00:00
|
|
|
// Launch StepMania
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
ZeroMemory( &si, sizeof(si) );
|
|
|
|
|
|
|
|
|
|
CreateProcess(
|
|
|
|
|
NULL, // pointer to name of executable module
|
2002-10-20 03:53:45 +00:00
|
|
|
szFullAppPath, // pointer to command line string
|
2002-02-05 05:33:33 +00:00
|
|
|
NULL, // process security attributes
|
|
|
|
|
NULL, // thread security attributes
|
|
|
|
|
false, // handle inheritance flag
|
|
|
|
|
0, // creation flags
|
|
|
|
|
NULL, // pointer to new environment block
|
|
|
|
|
NULL, // pointer to current directory name
|
|
|
|
|
&si, // pointer to STARTUPINFO
|
|
|
|
|
&pi // pointer to PROCESS_INFORMATION
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
|
|
|
|
// fall through
|
|
|
|
|
case IDOK:
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-11-11 04:53:31 +00:00
|
|
|
// Name: ApplyGraphicOptions()
|
|
|
|
|
// Desc:
|
2001-11-03 10:52:42 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-11-11 04:53:31 +00:00
|
|
|
void ApplyGraphicOptions()
|
|
|
|
|
{
|
2002-11-12 09:31:08 +00:00
|
|
|
bool ReloadTextures = DISPLAY->SetVideoMode(
|
2002-11-11 04:53:31 +00:00
|
|
|
PREFSMAN->m_bWindowed,
|
|
|
|
|
PREFSMAN->m_iDisplayWidth,
|
|
|
|
|
PREFSMAN->m_iDisplayHeight,
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth,
|
2002-11-12 09:31:08 +00:00
|
|
|
PREFSMAN->m_iRefreshRate,
|
2002-11-11 04:53:31 +00:00
|
|
|
PREFSMAN->m_bVsync );
|
2002-11-12 09:31:08 +00:00
|
|
|
|
|
|
|
|
if(TEXTUREMAN->SetPrefs( PREFSMAN->m_iTextureColorDepth, PREFSMAN->m_iUnloadTextureDelaySeconds ))
|
|
|
|
|
ReloadTextures = true;
|
|
|
|
|
|
|
|
|
|
if(ReloadTextures)
|
|
|
|
|
TEXTUREMAN->ReloadAll();
|
2002-11-11 04:53:31 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
void GameLoop();
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Name: WinMain()
|
|
|
|
|
// Desc: Application entry point
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
ChangeToDirOfExecutable();
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
atexit(SDL_Quit); /* Clean up on exit */
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/*
|
|
|
|
|
* Handle command line args
|
|
|
|
|
*/
|
|
|
|
|
for(int i=0; i<argc; i++)
|
|
|
|
|
{
|
2002-11-11 08:53:26 +00:00
|
|
|
if(!strcmp(argv[i], "--fsck"))
|
2002-11-11 04:53:31 +00:00
|
|
|
;//crash();
|
2002-11-11 08:53:26 +00:00
|
|
|
else if(!strcmp(argv[i], "--song"))
|
2002-11-11 04:53:31 +00:00
|
|
|
g_sSongPath = argv[++i];
|
2002-11-11 08:53:26 +00:00
|
|
|
else if(!strcmp(argv[i], "--client"))
|
2002-11-11 04:53:31 +00:00
|
|
|
g_bBeClient = true;
|
2002-11-11 08:53:26 +00:00
|
|
|
else if(!strcmp(argv[i], "--server"))
|
2002-11-11 04:53:31 +00:00
|
|
|
g_bBeServer = true;
|
2002-11-11 08:53:26 +00:00
|
|
|
else if(!strcmp(argv[i], "--ip"))
|
2002-11-11 04:53:31 +00:00
|
|
|
g_sServerIP = argv[++i];
|
2002-11-11 08:53:26 +00:00
|
|
|
else if(!strcmp(argv[i], "--numclients"))
|
2002-11-11 04:53:31 +00:00
|
|
|
g_iNumClients = atoi(argv[++i]);
|
|
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
|
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
|
|
|
|
|
#endif
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
// SetUnhandledExceptionFilter(CrashHandler);
|
|
|
|
|
// InitThreadData("Main thread");
|
|
|
|
|
// VDCHECKPOINT;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SDL_Init(0); /* Fire up the SDL, but don't actually start any subsystems. */
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
atexit(SDL_Quit);
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
#ifndef _DEBUG
|
|
|
|
|
try{
|
|
|
|
|
#endif
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
CreateLoadingWindow();
|
|
|
|
|
PaintLoadingWindow();
|
2001-12-11 11:25:37 +00:00
|
|
|
|
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-01-24 08:01:24 +00:00
|
|
|
srand( (unsigned)time(NULL) ); // seed number generator
|
|
|
|
|
|
2002-06-14 22:25:22 +00:00
|
|
|
LOG = new RageLog();
|
2002-07-23 01:41:40 +00:00
|
|
|
#ifdef _DEBUG
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->ShowConsole();
|
2002-07-23 01:41:40 +00:00
|
|
|
#endif
|
2002-06-14 22:25:22 +00:00
|
|
|
TIMER = new RageTimer;
|
2002-07-23 01:41:40 +00:00
|
|
|
GAMESTATE = new GameState;
|
2002-05-27 08:23:27 +00:00
|
|
|
PREFSMAN = new PrefsManager;
|
2002-06-14 22:25:22 +00:00
|
|
|
GAMEMAN = new GameManager;
|
|
|
|
|
THEME = new ThemeManager;
|
2002-11-11 04:53:31 +00:00
|
|
|
SOUND = new RageSound;
|
2002-07-23 01:41:40 +00:00
|
|
|
MUSIC = new RageSoundStream;
|
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;
|
|
|
|
|
NETWORK = new RageNetwork;
|
|
|
|
|
INPUTQUEUE = new InputQueue;
|
|
|
|
|
SONGINDEX = new SongCacheIndex;
|
2002-08-21 02:13:08 +00:00
|
|
|
/* depends on SONGINDEX: */
|
2002-07-31 19:40:40 +00:00
|
|
|
SONGMAN = new SongManager( PaintLoadingWindow ); // this takes a long time to load
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
DestroyLoadingWindow(); // destroy this before init'ing Display
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
PREFSMAN->ReadGlobalPrefsFromDisk( true );
|
2001-12-11 11:25:37 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
DISPLAY = new RageDisplay(
|
|
|
|
|
PREFSMAN->m_bWindowed,
|
|
|
|
|
PREFSMAN->m_iDisplayWidth,
|
|
|
|
|
PREFSMAN->m_iDisplayHeight,
|
|
|
|
|
PREFSMAN->m_iDisplayColorDepth,
|
2002-11-12 09:31:08 +00:00
|
|
|
PREFSMAN->m_iRefreshRate,
|
2002-11-11 04:53:31 +00:00
|
|
|
PREFSMAN->m_bVsync );
|
|
|
|
|
TEXTUREMAN = new RageTextureManager( PREFSMAN->m_iTextureColorDepth, PREFSMAN->m_iUnloadTextureDelaySeconds );
|
2002-03-30 20:00:13 +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 )
|
|
|
|
|
throw RageException( "SDL_GetWMInfo failed" );
|
|
|
|
|
HWND hwnd = info.window;
|
2002-09-21 16:29:14 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
INPUTMAN = new RageInput( hwnd );
|
2002-11-11 08:52:07 +00:00
|
|
|
// SOUNDMAN = new RageSoundManager( hwnd );
|
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
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/*
|
|
|
|
|
* Load initial screen depending on network mode
|
|
|
|
|
*/
|
2002-11-08 08:17:59 +00:00
|
|
|
if( g_bBeClient )
|
|
|
|
|
{
|
|
|
|
|
// immediately try to connect to server
|
|
|
|
|
GAMESTATE->m_pCurSong = SONGMAN->GetSongFromPath( g_sSongPath );
|
|
|
|
|
if( GAMESTATE->m_pCurSong == NULL )
|
|
|
|
|
throw RageException( "The song '%s' is required to play this network game.", g_sSongPath );
|
|
|
|
|
NETWORK->Init( false );
|
|
|
|
|
if( !NETWORK->Connect( (const char*)g_sServerIP, SM_PORT ) )
|
|
|
|
|
throw RageException( "Could not connect to server '%s'", g_sServerIP );
|
|
|
|
|
SCREENMAN->SetNewScreen( "ScreenSandbox" );
|
|
|
|
|
}
|
|
|
|
|
else if( g_bBeServer )
|
|
|
|
|
{
|
|
|
|
|
// wait for clients to connect
|
|
|
|
|
GAMESTATE->m_pCurSong = SONGMAN->GetSongFromPath( g_sSongPath );
|
|
|
|
|
if( GAMESTATE->m_pCurSong == NULL )
|
|
|
|
|
throw RageException( "The song '%s' is required to play this network game.", g_sSongPath );
|
|
|
|
|
NETWORK->Init( true );
|
|
|
|
|
if( !NETWORK->Listen( SM_PORT ) )
|
|
|
|
|
throw RageException( "Could not connect to server '%s'", g_sServerIP );
|
|
|
|
|
SCREENMAN->SetNewScreen( "ScreenSandbox" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// normal game
|
|
|
|
|
SCREENMAN->SetNewScreen( "ScreenTitleMenu" );
|
|
|
|
|
// SCREENMAN->SetNewScreen( "ScreenSandbox" );
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
/* Run the main loop. */
|
|
|
|
|
GameLoop();
|
|
|
|
|
|
|
|
|
|
#ifndef _DEBUG
|
|
|
|
|
}
|
|
|
|
|
catch( RageException e )
|
|
|
|
|
{
|
|
|
|
|
g_sErrorString = e.what();
|
|
|
|
|
|
|
|
|
|
LOG->Trace(
|
|
|
|
|
"\n"
|
|
|
|
|
"//////////////////////////////////////////////////////\n"
|
|
|
|
|
"Exception: %s\n"
|
|
|
|
|
"//////////////////////////////////////////////////////\n"
|
|
|
|
|
"\n",
|
|
|
|
|
g_sErrorString.GetString()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
LOG->Flush();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-12-19 14:56:22 +00:00
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
SAFE_DELETE( SCREENMAN );
|
|
|
|
|
SAFE_DELETE( NETWORK );
|
|
|
|
|
SAFE_DELETE( INPUTQUEUE );
|
|
|
|
|
SAFE_DELETE( INPUTMAPPER );
|
|
|
|
|
SAFE_DELETE( INPUTFILTER );
|
|
|
|
|
SAFE_DELETE( SONGMAN );
|
|
|
|
|
SAFE_DELETE( SONGINDEX );
|
|
|
|
|
SAFE_DELETE( PREFSMAN );
|
|
|
|
|
SAFE_DELETE( GAMESTATE );
|
|
|
|
|
SAFE_DELETE( GAMEMAN );
|
|
|
|
|
SAFE_DELETE( THEME );
|
|
|
|
|
SAFE_DELETE( ANNOUNCER );
|
|
|
|
|
SAFE_DELETE( INPUTMAN );
|
|
|
|
|
SAFE_DELETE( MUSIC );
|
|
|
|
|
SAFE_DELETE( SOUND );
|
|
|
|
|
// SAFE_DELETE( SOUNDMAN );
|
|
|
|
|
SAFE_DELETE( TIMER );
|
|
|
|
|
SAFE_DELETE( FONT );
|
|
|
|
|
SAFE_DELETE( TEXTUREMAN );
|
|
|
|
|
SAFE_DELETE( DISPLAY );
|
|
|
|
|
SAFE_DELETE( LOG );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( g_sErrorString != "" )
|
|
|
|
|
{
|
|
|
|
|
// throw up a pretty error dialog
|
|
|
|
|
DialogBox(
|
|
|
|
|
NULL,
|
|
|
|
|
MAKEINTRESOURCE(IDD_ERROR_DIALOG),
|
|
|
|
|
NULL,
|
|
|
|
|
ErrorWndProc
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameLoop()
|
|
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
bool do_exit = false;
|
|
|
|
|
SDL_Event event;
|
|
|
|
|
while(!do_exit)
|
2002-10-28 05:30:45 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
// process all queued events
|
|
|
|
|
while(SDL_PollEvent(&event))
|
2002-10-28 05:30:45 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
switch(event.type)
|
2002-10-28 05:30:45 +00:00
|
|
|
{
|
2002-11-11 04:53:31 +00:00
|
|
|
case SDL_QUIT:
|
|
|
|
|
do_exit = 1;
|
|
|
|
|
break;
|
|
|
|
|
case SDL_VIDEORESIZE:
|
|
|
|
|
PREFSMAN->m_iDisplayWidth = event.resize.w;
|
|
|
|
|
PREFSMAN->m_iDisplayHeight = event.resize.h;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
break;
|
2002-10-28 05:30:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
2001-12-19 01:50:57 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
DISPLAY->Clear();
|
|
|
|
|
DISPLAY->ResetMatrixStack();
|
2001-12-19 01:50:57 +00:00
|
|
|
|
2002-10-28 05:30:45 +00:00
|
|
|
|
2002-11-01 20:01:59 +00:00
|
|
|
/*
|
2002-11-11 04:53:31 +00:00
|
|
|
* Update
|
|
|
|
|
*/
|
|
|
|
|
float fDeltaTime = TIMER->GetDeltaTime();
|
|
|
|
|
|
|
|
|
|
// This was a hack to fix timing issues with the old ScreenSelectSong
|
|
|
|
|
// See ScreenManager::Update comments for why we shouldn't do this. -glenn
|
|
|
|
|
//if( fDeltaTime > 0.050f ) // we dropped a bunch of frames
|
|
|
|
|
// fDeltaTime = 0.050f;
|
2002-11-11 08:52:07 +00:00
|
|
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_TAB) ) ) {
|
|
|
|
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_GRAVE) ) )
|
|
|
|
|
fDeltaTime = 0; /* both; stop time */
|
|
|
|
|
else
|
|
|
|
|
fDeltaTime *= 4;
|
|
|
|
|
} else
|
|
|
|
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_GRAVE) ) )
|
|
|
|
|
fDeltaTime /= 4;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
MUSIC->Update( fDeltaTime );
|
|
|
|
|
SCREENMAN->Update( fDeltaTime );
|
|
|
|
|
NETWORK->Update( fDeltaTime );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-08-29 23:05:54 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
static InputEventArray ieArray;
|
|
|
|
|
ieArray.clear(); // empty the array
|
|
|
|
|
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
|
|
|
|
|
for( unsigned i=0; i<ieArray.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
DeviceInput DeviceI = (DeviceInput)ieArray[i];
|
|
|
|
|
InputEventType type = ieArray[i].type;
|
2002-11-11 09:06:30 +00:00
|
|
|
|
|
|
|
|
/* ALT-F4 -> quit (better place for this? in ScreenManager perhaps?) */
|
2002-11-12 11:11:16 +00:00
|
|
|
/* Nah. this is fine. -Chris */
|
|
|
|
|
if(type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, DIK_F4))
|
2002-11-11 09:06:30 +00:00
|
|
|
{
|
2002-11-12 11:11:16 +00:00
|
|
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_RMENU)) ||
|
|
|
|
|
INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_LMENU)) )
|
|
|
|
|
{
|
|
|
|
|
// pressed Alt+F4
|
|
|
|
|
SDL_Event *event;
|
|
|
|
|
event = (SDL_Event *) malloc(sizeof(event));
|
|
|
|
|
event->type = SDL_QUIT;
|
|
|
|
|
SDL_PushEvent(event);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// pressed just F4
|
|
|
|
|
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
2002-11-11 09:06:30 +00:00
|
|
|
}
|
2002-11-12 11:11:16 +00:00
|
|
|
else if( type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, DIK_F5))
|
|
|
|
|
{
|
|
|
|
|
// pressed F5. Toggle detail.
|
|
|
|
|
if(PREFSMAN->m_iDisplayWidth != 640)
|
|
|
|
|
{
|
|
|
|
|
PREFSMAN->m_iDisplayWidth = 640;
|
|
|
|
|
PREFSMAN->m_iDisplayHeight = 480;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PREFSMAN->m_iDisplayWidth = 320;
|
|
|
|
|
PREFSMAN->m_iDisplayHeight = 240;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-14 23:54:40 +00:00
|
|
|
if(type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, DIK_RETURN))
|
|
|
|
|
{
|
|
|
|
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_RMENU)) ||
|
|
|
|
|
INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_LMENU)) )
|
|
|
|
|
{
|
|
|
|
|
/* alt-enter */
|
|
|
|
|
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
|
|
|
|
|
ApplyGraphicOptions();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-11-11 09:06:30 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
GameInput GameI;
|
|
|
|
|
MenuInput MenuI;
|
|
|
|
|
StyleInput StyleI;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
INPUTMAPPER->DeviceToGame( DeviceI, GameI );
|
2002-08-18 16:19:26 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
if( GameI.IsValid() && type == IET_FIRST_PRESS )
|
|
|
|
|
INPUTQUEUE->RememberInput( GameI );
|
|
|
|
|
if( GameI.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
INPUTMAPPER->GameToMenu( GameI, MenuI );
|
|
|
|
|
INPUTMAPPER->GameToStyle( GameI, StyleI );
|
2001-11-28 20:26:45 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI );
|
|
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
/*
|
|
|
|
|
* Render
|
|
|
|
|
*/
|
|
|
|
|
DISPLAY->ResetMatrixStack();
|
2002-01-20 07:53:20 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
RageMatrix mat;
|
2002-11-14 23:54:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
RageMatrixIdentity( &mat );
|
|
|
|
|
DISPLAY->SetViewTransform( &mat );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
SCREENMAN->Draw(); // draw the game
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
DISPLAY->FlushQueue();
|
|
|
|
|
DISPLAY->Flip();
|
2002-09-18 20:42:33 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
if( DISPLAY && DISPLAY->IsWindowed() )
|
|
|
|
|
::Sleep( 0 ); // give some time to other processes
|
|
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
2002-11-14 23:54:40 +00:00
|
|
|
|