Files
itgmania212121/stepmania/src/StepMania.cpp
T

818 lines
22 KiB
C++
Raw Normal View History

2001-11-03 10:52:42 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: StepMania.cpp
Desc:
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
-----------------------------------------------------------------------------
*/
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "resource.h"
2002-04-16 17:31:00 +00:00
//
// StepMania global classes
//
2002-02-28 19:40:40 +00:00
#include "PrefsManager.h"
#include "SongManager.h"
2002-01-16 10:01:32 +00:00
#include "ThemeManager.h"
2002-05-19 01:59:48 +00:00
#include "AnnouncerManager.h"
#include "ScreenManager.h"
#include "GameManager.h"
#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-04-16 17:31:00 +00:00
//
// StepMania common classes
//
#include "Font.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-04-16 17:31:00 +00:00
#include "GameInput.h"
#include "StyleInput.h"
#include "Song.h"
#include "StyleDef.h"
#include "NoteData.h"
2002-05-19 01:59:48 +00:00
#include "Notes.h"
2001-11-03 10:52:42 +00:00
2002-05-19 01:59:48 +00:00
#include "ScreenSandbox.h"
#include "ScreenResults.h"
#include "ScreenTitleMenu.h"
#include "ScreenPlayerOptions.h"
#include "ScreenMusicScroll.h"
#include "ScreenSelectMusic.h"
2002-05-27 08:23:27 +00:00
#include "ScreenGameplay.h"
2002-02-05 05:33:33 +00:00
2002-04-16 17:31:00 +00:00
// error catcher stuff
#include "ErrorCatcher/ErrorCatcher.h"
#pragma comment(lib, "ErrorCatcher/dbghelp.lib")
#if defined(DEBUG) | defined(_DEBUG)
#pragma comment(lib, "ErrorCatcher/ErrorCatcherD.lib")
#else
#pragma comment(lib, "ErrorCatcher/ErrorCatcher.lib")
#endif
#include "dxerr8.h"
2002-02-24 01:43:11 +00:00
#include "DXUtil.h"
2002-03-06 08:25:09 +00:00
#include <Afxdisp.h>
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Links
//-----------------------------------------------------------------------------
#pragma comment(lib, "d3dx8.lib")
#pragma comment(lib, "d3d8.lib")
//-----------------------------------------------------------------------------
// Application globals
//-----------------------------------------------------------------------------
const CString g_sAppName = "StepMania";
const CString g_sAppClassName = "StepMania Class";
2002-02-05 05:33:33 +00:00
HWND g_hWndMain; // Main Window Handle
HINSTANCE g_hInstance; // The Handle to Window Instance
HANDLE g_hMutex; // Used to check if an instance of our app is already
2001-11-03 10:52:42 +00:00
const DWORD g_dwWindowStyle = WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU;
BOOL g_bIsActive = FALSE; // Whether the focus is on our app
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
// Main game functions
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
2002-02-05 05:33:33 +00:00
BOOL CALLBACK ErrorWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
2001-11-03 10:52:42 +00:00
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow ); // windows entry point
void MainLoop(); // put everything in here so we can wrap it in a try...catch block
2001-11-03 10:52:42 +00:00
void Update(); // Update the game logic
void Render(); // Render a frame
2002-05-19 01:59:48 +00:00
void ShowFrame(); // Display the contents of the back buffer to the Window
2001-11-03 10:52:42 +00:00
// Functions that work with game objects
HRESULT CreateObjects( HWND hWnd ); // allocate and initialize game objects
HRESULT InvalidateObjects(); // invalidate game objects before a display mode change
HRESULT RestoreObjects(); // restore game objects after a display mode change
VOID DestroyObjects(); // deallocate game objects when we're done with them
void ApplyGraphicOptions(); // Set the display mode according to the user's preferences
2001-11-03 10:52:42 +00:00
2002-05-27 08:23:27 +00:00
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Application entry point
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
// Initialize ActiveX for Flash
//AfxEnableControlContainer();
2001-12-19 01:50:57 +00:00
//
// Check to see if the app is already running.
//
g_hMutex = CreateMutex( NULL, TRUE, g_sAppName );
if( GetLastError() == ERROR_ALREADY_EXISTS )
{
CloseHandle( g_hMutex );
}
2002-01-16 10:01:32 +00:00
//
// Make sure the current directory is the root program directory
//
if( !DoesFileExist("Songs") )
{
// 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
SetCurrentDirectory( szFullAppPath );
}
2001-11-03 10:52:42 +00:00
CoInitialize (NULL); // Initialize COM
// Register the window class
WNDCLASS wndClass = {
0,
WndProc, // callback handler
0, // cbClsExtra;
0, // cbWndExtra;
hInstance,
LoadIcon( hInstance, MAKEINTRESOURCE(IDI_ICON) ),
LoadCursor( hInstance, IDC_ARROW),
(HBRUSH)GetStockObject( BLACK_BRUSH ),
NULL, // lpszMenuName;
g_sAppClassName // lpszClassName;
};
RegisterClass( &wndClass );
// Set the window's initial width
RECT rcWnd;
SetRect( &rcWnd, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
AdjustWindowRect( &rcWnd, g_dwWindowStyle, FALSE );
// Create our main window
g_hWndMain = CreateWindow(
g_sAppClassName,// pointer to registered class name
g_sAppName, // pointer to window name
g_dwWindowStyle, // window StyleDef
CW_USEDEFAULT, // horizontal position of window
CW_USEDEFAULT, // vertical position of window
RECTWIDTH(rcWnd), // window width
RECTHEIGHT(rcWnd),// window height
NULL, // handle to parent or owner window
NULL, // handle to menu, or child-window identifier
hInstance, // handle to application instance
NULL // pointer to window-creation data
);
if( NULL == g_hWndMain )
exit(1);
2001-11-03 10:52:42 +00:00
2002-05-19 01:59:48 +00:00
ShowWindow( g_hWndMain, SW_HIDE );
2001-11-03 10:52:42 +00:00
2002-05-27 08:23:27 +00:00
// Don't catch errors if we're running in the debugger. This way, the debugger
// will give us a nice stack trace.
#ifdef _DEBUG
#define bCatchErrors false
2002-04-16 17:31:00 +00:00
#else
2002-05-27 08:23:27 +00:00
#define bCatchErrors true
2002-04-16 17:31:00 +00:00
#endif
2002-02-05 05:33:33 +00:00
2002-05-27 08:23:27 +00:00
bool bSuccess = RunAndCatchErrors( MainLoop, bCatchErrors );
2002-03-06 08:25:09 +00:00
2002-02-05 05:33:33 +00:00
// clean up after a normal exit
DestroyObjects(); // deallocate our game objects and leave fullscreen
ShowWindow( g_hWndMain, SW_HIDE );
if( !bSuccess )
{
2002-03-06 08:25:09 +00:00
// throw up a pretty error dialog
2002-02-05 05:33:33 +00:00
DialogBox(
hInstance,
MAKEINTRESOURCE(IDD_ERROR_DIALOG),
NULL,
ErrorWndProc
);
}
2002-03-06 08:25:09 +00:00
DestroyWindow( g_hWndMain );
UnregisterClass( g_sAppClassName, hInstance );
CoUninitialize(); // Uninitialize COM
CloseHandle( g_hMutex );
2002-03-06 08:25:09 +00:00
2001-11-03 10:52:42 +00:00
return 0L;
}
void MainLoop()
{
// Load keyboard accelerators
HACCEL hAccel = LoadAccelerators( NULL, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// run the game
CreateObjects( g_hWndMain ); // Create the game objects
2002-05-19 01:59:48 +00:00
ShowWindow( g_hWndMain, SW_SHOW );
// Now we're ready to recieve and process Windows messages.
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( WM_QUIT != msg.message )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
GetMessage(&msg, NULL, 0, 0 );
// Translate and dispatch the message
if( 0 == TranslateAccelerator( g_hWndMain, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else // No messages are waiting. Render a frame during idle time.
{
Update();
Render();
2002-05-19 01:59:48 +00:00
if( DISPLAY && DISPLAY->IsWindowed() )
::Sleep( 1 ); // give some time to other processes
}
} // end while( WM_QUIT != msg.message )
}
2001-11-03 10:52:42 +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-04-16 17:31:00 +00:00
CString sMessage = ssprintf("%s", GetError() );
if( GetErrorHr() != 0 )
sMessage += ssprintf(" ('%d - %s)'", GetErrorHr(), DXGetErrorString8(GetErrorHr()) );
2002-05-27 08:23:27 +00:00
sMessage += ssprintf("\n\nStack Trace: (PDB file required for function names)", GetStackTrace() );
2002-04-16 17:31:00 +00:00
sMessage += ssprintf("\n\n%s", GetStackTrace() );
sMessage.Replace( "\n", "\r\n" );
2002-02-05 05:33:33 +00:00
SendDlgItemMessage(
hWnd,
IDC_EDIT_ERROR,
WM_SETTEXT,
0,
(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:
{
// Launch StepMania
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
CreateProcess(
NULL, // pointer to name of executable module
"stepmania.exe", // 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
);
}
EndDialog( hWnd, 0 );
break;
// fall through
case IDOK:
EndDialog( hWnd, 0 );
break;
}
}
return FALSE;
}
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Name: WndProc()
// Desc: Callback for all Windows messages
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_ACTIVATEAPP:
// Check to see if we are losing our window...
g_bIsActive = (BOOL)wParam;
break;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
2001-11-03 10:52:42 +00:00
g_bIsActive = FALSE;
else
g_bIsActive = TRUE;
break;
case WM_GETMINMAXINFO:
{
// Don't allow the window to be resized smaller than the screen resolution.
2002-05-19 01:59:48 +00:00
// This should snap to multiples of the Window size two!
2001-11-03 10:52:42 +00:00
RECT rcWnd;
SetRect( &rcWnd, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
2001-11-03 10:52:42 +00:00
DWORD dwWindowStyle = GetWindowLong( g_hWndMain, GWL_STYLE );
AdjustWindowRect( &rcWnd, dwWindowStyle, FALSE );
((MINMAXINFO*)lParam)->ptMinTrackSize.x = RECTWIDTH(rcWnd);
((MINMAXINFO*)lParam)->ptMinTrackSize.y = RECTHEIGHT(rcWnd);
}
break;
case WM_SETCURSOR:
// Turn off Windows cursor in fullscreen mode
2002-05-19 01:59:48 +00:00
if( DISPLAY && !DISPLAY->IsWindowed() )
2001-11-03 10:52:42 +00:00
{
SetCursor( NULL );
return TRUE; // prevent Windows from setting the cursor
}
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_KEYMENU:
case SC_MONITORPOWER:
return 1;
case SC_MAXIMIZE:
//SendMessage( g_hWndMain, WM_COMMAND, IDM_TOGGLEFULLSCREEN, 0 );
//return 1;
2001-11-03 10:52:42 +00:00
break;
}
break;
case WM_COMMAND:
{
2001-11-03 10:52:42 +00:00
switch( LOWORD(wParam) )
{
case IDM_TOGGLEFULLSCREEN:
2002-05-28 20:01:22 +00:00
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
ApplyGraphicOptions();
return 0;
2002-04-16 17:31:00 +00:00
case IDM_CHANGEDETAIL:
2002-05-27 08:23:27 +00:00
PREFSMAN->m_bHighDetail = !PREFSMAN->m_bHighDetail;
ApplyGraphicOptions();
return 0;
case IDM_EXIT:
2001-11-03 10:52:42 +00:00
// Recieved key/menu command to exit app
SendMessage( hWnd, WM_CLOSE, 0, 0 );
return 0;
}
break;
}
2001-11-03 10:52:42 +00:00
case WM_NCHITTEST:
// Prevent the user from selecting the menu in fullscreen mode
2002-05-19 01:59:48 +00:00
if( DISPLAY && !DISPLAY->IsWindowed() )
2001-11-03 10:52:42 +00:00
return HTCLIENT;
break;
case WM_PAINT:
// redisplay the contents of the back buffer if the window needs to be redrawn
ShowFrame();
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: CreateObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CreateObjects( HWND hWnd )
{
//
2002-05-19 01:59:48 +00:00
// Draw a splash bitmap so the user isn't looking at a black Window
//
HBITMAP hSplashBitmap = (HBITMAP)LoadImage(
GetModuleHandle( NULL ),
TEXT("BITMAP_SPLASH"),
IMAGE_BITMAP,
0, 0, LR_CREATEDIBSECTION );
BITMAP bmp;
RECT rc;
GetClientRect( hWnd, &rc );
// Display the splash bitmap in the window
HDC hDCWindow = GetDC( hWnd );
HDC hDCImage = CreateCompatibleDC( NULL );
SelectObject( hDCImage, hSplashBitmap );
GetObject( hSplashBitmap, sizeof(bmp), &bmp );
StretchBlt( hDCWindow, 0, 0, rc.right, rc.bottom,
hDCImage, 0, 0,
bmp.bmWidth, bmp.bmHeight, SRCCOPY );
DeleteDC( hDCImage );
ReleaseDC( hWnd, hDCWindow );
// Delete the bitmap
DeleteObject( hSplashBitmap );
//
// Create game objects
//
srand( (unsigned)time(NULL) ); // seed number generator
2002-05-01 19:14:55 +00:00
LOG = new RageLog();
2001-11-03 10:52:42 +00:00
SOUND = new RageSound( hWnd );
2002-01-16 10:01:32 +00:00
MUSIC = new RageSoundStream;
2002-05-19 01:59:48 +00:00
INPUTMAN= new RageInput( hWnd );
2002-05-27 08:23:27 +00:00
PREFSMAN = new PrefsManager;
2002-05-19 01:59:48 +00:00
DISPLAY = new RageDisplay( hWnd );
SONGMAN = new SongManager; // this takes a long time to load
2002-05-27 08:23:27 +00:00
GAMEMAN = new GameManager;
THEME = new ThemeManager;
2002-05-19 01:59:48 +00:00
ANNOUNCER = new AnnouncerManager;
INPUTFILTER = new InputFilter();
INPUTMAPPER = new InputMapper();
INPUTQUEUE = new InputQueue();
2001-12-20 12:37:38 +00:00
BringWindowToTop( hWnd );
SetForegroundWindow( hWnd );
// We can't do any texture loading unless the D3D device is created.
// Set the display mode to make sure the D3D device is created.
ApplyGraphicOptions();
2002-05-19 01:59:48 +00:00
TEXTUREMAN = new RageTextureManager( DISPLAY );
// These things depend on the TextureManager, so do them last!
2002-05-28 20:01:22 +00:00
FONT = new FontManager;
SCREENMAN = new ScreenManager;
2001-11-03 10:52:42 +00:00
2002-01-29 21:56:14 +00:00
2002-05-19 01:59:48 +00:00
//SCREENMAN->SetNewScreen( new ScreenLoading );
//SCREENMAN->SetNewScreen( new ScreenSandbox );
2002-05-28 20:01:22 +00:00
//SCREENMAN->SetNewScreen( new ScreenResults(false) );
2002-05-19 01:59:48 +00:00
//SCREENMAN->SetNewScreen( new ScreenPlayerOptions );
2002-05-27 08:23:27 +00:00
//SCREENMAN->SetNewScreen( new ScreenTitleMenu );
//SCREENMAN->SetNewScreen( new ScreenGameplay );
2002-05-19 01:59:48 +00:00
//SCREENMAN->SetNewScreen( new ScreenMusicScroll );
2002-05-27 08:23:27 +00:00
SCREENMAN->SetNewScreen( new ScreenSelectMusic );
2002-05-19 01:59:48 +00:00
//SCREENMAN->SetNewScreen( new ScreenSelectGroup );
2001-12-19 14:56:22 +00:00
2001-11-28 01:26:58 +00:00
DXUtil_Timer( TIMER_START ); // Start the accurate timer
2001-11-03 10:52:42 +00:00
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DestroyObjects()
// Desc:
//-----------------------------------------------------------------------------
void DestroyObjects()
{
DXUtil_Timer( TIMER_STOP );
2002-05-19 01:59:48 +00:00
SAFE_DELETE( SCREENMAN );
SAFE_DELETE( FONT );
2002-05-19 01:59:48 +00:00
SAFE_DELETE( TEXTUREMAN );
SAFE_DELETE( INPUTQUEUE );
SAFE_DELETE( INPUTMAPPER );
SAFE_DELETE( INPUTFILTER );
SAFE_DELETE( ANNOUNCER );
SAFE_DELETE( THEME );
2002-05-27 08:23:27 +00:00
SAFE_DELETE( GAMEMAN );
2002-05-19 01:59:48 +00:00
SAFE_DELETE( SONGMAN );
SAFE_DELETE( DISPLAY );
2002-05-27 08:23:27 +00:00
SAFE_DELETE( PREFSMAN );
2002-05-19 01:59:48 +00:00
SAFE_DELETE( INPUTMAN );
2001-11-03 10:52:42 +00:00
SAFE_DELETE( MUSIC );
SAFE_DELETE( SOUND );
2002-05-01 19:14:55 +00:00
SAFE_DELETE( LOG );
2001-11-03 10:52:42 +00:00
}
//-----------------------------------------------------------------------------
// Name: RestoreObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT RestoreObjects()
{
/////////////////////
// Restore the window
/////////////////////
2002-05-28 20:01:22 +00:00
2001-11-03 10:52:42 +00:00
// Set window size
RECT rcWnd;
2002-05-19 01:59:48 +00:00
if( DISPLAY->IsWindowed() )
2001-11-03 10:52:42 +00:00
{
SetRect( &rcWnd, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
2001-11-03 10:52:42 +00:00
AdjustWindowRect( &rcWnd, g_dwWindowStyle, FALSE );
}
else // if fullscreen
{
SetRect( &rcWnd, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) );
}
2001-11-03 10:52:42 +00:00
// Bring the window to the foreground
SetWindowPos( g_hWndMain,
HWND_NOTOPMOST,
0,
0,
RECTWIDTH(rcWnd),
RECTHEIGHT(rcWnd),
0 );
2002-05-28 20:01:22 +00:00
2001-11-03 10:52:42 +00:00
///////////////////////////
// Restore all game objects
///////////////////////////
2002-05-19 01:59:48 +00:00
DISPLAY->Restore();
2001-11-03 10:52:42 +00:00
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InvalidateObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT InvalidateObjects()
{
2002-05-19 01:59:48 +00:00
DISPLAY->Invalidate();
2001-11-03 10:52:42 +00:00
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Update()
// Desc:
//-----------------------------------------------------------------------------
void Update()
{
2001-12-28 10:15:59 +00:00
float fDeltaTime = DXUtil_Timer( TIMER_GETELAPSEDTIME );
2001-11-03 10:52:42 +00:00
2002-05-19 01:59:48 +00:00
// This was a hack to fix timing issues with the old ScreenSelectSong
2001-11-03 10:52:42 +00:00
//
if( fDeltaTime > 0.050f ) // we dropped a bunch of frames
2002-01-16 10:01:32 +00:00
fDeltaTime = 0.050f;
2001-11-03 10:52:42 +00:00
2002-05-19 01:59:48 +00:00
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_TAB) ) )
2002-04-16 17:31:00 +00:00
fDeltaTime *= 4;
2002-05-19 01:59:48 +00:00
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, DIK_LSHIFT) ) )
2002-04-16 17:31:00 +00:00
fDeltaTime /= 4;
2001-11-03 10:52:42 +00:00
MUSIC->Update( fDeltaTime );
2002-05-19 01:59:48 +00:00
SCREENMAN->Update( fDeltaTime );
2001-11-03 10:52:42 +00:00
2002-04-16 17:31:00 +00:00
static InputEventArray ieArray;
ieArray.SetSize( 0, 20 ); // zero the array
2002-05-19 01:59:48 +00:00
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
2001-11-03 10:52:42 +00:00
2001-12-19 01:50:57 +00:00
DeviceInput DeviceI;
2002-04-16 17:31:00 +00:00
InputEventType type;
GameInput GameI;
MenuInput MenuI;
StyleInput StyleI;
2001-12-19 01:50:57 +00:00
2002-04-16 17:31:00 +00:00
for( int i=0; i<ieArray.GetSize(); i++ )
2001-11-03 10:52:42 +00:00
{
2002-04-16 17:31:00 +00:00
DeviceI = (DeviceInput)ieArray[i];
type = ieArray[i].type;
2001-12-19 01:50:57 +00:00
2002-05-19 01:59:48 +00:00
INPUTMAPPER->DeviceToGame( DeviceI, GameI );
2002-04-16 17:31:00 +00:00
2002-05-19 01:59:48 +00:00
MenuI = INPUTMAPPER->DeviceToMenu( DeviceI );
2002-04-16 17:31:00 +00:00
if( !MenuI.IsValid() ) // try again
2002-05-19 01:59:48 +00:00
INPUTMAPPER->GameToMenu( GameI, MenuI );
2002-04-16 17:31:00 +00:00
2002-05-19 01:59:48 +00:00
if( MenuI.IsValid() && type == IET_FIRST_PRESS )
INPUTQUEUE->HandleInput( MenuI.player, MenuI.button );
INPUTMAPPER->GameToStyle( GameI, StyleI );
2001-12-19 01:50:57 +00:00
2002-05-19 01:59:48 +00:00
SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI );
2001-11-03 10:52:42 +00:00
}
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc:
//-----------------------------------------------------------------------------
void Render()
{
2002-05-19 01:59:48 +00:00
HRESULT hr = DISPLAY->BeginFrame();
2001-11-03 10:52:42 +00:00
switch( hr )
{
case D3DERR_DEVICELOST:
// The user probably alt-tabbed out of fullscreen.
// Do not render a frame until we re-acquire the device
break;
case D3DERR_DEVICENOTRESET:
InvalidateObjects();
// Resize the device
2002-05-19 01:59:48 +00:00
if( SUCCEEDED( hr = DISPLAY->Reset() ) )
2001-11-03 10:52:42 +00:00
{
// Initialize the app's device-dependent objects
RestoreObjects();
return;
}
else
{
2002-05-19 01:59:48 +00:00
FatalErrorHr( hr, "Failed to DISPLAY->Reset()" );
}
2001-11-03 10:52:42 +00:00
break;
case S_OK:
2001-11-28 20:26:45 +00:00
{
// set texture and alpha properties
2002-05-19 01:59:48 +00:00
LPDIRECT3DDEVICE8 pd3dDevice = DISPLAY->GetDevice();
2001-11-28 20:26:45 +00:00
// calculate view and projection transforms
2002-01-16 10:01:32 +00:00
D3DXMATRIX matProj;
2002-04-16 17:31:00 +00:00
D3DXMatrixOrthoOffCenterLH( &matProj, 0, 640, 480, 0, -1000, 1000 );
2002-01-16 10:01:32 +00:00
pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
2001-11-28 20:26:45 +00:00
D3DXMATRIX matView;
D3DXMatrixIdentity( &matView );
pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
2002-05-19 01:59:48 +00:00
DISPLAY->ResetMatrixStack();
2001-11-03 10:52:42 +00:00
2002-04-28 20:42:32 +00:00
2001-11-28 20:26:45 +00:00
// draw the game
2002-05-19 01:59:48 +00:00
SCREENMAN->Draw();
2001-11-28 20:26:45 +00:00
2002-05-19 01:59:48 +00:00
DISPLAY->EndFrame();
2001-11-28 20:26:45 +00:00
}
2001-11-03 10:52:42 +00:00
break;
}
ShowFrame();
2001-11-03 10:52:42 +00:00
}
//-----------------------------------------------------------------------------
// Name: ShowFrame()
// Desc:
//-----------------------------------------------------------------------------
void ShowFrame()
{
// display the contents of the back buffer to the front
2002-05-19 01:59:48 +00:00
if( DISPLAY )
DISPLAY->ShowFrame();
2001-11-03 10:52:42 +00:00
}
//-----------------------------------------------------------------------------
// Name: ApplyGraphicOptions()
2001-11-03 10:52:42 +00:00
// Desc:
//-----------------------------------------------------------------------------
void ApplyGraphicOptions()
2001-11-03 10:52:42 +00:00
{
InvalidateObjects();
2002-05-28 20:01:22 +00:00
bool bWindowed = PREFSMAN->m_bWindowed;
2002-05-27 08:23:27 +00:00
CString sProfileName = PREFSMAN->m_bHighDetail ? "High Detail" : "Low Detail";
DWORD dwWidth = PREFSMAN->m_bHighDetail ? 640 : 320;
DWORD dwHeight = PREFSMAN->m_bHighDetail ? 480 : 240;
DWORD dwDisplayBPP = PREFSMAN->m_bHighDetail ? 16 : 16;
DWORD dwTextureBPP = PREFSMAN->m_bHighDetail ? 16 : 16;
DWORD dwMaxTextureSize = PREFSMAN->m_bHighDetail ?
(PREFSMAN->m_bHighTextureDetail ? 1024 : 512) :
(PREFSMAN->m_bHighTextureDetail ? 512 : 256);
//
// If the requested resolution doesn't work, keep switching until we find one that does.
//
2002-05-27 08:23:27 +00:00
if( !DISPLAY->SwitchDisplayMode(bWindowed, dwWidth, dwHeight, dwDisplayBPP) )
{
// We failed. Try full screen with same params.
bWindowed = false;
2002-05-27 08:23:27 +00:00
if( !DISPLAY->SwitchDisplayMode(bWindowed, dwWidth, dwHeight, dwDisplayBPP) )
{
// Failed again. Try 16 BPP
2002-04-16 17:31:00 +00:00
dwDisplayBPP = 16;
2002-05-27 08:23:27 +00:00
if( !DISPLAY->SwitchDisplayMode(bWindowed, dwWidth, dwHeight, dwDisplayBPP) )
{
// Failed again. Try 640x480
dwWidth = 640;
dwHeight = 480;
2002-05-27 08:23:27 +00:00
if( !DISPLAY->SwitchDisplayMode(bWindowed, dwWidth, dwHeight, dwDisplayBPP) )
{
2002-03-10 10:30:45 +00:00
// Failed again. Try 320x240
dwWidth = 320;
dwHeight = 240;
2002-05-27 08:23:27 +00:00
if( !DISPLAY->SwitchDisplayMode(bWindowed, dwWidth, dwHeight, dwDisplayBPP) )
{
2002-05-20 08:59:37 +00:00
FatalError( "Tried every possible display mode, and couldn't find one that works." );
}
}
}
}
}
2002-04-16 17:31:00 +00:00
//
// Let the texture manager know about our preferences
//
2002-05-19 01:59:48 +00:00
if( TEXTUREMAN != NULL )
TEXTUREMAN->SetPrefs( dwMaxTextureSize, dwTextureBPP );
2001-11-03 10:52:42 +00:00
RestoreObjects();
2001-12-20 12:37:38 +00:00
2002-05-27 08:23:27 +00:00
PREFSMAN->SavePrefsToDisk();
2002-05-19 01:59:48 +00:00
if( SCREENMAN )
{
2002-04-28 20:42:32 +00:00
CString sMessage = ssprintf("%s - %s detail", bWindowed ? "Windowed" : "FullScreen", sProfileName );
2002-05-19 01:59:48 +00:00
SCREENMAN->SystemMessage( sMessage );
}
2001-11-03 10:52:42 +00:00
}