1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
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 <http://www.gnu.org/licenses/>.
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)))
23 ;;; Behaviours of entities
25 (defmacro make-behaviour (name properties &rest code)
26 `(defun ,name (entity)
27 (let ,(mapcar #'property-definition properties)
29 ,(cons 'progn (mapcar #'property-save properties))
32 (defun property-name (property)
33 (intern (string property) 'keyword))
35 (defun property-definition (property)
36 (let* ((name (cond ((listp property) (car property))
38 (pname (property-name name))
39 (value (cond ((listp property) (cadr property)))))
40 `(,name (getf entity ,pname ,value))))
42 (defun property-save (property)
43 (let* ((name (cond ((listp property) (car property))
45 (pname (property-name name)))
46 `(setf (getf entity ,pname) ,name)))
54 (let (visible-boxes boxes-to-add boxes-to-quit)
56 (push box boxes-to-add))
59 (push box boxes-to-quit))
61 (defun quit-all-boxes ()
62 (setq visible-boxes nil boxes-to-add nil boxes-to-quit nil))
64 (defun refresh-visible-boxes ()
66 (setq visible-boxes (union visible-boxes boxes-to-add))
67 (setq boxes-to-add nil)))
69 (setq visible-boxes (reverse (set-difference visible-boxes boxes-to-quit)))
70 (setq boxes-to-quit nil))))
72 (defun render-boxes ()
74 (cond (l (funcall (render-fun-name (car l)))
76 (render visible-boxes))))
79 (defun render-fun-name (name)
80 (intern (concatenate 'string "RENDER-BOX-" (string name)) 'gacela))
82 (defun get-props-fun-name (name)
83 (intern (concatenate 'string "GET-PROPERTIES-BOX-" (string name)) 'gacela))
85 (defmacro make-box (name properties &rest code)
87 (let ,(union '((rx 0) (ry 0) (rz 0)) properties)
88 (defun ,(render-fun-name name) () ,@code)
89 (defun ,(get-props-fun-name name) () (list :rx rx :ry ry :rz rz)))