Expose global entity-manager and system-manager parameters
This commit is contained in:
parent
e99af4512d
commit
9e294b88d7
1 changed files with 14 additions and 11 deletions
|
@ -15,7 +15,10 @@
|
|||
step-game!
|
||||
start-game!
|
||||
get-entity-manager
|
||||
get-system-manager))
|
||||
get-system-manager
|
||||
|
||||
%entity-manager-parameter
|
||||
%system-manager-parameter))
|
||||
|
||||
(define-record-type <game>
|
||||
(make-game entity-manager system-manager previous-time current-time)
|
||||
|
@ -28,19 +31,19 @@
|
|||
;;; Both entity and system managers are parameterized which means that
|
||||
;;; systems can pretend they are accessing global varables, however
|
||||
;;; the managers are bound for each loop. Nothing leaks. :)
|
||||
(define %entity-manager-parameter (make-parameter #f))
|
||||
(define %system-manager-parameter (make-parameter #f))
|
||||
(define *entity-manager-parameter* (make-parameter #f))
|
||||
(define *system-manager-parameter* (make-parameter #f))
|
||||
|
||||
(define (get-entity-manager)
|
||||
(%entity-manager-parameter))
|
||||
(*entity-manager-parameter*))
|
||||
(define (get-system-manager)
|
||||
(%system-manager-parameter))
|
||||
(*system-manager-parameter*))
|
||||
|
||||
(define (initialize-game! game)
|
||||
(let ((e-manager (game-entity-manager game))
|
||||
(s-manager (game-system-manager game)))
|
||||
(parameterize ((%entity-manager-parameter e-manager)
|
||||
(%system-manager-parameter s-manager))
|
||||
(parameterize ((*entity-manager-parameter* e-manager)
|
||||
(*system-manager-parameter* s-manager))
|
||||
(vector-for-each (lambda (entity)
|
||||
(apply-systems-to-entity! s-manager entity))
|
||||
(get-current-entities e-manager)))))
|
||||
|
@ -49,8 +52,8 @@
|
|||
"Returns a new game-state after dt"
|
||||
(let* ((e-manager (game-entity-manager game))
|
||||
(s-manager (game-system-manager game)))
|
||||
(parameterize ((%entity-manager-parameter e-manager)
|
||||
(%system-manager-parameter s-manager))
|
||||
(parameterize ((*entity-manager-parameter* e-manager)
|
||||
(*system-manager-parameter* s-manager))
|
||||
(run-systems-pre-process! s-manager)
|
||||
(run-systems! s-manager dt)
|
||||
(run-systems-post-process! s-manager)
|
||||
|
@ -68,7 +71,7 @@
|
|||
(loop-game! next-state dt)))
|
||||
|
||||
(define (start-game! game dt)
|
||||
(parameterize ((%entity-manager-parameter (game-entity-manager game))
|
||||
(%system-manager-parameter (game-system-manager game)))
|
||||
(parameterize ((*entity-manager-parameter* (game-entity-manager game))
|
||||
(*system-manager-parameter* (game-system-manager game)))
|
||||
(initialize-game! game)
|
||||
(loop-game! game dt)))
|
||||
|
|
Loading…
Reference in a new issue