-
Notifications
You must be signed in to change notification settings - Fork 399
/
GameApplication.cs
62 lines (51 loc) · 2.35 KB
/
GameApplication.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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 System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using AVFoundation;
using Foundation;
using ManagedBass;
using ManagedBass.Fx;
using ManagedBass.Mix;
using SDL;
namespace osu.Framework.iOS
{
public static class GameApplication
{
private const string output_volume = @"outputVolume";
private static IOSGameHost host = null!;
private static Game game = null!;
private static readonly OutputVolumeObserver output_volume_observer = new OutputVolumeObserver();
public static unsafe void Main(Game target)
{
NativeLibrary.SetDllImportResolver(typeof(Bass).Assembly, (_, assembly, path) => NativeLibrary.Load("@rpath/bass.framework/bass", assembly, path));
NativeLibrary.SetDllImportResolver(typeof(BassFx).Assembly, (_, assembly, path) => NativeLibrary.Load("@rpath/bass_fx.framework/bass_fx", assembly, path));
NativeLibrary.SetDllImportResolver(typeof(BassMix).Assembly, (_, assembly, path) => NativeLibrary.Load("@rpath/bassmix.framework/bassmix", assembly, path));
NativeLibrary.SetDllImportResolver(typeof(SDL3).Assembly, (_, assembly, path) => NativeLibrary.Load("@rpath/SDL3.framework/SDL3", assembly, path));
game = target;
SDL3.SDL_RunApp(0, null, &main, IntPtr.Zero);
}
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static unsafe int main(int argc, byte** argv)
{
var audioSession = AVAudioSession.SharedInstance();
audioSession.AddObserver(output_volume_observer, output_volume, NSKeyValueObservingOptions.New, 0);
host = new IOSGameHost();
host.Run(game);
return 0;
}
private class OutputVolumeObserver : NSObject
{
public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, nint context)
{
switch (keyPath)
{
case output_volume:
AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
break;
}
}
}
}
}