about singletons in OGRE

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
zydgyy
Gremlin
Posts: 160
Joined: Mon Jun 06, 2011 1:51 pm

about singletons in OGRE

Post by zydgyy »

Hi,guys!
I read about a lot sources in OGRE,i found most singleton patterns in OGRE is not tranditional,just make classes' construnctors public,and we are free to new them,but we just get instances through facade ROOT?Is it regular?
THANKS!
chincillya
Halfling
Posts: 94
Joined: Sun Dec 19, 2004 7:12 pm
Location: Finland
x 3
Contact:

Re: about singletons in OGRE

Post by chincillya »

The singleton pattern used in ogre is based on a gem from Game Programming Gems 1. I use the same pattern in my own engine. You can read more about it here: http://scottbilas.com/publications/gem-singleton/

The nice thing with the pattern is that the constructors can indeed be public, which allows the programmer to pass in parameters to the singleton object when it is created. The base class makes sure no more than one objects exists at any time (it asserts if trying to create multiple objects).

The fact that Root is used to create some objects (like scene managers) has nothing to do with the singleton pattern. It has to do with the face that some objects (like Root and SceneManager) have a very tight relationship and it would not make sense to have a scene manager without a root object.
"Black holes are the result of God dividing by zero."

http://www.sebastian-ahlman.fi/
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: about singletons in OGRE

Post by Klaim »

By the way, there are discussions in Boost to implement a similar pattern but renamed "singularity" because 1. it forces you to have explicit creation/destruction points, like the ogre singletons, instead of automatic instantiation 2. global access is optional.

Just to say that the word "singleton" is really misleading. Depending on the implementations, they don't allow the same thing and have only the single instance possible common feature.
Post Reply