a bunch of shit lol

This commit is contained in:
~keith 2022-02-22 17:16:02 +00:00
parent 738da6f74b
commit 98d8b35a4f
Signed by: keith
GPG Key ID: 5BEBEEAB2C73D520
5 changed files with 38 additions and 36 deletions

View File

@ -92,13 +92,15 @@
(funcall fun this) (funcall fun this)
(loop for child-ptr in (o! this children) (loop for child-ptr in (o! this children)
when (typep child-ptr 'weak-pointer) when (typep child-ptr 'weak-pointer)
do (o! (weak-pointer-value child-ptr) (apply-to-tree fun)))) do (let ((child (weak-pointer-value child-ptr)))
(unless child
(error "nil value dereferencing child-ptr in ~S" this))
(o! child (apply-to-tree fun)))))
(defmethod print-object ((this actor) stream) (defmethod print-object ((this actor) stream)
(print-unreadable-object (this stream :type t :identity t) (print-unreadable-object (this stream :type t :identity t)
(prin1 (o! this :slot id) stream) (format stream "~D ~S"
(princ " ") (o! this :slot id) (o! this :slot name))))
(prin1 (o! this :slot name) stream)))
(defmethod get-component ((this actor) component-class) (defmethod get-component ((this actor) component-class)
"Get a component of the specified class attached to this object." "Get a component of the specified class attached to this object."
@ -183,6 +185,7 @@
(defmethod resume ((this actor)) (defmethod resume ((this actor))
"Initialize or restore this actor's state." "Initialize or restore this actor's state."
(format t "=> actor resume: ~S~%" this)
;; Restore self ;; Restore self
(when (typep (o! this :slot scene) 'id-ref) (when (typep (o! this :slot scene) 'id-ref)
;; relink to scene ;; relink to scene
@ -218,6 +221,7 @@
(loop for child-cell on (o! this :slot children) (loop for child-cell on (o! this :slot children)
when (typep (car child-cell) 'weak-pointer) when (typep (car child-cell) 'weak-pointer)
do (rplaca child-cell (referize (car child-cell)))) do (rplaca child-cell (referize (car child-cell))))
(format t "suspend -- children: ~S~%" (o! this :slot children))
(referize-setf (o! this :slot scene)) (referize-setf (o! this :slot scene))
(referize-setf (o! this :slot parent))) (referize-setf (o! this :slot parent)))
@ -226,11 +230,7 @@
(loop for component in (o! this components) (loop for component in (o! this components)
do (when (o! component active-p) do (when (o! component active-p)
(unless (o! component started-p) (o! component (start))) (unless (o! component started-p) (o! component (start)))
(o! component (update)))) (o! component (update)))))
; (loop for child in (o! this children)
; do (when (o! child active-p)
; (o! child (update))))
)
(defmethod destroy ((this actor)) (defmethod destroy ((this actor))
"Mark this object for unloading." "Mark this object for unloading."

View File

@ -98,19 +98,19 @@
"Get a scene by its ID." "Get a scene by its ID."
(find-if (lambda (scene) (eq (o! scene id) scene-id)) *world-scenes*)) (find-if (lambda (scene) (eq (o! scene id) scene-id)) *world-scenes*))
(defun attach-actor-to-world (actor scene) (defun initialize-actors-in (scene &rest actors)
"Properly attach actor and its descendents to scene, and initialize them." "Properly attach actors and their descendents to scene, and initialize them."
;; attach actors to scene (loop for actor in actors
(apply-to-tree actor (lambda (a) do ;; attach actor to scene
(setf (o! a :slot scene) nil) (o! actor (apply-to-tree (lambda (a)
(o! scene (add-actor a)))) (setf (o! a :slot scene) nil)
;; (resume) -> automatically resumes children (o! scene (add-actor a)))))
(o! actor (resume)) ;; (resume) -> automatically resumes children
;; FIXME make (activate) call itself recursively on children (o! actor (resume))
(apply-to-tree actor (lambda (a) ;; (activate) -> automatically activates eligible children
(when (o! a tree-active-p) (when (o! actor tree-active-p)
(o! a (activate))))) (o! actor (activate)))
) ))
(defvar *view-width* 384 (defvar *view-width* 384
"View-space width in pixels.") "View-space width in pixels.")
@ -179,9 +179,9 @@
(setf camera-view (make-instance 'view)) (setf camera-view (make-instance 'view))
(o! camera-actor (add-component camera-view)) (o! camera-actor (add-component camera-view))
(attach-actor-to-world test-actor test-scene) ;;(sb-ext:gc)
(attach-actor-to-world test-actor-2 test-scene) (initialize-actors-in test-scene
(attach-actor-to-world camera-actor test-scene) test-actor test-actor-2 camera-actor)
test-scene)) test-scene))

View File

@ -15,7 +15,7 @@
make-id fixed-id make-id fixed-id
*running-scenes* *running-scenes*
add-scene remove-scene get-scene update-all-scenes add-scene remove-scene get-scene update-all-scenes
attach-actor-to-world initialize-actors-in
*view-width* *view-height* *view-ppu* *pixel-scale* *view-width* *view-height* *view-ppu* *pixel-scale*
register-test-scene register-test-scene
run run

View File

@ -67,13 +67,13 @@
(setf (o! this :slot renderbuffer) (gl:gen-renderbuffer)) (setf (o! this :slot renderbuffer) (gl:gen-renderbuffer))
(gl:bind-renderbuffer :renderbuffer (o! this renderbuffer)) (gl:bind-renderbuffer :renderbuffer (o! this renderbuffer))
(gl:renderbuffer-storage :renderbuffer :depth24-stencil8 *view-width* *view-height*) (gl:renderbuffer-storage :renderbuffer :depth24-stencil8 *view-width* *view-height*)
(gl:bind-renderbuffer 0) (gl:bind-renderbuffer :renderbuffer 0)
;; create framebuffer ;; create framebuffer
(setf (o! this :slot framebuffer) (gl:gen-framebuffer)) (setf (o! this :slot framebuffer) (gl:gen-framebuffer))
(gl:bind-framebuffer :framebuffer (o! this framebuffer)) (gl:bind-framebuffer :framebuffer (o! this framebuffer))
(gl:framebuffer-texture-2d :framebuffer :color-attachment0 :texture-2d (o! this render-texture) 0) (gl:framebuffer-texture-2d :framebuffer :color-attachment0 :texture-2d (o! this render-texture) 0)
(gl:framebuffer-renderbuffer :framebuffer :depth-stencil-attachment :renderbuffer (o! this renderbuffer)) (gl:framebuffer-renderbuffer :framebuffer :depth-stencil-attachment :renderbuffer (o! this renderbuffer))
(gl:bind-framebuffer 0) (gl:bind-framebuffer :framebuffer 0)
)) ))
(defmethod activate :after ((this view) &key) (defmethod activate :after ((this view) &key)

View File

@ -27,15 +27,14 @@
(defmethod print-object ((this scene) stream) (defmethod print-object ((this scene) stream)
(print-unreadable-object (this stream :type t :identity t) (print-unreadable-object (this stream :type t :identity t)
(prin1 (o! this :slot id) stream) (format stream "~D ~S"
(princ " ") (o! this :slot id) (o! this :slot name))))
(prin1 (o! this :slot name) stream)))
(defmethod add-actor ((this scene) actor) (defmethod add-actor ((this scene) actor)
"Add an actor to this scene." "Add an actor to this scene."
(when (o! actor scene) (when (o! actor scene)
(error "~S is already in scene ~S" actor (o! actor scene))) (error "~S is already in scene ~S" actor (o! actor scene)))
(push actor (o! this :slot actors)) (pushnew actor (o! this :slot actors))
(setf (o! actor :slot scene) (make-weak-pointer this)) (setf (o! actor :slot scene) (make-weak-pointer this))
actor) actor)
@ -74,12 +73,15 @@
(defmethod resume ((this scene)) (defmethod resume ((this scene))
"Initialize or restore this scene's state." "Initialize or restore this scene's state."
; Restore actors ;; Restore actors
(loop for actor in (o! this actors) (loop for actor in (o! this actors)
do (o! actor (resume)))) unless (o! actor :slot parent)
do (format t "===> scene resume: ~S~%" actor)
(o! actor (resume))))
(defmethod suspend ((this scene)) (defmethod suspend ((this scene))
"Prepare this scene for serialization." "Prepare this scene for serialization."
; Suspend actors ;; Suspend actors
(loop for actor in (o! this actors) (loop for actor in (o! this actors)
do (o! actor (suspend)))) unless (o! actor :slot parent)
do (o! actor (suspend))))