From b1513f3640a47a17a4b00c9f6e7f575bfd514619 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 27 Jan 2016 20:26:31 -0500 Subject: game: Add game started hook. * sly/game.scm (game-start-hook, game-started?): New variables. (run-game-loop): Run game-start-hook before loop starts. --- sly/game.scm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sly/game.scm b/sly/game.scm index 6e82b78..615f934 100644 --- a/sly/game.scm +++ b/sly/game.scm @@ -36,18 +36,31 @@ #:use-module (sly math vector) #:use-module (sly window) #:use-module (sly render) - #:export (draw-hook + #:export (game-start-hook + draw-hook after-game-loop-error-hook + game-started? + run-game-loop stop-game-loop)) + ;;; -;;; Game Loop +;;; Hooks and initializers ;;; +(define game-start-hook (make-hook)) (define draw-hook (make-hook 2)) (define after-game-loop-error-hook (make-hook)) +(define-signal game-started? + (hook->signal game-start-hook #f (lambda () #t))) + + +;;; +;;; Game Loop +;;; + (define (interval rate) (floor (/ 1000 rate))) @@ -159,6 +172,7 @@ milliseconds of the last iteration of the game loop." (lambda (signum) (stop-game-loop))) ;; Let's play! + (run-hook game-start-hook) (game-loop (sdl-ticks) 0)) (lambda (cont callback) (when (procedure? callback) -- cgit v1.2.3