Persistent prim inventory phase 5. Restart scripts contained in persisted prims on region start.

No user functionality exposed yet - no ini switch to enable persistence or restore.  A bit more initial work to do.
afrisby
Justin Clarke Casey 2008-01-07 02:12:06 +00:00
parent f43e75762a
commit 3e75dede1b
9 changed files with 111 additions and 29 deletions

View File

@ -426,23 +426,24 @@ namespace OpenSim
UDPServer udpServer; UDPServer udpServer;
Scene scene = SetupScene(regionInfo, out udpServer, m_permissions); Scene scene = SetupScene(regionInfo, out udpServer, m_permissions);
MainLog.Instance.Verbose("MODULES", "Loading Region's Modules"); MainLog.Instance.Verbose("MODULES", "Loading Region's modules");
m_moduleLoader.PickupModules(scene, "."); m_moduleLoader.PickupModules(scene, ".");
//m_moduleLoader.PickupModules(scene, "ScriptEngines"); //m_moduleLoader.PickupModules(scene, "ScriptEngines");
//m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
MainLog.Instance.Verbose("MODULES", "Loading scripting engine modules"); MainLog.Instance.Verbose("MODULES", "Loading scripting engine modules");
m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
m_moduleLoader.InitialiseSharedModules(scene); m_moduleLoader.InitialiseSharedModules(scene);
scene.SetModuleInterfaces(); scene.SetModuleInterfaces();
//Server side object editing permissions checking //Server side object editing permissions checking
scene.PermissionsMngr.BypassPermissions = !m_permissions; scene.PermissionsMngr.BypassPermissions = !m_permissions;
// We need to do this after we've initialized the scripting engines.
scene.StartScripts();
m_sceneManager.Add(scene); m_sceneManager.Add(scene);
m_udpServers.Add(udpServer); m_udpServers.Add(udpServer);
m_regionData.Add(regionInfo); m_regionData.Add(regionInfo);

View File

@ -36,7 +36,12 @@ namespace OpenSim.Region.Environment.Scenes
{ {
protected List<EntityBase> m_children; protected List<EntityBase> m_children;
public Scene m_scene; protected Scene m_scene;
public Scene Scene
{
get { return m_scene; }
}
public LLUUID m_uuid; public LLUUID m_uuid;

View File

@ -37,6 +37,19 @@ namespace OpenSim.Region.Environment.Scenes
{ {
public partial class Scene public partial class Scene
{ {
/// <summary>
/// Start all the scripts in the scene which should be started.
/// </summary>
public void StartScripts()
{
MainLog.Instance.Verbose("PRIMINVENTORY", "Starting scripts in scene");
foreach (SceneObjectGroup group in Entities.Values)
{
group.StartScripts();
}
}
//split these method into this partial as a lot of these (hopefully) are only temporary and won't be needed once Caps is more complete //split these method into this partial as a lot of these (hopefully) are only temporary and won't be needed once Caps is more complete
// or at least some of they can be moved somewhere else // or at least some of they can be moved somewhere else

View File

@ -890,11 +890,12 @@ namespace OpenSim.Region.Environment.Scenes
public virtual void LoadPrimsFromStorage(bool m_permissions) public virtual void LoadPrimsFromStorage(bool m_permissions)
{ {
MainLog.Instance.Verbose("SCENE", "Loading objects from datastore"); MainLog.Instance.Verbose("SCENE", "Loading objects from datastore");
List<SceneObjectGroup> PrimsFromDB = m_storageManager.DataStore.LoadObjects(m_regInfo.RegionID); List<SceneObjectGroup> PrimsFromDB = m_storageManager.DataStore.LoadObjects(m_regInfo.RegionID);
foreach (SceneObjectGroup prim in PrimsFromDB) foreach (SceneObjectGroup group in PrimsFromDB)
{ {
AddEntityFromStorage(prim); AddEntityFromStorage(group);
SceneObjectPart rootPart = prim.GetChildPart(prim.UUID); SceneObjectPart rootPart = group.GetChildPart(group.UUID);
rootPart.ApplySanePermissions(); rootPart.ApplySanePermissions();
bool UsePhysics = (((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) > 0) && m_physicalPrim); bool UsePhysics = (((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) > 0) && m_physicalPrim);
@ -909,6 +910,7 @@ namespace OpenSim.Region.Environment.Scenes
rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
} }
MainLog.Instance.Verbose("SCENE", "Loaded " + PrimsFromDB.Count.ToString() + " SceneObject(s)"); MainLog.Instance.Verbose("SCENE", "Loaded " + PrimsFromDB.Count.ToString() + " SceneObject(s)");
} }

View File

@ -54,7 +54,6 @@ namespace OpenSim.Region.Environment.Scenes
protected ulong m_regionHandle; protected ulong m_regionHandle;
protected string m_regionName; protected string m_regionName;
protected RegionInfo m_regInfo; protected RegionInfo m_regInfo;
protected RegionStatus m_regStatus;
public TerrainEngine Terrain; public TerrainEngine Terrain;
@ -68,6 +67,7 @@ namespace OpenSim.Region.Environment.Scenes
protected string m_datastore; protected string m_datastore;
private uint m_nextLocalId = 8880000; private uint m_nextLocalId = 8880000;
private AssetCache m_assetCache; private AssetCache m_assetCache;
public AssetCache AssetCache public AssetCache AssetCache
@ -75,6 +75,8 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_assetCache; } get { return m_assetCache; }
set { m_assetCache = value; } set { m_assetCache = value; }
} }
protected RegionStatus m_regStatus;
public RegionStatus Region_Status public RegionStatus Region_Status
{ {

View File

@ -37,7 +37,18 @@ using OpenSim.Region.Environment.Interfaces;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
public partial class SceneObjectGroup : EntityBase public partial class SceneObjectGroup : EntityBase
{ {
/// <summary>
/// Start the scripts contained in all the prims in this group.
/// </summary>
public void StartScripts()
{
foreach (SceneObjectPart part in m_parts.Values)
{
part.StartScripts();
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -131,6 +142,6 @@ namespace OpenSim.Region.Environment.Scenes
return part.RemoveInventoryItem(remoteClient, localID, itemID); return part.RemoveInventoryItem(remoteClient, localID, itemID);
} }
return -1; return -1;
} }
} }
} }

View File

@ -33,6 +33,7 @@ using System.Xml.Serialization;
using libsecondlife; using libsecondlife;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes.Scripting; using OpenSim.Region.Environment.Scenes.Scripting;
@ -79,6 +80,53 @@ namespace OpenSim.Region.Environment.Scenes
{ {
get { return m_inventorySerial; } get { return m_inventorySerial; }
} }
/// <summary>
/// Start all the scripts contained in this prim's inventory
/// </summary>
public void StartScripts()
{
foreach (TaskInventoryItem item in m_taskInventory.Values)
{
if ("lsltext" == item.type)
{
StartScript(item);
}
}
}
/// <summary>
/// Start a script in this prim
/// </summary>
/// <param name="item"></param>
/// <returns>true if script asset was found, false if it wasn't</returns>
public bool StartScript(TaskInventoryItem item)
{
// MainLog.Instance.Verbose(
// "PRIMINVENTORY",
// "Starting script {0}, {1} in prim {2}, {3}",
// item.name, item.item_id, Name, UUID);
AssetBase rezAsset = m_parentGroup.Scene.AssetCache.GetAsset(item.asset_id, false);
if (rezAsset != null)
{
string script = Helpers.FieldToUTF8String(rezAsset.Data);
m_parentGroup.Scene.EventManager.TriggerRezScript(LocalID, item.item_id, script);
return true;
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Couldn't start script {0}, {1} since asset ID {2} could not be found",
item.name, item.item_id, item.asset_id);
}
return false;
}
/// <summary> /// <summary>
/// Add an item to this prim's inventory. /// Add an item to this prim's inventory.

View File

@ -172,10 +172,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
try try
{ {
//lock (m_parentGroup.m_scene.SyncRoot) //lock (m_parentGroup.Scene.SyncRoot)
//{ //{
PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z); PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
//} //}
} }
catch (Exception e) catch (Exception e)
@ -225,10 +225,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
try try
{ {
//lock (m_scene.SyncRoot) //lock (Scene.SyncRoot)
//{ //{
PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z); PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z);
m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
//} //}
} }
catch (Exception ex) catch (Exception ex)
@ -554,7 +554,7 @@ namespace OpenSim.Region.Environment.Scenes
if (usePhysics) if (usePhysics)
{ {
PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
Name, Name,
Shape, Shape,
new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
@ -1044,7 +1044,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
i += 46; i += 46;
//IsLocked = (data[i++] != 0) ? true : false; //IsLocked = (data[i++] != 0) ? true : false;
usePhysics = ((data[i++] != 0) && m_parentGroup.m_scene.m_physicalPrim) ? true : false; usePhysics = ((data[i++] != 0) && m_parentGroup.Scene.m_physicalPrim) ? true : false;
//System.Console.WriteLine("U" + packet.ToBytes().Length.ToString()); //System.Console.WriteLine("U" + packet.ToBytes().Length.ToString());
IsTemporary = (data[i++] != 0) ? true : false; IsTemporary = (data[i++] != 0) ? true : false;
IsPhantom = (data[i++] != 0) ? true : false; IsPhantom = (data[i++] != 0) ? true : false;
@ -1079,8 +1079,8 @@ namespace OpenSim.Region.Environment.Scenes
AddFlag(LLObject.ObjectFlags.Phantom); AddFlag(LLObject.ObjectFlags.Phantom);
if (PhysActor != null) if (PhysActor != null)
{ {
m_parentGroup.m_scene.PhysicsScene.RemovePrim(PhysActor); m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
/// that's not wholesome. Had to make m_scene public /// that's not wholesome. Had to make Scene public
PhysActor = null; PhysActor = null;
} }
} }
@ -1089,7 +1089,7 @@ namespace OpenSim.Region.Environment.Scenes
RemFlag(LLObject.ObjectFlags.Phantom); RemFlag(LLObject.ObjectFlags.Phantom);
if (PhysActor == null) if (PhysActor == null)
{ {
PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
Name, Name,
Shape, Shape,
new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
@ -1127,7 +1127,7 @@ namespace OpenSim.Region.Environment.Scenes
if (PhysActor.IsPhysical) if (PhysActor.IsPhysical)
{ {
if (!isNew) if (!isNew)
ParentGroup.m_scene.RemovePhysicalPrim(1); ParentGroup.Scene.RemovePhysicalPrim(1);
PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
@ -1135,14 +1135,14 @@ namespace OpenSim.Region.Environment.Scenes
PhysActor.IsPhysical = UsePhysics; PhysActor.IsPhysical = UsePhysics;
// If we're not what we're supposed to be in the physics scene, recreate ourselves. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
//m_parentGroup.m_scene.PhysicsScene.RemovePrim(PhysActor); //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
/// that's not wholesome. Had to make m_scene public /// that's not wholesome. Had to make Scene public
//PhysActor = null; //PhysActor = null;
if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
{ {
//PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( //PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
//Name, //Name,
//Shape, //Shape,
//new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, //new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
@ -1152,14 +1152,14 @@ namespace OpenSim.Region.Environment.Scenes
//RotationOffset.Y, RotationOffset.Z), UsePhysics); //RotationOffset.Y, RotationOffset.Z), UsePhysics);
if (UsePhysics) if (UsePhysics)
{ {
ParentGroup.m_scene.AddPhysicalPrim(1); ParentGroup.Scene.AddPhysicalPrim(1);
PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
PhysActor.OnOutOfBounds += PhysicsOutOfBounds; PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
} }
} }
} }
m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
} }
} }
@ -1517,7 +1517,7 @@ namespace OpenSim.Region.Environment.Scenes
MainLog.Instance.Verbose("PHYSICS", "Physical Object went out of bounds."); MainLog.Instance.Verbose("PHYSICS", "Physical Object went out of bounds.");
RemFlag(LLObject.ObjectFlags.Physics); RemFlag(LLObject.ObjectFlags.Physics);
DoPhysicsPropertyUpdate(false, true); DoPhysicsPropertyUpdate(false, true);
m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
} }
public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient) public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient)

View File

@ -243,7 +243,7 @@ namespace OpenSim.DataStore.MonoSqlite
/// Load persisted objects from region storage. /// Load persisted objects from region storage.
/// </summary> /// </summary>
/// <param name="regionUUID"></param> /// <param name="regionUUID"></param>
/// <returns></returns> /// <returns>List of loaded groups</returns>
public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
{ {
Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>(); Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>();