Index: source/graphics/CinemaManager.h =================================================================== --- source/graphics/CinemaManager.h +++ source/graphics/CinemaManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -32,29 +32,6 @@ See also: CinemaHandler.cpp, CinemaPath.cpp */ -// Cinematic structure for data accessable from the simulation -struct CinematicSimulationData -{ - bool m_Enabled; - bool m_Paused; - std::map m_Paths; - std::list m_PathQueue; - - // States before playing - bool m_MapRevealed; - - fixed m_ElapsedTime, m_TotalTime, m_CurrentPathElapsedTime; - - CinematicSimulationData() - : m_Enabled(false), - m_Paused(true), - m_MapRevealed(false), - m_ElapsedTime(fixed::Zero()), - m_TotalTime(fixed::Zero()), - m_CurrentPathElapsedTime(fixed::Zero()) - {} -}; - /** * Class for in game playing of cinematics. Should only be instantiated in CGameView. */ @@ -66,56 +43,20 @@ ~CCinemaManager() {} /** - * Adds the path to the path list - * @param name path name - * @param CCinemaPath path data - */ - void AddPath(const CStrW& name, const CCinemaPath& path); - - /** - * Adds the path to the playlist - * @param name path name - */ - void AddPathToQueue(const CStrW& name); - - /** - * Clears the playlist - */ - void ClearQueue(); - - /** - * Checks the path name in the path list - * @param name path name - * @return true if path with that name exists, else false - */ - bool HasPath(const CStrW& name) const; - - const std::map& GetAllPaths(); - void SetAllPaths( const std::map& tracks); - - /** - * Starts play paths - */ - void Play(); - void Stop(); - bool IsPlaying() const; - - /** * Renders black bars and paths (if enabled) */ - void Render(); + void Render() const; void DrawBars() const; /** - * Get current enable state of the cinema manager - */ - bool GetEnabled() const; + * Get current play state of the cinema manager + */ + bool IsPlaying() const; /** - * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) - * @enable new state + * Get current enable state of the cinema manager */ - void SetEnabled(bool enabled); + bool IsEnabled() const; /** * Updates CCinemManager and current path @@ -125,16 +66,13 @@ InReaction HandleEvent(const SDL_Event_* ev); - CinematicSimulationData* GetCinematicSimulationData(); - bool GetPathsDrawing() const; void SetPathsDrawing(const bool drawPath); private: bool m_DrawPaths; - - // Cinematic data is accessed from the simulation - CinematicSimulationData m_CinematicSimulationData; + bool m_Enabled; + bool m_Paused; }; extern InReaction cinema_manager_handler(const SDL_Event_* ev); Index: source/graphics/CinemaManager.cpp =================================================================== --- source/graphics/CinemaManager.cpp +++ source/graphics/CinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -36,6 +36,7 @@ #include "ps/Game.h" #include "ps/GameSetup/Config.h" #include "ps/Hotkey.h" +#include "simulation2/components/ICmpCinemaManager.h" #include "simulation2/components/ICmpOverlayRenderer.h" #include "simulation2/components/ICmpRangeManager.h" #include "simulation2/components/ICmpSelectable.h" @@ -47,109 +48,26 @@ CCinemaManager::CCinemaManager() - : m_DrawPaths(false) + : m_DrawPaths(false), m_Paused(false), m_Enabled(false) { } -void CCinemaManager::AddPath(const CStrW& name, const CCinemaPath& path) -{ - if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end()) - { - LOGWARNING("Path with name '%s' already exists", name.ToUTF8()); - return; - } - m_CinematicSimulationData.m_Paths[name] = path; -} - -void CCinemaManager::AddPathToQueue(const CStrW& name) -{ - if (!HasPath(name)) - { - LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8()); - return; - } - m_CinematicSimulationData.m_PathQueue.push_back(m_CinematicSimulationData.m_Paths[name]); -} - -void CCinemaManager::ClearQueue() -{ - m_CinematicSimulationData.m_PathQueue.clear(); -} - -void CCinemaManager::SetAllPaths(const std::map& paths) -{ - m_CinematicSimulationData.m_Paths = paths; -} - -bool CCinemaManager::HasPath(const CStrW& name) const -{ - return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end(); -} - -void CCinemaManager::SetEnabled(bool enabled) +void CCinemaManager::Update(const float deltaRealTime) { - // TODO: maybe assert? - if (m_CinematicSimulationData.m_PathQueue.empty() && enabled) - { - enabled = false; - m_CinematicSimulationData.m_Paused = true; - } - - if (m_CinematicSimulationData.m_Enabled == enabled) + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + if (!cmpCinemaManager || !g_Game) return; - // TODO: Enabling/Disabling does not work if the session GUI page is not the top page. - // This can happen in various situations, for example when the player wins/looses the game - // while the cinematic is running (a message box is the top page in this case). - // It might be better to disable the whole GUI during the cinematic instead of a specific - // GUI object. - - // sn - session gui object - IGUIObject *sn = g_GUI->FindObjectByName("sn"); - CmpPtr cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); - CmpPtr cmpTerritoryManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); - - // GUI visibility - if (sn) + if (g_Game->m_Paused != m_Paused || cmpCinemaManager->IsEnabled() != m_Enabled) { - if (enabled) - sn->SetSetting("hidden", L"true"); - else - sn->SetSetting("hidden", L"false"); - } - - // Overlay visibility - g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled); - if (cmpRangeManager) - { - if (enabled) - m_CinematicSimulationData.m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1); - // TODO: improve m_MapRevealed state and without fade in - cmpRangeManager->SetLosRevealAll(-1, enabled); - } - if (cmpTerritoryManager) - cmpTerritoryManager->SetVisibility(!enabled); - ICmpSelectable::SetOverrideVisibility(!enabled); - ICmpOverlayRenderer::SetOverrideVisibility(!enabled); + // TODO: Enabling/Disabling does not work if the session GUI page is not the top page. + // This can happen in various situations, for example when the player wins/looses the game + // while the cinematic is running (a message box is the top page in this case). + // It might be better to disable the whole GUI during the cinematic instead of a specific + // GUI object. - m_CinematicSimulationData.m_Enabled = enabled; -} - -void CCinemaManager::Play() -{ - m_CinematicSimulationData.m_Paused = false; -} - -void CCinemaManager::Stop() -{ - m_CinematicSimulationData.m_PathQueue.clear(); -} - -void CCinemaManager::Update(const float deltaRealTime) -{ - if (g_Game->m_Paused != m_CinematicSimulationData.m_Paused) - { - m_CinematicSimulationData.m_Paused = g_Game->m_Paused; + m_Paused = g_Game->m_Paused; + m_Enabled = cmpCinemaManager->IsEnabled(); // sn - session gui object IGUIObject *sn = g_GUI->FindObjectByName("sn"); @@ -157,14 +75,14 @@ // GUI visibility if (sn) { - if (m_CinematicSimulationData.m_Paused) - sn->SetSetting("hidden", L"false"); - else + if (m_Enabled && !m_Paused) sn->SetSetting("hidden", L"true"); + else + sn->SetSetting("hidden", L"false"); } } - if (m_CinematicSimulationData.m_PathQueue.empty() || !m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused) + if (!m_Enabled || m_Paused) return; if (HotkeyIsPressed("leave")) @@ -172,13 +90,13 @@ // TODO: implement skip } - CCamera *camera = g_Game->GetView()->GetCamera(); - m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime, camera); + if (g_Game->GetView()) + cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera()); } -void CCinemaManager::Render() +void CCinemaManager::Render() const { - if (GetEnabled()) + if (IsEnabled()) { DrawBars(); return; @@ -188,7 +106,10 @@ return; // draw all paths - for (const std::pair& p : m_CinematicSimulationData.m_Paths) + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + if (!cmpCinemaManager) + return; + for (const std::pair& p : cmpCinemaManager->GetPaths()) p.second.Draw(); } @@ -260,31 +181,23 @@ { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - if (GetEnabled() && !m_CinematicSimulationData.m_Paused) + if (m_Enabled && !m_Paused) return IN_HANDLED; default: return IN_PASS; } } -bool CCinemaManager::GetEnabled() const +bool CCinemaManager::IsEnabled() const { - return m_CinematicSimulationData.m_Enabled; + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + return cmpCinemaManager && cmpCinemaManager->IsEnabled(); } bool CCinemaManager::IsPlaying() const { - return !m_CinematicSimulationData.m_Paused; -} - -const std::map& CCinemaManager::GetAllPaths() -{ - return m_CinematicSimulationData.m_Paths; -} - -CinematicSimulationData* CCinemaManager::GetCinematicSimulationData() -{ - return &m_CinematicSimulationData; + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + return cmpCinemaManager && cmpCinemaManager->IsPaused(); } bool CCinemaManager::GetPathsDrawing() const Index: source/graphics/CinemaPath.h =================================================================== --- source/graphics/CinemaPath.h +++ source/graphics/CinemaPath.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -61,7 +61,7 @@ CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); // Sets camera position to calculated point on spline - void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera); + void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const; // Distortion mode functions-change how ratio is passed to distortion style functions float EaseIn(float t) const; Index: source/graphics/CinemaPath.cpp =================================================================== --- source/graphics/CinemaPath.cpp +++ source/graphics/CinemaPath.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,8 +42,6 @@ CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline) : CCinemaData(data), TNSpline(spline), m_TargetSpline(targetSpline), m_TimeElapsed(0.f) { - m_TimeElapsed = 0; - // Calculate curves by nodes BuildSpline(); m_TargetSpline.BuildSpline(); @@ -217,7 +215,7 @@ m_Timescale = scale; } -void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) +void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const { t = (this->*DistModePtr)(t); Index: source/graphics/GameView.cpp =================================================================== --- source/graphics/GameView.cpp +++ source/graphics/GameView.cpp @@ -626,11 +626,9 @@ if (!g_app_has_focus) return; - if (m->CinemaManager.GetEnabled()) - { - m->CinemaManager.Update(deltaRealTime); + m->CinemaManager.Update(deltaRealTime); + if (m->CinemaManager.IsEnabled()) return; - } // Calculate mouse movement static int mouse_last_x = 0; Index: source/graphics/MapReader.cpp =================================================================== --- source/graphics/MapReader.cpp +++ source/graphics/MapReader.cpp @@ -40,6 +40,7 @@ #include "renderer/SkyManager.h" #include "renderer/WaterManager.h" #include "simulation2/Simulation2.h" +#include "simulation2/components/ICmpCinemaManager.h" #include "simulation2/components/ICmpObstruction.h" #include "simulation2/components/ICmpOwnership.h" #include "simulation2/components/ICmpPlayer.h" @@ -850,6 +851,7 @@ #undef EL #undef AT + CmpPtr cmpCinemaManager(*m_MapReader.pSimContext, SYSTEM_ENTITY); XERO_ITER_EL(parent, element) { int elementName = element.GetNodeName(); @@ -922,8 +924,10 @@ return; } - if (!m_MapReader.pCinema->HasPath(pathName)) - m_MapReader.pCinema->AddPath(pathName, path); + if (!cmpCinemaManager) + continue; + if (!cmpCinemaManager->HasPath(pathName)) + cmpCinemaManager->AddPath(pathName, path); else LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8()); } Index: source/graphics/MapWriter.cpp =================================================================== --- source/graphics/MapWriter.cpp +++ source/graphics/MapWriter.cpp @@ -38,6 +38,7 @@ #include "renderer/SkyManager.h" #include "renderer/WaterManager.h" #include "simulation2/Simulation2.h" +#include "simulation2/components/ICmpCinemaManager.h" #include "simulation2/components/ICmpObstruction.h" #include "simulation2/components/ICmpOwnership.h" #include "simulation2/components/ICmpPosition.h" @@ -400,10 +401,12 @@ } } - const std::map& paths = pCinema->GetAllPaths(); - std::map::const_iterator it = paths.begin(); + CmpPtr cmpCinemaManager(sim, SYSTEM_ENTITY); + if (cmpCinemaManager) { + const std::map& paths = cmpCinemaManager->GetPaths(); + std::map::const_iterator it = paths.begin(); XML_Element("Paths"); for ( ; it != paths.end(); ++it ) Index: source/simulation2/components/CCmpCinemaManager.cpp =================================================================== --- source/simulation2/components/CCmpCinemaManager.cpp +++ source/simulation2/components/CCmpCinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,10 +22,18 @@ #include "graphics/GameView.h" #include "graphics/CinemaManager.h" +#include "gui/CGUI.h" +#include "gui/GUIManager.h" +#include "gui/IGUIObject.h" #include "ps/CLogger.h" #include "ps/Game.h" +#include "simulation2/components/ICmpOverlayRenderer.h" +#include "simulation2/components/ICmpRangeManager.h" +#include "simulation2/components/ICmpSelectable.h" +#include "simulation2/components/ICmpTerritoryManager.h" #include "simulation2/MessageTypes.h" #include "simulation2/Simulation2.h" +#include "renderer/Renderer.h" class CCmpCinemaManager : public ICmpCinemaManager @@ -47,7 +55,12 @@ virtual void Init(const CParamNode& UNUSED(paramNode)) { - // ... + m_Enabled = false; + m_Paused = false; + m_MapRevealed = false; + m_ElapsedTime = fixed::Zero(); + m_TotalTime = fixed::Zero(); + m_CurrentPathElapsedTime = fixed::Zero(); } virtual void Deinit() @@ -57,13 +70,9 @@ virtual void Serialize(ISerializer& serialize) { - if (!g_Game || !g_Game->GetView()) - return; - - CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); - serialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); - serialize.NumberU32_Unbounded("NumberOfPaths", p_CinematicSimulationData->m_Paths.size()); - for (auto it : p_CinematicSimulationData->m_Paths) + serialize.Bool("MapRevealed", m_MapRevealed); + serialize.NumberU32_Unbounded("NumberOfPaths", m_Paths.size()); + for (auto it : m_Paths) { CCinemaPath& path = it.second; const CCinemaData* data = path.GetData(); @@ -113,11 +122,7 @@ virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize) { - if (!g_Game || !g_Game->GetView()) - return; - - CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); - deserialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); + deserialize.Bool("MapRevealed", m_MapRevealed); uint32_t numberOfPaths = 0; deserialize.NumberU32_Unbounded("NumberOfPaths", numberOfPaths); for (uint32_t i = 0; i < numberOfPaths; ++i) @@ -168,44 +173,39 @@ } // Construct cinema path with data gathered - CCinemaPath path(data, pathSpline, targetSpline); - p_CinematicSimulationData->m_Paths[data.m_Name] = path; + m_Paths[data.m_Name] = CCinemaPath(data, pathSpline, targetSpline); } - g_Game->GetView()->GetCinema()->SetEnabled(p_CinematicSimulationData->m_Enabled); + SetEnabled(m_Enabled); } virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) { - if (!g_Game || !g_Game->GetView()) - return; - switch (msg.GetType()) { case MT_Update: { const CMessageUpdate &msgData = static_cast(msg); - CinematicSimulationData* pCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); - if (!pCinematicSimulationData->m_Enabled) + if (!m_Enabled) break; - pCinematicSimulationData->m_ElapsedTime += msgData.turnLength; - pCinematicSimulationData->m_CurrentPathElapsedTime += msgData.turnLength; - if (pCinematicSimulationData->m_CurrentPathElapsedTime >= pCinematicSimulationData->m_PathQueue.front().GetDuration()) - { - CMessageCinemaPathEnded msgCinemaPathEnded(pCinematicSimulationData->m_PathQueue.front().GetName()); - pCinematicSimulationData->m_PathQueue.pop_front(); - g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msgCinemaPathEnded); - pCinematicSimulationData->m_CurrentPathElapsedTime = fixed::Zero(); - if (!pCinematicSimulationData->m_PathQueue.empty()) - pCinematicSimulationData->m_PathQueue.front().Reset(); - } - if (pCinematicSimulationData->m_ElapsedTime >= pCinematicSimulationData->m_TotalTime) - { - pCinematicSimulationData->m_CurrentPathElapsedTime = fixed::Zero(); - pCinematicSimulationData->m_ElapsedTime = fixed::Zero(); - pCinematicSimulationData->m_TotalTime = fixed::Zero(); - g_Game->GetView()->GetCinema()->SetEnabled(false); - g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, CMessageCinemaQueueEnded()); + m_ElapsedTime += msgData.turnLength; + m_CurrentPathElapsedTime += msgData.turnLength; + if (m_CurrentPathElapsedTime >= m_PathQueue.front().GetDuration()) + { + CMessageCinemaPathEnded msgCinemaPathEnded(m_PathQueue.front().GetName()); + m_PathQueue.pop_front(); + GetSimContext().GetComponentManager().PostMessage(SYSTEM_ENTITY, msgCinemaPathEnded); + m_CurrentPathElapsedTime = fixed::Zero(); + if (!m_PathQueue.empty()) + m_PathQueue.front().Reset(); + } + if (m_ElapsedTime >= m_TotalTime) + { + m_CurrentPathElapsedTime = fixed::Zero(); + m_ElapsedTime = fixed::Zero(); + m_TotalTime = fixed::Zero(); + SetEnabled(false); + GetSimContext().GetComponentManager().PostMessage(SYSTEM_ENTITY, CMessageCinemaQueueEnded()); } break; } @@ -214,33 +214,120 @@ } } + virtual void AddPath(const CStrW& name, const CCinemaPath& path) + { + if (m_Paths.find(name) != m_Paths.end()) + { + LOGWARNING("Path with name '%s' already exists", name.ToUTF8()); + return; + } + m_Paths[name] = path; + } + virtual void AddCinemaPathToQueue(const CStrW& name) { - if (!g_Game || !g_Game->GetView()) + if (!HasPath(name)) + { + LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8()); return; - g_Game->GetView()->GetCinema()->AddPathToQueue(name); - CinematicSimulationData* pCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); - if (pCinematicSimulationData->m_PathQueue.size() == 1) - pCinematicSimulationData->m_PathQueue.front().Reset(); - pCinematicSimulationData->m_TotalTime += pCinematicSimulationData->m_Paths[name].GetDuration(); + } + m_PathQueue.push_back(m_Paths[name]); + + if (m_PathQueue.size() == 1) + m_PathQueue.front().Reset(); + m_TotalTime += m_Paths[name].GetDuration(); } virtual void Play() { - if (!g_Game || !g_Game->GetView()) - return; - g_Game->GetView()->GetCinema()->Play(); - g_Game->GetView()->GetCinema()->SetEnabled(true); + SetEnabled(true); } virtual void Stop() { - if (!g_Game || !g_Game->GetView()) + SetEnabled(false); + } + + virtual bool HasPath(const CStrW& name) const + { + return m_Paths.find(name) != m_Paths.end(); + } + + virtual void ClearQueue() + { + m_PathQueue.clear(); + } + + virtual const std::map& GetPaths() const + { + return m_Paths; + } + + virtual void SetPaths(const std::map& newPaths) + { + m_Paths = newPaths; + } + + virtual const std::list& GetQueue() const + { + return m_PathQueue; + } + + virtual bool IsEnabled() const + { + return m_Enabled; + } + + virtual bool IsPaused() const + { + return m_Paused; + } + + virtual void SetEnabled(bool enabled) + { + if (m_PathQueue.empty() && enabled) + enabled = false; + + if (m_Enabled == enabled) + return; + + // Overlay visibility + g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled); + + CmpPtr cmpRangeManager(GetSimContext().GetSystemEntity()); + CmpPtr cmpTerritoryManager(GetSimContext().GetSystemEntity()); + if (cmpRangeManager) + { + if (enabled) + m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1); + // TODO: improve m_MapRevealed state and without fade in + cmpRangeManager->SetLosRevealAll(-1, enabled); + } + if (cmpTerritoryManager) + cmpTerritoryManager->SetVisibility(!enabled); + ICmpSelectable::SetOverrideVisibility(!enabled); + ICmpOverlayRenderer::SetOverrideVisibility(!enabled); + + m_Enabled = enabled; + } + + virtual void PlayQueue(const float deltaRealTime, CCamera* camera) + { + if (m_PathQueue.empty()) return; - g_Game->GetView()->GetCinema()->Stop(); - g_Game->GetView()->GetCinema()->SetEnabled(false); + m_PathQueue.front().Play(deltaRealTime, camera); } +private: + bool m_Enabled; + bool m_Paused; + std::map m_Paths; + std::list m_PathQueue; + + // States before playing + bool m_MapRevealed; + + fixed m_ElapsedTime, m_TotalTime, m_CurrentPathElapsedTime; }; REGISTER_COMPONENT_TYPE(CinemaManager) Index: source/simulation2/components/ICmpCinemaManager.h =================================================================== --- source/simulation2/components/ICmpCinemaManager.h +++ source/simulation2/components/ICmpCinemaManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,6 +18,7 @@ #ifndef INCLUDED_ICMPCINEMAMANAGER #define INCLUDED_ICMPCINEMAMANAGER +#include "graphics/CinemaPath.h" #include "simulation2/system/Interface.h" #include "ps/CStr.h" @@ -30,11 +31,47 @@ class ICmpCinemaManager : public IComponent { public: - // TODO: add path name and description + /** + * Adds the path to the path list + * @param name path name + * @param CCinemaPath path data + */ + virtual void AddPath(const CStrW& name, const CCinemaPath& path) = 0; + + /** + * Adds the path to the playlist + * @param name path name + */ virtual void AddCinemaPathToQueue(const CStrW& name) = 0; virtual void Play() = 0; virtual void Stop() = 0; + virtual void PlayQueue(const float deltaRealTime, CCamera* camera) = 0; + + /** + * Checks the path name in the path list + * @param name path name + * @return true if path with that name exists, else false + */ + virtual bool HasPath(const CStrW& name) const = 0; + + /** + * Clears the playlist + */ + virtual void ClearQueue() = 0; + + virtual const std::map& GetPaths() const = 0; + virtual void SetPaths(const std::map& newPaths) = 0; + virtual const std::list& GetQueue() const = 0; + + virtual bool IsEnabled() const = 0; + virtual bool IsPaused() const = 0; + + /** + * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) + * @enable new state + */ + virtual void SetEnabled(bool enabled) = 0; DECLARE_INTERFACE_TYPE(CinemaManager) }; Index: source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -29,6 +29,8 @@ #include "maths/MathUtil.h" #include "maths/Quaternion.h" #include "lib/res/graphics/ogl_tex.h" +#include "simulation2/Simulation2.h" +#include "simulation2/components/ICmpCinemaManager.h" namespace AtlasMessage { @@ -73,8 +75,11 @@ std::vector GetCurrentPaths() { - const std::map& paths = g_Game->GetView()->GetCinema()->GetAllPaths(); std::vector atlasPaths; + CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + if (!cmpCinemaManager) + return atlasPaths; + const std::map& paths = cmpCinemaManager->GetPaths(); for ( std::map::const_iterator it=paths.begin(); it!=paths.end(); ++it ) { @@ -127,7 +132,10 @@ paths[pathName] = CCinemaPath(data, spline, TNSpline()); } - g_Game->GetView()->GetCinema()->SetAllPaths(paths); + // TODO: use the component of the cinema manager + CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + if (cmpCinemaManager) + cmpCinemaManager->SetPaths(paths); } QUERYHANDLER(GetCameraInfo) { @@ -154,11 +162,13 @@ MESSAGEHANDLER(CinemaEvent) { CCinemaManager* manager = g_Game->GetView()->GetCinema(); + CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + if (!cmpCinemaManager) + return; if (msg->mode == eCinemaEventMode::SMOOTH) { - manager->ClearQueue(); - manager->AddPathToQueue(*msg->path); + cmpCinemaManager->AddCinemaPathToQueue(*msg->path); } else if ( msg->mode == eCinemaEventMode::RESET ) {