Skip to content

Commit

Permalink
Merge pull request #5903 from frenzibyte/ios-release-aot
Browse files Browse the repository at this point in the history
Switch osu!framework iOS projects to use AOT compilation on release configurations
  • Loading branch information
peppy authored Jul 7, 2023
2 parents a4024ed + 659edfb commit 0871079
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
11 changes: 8 additions & 3 deletions osu.Framework.iOS.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<Project>
<PropertyGroup>
<CodesignKey>iPhone Developer</CodesignKey>
<!-- Mono Interpreter resolves many AOT issues occuring on runtime,
and will be enabled by default on .NET 8+: https://github.com/dotnet/maui/issues/13019 -->
<UseInterpreter>true</UseInterpreter>
<NullabilityInfoContextSupport>true</NullabilityInfoContextSupport>
<!-- MT7091 occurs when referencing a .framework bundle that consists of a static library.
It only warns about not copying the library to the app bundle to save space,
so there's nothing to be worried about. -->
<NoWarn>$(NoWarn);MT7091</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<!-- On debug configurations, we use Mono interpreter for faster compilation. -->
<UseInterpreter>true</UseInterpreter>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<!-- On release configurations, we use AOT compiler for optimal performance. -->
<UseInterpreter>false</UseInterpreter>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'iPhone'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions osu.Framework.iOS/GameApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void Main(Game target)

game = target;

SDL.PrepareLibraryForIOS();
SDL.SDL_UIKitRunApp(0, IntPtr.Zero, main);
}

Expand Down
12 changes: 11 additions & 1 deletion osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Drawing;
using ObjCRuntime;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using SDL2;
Expand Down Expand Up @@ -60,7 +61,16 @@ protected override void RunMainLoop()
// frame rate with multi-threaded mode turned on, but it is going to give them worse input latency
// and higher power usage.
SDL.SDL_iPhoneSetEventPump(SDL.SDL_bool.SDL_FALSE);
SDL.SDL_iPhoneSetAnimationCallback(SDLWindowHandle, 1, _ => RunFrame(), IntPtr.Zero);
SDL.SDL_iPhoneSetAnimationCallback(SDLWindowHandle, 1, runFrame, ObjectHandle.Handle);
}

[ObjCRuntime.MonoPInvokeCallback(typeof(SDL.SDL_iPhoneAnimationCallback))]
private static void runFrame(IntPtr userdata)
{
var handle = new ObjectHandle<IOSWindow>(userdata);

if (handle.GetTarget(out IOSWindow window))
window.RunFrame();
}

private void updateSafeArea()
Expand Down
11 changes: 7 additions & 4 deletions osu.Framework/Platform/SDL2Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ internal SDL.SDL_SysWMinfo GetWindowSystemInformation()
[UsedImplicitly]
private SDL.SDL_EventFilter? eventFilterDelegate;

private ObjectHandle<SDL2Window> objectHandle;
/// <summary>
/// Represents a handle to this <see cref="SDL2Window"/> instance, used for unmanaged callbacks.
/// </summary>
protected ObjectHandle<SDL2Window> ObjectHandle { get; private set; }

protected SDL2Window(GraphicsSurfaceType surfaceType)
{
objectHandle = new ObjectHandle<SDL2Window>(this, GCHandleType.Normal);
ObjectHandle = new ObjectHandle<SDL2Window>(this, GCHandleType.Normal);

if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_GAMECONTROLLER) < 0)
{
Expand Down Expand Up @@ -250,7 +253,7 @@ public virtual void Create()
/// </summary>
public void Run()
{
SDL.SDL_SetEventFilter(eventFilterDelegate = eventFilter, objectHandle.Handle);
SDL.SDL_SetEventFilter(eventFilterDelegate = eventFilter, ObjectHandle.Handle);

RunMainLoop();
}
Expand Down Expand Up @@ -614,7 +617,7 @@ public void Dispose()
Close();
SDL.SDL_Quit();

objectHandle.Dispose();
ObjectHandle.Dispose();
}
}
}
4 changes: 2 additions & 2 deletions osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="ppy.ManagedBass" Version="2022.1216.0" />
<PackageReference Include="ppy.ManagedBass.Fx" Version="2022.1216.0" />
<PackageReference Include="ppy.ManagedBass.Mix" Version="2022.1216.0" />
<PackageReference Include="ppy.Veldrid" Version="4.9.3-gf4e09bb395" />
<PackageReference Include="ppy.Veldrid" Version="4.9.3-g9f8aa2931a" />
<PackageReference Include="ppy.Veldrid.SPIRV" Version="1.0.15-g3e4b9f196a" />
<PackageReference Include="SharpFNT" Version="2.0.0" />
<!-- Preview version of ImageSharp causes NU5104. -->
Expand All @@ -38,7 +38,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.211" />
<PackageReference Include="StbiSharp" Version="1.1.0" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.669-alpha" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.671-alpha" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2023.619.0" />

<!-- DO NOT use ProjectReference for native packaging project.
Expand Down

0 comments on commit 0871079

Please sign in to comment.