bool Application::OnInit() { std::string textException = "OnInit() => "; try { SettingsCreator::ConfigureSettingsFile(); InitializeSDLSystem(); InitializeVideoSystem(); InitializeTTFSystem(); InitializeAudioSystem(); InitializeResources(); StateManager::SetActiveState(STATE_MENU); return true; } catch (const SDLException& sdlException) { textException.append(sdlException.WhatHappens()); throw SDLException(textException); } catch (const TTFException& ttfException) { textException.append(ttfException.WhatHappens()); throw TTFException(textException); } catch (const MixerException& mixerException) { textException.append(mixerException.WhatHappens()); throw MixerException(textException); } catch (const GenericException& exception) { textException.append(exception.WhatHappens()); throw GenericException(textException); } return false; }
/*virtual*/ void Framework3D::Initialize() { XTRACE_FUNCTION; m_IsInitializing = true; #if BUILD_SDL const int Error = SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE ); ASSERT( 0 == Error ); Unused( Error ); if( 0 != Error ) { PRINTF( "SDL_Init: %s\n", SDL_GetError() ); } SDL_DisableScreenSaver(); #endif STATICHASH( Framework ); #if BUILD_WINDOWS #if BUILD_FINAL STATICHASH( ShowConsole ); const bool ShowConsole = ConfigManager::GetBool( sShowConsole, false, sFramework ); if( ShowConsole ) #endif { Console::GetInstance()->SetPos( 0, 0 ); } #endif STATICHASH( UseRandomSeed ); const bool UseRandomSeed = ConfigManager::GetBool( sUseRandomSeed, false, sFramework ); STATICHASH( RandomSeed ); const int RandomSeed = ConfigManager::GetInt( sRandomSeed, 0, sFramework ); if( UseRandomSeed ) { Math::SeedGenerator( RandomSeed ); } else { Math::SeedGenerator(); } STATICHASH( UseFixedFrameTime ); m_UseFixedFrameTime = ConfigManager::GetBool( sUseFixedFrameTime, true, sFramework ); STATICHASH( FixedFrameTime ); m_FixedFrameTime = ConfigManager::GetFloat( sFixedFrameTime, 1.0f / 60.0f, sFramework ); STATICHASH( FramesLimit ); const int FramesLimit = ConfigManager::GetInt( sFramesLimit, 5, sFramework ); m_FrameTimeLimit = m_FixedFrameTime * static_cast<float>( FramesLimit ); STATICHASH( DoVideoCapture ); m_DoVideoCapture = ConfigManager::GetBool( sDoVideoCapture, false, sFramework ); STATICHASH( VideoCaptureFixedFrameTime ); m_VideoCaptureFixedFrameTime = ConfigManager::GetFloat( sVideoCaptureFixedFrameTime, 1.0f / 30.0f, sFramework ); uint DisplayWidth = 0; uint DisplayHeight = 0; SimpleString WindowTitle; // Loads display parameters from config, so GetInitialDisplaySize can use that. m_Display = new Display; // Make sure that we use a supported resolution regardless of what the config file said. const SDisplayMode BestDisplayMode = m_Display->GetBestDisplayMode( m_Display->m_Width, m_Display->m_Height ); m_Display->SetResolution( BestDisplayMode.Width, BestDisplayMode.Height ); uint WindowIcon = 0; GetInitialWindowIcon( WindowIcon ); GetInitialDisplaySize( DisplayWidth, DisplayHeight ); GetInitialWindowTitle( WindowTitle ); CreateSplashWindow( WindowIcon, WindowTitle.CStr() ); m_Window = new Window; #if BUILD_WINDOWS_NO_SDL DWORD WindowStyle = 0; if( m_Display->m_Fullscreen || ( m_Display->m_ScreenWidth == m_Display->m_Width && m_Display->m_ScreenHeight == m_Display->m_Height ) ) { WindowStyle = WS_POPUP; } else { WindowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; } m_Window->Init( WindowTitle.CStr(), "Class1", WindowStyle, 0, DisplayWidth, DisplayHeight, m_hInstance, WindowProc, WindowIcon, m_Display->m_ScreenWidth, m_Display->m_ScreenHeight ); #elif BUILD_SDL uint WindowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN; if( m_Display->m_Fullscreen || ( m_Display->m_ScreenWidth == m_Display->m_Width && m_Display->m_ScreenHeight == m_Display->m_Height ) ) { WindowFlags |= SDL_WINDOW_BORDERLESS; } // TODO SDL: Unify interface? m_Window->Init( WindowTitle.CStr(), WindowFlags, DisplayWidth, DisplayHeight ); STATICHASH( IconImage ); const char* const pIconImage = ConfigManager::GetString( sIconImage, NULL, sFramework ); ASSERT( pIconImage ); const Surface IconSurface = Surface( PackStream( pIconImage ), Surface::ESFT_BMP ); SDL_SetWindowIcon( m_Window->GetSDLWindow(), IconSurface.GetSDLSurface() ); #endif m_Window->SetFullscreen( m_Display->m_Fullscreen ); if( m_Display->m_Fullscreen ) { m_Window->SetPosition( 0, 0 ); } m_Clock = new Clock; XTRACE_BEGIN( InitializeDevices ); m_Keyboard = new Keyboard; #if BUILD_WINDOWS_NO_SDL m_Mouse = new Mouse( m_hInstance, m_Window->GetHWnd() ); #elif BUILD_SDL m_Mouse = new Mouse( m_Window ); #endif XTRACE_END; InitializeUIInputMap(); XTRACE_BEGIN( InitializeAudioSystem ); InitializeAudioSystem(); XTRACE_END; XTRACE_BEGIN( InitializeRenderer ); #if BUILD_WINDOWS_NO_SDL STATICHASH( OpenGL ); const bool OpenGL = ConfigManager::GetBool( sOpenGL ); if( OpenGL ) #endif { PRINTF( "Using OpenGL renderer.\n" ); m_Renderer = CreateGL2Renderer( m_Window ); } #if BUILD_WINDOWS_NO_SDL else { PRINTF( "Using Direct3D renderer.\n" ); m_Renderer = CreateD3D9Renderer( m_Window->GetHWnd(), m_Display->m_Fullscreen ); } #endif IRenderer::SRestoreDeviceCallback Callback; Callback.m_Callback = &Framework3D::RendererRestoreDeviceCallback; Callback.m_Void = this; m_Renderer->SetRestoreDeviceCallback( Callback ); InitializeRender(); m_Renderer->Initialize(); m_Renderer->SetDisplay( m_Display ); m_Renderer->SetClock( m_Clock ); XTRACE_END; if( ShowWindowASAP() ) { SafeDelete( m_SplashWindow ); #if BUILD_WINDOWS_NO_SDL m_Window->Show( m_CmdShow ); #elif BUILD_SDL m_Window->Show(); #endif // Reattach GL context if needed. m_Renderer->Refresh(); } if( UseClassicTargetManager() ) { m_TargetManager = new TargetManager( m_Renderer, DisplayWidth, DisplayHeight ); } XTRACE_BEGIN( InitializeUI ); SimpleString UIManagerDefinitionName; GetUIManagerDefinitionName( UIManagerDefinitionName ); m_UIManager = new UIManagerFramework( this ); m_UIManager->InitializeFromDefinition( UIManagerDefinitionName ); m_UIManager->GetUIStack()->SetFadeOverlay( m_UIManager->GetScreen( "Fade" ) ); UIScreen::UpdateMouseButtonsSwapped(); XTRACE_END; m_IsInitializing = false; }