Add scene system and update example
This commit is contained in:
parent
e7bfc01f7b
commit
f54f9c4b40
3 changed files with 197 additions and 115 deletions
42
engine/scene.scm
Normal file
42
engine/scene.scm
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
(module (engine scene) ()
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken module)
|
||||
(engine core)
|
||||
(srfi 1)
|
||||
(srfi 99))
|
||||
|
||||
;; This is just for easier serialization
|
||||
(define-record-type <entity>
|
||||
(make-entity name components)
|
||||
entity?
|
||||
(name entity-name)
|
||||
(components entity-components))
|
||||
|
||||
(export entity named-entity)
|
||||
(define (entity . components)
|
||||
(apply make-entity (cons '() (list components))))
|
||||
|
||||
(define (named-entity name . components)
|
||||
(apply make-entity (cons name (list components))))
|
||||
|
||||
(export scene)
|
||||
;; Every element of items here is either an entity record or system
|
||||
(define (scene . items)
|
||||
(lambda ()
|
||||
(clear-world)
|
||||
(clear-systems)
|
||||
(clear-event-bus 'input)
|
||||
(for-each
|
||||
(lambda (entity)
|
||||
(if (null? (entity-name entity))
|
||||
(apply create-entity (entity-components entity))
|
||||
(apply create-named-entity (cons (entity-name entity)
|
||||
(entity-components entity)))))
|
||||
(filter entity? items))
|
||||
(for-each
|
||||
(lambda (system)
|
||||
(add-system system))
|
||||
(filter system? items))))
|
||||
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue