diff options
author | David Thompson <dthompson2@worcester.edu> | 2016-01-27 20:26:31 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-01-27 20:26:31 -0500 |
commit | b1513f3640a47a17a4b00c9f6e7f575bfd514619 (patch) | |
tree | d283d34ca496517ea8b4df34352f59d7a593db99 | |
parent | 6ac84e6ac7e83ea840a92747706bc0771cc4c829 (diff) |
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.
-rw-r--r-- | sly/game.scm | 18 |
1 files 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) |