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