forked from 0ad/0ad
Move most cinematic path simulation data and control from the graphics class to the simulation component and solve the hash mimatch in non-visual replay.
Move graphics code to smaller helper functions UpdateSessionVisibility, UpdateSilhouettesVisibility and DrawPaths. Remove the hotkey TODO code which should be implemented differently. Mark voids as const. Differential Revision: https://code.wildfiregames.com/D271 Patch By: Vladislav This was SVN commit r19375.
This commit is contained in:
parent
c0708da215
commit
5d49e6c456
@ -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 <sstream>
|
||||
#include <string>
|
||||
|
||||
#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 @@ CCinemaManager::CCinemaManager()
|
||||
{
|
||||
}
|
||||
|
||||
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());
|
||||
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<CStrW, CCinemaPath>& 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)
|
||||
{
|
||||
// TODO: maybe assert?
|
||||
if (m_CinematicSimulationData.m_PathQueue.empty() && enabled)
|
||||
{
|
||||
enabled = false;
|
||||
m_CinematicSimulationData.m_Paused = true;
|
||||
}
|
||||
|
||||
if (m_CinematicSimulationData.m_Enabled == enabled)
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
|
||||
if (!cmpCinemaManager)
|
||||
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.
|
||||
UpdateSessionVisibility();
|
||||
UpdateSilhouettesVisibility();
|
||||
|
||||
// sn - session gui object
|
||||
IGUIObject *sn = g_GUI->FindObjectByName("sn");
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
|
||||
CmpPtr<ICmpTerritoryManager> 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);
|
||||
|
||||
m_CinematicSimulationData.m_Enabled = enabled;
|
||||
if (IsPlaying())
|
||||
cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera());
|
||||
}
|
||||
|
||||
void CCinemaManager::Play()
|
||||
void CCinemaManager::Render() const
|
||||
{
|
||||
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;
|
||||
|
||||
// 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)
|
||||
return;
|
||||
|
||||
if (HotkeyIsPressed("leave"))
|
||||
{
|
||||
// TODO: implement skip
|
||||
}
|
||||
|
||||
CCamera *camera = g_Game->GetView()->GetCamera();
|
||||
m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime, camera);
|
||||
}
|
||||
|
||||
void CCinemaManager::Render()
|
||||
{
|
||||
if (GetEnabled())
|
||||
{
|
||||
if (IsEnabled())
|
||||
DrawBars();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_DrawPaths)
|
||||
if (m_DrawPaths)
|
||||
DrawPaths();
|
||||
}
|
||||
|
||||
void CCinemaManager::UpdateSessionVisibility() const
|
||||
{
|
||||
// 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/loses the game
|
||||
// while the cinematic is running (a message box is the top page in this case).
|
||||
|
||||
IGUIObject *sn = g_GUI->FindObjectByName("sn");
|
||||
if (!sn)
|
||||
return;
|
||||
|
||||
// draw all paths
|
||||
for (const std::pair<CStrW, CCinemaPath>& p : m_CinematicSimulationData.m_Paths)
|
||||
bool hidden = false;
|
||||
GUI<bool>::GetSetting(sn, "hidden", hidden);
|
||||
|
||||
if (hidden != IsPlaying())
|
||||
sn->SetSetting("hidden", IsPlaying() ? L"true" : L"false");
|
||||
}
|
||||
|
||||
void CCinemaManager::UpdateSilhouettesVisibility() const
|
||||
{
|
||||
if (!CRenderer::IsInitialised())
|
||||
return;
|
||||
|
||||
bool silhouettes = false;
|
||||
CFG_GET_VAL("silhouettes", silhouettes);
|
||||
g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !IsEnabled() && silhouettes);
|
||||
}
|
||||
|
||||
void CCinemaManager::DrawPaths() const
|
||||
{
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
|
||||
if (!cmpCinemaManager)
|
||||
return;
|
||||
|
||||
for (const std::pair<CStrW, CCinemaPath>& p : cmpCinemaManager->GetPaths())
|
||||
p.second.Draw();
|
||||
}
|
||||
|
||||
@ -254,37 +176,29 @@ InReaction cinema_manager_handler(const SDL_Event_* ev)
|
||||
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<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());
|
||||
return cmpCinemaManager && cmpCinemaManager->IsEnabled();
|
||||
}
|
||||
|
||||
bool CCinemaManager::IsPlaying() const
|
||||
{
|
||||
return !m_CinematicSimulationData.m_Paused;
|
||||
}
|
||||
|
||||
const std::map<CStrW, CCinemaPath>& 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
|
||||
|
@ -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,114 +27,39 @@
|
||||
#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<CStrW, CCinemaPath> m_Paths;
|
||||
std::list<CCinemaPath> 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:
|
||||
CCinemaManager();
|
||||
~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<CStrW, CCinemaPath>& GetAllPaths();
|
||||
void SetAllPaths( const std::map<CStrW, CCinemaPath>& 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);
|
||||
|
@ -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 @@ void CCinemaPath::SetTimescale(fixed scale)
|
||||
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);
|
||||
|
||||
|
@ -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 @@ public:
|
||||
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;
|
||||
|
@ -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 @@ void CGameView::Update(const float deltaRealTime)
|
||||
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;
|
||||
|
@ -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 @@ void CXMLReader::ReadPaths(XMBElement parent)
|
||||
#undef EL
|
||||
#undef AT
|
||||
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(*m_MapReader.pSimContext, SYSTEM_ENTITY);
|
||||
XERO_ITER_EL(parent, element)
|
||||
{
|
||||
int elementName = element.GetNodeName();
|
||||
@ -922,8 +924,10 @@ void CXMLReader::ReadPaths(XMBElement parent)
|
||||
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());
|
||||
}
|
||||
|
@ -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 @@ CMapWriter::CMapWriter()
|
||||
// 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 @@ void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain,
|
||||
}
|
||||
|
||||
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::PackTerrain(CFilePacker& packer, CTerrain* pTerrain)
|
||||
|
||||
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 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<CStrW, CCinemaPath>& paths = pCinema->GetAllPaths();
|
||||
std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin();
|
||||
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(sim, SYSTEM_ENTITY);
|
||||
if (cmpCinemaManager)
|
||||
{
|
||||
const std::map<CStrW, CCinemaPath>& paths = cmpCinemaManager->GetPaths();
|
||||
std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin();
|
||||
XML_Element("Paths");
|
||||
|
||||
for ( ; it != paths.end(); ++it )
|
||||
|
@ -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 @@ private:
|
||||
// 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);
|
||||
};
|
||||
|
||||
|
@ -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 @@ public:
|
||||
|
||||
static std::string GetSchema()
|
||||
{
|
||||
return "<a:component type='system'/>"
|
||||
"<empty/>"
|
||||
;
|
||||
return "<a:component type='system'/><empty/>";
|
||||
}
|
||||
|
||||
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<CStrW, CCinemaPath>& 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 @@ public:
|
||||
|
||||
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 @@ public:
|
||||
}
|
||||
|
||||
// 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<const CMessageUpdate&>(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())
|
||||
m_ElapsedTime += msgData.turnLength;
|
||||
m_CurrentPathElapsedTime += msgData.turnLength;
|
||||
if (m_CurrentPathElapsedTime >= 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();
|
||||
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 (pCinematicSimulationData->m_ElapsedTime >= pCinematicSimulationData->m_TotalTime)
|
||||
|
||||
if (m_ElapsedTime >= 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_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 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
return;
|
||||
g_Game->GetView()->GetCinema()->Stop();
|
||||
g_Game->GetView()->GetCinema()->SetEnabled(false);
|
||||
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<CStrW, CCinemaPath>& GetPaths() const
|
||||
{
|
||||
return m_Paths;
|
||||
}
|
||||
|
||||
virtual void SetPaths(const std::map<CStrW, CCinemaPath>& newPaths)
|
||||
{
|
||||
m_Paths = newPaths;
|
||||
}
|
||||
|
||||
virtual const std::list<CCinemaPath>& 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<ICmpRangeManager> cmpRangeManager(GetSimContext().GetSystemEntity());
|
||||
CmpPtr<ICmpTerritoryManager> 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;
|
||||
m_PathQueue.front().Play(deltaRealTime, camera);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_Enabled;
|
||||
std::map<CStrW, CCinemaPath> m_Paths;
|
||||
std::list<CCinemaPath> m_PathQueue;
|
||||
|
||||
// States before playing
|
||||
bool m_MapRevealed;
|
||||
|
||||
fixed m_ElapsedTime;
|
||||
fixed m_TotalTime;
|
||||
fixed m_CurrentPathElapsedTime;
|
||||
};
|
||||
|
||||
REGISTER_COMPONENT_TYPE(CinemaManager)
|
||||
|
@ -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<CStrW, CCinemaPath>& GetPaths() const = 0;
|
||||
virtual void SetPaths(const std::map<CStrW, CCinemaPath>& newPaths) = 0;
|
||||
virtual const std::list<CCinemaPath>& 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)
|
||||
};
|
||||
|
@ -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 @@ sCinemaSplineNode ConstructCinemaNode(const SplineData& data)
|
||||
|
||||
std::vector<sCinemaPath> GetCurrentPaths()
|
||||
{
|
||||
const std::map<CStrW, CCinemaPath>& paths = g_Game->GetView()->GetCinema()->GetAllPaths();
|
||||
std::vector<sCinemaPath> atlasPaths;
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpCinemaManager)
|
||||
return atlasPaths;
|
||||
const std::map<CStrW, CCinemaPath>& paths = cmpCinemaManager->GetPaths();
|
||||
|
||||
for ( std::map<CStrW, CCinemaPath>::const_iterator it=paths.begin(); it!=paths.end(); ++it )
|
||||
{
|
||||
@ -127,7 +132,9 @@ void SetCurrentPaths(const std::vector<sCinemaPath>& atlasPaths)
|
||||
paths[pathName] = CCinemaPath(data, spline, TNSpline());
|
||||
}
|
||||
|
||||
g_Game->GetView()->GetCinema()->SetAllPaths(paths);
|
||||
CmpPtr<ICmpCinemaManager> cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpCinemaManager)
|
||||
cmpCinemaManager->SetPaths(paths);
|
||||
}
|
||||
QUERYHANDLER(GetCameraInfo)
|
||||
{
|
||||
@ -153,12 +160,13 @@ QUERYHANDLER(GetCameraInfo)
|
||||
|
||||
MESSAGEHANDLER(CinemaEvent)
|
||||
{
|
||||
CCinemaManager* manager = g_Game->GetView()->GetCinema();
|
||||
CmpPtr<ICmpCinemaManager> 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 )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user