1 ;;; Gacela, a GNU Guile extension for fast games development
2 ;;; Copyright (C) 2013 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 (define-module (gacela examples composing-systems)
19 #:use-module (gacela system)
20 #:use-module (ice-9 receive))
23 (define-system s1 ((with-l (l)))
27 (set-entity-components (get-key e) '(l1 . 1)))
30 (define-system s2 ((with-l (l)))
34 (set-entity-components (get-key e) '(l2 . 2)))
37 (define (composing-with-join)
38 (let ((entities (make-entity-set (new-entity '(l . ())) (new-entity '(l . ())) (new-entity '(a . #f)))))
39 (set! entities (modify-entities entities (get-entities-changes ((join-systems s1 s2) entities))))
40 (entity-list entities)))
42 (export composing-with-join)
45 (define (composing-with-thread)
46 (let ((entities (make-entity-set (new-entity '(l . ())) (new-entity '(l . ())) (new-entity '(a . #f)))))
47 (set! entities (modify-entities entities (get-entities-changes ((thread-systems s1 s2) entities))))
48 (entity-list entities)))
50 (export composing-with-thread)
53 (define (join-vs-thread)
54 (let ((entities (make-entity-set (new-entity '(l . ())) (new-entity '(l . ())) (new-entity '(a . #f))))
56 (set! entities (modify-entities entities (get-entities-changes ((join-systems s1 s2) entities))))
57 (format #t "~a~%Time: ~a~%~%" entities (- (current-time) t)))
59 (let ((entities (make-entity-set (new-entity '(l . ())) (new-entity '(l . ())) (new-entity '(a . #f))))
61 (set! entities (modify-entities entities (get-entities-changes ((thread-systems s1 s2) entities))))
62 (format #t "~a~%Time: ~a~%~%" entities (- (current-time) t))))
64 (export join-vs-thread)