Color API Fussery

(November 23, 2007 @ 01:45 PM)

As mentioned before, I pushed back Color from 2.1.0 to 2.2.0 to get 2.1.0 released sooner. Also as mentioned, I’m trying out focusing on 1 core feature per release (with other smaller features on the side as available). So, that means the focus of 2.2.0 is going to be the new Color system.

So, what’s going to be in the new sytsem? It’s basically 2 parts:

  1. A variety of classes representing different color models: RGB, HSV, and HSL are planned for starters, since they are the most useful for games.
  2. An extensible table of commonly-used named colors (:red, :black, :yellow, :purple, etc.).

If I weren’t so fussy, this version would be a piece of cake. I’ve had at least 2 nearly-complete suites of color classes dropped in my lap in the past year, and there are lists of standard color names and their RGB values on Wikipedia.

But I _am_ fussy, especially when it comes to Rubygame’s API. So, I’m designing the API in a written description, without touching any code. I’ve learned from experience that this way yields pleasing results; I’ve been using it quite a bit in the Rubygame 3.0.0 development branch, designing the API before implementing it.

I’ve found that when you dive into the code before designing, the quirks and difficulties of the language/library you are using influence the result too much. When you don’t have the plan, you make compromises, quick and easy solutions at the expense of a clean API.

So, it’s back to the planning that I go.

Rubygame 2.1.0 released

(November 20, 2007 @ 10:12 AM)

Here’s the blurb I’ve been using:

Rubygame 2.1.0 adds a new module for music playback, new Sprite features, and plenty of other smaller additions and bug fixes.

Tarball and source gem are available now. Precompiled gems for various systems will be added as they become available.

Downloads

Release Notes/Changes

Quirky APIs

(November 16, 2007 @ 01:49 PM)

I don’t like quirky, idiosyncratic APIs. I really, really don’t like them. They’re harder to learn, more prone to bugs, and altogether not fun.

So naturally, I put a lot of effort into making Rubygame’s API as consistent as I can. Sometimes, though, I have the unfortunate task of trying to create a consistent Rubygame API on top of a quirky library, and things get tricky.

SDL_gfx was an example of this early in Rubygame’s development. Small things, like one function having a lowercase letter where all the others like it had upper case. Or one type of shape not having every drawing style that the others do.

Right now, though, it’s SDL_mixer and its weird little idiosyncracies that I’m wrestling with:

  1. For Mix_PlayChannel, passing 0 for the number of loops means to play the sound 1 time (repeat 0 times), and passing 1 means to play it twice (repeat 1 time). But for Mix_PlayMusic, passing 0 means play the music 0 times, and passing 1 means to play it once!

  2. Worse, you can’t just blindly offset the loops variable by 1 to make them consistent, because in both cases, passing -1 means to repeat forever. So, you have to test if it’s -1 before offsetting.

  3. Mix_SetMusicPosition does different things depending on whether you’re playing an Ogg Vorbis, MP3, or MOD file. (And if you were hoping to use this function with the other music formats SDL_mixer can load… well, tough break.)

  4. Mix_RewindMusic apparently doesn’t work for WAV files at all. (Don’t ask me why not, I have no clue.)

  5. Mix_ResumeMusic is safe to use even on music which was stopped or is already playing, but the docs for Mix_PauseMusic suggest that function shouldn’t be used on music which is stopped or already paused.

And the thing about library APIs is that you can’t change them later. Not without breaking the applications that use that library, that is. So I don’t expect SDL_mixer to get better soon.

But, it’s my task to turn the quirky API I’m given into something consistent… even elegant, if I can manage it.

Prepping Rubygame 2.1.0

(November 15, 2007 @ 09:04 AM)

I’m looking over everything and making sure it’s ready to release as Rubygame 2.1.0. Here’s a quick look at the major changes:

  • Added Mixer::Music module (patches by Johan Berntsson and Bjorn De Meyer)
  • Added Sprite#undraw (patch by Daniel Neis Araujo)
  • Added depth sorting for Sprites
  • Lots of bug fixes, improvements, and small features

The coolest thing from my perspective, though, is that this is the first release of Rubygame whose new features almost entirely come from patches sent in by other people. That means that at least a couple people besides myself care about Rubygame, and that gives me warm fuzzy feelings inside.

Something that had been tentatively slated for this release, but didn’t make it, is the suite of Color classes. Quite simply, the code for them just isn’t there yet! Rather than delay this release, I’m making the Color classes the milestone for 2.2.0. I like the idea of having 1 major feature per release, so I think I’ll try that out for the next few releases.