Ticket #3301: cinematic_camera_core_v1.8c.patch

File cinematic_camera_core_v1.8c.patch, 74.0 KB (added by Vladislav Belov, 8 years ago)

Clean-up, path drawing control fix

  • binaries/data/mods/public/simulation/components/Trigger.js

     
    1919    "Interval",
    2020    "Range",
    2121    "TreasureCollected",
     22    "CinemaPathEnded",
     23    "CinemaQueueEnded"
    2224];
    2325
    2426Trigger.prototype.Init = function()
     
    242244    //                           "tech": tech}
    243245};
    244246
     247// Handles "OnCinemaPathEnded" event.
     248Trigger.prototype.OnGlobalCinemaPathEnded = function(msg)
     249{
     250    this.CallEvent("CinemaPathEnded", msg);
     251}
     252
     253// Handles "OnCinemaQueueEnded" event.
     254Trigger.prototype.OnGlobalCinemaQueueEnded = function(msg)
     255{
     256    this.CallEvent("CinemaQueueEnded", msg);
     257}
     258
    245259Trigger.prototype.OnGlobalOwnershipChanged = function(msg)
    246260{
    247261    this.CallEvent("OwnershipChanged", msg);
  • source/graphics/CinemaManager.cpp

     
    1818
    1919#include "precompiled.h"
    2020
     21#include <sstream>
    2122#include <string>
    22 #include <sstream>
    2323
    24 #include "CinemaManager.h"
    25 
    26 #include "CinemaPath.h"
     24#include "graphics/Camera.h"
     25#include "graphics/CinemaManager.h"
     26#include "graphics/GameView.h"
     27#include "gui/CGUI.h"
     28#include "gui/GUIManager.h"
     29#include "gui/IGUIObject.h"
     30#include "lib/ogl.h"
     31#include "maths/MathUtil.h"
     32#include "maths/Quaternion.h"
     33#include "maths/Vector3D.h"
     34#include "maths/Vector4D.h"
     35#include "ps/CLogger.h"
    2736#include "ps/CStr.h"
    28 #include "maths/Vector4D.h"
     37#include "ps/Game.h"
     38#include "ps/Hotkey.h"
     39#include "simulation2/components/ICmpOverlayRenderer.h"
     40#include "simulation2/components/ICmpRangeManager.h"
     41#include "simulation2/components/ICmpSelectable.h"
     42#include "simulation2/components/ICmpTerritoryManager.h"
     43#include "simulation2/MessageTypes.h"
     44#include "simulation2/system/ComponentManager.h"
     45#include "simulation2/Simulation2.h"
     46#include "renderer/Renderer.h"
    2947
    30 CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false)
     48
     49CCinemaManager::CCinemaManager()
     50    : m_DrawPaths(false)
    3151{
    32     m_CurrentPath = m_Paths.end();
    3352}
    3453
    35 void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name)
     54void CCinemaManager::AddPath(const CStrW& name, const CCinemaPath& path)
    3655{
    37     ENSURE( m_Paths.find( name ) == m_Paths.end() );
    38     m_Paths[name] = path;
     56    if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end())
     57    {
     58        LOGWARNING("Path with name '%s' already exists", name.ToUTF8());
     59        return;
     60    }
     61    m_CinematicSimulationData.m_Paths[name] = path;
    3962}
    4063
    41 void CCinemaManager::QueuePath(const CStrW& name, bool queue)
     64void CCinemaManager::AddPathToQueue(const CStrW& name)
    4265{
    43     if (!m_PathQueue.empty() && queue == false)
     66    if (!HasPath(name))
    4467    {
     68        LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8());
    4569        return;
    4670    }
    47     else
     71    m_CinematicSimulationData.m_PathQueue.push_back(m_CinematicSimulationData.m_Paths[name]);
     72}
     73
     74void CCinemaManager::ClearQueue()
     75{
     76    m_CinematicSimulationData.m_PathQueue.clear();
     77}
     78
     79void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths)
     80{
     81    m_CinematicSimulationData.m_Paths = paths;
     82}
     83
     84bool CCinemaManager::HasPath(const CStrW& name) const
     85{
     86    return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end();
     87}
     88
     89void CCinemaManager::SetEnabled(bool enabled)
     90{
     91    // TODO: maybe assert?
     92    if (m_CinematicSimulationData.m_PathQueue.empty() && enabled)
    4893    {
    49         ENSURE(HasTrack(name));
    50         m_PathQueue.push_back(m_Paths[name]);
     94        enabled = false;
     95        m_CinematicSimulationData.m_Paused = true;
    5196    }
     97
     98    if (m_CinematicSimulationData.m_Enabled == enabled)
     99        return;
     100
     101    // sn - session gui object
     102    IGUIObject *sn = g_GUI->FindObjectByName("sn");
     103    CmpPtr<ICmpRangeManager> cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
     104    CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
     105
     106    // GUI visibility
     107    if (sn)
     108    {
     109        if (enabled)
     110            sn->SetSetting("hidden", L"true");
     111        else
     112            sn->SetSetting("hidden", L"false");
     113    }
     114
     115    // Overlay visibility
     116    g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled);
     117    if (cmpRangeManager)
     118    {
     119        if (enabled)
     120            m_CinematicSimulationData.m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1);
     121        // TODO: improve m_MapRevealed state and without fade in
     122        cmpRangeManager->SetLosRevealAll(-1, enabled);
     123    }
     124    if (cmpTerritoryManager)
     125        cmpTerritoryManager->SetVisibility(!enabled);
     126    ICmpSelectable::SetOverrideVisibility(!enabled);
     127    ICmpOverlayRenderer::SetOverrideVisibility(!enabled);
     128
     129    m_CinematicSimulationData.m_Enabled = enabled;
    52130}
    53131
    54 void CCinemaManager::OverridePath(const CStrW& name)
     132void CCinemaManager::Play()
    55133{
    56     m_PathQueue.clear();
    57     ENSURE(HasTrack(name));
    58     m_PathQueue.push_back( m_Paths[name] );
     134    m_CinematicSimulationData.m_Paused = false;
    59135}
    60136
    61 void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths)
     137void CCinemaManager::Stop()
    62138{
    63     CStrW name;
    64     m_Paths = paths;
     139    m_CinematicSimulationData.m_PathQueue.clear();
    65140}
    66 void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines)
     141
     142void CCinemaManager::Update(const float deltaRealTime)
    67143{
    68     if ( !HasTrack(name) )
    69         m_ValidCurrent = false;
    70     else
    71         m_ValidCurrent = true;
     144    if (g_Game->m_Paused != m_CinematicSimulationData.m_Paused)
     145    {
     146        m_CinematicSimulationData.m_Paused = g_Game->m_Paused;
    72147
    73     m_CurrentPath = m_Paths.find(name);
    74     m_DrawCurrentSpline = current;
    75     m_DrawLines = drawLines;
    76     DrawSpline();
     148        // sn - session gui object
     149        IGUIObject *sn = g_GUI->FindObjectByName("sn");
     150
     151        // GUI visibility
     152        if (sn)
     153        {
     154            if (m_CinematicSimulationData.m_Paused)
     155                sn->SetSetting("hidden", L"false");
     156            else
     157                sn->SetSetting("hidden", L"true");
     158        }
     159    }
     160
     161    if (m_CinematicSimulationData.m_PathQueue.empty() || !m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused)
     162        return;
     163   
     164    if (HotkeyIsPressed("leave"))
     165    {
     166        // TODO: implement skip
     167    }
     168   
     169    m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime);
    77170}
    78171
    79 bool CCinemaManager::HasTrack(const CStrW& name) const
    80 {
    81     return m_Paths.find(name) != m_Paths.end();
     172void CCinemaManager::Render()
     173{
     174    if (GetEnabled())
     175    {
     176        DrawBars();
     177        return;
     178    }
     179   
     180    if (!m_DrawPaths)
     181        return;
     182
     183    // draw all paths
     184    for (auto it : m_CinematicSimulationData.m_Paths)
     185        it.second.Draw();
    82186}
    83187
    84 void CCinemaManager::DrawSpline() const
     188void CCinemaManager::DrawBars() const
    85189{
    86     if ( !(m_DrawCurrentSpline && m_ValidCurrent) )
     190    int height = (float)g_xres / 2.39f;
     191    int shift = (g_yres - height) / 2;
     192    if (shift <= 0)
    87193        return;
    88     static const int smoothness = 200;
    89194
    90     m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines);
     195#if CONFIG2_GLES
     196    #warning TODO : implement bars for GLES
     197#else
     198    // Set up transform for GL bars
     199    glMatrixMode(GL_PROJECTION);
     200    glPushMatrix();
     201    glLoadIdentity();
     202    glMatrixMode(GL_MODELVIEW);
     203    glPushMatrix();
     204    glLoadIdentity();
     205    CMatrix3D transform;
     206    transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
     207    glLoadMatrixf(&transform._11);
     208
     209    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
     210
     211    glEnable(GL_BLEND);
     212    glDisable(GL_DEPTH_TEST);
     213
     214    glBegin(GL_QUADS);
     215    glVertex2i(0, 0);
     216    glVertex2i(g_xres, 0);
     217    glVertex2i(g_xres, shift);
     218    glVertex2i(0, shift);
     219    glEnd();
     220
     221    glBegin(GL_QUADS);
     222    glVertex2i(0, g_yres - shift);
     223    glVertex2i(g_xres, g_yres - shift);
     224    glVertex2i(g_xres, g_yres);
     225    glVertex2i(0, g_yres);
     226    glEnd();
     227
     228    glDisable(GL_BLEND);
     229    glEnable(GL_DEPTH_TEST);
     230
     231    // Restore transform
     232    glMatrixMode(GL_PROJECTION);
     233    glPopMatrix();
     234    glMatrixMode(GL_MODELVIEW);
     235    glPopMatrix();
     236#endif
    91237}
    92238
    93 void CCinemaManager::MoveToPointAt(float time)
     239InReaction cinema_manager_handler(const SDL_Event_* ev)
    94240{
    95     ENSURE(m_CurrentPath != m_Paths.end());
    96     StopPlaying();
     241    // put any events that must be processed even if inactive here
     242    if (!g_Game || !g_Game->IsGameStarted())
     243        return IN_PASS;
    97244
    98     m_CurrentPath->second.m_TimeElapsed = time;
    99     if (!m_CurrentPath->second.Validate())
    100         return;
     245    CCinemaManager* pCinemaManager = g_Game->GetView()->GetCinema();
    101246
    102     m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed /
    103                 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(),
    104                 m_CurrentPath->second.m_PreviousRotation);
     247    return pCinemaManager->HandleEvent(ev);
    105248}
    106249
    107 bool CCinemaManager::Update(const float deltaRealTime)
     250InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev)
    108251{
    109     if (!m_PathQueue.front().Play(deltaRealTime))
     252    switch (ev->ev.type)
    110253    {
    111         m_PathQueue.pop_front();
    112         return false;
     254    case SDL_MOUSEBUTTONDOWN:
     255    case SDL_MOUSEBUTTONUP:
     256        if (GetEnabled() && !m_CinematicSimulationData.m_Paused)
     257            return IN_HANDLED;
     258    default:
     259        return IN_PASS;
    113260    }
    114     return true;
    115261}
     262
     263bool CCinemaManager::GetEnabled() const
     264{
     265    return m_CinematicSimulationData.m_Enabled;
     266}
     267
     268bool CCinemaManager::IsPlaying() const
     269{
     270    return !m_CinematicSimulationData.m_Paused;
     271}
     272
     273const std::map<CStrW, CCinemaPath>& CCinemaManager::GetAllPaths()
     274{
     275    return m_CinematicSimulationData.m_Paths;
     276}
     277
     278CinematicSimulationData* CCinemaManager::GetCinematicSimulationData()
     279{
     280    return &m_CinematicSimulationData;
     281}
     282
     283bool CCinemaManager::GetPathsDrawing() const
     284{
     285    return m_DrawPaths;
     286}
     287
     288void CCinemaManager::SetPathsDrawing(const bool drawPath)
     289{
     290    m_DrawPaths = drawPath;
     291}
     292 No newline at end of file
  • source/graphics/CinemaManager.h

     
    2222#include <list>
    2323#include <map>
    2424
     25#include "lib/input.h" // InReaction - can't forward-declare enum
     26
    2527#include "graphics/CinemaPath.h"
    2628#include "ps/CStr.h"
    2729
    28 //Class for in game playing of cinematics. Should only be instantiated in CGameView.
     30/*
     31    desc: contains various functions used for cinematic camera paths
     32    See also: CinemaHandler.cpp, CinemaPath.cpp
     33*/
     34
     35// Cinematic structure for data accessable from the simulation
     36struct CinematicSimulationData
     37{
     38    bool m_Enabled;
     39    bool m_Paused;
     40    std::map<CStrW, CCinemaPath> m_Paths;
     41    std::list<CCinemaPath> m_PathQueue;
     42
     43    // States before playing
     44    bool m_MapRevealed;
     45
     46    fixed m_ElapsedTime, m_TotalTime, m_CurrentPathElapsedTime;
     47
     48    CinematicSimulationData()
     49        :   m_Enabled(false),
     50            m_Paused(true),
     51            m_MapRevealed(false),
     52            m_ElapsedTime(fixed::Zero()),
     53            m_TotalTime(fixed::Zero()),
     54            m_CurrentPathElapsedTime(fixed::Zero())
     55    {}
     56};
     57
     58/**
     59 * Class for in game playing of cinematics. Should only be instantiated in CGameView.
     60 */
     61
    2962class CCinemaManager
    3063{
    3164public:
     
    3265    CCinemaManager();
    3366    ~CCinemaManager() {}
    3467
    35     void AddPath(CCinemaPath path, const CStrW& name);
     68    /**
     69     * Adds the path to the path list
     70     * @param name path name
     71     * @param CCinemaPath path data
     72     */
     73    void AddPath(const CStrW& name, const CCinemaPath& path);
    3674
    37     //Adds track to list of being played.
    38     void QueuePath(const CStrW& name, bool queue);
    39     void OverridePath(const CStrW& name);   //clears track queue and replaces with 'name'
     75    /**
     76     * Adds the path to the playlist
     77     * @param name path name
     78     */
     79    void AddPathToQueue(const CStrW& name);
    4080
    4181    /**
    42      * @param deltaRealTime Elapsed real time since the last frame.
     82     * Clears the playlist
    4383     */
    44     bool Update(const float deltaRealTime);
    45    
    46     //These stop track play, and accept time, not ratio of time
    47     void MoveToPointAt(float time);
     84    void ClearQueue();
    4885
    49     inline void StopPlaying() { m_PathQueue.clear(); }
    50     void DrawSpline() const;
     86    /**
     87     * Checks the path name in the path list
     88     * @param name path name
     89     * @return true if path with that name exists, else false
     90     */
     91    bool HasPath(const CStrW& name) const;
    5192   
    52     inline bool IsPlaying() const { return !m_PathQueue.empty(); }
    53     bool HasTrack(const CStrW& name) const;
    54     inline bool IsActive() const { return m_Active; }
    55     inline void SetActive(bool active) { m_Active=active; }
    56 
    57     inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; }
     93    const std::map<CStrW, CCinemaPath>& GetAllPaths();
    5894    void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks);
    59     void SetCurrentPath(const CStrW& name, bool current, bool lines);
    6095
    61 private:
    62    
    63     bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent;
    64     std::map<CStrW, CCinemaPath>::iterator m_CurrentPath;
    65     std::map<CStrW, CCinemaPath> m_Paths;
    66     std::list<CCinemaPath> m_PathQueue;
     96    /**
     97     * Starts play paths
     98     */
     99    void Play();
     100    void Stop();
     101    bool IsPlaying() const;
     102
     103    /**
     104     * Renders black bars and paths (if enabled)
     105     */
     106    void Render();
     107    void DrawBars() const;
     108
     109    /**
     110     * Get current enable state of the cinema manager
     111     */
     112    bool GetEnabled() const;
     113
     114    /**
     115     * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc)
     116     * @enable new state
     117     */
     118    void SetEnabled(bool enabled);
     119
     120    /**
     121     * Updates CCinemManager and current path
     122     * @param deltaRealTime Elapsed real time since the last frame.
     123     */
     124    void Update(const float deltaRealTime);
     125
     126    InReaction HandleEvent(const SDL_Event_* ev);
     127
     128    CinematicSimulationData* GetCinematicSimulationData();
     129
     130    bool GetPathsDrawing() const;
     131    void SetPathsDrawing(const bool drawPath);
     132
     133private:   
     134    bool m_DrawPaths;
     135
     136    // Cinematic data is accessed from the simulation
     137    CinematicSimulationData m_CinematicSimulationData;
    67138};
    68139
     140extern InReaction cinema_manager_handler(const SDL_Event_* ev);
     141
    69142#endif
  • source/graphics/CinemaPath.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 
    1918#include "precompiled.h"
    2019
    2120#include "CinemaPath.h"
    2221
     22#include <sstream>
    2323#include <string>
    24 #include <sstream>
    2524
     25#include "Camera.h"
     26#include "CinemaManager.h"
     27#include "GameView.h"
     28#include "gui/CGUI.h"
     29#include "gui/GUIManager.h"
     30#include "gui/IGUIObject.h"
    2631#include "lib/ogl.h"
    27 #include "ps/Game.h"
    28 #include "GameView.h"
    2932#include "maths/MathUtil.h"
    30 #include "Camera.h"
    31 #include "ps/CStr.h"
     33#include "maths/Quaternion.h"
    3234#include "maths/Vector3D.h"
    3335#include "maths/Vector4D.h"
    34 #include "maths/Quaternion.h"
     36#include "ps/CLogger.h"
     37#include "ps/CStr.h"
     38#include "ps/Game.h"
     39#include "renderer/Renderer.h"
    3540
    36 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline)
    37     : CCinemaData(data), TNSpline(spline), m_TimeElapsed(0.f)
    38 {
    39     m_TimeElapsed = 0;
     41CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline)
     42    : CCinemaData(data), TNSpline(spline), m_TargetSpline(targetSpline), m_TimeElapsed(0.f)
     43{
    4044    BuildSpline();
    4145
    42     //Set distortion mode and style
    43     switch(data.m_Mode)
     46    if (m_Orientation == L"target")
    4447    {
    45     case CCinemaPath::EM_IN:
     48        m_LookAtTarget = true;
     49        ENSURE(!m_TargetSpline.GetAllNodes().empty());
     50    }
     51
     52    // Set distortion mode and style
     53    if (data.m_Mode == L"ease_in")
    4654        DistModePtr = &CCinemaPath::EaseIn;
    47         break;
    48     case CCinemaPath::EM_OUT:
     55    else if (data.m_Mode == L"ease_out")
    4956        DistModePtr = &CCinemaPath::EaseOut;
    50         break;
    51     case CCinemaPath::EM_INOUT:
     57    else if (data.m_Mode == L"ease_inout")
    5258        DistModePtr = &CCinemaPath::EaseInOut;
    53         break;
    54     case CCinemaPath::EM_OUTIN:
     59    else if (data.m_Mode == L"ease_outin")
    5560        DistModePtr = &CCinemaPath::EaseOutIn;
    56         break;
    57     default:
    58         debug_printf("Cinematic mode not found for %d\n", data.m_Mode);
    59         break;
     61    else
     62    {
     63        LOGWARNING("Cinematic mode not found for '%s'", data.m_Mode.ToUTF8().c_str());
     64        DistModePtr = &CCinemaPath::EaseInOut;
    6065    }
    6166
    62     switch (data.m_Style)
    63     {
    64     case CCinemaPath::ES_DEFAULT:
     67    if (data.m_Style == L"default")
    6568        DistStylePtr = &CCinemaPath::EaseDefault;
    66         break;
    67     case CCinemaPath::ES_GROWTH:
     69    else if (data.m_Style == L"growth")
    6870        DistStylePtr = &CCinemaPath::EaseGrowth;
    69         break;
    70     case CCinemaPath::ES_EXPO:
     71    else if (data.m_Style == L"expo")
    7172        DistStylePtr = &CCinemaPath::EaseExpo;
    72         break;
    73     case CCinemaPath::ES_CIRCLE:
     73    else if (data.m_Style == L"circle")
    7474        DistStylePtr = &CCinemaPath::EaseCircle;
    75         break;
    76     case CCinemaPath::ES_SINE:
     75    else if (data.m_Style == L"sine")
    7776        DistStylePtr = &CCinemaPath::EaseSine;
    78         break;
    79     default:
    80         debug_printf("Cinematic mode not found for %d\n", data.m_Style);
    81         break;
     77    else
     78    {
     79        LOGWARNING("Cinematic style not found for '%s'", data.m_Style.ToUTF8().c_str());
     80        DistStylePtr = &CCinemaPath::EaseDefault;
    8281    }
    83     //UpdateDuration();
     82}
    8483
     84void CCinemaPath::Draw() const
     85{
     86    DrawSpline(*this, CVector4D(0.2f, 0.2f, 1.f, 0.5f), 100, true);
     87    DrawSpline(m_TargetSpline, CVector4D(1.0f, 0.2f, 0.2f, 0.5f), 100, true);
     88    DrawNodes(CVector4D(0.5f, 1.0f, 0.f, 0.5f));
    8589}
    8690
    87 void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const
     91void CCinemaPath::DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const
    8892{
    89     if (NodeCount < 2 || DistModePtr == NULL)
     93    if (spline.NodeCount < 2 || DistModePtr == NULL)
    9094        return;
    91     if ( NodeCount == 2 && lines )
     95    if (spline.NodeCount == 2 && lines)
    9296        smoothness = 2;
    9397
    94     float start = MaxDistance / smoothness;
    95     float time=0;
    96    
     98    float start = spline.MaxDistance.ToFloat() / smoothness;
     99    float time = 0;
     100
    97101#if CONFIG2_GLES
    98 #warning TODO: do something about CCinemaPath on GLES
     102    #warning TODO : do something about CCinemaPath on GLES
    99103#else
    100104
    101     glColor4f( RGBA.X, RGBA.Y, RGBA.Z, RGBA.W );
    102     if ( lines )
    103     {   
     105    glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W);
     106    if (lines)
     107    {
    104108        glLineWidth(1.8f);
    105109        glEnable(GL_LINE_SMOOTH);
    106110        glBegin(GL_LINE_STRIP);
    107111
    108         for (int i=0; i<=smoothness; ++i)
     112        for (int i = 0; i <= smoothness; ++i)
    109113        {
    110             //Find distorted time
    111             time = start*i / MaxDistance;
    112             CVector3D tmp = GetPosition(time);
    113             glVertex3f( tmp.X, tmp.Y, tmp.Z );
     114            // Find distorted time
     115            time = start*i / spline.MaxDistance.ToFloat();
     116            CVector3D tmp = spline.GetPosition(time);
     117            glVertex3f(tmp.X, tmp.Y, tmp.Z);
    114118        }
    115119        glEnd();
    116120        glDisable(GL_LINE_SMOOTH);
     
    119123    else
    120124    {
    121125        smoothness /= 2;
    122         start = MaxDistance / smoothness;
     126        start = spline.MaxDistance.ToFloat() / smoothness;
    123127        glEnable(GL_POINT_SMOOTH);
    124128        glPointSize(3.0f);
    125129        glBegin(GL_POINTS);
    126130
    127         for (int i=0; i<=smoothness; ++i)
     131        for (int i = 0; i <= smoothness; ++i)
    128132        {
    129             //Find distorted time
    130             time = (this->*DistModePtr)(start*i / MaxDistance);
    131             CVector3D tmp = GetPosition(time);
    132             glVertex3f( tmp.X, tmp.Y, tmp.Z );
     133            // Find distorted time
     134            time = (this->*DistModePtr)(start*i / spline.MaxDistance.ToFloat());
     135            CVector3D tmp = spline.GetPosition(time);
     136            glVertex3f(tmp.X, tmp.Y, tmp.Z);
    133137        }
    134         glColor3f(1.0f, 1.0f, 0.0f);    //yellow
     138        glColor3f(1.0f, 1.0f, 0.0f);    // yellow
    135139
    136         for ( size_t i=0; i<Node.size(); ++i )
    137             glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z);
     140        for (size_t i = 0; i < spline.GetAllNodes().size(); ++i)
     141            glVertex3f(
     142                spline.GetAllNodes()[i].Position.X.ToFloat(),
     143                spline.GetAllNodes()[i].Position.Y.ToFloat(),
     144                spline.GetAllNodes()[i].Position.Z.ToFloat()
     145            );
    138146
    139147        glEnd();
    140148        glPointSize(1.0f);
     
    144152#endif
    145153}
    146154
     155void CCinemaPath::DrawNodes(const CVector4D& RGBA) const
     156{
     157#if CONFIG2_GLES
     158    #warning TODO : do something about CCinemaPath on GLES
     159#else
     160    glEnable(GL_POINT_SMOOTH);
     161    glPointSize(5.0f);
     162
     163    glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W);
     164    glBegin(GL_POINTS);
     165    for (size_t i = 0; i < Node.size(); ++i)
     166        glVertex3f(Node[i].Position.X.ToFloat(), Node[i].Position.Y.ToFloat(), Node[i].Position.Z.ToFloat());
     167    glEnd();
     168
     169    if (!m_LookAtTarget)
     170    {
     171        glPointSize(1.0f);
     172        glDisable(GL_POINT_SMOOTH);
     173        return;
     174    }
     175
     176    // draw target nodes
     177    glColor4f(RGBA.Y, RGBA.X, RGBA.Z, RGBA.W);
     178    glBegin(GL_POINTS);
     179    for (size_t i = 0; i < m_TargetSpline.GetAllNodes().size(); ++i)
     180        glVertex3f(
     181            m_TargetSpline.GetAllNodes()[i].Position.X.ToFloat(),
     182            m_TargetSpline.GetAllNodes()[i].Position.Y.ToFloat(),
     183            m_TargetSpline.GetAllNodes()[i].Position.Z.ToFloat()
     184        );
     185    glEnd();
     186
     187    glPointSize(1.0f);
     188    glDisable(GL_POINT_SMOOTH);
     189#endif
     190}
     191
    147192void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)
    148193{
    149     CCamera *Cam = g_Game->GetView()->GetCamera();
     194    CCamera *camera = g_Game->GetView()->GetCamera();
    150195    t = (this->*DistModePtr)(t);
    151    
    152     CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation;
    153     CQuaternion start, end;
    154     start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z));
    155     end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z));
    156     start.Slerp(start, end, nodet);
    157196    CVector3D pos = GetPosition(t);
    158     CQuaternion quat;
    159197   
    160     Cam->m_Orientation.SetIdentity();
    161     Cam->m_Orientation.Rotate(start);
    162     Cam->m_Orientation.Translate(pos);
    163     Cam->UpdateFrustum();
     198    if (m_LookAtTarget)
     199    {
     200        if (m_TimeElapsed <= m_TargetSpline.MaxDistance.ToFloat())
     201            camera->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance.ToFloat()), CVector3D(0, 1, 0));
     202        else
     203            camera->LookAt(pos, m_TargetSpline.GetAllNodes().back().Position, CVector3D(0, 1, 0));
     204    }
     205    else
     206    {
     207        CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation;
     208        CQuaternion start, end;
     209        start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z));
     210        end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z));
     211        start.Slerp(start, end, nodet);
     212
     213        camera->m_Orientation.SetIdentity();
     214        camera->m_Orientation.Rotate(start);
     215        camera->m_Orientation.Translate(pos);
     216    }
     217    camera->UpdateFrustum();
    164218}
    165219
    166 //Distortion mode functions
     220// Distortion mode functions
    167221float CCinemaPath::EaseIn(float t) const
    168222{
    169223    return (this->*DistStylePtr)(t);
    170224}
     225
    171226float CCinemaPath::EaseOut(float t) const
    172227{
    173     return 1.0f - EaseIn(1.0f-t);
     228    return 1.0f - EaseIn(1.0f - t);
    174229}
     230
    175231float CCinemaPath::EaseInOut(float t) const
    176232{
    177233    if (t < m_Switch)
    178         return EaseIn(1.0f/m_Switch * t) * m_Switch;
    179     return EaseOut(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;
     234        return EaseIn(1.0f / m_Switch * t) * m_Switch;
     235    return EaseOut(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch;
    180236}
     237
    181238float CCinemaPath::EaseOutIn(float t) const
    182239{
    183240    if (t < m_Switch)
    184         return EaseOut(1.0f/m_Switch * t) * m_Switch;
    185     return EaseIn(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;
     241        return EaseOut(1.0f / m_Switch * t) * m_Switch;
     242    return EaseIn(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch;
    186243}
    187244
    188 
    189 //Distortion style functions
     245// Distortion style functions
    190246float CCinemaPath::EaseDefault(float t) const
    191247{
    192248    return t;
    193249}
     250
    194251float CCinemaPath::EaseGrowth(float t) const
    195252{
    196253    return pow(t, m_Growth);
    197254}
    198255
     256
    199257float CCinemaPath::EaseExpo(float t) const
    200258{
    201     if(t == 0)
     259    if (t == 0)
    202260        return t;
    203     return powf(m_Growth, 10*(t-1.0f));
     261    return powf(m_Growth, 10 * (t - 1.0f));
    204262}
     263
    205264float CCinemaPath::EaseCircle(float t) const
    206265{
    207      t = -(sqrt(1.0f - t*t) - 1.0f);
    208      if(m_GrowthCount > 1.0f)
    209      {
    210          m_GrowthCount--;
    211          return (this->*DistStylePtr)(t);
    212      }
    213      return t;
     266    t = -(sqrt(1.0f - t*t) - 1.0f);
     267    if (m_GrowthCount > 1.0f)
     268    {
     269        --m_GrowthCount;
     270        return (this->*DistStylePtr)(t);
     271    }
     272    return t;
    214273}
    215274
    216275float CCinemaPath::EaseSine(float t) const
    217276{
    218      t = 1.0f - cos(t * (float)M_PI/2);
    219      if(m_GrowthCount > 1.0f)
    220      {
    221          m_GrowthCount--;
    222          return (this->*DistStylePtr)(t);
    223      }
    224      return t;
     277    t = 1.0f - cos(t * (float)M_PI / 2);
     278    if (m_GrowthCount > 1.0f)
     279    {
     280        --m_GrowthCount;
     281        return (this->*DistStylePtr)(t);
     282    }
     283    return t;
    225284}
    226285
    227286bool CCinemaPath::Validate()
    228287{
    229     if ( m_TimeElapsed <= GetDuration() && m_TimeElapsed >= 0.0f )
     288    if (m_TimeElapsed > GetDuration().ToFloat() || m_TimeElapsed < 0.0f)
     289        return false;
     290
     291    // Find current node and past "node time"
     292    float previousTime = 0.0f, cumulation = 0.0f;
     293
     294    // Ignore the last node, since it is a blank (node time values are shifted down one from interface)
     295    for (size_t i = 0; i < Node.size() - 1; ++i)
    230296    {
    231         //Find current node and past "node time"
    232         float previousTime = 0.0f, cumulation = 0.0f;
    233         //Ignore the last node, since it is a blank (node time values are shifted down one from interface)
    234         for ( size_t i = 0; i < Node.size() - 1; ++i )
     297        cumulation += Node[i].Distance.ToFloat();
     298        if (m_TimeElapsed <= cumulation)
    235299        {
    236             cumulation += Node[i].Distance;
    237             if ( m_TimeElapsed <= cumulation )
    238             {
    239                 m_PreviousNodeTime = previousTime;
    240                 m_PreviousRotation = Node[i].Rotation;
    241                 m_CurrentNode = i;  //We're moving toward this next node, so use its rotation
    242                 return true;
    243             }
    244             else
    245                 previousTime += Node[i].Distance;
     300            m_PreviousNodeTime = previousTime;
     301            m_PreviousRotation = Node[i].Rotation;
     302            m_CurrentNode = i;  // We're moving toward this next node, so use its rotation
     303            return true;
    246304        }
     305        previousTime += Node[i].Distance.ToFloat();
    247306    }
     307    debug_warn("validation of cinema path is wrong\n");
    248308    return false;
    249309}
    250310
    251311bool CCinemaPath::Play(const float deltaRealTime)
    252312{
    253     m_TimeElapsed += m_Timescale * deltaRealTime;
    254 
     313    m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime;
    255314    if (!Validate())
    256315    {
    257316        m_TimeElapsed = 0.0f;
    258317        return false;
    259318    }
    260    
    261     MoveToPointAt( m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation );
     319    MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation);
    262320    return true;
    263 }
    264  No newline at end of file
     321}
  • source/graphics/CinemaPath.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 
    1918#ifndef INCLUDED_CINEMAPATH
    2019#define INCLUDED_CINEMAPATH
    2120
    22 #include <list>
    23 #include <map>
     21#include "maths/NUSpline.h"
    2422#include "ps/CStr.h"
    25 #include "maths/NUSpline.h"
    2623
    27 /*
    28     desc: contains various functions used for cinematic camera paths
    29     See also: CinemaHandler.cpp, Cinematic.h/.cpp
    30 */
    31 
    3224class CVector3D;
    3325class CVector4D;
    3426class CCamera;
    3527
    36 //For loading data
     28// For loading data
    3729class CCinemaData
    3830{
    3931public:
    40     CCinemaData() : m_GrowthCount(0), m_Growth(0), m_Switch(0),
    41                     m_Mode(0), m_Style(0), m_Timescale(1) {}
     32    CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
    4233    virtual ~CCinemaData() {}
    43    
     34
    4435    const CCinemaData* GetData() const { return this; }
    45    
    46     //Distortion variables
     36
     37    CStrW m_Name;
     38    CStrW m_Orientation;
     39    CStrW m_Mode;
     40    CStrW m_Style;
     41
     42    bool m_LookAtTarget;
     43
     44    fixed m_Timescale; // a negative timescale results in backwards play
     45
     46    // Distortion variables
    4747    mutable float m_GrowthCount;
    4848    float m_Growth;
    4949    float m_Switch;
    50     int m_Mode;
    51     int m_Style;
    52     float m_Timescale;  //a negative timescale results in backwards play
    53 
    5450};
    5551
    5652
    57 //Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
    58 //This class encompasses the spline and the information which determines how the path will operate
    59 //and also provides the functionality for doing so
     53// Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
     54// This class encompasses the spline and the information which determines how the path will operate
     55// and also provides the functionality for doing so
    6056
    6157class CCinemaPath : private CCinemaData, public TNSpline
    6258{
    6359public:
    64     CCinemaPath() { m_TimeElapsed = 0.0f; m_PreviousNodeTime = 0.0f; }
    65     CCinemaPath(const CCinemaData& data, const TNSpline& spline);
     60    CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
     61    CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
    6662    ~CCinemaPath() { DistStylePtr = NULL;  DistModePtr = NULL; }
    67    
    68     enum { EM_IN, EM_OUT, EM_INOUT, EM_OUTIN };
    69     enum { ES_DEFAULT, ES_GROWTH, ES_EXPO, ES_CIRCLE, ES_SINE };
    70    
    71     //sets camera position to calculated point on spline
    72     void MoveToPointAt(float t, float nodet, const CVector3D& );
    73    
    74     //Distortion mode functions-change how ratio is passed to distortion style functions
     63
     64    // Sets camera position to calculated point on spline
     65    void MoveToPointAt(float t, float nodet, const CVector3D&);
     66
     67    // Distortion mode functions-change how ratio is passed to distortion style functions
    7568    float EaseIn(float t) const;
    7669    float EaseOut(float t) const;
    7770    float EaseInOut(float t) const;
    7871    float EaseOutIn(float t) const;
    7972
    80     //Distortion style functions
     73    // Distortion style functions
    8174    float EaseDefault(float t) const;
    8275    float EaseGrowth(float t) const;
    8376    float EaseExpo(float t) const;
    8477    float EaseCircle(float t) const;
    8578    float EaseSine(float t) const;
    86    
     79
    8780    float (CCinemaPath::*DistStylePtr)(float ratio) const;
    8881    float (CCinemaPath::*DistModePtr)(float ratio) const;
    8982
     
    9184
    9285public:
    9386
    94     void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const;
     87    void Draw() const;
     88    void DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const;
     89    void DrawNodes(const CVector4D& RGBA) const;
    9590
    9691    inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; }
    97     inline float GetNodeDuration(const int index) const { return Node[index].Distance; }
    98     inline float GetDuration() const { return MaxDistance; }
    99    
    100     inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance; }
     92    inline fixed GetNodeDuration(const int index) const { return Node[index].Distance; }
     93    inline fixed GetDuration() const { return MaxDistance; }
     94
     95    inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance.ToFloat(); }
    10196    inline float GetElapsedTime() const { return m_TimeElapsed; }
    10297
    103     inline void SetTimescale(float scale) { m_Timescale = scale; }
    104    
     98    CStrW GetName() const { return m_Name; }
     99
     100    inline void SetTimescale(fixed scale) { m_Timescale = scale; }
     101
    105102    float m_TimeElapsed;
    106     float m_PreviousNodeTime;   //How much time has passed before the current node
    107    
     103    float m_PreviousNodeTime;   //How much time has passed before the current node
     104
    108105    size_t m_CurrentNode;
    109106    CVector3D m_PreviousRotation;
    110107
    111 public: 
     108public:
    112109
    113110    /**
    114111     * Returns false if finished.
    115      *
    116112     * @param deltaRealTime Elapsed real time since the last frame.
    117113     */
    118114    bool Play(const float deltaRealTime);
     115
     116    /**
     117     * Validate the path
     118     * @return true if the path is valid
     119     */
    119120    bool Validate();
    120121
    121     inline float GetTimescale() const { return m_Timescale; }   
     122    /**
     123     * Returns true if path doesn't contain nodes
     124     */
     125    bool Empty() { return Node.empty(); }
     126
     127    fixed GetTimescale() const { return m_Timescale; }
     128
     129    TNSpline* getTargetSpline() { return &m_TargetSpline; }
     130
     131private:
     132
     133    TNSpline m_TargetSpline;
    122134};
    123135
    124 #endif
     136#endif // INCLUDED_CINEMAPATH
  • source/graphics/GameView.cpp

     
    626626    if (!g_app_has_focus)
    627627        return;
    628628
    629     if (m->CinemaManager.IsActive() && m->CinemaManager.IsPlaying())
     629    if (m->CinemaManager.GetEnabled())
    630630    {
    631         if (! m->CinemaManager.Update(deltaRealTime))
    632         {
    633 //          ResetCamera();
    634         }
     631        m->CinemaManager.Update(deltaRealTime);
    635632        return;
    636633    }
    637634
  • source/graphics/MapReader.cpp

     
    456456    void ReadTerrain(XMBElement parent);
    457457    void ReadEnvironment(XMBElement parent);
    458458    void ReadCamera(XMBElement parent);
    459     void ReadCinema(XMBElement parent);
     459    void ReadPaths(XMBElement parent);
    460460    void ReadTriggers(XMBElement parent);
    461461    int ReadEntities(XMBElement parent, double end_time);
    462462};
     
    839839    }
    840840}
    841841
    842 void CXMLReader::ReadCinema(XMBElement parent)
     842void CXMLReader::ReadPaths(XMBElement parent)
    843843{
    844844    #define EL(x) int el_##x = xmb_file.GetElementID(#x)
    845845    #define AT(x) int at_##x = xmb_file.GetAttributeID(#x)
     
    846846
    847847    EL(path);
    848848    EL(rotation);
    849     EL(distortion);
    850849    EL(node);
    851850    EL(position);
    852     EL(time);
     851    EL(target);
    853852    AT(name);
    854853    AT(timescale);
     854    AT(orientation);
    855855    AT(mode);
    856856    AT(style);
    857     AT(growth);
    858     AT(switch);
    859857    AT(x);
    860858    AT(y);
    861859    AT(z);
     860    AT(deltatime);
    862861
    863862#undef EL
    864863#undef AT
    865    
    866     std::map<CStrW, CCinemaPath> pathList;
     864
    867865    XERO_ITER_EL(parent, element)
    868866    {
    869867        int elementName = element.GetNodeName();
     
    870868           
    871869        if (elementName == el_path)
    872870        {
     871            CCinemaData pathData;
    873872            XMBAttributeList attrs = element.GetAttributes();
    874             CStrW name(attrs.GetNamedItem(at_name).FromUTF8());
    875             float timescale = attrs.GetNamedItem(at_timescale).ToFloat();
    876             CCinemaData pathData;
    877             pathData.m_Timescale = timescale;
    878             TNSpline spline, backwardSpline;
     873            CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8());
     874            pathData.m_Timescale = fixed::FromFloat(attrs.GetNamedItem(at_timescale).ToFloat());
     875            TNSpline pathSpline, targetSpline;
     876            fixed lastTargetTime = fixed::Zero();
    879877
     878            pathData.m_Name = pathName;
     879            pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8();
     880            pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8();
     881            pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8();
     882
    880883            XERO_ITER_EL(element, pathChild)
    881884            {
    882885                elementName = pathChild.GetNodeName();
    883886                attrs = pathChild.GetAttributes();
    884887
    885                 //Load distortion attributes
    886                 if (elementName == el_distortion)
     888                // Load node data used for spline
     889                if (elementName == el_node)
    887890                {
    888                         pathData.m_Mode = attrs.GetNamedItem(at_mode).ToInt();
    889                         pathData.m_Style = attrs.GetNamedItem(at_style).ToInt();
    890                         pathData.m_Growth = attrs.GetNamedItem(at_growth).ToInt();
    891                         pathData.m_Switch = attrs.GetNamedItem(at_switch).ToInt();
    892                 }
    893                
    894                 //Load node data used for spline
    895                 else if (elementName == el_node)
    896                 {
     891                    bool positionDeclared = false;
    897892                    SplineData data;
     893                    data.Distance = fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat());
     894                    lastTargetTime += fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat());
    898895                    XERO_ITER_EL(pathChild, nodeChild)
    899896                    {
    900897                        elementName = nodeChild.GetNodeName();
    901898                        attrs = nodeChild.GetAttributes();
    902899                       
    903                         //Fix?:  assumes that time is last element
    904900                        if (elementName == el_position)
    905901                        {
    906                             data.Position.X = attrs.GetNamedItem(at_x).ToFloat();
    907                             data.Position.Y = attrs.GetNamedItem(at_y).ToFloat();
    908                             data.Position.Z = attrs.GetNamedItem(at_z).ToFloat();
    909                             continue;
     902                            data.Position.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     903                            data.Position.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     904                            data.Position.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
     905                            positionDeclared = true;
    910906                        }
    911907                        else if (elementName == el_rotation)
    912908                        {
    913                             data.Rotation.X = attrs.GetNamedItem(at_x).ToFloat();
    914                             data.Rotation.Y = attrs.GetNamedItem(at_y).ToFloat();
    915                             data.Rotation.Z = attrs.GetNamedItem(at_z).ToFloat();
    916                             continue;
     909                            data.Rotation.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     910                            data.Rotation.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     911                            data.Rotation.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
    917912                        }
    918                         else if (elementName == el_time)
    919                             data.Distance = nodeChild.GetText().ToFloat();
     913                        else if (elementName == el_target)
     914                        {
     915                            CFixedVector3D targetPosition;
     916                            targetPosition.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     917                            targetPosition.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     918                            targetPosition.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
     919
     920                            targetSpline.AddNode(targetPosition, CFixedVector3D(), lastTargetTime);
     921                            lastTargetTime = fixed::Zero();
     922                        }
    920923                        else
    921                             debug_warn(L"Invalid cinematic element for node child");
    922                    
    923                         backwardSpline.AddNode(data.Position, data.Rotation, data.Distance);
     924                            LOGWARNING("Invalid cinematic element for node child");
    924925                    }
     926
     927                    // skip the node if no position
     928                    if (positionDeclared)
     929                        pathSpline.AddNode(data.Position, data.Rotation, data.Distance);
    925930                }
    926931                else
    927                     debug_warn(L"Invalid cinematic element for path child");
    928                
    929                
     932                    LOGWARNING("Invalid cinematic element for path child");
    930933            }
    931934
    932             //Construct cinema path with data gathered
    933             CCinemaPath temp(pathData, backwardSpline);
    934             const std::vector<SplineData>& nodes = temp.GetAllNodes();
    935             if (nodes.empty())
     935            // Construct cinema path with data gathered
     936            CCinemaPath path(pathData, pathSpline, targetSpline);
     937            if (path.Empty())
    936938            {
    937                 debug_warn(L"Failure loading cinematics");
     939                LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8());
    938940                return;
    939941            }
    940942                   
    941             for (std::vector<SplineData>::const_reverse_iterator it = nodes.rbegin();
    942                 it != nodes.rend(); ++it)
    943             {
    944                 spline.AddNode(it->Position, it->Rotation, it->Distance);
    945             }
    946                
    947             CCinemaPath path(pathData, spline);
    948             pathList[name] = path; 
     943            if (!m_MapReader.pCinema->HasPath(pathName))
     944                m_MapReader.pCinema->AddPath(pathName, path);
     945            else
     946                LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8());
    949947        }
    950948        else
    951             ENSURE("Invalid cinema child");
     949            LOGWARNING("Invalid path child with name '%s'", element.GetText());
    952950    }
    953 
    954     if (m_MapReader.pCinema)
    955         m_MapReader.pCinema->SetAllPaths(pathList);
    956951}
    957952
    958953void CXMLReader::ReadTriggers(XMBElement UNUSED(parent))
     
    11251120        }
    11261121        else if (name == "Paths")
    11271122        {
    1128             ReadCinema(node);
     1123            ReadPaths(node);
    11291124        }
    11301125        else if (name == "Triggers")
    11311126        {
  • source/graphics/MapWriter.cpp

     
    408408
    409409            for ( ; it != paths.end(); ++it )
    410410            {
    411                 CStrW name = it->first;
    412                 float timescale = it->second.GetTimescale();
     411                fixed timescale = it->second.GetTimescale();
     412                const std::vector<SplineData>& nodes = it->second.GetAllNodes();
     413                const CCinemaData* data = it->second.GetData();
    413414               
    414415                XML_Element("Path");
    415                 XML_Attribute("name", name);
     416                XML_Attribute("name", data->m_Name);
    416417                XML_Attribute("timescale", timescale);
     418                XML_Attribute("orientation", data->m_Orientation);
     419                XML_Attribute("mode", data->m_Mode);
     420                XML_Attribute("style", data->m_Style);
    417421
    418                 const std::vector<SplineData>& nodes = it->second.GetAllNodes();
    419                 const CCinemaData* data = it->second.GetData();
    420                
     422                // TODO: write target nodes
     423                for (size_t j = 0; j < nodes.size(); ++j)
    421424                {
    422                     XML_Element("Distortion");
    423                     XML_Attribute("mode", data->m_Mode);
    424                     XML_Attribute("style", data->m_Style);
    425                     XML_Attribute("growth", data->m_Growth);
    426                     XML_Attribute("switch", data->m_Switch);
    427                 }
    428 
    429                 for ( ssize_t j=nodes.size()-1; j >= 0; --j )
    430                 {
    431425                    XML_Element("Node");
     426                    if (j > 0)
     427                        XML_Attribute("deltatime", nodes[j - 1].Distance);
     428                    else
     429                        XML_Attribute("deltatime", 0.0f);
    432430                   
    433431                    {
    434432                        XML_Element("Position");
     
    443441                        XML_Attribute("y", nodes[j].Rotation.Y);
    444442                        XML_Attribute("z", nodes[j].Rotation.Z);
    445443                    }
    446 
    447                     XML_Setting("Time", nodes[j].Distance);
    448444                }
    449445            }
    450446        }
  • source/lib/input.cpp

     
    3232
    3333#include "lib/external_libraries/libsdl.h"
    3434
    35 const size_t MAX_HANDLERS = 8;
     35const size_t MAX_HANDLERS = 9;
    3636static InHandler handler_stack[MAX_HANDLERS];
    3737static size_t handler_stack_top = 0;
    3838
  • source/maths/NUSpline.cpp

     
    4545/*********************************** R N S **************************************************/
    4646
    4747// adds node and updates segment length
    48 void RNSpline::AddNode(const CVector3D& pos)
     48void RNSpline::AddNode(const CFixedVector3D& pos)
    4949{
    5050    if (NodeCount >= MAX_SPLINE_NODES)
    5151        return;
    52 
    5352    if (NodeCount == 0)
    54         MaxDistance = 0.f;
     53        MaxDistance = fixed::Zero();
    5554    else
    5655    {
    5756        Node[NodeCount-1].Distance = (Node[NodeCount-1].Position - pos).Length();
     
    9796{
    9897    if (NodeCount < 2)
    9998        return CVector3D(0.0f, 0.0f, 0.0f);
    100 
     99    if (time < 0.0f)
     100        time = 0.0f;
    101101    if (time > 1.0f)
    102102        time = 1.0f;
    103     float Distance = time * MaxDistance;
     103    float Distance = time * MaxDistance.ToFloat();
    104104    float CurrentDistance = 0.f;
    105105    int i = 0;
    106106
    107     //Find which node we're on
    108     while (CurrentDistance + Node[i].Distance < Distance && i < NodeCount - 2)
     107    // Find which node we're on
     108    while (CurrentDistance + Node[i].Distance.ToFloat() < Distance && i < NodeCount - 2)
    109109    {
    110         CurrentDistance += Node[i].Distance;
     110        CurrentDistance += Node[i].Distance.ToFloat();
    111111        ++i;
    112112    }
    113113    ENSURE(i < NodeCount - 1);
    114114    float t = Distance - CurrentDistance;
    115     t /= Node[i].Distance; // scale t in range 0 - 1
    116     CVector3D startVel = Node[i].Velocity * Node[i].Distance;
    117     CVector3D endVel = Node[i+1].Velocity * Node[i].Distance; 
    118     return GetPositionOnCubic(Node[i].Position, startVel, Node[i+1].Position, endVel, t);
     115    // TODO: reimplement CVector3D comparator (float comparing is bad without EPS)
     116    if (Node[i].Position == Node[i+1].Position || Node[i].Distance.ToFloat() < 1e-7) // distance too small or zero
     117    {
     118        return Node[i+1].Position;
     119    }
     120    t /= Node[i].Distance.ToFloat(); // scale t in range 0 - 1
     121    CVector3D startVel = Node[i].Velocity * Node[i].Distance.ToFloat();
     122    CVector3D endVel = Node[i+1].Velocity * Node[i].Distance.ToFloat();
     123    return GetPositionOnCubic(Node[i].Position, startVel,
     124        Node[i+1].Position, endVel, t);
    119125}
    120126
    121127// internal. Based on Equation 14
     
    123129{
    124130    if (index >= NodeCount - 1 || index < 0)
    125131        return CVector3D(0.0f, 0.0f, 0.0f);
    126 
    127     CVector3D temp = (Node[index+1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance);
     132    CVector3D temp = CVector3D(Node[index+1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance.ToFloat());
    128133    return (temp - Node[index+1].Velocity)*0.5f;
    129134}
    130135
     
    133138{
    134139    if (index >= NodeCount || index < 1)
    135140        return CVector3D(0.0f, 0.0f, 0.0f);
    136 
    137     CVector3D temp = (Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance);
     141    CVector3D temp = CVector3D(Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance.ToFloat());
    138142    return (temp - Node[index-1].Velocity) * 0.5f;
    139143}
    140144
     
    151155    for (int i = 1; i < NodeCount-1; ++i)
    152156    {
    153157        // Equation 12
    154         newVel = GetEndVelocity(i) * Node[i].Distance + GetStartVelocity(i) * Node[i-1].Distance;
    155         newVel = newVel * ( 1 / (Node[i-1].Distance + Node[i].Distance) );
     158        newVel = GetEndVelocity(i) * Node[i].Distance.ToFloat() + GetStartVelocity(i) * Node[i-1].Distance.ToFloat();
     159        newVel = newVel * (1 / (Node[i-1].Distance + Node[i].Distance).ToFloat());
    156160        Node[i-1].Velocity = oldVel;
    157161        oldVel = newVel;
    158162    }
     
    164168
    165169// as with RNSpline but use timePeriod in place of actual node spacing
    166170// ie time period is time from last node to this node
    167 void TNSpline::AddNode(const CVector3D& pos, const CVector3D& rotation, float timePeriod)
     171void TNSpline::AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod)
    168172{
    169173    if (NodeCount >= MAX_SPLINE_NODES)
    170174        return;
    171175
    172176    if (NodeCount == 0)
    173         MaxDistance = 0.f;
     177        MaxDistance = fixed::Zero();
    174178    else
    175179    {
    176180        Node[NodeCount-1].Distance = timePeriod;
     
    181185    temp.Position = pos;
    182186
    183187    //make sure we don't end up using undefined numbers...
    184     temp.Distance = 0.0f;
     188    temp.Distance = fixed::Zero();
    185189    temp.Velocity = CVector3D(0.0f, 0.0f, 0.0f);
    186190    temp.Rotation = rotation;
    187191    Node.push_back(temp);
     
    189193}
    190194
    191195//Inserts node before position
    192 void TNSpline::InsertNode(const int index, const CVector3D& pos, const CVector3D& rotation, float timePeriod)
     196void TNSpline::InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod)
    193197{
    194198    if (NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1)
    195199        return;
    196 
    197200    if (NodeCount == 0)
    198         MaxDistance = 0.f;
     201        MaxDistance = fixed::Zero();
    199202    else
    200203    {
    201204        Node[NodeCount-1].Distance = timePeriod;
     
    216219
    217220    MaxDistance -= Node[index].Distance;
    218221    MaxDistance -= Node[index-1].Distance;
    219     Node[index-1].Distance = 0.0f;
     222    Node[index-1].Distance = fixed::Zero();
    220223    Node.erase(Node.begin() + index, Node.begin() + index + 1);
    221224    --NodeCount;
    222225}
    223 
    224 void TNSpline::UpdateNodeTime(const int index, float time)
    225 {
     226void TNSpline::UpdateNodeTime(const int index, fixed time)
     227{
    226228    if (NodeCount == 0 || index > NodeCount - 1)
    227229        return;
    228230
    229231    Node[index].Distance = time;
    230232}
    231 
    232 void TNSpline::UpdateNodePos(const int index, const CVector3D& pos)
    233 {
     233void TNSpline::UpdateNodePos(const int index, const CFixedVector3D& pos)
     234{
    234235    if (NodeCount == 0 || index > NodeCount - 1)
    235236        return;
    236237
    237238    Node[index].Position = pos;
    238239}
    239 
    240240void TNSpline::Constrain()
    241241{
    242242    if (NodeCount < 3)
     
    245245    for (int i = 1; i < NodeCount-1; ++i)
    246246    {
    247247        // Equation 13
    248         float r0 = (Node[i].Position-Node[i-1].Position).Length() / Node[i-1].Distance;
    249         float r1 = (Node[i+1].Position - Node[i].Position).Length() / Node[i].Distance;
    250         Node[i].Velocity *= 4.0f*r0*r1/((r0+r1)*(r0+r1));
     248        float r0 = (Node[i].Position - Node[i - 1].Position).Length().ToFloat() / Node[i-1].Distance.ToFloat();
     249        float r1 = (Node[i+1].Position - Node[i].Position).Length().ToFloat() / Node[i].Distance.ToFloat();
     250        Node[i].Velocity *= 4.0f*r0*r1 / ((r0 + r1)*(r0 + r1));
    251251    }
    252252}
    253253
  • source/maths/NUSpline.h

     
    2222#ifndef INCLUDED_NUSPLINE
    2323#define INCLUDED_NUSPLINE
    2424
     25// TODO: why not bigger?
    2526#define MAX_SPLINE_NODES 40
    2627#include <stdlib.h>
     28
     29#include "FixedVector3D.h"
    2730#include "Vector3D.h"
    2831
    2932struct SplineData
    3033{
    31     CVector3D Position;
     34    // Should be fixed, because used in the simulation
     35    CFixedVector3D Position;
    3236    CVector3D Velocity;
    33     CVector3D Rotation;
    34     float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
     37    // TODO: make rotation as other spline
     38    CFixedVector3D Rotation;
     39    fixed Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
    3540};
    3641
    3742class RNSpline
     
    4146    RNSpline() { NodeCount = 0; }
    4247    virtual ~RNSpline() {}
    4348
    44     void AddNode(const CVector3D& pos);
     49    void AddNode(const CFixedVector3D& pos);
    4550    void BuildSpline();
    4651    CVector3D GetPosition(float time) const;
    4752    CVector3D GetRotation(float time) const;
    4853    const std::vector<SplineData>& GetAllNodes() const { return Node; }
    4954
    50     float MaxDistance;
     55    // TODO: rename to TotalDistance
     56    fixed MaxDistance;
    5157    int NodeCount;
    5258
    5359protected:
     
    7076public:
    7177    virtual ~TNSpline() {}
    7278
    73     void AddNode(const CVector3D& pos, const CVector3D& rotation, float timePeriod);
     79    void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
    7480    void PushNode() { Node.push_back( SplineData() ); }
    75     void InsertNode(const int index, const CVector3D& pos, const CVector3D& rotation, float timePeriod);
     81    void InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
    7682    void RemoveNode(const int index);
    77     void UpdateNodeTime(const int index, float time);
    78     void UpdateNodePos(const int index, const CVector3D& pos);
     83    void UpdateNodeTime(const int index, fixed time);
     84    void UpdateNodePos(const int index, const CFixedVector3D& pos);
    7985
    8086    void BuildSpline(){ RNSpline::BuildSpline();  Smooth(); Smooth(); Smooth(); }
    8187    void Smooth(){ for (int x = 0; x < 3; ++x) { SNSpline::Smooth(); Constrain(); } }
  • source/ps/GameSetup/GameSetup.cpp

     
    3535#include "lib/sysdep/os/win/wversion.h"
    3636#endif
    3737
     38#include "graphics/CinemaManager.h"
    3839#include "graphics/CinemaPath.h"
    3940#include "graphics/FontMetrics.h"
    4041#include "graphics/GameView.h"
     
    228229
    229230    g_Renderer.RenderTextOverlays();
    230231
     232    if (g_Game && g_Game->IsGameStarted())
     233        g_Game->GetView()->GetCinema()->Render();
     234
     235    ogl_WarnIfError();
     236
    231237    if (g_DoRenderGui)
    232238        g_GUI->Draw();
    233239
     
    568574    in_add_handler(gui_handler);
    569575
    570576    in_add_handler(touch_input_handler);
     577   
     578    in_add_handler(cinema_manager_handler);
    571579
    572580    // must be registered after (called before) the GUI which relies on these globals
    573581    in_add_handler(GlobalsInputHandler);
  • source/simulation2/components/CCmpCinemaManager.cpp

     
     1/* Copyright (C) 2016 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 "ICmpCinemaManager.h"
     22
     23#include "graphics/GameView.h"
     24#include "graphics/CinemaManager.h"
     25#include "ps/CLogger.h"
     26#include "ps/Game.h"
     27#include "simulation2/MessageTypes.h"
     28#include "simulation2/Simulation2.h"
     29
     30
     31class CCmpCinemaManager : public ICmpCinemaManager
     32{
     33public:
     34    static void ClassInit(CComponentManager& componentManager)
     35    {
     36        componentManager.SubscribeToMessageType(MT_Update);
     37    }
     38
     39    DEFAULT_COMPONENT_ALLOCATOR(CinemaManager)
     40
     41    static std::string GetSchema()
     42    {
     43        return "<a:component type='system'/>"
     44            "<empty/>"
     45            ;
     46    }
     47
     48    virtual void Init(const CParamNode& UNUSED(paramNode))
     49    {
     50        // ...
     51    }
     52
     53    virtual void Deinit()
     54    {
     55        // ...
     56    }
     57
     58    virtual void Serialize(ISerializer& serialize)
     59    {
     60        if (!g_Game || !g_Game->GetView())
     61        {
     62            LOGERROR("Trying to serialize cinematics when GameView isn't initialized!");
     63            return;
     64        }
     65        CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData();
     66        serialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed);
     67        serialize.NumberU32_Unbounded("NumberOfPaths", p_CinematicSimulationData->m_Paths.size());
     68        for (auto it : p_CinematicSimulationData->m_Paths)
     69        {
     70            CCinemaPath& path = it.second;
     71            const CCinemaData* data = path.GetData();
     72
     73            // TODO: maybe implement String_Unbounded
     74            serialize.String("PathName", data->m_Name, 1, 2048);
     75            serialize.String("PathOrientation", data->m_Orientation, 1, 2048);
     76            serialize.String("PathMode", data->m_Mode, 1, 2048);
     77            serialize.String("PathStyle", data->m_Style, 1, 2048);
     78            serialize.NumberFixed_Unbounded("PathTimescale", data->m_Timescale);
     79            serialize.Bool("LookAtTarget", data->m_LookAtTarget);
     80
     81            serialize.NumberU32("NumberOfNodes", path.GetAllNodes().size(), 1, MAX_SPLINE_NODES);
     82            const std::vector<SplineData>& nodes = path.GetAllNodes();
     83            for (size_t i = 0; i < nodes.size(); ++i)
     84            {
     85                if (i > 0)
     86                    serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance);
     87                else
     88                    serialize.NumberFixed_Unbounded("NodeDeltaTime", fixed::Zero());
     89                serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X);
     90                serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y);
     91                serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z);
     92
     93                serialize.NumberFixed_Unbounded("RotationX", nodes[i].Rotation.X);
     94                serialize.NumberFixed_Unbounded("RotationY", nodes[i].Rotation.Y);
     95                serialize.NumberFixed_Unbounded("RotationZ", nodes[i].Rotation.Z);
     96            }
     97
     98            if (!data->m_LookAtTarget)
     99                continue;
     100
     101            const std::vector<SplineData>& targetNodes = path.getTargetSpline()->GetAllNodes();
     102            serialize.NumberU32("NumberOfTargetNodes", targetNodes.size(), 1, MAX_SPLINE_NODES);
     103            for (size_t i = 0; i < targetNodes.size(); ++i)
     104            {
     105                if (i > 0)
     106                    serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance);
     107                else
     108                    serialize.NumberFixed_Unbounded("NodeDeltaTime", fixed::Zero());
     109                serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X);
     110                serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y);
     111                serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z);
     112            }
     113        }
     114    }
     115
     116    virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
     117    {
     118        if (!g_Game || !g_Game->GetView())
     119        {
     120            LOGERROR("Trying to deserialize cinematics when GameView isn't initialized!");
     121            return;
     122        }
     123        CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData();
     124        deserialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed);
     125        uint32_t numberOfPaths = 0;
     126        deserialize.NumberU32_Unbounded("NumberOfPaths", numberOfPaths);
     127        for (uint32_t i = 0; i < numberOfPaths; ++i)
     128        {
     129            CCinemaData data;
     130
     131            deserialize.String("PathName", data.m_Name, 1, 2048);
     132            deserialize.String("PathOrientation", data.m_Orientation, 1, 2048);
     133            deserialize.String("PathMode", data.m_Mode, 1, 2048);
     134            deserialize.String("PathStyle", data.m_Style, 1, 2048);
     135            deserialize.NumberFixed_Unbounded("PathTimescale", data.m_Timescale);
     136            deserialize.Bool("LookAtTarget", data.m_LookAtTarget);
     137
     138            TNSpline pathSpline, targetSpline;
     139            uint32_t numberOfNodes = 0;
     140            deserialize.NumberU32("NumberOfNodes", numberOfNodes, 1, MAX_SPLINE_NODES);
     141            for (uint32_t j = 0; j < numberOfNodes; ++j)
     142            {
     143                SplineData node;
     144                deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance);
     145
     146                deserialize.NumberFixed_Unbounded("PositionX", node.Position.X);
     147                deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y);
     148                deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z);
     149
     150                deserialize.NumberFixed_Unbounded("RotationX", node.Rotation.X);
     151                deserialize.NumberFixed_Unbounded("RotationY", node.Rotation.Y);
     152                deserialize.NumberFixed_Unbounded("RotationZ", node.Rotation.Z);
     153
     154                pathSpline.AddNode(node.Position, node.Rotation, node.Distance);
     155            }
     156
     157            if (data.m_LookAtTarget)
     158            {
     159                uint32_t numberOfTargetNodes = 0;
     160                deserialize.NumberU32("NumberOfTargetNodes", numberOfTargetNodes, 1, MAX_SPLINE_NODES);
     161                for (uint32_t j = 0; j < numberOfTargetNodes; ++j)
     162                {
     163                    SplineData node;
     164                    deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance);
     165
     166                    deserialize.NumberFixed_Unbounded("PositionX", node.Position.X);
     167                    deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y);
     168                    deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z);
     169
     170                    targetSpline.AddNode(node.Position, CFixedVector3D(), node.Distance);
     171                }
     172            }
     173
     174            // Construct cinema path with data gathered
     175            CCinemaPath path(data, pathSpline, targetSpline);
     176            p_CinematicSimulationData->m_Paths[data.m_Name] = path;
     177        }
     178        g_Game->GetView()->GetCinema()->SetEnabled(p_CinematicSimulationData->m_Enabled);
     179    }
     180
     181    virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
     182    {
     183        switch (msg.GetType())
     184        {
     185        case MT_Update:
     186        {
     187            const CMessageUpdate &msgData = static_cast<const CMessageUpdate&>(msg);
     188            CinematicSimulationData* pCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData();
     189            if (!pCinematicSimulationData->m_Enabled)
     190                break;
     191
     192            if (pCinematicSimulationData->m_ElapsedTime >= pCinematicSimulationData->m_TotalTime)
     193            {
     194                pCinematicSimulationData->m_ElapsedTime = fixed::Zero();
     195                pCinematicSimulationData->m_TotalTime = fixed::Zero();
     196                g_Game->GetView()->GetCinema()->SetEnabled(false);
     197                g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, CMessageCinemaQueueEnded());
     198            }
     199            else
     200            {
     201                pCinematicSimulationData->m_ElapsedTime += msgData.turnLength;
     202                pCinematicSimulationData->m_CurrentPathElapsedTime += msgData.turnLength;
     203                if (pCinematicSimulationData->m_CurrentPathElapsedTime >= pCinematicSimulationData->m_PathQueue.front().GetDuration())
     204                {
     205                    CMessageCinemaPathEnded msgCinemaPathEnded(pCinematicSimulationData->m_PathQueue.front().GetName());
     206                    pCinematicSimulationData->m_PathQueue.pop_front();
     207                    g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msgCinemaPathEnded);
     208                }
     209            }
     210            break;
     211        }
     212        default:
     213            break;
     214        }
     215    }
     216
     217    virtual void AddCinemaPathToQueue(CStrW name)
     218    {
     219        if (!g_Game || !g_Game->GetView())
     220        {
     221            LOGERROR("Trying to add cinema path when GameView isn't initialized!");
     222            return;
     223        }
     224        g_Game->GetView()->GetCinema()->AddPathToQueue(name);
     225        CinematicSimulationData* pGetCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData();
     226        pGetCinematicSimulationData->m_TotalTime += pGetCinematicSimulationData->m_Paths[name].GetDuration();
     227    }
     228
     229    virtual void Play()
     230    {
     231        if (!g_Game || !g_Game->GetView())
     232        {
     233            LOGERROR("Trying to play cinematics when GameView isn't initialized!");
     234            return;
     235        }
     236        g_Game->GetView()->GetCinema()->Play();
     237        g_Game->GetView()->GetCinema()->SetEnabled(true);
     238    }
     239
     240    virtual void Stop()
     241    {
     242        if (!g_Game || !g_Game->GetView())
     243        {
     244            LOGERROR("Trying to stop cinematics when GameView isn't initialized!");
     245            return;
     246        }
     247        g_Game->GetView()->GetCinema()->Stop();
     248        g_Game->GetView()->GetCinema()->SetEnabled(false);
     249    }
     250
     251};
     252
     253REGISTER_COMPONENT_TYPE(CinemaManager)
  • source/simulation2/components/CCmpOverlayRenderer.cpp

     
    166166
    167167    void RenderSubmit(SceneCollector& collector)
    168168    {
    169         if (!m_Enabled)
     169        if (!m_Enabled || !ICmpOverlayRenderer::m_OverrideVisible)
    170170            return;
    171171
    172172        for (size_t i = 0; i < m_Sprites.size(); ++i)
  • source/simulation2/components/CCmpSelectable.cpp

     
    587587void CCmpSelectable::RenderSubmit(SceneCollector& collector)
    588588{
    589589    // don't render selection overlay if it's not gonna be visible
     590    if (!ICmpSelectable::m_OverrideVisible)
     591        return;
     592
    590593    if (m_Visible && m_Color.a > 0)
    591594    {
    592595        if (!m_Cached)
  • source/simulation2/components/CCmpTerritoryManager.cpp

     
    123123        m_TriggerEvent = true;
    124124        m_EnableLineDebugOverlays = false;
    125125        m_DirtyID = 1;
     126        m_Visible = true;
    126127
    127128        m_AnimTime = 0.0;
    128129
     
    275276    void Interpolate(float frameTime, float frameOffset);
    276277
    277278    void RenderSubmit(SceneCollector& collector);
     279
     280    void SetVisibility(bool visible)
     281    {
     282        m_Visible = visible;
     283    }
     284
     285private:
     286
     287    bool m_Visible;
    278288};
    279289
    280290REGISTER_COMPONENT_TYPE(TerritoryManager)
     
    644654
    645655void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector)
    646656{
     657    if (!m_Visible)
     658        return;
     659
    647660    for (size_t i = 0; i < m_BoundaryLines.size(); ++i)
    648661        collector.Submit(&m_BoundaryLines[i].overlay);
    649662   
  • source/simulation2/components/ICmpCinemaManager.cpp

     
     1/* Copyright (C) 2016 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 "ICmpCinemaManager.h"
     21
     22#include "simulation2/system/InterfaceScripted.h"
     23
     24BEGIN_INTERFACE_WRAPPER(CinemaManager)
     25DEFINE_INTERFACE_METHOD_1("AddCinemaPathToQueue", void, ICmpCinemaManager, AddCinemaPathToQueue, CStrW)
     26DEFINE_INTERFACE_METHOD_0("Play", void, ICmpCinemaManager, Play)
     27DEFINE_INTERFACE_METHOD_0("Stop", void, ICmpCinemaManager, Stop)
     28END_INTERFACE_WRAPPER(CinemaManager)
  • source/simulation2/components/ICmpCinemaManager.h

     
     1/* Copyright (C) 2016 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_ICMPCINEMAMANAGER
     19#define INCLUDED_ICMPCINEMAMANAGER
     20
     21#include "simulation2/system/Interface.h"
     22
     23#include "ps/CStr.h"
     24
     25/**
     26 * Component for CCinemaManager class
     27 * TODO: write description
     28 */
     29
     30class ICmpCinemaManager : public IComponent
     31{
     32public:
     33    // TODO: add path name and description
     34    virtual void AddCinemaPathToQueue(CStrW name) = 0;
     35   
     36    virtual void Play() = 0;
     37    virtual void Stop() = 0;
     38
     39    DECLARE_INTERFACE_TYPE(CinemaManager)
     40};
     41
     42#endif // INCLUDED_ICMPCINEMAMANAGER
     43 No newline at end of file
  • source/simulation2/components/ICmpOverlayRenderer.cpp

     
    2525DEFINE_INTERFACE_METHOD_0("Reset", void, ICmpOverlayRenderer, Reset)
    2626DEFINE_INTERFACE_METHOD_5("AddSprite", void, ICmpOverlayRenderer, AddSprite, VfsPath, CFixedVector2D, CFixedVector2D, CFixedVector3D, std::string)
    2727END_INTERFACE_WRAPPER(OverlayRenderer)
     28
     29bool ICmpOverlayRenderer::m_OverrideVisible = true;
     30 No newline at end of file
  • source/simulation2/components/ICmpOverlayRenderer.h

     
    5252     */
    5353    virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D offset, std::string color = "255 255 255 255") = 0;
    5454
     55    /**
     56    * Enables or disables rendering of all sprites.
     57    * @param visible Whether the selectable should be visible.
     58    */
     59    static void SetOverrideVisibility(bool visible)
     60    {
     61        ICmpOverlayRenderer::m_OverrideVisible = visible;
     62    }
     63
    5564    DECLARE_INTERFACE_TYPE(OverlayRenderer)
     65
     66protected:
     67    static bool m_OverrideVisible;
    5668};
    5769
    5870#endif // INCLUDED_ICMPOVERLAYRENDERER
  • source/simulation2/components/ICmpSelectable.cpp

     
    2828END_INTERFACE_WRAPPER(Selectable)
    2929
    3030bool ICmpSelectable::ms_EnableDebugOverlays = false;
     31bool ICmpSelectable::m_OverrideVisible = true;
  • source/simulation2/components/ICmpSelectable.h

     
    6767    virtual void SetVisibility(bool visible) = 0;
    6868
    6969    /**
     70    * Enables or disables rendering of all entities selectable.
     71    * @param visible Whether the selectable should be visible.
     72    */
     73    static void SetOverrideVisibility(bool visible)
     74    {
     75        ICmpSelectable::m_OverrideVisible = visible;
     76    }
     77
     78    /**
    7079     * Set the alpha of the selection highlight. Set to 0 to hide the highlight.
    7180     */
    7281    virtual void SetSelectionHighlightAlpha(float alpha) = 0;
     
    7786    // and methods, where we can keep settings like these. Note that any such data store would need to be per-component-manager
    7887    // and not entirely global, to support multiple simulation instances.
    7988    static bool ms_EnableDebugOverlays; // ms for member static
     89
     90protected:
     91    static bool m_OverrideVisible;
    8092};
    8193
    8294#endif // INCLUDED_ICMPSELECTABLE
  • source/simulation2/components/ICmpTerritoryManager.h

     
    7878     */
    7979     virtual u8 GetTerritoryPercentage(player_id_t player) = 0;
    8080
     81    /**
     82     * Enables or disables rendering of an territory borders.
     83     */
     84    virtual void SetVisibility(bool visible) = 0;
     85
    8186    DECLARE_INTERFACE_TYPE(TerritoryManager)
    8287};
    8388
  • source/simulation2/MessageTypes.h

     
    2929
    3030#include "maths/Vector3D.h"
    3131
     32#include "ps/CStr.h"
     33
    3234#define DEFAULT_MESSAGE_IMPL(name) \
    3335    virtual int GetType() const { return MT_##name; } \
    3436    virtual const char* GetScriptHandlerName() const { return "On" #name; } \
     
    538540    }
    539541};
    540542
     543/**
     544* Cinematics events
     545*/
     546
     547class CMessageCinemaPathEnded : public CMessage
     548{
     549public:
     550    DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
     551
     552    CMessageCinemaPathEnded(CStrW name) :
     553    name(name)
     554    {
     555    }
     556
     557    CStrW name;
     558};
     559
     560class CMessageCinemaQueueEnded : public CMessage
     561{
     562public:
     563    DEFAULT_MESSAGE_IMPL(CinemaQueueEnded)
     564};
     565
    541566#endif // INCLUDED_MESSAGETYPES
  • source/simulation2/scripting/MessageTypeConversions.cpp

     
    470470    return new CMessageMinimapPing();
    471471}
    472472
     473////////////////////////////////
     474
     475JS::Value CMessageCinemaPathEnded::ToJSVal(ScriptInterface& scriptInterface) const
     476{
     477    TOJSVAL_SETUP();
     478    SET_MSG_PROPERTY(name);
     479    return JS::ObjectValue(*obj);
     480}
     481
     482CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
     483{
     484    FROMJSVAL_SETUP();
     485    GET_MSG_PROPERTY(CStrW, name);
     486    return new CMessageCinemaPathEnded(name);
     487}
     488
     489////////////////////////////////
     490
     491JS::Value CMessageCinemaQueueEnded::ToJSVal(ScriptInterface& scriptInterface) const
     492{
     493    TOJSVAL_SETUP();
     494    return JS::ObjectValue(*obj);
     495}
     496
     497CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
     498{
     499    FROMJSVAL_SETUP();
     500    return new CMessageCinemaQueueEnded();
     501}
     502
    473503////////////////////////////////////////////////////////////////
    474504
    475505CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val)
  • source/simulation2/system/ComponentManager.cpp

     
    711711{
    712712    CParamNode noParam;
    713713    AddComponent(m_SystemEntity, CID_TemplateManager, noParam);
     714    AddComponent(m_SystemEntity, CID_CinemaManager, noParam);
    714715    AddComponent(m_SystemEntity, CID_CommandQueue, noParam);
    715716    AddComponent(m_SystemEntity, CID_ObstructionManager, noParam);
    716717    AddComponent(m_SystemEntity, CID_ParticleManager, noParam);
  • source/simulation2/TypeList.h

     
    5757MESSAGE(TemplateModification)
    5858MESSAGE(VisionRangeChanged)
    5959MESSAGE(MinimapPing)
     60MESSAGE(CinemaPathEnded)
     61MESSAGE(CinemaQueueEnded)
    6062
    6163// TemplateManager must come before all other (non-test) components,
    6264// so that it is the first to be (de)serialized
     
    7577INTERFACE(AIManager)
    7678COMPONENT(AIManager)
    7779
     80INTERFACE(CinemaManager)
     81COMPONENT(CinemaManager)
     82
    7883INTERFACE(CommandQueue)
    7984COMPONENT(CommandQueue)
    8085
  • source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp

     
    3838{
    3939    sCinemaPath path;
    4040    const CCinemaData* data = source->GetData();
    41     path.mode = data->m_Mode;
    42     path.style = data->m_Style;
     41    //path.mode = data->m_Mode;
     42    //path.style = data->m_Style;
    4343    path.growth = data->m_Growth;
    44     path.timescale = data->m_Timescale;
     44    path.timescale = data->m_Timescale.ToFloat();
    4545    path.change = data->m_Switch;
    4646
    4747    return path;
     
    5151    CCinemaData data;
    5252    data.m_Growth = data.m_GrowthCount = path.growth;
    5353    data.m_Switch = path.change;
    54     data.m_Mode = path.mode;
    55     data.m_Style = path.style;
     54    //data.m_Mode = path.mode;
     55    //data.m_Style = path.style;
    5656   
    5757    return data;
    5858}
     
    5959sCinemaSplineNode ConstructCinemaNode(const SplineData& data)
    6060{
    6161    sCinemaSplineNode node;
    62     node.px = data.Position.X;
    63     node.py = data.Position.Y;
    64     node.pz = data.Position.Z;
     62    node.px = data.Position.X.ToFloat();
     63    node.py = data.Position.Y.ToFloat();
     64    node.pz = data.Position.Z.ToFloat();
    6565   
    66     node.rx = data.Rotation.X;
    67     node.ry = data.Rotation.Y;
    68     node.rz = data.Rotation.Z;
    69     node.t = data.Distance;
     66    node.rx = data.Rotation.X.ToFloat();
     67    node.ry = data.Rotation.Y.ToFloat();
     68    node.rz = data.Rotation.Z.ToFloat();
     69    node.t = data.Distance.ToFloat();
    7070   
    7171    return node;
    7272}
     
    112112    {
    113113        CStrW pathName(*it->name);
    114114        paths[pathName] = CCinemaPath();
    115         paths[pathName].SetTimescale(it->timescale);
     115        paths[pathName].SetTimescale(fixed::FromFloat(it->timescale));
    116116
    117117        const sCinemaPath& atlasPath = *it;
    118118        const std::vector<sCinemaSplineNode> nodes = *atlasPath.nodes;
     
    121121   
    122122        for ( size_t j=0; j<nodes.size(); ++j )
    123123        {   
    124             spline.AddNode( CVector3D(nodes[j].px, nodes[j].py, nodes[j].pz),
    125                             CVector3D(nodes[j].rx, nodes[j].ry, nodes[j].rz), nodes[j].t );
     124            spline.AddNode( CFixedVector3D(fixed::FromFloat(nodes[j].px), fixed::FromFloat(nodes[j].py), fixed::FromFloat(nodes[j].pz)),
     125                CFixedVector3D(fixed::FromFloat(nodes[j].rx), fixed::FromFloat(nodes[j].ry), fixed::FromFloat(nodes[j].rz)), fixed::FromFloat(nodes[j].t));
    126126        }
    127         paths[pathName] = CCinemaPath(data, spline);
     127        paths[pathName] = CCinemaPath(data, spline, TNSpline());
    128128    }
    129129
    130130    g_Game->GetView()->GetCinema()->SetAllPaths(paths);
     
    155155{
    156156    CCinemaManager* manager = g_Game->GetView()->GetCinema();
    157157   
    158     if ( msg->mode == eCinemaEventMode::SMOOTH )
    159         manager->OverridePath(*msg->path); 
    160     else if ( msg->mode == eCinemaEventMode::IMMEDIATE_PATH )
    161         manager->MoveToPointAt(msg->t);
     158    if (msg->mode == eCinemaEventMode::SMOOTH)
     159    {
     160        manager->ClearQueue();
     161        manager->AddPathToQueue(*msg->path);
     162    }
    162163    else if ( msg->mode == eCinemaEventMode::RESET )
    163164    {
    164165//      g_Game->GetView()->ResetCamera();
    165166    }
    166     else if ( msg->mode == eCinemaEventMode::SELECT )
    167         manager->SetCurrentPath(*msg->path, msg->drawCurrent, msg->lines);
    168167    else
    169168        ENSURE(false);
    170169}
  • source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp

     
    5757QUERYHANDLER(CinemaRecord)
    5858{
    5959    CCinemaManager* manager = g_Game->GetView()->GetCinema();
    60     manager->SetCurrentPath(*msg->path, false, false);
    6160
    6261    const int w = msg->width, h = msg->height;
    6362
     
    8180    for (int frame = 0; frame < num_frames; ++frame)
    8281    {
    8382        AtlasView::GetView_Game()->Update(1.f / msg->framerate);
    84 
    85         manager->MoveToPointAt((float)frame/msg->framerate);
     83       
    8684        Render();
    8785        Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas);
    8886