quit-gacela
game-loop
game-running?
- set-game-code)
- #:export-syntax (game)
+ set-game-code
+ show-mob-hash
+ hide-mob-hash
+ hide-all-mobs
+ get-mob-function-name)
+ #:export-syntax (game
+ show-mob
+ hide-mob
+ the-mob
+ define-mob-function
+ define-mob
+ lambda-mob)
#:re-export (get-current-color
set-current-color
with-color
add-light
set-camera
camera-look
- render-text))
+ render-text
+ get-frame-time))
;;; Resources Cache
(set! loop-flag #f))
(define (game-loop)
-; (refresh-active-mobs)
+ (refresh-active-mobs)
(set! loop-flag #t)
(init-video *width-screen* *height-screen* *bpp-screen* #:title *title* #:mode *mode* #:fps *frames-per-second*)
(while loop-flag
(else
(clear-screen)
(to-origin)
-; (refresh-active-mobs)
+ (refresh-active-mobs)
(if (procedure? game-code)
(catch #t
(lambda () (game-code))
(lambda (key . args) #f)))
-; (run-mobs)
+ (run-mobs)
(flip-screen)
(delay-frame))))
(quit-video))
(define mobs-table (make-hash-table))
(define active-mobs '())
-(define changed #f))
+(define mobs-changed #f)
(define (show-mob-hash mob)
(hash-set! mobs-table (mob 'get-mob-id) mob)
- (set! changed #t))
+ (set! mobs-changed #t))
(define (hide-mob-hash mob-id)
(hash-remove! mobs-table mob-id)
- (set! changed #t))
+ (set! mobs-changed #t))
(define (refresh-active-mobs)
- (cond (changed
- (set! changed #f)
+ (cond (mobs-changed
+ (set! mobs-changed #f)
(set! active-mobs (hash-map->list (lambda (k v) v) mobs-table)))))
(define (get-active-mobs)
active-mobs)
(define (hide-all-mobs)
- (set! changed #t)
+ (set! mobs-changed #t)
(hash-clear! mobs-table))
(define (mobs-changed?)
- changed)
+ mobs-changed)
(define-macro (show-mob mob)
(define* (run-mobs #:optional (mobs (get-active-mobs)))
(for-each
(lambda (m)
- (glPushMatrix)
- (m)
- (glPopMatrix))
+ (glmatrix-block (m)))
mobs))
;;; Making mobs
-(define-macro (define-mob mob-head . body)
- (let ((name (car mob-head)) (attr (cdr mob-head)))
- `(define ,(string->symbol (string-concatenate (list "make-" (symbol->string name))))
- (lambda* ,(if (null? attr) '() `(#:key ,@attr))
- (the-mob ',name () ,attr ,@body)))))
+(define mob-functions (make-hash-table))
+
+(define (get-mob-function-name mob-name)
+ (let ((name (hash-ref mob-functions mob-name)))
+ (cond ((not name)
+ (set! name (gensym))
+ (hash-set! mob-functions mob-name name)))
+ name))
-(define-macro (the-mob type attr publish . body)
+(define-macro (the-mob type attr publish fun-name)
(let ((mob-id-symbol (gensym))
(type-symbol (gensym))
(time-symbol (gensym))
,data-symbol)
(else
(save-data)
- (catch #t
- (lambda () ,@body)
- (lambda (key . args) #f))))))))
+ (,fun-name 123)))))))
+
+(define-macro (define-mob-function head . body)
+ (let ((fun-name (car head)) (attr (map (lambda (a) (if (list? a) a (list a #f))) (cdr head)))
+ (data-symbol (gensym))
+ (body-fun
+ `(catch #t
+ (lambda* () ,@body)
+ (lambda (key . args) #f))))
+ `(define (,fun-name ,data-symbol)
+ (let ,attr
+ ,@(map
+ (lambda (a)
+ `(let ((val (assoc-ref ,data-symbol ',(car a))))
+ (cond (val (set! ,(car a) val)))))
+ attr)
+ ,body-fun
+ (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr))))))
+
+(define-macro (define-mob mob-head . body)
+ (let* ((name (car mob-head)) (attr (cdr mob-head))
+ (fun-name (get-mob-function-name name)))
+ `(begin
+ (define-mob-function ,(cons fun-name attr) ,@body)
+ (define ,(string->symbol (string-concatenate (list "make-" (symbol->string name))))
+ (lambda* ,(if (null? attr) '() `(#:key ,@attr))
+ (the-mob ',name () ,attr ,fun-name))))))
(define-macro (lambda-mob attr . body)
- `(the-mob 'undefined ,attr '() ,@body))
+ (let ((fun-name (gensym)))
+ `(begin
+ (define-mob-function ,(cons fun-name attr) ,@body)
+ (the-mob 'undefined ,attr '() ,fun-name))))
;;; Collisions