Created
April 22, 2018 03:05
-
-
Save psilord/2e0151c676d1580e4bde91c8202d9097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/frame-manager.lisp b/src/frame-manager.lisp | |
index b0b3e7c..c954c46 100644 | |
--- a/src/frame-manager.lisp | |
+++ b/src/frame-manager.lisp | |
@@ -1,7 +1,8 @@ | |
(in-package :box.frame) | |
(defclass frame-manager () | |
- ((%start :initform (local-time:now)) | |
+ ((%vsyncp :initarg :vsyncp) | |
+ (%start :initform (local-time:now)) | |
(%now :initform (local-time:now)) | |
(%before :initform 0) | |
(%total-time :reader total-time | |
@@ -45,7 +46,7 @@ | |
(incf %frame-time %delta-buffer) | |
(let ((frame-count (truncate (1+ (* %frame-time refresh-rate)))) | |
(previous %frame-time)) | |
- (setf frame-count (if (minusp frame-count) 1 frame-count) | |
+ (setf frame-count (if (<= frame-count 0) 1 frame-count) | |
%frame-time (/ frame-count refresh-rate) | |
%delta-buffer (- previous %frame-time))))) | |
@@ -90,12 +91,13 @@ or perform operations periodically, rather than every game tick." | |
"This is designed to be called each iteration of a main game loop, which calls STEP-FUNC to update | |
the physics when necessary, based on the DELTA of the frame manager. PERIODIC-FUNC is a function to | |
be called periodically, controlled by the PERIOD-INTERVAL slot of FRAME-MANAGER." | |
- (with-slots (%init %now %start %before %total-time %frame-time %period) frame-manager | |
+ (with-slots (%vsyncp %init %now %start %before %total-time %frame-time %period) frame-manager | |
(setf %before %now | |
%now (local-time:now) | |
- %frame-time (local-time:timestamp-difference %now %before) | |
- %total-time (local-time:timestamp-difference %now %start)) | |
- (smooth-delta-time frame-manager refresh-rate) | |
+ %frame-time (float (local-time:timestamp-difference %now %before) 1.0) | |
+ %total-time (float (local-time:timestamp-difference %now %start) 1.0)) | |
+ (when %vsyncp | |
+ (smooth-delta-time frame-manager refresh-rate)) | |
(update frame-manager step-func) | |
(when periodic-func | |
(periodic-update frame-manager periodic-func)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment