LCOV - code coverage report
Current view: top level - source/graphics - MeshManager.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 19 22 86.4 %
Date: 2023-01-19 00:18:29 Functions: 5 5 100.0 %

          Line data    Source code
       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             : 
      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"
      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             : 
      32          11 : CMeshManager::CMeshManager(CColladaManager& colladaManager)
      33          11 : : m_ColladaManager(colladaManager)
      34             : {
      35          11 : }
      36             : 
      37          11 : CMeshManager::~CMeshManager()
      38             : {
      39          11 : }
      40             : 
      41          11 : CModelDefPtr CMeshManager::GetMesh(const VfsPath& pathname)
      42             : {
      43          22 :     const VfsPath name = pathname.ChangeExtension(L"");
      44             : 
      45             :     // Find the mesh if it's already been loaded and cached
      46          11 :     mesh_map::iterator iter = m_MeshMap.find(name);
      47          11 :     if (iter != m_MeshMap.end() && !iter->second.expired())
      48           1 :         return CModelDefPtr(iter->second);
      49             : 
      50          20 :     PROFILE("load mesh");
      51             : 
      52          20 :     VfsPath pmdFilename = m_ColladaManager.GetLoadablePath(name, CColladaManager::PMD);
      53             : 
      54          10 :     if (pmdFilename.empty())
      55             :     {
      56           4 :         LOGERROR("Could not load mesh '%s'", pathname.string8());
      57           4 :         return CModelDefPtr();
      58             :     }
      59             : 
      60             :     try
      61             :     {
      62          12 :         CModelDefPtr model (CModelDef::Load(pmdFilename, name));
      63           6 :         m_MeshMap[name] = model;
      64           6 :         return model;
      65             :     }
      66           0 :     catch (PSERROR_File&)
      67             :     {
      68           0 :         LOGERROR("Could not load mesh '%s'", pmdFilename.string8());
      69           0 :         return CModelDefPtr();
      70             :     }
      71           3 : }

Generated by: LCOV version 1.13