Monday 26 October 2009

I am finished with the building!

I am a naughty child :) I have allowed my weekend of coding to overflow into all of Monday. Good news is this little project is done now. Here's a little video of it in action:

Things that have happened:

  • Death sequence for trees and spiders. When they die, trees disappear segment by segment from the ground up because I thought it looked funny, and spiders go black and shrink... kinda like real spiders.
  • Rebirth! Tiny spiders appear and start running around, scaling back up to normal size over 15sec. Trees respawn as little stubs and scale up over 10 sec (while continuing animation).

As far as features go thats about it. Most of the time was spent on fixing bugs, finding and murdering memory leaks, and trying in vain to get better frame rates when fire is everywhere.

Since this has been my first real project using c++, solving all the errors and bugs has been great for developing my understanding of the language, one thing i thought was interesting:

Type casting. I had an issue where the program would randomly crash due to corrupted heap, the reason, I discovered, was down to some of my deconstructor code. In two places there were lists of pointers to a base class, which lots of things were inherited from. I would cast the children onto the base class and add them to the list. When I wanted to delete everything I iterated through the list and deleted all the pointers, however it was only deleting the inherited objects as though they were their parent class, so the actual deconstructors of the children never got called.

Turns out i needed to use typeid(...) to get the fully inherited type of the pointer, and then reinterpret_cast<...>(...) the base class pointers into their child types, before deleting them.

More next weekend!

Toodles

No comments:

Post a Comment