Saturday, March 18, 2006

Nearly playable...

Managed to find some time for some more fiddling. I've made the board display a bit prettier and it detects mouse presses and updates it all. It's dog slow at the moment though - is actually unplayable unless I compile it. Guess it's time to learn about profiling and optimising in lisp.

A couple of useful macros came out of it:

  • with-board-geometry sets up an environment where a bunch of useful variables are defined - cell-width, total-width, total board area, etc. So the mouse click detection and board drawing code both use this.
  • do-all-cells iterates over all the cells in the board and evaluates the given form on them.
  • do-surrounding-cells iterates over all the cells surrounding a given cell
  • do-steps is a simple wrapper around do that increments a given variable by a certain amount for a given number of times. This is used when drawing the board.
So it is nice to have code that looks like this:

(do-all-cells (ix iy board)
(update-cell-visibility board ix iy))

(defun add-counts-for-mine (board mine-x mine-y)
"Increment the mine counts for all cells surrounding mine-x mine-y"
(let ((cells (board-cells board)))
(do-surrounding-cells (ix iy board mine-x mine-y)
(when (cell-mine-count (aref cells ix iy))
(incf (cell-mine-count (aref cells ix iy)))))))

Sunday, March 12, 2006

cl-alleg on Sourceforge

I've set up a sourceforge project for hosting the Allegro/CFFI stuff:

Saturday, March 04, 2006

Taking shape

I started getting some of the stuff from Allegro's test.c going but very quickly got bored of that so I've started some actual work on the game itself.

There's a main loop going that attempts to run an update function 60 times a second and render the screen as often as it can. (I'm not convinced my version is working quite how I expect it to though!) I've got a very basic 'button' class that monitors the mouse and works like a button in a GUI. There's also the simple first-pass at the game logic - storing a minesweeper grid and calculating the number of neighbouring mines and that stuff.

Something that struck me while writing this is just how natural it feels to work with lexical scoping. I didn't really think about the fact that I was passing closures to an 'onclick' style function in my button object - it just turned out that way after I wrote it the first way I thought of. Very nice.

I'm also looking into setting up somewhere to host the source for the allegro / cffi stuff.