X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela.lisp;h=6ad199f314623426210e823ef26e4555b20a1391;hb=d672794dd75f5607aa8b60d5b67474887cd6ae73;hp=45df43c9891388c4eb2a905a7474066d03c49eeb;hpb=870f146b156daf8910c0ee549df1bc47d509169e;p=gacela.git diff --git a/gacela.lisp b/gacela.lisp index 45df43c..6ad199f 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -156,7 +156,7 @@ ;;; Resources Manager -(defstruct resource plist free-function time) +(defstruct resource plist constructor destructor time) (defun make-resource-texture (&key filename min-filter mag-filter) `(:type texture :filename ,filename :min-filter ,min-filter :mag-filter ,mag-filter)) @@ -166,11 +166,13 @@ (let ((resources-table (make-hash-table :test 'equal))) - (defun set-resource (key plist free-function &key static) + (defun set-resource (key plist constructor destructor &key static) (setf (gethash key resources-table) (make-resource :plist plist + :constructor constructor + :destructor destructor :free-function free-function - :time (if static -1 (SDL_GetTicks))))) + :time (if static t (SDL_GetTicks))))) (defun get-resource (key) (let ((resource (gethash key resources-table))) @@ -180,10 +182,12 @@ (setf (gethash key resources-table) resource))) (resource-plist resource))))) + (defun free-resource (key) + (funcall (resource-destructor (gethash key resources-table))) + (setf (resource-time (gethash key resources-table)) nil)) + (defun free-all-resources () - (maphash (lambda (key res) (funcall (resource-free-function res) (resource-address res))) - resources-table) - (clrhash resources-table))) + (maphash (lambda (key res) (free-resource key)) resources-table))) ;;; Connection with the GUI