LCOV - code coverage report
Current view: top level - source/simulation2/components - CCmpParticleManager.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 13 30 43.3 %
Date: 2023-01-19 00:18:29 Functions: 12 17 70.6 %

          Line data    Source code
       1             : /* Copyright (C) 2022 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 "simulation2/system/Component.h"
      21             : #include "ICmpParticleManager.h"
      22             : 
      23             : #include "graphics/ParticleManager.h"
      24             : #include "renderer/Renderer.h"
      25             : #include "renderer/SceneRenderer.h"
      26             : #include "simulation2/MessageTypes.h"
      27             : 
      28           9 : class CCmpParticleManager final : public ICmpParticleManager
      29             : {
      30             : public:
      31         116 :     static void ClassInit(CComponentManager& componentManager)
      32             :     {
      33         116 :         componentManager.SubscribeToMessageType(MT_Interpolate);
      34         116 :     }
      35             : 
      36           6 :     DEFAULT_COMPONENT_ALLOCATOR(ParticleManager)
      37             : 
      38             :     bool useSimTime;
      39             : 
      40         116 :     static std::string GetSchema()
      41             :     {
      42         116 :         return "<a:component type='system'/><empty/>";
      43             :     }
      44             : 
      45           3 :     void Init(const CParamNode& UNUSED(paramNode)) override
      46             :     {
      47           3 :         useSimTime = true;
      48           3 :     }
      49             : 
      50           3 :     void Deinit() override
      51             :     {
      52           3 :     }
      53             : 
      54           0 :     void Serialize(ISerializer& UNUSED(serialize)) override
      55             :     {
      56           0 :     }
      57             : 
      58           0 :     void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override
      59             :     {
      60           0 :         Init(paramNode);
      61           0 :     }
      62             : 
      63           0 :     void HandleMessage(const CMessage& msg, bool UNUSED(global)) override
      64             :     {
      65           0 :         switch (msg.GetType())
      66             :         {
      67           0 :         case MT_Interpolate:
      68             :         {
      69           0 :             const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
      70           0 :             if (CRenderer::IsInitialised())
      71             :             {
      72           0 :                 float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime;
      73           0 :                 g_Renderer.GetSceneRenderer().GetParticleManager().Interpolate(time);
      74             :             }
      75           0 :             break;
      76             :         }
      77             :         }
      78           0 :     }
      79             : 
      80           0 :     void SetUseSimTime(bool flag) override
      81             :     {
      82           0 :         useSimTime = flag;
      83           0 :     }
      84             : };
      85             : 
      86         119 : REGISTER_COMPONENT_TYPE(ParticleManager)

Generated by: LCOV version 1.13