From d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 26 Jul 2010 21:09:54 +0100 Subject: relocate serialization code from SQLiteRegionData to MoapModule using load and save events. This is better modularity. It also allows MoapModule to be replaced with some other media module that may behave completely differently in the future. Remaining non-modularity: PrimitiveBaseShape needs explicit Media and MediaRaw fields. MediaRaw is required in order to shuttle the pre-serialization data back and forth from the database layer. The database also needs to know about MediaRaw though not about Media. IMO, it would be extremely nice to remove these hard codings but this is a bridge too far at the present time. --- .../CoreModules/World/Media/Moap/MoapModule.cs | 70 +++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs index 263ee57..0e03318 100644 --- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs +++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs @@ -32,6 +32,7 @@ using System.Collections.Specialized; using System.Reflection; using System.IO; using System.Web; +using System.Xml; using log4net; using Mono.Addins; using Nini.Config; @@ -46,6 +47,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; using Caps = OpenSim.Framework.Capabilities.Caps; +using OSDArray = OpenMetaverse.StructuredData.OSDArray; using OSDMap = OpenMetaverse.StructuredData.OSDMap; namespace OpenSim.Region.CoreModules.Media.Moap @@ -162,12 +164,76 @@ namespace OpenSim.Region.CoreModules.Media.Moap public void OnSceneObjectLoaded(SceneObjectGroup so) { m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID); + + so.ForEachPart(OnSceneObjectPartLoaded); } public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo) { - m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); - } + m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); + + persistingSo.ForEachPart(OnSceneObjectPartPreSave); + } + + protected void OnSceneObjectPartLoaded(SceneObjectPart part) + { + if (null == part.Shape.MediaRaw) + return; + + using (StringReader sr = new StringReader(part.Shape.MediaRaw)) + { + using (XmlTextReader xtr = new XmlTextReader(sr)) + { + xtr.ReadStartElement("osmedia"); + + OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); + + List mediaEntries = new List(); + foreach (OSD osdMe in osdMeArray) + { + MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); + mediaEntries.Add(me); + } + + xtr.ReadEndElement(); + + part.Shape.Media = mediaEntries; + } + } + } + + protected void OnSceneObjectPartPreSave(SceneObjectPart part) + { + if (null == part.Shape.Media) + return; + + using (StringWriter sw = new StringWriter()) + { + using (XmlTextWriter xtw = new XmlTextWriter(sw)) + { + xtw.WriteStartElement("osmedia"); + xtw.WriteAttributeString("type", "sl"); + xtw.WriteAttributeString("major_version", "0"); + xtw.WriteAttributeString("minor_version", "1"); + + OSDArray meArray = new OSDArray(); + foreach (MediaEntry me in part.Shape.Media) + { + OSD osd = (null == me ? new OSD() : me.GetOSD()); + meArray.Add(osd); + } + + xtw.WriteStartElement("osdata"); + xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); + xtw.WriteEndElement(); + + xtw.WriteEndElement(); + + xtw.Flush(); + part.Shape.MediaRaw = sw.ToString(); + } + } + } public MediaEntry GetMediaEntry(SceneObjectPart part, int face) { -- cgit v1.1