X-Git-Url: https://git.jsancho.org/?p=gacela.git;a=blobdiff_plain;f=gacela%2Fgame.scm;fp=gacela%2Fgame.scm;h=48bf1297b2fce045905db6d40030fa10165fe81e;hp=86136cd9a08fdf0070554dcf6a975efff108ff1d;hb=5a8e5314cceaa73d438c0b3f7a2fdb26ea9b3a2c;hpb=c99c0f2ef95a3f78ed1be83b9b38db6010d21981 diff --git a/gacela/game.scm b/gacela/game.scm index 86136cd..48bf129 100644 --- a/gacela/game.scm +++ b/gacela/game.scm @@ -24,7 +24,8 @@ #:use-module ((sdl2 video) #:prefix sdl2:) #:use-module (gl) #:use-module (srfi srfi-11) - #:export (play-game + #:export (start-game + stop-game %sdl-renderer)) @@ -38,7 +39,8 @@ (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 @@ -74,6 +76,8 @@ unused accumulator time." lag) ((>= lag tick-interval) (process-events) + (if (and (quit?) (procedure? when-quit)) + (when-quit)) ;(agenda-tick!) (iter (- lag tick-interval) (1+ ticks))) (else @@ -143,7 +147,7 @@ milliseconds of the last iteration of the game loop." (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?) @@ -153,8 +157,15 @@ milliseconds of the last iteration of the game loop." (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))