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 action-def . code)
23 (let ((name (car action-def)) (attr (cdr action-def)))
24 `(define (,name mob-attr)
25 (let ,(map attribute-definition attr)
27 ,(cons 'list (map attribute-result attr))))))
29 (define (attribute-definition attribute)
30 (let ((name (if (list? attribute) (car attribute) attribute))
31 (value (if (list? attribute) (cadr attribute) #f)))
32 `(,name (let ((v (assoc-ref mob-attr ',name))) (if v (cdr v) ,value)))))
34 (define (attribute-result attribute)
35 (let ((name (if (list? attribute) (car attribute) attribute)))
36 `(list ',name ,name)))
41 (define-macro (makemob name . methods)
42 `(define* (,name . args)
43 (let ((option (car args)))
47 (:off (mob-off ',name)))
49 (let ((option (car m)) (body (cadr m)))
51 (else (cons (list option `(apply ,body (cdr args))) (options (cddr m)))))))
54 (define-macro (makemob name . methods)
56 (cond ((null? m) '((else #f)))
58 (let ((option (caar m)) (body (cadar m)))
59 (cons `((,option) (apply ,body (cdr args))) (options (cdr m)))))))
60 (let ((m (options methods)))
61 `(define (,name . args)
62 (let ((option (car args)))
64 ((#:on) (mob-on ',name))
65 ((#:off) (mob-off ',name))
72 (define refresh-running-mobs #f)
73 (define quit-all-mobs #f)
75 (let ((running-mobs '()) (mobs-to-add '()) (mobs-to-quit '()))
78 (push mob mobs-to-add)))
81 (lambda* (option #:key args function)
82 (define (run-mobs-rec mobs)
83 (cond ((null? mobs) #f)
85 (cond (function (function)))
86 (catch #t (lambda () (apply (car mobs) (cons option args))) (lambda (key . args) #f))
87 (or #t (run-mobs-rec (cdr mobs))))))
88 (run-mobs-rec running-mobs)))
92 (push mob mobs-to-quit)))
94 (set! refresh-running-mobs
96 (do ((mob (pop mobs-to-add) (pop mobs-to-add))) ((null? mob))
97 (push mob running-mobs)
98 (catch #t (lambda () (mob #:init)) (lambda (key . args) #f)))
99 (set! running-mobs (reverse (lset-difference eq? running-mobs mobs-to-quit)))
100 (set! mobs-to-quit '())))
104 (set! running-mobs '())
105 (set! mobs-to-add '())
106 (set! mobs-to-quit '()))))
112 (define (render-mobs)
113 (run-mobs #:render #:function (lambda () (glLoadIdentity))))