Index: ps/trunk/source/graphics/CinemaManager.h =================================================================== --- ps/trunk/source/graphics/CinemaManager.h +++ ps/trunk/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 @@ -27,38 +27,9 @@ #include "graphics/CinemaPath.h" #include "ps/CStr.h" -/* - desc: contains various functions used for cinematic camera paths - 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. */ - class CCinemaManager { public: @@ -66,75 +37,29 @@ ~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; + void DrawPaths() const; + void UpdateSessionVisibility() const; + void UpdateSilhouettesVisibility() const; - /** - * Get current enable state of the cinema manager - */ - bool GetEnabled() const; - - /** - * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) - * @enable new state - */ - void SetEnabled(bool enabled); + bool IsPlaying() const; + bool IsEnabled() const; /** * Updates CCinemManager and current path * @param deltaRealTime Elapsed real time since the last frame. */ - void Update(const float deltaRealTime); - - InReaction HandleEvent(const SDL_Event_* ev); - - CinematicSimulationData* GetCinematicSimulationData(); + void Update(const float deltaRealTime) const; + InReaction HandleEvent(const SDL_Event_* ev) const; bool GetPathsDrawing() const; void SetPathsDrawing(const bool drawPath); private: bool m_DrawPaths; - - // Cinematic data is accessed from the simulation - CinematicSimulationData m_CinematicSimulationData; }; extern InReaction cinema_manager_handler(const SDL_Event_* ev); Index: ps/trunk/source/graphics/CinemaManager.cpp =================================================================== --- ps/trunk/source/graphics/CinemaManager.cpp +++ ps/trunk/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 @@ -20,10 +20,12 @@ #include #include -#include "graphics/Camera.h" #include "graphics/CinemaManager.h" + +#include "graphics/Camera.h" #include "graphics/GameView.h" #include "gui/CGUI.h" +#include "gui/GUIutil.h" #include "gui/GUIManager.h" #include "gui/IGUIObject.h" #include "lib/ogl.h" @@ -32,10 +34,12 @@ #include "maths/Vector3D.h" #include "maths/Vector4D.h" #include "ps/CLogger.h" +#include "ps/ConfigDB.h" #include "ps/CStr.h" #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" @@ -51,144 +55,62 @@ { } -void CCinemaManager::AddPath(const CStrW& name, const CCinemaPath& path) +void CCinemaManager::Update(const float deltaRealTime) const { - if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end()) - { - LOGWARNING("Path with name '%s' already exists", name.ToUTF8()); + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + if (!cmpCinemaManager) 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]); -} + UpdateSessionVisibility(); + UpdateSilhouettesVisibility(); -void CCinemaManager::ClearQueue() -{ - m_CinematicSimulationData.m_PathQueue.clear(); + if (IsPlaying()) + cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera()); } -void CCinemaManager::SetAllPaths(const std::map& paths) +void CCinemaManager::Render() const { - m_CinematicSimulationData.m_Paths = paths; -} + if (IsEnabled()) + DrawBars(); -bool CCinemaManager::HasPath(const CStrW& name) const -{ - return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end(); + if (m_DrawPaths) + DrawPaths(); } -void CCinemaManager::SetEnabled(bool enabled) +void CCinemaManager::UpdateSessionVisibility() const { - // TODO: maybe assert? - if (m_CinematicSimulationData.m_PathQueue.empty() && enabled) - { - enabled = false; - m_CinematicSimulationData.m_Paused = true; - } - - if (m_CinematicSimulationData.m_Enabled == enabled) - 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 + // This can happen in various situations, for example when the player wins/loses 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 (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); + if (!sn) + return; - m_CinematicSimulationData.m_Enabled = enabled; -} + bool hidden = false; + GUI::GetSetting(sn, "hidden", hidden); -void CCinemaManager::Play() -{ - m_CinematicSimulationData.m_Paused = false; + if (hidden != IsPlaying()) + sn->SetSetting("hidden", IsPlaying() ? L"true" : L"false"); } -void CCinemaManager::Stop() +void CCinemaManager::UpdateSilhouettesVisibility() const { - 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; - - // sn - session gui object - IGUIObject *sn = g_GUI->FindObjectByName("sn"); - - // GUI visibility - if (sn) - { - if (m_CinematicSimulationData.m_Paused) - sn->SetSetting("hidden", L"false"); - else - sn->SetSetting("hidden", L"true"); - } - } - - if (m_CinematicSimulationData.m_PathQueue.empty() || !m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused) + if (!CRenderer::IsInitialised()) return; - if (HotkeyIsPressed("leave")) - { - // TODO: implement skip - } - - CCamera *camera = g_Game->GetView()->GetCamera(); - m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime, camera); + bool silhouettes = false; + CFG_GET_VAL("silhouettes", silhouettes); + g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !IsEnabled() && silhouettes); } -void CCinemaManager::Render() +void CCinemaManager::DrawPaths() const { - if (GetEnabled()) - { - DrawBars(); - return; - } - - if (!m_DrawPaths) + CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + if (!cmpCinemaManager) return; - // draw all paths - for (const std::pair& p : m_CinematicSimulationData.m_Paths) + for (const std::pair& p : cmpCinemaManager->GetPaths()) p.second.Draw(); } @@ -254,37 +176,29 @@ return pCinemaManager->HandleEvent(ev); } -InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev) +InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev) const { switch (ev->ev.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - if (GetEnabled() && !m_CinematicSimulationData.m_Paused) + // Prevent selection of units while the path is playing + if (IsPlaying()) 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; + return IsEnabled() && g_Game && !g_Game->m_Paused; } bool CCinemaManager::GetPathsDrawing() const Index: ps/trunk/source/graphics/CinemaPath.h =================================================================== --- ps/trunk/source/graphics/CinemaPath.h +++ ps/trunk/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: ps/trunk/source/graphics/CinemaPath.cpp =================================================================== --- ps/trunk/source/graphics/CinemaPath.cpp +++ ps/trunk/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: ps/trunk/source/graphics/GameView.cpp =================================================================== --- ps/trunk/source/graphics/GameView.cpp +++ ps/trunk/source/graphics/GameView.cpp @@ -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 @@ -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: ps/trunk/source/graphics/MapReader.cpp =================================================================== --- ps/trunk/source/graphics/MapReader.cpp +++ ps/trunk/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: ps/trunk/source/graphics/MapWriter.h =================================================================== --- ps/trunk/source/graphics/MapWriter.h +++ ps/trunk/source/graphics/MapWriter.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 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 @@ -64,7 +64,7 @@ // WriteXML: output some other data (entities, etc) in XML format void WriteXML(const VfsPath& pathname, WaterManager* pWaterMan, SkyManager* pSkyMan, CLightEnv* pLightEnv, CCamera* pCamera, - CCinemaManager* pCinema, CPostprocManager* pPostproc, + CPostprocManager* pPostproc, CSimulation2* pSimulation2); }; Index: ps/trunk/source/graphics/MapWriter.cpp =================================================================== --- ps/trunk/source/graphics/MapWriter.cpp +++ ps/trunk/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" @@ -55,7 +56,7 @@ // SaveMap: try to save the current map to the given file void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain, WaterManager* pWaterMan, SkyManager* pSkyMan, - CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema, + CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* UNUSED(pCinema), CPostprocManager* pPostproc, CSimulation2* pSimulation2) { @@ -76,7 +77,7 @@ } VfsPath pathnameXML = pathname.ChangeExtension(L".xml"); - WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, pPostproc, pSimulation2); + WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pPostproc, pSimulation2); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -184,7 +185,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, WaterManager* pWaterMan, SkyManager* pSkyMan, - CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema, + CLightEnv* pLightEnv, CCamera* pCamera, CPostprocManager* pPostproc, CSimulation2* pSimulation2) { @@ -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: ps/trunk/source/simulation2/components/CCmpCinemaManager.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpCinemaManager.cpp +++ ps/trunk/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 @@ -40,32 +48,29 @@ static std::string GetSchema() { - return "" - "" - ; + return ""; } virtual void Init(const CParamNode& UNUSED(paramNode)) { - // ... + m_Enabled = false; + m_MapRevealed = false; + m_ElapsedTime = fixed::Zero(); + m_TotalTime = fixed::Zero(); + m_CurrentPathElapsedTime = fixed::Zero(); } virtual void Deinit() { - // ... } 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 (const std::pair& it : m_Paths) { - CCinemaPath& path = it.second; + const CCinemaPath& path = it.second; const CCinemaData* data = path.GetData(); // TODO: maybe implement String_Unbounded @@ -113,11 +118,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,45 +169,43 @@ } // 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; } default: @@ -214,33 +213,113 @@ } } + 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 void SetEnabled(bool enabled) + { + if (m_PathQueue.empty() && enabled) + enabled = false; + + if (m_Enabled == enabled) + return; + + 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; + std::map m_Paths; + std::list m_PathQueue; + + // States before playing + bool m_MapRevealed; + + fixed m_ElapsedTime; + fixed m_TotalTime; + fixed m_CurrentPathElapsedTime; }; REGISTER_COMPONENT_TYPE(CinemaManager) Index: ps/trunk/source/simulation2/components/ICmpCinemaManager.h =================================================================== --- ps/trunk/source/simulation2/components/ICmpCinemaManager.h +++ ps/trunk/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,46 @@ 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; + + /** + * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) + * @param enable new state + */ + virtual void SetEnabled(bool enabled) = 0; DECLARE_INTERFACE_TYPE(CinemaManager) }; Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 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 @@ -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,9 @@ paths[pathName] = CCinemaPath(data, spline, TNSpline()); } - g_Game->GetView()->GetCinema()->SetAllPaths(paths); + CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + if (cmpCinemaManager) + cmpCinemaManager->SetPaths(paths); } QUERYHANDLER(GetCameraInfo) { @@ -153,12 +160,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 ) {