Skip to content

Commit

Permalink
Merge pull request #162 from XuYicong/master
Browse files Browse the repository at this point in the history
Fix controller input lag or unresponsive in some games
  • Loading branch information
TheMoonThatRises authored Jul 10, 2024
2 parents 5f8a7c9 + 27a1429 commit 4c2a3a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions PlayTools/Controls/PlayInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ class PlayInput {
qos: .userInteractive,
autoreleaseFrequency: .workItem)

@objc func drainMainDispatchQueue() {
_dispatch_main_queue_callback_4CF(nil)
}

func initialize() {
// drain the dispatch queue every frame for responding to GCController events
let displaylink = CADisplayLink(target: self, selector: #selector(drainMainDispatchQueue))
displaylink.add(to: .main, forMode: .common)

if !PlaySettings.shared.keymapping {
return
}
Expand Down
4 changes: 4 additions & 0 deletions PlayTools/PlayTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ FOUNDATION_EXPORT const unsigned char PlayToolsVersionString[];
#import "UIApplication+Private.h"
#import "UIEvent+Private.h"
#import "UITouch+Private.h"

// This is the function that CFRunLoop calls to serve main dispatch queue
// Used by PlayInput to manually drain the queue
extern void _dispatch_main_queue_callback_4CF(void *);

0 comments on commit 4c2a3a3

Please sign in to comment.