NL3D::CShapeBank Class Reference

A CShapeBank handle all the instance of the shapes and the cache management system. More...

#include <shape_bank.h>

List of all members.

Classes

struct  CShapeCache
struct  CShapeInfo
struct  CWaitingShape

Public Types

State of a shape



enum  TShapeState {
  NotPresent, Present, AsyncLoad_Error, AsyncLoad_Shape,
  AsyncLoad_Texture, AsyncLoad_Ready, AsyncLoad_Delete
}
 

NotPresent : Not present in the bank Present : Present in the bank and ready to be used AsyncLoad_Error : Asynchronous loading failed AsyncLoad_Shape : Asynchronous loading is currently loading the .shape file, textures and lightmaps AsyncLoad_Texture : Asynchronous loading is currently uploading textures and lightmaps to VRAM.

More...

Public Member Functions

 CShapeBank ()
 ~CShapeBank ()
const std::string * getShapeNameFromShapePtr (IShape *pShp) const
Instance Management



IShapeaddRef (const std::string &shapeName)
 Add a reference to a shape and return the instance created. NB: getPresentState()==Present must be tested first.
void release (IShape *pShp)
 Release a reference to a shape by its instance.
TShapeState getPresentState (const std::string &shapeName)
 Return the shape state. Process the waiting shapes.
IShapegetShape (const std::string &shapeName)
 Return the IShape from the bank.
void load (const std::string &shapeName)
 Load the corresponding file from disk and add it to the bank.
void loadAsync (const std::string &shapeName, IDriver *pDriver, const NLMISC::CVector &position, bool *bSignal, uint selectedTexture)
 Load the corresponding file from disk asynchronously and add it to the bank.
void cancelLoadAsync (const std::string &shapeName)
bool isShapeWaiting ()
void processWaitingShapes ()
 processWaitingShapes must be done one time per frame
void setMaxBytesToUpload (uint32 MaxUploadPerFrame)
 Setup the maximum number of bytes to upload for a frame (texture upload from RAM to VRAM).
void add (const std::string &shapeName, IShape *shape)
 Add directly a shape to the bank. If the shape name is already used do nothing.
Shape cache management



void addShapeCache (const std::string &shapeCacheName)
 Add a new ShapeCache. If already exist do nothing.
void removeShapeCache (const std::string &shapeCacheName)
 Remove a ShapeCache.
bool isShapeCache (const std::string &shapeCacheName) const
 true if the shape cache exist
void reset ()
 Remove all ShapeCache and suppress all links (even the link to the default cache are removed).
void setShapeCacheSize (const std::string &shapeCacheName, sint32 maxSize)
 Set the shapeCache shapeCacheName the new size.(delete shapes if maxsize<shapeCacheSize).
sint getShapeCacheFreeSpace (const std::string &shapeCacheName) const
 return free cache space (maxSize-nbCurrentInCache)
void linkShapeToShapeCache (const std::string &shapeName, const std::string &shapeCacheName)
 Link a shape to a ShapeCache. The ShapeCache must exist and must not contains the shape.
Tools



void preLoadShapes (const std::string &shapeCacheName, const std::vector< std::string > &listFile, const std::string &wildCardNotLwr, NLMISC::IProgressCallback *progress=NULL, bool flushTextures=false, IDriver *drv=NULL)
 PreLoad all shapes (.shape, .ps, .skel.
void buildSystemGeometryForshape (const std::string &shapeName)
 Mark this shape name as needing a buildSystemGeometry() (typically used for selection) NB: this will take effect only for shapes on a subsequent add(), load() or loadAsync().

Shape/Instances.



typedef NLMISC::CSmartPtr< IShapePShape
typedef std::map< std::string,
PShape
TShapeMap
typedef std::map< std::string,
CWaitingShape
TWaitingShapesMap
TShapeMap ShapeMap
TWaitingShapesMap WaitingShapes
uint32 _MaxUploadPerFrame
IDriver_pDriver
bool processWSUploadTexture (CWaitingShape &rWS, uint32 &nTotalUploaded, ITexture *pText)
 return true if the texture is entirely uploaded

Shape/Caches.



typedef std::map< std::string,
std::string > 
TShapeCacheNameMap
typedef std::map< std::string,
CShapeCache
TShapeCacheMap
typedef std::map< IShape
*, CShapeInfo
TShapeInfoMap
TShapeCacheNameMap ShapeNameToShapeCacheName
TShapeCacheMap ShapeCacheNameToShapeCache
TShapeInfoMap ShapePtrToShapeInfo
std::set< std::string > _ShapeNeedingSystemGeometryCopy
IShapegetShapePtrFromShapeName (const std::string &pShpName)
CShapeCachegetShapeCachePtrFromShapePtr (IShape *pShp)
CShapeCachegetShapeCachePtrFromShapeCacheName (const std::string &shapeCacheName)
CShapeCachegetShapeCachePtrFromShapeName (const std::string &shapeName)
void checkShapeCache (CShapeCache *pShpCache)

Detailed Description

A CShapeBank handle all the instance of the shapes and the cache management system.

There is a default cache. If the shape is not linked explicitly to any cache it is linked to the default cache. The comportement of this cache is to not do any cache. When the release is called on the last reference to a shape linked to this cache, the shape is removed instantly. This is the behavior of all newly created cache before we call the setShapeCacheSize method.

NB: ShapeCacheName is case-sensitive but shapeName are not (all entry are lwrcased)

Author:
Matthieu Besson
Nevrax France
Date:
2000

Definition at line 61 of file shape_bank.h.


Member Typedef Documentation

Definition at line 173 of file shape_bank.h.

typedef std::map<std::string,CShapeCache> NL3D::CShapeBank::TShapeCacheMap [private]

Definition at line 237 of file shape_bank.h.

typedef std::map<std::string,std::string> NL3D::CShapeBank::TShapeCacheNameMap [private]

Definition at line 236 of file shape_bank.h.

typedef std::map<IShape*,CShapeInfo> NL3D::CShapeBank::TShapeInfoMap [private]

Definition at line 238 of file shape_bank.h.

typedef std::map<std::string, PShape> NL3D::CShapeBank::TShapeMap [private]

Definition at line 174 of file shape_bank.h.

typedef std::map< std::string, CWaitingShape > NL3D::CShapeBank::TWaitingShapesMap [private]

Definition at line 198 of file shape_bank.h.


Member Enumeration Documentation

NotPresent : Not present in the bank Present : Present in the bank and ready to be used AsyncLoad_Error : Asynchronous loading failed AsyncLoad_Shape : Asynchronous loading is currently loading the .shape file, textures and lightmaps AsyncLoad_Texture : Asynchronous loading is currently uploading textures and lightmaps to VRAM.

Enumerator:
NotPresent 
Present 
AsyncLoad_Error 
AsyncLoad_Shape 
AsyncLoad_Texture 
AsyncLoad_Ready 
AsyncLoad_Delete 

Definition at line 73 of file shape_bank.h.


Constructor & Destructor Documentation

NL3D::CShapeBank::CShapeBank (  ) 

Definition at line 42 of file shape_bank.cpp.

References _MaxUploadPerFrame, and addShapeCache().

NL3D::CShapeBank::~CShapeBank (  ) 

Definition at line 51 of file shape_bank.cpp.


Member Function Documentation

void NL3D::CShapeBank::add ( const std::string &  shapeName,
IShape shape 
)
IShape * NL3D::CShapeBank::addRef ( const std::string &  shapeName  ) 
void NL3D::CShapeBank::addShapeCache ( const std::string &  shapeCacheName  ) 

Add a new ShapeCache. If already exist do nothing.

Definition at line 646 of file shape_bank.cpp.

References ShapeCacheNameToShapeCache.

Referenced by NL3D::CShapeBankUser::addShapeCache(), CShapeBank(), NL3D::CAnimationSet::preloadSSSShapes(), and reset().

void NL3D::CShapeBank::buildSystemGeometryForshape ( const std::string &  shapeName  ) 

Mark this shape name as needing a buildSystemGeometry() (typically used for selection) NB: this will take effect only for shapes on a subsequent add(), load() or loadAsync().

Definition at line 913 of file shape_bank.cpp.

References _ShapeNeedingSystemGeometryCopy, and NLMISC::toLower().

Referenced by NL3D::CShapeBankUser::buildSystemGeometryForshape().

void NL3D::CShapeBank::cancelLoadAsync ( const std::string &  shapeName  ) 
void NL3D::CShapeBank::checkShapeCache ( CShapeCache pShpCache  )  [private]
CShapeBank::TShapeState NL3D::CShapeBank::getPresentState ( const std::string &  shapeName  ) 
IShape * NL3D::CShapeBank::getShape ( const std::string &  shapeName  ) 

Return the IShape from the bank.

Unlike addRef, no reference is added. Thus the returning shape sould be used temporarily

Returns:
NULL if shape not found or not loaded (if being async loaded still return NULL)

Definition at line 451 of file shape_bank.cpp.

References ShapeMap, and NLMISC::toLower().

Referenced by NL3D::CShapeBankUser::getShape().

sint NL3D::CShapeBank::getShapeCacheFreeSpace ( const std::string &  shapeCacheName  )  const

return free cache space (maxSize-nbCurrentInCache)

Definition at line 717 of file shape_bank.cpp.

References ShapeCacheNameToShapeCache.

Referenced by preLoadShapes(), and NL3D::CAnimationSet::preloadSSSShapes().

CShapeBank::CShapeCache * NL3D::CShapeBank::getShapeCachePtrFromShapeCacheName ( const std::string &  shapeCacheName  )  [private]
CShapeBank::CShapeCache * NL3D::CShapeBank::getShapeCachePtrFromShapeName ( const std::string &  shapeName  )  [private]

Definition at line 820 of file shape_bank.cpp.

References getShapeCachePtrFromShapeCacheName(), and ShapeNameToShapeCacheName.

Referenced by add().

CShapeBank::CShapeCache * NL3D::CShapeBank::getShapeCachePtrFromShapePtr ( IShape pShp  )  [private]

Definition at line 770 of file shape_bank.cpp.

References ShapePtrToShapeInfo.

Referenced by release().

const string * NL3D::CShapeBank::getShapeNameFromShapePtr ( IShape pShp  )  const
IShape * NL3D::CShapeBank::getShapePtrFromShapeName ( const std::string &  pShpName  )  [private]

Definition at line 782 of file shape_bank.cpp.

References ShapeMap.

Referenced by addRef(), and linkShapeToShapeCache().

bool NL3D::CShapeBank::isShapeCache ( const std::string &  shapeCacheName  )  const

true if the shape cache exist

Definition at line 850 of file shape_bank.cpp.

References ShapeCacheNameToShapeCache.

Referenced by preLoadShapes(), and NL3D::CAnimationSet::preloadSSSShapes().

bool NL3D::CShapeBank::isShapeWaiting (  ) 

Definition at line 593 of file shape_bank.cpp.

References WaitingShapes.

void NL3D::CShapeBank::linkShapeToShapeCache ( const std::string &  shapeName,
const std::string &  shapeCacheName 
)
void NL3D::CShapeBank::load ( const std::string &  shapeName  ) 
void NL3D::CShapeBank::loadAsync ( const std::string &  shapeName,
IDriver pDriver,
const NLMISC::CVector position,
bool bSignal,
uint  selectedTexture 
)

Load the corresponding file from disk asynchronously and add it to the bank.

The driver passed to this function is used to know if we have to load the textures.

Definition at line 499 of file shape_bank.cpp.

References _pDriver, NL3D::CShapeBank::CWaitingShape::RefCnt, ShapeMap, NL3D::CShapeBank::CWaitingShape::Signal, NLMISC::toLower(), and WaitingShapes.

Referenced by NL3D::CInstanceGroup::addToSceneAsync(), and NL3D::CScene::createInstanceAsync().

void NL3D::CShapeBank::preLoadShapes ( const std::string &  shapeCacheName,
const std::vector< std::string > &  listFile,
const std::string &  wildCardNotLwr,
NLMISC::IProgressCallback progress = NULL,
bool  flushTextures = false,
IDriver drv = NULL 
)

PreLoad all shapes (.shape, .ps, .skel.

..) files from a list of files Shapes are Loaded if not present, assigned to the given cache, and fit in the cache Size as max possible. NB: crash if you try to load a non shape file (eg: a .dds etc...)

Parameters:
shapeCacheName name of a shapeCache created with addShapeCache()/setShapeCacheSize(). no-op if don't exist
fileList a list of file names. NB: CPath is used to load the shapes.
wildcard a filter string like: "*.shape", "??_HOM*.shape". NB: toLower-ed internally
flushTextures if true, then textures are flushed in the driver drv

Definition at line 856 of file shape_bank.cpp.

References addRef(), NL3D::IShape::flushTextures(), NLMISC::CFile::getFilename(), getPresentState(), getShapeCacheFreeSpace(), isShapeCache(), linkShapeToShapeCache(), load(), NotPresent, Present, NLMISC::IProgressCallback::progress(), release(), NLMISC::testWildCard(), and NLMISC::toLower().

Referenced by NL3D::CShapeBankUser::preLoadShapesFromBNP(), and NL3D::CShapeBankUser::preLoadShapesFromDirectory().

void NL3D::CShapeBank::processWaitingShapes (  ) 
bool NL3D::CShapeBank::processWSUploadTexture ( CWaitingShape rWS,
uint32 nTotalUploaded,
ITexture pText 
) [private]
void NL3D::CShapeBank::release ( IShape pShp  ) 
void NL3D::CShapeBank::removeShapeCache ( const std::string &  shapeCacheName  ) 

Remove a ShapeCache.

All shapes in the shape cache are deleted. All links are redirected to the default ShapeCache

Definition at line 658 of file shape_bank.cpp.

References checkShapeCache(), getShapeCachePtrFromShapeCacheName(), NL3D::CShapeBank::CShapeCache::MaxSize, ShapeCacheNameToShapeCache, and ShapeNameToShapeCacheName.

Referenced by NL3D::CShapeBankUser::removeShapeCache().

void NL3D::CShapeBank::reset (  ) 

Remove all ShapeCache and suppress all links (even the link to the default cache are removed).

Definition at line 685 of file shape_bank.cpp.

References addShapeCache(), checkShapeCache(), getShapeCachePtrFromShapeCacheName(), NL3D::CShapeBank::CShapeCache::MaxSize, nlstop, ShapeCacheNameToShapeCache, and ShapeNameToShapeCacheName.

Referenced by NL3D::CShapeBankUser::reset().

void NL3D::CShapeBank::setMaxBytesToUpload ( uint32  MaxUploadPerFrame  ) 

Setup the maximum number of bytes to upload for a frame (texture upload from RAM to VRAM).

Definition at line 329 of file shape_bank.cpp.

References _MaxUploadPerFrame.

Referenced by NL3D::CScene::updateWaitingInstances().

void NL3D::CShapeBank::setShapeCacheSize ( const std::string &  shapeCacheName,
sint32  maxSize 
)

Set the shapeCache shapeCacheName the new size.(delete shapes if maxsize<shapeCacheSize).

Definition at line 706 of file shape_bank.cpp.

References checkShapeCache(), getShapeCachePtrFromShapeCacheName(), and ShapeCacheNameToShapeCache.

Referenced by NL3D::CAnimationSet::preloadSSSShapes(), and NL3D::CShapeBankUser::setShapeCacheSize().


Member Data Documentation

Definition at line 209 of file shape_bank.h.

Referenced by loadAsync(), processWaitingShapes(), and processWSUploadTexture().

std::set<std::string> NL3D::CShapeBank::_ShapeNeedingSystemGeometryCopy [private]

Definition at line 244 of file shape_bank.h.

Referenced by add(), and buildSystemGeometryForshape().


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

Generated on Thu Jan 7 08:30:11 2010 for NeL by  doxygen 1.6.1