Change to centiseconds across the program

This commit is contained in:
Logan Hunt 2022-05-31 15:59:29 -07:00
parent 84e566e92b
commit 10d7a20a79
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
3 changed files with 12 additions and 10 deletions

View File

@ -22,7 +22,7 @@
(let ((start (ignore-errors (run-split-start-time run-split))) (let ((start (ignore-errors (run-split-start-time run-split)))
(end (or (ignore-errors (run-split-end-time run-split)) (local-time:now)))) (end (or (ignore-errors (run-split-end-time run-split)) (local-time:now))))
(if start (if start
(floor (* 1000 (local-time:timestamp-difference end start)))))) (floor (* 100 (local-time:timestamp-difference end start))))))
(defun format-elapsed-time (run-split) (defun format-elapsed-time (run-split)
(let ((elapsed (run-split-elapsed-time run-split))) (let ((elapsed (run-split-elapsed-time run-split)))

View File

@ -44,7 +44,7 @@
;; Updates the current total elapsed time of the speedrun if it's running ;; Updates the current total elapsed time of the speedrun if it's running
(defun update-time (speedrun) (defun update-time (speedrun)
(if (eq (speedrun-state speedrun) 'RUNNING) (if (eq (speedrun-state speedrun) 'RUNNING)
(setf (speedrun-elapsed speedrun) (* 1000 (/ (- (get-internal-real-time) (speedrun-start-timestamp speedrun)) internal-time-units-per-second))))) (setf (speedrun-elapsed speedrun) (floor (* 100 (/ (- (get-internal-real-time) (speedrun-start-timestamp speedrun)) internal-time-units-per-second))))))
;; Initializes a speedrun to start running the timer ;; Initializes a speedrun to start running the timer
(defun start-speedrun (speedrun) (defun start-speedrun (speedrun)
@ -64,7 +64,9 @@
(setf (run-split-end-time (current-split speedrun)) now) (setf (run-split-end-time (current-split speedrun)) now)
(if (equal (speedrun-current-split-index speedrun) (1- (length (speedrun-splits speedrun)))) (if (equal (speedrun-current-split-index speedrun) (1- (length (speedrun-splits speedrun))))
(progn (progn
(setf (speedrun-state speedrun) 'STOPPED) (setf
(speedrun-elapsed speedrun) (apply '+ (mapcar 'run-split-elapsed-time (speedrun-splits speedrun)))
(speedrun-state speedrun) 'STOPPED)
(save-speedrun speedrun)) (save-speedrun speedrun))
(progn (progn
(inc (speedrun-current-split-index speedrun)) (inc (speedrun-current-split-index speedrun))

View File

@ -1,9 +1,9 @@
;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (ms . MILLISECONDS)) ;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (cs . CENTISECONDS))
(defun make-time-alist (ms) (defun make-time-alist (cs)
`((hours . ,(floor (/ ms (* 1000 60 60)))) `((hours . ,(floor (/ cs (* 100 60 60))))
(minutes . ,(floor (mod (/ ms (* 1000 60)) 60))) (minutes . ,(floor (mod (/ cs (* 100 60)) 60)))
(seconds . ,(floor (mod (/ ms 1000) 60))) (seconds . ,(floor (mod (/ cs 100) 60)))
(ms . ,(mod ms 1000)))) (cs . ,(mod cs 100))))
;; Formats, disregarding min/hour if they shouldn't be shown, a time alist to "H:M:S.ms" ;; Formats, disregarding min/hour if they shouldn't be shown, a time alist to "H:M:S.ms"
(defun format-time (time-alist) (defun format-time (time-alist)
@ -11,7 +11,7 @@
((hours (cdr (assoc 'hours time-alist))) ((hours (cdr (assoc 'hours time-alist)))
(minutes (cdr (assoc 'minutes time-alist))) (minutes (cdr (assoc 'minutes time-alist)))
(seconds (cdr (assoc 'seconds time-alist))) (seconds (cdr (assoc 'seconds time-alist)))
(centis (round (/ (cdr (assoc 'ms time-alist)) 10)))) (centis (cdr (assoc 'cs time-alist))))
(concatenate 'string (concatenate 'string
(unless (zerop hours) (format nil "~2,'0d:" hours)) (unless (zerop hours) (format nil "~2,'0d:" hours))
(unless (and (zerop minutes) (zerop hours)) (format nil "~2,'0d:" minutes)) (unless (and (zerop minutes) (zerop hours)) (format nil "~2,'0d:" minutes))