Permalink
Browse files

Attempt at allowing you to reset the render loop, avoiding update cat…

…chups.
  • Loading branch information...
Shinmera committed Jul 31, 2017
1 parent ca400e7 commit 599b79df858cf3e4f1d30f80dba8a61276a93e44
Showing with 31 additions and 28 deletions.
  1. +2 −1 main.lisp
  2. +2 −1 package.lisp
  3. +27 −26 renderable.lisp
View
@@ -51,7 +51,8 @@
(load (scene main))
(start (scene main))
;; Cause camera to refresh
(issue (scene main) 'resize :width (width main) :height (height main)))
(issue (scene main) 'resize :width (width main) :height (height main))
(invoke-restart 'reset-render-loop))
;; FIXME: proper LOADing of a map
(defmethod setup-scene ((main main))
View
@@ -350,7 +350,8 @@
#:start
#:stop
#:render
#:update)
#:update
#:reset-render-loop)
;; retention.lisp
(:export
#:retained
View
@@ -31,29 +31,30 @@
(defmethod update ((renderable renderable) tt dt))
(defun render-loop (renderable)
(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))))
(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)))))

0 comments on commit 599b79d

Please sign in to comment.