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:

    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.


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.

  1. #1 by gothboyuk on January 23, 2019 - 12:16 am

    Vegemite looks, feels & (probably) tastes like earwax.

  2. #2 by ququasar on January 23, 2019 - 11:19 am

    What is wrong with your ears that your earwax is the same colour as crude oil?

  3. #3 by A. L. on February 24, 2019 - 8:19 am

    Disembodied skeletons could be useful as fossils of extinct species in the cladogram…

  4. #4 by self growth on March 14, 2019 - 2:35 pm

    I have been exploring for a bit for any high quality articles or blog posts on this sort of
    house . Exploring in Yahoo I ultimately stumbled upon this site.
    Reading this info So i’m happy to express that I have a very good uncanny feeling I came upon just what I needed.
    I so much indisputably will make sure to don?t
    forget this web site and provides it a look on a relentless

Leave a Reply

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

You are commenting using your 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: