From 357aa6f62c04d59385ac4e44a5303d0825aa81ba Mon Sep 17 00:00:00 2001 From: jsancho Date: Tue, 1 Sep 2009 15:49:13 +0000 Subject: [PATCH] --- gacela.lisp | 11 ++++++++--- gacela_tetris.lisp | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/gacela.lisp b/gacela.lisp index aea2df6..4dc430a 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -22,7 +22,8 @@ (defvar *height-screen* 480) (defvar *bpp-screen* 32) (defvar *title-screen* "Happy Hacking!!") -(defvar *gacela-freq* 30) +(defvar *frames-per-second* 30) +;(defvar *gacela-freq* 100) (defvar *transparent-color* '(:red 0 :green 0 :blue 0)) (defvar *background-color* '(:red 0 :green 0 :blue 0)) @@ -349,16 +350,20 @@ (run-com running))))))) (defmacro run-game (title &body code) - `(progn + `(let ((fpstemp (make-timer))) (init-video-mode) (SDL_WM_SetCaption ,title "") (process-events) (do () ((quit?)) + (start-timer fpstemp) (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-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*))) (process-events) (setq running nil)))) diff --git a/gacela_tetris.lisp b/gacela_tetris.lisp index 07a4755..6a0242f 100644 --- a/gacela_tetris.lisp +++ b/gacela_tetris.lisp @@ -100,7 +100,7 @@ (let ((tetramine (random-tetramine)) (x 6) (y 0) (next (random-tetramine)) (timer (make-timer)) - (grid (make-list 20 :initial-element (make-list 14))) ;320x460 + (grid (make-list 20 :initial-element (make-list 14))) (background (draw-image-function "fondo_tetris.png"))) (defun tetramine () (cond ((eq (timer-state timer) 'stopped) (start-timer timer))) @@ -127,10 +127,17 @@ (setq next (random-tetramine))) (t (incf y) (start-timer timer))))) - (funcall background) - (translate -288 218) - (draw-grid (join-grids tetramine grid x y)) - (translate 440 440) - (draw-grid next))) - -(run-game "Gacela Tetris" (tetramine)) +; (draw-square :size 200))) + (funcall background))) +; (translate -288 218) +; (draw-grid (join-grids tetramine grid x y)) +; (translate 440 440) +; (draw-grid next))) + +(let ((frame 0.0) (fps (make-timer)) (update (make-timer))) + (start-timer update) + (start-timer fps) + (run-game "Gacela Tetris" + (tetramine) + (incf frame) + (cond ((> (get-time update) 1000) (print (/ frame (/ (get-time fps) 1000.0))) (start-timer update))))) -- 2.39.5