Exemplo n.º 1
0
        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);

            var xenkoGameView = CreateView(bounds);

            var xenkoGameController = CreateViewController(xenkoGameView);

            // create the game context
            var gameContext = new GameContextiOS(new iOSWindow(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.Control.GameViewController, false);
            MainWindow.RootViewController = navigationController;

            // launch the main window
            MainWindow.MakeKeyAndVisible();

            // launch the game
            Game.Run(gameContext);

            return Game.IsRunning;
        }
Exemplo n.º 2
0
        private void InitializeImpl()
        {
            if (gameContext == null)
            {
                Debug.Assert(game.Context is GameContextiOS, "There is only one possible descendant of GameContext for iOS.");
                gameContext = (GameContextiOS)game.Context;
                gameContext.Control.GameView.AddSubview(overlayView);

                NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated);

                UpdateOverlayAndEditBarLayout();
            }
        }
Exemplo n.º 3
0
        private void InitializeImpl()
        {
            if (gameContext == null)
            {
                Debug.Assert(game.Context is GameContextiOS, "There is only one possible descendant of GameContext for iOS.");
                gameContext = (GameContextiOS)game.Context;
                gameContext.Control.GameView.AddSubview(overlayView);

                NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated);

                UpdateOverlayAndEditBarLayout();
            }
        }
Exemplo n.º 4
0
        private void EnsureGameContext()
        {
            if (gameContext == null)
            {
                var game = GetGame();

                Debug.Assert(game.Context is GameContextiOS, "There is only one possible descendant of GameContext for iOS.");

                gameContext = (GameContextiOS)game.Context;
                throw new NotImplementedException();
                //gameContext.Control.GameView.AddSubview(overlayView);

                NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated);

                UpdateOverlayAndEditBarLayout();
            }
        }
Exemplo n.º 5
0
        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 GameContextiOS(new iOSWindow(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.Control.GameViewController, false);
            MainWindow.RootViewController = navigationController;

            // launch the main window
            MainWindow.MakeKeyAndVisible();

            // launch the game
            Game.Run(gameContext);

            return(Game.IsRunning);
        }
Exemplo n.º 6
0
        private void EnsureGameContext()
        {
            if (gameContext == null)
            {
                var game = GetGame();
                if (game == null)
                {
                    throw new ArgumentException("Provided services need to contain a provider for the IGame interface.");
                }

                Debug.Assert(game.Context is GameContextiOS, "There is only one possible descendant of GameContext for iOS.");

                gameContext = (GameContextiOS)game.Context;
                gameContext.Control.GameView.AddSubview(overlayView);

                NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated);

                UpdateOverlayAndEditBarLayout();
            }
        }
Exemplo n.º 7
0
        public static void RunGameTest(Game game)
        {
#if STRIDE_PLATFORM_DESKTOP
            using (game)
            {
                game.Run();
            }
#elif STRIDE_PLATFORM_UWP
            throw new NotImplementedException();
#elif STRIDE_PLATFORM_IOS || STRIDE_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 ={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 STRIDE_PLATFORM_IOS
                    game.Exiting += gameFinishedCallback;

                    UIApplication.SharedApplication.InvokeOnMainThread(() =>
                    {
                        var window = UIApplication.SharedApplication.KeyWindow;
                        var rootNavigationController = (UINavigationController)window.RootViewController;

                        // create the stride game view
                        var bounds         = UIScreen.MainScreen.Bounds;
                        var strideGameView = new iOSStrideView((System.Drawing.RectangleF)bounds)
                        {
                            ContentScaleFactor = UIScreen.MainScreen.Scale
                        };

                        // create the view controller used to display the stride game
                        var strideGameController = new iOSGameTestController(game)
                        {
                            View = strideGameView
                        };

                        // create the game context
                        var gameContext = new GameContextiOS(new iOSWindow(window, strideGameView, strideGameController));

                        // push view
                        rootNavigationController.PushViewController(gameContext.Control.GameViewController, false);

                        // launch the game
                        game.Run(gameContext);
                    });
#elif STRIDE_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 STRIDE_PLATFORM_IOS
                    // iOS Cleanup
                    UIApplication.SharedApplication.InvokeOnMainThread(() =>
                    {
                        var window = UIApplication.SharedApplication.KeyWindow;
                        var rootNavigationController = (UINavigationController)window.RootViewController;

                        rootNavigationController.PopViewController(false);
                    });
#elif STRIDE_PLATFORM_ANDROID
                    AndroidGameTestActivity.Destroyed  -= gameFinishedCallback;
                    AndroidGameTestActivity.GameToStart = null;
#endif
                }
            }
#endif
        }
Exemplo n.º 8
0
        public static void RunGameTest(Game game)
        {
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP

            using (game)
            {
                game.Run();
            }

#elif SILICONSTUDIO_PLATFORM_UWP

            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 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 GameContextiOS(new iOSWindow(window, xenkoGameView, xenkoGameController));

                        // push view
                        rootNavigationController.PushViewController(gameContext.Control.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;
                    AndroidGameTestActivity.GameToStart = null;
#endif
                }
            }
#endif
        }
Exemplo n.º 9
0
        private void EnsureGameContext()
        {
            if (gameContext == null)
            {
                var game = GetGame();
                if (game == null)
                    throw new ArgumentException("Provided services need to contain a provider for the IGame interface.");

                Debug.Assert(game.Context is GameContextiOS, "There is only one possible descendant of GameContext for iOS.");

                gameContext = (GameContextiOS)game.Context;
                gameContext.Control.GameView.AddSubview(overlayView);

                NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OnScreenRotated);

                UpdateOverlayAndEditBarLayout();
            }
        }