From d379cd28d7531b82f8e0d4887806cbcf43d01b6e Mon Sep 17 00:00:00 2001 From: BirDt_ Date: Thu, 16 Apr 2026 18:48:39 +0800 Subject: [PATCH] Add global systems and bounce boosting --- engine/core.scm | 12 +++++++----- samples/bounce.scm | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/engine/core.scm b/engine/core.scm index aee7e18..92808e2 100644 --- a/engine/core.scm +++ b/engine/core.scm @@ -162,7 +162,7 @@ (define (make-system name priority mode criteria process) (assert (symbol? name)) (assert (integer? priority)) - (assert (member mode '(entity batch))) + (assert (member mode '(entity batch global))) (assert (every symbol? criteria)) (assert (procedure? process)) (int:make-system name priority mode criteria process)) @@ -266,10 +266,12 @@ ;; Execute a single system (define (execute-system system) (assert (system? system)) - (let ((entities (map get-entity (set->list (apply query-by-components (system-criteria system)))))) - (cond - ((eqv? (system-mode system) 'batch) ((system-process system) entities)) - ((eqv? (system-mode system) 'entity) (for-each (lambda (e) ((system-process system) e)) entities))))) + (if (eqv? (system-mode system) 'global) + ((system-process system)) + (let ((entities (map get-entity (set->list (apply query-by-components (system-criteria system)))))) + (cond + ((eqv? (system-mode system) 'batch) ((system-process system) entities)) + ((eqv? (system-mode system) 'entity) (for-each (lambda (e) ((system-process system) e)) entities)))))) (define (execute-systems) (for-each diff --git a/samples/bounce.scm b/samples/bounce.scm index 896a09d..4890d51 100644 --- a/samples/bounce.scm +++ b/samples/bounce.scm @@ -51,8 +51,6 @@ '() (lambda (body) (let ((rbody (find rigidbody-2d? body))) - (display (get-fps)) - (newline) (set-rigidbody-2d-velocity! rbody (vector-+ (rigidbody-2d-velocity rbody) (vector-* @@ -110,6 +108,40 @@ (vector-+ (rigidbody-2d-velocity rbody) (position transform))))))) +(define-record-type + (make-key-press key) + key-press? + (key key-press-key)) + +(add-system + (make-system 'input + 0 + 'global + '() + (lambda () + (when (key-pressed? KEY_SPACE) + (push-event 'input 'boost (make-key-press 'space)))))) + +(add-system + (make-system 'boost-rigidbody + 2 + 'entity + '() + (lambda (ball) + (let ((rbody (find rigidbody-2d? ball))) + (when (peek-event 'input 'boost) + (set-rigidbody-2d-velocity! rbody + (vector-* (make-vector2 2 2) + (rigidbody-2d-velocity rbody)))))))) + +(add-system + (make-system 'clear-boost-input + 10 + 'global + '() + (lambda () + (pop-event 'input 'boost)))) + (create-entity (make-visual-2d (make-circle-2d