HELP! NxOgre Singleton Problem!

artn3r

11-11-2008 14:02:05

I am trying to "Singletonize" the NxOgre::World class, because i want to use it in my application, which can script in python using python-ogre.
I want to create the World object in Python and then in C++ i want to get
the singleton of World to access the same World object as in Python.

In the code of the World-class, there is already an include for "OgreSingleton.h", but there is no "ms_Singleton" pointer declared,
maybe the code is not finished yet? The World class does also not inherit
the Ogre::Singleton class.

So in NxOgreWorld.h i changed:

class NxPublicClass World {

to


class NxPublicClass World : public Ogre::Singleton<World> {

In NxOgreWorld.cpp i added:

NxOgre::World* Ogre::Singleton<NxOgre::World>::ms_Singleton;, now the class looks like this:

#include "NxOgreStable.h"
#include "NxOgreWorld.h"
#include "NxOgreScene.h" // For: Scene operations
#include "NxOgreHelpers.h" // For: Incase of Scene duplicate names.

#include "NxOgreDebugRenderer.h" // For: Times when it's really needed.
#include "time.h" // For: Making sure NxGenerateID is random.

#if (NX_USE_OGRE == 1)
# include "OgreRoot.h"
# include "OgreSingleton.h"
#endif


NxOgre::World* Ogre::Singleton<NxOgre::World>::ms_Singleton;

namespace NxOgre {




World::World(PhysXParams driverParams, bool loadResources) {



mDriver = NxNew(PhysXDriver)(this, driverParams);

mNbFrames = 0;
srand((unsigned)time(0));

#if (NX_USE_DEBUG_RENDERER_API == 1)
mDebugRenderer = 0;
#endif

// mSerialiser = new Serialiser(this);

NxLabelContainer(World, mScenes, Scenes);

}

///////////////////////////////////////////////////////////////////////

World::~World() {
shutdown();
}
.
.
.


The code compiles fine!

But when i add my new compiled .lib and .dll file to my project
and call NxOgre::World::getSingleton(); then, the linker gives me
the error:

""protected: static class NxOgre::World * Ogre::Singleton<class NxOgre::World>::ms_Singleton" (?ms_Singleton@?$Singleton@VWorld@NxOgre@@@Ogre@@1PAVWorld@NxOgre@@A)".
1>bin\Release\3DIS-Client.exe : fatal error LNK1120: 1 not resolved external references.

I do not know why, because i did this procedure with all my classes
in my application and it worked fine! I just added the : public Ogre::Singleton to the class declaration in the .h file and the ms_Singleton pointer to my .cpp file.

I use Visual Studio 2008 and NxOgre 1.0 '21 from the SVN!

betajaen

11-11-2008 14:03:00

Why don't you just make a generic singleton and make a World a member variable of that?

artn3r

11-11-2008 14:15:16

Hello,
Because then i have to wrap this into a python-class with boost or something.
for nxogre there are already bindings for python-ogre!

Do you know how to make a singleton of this? in version 0.4, there was
singleton code in the World class, and i saw a post in which you wrote
that World is a singleton. But in 1,0 from svn there is not? Am i right?

Regards, Christian

betajaen

11-11-2008 16:11:50

It's just a silly idea.

You can put World into a Singleton class or function, or make the World a global variable.

mrmclovin

14-11-2008 17:53:48

Is it not that you have to put:
template<>
NxOgre::World* Ogre::Singleton<NxOgre::World>::ms_Singleton = 0;


outside of the class declartion?