As in my last thread, I'm working on a small game using cl-sdl2. At this point I've got a playable demo and I'm working out a few kinks.
The biggest is loading images. I have a small routine that loads sprites from *.png files, and memoizes the resultant textures.
Code: Select all
(defvar *sprites* nil)
(defun load-sprite (sprite-type renderer)
(let* ((filename (concatenate 'string (symbol-name sprite-type) ".png"))
(sprite (getf *sprites* sprite-type)))
(unless sprite
(setf sprite (sdl2:create-texture-from-surface renderer
(sdl2-image:load-image filename))
(getf *sprites* sprite-type) sprite))
sprite))
Code: Select all
(sb-posix:chdir #P"/home/jakykong/lisp/mouse")
As a first pass at figuring out a better way to locate resources, I looked in the ASDF documentation to see if there's a way to find the source path for the current package, and the closest I could get is:
Code: Select all
(defun get-system-path (system)
(asdf:component-pathname (asdf:find-system system)))
This feels like a hack that probably has pitfalls I'm not considering. Is there a more conventional way to locate external files?