68 lines
2.0 KiB
Common Lisp
68 lines
2.0 KiB
Common Lisp
;;;; wh-engine/component.lisp
|
|
(in-package wh-engine)
|
|
|
|
(defclass component ()
|
|
((actor :documentation "The actor this component belongs to."
|
|
:reader actor
|
|
:type (or weak-pointer null)
|
|
:initform nil)
|
|
(active-p :documentation "Whether or not this component is active."
|
|
:reader active-p
|
|
:type boolean
|
|
:initarg :active-p
|
|
:initform t)
|
|
(started-p :documentation "Whether or not this component has been started yet."
|
|
:reader started-p
|
|
:type boolean
|
|
:initform nil))
|
|
(:documentation "Base class for components attached to game entities."))
|
|
|
|
(defmethod actor ((this component))
|
|
"The actor this component belongs to."
|
|
(deref-pointer [this :slot actor]))
|
|
|
|
(defmethod scene ((this component))
|
|
"The scene this component belongs to."
|
|
[this actor scene])
|
|
|
|
(defmethod destroyed-p ((this component))
|
|
"If true, this component will be unloaded."
|
|
[this actor destroyed-p])
|
|
|
|
(defmethod attach ((this component) actor)
|
|
"Attach this component to an actor."
|
|
(setf [this :slot actor] (make-weak-pointer (ensure-live actor)))
|
|
[this (parent-changed)])
|
|
|
|
(defmethod parent-deactivated ((this component) parent)
|
|
"Called when the component's actor is deactivated."
|
|
nil)
|
|
|
|
(defmethod parent-activated ((this component) parent)
|
|
"Called when the component's actor is activated."
|
|
nil)
|
|
|
|
(defmethod parent-changed ((this component))
|
|
"Called when the component's actor's parent is changed."
|
|
nil)
|
|
|
|
(defmethod deactivate ((this component))
|
|
"Deactivate this component."
|
|
(setf [this :slot active-p] nil))
|
|
|
|
(defmethod activate ((this component))
|
|
"Activate this component."
|
|
(setf [this :slot active-p] t))
|
|
|
|
(defmethod start ((this component))
|
|
"Called before on-update the first time this component is processed."
|
|
(setf [this :slot started-p] t))
|
|
|
|
(defmethod update ((this component))
|
|
"Called every game tick while this component and its actor are active."
|
|
nil)
|
|
|
|
(defmethod destroy ((this component))
|
|
"Called just before the component's actor is destroyed."
|
|
nil)
|