Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MeshManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "MeshManager.h"
21 
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"
27 
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.)
31 
33 : m_ColladaManager(colladaManager)
34 {
35 }
36 
38 {
39 }
40 
42 {
43  const VfsPath name = pathname.ChangeExtension(L"");
44 
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);
49 
50  PROFILE("load mesh");
51 
53 
54  if (pmdFilename.empty())
55  {
56  LOGERROR(L"Could not load mesh '%ls'", pathname.string().c_str());
57  return CModelDefPtr();
58  }
59 
60  try
61  {
62  CModelDefPtr model (CModelDef::Load(pmdFilename, name));
63  m_MeshMap[name] = model;
64  return model;
65  }
66  catch (PSERROR_File&)
67  {
68  LOGERROR(L"Could not load mesh '%ls'", pmdFilename.string().c_str());
69  return CModelDefPtr();
70  }
71 }
CColladaManager & m_ColladaManager
Definition: MeshManager.h:44
VfsPath GetLoadablePath(const VfsPath &pathnameNoExtension, FileType type)
Returns the VFS path to a PMD/PSA file for the given source file.
#define LOGERROR
Definition: CLogger.h:35
CMeshManager(CColladaManager &colladaManager)
Definition: MeshManager.cpp:32
static CModelDef * Load(const VfsPath &filename, const VfsPath &name)
Loads a PMD file.
Definition: ModelDef.cpp:261
Definition: path.h:75
const String & string() const
Definition: path.h:123
#define PROFILE(name)
Definition: Profile.h:195
bool empty() const
Definition: path.h:118
Path ChangeExtension(Path extension) const
Definition: path.h:185
static size_t model
Definition: x86_x64.cpp:211
CModelDefPtr GetMesh(const VfsPath &pathname)
Definition: MeshManager.cpp:41
mesh_map m_MeshMap
Definition: MeshManager.h:43
boost::shared_ptr< CModelDef > CModelDefPtr
Definition: MeshManager.h:27