Cripes 2.0: More on sprite management

Published February 20, 2009
Advertisement
Okay, I thought I'd go into more depth on how I started managing my sprite resouurces. I started by picking out the bits of the Entity that correspond to the sprites, and encapsulating them in a new class, SpriteSet. These "bits" are the CHAR_INFO* vector and width/height fields. I then gave my Entity a SpriteSet pointer. (Along this entire process I'm leaving both versions in, so I can compile and test the code as I go. It also makes for easier refactoring.)

Next, I went to my EntityFactory and refactored it to work with SpriteSets instead of Entities. As I did this I realized I was working with the C++ "pimpl" idiom, and I thought it fit quite well. I think this is one of the times when pimpl is a "logical part of a good design", as EasilyConfused pointed out here (but I honestly don't know much about good design at this point!). I also renamed the EntityFactory to a SpriteManager, because it's more fitting the way I have it now. It's more or less unchanged, except that its Construct() member is now Get(), and returns a const SpriteSet pointer instead of an Entity. The Entity now takes a SpriteSet pointer in its constructor, which could be NULL if you don't have a sprite for it to draw. This setup means you can swap sets of sprites out for an entity, to change its appearence dramatically. For example, my Sniper guy might suddenly turn into a Ghost Snipe if I wanted him to!

During this process I cleaned my Entity class up quite nicely, and with a few tweaks I should be able to inherit subclasses like Missile. I think the best part of this pimpl design is that the sprite management, which should stay constant through all of my Entities, doesn't need to be rewritten every time I subclass a new Entity. I also moved my Corner# entities back into a single Corner with each corner sprite in the sprites file. After all this resource-mongering was done, I checked my MazeGen speed and it was down to fifteen ticks on average. That's shocking.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement