Skip to content

Commit

Permalink
Fixed for Swift 3.0.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 22, 2017
1 parent 10688a8 commit 7d73084
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
12 changes: 12 additions & 0 deletions Package.pins
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"autoPin": true,
"pins": [
{
"package": "CSDL2",
"reason": null,
"repositoryURL": "https://github.com/PureSwift/CSDL2.git",
"version": "1.0.1"
}
],
"version": 1
}
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Expand Down
33 changes: 10 additions & 23 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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)
]
)
27 changes: 26 additions & 1 deletion Sources/SDL/BitMaskOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,42 @@
//

/// 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<Self> { get }
}
#elseif swift(>=3.0.2)
public protocol BitMaskOption: RawRepresentable, Hashable {

associatedtype RawValue: Integer

/// All the cases of the enum.
static var all: Set<Self> { 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 {

@inline(__always)
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 {

Expand All @@ -34,6 +55,10 @@ internal extension BitMaskOption {
@inline(__always)
static func from(flags: RawValue) -> Set<Self> {

#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
}
}
4 changes: 2 additions & 2 deletions Sources/SDLDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 7d73084

Please sign in to comment.