Skip to content
Permalink
Browse files

Add frame count to ticks/updates.

  • Loading branch information...
Shinmera committed Jul 15, 2019
1 parent 200c71f commit 2c921d1982ae511adf420909280f1103c7c6327b
Showing with 37 additions and 32 deletions.
  1. +2 −1 event-loop.lisp
  2. +2 −2 main.lisp
  3. +2 −1 package.lisp
  4. +31 −28 renderable.lisp
@@ -146,7 +146,8 @@

(defclass tick (event)
((tt :initarg :tt :accessor tt)
(dt :initarg :dt :accessor dt)))
(dt :initarg :dt :accessor dt)
(fc :initarg :fc :accessor fc)))

(defclass class-changed (event)
((changed-class :initarg :changed-class :accessor changed-class)))
@@ -26,8 +26,8 @@
(defmethod handle (event (main main))
(issue (scene main) event))

(defmethod update ((main main) tt dt)
(issue (scene main) 'tick :tt tt :dt dt)
(defmethod update ((main main) tt dt fc)
(issue (scene main) 'tick :tt tt :dt dt :fc fc)
(process (scene main)))

(defmethod setup-rendering :after ((main main))
@@ -295,7 +295,8 @@
#:event
#:tick
#:tt
#:dt)
#:dt
#:fc)
;; features.lisp
(:export
#:*debug-features*
@@ -28,33 +28,36 @@
(stop renderable))

(defmethod render (thing (renderable renderable)))
(defmethod update ((renderable renderable) tt dt))
(defmethod update ((renderable renderable) tt dt fc))

(defmethod render-loop ((renderable renderable))
(with-retry-restart (reset-render-loop "Reset the render loop timing, not catching up with lost frames.")
(let ((tt 0.0d0)
(dt (coerce (delta-time renderable) 'double-float))
(current-time (current-time))
(accumulator 0.0d0)
(new-time 0.0d0)
(frame-time 0.0d0))
(declare (type double-float tt dt current-time
accumulator new-time frame-time))
(declare (optimize speed))
(unwind-protect
(with-error-logging (:trial.renderable "Error in render thread")
(loop while (thread renderable)
do (setf new-time (current-time))
(setf frame-time (- new-time current-time))
(setf current-time new-time)
(incf accumulator frame-time)
(loop while (<= dt accumulator)
do (update renderable tt dt)
(decf accumulator dt)
(incf tt dt))
;; FIXME: interpolate state
;; See http://gafferongames.com/game-physics/fix-your-timestep/
(setf (frame-time renderable) frame-time)
(with-simple-restart (abort "Abort the update and retry.")
(render renderable renderable))))
(v:info :trial.renderable "Exiting render-loop for ~a." renderable)))))
(declare (optimize speed))
(let ((fc 0))
(declare (type fixnum fc))
(with-retry-restart (reset-render-loop "Reset the render loop timing, not catching up with lost frames.")
(let ((tt 0.0d0)
(dt (coerce (delta-time renderable) 'double-float))
(current-time (current-time))
(accumulator 0.0d0)
(new-time 0.0d0)
(frame-time 0.0d0))
(declare (type double-float tt dt current-time
accumulator new-time frame-time))
(unwind-protect
(with-error-logging (:trial.renderable "Error in render thread")
(loop while (thread renderable)
do (setf new-time (current-time))
(setf frame-time (- new-time current-time))
(setf current-time new-time)
(incf accumulator frame-time)
(loop while (<= dt accumulator)
do (update renderable tt dt fc)
(decf accumulator dt)
(incf tt dt))
;; FIXME: interpolate state
;; See http://gafferongames.com/game-physics/fix-your-timestep/
(setf (frame-time renderable) frame-time)
(with-simple-restart (abort "Abort the update and retry.")
(render renderable renderable)
(incf fc))))
(v:info :trial.renderable "Exiting render-loop for ~a." renderable))))))

0 comments on commit 2c921d1

Please sign in to comment.
You can’t perform that action at this time.