/// <summary> /// Call this method to initialize the game, begin running the game loop, and start processing events for the game. /// </summary> /// <param name="gameContext">The window Context for this game.</param> /// <exception cref="System.InvalidOperationException">Cannot run this instance while it is already running</exception> public void Run(GameContext gameContext = null) { if (IsRunning) { throw new InvalidOperationException("Cannot run this instance while it is already running"); } // Gets the graphics device manager graphicsDeviceManager = Services.GetService <IGraphicsDeviceManager>(); if (graphicsDeviceManager == null) { throw new InvalidOperationException("No GraphicsDeviceManager found"); } #if XENKO_PLATFORM_WINDOWS_DESKTOP && XENKO_GRAPHICS_API_VULKAN try { // fix scaling on Windows 8.1+ SetProcessDpiAwareness(2); } catch (Exception e) { } // don't break if we are on windows 8 or lower #endif #if XENKO_GRAPHICS_API_VULKAN // get the resolution now, so we can create our window with the right settings right from the start GraphicsDeviceManager gdm = graphicsDeviceManager as GraphicsDeviceManager; GetDefaultSettings(out gdm.preferredBackBufferWidth, out gdm.preferredBackBufferHeight, out bool fullScreen, out float fov, (gameContext as GameContextSDL)?.Control ?? null); gdm.IsFullScreen = fullScreen; // Gets the GameWindow Context Context = gameContext ?? GameContextFactory.NewDefaultGameContext(gdm.preferredBackBufferWidth, gdm.preferredBackBufferHeight, fullScreen); PrepareContext(fov); #else Context = gameContext ?? GameContextFactory.NewDefaultGameContext(); PrepareContext(); #endif try { // TODO temporary workaround as the engine doesn't support yet resize var graphicsDeviceManagerImpl = (GraphicsDeviceManager)graphicsDeviceManager; Context.RequestedWidth = graphicsDeviceManagerImpl.PreferredBackBufferWidth; Context.RequestedHeight = graphicsDeviceManagerImpl.PreferredBackBufferHeight; Context.RequestedBackBufferFormat = graphicsDeviceManagerImpl.PreferredBackBufferFormat; Context.RequestedDepthStencilFormat = graphicsDeviceManagerImpl.PreferredDepthStencilFormat; Context.RequestedGraphicsProfile = graphicsDeviceManagerImpl.PreferredGraphicsProfile; Context.DeviceCreationFlags = graphicsDeviceManagerImpl.DeviceCreationFlags; gamePlatform.Run(Context); EndRun(); } finally { IsRunning = false; } }
/// <summary> /// Call this method to initialize the game, begin running the game loop, and start processing events for the game. /// </summary> /// <param name="gameContext">The window Context for this game.</param> /// <exception cref="System.InvalidOperationException">Cannot run this instance while it is already running</exception> public void Run(GameContext gameContext = null) { if (IsRunning) { throw new InvalidOperationException("Cannot run this instance while it is already running"); } // Gets the graphics device manager graphicsDeviceManager = Services.GetService <IGraphicsDeviceManager>(); if (graphicsDeviceManager == null) { throw new InvalidOperationException("No GraphicsDeviceManager found"); } // Gets the GameWindow Context Context = gameContext ?? GameContextFactory.NewDefaultGameContext(); PrepareContext(); try { // TODO temporary workaround as the engine doesn't support yet resize var graphicsDeviceManagerImpl = (GraphicsDeviceManager)graphicsDeviceManager; Context.RequestedWidth = graphicsDeviceManagerImpl.PreferredBackBufferWidth; Context.RequestedHeight = graphicsDeviceManagerImpl.PreferredBackBufferHeight; Context.RequestedBackBufferFormat = graphicsDeviceManagerImpl.PreferredBackBufferFormat; Context.RequestedDepthStencilFormat = graphicsDeviceManagerImpl.PreferredDepthStencilFormat; Context.RequestedGraphicsProfile = graphicsDeviceManagerImpl.PreferredGraphicsProfile; Context.DeviceCreationFlags = graphicsDeviceManagerImpl.DeviceCreationFlags; gamePlatform.Run(Context); if (gamePlatform.IsBlockingRun) { // If the previous call was blocking, then we can call Endrun EndRun(); } else { // EndRun will be executed on Game.Exit isEndRunRequired = true; } } finally { if (!isEndRunRequired) { IsRunning = false; } } }