From d521b9e605e8153096a377b60b412514f7adbdfd Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sat, 14 Sep 2013 08:27:46 +0200 Subject: [PATCH] Functions to access entities and components inside systems * src/system.scm: get-key get-component * src/examples/making-systems.scm: access functions testing --- src/examples/making-systems.scm | 17 +++++++++++++++-- src/system.scm | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/examples/making-systems.scm b/src/examples/making-systems.scm index 3709719..0addc1b 100644 --- a/src/examples/making-systems.scm +++ b/src/examples/making-systems.scm @@ -22,14 +22,27 @@ (define-component a x y) +(define-system (s1) + (lambda (e) + (list (new-entity (make-a 1 2)) + (new-entity (make-a 10 20))))) + +(define-system (s2 a) + (lambda (e) + (for-each + (lambda (e1) + (format #t "Key: ~a Component: ~a~%" (get-key e1) (get-component 'a e1))) + e) + '())) + (define (making-systems) (let ((entities '()) (components '())) - (receive (e c) (((make-system () (lambda (e) (list (new-entity (make-a 1 2)) (new-entity (make-a 10 20))))) entities components)) + (receive (e c) ((s1 entities components)) (set! entities e) (set! components c)) (format #t "Two new entities with a:~%~a~%~a~%~%" entities components) - (((make-system (a) (lambda (e) (display e) (newline) '())) entities components)))) + ((s2 entities components)))) (export making-systems) diff --git a/src/system.scm b/src/system.scm index 2a9365b..587fc06 100644 --- a/src/system.scm +++ b/src/system.scm @@ -225,3 +225,16 @@ make-system join-systems threaded-systems) + + +;;; Entities and components access inside systems + +(define (get-key entity) + (car entity)) + +(define (get-component component-name entity) + (assoc-ref (cdr entity) component-name)) + + +(export get-key + get-component) -- 2.39.5