Skip to content

Commit

Permalink
[#15] Keep track of times a frame was drawn to calcualte current-fram…
Browse files Browse the repository at this point in the history
…e-rate
  • Loading branch information
jfacorro committed Nov 24, 2018
1 parent 1ac7c9b commit b02e797
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/doodler/core.clje
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@

(defn current-frame-rate
[]
(/ (* (:frame-count *sketch*) 1000)
(- (u/time-mark) (:epoch *sketch*))))
(/ 1000 (- (:time-mark *sketch*) (:p-time-mark *sketch*))))

(defn millis
[]
(- (u/time-mark) (*sketch* :epoch)))

(defmacro defsketch
[name & opts]
Expand Down
23 changes: 14 additions & 9 deletions src/doodler/sketch.clje
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@

(defn next-refresh
[sketch time-mark]
(let [interval (-> sketch :internal-state :frame-interval)
time-mark (+ time-mark interval)
now (u/time-mark)
diff (- time-mark now)
delay (max 0 diff)]
;; (prn :interval interval :diff diff :delay delay)
(let [interval (-> sketch :internal-state :frame-interval)
next-time-mark (+ time-mark interval)
now (u/time-mark)
diff (- next-time-mark now)
delay (max 0 diff)]
(u/send-after delay :refresh)
(assoc sketch :refresh false)))
(assoc sketch
:refresh false
:p-time-mark (sketch :time-mark)
:time-mark time-mark
:frame-count (inc (sketch :frame-count)))))

(defn on-paint
[sketch]
Expand All @@ -113,7 +116,7 @@

(defn on-draw
[sketch f]
(with-sketch (update-in sketch [:frame-count] inc)
(with-sketch sketch
(doodler.wx/batch f)))

(defn on-resize
Expand Down Expand Up @@ -205,7 +208,9 @@
:on-resize on-resize
:on-close on-close-fn
:frame-count 0
:epoch (u/time-mark)}
:epoch (u/time-mark)
:p-time-mark (u/time-mark)
:time-mark (inc (u/time-mark))}
;; Create bitmap after frame is visible to
;; get the right dimensions
(let [bitmap (make-bitmap canvas)
Expand Down

0 comments on commit b02e797

Please sign in to comment.