(define-system s1 ((with-l (l)))
(sleep 3)
- (map
- (lambda (e)
- (set-entity-components (get-key e) `(l . ,(cons 1 (get-component 'l e)))))
- with-l))
+ (entities-changes
+ (map (lambda (e)
+ (set-entity-components (get-key e) `(l . ,(cons 1 (get-component 'l e)))))
+ with-l)))
(define-system s2 ((with-l (l)))
(sleep 4)
- (map
- (lambda (e)
- (set-entity-components (get-key e) `(l . ,(cons 2 (get-component 'l e)))))
- with-l))
+ (entities-changes
+ (map (lambda (e)
+ (set-entity-components (get-key e) `(l . ,(cons 2 (get-component 'l e)))))
+ with-l)))
(define (composing-with-join)
(let ((entities '())
(define-component a x y)
(define-system s1 ()
- (list (new-entity (make-a 1 2))
- (new-entity (make-a 10 20))))
+ (entities-changes
+ (list (new-entity (make-a 1 2))
+ (new-entity (make-a 10 20)))))
(define-system s2 ((with-a (a)))
(for-each
(lambda (e)
(format #t "Key: ~a Component: ~a~%" (get-key e) (get-component 'a e)))
- with-a)
- '())
+ with-a))
(define (making-systems)
(let ((entities '())
;;; Making systems
+(define-record-type entities-changes-type
+ (entities-changes changes)
+ entities-changes?
+ (changes get-entities-changes))
+
(define* (find-entities-by-components c t)
(cond ((null? t) '())
(else
(lambda* (#:optional (entities2 #f) (components2 #f))
(let ((e (if (and entities2 components2) entities2 entities))
(c (if (and entities2 components2) components2 components)))
- (modify-entities res e c)))))))))
+ (modify-entities (if (entities-changes? res) (get-entities-changes res) '()) e c)))))))))
(define-syntax define-system
(syntax-rules ()
(else
(apply join-systems systems))))
-(export find-entities-by-components
+(export entities-changes
+ entities-changes?
+ get-entities-changes
+ find-entities-by-components
define-system
make-system
join-systems