1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
20 #include "MeshManager.h"
22 #include "graphics/ColladaManager.h"
23 #include "graphics/ModelDef.h"
24 #include "ps/CLogger.h"
25 #include "ps/FileIo.h" // to get access to its CError
26 #include "ps/Profile.h"
28 // TODO: should this cache models while they're not actively in the game?
29 // (Currently they'll probably be deleted when the reference count drops to 0,
30 // even if it's quite possible that they'll get reloaded very soon.)
32 CMeshManager::CMeshManager(CColladaManager
& colladaManager
)
33 : m_ColladaManager(colladaManager
)
37 CMeshManager::~CMeshManager()
41 CModelDefPtr
CMeshManager::GetMesh(const VfsPath
& pathname
)
43 const VfsPath name
= pathname
.ChangeExtension(L
"");
45 // Find the mesh if it's already been loaded and cached
46 mesh_map::iterator iter
= m_MeshMap
.find(name
);
47 if (iter
!= m_MeshMap
.end() && !iter
->second
.expired())
48 return CModelDefPtr(iter
->second
);
52 VfsPath pmdFilename
= m_ColladaManager
.GetLoadablePath(name
, CColladaManager::PMD
);
54 if (pmdFilename
.empty())
56 LOGERROR("Could not load mesh '%s'", pathname
.string8());
57 return CModelDefPtr();
62 CModelDefPtr
model (CModelDef::Load(pmdFilename
, name
));
63 m_MeshMap
[name
] = model
;
68 LOGERROR("Could not load mesh '%s'", pmdFilename
.string8());
69 return CModelDefPtr();