LCOV - code coverage report
Current view: top level - source/graphics - CinemaManager.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 58 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 8 0.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 "CinemaManager.h"
      21             : 
      22             : #include "graphics/Color.h"
      23             : #include "graphics/Terrain.h"
      24             : #include "maths/FixedVector3D.h"
      25             : #include "maths/NUSpline.h"
      26             : #include "maths/Vector3D.h"
      27             : #include "ps/CStr.h"
      28             : #include "ps/Game.h"
      29             : #include "ps/World.h"
      30             : #include "renderer/DebugRenderer.h"
      31             : #include "renderer/Renderer.h"
      32             : #include "renderer/RenderingOptions.h"
      33             : #include "simulation2/Simulation2.h"
      34             : #include "simulation2/components/ICmpCinemaManager.h"
      35             : #include "simulation2/helpers/CinemaPath.h"
      36             : #include "simulation2/system/Component.h"
      37             : 
      38             : #include <map>
      39             : #include <utility>
      40             : #include <vector>
      41             : 
      42           0 : void CCinemaManager::Update(const float deltaRealTime, CCamera& camera)
      43             : {
      44           0 :     CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
      45           0 :     if (!cmpCinemaManager)
      46           0 :         return;
      47             : 
      48           0 :     if (IsPlaying())
      49             :     {
      50           0 :         if (g_RenderingOptions.GetSmoothLOS())
      51             :         {
      52           0 :             g_RenderingOptions.SetSmoothLOS(false);
      53           0 :             m_SmoothLosOverridden = true;
      54             :         }
      55           0 :         cmpCinemaManager->UpdateActivePath(deltaRealTime, camera);
      56           0 :         return;
      57             :     }
      58             : 
      59           0 :     if (std::exchange(m_SmoothLosOverridden, false))
      60           0 :         g_RenderingOptions.SetSmoothLOS(true);
      61             : }
      62             : 
      63           0 : void CCinemaManager::Render(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const
      64             : {
      65           0 :     if (!IsPlaying() && m_DrawPaths)
      66           0 :         DrawPaths(deviceCommandContext);
      67           0 : }
      68             : 
      69           0 : void CCinemaManager::DrawPaths(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const
      70             : {
      71           0 :     CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
      72           0 :     if (!cmpCinemaManager)
      73           0 :         return;
      74             : 
      75           0 :     for (const std::pair<const CStrW, CCinemaPath>& p : cmpCinemaManager->GetPaths())
      76             :     {
      77           0 :         DrawSpline(deviceCommandContext, p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 128);
      78           0 :         DrawNodes(deviceCommandContext, p.second, CColor(0.1f, 1.f, 0.f, 1.f));
      79             : 
      80           0 :         if (p.second.GetTargetSpline().GetAllNodes().empty())
      81           0 :             continue;
      82             : 
      83           0 :         DrawSpline(deviceCommandContext, p.second.GetTargetSpline(), CColor(1.f, 0.3f, 0.4f, 0.9f), 128);
      84           0 :         DrawNodes(deviceCommandContext, p.second.GetTargetSpline(), CColor(1.f, 0.1f, 0.f, 1.f));
      85             :     }
      86             : }
      87             : 
      88           0 : void CCinemaManager::DrawSpline(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& splineColor, int smoothness) const
      89             : {
      90           0 :     if (spline.GetAllNodes().size() < 2)
      91           0 :         return;
      92           0 :     if (spline.GetAllNodes().size() == 2)
      93           0 :         smoothness = 2;
      94             : 
      95           0 :     const float start = spline.GetMaxDistance().ToFloat() / smoothness;
      96             : 
      97           0 :     std::vector<CVector3D> line;
      98           0 :     for (int i = 0; i <= smoothness; ++i)
      99             :     {
     100           0 :         const float time = start * i / spline.GetMaxDistance().ToFloat();
     101           0 :         line.emplace_back(spline.GetPosition(time));
     102             :     }
     103             : 
     104           0 :     g_Renderer.GetDebugRenderer().DrawLine(deviceCommandContext, line, splineColor, 0.2f, false);
     105             : 
     106             :     // Height indicator
     107           0 :     if (g_Game && g_Game->GetWorld())
     108             :     {
     109           0 :         for (int i = 0; i <= smoothness; ++i)
     110             :         {
     111           0 :             const float time = start * i / spline.GetMaxDistance().ToFloat();
     112           0 :             const CVector3D tmp = spline.GetPosition(time);
     113           0 :             const float groundY = g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(tmp.X, tmp.Z);
     114           0 :             g_Renderer.GetDebugRenderer().DrawLine(deviceCommandContext, tmp, CVector3D(tmp.X, groundY, tmp.Z), splineColor, 0.1f, false);
     115             :         }
     116             :     }
     117           0 : }
     118             : 
     119           0 : void CCinemaManager::DrawNodes(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& nodeColor) const
     120             : {
     121           0 :     for (const SplineData& node : spline.GetAllNodes())
     122             :     {
     123           0 :         g_Renderer.GetDebugRenderer().DrawCircle(
     124             :             deviceCommandContext,
     125           0 :             CVector3D(node.Position.X.ToFloat(), node.Position.Y.ToFloat(), node.Position.Z.ToFloat()),
     126             :             0.5f, nodeColor);
     127             :     }
     128           0 : }
     129             : 
     130           0 : bool CCinemaManager::IsPlaying() const
     131             : {
     132           0 :     CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
     133           0 :     return cmpCinemaManager && cmpCinemaManager->IsPlayingQueue();
     134             : }
     135             : 
     136           0 : bool CCinemaManager::GetPathsDrawing() const
     137             : {
     138           0 :     return m_DrawPaths;
     139             : }
     140             : 
     141           0 : void CCinemaManager::SetPathsDrawing(const bool drawPath)
     142             : {
     143           0 :     m_DrawPaths = drawPath;
     144           0 : }

Generated by: LCOV version 1.16