X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela.lisp;h=140f0edbcdbd5dcccbb337261786f023e9a7c648;hb=6b5631c92ca29a80af99d228b3fe346c5b5e8eee;hp=b7ad4e3d04214f56fc2ae62a51d70de5cb1adf4a;hpb=b56cc2e7d421a067fbdcd3a542908fe0617352b8;p=gacela.git diff --git a/gacela.lisp b/gacela.lisp index b7ad4e3..140f0ed 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -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,24 +322,32 @@ (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))) +(let (time (time-per-frame (/ 1000.0 *frames-per-second*))) + (defun set-frames-per-second (fps) + (setq time-per-frame (/ 1000.0 fps))) + + (defun init-frame-time () + (setq time (SDL_GetTicks))) + + (defun delay-frame () + (let ((frame-time (- (SDL_GetTicks) time))) + (cond ((< frame-time time-per-frame) + (SDL_Delay (- time-per-frame frame-time))))))) + (defmacro run-game (title &body code) `(progn (init-video-mode) (SDL_WM_SetCaption ,title "") + (init-frame-time) (process-events) (do () ((quit?)) - (start-gacela-timer) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (glLoadIdentity) ,@code (SDL_GL_SwapBuffers) - (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))))) + (delay-frame) + (init-frame-time) (process-events) (setq running nil))))