Skip to content

Commit

Permalink
sim-time-up?
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthalloway committed Feb 7, 2013
1 parent 4d45804 commit bfbc6b6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/simulant/sim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,20 @@ process."
(fn [clock elapsed] (getx clock :clock/type)))

(defmulti clock-elapsed-time
"Return the elapsed simulation time, in msec"
"Return the elapsed simulation time, in msec, or nil
if clock has not started"
(fn [clock] (getx clock :clock/type)))

;; ## Clock
(defn sim-time-up?
"Has the time allotment for this sim expired?"
[sim]
(if-let [clock (get sim :sim/clock)]
(if-let [elapsed (clock-elapsed-time clock)]
(< (-> sim :test/_sims only :test/duration) elapsed)
false)
false))

;; ## Processes
(def ^:private default-executor
"Default executor used by sim agents. This is important because
Expand Down Expand Up @@ -267,10 +278,10 @@ process."

(defmethod clock-elapsed-time :clock.type/fixed
[clock]
(let [start (getx clock :clock/realStart)
mult (getx clock :clock/multiplier)
real-elapsed (- (System/currentTimeMillis) start)]
(long (* real-elapsed mult))))
(when-let [start (get clock :clock/realStart)]
(let [mult (getx clock :clock/multiplier)
real-elapsed (- (System/currentTimeMillis) start)]
(long (* real-elapsed mult)))))

(defn sleep-until
[clock twhen]
Expand Down

0 comments on commit bfbc6b6

Please # to comment.