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
parent
e6f3181d3a
commit
903fbd1f06
|
@ -2294,15 +2294,13 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
if (CollisionEventsThisFrame == null)
|
if (CollisionEventsThisFrame == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//if (CollisionEventsThisFrame.m_objCollisionList == null)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (CollisionEventsThisFrame.m_objCollisionList.Count > 0)
|
|
||||||
{
|
|
||||||
base.SendCollisionUpdate(CollisionEventsThisFrame);
|
base.SendCollisionUpdate(CollisionEventsThisFrame);
|
||||||
|
|
||||||
|
if(CollisionEventsThisFrame.m_objCollisionList.Count == 0)
|
||||||
|
CollisionEventsThisFrame = null;
|
||||||
|
else
|
||||||
CollisionEventsThisFrame = new CollisionEventUpdate();
|
CollisionEventsThisFrame = new CollisionEventUpdate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override bool SubscribedEvents()
|
public override bool SubscribedEvents()
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,6 +79,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
private bool m_ShuttingDown = false;
|
private bool m_ShuttingDown = false;
|
||||||
private int m_ControlEventsInQueue = 0;
|
private int m_ControlEventsInQueue = 0;
|
||||||
private int m_LastControlLevel = 0;
|
private int m_LastControlLevel = 0;
|
||||||
|
private bool m_CollisionInQueue = false;
|
||||||
|
|
||||||
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
|
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
|
||||||
|
|
||||||
|
@ -495,6 +496,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
m_ControlEventsInQueue++;
|
m_ControlEventsInQueue++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.EventName == "collision")
|
||||||
|
{
|
||||||
|
if (m_CollisionInQueue)
|
||||||
|
return;
|
||||||
|
if (data.DetectParams == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_CollisionInQueue = true;
|
||||||
|
}
|
||||||
|
|
||||||
m_EventQueue.Enqueue(data);
|
m_EventQueue.Enqueue(data);
|
||||||
|
|
||||||
if (m_CurrentResult == null)
|
if (m_CurrentResult == null)
|
||||||
|
@ -509,6 +520,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public object EventProcessor()
|
public object EventProcessor()
|
||||||
|
{
|
||||||
|
lock(m_Script)
|
||||||
{
|
{
|
||||||
EventParams data = null;
|
EventParams data = null;
|
||||||
|
|
||||||
|
@ -516,10 +529,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
{
|
{
|
||||||
data = (EventParams) m_EventQueue.Dequeue();
|
data = (EventParams) m_EventQueue.Dequeue();
|
||||||
if (data == null) // Shouldn't happen
|
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;
|
m_CurrentResult = null;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.EventName == "timer")
|
if (data.EventName == "timer")
|
||||||
m_TimerQueued = false;
|
m_TimerQueued = false;
|
||||||
if (data.EventName == "control")
|
if (data.EventName == "control")
|
||||||
|
@ -527,6 +548,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
if (m_ControlEventsInQueue > 0)
|
if (m_ControlEventsInQueue > 0)
|
||||||
m_ControlEventsInQueue--;
|
m_ControlEventsInQueue--;
|
||||||
}
|
}
|
||||||
|
if (data.EventName == "collision")
|
||||||
|
m_CollisionInQueue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
|
//m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
|
||||||
|
@ -535,8 +558,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
|
|
||||||
if (data.EventName == "state") // Hardcoded state change
|
if (data.EventName == "state") // Hardcoded state change
|
||||||
{
|
{
|
||||||
// m_Engine.Log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
|
// m_Engine.Log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
|
||||||
// m_PrimName, m_ScriptName, data.Params[0].ToString());
|
// m_PrimName, m_ScriptName, data.Params[0].ToString());
|
||||||
m_State=data.Params[0].ToString();
|
m_State=data.Params[0].ToString();
|
||||||
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
|
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
|
||||||
async.RemoveScript(
|
async.RemoveScript(
|
||||||
|
@ -554,8 +577,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
{
|
{
|
||||||
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
|
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
|
||||||
m_LocalID);
|
m_LocalID);
|
||||||
// m_Engine.Log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
|
// m_Engine.Log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
|
||||||
// m_PrimName, m_ScriptName, data.EventName, m_State);
|
// m_PrimName, m_ScriptName, data.EventName, m_State);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -651,6 +674,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int EventTime()
|
public int EventTime()
|
||||||
{
|
{
|
||||||
|
@ -730,6 +754,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
|
|
||||||
public DetectParams GetDetectParams(int idx)
|
public DetectParams GetDetectParams(int idx)
|
||||||
{
|
{
|
||||||
|
if (m_DetectParams == null)
|
||||||
|
return null;
|
||||||
if (idx < 0 || idx >= m_DetectParams.Length)
|
if (idx < 0 || idx >= m_DetectParams.Length)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -738,6 +764,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
|
|
||||||
public UUID GetDetectID(int idx)
|
public UUID GetDetectID(int idx)
|
||||||
{
|
{
|
||||||
|
if (m_DetectParams == null)
|
||||||
|
return UUID.Zero;
|
||||||
if (idx < 0 || idx >= m_DetectParams.Length)
|
if (idx < 0 || idx >= m_DetectParams.Length)
|
||||||
return UUID.Zero;
|
return UUID.Zero;
|
||||||
|
|
||||||
|
|
|
@ -198,9 +198,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
det.Add(d);
|
det.Add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (det.Count > 0)
|
||||||
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
||||||
"collision_start",
|
"collision_start",
|
||||||
new Object[] { new LSL_Types.LSLInteger(1) },
|
new Object[] { new LSL_Types.LSLInteger(det.Count) },
|
||||||
det.ToArray()));
|
det.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,8 +218,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
det.Add(d);
|
det.Add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (det.Count > 0)
|
||||||
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
||||||
"collision", new Object[] { new LSL_Types.LSLInteger(1) },
|
"collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
|
||||||
det.ToArray()));
|
det.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,9 +237,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
det.Add(d);
|
det.Add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (det.Count > 0)
|
||||||
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
myScriptEngine.PostObjectEvent(localID, new EventParams(
|
||||||
"collision_end",
|
"collision_end",
|
||||||
new Object[] { new LSL_Types.LSLInteger(1) },
|
new Object[] { new LSL_Types.LSLInteger(det.Count) },
|
||||||
det.ToArray()));
|
det.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue