Refactoring BodyPlan

I’m don’t have too much to say about my multithreading work just yet (aside from “it’s coming along, and early results are promising”), so instead let’s talk about a long-overdue task I undertook at the start of work for 0.12.0. It’s not directly related to multithreading, but it’s related to things that are related to multithreading, so it’ll provide a foundation for future blog posts.

Creature in Species are built out of a series of sub-objects, the biggest of which are the following five:

Creature
{
    Genome //Contains Genetic Stats
    BodyPlan //Contains Skeletal Physics and Drawable Body Parts
    Phenotype //Contains Derived-At-Birth Stats (things like speed, attack damage, etc)
    Specimen //Contains always-up-to-date State Information (Health/Food/Etc)
    Brain //Contains the creatures AI State
}

One of these things is not like the others, one of these things just doesn’t belong…

… and that thing is BodyPlan. I mean, obviously. It’s right there in the title of the blog post. I’m not exactly being coy about it here.

BodyPlan handles two responsibilities: generating and applying the skeletal physics, and drawing the creature’s body parts to the screen. The reason it was originally built this way is because these things are superficially related: I take the skeleton shape from the drawable art assets, and the art assets are rotated by droop and balance effects when I draw the creature.

But let’s embarrass ourselves trying to justify it. This is bad. This is really bad. To be gratuitously technical for a moment: under the SOLID principles of Object Oriented Programming, this is a severe violation of the first rule: the Single Responsibility Principle.

The Single Responsibility Principle dictates… well, exactly what you’d expect it to dictate based on that name. A class should have one responsibility. BodyPlan has two. Ergo propter hoc, Quasar is a dumbass.

This is important because those rules exist for reason: by violating the SRP, I’ve coupled drawing and animating limbs, heads and other body parts to the skeletal physics. Let’s say I wanted to draw heads or tails separate from a creature, as part of a creature editor or mutation map viewer: I can’t do that. At least, not without also creating some sort of temporary skeletal data for them.

The same also applies in reverse: I need to provide drawable assets like the body cover texture and colour to make the skeleton. This is less of an issue because there’s not too many places where I’m going to want a disembodied skeleton walking around (they fall apart too easily to use as soldiers and they’re too dumb to be servants), but still. It’s the principle of the thing. I might not want disembodied skeletons, but I’d object if someone tried to take away my right to have disembodied skeletons.

So this needed fixing and since I was already waist deep in refactoring everything else for multithreading, I figured I might as well address it. I’ve been splitting “BodyPlan” into “DrawableBodyPlan” and “SkeletalBodyPlan” (which I’ll probably rename simply to “Body” and “Skeleton” for the sake of being concise).

This is the only change I’ve made for 0.12.0 not directly related to multithreading: everything else from here on out will be in service of smearing the game across multiple cores like some sort of weird inedible Vegemite.

Cheers,
Quasar



My plan was to make a joke about Vegemite, but I’m like 70% sure that would be grounds for having my Australian citizenship revoked.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: