Function name changes and state exports

This commit is contained in:
BirDt_ 2026-03-29 02:07:49 +08:00
parent 700b7a9cda
commit 2a4945d9c7

View file

@ -10,6 +10,11 @@
(srfi 113) (srfi 113)
(srfi 128)) (srfi 128))
;; We export the world, component sets, systems, and event buses so that the core can be extended to
;; include serialization functions across all.
;; NOTE: direct read/write to these is undefined, and will cause problems.
(export world component-sets systems event-buses)
;; The world hash table ;; The world hash table
(define world (make-hash-table)) (define world (make-hash-table))
;; The component-sets hash table ;; The component-sets hash table
@ -33,7 +38,7 @@
;; Create an entity in the world immediately, ;; Create an entity in the world immediately,
;; and add it to the requisite component-sets ;; and add it to the requisite component-sets
(define (create-entity id components) (define (create-entity-now id components)
(hash-table-set! world id components) (hash-table-set! world id components)
(for-each (for-each
(lambda (component) (lambda (component)
@ -41,7 +46,7 @@
components)) components))
;; Remove a single matching item from a set ;; Remove a single matching item from a set
(define (set-remove! set element) (define (remove-from-set! set element)
(set-search! set element (set-search! set element
(lambda (insert ignore) (lambda (insert ignore)
(ignore #f)) (ignore #f))
@ -50,11 +55,11 @@
;; Remove an entity from the world immediately, ;; Remove an entity from the world immediately,
;; as well as from all component sets. ;; as well as from all component sets.
(define (remove-entity id) (define (remove-entity-now id)
(hash-table-delete! world id) (hash-table-delete! world id)
(for-each (for-each
(lambda (set) (lambda (set)
(set-remove! set id)) (remove-from-set! set id))
(hash-table-values component-sets))) (hash-table-values component-sets)))
;; Queues for entity creation and deletion ;; Queues for entity creation and deletion
@ -78,7 +83,7 @@
(lambda (entity) (lambda (entity)
(let ((id (car entity)) (let ((id (car entity))
(components (cdr entity))) (components (cdr entity)))
(create-entity id components))) (create-entity-now id components)))
add-entity-queue) add-entity-queue)
(set! add-entity-queue '())) (set! add-entity-queue '()))
@ -86,7 +91,7 @@
(define (remove-queued-entities) (define (remove-queued-entities)
(for-each (for-each
(lambda (id) (lambda (id)
(remove-entity id)) (remove-entity-now id))
del-entity-queue) del-entity-queue)
(set! del-entity-queue '())) (set! del-entity-queue '()))