Ticket #3301: cinematic_camera_core_v1.8b.patch
File cinematic_camera_core_v1.8b.patch, 74.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Trigger.js
19 19 "Interval", 20 20 "Range", 21 21 "TreasureCollected", 22 "CinemaPathEnded", 23 "CinemaQueueEnded" 22 24 ]; 23 25 24 26 Trigger.prototype.Init = function() … … 242 244 // "tech": tech} 243 245 }; 244 246 247 // Handles "OnCinemaPathEnded" event. 248 Trigger.prototype.OnGlobalCinemaPathEnded = function(msg) 249 { 250 this.CallEvent("CinemaPathEnded", msg); 251 } 252 253 // Handles "OnCinemaQueueEnded" event. 254 Trigger.prototype.OnGlobalCinemaQueueEnded = function(msg) 255 { 256 this.CallEvent("CinemaQueueEnded", msg); 257 } 258 245 259 Trigger.prototype.OnGlobalOwnershipChanged = function(msg) 246 260 { 247 261 this.CallEvent("OwnershipChanged", msg); -
source/graphics/CinemaManager.cpp
18 18 19 19 #include "precompiled.h" 20 20 21 #include <sstream> 21 22 #include <string> 22 #include <sstream>23 23 24 #include "CinemaManager.h" 25 26 #include "CinemaPath.h" 24 #include "graphics/Camera.h" 25 #include "graphics/CinemaManager.h" 26 #include "graphics/GameView.h" 27 #include "gui/CGUI.h" 28 #include "gui/GUIManager.h" 29 #include "gui/IGUIObject.h" 30 #include "lib/ogl.h" 31 #include "maths/MathUtil.h" 32 #include "maths/Quaternion.h" 33 #include "maths/Vector3D.h" 34 #include "maths/Vector4D.h" 35 #include "ps/CLogger.h" 27 36 #include "ps/CStr.h" 28 #include "maths/Vector4D.h" 37 #include "ps/Game.h" 38 #include "ps/Hotkey.h" 39 #include "simulation2/components/ICmpOverlayRenderer.h" 40 #include "simulation2/components/ICmpRangeManager.h" 41 #include "simulation2/components/ICmpSelectable.h" 42 #include "simulation2/components/ICmpTerritoryManager.h" 43 #include "simulation2/MessageTypes.h" 44 #include "simulation2/system/ComponentManager.h" 45 #include "simulation2/Simulation2.h" 46 #include "renderer/Renderer.h" 29 47 30 CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false) 48 49 CCinemaManager::CCinemaManager() 50 : m_DrawPaths(false) 31 51 { 32 m_CurrentPath = m_Paths.end();33 52 } 34 53 35 void CCinemaManager::AddPath( CCinemaPath path, const CStrW& name)54 void CCinemaManager::AddPath(const CStrW& name, const CCinemaPath& path) 36 55 { 37 ENSURE( m_Paths.find( name ) == m_Paths.end() ); 38 m_Paths[name] = path; 56 if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end()) 57 { 58 LOGWARNING("Path with name '%s' already exists", name.ToUTF8()); 59 return; 60 } 61 m_CinematicSimulationData.m_Paths[name] = path; 39 62 } 40 63 41 void CCinemaManager:: QueuePath(const CStrW& name, bool queue)64 void CCinemaManager::AddPathToQueue(const CStrW& name) 42 65 { 43 if (! m_PathQueue.empty() && queue == false)66 if (!HasPath(name)) 44 67 { 68 LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8()); 45 69 return; 46 70 } 47 else 71 m_CinematicSimulationData.m_PathQueue.push_back(m_CinematicSimulationData.m_Paths[name]); 72 } 73 74 void CCinemaManager::ClearQueue() 75 { 76 m_CinematicSimulationData.m_PathQueue.clear(); 77 } 78 79 void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths) 80 { 81 m_CinematicSimulationData.m_Paths = paths; 82 } 83 84 bool CCinemaManager::HasPath(const CStrW& name) const 85 { 86 return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end(); 87 } 88 89 void CCinemaManager::SetEnabled(bool enabled) 90 { 91 // TODO: maybe assert? 92 if (m_CinematicSimulationData.m_PathQueue.empty() && enabled) 48 93 { 49 ENSURE(HasTrack(name));50 m_ PathQueue.push_back(m_Paths[name]);94 enabled = false; 95 m_CinematicSimulationData.m_Paused = true; 51 96 } 97 98 if (m_CinematicSimulationData.m_Enabled == enabled) 99 return; 100 101 // sn - session gui object 102 IGUIObject *sn = g_GUI->FindObjectByName("sn"); 103 CmpPtr<ICmpRangeManager> cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); 104 CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); 105 106 // GUI visibility 107 if (sn) 108 { 109 if (enabled) 110 sn->SetSetting("hidden", L"true"); 111 else 112 sn->SetSetting("hidden", L"false"); 113 } 114 115 // Overlay visibility 116 g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled); 117 if (cmpRangeManager) 118 { 119 if (enabled) 120 m_CinematicSimulationData.m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1); 121 // TODO: improve m_MapRevealed state and without fade in 122 cmpRangeManager->SetLosRevealAll(-1, enabled); 123 } 124 if (cmpTerritoryManager) 125 cmpTerritoryManager->SetVisibility(!enabled); 126 ICmpSelectable::SetOverrideVisibility(!enabled); 127 ICmpOverlayRenderer::SetOverrideVisibility(!enabled); 128 129 m_CinematicSimulationData.m_Enabled = enabled; 52 130 } 53 131 54 void CCinemaManager:: OverridePath(const CStrW& name)132 void CCinemaManager::Play() 55 133 { 56 m_PathQueue.clear(); 57 ENSURE(HasTrack(name)); 58 m_PathQueue.push_back( m_Paths[name] ); 134 m_CinematicSimulationData.m_Paused = false; 59 135 } 60 136 61 void CCinemaManager:: SetAllPaths(const std::map<CStrW, CCinemaPath>& paths)137 void CCinemaManager::Pause() 62 138 { 63 CStrW name; 64 m_Paths = paths; 139 m_CinematicSimulationData.m_Paused = true; 65 140 } 66 void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines) 141 142 void CCinemaManager::Stop() 67 143 { 68 if ( !HasTrack(name) ) 69 m_ValidCurrent = false; 70 else 71 m_ValidCurrent = true; 144 m_CinematicSimulationData.m_PathQueue.clear(); 145 } 72 146 73 m_CurrentPath = m_Paths.find(name); 74 m_DrawCurrentSpline = current; 75 m_DrawLines = drawLines; 76 DrawSpline(); 147 void CCinemaManager::Update(const float deltaRealTime) 148 { 149 if (g_Game->m_Paused != m_CinematicSimulationData.m_Paused) 150 { 151 m_CinematicSimulationData.m_Paused = g_Game->m_Paused; 152 153 // sn - session gui object 154 IGUIObject *sn = g_GUI->FindObjectByName("sn"); 155 156 // GUI visibility 157 if (sn) 158 { 159 if (m_CinematicSimulationData.m_Paused) 160 sn->SetSetting("hidden", L"false"); 161 else 162 sn->SetSetting("hidden", L"true"); 163 } 164 } 165 166 if (m_CinematicSimulationData.m_PathQueue.empty() || !m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused) 167 return; 168 169 if (HotkeyIsPressed("leave")) 170 { 171 // TODO: implement skip 172 } 173 174 m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime); 77 175 } 78 176 79 bool CCinemaManager::HasTrack(const CStrW& name) const 80 { 81 return m_Paths.find(name) != m_Paths.end(); 177 void CCinemaManager::Render() 178 { 179 if (GetEnabled()) 180 { 181 DrawBars(); 182 return; 183 } 184 185 if (!m_DrawPaths) 186 return; 187 188 // draw all paths 189 for (auto it : m_CinematicSimulationData.m_Paths) 190 it.second.Draw(); 82 191 } 83 192 84 void CCinemaManager::Draw Spline() const193 void CCinemaManager::DrawBars() const 85 194 { 86 if ( !(m_DrawCurrentSpline && m_ValidCurrent) ) 195 int height = (float)g_xres / 2.39f; 196 int shift = (g_yres - height) / 2; 197 if (shift <= 0) 87 198 return; 88 static const int smoothness = 200;89 199 90 m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines); 200 #if CONFIG2_GLES 201 #warning TODO : implement bars for GLES 202 #else 203 // Set up transform for GL bars 204 glMatrixMode(GL_PROJECTION); 205 glPushMatrix(); 206 glLoadIdentity(); 207 glMatrixMode(GL_MODELVIEW); 208 glPushMatrix(); 209 glLoadIdentity(); 210 CMatrix3D transform; 211 transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f); 212 glLoadMatrixf(&transform._11); 213 214 glColor4f(0.0f, 0.0f, 0.0f, 1.0f); 215 216 glEnable(GL_BLEND); 217 glDisable(GL_DEPTH_TEST); 218 219 glBegin(GL_QUADS); 220 glVertex2i(0, 0); 221 glVertex2i(g_xres, 0); 222 glVertex2i(g_xres, shift); 223 glVertex2i(0, shift); 224 glEnd(); 225 226 glBegin(GL_QUADS); 227 glVertex2i(0, g_yres - shift); 228 glVertex2i(g_xres, g_yres - shift); 229 glVertex2i(g_xres, g_yres); 230 glVertex2i(0, g_yres); 231 glEnd(); 232 233 glDisable(GL_BLEND); 234 glEnable(GL_DEPTH_TEST); 235 236 // Restore transform 237 glMatrixMode(GL_PROJECTION); 238 glPopMatrix(); 239 glMatrixMode(GL_MODELVIEW); 240 glPopMatrix(); 241 #endif 91 242 } 92 243 93 void CCinemaManager::MoveToPointAt(float time)244 InReaction cinema_manager_handler(const SDL_Event_* ev) 94 245 { 95 ENSURE(m_CurrentPath != m_Paths.end()); 96 StopPlaying(); 246 // put any events that must be processed even if inactive here 247 if (!g_Game || !g_Game->IsGameStarted()) 248 return IN_PASS; 97 249 98 m_CurrentPath->second.m_TimeElapsed = time; 99 if (!m_CurrentPath->second.Validate()) 100 return; 250 CCinemaManager* pCinemaManager = g_Game->GetView()->GetCinema(); 101 251 102 m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed / 103 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(), 104 m_CurrentPath->second.m_PreviousRotation); 252 return pCinemaManager->HandleEvent(ev); 105 253 } 106 254 107 bool CCinemaManager::Update(const float deltaRealTime)255 InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev) 108 256 { 109 if (!m_PathQueue.front().Play(deltaRealTime))257 switch (ev->ev.type) 110 258 { 111 m_PathQueue.pop_front(); 112 return false; 259 case SDL_MOUSEBUTTONDOWN: 260 case SDL_MOUSEBUTTONUP: 261 if (GetEnabled() && !m_CinematicSimulationData.m_Paused) 262 return IN_HANDLED; 263 default: 264 return IN_PASS; 113 265 } 114 return true;115 266 } 267 268 bool CCinemaManager::GetEnabled() const 269 { 270 return m_CinematicSimulationData.m_Enabled; 271 } 272 273 bool CCinemaManager::IsPlaying() const 274 { 275 return !m_CinematicSimulationData.m_Paused; 276 } 277 278 const std::map<CStrW, CCinemaPath>& CCinemaManager::GetAllPaths() 279 { 280 return m_CinematicSimulationData.m_Paths; 281 } 282 283 CinematicSimulationData* CCinemaManager::GetCinematicSimulationData() 284 { 285 return &m_CinematicSimulationData; 286 } 287 No newline at end of file -
source/graphics/CinemaManager.h
22 22 #include <list> 23 23 #include <map> 24 24 25 #include "lib/input.h" // InReaction - can't forward-declare enum 26 25 27 #include "graphics/CinemaPath.h" 26 28 #include "ps/CStr.h" 27 29 28 //Class for in game playing of cinematics. Should only be instantiated in CGameView. 30 /* 31 desc: contains various functions used for cinematic camera paths 32 See also: CinemaHandler.cpp, CinemaPath.cpp 33 */ 34 35 // Cinematic structure for data accessable from the simulation 36 struct CinematicSimulationData 37 { 38 bool m_Enabled; 39 bool m_Paused; 40 std::map<CStrW, CCinemaPath> m_Paths; 41 std::list<CCinemaPath> m_PathQueue; 42 43 // States before playing 44 bool m_MapRevealed; 45 46 fixed m_ElapsedTime, m_TotalTime, m_CurrentPathElapsedTime; 47 48 CinematicSimulationData() 49 : m_Enabled(false), 50 m_Paused(true), 51 m_MapRevealed(false), 52 m_ElapsedTime(fixed::Zero()), 53 m_TotalTime(fixed::Zero()), 54 m_CurrentPathElapsedTime(fixed::Zero()) 55 {} 56 }; 57 58 /** 59 * Class for in game playing of cinematics. Should only be instantiated in CGameView. 60 */ 61 29 62 class CCinemaManager 30 63 { 31 64 public: … … 32 65 CCinemaManager(); 33 66 ~CCinemaManager() {} 34 67 35 void AddPath(CCinemaPath path, const CStrW& name); 68 /** 69 * Adds the path to the path list 70 * @param name path name 71 * @param CCinemaPath path data 72 */ 73 void AddPath(const CStrW& name, const CCinemaPath& path); 36 74 37 //Adds track to list of being played. 38 void QueuePath(const CStrW& name, bool queue); 39 void OverridePath(const CStrW& name); //clears track queue and replaces with 'name' 75 /** 76 * Adds the path to the playlist 77 * @param name path name 78 */ 79 void AddPathToQueue(const CStrW& name); 40 80 41 81 /** 42 * @param deltaRealTime Elapsed real time since the last frame.82 * Clears the playlist 43 83 */ 44 bool Update(const float deltaRealTime); 45 46 //These stop track play, and accept time, not ratio of time 47 void MoveToPointAt(float time); 84 void ClearQueue(); 48 85 49 inline void StopPlaying() { m_PathQueue.clear(); } 50 void DrawSpline() const; 86 /** 87 * Checks the path name in the path list 88 * @param name path name 89 * @return true if path with that name exists, else false 90 */ 91 bool HasPath(const CStrW& name) const; 51 92 52 inline bool IsPlaying() const { return !m_PathQueue.empty(); } 53 bool HasTrack(const CStrW& name) const; 54 inline bool IsActive() const { return m_Active; } 55 inline void SetActive(bool active) { m_Active=active; } 56 57 inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; } 93 const std::map<CStrW, CCinemaPath>& GetAllPaths(); 58 94 void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks); 59 void SetCurrentPath(const CStrW& name, bool current, bool lines);60 95 61 private: 62 63 bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent; 64 std::map<CStrW, CCinemaPath>::iterator m_CurrentPath; 65 std::map<CStrW, CCinemaPath> m_Paths; 66 std::list<CCinemaPath> m_PathQueue; 96 /** 97 * Starts play paths 98 */ 99 void Play(); 100 void Pause(); 101 void Stop(); 102 bool IsPlaying() const; 103 104 /** 105 * Renders black bars and paths (if enabled) 106 */ 107 void Render(); 108 void DrawBars() const; 109 110 /** 111 * Get current enable state of the cinema manager 112 */ 113 bool GetEnabled() const; 114 115 /** 116 * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) 117 * @enable new state 118 */ 119 void SetEnabled(bool enabled); 120 121 /** 122 * Updates CCinemManager and current path 123 * @param deltaRealTime Elapsed real time since the last frame. 124 */ 125 void Update(const float deltaRealTime); 126 127 InReaction HandleEvent(const SDL_Event_* ev); 128 129 CinematicSimulationData* GetCinematicSimulationData(); 130 131 private: 132 bool m_DrawPaths; 133 134 // Cinematic data is accessed from the simulation 135 CinematicSimulationData m_CinematicSimulationData; 67 136 }; 68 137 138 extern InReaction cinema_manager_handler(const SDL_Event_* ev); 139 69 140 #endif -
source/graphics/CinemaPath.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 19 18 #include "precompiled.h" 20 19 21 20 #include "CinemaPath.h" 22 21 22 #include <sstream> 23 23 #include <string> 24 #include <sstream>25 24 25 #include "Camera.h" 26 #include "CinemaManager.h" 27 #include "GameView.h" 28 #include "gui/CGUI.h" 29 #include "gui/GUIManager.h" 30 #include "gui/IGUIObject.h" 26 31 #include "lib/ogl.h" 27 #include "ps/Game.h"28 #include "GameView.h"29 32 #include "maths/MathUtil.h" 30 #include "Camera.h" 31 #include "ps/CStr.h" 33 #include "maths/Quaternion.h" 32 34 #include "maths/Vector3D.h" 33 35 #include "maths/Vector4D.h" 34 #include "maths/Quaternion.h" 36 #include "ps/CLogger.h" 37 #include "ps/CStr.h" 38 #include "ps/Game.h" 39 #include "renderer/Renderer.h" 35 40 36 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline) 37 : CCinemaData(data), TNSpline(spline), m_TimeElapsed(0.f) 38 { 39 m_TimeElapsed = 0; 41 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline) 42 : CCinemaData(data), TNSpline(spline), m_TargetSpline(targetSpline), m_TimeElapsed(0.f) 43 { 40 44 BuildSpline(); 41 45 42 //Set distortion mode and style 43 switch(data.m_Mode) 46 if (m_Orientation == L"target") 44 47 { 45 case CCinemaPath::EM_IN: 48 m_LookAtTarget = true; 49 ENSURE(!m_TargetSpline.GetAllNodes().empty()); 50 } 51 52 // Set distortion mode and style 53 if (data.m_Mode == L"ease_in") 46 54 DistModePtr = &CCinemaPath::EaseIn; 47 break; 48 case CCinemaPath::EM_OUT: 55 else if (data.m_Mode == L"ease_out") 49 56 DistModePtr = &CCinemaPath::EaseOut; 50 break; 51 case CCinemaPath::EM_INOUT: 57 else if (data.m_Mode == L"ease_inout") 52 58 DistModePtr = &CCinemaPath::EaseInOut; 53 break; 54 case CCinemaPath::EM_OUTIN: 59 else if (data.m_Mode == L"ease_outin") 55 60 DistModePtr = &CCinemaPath::EaseOutIn; 56 break;57 default:58 debug_printf("Cinematic mode not found for %d\n", data.m_Mode);59 break;61 else 62 { 63 LOGWARNING("Cinematic mode not found for '%s'", data.m_Mode.ToUTF8().c_str()); 64 DistModePtr = &CCinemaPath::EaseInOut; 60 65 } 61 66 62 switch (data.m_Style) 63 { 64 case CCinemaPath::ES_DEFAULT: 67 if (data.m_Style == L"default") 65 68 DistStylePtr = &CCinemaPath::EaseDefault; 66 break; 67 case CCinemaPath::ES_GROWTH: 69 else if (data.m_Style == L"growth") 68 70 DistStylePtr = &CCinemaPath::EaseGrowth; 69 break; 70 case CCinemaPath::ES_EXPO: 71 else if (data.m_Style == L"expo") 71 72 DistStylePtr = &CCinemaPath::EaseExpo; 72 break; 73 case CCinemaPath::ES_CIRCLE: 73 else if (data.m_Style == L"circle") 74 74 DistStylePtr = &CCinemaPath::EaseCircle; 75 break; 76 case CCinemaPath::ES_SINE: 75 else if (data.m_Style == L"sine") 77 76 DistStylePtr = &CCinemaPath::EaseSine; 78 break;79 default:80 debug_printf("Cinematic mode not found for %d\n", data.m_Style);81 break;77 else 78 { 79 LOGWARNING("Cinematic style not found for '%s'", data.m_Style.ToUTF8().c_str()); 80 DistStylePtr = &CCinemaPath::EaseDefault; 82 81 } 83 //UpdateDuration(); 82 } 84 83 84 void CCinemaPath::Draw() const 85 { 86 DrawSpline(*this, CVector4D(0.2f, 0.2f, 1.f, 0.5f), 100, true); 87 DrawSpline(m_TargetSpline, CVector4D(1.0f, 0.2f, 0.2f, 0.5f), 100, true); 88 DrawNodes(CVector4D(0.5f, 1.0f, 0.f, 0.5f)); 85 89 } 86 90 87 void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const91 void CCinemaPath::DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const 88 92 { 89 if ( NodeCount < 2 || DistModePtr == NULL)93 if (spline.NodeCount < 2 || DistModePtr == NULL) 90 94 return; 91 if ( NodeCount == 2 && lines)95 if (spline.NodeCount == 2 && lines) 92 96 smoothness = 2; 93 97 94 float start = MaxDistance/ smoothness;95 float time =0;96 98 float start = spline.MaxDistance.ToFloat() / smoothness; 99 float time = 0; 100 97 101 #if CONFIG2_GLES 98 #warning TODO: do something about CCinemaPath on GLES102 #warning TODO : do something about CCinemaPath on GLES 99 103 #else 100 104 101 glColor4f( RGBA.X, RGBA.Y, RGBA.Z, RGBA.W);102 if ( lines)103 { 105 glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); 106 if (lines) 107 { 104 108 glLineWidth(1.8f); 105 109 glEnable(GL_LINE_SMOOTH); 106 110 glBegin(GL_LINE_STRIP); 107 111 108 for (int i =0; i<=smoothness; ++i)112 for (int i = 0; i <= smoothness; ++i) 109 113 { 110 // Find distorted time111 time = start*i / MaxDistance;112 CVector3D tmp = GetPosition(time);113 glVertex3f( tmp.X, tmp.Y, tmp.Z);114 // Find distorted time 115 time = start*i / spline.MaxDistance.ToFloat(); 116 CVector3D tmp = spline.GetPosition(time); 117 glVertex3f(tmp.X, tmp.Y, tmp.Z); 114 118 } 115 119 glEnd(); 116 120 glDisable(GL_LINE_SMOOTH); … … 119 123 else 120 124 { 121 125 smoothness /= 2; 122 start = MaxDistance/ smoothness;126 start = spline.MaxDistance.ToFloat() / smoothness; 123 127 glEnable(GL_POINT_SMOOTH); 124 128 glPointSize(3.0f); 125 129 glBegin(GL_POINTS); 126 130 127 for (int i =0; i<=smoothness; ++i)131 for (int i = 0; i <= smoothness; ++i) 128 132 { 129 // Find distorted time130 time = (this->*DistModePtr)(start*i / MaxDistance);131 CVector3D tmp = GetPosition(time);132 glVertex3f( tmp.X, tmp.Y, tmp.Z);133 // Find distorted time 134 time = (this->*DistModePtr)(start*i / spline.MaxDistance.ToFloat()); 135 CVector3D tmp = spline.GetPosition(time); 136 glVertex3f(tmp.X, tmp.Y, tmp.Z); 133 137 } 134 glColor3f(1.0f, 1.0f, 0.0f); //yellow138 glColor3f(1.0f, 1.0f, 0.0f); // yellow 135 139 136 for ( size_t i=0; i<Node.size(); ++i ) 137 glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z); 140 for (size_t i = 0; i < spline.GetAllNodes().size(); ++i) 141 glVertex3f( 142 spline.GetAllNodes()[i].Position.X.ToFloat(), 143 spline.GetAllNodes()[i].Position.Y.ToFloat(), 144 spline.GetAllNodes()[i].Position.Z.ToFloat() 145 ); 138 146 139 147 glEnd(); 140 148 glPointSize(1.0f); … … 144 152 #endif 145 153 } 146 154 155 void CCinemaPath::DrawNodes(const CVector4D& RGBA) const 156 { 157 #if CONFIG2_GLES 158 #warning TODO : do something about CCinemaPath on GLES 159 #else 160 glEnable(GL_POINT_SMOOTH); 161 glPointSize(5.0f); 162 163 glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); 164 glBegin(GL_POINTS); 165 for (size_t i = 0; i < Node.size(); ++i) 166 glVertex3f(Node[i].Position.X.ToFloat(), Node[i].Position.Y.ToFloat(), Node[i].Position.Z.ToFloat()); 167 glEnd(); 168 169 if (!m_LookAtTarget) 170 { 171 glPointSize(1.0f); 172 glDisable(GL_POINT_SMOOTH); 173 return; 174 } 175 176 // draw target nodes 177 glColor4f(RGBA.Y, RGBA.X, RGBA.Z, RGBA.W); 178 glBegin(GL_POINTS); 179 for (size_t i = 0; i < m_TargetSpline.GetAllNodes().size(); ++i) 180 glVertex3f( 181 m_TargetSpline.GetAllNodes()[i].Position.X.ToFloat(), 182 m_TargetSpline.GetAllNodes()[i].Position.Y.ToFloat(), 183 m_TargetSpline.GetAllNodes()[i].Position.Z.ToFloat() 184 ); 185 glEnd(); 186 187 glPointSize(1.0f); 188 glDisable(GL_POINT_SMOOTH); 189 #endif 190 } 191 147 192 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation) 148 193 { 149 CCamera * Cam= g_Game->GetView()->GetCamera();194 CCamera *camera = g_Game->GetView()->GetCamera(); 150 195 t = (this->*DistModePtr)(t); 151 152 CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation;153 CQuaternion start, end;154 start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z));155 end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z));156 start.Slerp(start, end, nodet);157 196 CVector3D pos = GetPosition(t); 158 CQuaternion quat;159 197 160 Cam->m_Orientation.SetIdentity(); 161 Cam->m_Orientation.Rotate(start); 162 Cam->m_Orientation.Translate(pos); 163 Cam->UpdateFrustum(); 198 if (m_LookAtTarget) 199 { 200 if (m_TimeElapsed <= m_TargetSpline.MaxDistance.ToFloat()) 201 camera->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance.ToFloat()), CVector3D(0, 1, 0)); 202 else 203 camera->LookAt(pos, m_TargetSpline.GetAllNodes().back().Position, CVector3D(0, 1, 0)); 204 } 205 else 206 { 207 CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation; 208 CQuaternion start, end; 209 start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z)); 210 end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z)); 211 start.Slerp(start, end, nodet); 212 213 camera->m_Orientation.SetIdentity(); 214 camera->m_Orientation.Rotate(start); 215 camera->m_Orientation.Translate(pos); 216 } 217 camera->UpdateFrustum(); 164 218 } 165 219 166 // Distortion mode functions220 // Distortion mode functions 167 221 float CCinemaPath::EaseIn(float t) const 168 222 { 169 223 return (this->*DistStylePtr)(t); 170 224 } 225 171 226 float CCinemaPath::EaseOut(float t) const 172 227 { 173 return 1.0f - EaseIn(1.0f -t);228 return 1.0f - EaseIn(1.0f - t); 174 229 } 230 175 231 float CCinemaPath::EaseInOut(float t) const 176 232 { 177 233 if (t < m_Switch) 178 return EaseIn(1.0f /m_Switch * t) * m_Switch;179 return EaseOut(1.0f /m_Switch * (t-m_Switch)) * m_Switch + m_Switch;234 return EaseIn(1.0f / m_Switch * t) * m_Switch; 235 return EaseOut(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch; 180 236 } 237 181 238 float CCinemaPath::EaseOutIn(float t) const 182 239 { 183 240 if (t < m_Switch) 184 return EaseOut(1.0f /m_Switch * t) * m_Switch;185 return EaseIn(1.0f /m_Switch * (t-m_Switch)) * m_Switch + m_Switch;241 return EaseOut(1.0f / m_Switch * t) * m_Switch; 242 return EaseIn(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch; 186 243 } 187 244 188 189 //Distortion style functions 245 // Distortion style functions 190 246 float CCinemaPath::EaseDefault(float t) const 191 247 { 192 248 return t; 193 249 } 250 194 251 float CCinemaPath::EaseGrowth(float t) const 195 252 { 196 253 return pow(t, m_Growth); 197 254 } 198 255 256 199 257 float CCinemaPath::EaseExpo(float t) const 200 258 { 201 if (t == 0)259 if (t == 0) 202 260 return t; 203 return powf(m_Growth, 10*(t-1.0f));261 return powf(m_Growth, 10 * (t - 1.0f)); 204 262 } 263 205 264 float CCinemaPath::EaseCircle(float t) const 206 265 { 207 208 if(m_GrowthCount > 1.0f)209 210 m_GrowthCount--;211 212 213 266 t = -(sqrt(1.0f - t*t) - 1.0f); 267 if (m_GrowthCount > 1.0f) 268 { 269 --m_GrowthCount; 270 return (this->*DistStylePtr)(t); 271 } 272 return t; 214 273 } 215 274 216 275 float CCinemaPath::EaseSine(float t) const 217 276 { 218 t = 1.0f - cos(t * (float)M_PI/2);219 if(m_GrowthCount > 1.0f)220 221 m_GrowthCount--;222 223 224 277 t = 1.0f - cos(t * (float)M_PI / 2); 278 if (m_GrowthCount > 1.0f) 279 { 280 --m_GrowthCount; 281 return (this->*DistStylePtr)(t); 282 } 283 return t; 225 284 } 226 285 227 286 bool CCinemaPath::Validate() 228 287 { 229 if ( m_TimeElapsed <= GetDuration() && m_TimeElapsed >= 0.0f ) 288 if (m_TimeElapsed > GetDuration().ToFloat() || m_TimeElapsed < 0.0f) 289 return false; 290 291 // Find current node and past "node time" 292 float previousTime = 0.0f, cumulation = 0.0f; 293 294 // Ignore the last node, since it is a blank (node time values are shifted down one from interface) 295 for (size_t i = 0; i < Node.size() - 1; ++i) 230 296 { 231 //Find current node and past "node time" 232 float previousTime = 0.0f, cumulation = 0.0f; 233 //Ignore the last node, since it is a blank (node time values are shifted down one from interface) 234 for ( size_t i = 0; i < Node.size() - 1; ++i ) 297 cumulation += Node[i].Distance.ToFloat(); 298 if (m_TimeElapsed <= cumulation) 235 299 { 236 cumulation += Node[i].Distance; 237 if ( m_TimeElapsed <= cumulation ) 238 { 239 m_PreviousNodeTime = previousTime; 240 m_PreviousRotation = Node[i].Rotation; 241 m_CurrentNode = i; //We're moving toward this next node, so use its rotation 242 return true; 243 } 244 else 245 previousTime += Node[i].Distance; 300 m_PreviousNodeTime = previousTime; 301 m_PreviousRotation = Node[i].Rotation; 302 m_CurrentNode = i; // We're moving toward this next node, so use its rotation 303 return true; 246 304 } 305 previousTime += Node[i].Distance.ToFloat(); 247 306 } 248 return false; 307 debug_warn("validation of cinema path is wrong\n"); 308 return true; 249 309 } 250 310 251 311 bool CCinemaPath::Play(const float deltaRealTime) 252 312 { 253 m_TimeElapsed += m_Timescale * deltaRealTime; 254 313 m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime; 255 314 if (!Validate()) 256 315 { 257 316 m_TimeElapsed = 0.0f; 258 317 return false; 259 318 } 260 261 MoveToPointAt( m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation ); 319 MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation); 262 320 return true; 263 } 264 No newline at end of file 321 } -
source/graphics/CinemaPath.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 19 18 #ifndef INCLUDED_CINEMAPATH 20 19 #define INCLUDED_CINEMAPATH 21 20 22 #include <list> 23 #include <map> 21 #include "maths/NUSpline.h" 24 22 #include "ps/CStr.h" 25 #include "maths/NUSpline.h"26 23 27 /*28 desc: contains various functions used for cinematic camera paths29 See also: CinemaHandler.cpp, Cinematic.h/.cpp30 */31 32 24 class CVector3D; 33 25 class CVector4D; 34 26 class CCamera; 35 27 36 // For loading data28 // For loading data 37 29 class CCinemaData 38 30 { 39 31 public: 40 CCinemaData() : m_GrowthCount(0), m_Growth(0), m_Switch(0), 41 m_Mode(0), m_Style(0), m_Timescale(1) {} 32 CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {} 42 33 virtual ~CCinemaData() {} 43 34 44 35 const CCinemaData* GetData() const { return this; } 45 46 //Distortion variables 36 37 CStrW m_Name; 38 CStrW m_Orientation; 39 CStrW m_Mode; 40 CStrW m_Style; 41 42 bool m_LookAtTarget; 43 44 fixed m_Timescale; // a negative timescale results in backwards play 45 46 // Distortion variables 47 47 mutable float m_GrowthCount; 48 48 float m_Growth; 49 49 float m_Switch; 50 int m_Mode;51 int m_Style;52 float m_Timescale; //a negative timescale results in backwards play53 54 50 }; 55 51 56 52 57 // Once the data is part of the path, it shouldn't be changeable, so use private inheritance.58 // This class encompasses the spline and the information which determines how the path will operate59 // and also provides the functionality for doing so53 // Once the data is part of the path, it shouldn't be changeable, so use private inheritance. 54 // This class encompasses the spline and the information which determines how the path will operate 55 // and also provides the functionality for doing so 60 56 61 57 class CCinemaPath : private CCinemaData, public TNSpline 62 58 { 63 59 public: 64 CCinemaPath() { m_TimeElapsed = 0.0f; m_PreviousNodeTime = 0.0f;}65 CCinemaPath(const CCinemaData& data, const TNSpline& spline );60 CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {} 61 CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); 66 62 ~CCinemaPath() { DistStylePtr = NULL; DistModePtr = NULL; } 67 68 enum { EM_IN, EM_OUT, EM_INOUT, EM_OUTIN }; 69 enum { ES_DEFAULT, ES_GROWTH, ES_EXPO, ES_CIRCLE, ES_SINE }; 70 71 //sets camera position to calculated point on spline 72 void MoveToPointAt(float t, float nodet, const CVector3D& ); 73 74 //Distortion mode functions-change how ratio is passed to distortion style functions 63 64 // Sets camera position to calculated point on spline 65 void MoveToPointAt(float t, float nodet, const CVector3D&); 66 67 // Distortion mode functions-change how ratio is passed to distortion style functions 75 68 float EaseIn(float t) const; 76 69 float EaseOut(float t) const; 77 70 float EaseInOut(float t) const; 78 71 float EaseOutIn(float t) const; 79 72 80 // Distortion style functions73 // Distortion style functions 81 74 float EaseDefault(float t) const; 82 75 float EaseGrowth(float t) const; 83 76 float EaseExpo(float t) const; 84 77 float EaseCircle(float t) const; 85 78 float EaseSine(float t) const; 86 79 87 80 float (CCinemaPath::*DistStylePtr)(float ratio) const; 88 81 float (CCinemaPath::*DistModePtr)(float ratio) const; 89 82 … … 91 84 92 85 public: 93 86 94 void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const; 87 void Draw() const; 88 void DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const; 89 void DrawNodes(const CVector4D& RGBA) const; 95 90 96 91 inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; } 97 inline f loatGetNodeDuration(const int index) const { return Node[index].Distance; }98 inline f loatGetDuration() const { return MaxDistance; }99 100 inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance ; }92 inline fixed GetNodeDuration(const int index) const { return Node[index].Distance; } 93 inline fixed GetDuration() const { return MaxDistance; } 94 95 inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance.ToFloat(); } 101 96 inline float GetElapsedTime() const { return m_TimeElapsed; } 102 97 103 inline void SetTimescale(float scale) { m_Timescale = scale; } 104 98 CStrW GetName() const { return m_Name; } 99 100 inline void SetTimescale(fixed scale) { m_Timescale = scale; } 101 105 102 float m_TimeElapsed; 106 float m_PreviousNodeTime; 107 103 float m_PreviousNodeTime; //How much time has passed before the current node 104 108 105 size_t m_CurrentNode; 109 106 CVector3D m_PreviousRotation; 110 107 111 public: 108 public: 112 109 113 110 /** 114 111 * Returns false if finished. 115 *116 112 * @param deltaRealTime Elapsed real time since the last frame. 117 113 */ 118 114 bool Play(const float deltaRealTime); 115 116 /** 117 * Validate the path 118 * @return true if the path is valid 119 */ 119 120 bool Validate(); 120 121 121 inline float GetTimescale() const { return m_Timescale; } 122 /** 123 * Returns true if path doesn't contain nodes 124 */ 125 bool Empty() { return Node.empty(); } 126 127 fixed GetTimescale() const { return m_Timescale; } 128 129 TNSpline* getTargetSpline() { return &m_TargetSpline; } 130 131 private: 132 133 TNSpline m_TargetSpline; 122 134 }; 123 135 124 #endif 136 #endif // INCLUDED_CINEMAPATH -
source/graphics/GameView.cpp
626 626 if (!g_app_has_focus) 627 627 return; 628 628 629 if (m->CinemaManager. IsActive() && m->CinemaManager.IsPlaying())629 if (m->CinemaManager.GetEnabled()) 630 630 { 631 if (! m->CinemaManager.Update(deltaRealTime)) 632 { 633 // ResetCamera(); 634 } 631 m->CinemaManager.Update(deltaRealTime); 635 632 return; 636 633 } 637 634 -
source/graphics/MapReader.cpp
456 456 void ReadTerrain(XMBElement parent); 457 457 void ReadEnvironment(XMBElement parent); 458 458 void ReadCamera(XMBElement parent); 459 void Read Cinema(XMBElement parent);459 void ReadPaths(XMBElement parent); 460 460 void ReadTriggers(XMBElement parent); 461 461 int ReadEntities(XMBElement parent, double end_time); 462 462 }; … … 839 839 } 840 840 } 841 841 842 void CXMLReader::Read Cinema(XMBElement parent)842 void CXMLReader::ReadPaths(XMBElement parent) 843 843 { 844 844 #define EL(x) int el_##x = xmb_file.GetElementID(#x) 845 845 #define AT(x) int at_##x = xmb_file.GetAttributeID(#x) … … 846 846 847 847 EL(path); 848 848 EL(rotation); 849 EL(distortion);850 849 EL(node); 851 850 EL(position); 852 EL(t ime);851 EL(target); 853 852 AT(name); 854 853 AT(timescale); 854 AT(orientation); 855 855 AT(mode); 856 856 AT(style); 857 AT(growth);858 AT(switch);859 857 AT(x); 860 858 AT(y); 861 859 AT(z); 860 AT(deltatime); 862 861 863 862 #undef EL 864 863 #undef AT 865 866 std::map<CStrW, CCinemaPath> pathList; 864 867 865 XERO_ITER_EL(parent, element) 868 866 { 869 867 int elementName = element.GetNodeName(); … … 870 868 871 869 if (elementName == el_path) 872 870 { 871 CCinemaData pathData; 873 872 XMBAttributeList attrs = element.GetAttributes(); 874 CStrW name(attrs.GetNamedItem(at_name).FromUTF8()); 875 float timescale = attrs.GetNamedItem(at_timescale).ToFloat(); 876 CCinemaData pathData; 877 pathData.m_Timescale = timescale; 878 TNSpline spline, backwardSpline; 873 CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8()); 874 pathData.m_Timescale = fixed::FromFloat(attrs.GetNamedItem(at_timescale).ToFloat()); 875 TNSpline pathSpline, targetSpline; 876 fixed lastTargetTime = fixed::Zero(); 879 877 878 pathData.m_Name = pathName; 879 pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8(); 880 pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8(); 881 pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8(); 882 880 883 XERO_ITER_EL(element, pathChild) 881 884 { 882 885 elementName = pathChild.GetNodeName(); 883 886 attrs = pathChild.GetAttributes(); 884 887 885 // Load distortion attributes886 if (elementName == el_ distortion)888 // Load node data used for spline 889 if (elementName == el_node) 887 890 { 888 pathData.m_Mode = attrs.GetNamedItem(at_mode).ToInt(); 889 pathData.m_Style = attrs.GetNamedItem(at_style).ToInt(); 890 pathData.m_Growth = attrs.GetNamedItem(at_growth).ToInt(); 891 pathData.m_Switch = attrs.GetNamedItem(at_switch).ToInt(); 892 } 893 894 //Load node data used for spline 895 else if (elementName == el_node) 896 { 891 bool positionDeclared = false; 897 892 SplineData data; 893 data.Distance = fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat()); 894 lastTargetTime += fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat()); 898 895 XERO_ITER_EL(pathChild, nodeChild) 899 896 { 900 897 elementName = nodeChild.GetNodeName(); 901 898 attrs = nodeChild.GetAttributes(); 902 899 903 //Fix?: assumes that time is last element904 900 if (elementName == el_position) 905 901 { 906 data.Position.X = attrs.GetNamedItem(at_x).ToFloat();907 data.Position.Y = attrs.GetNamedItem(at_y).ToFloat();908 data.Position.Z = attrs.GetNamedItem(at_z).ToFloat();909 continue;902 data.Position.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 903 data.Position.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 904 data.Position.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 905 positionDeclared = true; 910 906 } 911 907 else if (elementName == el_rotation) 912 908 { 913 data.Rotation.X = attrs.GetNamedItem(at_x).ToFloat(); 914 data.Rotation.Y = attrs.GetNamedItem(at_y).ToFloat(); 915 data.Rotation.Z = attrs.GetNamedItem(at_z).ToFloat(); 916 continue; 909 data.Rotation.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 910 data.Rotation.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 911 data.Rotation.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 917 912 } 918 else if (elementName == el_time) 919 data.Distance = nodeChild.GetText().ToFloat(); 913 else if (elementName == el_target) 914 { 915 CFixedVector3D targetPosition; 916 targetPosition.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 917 targetPosition.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 918 targetPosition.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 919 920 targetSpline.AddNode(targetPosition, CFixedVector3D(), lastTargetTime); 921 lastTargetTime = fixed::Zero(); 922 } 920 923 else 921 debug_warn(L"Invalid cinematic element for node child"); 922 923 backwardSpline.AddNode(data.Position, data.Rotation, data.Distance); 924 LOGWARNING("Invalid cinematic element for node child"); 924 925 } 926 927 // skip the node if no position 928 if (positionDeclared) 929 pathSpline.AddNode(data.Position, data.Rotation, data.Distance); 925 930 } 926 931 else 927 debug_warn(L"Invalid cinematic element for path child"); 928 929 932 LOGWARNING("Invalid cinematic element for path child"); 930 933 } 931 934 932 //Construct cinema path with data gathered 933 CCinemaPath temp(pathData, backwardSpline); 934 const std::vector<SplineData>& nodes = temp.GetAllNodes(); 935 if (nodes.empty()) 935 // Construct cinema path with data gathered 936 CCinemaPath path(pathData, pathSpline, targetSpline); 937 if (path.Empty()) 936 938 { 937 debug_warn(L"Failure loading cinematics");939 LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8()); 938 940 return; 939 941 } 940 942 941 for (std::vector<SplineData>::const_reverse_iterator it = nodes.rbegin(); 942 it != nodes.rend(); ++it) 943 { 944 spline.AddNode(it->Position, it->Rotation, it->Distance); 945 } 946 947 CCinemaPath path(pathData, spline); 948 pathList[name] = path; 943 if (!m_MapReader.pCinema->HasPath(pathName)) 944 m_MapReader.pCinema->AddPath(pathName, path); 945 else 946 LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8()); 949 947 } 950 948 else 951 ENSURE("Invalid cinema child");949 LOGWARNING("Invalid path child with name '%s'", element.GetText()); 952 950 } 953 954 if (m_MapReader.pCinema)955 m_MapReader.pCinema->SetAllPaths(pathList);956 951 } 957 952 958 953 void CXMLReader::ReadTriggers(XMBElement UNUSED(parent)) … … 1125 1120 } 1126 1121 else if (name == "Paths") 1127 1122 { 1128 Read Cinema(node);1123 ReadPaths(node); 1129 1124 } 1130 1125 else if (name == "Triggers") 1131 1126 { -
source/graphics/MapWriter.cpp
408 408 409 409 for ( ; it != paths.end(); ++it ) 410 410 { 411 CStrW name = it->first; 412 float timescale = it->second.GetTimescale(); 411 fixed timescale = it->second.GetTimescale(); 412 const std::vector<SplineData>& nodes = it->second.GetAllNodes(); 413 const CCinemaData* data = it->second.GetData(); 413 414 414 415 XML_Element("Path"); 415 XML_Attribute("name", name);416 XML_Attribute("name", data->m_Name); 416 417 XML_Attribute("timescale", timescale); 418 XML_Attribute("orientation", data->m_Orientation); 419 XML_Attribute("mode", data->m_Mode); 420 XML_Attribute("style", data->m_Style); 417 421 418 const std::vector<SplineData>& nodes = it->second.GetAllNodes(); 419 const CCinemaData* data = it->second.GetData(); 420 422 // TODO: write target nodes 423 for (size_t j = 0; j < nodes.size(); ++j) 421 424 { 422 XML_Element("Distortion");423 XML_Attribute("mode", data->m_Mode);424 XML_Attribute("style", data->m_Style);425 XML_Attribute("growth", data->m_Growth);426 XML_Attribute("switch", data->m_Switch);427 }428 429 for ( ssize_t j=nodes.size()-1; j >= 0; --j )430 {431 425 XML_Element("Node"); 426 if (j > 0) 427 XML_Attribute("deltatime", nodes[j - 1].Distance); 428 else 429 XML_Attribute("deltatime", 0.0f); 432 430 433 431 { 434 432 XML_Element("Position"); … … 443 441 XML_Attribute("y", nodes[j].Rotation.Y); 444 442 XML_Attribute("z", nodes[j].Rotation.Z); 445 443 } 446 447 XML_Setting("Time", nodes[j].Distance);448 444 } 449 445 } 450 446 } -
source/lib/input.cpp
32 32 33 33 #include "lib/external_libraries/libsdl.h" 34 34 35 const size_t MAX_HANDLERS = 8;35 const size_t MAX_HANDLERS = 9; 36 36 static InHandler handler_stack[MAX_HANDLERS]; 37 37 static size_t handler_stack_top = 0; 38 38 -
source/maths/NUSpline.cpp
45 45 /*********************************** R N S **************************************************/ 46 46 47 47 // adds node and updates segment length 48 void RNSpline::AddNode(const C Vector3D& pos)48 void RNSpline::AddNode(const CFixedVector3D& pos) 49 49 { 50 50 if (NodeCount >= MAX_SPLINE_NODES) 51 51 return; 52 53 52 if (NodeCount == 0) 54 MaxDistance = 0.f;53 MaxDistance = fixed::Zero(); 55 54 else 56 55 { 57 56 Node[NodeCount-1].Distance = (Node[NodeCount-1].Position - pos).Length(); … … 97 96 { 98 97 if (NodeCount < 2) 99 98 return CVector3D(0.0f, 0.0f, 0.0f); 100 99 if (time < 0.0f) 100 time = 0.0f; 101 101 if (time > 1.0f) 102 102 time = 1.0f; 103 float Distance = time * MaxDistance ;103 float Distance = time * MaxDistance.ToFloat(); 104 104 float CurrentDistance = 0.f; 105 105 int i = 0; 106 106 107 // Find which node we're on108 while (CurrentDistance + Node[i].Distance < Distance && i < NodeCount - 2)107 // Find which node we're on 108 while (CurrentDistance + Node[i].Distance.ToFloat() < Distance && i < NodeCount - 2) 109 109 { 110 CurrentDistance += Node[i].Distance ;110 CurrentDistance += Node[i].Distance.ToFloat(); 111 111 ++i; 112 112 } 113 113 ENSURE(i < NodeCount - 1); 114 114 float t = Distance - CurrentDistance; 115 t /= Node[i].Distance; // scale t in range 0 - 1 116 CVector3D startVel = Node[i].Velocity * Node[i].Distance; 117 CVector3D endVel = Node[i+1].Velocity * Node[i].Distance; 118 return GetPositionOnCubic(Node[i].Position, startVel, Node[i+1].Position, endVel, t); 115 // TODO: reimplement CVector3D comparator (float comparing is bad without EPS) 116 if (Node[i].Position == Node[i+1].Position || Node[i].Distance.ToFloat() < 1e-7) // distance too small or zero 117 { 118 return Node[i+1].Position; 119 } 120 t /= Node[i].Distance.ToFloat(); // scale t in range 0 - 1 121 CVector3D startVel = Node[i].Velocity * Node[i].Distance.ToFloat(); 122 CVector3D endVel = Node[i+1].Velocity * Node[i].Distance.ToFloat(); 123 return GetPositionOnCubic(Node[i].Position, startVel, 124 Node[i+1].Position, endVel, t); 119 125 } 120 126 121 127 // internal. Based on Equation 14 … … 123 129 { 124 130 if (index >= NodeCount - 1 || index < 0) 125 131 return CVector3D(0.0f, 0.0f, 0.0f); 126 127 CVector3D temp = (Node[index+1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance); 132 CVector3D temp = CVector3D(Node[index+1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance.ToFloat()); 128 133 return (temp - Node[index+1].Velocity)*0.5f; 129 134 } 130 135 … … 133 138 { 134 139 if (index >= NodeCount || index < 1) 135 140 return CVector3D(0.0f, 0.0f, 0.0f); 136 137 CVector3D temp = (Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance); 141 CVector3D temp = CVector3D(Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance.ToFloat()); 138 142 return (temp - Node[index-1].Velocity) * 0.5f; 139 143 } 140 144 … … 151 155 for (int i = 1; i < NodeCount-1; ++i) 152 156 { 153 157 // Equation 12 154 newVel = GetEndVelocity(i) * Node[i].Distance + GetStartVelocity(i) * Node[i-1].Distance;155 newVel = newVel * ( 1 / (Node[i-1].Distance + Node[i].Distance));158 newVel = GetEndVelocity(i) * Node[i].Distance.ToFloat() + GetStartVelocity(i) * Node[i-1].Distance.ToFloat(); 159 newVel = newVel * (1 / (Node[i-1].Distance + Node[i].Distance).ToFloat()); 156 160 Node[i-1].Velocity = oldVel; 157 161 oldVel = newVel; 158 162 } … … 164 168 165 169 // as with RNSpline but use timePeriod in place of actual node spacing 166 170 // ie time period is time from last node to this node 167 void TNSpline::AddNode(const C Vector3D& pos, const CVector3D& rotation, floattimePeriod)171 void TNSpline::AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod) 168 172 { 169 173 if (NodeCount >= MAX_SPLINE_NODES) 170 174 return; 171 175 172 176 if (NodeCount == 0) 173 MaxDistance = 0.f;177 MaxDistance = fixed::Zero(); 174 178 else 175 179 { 176 180 Node[NodeCount-1].Distance = timePeriod; … … 181 185 temp.Position = pos; 182 186 183 187 //make sure we don't end up using undefined numbers... 184 temp.Distance = 0.0f;188 temp.Distance = fixed::Zero(); 185 189 temp.Velocity = CVector3D(0.0f, 0.0f, 0.0f); 186 190 temp.Rotation = rotation; 187 191 Node.push_back(temp); … … 189 193 } 190 194 191 195 //Inserts node before position 192 void TNSpline::InsertNode(const int index, const C Vector3D& pos, const CVector3D& rotation, floattimePeriod)196 void TNSpline::InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod) 193 197 { 194 198 if (NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1) 195 199 return; 196 197 200 if (NodeCount == 0) 198 MaxDistance = 0.f;201 MaxDistance = fixed::Zero(); 199 202 else 200 203 { 201 204 Node[NodeCount-1].Distance = timePeriod; … … 216 219 217 220 MaxDistance -= Node[index].Distance; 218 221 MaxDistance -= Node[index-1].Distance; 219 Node[index-1].Distance = 0.0f;222 Node[index-1].Distance = fixed::Zero(); 220 223 Node.erase(Node.begin() + index, Node.begin() + index + 1); 221 224 --NodeCount; 222 225 } 223 224 void TNSpline::UpdateNodeTime(const int index, float time) 225 { 226 void TNSpline::UpdateNodeTime(const int index, fixed time) 227 { 226 228 if (NodeCount == 0 || index > NodeCount - 1) 227 229 return; 228 230 229 231 Node[index].Distance = time; 230 232 } 231 232 void TNSpline::UpdateNodePos(const int index, const CVector3D& pos) 233 { 233 void TNSpline::UpdateNodePos(const int index, const CFixedVector3D& pos) 234 { 234 235 if (NodeCount == 0 || index > NodeCount - 1) 235 236 return; 236 237 237 238 Node[index].Position = pos; 238 239 } 239 240 240 void TNSpline::Constrain() 241 241 { 242 242 if (NodeCount < 3) … … 245 245 for (int i = 1; i < NodeCount-1; ++i) 246 246 { 247 247 // Equation 13 248 float r0 = (Node[i].Position -Node[i-1].Position).Length() / Node[i-1].Distance;249 float r1 = (Node[i+1].Position - Node[i].Position).Length() / Node[i].Distance;250 Node[i].Velocity *= 4.0f*r0*r1 /((r0+r1)*(r0+r1));248 float r0 = (Node[i].Position - Node[i - 1].Position).Length().ToFloat() / Node[i-1].Distance.ToFloat(); 249 float r1 = (Node[i+1].Position - Node[i].Position).Length().ToFloat() / Node[i].Distance.ToFloat(); 250 Node[i].Velocity *= 4.0f*r0*r1 / ((r0 + r1)*(r0 + r1)); 251 251 } 252 252 } 253 253 -
source/maths/NUSpline.h
22 22 #ifndef INCLUDED_NUSPLINE 23 23 #define INCLUDED_NUSPLINE 24 24 25 // TODO: why not bigger? 25 26 #define MAX_SPLINE_NODES 40 26 27 #include <stdlib.h> 28 29 #include "FixedVector3D.h" 27 30 #include "Vector3D.h" 28 31 29 32 struct SplineData 30 33 { 31 CVector3D Position; 34 // Should be fixed, because used in the simulation 35 CFixedVector3D Position; 32 36 CVector3D Velocity; 33 CVector3D Rotation; 34 float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is 37 // TODO: make rotation as other spline 38 CFixedVector3D Rotation; 39 fixed Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is 35 40 }; 36 41 37 42 class RNSpline … … 41 46 RNSpline() { NodeCount = 0; } 42 47 virtual ~RNSpline() {} 43 48 44 void AddNode(const C Vector3D& pos);49 void AddNode(const CFixedVector3D& pos); 45 50 void BuildSpline(); 46 51 CVector3D GetPosition(float time) const; 47 52 CVector3D GetRotation(float time) const; 48 53 const std::vector<SplineData>& GetAllNodes() const { return Node; } 49 54 50 float MaxDistance; 55 // TODO: rename to TotalDistance 56 fixed MaxDistance; 51 57 int NodeCount; 52 58 53 59 protected: … … 70 76 public: 71 77 virtual ~TNSpline() {} 72 78 73 void AddNode(const C Vector3D& pos, const CVector3D& rotation, floattimePeriod);79 void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod); 74 80 void PushNode() { Node.push_back( SplineData() ); } 75 void InsertNode(const int index, const C Vector3D& pos, const CVector3D& rotation, floattimePeriod);81 void InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod); 76 82 void RemoveNode(const int index); 77 void UpdateNodeTime(const int index, f loattime);78 void UpdateNodePos(const int index, const C Vector3D& pos);83 void UpdateNodeTime(const int index, fixed time); 84 void UpdateNodePos(const int index, const CFixedVector3D& pos); 79 85 80 86 void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); } 81 87 void Smooth(){ for (int x = 0; x < 3; ++x) { SNSpline::Smooth(); Constrain(); } } -
source/ps/GameSetup/GameSetup.cpp
35 35 #include "lib/sysdep/os/win/wversion.h" 36 36 #endif 37 37 38 #include "graphics/CinemaManager.h" 38 39 #include "graphics/CinemaPath.h" 39 40 #include "graphics/FontMetrics.h" 40 41 #include "graphics/GameView.h" … … 228 229 229 230 g_Renderer.RenderTextOverlays(); 230 231 232 if (g_Game && g_Game->IsGameStarted()) 233 g_Game->GetView()->GetCinema()->Render(); 234 235 ogl_WarnIfError(); 236 231 237 if (g_DoRenderGui) 232 238 g_GUI->Draw(); 233 239 … … 568 574 in_add_handler(gui_handler); 569 575 570 576 in_add_handler(touch_input_handler); 577 578 in_add_handler(cinema_manager_handler); 571 579 572 580 // must be registered after (called before) the GUI which relies on these globals 573 581 in_add_handler(GlobalsInputHandler); -
source/simulation2/components/CCmpCinemaManager.cpp
1 /* Copyright (C) 2016 Wildfire Games. 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "precompiled.h" 19 20 #include "simulation2/system/Component.h" 21 #include "ICmpCinemaManager.h" 22 23 #include "graphics/GameView.h" 24 #include "graphics/CinemaManager.h" 25 #include "ps/CLogger.h" 26 #include "ps/Game.h" 27 #include "simulation2/MessageTypes.h" 28 #include "simulation2/Simulation2.h" 29 30 31 class CCmpCinemaManager : public ICmpCinemaManager 32 { 33 public: 34 static void ClassInit(CComponentManager& componentManager) 35 { 36 componentManager.SubscribeToMessageType(MT_Update); 37 } 38 39 DEFAULT_COMPONENT_ALLOCATOR(CinemaManager) 40 41 static std::string GetSchema() 42 { 43 return "<a:component type='system'/>" 44 "<empty/>" 45 ; 46 } 47 48 virtual void Init(const CParamNode& UNUSED(paramNode)) 49 { 50 // ... 51 } 52 53 virtual void Deinit() 54 { 55 // ... 56 } 57 58 virtual void Serialize(ISerializer& serialize) 59 { 60 if (!g_Game || !g_Game->GetView()) 61 { 62 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 63 return; 64 } 65 CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 66 serialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); 67 serialize.NumberU32_Unbounded("NumberOfPaths", p_CinematicSimulationData->m_Paths.size()); 68 for (auto it : p_CinematicSimulationData->m_Paths) 69 { 70 CCinemaPath& path = it.second; 71 const CCinemaData* data = path.GetData(); 72 73 // TODO: maybe implement String_Unbounded 74 serialize.String("PathName", data->m_Name, 1, 2048); 75 serialize.String("PathOrientation", data->m_Orientation, 1, 2048); 76 serialize.String("PathMode", data->m_Mode, 1, 2048); 77 serialize.String("PathStyle", data->m_Style, 1, 2048); 78 serialize.NumberFixed_Unbounded("PathTimescale", data->m_Timescale); 79 serialize.Bool("LookAtTarget", data->m_LookAtTarget); 80 81 serialize.NumberU32("NumberOfNodes", path.GetAllNodes().size(), 1, MAX_SPLINE_NODES); 82 const std::vector<SplineData>& nodes = path.GetAllNodes(); 83 for (size_t i = 0; i < nodes.size(); ++i) 84 { 85 if (i > 0) 86 serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance); 87 else 88 serialize.NumberFixed_Unbounded("NodeDeltaTime", fixed::Zero()); 89 serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X); 90 serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y); 91 serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z); 92 93 serialize.NumberFixed_Unbounded("RotationX", nodes[i].Rotation.X); 94 serialize.NumberFixed_Unbounded("RotationY", nodes[i].Rotation.Y); 95 serialize.NumberFixed_Unbounded("RotationZ", nodes[i].Rotation.Z); 96 } 97 98 if (!data->m_LookAtTarget) 99 continue; 100 101 const std::vector<SplineData>& targetNodes = path.getTargetSpline()->GetAllNodes(); 102 serialize.NumberU32("NumberOfTargetNodes", targetNodes.size(), 1, MAX_SPLINE_NODES); 103 for (size_t i = 0; i < targetNodes.size(); ++i) 104 { 105 if (i > 0) 106 serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance); 107 else 108 serialize.NumberFixed_Unbounded("NodeDeltaTime", fixed::Zero()); 109 serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X); 110 serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y); 111 serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z); 112 } 113 } 114 } 115 116 virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize) 117 { 118 if (!g_Game || !g_Game->GetView()) 119 { 120 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 121 return; 122 } 123 CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 124 deserialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); 125 uint32_t numberOfPaths = 0; 126 deserialize.NumberU32_Unbounded("NumberOfPaths", numberOfPaths); 127 for (uint32_t i = 0; i < numberOfPaths; ++i) 128 { 129 CCinemaData data; 130 131 deserialize.String("PathName", data.m_Name, 1, 2048); 132 deserialize.String("PathOrientation", data.m_Orientation, 1, 2048); 133 deserialize.String("PathMode", data.m_Mode, 1, 2048); 134 deserialize.String("PathStyle", data.m_Style, 1, 2048); 135 deserialize.NumberFixed_Unbounded("PathTimescale", data.m_Timescale); 136 deserialize.Bool("LookAtTarget", data.m_LookAtTarget); 137 138 TNSpline pathSpline, targetSpline; 139 uint32_t numberOfNodes = 0; 140 deserialize.NumberU32("NumberOfNodes", numberOfNodes, 1, MAX_SPLINE_NODES); 141 for (uint32_t j = 0; j < numberOfNodes; ++j) 142 { 143 SplineData node; 144 deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance); 145 146 deserialize.NumberFixed_Unbounded("PositionX", node.Position.X); 147 deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y); 148 deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z); 149 150 deserialize.NumberFixed_Unbounded("RotationX", node.Rotation.X); 151 deserialize.NumberFixed_Unbounded("RotationY", node.Rotation.Y); 152 deserialize.NumberFixed_Unbounded("RotationZ", node.Rotation.Z); 153 154 pathSpline.AddNode(node.Position, node.Rotation, node.Distance); 155 } 156 157 if (data.m_LookAtTarget) 158 { 159 uint32_t numberOfTargetNodes = 0; 160 deserialize.NumberU32("NumberOfTargetNodes", numberOfTargetNodes, 1, MAX_SPLINE_NODES); 161 for (uint32_t j = 0; j < numberOfTargetNodes; ++j) 162 { 163 SplineData node; 164 deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance); 165 166 deserialize.NumberFixed_Unbounded("PositionX", node.Position.X); 167 deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y); 168 deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z); 169 170 targetSpline.AddNode(node.Position, CFixedVector3D(), node.Distance); 171 } 172 } 173 174 // Construct cinema path with data gathered 175 CCinemaPath path(data, pathSpline, targetSpline); 176 p_CinematicSimulationData->m_Paths[data.m_Name] = path; 177 } 178 g_Game->GetView()->GetCinema()->SetEnabled(p_CinematicSimulationData->m_Enabled); 179 } 180 181 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) 182 { 183 switch (msg.GetType()) 184 { 185 case MT_Update: 186 { 187 const CMessageUpdate &msgData = static_cast<const CMessageUpdate&>(msg); 188 CinematicSimulationData* pCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 189 if (!pCinematicSimulationData->m_Enabled) 190 break; 191 192 if (pCinematicSimulationData->m_ElapsedTime >= pCinematicSimulationData->m_TotalTime) 193 { 194 pCinematicSimulationData->m_ElapsedTime = fixed::Zero(); 195 pCinematicSimulationData->m_TotalTime = fixed::Zero(); 196 g_Game->GetView()->GetCinema()->SetEnabled(false); 197 g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, CMessageCinemaQueueEnded()); 198 } 199 else 200 { 201 pCinematicSimulationData->m_ElapsedTime += msgData.turnLength; 202 pCinematicSimulationData->m_CurrentPathElapsedTime += msgData.turnLength; 203 if (pCinematicSimulationData->m_CurrentPathElapsedTime >= pCinematicSimulationData->m_PathQueue.front().GetDuration()) 204 { 205 CMessageCinemaPathEnded msgCinemaPathEnded(pCinematicSimulationData->m_PathQueue.front().GetName()); 206 pCinematicSimulationData->m_PathQueue.pop_front(); 207 g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msgCinemaPathEnded); 208 } 209 } 210 break; 211 } 212 default: 213 break; 214 } 215 } 216 217 virtual void AddCinemaPathToQueue(CStrW name) 218 { 219 if (!g_Game || !g_Game->GetView()) 220 { 221 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 222 return; 223 } 224 g_Game->GetView()->GetCinema()->AddPathToQueue(name); 225 CinematicSimulationData* pGetCinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 226 pGetCinematicSimulationData->m_TotalTime += pGetCinematicSimulationData->m_Paths[name].GetDuration(); 227 } 228 229 virtual void Play() 230 { 231 if (!g_Game || !g_Game->GetView()) 232 { 233 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 234 return; 235 } 236 g_Game->GetView()->GetCinema()->Play(); 237 g_Game->GetView()->GetCinema()->SetEnabled(true); 238 } 239 240 virtual void Pause() 241 { 242 if (!g_Game || !g_Game->GetView()) 243 { 244 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 245 return; 246 } 247 g_Game->GetView()->GetCinema()->Pause(); 248 } 249 250 virtual void Stop() 251 { 252 if (!g_Game || !g_Game->GetView()) 253 { 254 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 255 return; 256 } 257 g_Game->GetView()->GetCinema()->Stop(); 258 g_Game->GetView()->GetCinema()->SetEnabled(false); 259 } 260 261 }; 262 263 REGISTER_COMPONENT_TYPE(CinemaManager) -
source/simulation2/components/CCmpOverlayRenderer.cpp
166 166 167 167 void RenderSubmit(SceneCollector& collector) 168 168 { 169 if (!m_Enabled )169 if (!m_Enabled || !ICmpOverlayRenderer::m_OverrideVisible) 170 170 return; 171 171 172 172 for (size_t i = 0; i < m_Sprites.size(); ++i) -
source/simulation2/components/CCmpSelectable.cpp
587 587 void CCmpSelectable::RenderSubmit(SceneCollector& collector) 588 588 { 589 589 // don't render selection overlay if it's not gonna be visible 590 if (!ICmpSelectable::m_OverrideVisible) 591 return; 592 590 593 if (m_Visible && m_Color.a > 0) 591 594 { 592 595 if (!m_Cached) -
source/simulation2/components/CCmpTerritoryManager.cpp
123 123 m_TriggerEvent = true; 124 124 m_EnableLineDebugOverlays = false; 125 125 m_DirtyID = 1; 126 m_Visible = true; 126 127 127 128 m_AnimTime = 0.0; 128 129 … … 275 276 void Interpolate(float frameTime, float frameOffset); 276 277 277 278 void RenderSubmit(SceneCollector& collector); 279 280 void SetVisibility(bool visible) 281 { 282 m_Visible = visible; 283 } 284 285 private: 286 287 bool m_Visible; 278 288 }; 279 289 280 290 REGISTER_COMPONENT_TYPE(TerritoryManager) … … 644 654 645 655 void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector) 646 656 { 657 if (!m_Visible) 658 return; 659 647 660 for (size_t i = 0; i < m_BoundaryLines.size(); ++i) 648 661 collector.Submit(&m_BoundaryLines[i].overlay); 649 662 -
source/simulation2/components/ICmpCinemaManager.cpp
1 /* Copyright (C) 2016 Wildfire Games. 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "precompiled.h" 19 20 #include "ICmpCinemaManager.h" 21 22 #include "simulation2/system/InterfaceScripted.h" 23 24 BEGIN_INTERFACE_WRAPPER(CinemaManager) 25 DEFINE_INTERFACE_METHOD_1("AddCinemaPathToQueue", void, ICmpCinemaManager, AddCinemaPathToQueue, CStrW) 26 DEFINE_INTERFACE_METHOD_0("Play", void, ICmpCinemaManager, Play) 27 DEFINE_INTERFACE_METHOD_0("Pause", void, ICmpCinemaManager, Pause) 28 DEFINE_INTERFACE_METHOD_0("Stop", void, ICmpCinemaManager, Stop) 29 END_INTERFACE_WRAPPER(CinemaManager) -
source/simulation2/components/ICmpCinemaManager.h
1 /* Copyright (C) 2016 Wildfire Games. 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef INCLUDED_ICMPCINEMAMANAGER 19 #define INCLUDED_ICMPCINEMAMANAGER 20 21 #include "simulation2/system/Interface.h" 22 23 #include "ps/CStr.h" 24 25 /** 26 * Component for CCinemaManager class 27 * TODO: write description 28 */ 29 30 class ICmpCinemaManager : public IComponent 31 { 32 public: 33 // TODO: add path name and description 34 virtual void AddCinemaPathToQueue(CStrW name) = 0; 35 36 virtual void Play() = 0; 37 virtual void Pause() = 0; 38 virtual void Stop() = 0; 39 40 DECLARE_INTERFACE_TYPE(CinemaManager) 41 }; 42 43 #endif // INCLUDED_ICMPCINEMAMANAGER 44 No newline at end of file -
source/simulation2/components/ICmpOverlayRenderer.cpp
25 25 DEFINE_INTERFACE_METHOD_0("Reset", void, ICmpOverlayRenderer, Reset) 26 26 DEFINE_INTERFACE_METHOD_5("AddSprite", void, ICmpOverlayRenderer, AddSprite, VfsPath, CFixedVector2D, CFixedVector2D, CFixedVector3D, std::string) 27 27 END_INTERFACE_WRAPPER(OverlayRenderer) 28 29 bool ICmpOverlayRenderer::m_OverrideVisible = true; 30 No newline at end of file -
source/simulation2/components/ICmpOverlayRenderer.h
52 52 */ 53 53 virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D offset, std::string color = "255 255 255 255") = 0; 54 54 55 /** 56 * Enables or disables rendering of all sprites. 57 * @param visible Whether the selectable should be visible. 58 */ 59 static void SetOverrideVisibility(bool visible) 60 { 61 ICmpOverlayRenderer::m_OverrideVisible = visible; 62 } 63 55 64 DECLARE_INTERFACE_TYPE(OverlayRenderer) 65 66 protected: 67 static bool m_OverrideVisible; 56 68 }; 57 69 58 70 #endif // INCLUDED_ICMPOVERLAYRENDERER -
source/simulation2/components/ICmpSelectable.cpp
28 28 END_INTERFACE_WRAPPER(Selectable) 29 29 30 30 bool ICmpSelectable::ms_EnableDebugOverlays = false; 31 bool ICmpSelectable::m_OverrideVisible = true; -
source/simulation2/components/ICmpSelectable.h
67 67 virtual void SetVisibility(bool visible) = 0; 68 68 69 69 /** 70 * Enables or disables rendering of all entities selectable. 71 * @param visible Whether the selectable should be visible. 72 */ 73 static void SetOverrideVisibility(bool visible) 74 { 75 ICmpSelectable::m_OverrideVisible = visible; 76 } 77 78 /** 70 79 * Set the alpha of the selection highlight. Set to 0 to hide the highlight. 71 80 */ 72 81 virtual void SetSelectionHighlightAlpha(float alpha) = 0; … … 77 86 // and methods, where we can keep settings like these. Note that any such data store would need to be per-component-manager 78 87 // and not entirely global, to support multiple simulation instances. 79 88 static bool ms_EnableDebugOverlays; // ms for member static 89 90 protected: 91 static bool m_OverrideVisible; 80 92 }; 81 93 82 94 #endif // INCLUDED_ICMPSELECTABLE -
source/simulation2/components/ICmpTerritoryManager.h
78 78 */ 79 79 virtual u8 GetTerritoryPercentage(player_id_t player) = 0; 80 80 81 /** 82 * Enables or disables rendering of an territory borders. 83 */ 84 virtual void SetVisibility(bool visible) = 0; 85 81 86 DECLARE_INTERFACE_TYPE(TerritoryManager) 82 87 }; 83 88 -
source/simulation2/MessageTypes.h
29 29 30 30 #include "maths/Vector3D.h" 31 31 32 #include "ps/CStr.h" 33 32 34 #define DEFAULT_MESSAGE_IMPL(name) \ 33 35 virtual int GetType() const { return MT_##name; } \ 34 36 virtual const char* GetScriptHandlerName() const { return "On" #name; } \ … … 538 540 } 539 541 }; 540 542 543 /** 544 * Cinematics events 545 */ 546 547 class CMessageCinemaPathEnded : public CMessage 548 { 549 public: 550 DEFAULT_MESSAGE_IMPL(CinemaPathEnded) 551 552 CMessageCinemaPathEnded(CStrW name) : 553 name(name) 554 { 555 } 556 557 CStrW name; 558 }; 559 560 class CMessageCinemaQueueEnded : public CMessage 561 { 562 public: 563 DEFAULT_MESSAGE_IMPL(CinemaQueueEnded) 564 }; 565 541 566 #endif // INCLUDED_MESSAGETYPES -
source/simulation2/scripting/MessageTypeConversions.cpp
470 470 return new CMessageMinimapPing(); 471 471 } 472 472 473 //////////////////////////////// 474 475 JS::Value CMessageCinemaPathEnded::ToJSVal(ScriptInterface& scriptInterface) const 476 { 477 TOJSVAL_SETUP(); 478 SET_MSG_PROPERTY(name); 479 return JS::ObjectValue(*obj); 480 } 481 482 CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) 483 { 484 FROMJSVAL_SETUP(); 485 GET_MSG_PROPERTY(CStrW, name); 486 return new CMessageCinemaPathEnded(name); 487 } 488 489 //////////////////////////////// 490 491 JS::Value CMessageCinemaQueueEnded::ToJSVal(ScriptInterface& scriptInterface) const 492 { 493 TOJSVAL_SETUP(); 494 return JS::ObjectValue(*obj); 495 } 496 497 CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) 498 { 499 FROMJSVAL_SETUP(); 500 return new CMessageCinemaQueueEnded(); 501 } 502 473 503 //////////////////////////////////////////////////////////////// 474 504 475 505 CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val) -
source/simulation2/system/ComponentManager.cpp
711 711 { 712 712 CParamNode noParam; 713 713 AddComponent(m_SystemEntity, CID_TemplateManager, noParam); 714 AddComponent(m_SystemEntity, CID_CinemaManager, noParam); 714 715 AddComponent(m_SystemEntity, CID_CommandQueue, noParam); 715 716 AddComponent(m_SystemEntity, CID_ObstructionManager, noParam); 716 717 AddComponent(m_SystemEntity, CID_ParticleManager, noParam); -
source/simulation2/TypeList.h
57 57 MESSAGE(TemplateModification) 58 58 MESSAGE(VisionRangeChanged) 59 59 MESSAGE(MinimapPing) 60 MESSAGE(CinemaPathEnded) 61 MESSAGE(CinemaQueueEnded) 60 62 61 63 // TemplateManager must come before all other (non-test) components, 62 64 // so that it is the first to be (de)serialized … … 75 77 INTERFACE(AIManager) 76 78 COMPONENT(AIManager) 77 79 80 INTERFACE(CinemaManager) 81 COMPONENT(CinemaManager) 82 78 83 INTERFACE(CommandQueue) 79 84 COMPONENT(CommandQueue) 80 85 -
source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp
38 38 { 39 39 sCinemaPath path; 40 40 const CCinemaData* data = source->GetData(); 41 path.mode = data->m_Mode;42 path.style = data->m_Style;41 //path.mode = data->m_Mode; 42 //path.style = data->m_Style; 43 43 path.growth = data->m_Growth; 44 path.timescale = data->m_Timescale ;44 path.timescale = data->m_Timescale.ToFloat(); 45 45 path.change = data->m_Switch; 46 46 47 47 return path; … … 51 51 CCinemaData data; 52 52 data.m_Growth = data.m_GrowthCount = path.growth; 53 53 data.m_Switch = path.change; 54 data.m_Mode = path.mode;55 data.m_Style = path.style;54 //data.m_Mode = path.mode; 55 //data.m_Style = path.style; 56 56 57 57 return data; 58 58 } … … 59 59 sCinemaSplineNode ConstructCinemaNode(const SplineData& data) 60 60 { 61 61 sCinemaSplineNode node; 62 node.px = data.Position.X ;63 node.py = data.Position.Y ;64 node.pz = data.Position.Z ;62 node.px = data.Position.X.ToFloat(); 63 node.py = data.Position.Y.ToFloat(); 64 node.pz = data.Position.Z.ToFloat(); 65 65 66 node.rx = data.Rotation.X ;67 node.ry = data.Rotation.Y ;68 node.rz = data.Rotation.Z ;69 node.t = data.Distance ;66 node.rx = data.Rotation.X.ToFloat(); 67 node.ry = data.Rotation.Y.ToFloat(); 68 node.rz = data.Rotation.Z.ToFloat(); 69 node.t = data.Distance.ToFloat(); 70 70 71 71 return node; 72 72 } … … 112 112 { 113 113 CStrW pathName(*it->name); 114 114 paths[pathName] = CCinemaPath(); 115 paths[pathName].SetTimescale( it->timescale);115 paths[pathName].SetTimescale(fixed::FromFloat(it->timescale)); 116 116 117 117 const sCinemaPath& atlasPath = *it; 118 118 const std::vector<sCinemaSplineNode> nodes = *atlasPath.nodes; … … 121 121 122 122 for ( size_t j=0; j<nodes.size(); ++j ) 123 123 { 124 spline.AddNode( C Vector3D(nodes[j].px, nodes[j].py, nodes[j].pz),125 CVector3D(nodes[j].rx, nodes[j].ry, nodes[j].rz), nodes[j].t);124 spline.AddNode( CFixedVector3D(fixed::FromFloat(nodes[j].px), fixed::FromFloat(nodes[j].py), fixed::FromFloat(nodes[j].pz)), 125 CFixedVector3D(fixed::FromFloat(nodes[j].rx), fixed::FromFloat(nodes[j].ry), fixed::FromFloat(nodes[j].rz)), fixed::FromFloat(nodes[j].t)); 126 126 } 127 paths[pathName] = CCinemaPath(data, spline );127 paths[pathName] = CCinemaPath(data, spline, TNSpline()); 128 128 } 129 129 130 130 g_Game->GetView()->GetCinema()->SetAllPaths(paths); … … 155 155 { 156 156 CCinemaManager* manager = g_Game->GetView()->GetCinema(); 157 157 158 if ( msg->mode == eCinemaEventMode::SMOOTH ) 159 manager->OverridePath(*msg->path); 160 else if ( msg->mode == eCinemaEventMode::IMMEDIATE_PATH ) 161 manager->MoveToPointAt(msg->t); 158 if (msg->mode == eCinemaEventMode::SMOOTH) 159 { 160 manager->ClearQueue(); 161 manager->AddPathToQueue(*msg->path); 162 } 162 163 else if ( msg->mode == eCinemaEventMode::RESET ) 163 164 { 164 165 // g_Game->GetView()->ResetCamera(); 165 166 } 166 else if ( msg->mode == eCinemaEventMode::SELECT )167 manager->SetCurrentPath(*msg->path, msg->drawCurrent, msg->lines);168 167 else 169 168 ENSURE(false); 170 169 } -
source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp
57 57 QUERYHANDLER(CinemaRecord) 58 58 { 59 59 CCinemaManager* manager = g_Game->GetView()->GetCinema(); 60 manager->SetCurrentPath(*msg->path, false, false);61 60 62 61 const int w = msg->width, h = msg->height; 63 62 … … 81 80 for (int frame = 0; frame < num_frames; ++frame) 82 81 { 83 82 AtlasView::GetView_Game()->Update(1.f / msg->framerate); 84 85 manager->MoveToPointAt((float)frame/msg->framerate); 83 86 84 Render(); 87 85 Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas); 88 86