From 2cd927bb14a19c1899dbc3287523106dedb06030 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sun, 22 Apr 2012 19:51:51 +0100 Subject: [PATCH] Fix bug where setting phantom on a prim would result in a server log message rather than setting phantom. This was an oversight when removing some race conditions from PhysicsActor setting recently. Regression tests extended to probe this code path. Extending regression tests required implementation of a BasicPhysicsPrim (there was none before). However, BasicPhysics plugin is still of no current practical use other than to fill in as a component for other parts of regression testing. --- .../World/Archiver/Tests/ArchiverTests.cs | 4 +- OpenSim/Region/Framework/Scenes/Scene.cs | 14 +- .../Framework/Scenes/SceneObjectPart.cs | 9 +- .../Scenes/Tests/SceneObjectStatusTests.cs | 2 + .../BasicPhysicsPlugin/BasicPhysicsPrim.cs | 344 ++++++++++++++++++ .../BasicPhysicsPlugin/BasicPhysicsScene.cs | 43 ++- 6 files changed, 383 insertions(+), 33 deletions(-) create mode 100644 OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 643c6cfde3..053c6f59d4 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs @@ -102,9 +102,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); Vector3 groupPosition = new Vector3(10, 20, 30); Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); - Vector3 offsetPosition = new Vector3(5, 10, 15); +// Vector3 offsetPosition = new Vector3(5, 10, 15); - return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition) { Name = partName }; + return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, Vector3.Zero) { Name = partName }; } protected SceneObjectPart CreateSceneObjectPart2() diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 2d4f4839b3..54c51c00b6 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -685,8 +685,8 @@ namespace OpenSim.Region.Framework.Scenes //Animation states m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); - PhysicalPrims = startupConfig.GetBoolean("physical_prim", true); - CollidablePrims = startupConfig.GetBoolean("collidable_prim", true); + PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims); + CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims); m_maxNonphys = startupConfig.GetFloat("NonphysicalPrimMax", m_maxNonphys); if (RegionInfo.NonphysPrimMax > 0) @@ -801,13 +801,11 @@ namespace OpenSim.Region.Framework.Scenes StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; } - /// - /// Mock constructor for scene group persistency unit tests. - /// SceneObjectGroup RegionId property is delegated to Scene. - /// - /// public Scene(RegionInfo regInfo) { + PhysicalPrims = true; + CollidablePrims = true; + BordersLocked = true; Border northBorder = new Border(); northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (int)Constants.RegionSize); //<--- @@ -834,8 +832,6 @@ namespace OpenSim.Region.Framework.Scenes m_eventManager = new EventManager(); m_permissions = new ScenePermissions(this); - -// m_lastUpdate = Util.EnvironmentTickCount(); } #endregion diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 680a554ac1..2a83c73bcb 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -4283,7 +4283,10 @@ namespace OpenSim.Region.Framework.Scenes AddFlag(PrimFlags.Phantom); if (PhysActor != null) + { RemoveFromPhysics(); + pa = null; + } } else // Not phantom { @@ -4349,7 +4352,7 @@ namespace OpenSim.Region.Framework.Scenes { pa.SetVolumeDetect(1); AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active - this.VolumeDetectActive = true; + VolumeDetectActive = true; } } else @@ -4357,9 +4360,9 @@ namespace OpenSim.Region.Framework.Scenes // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like // (mumbles, well, at least if you have infinte CPU powers :-)) if (pa != null) - PhysActor.SetVolumeDetect(0); + pa.SetVolumeDetect(0); - this.VolumeDetectActive = false; + VolumeDetectActive = false; } if (SetTemporary) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs index c069321209..87580003a6 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs @@ -62,6 +62,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests { TestHelpers.InMethod(); + m_scene.AddSceneObject(m_so1); + SceneObjectPart rootPart = m_so1.RootPart; Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs new file mode 100644 index 0000000000..ba7fe1e7bb --- /dev/null +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs @@ -0,0 +1,344 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + */ + +using System; +using System.Collections.Generic; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.Physics.Manager; + +namespace OpenSim.Region.Physics.BasicPhysicsPlugin +{ + public class BasicPhysicsPrim : PhysicsActor + { + private Vector3 _position; + private Vector3 _velocity; + private Vector3 _acceleration; + private Vector3 _size; + private PrimitiveBaseShape _shape; + private Vector3 m_rotationalVelocity; + private bool flying; + private bool iscolliding; + + public BasicPhysicsPrim( + string name, uint localId, Vector3 position, Vector3 size, Quaternion orientation, PrimitiveBaseShape shape) + { + Name = name; + LocalID = localId; + Position = position; + Size = size; + Orientation = orientation; + Shape = shape; + } + + public override int PhysicsActorType + { + get { return (int) ActorTypes.Agent; } + set { return; } + } + + public override Vector3 RotationalVelocity + { + get { return m_rotationalVelocity; } + set { m_rotationalVelocity = value; } + } + + public override bool SetAlwaysRun + { + get { return false; } + set { return; } + } + + public override uint LocalID + { + set { return; } + } + + public override bool Grabbed + { + set { return; } + } + + public override bool Selected + { + set { return; } + } + + public override float Buoyancy + { + get { return 0f; } + set { return; } + } + + public override bool FloatOnWater + { + set { return; } + } + + public override bool IsPhysical + { + get { return false; } + set { return; } + } + + public override bool ThrottleUpdates + { + get { return false; } + set { return; } + } + + public override bool Flying + { + get { return flying; } + set { flying = value; } + } + + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } + + public override bool CollidingGround + { + get { return false; } + set { return; } + } + + public override bool CollidingObj + { + get { return false; } + set { return; } + } + + public override bool Stopped + { + get { return false; } + } + + public override Vector3 Position + { + get { return _position; } + set { _position = value; } + } + + public override Vector3 Size + { + get { return _size; } + set { + _size = value; + _size.Z = _size.Z / 2.0f; + } + } + + public override PrimitiveBaseShape Shape + { + set { _shape = value; } + } + + public override float Mass + { + get { return 0f; } + } + + public override Vector3 Force + { + get { return Vector3.Zero; } + set { return; } + } + + public override int VehicleType + { + get { return 0; } + set { return; } + } + + public override void VehicleFloatParam(int param, float value) + { + + } + + public override void VehicleVectorParam(int param, Vector3 value) + { + + } + + public override void VehicleRotationParam(int param, Quaternion rotation) + { + + } + + public override void VehicleFlags(int param, bool remove) + { + + } + + public override void SetVolumeDetect(int param) + { + + } + + public override Vector3 CenterOfMass + { + get { return Vector3.Zero; } + } + + public override Vector3 GeometricCenter + { + get { return Vector3.Zero; } + } + + public override Vector3 Velocity + { + get { return _velocity; } + set { _velocity = value; } + } + + public override Vector3 Torque + { + get { return Vector3.Zero; } + set { return; } + } + + public override float CollisionScore + { + get { return 0f; } + set { } + } + + public override Quaternion Orientation { get; set; } + + public override Vector3 Acceleration + { + get { return _acceleration; } + set { _acceleration = value; } + } + + public override bool Kinematic + { + get { return true; } + set { } + } + + public override void link(PhysicsActor obj) + { + } + + public override void delink() + { + } + + public override void LockAngularMotion(Vector3 axis) + { + } + + public override void AddForce(Vector3 force, bool pushforce) + { + } + + public override void AddAngularForce(Vector3 force, bool pushforce) + { + } + + public override void SetMomentum(Vector3 momentum) + { + } + + public override void CrossingFailure() + { + } + + public override Vector3 PIDTarget + { + set { return; } + } + + public override bool PIDActive + { + set { return; } + } + + public override float PIDTau + { + set { return; } + } + + public override float PIDHoverHeight + { + set { return; } + } + + public override bool PIDHoverActive + { + set { return; } + } + + public override PIDHoverType PIDHoverType + { + set { return; } + } + + public override float PIDHoverTau + { + set { return; } + } + + public override Quaternion APIDTarget + { + set { return; } + } + + public override bool APIDActive + { + set { return; } + } + + public override float APIDStrength + { + set { return; } + } + + public override float APIDDamping + { + set { return; } + } + + public override void SubscribeEvents(int ms) + { + } + + public override void UnSubscribeEvents() + { + } + + public override bool SubscribedEvents() + { + return false; + } + } +} diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs index 2e1421649f..f5826edd2c 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs @@ -34,9 +34,17 @@ using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.BasicPhysicsPlugin { + /// + /// This is an incomplete extremely basic physics implementation + /// + /// + /// Not useful for anything at the moment apart from some regression testing in other components where some form + /// of physics plugin is needed. + /// public class BasicScene : PhysicsScene { private List _actors = new List(); + private List _prims = new List(); private float[] _heightMap; //protected internal string sceneIdentifier; @@ -50,10 +58,19 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin { } - public override void Dispose() - { + public override void Dispose() {} + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, + Vector3 size, Quaternion rotation, bool isPhysical, uint localid) + { + BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs); + prim.IsPhysical = isPhysical; + + _prims.Add(prim); + + return prim; } + public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) { BasicActor act = new BasicActor(size); @@ -63,30 +80,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin return act; } - public override void RemovePrim(PhysicsActor prim) + public override void RemovePrim(PhysicsActor actor) { + BasicPhysicsPrim prim = (BasicPhysicsPrim)actor; + if (_prims.Contains(prim)) + _prims.Remove(prim); } public override void RemoveAvatar(PhysicsActor actor) { - BasicActor act = (BasicActor) actor; + BasicActor act = (BasicActor)actor; if (_actors.Contains(act)) - { _actors.Remove(act); - } - } - -/* - public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation) - { - return null; - } -*/ - - public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, - Vector3 size, Quaternion rotation, bool isPhysical, uint localid) - { - return null; } public override void AddPhysicsActorTaint(PhysicsActor prim)