OSDN Git Service

FIX: entities under flyweight
[rulp/rulp.git] / layers / planes.lisp
1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022  Zull
3 ;;;;
4 ;;;; This program is free software: you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation, either version 3 of the License, or
7 ;;;; (at your option) any later version.
8 ;;;;
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;;; GNU General Public License for more details.
13 ;;;;
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17 (in-package :rulp.layers)
18
19 (defgeneric bounce (v p)
20   (:documentation "Given a point v and a plane p this generic check if
21 the point collide with some wall or it is out of bound and return t
22 when it is, nil otherwise"))
23
24 (defun lex< (a b)
25   "lexycal-graphical orders between a and b, returns t if a < b, otherwise returns nil"
26   (declare (list a b)
27            (optimize (speed 3)))
28   (if (eql (car a) (car b))
29       (< (cdr a) (cdr b))
30       (< (car a) (car B))))
31
32 (defclass plane (displayable)
33   ((collision-list :accessor collision-list
34                    :initarg :collision-list
35                    :initform nil
36                    :type list
37                    :documentation "an ordered list of collision, use when entities do stuff")
38    (entities-list :accessor entities-list
39                   :initarg :entities-list
40                   :initform nil
41                   :type list
42                   :documentation "the entities contained into the plane")
43    ;; (width :accessor width
44    ;;        :initarg :width
45    ;;        :initform 0
46    ;;        :type number
47    ;;        :documentation "the width of the plane, when 0 or negative it uses the texture width")
48    ;; (height :accessor height
49    ;;         :initarg :height
50    ;;         :initform 0
51    ;;         :type number
52    ;;         :documentation "the height of the plane, when 0 or negative it uses the texture height")
53    (background :accessor background
54                :initarg :background
55                :initform ""
56                :type string
57                :documentation "the path for the construction, that can be a image or something else")
58    (grid :accessor plane-grid
59          :initarg :grid)
60    (span :accessor grid-dimension
61          :initarg :grid-dimension
62          :documentation "the dimension of the standard grid, this will be replaced with a function"
63          :initform 70)))
64
65 ;; grid logic, to be placed in the correct package (and file
66 (defmethod bounce (v (p plane))
67   "rapidly check if the given point is in the collision list"
68   (member v (collision-list p)))
69
70 ;; the name is intended to be temporary
71 ;; BUG: this method is (somehow) being replaced by the entity version.
72 (defmethod display ((p plane) (grid t))
73   (declare (ignore grid))
74   (render (get-screen (background p)) 0 0 (w p) (h p)))
75
76 (defmethod w ((obj plane))
77   (if (= (car (slot-value obj 'size)) 0)
78       (w (get-screen (background obj)))
79       (car (slot-value obj 'size))))
80
81 (defmethod h ((obj plane))
82   (if (= (cdr (slot-value obj 'size)) 0)
83       (h (get-screen (background obj)))
84       (car (slot-value obj 'size))))
85
86 ;; temporary, they are used somewhere on view for the evenience the
87 ;; plane was moved (now the plane doesn't consider coordinates)
88 (defmethod x ((obj plane))
89   0)
90
91 (defmethod y ((obj plane))
92   0)