OGRE 2.1
Object-Oriented Graphics Rendering Engine
Loading...
Searching...
No Matches
Ogre::ObjectMemoryManager Class Reference

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

#include <OgreObjectMemoryManager.h>

+ Inheritance diagram for Ogre::ObjectMemoryManager:

Public Member Functions

 ObjectMemoryManager ()
 
virtual ~ObjectMemoryManager ()
 
SceneNode_getDummyNode () const
 Returns the pointer to the dummy node (useful when detaching)
 
size_t _getTotalRenderQueues () const
 
void _setTwin (SceneMemoryMgrTypes memoryManagerType, ObjectMemoryManager *twinMemoryManager)
 @See mMemoryManagerType
 
virtual void applyRebase (uint16 level, const MemoryPoolVec &newBasePtrs, const ArrayMemoryManager::PtrdiffVec &diffsList)
 Called when the manager already grew it's memory pool to honour more node requests.
 
virtual void buildDiffList (uint16 level, const MemoryPoolVec &basePtrs, ArrayMemoryManager::PtrdiffVec &outDiffsList)
 Called when the manager needs to grow it's memory pool to honour more node requests.
 
size_t calculateTotalNumObjectDataIncludingFragmentedSlots () const
 This is the opposite of getTotalNumObjects.
 
size_t getFirstObjectData (ObjectData &outObjectData, size_t renderQueue)
 Retrieves a ObjectData pointing to the first MovableObject in the given render queue.
 
SceneMemoryMgrTypes getMemoryManagerType () const
 
size_t getNumRenderQueues () const
 Retrieves the number of render queues that have been created.
 
size_t getTotalNumObjects () const
 Retrieves the sum of the number of objects in all render queues.
 
ObjectMemoryManagergetTwin () const
 Note the return value can be null.
 
void migrateTo (ObjectData &inOutTransform, size_t renderQueue, ObjectMemoryManager *dstObjectMemoryManager)
 Releases memory belonging to us, not before copying it into another manager.
 
void objectCreated (ObjectData &outObjectData, size_t renderQueue)
 Requests memory for the given ObjectData, initializing values.
 
void objectDestroyed (ObjectData &outObjectData, size_t renderQueue)
 Releases current memory.
 
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.
 
virtual void performCleanup (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.
 

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.

Constructor & Destructor Documentation

◆ ObjectMemoryManager()

Ogre::ObjectMemoryManager::ObjectMemoryManager ( )

◆ ~ObjectMemoryManager()

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

Member Function Documentation

◆ _getDummyNode()

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

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

◆ _getTotalRenderQueues()

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

◆ _setTwin()

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

@See mMemoryManagerType

◆ applyRebase()

virtual void Ogre::ObjectMemoryManager::applyRebase ( 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
levelThe hierarchy depth level
newBasePtrsThe new base ptr.
diffsListThe list built in buildDiffList

Implements Ogre::ArrayMemoryManager::RebaseListener.

◆ buildDiffList()

virtual void Ogre::ObjectMemoryManager::buildDiffList ( 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
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.

◆ calculateTotalNumObjectDataIncludingFragmentedSlots()

size_t Ogre::ObjectMemoryManager::calculateTotalNumObjectDataIncludingFragmentedSlots ( ) const

This is the opposite of getTotalNumObjects.

This function returns the sum of the return values of getFirstObjectData

◆ getFirstObjectData()

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

◆ getMemoryManagerType()

SceneMemoryMgrTypes Ogre::ObjectMemoryManager::getMemoryManagerType ( ) const
inline

◆ getNumRenderQueues()

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.

◆ getTotalNumObjects()

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. Specially careful when distributing work to different threads, since you may have to include skipping unassigned slots, and thus the last thread may end up writing out of bounds if you use getTotalNumObjects to allocate a buffer to hold results instead of calculateTotalNumObjectDataIncludingFragmentedSlots (depends on how your algorithm works).
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.

◆ getTwin()

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

Note the return value can be null.

◆ migrateTo()

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.

◆ objectCreated()

void Ogre::ObjectMemoryManager::objectCreated ( ObjectData outObjectData,
size_t  renderQueue 
)

Requests memory for the given ObjectData, initializing values.

Parameters
outObjectDataObjectData with filled pointers
renderQueueRenderQueue ID.

◆ objectDestroyed()

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.

◆ objectMoved()

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.

◆ performCleanup()

virtual void Ogre::ObjectMemoryManager::performCleanup ( 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
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.


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