The Skung Rockification of Ziggy Skungdust and the SIMD's
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import Foundation
|
||||
import SDL2
|
||||
import Maths
|
||||
|
||||
|
||||
public class GamePad
|
||||
@ -144,8 +145,8 @@ internal extension GamePad.Buttons
|
||||
{
|
||||
case .east: SDL_CONTROLLER_BUTTON_B
|
||||
case .south: SDL_CONTROLLER_BUTTON_A
|
||||
case .west: SDL_CONTROLLER_BUTTON_Y
|
||||
case .north: SDL_CONTROLLER_BUTTON_X
|
||||
case .north: SDL_CONTROLLER_BUTTON_Y
|
||||
case .west: SDL_CONTROLLER_BUTTON_X
|
||||
case .start: SDL_CONTROLLER_BUTTON_START
|
||||
case .select: SDL_CONTROLLER_BUTTON_BACK
|
||||
case .guide: SDL_CONTROLLER_BUTTON_GUIDE
|
||||
@ -166,3 +167,32 @@ internal extension GamePad.Buttons
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public extension Vector2 where Scalar: FloatingPoint
|
||||
{
|
||||
func cardinalDeadzone(min: Scalar, max: Scalar) -> Self
|
||||
{
|
||||
Self(self.x.axisDeadzone(min, max), self.y.axisDeadzone(min, max))
|
||||
}
|
||||
|
||||
func radialDeadzone(min: Scalar, max: Scalar) -> Self
|
||||
{
|
||||
let magnitude = self.len
|
||||
if magnitude == .zero || magnitude < min { return Self.zero }
|
||||
if magnitude > max { return self / magnitude }
|
||||
let rescale = (magnitude - min) / (max - min)
|
||||
return self / magnitude * rescale
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension FloatingPoint
|
||||
{
|
||||
@inline(__always) internal func axisDeadzone(_ min: Self, _ max: Self) -> Self
|
||||
{
|
||||
let xabs = abs(self)
|
||||
return if xabs <= min { 0 }
|
||||
else if xabs >= max { Self(signOf: self, magnitudeOf: 1) }
|
||||
else { Self(signOf: self, magnitudeOf: xabs - min) / (max - min) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user