diff options
author | Oren Hurvitz | 2013-11-18 12:48:23 +0200 |
---|---|---|
committer | Oren Hurvitz | 2014-03-24 18:17:35 +0100 |
commit | 5fd94111434c2faa742d4eb7357d7a6b02253988 (patch) | |
tree | ee9272cc38a1d2a2afcd6c0b85c38dccc6449315 /OpenSim/Region/Framework/Scenes/Serialization | |
parent | HGAssetService searches for the "HomeURI" setting in several sections: Startu... (diff) | |
download | opensim-SC-5fd94111434c2faa742d4eb7357d7a6b02253988.zip opensim-SC-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.gz opensim-SC-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.bz2 opensim-SC-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.xz |
Refactored Load IAR: created a generic mechanism to modify the SOG's as they are being loaded
Resolves http://opensimulator.org/mantis/view.php?id=6942
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 4deca00..a93f3c8 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | |||
@@ -299,6 +299,73 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | |||
303 | /// <summary> | ||
304 | /// Modifies a SceneObjectGroup. | ||
305 | /// </summary> | ||
306 | /// <param name="sog">The object</param> | ||
307 | /// <returns>Whether the object was actually modified</returns> | ||
308 | public delegate bool SceneObjectModifier(SceneObjectGroup sog); | ||
309 | |||
310 | /// <summary> | ||
311 | /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing. | ||
312 | /// </summary> | ||
313 | /// <param name="assetId">The object's UUID</param> | ||
314 | /// <param name="data">Serialized data</param> | ||
315 | /// <param name="modifier">The function to run on each SceneObjectGroup</param> | ||
316 | /// <returns>The new serialized object's data, or null if an error occurred</returns> | ||
317 | public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier) | ||
318 | { | ||
319 | List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); | ||
320 | CoalescedSceneObjects coa = null; | ||
321 | |||
322 | string xmlData = Utils.BytesToString(data); | ||
323 | |||
324 | if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) | ||
325 | { | ||
326 | // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); | ||
327 | |||
328 | if (coa.Objects.Count == 0) | ||
329 | { | ||
330 | m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId); | ||
331 | return null; | ||
332 | } | ||
333 | |||
334 | sceneObjects.AddRange(coa.Objects); | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData); | ||
339 | |||
340 | if (deserializedObject != null) | ||
341 | { | ||
342 | sceneObjects.Add(deserializedObject); | ||
343 | } | ||
344 | else | ||
345 | { | ||
346 | m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId); | ||
347 | return null; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | bool modified = false; | ||
352 | foreach (SceneObjectGroup sog in sceneObjects) | ||
353 | { | ||
354 | if (modifier(sog)) | ||
355 | modified = true; | ||
356 | } | ||
357 | |||
358 | if (modified) | ||
359 | { | ||
360 | if (coa != null) | ||
361 | data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa)); | ||
362 | else | ||
363 | data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0])); | ||
364 | } | ||
365 | |||
366 | return data; | ||
367 | } | ||
368 | |||
302 | 369 | ||
303 | #region manual serialization | 370 | #region manual serialization |
304 | 371 | ||