From: jsancho Date: Thu, 29 Dec 2011 20:38:33 +0000 (+0000) Subject: Games properties. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=bbfc49f49dedf5020c25426f276537fe0aa46771;p=gacela.git Games properties. --- diff --git a/src/gacela.scm b/src/gacela.scm index 86c4605..a0b9b22 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -22,6 +22,12 @@ #: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 @@ -80,12 +86,12 @@ ;;; 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 *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 @@ -98,13 +104,13 @@ (if (not height) (set! height (get-screen-height))) (resize-screen width height))) (if fps - (set-frames-per-second 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))) + `((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)))) ;;; Main Loop @@ -129,12 +135,14 @@ (define (game-loop) ; (refresh-active-mobs) (set! loop-flag #t) - (init-video 640 480 32) + (init-video *width-screen* *height-screen* *bpp-screen* #:title *title* #:mode *mode* #:fps *frames-per-second*) (while loop-flag (init-frame-time) ; (check-connections) (process-events) - (cond ((not (quit?)) + (cond ((quit-signal?) + (quit-gacela)) + (else (clear-screen) (to-origin) ; (refresh-active-mobs) diff --git a/src/video.scm b/src/video.scm index f9e37f1..c30f333 100644 --- a/src/video.scm +++ b/src/video.scm @@ -36,7 +36,8 @@ set-2d-mode set-3d-mode 3d-mode? - set-frames-per-second + get-frames-per-second + set-frames-per-second! init-frame-time get-frame-time delay-frame @@ -67,7 +68,7 @@ (define screen #f) (define flags 0) -(define* (init-video width height bpp #:key (mode '2d) (title "")) +(define* (init-video width height bpp #:key (mode '2d) (title "") (fps 20)) (cond ((not screen) (SDL_Init SDL_INIT_VIDEO) (let ((info (SDL_GetVideoInfo))) @@ -77,6 +78,7 @@ (if (= (assoc-ref info 'blit_hw) 0) 0 SDL_HWACCEL))) (set! screen (SDL_SetVideoMode width height bpp flags)) (set-screen-title! title) + (set-frames-per-second! fps) (init-gl) (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))))) @@ -87,7 +89,7 @@ (surface-w screen)) (define (get-screen-bpp) - (surface-format-BytesPerPixel screen)) + (* (surface-format-BytesPerPixel screen) 8)) (define (set-screen-bpp! bpp) (cond (screen @@ -163,9 +165,14 @@ ;;; Frames per second (define time 0) +(define frames-per-second 20) (define time-per-frame 50) ;in ms -(define (set-frames-per-second fps) +(define (get-frames-per-second) + frames-per-second) + +(define (set-frames-per-second! fps) + (set! frames-per-second fps) (set! time-per-frame (/ 1000.0 fps))) (define (init-frame-time)