diff options
-rw-r--r-- | chickadee/graphics/engine.scm | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/chickadee/graphics/engine.scm b/chickadee/graphics/engine.scm index ed0650e..804e705 100644 --- a/chickadee/graphics/engine.scm +++ b/chickadee/graphics/engine.scm @@ -186,10 +186,15 @@ (define (install-graphics-state engine spec) (let ((binder (graphics-state-spec-binder spec)) - (default (graphics-state-spec-default spec))) - (hashv-set! (graphics-engine-states engine) - (graphics-state-spec-id spec) - (make-graphics-state binder default)))) + (default (graphics-state-spec-default spec)) + (states (graphics-engine-states engine)) + (id (graphics-state-spec-id spec))) + (unless (> (array-list-size states) id) + (let loop ((i (array-list-size states))) + (unless (> i id) + (array-list-push! states #f) + (loop (+ i 1))))) + (array-list-set! states id (make-graphics-state binder default)))) (define (install-graphics-variable engine var) (hashq-set! (graphics-engine-variables engine) @@ -212,7 +217,7 @@ (max-texture-size) (make-identity-matrix4) (make-guardian) - (make-hash-table) + (make-array-list) (make-hash-table)))) ;; Variable initialization must be delayed until after engine ;; creation because variable initializers may modify graphics @@ -257,26 +262,22 @@ (define* (set-graphics-engine-projection-matrix! matrix #:optional (engine (current-graphics-engine))) (%set-graphics-engine-projection-matrix! engine matrix)) +(define (graphics-engine-lookup-state engine spec) + (array-list-ref (graphics-engine-states engine) + (graphics-state-spec-id spec))) + (define* (graphics-engine-state-ref spec #:optional (engine (current-graphics-engine))) - (let ((state (hashv-ref (graphics-engine-states engine) - (graphics-state-spec-id spec)))) + (let ((state (graphics-engine-lookup-state engine spec))) (and state (graphics-state-ref state)))) (define* (graphics-engine-state-push! spec value #:optional (engine (current-graphics-engine))) - (if (graphics-state-spec? spec) - (let ((id (graphics-state-spec-id spec))) - (graphics-state-push! (hashv-ref (graphics-engine-states engine) id) - value)) - (error "not a graphics state specification" spec))) + (graphics-state-push! (graphics-engine-lookup-state engine spec) value)) (define* (graphics-engine-state-pop! spec #:optional (engine (current-graphics-engine))) - (if (graphics-state-spec? spec) - (let ((id (graphics-state-spec-id spec))) - (graphics-state-pop! (hashv-ref (graphics-engine-states engine) id))) - (error "not a graphics state specification" spec))) + (graphics-state-pop! (graphics-engine-lookup-state engine spec))) (define* (graphics-variable-ref var #:optional (engine (current-graphics-engine))) @@ -287,9 +288,9 @@ (hashq-set! (graphics-engine-variables engine) var value)) (define* (graphics-engine-commit! #:optional (engine (current-graphics-engine))) - (hash-for-each (lambda (id state) - (graphics-state-bind-maybe state)) - (graphics-engine-states engine))) + (array-list-for-each (lambda (id state) + (graphics-state-bind-maybe state)) + (graphics-engine-states engine))) (define* (graphics-engine-guard! obj #:optional (engine (current-graphics-engine))) |