diff options
author | Melanie | 2011-04-17 18:48:53 +0100 |
---|---|---|
committer | Melanie | 2011-04-17 18:48:53 +0100 |
commit | 474910c9d624b53c010232ddb32b4002f58f1de0 (patch) | |
tree | 45ddab37c6afa0b095ffa0503640b9fe235bc400 /OpenSim/Region/Framework/Scenes/Serialization | |
parent | Merge branch 'master' into careminster-presence-refactor (diff) | |
parent | More descriptive debug msg for ServiceOSDRequest failures. (diff) | |
download | opensim-SC-474910c9d624b53c010232ddb32b4002f58f1de0.zip opensim-SC-474910c9d624b53c010232ddb32b4002f58f1de0.tar.gz opensim-SC-474910c9d624b53c010232ddb32b4002f58f1de0.tar.bz2 opensim-SC-474910c9d624b53c010232ddb32b4002f58f1de0.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs | 149 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | 25 |
2 files changed, 170 insertions, 4 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs new file mode 100644 index 0000000..babcb54 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Drawing; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Xml; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | |||
40 | namespace OpenSim.Region.Framework.Scenes.Serialization | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Serialize and deserialize coalesced scene objects. | ||
44 | /// </summary> | ||
45 | /// <remarks> | ||
46 | /// Deserialization not yet here. | ||
47 | /// </remarks> | ||
48 | public class CoalescedSceneObjectsSerializer | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | /// <summary> | ||
53 | /// Serialize coalesced objects to Xml | ||
54 | /// </summary> | ||
55 | /// <param name="coa"></param> | ||
56 | /// <returns></returns> | ||
57 | public static string ToXml(CoalescedSceneObjects coa) | ||
58 | { | ||
59 | using (StringWriter sw = new StringWriter()) | ||
60 | { | ||
61 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
62 | { | ||
63 | Vector3 size; | ||
64 | |||
65 | List<SceneObjectGroup> coaObjects = coa.Objects; | ||
66 | |||
67 | // m_log.DebugFormat( | ||
68 | // "[COALESCED SCENE OBJECTS SERIALIZER]: Writing {0} objects for coalesced object", | ||
69 | // coaObjects.Count); | ||
70 | |||
71 | // This is weak - we're relying on the set of coalesced objects still being identical | ||
72 | Vector3[] offsets = coa.GetSizeAndOffsets(out size); | ||
73 | |||
74 | writer.WriteStartElement("CoalescedObject"); | ||
75 | |||
76 | writer.WriteAttributeString("x", size.X.ToString()); | ||
77 | writer.WriteAttributeString("y", size.Y.ToString()); | ||
78 | writer.WriteAttributeString("z", size.Z.ToString()); | ||
79 | |||
80 | // Embed the offsets into the group XML | ||
81 | for (int i = 0; i < coaObjects.Count; i++) | ||
82 | { | ||
83 | SceneObjectGroup obj = coaObjects[i]; | ||
84 | |||
85 | // m_log.DebugFormat( | ||
86 | // "[COALESCED SCENE OBJECTS SERIALIZER]: Writing offset for object {0}, {1}", | ||
87 | // i, obj.Name); | ||
88 | |||
89 | writer.WriteStartElement("SceneObjectGroup"); | ||
90 | writer.WriteAttributeString("offsetx", offsets[i].X.ToString()); | ||
91 | writer.WriteAttributeString("offsety", offsets[i].Y.ToString()); | ||
92 | writer.WriteAttributeString("offsetz", offsets[i].Z.ToString()); | ||
93 | |||
94 | SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, true); | ||
95 | |||
96 | writer.WriteEndElement(); // SceneObjectGroup | ||
97 | } | ||
98 | |||
99 | writer.WriteEndElement(); // CoalescedObject | ||
100 | } | ||
101 | |||
102 | string output = sw.ToString(); | ||
103 | |||
104 | // Console.WriteLine(output); | ||
105 | |||
106 | return output; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | public static bool TryFromXml(string xml, out CoalescedSceneObjects coa) | ||
111 | { | ||
112 | // m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml); | ||
113 | |||
114 | coa = null; | ||
115 | |||
116 | using (StringReader sr = new StringReader(xml)) | ||
117 | { | ||
118 | using (XmlTextReader reader = new XmlTextReader(sr)) | ||
119 | { | ||
120 | reader.Read(); | ||
121 | if (reader.Name != "CoalescedObject") | ||
122 | { | ||
123 | // m_log.DebugFormat( | ||
124 | // "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false", | ||
125 | // reader.Name); | ||
126 | |||
127 | return false; | ||
128 | } | ||
129 | |||
130 | coa = new CoalescedSceneObjects(UUID.Zero); | ||
131 | reader.Read(); | ||
132 | |||
133 | while (reader.NodeType != XmlNodeType.EndElement && reader.Name != "CoalescedObject") | ||
134 | { | ||
135 | if (reader.Name == "SceneObjectGroup") | ||
136 | { | ||
137 | string soXml = reader.ReadOuterXml(); | ||
138 | coa.Add(SceneObjectSerializer.FromOriginalXmlFormat(soXml)); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | reader.ReadEndElement(); // CoalescedObject | ||
143 | } | ||
144 | } | ||
145 | |||
146 | return true; | ||
147 | } | ||
148 | } | ||
149 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index b2b3ad9..769d8a5 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | |||
@@ -139,6 +139,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
139 | return sw.ToString(); | 139 | return sw.ToString(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | |||
142 | 143 | ||
143 | /// <summary> | 144 | /// <summary> |
144 | /// Serialize a scene object to the original xml format | 145 | /// Serialize a scene object to the original xml format |
@@ -147,10 +148,24 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
147 | /// <returns></returns> | 148 | /// <returns></returns> |
148 | public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer) | 149 | public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer) |
149 | { | 150 | { |
151 | ToOriginalXmlFormat(sceneObject, writer, false); | ||
152 | } | ||
153 | |||
154 | /// <summary> | ||
155 | /// Serialize a scene object to the original xml format | ||
156 | /// </summary> | ||
157 | /// <param name="sceneObject"></param> | ||
158 | /// <param name="writer"></param> | ||
159 | /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param> | ||
160 | /// <returns></returns> | ||
161 | public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool noRootElement) | ||
162 | { | ||
150 | //m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name); | 163 | //m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name); |
151 | //int time = System.Environment.TickCount; | 164 | //int time = System.Environment.TickCount; |
152 | 165 | ||
153 | writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); | 166 | if (!noRootElement) |
167 | writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); | ||
168 | |||
154 | writer.WriteStartElement(String.Empty, "RootPart", String.Empty); | 169 | writer.WriteStartElement(String.Empty, "RootPart", String.Empty); |
155 | ToXmlFormat(sceneObject.RootPart, writer); | 170 | ToXmlFormat(sceneObject.RootPart, writer); |
156 | writer.WriteEndElement(); | 171 | writer.WriteEndElement(); |
@@ -170,10 +185,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
170 | 185 | ||
171 | writer.WriteEndElement(); // OtherParts | 186 | writer.WriteEndElement(); // OtherParts |
172 | sceneObject.SaveScriptedState(writer); | 187 | sceneObject.SaveScriptedState(writer); |
173 | writer.WriteEndElement(); // SceneObjectGroup | 188 | |
189 | if (!noRootElement) | ||
190 | writer.WriteEndElement(); // SceneObjectGroup | ||
174 | 191 | ||
175 | //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time); | 192 | //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time); |
176 | } | 193 | } |
177 | 194 | ||
178 | protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer) | 195 | protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer) |
179 | { | 196 | { |
@@ -1318,7 +1335,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
1318 | writer.WriteStartElement("SculptData"); | 1335 | writer.WriteStartElement("SculptData"); |
1319 | byte[] sd; | 1336 | byte[] sd; |
1320 | if (shp.SculptData != null) | 1337 | if (shp.SculptData != null) |
1321 | sd = shp.ExtraParams; | 1338 | sd = shp.SculptData; |
1322 | else | 1339 | else |
1323 | sd = Utils.EmptyBytes; | 1340 | sd = Utils.EmptyBytes; |
1324 | writer.WriteBase64(sd, 0, sd.Length); | 1341 | writer.WriteBase64(sd, 0, sd.Length); |