XEngine: fix collisions, add event coalescing for collision events.

Fix a nasty concurrency issue that could cause a high event frequency
to start more than one thread pool job for a single script.
0.6.0-stable
Melanie Thielker 2008-09-18 18:50:39 +00:00
parent e6f3181d3a
commit 903fbd1f06
3 changed files with 171 additions and 142 deletions

View File

@ -2294,15 +2294,13 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollisionEventsThisFrame == null)
return;
//if (CollisionEventsThisFrame.m_objCollisionList == null)
// return;
if (CollisionEventsThisFrame.m_objCollisionList.Count > 0)
{
base.SendCollisionUpdate(CollisionEventsThisFrame);
if(CollisionEventsThisFrame.m_objCollisionList.Count == 0)
CollisionEventsThisFrame = null;
else
CollisionEventsThisFrame = new CollisionEventUpdate();
}
}
public override bool SubscribedEvents()
{

View File

@ -79,6 +79,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private bool m_ShuttingDown = false;
private int m_ControlEventsInQueue = 0;
private int m_LastControlLevel = 0;
private bool m_CollisionInQueue = false;
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
@ -495,6 +496,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_ControlEventsInQueue++;
}
if (data.EventName == "collision")
{
if (m_CollisionInQueue)
return;
if (data.DetectParams == null)
return;
m_CollisionInQueue = true;
}
m_EventQueue.Enqueue(data);
if (m_CurrentResult == null)
@ -509,6 +520,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
/// </summary>
/// <returns></returns>
public object EventProcessor()
{
lock(m_Script)
{
EventParams data = null;
@ -516,10 +529,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
data = (EventParams) m_EventQueue.Dequeue();
if (data == null) // Shouldn't happen
{
if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
{
m_CurrentResult = m_Engine.QueueEventHandler(this);
}
else
{
m_CurrentResult = null;
}
return 0;
}
if (data.EventName == "timer")
m_TimerQueued = false;
if (data.EventName == "control")
@ -527,6 +548,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (m_ControlEventsInQueue > 0)
m_ControlEventsInQueue--;
}
if (data.EventName == "collision")
m_CollisionInQueue = false;
}
//m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
@ -651,6 +674,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return 0;
}
}
public int EventTime()
{
@ -730,6 +754,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public DetectParams GetDetectParams(int idx)
{
if (m_DetectParams == null)
return null;
if (idx < 0 || idx >= m_DetectParams.Length)
return null;
@ -738,6 +764,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public UUID GetDetectID(int idx)
{
if (m_DetectParams == null)
return UUID.Zero;
if (idx < 0 || idx >= m_DetectParams.Length)
return UUID.Zero;

View File

@ -198,9 +198,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
det.Add(d);
}
if (det.Count > 0)
myScriptEngine.PostObjectEvent(localID, new EventParams(
"collision_start",
new Object[] { new LSL_Types.LSLInteger(1) },
new Object[] { new LSL_Types.LSLInteger(det.Count) },
det.ToArray()));
}
@ -217,8 +218,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
det.Add(d);
}
if (det.Count > 0)
myScriptEngine.PostObjectEvent(localID, new EventParams(
"collision", new Object[] { new LSL_Types.LSLInteger(1) },
"collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
det.ToArray()));
}
@ -235,9 +237,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
det.Add(d);
}
if (det.Count > 0)
myScriptEngine.PostObjectEvent(localID, new EventParams(
"collision_end",
new Object[] { new LSL_Types.LSLInteger(1) },
new Object[] { new LSL_Types.LSLInteger(det.Count) },
det.ToArray()));
}