public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { if(Game == null) throw new InvalidOperationException("Please set 'Game' to a valid instance of Game before calling this method."); var bounds = UIScreen.MainScreen.Bounds; // create the game main windows MainWindow = new UIWindow(bounds); // create the xenko game view var xenkoGameView = new iOSXenkoView((RectangleF)bounds) {ContentScaleFactor = UIScreen.MainScreen.Scale}; // create the view controller used to display the xenko game var xenkoGameController = new XenkoGameController { View = xenkoGameView }; // create the game context var gameContext = new GameContext(MainWindow, xenkoGameView, xenkoGameController); // Force fullscreen UIApplication.SharedApplication.SetStatusBarHidden(true, false); // Added UINavigationController to switch between UIViewController because the game is killed if the FinishedLaunching (in the AppDelegate) method doesn't return true in 10 sec. var navigationController = new UINavigationController {NavigationBarHidden = true}; navigationController.PushViewController(gameContext.GameViewController, false); MainWindow.RootViewController = navigationController; // launch the main window MainWindow.MakeKeyAndVisible(); // launch the game Game.Run(gameContext); return Game.IsRunning; }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; xenkoGameForm = (AndroidXenkoGameView)gameContext.Control; nativeWindow = new WindowHandle(AppContextType.Android, xenkoGameForm); xenkoGameForm.Load += gameForm_Resume; xenkoGameForm.OnPause += gameForm_OnPause; xenkoGameForm.Unload += gameForm_Unload; xenkoGameForm.RenderFrame += gameForm_RenderFrame; // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = xenkoGameForm.Width; } var height = gameContext.RequestedHeight; if (height == 0) { height = xenkoGameForm.Height; } // Transmit requested back buffer and depth stencil formats to OpenTK xenkoGameForm.RequestedBackBufferFormat = gameContext.RequestedBackBufferFormat; xenkoGameForm.RequestedGraphicsProfile = gameContext.RequestedGraphicsProfile; xenkoGameForm.Size = new Size(width, height); //xenkoGameForm.Resize += OnClientSizeChanged; }
internal override void Initialize(GameContext gameContext) { this.GameContext = gameContext; gameForm = (OpenTK.GameWindow)gameContext.Control; nativeWindow = new WindowHandle(AppContextType.DesktopOpenTK, gameForm); // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = gameForm.Width; } var height = gameContext.RequestedHeight; if (height == 0) { height = gameForm.Height; } gameForm.ClientSize = new System.Drawing.Size(width, height); gameForm.MouseEnter += GameWindowForm_MouseEnter; gameForm.MouseLeave += GameWindowForm_MouseLeave; gameForm.Resize += OnClientSizeChanged; }
private void InitializeImpl() { if (gameContext == null) { gameContext = game.Context; gameContext.GameView.AddSubview(overlayView); NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated); UpdateOverlayAndEditBarLayout(); } }
public void InitializeFromOpenTK(GameContext gameContext) { gameWindow = (OpenTK.GameWindow)gameContext.Control; gameWindow.Keyboard.KeyDown += Keyboard_KeyDown; gameWindow.Keyboard.KeyUp += Keyboard_KeyUp; gameWindow.Mouse.ButtonDown += Mouse_ButtonDown; gameWindow.Mouse.ButtonUp += Mouse_ButtonUp; gameWindow.Mouse.Move += Mouse_Move; gameWindow.Resize += GameWindowOnResize; GameWindowOnResize(null, EventArgs.Empty); }
/// <summary> /// Create the appropriate instance of InputManager depending on the platform and context associated to <paramref name="registry"/>. /// </summary> /// <param name="registry"></param> /// <param name="context">Associated context. Cannot be null.</param> /// <returns></returns> public static InputManager NewInputManager(IServiceRegistry registry, GameContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } InputManager res = null; switch (context.ContextType) { case AppContextType.Desktop: #if SILICONSTUDIO_XENKO_UI_WINFORMS res = NewInputManagerWinforms(registry); #elif SILICONSTUDIO_XENKO_UI_SDL // When SDL is the only UI available, Desktop and DesktopSDL are equivalent. res = NewInputManagerSDL(registry); #endif break; case AppContextType.DesktopWpf: res = NewInputManagerWpf(registry); break; case AppContextType.DesktopOpenTK: res = NewInputManagerOpenTK(registry); break; case AppContextType.DesktopSDL: res = NewInputManagerSDL(registry); break; case AppContextType.WindowsRuntime: res = NewInputManagerWindowsRuntime(registry); break; case AppContextType.Android: res = NewInputManagerAndroid(registry); break; case AppContextType.iOS: res = NewInputManageriOS(registry); break; } if (res == null) { throw new NotSupportedException("Unsupported Input type"); } return res; }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; gameForm = gameContext.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) contextTest.Dispose(); gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; break; } catch (Exception) { // TODO: log message } } if (!contextAvailable) throw new Exception("Graphics context could not be created."); gameForm.LayerColorFormat = EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; }
public void Run(GameContext gameContext) { gameWindow = CreateWindow(gameContext); // Register on Activated gameWindow.Activated += OnActivated; gameWindow.Deactivated += OnDeactivated; gameWindow.InitCallback = OnInitCallback; gameWindow.RunCallback = OnRunCallback; WindowCreated?.Invoke(this, EventArgs.Empty); gameWindow.Run(); }
private void InitializeFromWindowsWpf(GameContext uiContext) { var uiControlWpf = (Window)uiContext.Control; var inputElement = uiControlWpf; BindRawInputKeyboard(uiControl); uiControlWpf.LostFocus += (_, e) => OnUiControlLostFocus(); uiControlWpf.Deactivated += (_, e) => OnUiControlLostFocus(); uiControlWpf.MouseMove += (_, e) => OnMouseMoveEvent(PointToVector2(e.GetPosition(inputElement))); uiControlWpf.MouseDown += (_, e) => OnMouseInputEvent(PointToVector2(e.GetPosition(inputElement)), ConvertMouseButton(e.ChangedButton), InputEventType.Down); uiControlWpf.MouseUp += (_, e) => OnMouseInputEvent(PointToVector2(e.GetPosition(inputElement)), ConvertMouseButton(e.ChangedButton), InputEventType.Up); uiControlWpf.MouseWheel += (_, e) => OnMouseInputEvent(PointToVector2(e.GetPosition(inputElement)), MouseButton.Middle, InputEventType.Wheel, e.Delta); uiControlWpf.SizeChanged += OnWpfSizeChanged; ControlWidth = (float)uiControlWpf.ActualWidth; ControlHeight = (float)uiControlWpf.ActualHeight; }
/// <summary> /// Initializes a new instance of the <see cref="GameWindowRenderer" /> class. /// </summary> /// <param name="registry">The registry.</param> /// <param name="gameContext">The window context.</param> public GameWindowRenderer(IServiceRegistry registry, GameContext gameContext) : base(registry) { GameContext = gameContext; }
public static void RunGameTest(Game game) { #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP using (game) { game.Run(); } #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME throw new NotImplementedException(); #elif SILICONSTUDIO_PLATFORM_IOS || SILICONSTUDIO_PLATFORM_ANDROID lock(uniThreadLock) { // Prepare finish callback var tcs = new TaskCompletionSource<bool>(); EventHandler<EventArgs> gameFinishedCallback = (sender, e) => { // Notify waiter that game has exited Logger.Info("Game finished."); tcs.TrySetResult(true); }; EventHandler<GameUnhandledExceptionEventArgs> exceptionhandler = (sender, e) => { Logger.Info("Game finished with exception ={0}.", e); tcs.TrySetException((Exception)e.ExceptionObject); }; // Transmit data to activity // TODO: Avoid static with string intent + Dictionary? try { game.UnhandledException += exceptionhandler; Logger.Info(@"Starting activity"); #if SILICONSTUDIO_PLATFORM_IOS game.Exiting += gameFinishedCallback; UIApplication.SharedApplication.InvokeOnMainThread(() => { var window = UIApplication.SharedApplication.KeyWindow; var rootNavigationController = (UINavigationController)window.RootViewController; // create the xenko game view var bounds = UIScreen.MainScreen.Bounds; var xenkoGameView = new Starter.XenkoApplicationDelegate.iOSXenkoView((System.Drawing.RectangleF)bounds) { ContentScaleFactor = UIScreen.MainScreen.Scale }; // create the view controller used to display the xenko game var xenkoGameController = new iOSGameTestController(game) { View = xenkoGameView }; // create the game context var gameContext = new GameContext(window, xenkoGameView, xenkoGameController); // push view rootNavigationController.PushViewController(gameContext.GameViewController, false); // launch the game game.Run(gameContext); }); #elif SILICONSTUDIO_PLATFORM_ANDROID // Start activity AndroidGameTestActivity.GameToStart = game; AndroidGameTestActivity.Destroyed += gameFinishedCallback; PlatformAndroid.Context.StartActivity(typeof(AndroidGameTestActivity)); #endif // Wait for completion of task // TODO: Should we put a timeout and issue a Game.Exit() in main thread if too long? tcs.Task.Wait(); Logger.Info(@"Activity ended"); } catch (AggregateException e) { // Unwrap aggregate exceptions if (e.InnerExceptions.Count == 1) ExceptionDispatchInfo.Capture(e.InnerException).Throw(); } finally { #if SILICONSTUDIO_PLATFORM_IOS // iOS Cleanup UIApplication.SharedApplication.InvokeOnMainThread(() => { var window = UIApplication.SharedApplication.KeyWindow; var rootNavigationController = (UINavigationController)window.RootViewController; rootNavigationController.PopViewController(false); }); #elif SILICONSTUDIO_PLATFORM_ANDROID AndroidGameTestActivity.Destroyed -= gameFinishedCallback; #endif } } #endif }
internal override bool CanHandle(GameContext windowContext) { return(windowContext.ContextType == AppContextType.WindowsRuntime); }
public virtual GameWindow CreateWindow(GameContext gameContext) { var window = GetSupportedGameWindow(gameContext.ContextType); if (window != null) { window.Services = Services; window.Initialize(gameContext); return window; } throw new ArgumentException("Game Window context not supported on this platform"); }
/// <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(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager; if (graphicsDeviceManager == null) { throw new InvalidOperationException("No GraphicsDeviceManager found"); } // Gets the GameWindow Context Context = gameContext ?? new GameContext(); 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; 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; } } }
internal override bool CanHandle(GameContext gameContext) { return gameContext.ContextType == AppContextType.DesktopOpenTK; }
internal abstract void Initialize(GameContext gameContext);
/// <summary> /// Initializes the GameWindow with the specified window context. /// </summary> /// <param name="gameContext">The window context.</param> internal abstract bool CanHandle(GameContext gameContext);
internal override void Initialize(GameContext windowContext) { if (windowContext != null) { swapChainPanel = windowContext.Control as SwapChainPanel; if (swapChainPanel == null) { throw new NotSupportedException(string.Format("Unsupported window context [{0}]. Only SwapChainPanel", windowContext.Control.GetType().FullName)); } windowHandle = new WindowHandle(AppContextType.WindowsRuntime, swapChainPanel); #if SILICONSTUDIO_PLATFORM_WINDOWS_10 var appView = ApplicationView.GetForCurrentView(); if (appView != null && windowContext.RequestedWidth != 0 && windowContext.RequestedHeight != 0) appView.TryResizeView(new Size(windowContext.RequestedWidth, windowContext.RequestedHeight)); #endif //clientBounds = new DrawingRectangle(0, 0, (int)swapChainPanel.ActualWidth, (int)swapChainPanel.ActualHeight); swapChainPanel.SizeChanged += swapChainPanel_SizeChanged; swapChainPanel.CompositionScaleChanged += swapChainPanel_CompositionScaleChanged; } }
internal override bool CanHandle(GameContext windowContext) { return windowContext.ContextType == AppContextType.WindowsRuntime; }
public virtual GameWindow CreateWindow(GameContext gameContext) { gameContext = gameContext ?? new GameContext(); var windows = GetSupportedGameWindows(); foreach (var gameWindowToTest in windows) { if (gameWindowToTest.CanHandle(gameContext)) { gameWindowToTest.Services = Services; gameWindowToTest.Initialize(gameContext); return gameWindowToTest; } } throw new ArgumentException("Game Window context not supported on this platform"); }
private void SetupGameViewAndGameContext() { // Set the main view of the Game SetContentView(Resource.Layout.Game); mainLayout = FindViewById<RelativeLayout>(Resource.Id.GameViewLayout); mainLayout.AddView(gameView); // Create the Game context GameContext = new GameContext(gameView, FindViewById<RelativeLayout>(Resource.Id.EditTextLayout)); }
private void InitializeFromWindowsForms(GameContext uiContext) { uiControl = (Control) uiContext.Control; pointerClock.Restart(); if (UseRawInput) { BindRawInputKeyboard(uiControl); } else { EnsureMapKeys(); defaultWndProc = Win32Native.GetWindowLong(new HandleRef(this, uiControl.Handle), Win32Native.WindowLongType.WndProc); // This is needed to prevent garbage collection of the delegate. inputWndProc = WndProc; var inputWndProcPtr = Marshal.GetFunctionPointerForDelegate(inputWndProc); Win32Native.SetWindowLong(new HandleRef(this, uiControl.Handle), Win32Native.WindowLongType.WndProc, inputWndProcPtr); } uiControl.GotFocus += (_, e) => OnUiControlGotFocus(); uiControl.LostFocus += (_, e) => OnUiControlLostFocus(); uiControl.MouseMove += (_, e) => OnMouseMoveEvent(new Vector2(e.X, e.Y)); uiControl.MouseDown += (_, e) => { uiControl.Focus(); OnMouseInputEvent(new Vector2(e.X, e.Y), ConvertMouseButton(e.Button), InputEventType.Down); }; uiControl.MouseUp += (_, e) => OnMouseInputEvent(new Vector2(e.X, e.Y), ConvertMouseButton(e.Button), InputEventType.Up); uiControl.MouseWheel += (_, e) => OnMouseInputEvent(new Vector2(e.X, e.Y), MouseButton.Middle, InputEventType.Wheel, e.Delta); uiControl.MouseCaptureChanged += (_, e) => OnLostMouseCaptureWinForms(); uiControl.SizeChanged += UiControlOnSizeChanged; ControlWidth = uiControl.ClientSize.Width; ControlHeight = uiControl.ClientSize.Height; }
public void Run(GameContext gameContext) { gameWindow = CreateWindow(gameContext); // Register on Activated gameWindow.Activated += OnActivated; gameWindow.Deactivated += OnDeactivated; gameWindow.InitCallback = OnInitCallback; gameWindow.RunCallback = OnRunCallback; var windowCreated = WindowCreated; if (windowCreated != null) { windowCreated(this, EventArgs.Empty); } gameWindow.Run(); }
/// <summary> /// Initializes a new instance of the <see cref="GameWindowRenderer" /> class. /// </summary> /// <param name="registry">The registry.</param> /// <param name="gameContext">The window context.</param> public GameWindowRenderer(IServiceRegistry registry, GameContext gameContext = null) : base(registry) { GameContext = gameContext ?? new GameContext(); }
internal override bool CanHandle(GameContext gameContext) { return gameContext.ContextType == AppContextType.Android; }
internal override bool CanHandle(GameContext gameContext) { return(gameContext.ContextType == AppContextType.DesktopOpenTK); }
/// <summary> /// Run the test. /// </summary> /// <param name="device">The device where to run the test.</param> /// <param name="gameContext">The game context.</param> public void RunTest(ConnectedDevice device, GameContext gameContext = null) { currentDevice = device; runTests = true; Console.WriteLine(@"Running test " + this.GetType().Name + @" on device " + device.Name + @" (" + device.Platform + @")"); // TODO: should be executed after LoadContent for client - or at the first frame? RegisterTests(); if (isServer) { Console.WriteLine(@"Running server" + (onBamboo ? @" on Bamboo" : @"" )); // Launch server SetUpServer(); if (!serverUp) { Assert.Fail("Unable to create a server."); return; } // Reset some variables imageReceived = false; testPerformed = false; dataReceivedEvent = new ManualResetEvent(false); // Launch remote test Console.WriteLine(@"Waiting for a connection... "); //server.BeginAcceptTcpClient(GetClientResultCallback, server); RunTestOnDevice(device); // Wait until data is received or timeout dataReceivedEvent.WaitOne(Timeout); try { Console.WriteLine(@"Stopping the server."); serverUp = false; StopServer(); } catch (Exception) { Console.WriteLine(@"Stopping the server threw an error."); } finally { // Some tests Assert.IsTrue(imageReceived, "The image was not received."); Assert.IsTrue(testPerformed, "The tests were not correctly performed"); } } else { Console.WriteLine(@"Running test client"); // 1. Create client SetUpClient(); // 2. Run game Run(gameContext); } }