aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
diff options
context:
space:
mode:
authorMelanie2013-02-14 07:45:30 +0000
committerMelanie2013-02-14 07:45:30 +0000
commitd5cd9308d5f92a25532f22b1e8a815d8606fa067 (patch)
tree9f0cae4d40329437ff30a7dde716dbe6bbb236ac /OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
parentMerge branch 'master' into careminster (diff)
parentSmall fix to sim features module (diff)
downloadopensim-SC_OLD-d5cd9308d5f92a25532f22b1e8a815d8606fa067.zip
opensim-SC_OLD-d5cd9308d5f92a25532f22b1e8a815d8606fa067.tar.gz
opensim-SC_OLD-d5cd9308d5f92a25532f22b1e8a815d8606fa067.tar.bz2
opensim-SC_OLD-d5cd9308d5f92a25532f22b1e8a815d8606fa067.tar.xz
Merge branch 'avination' into careminster
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/KeyframeMotion.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/KeyframeMotion.cs95
1 files changed, 75 insertions, 20 deletions
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
index 5a1fd13..6dc6504 100644
--- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
+++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
@@ -22,25 +22,36 @@ using log4net;
22 22
23namespace OpenSim.Region.Framework.Scenes 23namespace OpenSim.Region.Framework.Scenes
24{ 24{
25 public static class KeyframeTimer 25 public class KeyframeTimer
26 { 26 {
27 private static Timer m_timer; 27 private static Dictionary<Scene, KeyframeTimer>m_timers =
28 private static Dictionary<KeyframeMotion, object> m_motions = new Dictionary<KeyframeMotion, object>(); 28 new Dictionary<Scene, KeyframeTimer>();
29 private static object m_lockObject = new object();
30 private static object m_timerLock = new object();
31 public const double timerInterval = 50.0;
32 29
33 static KeyframeTimer() 30 private Timer m_timer;
31 private Dictionary<KeyframeMotion, object> m_motions = new Dictionary<KeyframeMotion, object>();
32 private object m_lockObject = new object();
33 private object m_timerLock = new object();
34 private const double m_tickDuration = 50.0;
35 private Scene m_scene;
36
37 public double TickDuration
38 {
39 get { return m_tickDuration; }
40 }
41
42 public KeyframeTimer(Scene scene)
34 { 43 {
35 m_timer = new Timer(); 44 m_timer = new Timer();
36 m_timer.Interval = timerInterval; 45 m_timer.Interval = TickDuration;
37 m_timer.AutoReset = true; 46 m_timer.AutoReset = true;
38 m_timer.Elapsed += OnTimer; 47 m_timer.Elapsed += OnTimer;
39 48
49 m_scene = scene;
50
40 m_timer.Start(); 51 m_timer.Start();
41 } 52 }
42 53
43 private static void OnTimer(object sender, ElapsedEventArgs ea) 54 private void OnTimer(object sender, ElapsedEventArgs ea)
44 { 55 {
45 if (!Monitor.TryEnter(m_timerLock)) 56 if (!Monitor.TryEnter(m_timerLock))
46 return; 57 return;
@@ -58,7 +69,7 @@ namespace OpenSim.Region.Framework.Scenes
58 { 69 {
59 try 70 try
60 { 71 {
61 m.OnTimer(); 72 m.OnTimer(TickDuration);
62 } 73 }
63 catch (Exception inner) 74 catch (Exception inner)
64 { 75 {
@@ -78,17 +89,44 @@ namespace OpenSim.Region.Framework.Scenes
78 89
79 public static void Add(KeyframeMotion motion) 90 public static void Add(KeyframeMotion motion)
80 { 91 {
81 lock (m_lockObject) 92 KeyframeTimer timer;
93
94 if (motion.Scene == null)
95 return;
96
97 lock (m_timers)
82 { 98 {
83 m_motions[motion] = null; 99 if (!m_timers.TryGetValue(motion.Scene, out timer))
100 {
101 timer = new KeyframeTimer(motion.Scene);
102 m_timers[motion.Scene] = timer;
103 }
104 }
105
106 lock (timer.m_lockObject)
107 {
108 timer.m_motions[motion] = null;
84 } 109 }
85 } 110 }
86 111
87 public static void Remove(KeyframeMotion motion) 112 public static void Remove(KeyframeMotion motion)
88 { 113 {
89 lock (m_lockObject) 114 KeyframeTimer timer;
115
116 if (motion.Scene == null)
117 return;
118
119 lock (m_timers)
90 { 120 {
91 m_motions.Remove(motion); 121 if (!m_timers.TryGetValue(motion.Scene, out timer))
122 {
123 return;
124 }
125 }
126
127 lock (timer.m_lockObject)
128 {
129 timer.m_motions.Remove(motion);
92 } 130 }
93 } 131 }
94 } 132 }
@@ -156,6 +194,7 @@ namespace OpenSim.Region.Framework.Scenes
156 private DataFormat m_data = DataFormat.Translation | DataFormat.Rotation; 194 private DataFormat m_data = DataFormat.Translation | DataFormat.Rotation;
157 195
158 private bool m_running = false; 196 private bool m_running = false;
197
159 [NonSerialized()] 198 [NonSerialized()]
160 private bool m_selected = false; 199 private bool m_selected = false;
161 200
@@ -163,6 +202,14 @@ namespace OpenSim.Region.Framework.Scenes
163 202
164 private int m_skipLoops = 0; 203 private int m_skipLoops = 0;
165 204
205 [NonSerialized()]
206 private Scene m_scene;
207
208 public Scene Scene
209 {
210 get { return m_scene; }
211 }
212
166 public DataFormat Data 213 public DataFormat Data
167 { 214 {
168 get { return m_data; } 215 get { return m_data; }
@@ -221,8 +268,12 @@ namespace OpenSim.Region.Framework.Scenes
221 268
222 newMotion.m_group = grp; 269 newMotion.m_group = grp;
223 270
224 if (grp != null && grp.IsSelected) 271 if (grp != null)
225 newMotion.m_selected = true; 272 {
273 newMotion.m_scene = grp.Scene;
274 if (grp.IsSelected)
275 newMotion.m_selected = true;
276 }
226 277
227 newMotion.m_timerStopped = false; 278 newMotion.m_timerStopped = false;
228 newMotion.m_isCrossing = false; 279 newMotion.m_isCrossing = false;
@@ -246,6 +297,8 @@ namespace OpenSim.Region.Framework.Scenes
246 return; 297 return;
247 298
248 m_group = grp; 299 m_group = grp;
300 m_scene = grp.Scene;
301
249 Vector3 grppos = grp.AbsolutePosition; 302 Vector3 grppos = grp.AbsolutePosition;
250 Vector3 offset = grppos - m_serializedPosition; 303 Vector3 offset = grppos - m_serializedPosition;
251 // avoid doing it more than once 304 // avoid doing it more than once
@@ -278,6 +331,7 @@ namespace OpenSim.Region.Framework.Scenes
278 { 331 {
279 m_basePosition = grp.AbsolutePosition; 332 m_basePosition = grp.AbsolutePosition;
280 m_baseRotation = grp.GroupRotation; 333 m_baseRotation = grp.GroupRotation;
334 m_scene = grp.Scene;
281 } 335 }
282 336
283 m_timerStopped = true; 337 m_timerStopped = true;
@@ -297,6 +351,7 @@ namespace OpenSim.Region.Framework.Scenes
297 KeyframeMotion newmotion = new KeyframeMotion(null, m_mode, m_data); 351 KeyframeMotion newmotion = new KeyframeMotion(null, m_mode, m_data);
298 352
299 newmotion.m_group = newgrp; 353 newmotion.m_group = newgrp;
354 newmotion.m_scene = newgrp.Scene;
300 355
301 if (m_keyframes != null) 356 if (m_keyframes != null)
302 { 357 {
@@ -482,7 +537,7 @@ namespace OpenSim.Region.Framework.Scenes
482 } 537 }
483 } 538 }
484 539
485 public void OnTimer() 540 public void OnTimer(double tickDuration)
486 { 541 {
487 if (m_skipLoops > 0) 542 if (m_skipLoops > 0)
488 { 543 {
@@ -546,16 +601,16 @@ namespace OpenSim.Region.Framework.Scenes
546 } 601 }
547 602
548 m_currentFrame = m_frames[0]; 603 m_currentFrame = m_frames[0];
549 m_currentFrame.TimeMS += (int)KeyframeTimer.timerInterval; 604 m_currentFrame.TimeMS += (int)tickDuration;
550 605
551 //force a update on a keyframe transition 606 //force a update on a keyframe transition
552 update = true; 607 update = true;
553 } 608 }
554 609
555 m_currentFrame.TimeMS -= (int)KeyframeTimer.timerInterval; 610 m_currentFrame.TimeMS -= (int)tickDuration;
556 611
557 // Do the frame processing 612 // Do the frame processing
558 double steps = (double)m_currentFrame.TimeMS / KeyframeTimer.timerInterval; 613 double steps = (double)m_currentFrame.TimeMS / tickDuration;
559 614
560 if (steps <= 0.0) 615 if (steps <= 0.0)
561 { 616 {