X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela.lisp;h=9a7e89b309a770da2f8bf0d4eaa6fb410d2b2462;hb=bb90258fa03aa649956bffcfc9b62ba35d3ec0bb;hp=efdeb60e95d68f58d411ad69e086fe967a25ac70;hpb=5293bb782051f9bfea3802151acb0c8644c98104;p=gacela.git diff --git a/gacela.lisp b/gacela.lisp index efdeb60..9a7e89b 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -22,7 +22,7 @@ (defvar *height-screen* 480) (defvar *bpp-screen* 32) (defvar *title-screen* "Happy Hacking!!") -(defvar *gacela-freq* 30) +(defvar *frames-per-second* 20) (defvar *transparent-color* '(:red 0 :green 0 :blue 0)) (defvar *background-color* '(:red 0 :green 0 :blue 0)) @@ -88,10 +88,10 @@ (defun init-GL () + (2d-mode) (glShadeModel GL_SMOOTH) (glClearColor 0 0 0 0) (glClearDepth 1) - (glDisable GL_DEPTH_TEST) (glDepthFunc GL_LEQUAL) ; (glEnable GL_BLEND) ; (glBlendFunc GL_SRC_ALPHA GL_ONE) @@ -108,12 +108,12 @@ (defun resize-screen-GL (width height) (let ((ratio (if (= height 0) width (/ width height)))) - (glViewPort 0 0 width height) +; (glViewPort 0 0 width height) (glMatrixMode GL_PROJECTION) (glLoadIdentity) (let* ((w (/ width 2)) (-w (neg w)) (h (/ height 2)) (-h (neg h))) (glOrtho -w w -h h 0 1)) - (gluPerspective 45 ratio 0.1 100) +; (gluPerspective 45 ratio 0.1 100) (glMatrixMode GL_MODELVIEW) (glLoadIdentity) t)) @@ -184,32 +184,6 @@ (flip)) -(defun filled-circle (radius &optional (color '(:red 255 :green 255 :blue 255))) - (init-video-mode) - (let ((new-surface (create-surface (1+ (* radius 2)) (1+ (* radius 2))))) - (sge_FilledCircle (surface-address new-surface) - radius radius radius - (getf color :red) - (getf color :green) - (getf color :blue)) - (setf (surface-shape new-surface) - `((,radius ,radius) ,radius)) - new-surface)) - - -(defun filled-rect (width height &optional (color '(:red 255 :green 255 :blue 255))) - (init-video-mode) - (let ((new-surface (create-surface width height))) - (sge_FilledRect (surface-address new-surface) - 0 0 width height - (getf color :red) - (getf color :green) - (getf color :blue)) - (setf (surface-shape new-surface) - (make-rectangle 0 0 width height)) - new-surface)) - - ;;; TTF Subsystem (defstruct font address) @@ -348,17 +322,24 @@ (eval (read-from-string (concatenate 'string "(progn " (car comlst) ")"))))))) (run-com running))))))) +(let ((gacela-timer (make-timer))) + (defun start-gacela-timer () (start-timer gacela-timer)) + (defun get-gacela-time () (get-time gacela-timer))) + (defmacro run-game (title &body code) `(progn (init-video-mode) (SDL_WM_SetCaption ,title "") (process-events) (do () ((quit?)) + (start-gacela-timer) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (glLoadIdentity) ,@code (SDL_GL_SwapBuffers) - (SDL_Delay (- *gacela-freq* (rem (SDL_GetTicks) *gacela-freq*))) + (let ((frame-time (get-gacela-time)) (time-per-frame (/ 1000.0 *frames-per-second*))) + (cond ((< frame-time time-per-frame) + (SDL_Delay (- time-per-frame frame-time))))) (process-events) (setq running nil))))