Fix the clocking system and add an fps counter

This commit is contained in:
Renaud Casenave-Péré 2014-10-11 17:14:18 +09:00
parent e80c9ce69a
commit ad0f6a0eb8
3 changed files with 18 additions and 8 deletions

View file

@ -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)
(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))))
(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)

View file

@ -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)

View file

@ -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)))