]> git.jsancho.org Git - gacela.git/blob - gacela_boxes.lisp
(no commit message)
[gacela.git] / gacela_boxes.lisp
1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
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 <http://www.gnu.org/licenses/>.
16
17
18 (eval-when (compile load eval)
19            (when (not (find-package 'gacela)) (make-package 'gacela :nicknames '(gg) :use '(lisp)))
20            (in-package 'gacela :nicknames '(gg) :use '(lisp)))
21
22
23 ;;; Boxes Factory
24
25 (let (visible-boxes boxes-to-add boxes-to-quit)
26   (defun add-box (box)
27     (push box boxes-to-add))
28
29   (defun quit-box (box)
30     (push box boxes-to-quit))
31
32   (defun quit-all-boxes ()
33     (setq visible-boxes nil boxes-to-add nil boxes-to-quit nil))
34
35   (defun refresh-visible-boxes ()
36     (cond (boxes-to-add
37            (setq visible-boxes (union visible-boxes boxes-to-add))
38            (setq boxes-to-add nil)))
39     (cond (boxes-to-quit
40            (setq visible-boxes (reverse (set-difference visible-boxes boxes-to-quit)))
41            (setq boxes-to-quit nil))))
42
43   (defun render-boxes ()
44     (labels ((render (l)
45                      (cond (l (funcall (render-fun-name (car l)))
46                               (render (cdr l))))))
47             (render visible-boxes))))
48
49
50 (defun render-fun-name (name)
51   (intern (concatenate 'string "RENDER-BOX-" (string name)) 'gacela))
52
53 (defun get-props-fun-name (name)
54   (intern (concatenate 'string "GET-PROPERTIES-BOX-" (string name)) 'gacela))
55
56 (defmacro make-box (name properties &rest code)
57   `(progn
58      (let ,(union '((rx 0) (ry 0) (rz 0)) properties)
59        (defun ,(render-fun-name name) () ,@code)
60        (defun ,(get-props-fun-name name) () (list :rx rx :ry ry :rz rz)))
61      (add-box ',name)))
62
63
64 ;;; Translations and rotations
65
66 (defun rotate-box (&rest rot)
67   )