(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)
))
(export test2)
+
+
+(define (test3)
+ (let ((entities '())
+ (components '())
+ (s1 (make-system '(l)
+ (lambda (e)
+ (map
+ (lambda (e1)
+ `(,(car e1) . ((l . (cons 1 (cdr e1)))))
+ e)))))
+ (s2 (make-system '(l)
+ (lambda (e)
+ (map
+ (lambda (e1)
+ `(,(car e1) . ((l . (cons 2 (cdr e1))))))
+ e)))))
+ (receive (e c) (set-entities `((#f . ((l . ()))) (#f . ((l . ())))) entities components)
+ ((join-systems s1 s2) e c))))
+
+(export test3)
+
+
+(define (test4)
+ (let ((f1 (lambda (e c) (sleep 3) (lambda (e2 c2) (values (+ 1 e2) c2))))
+ (f2 (lambda (e c) (sleep 4) (lambda (e2 c2) (values e2 (+ 10 c2))))))
+ (let ((t (current-time)))
+ (receive (e c) ((join-systems f1 f2) 2 2) (format #t "~a~%~a~%" e c))
+ (display (- (current-time) t)) (newline) (newline))
+ (let ((t (current-time)))
+ (receive (e c) ((threaded-systems f1 f2) 2 2) (format #t "~a~%~a~%" e c))
+ (display (- (current-time) t)) (newline) (newline))))
+
+(export test4)