Episode 30 - Reconstructing Cave Story: Refactor Sprite States
671 views · Published 28 January 2014 · 17:44 · Indexed 30 September 2026
Channel: Christopher Hebert · 2014 · Education
Introduce boost::tuple and our own ENUM_FOREACH macro to help clean up sprite states. IMPORTANT: The implicit constructors for the sprite states need to take const SpriteTuple& s. Emphasis on the const. Why/how should I be careful when I publicly inherit from boost::tuple? TLDR; base class has no virtual interface; can't use derived class polymorphically. boost::tuple has no virtual methods/destructors. This makes it tricky when you have a boost::tuple pointer to a derived object. If you try to delete this pointer, you will not be deconstructing the derived object. e.g. https://gist.github.com/bkuhns/8689289 will leak all of the memory in derived object. In our case we are safe, since we aren't using SpriteState polymorphically. ================================================= Playlist: https://www.youtube.com/playlist?list=PL006xsVEsbKjSKBmLu1clo85yLrwjY67X Content (.bmp files and such): https://github.com/chebert/cavestory-content/archive/master.zip Cave Story (freeware version) download page: http://www.cavestory.org/downloads_game.php