summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-05-31 15:59:29 -0700
committerLogan Hunt <loganhunt@simponic.xyz>2022-05-31 15:59:29 -0700
commit10d7a20a79f8e7746d965cfadf1757b3e3799858 (patch)
treed0a3e66456f28858701e2ca2507ba452de3185f9
parent84e566e92bd7c00fa01bd08c5d22ed77cbeb1a4c (diff)
downloadlispruns-10d7a20a79f8e7746d965cfadf1757b3e3799858.tar.gz
lispruns-10d7a20a79f8e7746d965cfadf1757b3e3799858.zip
Change to centiseconds across the program
-rw-r--r--database/run.lisp2
-rw-r--r--speedrun.lisp6
-rw-r--r--time.lisp14
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))