Wednesday, January 9, 2013

Refactoring Textures and Animations

(Disregard what I said I'd be working on last, more advanced layering. I changed my mind.)

Code-design update here mostly, so if you aren't interested in programming or anything this might be boring.

My entity model was designed such that you could set either a texture (via a TextureID property) or an animation (via an AnimationID property). This worked, but was a mediocre design since it resulted in multiple occurrences of code that looked like this:


            if (entity.TextureID != 0)
            {
                //Do something here
            }
            else if (entity.AnimationID != 0)
            {
                //Do another thing here
            }


The missing abstraction here is that a Texture is simply an animation with one frame. So, I changed the data model so that all textures have a frame collection, with the normal case being a single frame, and then eliminated the Animation structure completely. Most of the work here was writing a migration utility which updated all existing data to fit this model, and then updating the Asset Editor program to handle these new structures. Here's what the texture editor portion of it looks like now--now there's two tabs on the texture editor, one for editing individual texture frames and one for previewing the animation.



Anyway, yeah, not the most exciting update in the world, but I'm trying to keep a fairly clean design and get these things right before actually creating levels, since I'm still at the stage that I can make major design changes with minimal impact.

No comments:

Post a Comment