OSDN Git Service

FIX: entities under flyweight
[rulp/rulp.git] / graphics / package.lisp
index 59174c6..06fee4c 100644 (file)
 ;;;; You should have received a copy of the GNU General Public License
 ;;;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-(defpackage :graphics
-  (:use :cl :layers)
+(defpackage :rulp.graphics
+  (:use :cl :rulp.layers :rulp.geometry)
   (:export
-   playground +plane+
+   playground +plane+ *plane* *plane-grid* *map-info* *map-path* *entities-list*
+   arrange-rect *window-width* *window-height* tr-write
            ))
+;; NOTE: remove +plane+, there is no other occurrence of the parameter on the code
 
-(in-package :graphics)
+(in-package :rulp.graphics)
 
-(defparameter +plane+ nil
-  "the rendered plane, this variable contain the plane which is gonna be presented
-into the main window")
+;; these variables contain information for the plane and grid systems. The default
+;; grid is a square grid but by changing the grid-layout function it is possible
+;; to modify it
+(defparameter *plane* nil
+  "the plane containing the graphics to be desplayed on the background. This is a
+basic layout:screen")
+
+(defparameter *plane-grid* 10
+  "the grid for the plane. By default the grid is square and this value contain the
+pixels between lines")
+
+(defparameter *entities-list* nil
+  "the list of the entities to be displayed on the plane. these entities are global and
+by default not connected to the *plane* choice. To change planes and entities use the proper
+functions")
 
 (defparameter *renderer* nil
   "a variable containing the tool to render textures to screen, this is associated
@@ -34,20 +48,17 @@ side variable and cannot be moved in a sdl enviroinment.")
 (defparameter *pointer* nil
   "this is a numeric value whose refer to the selected entity in the plane, it is
 used combined with input to apply the actions and with view to display a 1x1 over
-grid square of the entity"
-  )
+grid square of the entity")
 
 ;; tr stands for text-rendering
-(defparameter *tr-string* "abcdefghijklmnopqrstuvwxyz 0123456789"
+(defparameter *tr-string* "abcdefghijklmnopqrstuvwxyz 0123456789-"
   "This string is used to generate a texture with the alphabet, the software
 in the text.lisp file will 'write' on the screen selecting squares and using
-this string again to parse a string variable into coordinate in the texture"
-  )
+this string again to parse a string variable into coordinate in the texture")
 
-(defparameter *alphabet* "abcdefghijklmnopqrstuvwxyz"
+(defparameter *alphabet* "abcdefghijklmnopqrstuvwxyz-"
   "this is used to generate the grid, when the coordinates run out of letters
-they restart from the beginning"
-  )
+they restart from the beginning")
 
 (defparameter *tr-texture* nil
   "this contains the texture of the characters from *tr-string*. This
@@ -58,30 +69,49 @@ with render-copy")
 (defconstant +mouse-button-right+ 3 "this binds the right button")
 (defconstant +mouse-button-middle+ 2 "this binds the scroll button")
 
+;; FIXME: replace with apply system and fixed arguments *mouse-position*, *mouse-previous-position* *viewpoint-offset*
 (defparameter *mouse-keybinds* (list
-                                '(+mouse-button-left+ select-pointer)
-                                ;; '(+mouse-button-middle+ mouse-view)
-                                '(+mouse-button-right+ move-entity)
+                                '(+mouse-button-left+ nil (select-pointer *mouse-position* *entities-list*))
+                                '(+mouse-button-middle+ (panning *viewpoint-offset* (velocity *mouse-position* *mouse-previous-position*)) nil)
+                                '(+mouse-button-right+ nil (move-entity *mouse-position*))
+                                ;; '(+mouse-button-right+ nil (push (summon-entry *mouse-position* '(1)) *active-entries*))
                                 )
-  "This list associate the button presses to a certain action, the action is evaluated
-as shown in graphics/input.lisp"
-  )
-
-(defparameter *previous-mouse-position* '(0 0))
-(defparameter *mouse-movement-delta* '(0 0)
-  "this parameter acknowledge saves the difference between the frames in mouse position.
-It is used to move the plane around using the mouse")
+  "This is the mouse-keybinds association list. The first value is the button, the second
+is the action executed on hold and the third is the action executed on release (if any)")
 
 
 (defparameter *is-grid* t
   "Parameter for displaying the grid, when nil it does not display a grid, when t
-it display a grid as defined by the +plane+")
+it display a grid as defined by the *plane-grid*")
 (defparameter *is-indexes* t
   "Parameter for displaying the indexes, when nil it does not display them, when t
 it uses the grid to create a chessboard like indexes")
 
-(defparameter *entries-list* nil
-  "List of entries, menues who are generated into the window with options")
-
 (defparameter *window-width* 1001)
 (defparameter *window-height* 750)
+
+;; NOTE: probably they need to be moved below in layers, for now they can stay here
+(defparameter *map-info* nil
+  "when the json informations are read, the content is dumped into this parameter and then
+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))