happy code

Published June 12, 2000
Advertisement
I'm happy. My code's happy. Everyone's happy.

My new polyglot self-growing data-structure that I mentioned in my last entry is working nicely. One bug that took a while to track down was a one-off error that was causing the [] operator to return zero for the last item in the structure. After about an hour's worth of debugging, though, I found the culprit. It's always gratifying to see something work after making so many code-changes that it takes an entire day just to get your code to compile.

You're always asking yourself if this "improvement" is just a colossal waste of time.



Also implemented an improvement to my animation manager that I'd been meaning to do for years. I use a dirty-rectangle-based sprite-animation system, in which there's a rectangle that encircles anything that needs to be changed. When I call refresh(), it updates everything in the dirty rectangle.

One problem I had, though, was that my old games didn't have a method to place a piece of a sprite --you could only blit an entire sprite at a time. This required the refresh() function to loop through all sprites that were touching the dirty rectangle, followed by any sprites that were touching any dirty sprites, and so on. It worked, but often you ended up blitting a lot of sprites that weren't touching the dirty rectangle.

Anyway, my new stuff allows you to draw just part of a sprite if you want. That means that I can truly only update sprites that are in the dirty rectangle. If a sprite is hanging halfway outside of a dirty rectangle, it only updates the part that's inside the rectangle. Seems to have perked things up a bit. Also, it dropped the refresh() function from 50 lines and three loops to 10 lines and one loop.

[John performs the "I'm so efficient" dance]

There's still a lot of optimizing I can do on the routines that actually copy bits from one bitmap to another, though. Currently, I just loop and copy bytes (or half-bytes) from one buffer to another. Eventually, though, I hope to be smarter and use memcpy() to copy an entire scan-line at a time.

It'd be a nightmare to do on grayscale machines, though, as they're 4-bits-per-pixel. Seems like 4-BPP machines are going the way of the dodo, though, so it might not be an issue. Also, since I've got a mask associated with most of my sprites, I could conceivably be calling memcpy() several times per scanline. It's probably worth it, though.
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!
Advertisement