Fix entity maps being wrong

This commit is contained in:
TakeV 2024-05-25 19:00:04 -04:00
parent d48efbdba4
commit 537e8cdf23
Signed by: TakeV
GPG key ID: A64F41345C7400AF
2 changed files with 23 additions and 4 deletions

View file

@ -46,7 +46,7 @@
(case-lambda
(() (create-entity-manager (emap:create-entity-map)))
((initial-world-state)
(make-entity-manager initial-world-state
(make-entity-manager (emap:create-entity-map initial-world-state)
(emap:create-entity-map)
(emap:create-entity-map)
(create-entity-generator)))

View file

@ -1,6 +1,7 @@
(define-module (ces entity entity-map)
#:pure
#:use-module (scheme base)
#:use-module (scheme case-lambda)
#:use-module (hoot atomics)
#:use-module (hoot hashtables)
#:use-module (hoot match)
@ -24,9 +25,27 @@
entity-map?
(entities entity-map-entities))
(define (create-entity-map)
"Creates a new entity-map and returns it."
(make-entity-map (make-eq-hashtable)))
(define create-entity-map
(case-lambda
(() (make-entity-map (make-eq-hashtable)))
((initial-entities)
(cond
((list? initial-entities)
(let ((initial-map (make-eq-hashtable)))
(for-each (lambda (val)
(when (game-entity? val)
(hashtable-set! initial-map
(game-entity-id val)
val)))
initial-entities)
(make-entity-map initial-map)))
((hashtable? initial-entities)
(make-entity-map initial-entities))
((entity-map? initial-entities)
(make-entity-map
(hashtable-copy
(entity-map-entities initial-entities))))
(else (create-entity-map))))))
(define (entity-key entity)
"Returns the entity id of an entity, or the value itself if it is