diff options
Added support for terrain map to be serialised to xml(as base64 binary). useful for places that the terrain map is needed in a serialised form. Also could add console commands to save and load from files, which should be faster than .raw files (these load/save commands are not included/implemented)
Add util functions to compress and uncompress strings.
Fixed a couple of modules so they use SceneCommunicationService rather than directly call functions on the CommsManager.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs index 1399960..53d03fc 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs | |||
@@ -27,6 +27,11 @@ | |||
27 | 27 | ||
28 | using OpenSim.Framework; | 28 | using OpenSim.Framework; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | using System; | ||
31 | using System.Text; | ||
32 | using System.Xml; | ||
33 | using System.IO; | ||
34 | using System.Xml.Serialization; | ||
30 | 35 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain | 36 | namespace OpenSim.Region.Environment.Modules.World.Terrain |
32 | { | 37 | { |
@@ -151,5 +156,75 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain | |||
151 | 156 | ||
152 | return copy; | 157 | return copy; |
153 | } | 158 | } |
159 | |||
160 | public string SaveToXmlString() | ||
161 | { | ||
162 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
163 | settings.Encoding = Encoding.UTF8; | ||
164 | using (StringWriter sw = new StringWriter()) | ||
165 | { | ||
166 | using (XmlWriter writer = XmlWriter.Create(sw, settings)) | ||
167 | { | ||
168 | WriteXml(writer); | ||
169 | } | ||
170 | string output = sw.ToString(); | ||
171 | return output; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | private void WriteXml(XmlWriter writer) | ||
176 | { | ||
177 | writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty); | ||
178 | ToXml(writer); | ||
179 | writer.WriteEndElement(); | ||
180 | } | ||
181 | |||
182 | public void LoadFromXmlString(string data) | ||
183 | { | ||
184 | StringReader sr = new StringReader(data); | ||
185 | XmlTextReader reader = new XmlTextReader(sr); | ||
186 | reader.Read(); | ||
187 | |||
188 | ReadXml(reader); | ||
189 | reader.Close(); | ||
190 | sr.Close(); | ||
191 | } | ||
192 | |||
193 | private void ReadXml(XmlReader reader) | ||
194 | { | ||
195 | reader.ReadStartElement("TerrainMap"); | ||
196 | FromXml(reader); | ||
197 | } | ||
198 | |||
199 | private void ToXml(XmlWriter xmlWriter) | ||
200 | { | ||
201 | float[] mapData = GetFloatsSerialised(); | ||
202 | byte[] buffer = new byte[mapData.Length * 4]; | ||
203 | for (int i = 0; i < mapData.Length; i++) | ||
204 | { | ||
205 | byte[] value = BitConverter.GetBytes(mapData[i]); | ||
206 | Array.Copy(value, 0, buffer, (i * 4), 4); | ||
207 | } | ||
208 | XmlSerializer serializer = new XmlSerializer(typeof(byte[])); | ||
209 | serializer.Serialize(xmlWriter, buffer); | ||
210 | } | ||
211 | |||
212 | private void FromXml(XmlReader xmlReader) | ||
213 | { | ||
214 | XmlSerializer serializer = new XmlSerializer(typeof(byte[])); | ||
215 | byte[] dataArray = (byte[])serializer.Deserialize(xmlReader); | ||
216 | int index = 0; | ||
217 | |||
218 | for (int y = 0; y < Height; y++) | ||
219 | { | ||
220 | for (int x = 0; x < Width; x++) | ||
221 | { | ||
222 | float value; | ||
223 | value = BitConverter.ToSingle(dataArray, index); | ||
224 | index += 4; | ||
225 | this[x, y] = (double)value; | ||
226 | } | ||
227 | } | ||
228 | } | ||
154 | } | 229 | } |
155 | } \ No newline at end of file | 230 | } \ No newline at end of file |