Add error checking

This commit is contained in:
TakeV 2024-05-26 00:29:47 -04:00
parent 7c63afa5b2
commit 0306d65895
Signed by: TakeV
GPG key ID: A64F41345C7400AF
3 changed files with 26 additions and 12 deletions

View file

@ -19,7 +19,8 @@
#:use-module (scheme case-lambda)
#:use-module (ces entity)
#:use-module ((ces entity entity-map) #:prefix emap:)
#:export (create-entity-manager
#:export (entity-manager?
create-entity-manager
create-entity!
add-entity!
reset-entity!
@ -184,6 +185,12 @@ current entities with the next-entities."
(let* ((current-gen (entity-manager-current-entities entity-manager))
(updates (entity-manager-next-entities entity-manager))
(next-generation (emap:copy-entity-map current-gen)))
(unless (emap:entity-map? current-gen)
(error "Current gen is not an entity map"))
(unless (emap:entity-map? updates)
(error "Updates is not an entity map"))
(unless (emap:entity-map? next-generation)
(error "next-generation is not an entity map"))
(write-log! "Updating entities for next-gen")
(emap:update-entities! next-generation updates)
(write-log! "Constructing new entity-manager")

View file

@ -128,10 +128,11 @@ Returns the updated entity, or false if the entity does not exist."
(define (update-entities! entity-map updated-entities-map)
"Updates entity-map using entities. entities can be a list, vector, or entity-map.
Entities within entity-map are added if they do not already exist, or are replaced if they do."
(when (and (entity-map? entity-map)
(entity-map? entity-map))
(if (and (entity-map? entity-map)
(entity-map? updated-entities-map))
(let ((cur-entity-table (entity-map-entities entity-map))
(update-source-table (entity-map-entities entity-map)))
(update-source-table (entity-map-entities updated-entities-map)))
(hashtable-for-each (lambda (k v)
(set-entity! cur-entity-table k v))
update-source-table))))
update-source-table))
(error "Invalid inputs for update-entities!" entity-map updated-entities-map)))

View file

@ -45,10 +45,16 @@
(let ((e-manager (game-entity-manager game))
(s-manager (game-system-manager game)))
(write-log! "Initializing game.")
(vector-for-each (lambda (entity)
(if (and (entity-manager? e-manager)
(system-manager? s-manager))
(begin
(vector-for-each
(lambda (entity)
(apply-systems-to-entity! s-manager entity))
(get-current-entities e-manager))
(make-game e-manager s-manager 0)))
(make-game e-manager s-manager 0))
(error "Game in incorrect state. System manager or entity manager incorrect."
e-manager s-manager))))
(define (step-game! game dt)
"Returns a new game-state after dt"