LCOV - code coverage report
Current view: top level - source/graphics - UnitManager.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 12 22 54.5 %
Date: 2026-12-03 01:19:39 Functions: 3 6 50.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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 "graphics/ModelAbstract.h"
      21             : #include "graphics/RenderableObject.h"
      22             : #include "graphics/Unit.h"
      23             : #include "graphics/UnitManager.h"
      24             : 
      25             : #include <algorithm>
      26             : #include <cstddef>
      27             : #include <utility>
      28             : 
      29             : ///////////////////////////////////////////////////////////////////////////////
      30             : // CUnitManager constructor
      31           4 : CUnitManager::CUnitManager() :
      32           4 :     m_ObjectManager(NULL)
      33             : {
      34           4 : }
      35             : 
      36             : ///////////////////////////////////////////////////////////////////////////////
      37             : // CUnitManager destructor
      38           4 : CUnitManager::~CUnitManager() = default;
      39             : 
      40             : 
      41             : ///////////////////////////////////////////////////////////////////////////////
      42             : // AddUnit: add given unit to world
      43           1 : CUnit* CUnitManager::AddUnit(std::unique_ptr<CUnit> unit)
      44             : {
      45           1 :     return m_Units.emplace_back(std::move(unit)).get();
      46             : }
      47             : 
      48             : 
      49             : ///////////////////////////////////////////////////////////////////////////////
      50             : // DeleteUnit: remove given unit from world and delete it
      51           0 : void CUnitManager::DeleteUnit(CUnit* unit)
      52             : {
      53           0 :     const auto it = std::find_if(m_Units.begin(), m_Units.end(), [&](const std::unique_ptr<CUnit>& elem)
      54             :         {
      55           0 :             return elem.get() == unit;
      56             :         });
      57             : 
      58           0 :     if (it != m_Units.end())
      59           0 :         m_Units.erase(it);
      60           0 : }
      61             : 
      62             : ///////////////////////////////////////////////////////////////////////////////
      63             : // CreateUnit: create a new unit and add it to the world
      64         196 : CUnit* CUnitManager::CreateUnit(const CStrW& actorName, const entity_id_t id, const uint32_t seed)
      65             : {
      66         196 :     if (!m_ObjectManager)
      67             :         return nullptr;
      68             : 
      69           1 :     std::unique_ptr<CUnit> unit{CUnit::Create(actorName, id, seed, *m_ObjectManager)};
      70           1 :     if (!unit)
      71             :         return nullptr;
      72             : 
      73           1 :     return AddUnit(std::move(unit));
      74           1 : }
      75             : 
      76           0 : void CUnitManager::MakeTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags)
      77             : {
      78           0 :     if (!(dirtyFlags & RENDERDATA_UPDATE_VERTICES))
      79             :         return;
      80           0 :     for (const std::unique_ptr<CUnit>& unit : m_Units)
      81           0 :         unit->GetModel().SetTerrainDirty(i0, j0, i1, j1);
      82             : }

Generated by: LCOV version 1.16