From: jsancho Date: Wed, 28 Dec 2011 19:32:05 +0000 (+0000) Subject: Game properties. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=62f29c535971a4af5c4a957444a53eb6007b32e3;p=gacela.git Game properties. --- diff --git a/src/events.scm b/src/events.scm index dfe9e60..fb21d88 100644 --- a/src/events.scm +++ b/src/events.scm @@ -18,7 +18,7 @@ (define-module (gacela events) #:use-module (gacela sdl) #:export (process-events - quit? + quit-signal? key? key-pressed? key-released?)) @@ -54,7 +54,7 @@ (cond ((= (assoc-ref event 'type) SDL_QUIT) (set! quit-signal #t)))) (process-screen-events (cdr events))))) -(define (quit?) +(define (quit-signal?) quit-signal) diff --git a/src/gacela.scm b/src/gacela.scm index 256e940..86c4605 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -22,6 +22,8 @@ #:use-module (ice-9 optargs) #:export (load-texture load-font + set-game-properties! + get-game-properties init-gacela quit-gacela game-loop @@ -48,16 +50,6 @@ 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)) @@ -88,37 +80,31 @@ ;;; 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))))) +(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 + (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))) + (resize-screen width height))) + (if fps + (set-frames-per-second fps)) + (if mode + (if (eq? mode '3d) (set-3d-mode) (set-2d-mode))) + (get-game-properties)) + +(define (get-game-properties) + `((title . ,(get-screen-title)) (width . ,(get-screen-width)) (height . ,(get-screen-height)) (bpp . ,(get-screen-bpp)) (fps . ,pfps) (mode . ,pmode))) ;;; Main Loop diff --git a/src/video.scm b/src/video.scm index 7eda879..f9e37f1 100644 --- a/src/video.scm +++ b/src/video.scm @@ -26,10 +26,13 @@ get-screen-height get-screen-width get-screen-bpp + set-screen-bpp! resize-screen quit-video clear-screen flip-screen + set-screen-title! + get-screen-title set-2d-mode set-3d-mode 3d-mode? @@ -73,7 +76,7 @@ (if (= (assoc-ref info 'hw_available) 0) SDL_SWSURFACE SDL_HWSURFACE) (if (= (assoc-ref info 'blit_hw) 0) 0 SDL_HWACCEL))) (set! screen (SDL_SetVideoMode width height bpp flags)) - (SDL_WM_SetCaption title "") + (set-screen-title! title) (init-gl) (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))))) @@ -86,6 +89,10 @@ (define (get-screen-bpp) (surface-format-BytesPerPixel screen)) +(define (set-screen-bpp! bpp) + (cond (screen + (set! screen (SDL_SetVideoMode (get-screen-width) (get-screen-height) bpp flags))))) + (define (resize-screen width height) (cond (screen (set! screen (SDL_SetVideoMode width height (get-screen-bpp) flags)) @@ -104,6 +111,16 @@ (SDL_GL_SwapBuffers)) +(define screen-title "") + +(define (set-screen-title! title) + (set! screen-title title) + (SDL_WM_SetCaption title "")) + +(define (get-screen-title) + screen-title) + + (define mode '2d) (define (set-2d-mode)