diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-04-29 12:21:49 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-05-01 08:01:39 -0400 |
commit | 4af0b4f579b03bdb9475c3d0e4c9ac7df29555d9 (patch) | |
tree | 00d2bf27be651300322a669b4bc2548c8f731244 | |
parent | 515ba05517c3fdf92aeb1e37c1ab5af320586604 (diff) |
Further reduce garbage generated by graphics state management.
I'm not totally sure if this does much good, but it seems there's at
least some savings by not using hash tables here.
-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))) |