• R/O
  • SSH

rulp: 提交

The main repository for rulp in Mercurial


Commit MetaInfo

修订版b30940a5b53e70e19df3dac2df6607b4f0e89c55 (tree)
时间2021-10-22 19:39:49
作者Giulio De Stasio <giuliods@user...>
CommiterGiulio De Stasio

Log Message

made grids global

更改概述

差异

diff -r c1407c4dbd67 -r b30940a5b53e README
--- a/README Wed Oct 20 14:34:11 2021 +0200
+++ b/README Fri Oct 22 12:39:49 2021 +0200
@@ -1,24 +1,33 @@
11 Ru*** roLeplay Playground
22 =========================
33
4-This is a virtual table for combats in d20 system (like Pathfinder
5-or Dungeons&Dragons. This is a rewamped version of the precedent
6-RuLP using raylib over sdl1.2.
4+RuLP is a virtual table for roleplay games like Dungeons&Dragons™,
5+Pathfinder™ and more. The program was developed to be used with a
6+VoIP videotelephony program.
7+
8+The program is growing to be autonomous and more user-friendly, yet
9+staying lightweight, customizable and free as in freedom.
710
811 !!!
9-This version is still a work in progress. Many of the features have to
10-be implemented and functions be polished, It is not reccomended to be used
11-as end-user tool (yet).
12+The program you are seeing now is on an early stage, many features are
13+yet to be implemented or hard to use and too much reliant on source code
14+editing
1215
13-Suggestions are well accepted.
16+I'm actively working to make the program both easy and powerful. Critics
17+and suggestions are well accepted but implementations can be slow due to
18+external duties.
1419 !!!
1520
16-Install
21+Installation
1722 -------
1823
19-RuLP is written in Lisp using Raylib and the ffi library. As now there are
20-no compiled versions of the program but it is easy to install and use it
21-with the following tools:
24+RuLP is written with Raylib in Lisp. Raylib is a powerful library for 2d
25+and 3d graphic, it is available for every system and most of the languages.
26+
27+The raylib implementation for lisp is cl-raylib that require ffi and
28+can be installed via quicklisp
29+
30+For compiling RuLP we need the followings:
2231
2332 * raylib
2433 * cl-raylib (by quicklisp or manually)
@@ -26,14 +35,24 @@
2635 * cffi (by quicklisp or manually)
2736 * sbcl/clisp (clisp not tested, but should work)
2837
29-Raylib can be downloaded from their website https://raylib.com/, or
30-from any package manager in linux, chokolately from windows or
31-macports/homebrew from Mac. If downloaded trough these latter ways,
32-remember to install both raylib and the development version (usually
33-as raylib-devel or raylib-dev)
38+Raylib, ffi and sbcl can be installed via a package manager, like
39+homebrew for Mac or almost all packages manager for GNU/Linux.
3440
35-the same as above for ffi, it can be downloaded from any package manager
36-and you need to download both the ffi and the developement version.
41+Users need to install the followings from the package manager:
42+
43+Homebrew (Mac)
44+* raylib
45+* xcode (for ffi)
46+* sbcl / clisp (they are both available through homebrew)
47+
48+Packages Managers (GNU/Linux)
49+* raylib
50+* raylib-devel / raylib-dev
51+* ffi
52+* ffi-devel / ffi-dev
53+* sbcl / clisp
54+
55+Better instructions for Windows system will be added soon
3756
3857 cl-raylib and cffi can be downloaded with quicklisp, indications
3958 about installation and usage are available on
@@ -49,8 +68,7 @@
4968 window in this folder and execute
5069
5170 $ sbcl --load rulp.lisp
52-
53-or load with your interpreter of choice
71+$ clisp rulp.lisp
5472
5573
5674 Usage
@@ -73,3 +91,14 @@
7391 this is a spare time project and I don't have much spare time to begin
7492 with. Even if there are few updates I work on the background on bug
7593 fixes and features but I just don't want to commit half done work.
94+
95+
96+Changes
97+-------
98+
99+commit 2021/10/22:
100+* grid is not a layer anymore, it is temporary global but implemented
101+ through a class that convert actor position to the pixel position in the
102+ window (and back) this can be edited at the beginning of rulp.lisp;
103+* select-pointer and move-actor were simplified;
104+* README redone
\ No newline at end of file
diff -r c1407c4dbd67 -r b30940a5b53e blank.lisp
--- a/blank.lisp Wed Oct 20 14:34:11 2021 +0200
+++ b/blank.lisp Fri Oct 22 12:39:49 2021 +0200
@@ -3,11 +3,7 @@
33 ;; drag and drop). All the elements that will be displayed in +layers+
44 ;; will be displayed in the map
55
6-(setf base-grid (make-instance 'grid-layer
7- :grid-layer-span 70))
8-
96 (setf amanda (make-instance 'actor-layer
10- :entity-layer-grid base-grid
117 :entity-name "Amanda"))
128
139 (setf (l-x amanda) 6)
@@ -15,8 +11,6 @@
1511
1612 (setq +layers+ (list
1713 (make-instance 'image-layer :source "board.png")
18- base-grid
1914 (make-instance 'actor-layer
20- :entity-layer-grid base-grid
2115 :entity-name "Barbuda")
2216 amanda))
diff -r c1407c4dbd67 -r b30940a5b53e grids.lisp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/grids.lisp Fri Oct 22 12:39:49 2021 +0200
@@ -0,0 +1,31 @@
1+(defclass grid ()
2+ ((type :accessor grid-type
3+ :initarg :grid-type
4+ :initform 'square)
5+ (size :accessor grid-size
6+ :initarg :grid-size
7+ :initform 70)
8+ (visible :accessor is-grid-visible
9+ :initarg :is-grid-visible
10+ :initform t)))
11+; (offset :accessor grid-offset
12+; :initarg :grid-offset
13+; :initform (make-array '(2) :initial-contents '(0 0)))))
14+
15+(defmethod coordinates-to-grid (coordinates (g grid))
16+ (map 'list #'(lambda (x) (* x (grid-size g))) coordinates))
17+
18+;; these are now the same, but with the implementation of an exagonal grid these will differ
19+;; and it is better to just have two functions that can be implemented soon and later edited
20+;; with the addition of new grids
21+(defmethod x-to-grid (value (object grid))
22+ (* value (grid-size object)))
23+
24+(defmethod y-to-grid (value (object grid))
25+ (* value (grid-size object)))
26+
27+(defmethod x-to-entity (value (object grid))
28+ (floor (/ value (grid-size object))))
29+
30+(defmethod y-to-entity (value (object grid))
31+ (floor (/ value (grid-size object))))
diff -r c1407c4dbd67 -r b30940a5b53e layers.lisp
--- a/layers.lisp Wed Oct 20 14:34:11 2021 +0200
+++ b/layers.lisp Fri Oct 22 12:39:49 2021 +0200
@@ -31,21 +31,10 @@
3131 :initform nil)
3232 ))
3333
34-(defclass grid-layer (layer)
35- ((span :accessor grid-layer-span
36- :initarg :grid-layer-span
37- :initform 70)))
38-
39-(defmethod grid-offset (value (object grid-layer))
40- (* value (grid-layer-span object)))
41-
4234 (defclass entity-layer (image-layer)
4335 ((display :accessor display
4436 :initarg :display
4537 :initform t)
46- (grid :accessor entity-layer-grid
47- :initarg :entity-layer-grid
48- :initform (make-instance 'grid-layer))
4938 (size :accessor entity-layer-size
5039 :initarg :entity-layer-size
5140 :initform 1)))
diff -r c1407c4dbd67 -r b30940a5b53e rulp.lisp
--- a/rulp.lisp Wed Oct 20 14:34:11 2021 +0200
+++ b/rulp.lisp Fri Oct 22 12:39:49 2021 +0200
@@ -1,31 +1,42 @@
11 (require :cl-raylib)
22 (load "layers.lisp")
3+(load "grids.lisp")
34
45 (defvar +layers+ nil)
56 (defvar screen-width 1000)
67 (defvar screen-height 750)
78 (defvar +pointer+ nil)
9+;; Grid is now global, local grid implementation will be done with the scene system
10+(defvar +grid+ (make-instance 'grid
11+ :grid-size 70
12+ :is-grid-visible t))
813
14+(defun actor-layers ()
15+ "function which get +layers+ and return only the actors in there"
16+ (remove-if-not #'(lambda (x) (typep x 'actor-layer)) +layers+))
17+
18+(defun vectorize (a b)
19+ "make an array from the two elements"
20+ (make-array '(2) :initial-contents (list a b)))
921
1022 ;; This function, starting with the x and y position of the mouse, find the actor that is placed in there
1123 ;; and return the pointer of the special "actor-from-layers" list
24+;; what this does is get the actors from the list with actor-layers
25+;; get a list of the coordinates
26+;; get the mouse position in the actor space
27+;; find the position of the first actor which is in that space
28+;; return the position if there is one or nil if there is none
1229 (defun select-pointer (mouse-x mouse-y)
13- (let* ((actors-from-layers (remove-if-not #'(lambda (x) (typep x 'actor-layer)) +layers+))
14- (coordinate-list (map 'list #'(lambda (x) (layer-coordinate x)) actors-from-layers))
15- (grid 70) ; this is an hardcoded variable that MUST be removed and replaced with a real grid one
16- (mouse-on-grid-x (floor (/ mouse-x grid)))
17- (mouse-on-grid-y (floor (/ mouse-y grid)))
18- (mouse-on-grid-vec (make-array '(2) :initial-contents (list mouse-on-grid-x mouse-on-grid-y)))
30+ (let* ((coordinate-list (map 'list #'(lambda (x) (layer-coordinate x)) (actor-layers)))
31+ ; clusterfucked
32+ (mouse-on-grid-vec (vectorize (x-to-entity mouse-x +grid+) (y-to-entity mouse-y +grid+)))
1933 (return-pointer (position-if #'(lambda (x) (compare x mouse-on-grid-vec)) coordinate-list)))
2034 return-pointer))
2135
36+;; this transform the mouse position in actor position, and change the selected actor position here
2237 (defun move-actor (mouse-x mouse-y)
23- (let* ((actors-from-layers (remove-if-not #'(lambda (x) (typep x 'actor-layer)) +layers+))
24- (grid 70) ; this is an hardcoded variable that MUST be removed and replaced with a real grid one
25- (mouse-on-grid-x (floor (/ mouse-x grid)))
26- (mouse-on-grid-y (floor (/ mouse-y grid)))
27- (mouse-on-grid-vec (make-array '(2) :initial-contents (list mouse-on-grid-x mouse-on-grid-y))))
28- (setf (layer-coordinate (nth +pointer+ actors-from-layers)) mouse-on-grid-vec)))
38+ (let* ((mouse-on-grid-vec (vectorize (x-to-entity mouse-x +grid+) (y-to-entity mouse-y +grid+))))
39+ (setf (layer-coordinate (nth +pointer+ (actor-layers))) mouse-on-grid-vec)))
2940
3041 #|
3142 Layer render implementation with raylib
@@ -33,6 +44,16 @@
3344 raylib imported, also this makes the layer
3445 file easy to convert in another implementations
3546 |#
47+(defmethod render-grid ()
48+ (when (is-grid-visible +grid+)
49+ (let* ((span (grid-size +grid+))
50+ (horizontal-lines (floor (/ screen-width span)))
51+ (vertical-lines (floor (/ screen-height span))))
52+ (loop for i from 1 to horizontal-lines
53+ do (raylib:draw-line (* i span) 0 (* i span) screen-height raylib:+lightgray+))
54+ (loop for j from 1 to vertical-lines
55+ do (raylib:draw-line 0 (* j span) screen-width (* j span) raylib:+lightgray+))
56+ )))
3657
3758 (defmethod render ((object layer))
3859 (raylib:draw-rectangle (l-x object) (l-y object) 20 20 raylib:+black+))
@@ -42,28 +63,15 @@
4263 (setf (slot-value object 'image-mipmap) (raylib:load-texture (image-source object)))
4364 (raylib:draw-texture (image-mipmap object) (l-x object) (l-y object) raylib:+raywhite+)))
4465
45-(defmethod render ((object grid-layer))
46- (with-slots (span)
47- object
48- (let ((horizontal-lines (floor (/ screen-width (grid-layer-span object))))
49- (vertical-lines (floor (/ screen-height (grid-layer-span object)))))
50- (loop for i from 1 to horizontal-lines
51- do (raylib:draw-line (* i span) 0 (* i span) screen-height raylib:+lightgray+))
52- (loop for j from 1 to vertical-lines
53- do (raylib:draw-line 0 (* j span) screen-width (* j span) raylib:+lightgray+))
54- )))
55-
56-
5766 ;; this render method doesn't resize images, it has to be implemented here or somewhere else
5867 ;; so it is not necessary to manually resize images to fit in here
5968 (defmethod render ((object entity-layer))
60- (let ((span (grid-layer-span (entity-layer-grid object))))
6169 (if (null (image-mipmap object))
6270 (setf (slot-value object 'image-mipmap) (raylib:load-texture (image-source object)))
6371 (raylib:draw-texture (image-mipmap object)
64- (* span (l-x object))
65- (* span (l-y object))
66- raylib:+raywhite+))))
72+ (x-to-grid (l-x object) +grid+)
73+ (y-to-grid (l-y object) +grid+)
74+ raylib:+raywhite+)))
6775
6876
6977 ;(defmethod render ((object entity-layer))
@@ -81,18 +89,17 @@
8189 ; (* span (l-y object))
8290 ; raylib:+raywhite+)))
8391
84-(defmethod render ((object entity-layer))
85- (let ((span (grid-layer-span (entity-layer-grid object))))
92+(defmethod render ((object actor-layer))
8693 (if (null (image-mipmap object))
8794 (setf (slot-value object 'image-mipmap) (raylib:load-texture (image-source object)))
8895 (raylib:draw-texture (image-mipmap object)
89- (* span (l-x object))
90- (* span (l-y object))
91- raylib:+raywhite+)))
92- (let* ((grid-span (grid-layer-span (entity-layer-grid object)))
93- (x-position (* (l-x object) grid-span))
94- (y-position (* (l-y object) grid-span))
95- (y-position-bottom (+ y-position grid-span)))
96+ (x-to-grid (l-x object) +grid+)
97+ (y-to-grid (l-y object) +grid+)
98+ raylib:+raywhite+))
99+ (let* ((grid-span (grid-size +grid+)) ; to simplify
100+ (x-position (x-to-grid (l-x object) +grid+))
101+ (y-position (y-to-grid (l-y object) +grid+))
102+ (y-position-bottom (y-to-grid (+ 1 (l-y object)) +grid+)))
96103 ;; Draw the name box
97104 (raylib:draw-rectangle x-position (- y-position-bottom 15) grid-span 15 raylib:+raywhite+)
98105 (raylib:draw-text (entity-name object) x-position (- y-position-bottom 15) 15 raylib:+black+)))
@@ -108,6 +115,7 @@
108115 ; (raylib:draw-texture board 0 0 raylib:+raywhite+)
109116 (raylib:draw-text "Ru*** Lisp Playground" 400 365 20 raylib:+lightgray+)
110117 (map 'list #'render +layers+)
118+ (render-grid)
111119 (raylib:draw-fps 20 20)
112120 ;; Draw pointer
113121 (when (numberp +pointer+)
@@ -117,9 +125,9 @@
117125 (actor-x (l-x actor-to-select))
118126 (actor-y (l-y actor-to-select))
119127 (actor-size (entity-layer-size actor-to-select))
120- (grid (grid-layer-span (entity-layer-grid actor-to-select))))
128+ (span (grid-size +grid+)))
121129 ;; Grammar to resolve, remove all the (* grid _) in the draw below
122- (raylib:draw-rectangle-lines (* grid actor-x) (* grid actor-y) (* grid actor-size) (* grid actor-size) raylib:+red+)
130+ (raylib:draw-rectangle-lines (x-to-grid actor-x +grid+) (y-to-grid actor-y +grid+) (* span actor-size) (* span actor-size) raylib:+red+)
123131 ))))
124132
125133 (defun main ()
@@ -130,6 +138,8 @@
130138 (loop
131139 (setf mouse-position (raylib:get-mouse-position)) ;; this is a structure (defstruct vector2 x y)
132140 (cond ((raylib:window-should-close)(return))
141+ ;; !! this is detected every frame, you have to make separate section that detect only
142+ ;; once every few frames (now is not possible to implement grid modifier options)
133143 ((raylib:is-mouse-button-pressed raylib:+mouse-left-button+)
134144 (setf +pointer+ (select-pointer (raylib:vector2-x mouse-position) (raylib:vector2-y mouse-position))))
135145 ((raylib:is-mouse-button-pressed raylib:+mouse-right-button+)
Show on old repository browser