1 ;;; Gacela, a GNU Guile 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 (use-modules (srfi srfi-1))
22 (define-macro (define-action name attr . code)
23 `(define (,name mob-attr)
26 ,(cons 'begin (map #'attribute-save (reverse attr)))
29 (defun attribute-save (attribute)
30 (let* ((name (cond ((listp attribute) (car attribute))
32 (pname (attribute-name name)))
33 `(setf (getf object-attr ,pname) ,name)))
39 (define-macro (makemob name . methods)
40 `(define* (,name . args)
41 (let ((option (car args)))
45 (:off (mob-off ',name)))
47 (let ((option (car m)) (body (cadr m)))
49 (else (cons (list option `(apply ,body (cdr args))) (options (cddr m)))))))
52 (define-macro (makemob name . methods)
54 (cond ((null? m) '((else #f)))
56 (let ((option (caar m)) (body (cadar m)))
57 (cons `((,option) (apply ,body (cdr args))) (options (cdr m)))))))
58 (let ((m (options methods)))
59 `(define (,name . args)
60 (let ((option (car args)))
62 ((#:on) (mob-on ',name))
63 ((#:off) (mob-off ',name))
70 (define refresh-running-mobs #f)
71 (define quit-all-mobs #f)
73 (let ((running-mobs '()) (mobs-to-add '()) (mobs-to-quit '()))
76 (push mob mobs-to-add)))
79 (lambda* (option #:key args function)
80 (define (run-mobs-rec mobs)
81 (cond ((null? mobs) #f)
83 (cond (function (function)))
84 (catch #t (lambda () (apply (car mobs) (cons option args))) (lambda (key . args) #f))
85 (or #t (run-mobs-rec (cdr mobs))))))
86 (run-mobs-rec running-mobs)))
90 (push mob mobs-to-quit)))
92 (set! refresh-running-mobs
94 (do ((mob (pop mobs-to-add) (pop mobs-to-add))) ((null? mob))
95 (push mob running-mobs)
96 (catch #t (lambda () (mob #:init)) (lambda (key . args) #f)))
97 (set! running-mobs (reverse (lset-difference eq? running-mobs mobs-to-quit)))
98 (set! mobs-to-quit '())))
102 (set! running-mobs '())
103 (set! mobs-to-add '())
104 (set! mobs-to-quit '()))))
110 (define (render-mobs)
111 (run-mobs #:render #:function (lambda () (glLoadIdentity))))