Skip to content

Commit

Permalink
Added timescale to clock
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jul 16, 2016
1 parent ff42331 commit bb32553
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions clock.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
(defgeneric start (clock))
(defgeneric reset (clock))
(defgeneric running (clock))
(defgeneric timescale (clock))
(defgeneric synchronize (clock new))
(defgeneric clock (clock))

Expand All @@ -22,9 +23,11 @@
(defclass clock ()
((previous-time :initform (get-internal-real-time) :accessor previous-time)
(clock :initarg :clock :accessor clock)
(running :initarg :running :accessor running))
(running :initarg :running :accessor running)
(timescale :initarg :timescale :accessor timescale))
(:default-initargs
:clock 0.0s0
:timescale 1.0s0
:running NIL))

(define-self-returning-method stop ((clock clock)))
Expand Down Expand Up @@ -66,9 +69,10 @@ Internal clock is at ~a~&"
(defmethod update :before ((clock clock))
(let ((new-time (get-internal-real-time)))
(incf (clock clock)
(float (/ (- new-time (previous-time clock))
internal-time-units-per-second)
1.0s0))
(* (float (/ (- new-time (previous-time clock))
internal-time-units-per-second)
1.0s0)
(timescale clock)))
(setf (previous-time clock) new-time)))

(defmethod update :around ((clock clock))
Expand Down
5 changes: 5 additions & 0 deletions documentation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ See CLOCK")
(function running
"Accessor to whether the clock is currently running or not.
See CLOCK")

(function timescale
"Accessor to the timescale of the clock to allow slowing or speeding up the progression of time.
See CLOCK")

(function synchronize
Expand Down
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#:start
#:reset
#:running
#:timescale
#:synchronize
#:clock

Expand Down

0 comments on commit bb32553

Please sign in to comment.