First pass at getting it running.

This commit is contained in:
TakeV 2024-05-25 01:32:58 -04:00
parent db07190a9c
commit 12b5ce8e03
Signed by: TakeV
GPG key ID: A64F41345C7400AF

View file

@ -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