From 6535f23e4b8fec9578dae5275db69b237a99e498 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 7 Jul 2012 02:05:01 +0200 Subject: Add saving vehicle physics data to the database --- OpenSim/Region/Framework/Scenes/SOPVehicle.cs | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework/Scenes/SOPVehicle.cs') diff --git a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs index d3c2d27..45ca00c 100644 --- a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs +++ b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs @@ -30,6 +30,8 @@ using System.Collections.Generic; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; +using System.Text; +using System.IO; using System.Xml; using OpenSim.Framework.Serialization; using OpenSim.Framework.Serialization.External; @@ -561,6 +563,35 @@ namespace OpenSim.Region.Framework.Scenes } + public string ToXml2() + { + MemoryStream ms = new MemoryStream(); + UTF8Encoding enc = new UTF8Encoding(); + XmlTextWriter writer = new XmlTextWriter(ms, null); + ToXml2(writer); + return enc.GetString(ms.ToArray()); + } + + public static SOPVehicle FromXml2(string text) + { + if (text == String.Empty) + return null; + UTF8Encoding enc = new UTF8Encoding(); + MemoryStream ms = new MemoryStream(enc.GetBytes(text)); + XmlTextReader reader = new XmlTextReader(ms); + + SOPVehicle v = new SOPVehicle(); + bool error; + + v.FromXml2(reader, out error); + if (error) + { + v = null; + return null; + } + + return v; + } public void FromXml2(XmlTextReader _reader, out bool errors) { @@ -739,4 +770,4 @@ namespace OpenSim.Region.Framework.Scenes vd.m_referenceFrame = XRquat(); } } -} \ No newline at end of file +} -- cgit v1.1 From afa02aa104e0cfbedd0e1b6c1d7b60522a79a4e8 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 7 Jul 2012 07:41:11 +0100 Subject: fix vehicle to XML string --- OpenSim/Region/Framework/Scenes/SOPVehicle.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/SOPVehicle.cs') diff --git a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs index 45ca00c..e2ef77b 100644 --- a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs +++ b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs @@ -565,31 +565,37 @@ namespace OpenSim.Region.Framework.Scenes public string ToXml2() { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new MemoryStream(512); UTF8Encoding enc = new UTF8Encoding(); - XmlTextWriter writer = new XmlTextWriter(ms, null); - ToXml2(writer); - return enc.GetString(ms.ToArray()); + XmlTextWriter xwriter = new XmlTextWriter(ms, enc); + ToXml2(xwriter); + xwriter.Flush(); + string s = ms.GetStreamString(); + xwriter.Close(); + return s; } public static SOPVehicle FromXml2(string text) { if (text == String.Empty) return null; + UTF8Encoding enc = new UTF8Encoding(); MemoryStream ms = new MemoryStream(enc.GetBytes(text)); - XmlTextReader reader = new XmlTextReader(ms); + XmlTextReader xreader = new XmlTextReader(ms); SOPVehicle v = new SOPVehicle(); bool error; - v.FromXml2(reader, out error); + v.FromXml2(xreader, out error); + + xreader.Close(); + if (error) { v = null; return null; } - return v; } -- cgit v1.1 From 470019b52a72de1a8777933ce3254cde87e184f9 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 7 Jul 2012 19:59:55 +0200 Subject: Change semantics of FromXML on vehicle data to make the serializer a bit cleaner --- OpenSim/Region/Framework/Scenes/SOPVehicle.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework/Scenes/SOPVehicle.cs') diff --git a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs index e2ef77b..41e8944 100644 --- a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs +++ b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs @@ -599,7 +599,20 @@ namespace OpenSim.Region.Framework.Scenes return v; } - public void FromXml2(XmlTextReader _reader, out bool errors) + public static SOPVehicle FromXml2(XmlTextReader reader) + { + SOPVehicle vehicle = new SOPVehicle(); + + bool errors = false; + + vehicle.FromXml2(reader, out errors); + if (errors) + return null; + + return vehicle; + } + + private void FromXml2(XmlTextReader _reader, out bool errors) { errors = false; reader = _reader; -- cgit v1.1