OSDN Git Service

view: entities-list in plane and fixes master
authorGiulio De Stasio <giuliodestasio98@gmail.com>
Sat, 22 Jul 2023 07:32:29 +0000 (09:32 +0200)
committerGiulio De Stasio <giuliodestasio98@gmail.com>
Sat, 22 Jul 2023 07:32:29 +0000 (09:32 +0200)
graphics/package.lisp
graphics/render.lisp
graphics/view.lisp

index e5093d9..4367862 100644 (file)
@@ -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)
index f038718..1b53e3b 100644 (file)
@@ -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
+  )
index 400d594..6304763 100644 (file)
                          ;; :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