NL3D::CAsyncFileManager3D::CMeshLoad Class Reference

Inheritance diagram for NL3D::CAsyncFileManager3D::CMeshLoad:

NLMISC::IRunnablePos NLMISC::IRunnable

Public Member Functions

 CMeshLoad (const std::string &meshName, IShape **ppShp, IDriver *pDriver, const CVector &position, uint selectedTexture)
void getName (std::string &result) const
void run (void)

Data Fields

std::string MeshName
NLMISC::CVector Position

Private Attributes

IDriver_pDriver
IShape ** _ppShp
uint _SelectedTexture

Constructor & Destructor Documentation

NL3D::CAsyncFileManager3D::CMeshLoad::CMeshLoad const std::string &  meshName,
IShape **  ppShp,
IDriver pDriver,
const CVector position,
uint  selectedTexture
 

Definition at line 220 of file async_file_manager_3d.cpp.

References _pDriver, _ppShp, _SelectedTexture, MeshName, and uint.

00221 {
00222         _pDriver = pDriver;
00223         MeshName = sMeshName;
00224         _ppShp = ppShp;
00225         Position = position;
00226         _SelectedTexture = selectedTexture;
00227 }


Member Function Documentation

void NL3D::CAsyncFileManager3D::CMeshLoad::getName std::string &  result  )  const [virtual]
 

Reimplemented from NLMISC::IRunnable.

Definition at line 358 of file async_file_manager_3d.cpp.

References MeshName.

00359 {
00360         result = "LoadMesh (" + MeshName + ")";
00361 }

void NL3D::CAsyncFileManager3D::CMeshLoad::run void   )  [virtual]
 

Implements NLMISC::IRunnable.

Definition at line 231 of file async_file_manager_3d.cpp.

References _pDriver, _ppShp, _SelectedTexture, NLMISC::CIFile::close(), NL3D::ITexture::generate(), NL3D::CMaterial::getLightMap(), NL3D::CMeshBase::getMaterial(), NL3D::CMeshBase::getNbMaterial(), NL3D::CMaterial::getShader(), NL3D::CShapeStream::getShapePointer(), NL3D::ITexture::getShareName(), NL3D::CMaterial::getTexture(), NL3D::IDRV_MAT_MAXTEXTURES, NL3D::IDriver::isTextureExist(), MeshName, NL3D_MEM_INSTANCE, nlwarning, NLMISC::CIFile::open(), NL3D::ITexture::selectTexture(), NLMISC::IStream::serial(), NLMISC::CIFile::setAsyncLoading(), NLMISC::CIFile::setCacheFileOnOpen(), NL3D::ITexture::supportSharing(), NL3D::CMaterial::texturePresent(), and uint.

00232 {
00233         NL3D_MEM_INSTANCE
00234         // This set represent the texture already loaded in memory
00235         // We have to have this set because the driver load the textures only on the 
00236         // setupTexture, done in CShapeBank::isPresent. This must be done in the main
00237         // thread because setupTexture upload texture to VRAM.
00238         typedef set<string> TAlreadyPresentTextureSet;
00239         TAlreadyPresentTextureSet AlreadyPresentTextureSet;
00240 
00241         try
00242         {
00243                 // Load from file the mesh
00244                 CShapeStream mesh;
00245                 CIFile meshfile;
00246                 meshfile.setAsyncLoading (true);
00247                 meshfile.setCacheFileOnOpen (true);
00248                 meshfile.open (CPath::lookup(MeshName));
00249                 meshfile.serial (mesh);
00250                 meshfile.close ();
00251 
00252                 // Is the pointer is invalid return -1
00253                 if (mesh.getShapePointer() == NULL)
00254                 {
00255                         nlwarning ("Couldn't load '%s'", MeshName.c_str());
00256                         *_ppShp = (IShape*)-1;
00257                         delete this;
00258                         return;
00259                 }
00260 
00261                 CMeshBase *pMesh = dynamic_cast<CMeshBase *>(mesh.getShapePointer());
00262 
00263                 // If the shape is a mesh but the driver is not given or if the shape is not a mesh 
00264                 // so do not try to load the textures
00265 
00266                 if ((pMesh == NULL) || ((pMesh != NULL) && (_pDriver == NULL)))
00267                 {
00268                         if (_pDriver == NULL || mesh.getShapePointer() == NULL)
00269                         {                       
00270                                 nlwarning ("mesh or driver is NULL for file '%s'", MeshName.c_str());
00271                         }
00272                         
00273                         *_ppShp = mesh.getShapePointer();
00274                         delete this;
00275                         return;
00276                 }
00277 
00278                 // Here we are sure that the shape is a mesh and the driver is not null
00279                 // Parse all materials of the mesh
00280                 uint i, j;
00281                 uint nNbMat = pMesh->getNbMaterial();
00282                 ITexture *pText;
00283 
00284                 for(i = 0; i < nNbMat; ++i)
00285                 {
00286                         const CMaterial &rMat = pMesh->getMaterial(i);
00287                         // Parse all textures from this material and generate them
00288                         for(j = 0; j < IDRV_MAT_MAXTEXTURES; ++j)
00289                         if (rMat.texturePresent(j))
00290                         {
00291                                 pText = rMat.getTexture (j);
00292 
00293                                 // Does this texture is a texture file ?
00294                                 if ((pText != NULL) && (pText->supportSharing()))
00295                                 {
00296                                         // Set texture slot
00297                                         pText->selectTexture(_SelectedTexture);
00298 
00299                                         // Yes -> Does the texture is already present in the driver ?
00300                                         if( ! _pDriver->isTextureExist(*pText) )
00301                                         {
00302                                                 // No -> So we have perhaps to load it
00303                                                 TAlreadyPresentTextureSet::iterator aptmIt = AlreadyPresentTextureSet.find (pText->getShareName());
00304                                                 // Is the texture already loaded ?
00305                                                 if(aptmIt == AlreadyPresentTextureSet.end())
00306                                                 {
00307                                                         // Texture not already present
00308                                                         // add it
00309                                                         AlreadyPresentTextureSet.insert (pText->getShareName());
00310                                                         // And load it (to RAM only (upload in VRAM is done in the shape bank))
00311                                                         pText->generate(true);
00312                                                 }
00313                                         }
00314                                 }
00315                         }
00316 
00317                         // Do the same with lightmaps
00318                         if (rMat.getShader() == CMaterial::LightMap)
00319                         {
00320                                 j = 0; pText = rMat.getLightMap (j);
00321                                 while (pText != NULL)
00322                                 {
00323                                         // Does this texture is a texture file ?
00324                                         if ((pText != NULL) && (pText->supportSharing()))
00325                                         {
00326                                                 // Yes -> Does the texture is already present in the driver ?
00327                                                 if (!_pDriver->isTextureExist(*pText))
00328                                                 {
00329                                                         // No -> So we have perhaps to load it
00330                                                         TAlreadyPresentTextureSet::iterator aptmIt = AlreadyPresentTextureSet.find (pText->getShareName());
00331                                                         // Is the texture already loaded ?
00332                                                         if(aptmIt == AlreadyPresentTextureSet.end())
00333                                                         {
00334                                                                 // Texture not already present -> add it and load it to RAM
00335                                                                 AlreadyPresentTextureSet.insert (pText->getShareName());
00336                                                                 pText->generate(true);
00337                                                         }
00338                                                 }                               
00339                                         }
00340                                         ++j; pText = rMat.getLightMap (j);
00341                                 }
00342                         }
00343                 }
00344                 // Finally affect the pointer (Trans-Thread operation -> this operation must be atomic)
00345                 *_ppShp = mesh.getShapePointer();
00346         }
00347         catch(EPathNotFound &)
00348         {
00349                 nlwarning ("Couldn't load '%s'", MeshName.c_str());
00350                 *_ppShp = (IShape*)-1;
00351                 delete this;
00352                 return;
00353         }
00354         delete this;
00355 }


Field Documentation

IDriver* NL3D::CAsyncFileManager3D::CMeshLoad::_pDriver [private]
 

Definition at line 93 of file async_file_manager_3d.h.

Referenced by CMeshLoad(), and run().

IShape** NL3D::CAsyncFileManager3D::CMeshLoad::_ppShp [private]
 

Definition at line 92 of file async_file_manager_3d.h.

Referenced by CMeshLoad(), and run().

uint NL3D::CAsyncFileManager3D::CMeshLoad::_SelectedTexture [private]
 

Definition at line 94 of file async_file_manager_3d.h.

Referenced by CMeshLoad(), and run().

std::string NL3D::CAsyncFileManager3D::CMeshLoad::MeshName
 

Definition at line 96 of file async_file_manager_3d.h.

Referenced by NL3D::CLoadMeshCancel::callback(), CMeshLoad(), getName(), and run().

NLMISC::CVector NLMISC::IRunnablePos::Position [inherited]
 

Definition at line 46 of file task_manager.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:44:31 2004 for NeL by doxygen 1.3.6