May 13, 2023 - Entity Component System as a programming model

Pandamonium is, perhaps unnecessarily, implemented using an Entity Component System architecture.

(Caveat: I have only read very surface-level things about Entity Component Systems, my approach has diverged over time, and I suspect it is abnormal and deficient in a bunch of ways. For now, I suspect those ways are ways I don’t care about)

What does that mean, and why? Well, the best way to illustrate that is by example. Much of my game logic is implemented using functions like this:

fn translate(entities: &mut Entities, dt: &Duration) {
    entities.apply(|(Velocity(dx, dy), Position(x, y))| Position(x + (dx * dt.as_secs_f64()), y + (dy * dt.as_secs_f64())));
}

What’s going on here? Very simply: we’re applying a function to our entities, that takes a velocity and a position, and returns a new position.

Feb 24, 2023 - It's Just Intonation

Following on from my last post, I was starting to get annoyed by the way I’d chosen to represent note frequencies. For example:

Tempo::new(2, 250).using(&BELL, 3).play(1.0, 0.25, B, 4).play(1.25, 1.0, E, 4).build()

I’d been represeting B4 as two separate values: a frequency and an octave. That permitted me to just define each letter-note once, and rely on math rather than specification to make everything work. However, when I start to get to solutions like this:

// r is root, r_o root octave, a is the first walk-up note, b is the second
fn bass_bar((r, r_o): (f32, i32), (a, a_o): (f32, i32), (b, b_o): (f32, i32)) 
        -> Vec<(f32, f32, f32, i32)> {
    vec![(1.0, 1.0, r, r_o), (2.5, 1.0, r, r_o), (4.0, 0.5, a, a_o), (4.5, 0.5, b, b_o)]
}
Tempo::new(4, 120).using(&BASS, 0)
    .bar(1).phrase(bass_bar((A, 1), (E, 0), (Gs, 0)))
    .bar(2).phrase(bass_bar((A, 1), (A, 1), (Gs, 0)))
    .build();

Having to provide tuples and destruct them to get their constituent parts… I’m now thinking I want to change my approach. I don’t particularly mind having 88 constants - maybe even upwards of that! - if they’re simply defined and simple to use: the relative importance of the use-cases vs the declaration-site has changed.

Feb 24, 2023 - Composing Music

Currently, I’m trying to implement music for the game.

Well, I already have music: I’ve implemented a simple 4-channel audio device, capable of playing sine, triangle, pulse, and noise waves, and I’ve got a variety of tunes already built into the game. This is one of the best ones:

image tooltip here