4 using System.Runtime.ExceptionServices;
5 using System.Threading.Tasks;
6 #if SILICONSTUDIO_PLATFORM_IOS
9 using SiliconStudio.Core;
10 using SiliconStudio.Core.Diagnostics;
11 using SiliconStudio.Paradox.Games;
13 namespace SiliconStudio.
Paradox.Graphics.Regression
17 public readonly
static Logger Logger = GlobalLogger.GetLogger(
"GameTester");
19 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
20 public static void RunGameTest(
GameBase game)
27 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
28 public static void RunGameTest(
GameBase game)
30 throw new NotImplementedException();
32 #elif SILICONSTUDIO_PLATFORM_IOS || SILICONSTUDIO_PLATFORM_ANDROID
33 public static void RunGameTest(
GameBase game)
36 var tcs =
new TaskCompletionSource<bool>();
37 EventHandler<EventArgs> gameFinishedCallback = (sender, e) =>
40 Logger.Info(
"Game finished.");
41 tcs.TrySetResult(
true);
44 EventHandler<GameUnhandledExceptionEventArgs> exceptionhandler = (sender, e) =>
46 Logger.Info(
"Game finished with exception ={0}.", e);
47 tcs.TrySetException((
Exception)e.ExceptionObject);
54 game.UnhandledException += exceptionhandler;
56 Logger.Info(
@"Starting activity");
58 #if SILICONSTUDIO_PLATFORM_IOS
59 game.Exiting += gameFinishedCallback;
61 UIApplication.SharedApplication.InvokeOnMainThread(() =>
63 var window = UIApplication.SharedApplication.KeyWindow;
64 var rootNavigationController = (UINavigationController)window.RootViewController;
67 var bounds = UIScreen.MainScreen.Bounds;
68 var paradoxGameView =
new Starter.ParadoxApplicationDelegate.iOSParadoxView(bounds) { ContentScaleFactor = UIScreen.MainScreen.Scale };
71 var paradoxGameController =
new iOSGameTestController(game) { View = paradoxGameView };
74 var gameContext =
new GameContext(window, paradoxGameView, paradoxGameController);
77 rootNavigationController.PushViewController(gameContext.GameViewController,
false);
80 game.Run(gameContext);
82 #elif SILICONSTUDIO_PLATFORM_ANDROID
84 AndroidGameTestActivity.Game = game;
85 AndroidGameTestActivity.Destroyed += gameFinishedCallback;
86 PlatformAndroid.Context.StartActivity(typeof (AndroidGameTestActivity));
93 Logger.Info(
@"Activity ended");
95 catch (AggregateException e)
98 if (e.InnerExceptions.Count == 1)
99 ExceptionDispatchInfo.Capture(e.InnerException).Throw();
103 #if SILICONSTUDIO_PLATFORM_IOS
105 UIApplication.SharedApplication.InvokeOnMainThread(() =>
107 var window = UIApplication.SharedApplication.KeyWindow;
108 var rootNavigationController = (UINavigationController)window.RootViewController;
110 rootNavigationController.PopViewControllerAnimated(
false);
112 #elif SILICONSTUDIO_PLATFORM_ANDROID
113 AndroidGameTestActivity.Game = null;
114 AndroidGameTestActivity.Destroyed -= gameFinishedCallback;
118 game.Exiting -= gameFinishedCallback;
119 game.UnhandledException -= exceptionhandler;
Base implementation for ILogger.
Contains context used to render the game (Control for WinForm, a DrawingSurface for WP8...