From c62dceb1471afb94efa57eef5506fbdf6f2ef679 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 8 Dec 2013 07:11:34 +0100 Subject: [PATCH] Set engine systems while running * src/engine.scm: new function set-engine-systems! using engine mutex for avoiding concurrency errors * src/system.scm: new function group-systems, that returns joined systems or an empty system, depending on arguments --- src/engine.scm | 11 +++++++---- src/system.scm | 11 ++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/engine.scm b/src/engine.scm index 4e311a0..33c8a6f 100644 --- a/src/engine.scm +++ b/src/engine.scm @@ -50,9 +50,7 @@ (list e c)) (make-mutex) (make-mutex) - (if (not (= (length systems) 1)) - (join-systems systems) - (car systems)))) + (apply group-systems systems))) (define-syntax define-engine (syntax-rules () @@ -122,6 +120,10 @@ (set-current-engine! old-engine) res))))) +(define (set-engine-systems! engine . systems) + (with-mutex (engine-mutex engine) + (set-engine-system! engine (apply group-systems systems)))) + (export current-engine set-current-engine! get-entity @@ -131,7 +133,8 @@ set-entity! set-entity-components! remove-entity-components! - with-engine) + with-engine + set-engine-systems!) ;;; Engine execution diff --git a/src/system.scm b/src/system.scm index 3d5cb2b..2bf0520 100644 --- a/src/system.scm +++ b/src/system.scm @@ -247,11 +247,20 @@ (receive (e2 c2) ((join-thread (car thd)) e c) (run-wait (cdr thd) e2 c2))))))) +(define (group-systems . systems) + (cond ((null? systems) + (make-system ())) + ((= (length systems) 1) + (car systems)) + (else + (join-systems systems)))) + (export find-entities-by-components define-system make-system join-systems - threaded-systems) + threaded-systems + group-systems) ;;; Entities and components access inside systems -- 2.39.5