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: 21 25 84.0 %
Date: 2026-12-03 01:19:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 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             : #include <string>
      29             : #include <utility>
      30             : 
      31             : // TODO: should this cache models while they're not actively in the game?
      32             : // (Currently they'll probably be deleted when the reference count drops to 0,
      33             : // even if it's quite possible that they'll get reloaded very soon.)
      34             : 
      35          12 : CMeshManager::CMeshManager(CColladaManager& colladaManager)
      36          12 : : m_ColladaManager(colladaManager)
      37             : {
      38          12 : }
      39             : 
      40          12 : CMeshManager::~CMeshManager()
      41             : {
      42          12 : }
      43             : 
      44          12 : CModelDefPtr CMeshManager::GetMesh(const VfsPath& pathname)
      45             : {
      46          12 :     const VfsPath name = pathname.ChangeExtension(L"");
      47             : 
      48             :     // Find the mesh if it's already been loaded and cached
      49          12 :     mesh_map::iterator iter = m_MeshMap.find(name);
      50          12 :     if (iter != m_MeshMap.end() && !iter->second.expired())
      51          13 :         return CModelDefPtr(iter->second);
      52             : 
      53          11 :     PROFILE("load mesh");
      54             : 
      55          11 :     VfsPath pmdFilename = m_ColladaManager.GetLoadablePath(name, CColladaManager::PMD);
      56             : 
      57          11 :     if (pmdFilename.empty())
      58             :     {
      59          12 :         LOGERROR("Could not load mesh '{}'", pathname.string8());
      60          11 :         return CModelDefPtr();
      61             :     }
      62             : 
      63           7 :     try
      64             :     {
      65           7 :         CModelDefPtr model (CModelDef::Load(pmdFilename, name));
      66           7 :         m_MeshMap[name] = model;
      67           7 :         return model;
      68           7 :     }
      69           0 :     catch (PSERROR_File&)
      70             :     {
      71           0 :         LOGERROR("Could not load mesh '{}'", pmdFilename.string8());
      72           0 :         return CModelDefPtr();
      73           0 :     }
      74          23 : }

Generated by: LCOV version 1.16