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/>.
22 (defmacro makemob (name &rest methods)
23 `(defun ,name (&rest args &aux (option (car args)))
26 (:on (mob-on #',name))
27 (:off (mob-off #',name)))
28 (labels ((options (m &aux (option (car m)) (body (cadr m)))
30 (t (cons (list option `(apply ,body (cdr args))) (options (cddr m)))))))
33 (defmacro mob-structure (variables init logic render)
35 :init (lambda () ,init)
36 :logic (lambda () ,logic)
37 :render (lambda () ,render)
41 ',(mapcar #'car+ variables)
43 (values-list ,(cons 'list (mapcar #'car+ variables)))))
46 (let (running-mobs mobs-to-add mobs-to-quit)
48 (push mob mobs-to-add))
51 (dolist (mob running-mobs) (funcall mob :logic)))
54 (dolist (mob running-mobs) (funcall mob :render)))
57 (push mob mobs-to-quit))
59 (defun refresh-running-mobs ()
60 (do ((mob (pop mobs-to-add) (pop mobs-to-add))) ((null mob))
61 (push mob running-mobs)
63 (setq running-mobs (reverse (set-difference running-mobs mobs-to-quit :test #'equal))))
65 (defun quit-all-mobs ()
66 (setq running-mobs nil mobs-to-add nil mobs-to-quit nil)))