(to-origin)
(refresh-active-mobs)
(run-mobs)
- (draw-meshes)
+ (run-extensions)
(flip-screen)
(delay-frame))))
(quit-video))
loop-flag)
+;;; Extensions to main loop
+
+(define extensions '())
+
+(define (add-extension! proc pri)
+ "Add an extension with a priority to the main loop"
+ (set! extensions
+ (sort (assoc-set! extensions proc pri)
+ (lambda (a b)
+ (< (cdr a) (cdr b))))))
+
+(define (remove-extension! proc)
+ "Remove an extension from the main loop"
+ (set! extensions
+ (assoc-remove! extensions proc)))
+
+(define (run-extensions)
+ (for-each (lambda (x) ((car x))) extensions))
+
+
;;; Game Properties
(define *title* "Gacela")
,@body))
-;;; Views Factory
-
-(define default-view (make-hash-table))
-
-(define* (draw-meshes #:optional (meshes (hash-map->list (lambda (k v) v) default-view)))
- (cond ((not (null? meshes))
- (catch #t
- (lambda () ((car meshes) 'draw))
- (lambda (key . args) #f))
- (draw-meshes (cdr meshes)))))
-
-
(module-map (lambda (sym var)
(if (not (eq? sym '%module-public-interface))
(module-export! (current-module) (list sym))))
#:use-module ((gacela gl) #:select (glPushMatrix glPopMatrix))
#:use-module (ice-9 optargs))
+
+(define default-view (make-hash-table))
+
+(define* (draw-meshes #:optional (meshes (hash-map->list (lambda (k v) v) default-view)))
+ (cond ((not (null? meshes))
+ (catch #t
+ (lambda () (mesh-draw (car meshes)))
+ (lambda (key . args) #f))
+ (draw-meshes (cdr meshes)))))
+
+(add-extension! draw-meshes 50)
+
(define-macro (define-view name content)
`(begin
(hash-set! active-views ',name (lambda () (video:glmatrix-block ,content)))
"property-set!"
(set! properties (assoc-set! properties prop-name value))))))))
-(define mesh-properties-set!
- (let ((f (record-accessor mesh-type 'properties-set!)))
- (lambda (mesh new-properties)
- ((f mesh) new-properties))))
+(define (mesh-draw mesh)
+ (((record-accessor mesh-type 'draw) mesh)))
+
+(define (mesh-inner-property mesh prop-name)
+ (((record-accessor mesh-type 'inner-property) mesh) prop-name))
+
+(define (mesh-properties mesh)
+ (((record-accessor mesh-type 'properties) mesh)))
+
+(define (mesh-properties-set! mesh new-properties)
+ (((record-accessor mesh-type 'properties-set!) mesh) new-properties))
(define* (show mesh #:optional (view default-view))
- (let ((id (mesh 'inner-property 'id)))
+ (let ((id (mesh-inner-property mesh 'id)))
(if (not (hash-ref view id))
(hash-set! view id mesh))))