From 7d73084635022234e399385ae2724ca03d47d2a5 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 22 Nov 2017 12:06:07 -0500 Subject: [PATCH] Fixed for Swift 3.0.2 compatibility --- Package.pins | 12 ++++++++++++ Package.resolved | 4 ++-- Package.swift | 33 ++++++++++----------------------- Sources/SDL/BitMaskOption.swift | 27 ++++++++++++++++++++++++++- Sources/SDLDemo/main.swift | 4 ++-- 5 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 Package.pins diff --git a/Package.pins b/Package.pins new file mode 100644 index 0000000..8b5013f --- /dev/null +++ b/Package.pins @@ -0,0 +1,12 @@ +{ + "autoPin": true, + "pins": [ + { + "package": "CSDL2", + "reason": null, + "repositoryURL": "https://github.com/PureSwift/CSDL2.git", + "version": "1.0.1" + } + ], + "version": 1 +} \ No newline at end of file diff --git a/Package.resolved b/Package.resolved index 69916f7..58fa175 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,9 +5,9 @@ "package": "CSDL2", "repositoryURL": "https://github.com/PureSwift/CSDL2.git", "state": { - "branch": "master", + "branch": null, "revision": "a4798aa0174f6661404b9df4ccaf2ba1dc9cc92c", - "version": null + "version": "1.0.1" } } ] diff --git a/Package.swift b/Package.swift index 7a4aac5..8f96f41 100644 --- a/Package.swift +++ b/Package.swift @@ -1,33 +1,20 @@ -// swift-tools-version:4.0 +// swift-tools-version:3.0.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "SDL", - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library( - name: "SDL", - targets: ["SDL"]), - .executable( - name: "SDLDemo", - targets: ["SDLDemo"]), + targets: [ + Target( + name: "SDLDemo", + dependencies: [.Target(name: "SDL")] + ), + Target( + name: "SDL" + ) ], dependencies: [ - .package(url: "https://github.com/PureSwift/CSDL2.git", .branch("master")) - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "SDLDemo", - dependencies: ["SDL"]), - .target( - name: "SDL", - dependencies: []), - .testTarget( - name: "SDLTests", - dependencies: ["SDL"]), + .Package(url: "https://github.com/PureSwift/CSDL2.git", majorVersion: 1) ] ) diff --git a/Sources/SDL/BitMaskOption.swift b/Sources/SDL/BitMaskOption.swift index 00e3ca4..839836c 100644 --- a/Sources/SDL/BitMaskOption.swift +++ b/Sources/SDL/BitMaskOption.swift @@ -6,14 +6,25 @@ // /// Enum represents a bit mask flag / option. +#if swift(>=4.0) public protocol BitMaskOption: RawRepresentable, Hashable where RawValue: FixedWidthInteger { /// All the cases of the enum. static var all: Set { get } } +#elseif swift(>=3.0.2) +public protocol BitMaskOption: RawRepresentable, Hashable { + + associatedtype RawValue: Integer + + /// All the cases of the enum. + static var all: Set { get } +} +#endif +#if swift(>=4.0) /// Convert Swift enums for option flags into their raw values OR'd. -internal extension Collection where Element: BitMaskOption { +public extension Collection where Element: BitMaskOption { var flags: Element.RawValue { @@ -21,6 +32,16 @@ internal extension Collection where Element: BitMaskOption { get { return reduce(0, { $0 | $1.rawValue }) } } } +#elseif swift(>=3.0.2) +public extension Collection where Iterator.Element: BitMaskOption { + + var flags: Iterator.Element.RawValue { + + @inline(__always) + get { return reduce(0, { $0 | $1.rawValue }) } + } +} +#endif internal extension BitMaskOption { @@ -34,6 +55,10 @@ internal extension BitMaskOption { @inline(__always) static func from(flags: RawValue) -> Set { + #if swift(>=4.0) return Self.all.filter({ $0.isContained(in: flags) }) + #elseif swift(>=3.0.2) + return Set(Array(Self.all).filter({ $0.isContained(in: flags) })) + #endif } } diff --git a/Sources/SDLDemo/main.swift b/Sources/SDLDemo/main.swift index 3388255..e2a719e 100644 --- a/Sources/SDLDemo/main.swift +++ b/Sources/SDLDemo/main.swift @@ -59,7 +59,7 @@ while isRunning { case SDL_WINDOWEVENT: - if event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED.rawValue { + if event.window.event == UInt8(SDL_WINDOWEVENT_SIZE_CHANGED.rawValue) { needsDisplay = true } @@ -89,7 +89,7 @@ while isRunning { // sleep to save energy let frameDuration = SDL_GetTicks() - startTime - if frameDuration < 1000 / framesPerSecond { + if frameDuration < 1000 / UInt32(framesPerSecond) { SDL_Delay((1000 / UInt32(framesPerSecond)) - frameDuration) } }