#:use-module ((sdl2 video) #:prefix sdl2:)
#:use-module (gl)
#:use-module (srfi srfi-11)
- #:export (play-game
+ #:export (start-game
+ stop-game
%sdl-renderer))
(define* (run-game-loop scene #:key
(frame-rate 60)
(tick-rate 60)
- (max-ticks-per-frame 4))
+ (max-ticks-per-frame 4)
+ (when-quit #f))
"Run the game loop. SCENE is a signal which contains the current
scene renderer procedure. FRAME-RATE specifies the optimal number of
frames to draw SCENE per second. TICK-RATE specifies the optimal game
lag)
((>= lag tick-interval)
(process-events)
+ (if (and (quit?) (procedure? when-quit))
+ (when-quit))
;(agenda-tick!)
(iter (- lag tick-interval) (1+ ticks)))
(else
(set! %gl-context (sdl2:make-gl-context %sdl-window))
(sdl2:set-gl-swap-interval! 'vsync))
-(define* (open-window #:key (title "Untitled") (resolution '(640 480)) (fullscreen? #f))
+(define (open-window title resolution fullscreen?)
(sdl2:set-window-title! %sdl-window title)
(sdl2:set-window-size! %sdl-window resolution)
(sdl2:set-window-fullscreen! %sdl-window fullscreen?)
(sdl2:hide-window! %sdl-window)
(sdl2:sdl-quit))
-(define (play-game scene . args)
+(define* (start-game scene #:key
+ (title "Untitled")
+ (resolution '(640 480))
+ (fullscreen? #f)
+ (when-quit (lambda () (stop-game))))
(init-window)
- (apply open-window args)
- (run-game-loop scene)
+ (open-window title resolution fullscreen?)
+ (run-game-loop scene #:when-quit when-quit)
(close-window))
+
+(define (stop-game)
+ (stop-game-loop))