1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022 Zull
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.
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.
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/>.
17 (in-package :graphics)
19 (defparameter +grid-span+ 50)
20 (defparameter +is-grid-letters+ t)
21 (defparameter +is-grid+ t)
24 ; these two functions can be edited when different grids will be added
25 (defun position-actor-to-view (a)
27 (defun position-view-to-actor (a)
28 (floor (/ a +grid-span+)))
30 (defparameter +letters-list+
31 '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M"
32 "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
34 ;; this function cycle throughout the letters
35 (defun letter-cycle (n)
36 (nth (mod n (length +letters-list+)) +letters-list+))
44 (defun toggle-grid-letters ()
46 (setf +is-grid-letters+ nil)
47 (setf +is-grid-letters+ t)))
49 (defmacro grid-render (renderer plane &optional (x 0) (y 0) (w 100) (h 100))
50 "renderize a grid in where required"
51 `(let ((neg-x (* ,x -1))
55 (x-iterations (/ (- ,w ,x) (grid-dimension ,plane)))
56 (y-iterations (/ (- ,h ,y) (grid-dimension ,plane)))
57 (grid-spacing (grid-dimension ,plane)))
59 ;; (sdl2:set-render-draw-color ,renderer ,red ,green ,blue 255)
60 (loop :for i :from (ceiling (/ neg-x grid-spacing)) :to x-iterations
62 (sdl2:render-draw-line ,renderer
63 (+ (* i grid-spacing) plane-x)
65 (+ (* i grid-spacing) plane-x)
68 (loop :for j :from (ceiling (/ neg-y grid-spacing)) :to y-iterations
70 (sdl2:render-draw-line ,renderer
72 (+ (* j grid-spacing) plane-y)
74 (+ (* j grid-spacing) plane-y))
76 (sdl2:set-render-draw-color ,renderer 0 0 0 255)
79 (defmacro indexes-render (renderer plane &optional (x 0) (y 0) (w 0) (h 0))
80 `(let ((neg-x (* ,x -1))
84 (x-iterations (/ (- ,w ,x) (grid-dimension ,plane)))
85 (y-iterations (/ (- ,h ,y) (grid-dimension ,plane)))
86 (grid-spacing (grid-dimension ,plane)))
87 (loop :for k :from (floor (/ neg-x grid-spacing)) :to x-iterations
88 :do (loop :for l :from (floor (/ neg-y grid-spacing)) :to y-iterations
89 :do (tr-write (coordinate-to-grid-index (cons l (+ k 1)))
90 (+ x-offset (* k grid-spacing))
91 (+ y-offset (* l grid-spacing))
92 (floor (/ grid-spacing 3))
93 (floor (/ grid-spacing 3))
95 ;; (sdl2:set-render-draw-color ,renderer 0 255 0 100) ; remember to uncomment both
96 ;; (sdl2:render-fill-rect ,renderer (sdl2:make-rect ,x ,y ,w ,h)) ; test for x y w and h
99 ;;; BUG: the coordinates given to the macros are incorrect. The render-fill-rect test
100 ;;; proven that the coordinates are not faithful of the view point visual. These
101 ;;; coordinate must be adjusted so the (now commented) render-fill-rect line will
102 ;;; always fill all the screen