diff options
-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 ...))))) |