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) `(l . ,(cons 1 (get-component 'l e)))))
30 (define-system s2 ((with-l (l)))
34 (set-entity-components (get-key e) `(l . ,(cons 2 (get-component 'l e)))))
37 (define (composing-with-join)
40 (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components)
41 (((join-systems s1 s2) e c)))))
43 (export composing-with-join)
46 (define (composing-with-threaded)
49 (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components)
50 (((threaded-systems s1 s2) e c)))))
52 (export composing-with-threaded)
55 (define (join-vs-threaded)
59 (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components)
60 (receive (e c) (((join-systems s1 s2) e c))
61 (format #t "~a~%~a~%Time: ~a~%~%" e c (- (current-time) t)))))
66 (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components)
67 (receive (e c) (((threaded-systems s1 s2) e c))
68 (format #t "~a~%~a~%Time: ~a~%~%" e c (- (current-time) t))))))
70 (export join-vs-threaded)