LCOV - code coverage report
Current view: top level - source/simulation2/helpers - CinemaPath.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 3 3 100.0 %
Date: 2026-12-03 01:19:39 Functions: 2 3 66.7 %

          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             : #ifndef INCLUDED_CINEMAPATH
      19             : #define INCLUDED_CINEMAPATH
      20             : 
      21             : #include "maths/Fixed.h"
      22             : #include "maths/NUSpline.h"
      23             : #include "maths/Vector3D.h"
      24             : #include "ps/CStr.h"
      25             : 
      26             : #include <cstddef>
      27             : 
      28             : class CCamera;
      29             : 
      30             : class CCinemaData
      31             : {
      32             : public:
      33           7 :     CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
      34         112 :     virtual ~CCinemaData() {}
      35             : 
      36             :     const CCinemaData* GetData() const { return this; }
      37             : 
      38             :     CStrW m_Name;
      39             :     CStrW m_Orientation;
      40             :     CStrW m_Mode;
      41             :     CStrW m_Style;
      42             : 
      43             :     bool m_LookAtTarget;
      44             : 
      45             :     // A value by which the total duration is multiplied, e.g. values less than 1 result in the path
      46             :     // playing faster. Must be greater than 0.
      47             :     fixed m_Timescale;
      48             : 
      49             :     // Distortion variables
      50             :     mutable float m_GrowthCount;
      51             :     float m_Growth;
      52             :     float m_Switch;
      53             : };
      54             : 
      55             : 
      56             : // Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
      57             : // This class encompasses the spline and the information which determines how the path will operate
      58             : // and also provides the functionality for doing so
      59             : 
      60             : class CCinemaPath : private CCinemaData, public TNSpline
      61             : {
      62             : public:
      63           6 :     CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
      64             :     CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
      65             : 
      66             :     // Sets camera position to calculated point on spline
      67             :     void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera& camera) const;
      68             : 
      69             :     // Distortion mode functions-change how ratio is passed to distortion style functions
      70             :     float EaseIn(float t) const;
      71             :     float EaseOut(float t) const;
      72             :     float EaseInOut(float t) const;
      73             :     float EaseOutIn(float t) const;
      74             : 
      75             :     // Distortion style functions
      76             :     float EaseDefault(float t) const;
      77             :     float EaseGrowth(float t) const;
      78             :     float EaseExpo(float t) const;
      79             :     float EaseCircle(float t) const;
      80             :     float EaseSine(float t) const;
      81             : 
      82             :     float (CCinemaPath::*DistStylePtr)(float ratio) const;
      83             :     float (CCinemaPath::*DistModePtr)(float ratio) const;
      84             : 
      85             :     const CCinemaData* GetData() const;
      86             : 
      87             : public:
      88             : 
      89             :     CVector3D GetNodePosition(const int index) const;
      90             :     fixed GetNodeDuration(const int index) const;
      91             :     fixed GetDuration() const;
      92             : 
      93             :     float GetNodeFraction() const;
      94             :     float GetElapsedTime() const;
      95             : 
      96             :     const CStrW& GetName() const;
      97             : 
      98             :     void SetTimescale(fixed scale);
      99             : 
     100             :     float m_TimeElapsed;
     101             :     float m_PreviousNodeTime; // How much time has passed before the current node
     102             : 
     103             :     size_t m_CurrentNode;
     104             :     CVector3D m_PreviousRotation;
     105             : 
     106             : public:
     107             : 
     108             :     /**
     109             :      * Returns false if finished.
     110             :      * @param deltaRealTime Elapsed real time since the last frame.
     111             :      * @param camera An affected camera
     112             :      */
     113             :     bool Play(const float deltaRealTime, CCamera& camera);
     114             : 
     115             :     /**
     116             :      * Validate the path
     117             :      * @return true if the path is valid
     118             :      */
     119             :     bool Validate();
     120             : 
     121             :     /**
     122             :      * Returns true if path doesn't contain nodes
     123             :      */
     124             :     bool Empty() const;
     125             : 
     126             :     /**
     127             :      * Resets the path state
     128             :      */
     129             :     void Reset();
     130             : 
     131             :     fixed GetTimescale() const;
     132             : 
     133             :     const TNSpline& GetTargetSpline() const;
     134             : 
     135             : private:
     136             : 
     137             :     TNSpline m_TargetSpline;
     138             : };
     139             : 
     140             : #endif // INCLUDED_CINEMAPATH

Generated by: LCOV version 1.16