rounded icon

This commit is contained in:
TrueZhuanjia
2025-06-29 16:35:06 +08:00
parent 527fb16428
commit d26cef7ef4
27 changed files with 6794 additions and 3617 deletions
+113 -10
View File
@@ -18,6 +18,9 @@
#include "Limelight.h"
@import GameController;
#if !TARGET_OS_TV
@import CoreMotion;
#endif
@import AudioToolbox;
static const double MOUSE_SPEED_DIVISOR = 1.25;
@@ -49,6 +52,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
char _controllerNumbers;
bool _multiController;
bool _swapABXYButtons;
int _motionMode;
bool _captureMouse;
}
@@ -90,18 +94,111 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
- (void) setMotionEventState:(uint16_t)controllerNumber motionType:(uint8_t)motionType reportRateHz:(uint16_t)reportRateHz
{
if (@available(iOS 14.0, tvOS 14.0, *)) {
Controller* controller = [_controllers objectForKey:[NSNumber numberWithInteger:controllerNumber]];
if (controller == nil) {
// No connected controller for this player
return;
}
if (controller.gamepad.motion == nil) {
// No motion supported for this controller
return;
}
#if !TARGET_OS_TV //tvOS has no device motion
NSInteger motionMode = _motionMode; //motionMode 0 = auto | 1 = always device | 2 = always controller
if(motionMode !=2 && controllerNumber < 2){
if(controller == nil || controller.gamepad.motion == nil || motionMode == 1){
//Player has no controller *or* no motion for controller 1 *or* wants to override controller 1 motion with device motion
//using device motion
if (controller == nil) {
// No connected controller for this player, use the _oscController instead
controller = _oscController;
}
if(!controller.motionManager) {
controller.motionManager = [[CMMotionManager alloc] init];
}
switch (motionType) {
case LI_MOTION_TYPE_ACCEL:
[controller.accelTimer invalidate];
controller.accelTimer = nil;
// Reset the last motion sample
CMAcceleration emptyDeviceAccelSample = {};
controller.lastDeviceAccelSample = emptyDeviceAccelSample;
{dispatch_sync(dispatch_get_main_queue(), ^{
controller.accelTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 / reportRateHz repeats:YES block:^(NSTimer *timer) {
// Don't send duplicate samples
CMAcceleration lastDeviceAccelSample = controller.lastDeviceAccelSample;
CMAcceleration deviceAccelSample = controller.motionManager.deviceMotion.userAcceleration;
//userAcceleration does not contain gravity, add gravity to x, y and z values:
deviceAccelSample.x += controller.motionManager.deviceMotion.gravity.x;
deviceAccelSample.y += controller.motionManager.deviceMotion.gravity.y;
deviceAccelSample.z += controller.motionManager.deviceMotion.gravity.z;
if (memcmp(&deviceAccelSample, &lastDeviceAccelSample, sizeof(deviceAccelSample)) == 0) {
return;
}
controller.lastDeviceAccelSample = deviceAccelSample;
// Convert g to m/s^2
if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){ //check for landscape left or landscape right
LiSendControllerMotionEvent((uint8_t)controllerNumber,
LI_MOTION_TYPE_ACCEL,
deviceAccelSample.y * -9.80665f,
deviceAccelSample.z * -9.80665f,
deviceAccelSample.x * -9.80665f);
}
else{
LiSendControllerMotionEvent((uint8_t)controllerNumber,
LI_MOTION_TYPE_ACCEL,
deviceAccelSample.y * +9.80665f,
deviceAccelSample.z * -9.80665f,
deviceAccelSample.x * +9.80665f);
}
}];
});}
break;
case LI_MOTION_TYPE_GYRO:
[controller.gyroTimer invalidate];
controller.gyroTimer = nil;
// Reset the last motion sample
CMRotationRate emptyDeviceGyroSample = {};
controller.lastDeviceGyroSample = emptyDeviceGyroSample;
[controller.motionManager startDeviceMotionUpdates];
dispatch_sync(dispatch_get_main_queue(), ^{
controller.gyroTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 / reportRateHz repeats:YES block:^(NSTimer *timer) {
// Don't send duplicate samples
CMRotationRate lastDeviceGyroSample = controller.lastDeviceGyroSample;
CMRotationRate deviceGyroSample = controller.motionManager.deviceMotion.rotationRate;
if (memcmp(&deviceGyroSample, &lastDeviceGyroSample, sizeof(deviceGyroSample)) == 0) {
return;
}
controller.lastDeviceGyroSample = deviceGyroSample;
// Convert rad/s to deg/s
if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){//check for landscape left or landscape right
LiSendControllerMotionEvent((uint8_t)controllerNumber,
LI_MOTION_TYPE_GYRO,
deviceGyroSample.y * 57.2957795f,
deviceGyroSample.z * 57.2957795f,
deviceGyroSample.x * 57.2957795f);
}
else{
LiSendControllerMotionEvent((uint8_t)controllerNumber,
LI_MOTION_TYPE_GYRO,
deviceGyroSample.y * -57.2957795f,
deviceGyroSample.z * 57.2957795f,
deviceGyroSample.x * -57.2957795f);
}
}];
});
break;
}
return;
}
}
#endif
switch (motionType) {
case LI_MOTION_TYPE_ACCEL:
[controller.accelTimer invalidate];
@@ -1108,6 +1205,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
_controllerNumbers = 0;
_multiController = streamConfig.multiController;
_swapABXYButtons = streamConfig.swapABXYButtons;
_motionMode = streamConfig.motionMode;
_delegate = delegate;
_oscController = [[Controller alloc] init];
@@ -1283,6 +1381,11 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
}
[_controllers removeAllObjects];
#if !TARGET_OS_TV
[self cleanupControllerMotion:_oscController];
[_oscController.motionManager stopDeviceMotionUpdates];
#endif
for (GCController* controller in [GCController controllers]) {
if ([ControllerSupport isSupportedGamepad:controller]) {
[self unregisterControllerCallbacks:controller];