Ticket #3301: cinematic_camera_core_v1.4.patch

File cinematic_camera_core_v1.4.patch, 92.7 KB (added by Vladislav Belov, 8 years ago)

Serialize & deserialize implemented

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

     
    1919    "Interval",
    2020    "Range",
    2121    "TreasureCollected",
     22    "CinemaPathEnded"
    2223];
    2324
    2425Trigger.prototype.Init = function()
     
    234235    // See function "SpawnUnits" in ProductionQueue for more details
    235236};
    236237
    237 // Handles "OnTrainingFinished" event.
     238// Handles "OnResearchFinished" event.
    238239Trigger.prototype.OnGlobalResearchFinished = function(msg)
    239240{
    240241    this.CallEvent("ResearchFinished", msg);
     
    242243    //                           "tech": tech}
    243244};
    244245
     246// Handles "OnCinemaPathEnded" event.
     247Trigger.prototype.OnGlobalCinemaPathEnded = function(msg)
     248{
     249    this.CallEvent("CinemaPathEnded", msg);
     250}
     251
    245252Trigger.prototype.OnGlobalOwnershipChanged = function(msg)
    246253{
    247254    this.CallEvent("OwnershipChanged", msg);
  • source/graphics/CinemaManager.cpp

     
     1/* Copyright (C) 2015 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
     19#include "precompiled.h"
     20
     21#include "Camera.h"
     22#include "CinemaManager.h"
     23#include "GameView.h"
     24#include "gui/CGUI.h"
     25#include "gui/GUIManager.h"
     26#include "gui/IGUIObject.h"
     27#include "lib/ogl.h"
     28#include "maths/MathUtil.h"
     29#include "maths/Quaternion.h"
     30#include "maths/Vector3D.h"
     31#include "maths/Vector4D.h"
     32#include "ps/CLogger.h"
     33#include "ps/CStr.h"
     34#include "ps/Game.h"
     35#include "ps/Hotkey.h"
     36#include "simulation2/components/ICmpOverlayRenderer.h"
     37#include "simulation2/components/ICmpRangeManager.h"
     38#include "simulation2/components/ICmpSelectable.h"
     39#include "simulation2/components/ICmpTerritoryManager.h"
     40#include "simulation2/MessageTypes.h"
     41#include "simulation2/system/ComponentManager.h"
     42#include "simulation2/Simulation2.h"
     43#include <sstream>
     44#include <string>
     45#include "renderer/Renderer.h"
     46
     47
     48CCinemaManager::CCinemaManager()
     49    : m_DrawPaths(false)
     50{
     51}
     52
     53void CCinemaManager::AddPath(const CStrW& name, CCinemaPath path)
     54{
     55    if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end())
     56    {
     57        LOGWARNING("Path with name '%s' already exists", name.ToUTF8());
     58        return;
     59    }
     60    m_CinematicSimulationData.m_Paths[name] = path;
     61}
     62
     63void CCinemaManager::AddPathToQueue(const CStrW& name)
     64{
     65    if (!HasPath(name))
     66    {
     67        LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8());
     68        return;
     69    }
     70    m_CinematicSimulationData.m_PathQueue.push_back(m_CinematicSimulationData.m_Paths[name]);
     71}
     72
     73void CCinemaManager::ClearQueue()
     74{
     75    m_CinematicSimulationData.m_PathQueue.clear();
     76}
     77
     78void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths)
     79{
     80    m_CinematicSimulationData.m_Paths = paths;
     81}
     82
     83void CCinemaManager::SetCurrentPath(const CStrW& name, bool current)
     84{
     85    // ...
     86}
     87
     88bool CCinemaManager::HasPath(const CStrW& name) const
     89{
     90    return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end();
     91}
     92
     93void CCinemaManager::SetEnabled(bool enabled)
     94{
     95    // TODO: maybe assert?
     96    if (m_CinematicSimulationData.m_PathQueue.empty() && enabled)
     97    {
     98        enabled = false;
     99        m_CinematicSimulationData.m_Paused = true;
     100    }
     101
     102    if (m_CinematicSimulationData.m_Enabled == enabled)
     103        return;
     104
     105    // sn - session gui object
     106    IGUIObject *sn = g_GUI->FindObjectByName("sn");
     107    CmpPtr<ICmpRangeManager> cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
     108    CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
     109
     110    // GUI visibility
     111    if (sn)
     112    {
     113        if (enabled)
     114            sn->SetSetting("hidden", L"true");
     115        else
     116            sn->SetSetting("hidden", L"false");
     117    }
     118
     119    // Overlay visibility
     120    g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled);
     121    if (cmpRangeManager)
     122    {
     123        if (enabled)
     124            m_CinematicSimulationData.m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1);
     125        // TODO: improve m_MapRevealed state and without fade in
     126        cmpRangeManager->SetLosRevealAll(-1, enabled);
     127    }
     128    if (cmpTerritoryManager)
     129        cmpTerritoryManager->SetVisibility(!enabled);
     130    ICmpSelectable::SetOverrideVisibility(!enabled);
     131    ICmpOverlayRenderer::SetOverrideVisibility(!enabled);
     132
     133    m_CinematicSimulationData.m_Enabled = enabled;
     134}
     135
     136void CCinemaManager::MoveToPointAt(float time)
     137{
     138    // TODO: Update after Atlas UI patch
     139    /*ENSURE(m_CurrentPath != m_Paths.end());
     140    ClearQueue();
     141
     142    m_CurrentPath->second.m_TimeElapsed = time;
     143    if (!m_CurrentPath->second.Validate())
     144        return;
     145
     146    m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed /
     147                m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(),
     148                m_CurrentPath->second.m_PreviousRotation );*/
     149}
     150
     151void CCinemaManager::Play()
     152{
     153    SetEnabled(true);
     154    m_CinematicSimulationData.m_Paused = false;
     155}
     156
     157void CCinemaManager::Pause()
     158{
     159    m_CinematicSimulationData.m_Paused = true;
     160}
     161
     162void CCinemaManager::Stop()
     163{
     164    m_CinematicSimulationData.m_Paused = true;
     165    SetEnabled(false);
     166    m_CinematicSimulationData.m_PathQueue.clear();
     167}
     168
     169void CCinemaManager::Skip()
     170{
     171    Next(true);
     172}
     173
     174void CCinemaManager::Next(bool skipped)
     175{
     176    CMessageCinemaPathEnded msg(m_CinematicSimulationData.m_PathQueue.back().GetName(), skipped);
     177    g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msg);
     178
     179    m_CinematicSimulationData.m_PathQueue.pop_front();
     180    if (m_CinematicSimulationData.m_PathQueue.empty())
     181    {
     182        SetEnabled(false);
     183        m_CinematicSimulationData.m_Paused = true;
     184    }
     185}
     186
     187void CCinemaManager::Update(const float deltaRealTime)
     188{
     189    if (g_Game->m_Paused != m_CinematicSimulationData.m_Paused)
     190    {
     191        m_CinematicSimulationData.m_Paused = g_Game->m_Paused;
     192
     193        // sn - session gui object
     194        IGUIObject *sn = g_GUI->FindObjectByName("sn");
     195
     196        // GUI visibility
     197        if (sn)
     198        {
     199            if (m_CinematicSimulationData.m_Paused)
     200                sn->SetSetting("hidden", L"false");
     201            else
     202                sn->SetSetting("hidden", L"true");
     203        }
     204    }
     205
     206    if (!m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused)
     207        return;
     208   
     209    if (HotkeyIsPressed("leave"))
     210    {
     211        Skip();
     212        return;
     213    }
     214
     215    ENSURE(m_CinematicSimulationData.m_PathQueue.size() > 0);
     216    if (m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime))
     217        return;
     218
     219    Next();
     220    return;
     221}
     222
     223void CCinemaManager::Render()
     224{
     225    if (GetEnabled())
     226    {
     227        DrawBars();
     228        return;
     229    }
     230   
     231    if (!m_DrawPaths)
     232        return;
     233
     234    // draw all paths
     235    for (auto it : m_CinematicSimulationData.m_Paths)
     236        it.second.Draw();
     237}
     238
     239void CCinemaManager::DrawBars() const
     240{
     241    int height = (float)g_xres / 2.39f;
     242    int shift = (g_yres - height) / 2;
     243    if (shift <= 0)
     244        return;
     245
     246#if CONFIG2_GLES
     247    #warning TODO : implement bars for GLES
     248#else
     249    // Set up transform for GL bars
     250    glMatrixMode(GL_PROJECTION);
     251    glPushMatrix();
     252    glLoadIdentity();
     253    glMatrixMode(GL_MODELVIEW);
     254    glPushMatrix();
     255    glLoadIdentity();
     256    CMatrix3D transform;
     257    transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
     258    glLoadMatrixf(&transform._11);
     259
     260    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
     261
     262    glEnable(GL_BLEND);
     263    glDisable(GL_DEPTH_TEST);
     264
     265    glBegin(GL_QUADS);
     266    glVertex2i(0, 0);
     267    glVertex2i(g_xres, 0);
     268    glVertex2i(g_xres, shift);
     269    glVertex2i(0, shift);
     270    glEnd();
     271
     272    glBegin(GL_QUADS);
     273    glVertex2i(0, g_yres - shift);
     274    glVertex2i(g_xres, g_yres - shift);
     275    glVertex2i(g_xres, g_yres);
     276    glVertex2i(0, g_yres);
     277    glEnd();
     278
     279    glDisable(GL_BLEND);
     280    glEnable(GL_DEPTH_TEST);
     281
     282    // Restore transform
     283    glMatrixMode(GL_PROJECTION);
     284    glPopMatrix();
     285    glMatrixMode(GL_MODELVIEW);
     286    glPopMatrix();
     287#endif
     288}
     289
     290InReaction cinema_manager_handler(const SDL_Event_* ev)
     291{
     292    // put any events that must be processed even if inactive here
     293    if (!g_Game || !g_Game->IsGameStarted())
     294        return IN_PASS;
     295
     296    CCinemaManager* pCinemaManager = g_Game->GetView()->GetCinema();
     297
     298    return pCinemaManager->HandleEvent(ev);
     299}
     300
     301InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev)
     302{
     303    switch (ev->ev.type)
     304    {
     305    case SDL_MOUSEBUTTONDOWN:
     306    case SDL_MOUSEBUTTONUP:
     307        if (GetEnabled() && !m_CinematicSimulationData.m_Paused)
     308            return IN_HANDLED;
     309    default:
     310        return IN_PASS;
     311    }
     312}
     313
     314bool CCinemaManager::GetEnabled() const
     315{
     316    return m_CinematicSimulationData.m_Enabled;
     317}
     318
     319bool CCinemaManager::IsPlaying() const
     320{
     321    return !m_CinematicSimulationData.m_Paused;
     322}
     323
     324const std::map<CStrW, CCinemaPath>& CCinemaManager::GetAllPaths()
     325{
     326    return m_CinematicSimulationData.m_Paths;
     327}
     328
     329CinematicSimulationData* CCinemaManager::GetCinematicSimulationData()
     330{
     331    return &m_CinematicSimulationData;
     332}
     333 No newline at end of file
  • source/graphics/CinemaManager.h

     
     1/* Copyright (C) 2015 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
     19#ifndef INCLUDED_CINEMAMANAGER
     20#define INCLUDED_CINEMAMANAGER
     21
     22#include <list>
     23#include <map>
     24
     25#include "lib/input.h" // InReaction - can't forward-declare enum
     26
     27#include "graphics/CinemaPath.h"
     28#include "ps/CStr.h"
     29
     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    CinematicSimulationData()
     47        : m_Enabled(false), m_Paused(true) {}
     48};
     49
     50/**
     51 * Class for in game playing of cinematics. Should only be instantiated in CGameView.
     52 */
     53
     54class CCinemaManager
     55{
     56public:
     57    CCinemaManager();
     58    ~CCinemaManager() {}
     59
     60    /**
     61     * Adds the path to the path list
     62     * @param name path name
     63     * @param CCinemaPath path data
     64     */
     65    void AddPath(const CStrW& name, CCinemaPath path);
     66
     67    /**
     68     * Adds the path to the playlist
     69     * @param name path name
     70     */
     71    void AddPathToQueue(const CStrW& name);
     72
     73    /**
     74     * Clears the playlist
     75     */
     76    void ClearQueue();
     77
     78    /**
     79     * Checks the path name in the path list
     80     * @param name path name
     81     * @return true if path with that name exists, else false
     82     */
     83    bool HasPath(const CStrW& name) const;
     84   
     85    /**
     86     * These stop track play, and accept time, not ratio of time
     87     * @time point in the timeline
     88     */
     89    void MoveToPointAt(float time);
     90
     91    // TODO: remove legacy methods after Atlas UI patch
     92    const std::map<CStrW, CCinemaPath>& GetAllPaths();
     93    void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks);
     94    void SetCurrentPath(const CStrW& name, bool current);
     95
     96    /**
     97     * Starts play paths
     98     */
     99    void Play();
     100    void Pause();
     101    void Next(bool skipped = false);
     102    void Stop();
     103    void Skip();
     104    bool IsPlaying() const;
     105
     106    /**
     107     * Renders black bars and paths (if enabled)
     108     */
     109    void Render();
     110    void DrawBars() const;
     111
     112    /**
     113     * Get current enable state of the cinema manager
     114     */
     115    bool GetEnabled() const;
     116
     117    /**
     118     * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc)
     119     * @enable new state
     120     */
     121    void SetEnabled(bool enabled);
     122
     123    /**
     124     * Updates CCinemManager and current path
     125     * @param deltaRealTime Elapsed real time since the last frame.
     126     */
     127    void Update(const float deltaRealTime);
     128
     129    InReaction HandleEvent(const SDL_Event_* ev);
     130
     131    CinematicSimulationData* GetCinematicSimulationData();
     132
     133private:   
     134    bool m_DrawPaths;
     135
     136    // Cinematic data is accessed from the simulation
     137    CinematicSimulationData m_CinematicSimulationData;
     138};
     139
     140extern InReaction cinema_manager_handler(const SDL_Event_* ev);
     141
     142#endif
  • source/graphics/CinemaPath.cpp

     
     1/* Copyright (C) 2015 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 "CinemaPath.h"
     21
     22#include <sstream>
     23#include <string>
     24
     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"
     31#include "lib/ogl.h"
     32#include "maths/MathUtil.h"
     33#include "maths/Quaternion.h"
     34#include "maths/Vector3D.h"
     35#include "maths/Vector4D.h"
     36#include "ps/CLogger.h"
     37#include "ps/CStr.h"
     38#include "ps/Game.h"
     39#include "renderer/Renderer.h"
     40
     41CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline)
     42    : CCinemaData(data), TNSpline(spline), m_TargetSpline(targetSpline), m_TimeElapsed(0.f)
     43{
     44    BuildSpline();
     45
     46    if (m_Orientation == L"target")
     47    {
     48        m_LookAtTarget = true;
     49        ENSURE(m_TargetSpline.GetAllNodes().size() > 0);
     50    }
     51
     52    // Set distortion mode and style
     53    if (data.m_Mode == L"ease_in")
     54        DistModePtr = &CCinemaPath::EaseIn;
     55    else if (data.m_Mode == L"ease_out")
     56        DistModePtr = &CCinemaPath::EaseOut;
     57    else if (data.m_Mode == L"ease_inout")
     58        DistModePtr = &CCinemaPath::EaseInOut;
     59    else if (data.m_Mode == L"ease_outin")
     60        DistModePtr = &CCinemaPath::EaseOutIn;
     61    else
     62    {
     63        LOGWARNING("Cinematic mode not found for '%s'\n", data.m_Mode.ToUTF8().c_str());
     64        DistModePtr = &CCinemaPath::EaseInOut;
     65    }
     66
     67    if (data.m_Style == L"default")
     68        DistStylePtr = &CCinemaPath::EaseDefault;
     69    else if (data.m_Style == L"growth")
     70        DistStylePtr = &CCinemaPath::EaseGrowth;
     71    else if (data.m_Style == L"expo")
     72        DistStylePtr = &CCinemaPath::EaseExpo;
     73    else if (data.m_Style == L"circle")
     74        DistStylePtr = &CCinemaPath::EaseCircle;
     75    else if (data.m_Style == L"sine")
     76        DistStylePtr = &CCinemaPath::EaseSine;
     77    else
     78    {
     79        LOGWARNING("Cinematic style not found for '%s'\n", data.m_Style.ToUTF8().c_str());
     80        DistStylePtr = &CCinemaPath::EaseDefault;
     81    }
     82}
     83
     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));
     89}
     90
     91void CCinemaPath::DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const
     92{
     93    if (spline.NodeCount < 2 || DistModePtr == NULL)
     94        return;
     95    if (spline.NodeCount == 2 && lines)
     96        smoothness = 2;
     97
     98    float start = spline.MaxDistance / smoothness;
     99    float time = 0;
     100
     101#if CONFIG2_GLES
     102    #warning TODO : do something about CCinemaPath on GLES
     103#else
     104
     105    glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W);
     106    if (lines)
     107    {
     108        glLineWidth(1.8f);
     109        glEnable(GL_LINE_SMOOTH);
     110        glBegin(GL_LINE_STRIP);
     111
     112        for (int i = 0; i <= smoothness; ++i)
     113        {
     114            // Find distorted time
     115            time = start*i / spline.MaxDistance;
     116            CVector3D tmp = spline.GetPosition(time);
     117            glVertex3f(tmp.X, tmp.Y, tmp.Z);
     118        }
     119        glEnd();
     120        glDisable(GL_LINE_SMOOTH);
     121        glLineWidth(1.0f);
     122    }
     123    else
     124    {
     125        smoothness /= 2;
     126        start = spline.MaxDistance / smoothness;
     127        glEnable(GL_POINT_SMOOTH);
     128        glPointSize(3.0f);
     129        glBegin(GL_POINTS);
     130
     131        for (int i = 0; i <= smoothness; ++i)
     132        {
     133            // Find distorted time
     134            time = (this->*DistModePtr)(start*i / spline.MaxDistance);
     135            CVector3D tmp = spline.GetPosition(time);
     136            glVertex3f(tmp.X, tmp.Y, tmp.Z);
     137        }
     138        glColor3f(1.0f, 1.0f, 0.0f);    // yellow
     139
     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            );
     146
     147        glEnd();
     148        glPointSize(1.0f);
     149        glDisable(GL_POINT_SMOOTH);
     150    }
     151
     152#endif
     153}
     154
     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
     192void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)
     193{
     194    CCamera *camera = g_Game->GetView()->GetCamera();
     195    t = (this->*DistModePtr)(t);
     196    CVector3D pos = GetPosition(t);
     197   
     198    if (m_LookAtTarget)
     199    {
     200        if (m_TimeElapsed <= m_TargetSpline.MaxDistance)
     201            camera->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance), 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();
     218}
     219
     220// Distortion mode functions
     221float CCinemaPath::EaseIn(float t) const
     222{
     223    return (this->*DistStylePtr)(t);
     224}
     225
     226float CCinemaPath::EaseOut(float t) const
     227{
     228    return 1.0f - EaseIn(1.0f - t);
     229}
     230
     231float CCinemaPath::EaseInOut(float t) const
     232{
     233    if (t < 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;
     236}
     237
     238float CCinemaPath::EaseOutIn(float t) const
     239{
     240    if (t < 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;
     243}
     244
     245// Distortion style functions
     246float CCinemaPath::EaseDefault(float t) const
     247{
     248    return t;
     249}
     250
     251float CCinemaPath::EaseGrowth(float t) const
     252{
     253    return pow(t, m_Growth);
     254}
     255
     256
     257float CCinemaPath::EaseExpo(float t) const
     258{
     259    if (t == 0)
     260        return t;
     261    return powf(m_Growth, 10 * (t - 1.0f));
     262}
     263
     264float CCinemaPath::EaseCircle(float t) const
     265{
     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;
     273}
     274
     275float CCinemaPath::EaseSine(float t) const
     276{
     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;
     284}
     285
     286bool CCinemaPath::Validate()
     287{
     288    if (m_TimeElapsed > GetDuration() || 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)
     296    {
     297        cumulation += Node[i].Distance.ToFloat();
     298        if (m_TimeElapsed <= cumulation)
     299        {
     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            break;
     304        }
     305        previousTime += Node[i].Distance.ToFloat();
     306    }
     307    return true;
     308}
     309
     310bool CCinemaPath::Play(const float deltaRealTime)
     311{
     312    m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime;
     313    if (!Validate())
     314    {
     315        m_TimeElapsed = 0.0f;
     316        return false;
     317    }
     318    MoveToPointAt(m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation);
     319    return true;
     320}
  • source/graphics/CinemaPath.h

     
     1/* Copyright (C) 2015 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#ifndef INCLUDED_CINEMAPATH
     19#define INCLUDED_CINEMAPATH
     20
     21#include "maths/NUSpline.h"
     22#include "ps/CStr.h"
     23
     24class CVector3D;
     25class CVector4D;
     26class CCamera;
     27
     28// For loading data
     29class CCinemaData
     30{
     31public:
     32    CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
     33    virtual ~CCinemaData() {}
     34
     35    const CCinemaData* GetData() const { return this; }
     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
     47    mutable float m_GrowthCount;
     48    float m_Growth;
     49    float m_Switch;
     50};
     51
     52
     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
     56
     57class CCinemaPath : private CCinemaData, public TNSpline
     58{
     59public:
     60    CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
     61    CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
     62    ~CCinemaPath() { DistStylePtr = NULL;  DistModePtr = NULL; }
     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
     68    float EaseIn(float t) const;
     69    float EaseOut(float t) const;
     70    float EaseInOut(float t) const;
     71    float EaseOutIn(float t) const;
     72
     73    // Distortion style functions
     74    float EaseDefault(float t) const;
     75    float EaseGrowth(float t) const;
     76    float EaseExpo(float t) const;
     77    float EaseCircle(float t) const;
     78    float EaseSine(float t) const;
     79
     80    float (CCinemaPath::*DistStylePtr)(float ratio) const;
     81    float (CCinemaPath::*DistModePtr)(float ratio) const;
     82
     83    const CCinemaData* GetData() const { return CCinemaData::GetData(); }
     84
     85public:
     86
     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;
     90
     91    inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; }
     92    inline fixed GetNodeDuration(const int index) const { return Node[index].Distance; }
     93    inline float GetDuration() const { return MaxDistance; }
     94
     95    inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance.ToFloat(); }
     96    inline float GetElapsedTime() const { return m_TimeElapsed; }
     97
     98    CStrW GetName() const { return m_Name; }
     99
     100    inline void SetTimescale(fixed scale) { m_Timescale = scale; }
     101
     102    float m_TimeElapsed;
     103    float m_PreviousNodeTime;   //How much time has passed before the current node
     104
     105    size_t m_CurrentNode;
     106    CVector3D m_PreviousRotation;
     107
     108public:
     109
     110    /**
     111     * Returns false if finished.
     112     * @param deltaRealTime Elapsed real time since the last frame.
     113     */
     114    bool Play(const float deltaRealTime);
     115
     116    /**
     117     * Validate the path
     118     * @return true if the path is valid
     119     */
     120    bool Validate();
     121
     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;
     134};
     135
     136#endif // INCLUDED_CINEMAPATH
  • source/graphics/CinemaTrack.cpp

     
    1 /* Copyright (C) 2015 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 
    19 #include "precompiled.h"
    20 #include <string>
    21 #include <sstream>
    22 #include "lib/ogl.h"
    23 #include "CinemaTrack.h"
    24 #include "ps/Game.h"
    25 #include "GameView.h"
    26 #include "maths/MathUtil.h"
    27 #include "Camera.h"
    28 #include "ps/CStr.h"
    29 #include "maths/Vector3D.h"
    30 #include "maths/Vector4D.h"
    31 #include "maths/Quaternion.h"
    32 
    33 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline)
    34     : CCinemaData(data), TNSpline(spline), m_TimeElapsed(0.f)
    35 {
    36     m_TimeElapsed = 0;
    37     BuildSpline();
    38 
    39     //Set distortion mode and style
    40     switch(data.m_Mode)
    41     {
    42     case CCinemaPath::EM_IN:
    43         DistModePtr = &CCinemaPath::EaseIn;
    44         break;
    45     case CCinemaPath::EM_OUT:
    46         DistModePtr = &CCinemaPath::EaseOut;
    47         break;
    48     case CCinemaPath::EM_INOUT:
    49         DistModePtr = &CCinemaPath::EaseInOut;
    50         break;
    51     case CCinemaPath::EM_OUTIN:
    52         DistModePtr = &CCinemaPath::EaseOutIn;
    53         break;
    54     default:
    55         debug_printf("Cinematic mode not found for %d\n", data.m_Mode);
    56         break;
    57     }
    58 
    59     switch (data.m_Style)
    60     {
    61     case CCinemaPath::ES_DEFAULT:
    62         DistStylePtr = &CCinemaPath::EaseDefault;
    63         break;
    64     case CCinemaPath::ES_GROWTH:
    65         DistStylePtr = &CCinemaPath::EaseGrowth;
    66         break;
    67     case CCinemaPath::ES_EXPO:
    68         DistStylePtr = &CCinemaPath::EaseExpo;
    69         break;
    70     case CCinemaPath::ES_CIRCLE:
    71         DistStylePtr = &CCinemaPath::EaseCircle;
    72         break;
    73     case CCinemaPath::ES_SINE:
    74         DistStylePtr = &CCinemaPath::EaseSine;
    75         break;
    76     default:
    77         debug_printf("Cinematic mode not found for %d\n", data.m_Style);
    78         break;
    79     }
    80     //UpdateDuration();
    81 
    82 }
    83 
    84 void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const
    85 {
    86     if (NodeCount < 2 || DistModePtr == NULL)
    87         return;
    88     if ( NodeCount == 2 && lines )
    89         smoothness = 2;
    90 
    91     float start = MaxDistance / smoothness;
    92     float time=0;
    93    
    94 #if CONFIG2_GLES
    95 #warning TODO: do something about CCinemaPath on GLES
    96 #else
    97 
    98     glColor4f( RGBA.X, RGBA.Y, RGBA.Z, RGBA.W );
    99     if ( lines )
    100     {   
    101         glLineWidth(1.8f);
    102         glEnable(GL_LINE_SMOOTH);
    103         glBegin(GL_LINE_STRIP);
    104 
    105         for (int i=0; i<=smoothness; ++i)
    106         {
    107             //Find distorted time
    108             time = start*i / MaxDistance;
    109             CVector3D tmp = GetPosition(time);
    110             glVertex3f( tmp.X, tmp.Y, tmp.Z );
    111         }
    112         glEnd();
    113         glDisable(GL_LINE_SMOOTH);
    114         glLineWidth(1.0f);
    115     }
    116     else
    117     {
    118         smoothness /= 2;
    119         start = MaxDistance / smoothness;
    120         glEnable(GL_POINT_SMOOTH);
    121         glPointSize(3.0f);
    122         glBegin(GL_POINTS);
    123 
    124         for (int i=0; i<=smoothness; ++i)
    125         {
    126             //Find distorted time
    127             time = (this->*DistModePtr)(start*i / MaxDistance);
    128             CVector3D tmp = GetPosition(time);
    129             glVertex3f( tmp.X, tmp.Y, tmp.Z );
    130         }
    131         glColor3f(1.0f, 1.0f, 0.0f);    //yellow
    132 
    133         for ( size_t i=0; i<Node.size(); ++i )
    134             glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z);
    135 
    136         glEnd();
    137         glPointSize(1.0f);
    138         glDisable(GL_POINT_SMOOTH);
    139     }
    140 
    141 #endif
    142 }
    143 
    144 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)
    145 {
    146     CCamera *Cam = g_Game->GetView()->GetCamera();
    147     t = (this->*DistModePtr)(t);
    148    
    149     CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation;
    150     CQuaternion start, end;
    151     start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z));
    152     end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z));
    153     start.Slerp(start, end, nodet);
    154     CVector3D pos = GetPosition(t);
    155     CQuaternion quat;
    156    
    157     Cam->m_Orientation.SetIdentity();
    158     Cam->m_Orientation.Rotate(start);
    159     Cam->m_Orientation.Translate(pos);
    160     Cam->UpdateFrustum();
    161 }
    162 
    163 //Distortion mode functions
    164 float CCinemaPath::EaseIn(float t) const
    165 {
    166     return (this->*DistStylePtr)(t);
    167 }
    168 float CCinemaPath::EaseOut(float t) const
    169 {
    170     return 1.0f - EaseIn(1.0f-t);
    171 }
    172 float CCinemaPath::EaseInOut(float t) const
    173 {
    174     if (t < m_Switch)
    175         return EaseIn(1.0f/m_Switch * t) * m_Switch;
    176     return EaseOut(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;
    177 }
    178 float CCinemaPath::EaseOutIn(float t) const
    179 {
    180     if (t < m_Switch)
    181         return EaseOut(1.0f/m_Switch * t) * m_Switch;
    182     return EaseIn(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;
    183 }
    184 
    185 
    186 //Distortion style functions
    187 float CCinemaPath::EaseDefault(float t) const
    188 {
    189     return t;
    190 }
    191 float CCinemaPath::EaseGrowth(float t) const
    192 {
    193     return pow(t, m_Growth);
    194 }
    195 
    196 float CCinemaPath::EaseExpo(float t) const
    197 {
    198     if(t == 0)
    199         return t;
    200     return powf(m_Growth, 10*(t-1.0f));
    201 }
    202 float CCinemaPath::EaseCircle(float t) const
    203 {
    204      t = -(sqrt(1.0f - t*t) - 1.0f);
    205      if(m_GrowthCount > 1.0f)
    206      {
    207          m_GrowthCount--;
    208          return (this->*DistStylePtr)(t);
    209      }
    210      return t;
    211 }
    212 
    213 float CCinemaPath::EaseSine(float t) const
    214 {
    215      t = 1.0f - cos(t * (float)M_PI/2);
    216      if(m_GrowthCount > 1.0f)
    217      {
    218          m_GrowthCount--;
    219          return (this->*DistStylePtr)(t);
    220      }
    221      return t;
    222 }
    223 
    224 bool CCinemaPath::Validate()
    225 {
    226     if ( m_TimeElapsed <= GetDuration() && m_TimeElapsed >= 0.0f )
    227     {
    228         //Find current node and past "node time"
    229         float previousTime = 0.0f, cumulation = 0.0f;
    230         //Ignore the last node, since it is a blank (node time values are shifted down one from interface)
    231         for ( size_t i = 0; i < Node.size() - 1; ++i )
    232         {
    233             cumulation += Node[i].Distance;
    234             if ( m_TimeElapsed <= cumulation )
    235             {
    236                 m_PreviousNodeTime = previousTime;
    237                 m_PreviousRotation = Node[i].Rotation;
    238                 m_CurrentNode = i;  //We're moving toward this next node, so use its rotation
    239                 return true;
    240             }
    241             else
    242                 previousTime += Node[i].Distance;
    243         }
    244     }
    245     return false;
    246 }
    247 
    248 bool CCinemaPath::Play(const float deltaRealTime)
    249 {
    250     m_TimeElapsed += m_Timescale * deltaRealTime;
    251 
    252     if (!Validate())
    253     {
    254         m_TimeElapsed = 0.0f;
    255         return false;
    256     }
    257    
    258     MoveToPointAt( m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation );
    259     return true;
    260 }
    261 
    262 
    263 CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false)
    264 {
    265     m_CurrentPath = m_Paths.end();
    266 }
    267 
    268 void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name)
    269 {
    270     ENSURE( m_Paths.find( name ) == m_Paths.end() );
    271     m_Paths[name] = path;
    272 }
    273 
    274 void CCinemaManager::QueuePath(const CStrW& name, bool queue )
    275 {
    276     if (!m_PathQueue.empty() && queue == false)
    277     {
    278         return;
    279     }
    280     else
    281     {
    282         ENSURE(HasTrack(name));
    283         m_PathQueue.push_back(m_Paths[name]);
    284     }
    285 }
    286 
    287 void CCinemaManager::OverridePath(const CStrW& name)
    288 {
    289     m_PathQueue.clear();
    290     ENSURE(HasTrack(name));
    291     m_PathQueue.push_back( m_Paths[name] );
    292 }
    293 
    294 void CCinemaManager::SetAllPaths( const std::map<CStrW, CCinemaPath>& paths)
    295 {
    296     CStrW name;
    297     m_Paths = paths;
    298 }
    299 void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines)
    300 {
    301     if ( !HasTrack(name) )
    302         m_ValidCurrent = false;
    303     else
    304         m_ValidCurrent = true;
    305 
    306     m_CurrentPath = m_Paths.find(name);
    307     m_DrawCurrentSpline = current;
    308     m_DrawLines = drawLines;
    309     DrawSpline();
    310 }
    311 
    312 bool CCinemaManager::HasTrack(const CStrW& name) const
    313 {
    314     return m_Paths.find(name) != m_Paths.end();
    315 }
    316 
    317 void CCinemaManager::DrawSpline() const
    318 {
    319     if ( !(m_DrawCurrentSpline && m_ValidCurrent) )
    320         return;
    321     static const int smoothness = 200;
    322 
    323     m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines);
    324 }
    325 
    326 void CCinemaManager::MoveToPointAt(float time)
    327 {
    328     ENSURE(m_CurrentPath != m_Paths.end());
    329     StopPlaying();
    330 
    331     m_CurrentPath->second.m_TimeElapsed = time;
    332     if ( !m_CurrentPath->second.Validate() )
    333         return;
    334 
    335     m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed /
    336                 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(),
    337                 m_CurrentPath->second.m_PreviousRotation );
    338 }
    339 
    340 bool CCinemaManager::Update(const float deltaRealTime)
    341 {
    342     if (!m_PathQueue.front().Play(deltaRealTime))
    343     {
    344         m_PathQueue.pop_front();
    345         return false;
    346     }
    347     return true;
    348 }
  • source/graphics/CinemaTrack.h

     
    1 /* Copyright (C) 2009 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 
    19 #ifndef INCLUDED_CINEMATRACK
    20 #define INCLUDED_CINEMATRACK
    21 
    22 #include <list>
    23 #include <map>
    24 #include "ps/CStr.h"
    25 #include "maths/NUSpline.h"
    26 
    27 /*
    28     desc: contains various functions used for cinematic camera paths
    29     See also: CinemaHandler.cpp, Cinematic.h/.cpp
    30 */
    31 
    32 class CVector3D;
    33 class CVector4D;
    34 class CCamera;
    35 
    36 //For loading data
    37 class CCinemaData
    38 {
    39 public:
    40     CCinemaData() : m_GrowthCount(0), m_Growth(0), m_Switch(0),
    41                     m_Mode(0), m_Style(0), m_Timescale(1) {}
    42     virtual ~CCinemaData() {}
    43    
    44     const CCinemaData* GetData() const { return this; }
    45    
    46     //Distortion variables
    47     mutable float m_GrowthCount;
    48     float m_Growth;
    49     float m_Switch;
    50     int m_Mode;
    51     int m_Style;
    52     float m_Timescale;  //a negative timescale results in backwards play
    53 
    54 };
    55 
    56 
    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
    60 
    61 class CCinemaPath : private CCinemaData, public TNSpline
    62 {
    63 public:
    64     CCinemaPath() { m_TimeElapsed = 0.0f; m_PreviousNodeTime = 0.0f; }
    65     CCinemaPath(const CCinemaData& data, const TNSpline& spline);
    66     ~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
    75     float EaseIn(float t) const;
    76     float EaseOut(float t) const;
    77     float EaseInOut(float t) const;
    78     float EaseOutIn(float t) const;
    79 
    80     //Distortion style functions
    81     float EaseDefault(float t) const;
    82     float EaseGrowth(float t) const;
    83     float EaseExpo(float t) const;
    84     float EaseCircle(float t) const;
    85     float EaseSine(float t) const;
    86    
    87     float (CCinemaPath::*DistStylePtr)(float ratio) const;
    88     float (CCinemaPath::*DistModePtr)(float ratio) const;
    89 
    90     const CCinemaData* GetData() const { return CCinemaData::GetData(); }
    91 
    92 public:
    93 
    94     void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const;
    95 
    96     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; }
    101     inline float GetElapsedTime() const { return m_TimeElapsed; }
    102 
    103     inline void SetTimescale(float scale) { m_Timescale = scale; }
    104    
    105     float m_TimeElapsed;
    106     float m_PreviousNodeTime;   //How much time has passed before the current node
    107    
    108     size_t m_CurrentNode;
    109     CVector3D m_PreviousRotation;
    110 
    111 public:
    112 
    113     /**
    114      * Returns false if finished.
    115      *
    116      * @param deltaRealTime Elapsed real time since the last frame.
    117      */
    118     bool Play(const float deltaRealTime);
    119     bool Validate();
    120 
    121     inline float GetTimescale() const { return m_Timescale; }   
    122 };
    123 
    124 //Class for in game playing of cinematics. Should only be instantiated in CGameView.
    125 class CCinemaManager
    126 {
    127 public:
    128     CCinemaManager();
    129     ~CCinemaManager() {}
    130 
    131     void AddPath(CCinemaPath path, const CStrW& name);
    132 
    133     //Adds track to list of being played.
    134     void QueuePath(const CStrW& name, bool queue);
    135     void OverridePath(const CStrW& name);   //clears track queue and replaces with 'name'
    136 
    137     /**
    138      * @param deltaRealTime Elapsed real time since the last frame.
    139      */
    140     bool Update(const float deltaRealTime);
    141    
    142     //These stop track play, and accept time, not ratio of time
    143     void MoveToPointAt(float time);
    144 
    145     inline void StopPlaying() { m_PathQueue.clear(); }
    146     void DrawSpline() const;
    147    
    148     inline bool IsPlaying() const { return !m_PathQueue.empty(); }
    149     bool HasTrack(const CStrW& name) const;
    150     inline bool IsActive() const { return m_Active; }
    151     inline void SetActive(bool active) { m_Active=active; }
    152 
    153     inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; }
    154     void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks);
    155     void SetCurrentPath(const CStrW& name, bool current, bool lines);
    156 
    157 private:
    158    
    159     bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent;
    160     std::map<CStrW, CCinemaPath>::iterator m_CurrentPath;
    161     std::map<CStrW, CCinemaPath> m_Paths;
    162     std::list<CCinemaPath> m_PathQueue;
    163 };
    164 
    165 #endif
  • source/graphics/GameView.cpp

     
    2020#include "GameView.h"
    2121
    2222#include "graphics/Camera.h"
    23 #include "graphics/CinemaTrack.h"
     23#include "graphics/CinemaManager.h"
    2424#include "graphics/ColladaManager.h"
    2525#include "graphics/HFTracer.h"
    2626#include "graphics/LOSTexture.h"
     
    258258     */
    259259    CLightEnv CachedLightEnv;
    260260
    261     CCinemaManager TrackManager;
     261    CCinemaManager CinemaManager;
    262262
    263263    /**
    264264     * Entity for the camera to follow, or INVALID_ENTITY if none.
     
    395395
    396396CCinemaManager* CGameView::GetCinema()
    397397{
    398     return &m->TrackManager;
     398    return &m->CinemaManager;
    399399};
    400400
    401401CLOSTexture& CGameView::GetLOSTexture()
     
    626626    if (!g_app_has_focus)
    627627        return;
    628628
    629     if (m->TrackManager.IsActive() && m->TrackManager.IsPlaying())
     629    if (m->CinemaManager.GetEnabled())
    630630    {
    631         if (! m->TrackManager.Update(deltaRealTime))
    632         {
    633 //          ResetCamera();
    634         }
     631        m->CinemaManager.Update(deltaRealTime);
    635632        return;
    636633    }
    637634
  • source/graphics/MapReader.cpp

     
    2020#include "MapReader.h"
    2121
    2222#include "graphics/Camera.h"
    23 #include "graphics/CinemaTrack.h"
     23#include "graphics/CinemaManager.h"
    2424#include "graphics/Entity.h"
    2525#include "graphics/GameView.h"
    2626#include "graphics/MapGenerator.h"
     
    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)
     
    849849    EL(distortion);
    850850    EL(node);
    851851    EL(position);
    852     EL(time);
     852    EL(target);
    853853    AT(name);
    854854    AT(timescale);
     855    AT(orientation);
    855856    AT(mode);
    856857    AT(style);
    857858    AT(growth);
     
    859860    AT(x);
    860861    AT(y);
    861862    AT(z);
     863    AT(deltatime);
    862864
    863865#undef EL
    864866#undef AT
    865    
    866     std::map<CStrW, CCinemaPath> pathList;
     867
    867868    XERO_ITER_EL(parent, element)
    868869    {
    869870        int elementName = element.GetNodeName();
    870            
    871         if ( elementName == el_path )
     871        if (elementName == el_path)
    872872        {
     873            CCinemaData pathData;
    873874            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;
     875            CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8());
     876            pathData.m_Timescale = fixed::FromFloat(attrs.GetNamedItem(at_timescale).ToFloat());
     877            TNSpline pathSpline, targetSpline;
     878            fixed lastTargetTime = fixed::Zero();
     879           
     880            pathData.m_Name = pathName;
     881            pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8();
     882            pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8();
     883            pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8();
    879884
    880885            XERO_ITER_EL(element, pathChild)
    881886            {
    882887                elementName = pathChild.GetNodeName();
    883888                attrs = pathChild.GetAttributes();
    884 
    885                 //Load distortion attributes
    886                 if ( elementName == el_distortion )
    887                 {
    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                 }
    893889               
    894                 //Load node data used for spline
    895                 else if ( elementName == el_node )
     890                // Load node data used for spline
     891                if (elementName == el_node)
    896892                {
     893                    bool positionDeclared = false;
    897894                    SplineData data;
     895                    data.Distance = fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat());
     896                    lastTargetTime += fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat());
    898897                    XERO_ITER_EL(pathChild, nodeChild)
    899898                    {
    900899                        elementName = nodeChild.GetNodeName();
    901900                        attrs = nodeChild.GetAttributes();
    902                        
    903                         //Fix?:  assumes that time is last element
    904                         if ( elementName == el_position )
     901                        if (elementName == el_position)
    905902                        {
    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;
     903                            data.Position.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     904                            data.Position.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     905                            data.Position.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
     906                            positionDeclared = true;
    910907                        }
    911                         else if ( elementName == el_rotation )
     908                        else if (elementName == el_rotation)
    912909                        {
    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;
     910                            data.Rotation.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     911                            data.Rotation.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     912                            data.Rotation.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
    917913                        }
    918                         else if ( elementName == el_time )
    919                             data.Distance = nodeChild.GetText().ToFloat();
     914                        else if (elementName == el_target)
     915                        {
     916                            CFixedVector3D targetPosition;
     917                            targetPosition.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat());
     918                            targetPosition.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat());
     919                            targetPosition.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat());
     920
     921                            targetSpline.AddNode(targetPosition, CFixedVector3D(), lastTargetTime);
     922                            lastTargetTime = fixed::Zero();
     923                        }
    920924                        else
    921                             debug_warn(L"Invalid cinematic element for node child");
    922                    
    923                         backwardSpline.AddNode(data.Position, data.Rotation, data.Distance);
     925                            LOGWARNING("Invalid cinematic element for node child");
    924926                    }
     927
     928                    // skip the node if no position
     929                    if (positionDeclared)
     930                        pathSpline.AddNode(data.Position, data.Rotation, data.Distance);
    925931                }
    926932                else
    927                     debug_warn(L"Invalid cinematic element for path child");
    928                
    929                
     933                    LOGWARNING("Invalid cinematic element for path child");
    930934            }
    931935
    932             //Construct cinema path with data gathered
    933             CCinemaPath temp(pathData, backwardSpline);
    934             const std::vector<SplineData>& nodes = temp.GetAllNodes();
    935             if ( nodes.empty() )
     936            // Construct cinema path with data gathered
     937            CCinemaPath path(pathData, pathSpline, targetSpline);
     938            if (path.Empty())
    936939            {
    937                 debug_warn(L"Failure loading cinematics");
     940                LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8());
    938941                return;
    939942            }
    940                    
    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
     944            if (!m_MapReader.pCinema->HasPath(pathName))
     945                m_MapReader.pCinema->AddPath(pathName, path);
     946            else
     947                LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8());
    949948        }
    950949        else
    951             ENSURE("Invalid cinema child");
     950            LOGWARNING("Invalid path child with name '%s'", element.GetText());
    952951    }
    953 
    954     if (m_MapReader.pCinema)
    955         m_MapReader.pCinema->SetAllPaths(pathList);
    956952}
    957953
    958954void CXMLReader::ReadTriggers(XMBElement UNUSED(parent))
     
    11251121        }
    11261122        else if (name == "Paths")
    11271123        {
    1128             ReadCinema(node);
     1124            ReadPaths(node);
    11291125        }
    11301126        else if (name == "Triggers")
    11311127        {
  • source/graphics/MapReader.h

     
    7070
    7171    // UnpackTerrain: unpack the terrain from the input stream
    7272    int UnpackTerrain();
    73     //UnpackCinema: unpack the cinematic tracks from the input stream
     73    // UnpackCinema: unpack the cinematic tracks from the input stream
    7474    int UnpackCinema();
    7575
    7676    // UnpackMap: unpack the given data from the raw data stream into local variables
  • source/graphics/MapWriter.cpp

     
    1818#include "precompiled.h"
    1919
    2020#include "Camera.h"
    21 #include "CinemaTrack.h"
     21#include "CinemaManager.h"
    2222#include "GameView.h"
    2323#include "LightEnv.h"
    2424#include "MapReader.h"
     
    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

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 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
     
    4646/*********************************** R N S **************************************************/
    4747
    4848// adds node and updates segment length
    49 void RNSpline::AddNode(const CVector3D &pos)
     49void RNSpline::AddNode(const CFixedVector3D &pos)
    5050{
    51   if ( NodeCount >= MAX_SPLINE_NODES )
    52       return;
    53   if (NodeCount == 0)
    54     MaxDistance = 0.f;
    55   else
    56   {
    57     Node[NodeCount-1].Distance = (Node[NodeCount-1].Position - pos).Length();
    58     MaxDistance += Node[NodeCount-1].Distance;
    59   }
    60   SplineData temp;
    61   temp.Position = pos;
    62   Node.push_back(temp);
    63   NodeCount++;
     51    if (NodeCount >= MAX_SPLINE_NODES)
     52        return;
     53    if (NodeCount == 0)
     54        MaxDistance = 0.f;
     55    else
     56    {
     57        Node[NodeCount - 1].Distance = (Node[NodeCount - 1].Position - pos).Length();
     58        MaxDistance += Node[NodeCount - 1].Distance.ToFloat();
     59    }
     60    SplineData temp;
     61    temp.Position = pos;
     62    Node.push_back(temp);
     63    NodeCount++;
    6464}
    6565
    6666
     
    6767// called after all nodes added. This function calculates the node velocities
    6868void RNSpline::BuildSpline()
    6969{
    70   if ( NodeCount == 2 )
    71   {
    72       Node[0].Velocity = GetStartVelocity(0);
    73       Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
    74       return;
    75   }
    76   else if ( NodeCount < 2 )
    77       return;
    78  
    79   for (int i = 1; i<NodeCount-1; i++)
    80   {
    81     CVector3D Next = Node[i+1].Position - Node[i].Position;
    82     CVector3D Previous = Node[i-1].Position - Node[i].Position;
    83     Next.Normalize();
    84     Previous.Normalize();
    85      
    86     // split the angle (figure 4)
    87     Node[i].Velocity = Next - Previous;
    88     Node[i].Velocity.Normalize();
    89   }
    90   // calculate start and end velocities
    91   Node[0].Velocity = GetStartVelocity(0);
    92   Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
     70    if (NodeCount == 2)
     71    {
     72        Node[0].Velocity = GetStartVelocity(0);
     73        Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1);
     74        return;
     75    }
     76    else if (NodeCount < 2)
     77        return;
     78
     79    for (int i = 1; i < NodeCount - 1; ++i)
     80    {
     81        CVector3D Next = Node[i + 1].Position - Node[i].Position;
     82        CVector3D Previous = Node[i - 1].Position - Node[i].Position;
     83        Next.Normalize();
     84        Previous.Normalize();
     85
     86        // split the angle (figure 4)
     87        Node[i].Velocity = Next - Previous;
     88        Node[i].Velocity.Normalize();
     89    }
     90    // calculate start and end velocities
     91    Node[0].Velocity = GetStartVelocity(0);
     92    Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1);
    9393}
    9494
    9595// spline access function. time is 0 -> 1
    9696CVector3D RNSpline::GetPosition(float time) const
    9797{
    98   if ( NodeCount < 2 )
    99       return CVector3D(0.0f, 0.0f, 0.0f);
    100   if ( time > 1.0f )
     98    if (NodeCount < 2)
     99        return CVector3D(0.0f, 0.0f, 0.0f);
     100    if (time < 0.0f)
     101        time = 0.0f;
     102    if (time > 1.0f)
    101103        time = 1.0f;
    102   float Distance = time * MaxDistance;
    103   float CurrentDistance = 0.f;
    104   int i = 0;
    105  
    106   //Find which node we're on
    107   while (CurrentDistance + Node[i].Distance < Distance
    108     && i < NodeCount - 2)
    109   {
    110     CurrentDistance += Node[i].Distance;
    111     i++;
    112   }
    113   ENSURE( i < NodeCount - 1 );
    114   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,
    119                          Node[i+1].Position, endVel, t);
     104    float Distance = time * MaxDistance;
     105    float CurrentDistance = 0.f;
     106    int i = 0;
     107
     108    // Find which node we're on
     109    while (CurrentDistance + Node[i].Distance.ToFloat() < Distance
     110        && i < NodeCount - 2)
     111    {
     112        CurrentDistance += Node[i].Distance.ToFloat();
     113        ++i;
     114    }
     115    ENSURE(i < NodeCount - 1);
     116    float t = Distance - CurrentDistance;
     117    // TODO: reimplement CVector3D comparator (float comparing is bad without EPS)
     118    if (Node[i].Position == Node[i + 1].Position || Node[i].Distance.ToFloat() < 1e-7) // distance too small or zero
     119    {
     120        return Node[i + 1].Position;
     121    }
     122    t /= Node[i].Distance.ToFloat(); // scale t in range 0 - 1
     123    CVector3D startVel = Node[i].Velocity * Node[i].Distance.ToFloat();
     124    CVector3D endVel = Node[i + 1].Velocity * Node[i].Distance.ToFloat();
     125    return GetPositionOnCubic(Node[i].Position, startVel,
     126        Node[i + 1].Position, endVel, t);
    120127}
    121128
    122129// internal. Based on Equation 14
    123130CVector3D RNSpline::GetStartVelocity(int index)
    124131{
    125   if ( index >= NodeCount - 1 || index < 0)
    126       return CVector3D(0.0f, 0.0f, 0.0f);
    127   CVector3D temp = (Node[index+1].Position - Node[index].Position) * 3.0f * ( 1.0f / Node[index].Distance) ;
    128   return (temp - Node[index+1].Velocity)*0.5f;
     132    if (index >= NodeCount - 1 || index < 0)
     133        return CVector3D(0.0f, 0.0f, 0.0f);
     134    CVector3D temp = CVector3D(Node[index + 1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance.ToFloat());
     135    return (temp - Node[index + 1].Velocity)*0.5f;
    129136}
    130137
    131138// internal. Based on Equation 15
    132139CVector3D RNSpline::GetEndVelocity(int index)
    133140{
    134   if ( index >= NodeCount || index < 1)
    135       return CVector3D(0.0f, 0.0f, 0.0f);
    136   CVector3D temp = (Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance);
    137   return (temp - Node[index-1].Velocity) * 0.5f;
     141    if (index >= NodeCount || index < 1)
     142        return CVector3D(0.0f, 0.0f, 0.0f);
     143    CVector3D temp = CVector3D(Node[index].Position - Node[index - 1].Position) * 3.0f * (1.0f / Node[index - 1].Distance.ToFloat());
     144    return (temp - Node[index - 1].Velocity) * 0.5f;
    138145}
    139146
    140147/*********************************** S N S **************************************************/
     
    142149// smoothing filter.
    143150void SNSpline::Smooth()
    144151{
    145   if ( NodeCount < 3 )
    146       return;
    147   CVector3D newVel;
    148   CVector3D oldVel = GetStartVelocity(0);
    149   for (int i = 1; i<NodeCount-1; i++)
    150   {
    151     // Equation 12
    152     newVel = GetEndVelocity(i) * Node[i].Distance +
    153              GetStartVelocity(i) * Node[i-1].Distance;
    154     newVel = newVel * ( 1 / (Node[i-1].Distance + Node[i].Distance) );
    155     Node[i-1].Velocity = oldVel;
    156     oldVel = newVel;
    157   }
    158   Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
    159   Node[NodeCount-2].Velocity = oldVel;
     152    if (NodeCount < 3)
     153        return;
     154    CVector3D newVel;
     155    CVector3D oldVel = GetStartVelocity(0);
     156    for (int i = 1; i < NodeCount - 1; ++i)
     157    {
     158        // Equation 12
     159        newVel = GetEndVelocity(i) * Node[i].Distance.ToFloat() +
     160            GetStartVelocity(i) * Node[i - 1].Distance.ToFloat();
     161        newVel = newVel * (1 / (Node[i - 1].Distance + Node[i].Distance).ToFloat());
     162        Node[i - 1].Velocity = oldVel;
     163        oldVel = newVel;
     164    }
     165    Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1);
     166    Node[NodeCount - 2].Velocity = oldVel;
    160167}
    161168
    162169/*********************************** T N S **************************************************/
     
    163170
    164171// as with RNSpline but use timePeriod in place of actual node spacing
    165172// ie time period is time from last node to this node
    166 void TNSpline::AddNode(const CVector3D &pos, const CVector3D& rotation, float timePeriod)
     173void TNSpline::AddNode(const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod)
    167174{
    168   if ( NodeCount >= MAX_SPLINE_NODES )
    169       return;
    170   if (NodeCount == 0)
    171      MaxDistance = 0.f;
    172   else
    173   {
    174     Node[NodeCount-1].Distance = timePeriod;
    175     MaxDistance += Node[NodeCount-1].Distance;
    176   }
     175    if (NodeCount >= MAX_SPLINE_NODES)
     176        return;
     177    if (NodeCount == 0)
     178        MaxDistance = 0.f;
     179    else
     180    {
     181        Node[NodeCount - 1].Distance = timePeriod;
     182        MaxDistance += Node[NodeCount - 1].Distance.ToFloat();
     183    }
    177184
    178   SplineData temp;
    179   temp.Position = pos;
     185    SplineData temp;
     186    temp.Position = pos;
    180187
    181   //make sure we don't end up using undefined numbers...
    182   temp.Distance = 0.0f;
    183   temp.Velocity = CVector3D( 0.0f, 0.0f, 0.0f );
    184   temp.Rotation = rotation;
    185   Node.push_back(temp);
    186   NodeCount++;
     188    //make sure we don't end up using undefined numbers...
     189    temp.Distance = fixed::FromFloat(0.0f);
     190    temp.Velocity = CVector3D(0.0f, 0.0f, 0.0f);
     191    temp.Rotation = rotation;
     192    Node.push_back(temp);
     193    NodeCount++;
    187194}
    188195
    189196//Inserts node before position
    190 void TNSpline::InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, float timePeriod)
     197void TNSpline::InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod)
    191198{
    192   if ( NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1  )
    193       return;
    194   if (NodeCount == 0)
    195       MaxDistance = 0.f;
    196   else
    197   {
    198     Node[NodeCount-1].Distance = timePeriod;
    199     Node[NodeCount-1].Rotation = rotation;
    200     MaxDistance += Node[NodeCount-1].Distance;
    201   }
    202   SplineData temp;
    203   temp.Position = pos;
    204   Node.insert(Node.begin() + index, temp);
    205   NodeCount++;
     199    if (NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1)
     200        return;
     201    if (NodeCount == 0)
     202        MaxDistance = 0.f;
     203    else
     204    {
     205        Node[NodeCount - 1].Distance = timePeriod;
     206        Node[NodeCount - 1].Rotation = rotation;
     207        MaxDistance += Node[NodeCount - 1].Distance.ToFloat();
     208    }
     209    SplineData temp;
     210    temp.Position = pos;
     211    Node.insert(Node.begin() + index, temp);
     212    NodeCount++;
    206213}
    207214//Removes node at index
    208215void TNSpline::RemoveNode(const int index)
    209216{
    210   if (NodeCount == 0 || index > NodeCount - 1 )
    211   {
    212      return;
    213   }
    214   else
    215   {
    216       MaxDistance -= Node[index].Distance;
    217       MaxDistance -= Node[index-1].Distance;
    218       Node[index-1].Distance = 0.0f;
    219       Node.erase( Node.begin() + index, Node.begin() + index + 1 );
    220   }
    221   NodeCount--;
     217    if (NodeCount == 0 || index > NodeCount - 1)
     218    {
     219        return;
     220    }
     221    else
     222    {
     223        MaxDistance -= Node[index].Distance.ToFloat();
     224        MaxDistance -= Node[index - 1].Distance.ToFloat();
     225        Node[index - 1].Distance = fixed::FromFloat(0.0f);
     226        Node.erase(Node.begin() + index, Node.begin() + index + 1);
     227    }
     228    NodeCount--;
    222229}
    223 void TNSpline::UpdateNodeTime(const int index, float time)
     230void TNSpline::UpdateNodeTime(const int index, fixed time)
    224231{
    225232    if (NodeCount == 0 || index > NodeCount - 1 )
    226233    {
     
    228235    }
    229236    Node[index].Distance = time;
    230237}
    231 void TNSpline::UpdateNodePos(const int index, const CVector3D &pos)
     238void TNSpline::UpdateNodePos(const int index, const CFixedVector3D &pos)
    232239{
    233240    if (NodeCount == 0 || index > NodeCount - 1 )
    234241    {
     
    238245}
    239246void TNSpline::Constrain()
    240247{
    241   if ( NodeCount < 3 )
    242       return;
    243   for (int i = 1; i<NodeCount-1; i++)
    244   {
    245     // Equation 13
    246     float r0 = (Node[i].Position-Node[i-1].Position).Length() / Node[i-1].Distance;
    247     float r1 = (Node[i+1].Position - Node[i].Position).Length() / Node[i].Distance;
    248     Node[i].Velocity *= 4.0f*r0*r1/((r0+r1)*(r0+r1));
    249   }
     248    if (NodeCount < 3)
     249        return;
     250    for (int i = 1; i < NodeCount - 1; ++i)
     251    {
     252        // Equation 13
     253        float r0 = (Node[i].Position - Node[i - 1].Position).Length().ToFloat() / Node[i - 1].Distance.ToFloat();
     254        float r1 = (Node[i + 1].Position - Node[i].Position).Length().ToFloat() / Node[i].Distance.ToFloat();
     255        Node[i].Velocity *= 4.0f*r0*r1 / ((r0 + r1)*(r0 + r1));
     256    }
    250257}
    251258
  • 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
     32// TODO: make template (ie, for non-fixed data)
    2933struct SplineData
    3034{
    31     CVector3D Position;
     35    // Should be fixed, because used in the simulation
     36    CFixedVector3D Position;
    3237    CVector3D Velocity;
    33     CVector3D Rotation;
    34     float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
     38    // TODO: make rotation as other spline
     39    CFixedVector3D Rotation;
     40    fixed Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
    3541};
    3642
    3743class RNSpline
    3844{
    3945public:
    40    
     46
    4147    RNSpline() { NodeCount = 0; }
    4248    virtual ~RNSpline() {}
    43  
    44   void AddNode(const CVector3D &pos);
    45   void BuildSpline();
    46   CVector3D GetPosition(float time) const;
    47   CVector3D GetRotation(float time) const;
    48   const std::vector<SplineData>& GetAllNodes() const { return Node; }
    49  
    50   float MaxDistance;
    51   int NodeCount;
    5249
     50    void AddNode(const CFixedVector3D &pos);
     51    void BuildSpline();
     52    CVector3D GetPosition(float time) const;
     53    CVector3D GetRotation(float time) const;
     54    const std::vector<SplineData>& GetAllNodes() const { return Node; }
     55
     56    float MaxDistance;
     57    int NodeCount;
     58
    5359protected:
    54   std::vector<SplineData> Node;
    55   CVector3D GetStartVelocity(int index);
    56   CVector3D GetEndVelocity(int index);
     60    std::vector<SplineData> Node;
     61    CVector3D GetStartVelocity(int index);
     62    CVector3D GetEndVelocity(int index);
    5763};
    5864
    5965class SNSpline : public RNSpline
     
    6066{
    6167public:
    6268    virtual ~SNSpline() {}
    63   void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); }
    64   void Smooth();
     69    void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); }
     70    void Smooth();
    6571};
    6672
    6773class TNSpline : public SNSpline
     
    6975public:
    7076    virtual ~TNSpline() {}
    7177
    72   void AddNode(const CVector3D& pos, const CVector3D& rotation, float timePeriod);
    73   void PushNode() { Node.push_back( SplineData() ); }
    74   void InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, float timePeriod);
    75   void RemoveNode(const int index);
    76   void UpdateNodeTime(const int index, float time);
    77   void UpdateNodePos(const int index, const CVector3D &pos);
    78  
    79   void BuildSpline(){ RNSpline::BuildSpline();  Smooth(); Smooth(); Smooth(); }
    80   void Smooth(){ for( int x=0; x<3; x++ ) { SNSpline::Smooth(); Constrain(); } }
    81   void Constrain();
     78    void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
     79    void PushNode() { Node.push_back(SplineData()); }
     80    void InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod);
     81    void RemoveNode(const int index);
     82    void UpdateNodeTime(const int index, fixed time);
     83    void UpdateNodePos(const int index, const CFixedVector3D &pos);
     84
     85    void BuildSpline(){ RNSpline::BuildSpline();  Smooth(); Smooth(); Smooth(); }
     86    void Smooth(){ for (int x = 0; x < 3; x++) { SNSpline::Smooth(); Constrain(); } }
     87    void Constrain();
    8288};
    8389
    8490#endif // INCLUDED_NUSPLINE
  • source/ps/GameSetup/GameSetup.cpp

     
    3535#include "lib/sysdep/os/win/wversion.h"
    3636#endif
    3737
    38 #include "graphics/CinemaTrack.h"
     38#include "graphics/CinemaManager.h"
    3939#include "graphics/FontMetrics.h"
    4040#include "graphics/GameView.h"
    4141#include "graphics/LightEnv.h"
     
    226226
    227227    ogl_WarnIfError();
    228228
     229    if (g_Game && g_Game->IsGameStarted())
     230        g_Game->GetView()->GetCinema()->Render();
     231
     232    ogl_WarnIfError();
     233
    229234    g_Renderer.RenderTextOverlays();
    230235
    231236    if (g_DoRenderGui)
     
    573578
    574579    in_add_handler(touch_input_handler);
    575580
     581    in_add_handler(cinema_manager_handler);
     582
    576583    // must be registered after (called before) the GUI which relies on these globals
    577584    in_add_handler(GlobalsInputHandler);
    578585}
  • source/ps/Globals.cpp

     
    2020
    2121#include "lib/external_libraries/libsdl.h"
    2222#include "network/NetClient.h"
     23
     24#include "graphics/CinemaManager.h"
     25#include "graphics/GameView.h"
     26#include "ps/Game.h"
    2327#include "ps/GameSetup/Config.h"
    2428#include "soundmanager/ISoundManager.h"
    2529
  • source/simulation2/components/CCmpCinemaManager.cpp

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

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

     
     1/* Copyright (C) 2015 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("Pause", void, ICmpCinemaManager, Pause)
     28DEFINE_INTERFACE_METHOD_0("Stop", void, ICmpCinemaManager, Stop)
     29END_INTERFACE_WRAPPER(CinemaManager)
  • source/simulation2/components/ICmpCinemaManager.h

     
     1/* Copyright (C) 2015 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 Pause() = 0;
     38    virtual void Stop() = 0;
     39
     40    DECLARE_INTERFACE_TYPE(CinemaManager)
     41};
     42
     43#endif // INCLUDED_ICMPCINEMAMANAGER
     44 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* Send when an path has ended
     545*/
     546
     547class CMessageCinemaPathEnded : public CMessage
     548{
     549public:
     550    DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
     551
     552    CMessageCinemaPathEnded(CStrW name, bool skipped) :
     553    name(name), skipped(skipped)
     554    {
     555    }
     556
     557    CStrW name;
     558    bool skipped;
     559};
     560
    541561#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    SET_MSG_PROPERTY(skipped);
     480    return JS::ObjectValue(*obj);
     481}
     482
     483CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
     484{
     485    FROMJSVAL_SETUP();
     486    GET_MSG_PROPERTY(CStrW, name);
     487    GET_MSG_PROPERTY(bool, skipped);
     488    return new CMessageCinemaPathEnded(name, skipped);
     489}
     490
    473491////////////////////////////////////////////////////////////////
    474492
    475493CMessage* 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)
    6061
    6162// TemplateManager must come before all other (non-test) components,
    6263// so that it is the first to be (de)serialized
     
    7576INTERFACE(AIManager)
    7677COMPONENT(AIManager)
    7778
     79INTERFACE(CinemaManager)
     80COMPONENT(CinemaManager)
     81
    7882INTERFACE(CommandQueue)
    7983COMPONENT(CommandQueue)
    8084
  • source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp

     
    2727#include "ps/Game.h"
    2828#include "renderer/Renderer.h"
    2929#include "graphics/GameView.h"
    30 #include "graphics/CinemaTrack.h"
     30#include "graphics/CinemaManager.h"
    3131
    3232#include "ps/World.h"
    3333#include "graphics/Terrain.h"
  • source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp

     
    2020#include "MessageHandler.h"
    2121#include "../CommandProc.h"
    2222#include "graphics/Camera.h"
    23 #include "graphics/CinemaTrack.h"
     23#include "graphics/CinemaManager.h"
    2424#include "graphics/GameView.h"
    2525#include "ps/Game.h"
    2626#include "ps/CStr.h"
     
    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); 
     158    if (msg->mode == eCinemaEventMode::SMOOTH)
     159    {
     160        manager->ClearQueue();
     161        manager->AddPathToQueue(*msg->path);
     162    }
    160163    else if ( msg->mode == eCinemaEventMode::IMMEDIATE_PATH )
    161164        manager->MoveToPointAt(msg->t);
    162165    else if ( msg->mode == eCinemaEventMode::RESET )
     
    164167//      g_Game->GetView()->ResetCamera();
    165168    }
    166169    else if ( msg->mode == eCinemaEventMode::SELECT )
    167         manager->SetCurrentPath(*msg->path, msg->drawCurrent, msg->lines);
     170        manager->SetCurrentPath(*msg->path, msg->drawCurrent);
    168171    else
    169172        ENSURE(false);
    170173}
  • source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp

     
    2222
    2323#include "../GameLoop.h"
    2424#include "../View.h"
    25 #include "graphics/CinemaTrack.h"
     25#include "graphics/CinemaManager.h"
    2626#include "graphics/GameView.h"
    2727#include "gui/GUIManager.h"
    2828#include "gui/GUI.h"
     
    5757QUERYHANDLER(CinemaRecord)
    5858{
    5959    CCinemaManager* manager = g_Game->GetView()->GetCinema();
    60     manager->SetCurrentPath(*msg->path, false, false);
     60    manager->SetCurrentPath(*msg->path, false);
    6161
    6262    const int w = msg->width, h = msg->height;
    6363
  • source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp

     
    2323
    2424#include "ps/Game.h"
    2525#include "graphics/GameView.h"
    26 #include "graphics/CinemaTrack.h"
     26#include "graphics/CinemaManager.h"
    2727#include "simulation2/Simulation2.h"
    2828
    2929namespace AtlasMessage {
  • source/tools/atlas/GameInterface/View.cpp

     
    2424#include "Messages.h"
    2525#include "SimState.h"
    2626
    27 #include "graphics/CinemaTrack.h"
     27#include "graphics/CinemaManager.h"
    2828#include "graphics/GameView.h"
    2929#include "graphics/ParticleManager.h"
    3030#include "graphics/SColor.h"