From 8c68d7c8aeae76231ffdd35a0dfcc8150e82c1b2 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 16 Dec 2020 09:57:02 -0500 Subject: asset: Purge old asset object when redefining it. --- starling/asset.scm | 26 +++++++++++++------------- 1 file 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 )) + (hash-remove! (hash-ref (asset-file-map) (file-name asset)) asset)) + (define (asset-inotify) (class-slot-ref 'inotify)) @@ -196,13 +199,10 @@ (define-syntax-rule (define-asset name (loader file-name loader-args ...)) (define name - (make - #: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-purge name)) + (make + #:file-name file-name + #:loader loader + #:loader-args (list loader-args ...))))) -- cgit v1.2.3