Skip to content

Commit

Permalink
Merge pull request #3 from dn-m/trailing-ws
Browse files Browse the repository at this point in the history
Remove trailing whitespace
  • Loading branch information
jsbean authored Aug 5, 2017
2 parents 6809cbf + eea2a65 commit a62ece4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
20 changes: 10 additions & 10 deletions Sources/Timeline/Timeline.Timer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ extension Timeline {
/// operating sytems.
///
public class Timer {

/// For OSX 10.12+ / iOS 10+, this will be a `DispatchSourceTimer`. For earlier
/// operating systems, this will be a `Foundation.Timer`.
var timer: AnyObject?

/// The closure to be performed repeatedly.
let closure: () -> ()

/// Creates a `Timer` which performs the given `closure` and the given `interval`.
init(interval: Seconds, performing closure: @escaping () -> ()) {
self.closure = closure
}

/// Starts the `Timer`.
func start() {

if #available(OSX 10.12, iOS 10, *) {

let queue = DispatchQueue(
label: "com.bean.timer",
qos: .userInteractive,
attributes: .concurrent
)

let timer = DispatchSource.makeTimerSource(queue: queue)
timer.setEventHandler(handler: self.closure)
timer.schedule(deadline: .now(), repeating: .milliseconds(4))
timer.resume()
self.timer = timer

} else {

// Create a `Timer` that will call the `advance` method at the given `rate`
let timer = Foundation.Timer.scheduledTimer(
timeInterval: 1/120,
Expand All @@ -61,7 +61,7 @@ extension Timeline {
self.timer = timer
}
}

/// Stops the `Timer`.
func stop() {

Expand Down
44 changes: 22 additions & 22 deletions Sources/Timeline/Timeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public typealias Ticks = UInt64
/// Playback can occur at real-time, or modified by the `playbackRate`.
///
public class Timeline {

// MARK: - Nested Types

/// Status of the `Timeline`.
public enum Status {

/// The `Timeline` is playing.
case playing

/// The `Timeline` is stopped.
case stopped

/// The `Timeline` is paused at the given frame offset.
case paused(Seconds)
}

// MARK: - Instance Properties

/// The rate at which the `Timeline` is played-back. Defaults to `1`.
Expand All @@ -44,7 +44,7 @@ public class Timeline {
resume()
}
}

/// Current state of the `Timeline`.
public var status: Status = .stopped

Expand All @@ -60,34 +60,34 @@ public class Timeline {

/// Scale of `Seconds` to `Frames`.
internal var rate: Seconds

/// Seconds (in schedule-time) of last pause.
internal var lastPausedDate: Seconds = 0

// MARK: - Mechanisms

/// Schedule that store actions to be performed by their offset time.
///
/// At each offset point, any number of `Actions` can be performed.
public var schedule: Schedule

/// Calls the `advance()` function rapidly.
public var timer: Timer?

/// Clock.
///
/// Measures timing between successive shots of the `timer`, to ensure accuracy and to
/// Measures timing between successive shots of the `timer`, to ensure accuracy and to
/// prevent drifting.
public var clock = Clock()

/// Closure to be called when the `Timeline` has reached the end.
public var completion: (() -> ())?

/// Identifier of `Timeline`.
public let identifier: String

// MARK: - Initializers

/// Creates an empty `Timeline`.
public init(
identifier: String = "",
Expand Down Expand Up @@ -131,9 +131,9 @@ public class Timeline {
public func removeAll(identifiers: Set<String> = []) {
schedule.removeAll(identifiers: identifiers)
}

// MARK: - Playback

/// Starts the `Timeline`.
public func start() {
if case .playing = status { return }
Expand All @@ -142,38 +142,38 @@ public class Timeline {
timer = makeTimer()
status = .playing
}

/// Stops the `Timeline` from executing, and is placed at the beginning.
public func stop() {
if case .stopped = status { return }
lastPausedDate = 0
timer?.stop()
status = .stopped
}

/// Pauses the `Timeline`.
public func pause() {
if case .paused = status { return }
lastPausedDate += clock.elapsed * playbackRate
timer?.stop()
status = .paused(lastPausedDate)
}

/// Resumes the `Timeline`.
public func resume() {
if case .playing = status { return }
clock.start()
timer = makeTimer()
status = .playing
}

/// Skips the given `time` in `Seconds`.
///
/// - warning: Not currently available.
public func skip(to time: Seconds) {
fatalError()
}

/// Creates a new `Timer`, making sure that the previous `Timer` has been killed.
private func makeTimer() -> Timer {
self.timer?.stop()
Expand Down Expand Up @@ -240,7 +240,7 @@ internal func frames(
extension Timeline: CustomStringConvertible {

// MARK: - CustomStringConvertible

/// Printed description.
public var description: String {
return schedule.description
Expand Down

0 comments on commit a62ece4

Please sign in to comment.