Ticket #3301: cinematic_camera_core_v1.5d.patch
File cinematic_camera_core_v1.5d.patch, 92.9 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" 22 23 ]; 23 24 24 25 Trigger.prototype.Init = function() … … 234 235 // See function "SpawnUnits" in ProductionQueue for more details 235 236 }; 236 237 237 // Handles "On TrainingFinished" event.238 // Handles "OnResearchFinished" event. 238 239 Trigger.prototype.OnGlobalResearchFinished = function(msg) 239 240 { 240 241 this.CallEvent("ResearchFinished", msg); … … 242 243 // "tech": tech} 243 244 }; 244 245 246 // Handles "OnCinemaPathEnded" event. 247 Trigger.prototype.OnGlobalCinemaPathEnded = function(msg) 248 { 249 this.CallEvent("CinemaPathEnded", msg); 250 } 251 245 252 Trigger.prototype.OnGlobalOwnershipChanged = function(msg) 246 253 { 247 254 this.CallEvent("OwnershipChanged", msg); -
source/graphics/CinemaManager.cpp
1 /* Copyright (C) 2015 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 19 #include "precompiled.h" 20 21 #include "Camera.h" 22 #include "CinemaManager.h" 23 #include "GameView.h" 24 #include "gui/CGUI.h" 25 #include "gui/GUIManager.h" 26 #include "gui/IGUIObject.h" 27 #include "lib/ogl.h" 28 #include "maths/MathUtil.h" 29 #include "maths/Quaternion.h" 30 #include "maths/Vector3D.h" 31 #include "maths/Vector4D.h" 32 #include "ps/CLogger.h" 33 #include "ps/CStr.h" 34 #include "ps/Game.h" 35 #include "ps/Hotkey.h" 36 #include "simulation2/components/ICmpOverlayRenderer.h" 37 #include "simulation2/components/ICmpRangeManager.h" 38 #include "simulation2/components/ICmpSelectable.h" 39 #include "simulation2/components/ICmpTerritoryManager.h" 40 #include "simulation2/MessageTypes.h" 41 #include "simulation2/system/ComponentManager.h" 42 #include "simulation2/Simulation2.h" 43 #include <sstream> 44 #include <string> 45 #include "renderer/Renderer.h" 46 47 48 CCinemaManager::CCinemaManager() 49 : m_DrawPaths(false) 50 { 51 } 52 53 void CCinemaManager::AddPath(const CStrW& name, CCinemaPath path) 54 { 55 if (m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end()) 56 { 57 LOGWARNING("Path with name '%s' already exists", name.ToUTF8()); 58 return; 59 } 60 m_CinematicSimulationData.m_Paths[name] = path; 61 } 62 63 void CCinemaManager::AddPathToQueue(const CStrW& name) 64 { 65 if (!HasPath(name)) 66 { 67 LOGWARNING("Path with name '%s' doesn't exist", name.ToUTF8()); 68 return; 69 } 70 m_CinematicSimulationData.m_PathQueue.push_back(m_CinematicSimulationData.m_Paths[name]); 71 } 72 73 void CCinemaManager::ClearQueue() 74 { 75 m_CinematicSimulationData.m_PathQueue.clear(); 76 } 77 78 void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths) 79 { 80 m_CinematicSimulationData.m_Paths = paths; 81 } 82 83 void CCinemaManager::SetCurrentPath(const CStrW& UNUSED(name), bool UNUSED(current)) 84 { 85 // ... 86 } 87 88 bool CCinemaManager::HasPath(const CStrW& name) const 89 { 90 return m_CinematicSimulationData.m_Paths.find(name) != m_CinematicSimulationData.m_Paths.end(); 91 } 92 93 void CCinemaManager::SetEnabled(bool enabled) 94 { 95 // TODO: maybe assert? 96 if (m_CinematicSimulationData.m_PathQueue.empty() && enabled) 97 { 98 enabled = false; 99 m_CinematicSimulationData.m_Paused = true; 100 } 101 102 if (m_CinematicSimulationData.m_Enabled == enabled) 103 return; 104 105 // sn - session gui object 106 IGUIObject *sn = g_GUI->FindObjectByName("sn"); 107 CmpPtr<ICmpRangeManager> cmpRangeManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); 108 CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); 109 110 // GUI visibility 111 if (sn) 112 { 113 if (enabled) 114 sn->SetSetting("hidden", L"true"); 115 else 116 sn->SetSetting("hidden", L"false"); 117 } 118 119 // Overlay visibility 120 g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !enabled); 121 if (cmpRangeManager) 122 { 123 if (enabled) 124 m_CinematicSimulationData.m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1); 125 // TODO: improve m_MapRevealed state and without fade in 126 cmpRangeManager->SetLosRevealAll(-1, enabled); 127 } 128 if (cmpTerritoryManager) 129 cmpTerritoryManager->SetVisibility(!enabled); 130 ICmpSelectable::SetOverrideVisibility(!enabled); 131 ICmpOverlayRenderer::SetOverrideVisibility(!enabled); 132 133 m_CinematicSimulationData.m_Enabled = enabled; 134 } 135 136 void CCinemaManager::MoveToPointAt(float UNUSED(time)) 137 { 138 // TODO: Update after Atlas UI patch 139 /*ENSURE(m_CurrentPath != m_Paths.end()); 140 ClearQueue(); 141 142 m_CurrentPath->second.m_TimeElapsed = time; 143 if (!m_CurrentPath->second.Validate()) 144 return; 145 146 m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed / 147 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(), 148 m_CurrentPath->second.m_PreviousRotation );*/ 149 } 150 151 void CCinemaManager::Play() 152 { 153 SetEnabled(true); 154 m_CinematicSimulationData.m_Paused = false; 155 } 156 157 void CCinemaManager::Pause() 158 { 159 m_CinematicSimulationData.m_Paused = true; 160 } 161 162 void CCinemaManager::Stop() 163 { 164 m_CinematicSimulationData.m_Paused = true; 165 SetEnabled(false); 166 m_CinematicSimulationData.m_PathQueue.clear(); 167 } 168 169 void CCinemaManager::Skip() 170 { 171 Next(true); 172 } 173 174 void CCinemaManager::Next(bool UNUSED(skipped)) 175 { 176 // Make call OOS, so use while only for a SP map 177 //CMessageCinemaPathEnded msg(m_CinematicSimulationData.m_PathQueue.back().GetName(), skipped); 178 //g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msg); 179 180 m_CinematicSimulationData.m_PathQueue.pop_front(); 181 if (m_CinematicSimulationData.m_PathQueue.empty()) 182 { 183 SetEnabled(false); 184 m_CinematicSimulationData.m_Paused = true; 185 } 186 } 187 188 void CCinemaManager::Update(const float deltaRealTime) 189 { 190 if (g_Game->m_Paused != m_CinematicSimulationData.m_Paused) 191 { 192 m_CinematicSimulationData.m_Paused = g_Game->m_Paused; 193 194 // sn - session gui object 195 IGUIObject *sn = g_GUI->FindObjectByName("sn"); 196 197 // GUI visibility 198 if (sn) 199 { 200 if (m_CinematicSimulationData.m_Paused) 201 sn->SetSetting("hidden", L"false"); 202 else 203 sn->SetSetting("hidden", L"true"); 204 } 205 } 206 207 if (!m_CinematicSimulationData.m_Enabled || m_CinematicSimulationData.m_Paused) 208 return; 209 210 if (HotkeyIsPressed("leave")) 211 { 212 Skip(); 213 return; 214 } 215 216 ENSURE(m_CinematicSimulationData.m_PathQueue.size() > 0); 217 if (m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime)) 218 return; 219 220 Next(); 221 return; 222 } 223 224 void CCinemaManager::Render() 225 { 226 if (GetEnabled()) 227 { 228 DrawBars(); 229 return; 230 } 231 232 if (!m_DrawPaths) 233 return; 234 235 // draw all paths 236 for (auto it : m_CinematicSimulationData.m_Paths) 237 it.second.Draw(); 238 } 239 240 void CCinemaManager::DrawBars() const 241 { 242 int height = (float)g_xres / 2.39f; 243 int shift = (g_yres - height) / 2; 244 if (shift <= 0) 245 return; 246 247 #if CONFIG2_GLES 248 #warning TODO : implement bars for GLES 249 #else 250 // Set up transform for GL bars 251 glMatrixMode(GL_PROJECTION); 252 glPushMatrix(); 253 glLoadIdentity(); 254 glMatrixMode(GL_MODELVIEW); 255 glPushMatrix(); 256 glLoadIdentity(); 257 CMatrix3D transform; 258 transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f); 259 glLoadMatrixf(&transform._11); 260 261 glColor4f(0.0f, 0.0f, 0.0f, 1.0f); 262 263 glEnable(GL_BLEND); 264 glDisable(GL_DEPTH_TEST); 265 266 glBegin(GL_QUADS); 267 glVertex2i(0, 0); 268 glVertex2i(g_xres, 0); 269 glVertex2i(g_xres, shift); 270 glVertex2i(0, shift); 271 glEnd(); 272 273 glBegin(GL_QUADS); 274 glVertex2i(0, g_yres - shift); 275 glVertex2i(g_xres, g_yres - shift); 276 glVertex2i(g_xres, g_yres); 277 glVertex2i(0, g_yres); 278 glEnd(); 279 280 glDisable(GL_BLEND); 281 glEnable(GL_DEPTH_TEST); 282 283 // Restore transform 284 glMatrixMode(GL_PROJECTION); 285 glPopMatrix(); 286 glMatrixMode(GL_MODELVIEW); 287 glPopMatrix(); 288 #endif 289 } 290 291 InReaction cinema_manager_handler(const SDL_Event_* ev) 292 { 293 // put any events that must be processed even if inactive here 294 if (!g_Game || !g_Game->IsGameStarted()) 295 return IN_PASS; 296 297 CCinemaManager* pCinemaManager = g_Game->GetView()->GetCinema(); 298 299 return pCinemaManager->HandleEvent(ev); 300 } 301 302 InReaction CCinemaManager::HandleEvent(const SDL_Event_* ev) 303 { 304 switch (ev->ev.type) 305 { 306 case SDL_MOUSEBUTTONDOWN: 307 case SDL_MOUSEBUTTONUP: 308 if (GetEnabled() && !m_CinematicSimulationData.m_Paused) 309 return IN_HANDLED; 310 default: 311 return IN_PASS; 312 } 313 } 314 315 bool CCinemaManager::GetEnabled() const 316 { 317 return m_CinematicSimulationData.m_Enabled; 318 } 319 320 bool CCinemaManager::IsPlaying() const 321 { 322 return !m_CinematicSimulationData.m_Paused; 323 } 324 325 const std::map<CStrW, CCinemaPath>& CCinemaManager::GetAllPaths() 326 { 327 return m_CinematicSimulationData.m_Paths; 328 } 329 330 CinematicSimulationData* CCinemaManager::GetCinematicSimulationData() 331 { 332 return &m_CinematicSimulationData; 333 } 334 No newline at end of file -
source/graphics/CinemaManager.h
1 /* Copyright (C) 2015 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 19 #ifndef INCLUDED_CINEMAMANAGER 20 #define INCLUDED_CINEMAMANAGER 21 22 #include <list> 23 #include <map> 24 25 #include "lib/input.h" // InReaction - can't forward-declare enum 26 27 #include "graphics/CinemaPath.h" 28 #include "ps/CStr.h" 29 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 CinematicSimulationData() 47 : m_Enabled(false), m_Paused(true), m_MapRevealed(false) {} 48 }; 49 50 /** 51 * Class for in game playing of cinematics. Should only be instantiated in CGameView. 52 */ 53 54 class CCinemaManager 55 { 56 public: 57 CCinemaManager(); 58 ~CCinemaManager() {} 59 60 /** 61 * Adds the path to the path list 62 * @param name path name 63 * @param CCinemaPath path data 64 */ 65 void AddPath(const CStrW& name, CCinemaPath path); 66 67 /** 68 * Adds the path to the playlist 69 * @param name path name 70 */ 71 void AddPathToQueue(const CStrW& name); 72 73 /** 74 * Clears the playlist 75 */ 76 void ClearQueue(); 77 78 /** 79 * Checks the path name in the path list 80 * @param name path name 81 * @return true if path with that name exists, else false 82 */ 83 bool HasPath(const CStrW& name) const; 84 85 /** 86 * These stop track play, and accept time, not ratio of time 87 * @time point in the timeline 88 */ 89 void MoveToPointAt(float time); 90 91 // TODO: remove legacy methods after Atlas UI patch 92 const std::map<CStrW, CCinemaPath>& GetAllPaths(); 93 void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks); 94 void SetCurrentPath(const CStrW& name, bool current); 95 96 /** 97 * Starts play paths 98 */ 99 void Play(); 100 void Pause(); 101 void Next(bool skipped = false); 102 void Stop(); 103 void Skip(); 104 bool IsPlaying() const; 105 106 /** 107 * Renders black bars and paths (if enabled) 108 */ 109 void Render(); 110 void DrawBars() const; 111 112 /** 113 * Get current enable state of the cinema manager 114 */ 115 bool GetEnabled() const; 116 117 /** 118 * Sets enable state of the cinema manager (shows/hide gui, show/hide rings, etc) 119 * @enable new state 120 */ 121 void SetEnabled(bool enabled); 122 123 /** 124 * Updates CCinemManager and current path 125 * @param deltaRealTime Elapsed real time since the last frame. 126 */ 127 void Update(const float deltaRealTime); 128 129 InReaction HandleEvent(const SDL_Event_* ev); 130 131 CinematicSimulationData* GetCinematicSimulationData(); 132 133 private: 134 bool m_DrawPaths; 135 136 // Cinematic data is accessed from the simulation 137 CinematicSimulationData m_CinematicSimulationData; 138 }; 139 140 extern InReaction cinema_manager_handler(const SDL_Event_* ev); 141 142 #endif -
source/graphics/CinemaPath.cpp
1 /* Copyright (C) 2015 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 "CinemaPath.h" 21 22 #include <sstream> 23 #include <string> 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" 31 #include "lib/ogl.h" 32 #include "maths/MathUtil.h" 33 #include "maths/Quaternion.h" 34 #include "maths/Vector3D.h" 35 #include "maths/Vector4D.h" 36 #include "ps/CLogger.h" 37 #include "ps/CStr.h" 38 #include "ps/Game.h" 39 #include "renderer/Renderer.h" 40 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 { 44 BuildSpline(); 45 46 if (m_Orientation == L"target") 47 { 48 m_LookAtTarget = true; 49 ENSURE(m_TargetSpline.GetAllNodes().size() > 0); 50 } 51 52 // Set distortion mode and style 53 if (data.m_Mode == L"ease_in") 54 DistModePtr = &CCinemaPath::EaseIn; 55 else if (data.m_Mode == L"ease_out") 56 DistModePtr = &CCinemaPath::EaseOut; 57 else if (data.m_Mode == L"ease_inout") 58 DistModePtr = &CCinemaPath::EaseInOut; 59 else if (data.m_Mode == L"ease_outin") 60 DistModePtr = &CCinemaPath::EaseOutIn; 61 else 62 { 63 LOGWARNING("Cinematic mode not found for '%s'\n", data.m_Mode.ToUTF8().c_str()); 64 DistModePtr = &CCinemaPath::EaseInOut; 65 } 66 67 if (data.m_Style == L"default") 68 DistStylePtr = &CCinemaPath::EaseDefault; 69 else if (data.m_Style == L"growth") 70 DistStylePtr = &CCinemaPath::EaseGrowth; 71 else if (data.m_Style == L"expo") 72 DistStylePtr = &CCinemaPath::EaseExpo; 73 else if (data.m_Style == L"circle") 74 DistStylePtr = &CCinemaPath::EaseCircle; 75 else if (data.m_Style == L"sine") 76 DistStylePtr = &CCinemaPath::EaseSine; 77 else 78 { 79 LOGWARNING("Cinematic style not found for '%s'\n", data.m_Style.ToUTF8().c_str()); 80 DistStylePtr = &CCinemaPath::EaseDefault; 81 } 82 } 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)); 89 } 90 91 void CCinemaPath::DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const 92 { 93 if (spline.NodeCount < 2 || DistModePtr == NULL) 94 return; 95 if (spline.NodeCount == 2 && lines) 96 smoothness = 2; 97 98 float start = spline.MaxDistance / smoothness; 99 float time = 0; 100 101 #if CONFIG2_GLES 102 #warning TODO : do something about CCinemaPath on GLES 103 #else 104 105 glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); 106 if (lines) 107 { 108 glLineWidth(1.8f); 109 glEnable(GL_LINE_SMOOTH); 110 glBegin(GL_LINE_STRIP); 111 112 for (int i = 0; i <= smoothness; ++i) 113 { 114 // Find distorted time 115 time = start*i / spline.MaxDistance; 116 CVector3D tmp = spline.GetPosition(time); 117 glVertex3f(tmp.X, tmp.Y, tmp.Z); 118 } 119 glEnd(); 120 glDisable(GL_LINE_SMOOTH); 121 glLineWidth(1.0f); 122 } 123 else 124 { 125 smoothness /= 2; 126 start = spline.MaxDistance / smoothness; 127 glEnable(GL_POINT_SMOOTH); 128 glPointSize(3.0f); 129 glBegin(GL_POINTS); 130 131 for (int i = 0; i <= smoothness; ++i) 132 { 133 // Find distorted time 134 time = (this->*DistModePtr)(start*i / spline.MaxDistance); 135 CVector3D tmp = spline.GetPosition(time); 136 glVertex3f(tmp.X, tmp.Y, tmp.Z); 137 } 138 glColor3f(1.0f, 1.0f, 0.0f); // yellow 139 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 ); 146 147 glEnd(); 148 glPointSize(1.0f); 149 glDisable(GL_POINT_SMOOTH); 150 } 151 152 #endif 153 } 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 192 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation) 193 { 194 CCamera *camera = g_Game->GetView()->GetCamera(); 195 t = (this->*DistModePtr)(t); 196 CVector3D pos = GetPosition(t); 197 198 if (m_LookAtTarget) 199 { 200 if (m_TimeElapsed <= m_TargetSpline.MaxDistance) 201 camera->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance), 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(); 218 } 219 220 // Distortion mode functions 221 float CCinemaPath::EaseIn(float t) const 222 { 223 return (this->*DistStylePtr)(t); 224 } 225 226 float CCinemaPath::EaseOut(float t) const 227 { 228 return 1.0f - EaseIn(1.0f - t); 229 } 230 231 float CCinemaPath::EaseInOut(float t) const 232 { 233 if (t < 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; 236 } 237 238 float CCinemaPath::EaseOutIn(float t) const 239 { 240 if (t < 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; 243 } 244 245 // Distortion style functions 246 float CCinemaPath::EaseDefault(float t) const 247 { 248 return t; 249 } 250 251 float CCinemaPath::EaseGrowth(float t) const 252 { 253 return pow(t, m_Growth); 254 } 255 256 257 float CCinemaPath::EaseExpo(float t) const 258 { 259 if (t == 0) 260 return t; 261 return powf(m_Growth, 10 * (t - 1.0f)); 262 } 263 264 float CCinemaPath::EaseCircle(float t) const 265 { 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; 273 } 274 275 float CCinemaPath::EaseSine(float t) const 276 { 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; 284 } 285 286 bool CCinemaPath::Validate() 287 { 288 if (m_TimeElapsed > GetDuration() || 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) 296 { 297 cumulation += Node[i].Distance.ToFloat(); 298 if (m_TimeElapsed <= cumulation) 299 { 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 break; 304 } 305 previousTime += Node[i].Distance.ToFloat(); 306 } 307 return true; 308 } 309 310 bool CCinemaPath::Play(const float deltaRealTime) 311 { 312 m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime; 313 if (!Validate()) 314 { 315 m_TimeElapsed = 0.0f; 316 return false; 317 } 318 MoveToPointAt(m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation); 319 return true; 320 } -
source/graphics/CinemaPath.h
1 /* Copyright (C) 2015 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_CINEMAPATH 19 #define INCLUDED_CINEMAPATH 20 21 #include "maths/NUSpline.h" 22 #include "ps/CStr.h" 23 24 class CVector3D; 25 class CVector4D; 26 class CCamera; 27 28 // For loading data 29 class CCinemaData 30 { 31 public: 32 CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {} 33 virtual ~CCinemaData() {} 34 35 const CCinemaData* GetData() const { return this; } 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 mutable float m_GrowthCount; 48 float m_Growth; 49 float m_Switch; 50 }; 51 52 53 // 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 56 57 class CCinemaPath : private CCinemaData, public TNSpline 58 { 59 public: 60 CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {} 61 CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); 62 ~CCinemaPath() { DistStylePtr = NULL; DistModePtr = NULL; } 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 68 float EaseIn(float t) const; 69 float EaseOut(float t) const; 70 float EaseInOut(float t) const; 71 float EaseOutIn(float t) const; 72 73 // Distortion style functions 74 float EaseDefault(float t) const; 75 float EaseGrowth(float t) const; 76 float EaseExpo(float t) const; 77 float EaseCircle(float t) const; 78 float EaseSine(float t) const; 79 80 float (CCinemaPath::*DistStylePtr)(float ratio) const; 81 float (CCinemaPath::*DistModePtr)(float ratio) const; 82 83 const CCinemaData* GetData() const { return CCinemaData::GetData(); } 84 85 public: 86 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; 90 91 inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; } 92 inline fixed GetNodeDuration(const int index) const { return Node[index].Distance; } 93 inline float GetDuration() const { return MaxDistance; } 94 95 inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance.ToFloat(); } 96 inline float GetElapsedTime() const { return m_TimeElapsed; } 97 98 CStrW GetName() const { return m_Name; } 99 100 inline void SetTimescale(fixed scale) { m_Timescale = scale; } 101 102 float m_TimeElapsed; 103 float m_PreviousNodeTime; //How much time has passed before the current node 104 105 size_t m_CurrentNode; 106 CVector3D m_PreviousRotation; 107 108 public: 109 110 /** 111 * Returns false if finished. 112 * @param deltaRealTime Elapsed real time since the last frame. 113 */ 114 bool Play(const float deltaRealTime); 115 116 /** 117 * Validate the path 118 * @return true if the path is valid 119 */ 120 bool Validate(); 121 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; 134 }; 135 136 #endif // INCLUDED_CINEMAPATH -
source/graphics/CinemaTrack.cpp
1 /* Copyright (C) 2015 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 modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (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 of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 19 #include "precompiled.h"20 #include <string>21 #include <sstream>22 #include "lib/ogl.h"23 #include "CinemaTrack.h"24 #include "ps/Game.h"25 #include "GameView.h"26 #include "maths/MathUtil.h"27 #include "Camera.h"28 #include "ps/CStr.h"29 #include "maths/Vector3D.h"30 #include "maths/Vector4D.h"31 #include "maths/Quaternion.h"32 33 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline)34 : CCinemaData(data), TNSpline(spline), m_TimeElapsed(0.f)35 {36 m_TimeElapsed = 0;37 BuildSpline();38 39 //Set distortion mode and style40 switch(data.m_Mode)41 {42 case CCinemaPath::EM_IN:43 DistModePtr = &CCinemaPath::EaseIn;44 break;45 case CCinemaPath::EM_OUT:46 DistModePtr = &CCinemaPath::EaseOut;47 break;48 case CCinemaPath::EM_INOUT:49 DistModePtr = &CCinemaPath::EaseInOut;50 break;51 case CCinemaPath::EM_OUTIN:52 DistModePtr = &CCinemaPath::EaseOutIn;53 break;54 default:55 debug_printf("Cinematic mode not found for %d\n", data.m_Mode);56 break;57 }58 59 switch (data.m_Style)60 {61 case CCinemaPath::ES_DEFAULT:62 DistStylePtr = &CCinemaPath::EaseDefault;63 break;64 case CCinemaPath::ES_GROWTH:65 DistStylePtr = &CCinemaPath::EaseGrowth;66 break;67 case CCinemaPath::ES_EXPO:68 DistStylePtr = &CCinemaPath::EaseExpo;69 break;70 case CCinemaPath::ES_CIRCLE:71 DistStylePtr = &CCinemaPath::EaseCircle;72 break;73 case CCinemaPath::ES_SINE:74 DistStylePtr = &CCinemaPath::EaseSine;75 break;76 default:77 debug_printf("Cinematic mode not found for %d\n", data.m_Style);78 break;79 }80 //UpdateDuration();81 82 }83 84 void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const85 {86 if (NodeCount < 2 || DistModePtr == NULL)87 return;88 if ( NodeCount == 2 && lines )89 smoothness = 2;90 91 float start = MaxDistance / smoothness;92 float time=0;93 94 #if CONFIG2_GLES95 #warning TODO: do something about CCinemaPath on GLES96 #else97 98 glColor4f( RGBA.X, RGBA.Y, RGBA.Z, RGBA.W );99 if ( lines )100 {101 glLineWidth(1.8f);102 glEnable(GL_LINE_SMOOTH);103 glBegin(GL_LINE_STRIP);104 105 for (int i=0; i<=smoothness; ++i)106 {107 //Find distorted time108 time = start*i / MaxDistance;109 CVector3D tmp = GetPosition(time);110 glVertex3f( tmp.X, tmp.Y, tmp.Z );111 }112 glEnd();113 glDisable(GL_LINE_SMOOTH);114 glLineWidth(1.0f);115 }116 else117 {118 smoothness /= 2;119 start = MaxDistance / smoothness;120 glEnable(GL_POINT_SMOOTH);121 glPointSize(3.0f);122 glBegin(GL_POINTS);123 124 for (int i=0; i<=smoothness; ++i)125 {126 //Find distorted time127 time = (this->*DistModePtr)(start*i / MaxDistance);128 CVector3D tmp = GetPosition(time);129 glVertex3f( tmp.X, tmp.Y, tmp.Z );130 }131 glColor3f(1.0f, 1.0f, 0.0f); //yellow132 133 for ( size_t i=0; i<Node.size(); ++i )134 glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z);135 136 glEnd();137 glPointSize(1.0f);138 glDisable(GL_POINT_SMOOTH);139 }140 141 #endif142 }143 144 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)145 {146 CCamera *Cam = g_Game->GetView()->GetCamera();147 t = (this->*DistModePtr)(t);148 149 CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation;150 CQuaternion start, end;151 start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z));152 end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z));153 start.Slerp(start, end, nodet);154 CVector3D pos = GetPosition(t);155 CQuaternion quat;156 157 Cam->m_Orientation.SetIdentity();158 Cam->m_Orientation.Rotate(start);159 Cam->m_Orientation.Translate(pos);160 Cam->UpdateFrustum();161 }162 163 //Distortion mode functions164 float CCinemaPath::EaseIn(float t) const165 {166 return (this->*DistStylePtr)(t);167 }168 float CCinemaPath::EaseOut(float t) const169 {170 return 1.0f - EaseIn(1.0f-t);171 }172 float CCinemaPath::EaseInOut(float t) const173 {174 if (t < m_Switch)175 return EaseIn(1.0f/m_Switch * t) * m_Switch;176 return EaseOut(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;177 }178 float CCinemaPath::EaseOutIn(float t) const179 {180 if (t < m_Switch)181 return EaseOut(1.0f/m_Switch * t) * m_Switch;182 return EaseIn(1.0f/m_Switch * (t-m_Switch)) * m_Switch + m_Switch;183 }184 185 186 //Distortion style functions187 float CCinemaPath::EaseDefault(float t) const188 {189 return t;190 }191 float CCinemaPath::EaseGrowth(float t) const192 {193 return pow(t, m_Growth);194 }195 196 float CCinemaPath::EaseExpo(float t) const197 {198 if(t == 0)199 return t;200 return powf(m_Growth, 10*(t-1.0f));201 }202 float CCinemaPath::EaseCircle(float t) const203 {204 t = -(sqrt(1.0f - t*t) - 1.0f);205 if(m_GrowthCount > 1.0f)206 {207 m_GrowthCount--;208 return (this->*DistStylePtr)(t);209 }210 return t;211 }212 213 float CCinemaPath::EaseSine(float t) const214 {215 t = 1.0f - cos(t * (float)M_PI/2);216 if(m_GrowthCount > 1.0f)217 {218 m_GrowthCount--;219 return (this->*DistStylePtr)(t);220 }221 return t;222 }223 224 bool CCinemaPath::Validate()225 {226 if ( m_TimeElapsed <= GetDuration() && m_TimeElapsed >= 0.0f )227 {228 //Find current node and past "node time"229 float previousTime = 0.0f, cumulation = 0.0f;230 //Ignore the last node, since it is a blank (node time values are shifted down one from interface)231 for ( size_t i = 0; i < Node.size() - 1; ++i )232 {233 cumulation += Node[i].Distance;234 if ( m_TimeElapsed <= cumulation )235 {236 m_PreviousNodeTime = previousTime;237 m_PreviousRotation = Node[i].Rotation;238 m_CurrentNode = i; //We're moving toward this next node, so use its rotation239 return true;240 }241 else242 previousTime += Node[i].Distance;243 }244 }245 return false;246 }247 248 bool CCinemaPath::Play(const float deltaRealTime)249 {250 m_TimeElapsed += m_Timescale * deltaRealTime;251 252 if (!Validate())253 {254 m_TimeElapsed = 0.0f;255 return false;256 }257 258 MoveToPointAt( m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation );259 return true;260 }261 262 263 CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m_ValidCurrent(false)264 {265 m_CurrentPath = m_Paths.end();266 }267 268 void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name)269 {270 ENSURE( m_Paths.find( name ) == m_Paths.end() );271 m_Paths[name] = path;272 }273 274 void CCinemaManager::QueuePath(const CStrW& name, bool queue )275 {276 if (!m_PathQueue.empty() && queue == false)277 {278 return;279 }280 else281 {282 ENSURE(HasTrack(name));283 m_PathQueue.push_back(m_Paths[name]);284 }285 }286 287 void CCinemaManager::OverridePath(const CStrW& name)288 {289 m_PathQueue.clear();290 ENSURE(HasTrack(name));291 m_PathQueue.push_back( m_Paths[name] );292 }293 294 void CCinemaManager::SetAllPaths( const std::map<CStrW, CCinemaPath>& paths)295 {296 CStrW name;297 m_Paths = paths;298 }299 void CCinemaManager::SetCurrentPath(const CStrW& name, bool current, bool drawLines)300 {301 if ( !HasTrack(name) )302 m_ValidCurrent = false;303 else304 m_ValidCurrent = true;305 306 m_CurrentPath = m_Paths.find(name);307 m_DrawCurrentSpline = current;308 m_DrawLines = drawLines;309 DrawSpline();310 }311 312 bool CCinemaManager::HasTrack(const CStrW& name) const313 {314 return m_Paths.find(name) != m_Paths.end();315 }316 317 void CCinemaManager::DrawSpline() const318 {319 if ( !(m_DrawCurrentSpline && m_ValidCurrent) )320 return;321 static const int smoothness = 200;322 323 m_CurrentPath->second.DrawSpline(CVector4D(0.f, 0.f, 1.f, 1.f), smoothness, m_DrawLines);324 }325 326 void CCinemaManager::MoveToPointAt(float time)327 {328 ENSURE(m_CurrentPath != m_Paths.end());329 StopPlaying();330 331 m_CurrentPath->second.m_TimeElapsed = time;332 if ( !m_CurrentPath->second.Validate() )333 return;334 335 m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed /336 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(),337 m_CurrentPath->second.m_PreviousRotation );338 }339 340 bool CCinemaManager::Update(const float deltaRealTime)341 {342 if (!m_PathQueue.front().Play(deltaRealTime))343 {344 m_PathQueue.pop_front();345 return false;346 }347 return true;348 } -
source/graphics/CinemaTrack.h
1 /* Copyright (C) 2009 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 modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (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 of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 19 #ifndef INCLUDED_CINEMATRACK20 #define INCLUDED_CINEMATRACK21 22 #include <list>23 #include <map>24 #include "ps/CStr.h"25 #include "maths/NUSpline.h"26 27 /*28 desc: contains various functions used for cinematic camera paths29 See also: CinemaHandler.cpp, Cinematic.h/.cpp30 */31 32 class CVector3D;33 class CVector4D;34 class CCamera;35 36 //For loading data37 class CCinemaData38 {39 public:40 CCinemaData() : m_GrowthCount(0), m_Growth(0), m_Switch(0),41 m_Mode(0), m_Style(0), m_Timescale(1) {}42 virtual ~CCinemaData() {}43 44 const CCinemaData* GetData() const { return this; }45 46 //Distortion variables47 mutable float m_GrowthCount;48 float m_Growth;49 float m_Switch;50 int m_Mode;51 int m_Style;52 float m_Timescale; //a negative timescale results in backwards play53 54 };55 56 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 so60 61 class CCinemaPath : private CCinemaData, public TNSpline62 {63 public:64 CCinemaPath() { m_TimeElapsed = 0.0f; m_PreviousNodeTime = 0.0f; }65 CCinemaPath(const CCinemaData& data, const TNSpline& spline);66 ~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 spline72 void MoveToPointAt(float t, float nodet, const CVector3D& );73 74 //Distortion mode functions-change how ratio is passed to distortion style functions75 float EaseIn(float t) const;76 float EaseOut(float t) const;77 float EaseInOut(float t) const;78 float EaseOutIn(float t) const;79 80 //Distortion style functions81 float EaseDefault(float t) const;82 float EaseGrowth(float t) const;83 float EaseExpo(float t) const;84 float EaseCircle(float t) const;85 float EaseSine(float t) const;86 87 float (CCinemaPath::*DistStylePtr)(float ratio) const;88 float (CCinemaPath::*DistModePtr)(float ratio) const;89 90 const CCinemaData* GetData() const { return CCinemaData::GetData(); }91 92 public:93 94 void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const;95 96 inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; }97 inline float GetNodeDuration(const int index) const { return Node[index].Distance; }98 inline float GetDuration() const { return MaxDistance; }99 100 inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance; }101 inline float GetElapsedTime() const { return m_TimeElapsed; }102 103 inline void SetTimescale(float scale) { m_Timescale = scale; }104 105 float m_TimeElapsed;106 float m_PreviousNodeTime; //How much time has passed before the current node107 108 size_t m_CurrentNode;109 CVector3D m_PreviousRotation;110 111 public:112 113 /**114 * Returns false if finished.115 *116 * @param deltaRealTime Elapsed real time since the last frame.117 */118 bool Play(const float deltaRealTime);119 bool Validate();120 121 inline float GetTimescale() const { return m_Timescale; }122 };123 124 //Class for in game playing of cinematics. Should only be instantiated in CGameView.125 class CCinemaManager126 {127 public:128 CCinemaManager();129 ~CCinemaManager() {}130 131 void AddPath(CCinemaPath path, const CStrW& name);132 133 //Adds track to list of being played.134 void QueuePath(const CStrW& name, bool queue);135 void OverridePath(const CStrW& name); //clears track queue and replaces with 'name'136 137 /**138 * @param deltaRealTime Elapsed real time since the last frame.139 */140 bool Update(const float deltaRealTime);141 142 //These stop track play, and accept time, not ratio of time143 void MoveToPointAt(float time);144 145 inline void StopPlaying() { m_PathQueue.clear(); }146 void DrawSpline() const;147 148 inline bool IsPlaying() const { return !m_PathQueue.empty(); }149 bool HasTrack(const CStrW& name) const;150 inline bool IsActive() const { return m_Active; }151 inline void SetActive(bool active) { m_Active=active; }152 153 inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; }154 void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks);155 void SetCurrentPath(const CStrW& name, bool current, bool lines);156 157 private:158 159 bool m_Active, m_DrawCurrentSpline, m_DrawLines, m_ValidCurrent;160 std::map<CStrW, CCinemaPath>::iterator m_CurrentPath;161 std::map<CStrW, CCinemaPath> m_Paths;162 std::list<CCinemaPath> m_PathQueue;163 };164 165 #endif -
source/graphics/GameView.cpp
20 20 #include "GameView.h" 21 21 22 22 #include "graphics/Camera.h" 23 #include "graphics/Cinema Track.h"23 #include "graphics/CinemaManager.h" 24 24 #include "graphics/ColladaManager.h" 25 25 #include "graphics/HFTracer.h" 26 26 #include "graphics/LOSTexture.h" … … 258 258 */ 259 259 CLightEnv CachedLightEnv; 260 260 261 CCinemaManager TrackManager;261 CCinemaManager CinemaManager; 262 262 263 263 /** 264 264 * Entity for the camera to follow, or INVALID_ENTITY if none. … … 395 395 396 396 CCinemaManager* CGameView::GetCinema() 397 397 { 398 return &m-> TrackManager;398 return &m->CinemaManager; 399 399 }; 400 400 401 401 CLOSTexture& CGameView::GetLOSTexture() … … 626 626 if (!g_app_has_focus) 627 627 return; 628 628 629 if (m-> TrackManager.IsActive() && m->TrackManager.IsPlaying())629 if (m->CinemaManager.GetEnabled()) 630 630 { 631 if (! m->TrackManager.Update(deltaRealTime)) 632 { 633 // ResetCamera(); 634 } 631 m->CinemaManager.Update(deltaRealTime); 635 632 return; 636 633 } 637 634 -
source/graphics/MapReader.cpp
20 20 #include "MapReader.h" 21 21 22 22 #include "graphics/Camera.h" 23 #include "graphics/Cinema Track.h"23 #include "graphics/CinemaManager.h" 24 24 #include "graphics/Entity.h" 25 25 #include "graphics/GameView.h" 26 26 #include "graphics/MapGenerator.h" … … 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 871 if ( elementName == el_path ) 868 if (elementName == el_path) 872 869 { 870 CCinemaData pathData; 873 871 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; 872 CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8()); 873 pathData.m_Timescale = fixed::FromFloat(attrs.GetNamedItem(at_timescale).ToFloat()); 874 TNSpline pathSpline, targetSpline; 875 fixed lastTargetTime = fixed::Zero(); 876 877 pathData.m_Name = pathName; 878 pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8(); 879 pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8(); 880 pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8(); 879 881 880 882 XERO_ITER_EL(element, pathChild) 881 883 { 882 884 elementName = pathChild.GetNodeName(); 883 885 attrs = pathChild.GetAttributes(); 884 885 //Load distortion attributes886 if ( elementName == el_distortion )887 {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 886 894 // Load node data used for spline895 else if ( elementName == el_node)887 // Load node data used for spline 888 if (elementName == el_node) 896 889 { 890 bool positionDeclared = false; 897 891 SplineData data; 892 data.Distance = fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat()); 893 lastTargetTime += fixed::FromFloat(pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat()); 898 894 XERO_ITER_EL(pathChild, nodeChild) 899 895 { 900 896 elementName = nodeChild.GetNodeName(); 901 897 attrs = nodeChild.GetAttributes(); 902 903 //Fix?: assumes that time is last element 904 if ( elementName == el_position ) 898 if (elementName == el_position) 905 899 { 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;900 data.Position.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 901 data.Position.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 902 data.Position.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 903 positionDeclared = true; 910 904 } 911 else if ( elementName == el_rotation)905 else if (elementName == el_rotation) 912 906 { 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; 907 data.Rotation.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 908 data.Rotation.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 909 data.Rotation.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 917 910 } 918 else if ( elementName == el_time ) 919 data.Distance = nodeChild.GetText().ToFloat(); 911 else if (elementName == el_target) 912 { 913 CFixedVector3D targetPosition; 914 targetPosition.X = fixed::FromFloat(attrs.GetNamedItem(at_x).ToFloat()); 915 targetPosition.Y = fixed::FromFloat(attrs.GetNamedItem(at_y).ToFloat()); 916 targetPosition.Z = fixed::FromFloat(attrs.GetNamedItem(at_z).ToFloat()); 917 918 targetSpline.AddNode(targetPosition, CFixedVector3D(), lastTargetTime); 919 lastTargetTime = fixed::Zero(); 920 } 920 921 else 921 debug_warn(L"Invalid cinematic element for node child"); 922 923 backwardSpline.AddNode(data.Position, data.Rotation, data.Distance); 922 LOGWARNING("Invalid cinematic element for node child"); 924 923 } 924 925 // skip the node if no position 926 if (positionDeclared) 927 pathSpline.AddNode(data.Position, data.Rotation, data.Distance); 925 928 } 926 929 else 927 debug_warn(L"Invalid cinematic element for path child"); 928 929 930 LOGWARNING("Invalid cinematic element for path child"); 930 931 } 931 932 932 //Construct cinema path with data gathered 933 CCinemaPath temp(pathData, backwardSpline); 934 const std::vector<SplineData>& nodes = temp.GetAllNodes(); 935 if ( nodes.empty() ) 933 // Construct cinema path with data gathered 934 CCinemaPath path(pathData, pathSpline, targetSpline); 935 if (path.Empty()) 936 936 { 937 debug_warn(L"Failure loading cinematics");937 LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8()); 938 938 return; 939 939 } 940 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; 940 941 if (!m_MapReader.pCinema->HasPath(pathName)) 942 m_MapReader.pCinema->AddPath(pathName, path); 943 else 944 LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8()); 949 945 } 950 946 else 951 ENSURE("Invalid cinema child");947 LOGWARNING("Invalid path child with name '%s'", element.GetText()); 952 948 } 953 954 if (m_MapReader.pCinema)955 m_MapReader.pCinema->SetAllPaths(pathList);956 949 } 957 950 958 951 void CXMLReader::ReadTriggers(XMBElement UNUSED(parent)) … … 1125 1118 } 1126 1119 else if (name == "Paths") 1127 1120 { 1128 Read Cinema(node);1121 ReadPaths(node); 1129 1122 } 1130 1123 else if (name == "Triggers") 1131 1124 { -
source/graphics/MapReader.h
70 70 71 71 // UnpackTerrain: unpack the terrain from the input stream 72 72 int UnpackTerrain(); 73 // UnpackCinema: unpack the cinematic tracks from the input stream73 // UnpackCinema: unpack the cinematic tracks from the input stream 74 74 int UnpackCinema(); 75 75 76 76 // UnpackMap: unpack the given data from the raw data stream into local variables -
source/graphics/MapWriter.cpp
18 18 #include "precompiled.h" 19 19 20 20 #include "Camera.h" 21 #include "Cinema Track.h"21 #include "CinemaManager.h" 22 22 #include "GameView.h" 23 23 #include "LightEnv.h" 24 24 #include "MapReader.h" … … 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
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 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 … … 46 46 /*********************************** R N S **************************************************/ 47 47 48 48 // adds node and updates segment length 49 void RNSpline::AddNode(const C Vector3D &pos)49 void RNSpline::AddNode(const CFixedVector3D &pos) 50 50 { 51 if ( NodeCount >= MAX_SPLINE_NODES)52 53 54 55 56 57 Node[NodeCount-1].Distance = (Node[NodeCount-1].Position - pos).Length();58 MaxDistance += Node[NodeCount-1].Distance;59 60 61 62 63 51 if (NodeCount >= MAX_SPLINE_NODES) 52 return; 53 if (NodeCount == 0) 54 MaxDistance = 0.f; 55 else 56 { 57 Node[NodeCount - 1].Distance = (Node[NodeCount - 1].Position - pos).Length(); 58 MaxDistance += Node[NodeCount - 1].Distance.ToFloat(); 59 } 60 SplineData temp; 61 temp.Position = pos; 62 Node.push_back(temp); 63 NodeCount++; 64 64 } 65 65 66 66 … … 67 67 // called after all nodes added. This function calculates the node velocities 68 68 void RNSpline::BuildSpline() 69 69 { 70 if ( NodeCount == 2)71 72 73 Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);74 75 76 else if ( NodeCount < 2)77 78 79 for (int i = 1; i<NodeCount-1; i++)80 81 CVector3D Next = Node[i+1].Position - Node[i].Position;82 CVector3D Previous = Node[i-1].Position - Node[i].Position;83 Next.Normalize();84 Previous.Normalize();85 86 // split the angle (figure 4)87 88 89 90 91 92 Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);70 if (NodeCount == 2) 71 { 72 Node[0].Velocity = GetStartVelocity(0); 73 Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1); 74 return; 75 } 76 else if (NodeCount < 2) 77 return; 78 79 for (int i = 1; i < NodeCount - 1; ++i) 80 { 81 CVector3D Next = Node[i + 1].Position - Node[i].Position; 82 CVector3D Previous = Node[i - 1].Position - Node[i].Position; 83 Next.Normalize(); 84 Previous.Normalize(); 85 86 // split the angle (figure 4) 87 Node[i].Velocity = Next - Previous; 88 Node[i].Velocity.Normalize(); 89 } 90 // calculate start and end velocities 91 Node[0].Velocity = GetStartVelocity(0); 92 Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1); 93 93 } 94 94 95 95 // spline access function. time is 0 -> 1 96 96 CVector3D RNSpline::GetPosition(float time) const 97 97 { 98 if ( NodeCount < 2 ) 99 return CVector3D(0.0f, 0.0f, 0.0f); 100 if ( time > 1.0f ) 98 if (NodeCount < 2) 99 return CVector3D(0.0f, 0.0f, 0.0f); 100 if (time < 0.0f) 101 time = 0.0f; 102 if (time > 1.0f) 101 103 time = 1.0f; 102 float Distance = time * MaxDistance; 103 float CurrentDistance = 0.f; 104 int i = 0; 105 106 //Find which node we're on 107 while (CurrentDistance + Node[i].Distance < Distance 108 && i < NodeCount - 2) 109 { 110 CurrentDistance += Node[i].Distance; 111 i++; 112 } 113 ENSURE( i < NodeCount - 1 ); 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, 119 Node[i+1].Position, endVel, t); 104 float Distance = time * MaxDistance; 105 float CurrentDistance = 0.f; 106 int i = 0; 107 108 // Find which node we're on 109 while (CurrentDistance + Node[i].Distance.ToFloat() < Distance 110 && i < NodeCount - 2) 111 { 112 CurrentDistance += Node[i].Distance.ToFloat(); 113 ++i; 114 } 115 ENSURE(i < NodeCount - 1); 116 float t = Distance - CurrentDistance; 117 // TODO: reimplement CVector3D comparator (float comparing is bad without EPS) 118 if (Node[i].Position == Node[i + 1].Position || Node[i].Distance.ToFloat() < 1e-7) // distance too small or zero 119 { 120 return Node[i + 1].Position; 121 } 122 t /= Node[i].Distance.ToFloat(); // scale t in range 0 - 1 123 CVector3D startVel = Node[i].Velocity * Node[i].Distance.ToFloat(); 124 CVector3D endVel = Node[i + 1].Velocity * Node[i].Distance.ToFloat(); 125 return GetPositionOnCubic(Node[i].Position, startVel, 126 Node[i + 1].Position, endVel, t); 120 127 } 121 128 122 129 // internal. Based on Equation 14 123 130 CVector3D RNSpline::GetStartVelocity(int index) 124 131 { 125 if (index >= NodeCount - 1 || index < 0)126 127 CVector3D temp = (Node[index+1].Position - Node[index].Position) * 3.0f * ( 1.0f / Node[index].Distance);128 return (temp - Node[index+1].Velocity)*0.5f;132 if (index >= NodeCount - 1 || index < 0) 133 return CVector3D(0.0f, 0.0f, 0.0f); 134 CVector3D temp = CVector3D(Node[index + 1].Position - Node[index].Position) * 3.0f * (1.0f / Node[index].Distance.ToFloat()); 135 return (temp - Node[index + 1].Velocity)*0.5f; 129 136 } 130 137 131 138 // internal. Based on Equation 15 132 139 CVector3D RNSpline::GetEndVelocity(int index) 133 140 { 134 if (index >= NodeCount || index < 1)135 136 CVector3D temp = (Node[index].Position - Node[index-1].Position) * 3.0f * (1.0f / Node[index-1].Distance);137 return (temp - Node[index-1].Velocity) * 0.5f;141 if (index >= NodeCount || index < 1) 142 return CVector3D(0.0f, 0.0f, 0.0f); 143 CVector3D temp = CVector3D(Node[index].Position - Node[index - 1].Position) * 3.0f * (1.0f / Node[index - 1].Distance.ToFloat()); 144 return (temp - Node[index - 1].Velocity) * 0.5f; 138 145 } 139 146 140 147 /*********************************** S N S **************************************************/ … … 142 149 // smoothing filter. 143 150 void SNSpline::Smooth() 144 151 { 145 if ( NodeCount < 3)146 147 148 149 for (int i = 1; i<NodeCount-1; i++)150 151 152 newVel = GetEndVelocity(i) * Node[i].Distance+153 GetStartVelocity(i) * Node[i-1].Distance;154 newVel = newVel * ( 1 / (Node[i-1].Distance + Node[i].Distance));155 Node[i-1].Velocity = oldVel;156 157 158 Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);159 Node[NodeCount-2].Velocity = oldVel;152 if (NodeCount < 3) 153 return; 154 CVector3D newVel; 155 CVector3D oldVel = GetStartVelocity(0); 156 for (int i = 1; i < NodeCount - 1; ++i) 157 { 158 // Equation 12 159 newVel = GetEndVelocity(i) * Node[i].Distance.ToFloat() + 160 GetStartVelocity(i) * Node[i - 1].Distance.ToFloat(); 161 newVel = newVel * (1 / (Node[i - 1].Distance + Node[i].Distance).ToFloat()); 162 Node[i - 1].Velocity = oldVel; 163 oldVel = newVel; 164 } 165 Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1); 166 Node[NodeCount - 2].Velocity = oldVel; 160 167 } 161 168 162 169 /*********************************** T N S **************************************************/ … … 163 170 164 171 // as with RNSpline but use timePeriod in place of actual node spacing 165 172 // ie time period is time from last node to this node 166 void TNSpline::AddNode(const C Vector3D &pos, const CVector3D& rotation, floattimePeriod)173 void TNSpline::AddNode(const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod) 167 174 { 168 if ( NodeCount >= MAX_SPLINE_NODES)169 170 171 172 173 174 Node[NodeCount-1].Distance = timePeriod;175 MaxDistance += Node[NodeCount-1].Distance;176 175 if (NodeCount >= MAX_SPLINE_NODES) 176 return; 177 if (NodeCount == 0) 178 MaxDistance = 0.f; 179 else 180 { 181 Node[NodeCount - 1].Distance = timePeriod; 182 MaxDistance += Node[NodeCount - 1].Distance.ToFloat(); 183 } 177 184 178 179 185 SplineData temp; 186 temp.Position = pos; 180 187 181 182 temp.Distance = 0.0f;183 temp.Velocity = CVector3D( 0.0f, 0.0f, 0.0f);184 185 186 188 //make sure we don't end up using undefined numbers... 189 temp.Distance = fixed::FromFloat(0.0f); 190 temp.Velocity = CVector3D(0.0f, 0.0f, 0.0f); 191 temp.Rotation = rotation; 192 Node.push_back(temp); 193 NodeCount++; 187 194 } 188 195 189 196 //Inserts node before position 190 void TNSpline::InsertNode(const int index, const C Vector3D &pos, const CVector3D& rotation, floattimePeriod)197 void TNSpline::InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod) 191 198 { 192 if ( NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1)193 194 195 196 197 198 Node[NodeCount-1].Distance = timePeriod;199 Node[NodeCount-1].Rotation = rotation;200 MaxDistance += Node[NodeCount-1].Distance;201 202 203 204 205 199 if (NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1) 200 return; 201 if (NodeCount == 0) 202 MaxDistance = 0.f; 203 else 204 { 205 Node[NodeCount - 1].Distance = timePeriod; 206 Node[NodeCount - 1].Rotation = rotation; 207 MaxDistance += Node[NodeCount - 1].Distance.ToFloat(); 208 } 209 SplineData temp; 210 temp.Position = pos; 211 Node.insert(Node.begin() + index, temp); 212 NodeCount++; 206 213 } 207 214 //Removes node at index 208 215 void TNSpline::RemoveNode(const int index) 209 216 { 210 if (NodeCount == 0 || index > NodeCount - 1)211 212 213 214 215 216 MaxDistance -= Node[index].Distance;217 MaxDistance -= Node[index-1].Distance;218 Node[index-1].Distance = 0.0f;219 Node.erase( Node.begin() + index, Node.begin() + index + 1);220 221 217 if (NodeCount == 0 || index > NodeCount - 1) 218 { 219 return; 220 } 221 else 222 { 223 MaxDistance -= Node[index].Distance.ToFloat(); 224 MaxDistance -= Node[index - 1].Distance.ToFloat(); 225 Node[index - 1].Distance = fixed::FromFloat(0.0f); 226 Node.erase(Node.begin() + index, Node.begin() + index + 1); 227 } 228 NodeCount--; 222 229 } 223 void TNSpline::UpdateNodeTime(const int index, f loattime)230 void TNSpline::UpdateNodeTime(const int index, fixed time) 224 231 { 225 232 if (NodeCount == 0 || index > NodeCount - 1 ) 226 233 { … … 228 235 } 229 236 Node[index].Distance = time; 230 237 } 231 void TNSpline::UpdateNodePos(const int index, const C Vector3D &pos)238 void TNSpline::UpdateNodePos(const int index, const CFixedVector3D &pos) 232 239 { 233 240 if (NodeCount == 0 || index > NodeCount - 1 ) 234 241 { … … 238 245 } 239 246 void TNSpline::Constrain() 240 247 { 241 if ( NodeCount < 3)242 243 for (int i = 1; i<NodeCount-1; i++)244 245 246 float r0 = (Node[i].Position-Node[i-1].Position).Length() / Node[i-1].Distance;247 float r1 = (Node[i+1].Position - Node[i].Position).Length() / Node[i].Distance;248 Node[i].Velocity *= 4.0f*r0*r1/((r0+r1)*(r0+r1));249 248 if (NodeCount < 3) 249 return; 250 for (int i = 1; i < NodeCount - 1; ++i) 251 { 252 // Equation 13 253 float r0 = (Node[i].Position - Node[i - 1].Position).Length().ToFloat() / Node[i - 1].Distance.ToFloat(); 254 float r1 = (Node[i + 1].Position - Node[i].Position).Length().ToFloat() / Node[i].Distance.ToFloat(); 255 Node[i].Velocity *= 4.0f*r0*r1 / ((r0 + r1)*(r0 + r1)); 256 } 250 257 } 251 258 -
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 32 // TODO: make template (ie, for non-fixed data) 29 33 struct SplineData 30 34 { 31 CVector3D Position; 35 // Should be fixed, because used in the simulation 36 CFixedVector3D Position; 32 37 CVector3D Velocity; 33 CVector3D Rotation; 34 float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is 38 // TODO: make rotation as other spline 39 CFixedVector3D Rotation; 40 fixed Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is 35 41 }; 36 42 37 43 class RNSpline 38 44 { 39 45 public: 40 46 41 47 RNSpline() { NodeCount = 0; } 42 48 virtual ~RNSpline() {} 43 44 void AddNode(const CVector3D &pos);45 void BuildSpline();46 CVector3D GetPosition(float time) const;47 CVector3D GetRotation(float time) const;48 const std::vector<SplineData>& GetAllNodes() const { return Node; }49 50 float MaxDistance;51 int NodeCount;52 49 50 void AddNode(const CFixedVector3D &pos); 51 void BuildSpline(); 52 CVector3D GetPosition(float time) const; 53 CVector3D GetRotation(float time) const; 54 const std::vector<SplineData>& GetAllNodes() const { return Node; } 55 56 float MaxDistance; 57 int NodeCount; 58 53 59 protected: 54 55 56 60 std::vector<SplineData> Node; 61 CVector3D GetStartVelocity(int index); 62 CVector3D GetEndVelocity(int index); 57 63 }; 58 64 59 65 class SNSpline : public RNSpline … … 60 66 { 61 67 public: 62 68 virtual ~SNSpline() {} 63 64 69 void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); } 70 void Smooth(); 65 71 }; 66 72 67 73 class TNSpline : public SNSpline … … 69 75 public: 70 76 virtual ~TNSpline() {} 71 77 72 void AddNode(const CVector3D& pos, const CVector3D& rotation, floattimePeriod);73 void PushNode() { Node.push_back( SplineData()); }74 void InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, floattimePeriod);75 76 void UpdateNodeTime(const int index, floattime);77 void UpdateNodePos(const int index, const CVector3D &pos);78 79 80 void Smooth(){ for( int x=0; x<3; x++ ) { SNSpline::Smooth(); Constrain(); }}81 void Constrain(); 78 void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod); 79 void PushNode() { Node.push_back(SplineData()); } 80 void InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D& rotation, fixed timePeriod); 81 void RemoveNode(const int index); 82 void UpdateNodeTime(const int index, fixed time); 83 void UpdateNodePos(const int index, const CFixedVector3D &pos); 84 85 void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); } 86 void Smooth(){ for (int x = 0; x < 3; x++) { SNSpline::Smooth(); Constrain(); } } 87 void Constrain(); 82 88 }; 83 89 84 90 #endif // INCLUDED_NUSPLINE -
source/ps/GameSetup/GameSetup.cpp
35 35 #include "lib/sysdep/os/win/wversion.h" 36 36 #endif 37 37 38 #include "graphics/Cinema Track.h"38 #include "graphics/CinemaManager.h" 39 39 #include "graphics/FontMetrics.h" 40 40 #include "graphics/GameView.h" 41 41 #include "graphics/LightEnv.h" … … 226 226 227 227 ogl_WarnIfError(); 228 228 229 if (g_Game && g_Game->IsGameStarted()) 230 g_Game->GetView()->GetCinema()->Render(); 231 232 ogl_WarnIfError(); 233 229 234 g_Renderer.RenderTextOverlays(); 230 235 231 236 if (g_DoRenderGui) … … 573 578 574 579 in_add_handler(touch_input_handler); 575 580 581 in_add_handler(cinema_manager_handler); 582 576 583 // must be registered after (called before) the GUI which relies on these globals 577 584 in_add_handler(GlobalsInputHandler); 578 585 } -
source/ps/Globals.cpp
20 20 21 21 #include "lib/external_libraries/libsdl.h" 22 22 #include "network/NetClient.h" 23 24 #include "graphics/CinemaManager.h" 25 #include "graphics/GameView.h" 26 #include "ps/Game.h" 23 27 #include "ps/GameSetup/Config.h" 24 28 #include "soundmanager/ISoundManager.h" 25 29 -
source/simulation2/components/CCmpCinemaManager.cpp
1 /* Copyright (C) 2015 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 29 30 class CCmpCinemaManager : public ICmpCinemaManager 31 { 32 public: 33 static void ClassInit(CComponentManager& componentManager) 34 { 35 componentManager.SubscribeToMessageType(MT_CinemaPathEnded); 36 } 37 38 DEFAULT_COMPONENT_ALLOCATOR(CinemaManager) 39 40 static std::string GetSchema() 41 { 42 return "<a:component type='system'/>" 43 "<empty/>" 44 ; 45 } 46 47 virtual void Init(const CParamNode& UNUSED(paramNode)) 48 { 49 // ... 50 } 51 52 virtual void Deinit() 53 { 54 // ... 55 } 56 57 virtual void Serialize(ISerializer& serialize) 58 { 59 if (!g_Game || !g_Game->GetView()) 60 { 61 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 62 return; 63 } 64 CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 65 serialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); 66 // Don't sync while 67 //serialize.Bool("Enabled", p_CinematicSimulationData->m_Enabled); 68 //serialize.Bool("Paused", p_CinematicSimulationData->m_Paused); 69 serialize.NumberU32_Unbounded("NumberOfPaths", p_CinematicSimulationData->m_Paths.size()); 70 for (auto it : p_CinematicSimulationData->m_Paths) 71 { 72 CCinemaPath& path = it.second; 73 const CCinemaData* data = path.GetData(); 74 75 // TODO: maybe implement String_Unbounded 76 serialize.String("PathName", data->m_Name, 1, 2048); 77 serialize.String("PathOrientation", data->m_Orientation, 1, 2048); 78 serialize.String("PathMode", data->m_Mode, 1, 2048); 79 serialize.String("PathStyle", data->m_Style, 1, 2048); 80 serialize.NumberFixed_Unbounded("PathTimescale", data->m_Timescale); 81 serialize.Bool("LookAtTarget", data->m_LookAtTarget); 82 83 serialize.NumberU32("NumberOfNodes", path.GetAllNodes().size(), 1, MAX_SPLINE_NODES); 84 const std::vector<SplineData>& nodes = path.GetAllNodes(); 85 for (size_t i = 0; i < nodes.size(); ++i) 86 { 87 if (i > 0) 88 serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance); 89 else 90 serialize.NumberFixed_Unbounded("NodeDeltaTime", fixed::Zero()); 91 serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X); 92 serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y); 93 serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z); 94 95 serialize.NumberFixed_Unbounded("RotationX", nodes[i].Rotation.X); 96 serialize.NumberFixed_Unbounded("RotationY", nodes[i].Rotation.Y); 97 serialize.NumberFixed_Unbounded("RotationZ", nodes[i].Rotation.Z); 98 } 99 100 if (!data->m_LookAtTarget) 101 continue; 102 103 const std::vector<SplineData>& targetNodes = path.getTargetSpline()->GetAllNodes(); 104 serialize.NumberU32("NumberOfTargetNodes", targetNodes.size(), 1, MAX_SPLINE_NODES); 105 for (size_t i = 0; i < targetNodes.size(); ++i) 106 { 107 if (i > 0) 108 serialize.NumberFixed_Unbounded("NodeDeltaTime", nodes[i - 1].Distance); 109 else 110 serialize.NumberFloat_Unbounded("NodeDeltaTime", 0); 111 serialize.NumberFixed_Unbounded("PositionX", nodes[i].Position.X); 112 serialize.NumberFixed_Unbounded("PositionY", nodes[i].Position.Y); 113 serialize.NumberFixed_Unbounded("PositionZ", nodes[i].Position.Z); 114 } 115 } 116 } 117 118 virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize) 119 { 120 if (!g_Game || !g_Game->GetView()) 121 { 122 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 123 return; 124 } 125 CinematicSimulationData* p_CinematicSimulationData = g_Game->GetView()->GetCinema()->GetCinematicSimulationData(); 126 deserialize.Bool("MapRevealed", p_CinematicSimulationData->m_MapRevealed); 127 // Don't sync while 128 //deserialize.Bool("Enabled", p_CinematicSimulationData->m_Enabled); 129 //deserialize.Bool("Paused", p_CinematicSimulationData->m_Paused); 130 uint32_t numberOfPaths = 0; 131 deserialize.NumberU32_Unbounded("NumberOfPaths", numberOfPaths); 132 for (uint32_t i = 0; i < numberOfPaths; ++i) 133 { 134 CCinemaData data; 135 136 deserialize.String("PathName", data.m_Name, 1, 2048); 137 deserialize.String("PathOrientation", data.m_Orientation, 1, 2048); 138 deserialize.String("PathMode", data.m_Mode, 1, 2048); 139 deserialize.String("PathStyle", data.m_Style, 1, 2048); 140 deserialize.NumberFixed_Unbounded("PathTimescale", data.m_Timescale); 141 deserialize.Bool("LookAtTarget", data.m_LookAtTarget); 142 143 TNSpline pathSpline, targetSpline; 144 uint32_t numberOfNodes = 0; 145 deserialize.NumberU32("NumberOfNodes", numberOfNodes, 1, MAX_SPLINE_NODES); 146 for (uint32_t j = 0; j < numberOfNodes; ++j) 147 { 148 SplineData node; 149 deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance); 150 151 deserialize.NumberFixed_Unbounded("PositionX", node.Position.X); 152 deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y); 153 deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z); 154 155 deserialize.NumberFixed_Unbounded("RotationX", node.Rotation.X); 156 deserialize.NumberFixed_Unbounded("RotationY", node.Rotation.Y); 157 deserialize.NumberFixed_Unbounded("RotationZ", node.Rotation.Z); 158 159 pathSpline.AddNode(node.Position, node.Rotation, node.Distance); 160 } 161 162 if (data.m_LookAtTarget) 163 { 164 uint32_t numberOfTargetNodes = 0; 165 deserialize.NumberU32("NumberOfTargetNodes", numberOfTargetNodes, 1, MAX_SPLINE_NODES); 166 for (uint32_t j = 0; j < numberOfTargetNodes; ++j) 167 { 168 SplineData node; 169 deserialize.NumberFixed_Unbounded("NodeDeltaTime", node.Distance); 170 171 deserialize.NumberFixed_Unbounded("PositionX", node.Position.X); 172 deserialize.NumberFixed_Unbounded("PositionY", node.Position.Y); 173 deserialize.NumberFixed_Unbounded("PositionZ", node.Position.Z); 174 175 targetSpline.AddNode(node.Position, CFixedVector3D(), node.Distance); 176 } 177 } 178 179 // Construct cinema path with data gathered 180 CCinemaPath path(data, pathSpline, targetSpline); 181 p_CinematicSimulationData->m_Paths[data.m_Name] = path; 182 } 183 g_Game->GetView()->GetCinema()->SetEnabled(p_CinematicSimulationData->m_Enabled); 184 } 185 186 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) 187 { 188 switch (msg.GetType()) 189 { 190 case MT_CinemaPathEnded: 191 { 192 // const CMessageCinemaPathEnded& msgData = static_cast<const CMessageCinemaPathEnded&> (msg); 193 // TODO: send more msg to trigger 194 break; 195 } 196 } 197 } 198 199 virtual void AddCinemaPathToQueue(CStrW name) 200 { 201 if (!g_Game || !g_Game->GetView()) 202 { 203 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 204 return; 205 } 206 g_Game->GetView()->GetCinema()->AddPathToQueue(name); 207 } 208 209 virtual void Play() 210 { 211 if (!g_Game || !g_Game->GetView()) 212 { 213 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 214 return; 215 } 216 g_Game->GetView()->GetCinema()->Play(); 217 } 218 219 virtual void Pause() 220 { 221 if (!g_Game || !g_Game->GetView()) 222 { 223 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 224 return; 225 } 226 g_Game->GetView()->GetCinema()->Pause(); 227 } 228 229 virtual void Stop() 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()->Stop(); 237 } 238 239 }; 240 241 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
124 124 m_TriggerEvent = true; 125 125 m_EnableLineDebugOverlays = false; 126 126 m_DirtyID = 1; 127 m_Visible = true; 127 128 128 129 m_AnimTime = 0.0; 129 130 … … 276 277 void Interpolate(float frameTime, float frameOffset); 277 278 278 279 void RenderSubmit(SceneCollector& collector); 280 281 void SetVisibility(bool visible) 282 { 283 m_Visible = visible; 284 } 285 286 private: 287 288 bool m_Visible; 279 289 }; 280 290 281 291 REGISTER_COMPONENT_TYPE(TerritoryManager) … … 645 655 646 656 void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector) 647 657 { 658 if (!m_Visible) 659 return; 660 648 661 for (size_t i = 0; i < m_BoundaryLines.size(); ++i) 649 662 collector.Submit(&m_BoundaryLines[i].overlay); 650 663 -
source/simulation2/components/ICmpCinemaManager.cpp
1 /* Copyright (C) 2015 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) 2015 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 * Send when an path has ended 545 */ 546 547 class CMessageCinemaPathEnded : public CMessage 548 { 549 public: 550 DEFAULT_MESSAGE_IMPL(CinemaPathEnded) 551 552 CMessageCinemaPathEnded(CStrW name, bool skipped) : 553 name(name), skipped(skipped) 554 { 555 } 556 557 CStrW name; 558 bool skipped; 559 }; 560 541 561 #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 SET_MSG_PROPERTY(skipped); 480 return JS::ObjectValue(*obj); 481 } 482 483 CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) 484 { 485 FROMJSVAL_SETUP(); 486 GET_MSG_PROPERTY(CStrW, name); 487 GET_MSG_PROPERTY(bool, skipped); 488 return new CMessageCinemaPathEnded(name, skipped); 489 } 490 473 491 //////////////////////////////////////////////////////////////// 474 492 475 493 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) 60 61 61 62 // TemplateManager must come before all other (non-test) components, 62 63 // so that it is the first to be (de)serialized … … 75 76 INTERFACE(AIManager) 76 77 COMPONENT(AIManager) 77 78 79 INTERFACE(CinemaManager) 80 COMPONENT(CinemaManager) 81 78 82 INTERFACE(CommandQueue) 79 83 COMPONENT(CommandQueue) 80 84 -
source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp
27 27 #include "ps/Game.h" 28 28 #include "renderer/Renderer.h" 29 29 #include "graphics/GameView.h" 30 #include "graphics/Cinema Track.h"30 #include "graphics/CinemaManager.h" 31 31 32 32 #include "ps/World.h" 33 33 #include "graphics/Terrain.h" -
source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp
20 20 #include "MessageHandler.h" 21 21 #include "../CommandProc.h" 22 22 #include "graphics/Camera.h" 23 #include "graphics/Cinema Track.h"23 #include "graphics/CinemaManager.h" 24 24 #include "graphics/GameView.h" 25 25 #include "ps/Game.h" 26 26 #include "ps/CStr.h" … … 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); 158 if (msg->mode == eCinemaEventMode::SMOOTH) 159 { 160 manager->ClearQueue(); 161 manager->AddPathToQueue(*msg->path); 162 } 160 163 else if ( msg->mode == eCinemaEventMode::IMMEDIATE_PATH ) 161 164 manager->MoveToPointAt(msg->t); 162 165 else if ( msg->mode == eCinemaEventMode::RESET ) … … 164 167 // g_Game->GetView()->ResetCamera(); 165 168 } 166 169 else if ( msg->mode == eCinemaEventMode::SELECT ) 167 manager->SetCurrentPath(*msg->path, msg->drawCurrent , msg->lines);170 manager->SetCurrentPath(*msg->path, msg->drawCurrent); 168 171 else 169 172 ENSURE(false); 170 173 } -
source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp
22 22 23 23 #include "../GameLoop.h" 24 24 #include "../View.h" 25 #include "graphics/Cinema Track.h"25 #include "graphics/CinemaManager.h" 26 26 #include "graphics/GameView.h" 27 27 #include "gui/GUIManager.h" 28 28 #include "gui/GUI.h" … … 57 57 QUERYHANDLER(CinemaRecord) 58 58 { 59 59 CCinemaManager* manager = g_Game->GetView()->GetCinema(); 60 manager->SetCurrentPath(*msg->path, false , false);60 manager->SetCurrentPath(*msg->path, false); 61 61 62 62 const int w = msg->width, h = msg->height; 63 63 -
source/tools/atlas/GameInterface/Handlers/TriggerHandler.cpp
23 23 24 24 #include "ps/Game.h" 25 25 #include "graphics/GameView.h" 26 #include "graphics/Cinema Track.h"26 #include "graphics/CinemaManager.h" 27 27 #include "simulation2/Simulation2.h" 28 28 29 29 namespace AtlasMessage { -
source/tools/atlas/GameInterface/View.cpp
24 24 #include "Messages.h" 25 25 #include "SimState.h" 26 26 27 #include "graphics/Cinema Track.h"27 #include "graphics/CinemaManager.h" 28 28 #include "graphics/GameView.h" 29 29 #include "graphics/ParticleManager.h" 30 30 #include "graphics/SColor.h"