diff --git a/wh-engine/serialization.lisp b/wh-engine/serialization.lisp index 37f0a4c..2335be9 100644 --- a/wh-engine/serialization.lisp +++ b/wh-engine/serialization.lisp @@ -13,13 +13,13 @@ (declare (type weak-pointer ptr)) (let ((target (weak-pointer-value ptr))) - (cond - ((typep target 'scene) + (typecase target + (scene (make-id-ref :scene [target id])) - ((typep target 'actor) + (actor (make-id-ref :scene [target scene id] :actor [target id])) - ((typep target 'component) + (component (make-id-ref :scene [target scene id] :actor [target actor id] :component (class-name (class-of target)))) @@ -68,11 +68,20 @@ (setf new-cdr (funcall atom-fun new-cdr))) (cons new-car new-cdr))) -(defun process-load-forms (obj table) +(defun process-load-forms (obj table &key (nice-syms nil)) "Update table with the forms necessary to generate obj." (multiple-value-bind (cons-form init-form) (make-load-form obj) - (let ((sym (gensym))) + (let ((sym (if nice-syms + (typecase obj + (scene (gensym (format nil "S~a-G" [obj :slot id]))) + (actor (gensym (format nil "A~a-G" [obj :slot id]))) + (component (gensym (if (typep [obj :slot actor] 'id-ref) + (format nil "C~a-~a-G" + (id-ref-actor [obj :slot actor]) (class-name (class-of obj))) + (format nil "C-~a-G" (class-name (class-of obj)))))) + (t (gensym))) + (gensym)))) (setf (gethash obj table) (cons sym (cons cons-form nil))) (when init-form (setf init-form @@ -89,7 +98,7 @@ :component ,(id-ref-component x))) ;; x needs to be run through process-load-forms ((typep x '(or standard-object structure-object condition class)) - (process-load-forms x table)) + (process-load-forms x table :nice-syms nice-syms)) ;; x doesn't need processing (t x))))) (setf (gethash obj table) (cons sym (cons cons-form init-form)))) @@ -134,14 +143,14 @@ x))) )) -(defun generate-load-forms (obj &key (prune t)) +(defun generate-load-forms (obj &key (prune t) (nice-syms nil)) "Generate code that restores the current state of obj." (declare (type boolean prune)) (let ((table (make-hash-table :test #'eq)) sym init-forms) ;; serialize - (setf sym (process-load-forms obj table)) + (setf sym (process-load-forms obj table :nice-syms nice-syms)) ;; collect init-forms (setf init-forms (loop for entry being each hash-value in table when (cddr entry)