From 10d7a20a79f8e7746d965cfadf1757b3e3799858 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 31 May 2022 15:59:29 -0700 Subject: [PATCH] Change to centiseconds across the program --- database/run.lisp | 2 +- speedrun.lisp | 6 ++++-- time.lisp | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/database/run.lisp b/database/run.lisp index a72f52e..739dc96 100644 --- a/database/run.lisp +++ b/database/run.lisp @@ -22,7 +22,7 @@ (let ((start (ignore-errors (run-split-start-time run-split))) (end (or (ignore-errors (run-split-end-time run-split)) (local-time:now)))) (if start - (floor (* 1000 (local-time:timestamp-difference end start)))))) + (floor (* 100 (local-time:timestamp-difference end start)))))) (defun format-elapsed-time (run-split) (let ((elapsed (run-split-elapsed-time run-split))) diff --git a/speedrun.lisp b/speedrun.lisp index df473c9..ba2d199 100644 --- a/speedrun.lisp +++ b/speedrun.lisp @@ -44,7 +44,7 @@ ;; Updates the current total elapsed time of the speedrun if it's running (defun update-time (speedrun) (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 (defun start-speedrun (speedrun) @@ -64,7 +64,9 @@ (setf (run-split-end-time (current-split speedrun)) now) (if (equal (speedrun-current-split-index speedrun) (1- (length (speedrun-splits speedrun)))) (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)) (progn (inc (speedrun-current-split-index speedrun)) diff --git a/time.lisp b/time.lisp index 3d0f2bb..009e9a5 100644 --- a/time.lisp +++ b/time.lisp @@ -1,9 +1,9 @@ -;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (ms . MILLISECONDS)) -(defun make-time-alist (ms) - `((hours . ,(floor (/ ms (* 1000 60 60)))) - (minutes . ,(floor (mod (/ ms (* 1000 60)) 60))) - (seconds . ,(floor (mod (/ ms 1000) 60))) - (ms . ,(mod ms 1000)))) +;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (cs . CENTISECONDS)) +(defun make-time-alist (cs) + `((hours . ,(floor (/ cs (* 100 60 60)))) + (minutes . ,(floor (mod (/ cs (* 100 60)) 60))) + (seconds . ,(floor (mod (/ cs 100) 60))) + (cs . ,(mod cs 100)))) ;; Formats, disregarding min/hour if they shouldn't be shown, a time alist to "H:M:S.ms" (defun format-time (time-alist) @@ -11,7 +11,7 @@ ((hours (cdr (assoc 'hours time-alist))) (minutes (cdr (assoc 'minutes time-alist))) (seconds (cdr (assoc 'seconds time-alist))) - (centis (round (/ (cdr (assoc 'ms time-alist)) 10)))) + (centis (cdr (assoc 'cs time-alist)))) (concatenate 'string (unless (zerop hours) (format nil "~2,'0d:" hours)) (unless (and (zerop minutes) (zerop hours)) (format nil "~2,'0d:" minutes))