From b1eed4b0190e44310dfe3fb5f6fa95cec73261b5 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Thu, 29 May 2025 01:14:30 +0100 Subject: [PATCH] Create define-system macro --- simulation.lisp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/simulation.lisp b/simulation.lisp index 3065ceb..e19e5e7 100644 --- a/simulation.lisp +++ b/simulation.lisp @@ -38,3 +38,17 @@ (with-slots (running simulation-thread) sim (setf running nil) (sb-thread:join-thread simulation-thread))) + +(defmacro define-simulation (name &key lagrangian coords render start params) + `(progn + (defclass ,name (simulation) + () + (:default-initargs :start ',start :params ',params)) + (defmethod update ((sim ,name) dt) + (with-slots (state params) sim + (setf state ,(let ((eqns (hamilton-eqns lagrangian coords))) + (update-body eqns coords params))))) + (defmethod render ((sim ,name)) + (with-slots (state) sim + (let ,(mapcar (lambda (q) `(,q (getf state ',q))) coords) + ,render)))))