(define-module (gacela gacela)
#:use-module (gacela events)
#:use-module (gacela video)
- #:use-module ((gacela video) #:renamer (symbol-prefix-proc 'video:))
#:use-module (gacela audio)
#:use-module (ice-9 optargs)
#:export (*title*
game-loop
gacela-script
game-running?
- set-game-code
show-mob-hash
hide-mob-hash
get-active-mobs
;;; Main Loop
(define loop-flag #f)
-(define game-code #f)
(define game-loop-thread #f)
(define-macro (run-in-game-loop proc)
(run-in-game-loop resize-screen)
(define-macro (game . code)
- `(let ((game-function ,(if (null? code)
- `(lambda () #f)
- `(lambda () ,@code))))
- (set-game-code game-function)
- (cond ((not (game-running?))
- (game-loop)))))
+ (if (null? code)
+ #f
+ `(call-with-new-thread (lambda () ,@code))))
(define (init-gacela)
(hide-all-mobs)
- (set-game-code (lambda () #f))
(cond ((not game-loop-thread)
- (set! game-loop-thread (call-with-new-thread (lambda () (game))))))
+ (set! game-loop-thread (call-with-new-thread (lambda () (cond ((not (game-running?)) (game-loop))))))))
(while (not loop-flag))
#t)
(define (quit-gacela)
(hide-all-mobs)
- (set-game-code (lambda () #f))
(set! game-loop-thread #f)
(set! loop-flag #f))
(clear-screen)
(to-origin)
(refresh-active-mobs)
- (if (procedure? game-code)
- (catch #t
- (lambda () (game-code))
- (lambda (key . args) #f)))
(run-mobs)
- (draw-bricks)
+ (draw-meshes)
(flip-screen)
(delay-frame))))
(quit-video))
(define (game-running?)
loop-flag)
-(define (set-game-code game-function)
- (set! game-code game-function))
-
;;; Game Properties
,@body))
-;;; Bricks Factory
-
-(define active-bricks '())
-
-(define* (draw-bricks #:optional (bricks active-bricks))
- (cond ((not (null? bricks))
- ((car bricks))
- (draw-bricks (cdr bricks)))))
-
-(define (show-brick brick)
- (set! active-bricks (cons brick active-bricks)))
-
-(define-macro (simple-brick brick-code)
- (let ((name (gensym)))
- `(begin
- (define (,name)
- ,brick-code)
- (show-brick ,name)
- ,name)))
+;;; Views Factory
+(define default-view (make-hash-table))
-;;; Primitive bricks
-
-(define (draw-square . args)
- (simple-brick (apply video:draw-square args)))
+(define* (draw-meshes #:optional (meshes (hash-map->list (lambda (k v) v) default-view)))
+ (cond ((not (null? meshes))
+ (catch #t
+ (lambda () (glmatrix-block ((car meshes))))
+ (lambda (key . args) #f))
+ (draw-meshes (cdr meshes)))))
(module-map (lambda (sym var)