• Advertisement
  • entries
    1212
  • comments
    1738
  • views
    1143713

happy code

Sign in to follow this  

60 views

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.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement