From 98b5811d8b50d20f8c15e9b202f0d3f0457df58b Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 30 Jun 2022 09:29:28 -0500 Subject: [modify] affine fns are generic; [add] safe-slot util --- examples/02-moving-bitmp.lisp | 2 +- src/core/affine.lisp | 12 +++++++----- src/core/unit.lisp | 8 ++++++-- src/protocol.lisp | 26 ++++++++++++++++++++++++++ src/utils.lisp | 7 +++++++ 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/examples/02-moving-bitmp.lisp b/examples/02-moving-bitmp.lisp index 7cb03d3..52cf0ca 100644 --- a/examples/02-moving-bitmp.lisp +++ b/examples/02-moving-bitmp.lisp @@ -51,7 +51,7 @@ (ww::add-handler target (ww::on-perframe () - (with-slots ((cx ww::x) (cy ww::y)) target + (with-accessors ((cx ww::x) (cy ww::y)) target (if (and (= cx destx) (= cy desty)) (progn (remhash target *shared-anim-table*) diff --git a/src/core/affine.lisp b/src/core/affine.lisp index cabe17c..4585a81 100644 --- a/src/core/affine.lisp +++ b/src/core/affine.lisp @@ -15,7 +15,9 @@ (setf (cached-model affine) nil (cached-projected-matrix affine) nil)))) -(defun scale-by (affine amount) + + +(defmethod scale-by ((affine affine) amount) (with-slots (scale-x scale-y) affine (setf scale-x (* amount scale-x) scale-y (* amount scale-y)))) @@ -26,19 +28,19 @@ (defun set-height-preserve-aspect (affine new-height) (scale-by affine (/ new-height (height affine) ))) -(defun width (affine) +(defmethod width ((affine affine)) (with-slots (scale-x base-width) affine (* scale-x base-width))) -(defun height (affine) +(defmethod height ((affine affine)) (with-slots (scale-y base-height) affine (* scale-y base-height))) -(defun (setf width) (newval affine) +(defmethod (setf width) (newval (affine affine)) (with-slots (scale-x base-width) affine (setf scale-x (coerce (/ newval base-width) 'single-float)))) -(defun (setf height) (newval affine) +(defmethod (setf height) (newval (affine affine)) (with-slots (scale-y base-height) affine (setf scale-y (coerce (/ newval base-height) 'single-float)))) diff --git a/src/core/unit.lisp b/src/core/unit.lisp index 20e05e2..fb02f08 100644 --- a/src/core/unit.lisp +++ b/src/core/unit.lisp @@ -3,8 +3,9 @@ (in-package #:wheelwork) (defclass/std unit () - ((cached-application :a) - (container :with :a))) + ((cached-application :a) + (container :with :a) + (visiblep :with :std t))) (defmethod (setf closer-mop:slot-value-using-class) :after (newval class (unit unit) slot) @@ -28,3 +29,6 @@ in this application." (rec unit))))) +(defmethod render :around ((unit unit)) + (when (unit-visiblep unit) + (call-next-method))) diff --git a/src/protocol.lisp b/src/protocol.lisp index f8386a6..bd436e6 100644 --- a/src/protocol.lisp +++ b/src/protocol.lisp @@ -33,3 +33,29 @@ (defgeneric ensure-loaded (asset) (:documentation "Ensures that the asset is loaded into memory and ready for use. Returns the asset.")) + +(defgeneric scale-by (thing amount) + (:documentation "Scale horizontal and vertical dimensions of THING by AMOUNT")) + +(defgeneric width (thing) + (:documentation "Returns the effective width, in screen coordinates, of the object in question")) + +(defgeneric (setf width) (new-width thing) + (:documentation "Sets the effective width of thing to new-width.")) + +(defgeneric height (thing) + (:documentation "Returns effective height, in screen coordinates, of the object in question.")) + +(defgeneric (setf height) (new-height thing) + (:documentation "sets the effective height of thing to new-height")) + +(defgeneric rotation (thing)) +(defgeneric (setf rotation) (newval thing)) +(defgeneric x (thing)) +(defgeneric (setf x) (newval thing)) +(defgeneric y (thing)) +(defgeneric (setf y) (newval thing)) +(defgeneric scale-x (thing)) +(defgeneric (setf scale-x) (newvval thing)) +(defgeneric scale-y (thing)) +(defgeneric (setf scale-y) (newval thing)) diff --git a/src/utils.lisp b/src/utils.lisp index e0f6dcd..3598ec3 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -7,3 +7,10 @@ (defun radians (degrees) "Converse DEGREES to radians" (* degrees +pi-over-180+)) + +(defun safe-slot (object slot &optional default) + (if-let (val (and (slot-exists-p object slot) + (slot-boundp object slot) + (slot-value object slot))) + val + default)) -- cgit v1.2.3