Thursday, November 29, 2012

Singleton Pattern

Uf, I'm such a perfectionist.  After finishing up cube fracture and a cool freeze frame effect that dampens the fractured cubes proportionally to their velocity so that after you die your scattered remnants slow down and freeze before going very far.  It's kinda cool, better I thought than smashing into a wall at high velocity and having your broken self scatter off screen instantly.  Ugh, run on sentence, I'm so tired.
Anyway, I've looped back again to revise my fundamental game class design.  Finally implemented a proper singleton design, thanks to ktodisco's suggestion on gamedev.stackexchange.com

I'm quite satisfied with the simplicity of it.  The constructor is made private to prevent other instances from being created, and the static method getInstance is used to grab a reference to the game class context from anywhere.
The first and only instance is created lazily in the 'main' method with the getInstance method as well:






kx& kyuplex = kx::getInstance();

Next I want to better encapsulate the player cube entity with the creation and organization of a proper kxPlayerCube class.  There was some confusion in my naming scheme between the Irrlicht node named playerCube, the Bullet rigidbody pCubeRigidBody, etc.  All the pointers and variables are stuffed into the kx main game class right now, for development, and need to be sorted out before I continue to grow the game.  
 

No comments:

Post a Comment