diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs | 114 |
1 files changed, 114 insertions, 0 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..a0e120a --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs | |||
@@ -0,0 +1,114 @@ | |||
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 | // TODO: Should probably return an empty xml serialization rather than a blank string | ||
60 | if (!coa.HasObjects) | ||
61 | return ""; | ||
62 | |||
63 | using (StringWriter sw = new StringWriter()) | ||
64 | { | ||
65 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
66 | { | ||
67 | Vector3 size; | ||
68 | |||
69 | List<SceneObjectGroup> coaObjects = coa.Objects; | ||
70 | |||
71 | // m_log.DebugFormat( | ||
72 | // "[COALESCED SCENE OBJECTS SERIALIZER]: Writing {0} objects for coalesced object", | ||
73 | // coaObjects.Count); | ||
74 | |||
75 | // This is weak - we're relying on the set of coalesced objects still being identical | ||
76 | Vector3[] offsets = coa.GetSizeAndOffsets(out size); | ||
77 | |||
78 | writer.WriteStartElement("CoalescedObject"); | ||
79 | |||
80 | writer.WriteAttributeString("x", size.X.ToString()); | ||
81 | writer.WriteAttributeString("y", size.Y.ToString()); | ||
82 | writer.WriteAttributeString("z", size.Z.ToString()); | ||
83 | |||
84 | // Embed the offsets into the group XML | ||
85 | for (int i = 0; i < coaObjects.Count; i++) | ||
86 | { | ||
87 | SceneObjectGroup obj = coaObjects[i]; | ||
88 | |||
89 | // m_log.DebugFormat( | ||
90 | // "[COALESCED SCENE OBJECTS SERIALIZER]: Writing offset for object {0}, {1}", | ||
91 | // i, obj.Name); | ||
92 | |||
93 | writer.WriteStartElement("SceneObjectGroup"); | ||
94 | writer.WriteAttributeString("offsetx", offsets[i].X.ToString()); | ||
95 | writer.WriteAttributeString("offsety", offsets[i].Y.ToString()); | ||
96 | writer.WriteAttributeString("offsetz", offsets[i].Z.ToString()); | ||
97 | |||
98 | SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, true); | ||
99 | |||
100 | writer.WriteEndElement(); // SceneObjectGroup | ||
101 | } | ||
102 | |||
103 | writer.WriteEndElement(); // CoalescedObject | ||
104 | } | ||
105 | |||
106 | string output = sw.ToString(); | ||
107 | |||
108 | // m_log.Debug(output); | ||
109 | |||
110 | return output; | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | } \ No newline at end of file | ||