X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela.scm;h=26a1e9cf93bd1935d17d289c78e090f0f461b308;hb=4ae3375d30bc921cb397feef4024c84ef29f9b74;hp=f83e11737b920d59f2a64c670471edc8b4446a36;hpb=e2ab9ffff05259980c1b333030fcb074d665acc1;p=gacela.git diff --git a/src/gacela.scm b/src/gacela.scm index f83e117..26a1e9c 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -16,6 +16,7 @@ ;;; Default values for Gacela + (define *width-screen* 640) (define *height-screen* 480) (define *bpp-screen* 32) @@ -23,6 +24,7 @@ ;;; SDL Initialization Subsystem + (define init-sdl #f) (define quit-sdl #f) @@ -39,37 +41,39 @@ ;;; Video Subsystem + (define init-video-mode #f) +(define video-mode-on? #f) (define resize-screen #f) -(define apply-mode-change #f) (define quit-video-mode #f) -(let ((screen #f) (flags 0) (current-width *width-screen*) (current-height *height-screen*) (current-bpp *bpp-screen*)) +(let ((screen #f) (flags 0)) (set! init-video-mode - (lambda* (#:optional (width current-width) (height current-height) (bpp current-bpp)) + (lambda () (cond ((not screen) (init-sdl) - (SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER 1) - (set! flags (+ SDL_OPENGL SDL_GL_DOUBLEBUFFER SDL_HWPALETTE SDL_RESIZABLE - (if (= (assoc-ref (SDL_GetVideoInfo) 'hw_available) 0) SDL_SWSURFACE SDL_HWSURFACE) - (if (= (assoc-ref (SDL_GetVideoInfo) 'blit_hw) 0) 0 SDL_HWACCEL))) - (set! screen (SDL_SetVideoMode width height bpp flags)) - (init-GL) - (resize-screen-GL width height) - (set! current-width width) - (set! current-height height) - (set! current-bpp bpp)) + (let* ((props (get-game-properties)) + (width (assoc-ref props 'width)) (height (assoc-ref props 'height)) + (bpp (assoc-ref props 'bpp)) (title (assoc-ref props 'title)) + (mode (assoc-ref props 'mode)) + (info (SDL_GetVideoInfo))) + (SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER 1) + (set! flags (+ SDL_OPENGL SDL_GL_DOUBLEBUFFER SDL_HWPALETTE SDL_RESIZABLE + (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 "") + (init-gl) + (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))) (else #t)))) + (set! video-mode-on? + (lambda () (if screen #t #f))) + (set! resize-screen (lambda* (width height #:optional (bpp current-bpp)) (cond (screen (set! screen (SDL_SetVideoMode width height bpp flags)) - (resize-screen-GL width height))) - (set! current-width width) - (set! current-height height))) - - (set! apply-mode-change - (lambda () (resize-screen-GL current-width current-height))) + (resize-screen-GL width height))))) (set! quit-video-mode (lambda () (set! screen #f)))) @@ -88,10 +92,15 @@ (glDepthFunc GL_LEQUAL) (apply-mode-change)))) +(define (apply-mode-change) + (let* ((props (get-game-properties)) + (width (assoc-ref props 'width)) (height (assoc-ref props 'height))) + (resize-screen-GL width height))) + (define (3d-mode?) (eq? (assoc-ref (get-game-properties) 'mode) '3d)) -(define (init-GL) +(define (init-gl) (glShadeModel GL_SMOOTH) (glClearColor 0 0 0 0) ; (glClearDepth 1) @@ -148,6 +157,7 @@ ;;; Audio Subsystem + (define init-audio #f) (define quit-audio #f) @@ -164,6 +174,12 @@ ;;; GaCeLa Functions + +(define (init-gacela) + (init-sdl) + (init-gl)) + + (define set-frames-per-second #f) (define init-frame-time #f) (define delay-frame #f) @@ -190,16 +206,26 @@ (let ((ptitle "") (pwidth *width-screen*) (pheight *height-screen*) (pbpp *bpp-screen*) (pfps *frames-per-second*) (pmode '2d)) (set! set-game-properties (lambda* (#:key title width height bpp fps mode) - (init-video-mode) - (if title (begin (set! ptitle title) (SDL_WM_SetCaption title ""))) +; (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)) - (resize-screen pwidth pheight pbpp))) - (if fps (begin (set! pfps fps) (set-frames-per-second fps))) - (if mode (begin (set! pmode mode) (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))) + (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 @@ -208,7 +234,9 @@ (define-macro (run-game . code) - `(let ((game-function (lambda () (begin ,@code)))) + `(let ((game-function ,(if (null? code) + `(lambda () #f) + `(lambda () ,@code)))) (init-video-mode) (set-game-code game-function) (cond ((not (game-running?)) @@ -218,23 +246,23 @@ (define game-running? #f) (define set-game-code #f) -(let ((running #f) (game-code #f)) +(let ((running #f) (game-code #f) (mobs '())) (set! game-loop (lambda () + (set! mobs (get-active-mobs)) (set! running #t) -; (do () ((quit?)) - (do () (#f) + (quit? #f) + (do () ((quit?)) (init-frame-time) ; (check-connections) ; (eval-from-clients) -; (process-events) -; (cond ((not (quit?)) - (cond ((not #f) + (process-events) + (cond ((not (quit?)) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) -; (to-origin) -; (refresh-active-objects) + (to-origin) + (cond ((mobs-changed?) (set! mobs (get-active-mobs)))) (if (procedure? game-code) (game-code)) -; (render-objects) + (process-mobs mobs) (SDL_GL_SwapBuffers) (delay-frame)))) (set! running #f))) @@ -248,11 +276,10 @@ (set! game-code game-function)))) (define (quit-game) -; (free-all-resources) (quit-audio) (quit-video-mode) ; (quit-all-mobs) ; (kill-all-objects) -; (clear-events) -; (quit-events) +; (clear-events) + (quit-events) (quit-sdl))