(module (imugi scene) () (import scheme (chicken base) (chicken module) (imugi core) (srfi 1) (srfi 99)) ;; This is just for easier serialization (define-record-type (make-entity name components) entity? (name entity-name) (components entity-components)) (export entity named-entity) (define (entity . components) (apply make-entity (cons '() (list components)))) (define (named-entity name . components) (apply make-entity (cons name (list components)))) (export scene) ;; Every element of items here is either an entity record or system (define (scene . items) (lambda () (clear-world) (clear-systems) (clear-event-bus 'input) (for-each (lambda (entity) (if (null? (entity-name entity)) (apply create-entity (entity-components entity)) (apply create-named-entity (cons (entity-name entity) (entity-components entity))))) (filter entity? items)) (for-each (lambda (system) (add-system system)) (filter system? items)))) )