]> git.jsancho.org Git - gacela.git/blobdiff - src/system.scm
Functions to merge systems, using a linear way or using threads
[gacela.git] / src / system.scm
index 9df7cdcc5a701d84783f04e7157497936888513f..3c8454821b733e432dcef33fb9efb8d900bd4d10 100644 (file)
          (set-entities res e c))))))
 
 
+(define (join-systems . systems)
+  (lambda (entities components)
+    (let run ((s systems) (e entities) (c components))
+      (cond ((null? s)
+            (values e c))
+           (else
+            (receive (e2 c2) (((car s) e c))
+              (run (cdr s) e2 c2)))))))
+
+
+(define (threaded-systems . systems)
+  (lambda (entities components)
+    (let run-wait ((thd
+                   (map
+                    (lambda (s)
+                      (call-with-new-thread
+                       (lambda () (s entities components))))
+                    systems))
+                  (e entities) (c components))
+      (cond ((null? thd)
+            (values e c))
+           (else
+            (receive (e2 c2) ((join-thread (car thd)) e c)
+              (run-wait (cdr thd) e2 c2)))))))
+
+
 (export find-entities-by-components
-       make-system)
+       make-system
+       join-systems
+       threaded-systems)