diff --git a/source/graphics/CinemaManager.cpp b/source/graphics/CinemaManager.cpp new file mode 100644 index 0000000000..4ef2ab1ad5 --- /dev/null +++ b/source/graphics/CinemaManager.cpp @@ -0,0 +1,115 @@ +/* Copyright (C) 2015 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + + +#include "precompiled.h" + +#include +#include + +#include "CinemaManager.h" + +#include "CinemaPath.h" +#include "ps/CStr.h" +#include "maths/Vector4D.h" + +CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false) +{ + m_CurrentPath = m_Paths.end(); +} + +void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name) +{ + ENSURE( m_Paths.find( name ) == m_Paths.end() ); + m_Paths[name] = path; +} + +void CCinemaManager::QueuePath(const CStrW& name, bool queue ) +{ + if (!m_PathQueue.empty() && queue == false) + { + return; + } + else + { + ENSURE(HasTrack(name)); + m_PathQueue.push_back(m_Paths[name]); + } +} + +void CCinemaManager::OverridePath(const CStrW& name) +{ + m_PathQueue.clear(); + ENSURE(HasTrack(name)); + m_PathQueue.push_back( m_Paths[name] ); +} + +void CCinemaManager::SetAllPaths( const std::map& paths) +{ + CStrW name; + m_Paths = paths; +} +void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines) +{ + if ( !HasTrack(name) ) + m_ValidCurrent = false; + else + m_ValidCurrent = true; + + m_CurrentPath = m_Paths.find(name); + m_DrawCurrentSpline = current; + m_DrawLines = drawLines; + DrawSpline(); +} + +bool CCinemaManager::HasTrack(const CStrW& name) const +{ + return m_Paths.find(name) != m_Paths.end(); +} + +void CCinemaManager::DrawSpline() const +{ + if ( !(m_DrawCurrentSpline && m_ValidCurrent) ) + return; + static const int smoothness = 200; + + m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines); +} + +void CCinemaManager::MoveToPointAt(float time) +{ + ENSURE(m_CurrentPath != m_Paths.end()); + StopPlaying(); + + m_CurrentPath->second.m_TimeElapsed = time; + if ( !m_CurrentPath->second.Validate() ) + return; + + m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed / + m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(), + m_CurrentPath->second.m_PreviousRotation ); +} + +bool CCinemaManager::Update(const float deltaRealTime) +{ + if (!m_PathQueue.front().Play(deltaRealTime)) + { + m_PathQueue.pop_front(); + return false; + } + return true; +} diff --git a/source/graphics/CinemaManager.h b/source/graphics/CinemaManager.h new file mode 100644 index 0000000000..567b62b198 --- /dev/null +++ b/source/graphics/CinemaManager.h @@ -0,0 +1,69 @@ +/* Copyright (C) 2015 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + + +#ifndef INCLUDED_CINEMAMANAGER +#define INCLUDED_CINEMAMANAGER + +#include +#include + +#include "graphics/CinemaPath.h" +#include "ps/CStr.h" + +//Class for in game playing of cinematics. Should only be instantiated in CGameView. +class CCinemaManager +{ +public: + CCinemaManager(); + ~CCinemaManager() {} + + void AddPath(CCinemaPath path, const CStrW& name); + + //Adds track to list of being played. + void QueuePath(const CStrW& name, bool queue); + void OverridePath(const CStrW& name); //clears track queue and replaces with 'name' + + /** + * @param deltaRealTime Elapsed real time since the last frame. + */ + bool Update(const float deltaRealTime); + + //These stop track play, and accept time, not ratio of time + void MoveToPointAt(float time); + + inline void StopPlaying() { m_PathQueue.clear(); } + void DrawSpline() const; + + inline bool IsPlaying() const { return !m_PathQueue.empty(); } + bool HasTrack(const CStrW& name) const; + inline bool IsActive() const { return m_Active; } + inline void SetActive(bool active) { m_Active=active; } + + inline const std::map& GetAllPaths() { return m_Paths; } + void SetAllPaths( const std::map& tracks); + void SetCurrentPath(const CStrW& name, bool current, bool lines); + +private: + + bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent; + std::map::iterator m_CurrentPath; + std::map m_Paths; + std::list m_PathQueue; +}; + +#endif diff --git a/source/graphics/CinemaTrack.cpp b/source/graphics/CinemaPath.cpp similarity index 76% rename from source/graphics/CinemaTrack.cpp rename to source/graphics/CinemaPath.cpp index c309694065..f3f78cd585 100644 --- a/source/graphics/CinemaTrack.cpp +++ b/source/graphics/CinemaPath.cpp @@ -17,10 +17,13 @@ #include "precompiled.h" + +#include "CinemaPath.h" + #include #include + #include "lib/ogl.h" -#include "CinemaTrack.h" #include "ps/Game.h" #include "GameView.h" #include "maths/MathUtil.h" @@ -257,92 +260,4 @@ bool CCinemaPath::Play(const float deltaRealTime) MoveToPointAt( m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation ); return true; -} - - -CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false) -{ - m_CurrentPath = m_Paths.end(); -} - -void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name) -{ - ENSURE( m_Paths.find( name ) == m_Paths.end() ); - m_Paths[name] = path; -} - -void CCinemaManager::QueuePath(const CStrW& name, bool queue ) -{ - if (!m_PathQueue.empty() && queue == false) - { - return; - } - else - { - ENSURE(HasTrack(name)); - m_PathQueue.push_back(m_Paths[name]); - } -} - -void CCinemaManager::OverridePath(const CStrW& name) -{ - m_PathQueue.clear(); - ENSURE(HasTrack(name)); - m_PathQueue.push_back( m_Paths[name] ); -} - -void CCinemaManager::SetAllPaths( const std::map& paths) -{ - CStrW name; - m_Paths = paths; -} -void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines) -{ - if ( !HasTrack(name) ) - m_ValidCurrent = false; - else - m_ValidCurrent = true; - - m_CurrentPath = m_Paths.find(name); - m_DrawCurrentSpline = current; - m_DrawLines = drawLines; - DrawSpline(); -} - -bool CCinemaManager::HasTrack(const CStrW& name) const -{ - return m_Paths.find(name) != m_Paths.end(); -} - -void CCinemaManager::DrawSpline() const -{ - if ( !(m_DrawCurrentSpline && m_ValidCurrent) ) - return; - static const int smoothness = 200; - - m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines); -} - -void CCinemaManager::MoveToPointAt(float time) -{ - ENSURE(m_CurrentPath != m_Paths.end()); - StopPlaying(); - - m_CurrentPath->second.m_TimeElapsed = time; - if ( !m_CurrentPath->second.Validate() ) - return; - - m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed / - m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(), - m_CurrentPath->second.m_PreviousRotation ); -} - -bool CCinemaManager::Update(const float deltaRealTime) -{ - if (!m_PathQueue.front().Play(deltaRealTime)) - { - m_PathQueue.pop_front(); - return false; - } - return true; -} +} \ No newline at end of file diff --git a/source/graphics/CinemaTrack.h b/source/graphics/CinemaPath.h similarity index 72% rename from source/graphics/CinemaTrack.h rename to source/graphics/CinemaPath.h index 9a1d4fa5d3..50caf6154f 100644 --- a/source/graphics/CinemaTrack.h +++ b/source/graphics/CinemaPath.h @@ -16,8 +16,8 @@ */ -#ifndef INCLUDED_CINEMATRACK -#define INCLUDED_CINEMATRACK +#ifndef INCLUDED_CINEMAPATH +#define INCLUDED_CINEMAPATH #include #include @@ -121,45 +121,4 @@ public: inline float GetTimescale() const { return m_Timescale; } }; -//Class for in game playing of cinematics. Should only be instantiated in CGameView. -class CCinemaManager -{ -public: - CCinemaManager(); - ~CCinemaManager() {} - - void AddPath(CCinemaPath path, const CStrW& name); - - //Adds track to list of being played. - void QueuePath(const CStrW& name, bool queue); - void OverridePath(const CStrW& name); //clears track queue and replaces with 'name' - - /** - * @param deltaRealTime Elapsed real time since the last frame. - */ - bool Update(const float deltaRealTime); - - //These stop track play, and accept time, not ratio of time - void MoveToPointAt(float time); - - inline void StopPlaying() { m_PathQueue.clear(); } - void DrawSpline() const; - - inline bool IsPlaying() const { return !m_PathQueue.empty(); } - bool HasTrack(const CStrW& name) const; - inline bool IsActive() const { return m_Active; } - inline void SetActive(bool active) { m_Active=active; } - - inline const std::map& GetAllPaths() { return m_Paths; } - void SetAllPaths( const std::map& tracks); - void SetCurrentPath(const CStrW& name, bool current, bool lines); - -private: - - bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent; - std::map::iterator m_CurrentPath; - std::map m_Paths; - std::list m_PathQueue; -}; - #endif diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index e28ebab1d1..daeb634d09 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -20,7 +20,7 @@ #include "GameView.h" #include "graphics/Camera.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "graphics/ColladaManager.h" #include "graphics/HFTracer.h" #include "graphics/LOSTexture.h" @@ -258,7 +258,7 @@ public: */ CLightEnv CachedLightEnv; - CCinemaManager TrackManager; + CCinemaManager CinemaManager; /** * Entity for the camera to follow, or INVALID_ENTITY if none. @@ -395,7 +395,7 @@ CCamera* CGameView::GetCamera() CCinemaManager* CGameView::GetCinema() { - return &m->TrackManager; + return &m->CinemaManager; }; CLOSTexture& CGameView::GetLOSTexture() @@ -626,9 +626,9 @@ void CGameView::Update(const float deltaRealTime) if (!g_app_has_focus) return; - if (m->TrackManager.IsActive() && m->TrackManager.IsPlaying()) + if (m->CinemaManager.IsActive() && m->CinemaManager.IsPlaying()) { - if (! m->TrackManager.Update(deltaRealTime)) + if (! m->CinemaManager.Update(deltaRealTime)) { // ResetCamera(); } diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 06b4b5510c..3a63e87808 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -20,7 +20,7 @@ #include "MapReader.h" #include "graphics/Camera.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "graphics/Entity.h" #include "graphics/GameView.h" #include "graphics/MapGenerator.h" diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 60cac577c8..20e407d18f 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -18,7 +18,7 @@ #include "precompiled.h" #include "Camera.h" -#include "CinemaTrack.h" +#include "CinemaManager.h" #include "GameView.h" #include "LightEnv.h" #include "MapReader.h" diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index ed34ba1fc2..4a926db09f 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -35,7 +35,7 @@ #include "lib/sysdep/os/win/wversion.h" #endif -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaPath.h" #include "graphics/FontMetrics.h" #include "graphics/GameView.h" #include "graphics/LightEnv.h" diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp index c803fcb49f..22b6b9e633 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -27,7 +27,7 @@ #include "ps/Game.h" #include "renderer/Renderer.h" #include "graphics/GameView.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "ps/World.h" #include "graphics/Terrain.h" diff --git a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp index edd2fba98e..22c96f6274 100644 --- a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -20,7 +20,7 @@ #include "MessageHandler.h" #include "../CommandProc.h" #include "graphics/Camera.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "graphics/GameView.h" #include "ps/Game.h" #include "ps/CStr.h" diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index 6cb2f89de2..f7ac490bc7 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -22,7 +22,7 @@ #include "../GameLoop.h" #include "../View.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "graphics/GameView.h" #include "gui/GUIManager.h" #include "gui/GUI.h" diff --git a/source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp b/source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp index 3f157af5d8..ef9a3e4941 100644 --- a/source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp @@ -23,7 +23,7 @@ #include "ps/Game.h" #include "graphics/GameView.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "simulation2/Simulation2.h" namespace AtlasMessage { diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 116c31a146..0a93195f46 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -24,7 +24,7 @@ #include "Messages.h" #include "SimState.h" -#include "graphics/CinemaTrack.h" +#include "graphics/CinemaManager.h" #include "graphics/GameView.h" #include "graphics/ParticleManager.h" #include "graphics/SColor.h"