X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela.lisp;h=9663a82d1028b8a9feaa8594a187cf05c46a5e09;hb=02026932e3ecf2ff041a8a0389cf6c077df3e49d;hp=4dc430aef63b9f913855670747173f63f45bb6b1;hpb=357aa6f62c04d59385ac4e44a5303d0825aa81ba;p=gacela.git diff --git a/gacela.lisp b/gacela.lisp index 4dc430a..9663a82 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -22,8 +22,7 @@ (defvar *height-screen* 480) (defvar *bpp-screen* 32) (defvar *title-screen* "Happy Hacking!!") -(defvar *frames-per-second* 30) -;(defvar *gacela-freq* 100) +(defvar *frames-per-second* 20) (defvar *transparent-color* '(:red 0 :green 0 :blue 0)) (defvar *background-color* '(:red 0 :green 0 :blue 0)) @@ -99,6 +98,14 @@ (glHint GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST) t) +(defmacro progn-textures (&body code) + `(let (values) + (init-video-mode) + (glEnable GL_TEXTURE_2D) + (setq values (multiple-value-list (progn ,@code))) + (glDisable GL_TEXTURE_2D) + (apply #'values values))) + (defun init-textures () (init-video-mode) (glEnable GL_TEXTURE_2D)) @@ -119,6 +126,14 @@ (glLoadIdentity) t)) +(let ((current-color '(1 1 1 1))) + (defun get-current-color () + current-color) + + (defun set-current-color (red green blue &optional (alpha 1)) + (setq current-color (list red green blue alpha)) + (glColor4f red green blue alpha))) + (defun copy-surface (source) (cond ((surface-p source) (let ((new-surface @@ -185,32 +200,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) @@ -323,18 +312,6 @@ ;;; GaCeLa Functions -;(defun game-loop (code) -; (process-events) -; (cond ((quit?) nil) -; (t -; (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) -; (glLoadIdentity) -; (translate 0 0 *zoom*) -; (funcall code) -; (SDL_GL_SwapBuffers) -; (SDL_Delay (- *gacela-freq* (rem (SDL_GetTicks) *gacela-freq*))) -; (game-loop code)))) - (let (commands) (defun prog-command (command) (setq commands (cons command commands))) @@ -349,37 +326,35 @@ (eval (read-from-string (concatenate 'string "(progn " (car comlst) ")"))))))) (run-com running))))))) +(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) - `(let ((fpstemp (make-timer))) + `(progn (init-video-mode) (SDL_WM_SetCaption ,title "") + (init-frame-time) (process-events) (do () ((quit?)) - (start-timer fpstemp) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (glLoadIdentity) ,@code (SDL_GL_SwapBuffers) - (let ((frame-time (get-time fpstemp)) (time-per-frame (/ 1000.0 *frames-per-second*))) - (cond ((< frame-time time-per-frame) - (SDL_Delay (- time-per-frame frame-time))))) -; (SDL_Delay (- *gacela-freq* (rem (SDL_GetTicks) *gacela-freq*))) + (delay-frame) + (init-frame-time) (process-events) (setq running nil)))) -;(defun run-game () -; (init-video-mode) -; (SDL_WM_SetCaption *title-screen* "") -; (refresh-active-procs) -; (enjoy!) -; (do () ((quit?)) -; (process-events) -; (logic-procs) -; (motion-procs) -; (refresh-active-procs) -; (refresh-screen) -; (SDL_Delay (- *gacela-freq* (rem (SDL_GetTicks) *gacela-freq*))))) - (defun quit-game () ; (free-all-resources) ; (quit-audio)