+;;; Entities and components
+
+(define (new-entity new-components entities components)
+ (let ((key (gensym)))
+ (values
+ (acons key (map (lambda (c) `(,(get-component-type c) . ,c)) new-components) entities)
+ (register-components key new-components components)
+ key)))
+
+(define* (register-components entity components clist)
+ (cond ((null? components) clist)
+ (else
+ (let* ((type (get-component-type (car components)))
+ (elist (assoc-ref clist type)))
+ (register-components entity (cdr components)
+ (assoc-set! clist type
+ (cond (elist
+ (lset-adjoin eq? elist entity))
+ (else
+ (list entity)))))))))
+
+(export new-entity)
+
+