try to reduce directionPad on-screen widget performance cost

This commit is contained in:
TrueZhuanjia committed 2025-08-27 14:04:45 +08:00
1 parent 19e78d5eb6
commit 83566ad4e1
3 files changed
+60 -27

No files matched your search

+1
View File
@@ -116,6 +116,7 @@ import UIKit
] ]
@objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "DS4TOUCH", "MOUSEPAD", "DPAD", "TRACKBALL", "WASDPAD", "ARROWPAD"] @objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "DS4TOUCH", "MOUSEPAD", "DPAD", "TRACKBALL", "WASDPAD", "ARROWPAD"]
@objc public static let directionPads: [String] = ["DPAD", "WASDPAD", "ARROWPAD"]
@objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"] @objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"]
@objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"] @objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"]
@objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"] @objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"]
+57 -27
View File
@@ -507,6 +507,7 @@ import UIKit
center = storedCenter //anchor the center while resizing self center = storedCenter //anchor the center while resizing self
setupButtonDownVisualEffectLayer(); setupButtonDownVisualEffectLayer();
if CommandManager.directionPads.contains(touchPadString) {setupLrudDirectionIndicatorlayers()}
} }
private func createAndShowl3r3Indicator() -> CAShapeLayer{ private func createAndShowl3r3Indicator() -> CAShapeLayer{
@@ -680,17 +681,31 @@ import UIKit
//=====LRUD(left right up & down buttons) touchPad touch ========================================= //=====LRUD(left right up & down buttons) touchPad touch =========================================
private func createAndShowLrudBall(at point: CGPoint) -> CAShapeLayer { private func showLrudBall(at point: CGPoint) {
// Create a circular path using UIBezierPath // Create a circular path using UIBezierPath
CATransaction.begin()
CATransaction.setDisableActions(true)
let path = UIBezierPath(arcCenter: point, radius: 10, startAngle: 0, endAngle: 2 * .pi, clockwise: true) let path = UIBezierPath(arcCenter: point, radius: 10, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
// Create a CAShapeLayer
lrudIndicatorBall.path = path.cgPath // Assign the circular path to the shape layer
lrudIndicatorBall.position = CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame))
lrudIndicatorBall.isHidden = false;
CATransaction.commit()
}
private func createLrudBall() -> CAShapeLayer {
// Create a circular path using UIBezierPath
let path = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 10, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
// Create a CAShapeLayer // Create a CAShapeLayer
let ballLayer = CAShapeLayer() let ballLayer = CAShapeLayer()
ballLayer.path = path.cgPath // Assign the circular path to the shape layer ballLayer.path = path.cgPath // Assign the circular path to the shape layer
self.layer.superlayer?.addSublayer(ballLayer) self.layer.superlayer?.addSublayer(ballLayer)
ballLayer.position = CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame))
// Set the stroke color and width (border of the circle) // Set the stroke color and width (border of the circle)
ballLayer.strokeColor = stickBallColor ballLayer.strokeColor = stickBallColor
ballLayer.lineWidth = 0 ballLayer.lineWidth = 0
@@ -698,6 +713,7 @@ import UIKit
ballLayer.shadowRadius = 0; ballLayer.shadowRadius = 0;
ballLayer.shadowOpacity = 0.8 ballLayer.shadowOpacity = 0.8
ballLayer.name = "lrudBall" ballLayer.name = "lrudBall"
ballLayer.isHidden = true
// Set the fill color (inside of the circle) // Set the fill color (inside of the circle)
ballLayer.fillColor = stickBallColor // Light fill with some transparency ballLayer.fillColor = stickBallColor // Light fill with some transparency
@@ -726,18 +742,15 @@ import UIKit
private func showLrudDirectionIndicator(with indicatorLayer:CAShapeLayer){ private func showLrudDirectionIndicator(with indicatorLayer:CAShapeLayer){
// Add the border layer below the super layer // Add the border layer below the super layer
self.layer.superlayer?.insertSublayer(indicatorLayer, below: self.layer) indicatorLayer.borderColor = voidlinkPurple
// show the indicator based on the touchBeganLocation // show the indicator based on the touchBeganLocation
let newPosition = CGPointMake(CGRectGetMinX(self.frame)+touchBeganLocation.x, CGRectGetMinY(self.frame)+touchBeganLocation.y) indicatorLayer.position = CGPointMake(CGRectGetMinX(self.frame)+touchBeganLocation.x, CGRectGetMinY(self.frame)+touchBeganLocation.y)
if indicatorLayer.position != newPosition && vibrationOn {
vibrationGenerator.prepare() vibrationGenerator.prepare()
vibrationGenerator.impactOccurred() vibrationGenerator.impactOccurred()
// print("vibrationInstance: \(vibrationGenerator)") print("vibrationInstance: \(vibrationGenerator)")
}
indicatorLayer.position = newPosition
} }
private func handleLrudTouchMove(){ private func handleLrudTouchMove(){
@@ -780,8 +793,8 @@ import UIKit
} }
} }
else{ else{
self.upIndicator.removeFromSuperlayer() //self.upIndicator.removeFromSuperlayer()
self.upIndicator.position = CGPointMake(0, 0) self.upIndicator.borderColor = UIColor.clear.cgColor
switch touchPadString { switch touchPadString {
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["W"]!,Int8(KEY_ACTION_UP), 0) case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["W"]!,Int8(KEY_ACTION_UP), 0)
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["UP_ARROW"]!,Int8(KEY_ACTION_UP), 0) case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["UP_ARROW"]!,Int8(KEY_ACTION_UP), 0)
@@ -799,8 +812,8 @@ import UIKit
} }
} }
else{ else{
self.downIndicator.removeFromSuperlayer() // self.downIndicator.removeFromSuperlayer()
self.downIndicator.position = CGPointMake(0, 0) self.downIndicator.borderColor = UIColor.clear.cgColor
switch touchPadString { switch touchPadString {
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["S"]!,Int8(KEY_ACTION_UP), 0) case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["S"]!,Int8(KEY_ACTION_UP), 0)
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["DOWN_ARROW"]!,Int8(KEY_ACTION_UP), 0) case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["DOWN_ARROW"]!,Int8(KEY_ACTION_UP), 0)
@@ -818,8 +831,8 @@ import UIKit
} }
} }
else{ else{
self.leftIndicator.removeFromSuperlayer() // self.leftIndicator.removeFromSuperlayer()
self.leftIndicator.position = CGPointMake(0, 0) self.leftIndicator.borderColor = UIColor.clear.cgColor
switch touchPadString { switch touchPadString {
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["A"]!,Int8(KEY_ACTION_UP), 0) case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["A"]!,Int8(KEY_ACTION_UP), 0)
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["LEFT_ARROW"]!,Int8(KEY_ACTION_UP), 0) case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["LEFT_ARROW"]!,Int8(KEY_ACTION_UP), 0)
@@ -837,8 +850,8 @@ import UIKit
} }
} }
else{ else{
self.rightIndicator.removeFromSuperlayer() // self.rightIndicator.removeFromSuperlayer()
self.rightIndicator.position = CGPointMake(0, 0) self.rightIndicator.borderColor = UIColor.clear.cgColor
switch touchPadString { switch touchPadString {
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["D"]!,Int8(KEY_ACTION_UP), 0) case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["D"]!,Int8(KEY_ACTION_UP), 0)
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["RIGHT_ARROW"]!,Int8(KEY_ACTION_UP), 0) case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["RIGHT_ARROW"]!,Int8(KEY_ACTION_UP), 0)
@@ -949,6 +962,17 @@ import UIKit
CATransaction.commit() CATransaction.commit()
} }
private func setupLrudDirectionIndicatorlayers() {
self.layer.superlayer?.insertSublayer(leftIndicator, below: self.layer);
self.layer.superlayer?.insertSublayer(rightIndicator, below: self.layer);
self.layer.superlayer?.insertSublayer(upIndicator, below: self.layer);
self.layer.superlayer?.insertSublayer(downIndicator, below: self.layer);
leftIndicator.borderColor = UIColor.clear.cgColor
rightIndicator.borderColor = UIColor.clear.cgColor
upIndicator.borderColor = UIColor.clear.cgColor
downIndicator.borderColor = UIColor.clear.cgColor
self.lrudIndicatorBall = self.createLrudBall()
}
private func setupButtonDownVisualEffectLayer() { private func setupButtonDownVisualEffectLayer() {
self.buttonDownVisualEffectWidth = 8 self.buttonDownVisualEffectWidth = 8
@@ -1136,7 +1160,7 @@ import UIKit
self.l3r3Indicator = self.createAndShowl3r3Indicator() self.l3r3Indicator = self.createAndShowl3r3Indicator()
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)} self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)}
case "DPAD", "WASDPAD", "ARROWPAD": case "DPAD", "WASDPAD", "ARROWPAD":
if allCapturedTouchesCount == 1 {self.lrudIndicatorBall = createAndShowLrudBall(at: touchBeganLocation)} if allCapturedTouchesCount == 1 {showLrudBall(at: touchBeganLocation)}
if quickDoubleTapDetected { if quickDoubleTapDetected {
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings) self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
DispatchQueue.global(qos: .userInteractive).async { DispatchQueue.global(qos: .userInteractive).async {
@@ -1398,6 +1422,9 @@ import UIKit
self.touchBegan = false self.touchBegan = false
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
CATransaction.begin()
CATransaction.setDisableActions(true)
// for checking stationary touch points // for checking stationary touch points
if self.touchPadString != "MOUSEPAD" {quickDoubleTapDetected = false} //do not reset this flag here in mousePad mode if self.touchPadString != "MOUSEPAD" {quickDoubleTapDetected = false} //do not reset this flag here in mousePad mode
@@ -1478,16 +1505,16 @@ import UIKit
break break
} }
} }
self.l3r3Indicator.removeFromSuperlayer()
self.upIndicator.removeFromSuperlayer()
self.downIndicator.removeFromSuperlayer()
self.leftIndicator.removeFromSuperlayer()
self.rightIndicator.removeFromSuperlayer()
// self.lrudIndicatorBall.removeFromSuperlayer()
for subLayer in self.layer.superlayer?.sublayers ?? [] {
if subLayer.name == "lrudBall" {subLayer.removeFromSuperlayer()}
}
self.l3r3Indicator.borderColor = UIColor.clear.cgColor
if CommandManager.directionPads.contains(touchPadString){
self.upIndicator.borderColor = UIColor.clear.cgColor
self.downIndicator.borderColor = UIColor.clear.cgColor
self.leftIndicator.borderColor = UIColor.clear.cgColor
self.rightIndicator.borderColor = UIColor.clear.cgColor
self.lrudIndicatorBall.isHidden = true
}
if !OnScreenWidgetView.editMode && !self.cmdString.contains("+") && !self.comboButtonStrings.isEmpty { // if the command(keystring contains "+", it's a legacy multi-key command if !OnScreenWidgetView.editMode && !self.cmdString.contains("+") && !self.comboButtonStrings.isEmpty { // if the command(keystring contains "+", it's a legacy multi-key command
self.handleButtonSlidingUp(touches: touches) self.handleButtonSlidingUp(touches: touches)
@@ -1505,6 +1532,8 @@ import UIKit
} }
} }
CATransaction.commit()
if OnScreenWidgetView.editMode { if OnScreenWidgetView.editMode {
storedCenter = center // Update initial center for next movement storedCenter = center // Update initial center for next movement
if center != layoutChanges.last { if center != layoutChanges.last {
@@ -1545,5 +1574,6 @@ import UIKit
self.handlebuttonUp() self.handlebuttonUp()
} }
} }
+2
View File
@@ -332,6 +332,7 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
while (LiPollNextVideoFrame(&handle, &du)) { while (LiPollNextVideoFrame(&handle, &du)) {
LiCompleteVideoFrame(handle, DrSubmitDecodeUnit(du)); LiCompleteVideoFrame(handle, DrSubmitDecodeUnit(du));
/*
// Calculate the actual display refresh rate // Calculate the actual display refresh rate
double displayRefreshRate = 1 / (_displayLink.targetTimestamp - _displayLink.timestamp); double displayRefreshRate = 1 / (_displayLink.targetTimestamp - _displayLink.timestamp);
@@ -345,6 +346,7 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
break; break;
} }
} }
*/
} }
} }