Adjust the external API a little.

This commit is contained in:
MAJigsaw77
2025-09-08 13:02:48 -04:00
committed by Eric
parent 1912155b32
commit f3ff132e90
18 changed files with 204 additions and 136 deletions
+1 -1
View File
@@ -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)
+31
View File
@@ -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
+36
View File
@@ -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<Float>, bottom:cpp.RawPointer<Float>, left:cpp.RawPointer<Float>, right:cpp.RawPointer<Float>):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<Float>, height:cpp.RawPointer<Float>):Void;
}
#end
@@ -10,7 +10,7 @@
<compilerflag value="-I${this_dir}/include" />
</files>
<files id="external-ios">
<files id="external-apple">
<compilerflag value="-I${this_dir}/include" />
<file name="${this_dir}/src/ScreenUtil.mm" />
@@ -22,6 +22,6 @@
<vflag name="-framework" value="Foundation" />
<vflag name="-framework" value="AVFAudio" />
<files id="external-ios" />
<files id="external-apple" />
</target>
</xml>
@@ -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);
@@ -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);
@@ -0,0 +1,38 @@
#import "AudioSession.hpp"
#import <Foundation/Foundation.h>
#import <AVFAudio/AVFAudio.h>
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);
}
+36
View File
@@ -0,0 +1,36 @@
#import "ScreenUtil.hpp"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
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;
}
-17
View File
@@ -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
-18
View File
@@ -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<Float>, bottom:cpp.RawPointer<Float>, left:cpp.RawPointer<Float>, right:cpp.RawPointer<Float>):Void;
@:native('getScreenSize')
static function getScreenSize(width:cpp.RawPointer<Float>, height:cpp.RawPointer<Float>):Void;
}
#end
@@ -1,4 +0,0 @@
#pragma once
void initialize();
void setActive(bool active);
@@ -1,4 +0,0 @@
#pragma once
void getSafeAreaInsets(double* top, double* bottom, double* left, double* right);
void getScreenSize(double* width, double* height);
-41
View File
@@ -1,41 +0,0 @@
#import <Foundation/Foundation.h>
#import <AVFAudio/AVFAudio.h>
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);
}
}
-36
View File
@@ -1,36 +0,0 @@
#import "ScreenUtil.hpp"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
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;
}
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -10,7 +10,7 @@
<compilerflag value="-I${this_dir}/include" />
</files>
<files id="winapi">
<files id="external-windows">
<compilerflag value="-I${this_dir}/include" />
<file name="${this_dir}/src/winapi.cpp" />
@@ -31,6 +31,6 @@
<lib name="advapi32.lib" />
</section>
<files id="winapi" />
<files id="external-windows" />
</target>
</xml>
+15 -9
View File
@@ -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();
+1 -1
View File
@@ -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