Avoid blocking the main thread when delaying for button presses

This commit is contained in:
Cameron Gutman
2018-06-02 19:19:24 -07:00
parent 5a13e44fdb
commit 80254513c4
2 changed files with 30 additions and 22 deletions
+4
View File
@@ -180,6 +180,9 @@
if (controller != NULL) { if (controller != NULL) {
controller.controllerPausedHandler = ^(GCController *controller) { controller.controllerPausedHandler = ^(GCController *controller) {
Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]]; Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]];
// Get off the main thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self setButtonFlag:limeController flags:PLAY_FLAG]; [self setButtonFlag:limeController flags:PLAY_FLAG];
[self updateFinished:limeController]; [self updateFinished:limeController];
@@ -188,6 +191,7 @@
[self clearButtonFlag:limeController flags:PLAY_FLAG]; [self clearButtonFlag:limeController flags:PLAY_FLAG];
[self updateFinished:limeController]; [self updateFinished:limeController];
});
}; };
if (controller.extendedGamepad != NULL) { if (controller.extendedGamepad != NULL) {
+6 -2
View File
@@ -132,6 +132,7 @@
} }
else if (!touchMoved) { else if (!touchMoved) {
if ([[event allTouches] count] == 2) { if ([[event allTouches] count] == 2) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
Log(LOG_D, @"Sending right mouse button press"); Log(LOG_D, @"Sending right mouse button press");
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT); LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
@@ -140,8 +141,10 @@
usleep(100 * 1000); usleep(100 * 1000);
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT); LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
});
} else { } else {
if (!isDragging){ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
if (!self->isDragging){
Log(LOG_D, @"Sending left mouse button press"); Log(LOG_D, @"Sending left mouse button press");
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
@@ -149,8 +152,9 @@
// Wait 100 ms to simulate a real button press // Wait 100 ms to simulate a real button press
usleep(100 * 1000); usleep(100 * 1000);
} }
isDragging = false; self->isDragging = false;
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT); LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
});
} }
} }