Ticket #3301: cinematic_camera_core_v0.6.patch
File cinematic_camera_core_v0.6.patch, 80.3 KB (added by , 8 years ago) |
---|
-
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_Active(false), m_Paused(true), m_DrawPaths(true) 50 { 51 } 52 53 void CCinemaManager::AddPath(const CStrW& name, CCinemaPath path) 54 { 55 ENSURE(m_Paths.find(name) == m_Paths.end()); 56 m_Paths[name] = path; 57 } 58 59 void CCinemaManager::AddPathToQueue(const CStrW& name) 60 { 61 ENSURE(HasPath(name)); 62 m_PathQueue.push_back(m_Paths[name]); 63 } 64 65 void CCinemaManager::ClearQueue() 66 { 67 m_PathQueue.clear(); 68 } 69 70 void CCinemaManager::SetAllPaths(const std::map<CStrW, CCinemaPath>& paths) 71 { 72 m_Paths = paths; 73 } 74 75 void CCinemaManager::SetCurrentPath(const CStrW& name, bool current) 76 { 77 // ... 78 } 79 80 bool CCinemaManager::HasPath(const CStrW& name) const 81 { 82 return m_Paths.find(name) != m_Paths.end(); 83 } 84 85 void CCinemaManager::SetActive(bool active) 86 { 87 if (m_Active == active) 88 return; 89 90 IGUIObject *sn = g_GUI->FindObjectByName("sn"); 91 CmpPtr <ICmpRangeManager> cmpRangeManager(*(g_Game->GetSimulation2()), SYSTEM_ENTITY); 92 CmpPtr <ICmpTerritoryManager> cmpTerritoryManager(*(g_Game->GetSimulation2()), SYSTEM_ENTITY); 93 94 // GUI visibility 95 if (sn) 96 { 97 if (active) 98 sn->SetSetting("hidden", L"true"); 99 else 100 sn->SetSetting("hidden", L"false"); 101 } 102 103 // Overlay visibility 104 g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !active); 105 if (cmpRangeManager) 106 { 107 if (active) 108 m_MapRevealed = cmpRangeManager->GetLosRevealAll(-1); 109 // TODO: improve m_MapRevealed state and without fade in 110 cmpRangeManager->SetLosRevealAll(-1, active); 111 } 112 if (cmpTerritoryManager) 113 cmpTerritoryManager->SetVisibility(!active); 114 ICmpSelectable::SetOverrideVisibility(!active); 115 ICmpOverlayRenderer::SetOverrideVisibility(!active); 116 117 m_Active = active; 118 } 119 120 void CCinemaManager::MoveToPointAt(float time) 121 { 122 // TODO: Update after Atlas UI patch 123 /*ENSURE(m_CurrentPath != m_Paths.end()); 124 ClearQueue(); 125 126 m_CurrentPath->second.m_TimeElapsed = time; 127 if (!m_CurrentPath->second.Validate()) 128 return; 129 130 m_CurrentPath->second.MoveToPointAt(m_CurrentPath->second.m_TimeElapsed / 131 m_CurrentPath->second.GetDuration(), m_CurrentPath->second.GetNodeFraction(), 132 m_CurrentPath->second.m_PreviousRotation );*/ 133 } 134 135 void CCinemaManager::Play() 136 { 137 SetActive(true); 138 m_Paused = false; 139 } 140 141 void CCinemaManager::Pause() 142 { 143 m_Paused = true; 144 } 145 146 void CCinemaManager::Stop() 147 { 148 m_Paused = true; 149 } 150 151 void CCinemaManager::Skip() 152 { 153 m_PathQueue.clear(); 154 SetActive(false); 155 m_Paused = true; 156 } 157 158 void CCinemaManager::Next() 159 { 160 CMessageCinemaPathEnded msg(m_PathQueue.back().GetName()); 161 g_Game->GetSimulation2()->PostMessage(SYSTEM_ENTITY, msg); 162 163 m_PathQueue.pop_front(); 164 if (m_PathQueue.empty()) 165 { 166 SetActive(false); 167 m_Paused = true; 168 } 169 } 170 171 void CCinemaManager::Update(const float deltaRealTime) 172 { 173 if (!m_Active || m_Paused) 174 return; 175 176 if (HotkeyIsPressed("leave")) 177 { 178 Skip(); 179 return; 180 } 181 182 if (m_PathQueue.front().Play(deltaRealTime)) 183 return; 184 185 Next(); 186 return; 187 } 188 189 void CCinemaManager::Render() 190 { 191 if (IsActive()) 192 { 193 DrawBars(); 194 return; 195 } 196 197 if (!m_DrawPaths) 198 return; 199 200 for (auto it : m_Paths) 201 { 202 it.second.DrawSpline(CVector4D(0.2f, 0.2f, 1.f, 0.5f), 100, true); 203 it.second.DrawNodes(CVector4D(0.5f, 1.0f, 0.f, 0.5f)); 204 } 205 } 206 207 void CCinemaManager::DrawBars() const 208 { 209 int height = (float)g_xres / 2.39f; 210 int shift = (g_yres - height) / 2; 211 if (shift <= 0) 212 return; 213 214 #if CONFIG2_GLES 215 #warning TODO : implement bars for GLES 216 #else 217 // Set up transform for GL bars 218 glMatrixMode(GL_PROJECTION); 219 glPushMatrix(); 220 glLoadIdentity(); 221 glMatrixMode(GL_MODELVIEW); 222 glPushMatrix(); 223 glLoadIdentity(); 224 CMatrix3D transform; 225 transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f); 226 glLoadMatrixf(&transform._11); 227 228 glColor4f(0.0f, 0.0f, 0.0f, 1.0f); 229 230 glEnable(GL_BLEND); 231 glDisable(GL_DEPTH_TEST); 232 233 glBegin(GL_QUADS); 234 glVertex2i(0, 0); 235 glVertex2i(g_xres, 0); 236 glVertex2i(g_xres, shift); 237 glVertex2i(0, shift); 238 glEnd(); 239 240 glBegin(GL_QUADS); 241 glVertex2i(0, g_yres - shift); 242 glVertex2i(g_xres, g_yres - shift); 243 glVertex2i(g_xres, g_yres); 244 glVertex2i(0, g_yres); 245 glEnd(); 246 247 glDisable(GL_BLEND); 248 glEnable(GL_DEPTH_TEST); 249 250 // Restore transform 251 glMatrixMode(GL_PROJECTION); 252 glPopMatrix(); 253 glMatrixMode(GL_MODELVIEW); 254 glPopMatrix(); 255 #endif 256 } -
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 #include "graphics/CinemaPath.h" 25 #include "ps/CStr.h" 26 27 /* 28 desc: contains various functions used for cinematic camera paths 29 See also: CinemaHandler.cpp, CinemaPath.cpp 30 */ 31 32 /** 33 * Class for in game playing of cinematics. Should only be instantiated in CGameView. 34 */ 35 36 class CCinemaManager 37 { 38 public: 39 CCinemaManager(); 40 ~CCinemaManager() {} 41 42 /** 43 * Adds the path to the path list 44 * @param name path name 45 * @param CCinemaPath path data 46 */ 47 void AddPath(const CStrW& name, CCinemaPath path); 48 49 /** 50 * Adds the path to the playlist 51 * @param name path name 52 */ 53 void AddPathToQueue(const CStrW& name); 54 55 /** 56 * Clears the playlist 57 */ 58 void ClearQueue(); 59 60 /** 61 * Checks the path name in the path list 62 * @param name path name 63 * @return true if path with that name exists, else false 64 */ 65 bool HasPath(const CStrW& name) const; 66 67 /** 68 * These stop track play, and accept time, not ratio of time 69 * @time point in the timeline 70 */ 71 void MoveToPointAt(float time); 72 73 // TODO: remove legacy methods after Atlas UI patch 74 inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; } 75 void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks); 76 void SetCurrentPath(const CStrW& name, bool current); 77 78 /** 79 * Starts play paths 80 */ 81 void Play(); 82 void Pause(); 83 void Next(); 84 void Stop(); 85 void Skip(); 86 inline bool IsPlaying() const { return !m_Paused; } 87 88 /** 89 * Renders black bars and paths (if enabled) 90 */ 91 void Render(); 92 void DrawBars() const; 93 94 /** 95 * Sets active state of the cinema manager (shows/hide gui, show/hide rings, etc) 96 * @active new active state 97 */ 98 void SetActive(bool active); 99 inline bool IsActive() const { return m_Active; } 100 101 /** 102 * Updates CCinemManager and current path 103 * @param deltaRealTime Elapsed real time since the last frame. 104 */ 105 void Update(const float deltaRealTime); 106 107 private: 108 bool m_Active, m_Paused, m_DrawPaths; 109 110 std::map<CStrW, CCinemaPath> m_Paths; 111 std::list<CCinemaPath> m_PathQueue; 112 113 // States before playing 114 bool m_MapRevealed; 115 }; 116 117 #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 "Camera.h" 23 #include "CinemaManager.h" 24 #include "GameView.h" 25 #include "gui/CGUI.h" 26 #include "gui/GUIManager.h" 27 #include "gui/IGUIObject.h" 28 #include "lib/ogl.h" 29 #include "maths/MathUtil.h" 30 #include "maths/Quaternion.h" 31 #include "maths/Vector3D.h" 32 #include "maths/Vector4D.h" 33 #include "ps/CLogger.h" 34 #include "ps/CStr.h" 35 #include "ps/Game.h" 36 #include <sstream> 37 #include <string> 38 #include "renderer/Renderer.h" 39 40 CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline) 41 : CCinemaData(data), TNSpline(spline), m_TargetSpline(targetSpline), m_TimeElapsed(0.f) 42 { 43 BuildSpline(); 44 45 if (m_Orientation == L"target") 46 { 47 m_LookAtTarget = true; 48 ENSURE(m_TargetSpline.GetAllNodes().size() > 0); 49 } 50 51 // Set distortion mode and style 52 if (data.m_Mode == L"ease_in") 53 DistModePtr = &CCinemaPath::EaseIn; 54 else if (data.m_Mode == L"ease_out") 55 DistModePtr = &CCinemaPath::EaseOut; 56 else if (data.m_Mode == L"ease_inout") 57 DistModePtr = &CCinemaPath::EaseInOut; 58 else if (data.m_Mode == L"ease_outin") 59 DistModePtr = &CCinemaPath::EaseOutIn; 60 else 61 { 62 debug_printf("Cinematic mode not found for '%s'\n", data.m_Mode.ToUTF8().c_str()); 63 DistModePtr = &CCinemaPath::EaseInOut; 64 } 65 66 if (data.m_Style == L"default") 67 DistStylePtr = &CCinemaPath::EaseDefault; 68 else if (data.m_Style == L"growth") 69 DistStylePtr = &CCinemaPath::EaseGrowth; 70 else if (data.m_Style == L"expo") 71 DistStylePtr = &CCinemaPath::EaseExpo; 72 else if (data.m_Style == L"circle") 73 DistStylePtr = &CCinemaPath::EaseCircle; 74 else if (data.m_Style == L"sine") 75 DistStylePtr = &CCinemaPath::EaseSine; 76 else 77 { 78 debug_printf("Cinematic style not found for '%s'\n", data.m_Style.ToUTF8().c_str()); 79 DistStylePtr = &CCinemaPath::EaseDefault; 80 } 81 82 //UpdateDuration(); 83 } 84 85 void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const 86 { 87 if (NodeCount < 2 || DistModePtr == NULL) 88 return; 89 if (NodeCount == 2 && lines) 90 smoothness = 2; 91 92 float start = MaxDistance / smoothness; 93 float time = 0; 94 95 #if CONFIG2_GLES 96 #warning TODO : do something about CCinemaPath on GLES 97 #else 98 99 glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); 100 if (lines) 101 { 102 glLineWidth(1.8f); 103 glEnable(GL_LINE_SMOOTH); 104 glBegin(GL_LINE_STRIP); 105 106 for (int i = 0; i <= smoothness; ++i) 107 { 108 // Find distorted time 109 time = start*i / MaxDistance; 110 CVector3D tmp = GetPosition(time); 111 glVertex3f(tmp.X, tmp.Y, tmp.Z); 112 } 113 glEnd(); 114 glDisable(GL_LINE_SMOOTH); 115 glLineWidth(1.0f); 116 } 117 else 118 { 119 smoothness /= 2; 120 start = MaxDistance / smoothness; 121 glEnable(GL_POINT_SMOOTH); 122 glPointSize(3.0f); 123 glBegin(GL_POINTS); 124 125 for (int i = 0; i <= smoothness; ++i) 126 { 127 // Find distorted time 128 time = (this->*DistModePtr)(start*i / MaxDistance); 129 CVector3D tmp = GetPosition(time); 130 glVertex3f(tmp.X, tmp.Y, tmp.Z); 131 } 132 glColor3f(1.0f, 1.0f, 0.0f); // yellow 133 134 for (size_t i = 0; i<Node.size(); ++i) 135 glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z); 136 137 glEnd(); 138 glPointSize(1.0f); 139 glDisable(GL_POINT_SMOOTH); 140 } 141 142 #endif 143 } 144 145 void CCinemaPath::DrawNodes(const CVector4D& RGBA) const 146 { 147 #if CONFIG2_GLES 148 #warning TODO : do something about CCinemaPath on GLES 149 #else 150 glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); 151 glEnable(GL_POINT_SMOOTH); 152 glPointSize(5.0f); 153 glBegin(GL_POINTS); 154 for (size_t i = 0; i < Node.size(); ++i) 155 glVertex3f(Node[i].Position.X, Node[i].Position.Y, Node[i].Position.Z); 156 glEnd(); 157 glPointSize(1.0f); 158 glDisable(GL_POINT_SMOOTH); 159 #endif 160 } 161 162 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation) 163 { 164 CCamera *Cam = g_Game->GetView()->GetCamera(); 165 t = (this->*DistModePtr)(t); 166 CVector3D pos = GetPosition(t); 167 168 if (m_LookAtTarget) 169 { 170 if (m_TimeElapsed <= m_TargetSpline.MaxDistance) 171 Cam->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance), CVector3D(0, 1, 0)); 172 else 173 Cam->LookAt(pos, m_TargetSpline.GetAllNodes().back().Position, CVector3D(0, 1, 0)); 174 } 175 else 176 { 177 CVector3D nodeRotation = Node[m_CurrentNode + 1].Rotation; 178 CQuaternion start, end; 179 start.FromEulerAngles(DEGTORAD(startRotation.X), DEGTORAD(startRotation.Y), DEGTORAD(startRotation.Z)); 180 end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z)); 181 start.Slerp(start, end, nodet); 182 183 Cam->m_Orientation.SetIdentity(); 184 Cam->m_Orientation.Rotate(start); 185 Cam->m_Orientation.Translate(pos); 186 } 187 Cam->UpdateFrustum(); 188 } 189 190 // Distortion mode functions 191 float CCinemaPath::EaseIn(float t) const 192 { 193 return (this->*DistStylePtr)(t); 194 } 195 196 float CCinemaPath::EaseOut(float t) const 197 { 198 return 1.0f - EaseIn(1.0f - t); 199 } 200 201 float CCinemaPath::EaseInOut(float t) const 202 { 203 if (t < m_Switch) 204 return EaseIn(1.0f / m_Switch * t) * m_Switch; 205 return EaseOut(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch; 206 } 207 208 float CCinemaPath::EaseOutIn(float t) const 209 { 210 if (t < m_Switch) 211 return EaseOut(1.0f / m_Switch * t) * m_Switch; 212 return EaseIn(1.0f / m_Switch * (t - m_Switch)) * m_Switch + m_Switch; 213 } 214 215 // Distortion style functions 216 float CCinemaPath::EaseDefault(float t) const 217 { 218 return t; 219 } 220 221 float CCinemaPath::EaseGrowth(float t) const 222 { 223 return pow(t, m_Growth); 224 } 225 226 227 float CCinemaPath::EaseExpo(float t) const 228 { 229 if (t == 0) 230 return t; 231 return powf(m_Growth, 10 * (t - 1.0f)); 232 } 233 234 float CCinemaPath::EaseCircle(float t) const 235 { 236 t = -(sqrt(1.0f - t*t) - 1.0f); 237 if (m_GrowthCount > 1.0f) 238 { 239 --m_GrowthCount; 240 return (this->*DistStylePtr)(t); 241 } 242 return t; 243 } 244 245 float CCinemaPath::EaseSine(float t) const 246 { 247 t = 1.0f - cos(t * (float)M_PI / 2); 248 if (m_GrowthCount > 1.0f) 249 { 250 --m_GrowthCount; 251 return (this->*DistStylePtr)(t); 252 } 253 return t; 254 } 255 256 bool CCinemaPath::Validate() 257 { 258 if (m_TimeElapsed <= GetDuration() && m_TimeElapsed >= 0.0f) 259 { 260 // Find current node and past "node time" 261 float previousTime = 0.0f, cumulation = 0.0f; 262 // Ignore the last node, since it is a blank (node time values are shifted down one from interface) 263 for (size_t i = 0; i < Node.size() - 1; ++i) 264 { 265 cumulation += Node[i].Distance; 266 if (m_TimeElapsed <= cumulation) 267 { 268 m_PreviousNodeTime = previousTime; 269 m_PreviousRotation = Node[i].Rotation; 270 m_CurrentNode = i; // We're moving toward this next node, so use its rotation 271 return true; 272 } 273 else 274 previousTime += Node[i].Distance; 275 } 276 } 277 return false; 278 } 279 280 bool CCinemaPath::Play(const float deltaRealTime) 281 { 282 m_TimeElapsed += m_Timescale * deltaRealTime; 283 if (!Validate()) 284 { 285 m_TimeElapsed = 0.0f; 286 return false; 287 } 288 MoveToPointAt(m_TimeElapsed / GetDuration(), GetNodeFraction(), m_PreviousRotation); 289 return true; 290 } -
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(1) {} 33 virtual ~CCinemaData() {} 34 35 const CCinemaData* GetData() const { return this; } 36 37 CStrW m_Name; 38 CStrW m_Orientation; 39 bool m_LookAtTarget; 40 41 // Distortion variables 42 mutable float m_GrowthCount; 43 float m_Growth; 44 float m_Switch; 45 CStrW m_Mode; 46 CStrW m_Style; 47 float m_Timescale; // a negative timescale results in backwards play 48 }; 49 50 51 // Once the data is part of the path, it shouldn't be changeable, so use private inheritance. 52 // This class encompasses the spline and the information which determines how the path will operate 53 // and also provides the functionality for doing so 54 55 class CCinemaPath : private CCinemaData, public TNSpline 56 { 57 public: 58 CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {} 59 CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); 60 ~CCinemaPath() { DistStylePtr = NULL; DistModePtr = NULL; } 61 62 // Sets camera position to calculated point on spline 63 void MoveToPointAt(float t, float nodet, const CVector3D&); 64 65 // Distortion mode functions-change how ratio is passed to distortion style functions 66 float EaseIn(float t) const; 67 float EaseOut(float t) const; 68 float EaseInOut(float t) const; 69 float EaseOutIn(float t) const; 70 71 // Distortion style functions 72 float EaseDefault(float t) const; 73 float EaseGrowth(float t) const; 74 float EaseExpo(float t) const; 75 float EaseCircle(float t) const; 76 float EaseSine(float t) const; 77 78 float (CCinemaPath::*DistStylePtr)(float ratio) const; 79 float (CCinemaPath::*DistModePtr)(float ratio) const; 80 81 const CCinemaData* GetData() const { return CCinemaData::GetData(); } 82 83 public: 84 85 void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const; 86 void DrawNodes(const CVector4D& RGBA) const; 87 88 inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; } 89 inline float GetNodeDuration(const int index) const { return Node[index].Distance; } 90 inline float GetDuration() const { return MaxDistance; } 91 92 inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance; } 93 inline float GetElapsedTime() const { return m_TimeElapsed; } 94 95 CStrW GetName() const { return m_Name; } 96 97 inline void SetTimescale(float scale) { m_Timescale = scale; } 98 99 float m_TimeElapsed; 100 float m_PreviousNodeTime; //How much time has passed before the current node 101 102 size_t m_CurrentNode; 103 CVector3D m_PreviousRotation; 104 105 public: 106 107 /** 108 * Returns false if finished. 109 * @param deltaRealTime Elapsed real time since the last frame. 110 */ 111 bool Play(const float deltaRealTime); 112 113 /** 114 * Validate the path 115 * @return true if the path is valid 116 */ 117 bool Validate(); 118 119 /** 120 * Returns true if path doesn't contain nodes 121 */ 122 bool Empty() { return Node.empty(); } 123 124 inline float GetTimescale() const { return m_Timescale; } 125 126 private: 127 128 TNSpline m_TargetSpline; 129 }; 130 131 #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.IsActive()) 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" … … 55 55 CMapReader::CMapReader() 56 56 : xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) 57 57 { 58 cur_terrain_tex = 0; 58 cur_terrain_tex = 0; // important - resets generator state 59 59 60 60 // Maps that don't override the default probably want the old lighting model 61 61 //m_LightEnv.SetLightingModel("old"); … … 215 215 { 216 216 // now unpack everything into local data 217 217 int ret = UnpackTerrain(); 218 if (ret != 0) 218 if (ret != 0) // failed or timed out 219 219 { 220 220 return ret; 221 221 } … … 224 224 } 225 225 226 226 // UnpackTerrain: unpack the terrain from the end of the input data stream 227 // 227 // - data: map size, heightmap, list of textures used by map, texture tile assignments 228 228 int CMapReader::UnpackTerrain() 229 229 { 230 230 // yield after this time is reached. balances increased progress bar … … 292 292 for (ssize_t i=0; i<m_PatchesPerSide; i++) { 293 293 for (ssize_t m=0; m<PATCH_SIZE; m++) { 294 294 for (ssize_t k=0; k<PATCH_SIZE; k++) { 295 CMiniPatch& mp = pTerrain->GetPatch(i,j)->m_MiniPatches[m][k]; 295 CMiniPatch& mp = pTerrain->GetPatch(i,j)->m_MiniPatches[m][k]; // can't fail 296 296 297 297 mp.Tex = m_TerrainTextures[tileptr->m_Tex1Index]; 298 298 mp.Priority = tileptr->m_Priority; … … 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 }; … … 573 573 { 574 574 for (ssize_t px = 0; px < patches; ++px) 575 575 { 576 CPatch* patch = m_MapReader.pTerrain->GetPatch(px, pz); 576 CPatch* patch = m_MapReader.pTerrain->GetPatch(px, pz); // can't fail 577 577 578 578 for (ssize_t z = 0; z < PATCH_SIZE; ++z) 579 579 { … … 605 605 EL(color); 606 606 EL(tint); 607 607 EL(height); 608 EL(shininess); 608 EL(shininess); // for compatibility 609 609 EL(waviness); 610 610 EL(murkiness); 611 611 EL(windangle); 612 EL(reflectiontint); 613 EL(reflectiontintstrength); 612 EL(reflectiontint); // for compatibility 613 EL(reflectiontintstrength); // for compatibility 614 614 EL(fog); 615 615 EL(fogcolor); 616 616 EL(fogfactor); … … 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) … … 849 849 EL(distortion); 850 850 EL(node); 851 851 EL(position); 852 EL(t ime);852 EL(target); 853 853 AT(name); 854 854 AT(timescale); 855 AT(orientation); 855 856 AT(mode); 856 857 AT(style); 857 858 AT(growth); … … 859 860 AT(x); 860 861 AT(y); 861 862 AT(z); 863 AT(deltatime); 862 864 863 865 #undef EL 864 866 #undef AT 865 866 std::map<CStrW, CCinemaPath> pathList; 867 867 868 XERO_ITER_EL(parent, element) 868 869 { 869 870 int elementName = element.GetNodeName(); 870 871 if ( elementName == el_path ) 871 if (elementName == el_path) 872 872 { 873 CCinemaData pathData; 873 874 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; 875 CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8()); 876 pathData.m_Timescale = attrs.GetNamedItem(at_timescale).ToFloat(); 877 TNSpline pathSpline, targetSpline; 878 float lastTargetTime = 0; 879 880 pathData.m_Name = pathName; 881 pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8(); 882 pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8(); 883 pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8(); 879 884 880 885 XERO_ITER_EL(element, pathChild) 881 886 { 882 887 elementName = pathChild.GetNodeName(); 883 888 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 889 894 // Load node data used for spline895 else if ( elementName == el_node)890 // Load node data used for spline 891 if (elementName == el_node) 896 892 { 897 893 SplineData data; 894 data.Distance = pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat(); 895 lastTargetTime += pathChild.GetAttributes().GetNamedItem(at_deltatime).ToFloat(); 898 896 XERO_ITER_EL(pathChild, nodeChild) 899 897 { 900 898 elementName = nodeChild.GetNodeName(); 901 899 attrs = nodeChild.GetAttributes(); 902 903 //Fix?: assumes that time is last element 904 if ( elementName == el_position ) 900 if (elementName == el_position) 905 901 { 906 902 data.Position.X = attrs.GetNamedItem(at_x).ToFloat(); 907 903 data.Position.Y = attrs.GetNamedItem(at_y).ToFloat(); 908 904 data.Position.Z = attrs.GetNamedItem(at_z).ToFloat(); 909 continue;910 905 } 911 else if ( elementName == el_rotation)906 else if (elementName == el_rotation) 912 907 { 913 908 data.Rotation.X = attrs.GetNamedItem(at_x).ToFloat(); 914 909 data.Rotation.Y = attrs.GetNamedItem(at_y).ToFloat(); 915 910 data.Rotation.Z = attrs.GetNamedItem(at_z).ToFloat(); 916 continue;917 911 } 918 else if ( elementName == el_time ) 919 data.Distance = nodeChild.GetText().ToFloat(); 912 else if (elementName == el_target) 913 { 914 CVector3D targetPosition; 915 targetPosition.X = attrs.GetNamedItem(at_x).ToFloat(); 916 targetPosition.Y = attrs.GetNamedItem(at_y).ToFloat(); 917 targetPosition.Z = attrs.GetNamedItem(at_z).ToFloat(); 918 919 targetSpline.AddNode(targetPosition, CVector3D(), lastTargetTime); 920 lastTargetTime = 0; 921 } 920 922 else 921 debug_warn(L"Invalid cinematic element for node child"); 922 923 backwardSpline.AddNode(data.Position, data.Rotation, data.Distance); 923 LOGWARNING("Invalid cinematic element for node child"); 924 924 } 925 pathSpline.AddNode(data.Position, data.Rotation, data.Distance); 925 926 } 926 927 else 927 debug_warn(L"Invalid cinematic element for path child"); 928 929 928 LOGWARNING("Invalid cinematic element for path child"); 930 929 } 931 930 932 //Construct cinema path with data gathered 933 CCinemaPath temp(pathData, backwardSpline); 934 const std::vector<SplineData>& nodes = temp.GetAllNodes(); 935 if ( nodes.empty() ) 931 // Construct cinema path with data gathered 932 CCinemaPath path(pathData, pathSpline, targetSpline); 933 if (path.Empty()) 936 934 { 937 debug_warn(L"Failure loading cinematics");935 LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8()); 938 936 return; 939 937 } 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; 938 939 if (!m_MapReader.pCinema->HasPath(pathName)) 940 m_MapReader.pCinema->AddPath(pathName, path); 941 else 942 LOGWARNING("Path with name '%s' already exists", pathName.ToUTF8()); 949 943 } 950 944 else 951 ENSURE("Invalid cinema child");945 LOGWARNING("Invalid path child with name '%s'", element.GetText()); 952 946 } 953 954 if (m_MapReader.pCinema)955 m_MapReader.pCinema->SetAllPaths(pathList);956 947 } 957 948 958 949 void CXMLReader::ReadTriggers(XMBElement UNUSED(parent)) … … 1048 1039 entity_id_t ent = sim.AddEntity(TemplateName, EntityUid); 1049 1040 entity_id_t player = cmpPlayerManager->GetPlayerByID(PlayerID); 1050 1041 if (ent == INVALID_ENTITY || player == INVALID_ENTITY) 1051 { 1042 { // Don't add entities with invalid player IDs 1052 1043 LOGERROR("Failed to load entity template '%s'", utf8_from_wstring(TemplateName)); 1053 1044 } 1054 1045 else … … 1125 1116 } 1126 1117 else if (name == "Paths") 1127 1118 { 1128 Read Cinema(node);1119 ReadPaths(node); 1129 1120 } 1130 1121 else if (name == "Triggers") 1131 1122 { … … 1161 1152 if (!m_MapReader.m_SkipEntities) 1162 1153 { 1163 1154 ret = ReadEntities(node, end_time); 1164 if (ret != 0) 1155 if (ret != 0) // error or timed out 1165 1156 return ret; 1166 1157 } 1167 1158 } … … 1323 1314 JSAutoRequest rq(cx); 1324 1315 1325 1316 // parse terrain from map data 1326 // 1317 // an error here should stop the loading process 1327 1318 #define GET_TERRAIN_PROPERTY(val, prop, out)\ 1328 1319 if (!pSimulation2->GetScriptInterface().GetProperty(val, #prop, out))\ 1329 { 1320 { LOGERROR("CMapReader::ParseTerrain() failed to get '%s' property", #prop);\ 1330 1321 throw PSERROR_Game_World_MapLoadFailed("Error parsing terrain data.\nCheck application log for details"); } 1331 1322 1332 1323 u32 size; … … 1420 1411 entity_id_t ent = pSimulation2->AddEntity(currEnt.templateName, currEnt.entityID); 1421 1412 entity_id_t player = cmpPlayerManager->GetPlayerByID(currEnt.playerID); 1422 1413 if (ent == INVALID_ENTITY || player == INVALID_ENTITY) 1423 { 1414 { // Don't add entities with invalid player IDs 1424 1415 LOGERROR("Failed to load entity template '%s'", utf8_from_wstring(currEnt.templateName)); 1425 1416 } 1426 1417 else … … 1576 1567 GET_CAMERA_PROPERTY(m_MapData.get(), Camera, &cameraObj) 1577 1568 1578 1569 if (!cameraObj.isUndefined()) 1579 { 1570 { // If camera property exists, read values 1580 1571 CFixedVector3D pos; 1581 1572 GET_CAMERA_PROPERTY(cameraObj, Position, pos) 1582 1573 translation = pos; -
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" … … 84 84 // handle isn't in list 85 85 static u16 GetEntryIndex(const CTerrainTextureEntry* entry, const std::vector<CTerrainTextureEntry*>& entries) 86 86 { 87 const size_t limit = std::min(entries.size(), size_t(0xFFFEu)); 87 const size_t limit = std::min(entries.size(), size_t(0xFFFEu)); // paranoia 88 88 for (size_t i=0;i<limit;i++) { 89 89 if (entries[i]==entry) { 90 90 return (u16)i; … … 114 114 for (ssize_t i=0;i<patchesPerSide;i++) { 115 115 for (ssize_t m=0;m<PATCH_SIZE;m++) { 116 116 for (ssize_t k=0;k<PATCH_SIZE;k++) { 117 CMiniPatch& mp=pTerrain->GetPatch(i,j)->m_MiniPatches[m][k]; 117 CMiniPatch& mp=pTerrain->GetPatch(i,j)->m_MiniPatches[m][k]; // can't fail 118 118 u16 index=u16(GetEntryIndex(mp.GetTextureEntry(),entries)); 119 119 if (index==0xFFFF) { 120 120 index=(u16)entries.size(); … … 154 154 155 155 /////////////////////////////////////////////////////////////////////////////////////////////////// 156 156 // PackTerrain: pack the terrain onto the end of the output data stream 157 // 157 // - data: map size, heightmap, list of textures used by map, texture tile assignments 158 158 void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain) 159 159 { 160 160 // pack map size … … 162 162 packer.PackSize(mapsize); 163 163 164 164 // pack heightmap 165 packer.PackRaw(pTerrain->GetHeightMap(),sizeof(u16)*SQR(pTerrain->GetVerticesPerSide())); 165 packer.PackRaw(pTerrain->GetHeightMap(),sizeof(u16)*SQR(pTerrain->GetVerticesPerSide())); 166 166 167 167 // the list of textures used by map 168 168 std::vector<CStr> terrainTextures; … … 408 408 409 409 for ( ; it != paths.end(); ++it ) 410 410 { 411 CStrW name = it->first;412 411 float 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 for (size_t j = 0; j < nodes.size(); ++j) 421 423 { 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 424 XML_Element("Node"); 425 if (j > 0) 426 XML_Attribute("deltatime", nodes[j - 1].Distance); 427 else 428 XML_Attribute("deltatime", 0.0f); 432 429 433 430 { 434 431 XML_Element("Position"); … … 443 440 XML_Attribute("y", nodes[j].Rotation.Y); 444 441 XML_Attribute("z", nodes[j].Rotation.Z); 445 442 } 446 447 XML_Setting("Time", nodes[j].Distance);448 443 } 449 444 } 450 445 } -
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 … … 48 48 // adds node and updates segment length 49 49 void RNSpline::AddNode(const CVector3D &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; 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 100 if ( time > 1.0f)98 if (NodeCount < 2) 99 return CVector3D(0.0f, 0.0f, 0.0f); 100 if (time > 1.0f) 101 101 time = 1.0f; 102 103 104 105 106 107 108 109 110 111 i++;112 113 ENSURE( i < NodeCount - 1 ); 114 115 116 117 CVector3D endVel = Node[i+1].Velocity * Node[i].Distance; 118 119 Node[i+1].Position, endVel, t);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); 120 120 } 121 121 122 122 // internal. Based on Equation 14 123 123 CVector3D RNSpline::GetStartVelocity(int index) 124 124 { 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;125 if (index >= NodeCount - 1 || index < 0) 126 return CVector3D(0.0f, 0.0f, 0.0f); 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; 129 129 } 130 130 131 131 // internal. Based on Equation 15 132 132 CVector3D RNSpline::GetEndVelocity(int index) 133 133 { 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;134 if (index >= NodeCount || index < 1) 135 return CVector3D(0.0f, 0.0f, 0.0f); 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; 138 138 } 139 139 140 140 /*********************************** S N S **************************************************/ … … 142 142 // smoothing filter. 143 143 void SNSpline::Smooth() 144 144 { 145 if ( NodeCount < 3)146 147 148 149 for (int i = 1; i<NodeCount-1; i++)150 151 152 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;145 if (NodeCount < 3) 146 return; 147 CVector3D newVel; 148 CVector3D oldVel = GetStartVelocity(0); 149 for (int i = 1; i < NodeCount - 1; ++i) 150 { 151 // Equation 12 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 oldVel = newVel; 157 } 158 Node[NodeCount - 1].Velocity = GetEndVelocity(NodeCount - 1); 159 Node[NodeCount - 2].Velocity = oldVel; 160 160 } 161 161 162 162 /*********************************** T N S **************************************************/ … … 165 165 // ie time period is time from last node to this node 166 166 void TNSpline::AddNode(const CVector3D &pos, const CVector3D& rotation, float timePeriod) 167 167 { 168 if ( NodeCount >= MAX_SPLINE_NODES)169 170 171 172 173 174 Node[NodeCount-1].Distance = timePeriod;175 MaxDistance += Node[NodeCount-1].Distance;176 168 if (NodeCount >= MAX_SPLINE_NODES) 169 return; 170 if (NodeCount == 0) 171 MaxDistance = 0.f; 172 else 173 { 174 Node[NodeCount - 1].Distance = timePeriod; 175 MaxDistance += Node[NodeCount - 1].Distance; 176 } 177 177 178 179 178 SplineData temp; 179 temp.Position = pos; 180 180 181 182 183 temp.Velocity = CVector3D( 0.0f, 0.0f, 0.0f);184 185 186 181 //make sure we don't end up using undefined numbers... 182 temp.Distance = 0.0f; 183 temp.Velocity = CVector3D(0.0f, 0.0f, 0.0f); 184 temp.Rotation = rotation; 185 Node.push_back(temp); 186 NodeCount++; 187 187 } 188 188 189 189 //Inserts node before position 190 190 void TNSpline::InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, float timePeriod) 191 191 { 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 192 if (NodeCount >= MAX_SPLINE_NODES || index < NodeCount - 1) 193 return; 194 if (NodeCount == 0) 195 MaxDistance = 0.f; 196 else 197 { 198 Node[NodeCount - 1].Distance = timePeriod; 199 Node[NodeCount - 1].Rotation = rotation; 200 MaxDistance += Node[NodeCount - 1].Distance; 201 } 202 SplineData temp; 203 temp.Position = pos; 204 Node.insert(Node.begin() + index, temp); 205 NodeCount++; 206 206 } 207 207 //Removes node at index 208 208 void TNSpline::RemoveNode(const int index) 209 209 { 210 if (NodeCount == 0 || index > NodeCount - 1)211 212 213 214 215 216 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 210 if (NodeCount == 0 || index > NodeCount - 1) 211 { 212 return; 213 } 214 else 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 NodeCount--; 222 222 } 223 223 void TNSpline::UpdateNodeTime(const int index, float time) 224 224 { … … 238 238 } 239 239 void TNSpline::Constrain() 240 240 { 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 241 if (NodeCount < 3) 242 return; 243 for (int i = 1; i < NodeCount - 1; ++i) 244 { 245 // Equation 13 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 } 250 250 } 251 251 -
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> 27 28 #include "Vector3D.h" -
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) -
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'/><empty/>"; 43 } 44 45 virtual void Init(const CParamNode& UNUSED(paramNode)) 46 { 47 // ... 48 } 49 50 virtual void Deinit() 51 { 52 // ... 53 } 54 55 virtual void Serialize(ISerializer& UNUSED(serialize)) 56 { 57 // ... 58 } 59 60 virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& UNUSED(deserialize)) 61 { 62 // ... 63 } 64 65 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) 66 { 67 switch (msg.GetType()) 68 { 69 case MT_CinemaPathEnded: 70 { 71 const CMessageCinemaPathEnded& msgData = static_cast<const CMessageCinemaPathEnded&> (msg); 72 // TODO: send more msg to trigger 73 break; 74 } 75 } 76 } 77 78 virtual void AddCinemaPathToQueue(CStrW name) 79 { 80 if (!g_Game || !g_Game->GetView()) 81 { 82 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 83 return; 84 } 85 g_Game->GetView()->GetCinema()->AddPathToQueue(name); 86 } 87 88 virtual void Play() 89 { 90 if (!g_Game || !g_Game->GetView()) 91 { 92 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 93 return; 94 } 95 g_Game->GetView()->GetCinema()->Play(); 96 } 97 98 virtual void Pause() 99 { 100 if (!g_Game || !g_Game->GetView()) 101 { 102 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 103 return; 104 } 105 g_Game->GetView()->GetCinema()->Pause(); 106 } 107 108 virtual void Stop() 109 { 110 if (!g_Game || !g_Game->GetView()) 111 { 112 LOGERROR("Trying to add cinema path when GameView isn't initialized!"); 113 return; 114 } 115 g_Game->GetView()->GetCinema()->Stop(); 116 } 117 }; 118 119 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) 30 No newline at end of file -
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) : 553 m_PathName(name) 554 { 555 } 556 557 CStrW m_PathName; 558 }; 559 541 560 #endif // INCLUDED_MESSAGETYPES -
source/simulation2/scripting/MessageTypeConversions.cpp
470 470 return new CMessageMinimapPing(); 471 471 } 472 472 473 //////////////////////////////// 474 475 jsval CMessageCinemaPathEnded::ToJSVal(ScriptInterface& scriptInterface) const 476 { 477 TOJSVAL_SETUP(); 478 SET_MSG_PROPERTY(m_PathName); 479 return OBJECT_TO_JSVAL(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 473 489 //////////////////////////////////////////////////////////////// 474 490 475 491 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 44 path.timescale = data->m_Timescale; 45 45 path.change = data->m_Switch; … … 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 } … … 124 124 spline.AddNode( CVector3D(nodes[j].px, nodes[j].py, nodes[j].pz), 125 125 CVector3D(nodes[j].rx, nodes[j].ry, nodes[j].rz), 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"