a bunch of shit lol
This commit is contained in:
parent
738da6f74b
commit
98d8b35a4f
5 changed files with 38 additions and 36 deletions
|
@ -92,13 +92,15 @@
|
|||
(funcall fun this)
|
||||
(loop for child-ptr in (o! this children)
|
||||
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)
|
||||
(print-unreadable-object (this stream :type t :identity t)
|
||||
(prin1 (o! this :slot id) stream)
|
||||
(princ " ")
|
||||
(prin1 (o! this :slot name) stream)))
|
||||
(format stream "~D ~S"
|
||||
(o! this :slot id) (o! this :slot name))))
|
||||
|
||||
(defmethod get-component ((this actor) component-class)
|
||||
"Get a component of the specified class attached to this object."
|
||||
|
@ -183,6 +185,7 @@
|
|||
|
||||
(defmethod resume ((this actor))
|
||||
"Initialize or restore this actor's state."
|
||||
(format t "=> actor resume: ~S~%" this)
|
||||
;; Restore self
|
||||
(when (typep (o! this :slot scene) 'id-ref)
|
||||
;; relink to scene
|
||||
|
@ -218,6 +221,7 @@
|
|||
(loop for child-cell on (o! this :slot children)
|
||||
when (typep (car child-cell) 'weak-pointer)
|
||||
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 parent)))
|
||||
|
||||
|
@ -226,11 +230,7 @@
|
|||
(loop for component in (o! this components)
|
||||
do (when (o! component active-p)
|
||||
(unless (o! component started-p) (o! component (start)))
|
||||
(o! component (update))))
|
||||
; (loop for child in (o! this children)
|
||||
; do (when (o! child active-p)
|
||||
; (o! child (update))))
|
||||
)
|
||||
(o! component (update)))))
|
||||
|
||||
(defmethod destroy ((this actor))
|
||||
"Mark this object for unloading."
|
||||
|
|
|
@ -98,19 +98,19 @@
|
|||
"Get a scene by its ID."
|
||||
(find-if (lambda (scene) (eq (o! scene id) scene-id)) *world-scenes*))
|
||||
|
||||
(defun attach-actor-to-world (actor scene)
|
||||
"Properly attach actor and its descendents to scene, and initialize them."
|
||||
;; attach actors to scene
|
||||
(apply-to-tree actor (lambda (a)
|
||||
(setf (o! a :slot scene) nil)
|
||||
(o! scene (add-actor a))))
|
||||
;; (resume) -> automatically resumes children
|
||||
(o! actor (resume))
|
||||
;; FIXME make (activate) call itself recursively on children
|
||||
(apply-to-tree actor (lambda (a)
|
||||
(when (o! a tree-active-p)
|
||||
(o! a (activate)))))
|
||||
)
|
||||
(defun initialize-actors-in (scene &rest actors)
|
||||
"Properly attach actors and their descendents to scene, and initialize them."
|
||||
(loop for actor in actors
|
||||
do ;; attach actor to scene
|
||||
(o! actor (apply-to-tree (lambda (a)
|
||||
(setf (o! a :slot scene) nil)
|
||||
(o! scene (add-actor a)))))
|
||||
;; (resume) -> automatically resumes children
|
||||
(o! actor (resume))
|
||||
;; (activate) -> automatically activates eligible children
|
||||
(when (o! actor tree-active-p)
|
||||
(o! actor (activate)))
|
||||
))
|
||||
|
||||
(defvar *view-width* 384
|
||||
"View-space width in pixels.")
|
||||
|
@ -179,9 +179,9 @@
|
|||
(setf camera-view (make-instance 'view))
|
||||
(o! camera-actor (add-component camera-view))
|
||||
|
||||
(attach-actor-to-world test-actor test-scene)
|
||||
(attach-actor-to-world test-actor-2 test-scene)
|
||||
(attach-actor-to-world camera-actor test-scene)
|
||||
;;(sb-ext:gc)
|
||||
(initialize-actors-in test-scene
|
||||
test-actor test-actor-2 camera-actor)
|
||||
|
||||
test-scene))
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
make-id fixed-id
|
||||
*running-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*
|
||||
register-test-scene
|
||||
run
|
||||
|
|
|
@ -67,13 +67,13 @@
|
|||
(setf (o! this :slot renderbuffer) (gl:gen-renderbuffer))
|
||||
(gl:bind-renderbuffer :renderbuffer (o! this renderbuffer))
|
||||
(gl:renderbuffer-storage :renderbuffer :depth24-stencil8 *view-width* *view-height*)
|
||||
(gl:bind-renderbuffer 0)
|
||||
(gl:bind-renderbuffer :renderbuffer 0)
|
||||
;; create framebuffer
|
||||
(setf (o! this :slot framebuffer) (gl:gen-framebuffer))
|
||||
(gl:bind-framebuffer :framebuffer (o! this framebuffer))
|
||||
(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:bind-framebuffer 0)
|
||||
(gl:bind-framebuffer :framebuffer 0)
|
||||
))
|
||||
|
||||
(defmethod activate :after ((this view) &key)
|
||||
|
|
|
@ -27,15 +27,14 @@
|
|||
|
||||
(defmethod print-object ((this scene) stream)
|
||||
(print-unreadable-object (this stream :type t :identity t)
|
||||
(prin1 (o! this :slot id) stream)
|
||||
(princ " ")
|
||||
(prin1 (o! this :slot name) stream)))
|
||||
(format stream "~D ~S"
|
||||
(o! this :slot id) (o! this :slot name))))
|
||||
|
||||
(defmethod add-actor ((this scene) actor)
|
||||
"Add an actor to this scene."
|
||||
(when (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))
|
||||
actor)
|
||||
|
||||
|
@ -74,12 +73,15 @@
|
|||
|
||||
(defmethod resume ((this scene))
|
||||
"Initialize or restore this scene's state."
|
||||
; Restore actors
|
||||
;; Restore 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))
|
||||
"Prepare this scene for serialization."
|
||||
; Suspend actors
|
||||
;; Suspend actors
|
||||
(loop for actor in (o! this actors)
|
||||
do (o! actor (suspend))))
|
||||
unless (o! actor :slot parent)
|
||||
do (o! actor (suspend))))
|
||||
|
|
Loading…
Reference in a new issue