OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Ogre::ObjectMemoryManager Class Reference

Wrap-around class that contains multiple ArrayMemoryManager, one per render queue. More...

#include <OgreObjectMemoryManager.h>

+ Inheritance diagram for Ogre::ObjectMemoryManager:
+ Collaboration diagram for Ogre::ObjectMemoryManager:

Public Member Functions

 ObjectMemoryManager ()
 
virtual ~ObjectMemoryManager ()
 
SceneNode_getDummyNode () const
 Returns the pointer to the dummy node (useful when detaching) More...
 
size_t _getTotalRenderQueues () const
 
void _setTwin (SceneMemoryMgrTypes memoryManagerType, ObjectMemoryManager *twinMemoryManager)
 mMemoryManagerType More...
 
virtual void applyRebase (ArrayMemoryManager::ManagerType managerType, uint16 level, const MemoryPoolVec &newBasePtrs, const ArrayMemoryManager::PtrdiffVec &diffsList)
 Called when the manager already grew it's memory pool to honour more node requests. More...
 
virtual void buildDiffList (ArrayMemoryManager::ManagerType managerType, uint16 level, const MemoryPoolVec &basePtrs, ArrayMemoryManager::PtrdiffVec &outDiffsList)
 Called when the manager needs to grow it's memory pool to honour more node requests. More...
 
size_t getFirstObjectData (ObjectData &outObjectData, size_t renderQueue)
 Retrieves a ObjectData pointing to the first MovableObject in the given render queue. More...
 
SceneMemoryMgrTypes getMemoryManagerType () const
 
size_t getNumRenderQueues () const
 Retrieves the number of render queues that have been created. More...
 
size_t getTotalNumObjects () const
 Retrieves the sum of the number of objects in all render queues. More...
 
ObjectMemoryManagergetTwin () const
 Note the return value can be null. More...
 
void migrateTo (ObjectData &inOutTransform, size_t renderQueue, ObjectMemoryManager *dstObjectMemoryManager)
 Releases memory belonging to us, not before copying it into another manager. More...
 
void objectCreated (ObjectData &outObjectData, size_t renderQueue)
 Requests memory for the given ObjectData, initializing values. More...
 
void objectDestroyed (ObjectData &outObjectData, size_t renderQueue)
 Releases current memory. More...
 
void objectMoved (ObjectData &inOutObjectData, size_t oldRenderQueue, size_t newRenderQueue)
 Requests memory for the given ObjectData to be moved to a different render queue, transferring existing values inside to the new memory slot. More...
 
virtual void performCleanup (ArrayMemoryManager::ManagerType managerType, uint16 level, const MemoryPoolVec &basePtrs, size_t const *elementsMemSizes, size_t startInstance, size_t diffInstances)
 Called when too many nodes were destroyed in a non-LIFO fashion. More...
 

Private Types

typedef vector
< ObjectDataArrayMemoryManager >
::type 
ArrayMemoryManagerVec
 

Private Member Functions

void growToDepth (size_t newDepth)
 Makes mMemoryManagers big enough to be able to fulfill mMemoryManagers[newDepth]. More...
 

Private Attributes

SceneNodemDummyNode
 Dummy node where to point ObjectData::mParents[i] when they're unused slots. More...
 
NullEntitymDummyObject
 
Transform mDummyTransformPtrs
 
ArrayMemoryManagerVec mMemoryManagers
 ArrayMemoryManagers grouped by hierarchy depth. More...
 
SceneMemoryMgrTypes mMemoryManagerType
 Memory managers can have a 'twin' (optional). More...
 
size_t mTotalObjects
 Tracks total number of objects in all render queues. More...
 
ObjectMemoryManagermTwinMemoryManager
 

Detailed Description

Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.

Remarks
This is the main memory manager that actually manages MovableObjects, and has to be called when a new MovableObject was created and when a MovableObject changes RenderQueue.
Note that some SceneManager implementations (i.e. Octree like) may want to have more than one ObjectMemoryManager, for example one per octant.

Definition at line 56 of file OgreObjectMemoryManager.h.

Member Typedef Documentation

Constructor & Destructor Documentation

Ogre::ObjectMemoryManager::ObjectMemoryManager ( )
virtual Ogre::ObjectMemoryManager::~ObjectMemoryManager ( )
virtual

Member Function Documentation

SceneNode* Ogre::ObjectMemoryManager::_getDummyNode ( ) const
inline

Returns the pointer to the dummy node (useful when detaching)

Definition at line 158 of file OgreObjectMemoryManager.h.

size_t Ogre::ObjectMemoryManager::_getTotalRenderQueues ( ) const
inline

Definition at line 142 of file OgreObjectMemoryManager.h.

void Ogre::ObjectMemoryManager::_setTwin ( SceneMemoryMgrTypes  memoryManagerType,
ObjectMemoryManager twinMemoryManager 
)

mMemoryManagerType

virtual void Ogre::ObjectMemoryManager::applyRebase ( ArrayMemoryManager::ManagerType  managerType,
uint16  level,
const MemoryPoolVec newBasePtrs,
const ArrayMemoryManager::PtrdiffVec diffsList 
)
virtual

Called when the manager already grew it's memory pool to honour more node requests.

Remarks
Will use the new base ptr and the list we built in
See also
buildDiffList() to know what mChunkPtr & mIndex needs to be set for each ArrayVector3/etc we have.
Parameters
managerTypeThe derived type of this manager, so listener knows whether this is an Node or ObjectData manager
levelThe hierarchy depth level
newBasePtrsThe new base ptr.
diffsListThe list built in buildDiffList

Implements Ogre::ArrayMemoryManager::RebaseListener.

virtual void Ogre::ObjectMemoryManager::buildDiffList ( ArrayMemoryManager::ManagerType  managerType,
uint16  level,
const MemoryPoolVec basePtrs,
ArrayMemoryManager::PtrdiffVec outDiffsList 
)
virtual

Called when the manager needs to grow it's memory pool to honour more node requests.

See the class description on why we need to do this (to avoid C++ undefined behavior)

Remarks
Needs to builds a list that will contain the difference in bytes between each ArrayVector3/ArrayMatrix4/etc and the base pointers in_the_order in which the derived class holds those pointers (i.e. in the order the SceneNodes are arranged in memory)
Parameters
managerTypeThe derived type of this manager, so listener knows whether this is an Node or ObjectData manager
levelThe hierarchy depth level
basePtrsThe base pointers from each pool so we can calculate the differences
utDiffsListThe list we'll generate. "outDiffsList" already has enough reserved space

Implements Ogre::ArrayMemoryManager::RebaseListener.

size_t Ogre::ObjectMemoryManager::getFirstObjectData ( ObjectData outObjectData,
size_t  renderQueue 
)

Retrieves a ObjectData pointing to the first MovableObject in the given render queue.

Parameters
outObjectData[out] ObjectData with filled pointers to the first MovableObject in this depth
renderQueueCurrent render queue it belongs to.
Returns
Number of MovableObject in this depth level
SceneMemoryMgrTypes Ogre::ObjectMemoryManager::getMemoryManagerType ( ) const
inline

Definition at line 92 of file OgreObjectMemoryManager.h.

size_t Ogre::ObjectMemoryManager::getNumRenderQueues ( ) const

Retrieves the number of render queues that have been created.

Remarks
The return value is equal or below mMemoryManagers.size(), you should cache the result instead of calling this function too often.
size_t Ogre::ObjectMemoryManager::getTotalNumObjects ( ) const
inline

Retrieves the sum of the number of objects in all render queues.

Remarks
The value is cached to avoid iterating through all RQ levels, however be very careful with this value it may not be equal to the sum of all getFirstObjectData() from all render queues.
When ARRAY_PACKED_REALS = 4, and 4 objects have been created but the 2nd one has been deleted, getFirstObjectData will still return 4 until the 4th object is removed or a cleanup is performed; whereas getTotalNumObjects will return the actual number of objects.

Definition at line 155 of file OgreObjectMemoryManager.h.

ObjectMemoryManager* Ogre::ObjectMemoryManager::getTwin ( ) const
inline

Note the return value can be null.

Definition at line 91 of file OgreObjectMemoryManager.h.

void Ogre::ObjectMemoryManager::growToDepth ( size_t  newDepth)
private

Makes mMemoryManagers big enough to be able to fulfill mMemoryManagers[newDepth].

Parameters
newDepthHierarchy level depth we wish to grow to.
void Ogre::ObjectMemoryManager::migrateTo ( ObjectData inOutTransform,
size_t  renderQueue,
ObjectMemoryManager dstObjectMemoryManager 
)

Releases memory belonging to us, not before copying it into another manager.

Remarks
This function is useful when implementing multiple Memory Managers in Scene Managers or when switching nodes from Static to/from Dynamic.
Parameters
inOutTransformValid Transform that belongs to us. Output will belong to the other memory mgr.
depthCurrent hierarchy level depth it belongs to.
dstObjectMemoryManagerObjectMemoryManager that will now own the transform.
void Ogre::ObjectMemoryManager::objectCreated ( ObjectData outObjectData,
size_t  renderQueue 
)

Requests memory for the given ObjectData, initializing values.

Parameters
outObjectDataObjectData with filled pointers
renderQueueRenderQueue ID.
void Ogre::ObjectMemoryManager::objectDestroyed ( ObjectData outObjectData,
size_t  renderQueue 
)

Releases current memory.

Parameters
outObjectDataObjectData whose pointers will be nullified.
renderQueueCurrent render queue it belongs to.
void Ogre::ObjectMemoryManager::objectMoved ( ObjectData inOutObjectData,
size_t  oldRenderQueue,
size_t  newRenderQueue 
)

Requests memory for the given ObjectData to be moved to a different render queue, transferring existing values inside to the new memory slot.

Parameters
inOutObjectDataObjectData with filled pointers
oldRenderQueueRenderQueue it's living now.
newRenderQueueRenderQueue it wants to live in.
virtual void Ogre::ObjectMemoryManager::performCleanup ( ArrayMemoryManager::ManagerType  managerType,
uint16  level,
const MemoryPoolVec basePtrs,
size_t const *  elementsMemSizes,
size_t  startInstance,
size_t  diffInstances 
)
virtual

Called when too many nodes were destroyed in a non-LIFO fashion.

Without cleaning up, the scene manager will waste CPU & bandwidth on processing vectors & matrices that are not in use. The more fragmented/unordered those removals were, the worst it is. Try to create everything static first, then dynamic content.

Remarks
The manager behaves similarly to a Garbage Collector, as it is triggered after certain amount of nodes have been freed (unless they respected LIFO order)

In a way, it's very similar to vector::remove(), as removing an element from the middle means we need to shift everything past that point one place (or more).

Parameters
managerTypeThe derived type of this manager, so listener knows whether this is an Node or ObjectData manager
levelThe hierarchy depth level
basePtrsThe base ptrs.
startInstanceThe instance to which past that we need to shift
diffInstancesHow many places we need to shift backwards.

Implements Ogre::ArrayMemoryManager::RebaseListener.

Member Data Documentation

SceneNode* Ogre::ObjectMemoryManager::mDummyNode
private

Dummy node where to point ObjectData::mParents[i] when they're unused slots.

Definition at line 66 of file OgreObjectMemoryManager.h.

NullEntity* Ogre::ObjectMemoryManager::mDummyObject
private

Definition at line 68 of file OgreObjectMemoryManager.h.

Transform Ogre::ObjectMemoryManager::mDummyTransformPtrs
private

Definition at line 67 of file OgreObjectMemoryManager.h.

ArrayMemoryManagerVec Ogre::ObjectMemoryManager::mMemoryManagers
private

ArrayMemoryManagers grouped by hierarchy depth.

Definition at line 60 of file OgreObjectMemoryManager.h.

SceneMemoryMgrTypes Ogre::ObjectMemoryManager::mMemoryManagerType
private

Memory managers can have a 'twin' (optional).

A twin is used when there static and dynamic scene managers, thus caching their pointers here is very convenient.

Definition at line 74 of file OgreObjectMemoryManager.h.

size_t Ogre::ObjectMemoryManager::mTotalObjects
private

Tracks total number of objects in all render queues.

Definition at line 63 of file OgreObjectMemoryManager.h.

ObjectMemoryManager* Ogre::ObjectMemoryManager::mTwinMemoryManager
private

Definition at line 75 of file OgreObjectMemoryManager.h.


The documentation for this class was generated from the following file: