I would like detail just details the two main points of question around this below (IdType & ObjectMemoryManager)
IdType
IdType is the unique Id of the object and effectively replaces string name. If you are creating an object which you dont tell Ogre about you can set this to whatever you want, however it is good practice to set it to a unique number. Luckily Ogre has a static function for that;
Code: Select all
Id::generateNewId<Type>()
ObjectMemoryManager
Now this is were it gets a little more complicated, although not really that complicated! You must provided an ObjectMemoryManager when instantiating a MovableObject; this is because in the constructor of MovableObject it calls the ObjectMemoryManager to allocate the SoA data of MovableObject. If you are trying to create an object that inherits from MovableObject outside of the SceneManager::create* methods you have 3 options;
- 1) You can supply it with one of the MemoryManagers from the SceneManager; Eg
This is potentially a bit dangerous, the reason is, for example, when culling Ogre 2.0 works very differently than 1.x. It actually iterates though the EntityMemoryManager and creates a list of 'visible' MovableObjects which are then rendered. So if you use SceneManager EntityMemoryManager, its likely that Ogre will try and render that object for you. This is probably not what you want when you are trying to instantiate MovablObject outside of the SceneManager.
Code: Select all
sceneMgr->_getEntityMemoryManager(Ogre::SCENE_DYNAMIC)
- 2) Just supply it with a new memory manager for each object;
This is simple, albeit a bit lazy, but very wasteful and should not really be done!
Code: Select all
new MovableObject( 0, new ObjectMemoryManager(), 0)
- 3) Create your own ObjectMemoryManager and use it for your 'special' objects. This is where I am heading towards for ParticleUniverse and seems to be the tidiest solution, but requires more work