Change keyframe motion to use a single timer for all objects. This is required
to prevent slippage between objects that are meant to move synchronously or keep their relative positions/rotations.avinationmerge
parent
2a558c7346
commit
d1ebb0a8f9
|
@ -22,6 +22,77 @@ using log4net;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Scenes
|
namespace OpenSim.Region.Framework.Scenes
|
||||||
{
|
{
|
||||||
|
public static class KeyframeTimer
|
||||||
|
{
|
||||||
|
private static Timer m_timer;
|
||||||
|
private static Dictionary<KeyframeMotion, object> m_motions = new Dictionary<KeyframeMotion, object>();
|
||||||
|
private static object m_lockObject = new object();
|
||||||
|
private static object m_timerLock = new object();
|
||||||
|
public const double timerInterval = 50.0;
|
||||||
|
|
||||||
|
static KeyframeTimer()
|
||||||
|
{
|
||||||
|
m_timer = new Timer();
|
||||||
|
m_timer.Interval = timerInterval;
|
||||||
|
m_timer.AutoReset = true;
|
||||||
|
m_timer.Elapsed += OnTimer;
|
||||||
|
|
||||||
|
m_timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnTimer(object sender, ElapsedEventArgs ea)
|
||||||
|
{
|
||||||
|
if (!Monitor.TryEnter(m_timerLock))
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<KeyframeMotion> motions;
|
||||||
|
|
||||||
|
lock (m_lockObject)
|
||||||
|
{
|
||||||
|
motions = new List<KeyframeMotion>(m_motions.Keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (KeyframeMotion m in motions)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m.OnTimer();
|
||||||
|
}
|
||||||
|
catch (Exception inner)
|
||||||
|
{
|
||||||
|
// Don't stop processing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Keep running no matter what
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Monitor.Exit(m_timerLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Add(KeyframeMotion motion)
|
||||||
|
{
|
||||||
|
lock (m_lockObject)
|
||||||
|
{
|
||||||
|
m_motions[motion] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Remove(KeyframeMotion motion)
|
||||||
|
{
|
||||||
|
lock (m_lockObject)
|
||||||
|
{
|
||||||
|
m_motions.Remove(motion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class KeyframeMotion
|
public class KeyframeMotion
|
||||||
{
|
{
|
||||||
|
@ -63,18 +134,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
private Keyframe[] m_keyframes;
|
private Keyframe[] m_keyframes;
|
||||||
|
|
||||||
[NonSerialized()]
|
|
||||||
protected Timer m_timer = null;
|
|
||||||
|
|
||||||
// timer lock
|
|
||||||
[NonSerialized()]
|
|
||||||
private object m_onTimerLock;
|
|
||||||
|
|
||||||
// timer overrun detect
|
|
||||||
// prevents overlap or timer events threads frozen on the lock
|
|
||||||
[NonSerialized()]
|
|
||||||
private bool m_inOnTimer;
|
|
||||||
|
|
||||||
// skip timer events.
|
// skip timer events.
|
||||||
//timer.stop doesn't assure there aren't event threads still being fired
|
//timer.stop doesn't assure there aren't event threads still being fired
|
||||||
[NonSerialized()]
|
[NonSerialized()]
|
||||||
|
@ -102,7 +161,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
private int m_iterations = 0;
|
private int m_iterations = 0;
|
||||||
|
|
||||||
private const double timerInterval = 50.0;
|
private int m_skipLoops = 0;
|
||||||
|
|
||||||
public DataFormat Data
|
public DataFormat Data
|
||||||
{
|
{
|
||||||
|
@ -139,31 +198,16 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
private void StartTimer()
|
private void StartTimer()
|
||||||
{
|
{
|
||||||
if (m_timer == null)
|
KeyframeTimer.Add(this);
|
||||||
return;
|
|
||||||
m_timerStopped = false;
|
m_timerStopped = false;
|
||||||
m_timer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopTimer()
|
private void StopTimer()
|
||||||
{
|
{
|
||||||
if (m_timer == null || m_timerStopped)
|
|
||||||
return;
|
|
||||||
m_timerStopped = true;
|
m_timerStopped = true;
|
||||||
m_timer.Stop();
|
KeyframeTimer.Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveTimer()
|
|
||||||
{
|
|
||||||
if (m_timer == null)
|
|
||||||
return;
|
|
||||||
m_timerStopped = true;
|
|
||||||
m_timer.Stop();
|
|
||||||
m_timer.Elapsed -= OnTimer;
|
|
||||||
m_timer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data)
|
public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data)
|
||||||
{
|
{
|
||||||
KeyframeMotion newMotion = null;
|
KeyframeMotion newMotion = null;
|
||||||
|
@ -180,9 +224,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (grp != null && grp.IsSelected)
|
if (grp != null && grp.IsSelected)
|
||||||
newMotion.m_selected = true;
|
newMotion.m_selected = true;
|
||||||
|
|
||||||
newMotion.m_onTimerLock = new object();
|
|
||||||
newMotion.m_timerStopped = false;
|
newMotion.m_timerStopped = false;
|
||||||
newMotion.m_inOnTimer = false;
|
|
||||||
newMotion.m_isCrossing = false;
|
newMotion.m_isCrossing = false;
|
||||||
newMotion.m_waitingCrossing = false;
|
newMotion.m_waitingCrossing = false;
|
||||||
}
|
}
|
||||||
|
@ -196,8 +238,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
public void UpdateSceneObject(SceneObjectGroup grp)
|
public void UpdateSceneObject(SceneObjectGroup grp)
|
||||||
{
|
{
|
||||||
// lock (m_onTimerLock)
|
|
||||||
{
|
|
||||||
m_isCrossing = false;
|
m_isCrossing = false;
|
||||||
m_waitingCrossing = false;
|
m_waitingCrossing = false;
|
||||||
StopTimer();
|
StopTimer();
|
||||||
|
@ -227,7 +267,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (m_running)
|
if (m_running)
|
||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public KeyframeMotion(SceneObjectGroup grp, PlayMode mode, DataFormat data)
|
public KeyframeMotion(SceneObjectGroup grp, PlayMode mode, DataFormat data)
|
||||||
{
|
{
|
||||||
|
@ -241,9 +280,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
m_baseRotation = grp.GroupRotation;
|
m_baseRotation = grp.GroupRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_onTimerLock = new object();
|
|
||||||
m_timerStopped = true;
|
m_timerStopped = true;
|
||||||
m_inOnTimer = false;
|
|
||||||
m_isCrossing = false;
|
m_isCrossing = false;
|
||||||
m_waitingCrossing = false;
|
m_waitingCrossing = false;
|
||||||
}
|
}
|
||||||
|
@ -296,7 +333,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public void Delete()
|
public void Delete()
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
RemoveTimer();
|
StopTimer();
|
||||||
m_isCrossing = false;
|
m_isCrossing = false;
|
||||||
m_waitingCrossing = false;
|
m_waitingCrossing = false;
|
||||||
m_frames.Clear();
|
m_frames.Clear();
|
||||||
|
@ -309,27 +346,13 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
m_waitingCrossing = false;
|
m_waitingCrossing = false;
|
||||||
if (m_keyframes != null && m_group != null && m_keyframes.Length > 0)
|
if (m_keyframes != null && m_group != null && m_keyframes.Length > 0)
|
||||||
{
|
{
|
||||||
if (m_timer == null)
|
|
||||||
{
|
|
||||||
m_timer = new Timer();
|
|
||||||
m_timer.Interval = timerInterval;
|
|
||||||
m_timer.AutoReset = true;
|
|
||||||
m_timer.Elapsed += OnTimer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StopTimer();
|
|
||||||
m_timer.Interval = timerInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_inOnTimer = false;
|
|
||||||
StartTimer();
|
StartTimer();
|
||||||
m_running = true;
|
m_running = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
RemoveTimer();
|
StopTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +362,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
m_isCrossing = false;
|
m_isCrossing = false;
|
||||||
m_waitingCrossing = false;
|
m_waitingCrossing = false;
|
||||||
|
|
||||||
RemoveTimer();
|
StopTimer();
|
||||||
|
|
||||||
m_basePosition = m_group.AbsolutePosition;
|
m_basePosition = m_group.AbsolutePosition;
|
||||||
m_baseRotation = m_group.GroupRotation;
|
m_baseRotation = m_group.GroupRotation;
|
||||||
|
@ -354,7 +377,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public void Pause()
|
public void Pause()
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
RemoveTimer();
|
StopTimer();
|
||||||
|
|
||||||
m_group.RootPart.Velocity = Vector3.Zero;
|
m_group.RootPart.Velocity = Vector3.Zero;
|
||||||
m_group.RootPart.AngularVelocity = Vector3.Zero;
|
m_group.RootPart.AngularVelocity = Vector3.Zero;
|
||||||
|
@ -377,15 +400,11 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = m_keyframes.Length;
|
int end = m_keyframes.Length;
|
||||||
// if (m_mode == PlayMode.PingPong && m_keyframes.Length > 1)
|
|
||||||
// end = m_keyframes.Length - 1;
|
|
||||||
|
|
||||||
if (direction < 0)
|
if (direction < 0)
|
||||||
{
|
{
|
||||||
start = m_keyframes.Length - 1;
|
start = m_keyframes.Length - 1;
|
||||||
end = -1;
|
end = -1;
|
||||||
// if (m_mode == PlayMode.PingPong && m_keyframes.Length > 1)
|
|
||||||
// end = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = start; i != end ; i += direction)
|
for (int i = start; i != end ; i += direction)
|
||||||
|
@ -463,39 +482,30 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnTimer(object sender, ElapsedEventArgs e)
|
public void OnTimer()
|
||||||
{
|
{
|
||||||
if (m_timerStopped) // trap events still in air even after a timer.stop
|
if (m_skipLoops > 0)
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_inOnTimer) // don't let overruns to happen
|
|
||||||
{
|
{
|
||||||
m_log.Warn("[KeyFrame]: timer overrun");
|
m_skipLoops--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_timerStopped) // trap events still in air even after a timer.stop
|
||||||
|
return;
|
||||||
|
|
||||||
if (m_group == null)
|
if (m_group == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (m_onTimerLock)
|
|
||||||
{
|
|
||||||
|
|
||||||
m_inOnTimer = true;
|
|
||||||
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (m_selected)
|
if (m_selected)
|
||||||
{
|
{
|
||||||
if (m_group.RootPart.Velocity != Vector3.Zero)
|
if (m_group.RootPart.Velocity != Vector3.Zero)
|
||||||
{
|
{
|
||||||
m_group.RootPart.Velocity = Vector3.Zero;
|
m_group.RootPart.Velocity = Vector3.Zero;
|
||||||
m_group.SendGroupRootTerseUpdate();
|
m_group.SendGroupRootTerseUpdate();
|
||||||
// m_group.RootPart.ScheduleTerseUpdate();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
m_inOnTimer = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,10 +520,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (!m_isCrossing)
|
if (!m_isCrossing)
|
||||||
{
|
{
|
||||||
StopTimer();
|
StopTimer();
|
||||||
m_timer.Interval = timerInterval;
|
|
||||||
StartTimer();
|
StartTimer();
|
||||||
}
|
}
|
||||||
m_inOnTimer = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,7 +532,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (m_frames.Count == 0)
|
if (m_frames.Count == 0)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
m_inOnTimer = false;
|
|
||||||
Scene scene = m_group.Scene;
|
Scene scene = m_group.Scene;
|
||||||
|
|
||||||
IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>();
|
IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>();
|
||||||
|
@ -539,16 +546,16 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentFrame = m_frames[0];
|
m_currentFrame = m_frames[0];
|
||||||
m_currentFrame.TimeMS += (int)timerInterval;
|
m_currentFrame.TimeMS += (int)KeyframeTimer.timerInterval;
|
||||||
|
|
||||||
//force a update on a keyframe transition
|
//force a update on a keyframe transition
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentFrame.TimeMS -= (int)timerInterval;
|
m_currentFrame.TimeMS -= (int)KeyframeTimer.timerInterval;
|
||||||
|
|
||||||
// Do the frame processing
|
// Do the frame processing
|
||||||
double steps = (double)m_currentFrame.TimeMS / timerInterval;
|
double steps = (double)m_currentFrame.TimeMS / KeyframeTimer.timerInterval;
|
||||||
|
|
||||||
if (steps <= 0.0)
|
if (steps <= 0.0)
|
||||||
{
|
{
|
||||||
|
@ -639,23 +646,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update)
|
if (update)
|
||||||
|
{
|
||||||
m_group.SendGroupRootTerseUpdate();
|
m_group.SendGroupRootTerseUpdate();
|
||||||
// m_group.RootPart.ScheduleTerseUpdate();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( Exception ex)
|
|
||||||
{
|
|
||||||
// still happening sometimes
|
|
||||||
// lets try to see where
|
|
||||||
m_log.Warn("[KeyFrame]: timer overrun" + ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
// make sure we do not let this frozen
|
|
||||||
m_inOnTimer = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,9 +698,10 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
m_group.SendGroupRootTerseUpdate();
|
m_group.SendGroupRootTerseUpdate();
|
||||||
// m_group.RootPart.ScheduleTerseUpdate();
|
// m_group.RootPart.ScheduleTerseUpdate();
|
||||||
|
|
||||||
if (m_running && m_timer != null)
|
if (m_running)
|
||||||
{
|
{
|
||||||
m_timer.Interval = 60000;
|
StopTimer();
|
||||||
|
m_skipLoops = 1200; // 60 seconds
|
||||||
StartTimer();
|
StartTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue