From: Giulio De Stasio Date: Sat, 22 Jul 2023 07:32:29 +0000 (+0200) Subject: view: entities-list in plane and fixes X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=HEAD;p=rulp%2Frulp.git view: entities-list in plane and fixes --- diff --git a/graphics/package.lisp b/graphics/package.lisp index e5093d9..4367862 100644 --- a/graphics/package.lisp +++ b/graphics/package.lisp @@ -98,34 +98,23 @@ used on uninitialized data to bootstrap the data") (defparameter *map-path* nil "this is the path where the json file lived") -(defparameter *execute-before* '()) -(defparameter *execute-in-viewpoint* '()) -(defparameter *execute-in-window* '()) -(defparameter *execute-after* '()) - - -;; FIXME: define push-once to avoid loading many times the same function from -;; slime/sly -(defmacro defchain (chain-name where &body body) - (cond - ((eq where :before) (push chain-name *execute-before*)) - ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*)) - ((eq where :window) (push chain-name *execute-in-window*)) - ((eq where :after) (push chain-name *execute-after*)) - ) - `(defun ,chain-name () - ,@body)) - - -(defchain render-plane-and-entities :viewpoint -;; "using *plane* and *entities-list* the macro display on the current rendering texture -;; the plane 'as is' and the entities with the grid-layout function" - (when *plane* - ;; NOTE: add error for non-screen planes - (display *plane* t) - (loop :for entity :in (entities-list *plane*) - :do - (when (displayp entity) - (display entity (plane-grid *plane*)) - ))) ; FIXME: create a grid-layout function +;; this defines the parameters and the defchain macro used to create inversion of +;; control. The parameters cannot be defined outside this function because asdf +;; would initialize them after the functions and break the functionality +(defun kick-start-chain () + (defparameter *execute-before* nil) + (defparameter *execute-in-viewpoint* nil) + (defparameter *execute-in-window* nil) + (defparameter *execute-after* nil) + (defmacro defchain (chain-name where &body body) + (cond + ((eq where :before) (push chain-name *execute-before*)) + ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*)) + ((eq where :window) (push chain-name *execute-in-window*)) + ((eq where :after) (push chain-name *execute-after*)) + ) + `(defun ,chain-name () + ,@body)) ) + +(kick-start-chain) diff --git a/graphics/render.lisp b/graphics/render.lisp index f038718..1b53e3b 100644 --- a/graphics/render.lisp +++ b/graphics/render.lisp @@ -72,3 +72,15 @@ rectangle directly, but use the arrange-rect") ;; BUG: when the system loads it doesn't fill the variable ;; *execute-in-viewpoint* therefore this function is never executed +(defchain render-plane-and-entities :viewpoint +;; "using *plane* and *entities-list* the macro display on the current rendering texture +;; the plane 'as is' and the entities with the grid-layout function" + (when *plane* + ;; NOTE: add error for non-screen planes + (display *plane* t) + (loop :for entity :in (entities-list *plane*) + :do + (when (displayp entity) + (display entity (plane-grid *plane*)) + ))) ; FIXME: create a grid-layout function + ) diff --git a/graphics/view.lisp b/graphics/view.lisp index 400d594..6304763 100644 --- a/graphics/view.lisp +++ b/graphics/view.lisp @@ -30,16 +30,24 @@ ;; :image (merge-pathnames map-path (cdr (assoc :image-path entity-info))) :background (merge-pathnames map-path (cdr (assoc :image-path entity-info))) :size (if (assoc :size entity-info) (cdr (assoc :size entity-info)) 1) - :name (assoc :name entity-info) + :name (cdr (assoc :name entity-info)) )))) +;; FIXME: this design can be improved with the use of cl-json options +(defun create-entity (alist map-path) + (make-instance 'entity + :background (merge-pathnames map-path (cdr (assoc :image-path alist))) + :size (if (assoc :size alist) (cdr (assoc :size alist)) 1) + :name (assoc :name alist) + )) + (defun create-plane (map-info map-path &key (number 0)) "convert the map informations into a functioning plane, without number it convert the first element" (let ((plane-info (nth number (cdr (assoc :planes map-info))))) (make-instance 'rulp.layers:plane :background (merge-pathnames map-path (cdr (assoc :image-path plane-info))) - :entities-list (create-entities map-info map-path) + :entities-list (map 'list #'(lambda (x) (create-entity x map-path)) (cdr (assoc :entities plane-info))) :grid (make-instance 'squaregrid :span (cdr (assoc :grid-dimension plane-info))) ) @@ -107,7 +115,7 @@ DEBUG-INFO can be used to display the content on screen for test and debug purpo (setf *plane-grid* (span (rulp.layers:plane-grid *plane*))) ;; FIXME: to remove - (setf *entities-list* (entities-list *plane*)) + ;; (setf *entities-list* (entities-list *plane*)) (loop :for i :in *execute-before* :do (eval `(,i))) ;; FIXME: to remove