Files
osu-framework/osu.Framework.iOS/GameAppDelegate.cs
Dean Herbert 6c0b1585c6 Allow memory clean-up via GameHost.Collect
Moved out from per-platform implementations to allow for future agnostic additions (and potential invocation on desktop platform).
2019-07-24 17:54:57 +09:00

55 lines
1.6 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using UIKit;
using Foundation;
using System.Drawing;
using SixLabors.ImageSharp.PixelFormats;
namespace osu.Framework.iOS
{
public abstract class GameAppDelegate : UIApplicationDelegate
{
public override UIWindow Window { get; set; }
private IOSGameView gameView;
private IOSGameHost host;
protected abstract Game CreateGame();
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
aotImageSharp();
Window = new UIWindow(UIScreen.MainScreen.Bounds);
gameView = new IOSGameView(new RectangleF(0.0f, 0.0f, (float)Window.Frame.Size.Width, (float)Window.Frame.Size.Height));
host = new IOSGameHost(gameView);
Window.RootViewController = new GameViewController(gameView, host);
Window.MakeKeyAndVisible();
// required to trigger the osuTK update loop, which is used for input handling.
gameView.Run();
host.Run(CreateGame());
return true;
}
private void aotImageSharp()
{
System.Runtime.CompilerServices.Unsafe.SizeOf<Rgba32>();
System.Runtime.CompilerServices.Unsafe.SizeOf<long>();
try
{
new SixLabors.ImageSharp.Formats.Png.PngDecoder().Decode<Rgba32>(SixLabors.ImageSharp.Configuration.Default, null);
}
catch
{
}
}
}
}