From 3aee642190add7045f78e522ae7b2221b3566f1e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 18 Feb 2012 17:42:14 +0000 Subject: changed how vehicle data is stored and passed to physics. use unsafe in serializer, tried to control m_dupeInProgress --- OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs | 62 ++++- OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs | 294 +++++++++++++++++---- OpenSim/Region/Physics/Manager/PhysicsActor.cs | 5 +- OpenSim/Region/Physics/Manager/VehicleConstants.cs | 45 +++- 4 files changed, 347 insertions(+), 59 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs index 6e28bfa..2306309 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs @@ -22,7 +22,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Revised March 5th 2010 by Kitto Flora. ODEDynamics.cs + * Revised March 5th 2010 by Kitto Flora. ODEDynamics.cs + * Ubit 2012 * rolled into ODEPrim.cs */ @@ -38,7 +39,6 @@ using Ode.NET; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; - namespace OpenSim.Region.Physics.OdePlugin { /// @@ -254,6 +254,61 @@ namespace OpenSim.Region.Physics.OdePlugin private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor. SerialControl m_taintserial = null; + object m_taintvehicledata = null; + + public void DoSetVehicle() + { + VehicleData vd = (VehicleData)m_taintvehicledata; + + m_type = vd.m_type; + m_flags = vd.m_flags; + + // Linear properties + m_linearMotorDirection = vd.m_linearMotorDirection; + m_linearFrictionTimescale = vd.m_linearFrictionTimescale; + m_linearMotorDecayTimescale = vd.m_linearMotorDecayTimescale; + m_linearMotorTimescale = vd.m_linearMotorTimescale; +// m_linearMotorOffset = vd.m_linearMotorOffset; + + //Angular properties + m_angularMotorDirection = vd.m_angularMotorDirection; + m_angularMotorTimescale = vd.m_angularMotorTimescale; + m_angularMotorDecayTimescale = vd.m_angularMotorDecayTimescale; + m_angularFrictionTimescale = vd.m_angularFrictionTimescale; + + //Deflection properties +// m_angularDeflectionEfficiency = vd.m_angularDeflectionEfficiency; +// m_angularDeflectionTimescale = vd.m_angularDeflectionTimescale; +// m_linearDeflectionEfficiency = vd.m_linearDeflectionEfficiency; +// m_linearDeflectionTimescale = vd.m_linearDeflectionTimescale; + + //Banking properties +// m_bankingEfficiency = vd.m_bankingEfficiency; +// m_bankingMix = vd.m_bankingMix; +// m_bankingTimescale = vd.m_bankingTimescale; + + //Hover and Buoyancy properties + m_VhoverHeight = vd.m_VhoverHeight; +// m_VhoverEfficiency = vd.m_VhoverEfficiency; + m_VhoverTimescale = vd.m_VhoverTimescale; + m_VehicleBuoyancy = vd.m_VehicleBuoyancy; + + //Attractor properties + m_verticalAttractionEfficiency = vd.m_verticalAttractionEfficiency; + m_verticalAttractionTimescale = vd.m_verticalAttractionTimescale; + + // Axis +// m_referenceFrame = vd.m_referenceFrame; + + + m_taintvehicledata = null; + } + + public override void SetVehicle(object vdata) + { + m_taintvehicledata = vdata; + _parent_scene.AddPhysicsActorTaint(this); + } public override byte[] Serialize(bool PhysIsRunning) { @@ -1843,6 +1898,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (m_taintCollidesWater != m_collidesWater) changefloatonwater(timestep); + if (m_taintvehicledata != null) + DoSetVehicle(); + if (m_taintserial != null) DoSerialize(m_taintserial); diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs index edd58d3..e7e7bb3 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs @@ -1,5 +1,17 @@ -// adapted from libomv removing cpu endian adjust -// for prims lowlevel serialization +/* Ubit 2012 + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// no endian conversion. So can't be use to pass information around diferent cpus with diferent endian using System; using System.IO; @@ -7,77 +19,168 @@ using OpenMetaverse; namespace OpenSim.Region.Physics.OdePlugin { - public class wstreamer + + unsafe public class wstreamer { - private MemoryStream st; + byte[] buf; + int index; + byte* src; public wstreamer() { - st = new MemoryStream(); + buf = new byte[1024]; + index = 0; + } + public wstreamer(int size) + { + buf = new byte[size]; + index = 0; } public byte[] close() { - byte[] data = st.ToArray(); - st.Close(); + byte[] data = new byte[index]; + Buffer.BlockCopy(buf, 0, data, 0, index); return data; } + public void Seek(int pos) + { + index = pos; + } + + public void Seekrel(int pos) + { + index += pos; + } + + public void Wbyte(byte value) + { + buf[index++] = value; + } public void Wshort(short value) { - st.Write(BitConverter.GetBytes(value), 0, 2); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src; } public void Wushort(ushort value) { - byte[] t = BitConverter.GetBytes(value); - st.Write(BitConverter.GetBytes(value), 0, 2); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src; } public void Wint(int value) { - st.Write(BitConverter.GetBytes(value), 0, 4); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wuint(uint value) { - st.Write(BitConverter.GetBytes(value), 0, 4); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wlong(long value) { - st.Write(BitConverter.GetBytes(value), 0, 8); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wulong(ulong value) { - st.Write(BitConverter.GetBytes(value), 0, 8); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wfloat(float value) { - st.Write(BitConverter.GetBytes(value), 0, 4); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wdouble(double value) { - st.Write(BitConverter.GetBytes(value), 0, 8); + src = (byte*)&value; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wvector3(Vector3 value) { - st.Write(BitConverter.GetBytes(value.X), 0, 4); - st.Write(BitConverter.GetBytes(value.Y), 0, 4); - st.Write(BitConverter.GetBytes(value.Z), 0, 4); + src = (byte*)&value.X; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; + src = (byte*)&value.Y; // it may have padding ?? + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; + src = (byte*)&value.Z; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } public void Wquat(Quaternion value) { - st.Write(BitConverter.GetBytes(value.X), 0, 4); - st.Write(BitConverter.GetBytes(value.Y), 0, 4); - st.Write(BitConverter.GetBytes(value.Z), 0, 4); - st.Write(BitConverter.GetBytes(value.W), 0, 4); + src = (byte*)&value.X; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; + src = (byte*)&value.Y; // it may have padding ?? + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; + src = (byte*)&value.Z; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; + src = (byte*)&value.W; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src++; + buf[index++] = *src; } } - public class rstreamer + unsafe public class rstreamer { private byte[] rbuf; private int ptr; + private byte* dst; public rstreamer(byte[] data) { @@ -89,78 +192,161 @@ namespace OpenSim.Region.Physics.OdePlugin { } + public void Seek(int pos) + { + ptr = pos; + } + + public void Seekrel(int pos) + { + ptr += pos; + } + + public byte Rbyte() + { + return (byte)rbuf[ptr++]; + } + public short Rshort() { - short v = BitConverter.ToInt16(rbuf, ptr); - ptr += 2; + short v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public ushort Rushort() { - ushort v = BitConverter.ToUInt16(rbuf, ptr); - ptr += 2; + ushort v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public int Rint() { - int v = BitConverter.ToInt32(rbuf, ptr); - ptr += 4; + int v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public uint Ruint() { - uint v = BitConverter.ToUInt32(rbuf, ptr); - ptr += 4; + uint v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public long Rlong() { - long v = BitConverter.ToInt64(rbuf, ptr); - ptr += 8; + long v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public ulong Rulong() { - ulong v = BitConverter.ToUInt64(rbuf, ptr); - ptr += 8; + ulong v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public float Rfloat() { - float v = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; + float v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public double Rdouble() { - double v = BitConverter.ToDouble(rbuf, ptr); - ptr += 8; + double v; + dst = (byte*)&v; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } public Vector3 Rvector3() { Vector3 v; - v.X = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; - v.Y = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; - v.Z = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; + dst = (byte*)&v.X; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + + dst = (byte*)&v.Y; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + + dst = (byte*)&v.Z; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; return v; } + public Quaternion Rquat() { Quaternion v; - v.X = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; - v.Y = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; - v.Z = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; - v.W = BitConverter.ToSingle(rbuf, ptr); - ptr += 4; + dst = (byte*)&v.X; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + + dst = (byte*)&v.Y; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + + dst = (byte*)&v.Z; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + + dst = (byte*)&v.W; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst++ = rbuf[ptr++]; + *dst = rbuf[ptr++]; + return v; } } diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index eb0228a..f525e9e 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -146,6 +146,8 @@ namespace OpenSim.Region.Physics.Manager /// public event CollisionUpdate OnCollisionUpdate; + public virtual void SetVehicle(object vdata) { } + public event OutOfBounds OnOutOfBounds; #pragma warning restore 67 @@ -153,8 +155,7 @@ namespace OpenSim.Region.Physics.Manager { get { return new NullPhysicsActor(); } } - - + public virtual bool Building { get; set; } public virtual ContactData ContactData diff --git a/OpenSim/Region/Physics/Manager/VehicleConstants.cs b/OpenSim/Region/Physics/Manager/VehicleConstants.cs index f0775c1..8e24b4c 100644 --- a/OpenSim/Region/Physics/Manager/VehicleConstants.cs +++ b/OpenSim/Region/Physics/Manager/VehicleConstants.cs @@ -26,6 +26,7 @@ */ using System; +using OpenMetaverse; namespace OpenSim.Region.Physics.Manager { @@ -117,5 +118,47 @@ namespace OpenSim.Region.Physics.Manager NO_DEFLECTION = 16392, LOCK_ROTATION = 32784 } - + + public struct VehicleData + { + public Vehicle m_type; + public VehicleFlag m_flags; + + // Linear properties + public Vector3 m_linearMotorDirection; + public Vector3 m_linearFrictionTimescale; + public float m_linearMotorDecayTimescale; + public float m_linearMotorTimescale; + public Vector3 m_linearMotorOffset; + + //Angular properties + public Vector3 m_angularMotorDirection; + public float m_angularMotorTimescale; + public float m_angularMotorDecayTimescale; + public Vector3 m_angularFrictionTimescale; + + //Deflection properties + public float m_angularDeflectionEfficiency; + public float m_angularDeflectionTimescale; + public float m_linearDeflectionEfficiency; + public float m_linearDeflectionTimescale; + + //Banking properties + public float m_bankingEfficiency; + public float m_bankingMix; + public float m_bankingTimescale; + + //Hover and Buoyancy properties + public float m_VhoverHeight; + public float m_VhoverEfficiency; + public float m_VhoverTimescale; + public float m_VehicleBuoyancy; + + //Attractor properties + public float m_verticalAttractionEfficiency; + public float m_verticalAttractionTimescale; + + // Axis + public Quaternion m_referenceFrame; + } } -- cgit v1.1