X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fexamples%2Fcomposing-systems.scm;fp=src%2Fexamples%2Fcomposing-systems.scm;h=feecee360b45957a06a639611841c13fba3549cd;hb=2b3814bf3f335a56c17b733caf90c17dbe229e91;hp=0000000000000000000000000000000000000000;hpb=9b261e3a07d92edf68979b46f756413a0ac9247a;p=gacela.git diff --git a/src/examples/composing-systems.scm b/src/examples/composing-systems.scm new file mode 100644 index 0000000..feecee3 --- /dev/null +++ b/src/examples/composing-systems.scm @@ -0,0 +1,74 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2013 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . + + +(define-module (gacela examples composing-systems) + #:use-module (gacela system) + #:use-module (ice-9 receive)) + + +(define s1 + (make-system '(l) + (lambda (e) + (sleep 3) + (map + (lambda (e1) + (set-entity-components (car e1) `(l . ,(cons 1 (cdadr e1))))) + e)))) + +(define s2 + (make-system '(l) + (lambda (e) + (sleep 4) + (map + (lambda (e1) + (set-entity-components (car e1) `(l . ,(cons 2 (cdadr e1))))) + e)))) + +(define (composing-with-join) + (let ((entities '()) + (components '())) + (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components) + ((join-systems s1 s2) e c)))) + +(export composing-with-join) + + +(define (composing-with-threaded) + (let ((entities '()) + (components '())) + (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components) + ((threaded-systems s1 s2) e c)))) + +(export composing-with-threaded) + + +(define (join-vs-threaded) + (let ((entities '()) + (components '()) + (t (current-time))) + (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components) + (receive (e c) ((join-systems s1 s2) e c) + (format #t "~a~%~a~%Time: ~a~%~%" e c (- (current-time) t))))) + + (let ((entities '()) + (components '()) + (t (current-time))) + (receive (e c) (modify-entities (list (new-entity '(l . ())) (new-entity '(l . ()))) entities components) + (receive (e c) ((threaded-systems s1 s2) e c) + (format #t "~a~%~a~%Time: ~a~%~%" e c (- (current-time) t)))))) + +(export join-vs-threaded)