#:use-module (ice-9 optargs)
#:export (load-texture
load-font
+ *title*
+ *width-screen*
+ *height-screen*
+ *bpp-screen*
+ *frames-per-second*
+ *mode*
+ set-game-properties!
+ get-game-properties
init-gacela
quit-gacela
game-loop
render-text))
-;;; Default values for Gacela
-
-(define *title* "Gacela")
-(define *width-screen* 640)
-(define *height-screen* 480)
-(define *bpp-screen* 32)
-(define *frames-per-second* 20)
-(define *mode* '2d)
-
-
;;; Resources Cache
(define resources-cache (make-weak-value-hash-table))
(use-cache-with (gacela video) load-font)
-;;; Game Properties
-
-(define set-game-properties! #f)
-(define get-game-properties #f)
-
-;; (let ((ptitle *title*) (pwidth *width-screen*) (pheight *height-screen*) (pbpp *bpp-screen*) (pfps *frames-per-second*) (pmode *mode*))
-;; (set! set-game-properties!
-;; (lambda* (#:key title width height bpp fps mode)
-;; ; (init-video-mode)
-;; (if title
-;; (begin
-;; (set! ptitle title)
-;; (if (video-mode-on?) (SDL_WM_SetCaption title ""))))
-;; (if (or width height bpp)
-;; (begin
-;; (if width (set! pwidth width))
-;; (if height (set! pheight height))
-;; (if bpp (set! pbpp bpp))
-;; (if (video-mode-on?) (resize-screen pwidth pheight pbpp))))
-;; (if fps
-;; (begin
-;; (set! pfps fps)
-;; (set-frames-per-second fps)))
-;; (if mode
-;; (begin
-;; (set! pmode mode)
-;; (if (video-mode-on?)
-;; (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))))
-;; (get-game-properties)))
-
-;; (set! get-game-properties
-;; (lambda ()
-;; `((title . ,ptitle) (width . ,pwidth) (height . ,pheight) (bpp . ,pbpp) (fps . ,pfps) (mode . ,pmode)))))
-
-
;;; Main Loop
(define loop-flag #f)
(define game-code #f)
+(define game-loop-thread #f)
(define-macro (game . code)
`(let ((game-function ,(if (null? code)
(cond ((not (game-running?))
(game-loop)))))
+(define-macro (run-in-game-loop . code)
+ `(if game-loop-thread
+ (system-async-mark (lambda () ,@code) game-loop-thread)
+ (begin ,@code)))
+
(define (init-gacela)
- (call-with-new-thread (lambda () (game))))
+ (set! game-loop-thread (call-with-new-thread (lambda () (game)))))
(define (quit-gacela)
+ (set! game-loop-thread #f)
(set! loop-flag #f))
(define (game-loop)
; (refresh-active-mobs)
(set! loop-flag #t)
- (init-video 640 480 32)
-; (quit! #f)
+ (init-video *width-screen* *height-screen* *bpp-screen* #:title *title* #:mode *mode* #:fps *frames-per-second*)
(while loop-flag
-; (init-frame-time)
+ (init-frame-time)
; (check-connections)
(process-events)
- (cond ((not (quit?))
+ (cond ((quit-signal?)
+ (quit-gacela))
+ (else
(clear-screen)
(to-origin)
; (refresh-active-mobs)
(lambda (key . args) #f)))
; (run-mobs)
(flip-screen)
-; (delay-frame))))
- )))
+ (delay-frame))))
(quit-video))
(define (game-running?)
(define (set-game-code game-function)
(set! game-code game-function))
+
+
+;;; Game Properties
+
+(define *title* "Gacela")
+(define *width-screen* 640)
+(define *height-screen* 480)
+(define *bpp-screen* 32)
+(define *frames-per-second* 20)
+(define *mode* '2d)
+
+(define* (set-game-properties! #:key title width height bpp fps mode)
+ (if title
+ (set-screen-title! title))
+ (if bpp
+ (run-in-game-loop (set-screen-bpp! bpp)))
+ (if (or width height)
+ (begin
+ (if (not width) (set! width (get-screen-width)))
+ (if (not height) (set! height (get-screen-height)))
+ (run-in-game-loop (resize-screen width height))))
+ (if fps
+ (set-frames-per-second! fps))
+ (if mode
+ (if (eq? mode '3d) (set-3d-mode) (set-2d-mode))))
+
+(define (get-game-properties)
+ `((title . ,(get-screen-title)) (width . ,(get-screen-width)) (height . ,(get-screen-height)) (bpp . ,(get-screen-bpp)) (fps . ,(get-frames-per-second)) (mode . ,(if (3d-mode?) '3d '2d))))