LCOV - code coverage report
Current view: top level - source/graphics - ParticleManager.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 8 42 19.0 %
Date: 2023-01-19 00:18:29 Functions: 4 12 33.3 %

          Line data    Source code
       1             : /* Copyright (C) 2019 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 "ParticleManager.h"
      21             : 
      22             : #include "ps/Filesystem.h"
      23             : #include "ps/Profile.h"
      24             : #include "renderer/Scene.h"
      25             : 
      26             : #include <unordered_map>
      27             : 
      28           0 : static Status ReloadChangedFileCB(void* param, const VfsPath& path)
      29             : {
      30           0 :     return static_cast<CParticleManager*>(param)->ReloadChangedFile(path);
      31             : }
      32             : 
      33           6 : CParticleManager::CParticleManager() :
      34           6 :     m_CurrentTime(0.f)
      35             : {
      36           6 :     RegisterFileReloadFunc(ReloadChangedFileCB, this);
      37           6 : }
      38             : 
      39          12 : CParticleManager::~CParticleManager()
      40             : {
      41           6 :     UnregisterFileReloadFunc(ReloadChangedFileCB, this);
      42           6 : }
      43             : 
      44           0 : CParticleEmitterTypePtr CParticleManager::LoadEmitterType(const VfsPath& path)
      45             : {
      46           0 :     std::unordered_map<VfsPath, CParticleEmitterTypePtr>::iterator it = m_EmitterTypes.find(path);
      47           0 :     if (it != m_EmitterTypes.end())
      48           0 :         return it->second;
      49             : 
      50           0 :     CParticleEmitterTypePtr emitterType(new CParticleEmitterType(path, *this));
      51           0 :     m_EmitterTypes[path] = emitterType;
      52           0 :     return emitterType;
      53             : }
      54             : 
      55           0 : void CParticleManager::AddUnattachedEmitter(const CParticleEmitterPtr& emitter)
      56             : {
      57           0 :     m_UnattachedEmitters.push_back(emitter);
      58           0 : }
      59             : 
      60           0 : void CParticleManager::ClearUnattachedEmitters()
      61             : {
      62           0 :     m_UnattachedEmitters.clear();
      63           0 : }
      64             : 
      65           0 : void CParticleManager::Interpolate(const float simFrameLength)
      66             : {
      67           0 :     m_CurrentTime += simFrameLength;
      68           0 : }
      69             : 
      70             : struct EmitterHasNoParticles
      71             : {
      72           0 :     bool operator()(const CParticleEmitterPtr& emitterPtr)
      73             :     {
      74           0 :         CParticleEmitter& emitter = *emitterPtr.get();
      75           0 :         for (size_t i = 0; i < emitter.m_Particles.size(); ++i)
      76             :         {
      77           0 :             SParticle& p = emitter.m_Particles[i];
      78           0 :             if (p.age < p.maxAge)
      79           0 :                 return false;
      80             :         }
      81           0 :         return true;
      82             :     }
      83             : };
      84             : 
      85           0 : void CParticleManager::RenderSubmit(SceneCollector& collector, const CFrustum& UNUSED(frustum))
      86             : {
      87           0 :     PROFILE("submit unattached particles");
      88             : 
      89             :     // Delete any unattached emitters that have no particles left
      90           0 :     m_UnattachedEmitters.remove_if(EmitterHasNoParticles());
      91             : 
      92             :     // TODO: should do some frustum culling
      93             : 
      94           0 :     for (std::list<CParticleEmitterPtr>::iterator it = m_UnattachedEmitters.begin(); it != m_UnattachedEmitters.end(); ++it)
      95           0 :         collector.Submit(it->get());
      96           0 : }
      97             : 
      98           0 : Status CParticleManager::ReloadChangedFile(const VfsPath& path)
      99             : {
     100           0 :     m_EmitterTypes.erase(path);
     101           0 :     return INFO::OK;
     102           3 : }

Generated by: LCOV version 1.13