* 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 Mono.Addins;
|
||||
using Nini.Config;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes.Components;
|
||||
|
@ -60,7 +61,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Components
|
|||
|
||||
#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)
|
||||
{
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
using System;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes.Components;
|
||||
|
||||
namespace OpenSim.Region.Framework.Interfaces
|
||||
{
|
||||
public delegate IComponent OnCreateComponentDelegate(string componentType, ComponentState componentState);
|
||||
public delegate IComponent OnCreateComponentDelegate(string componentType, OSDMap componentState);
|
||||
|
||||
public interface IComponentManagerModule
|
||||
{
|
||||
void CreateComponent(SceneObjectPart part, string componentType, ComponentState state);
|
||||
void CreateComponent(SceneObjectPart part, string componentType, OSDMap state);
|
||||
event OnCreateComponentDelegate OnCreateComponent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
|
||||
namespace OpenSim.Region.Framework.Scenes.Components
|
||||
|
@ -11,6 +12,6 @@ namespace OpenSim.Region.Framework.Scenes.Components
|
|||
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 OpenMetaverse.StructuredData;
|
||||
|
||||
namespace OpenSim.Region.Framework.Scenes.Components
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace OpenSim.Region.Framework.Scenes.Components
|
|||
/// <summary>
|
||||
/// A representation of the current state of the component, to be deserialised later.
|
||||
/// </summary>
|
||||
ComponentState State { get; }
|
||||
OSDMap State { get; }
|
||||
|
||||
void SetParent(SceneObjectPart part);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ using System.Xml.Serialization;
|
|||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Packets;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes.Components;
|
||||
|
@ -4806,7 +4807,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
[NonSerializedAttribute] // Component serialisation occurs manually.
|
||||
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]
|
||||
private bool m_componentsInit = false;
|
||||
|
@ -4816,12 +4817,19 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
if(m_componentsInit)
|
||||
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)
|
||||
{
|
||||
m_log.Info("[COMPONENTS] Initialising components...");
|
||||
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.");
|
||||
|
||||
|
@ -4847,12 +4855,12 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
m_log.Info("[COMPONENTS] Saving 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();
|
||||
|
||||
m_log.Info("[COMPONENTS] Saving component " + baseType);
|
||||
|
||||
ComponentStates[baseType] = state;
|
||||
ComponentStates[baseType] = OSDParser.SerializeJsonString(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes.Components;
|
||||
|
||||
|
@ -18,7 +19,12 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
|||
|
||||
#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!");
|
||||
}
|
||||
|
@ -28,13 +34,14 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
|||
get { return typeof (TestComponent); }
|
||||
}
|
||||
|
||||
public ComponentState State
|
||||
public OSDMap State
|
||||
{
|
||||
get
|
||||
{
|
||||
ComponentState x = new ComponentState();
|
||||
x.Set("Hello","World");
|
||||
x.Set("HitchhikersReference", m_theAnswerToTheQuestionOfLifeTheUniverseAndEverything);
|
||||
OSDMap x = new OSDMap();
|
||||
x["Hello"] = "World";
|
||||
x["HitchhikersReference"] = m_theAnswerToTheQuestionOfLifeTheUniverseAndEverything;
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Reflection;
|
|||
using log4net;
|
||||
using Mono.Addins;
|
||||
using Nini.Config;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes.Components;
|
||||
|
@ -20,15 +21,14 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
|||
|
||||
#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);
|
||||
if(componentType == typeof(TestComponent).ToString())
|
||||
{
|
||||
string tmp;
|
||||
if(componentState.TryGet("Hello", out tmp))
|
||||
if(componentState.ContainsKey("Hello"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -89,11 +89,7 @@ namespace OpenSim.Region.OptionalModules.World.TestComponent
|
|||
foreach (SceneObjectPart part in sog.GetParts())
|
||||
{
|
||||
m_log.Info("[TESTCOMPONENT] Adding new test component to SOP");
|
||||
part.SetComponent(
|
||||
new TestComponent(
|
||||
new ComponentState()
|
||||
)
|
||||
);
|
||||
part.SetComponent(new TestComponent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue