diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2020-12-16 09:57:02 -0500 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2020-12-16 09:57:02 -0500 |
commit | 8c68d7c8aeae76231ffdd35a0dfcc8150e82c1b2 (patch) | |
tree | 19c1df619394755c9ba9075d3c295f191f16a37f | |
parent | 656b2b626f7acf75c27466d4ec7f6e34e8b1847a (diff) |
asset: Purge old asset object when redefining it.
-rw-r--r-- | starling/asset.scm | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/starling/asset.scm b/starling/asset.scm index 3a9b6bf..c1a05a1 100644 --- a/starling/asset.scm +++ b/starling/asset.scm @@ -47,11 +47,11 @@ ;; class slots for asset cache and live reloading (inotify #:allocation #:class #:init-form #f) ;; file-name -> assets mapping - (asset-file-map #:allocation #:class #:init-form (make-hash-table)) + (asset-file-map #:allocation #:class #:init-thunk make-hash-table) ;; args -> artifact mapping - (artifact-cache #:allocation #:class #:init-form (make-weak-value-hash-table)) + (artifact-cache #:allocation #:class #:init-thunk make-weak-value-hash-table) ;; asset -> artifact mapping - (asset-artifact-map #:allocation #:class #:init-form (make-weak-key-hash-table)) + (asset-artifact-map #:allocation #:class #:init-thunk make-weak-key-hash-table) (watches #:allocation #:class #:init-form '()) ;; instance slots (file-name #:getter file-name #:init-keyword #:file-name) @@ -80,6 +80,9 @@ wt)))) (hash-set! sub-table asset asset))) +(define-method (asset-purge (asset <asset>)) + (hash-remove! (hash-ref (asset-file-map) (file-name asset)) asset)) + (define (asset-inotify) (class-slot-ref <asset> 'inotify)) @@ -196,13 +199,10 @@ (define-syntax-rule (define-asset name (loader file-name loader-args ...)) (define name - (make <asset> - #:file-name file-name - #:loader loader - #:loader-args (list loader-args ...)))) - -;; Convenience procedure for loading tilesets -(define* (load-tile-atlas file-name tile-width tile-height - #:key (margin 0) (spacing 0)) - (split-texture (load-image file-name) tile-width tile-height - #:margin margin #:spacing spacing)) + (begin + (when (and (defined? 'name) (is-a? name <asset>)) + (asset-purge name)) + (make <asset> + #:file-name file-name + #:loader loader + #:loader-args (list loader-args ...))))) |