| Revision | 852eb9f4106976ccbe629e6252750d6d3a54847b (tree) |
|---|---|
| Time | 2023-07-22 16:32:29 |
| Author | Giulio De Stasio <giuliodestasio98@gmai...> |
| Commiter | Giulio De Stasio |
view: entities-list in plane and fixes
| @@ -98,34 +98,23 @@ used on uninitialized data to bootstrap the data") | ||
| 98 | 98 | (defparameter *map-path* nil |
| 99 | 99 | "this is the path where the json file lived") |
| 100 | 100 | |
| 101 | -(defparameter *execute-before* '()) | |
| 102 | -(defparameter *execute-in-viewpoint* '()) | |
| 103 | -(defparameter *execute-in-window* '()) | |
| 104 | -(defparameter *execute-after* '()) | |
| 105 | - | |
| 106 | - | |
| 107 | -;; FIXME: define push-once to avoid loading many times the same function from | |
| 108 | -;; slime/sly | |
| 109 | -(defmacro defchain (chain-name where &body body) | |
| 110 | - (cond | |
| 111 | - ((eq where :before) (push chain-name *execute-before*)) | |
| 112 | - ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*)) | |
| 113 | - ((eq where :window) (push chain-name *execute-in-window*)) | |
| 114 | - ((eq where :after) (push chain-name *execute-after*)) | |
| 115 | - ) | |
| 116 | - `(defun ,chain-name () | |
| 117 | - ,@body)) | |
| 118 | - | |
| 119 | - | |
| 120 | -(defchain render-plane-and-entities :viewpoint | |
| 121 | -;; "using *plane* and *entities-list* the macro display on the current rendering texture | |
| 122 | -;; the plane 'as is' and the entities with the grid-layout function" | |
| 123 | - (when *plane* | |
| 124 | - ;; NOTE: add error for non-screen planes | |
| 125 | - (display *plane* t) | |
| 126 | - (loop :for entity :in (entities-list *plane*) | |
| 127 | - :do | |
| 128 | - (when (displayp entity) | |
| 129 | - (display entity (plane-grid *plane*)) | |
| 130 | - ))) ; FIXME: create a grid-layout function | |
| 101 | +;; this defines the parameters and the defchain macro used to create inversion of | |
| 102 | +;; control. The parameters cannot be defined outside this function because asdf | |
| 103 | +;; would initialize them after the functions and break the functionality | |
| 104 | +(defun kick-start-chain () | |
| 105 | + (defparameter *execute-before* nil) | |
| 106 | + (defparameter *execute-in-viewpoint* nil) | |
| 107 | + (defparameter *execute-in-window* nil) | |
| 108 | + (defparameter *execute-after* nil) | |
| 109 | + (defmacro defchain (chain-name where &body body) | |
| 110 | + (cond | |
| 111 | + ((eq where :before) (push chain-name *execute-before*)) | |
| 112 | + ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*)) | |
| 113 | + ((eq where :window) (push chain-name *execute-in-window*)) | |
| 114 | + ((eq where :after) (push chain-name *execute-after*)) | |
| 115 | + ) | |
| 116 | + `(defun ,chain-name () | |
| 117 | + ,@body)) | |
| 131 | 118 | ) |
| 119 | + | |
| 120 | +(kick-start-chain) |
| @@ -72,3 +72,15 @@ rectangle directly, but use the arrange-rect") | ||
| 72 | 72 | |
| 73 | 73 | ;; BUG: when the system loads it doesn't fill the variable |
| 74 | 74 | ;; *execute-in-viewpoint* therefore this function is never executed |
| 75 | +(defchain render-plane-and-entities :viewpoint | |
| 76 | +;; "using *plane* and *entities-list* the macro display on the current rendering texture | |
| 77 | +;; the plane 'as is' and the entities with the grid-layout function" | |
| 78 | + (when *plane* | |
| 79 | + ;; NOTE: add error for non-screen planes | |
| 80 | + (display *plane* t) | |
| 81 | + (loop :for entity :in (entities-list *plane*) | |
| 82 | + :do | |
| 83 | + (when (displayp entity) | |
| 84 | + (display entity (plane-grid *plane*)) | |
| 85 | + ))) ; FIXME: create a grid-layout function | |
| 86 | + ) |
| @@ -30,16 +30,24 @@ | ||
| 30 | 30 | ;; :image (merge-pathnames map-path (cdr (assoc :image-path entity-info))) |
| 31 | 31 | :background (merge-pathnames map-path (cdr (assoc :image-path entity-info))) |
| 32 | 32 | :size (if (assoc :size entity-info) (cdr (assoc :size entity-info)) 1) |
| 33 | - :name (assoc :name entity-info) | |
| 33 | + :name (cdr (assoc :name entity-info)) | |
| 34 | 34 | )))) |
| 35 | 35 | |
| 36 | +;; FIXME: this design can be improved with the use of cl-json options | |
| 37 | +(defun create-entity (alist map-path) | |
| 38 | + (make-instance 'entity | |
| 39 | + :background (merge-pathnames map-path (cdr (assoc :image-path alist))) | |
| 40 | + :size (if (assoc :size alist) (cdr (assoc :size alist)) 1) | |
| 41 | + :name (assoc :name alist) | |
| 42 | + )) | |
| 43 | + | |
| 36 | 44 | (defun create-plane (map-info map-path &key (number 0)) |
| 37 | 45 | "convert the map informations into a functioning plane, without number it convert the |
| 38 | 46 | first element" |
| 39 | 47 | (let ((plane-info (nth number (cdr (assoc :planes map-info))))) |
| 40 | 48 | (make-instance 'rulp.layers:plane |
| 41 | 49 | :background (merge-pathnames map-path (cdr (assoc :image-path plane-info))) |
| 42 | - :entities-list (create-entities map-info map-path) | |
| 50 | + :entities-list (map 'list #'(lambda (x) (create-entity x map-path)) (cdr (assoc :entities plane-info))) | |
| 43 | 51 | :grid (make-instance 'squaregrid |
| 44 | 52 | :span (cdr (assoc :grid-dimension plane-info))) |
| 45 | 53 | ) |
| @@ -107,7 +115,7 @@ DEBUG-INFO can be used to display the content on screen for test and debug purpo | ||
| 107 | 115 | (setf *plane-grid* (span (rulp.layers:plane-grid *plane*))) |
| 108 | 116 | ;; FIXME: to remove |
| 109 | 117 | |
| 110 | - (setf *entities-list* (entities-list *plane*)) | |
| 118 | + ;; (setf *entities-list* (entities-list *plane*)) | |
| 111 | 119 | (loop :for i :in *execute-before* |
| 112 | 120 | :do (eval `(,i))) |
| 113 | 121 | ;; FIXME: to remove |