Good morning!
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.
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:
This feels like a hack that probably has pitfalls I'm not considering. Is there a more conventional way to locate external files?
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.
(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))
This routine works fine as long as the images are stored in the current path, but if I just start SLIME and eval, I get a path error. To get around that problem, I added this to the top of my source file initially:
(sb-posix:chdir #P"/home/jakykong/lisp/mouse")
This works, but it's obviously not going to allow the code to move around. If I'm using SLIME, it's doubly annoying since starting SLIME from the current directory is inconvenient.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:
(defun get-system-path (system)
(asdf:component-pathname (asdf:find-system system)))
Which returns a path like #P"/home/jakykong/quicklisp/local-projects/name/"; I can either change directory there as before or use #'merge-pathnames when loading the image.This feels like a hack that probably has pitfalls I'm not considering. Is there a more conventional way to locate external files?