From ad0f6a0eb892007e24a480964e957a3ec973211c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20Casenave-P=C3=A9r=C3=A9?= Date: Sat, 11 Oct 2014 17:14:18 +0900 Subject: [PATCH] Fix the clocking system and add an fps counter --- src/debug.lisp | 23 ++++++++++++++++------- src/stoe.lisp | 1 + src/utils.lisp | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/debug.lisp b/src/debug.lisp index 198f618..27158b6 100644 --- a/src/debug.lisp +++ b/src/debug.lisp @@ -11,6 +11,7 @@ (in-package :stoe.debug) (defvar *swank-server-port* 4006) +(defvar *frames-per-second* 0.0) (defun initialize (&optional argv) "Initialize the debug module. @@ -31,12 +32,20 @@ start the swank server to accept remote connection." (add-hook modules:*initialize-hook* #'initialize) (add-hook modules:*finalize-hook* #'finalize) -(defun update (delta-time) - "Eval the repl each frame." - #+swank - (let ((conn (or swank::*emacs-connection* - (swank::default-connection)))) - (when conn - (swank::handle-requests conn t)))) +(let ((time-counter 0.0) + (frames-counter 0)) + (defun update (delta-time) + "Eval the repl each frame." + #+swank + (let ((conn (or swank::*emacs-connection* + (swank::default-connection)))) + (when conn + (swank::handle-requests conn t))) + (incf time-counter delta-time) + (incf frames-counter) + (when (> time-counter 1000000.0) + (setf *frames-per-second* frames-counter) + (setf time-counter 0.0) + (setf frames-counter 0)))) (add-hook modules:*update-hook* #'update) diff --git a/src/stoe.lisp b/src/stoe.lisp index 02054ce..e9d764b 100644 --- a/src/stoe.lisp +++ b/src/stoe.lisp @@ -18,6 +18,7 @@ continue unless `unprotected' is t." (setf exit-main-loop nil) (let ((clock (make-clock))) + (update-current-time) (loop while (not exit-main-loop) do (restartable unprotected (update-current-time) diff --git a/src/utils.lisp b/src/utils.lisp index 9658bbd..87724af 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -125,7 +125,7 @@ "Update clock using `sec' and `usec' values passed as parameter." (unless (clock-paused clock) (setf (clock-last-time clock) (clock-time clock)) - (setf (clock-time clock) (* (or delta-time (get-delta-time)) (clock-scale clock))))) + (incf (clock-time clock) (* (or delta-time (get-delta-time)) (clock-scale clock))))) (defun clock-delta (clock) (- (clock-time clock) (clock-last-time clock)))