diff --git a/source/funkin/InitState.hx b/source/funkin/InitState.hx index 1cd27758f..28d8db6b5 100644 --- a/source/funkin/InitState.hx +++ b/source/funkin/InitState.hx @@ -125,7 +125,7 @@ class InitState extends FlxState #if ios // Setup Audio session - funkin.external.ios.AudioSession.initialize(); + funkin.external.apple.AudioSession.initialize(); #end // This ain't a pixel art game! (most of the time) diff --git a/source/funkin/external/apple/AudioSession.hx b/source/funkin/external/apple/AudioSession.hx new file mode 100644 index 000000000..34c9d734d --- /dev/null +++ b/source/funkin/external/apple/AudioSession.hx @@ -0,0 +1,31 @@ +package funkin.external.apple; + +#if (ios || macos) +/** + * A utility class to manage the audio session on apple devices. + */ +@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml')) +@:include('AudioSession.hpp') +@:unreflective +extern class AudioSession +{ + /** + * Initializes the audio session for playback. + * + * This function configures the shared AVAudioSession instance with the following settings: + * - Sets the audio session category to Playback, allowing Bluetooth A2DP and mixing with spoken audio interruptions. + * - For iOS 17.0 and above, disables interruption on route disconnect. + * - For iOS 14.5 and above, prefers no interruptions from system alerts. + */ + @:native('Apple_AudioSession_Initialize') + static function initialize():Void; + + /** + * Sets the active state of the shared AVAudioSession. + * + * @param active Whether to activate or deactivate the audio session. + */ + @:native('Apple_AudioSession_SetActive') + static function setActive(active:Bool):Void; +} +#end diff --git a/source/funkin/external/apple/ScreenUtil.hx b/source/funkin/external/apple/ScreenUtil.hx new file mode 100644 index 000000000..042ee4e70 --- /dev/null +++ b/source/funkin/external/apple/ScreenUtil.hx @@ -0,0 +1,36 @@ +package funkin.external.apple; + +#if (ios || macos) +/** + * A utility class to get screen related informations on apple devices. + */ +@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml')) +@:include('ScreenUtil.hpp') +@:unreflective +extern class ScreenUtil +{ + /** + * Retrieves the safe area insets for the current screen on iOS devices. + * + * This function populates the provided pointers with the safe area insets (in pixels) for the top, bottom, left, and right edges of the screen. + * On iOS 11 and later, it uses the main window's safeAreaInsets and converts them to pixel values using the screen scale. + * On earlier iOS versions, all insets are set to 0.0. + * + * @param top Pointer to a double to receive the top safe area inset (in pixels). + * @param bottom Pointer to a double to receive the bottom safe area inset (in pixels). + * @param left Pointer to a double to receive the left safe area inset (in pixels). + * @param right Pointer to a double to receive the right safe area inset (in pixels). + */ + @:native('Apple_ScreenUtil_GetSafeAreaInsets') + static function getSafeAreaInsets(top:cpp.RawPointer, bottom:cpp.RawPointer, left:cpp.RawPointer, right:cpp.RawPointer):Void; + + /** + * Retrieves the size of the main screen in pixels. + * + * @param width Pointer to a double where the screen width (in pixels) will be stored. + * @param height Pointer to a double where the screen height (in pixels) will be stored. + */ + @:native('Apple_ScreenUtil_GetScreenSize') + static function getScreenSize(width:cpp.RawPointer, height:cpp.RawPointer):Void; +} +#end diff --git a/source/funkin/external/ios/project/Build.xml b/source/funkin/external/apple/project/Build.xml similarity index 90% rename from source/funkin/external/ios/project/Build.xml rename to source/funkin/external/apple/project/Build.xml index f3baf57e1..c141a246b 100644 --- a/source/funkin/external/ios/project/Build.xml +++ b/source/funkin/external/apple/project/Build.xml @@ -10,7 +10,7 @@ - + @@ -22,6 +22,6 @@ - + diff --git a/source/funkin/external/apple/project/include/AudioSession.hpp b/source/funkin/external/apple/project/include/AudioSession.hpp new file mode 100644 index 000000000..c2a519bb2 --- /dev/null +++ b/source/funkin/external/apple/project/include/AudioSession.hpp @@ -0,0 +1,18 @@ +#pragma once + +/** + * Initializes the audio session for playback. + * + * This function configures the shared AVAudioSession instance with the following settings: + * - Sets the audio session category to Playback, allowing Bluetooth A2DP and mixing with spoken audio interruptions. + * - For iOS 17.0 and above, disables interruption on route disconnect. + * - For iOS 14.5 and above, prefers no interruptions from system alerts. + */ +void Apple_AudioSession_Initialize(); + +/** + * Sets the active state of the shared AVAudioSession. + * + * @param active Whether to activate or deactivate the audio session. + */ +void Apple_AudioSession_SetActive(bool active); diff --git a/source/funkin/external/apple/project/include/ScreenUtil.hpp b/source/funkin/external/apple/project/include/ScreenUtil.hpp new file mode 100644 index 000000000..4353cf49a --- /dev/null +++ b/source/funkin/external/apple/project/include/ScreenUtil.hpp @@ -0,0 +1,23 @@ +#pragma once + +/** + * Retrieves the safe area insets for the current screen on iOS devices. + * + * This function populates the provided pointers with the safe area insets (in pixels) for the top, bottom, left, and right edges of the screen. + * On iOS 11 and later, it uses the main window's safeAreaInsets and converts them to pixel values using the screen scale. + * On earlier iOS versions, all insets are set to 0.0. + * + * @param top Pointer to a double to receive the top safe area inset (in pixels). + * @param bottom Pointer to a double to receive the bottom safe area inset (in pixels). + * @param left Pointer to a double to receive the left safe area inset (in pixels). + * @param right Pointer to a double to receive the right safe area inset (in pixels). + */ +void Apple_ScreenUtil_GetSafeAreaInsets(double* top, double* bottom, double* left, double* right); + +/** + * Retrieves the size of the main screen in pixels. + * + * @param width Pointer to a double where the screen width (in pixels) will be stored. + * @param height Pointer to a double where the screen height (in pixels) will be stored. + */ +void Apple_ScreenUtil_GetScreenSize(double* width, double* height); diff --git a/source/funkin/external/apple/project/src/AudioSession.mm b/source/funkin/external/apple/project/src/AudioSession.mm new file mode 100644 index 000000000..666f668de --- /dev/null +++ b/source/funkin/external/apple/project/src/AudioSession.mm @@ -0,0 +1,38 @@ +#import "AudioSession.hpp" + +#import +#import + +void Apple_AudioSession_Initialize() +{ + AVAudioSession *session = [AVAudioSession sharedInstance]; + + NSError *error; + + [session setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeDefault options:AVAudioSessionCategoryOptionAllowBluetoothA2DP|AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:&error]; + + if (@available(iOS 17.0, *)) + { + [session setPrefersInterruptionOnRouteDisconnect:false error:nil]; + } + + if (@available(iOS 14.5, *)) + { + [session setPrefersNoInterruptionsFromSystemAlerts:true error:nil]; + } + + if (error) + NSLog(@"Unable to set category of audio session: %@", error); +} + +void Apple_AudioSession_SetActive(bool active) +{ + AVAudioSession *session = [AVAudioSession sharedInstance]; + + NSError *error; + + [session setActive:YES error:&error]; + + if (error) + NSLog(@"Unable to set active of audio session: %@", error); +} diff --git a/source/funkin/external/apple/project/src/ScreenUtil.mm b/source/funkin/external/apple/project/src/ScreenUtil.mm new file mode 100644 index 000000000..dd1754892 --- /dev/null +++ b/source/funkin/external/apple/project/src/ScreenUtil.mm @@ -0,0 +1,36 @@ +#import "ScreenUtil.hpp" + +#import +#import + +void Apple_ScreenUtil_GetSafeAreaInsets(double* top, double* bottom, double* left, double* right) +{ + if (@available(iOS 11, *)) + { + UIWindow* window = [UIApplication sharedApplication].windows[0]; + UIEdgeInsets safeAreaInsets = window.safeAreaInsets; + + float scale = [UIScreen mainScreen].scale; + + (*top) = safeAreaInsets.top * scale; + (*bottom) = safeAreaInsets.bottom * scale; + (*left) = safeAreaInsets.left * scale; + (*right) = safeAreaInsets.right * scale; + + return; + } + + (*top) = 0.0; + (*bottom) = 0.0; + (*left) = 0.0; + (*right) = 0.0; +} + +void Apple_ScreenUtil_GetScreenSize(double* width, double* height) +{ + CGRect screenRect = [[UIScreen mainScreen] bounds]; + float scale = [UIScreen mainScreen].scale; + + (*width) = (double)screenRect.size.width * scale; + (*height) = (double)screenRect.size.height * scale; +} diff --git a/source/funkin/external/ios/AudioSession.hx b/source/funkin/external/ios/AudioSession.hx deleted file mode 100644 index bd31b4f65..000000000 --- a/source/funkin/external/ios/AudioSession.hx +++ /dev/null @@ -1,17 +0,0 @@ -package funkin.external.ios; - -#if ios -/** - * A Utility class to manage iOS audio. - */ -@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml')) -@:include('AudioSession.hpp') -@:unreflective -extern class AudioSession -{ - @:native('initialize') - static function initialize():Void; - @:native('setActive') - static function setActive(active:Bool):Void; -} -#end diff --git a/source/funkin/external/ios/ScreenUtil.hx b/source/funkin/external/ios/ScreenUtil.hx deleted file mode 100644 index 8586e5f7a..000000000 --- a/source/funkin/external/ios/ScreenUtil.hx +++ /dev/null @@ -1,18 +0,0 @@ -package funkin.external.ios; - -#if ios -/** - * A Utility class to get iOS screen related informations. - */ -@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml')) -@:include('ScreenUtil.hpp') -@:unreflective -extern class ScreenUtil -{ - @:native('getSafeAreaInsets') - static function getSafeAreaInsets(top:cpp.RawPointer, bottom:cpp.RawPointer, left:cpp.RawPointer, right:cpp.RawPointer):Void; - - @:native('getScreenSize') - static function getScreenSize(width:cpp.RawPointer, height:cpp.RawPointer):Void; -} -#end diff --git a/source/funkin/external/ios/project/include/AudioSession.hpp b/source/funkin/external/ios/project/include/AudioSession.hpp deleted file mode 100644 index f0e752dcf..000000000 --- a/source/funkin/external/ios/project/include/AudioSession.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -void initialize(); -void setActive(bool active); diff --git a/source/funkin/external/ios/project/include/ScreenUtil.hpp b/source/funkin/external/ios/project/include/ScreenUtil.hpp deleted file mode 100644 index b6036d8b8..000000000 --- a/source/funkin/external/ios/project/include/ScreenUtil.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -void getSafeAreaInsets(double* top, double* bottom, double* left, double* right); -void getScreenSize(double* width, double* height); diff --git a/source/funkin/external/ios/project/src/AudioSession.mm b/source/funkin/external/ios/project/src/AudioSession.mm deleted file mode 100644 index db9569366..000000000 --- a/source/funkin/external/ios/project/src/AudioSession.mm +++ /dev/null @@ -1,41 +0,0 @@ -#import -#import - -void initialize() -{ - AVAudioSession *session = [AVAudioSession sharedInstance]; - - NSError *error; - [session setCategory:AVAudioSessionCategoryPlayback - mode:AVAudioSessionModeDefault - options:AVAudioSessionCategoryOptionAllowBluetoothA2DP|AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers - error:&error]; - - if (@available(iOS 17.0, *)) - { - [session setPrefersInterruptionOnRouteDisconnect:false error:nil]; - } - - if (@available(iOS 14.5, *)) - { - [session setPrefersNoInterruptionsFromSystemAlerts:true error:nil]; - } - - if (error) - { - NSLog(@"Unable to set category of audio session: %@", error); - } -} - -void setActive(bool active) -{ - AVAudioSession *session = [AVAudioSession sharedInstance]; - NSError *error; - - [session setActive:YES error:&error]; - - if (error) - { - NSLog(@"Unable to set active of audio session: %@", error); - } -} diff --git a/source/funkin/external/ios/project/src/ScreenUtil.mm b/source/funkin/external/ios/project/src/ScreenUtil.mm deleted file mode 100644 index 7b7a29097..000000000 --- a/source/funkin/external/ios/project/src/ScreenUtil.mm +++ /dev/null @@ -1,36 +0,0 @@ -#import "ScreenUtil.hpp" - -#import -#import - -void getSafeAreaInsets(double* top, double* bottom, double* left, double* right) -{ - if (@available(iOS 11, *)) - { - UIWindow* window = [UIApplication sharedApplication].windows[0]; - UIEdgeInsets safeAreaInsets = window.safeAreaInsets; - - float scale = [UIScreen mainScreen].scale; - - (*top) = safeAreaInsets.top * scale; - (*bottom) = safeAreaInsets.bottom * scale; - (*left) = safeAreaInsets.left * scale; - (*right) = safeAreaInsets.right * scale; - - return; - } - - (*top) = 0.0; - (*bottom) = 0.0; - (*left) = 0.0; - (*right) = 0.0; -} - -void getScreenSize(double* width, double* height) -{ - CGRect screenRect = [[UIScreen mainScreen] bounds]; - float scale = [UIScreen mainScreen].scale; - - (*width) = (double)screenRect.size.width * scale; - (*height) = (double)screenRect.size.height * scale; -} diff --git a/source/funkin/external/windows/WinAPI.hx b/source/funkin/external/windows/WinAPI.hx index edc639758..c8d567ac3 100644 --- a/source/funkin/external/windows/WinAPI.hx +++ b/source/funkin/external/windows/WinAPI.hx @@ -67,7 +67,7 @@ extern class WinAPI /** * Sets the dark mode for the active window. * - * @param enable A boolean value indicating whether to enable (true) or disable (false) dark mode. + * @param enable Whether to enable or disable dark mode. */ @:native('WINAPI_SetDarkMode') static function setDarkMode(enable:Bool):Void; diff --git a/source/funkin/external/windows/project/Build.xml b/source/funkin/external/windows/project/Build.xml index d68c41301..128ea557b 100644 --- a/source/funkin/external/windows/project/Build.xml +++ b/source/funkin/external/windows/project/Build.xml @@ -10,7 +10,7 @@ - + @@ -31,6 +31,6 @@ - + diff --git a/source/funkin/external/windows/project/include/winapi.hpp b/source/funkin/external/windows/project/include/winapi.hpp index cfaf699b8..59ad3a9e2 100644 --- a/source/funkin/external/windows/project/include/winapi.hpp +++ b/source/funkin/external/windows/project/include/winapi.hpp @@ -1,45 +1,49 @@ #pragma once /** - * @brief Shows an error message box + * Shows an error message box. + * * @param message The error message to display * @param title The title of the message box */ void WINAPI_ShowError(const char *message, const char *title); /** - * @brief Shows a warning message box + * Shows a warning message box. + * * @param message The warning message to display * @param title The title of the message box */ void WINAPI_ShowWarning(const char *message, const char *title); /** - * @brief Shows an information message box + * Shows an information message box. + * * @param message The information message to display * @param title The title of the message box */ void WINAPI_ShowInformation(const char *message, const char *title); /** - * @brief Shows a question message box with OK/Cancel buttons + * Shows a question message box with OK/Cancel buttons. + * * @param message The question message to display * @param title The title of the message box */ void WINAPI_ShowQuestion(const char *message, const char *title); /** - * @brief Disables Windows error reporting dialogs + * Disables Windows error reporting dialogs. */ void WINAPI_DisableErrorReporting(); /** - * @brief Disables Windows ghosting for the current process + * Disables Windows ghosting for the current process. */ void WINAPI_DisableWindowsGhosting(); /** - * @brief Retrieves the current working set size (in bytes) of the calling process. + * Retrieves the current working set size (in bytes) of the calling process. * * This function queries the operating system for the amount of physical memory currently allocated to the process (its working set). * @@ -48,13 +52,15 @@ void WINAPI_DisableWindowsGhosting(); size_t WINAPI_GetProcessMemoryWorkingSetSize(); /** - * @brief Sets dark mode for the active window + * Sets dark mode for the active window. + * * @param enable True to enable dark mode, false to disable */ void WINAPI_SetDarkMode(bool enable); /** - * @brief Checks if the system is using dark mode + * Checks if the system is using dark mode. + * * @return True if system is in dark mode, false otherwise */ bool WINAPI_IsSystemDarkMode(); diff --git a/source/funkin/mobile/util/ScreenUtil.hx b/source/funkin/mobile/util/ScreenUtil.hx index cb1a9c562..4cfd3e092 100644 --- a/source/funkin/mobile/util/ScreenUtil.hx +++ b/source/funkin/mobile/util/ScreenUtil.hx @@ -1,7 +1,7 @@ package funkin.mobile.util; #if ios -import funkin.external.ios.ScreenUtil as NativeScreenUtil; +import funkin.external.apple.ScreenUtil as NativeScreenUtil; #elseif android import funkin.external.android.ScreenUtil as NativeScreenUtil; #end