Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Stupid, Clever, or Both?

Name: Anonymous 2007-10-24 2:02

I'm doing some expert programming of a tile-based game in which tile classes have references to anonymous functions that return the proper image for that tile. I figure I might as well not duplicate these. Should I make these functions onymous or just have a picture function manager that lets me get at them easily? It would be dead simple to create onymous functions for them at runtime, but it makes me feel funny to do it.

Name: Anonymous 2007-10-24 12:34

>>4
Oh, I did that first.
(let ((pictures))
  (defun init-pics ()
    (setf pictures (make-hash-table)))
  (defun get-pic (image-name)
    (gethash image-name pictures))
  (defun load-pic (game-file image-name)
    (setf (gethash image-name pictures)
      (sdl-image:load (game-file game-file)))))

Trivial. (I should probably make this work with setf rather than having both get and load.) But each tile has a function (probably implemented in terms of get-pic) to return its proper image. The upshot of this system is that they can animate themselves with no outside code if I want. The functions don't know how to get the tile's state without a minor rewrite, but they can be swapped out easily, so this isn't really an issue.

The question is whether I should store these in a hash table or just give them names. It seems kind of silly to make a hash table for them when there's already a system for referring to functions by name. On the other hand, it seems strange to use the function system in this way.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List