X-Git-Url: https://git.jsancho.org/?p=gacela.git;a=blobdiff_plain;f=src%2Fsystem.scm;h=3c8454821b733e432dcef33fb9efb8d900bd4d10;hp=9df7cdcc5a701d84783f04e7157497936888513f;hb=0f49b8fac5821694a2db6f88b95423e5ad8aa719;hpb=c4ba277c7f9d23516926693b48e704ff3ea5e8f9 diff --git a/src/system.scm b/src/system.scm index 9df7cdc..3c84548 100644 --- a/src/system.scm +++ b/src/system.scm @@ -180,5 +180,33 @@ (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)