Commit MetaInfo

Revision852eb9f4106976ccbe629e6252750d6d3a54847b (tree)
Time2023-07-22 16:32:29
AuthorGiulio De Stasio <giuliodestasio98@gmai...>
CommiterGiulio De Stasio

Log Message

view: entities-list in plane and fixes

Change Summary

Incremental Difference

--- a/graphics/package.lisp
+++ b/graphics/package.lisp
@@ -98,34 +98,23 @@ used on uninitialized data to bootstrap the data")
9898 (defparameter *map-path* nil
9999 "this is the path where the json file lived")
100100
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))
131118 )
119+
120+(kick-start-chain)
--- a/graphics/render.lisp
+++ b/graphics/render.lisp
@@ -72,3 +72,15 @@ rectangle directly, but use the arrange-rect")
7272
7373 ;; BUG: when the system loads it doesn't fill the variable
7474 ;; *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+ )
--- a/graphics/view.lisp
+++ b/graphics/view.lisp
@@ -30,16 +30,24 @@
3030 ;; :image (merge-pathnames map-path (cdr (assoc :image-path entity-info)))
3131 :background (merge-pathnames map-path (cdr (assoc :image-path entity-info)))
3232 :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))
3434 ))))
3535
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+
3644 (defun create-plane (map-info map-path &key (number 0))
3745 "convert the map informations into a functioning plane, without number it convert the
3846 first element"
3947 (let ((plane-info (nth number (cdr (assoc :planes map-info)))))
4048 (make-instance 'rulp.layers:plane
4149 :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)))
4351 :grid (make-instance 'squaregrid
4452 :span (cdr (assoc :grid-dimension plane-info)))
4553 )
@@ -107,7 +115,7 @@ DEBUG-INFO can be used to display the content on screen for test and debug purpo
107115 (setf *plane-grid* (span (rulp.layers:plane-grid *plane*)))
108116 ;; FIXME: to remove
109117
110- (setf *entities-list* (entities-list *plane*))
118+ ;; (setf *entities-list* (entities-list *plane*))
111119 (loop :for i :in *execute-before*
112120 :do (eval `(,i)))
113121 ;; FIXME: to remove
Show on old repository browser