OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreArrayMemoryManager.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __ArrayMemoryManager_H__
29 #define __ArrayMemoryManager_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include <stddef.h>
34 
35 namespace Ogre
36 {
38 
46  typedef void (*CleanupRoutines)( char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc,
47  size_t numSlots, size_t numFreeSlots, size_t elementsMemSize );
48 
65  {
66  public:
68  {
72 
73  // User defined types in case you may want to have more than
74  // one NodeArrayMemoryManager, or your own custom ones
82 
83  NumStructTypes
84  };
85 
86  //typedef vector<ptrdiff_t>::type PtrdiffVec; //TODO: Modify for Ogre
87  typedef std::vector<ptrdiff_t> PtrdiffVec;
88 
102  {
103  public:
121  virtual void buildDiffList( ManagerType managerType, uint16 level,
122  const MemoryPoolVec &basePtrs, PtrdiffVec &outDiffsList ) = 0;
123 
138  virtual void applyRebase( ManagerType managerType, uint16 level,
139  const MemoryPoolVec &newBasePtrs,
140  const PtrdiffVec &diffsList ) = 0;
141 
164  virtual void performCleanup( ManagerType managerType, uint16 level,
165  const MemoryPoolVec &basePtrs,
166  size_t const *elementsMemSizes, size_t startInstance,
167  size_t diffInstances ) = 0;
168  };
169 
170  protected:
173  size_t const *mElementsMemSizes;
176 
177  //The following three are measured in instances, not bytes
178  size_t mUsedMemory;
179  size_t mMaxMemory;
182  typedef std::vector<size_t> SlotsVec; //TODO: Modify for Ogre
185 
190 
192 
193  public:
194  static const size_t MAX_MEMORY_SLOTS;
195 
226  ArrayMemoryManager( ManagerType managerType, size_t const *elementsMemSize,
227  CleanupRoutines const *cleanupRoutines, size_t numElementsSize,
228  uint16 depthLevel, size_t hintMaxNodes,
229  size_t cleanupThreshold=100, size_t maxHardLimit=MAX_MEMORY_SLOTS,
230  RebaseListener *rebaseListener=0 );
231 
240  void initialize();
241 
248  void destroy();
249 
251  size_t getFreeMemory() const;
253  size_t getUsedMemory() const;
255  size_t getWastedMemory() const;
257  size_t getAllMemory() const;
258 
259  protected:
268  size_t createNewSlot();
269 
278  void destroySlot( const char *ptrToFirstElement, uint8 index );
279 
285  virtual void slotsRecreated( size_t prevNumSlots ) {}
286  };
287 
288 
289 
290 
298  {
301 
302  protected:
304  virtual void slotsRecreated( size_t prevNumSlots );
305 
306  public:
308  {
309  Parent = 0,
320  NumMemoryTypes
321  };
322 
323  static const size_t ElementsMemSize[NumMemoryTypes];
324  static const CleanupRoutines NodeCleanupRoutines[NumMemoryTypes];
325 
327  NodeArrayMemoryManager( uint16 depthLevel, size_t hintMaxNodes, Node *dummyNode,
328  size_t cleanupThreshold=100, size_t maxHardLimit=MAX_MEMORY_SLOTS,
329  RebaseListener *rebaseListener=0 );
330 
340  void createNewNode( Transform &outTransform );
341 
348  void destroyNode( Transform &inOutTransform );
349 
358  size_t getFirstNode( Transform &outTransform );
359  };
360 
361 
362 
370  {
374 
375  protected:
377  virtual void slotsRecreated( size_t prevNumSlots );
378 
379  public:
381  {
382  Parent = 0,
392  NumMemoryTypes
393  };
394 
395  static const size_t ElementsMemSize[NumMemoryTypes];
396  static const CleanupRoutines ObjCleanupRoutines[NumMemoryTypes];
397 
399  ObjectDataArrayMemoryManager( uint16 depthLevel, size_t hintMaxNodes, Node *dummyNode,
400  MovableObject *dummyObject, size_t cleanupThreshold=100,
401  size_t maxHardLimit=MAX_MEMORY_SLOTS,
402  RebaseListener *rebaseListener=0 );
403 
405  void createNewNode( ObjectData &outData );
406 
408  void destroyNode( ObjectData &inOutData );
409 
411  size_t getFirstNode( ObjectData &outData );
412  };
413 
414  extern void cleanerFlat( char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc,
415  size_t numSlots, size_t numFreeSlots, size_t elementsMemSize );
416  extern void cleanerArrayVector3( char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc,
417  size_t numSlots, size_t numFreeSlots, size_t elementsMemSize );
418  extern void cleanerArrayQuaternion( char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc,
419  size_t numSlots, size_t numFreeSlots, size_t elementsMemSize );
420  extern void cleanerArrayAabb( char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc,
421  size_t numSlots, size_t numFreeSlots, size_t elementsMemSize );
422 
425 }
426 
427 #endif
std::vector< ptrdiff_t > PtrdiffVec
When mUsedMemory >= mMaxMemory (that is, we've exhausted all our preallocated memory) ArrayMemoryMana...
unsigned char uint8
Definition: OgrePlatform.h:422
Represents the transform of a single object, arranged in SoA (Structure of Arrays) ...
Represents the transform of a single object, arranged in SoA (Structure of Arrays) ...
Definition: OgreTransform.h:37
#define _OgreExport
Definition: OgrePlatform.h:255
MemoryPoolVec mMemoryPools
One per memory type.
CleanupRoutines const * mCleanupRoutines
Implementation to create the Transform variables needed by Nodes & SceneNodes.
Node * mDummyNode
Dummy node where to point Transform::mParents[i] when they're unused slots.
Abstract class defining a movable object in a scene.
Abstract memory manager for managing large chunks of contiguous memory, optimized for SoA (Structure ...
Node * mDummyNode
Dummy node where to point ObjectData::mParents[i] when they're unused slots.
std::vector< size_t > SlotsVec
Implementation to create the ObjectData variables needed by MovableObjects.
void cleanerFlat(char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc, size_t numSlots, size_t numFreeSlots, size_t elementsMemSize)
void(* CleanupRoutines)(char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc, size_t numSlots, size_t numFreeSlots, size_t elementsMemSize)
vector< char * >::type MemoryPoolVec
static const size_t MAX_MEMORY_SLOTS
unsigned short uint16
Definition: OgrePlatform.h:421
void cleanerArrayAabb(char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc, size_t numSlots, size_t numFreeSlots, size_t elementsMemSize)
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
void cleanerArrayQuaternion(char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc, size_t numSlots, size_t numFreeSlots, size_t elementsMemSize)
void cleanerArrayVector3(char *dstPtr, size_t indexDst, char *srcPtr, size_t indexSrc, size_t numSlots, size_t numFreeSlots, size_t elementsMemSize)
virtual void slotsRecreated(size_t prevNumSlots)
Called when mMemoryPools changes, to give a chance derived class to initialize memory to default valu...
uint16 mLevel
The hierarchy depth level.