Add saving vehicle physics data to the database

avinationmerge
Melanie 2012-07-07 02:05:01 +02:00
parent ce7864632b
commit 6535f23e4b
4 changed files with 73 additions and 27 deletions

View File

@ -175,7 +175,8 @@ namespace OpenSim.Data.MySQL
"PassCollisions, " +
"LinkNumber, MediaURL, KeyframeMotion, " +
"PhysicsShapeType, Density, GravityModifier, " +
"Friction, Restitution) values (" + "?UUID, " +
"Friction, Restitution, Vehicle " +
") values (" + "?UUID, " +
"?CreationDate, ?Name, ?Text, " +
"?Description, ?SitName, ?TouchName, " +
"?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
@ -209,7 +210,7 @@ namespace OpenSim.Data.MySQL
"?CollisionSoundVolume, ?PassTouches, ?PassCollisions, " +
"?LinkNumber, ?MediaURL, ?KeyframeMotion, " +
"?PhysicsShapeType, ?Density, ?GravityModifier, " +
"?Friction, ?Restitution)";
"?Friction, ?Restitution, ?Vehicle)";
FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
@ -1258,6 +1259,15 @@ namespace OpenSim.Data.MySQL
prim.GravityModifier = (float)(double)row["GravityModifier"];
prim.Friction = (float)(double)row["Friction"];
prim.Bounciness = (float)(double)row["Restitution"];
SOPVehicle vehicle = null;
if (row["Vehicle"].ToString() != String.Empty)
{
vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
if (vehicle != null)
prim.VehicleParams = vehicle;
}
return prim;
}
@ -1635,6 +1645,11 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("GravityModifier", (double)prim.GravityModifier);
cmd.Parameters.AddWithValue("Friction", (double)prim.Friction);
cmd.Parameters.AddWithValue("Restitution", (double)prim.Bounciness);
if (prim.VehicleParams != null)
{
cmd.Parameters.AddWithValue("Vehicle", prim.VehicleParams.ToXml2());
}
}
/// <summary>

View File

@ -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();
}
}
}
}

View File

@ -338,7 +338,7 @@ namespace OpenSim.Region.Framework.Scenes
private int LastColSoundSentTime;
private SOPVehicle m_vehicle = null;
private SOPVehicle m_vehicleParams = null;
private KeyframeMotion m_keyframeMotion = null;
@ -3379,15 +3379,15 @@ namespace OpenSim.Region.Framework.Scenes
Force = force;
}
public SOPVehicle sopVehicle
public SOPVehicle VehicleParams
{
get
{
return m_vehicle;
return m_vehicleParams;
}
set
{
m_vehicle = value;
m_vehicleParams = value;
}
}
@ -3396,10 +3396,10 @@ namespace OpenSim.Region.Framework.Scenes
{
get
{
if (m_vehicle == null)
if (m_vehicleParams == null)
return (int)Vehicle.TYPE_NONE;
else
return (int)m_vehicle.Type;
return (int)m_vehicleParams.Type;
}
set
{
@ -3409,7 +3409,7 @@ namespace OpenSim.Region.Framework.Scenes
public void SetVehicleType(int type)
{
m_vehicle = null;
m_vehicleParams = null;
if (type == (int)Vehicle.TYPE_NONE)
{
@ -3417,8 +3417,8 @@ namespace OpenSim.Region.Framework.Scenes
PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
return;
}
m_vehicle = new SOPVehicle();
m_vehicle.ProcessTypeChange((Vehicle)type);
m_vehicleParams = new SOPVehicle();
m_vehicleParams.ProcessTypeChange((Vehicle)type);
{
if (_parentID ==0 && PhysActor != null)
PhysActor.VehicleType = type;
@ -3428,10 +3428,10 @@ namespace OpenSim.Region.Framework.Scenes
public void SetVehicleFlags(int param, bool remove)
{
if (m_vehicle == null)
if (m_vehicleParams == null)
return;
m_vehicle.ProcessVehicleFlags(param, remove);
m_vehicleParams.ProcessVehicleFlags(param, remove);
if (_parentID ==0 && PhysActor != null)
{
@ -3441,10 +3441,10 @@ namespace OpenSim.Region.Framework.Scenes
public void SetVehicleFloatParam(int param, float value)
{
if (m_vehicle == null)
if (m_vehicleParams == null)
return;
m_vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
if (_parentID == 0 && PhysActor != null)
{
@ -3454,10 +3454,10 @@ namespace OpenSim.Region.Framework.Scenes
public void SetVehicleVectorParam(int param, Vector3 value)
{
if (m_vehicle == null)
if (m_vehicleParams == null)
return;
m_vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
if (_parentID == 0 && PhysActor != null)
{
@ -3467,10 +3467,10 @@ namespace OpenSim.Region.Framework.Scenes
public void SetVehicleRotationParam(int param, Quaternion rotation)
{
if (m_vehicle == null)
if (m_vehicleParams == null)
return;
m_vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
if (_parentID == 0 && PhysActor != null)
{
@ -4637,8 +4637,8 @@ namespace OpenSim.Region.Framework.Scenes
if (VolumeDetectActive) // change if not the default only
pa.SetVolumeDetect(1);
if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
m_vehicle.SetVehicle(pa);
if (m_vehicleParams != null && LocalId == ParentGroup.RootPart.LocalId)
m_vehicleParams.SetVehicle(pa);
// we are going to tell rest of code about physics so better have this here
PhysActor = pa;
@ -4676,7 +4676,7 @@ namespace OpenSim.Region.Framework.Scenes
pa.RotationalVelocity = rotationalVelocity;
// if not vehicle and root part apply force and torque
if ((m_vehicle == null || m_vehicle.Type == Vehicle.TYPE_NONE)
if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE)
&& LocalId == ParentGroup.RootPart.LocalId)
{
pa.Force = Force;

View File

@ -630,13 +630,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
if (errors)
{
obj.sopVehicle = null;
obj.VehicleParams = null;
m_log.DebugFormat(
"[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
obj.Name, obj.UUID);
}
else
obj.sopVehicle = _vehicle;
obj.VehicleParams = _vehicle;
}
private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader)
@ -1325,8 +1325,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
if (sop.sopVehicle != null)
sop.sopVehicle.ToXml2(writer);
if (sop.VehicleParams != null)
sop.VehicleParams.ToXml2(writer);
if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType())
writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());