Preserve the script running flag when copying an object.

avinationmerge
Melanie 2011-01-08 16:44:28 +01:00
parent 1ab9cd0997
commit c271bbcc8a
4 changed files with 60 additions and 0 deletions

View File

@ -124,6 +124,9 @@ namespace OpenSim.Framework
private UUID _oldID = UUID.Zero; private UUID _oldID = UUID.Zero;
private bool _ownerChanged = false; private bool _ownerChanged = false;
// This used ONLY during copy. It can't be relied on at other times!
private bool _scriptRunning = true;
public UUID AssetID { public UUID AssetID {
get { get {
@ -387,6 +390,15 @@ namespace OpenSim.Framework
} }
} }
public bool ScriptRunning {
get {
return _scriptRunning;
}
set {
_scriptRunning = value;
}
}
// See ICloneable // See ICloneable
#region ICloneable Members #region ICloneable Members

View File

@ -50,5 +50,7 @@ namespace OpenSim.Region.Framework.Interfaces
void ResumeScript(UUID itemID); void ResumeScript(UUID itemID);
ArrayList GetScriptErrors(UUID itemID); ArrayList GetScriptErrors(UUID itemID);
bool HasScript(UUID itemID, out bool running);
} }
} }

View File

@ -94,6 +94,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_items = value; m_items = value;
m_inventorySerial++; m_inventorySerial++;
QueryScriptStates();
} }
} }
@ -226,6 +227,36 @@ namespace OpenSim.Region.Framework.Scenes
m_items.LockItemsForWrite(false); m_items.LockItemsForWrite(false);
} }
private void QueryScriptStates()
{
if (m_part == null || m_part.ParentGroup == null)
return;
IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
if (engines == null) // No engine at all
return;
Items.LockItemsForRead(true);
foreach (TaskInventoryItem item in Items.Values)
{
if (item.InvType == (int)InventoryType.LSL)
{
foreach (IScriptModule e in engines)
{
bool running;
if (e.HasScript(item.ItemID, out running))
{
item.ScriptRunning = running;
break;
}
}
}
}
Items.LockItemsForRead(false);
}
/// <summary> /// <summary>
/// Start all the scripts contained in this prim's inventory /// Start all the scripts contained in this prim's inventory
/// </summary> /// </summary>
@ -349,6 +380,9 @@ namespace OpenSim.Region.Framework.Scenes
m_part.ParentGroup.Scene.EventManager.TriggerRezScript( m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
StoreScriptErrors(item.ItemID, null); StoreScriptErrors(item.ItemID, null);
if (!item.ScriptRunning)
m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
m_part.LocalId, item.ItemID);
m_part.ParentGroup.AddActiveScriptCount(1); m_part.ParentGroup.AddActiveScriptCount(1);
m_part.ScheduleFullUpdate(); m_part.ScheduleFullUpdate();
} }

View File

@ -1695,5 +1695,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
instance.Resume(); instance.Resume();
} }
public bool HasScript(UUID itemID, out bool running)
{
running = true;
IScriptInstance instance = GetInstance(itemID);
if (instance == null)
return false;
running = instance.Running;
return true;
}
} }
} }