From 537e8cdf23319c906d5ba6cdacb4e6729f288295 Mon Sep 17 00:00:00 2001 From: TakeV Date: Sat, 25 May 2024 19:00:04 -0400 Subject: [PATCH 1/4] Fix entity maps being wrong --- modules/ces/entity-manager.scm | 2 +- modules/ces/entity/entity-map.scm | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/ces/entity-manager.scm b/modules/ces/entity-manager.scm index 3dc8d6c..5192200 100644 --- a/modules/ces/entity-manager.scm +++ b/modules/ces/entity-manager.scm @@ -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))) diff --git a/modules/ces/entity/entity-map.scm b/modules/ces/entity/entity-map.scm index 092ad52..a8b51ff 100644 --- a/modules/ces/entity/entity-map.scm +++ b/modules/ces/entity/entity-map.scm @@ -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 From 7888601c1e37a6c60ab5309f0cbc057a411e5aec Mon Sep 17 00:00:00 2001 From: TakeV Date: Sat, 25 May 2024 19:00:49 -0400 Subject: [PATCH 2/4] Bootstrap entity-manager/system-manager so we can use the initial list --- game.scm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/game.scm b/game.scm index d349bc9..1f892f0 100644 --- a/game.scm +++ b/game.scm @@ -66,9 +66,12 @@ (parameterize ((*media-library* (create-media-library))) (add-images! (get-media-library) game-images) + (define bootstrap-entity-manager (make-parameter #f)) + (define bootstrap-system-manager (make-parameter #f)) (write-log! "Creating entity manager") - (define e-manager - (create-entity-manager (init-game-entities))) + (define e-manager (parameterize ((*entity-manager-parameter* bootstrap-entity-manager) + (*system-manager-parameter* bootstrap-system-manager)) + (create-entity-manager (pk (init-game-entities))))) (write-log! "Creating system manager") (define s-manager From 4fcc130c9c1ca25fd01c7053c2f71ff519ccf279 Mon Sep 17 00:00:00 2001 From: TakeV Date: Sat, 25 May 2024 19:27:03 -0400 Subject: [PATCH 3/4] Fix game images alist --- game.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/game.scm b/game.scm index 1f892f0..1b7faab 100644 --- a/game.scm +++ b/game.scm @@ -56,11 +56,11 @@ (define game-width 640.0) (define game-height 480.0) -(define game-images `(('player . ,(make-image "assets/sprites/player.png")) - ('barrel . ,(make-image "assets/sprites/barrel.png")) - ('bricks . ,(make-image "assets/sprites/bricks.png")) - ('stones . ,(make-image "assets/sprites/stones.png")) - ('card-back . ,(make-image "assets/sprites/bricks.png")))) +(define game-images `((player . ,(make-image "assets/sprites/player.png")) + (barrel . ,(make-image "assets/sprites/barrel.png")) + (bricks . ,(make-image "assets/sprites/bricks.png")) + (stones . ,(make-image "assets/sprites/stones.png")) + (card-back . ,(make-image "assets/sprites/bricks.png")))) (parameterize ((*logger* pk)) (parameterize ((*media-library* (create-media-library))) From 86af891b0c50f322d4dc6c4817dd34c4ffe06bae Mon Sep 17 00:00:00 2001 From: TakeV Date: Sat, 25 May 2024 19:28:44 -0400 Subject: [PATCH 4/4] Update media-library logging and return value --- modules/media.scm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/media.scm b/modules/media.scm index 6c45000..5ef5f54 100644 --- a/modules/media.scm +++ b/modules/media.scm @@ -27,19 +27,17 @@ (*media-library*)) (define (create-media-library) - (write-log! "Creating media library.") (make-media-library (make-eq-hashtable) (make-eq-hashtable))) (define (add-image! media-library image-symbol image) - (write-log! "Adding image: " image-symbol) (hashtable-set! (media-images media-library) image-symbol image)) (define (add-images! media-library images) - (write-log! "Adding images: " images) (for-each (lambda (val) (add-image! media-library (car val) (cdr val))) images)) (define (get-image media-library image-symbol) - (hashtable-ref (media-images media-library) image-symbol #f)) + "Gets the image in the library, or 'image-not-found if the image does not exists." + (hashtable-ref (media-images media-library) image-symbol 'image-not-found))