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: 5 6 83.3 %
Date: 2023-01-19 00:18:29 Functions: 8 13 61.5 %

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

Generated by: LCOV version 1.13