First pass at getting it running.
This commit is contained in:
parent
db07190a9c
commit
12b5ce8e03
1 changed files with 19 additions and 22 deletions
41
game.scm
41
game.scm
|
@ -69,33 +69,30 @@
|
|||
|
||||
(write-log! "Creating game")
|
||||
(define game (make-game e-manager s-manager 0))
|
||||
(define dt (/ 1000.0 60.0))
|
||||
(define game-atom (make-atomic-box #f))
|
||||
(atomic-box-set! game-atom (initialize-game! game))
|
||||
(write-log! "Initialized game.")
|
||||
|
||||
(write-log! "Defining game loop.")
|
||||
(define (update-game)
|
||||
(begin (write-log! "Heartbeat")
|
||||
(let* ((last-game-state (atomic-box-ref game-atom))
|
||||
(next-game-state (step-game! last-game-state dt)))
|
||||
(begin
|
||||
(write-log! (string-append "Looped at - " dt))
|
||||
(atomic-box-set! game-atom next-game-state)
|
||||
(timeout timeout-callback dt)))))
|
||||
|
||||
(write-log! "Defining draw callback maker")
|
||||
(define (make-game-draw-callback game)
|
||||
(let* ((game-atom (make-atomic-box #f)))
|
||||
(begin
|
||||
(write-log! "Called draw callback maker")
|
||||
(atomic-box-set! game-atom (initialize-game! game))
|
||||
(write-log! "Initialized game.")
|
||||
(lambda (dt)
|
||||
(begin
|
||||
(write-log! "Hit pre-game step")
|
||||
(let* ((last-game-state (atomic-box-ref game-atom))
|
||||
(next-game-state (step-game! last-game-state dt)))
|
||||
(begin
|
||||
(write-log! (string-append "Looped at - " dt))
|
||||
(atomic-box-set! game-atom next-game-state))))))))
|
||||
|
||||
(write-log! "Defining update callback")
|
||||
(define timeout-callback (procedure->external update-game))
|
||||
|
||||
(write-log! "Setting canvas size")
|
||||
(set-element-width! canvas (exact game-width))
|
||||
(set-element-height! canvas (exact game-height))
|
||||
|
||||
(write-log! "Defining draw callback")
|
||||
(define draw-callback (procedure->external
|
||||
(make-game-draw-callback game)))
|
||||
|
||||
(write-log! "Requesting initial animation frame.")
|
||||
(request-animation-frame draw-callback))
|
||||
(write-log! "Starting game")
|
||||
(timeout timeout-callback dt))
|
||||
|
||||
|
||||
;; Canvas and event loop setup
|
||||
|
|
Loading…
Reference in a new issue