2004-11-08 14:02:01 -08:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
#include "graphics/MeshManager.h"
|
|
|
|
|
#include "CLogger.h"
|
2004-12-12 10:40:00 -08:00
|
|
|
#include "FileUnpacker.h" // to get access to its CError
|
2004-12-12 11:43:55 -08:00
|
|
|
#include "ModelDef.h"
|
2004-11-08 14:02:01 -08:00
|
|
|
|
|
|
|
|
CMeshManager::CMeshManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMeshManager::~CMeshManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 10:40:00 -08:00
|
|
|
CModelDefPtr CMeshManager::GetMesh(const char *filename)
|
2004-11-08 14:02:01 -08:00
|
|
|
{
|
2005-01-11 08:58:16 -08:00
|
|
|
CStr fn(filename);
|
2004-12-12 10:40:00 -08:00
|
|
|
mesh_map::iterator iter = m_MeshMap.find(fn);
|
2005-01-11 08:58:16 -08:00
|
|
|
if (iter != m_MeshMap.end())
|
|
|
|
|
{
|
2004-12-12 10:40:00 -08:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CModelDefPtr model (iter->second);
|
2005-01-12 16:17:31 -08:00
|
|
|
//LOG(MESSAGE, "mesh", "Loading mesh '%s%' (cached)...", filename);
|
2004-12-12 10:40:00 -08:00
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
// If the mesh has already been deleted, the weak_ptr -> shared_ptr
|
|
|
|
|
// conversion will throw bad_weak_ptr (and we need to reload the mesh)
|
|
|
|
|
catch (boost::bad_weak_ptr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-11-10 23:09:32 -08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2004-12-12 10:40:00 -08:00
|
|
|
CModelDefPtr model (CModelDef::Load(filename));
|
|
|
|
|
if (!model)
|
|
|
|
|
return CModelDefPtr();
|
|
|
|
|
|
2005-01-12 16:17:31 -08:00
|
|
|
//LOG(MESSAGE, "mesh", "Loading mesh '%s'...", filename);
|
2004-12-12 10:40:00 -08:00
|
|
|
m_MeshMap[fn] = model;
|
|
|
|
|
return model;
|
2004-11-10 23:09:32 -08:00
|
|
|
}
|
2004-12-12 10:40:00 -08:00
|
|
|
catch (CFileUnpacker::CError)
|
2004-11-10 23:09:32 -08:00
|
|
|
{
|
2005-01-11 08:58:16 -08:00
|
|
|
LOG(ERROR, "mesh", "Could not load mesh '%s'!", filename);
|
2004-12-12 10:40:00 -08:00
|
|
|
return CModelDefPtr();
|
2004-11-10 23:09:32 -08:00
|
|
|
}
|
2004-11-08 14:02:01 -08:00
|
|
|
}
|