Tuesday, June 9, 2009

Callbacks in C++

Paul pointed me to a Rich Hickey article called Callbacks in C++ Using Template Functors. It is a great paper because it pointed out many of the flaws in my earlier implementations. One implementation, in which I mostly copied the Observer pattern right out of the GoF Design Patterns book, had the big hang-up that I could only have one kind of attachment per Subject. A bigger problem with the Observer pattern as outlined in the book, though, is that any class wanting to listen to a Subject would need to inherit an Observer interface to do it. Using the callbacks implementation created in the Rich Hickey article instead, I was able to remove the Observer class altogether, and just have some function called instead. It's a great setup.

It took me a little bit just to code the callback.h file, and only implementing the one-parameter functor at that. That's when I found out I could've just gone to koders.com and picked up Joel Vennin's callback.h implementation. On the other hand I do have my own callback.h that isn't tied to any license, so I'll probably just stick with mine for now.

Some other references that I used throughout learning about callbacks were Bert Peers Callbacks in C++ which is a different perspective on the original paper, and C++ FAQ Lite on pointers-to-member-functions.

In conclusion, thanks to callbacks, I've found yet another way to unnecessarily complicate the pure simplicity of Tetris. Yep, the shear number of classes we have are going through the roof, and we haven't even begun to code, really. I can see this getting much worse than it currently is. In the end it will be worth it, because all those other simple Tetris projects were mostly for programming practice, rather than making a quality game. Yes indeed, my hope for getting this game out isn't crushed just yet. Although my hope for getting a date is certainly ground into a fine powder. Their eyes seem to glaze over when I start talking about callbacks...

Saturday, June 6, 2009

25 years of Tetris

Today Google changed there image to be made of Tetris blocks as Tetris turns 25 years old. All I have to say is the 26th year of Tetris will be the year of Tezad (at least I hope). Believe it or not we are still working the Tezad project. We have just been running into a lot of low level issues that need to be worked out. If we do it right it should provide a nice framework as we move forward.