diff --git a/tracks/database.lisp b/tracks/database.lisp index 7dd0240..9d0c523 100644 --- a/tracks/database.lisp +++ b/tracks/database.lisp @@ -62,14 +62,20 @@ (connect-dirs (car cons) (car other-cons) (+ (cadr cons) (cadr other-cons))) (psetf (aref connections dir) nil (aref connections other) nil)))) + (merge-simple-eol (pos connections) + (loop for dir from 0 to 15 for cons across connections + when (and cons (not (car cons))) do + (psetf (car cons) (make-trackside :pos pos :side dir) + (cadr cons) (* 2 (cadr cons))))) (removable-p (connections) (every #'null connections))) - (loop for pos of-type aux:v3d in (loop for i being the hash-keys of tdb collect i) - for track = (gethash pos tdb) + (loop for pos of-type aux:v3d being the hash-keys of tdb using (hash-value track) when (and track (not (track-special track))) do (let ((connections (track-connects track))) (merge-2way connections) (when (removable-p connections) - (remhash pos tdb)))))) + (remhash pos tdb)))) + (loop for pos of-type aux:v3d being the hash-keys of tdb using (hash-value track) + when track do (merge-simple-eol pos (track-connects track))))) ;;; written based on https://gigamonkeys.com/book/practical-parsing-binary-files.html ;;; note that this implementation only reads nodes that are known to be tracks