* Removed ComponentState class
* We now store component state information as a OSDMapsoprefactor
parent
13079df156
commit
daa0d83e3a
|
@ -3,6 +3,7 @@ using System.Reflection;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Mono.Addins;
|
using Mono.Addins;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using OpenSim.Region.Framework.Scenes.Components;
|
using OpenSim.Region.Framework.Scenes.Components;
|
||||||
|
@ -60,7 +61,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Components
|
||||||
|
|
||||||
#region Implementation of IComponentManagerModule
|
#region Implementation of IComponentManagerModule
|
||||||
|
|
||||||
public void CreateComponent(SceneObjectPart target, string componentType, ComponentState state)
|
public void CreateComponent(SceneObjectPart target, string componentType, OSDMap state)
|
||||||
{
|
{
|
||||||
if (OnCreateComponent != null)
|
if (OnCreateComponent != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using OpenSim.Region.Framework.Scenes.Components;
|
using OpenSim.Region.Framework.Scenes.Components;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Interfaces
|
namespace OpenSim.Region.Framework.Interfaces
|
||||||
{
|
{
|
||||||
public delegate IComponent OnCreateComponentDelegate(string componentType, ComponentState componentState);
|
public delegate IComponent OnCreateComponentDelegate(string componentType, OSDMap componentState);
|
||||||
|
|
||||||
public interface IComponentManagerModule
|
public interface IComponentManagerModule
|
||||||
{
|
{
|
||||||
void CreateComponent(SceneObjectPart part, string componentType, ComponentState state);
|
void CreateComponent(SceneObjectPart part, string componentType, OSDMap state);
|
||||||
event OnCreateComponentDelegate OnCreateComponent;
|
event OnCreateComponentDelegate OnCreateComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Scenes.Components
|
namespace OpenSim.Region.Framework.Scenes.Components
|
||||||
|
@ -11,6 +12,6 @@ namespace OpenSim.Region.Framework.Scenes.Components
|
||||||
cmm.OnCreateComponent += CreateComponent;
|
cmm.OnCreateComponent += CreateComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract IComponent CreateComponent(string componentType, ComponentState componentState);
|
protected abstract IComponent CreateComponent(string componentType, OSDMap componentState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Scenes.Components
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public class ComponentState
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string,Object> m_stateData = new Dictionary<string,object>();
|
|
||||||
|
|
||||||
public void Set<T>(string name, T data)
|
|
||||||
{
|
|
||||||
if (typeof(T).IsSerializable)
|
|
||||||
{
|
|
||||||
m_stateData[name] = data;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new SerializationException("Unable to set " + name + " as value because " + typeof (T) +
|
|
||||||
" is not a serializable type.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGet<T>(string name, out T val)
|
|
||||||
{
|
|
||||||
Object x;
|
|
||||||
if(m_stateData.TryGetValue(name, out x))
|
|
||||||
{
|
|
||||||
if(x is T)
|
|
||||||
{
|
|
||||||
val = (T)x;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val = default(T);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Get<T>(string name)
|
|
||||||
{
|
|
||||||
return (T) m_stateData[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Serialise()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Scenes.Components
|
namespace OpenSim.Region.Framework.Scenes.Components
|
||||||
{
|
{
|
||||||
|
@ -16,7 +17,7 @@ namespace OpenSim.Region.Framework.Scenes.Components
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A representation of the current state of the component, to be deserialised later.
|
/// A representation of the current state of the component, to be deserialised later.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ComponentState State { get; }
|
OSDMap State { get; }
|
||||||
|
|
||||||
void SetParent(SceneObjectPart part);
|
void SetParent(SceneObjectPart part);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ using System.Xml.Serialization;
|
||||||
using log4net;
|
using log4net;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenMetaverse.Packets;
|
using OpenMetaverse.Packets;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes.Components;
|
using OpenSim.Region.Framework.Scenes.Components;
|
||||||
|
@ -4806,7 +4807,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
[NonSerializedAttribute] // Component serialisation occurs manually.
|
[NonSerializedAttribute] // Component serialisation occurs manually.
|
||||||
private Dictionary<string, IComponent> m_components = new Dictionary<string, IComponent>();
|
private Dictionary<string, IComponent> m_components = new Dictionary<string, IComponent>();
|
||||||
|
|
||||||
public SerializableDictionary<string, ComponentState> ComponentStates = new SerializableDictionary<string, ComponentState>();
|
public SerializableDictionary<string, string> ComponentStates = new SerializableDictionary<string, string>();
|
||||||
|
|
||||||
[NonSerializedAttribute]
|
[NonSerializedAttribute]
|
||||||
private bool m_componentsInit = false;
|
private bool m_componentsInit = false;
|
||||||
|
@ -4816,12 +4817,19 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if(m_componentsInit)
|
if(m_componentsInit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SerializableDictionary<string, ComponentState> states = ComponentStates;
|
Dictionary<string,OSDMap> states = new Dictionary<string, OSDMap>();
|
||||||
|
foreach (KeyValuePair<string, string> componentState in ComponentStates)
|
||||||
|
{
|
||||||
|
states.Add(componentState.Key, OSDParser.DeserializeJson(componentState.Value) as OSDMap);
|
||||||
|
}
|
||||||
|
//SerializableDictionary<string, OSDMap> states = ComponentStates;
|
||||||
|
|
||||||
|
|
||||||
if(ParentGroup.Scene != null)
|
if(ParentGroup.Scene != null)
|
||||||
{
|
{
|
||||||
m_log.Info("[COMPONENTS] Initialising components...");
|
m_log.Info("[COMPONENTS] Initialising components...");
|
||||||
IComponentManagerModule cmm = ParentGroup.Scene.RequestModuleInterface<IComponentManagerModule>();
|
IComponentManagerModule cmm = ParentGroup.Scene.RequestModuleInterface<IComponentManagerModule>();
|
||||||
foreach(KeyValuePair<string,ComponentState> kvp in states)
|
foreach (KeyValuePair<string, OSDMap> kvp in states)
|
||||||
{
|
{
|
||||||
m_log.Info("[COMPONENTS] Adding component " + kvp.Key + " to SceneObjectPart.");
|
m_log.Info("[COMPONENTS] Adding component " + kvp.Key + " to SceneObjectPart.");
|
||||||
|
|
||||||
|
@ -4847,12 +4855,12 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
m_log.Info("[COMPONENTS] Saving components...");
|
m_log.Info("[COMPONENTS] Saving components...");
|
||||||
foreach (KeyValuePair<string, IComponent> keyValuePair in m_components)
|
foreach (KeyValuePair<string, IComponent> keyValuePair in m_components)
|
||||||
{
|
{
|
||||||
ComponentState state = keyValuePair.Value.State;
|
OSDMap state = keyValuePair.Value.State;
|
||||||
string baseType = keyValuePair.Value.BaseType.ToString();
|
string baseType = keyValuePair.Value.BaseType.ToString();
|
||||||
|
|
||||||
m_log.Info("[COMPONENTS] Saving component " + baseType);
|
m_log.Info("[COMPONENTS] Saving component " + baseType);
|
||||||
|
|
||||||
ComponentStates[baseType] = state;
|
ComponentStates[baseType] = OSDParser.SerializeJsonString(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using OpenSim.Region.Framework.Scenes.Components;
|
using OpenSim.Region.Framework.Scenes.Components;
|
||||||
|
|
||||||
|
@ -18,7 +19,12 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
||||||
|
|
||||||
#region Implementation of IComponent
|
#region Implementation of IComponent
|
||||||
|
|
||||||
public TestComponent(ComponentState state)
|
public TestComponent()
|
||||||
|
{
|
||||||
|
m_log.Info("Its alive! (for the very first time...!)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestComponent(OSDMap state)
|
||||||
{
|
{
|
||||||
m_log.Info("Its alive!");
|
m_log.Info("Its alive!");
|
||||||
}
|
}
|
||||||
|
@ -28,13 +34,14 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
||||||
get { return typeof (TestComponent); }
|
get { return typeof (TestComponent); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComponentState State
|
public OSDMap State
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ComponentState x = new ComponentState();
|
OSDMap x = new OSDMap();
|
||||||
x.Set("Hello","World");
|
x["Hello"] = "World";
|
||||||
x.Set("HitchhikersReference", m_theAnswerToTheQuestionOfLifeTheUniverseAndEverything);
|
x["HitchhikersReference"] = m_theAnswerToTheQuestionOfLifeTheUniverseAndEverything;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Reflection;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Mono.Addins;
|
using Mono.Addins;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using OpenSim.Region.Framework.Scenes.Components;
|
using OpenSim.Region.Framework.Scenes.Components;
|
||||||
|
@ -20,15 +21,14 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
||||||
|
|
||||||
#region Overrides of ComponentFactory
|
#region Overrides of ComponentFactory
|
||||||
|
|
||||||
protected override IComponent CreateComponent(string componentType, ComponentState componentState)
|
protected override IComponent CreateComponent(string componentType, OSDMap componentState)
|
||||||
{
|
{
|
||||||
m_log.Info("[TestComponentFactory] Recieved CreateComponent for " + componentType);
|
m_log.Info("[TestComponentFactory] Recieved CreateComponent for " + componentType);
|
||||||
if(componentType == typeof(TestComponent).ToString())
|
if(componentType == typeof(TestComponent).ToString())
|
||||||
{
|
{
|
||||||
string tmp;
|
if(componentState.ContainsKey("Hello"))
|
||||||
if(componentState.TryGet("Hello", out tmp))
|
|
||||||
{
|
{
|
||||||
m_log.Info("[TestComponentFactory] Successfully recovered '" + tmp + "' from a component via serialisation.");
|
m_log.Info("[TestComponentFactory] Successfully recovered '" + componentState["Hello"] + "' from a component via serialisation.");
|
||||||
}
|
}
|
||||||
return new TestComponent(componentState);
|
return new TestComponent(componentState);
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,7 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
||||||
foreach (SceneObjectPart part in sog.GetParts())
|
foreach (SceneObjectPart part in sog.GetParts())
|
||||||
{
|
{
|
||||||
m_log.Info("[TESTCOMPONENT] Adding new test component to SOP");
|
m_log.Info("[TESTCOMPONENT] Adding new test component to SOP");
|
||||||
part.SetComponent(
|
part.SetComponent(new TestComponent());
|
||||||
new TestComponent(
|
|
||||||
new ComponentState()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue