(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))
(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))))
(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)))
(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)))))