diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index f1b4732bf0..76b731f0f3 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -102,12 +102,28 @@ namespace OpenSim.Framework bool TryGetScenePresence(UUID agentID, out object scenePresence); - T RequestModuleInterface(); - T[] RequestModuleInterfaces(); - + /// + /// Register an interface to a region module. This allows module methods to be called directly as + /// well as via events. If there is already a module registered for this interface, it is not replaced + /// (is this the best behaviour?) + /// + /// void RegisterModuleInterface(M mod); + void StackModuleInterface(M mod); + /// + /// For the given interface, retrieve the region module which implements it. + /// + /// null if there is no registered module implementing that interface + T RequestModuleInterface(); + + /// + /// For the given interface, retrieve an array of region modules that implement it. + /// + /// an empty array if there are no registered modules implementing that interface + T[] RequestModuleInterfaces(); + // void AddCommand(object module, string command, string shorthelp, string longhelp, CommandDelegate callback); ISceneObject DeserializeObject(string representation); diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index d0f6ab7c94..4a7c8b083b 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs @@ -70,7 +70,7 @@ namespace OpenSim /// /// A configuration that gets passed to modules public OpenSimConfigSource LoadConfigSettings( - IConfigSource argvSource, out ConfigSettings configSettings, + IConfigSource argvSource, EnvConfigSource envConfigSource, out ConfigSettings configSettings, out NetworkServersInfo networkInfo) { m_configSettings = configSettings = new ConfigSettings(); @@ -195,6 +195,24 @@ namespace OpenSim // Make sure command line options take precedence m_config.Source.Merge(argvSource); + + IConfig enVars = m_config.Source.Configs["Environment"]; + + if( enVars != null ) + { + string[] env_keys = enVars.GetKeys(); + + foreach ( string key in env_keys ) + { + envConfigSource.AddEnv(key, string.Empty); + } + + envConfigSource.LoadEnv(); + m_config.Source.Merge(envConfigSource); + m_config.Source.ExpandKeyValues(); + } + + ReadConfigSettings(); return m_config; diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 542211aa2f..8e1eb95dba 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -112,6 +112,13 @@ namespace OpenSim get { return m_clientServers; } } + protected EnvConfigSource m_EnvConfigSource = new EnvConfigSource(); + + public EnvConfigSource envConfigSource + { + get { return m_EnvConfigSource; } + } + protected List m_clientServers = new List(); public uint HttpServerPort @@ -146,7 +153,7 @@ namespace OpenSim protected virtual void LoadConfigSettings(IConfigSource configSource) { m_configLoader = new ConfigurationLoader(); - m_config = m_configLoader.LoadConfigSettings(configSource, out m_configSettings, out m_networkServersInfo); + m_config = m_configLoader.LoadConfigSettings(configSource, envConfigSource, out m_configSettings, out m_networkServersInfo); ReadExtraConfigSettings(); } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 53f0f2e09a..245f2587ec 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -82,16 +82,9 @@ namespace OpenSim.Region.Framework.Scenes m_log.Info("[PRIM INVENTORY]: Starting scripts in scene"); IScriptModule[] engines = RequestModuleInterfaces(); - if (engines != null) - { - foreach (IScriptModule engine in engines) - { - if (engine != null) - { - engine.StartProcessing(); - } - } - } + + foreach (IScriptModule engine in engines) + engine.StartProcessing(); } public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item) diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index 73e9392b1a..0fd5164380 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -451,7 +451,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - return new T[] { default(T) }; + return new T[] {}; } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index e214f5788d..11040b79a1 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -252,7 +252,6 @@ namespace OpenSim.Region.Framework.Scenes private byte[] m_TextureAnimation; private byte m_clickAction; private Color m_color = Color.Black; - private string m_description = String.Empty; private readonly List m_lastColliders = new List(); private int m_linkNum; @@ -331,11 +330,14 @@ namespace OpenSim.Region.Framework.Scenes /// public SceneObjectPart() { - // It's not necessary to persist this m_TextureAnimation = Utils.EmptyBytes; m_particleSystem = Utils.EmptyBytes; Rezzed = DateTime.UtcNow; - + Description = String.Empty; + + // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, + // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from + // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log m_inventory = new SceneObjectPartInventory(this); } @@ -349,11 +351,10 @@ namespace OpenSim.Region.Framework.Scenes /// public SceneObjectPart( UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, - Quaternion rotationOffset, Vector3 offsetPosition) + Quaternion rotationOffset, Vector3 offsetPosition) : this() { m_name = "Object"; - Rezzed = DateTime.UtcNow; CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed); LastOwnerID = CreatorID = OwnerID = ownerID; UUID = UUID.Random(); @@ -368,19 +369,10 @@ namespace OpenSim.Region.Framework.Scenes Velocity = Vector3.Zero; AngularVelocity = Vector3.Zero; Acceleration = Vector3.Zero; - m_TextureAnimation = Utils.EmptyBytes; - m_particleSystem = Utils.EmptyBytes; - - // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, - // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from - // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log - Flags = 0; CreateSelected = true; TrimPermissions(); - - m_inventory = new SceneObjectPartInventory(this); } #endregion Constructors @@ -938,19 +930,7 @@ namespace OpenSim.Region.Framework.Scenes set { m_acceleration = value; } } - public string Description - { - get { return m_description; } - set - { - m_description = value; - PhysicsActor actor = PhysActor; - if (actor != null) - { - actor.SOPDescription = value; - } - } - } + public string Description { get; set; } /// /// Text color. @@ -1595,8 +1575,7 @@ namespace OpenSim.Region.Framework.Scenes // Basic Physics returns null.. joy joy joy. if (PhysActor != null) { - PhysActor.SOPName = this.Name; // save object name and desc into the PhysActor so ODE internals know the joint/body info - PhysActor.SOPDescription = this.Description; + PhysActor.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info PhysActor.SetMaterial(Material); DoPhysicsPropertyUpdate(RigidBody, true); PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 309f543972..c485e87324 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -282,8 +282,6 @@ namespace OpenSim.Region.Framework.Scenes ArrayList ret = new ArrayList(); IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); - if (engines == null) // No engine at all - return ret; foreach (IScriptModule e in engines) { @@ -397,7 +395,7 @@ namespace OpenSim.Region.Framework.Scenes private void RestoreSavedScriptState(UUID oldID, UUID newID) { IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); - if (engines == null) // No engine at all + if (engines.Length == 0) // No engine at all return; if (m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID)) @@ -437,6 +435,7 @@ namespace OpenSim.Region.Framework.Scenes m_part.ParentGroup.m_savedScriptState[oldID] = newDoc.OuterXml; } + foreach (IScriptModule e in engines) { if (e != null) @@ -445,6 +444,7 @@ namespace OpenSim.Region.Framework.Scenes break; } } + m_part.ParentGroup.m_savedScriptState.Remove(oldID); } } @@ -1327,7 +1327,7 @@ namespace OpenSim.Region.Framework.Scenes IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); - if (engines == null) // No engine at all + if (engines.Length == 0) // No engine at all return ret; Items.LockItemsForRead(true); @@ -1365,7 +1365,7 @@ namespace OpenSim.Region.Framework.Scenes public void ResumeScripts() { IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); - if (engines == null) + if (engines.Length == 0) return; diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index d89c1c0157..0eaac644ce 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -3535,23 +3535,23 @@ namespace OpenSim.Region.Framework.Scenes /// The arguments for the event public void SendScriptEventToAttachments(string eventName, Object[] args) { - if (m_scriptEngines != null) - { - lock (m_attachments) - { - foreach (SceneObjectGroup grp in m_attachments) - { - // 16384 is CHANGED_ANIMATION - // - // Send this to all attachment root prims - // - foreach (IScriptModule m in m_scriptEngines) - { - if (m == null) // No script engine loaded - continue; + if (m_scriptEngines.Length == 0) + return; - m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); - } + lock (m_attachments) + { + foreach (SceneObjectGroup grp in m_attachments) + { + // 16384 is CHANGED_ANIMATION + // + // Send this to all attachment root prims + // + foreach (IScriptModule m in m_scriptEngines) + { + if (m == null) // No script engine loaded + continue; + + m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); } } } diff --git a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs index 2a44360f28..23ef7576f3 100755 --- a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs +++ b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs @@ -48,7 +48,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters public class PhysicsParameters : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static string LogHeader = "[PHYSICS PARAMETERS]"; +// private static string LogHeader = "[PHYSICS PARAMETERS]"; private List m_scenes = new List(); private static bool m_commandsLoaded = false; diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 798a0a42d9..c2acf971f9 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -160,8 +160,19 @@ namespace OpenSim.Region.Physics.Manager public abstract bool Selected { set; } + /// + /// Name of this actor. + /// + /// + /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or + /// water. This is not a problem due to the formatting of names given by prims and avatars. + /// + public string Name { get; protected set; } + + /// + /// This is being used by ODE joint code. + /// public string SOPName; - public string SOPDescription; public abstract void CrossingFailure(); diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index acedf44341..1f631ee7c9 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs @@ -224,15 +224,9 @@ namespace OpenSim.Region.Physics.Manager return false; } - public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) - { - return; - } + public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} - public virtual void UnCombine(PhysicsScene pScene) - { - - } + public virtual void UnCombine(PhysicsScene pScene) {} /// /// Queue a raycast against the physics scene. diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index c37d588730..489a23a273 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -70,7 +70,6 @@ namespace OpenSim.Region.Physics.OdePlugin private Vector3 _position; private d.Vector3 _zeroPosition; - // private d.Matrix3 m_StandUpRotation; private bool _zeroFlag = false; private bool m_lastUpdateSent = false; private Vector3 _velocity; @@ -123,9 +122,6 @@ namespace OpenSim.Region.Physics.OdePlugin private float m_buoyancy = 0f; // private CollisionLocker ode; - - private string m_name = String.Empty; - private bool[] m_colliderarr = new bool[11]; private bool[] m_colliderGroundarr = new bool[11]; @@ -181,7 +177,7 @@ namespace OpenSim.Region.Physics.OdePlugin parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f); m_taintPosition = _position; - m_log.Warn("[PHYSICS]: Got NaN Position on Character Create"); + m_log.WarnFormat("[ODE CHARACTER]: Got NaN Position on Character Create for {0}", avName); } _parent_scene = parent_scene; @@ -204,7 +200,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_colliderarr[i] = false; } CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; - //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); + //m_log.Info("[ODE CHARACTER]: " + CAPSULE_LENGTH.ToString()); m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH; m_isPhysical = false; // current status: no ODE information exists @@ -212,7 +208,7 @@ namespace OpenSim.Region.Physics.OdePlugin _parent_scene.AddPhysicsActorTaint(this); - m_name = avName; + Name = avName; } public override int PhysicsActorType @@ -269,7 +265,7 @@ namespace OpenSim.Region.Physics.OdePlugin set { flying = value; -// m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying); +// m_log.DebugFormat("[ODE CHARACTER]: Set OdeCharacter Flying to {0}", flying); } } @@ -440,7 +436,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN Position from Scene on character {0}", Name); } } } @@ -467,7 +463,7 @@ namespace OpenSim.Region.Physics.OdePlugin Vector3 SetSize = value; m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; -// m_log.Info("[SIZE]: " + CAPSULE_LENGTH); +// m_log.Info("[ODE CHARACTER]: " + CAPSULE_LENGTH); // If we reset velocity here, then an avatar stalls when it crosses a border for the first time // (as the height of the new root agent is set). @@ -477,7 +473,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN Size from Scene on {0}", Name); } } } @@ -529,7 +525,6 @@ namespace OpenSim.Region.Physics.OdePlugin } } - // movementVector.Z is zero // calculate tilt components based on desired amount of tilt and current (snapped) heading. @@ -537,7 +532,7 @@ namespace OpenSim.Region.Physics.OdePlugin float xTiltComponent = -movementVector.X * m_tiltMagnitudeWhenProjectedOnXYPlane; float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane; - //m_log.Debug("[PHYSICS] changing avatar tilt"); + //m_log.Debug("[ODE CHARACTER]: changing avatar tilt"); d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent); d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent); @@ -546,124 +541,6 @@ namespace OpenSim.Region.Physics.OdePlugin d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop } - /// - /// This creates the Avatar's physical Surrogate at the position supplied - /// - /// - /// - /// - - // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access - // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only - // place that is safe to call this routine AvatarGeomAndBodyCreation. - private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ, float tensor) - { - //CAPSULE_LENGTH = -5; - //CAPSULE_RADIUS = -5; - int dAMotorEuler = 1; - _parent_scene.waitForSpaceUnlock(_parent_scene.space); - if (CAPSULE_LENGTH <= 0) - { - m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); - CAPSULE_LENGTH = 0.01f; - - } - - if (CAPSULE_RADIUS <= 0) - { - m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); - CAPSULE_RADIUS = 0.01f; - - } - Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); - - d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); - d.GeomSetCollideBits(Shell, (int)m_collisionFlags); - - d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH); - Body = d.BodyCreate(_parent_scene.world); - d.BodySetPosition(Body, npositionX, npositionY, npositionZ); - - _position.X = npositionX; - _position.Y = npositionY; - _position.Z = npositionZ; - - m_taintPosition = _position; - - d.BodySetMass(Body, ref ShellMass); - d.Matrix3 m_caprot; - // 90 Stand up on the cap of the capped cyllinder - if (_parent_scene.IsAvCapsuleTilted) - { - d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2)); - } - else - { - d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2)); - } - - - d.GeomSetRotation(Shell, ref m_caprot); - d.BodySetRotation(Body, ref m_caprot); - - d.GeomSetBody(Shell, Body); - - - // The purpose of the AMotor here is to keep the avatar's physical - // surrogate from rotating while moving - Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); - d.JointAttach(Amotor, Body, IntPtr.Zero); - d.JointSetAMotorMode(Amotor, dAMotorEuler); - d.JointSetAMotorNumAxes(Amotor, 3); - d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); - d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); - d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); - d.JointSetAMotorAngle(Amotor, 0, 0); - d.JointSetAMotorAngle(Amotor, 1, 0); - d.JointSetAMotorAngle(Amotor, 2, 0); - - // These lowstops and high stops are effectively (no wiggle room) - if (_parent_scene.IsAvCapsuleTilted) - { - d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f); - } - else - { - #region Documentation of capsule motor LowStop and HighStop parameters - // Intentionally introduce some tilt into the capsule by setting - // the motor stops to small epsilon values. This small tilt prevents - // the capsule from falling into the terrain; a straight-up capsule - // (with -0..0 motor stops) falls into the terrain for reasons yet - // to be comprehended in their entirety. - #endregion - AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero); - d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop - } - - // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the - // capped cyllinder will fall over - d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f); - d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor); - - //d.Matrix3 bodyrotation = d.BodyGetRotation(Body); - //d.QfromR( - //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068, - // - //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); - //standupStraight(); - } - - // /// /// Uses the capped cyllinder volume formula to calculate the avatar's mass. /// This may be used in calculations in the scene/scenepresence @@ -774,7 +651,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN velocity from Scene for {0}", Name); } // m_log.DebugFormat("[PHYSICS]: Set target velocity of {0}", m_taintTargetVelocity); @@ -836,7 +713,6 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintForce += force; _parent_scene.AddPhysicsActorTaint(this); - //doForce(force); // If uncommented, things get pushed off world // // m_log.Debug("Push!"); @@ -852,7 +728,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN force applied to {0}", Name); } //m_lastUpdateSent = false; } @@ -861,15 +737,6 @@ namespace OpenSim.Region.Physics.OdePlugin { } - /// - /// After all of the forces add up with 'add force' we apply them with doForce - /// - /// - public void doForce(Vector3 force) - { - d.BodyAddForce(Body, force.X, force.Y, force.Z); - } - public override void SetMomentum(Vector3 momentum) { } @@ -878,9 +745,8 @@ namespace OpenSim.Region.Physics.OdePlugin /// Called from Simulate /// This is the avatar's movement control + PID Controller /// - /// - /// If there is something wrong with the character (e.g. its position is non-finite) - /// then it is added to this list. The ODE structures associated with it are also destroyed. + /// The character will be added to this list if there is something wrong (non-finite + /// position or velocity). /// internal void Move(List defects) { @@ -903,12 +769,11 @@ namespace OpenSim.Region.Physics.OdePlugin if (!localPos.IsFinite()) { - m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); + m_log.WarnFormat( + "[ODE CHARACTER]: Avatar position of {0} for {1} is non-finite! Removing from physics scene.", + localPos, Name); defects.Add(this); - // _parent_scene.RemoveCharacter(this); - - DestroyOdeStructures(); return; } @@ -1035,26 +900,31 @@ namespace OpenSim.Region.Physics.OdePlugin if (vec.IsFinite()) { - doForce(vec); + // Apply the total force acting on this avatar + d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); if (!_zeroFlag) AlignAvatarTiltWithCurrentDirectionOfMovement(vec); } else { - m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()"); - m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); - defects.Add(this); - // _parent_scene.RemoveCharacter(this); + m_log.WarnFormat( + "[ODE CHARACTER]: Got a NaN force vector {0} in Move() for {1}. Removing character from physics scene.", + vec, Name); - DestroyOdeStructures(); + defects.Add(this); + + return; } } /// /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. /// - internal void UpdatePositionAndVelocity() + /// The character will be added to this list if there is something wrong (non-finite + /// position or velocity). + /// + internal void UpdatePositionAndVelocity(List defects) { // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! d.Vector3 newPos; @@ -1065,10 +935,12 @@ namespace OpenSim.Region.Physics.OdePlugin catch (NullReferenceException) { bad = true; - _parent_scene.BadCharacter(this); + defects.Add(this); newPos = new d.Vector3(_position.X, _position.Y, _position.Z); base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! - m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid); + m_log.WarnFormat("[ODE CHARACTER]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid); + + return; } // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) @@ -1136,6 +1008,123 @@ namespace OpenSim.Region.Physics.OdePlugin } } + /// + /// This creates the Avatar's physical Surrogate in ODE at the position supplied + /// + /// + /// WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access + /// to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only + /// place that is safe to call this routine AvatarGeomAndBodyCreation. + /// + /// + /// + /// + /// + private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) + { + int dAMotorEuler = 1; +// _parent_scene.waitForSpaceUnlock(_parent_scene.space); + if (CAPSULE_LENGTH <= 0) + { + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + CAPSULE_LENGTH = 0.01f; + } + + if (CAPSULE_RADIUS <= 0) + { + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + CAPSULE_RADIUS = 0.01f; + } + + Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); + + d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); + d.GeomSetCollideBits(Shell, (int)m_collisionFlags); + + d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH); + Body = d.BodyCreate(_parent_scene.world); + d.BodySetPosition(Body, npositionX, npositionY, npositionZ); + + _position.X = npositionX; + _position.Y = npositionY; + _position.Z = npositionZ; + + m_taintPosition = _position; + + d.BodySetMass(Body, ref ShellMass); + d.Matrix3 m_caprot; + // 90 Stand up on the cap of the capped cyllinder + if (_parent_scene.IsAvCapsuleTilted) + { + d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2)); + } + else + { + d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2)); + } + + d.GeomSetRotation(Shell, ref m_caprot); + d.BodySetRotation(Body, ref m_caprot); + + d.GeomSetBody(Shell, Body); + + // The purpose of the AMotor here is to keep the avatar's physical + // surrogate from rotating while moving + Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); + d.JointAttach(Amotor, Body, IntPtr.Zero); + d.JointSetAMotorMode(Amotor, dAMotorEuler); + d.JointSetAMotorNumAxes(Amotor, 3); + d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); + d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); + d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); + d.JointSetAMotorAngle(Amotor, 0, 0); + d.JointSetAMotorAngle(Amotor, 1, 0); + d.JointSetAMotorAngle(Amotor, 2, 0); + + // These lowstops and high stops are effectively (no wiggle room) + if (_parent_scene.IsAvCapsuleTilted) + { + d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f); + } + else + { + #region Documentation of capsule motor LowStop and HighStop parameters + // Intentionally introduce some tilt into the capsule by setting + // the motor stops to small epsilon values. This small tilt prevents + // the capsule from falling into the terrain; a straight-up capsule + // (with -0..0 motor stops) falls into the terrain for reasons yet + // to be comprehended in their entirety. + #endregion + AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero); + d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop + } + + // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the + // capped cyllinder will fall over + d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f); + d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor); + + //d.Matrix3 bodyrotation = d.BodyGetRotation(Body); + //d.QfromR( + //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068, + // + //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); + //standupStraight(); + + _parent_scene.geom_name_map[Shell] = Name; + _parent_scene.actor_name_map[Shell] = this; + } + /// /// Cleanup the things we use in the scene. /// @@ -1148,7 +1137,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// /// Used internally to destroy the ODE structures associated with this character. /// - private void DestroyOdeStructures() + internal void DestroyOdeStructures() { // destroy avatar capsule and related ODE data if (Amotor != IntPtr.Zero) @@ -1159,13 +1148,12 @@ namespace OpenSim.Region.Physics.OdePlugin } //kill the Geometry - _parent_scene.waitForSpaceUnlock(_parent_scene.space); +// _parent_scene.waitForSpaceUnlock(_parent_scene.space); if (Body != IntPtr.Zero) { //kill the body d.BodyDestroy(Body); - Body = IntPtr.Zero; } @@ -1173,6 +1161,8 @@ namespace OpenSim.Region.Physics.OdePlugin { d.GeomDestroy(Shell); _parent_scene.geom_name_map.Remove(Shell); + _parent_scene.actor_name_map.Remove(Shell); + Shell = IntPtr.Zero; } } @@ -1261,7 +1251,7 @@ namespace OpenSim.Region.Physics.OdePlugin // FIXME: This is not a good solution since it's subject to a race condition if a force is another // thread sets a new force while we're in this loop (since it could be obliterated by // m_taintForce = Vector3.Zero. Need to lock ProcessTaints() when we set a new tainted force. - doForce(m_taintForce); + d.BodyAddForce(Body, m_taintForce.X, m_taintForce.Y, m_taintForce.Z); } m_taintForce = Vector3.Zero; @@ -1277,15 +1267,13 @@ namespace OpenSim.Region.Physics.OdePlugin // Create avatar capsule and related ODE data if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero)) { - m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - " + m_log.Warn("[ODE CHARACTER]: re-creating the following avatar ODE data for " + Name + ", even though it already exists - " + (Shell!=IntPtr.Zero ? "Shell ":"") + (Body!=IntPtr.Zero ? "Body ":"") + (Amotor!=IntPtr.Zero ? "Amotor ":"")); } - AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor); - - _parent_scene.geom_name_map[Shell] = m_name; - _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; + + CreateOdeStructures(_position.X, _position.Y, _position.Z, m_tensor); _parent_scene.AddCharacter(this); } else @@ -1301,17 +1289,19 @@ namespace OpenSim.Region.Physics.OdePlugin { if (Shell != IntPtr.Zero && Body != IntPtr.Zero && Amotor != IntPtr.Zero) { -// m_log.DebugFormat("[PHYSICS]: Changing capsule size"); +// m_log.DebugFormat( +// "[ODE CHARACTER]: Changing capsule size from {0} to {1} for {2}", +// CAPSULE_LENGTH, m_tainted_CAPSULE_LENGTH, Name); m_pidControllerActive = true; + // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() - d.JointDestroy(Amotor); + DestroyOdeStructures(); + float prevCapsule = CAPSULE_LENGTH; CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; - //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); - d.BodyDestroy(Body); - d.GeomDestroy(Shell); - AvatarGeomAndBodyCreation( + + CreateOdeStructures( _position.X, _position.Y, _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor); @@ -1319,13 +1309,10 @@ namespace OpenSim.Region.Physics.OdePlugin // As with Size, we reset velocity. However, this isn't strictly necessary since it doesn't // appear to stall initial region crossings when done here. Being done for consistency. // Velocity = Vector3.Zero; - - _parent_scene.geom_name_map[Shell] = m_name; - _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; } else { - m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - " + m_log.Warn("[ODE CHARACTER]: trying to change capsule size for " + Name + ", but the following ODE data is missing - " + (Shell==IntPtr.Zero ? "Shell ":"") + (Body==IntPtr.Zero ? "Body ":"") + (Amotor==IntPtr.Zero ? "Amotor ":"")); diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index f07cf46f94..af05a15260 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -184,7 +184,6 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_lastUpdateSent; public IntPtr Body = IntPtr.Zero; - public String Name { get; private set; } private Vector3 _target_velocity; private d.Mass pMass; @@ -273,7 +272,6 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintadd = true; _parent_scene.AddPhysicsActorTaint(this); - // don't do .add() here; old geoms get recycled with the same hash } public override int PhysicsActorType @@ -857,7 +855,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_MeshToTriMeshMap[mesh] = _triMeshData; } - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { if (prim_geom == IntPtr.Zero) @@ -1380,7 +1378,7 @@ Console.WriteLine("CreateGeom:"); { if (((_size.X / 2f) > 0f)) { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 1"); @@ -1394,7 +1392,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 2"); @@ -1409,7 +1407,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 3"); @@ -1424,7 +1422,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 4"); @@ -1577,17 +1575,17 @@ Console.WriteLine(" JointCreateFixed"); { // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position); // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace); m_targetSpace = tempspace; - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); if (prim_geom != IntPtr.Zero) { d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); d.SpaceAdd(m_targetSpace, prim_geom); } } @@ -1978,7 +1976,7 @@ Console.WriteLine(" JointCreateFixed"); if (d.SpaceQuery(m_targetSpace, prim_geom)) { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); d.SpaceRemove(m_targetSpace, prim_geom); } diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 43d852b05e..0456f5667c 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -188,8 +188,20 @@ namespace OpenSim.Region.Physics.OdePlugin private d.NearCallback nearCallback; public d.TriCallback triCallback; public d.TriArrayCallback triArrayCallback; + + /// + /// Avatars in the physics scene. + /// private readonly HashSet _characters = new HashSet(); + + /// + /// Prims in the physics scene. + /// private readonly HashSet _prims = new HashSet(); + + /// + /// Prims in the physics scene that are subject to physics, not just collisions. + /// private readonly HashSet _activeprims = new HashSet(); /// @@ -215,7 +227,14 @@ namespace OpenSim.Region.Physics.OdePlugin /// private readonly HashSet _taintedPrimH = new HashSet(); + /// + /// Record a character that has taints to be processed. + /// private readonly HashSet _taintedActors = new HashSet(); + + /// + /// Keep record of contacts in the physics loop so that we can remove duplicates. + /// private readonly List _perloopContact = new List(); /// @@ -227,18 +246,58 @@ namespace OpenSim.Region.Physics.OdePlugin /// A dictionary of collision event changes that are waiting to be processed. /// private readonly Dictionary _collisionEventPrimChanges = new Dictionary(); - - private readonly HashSet _badCharacter = new HashSet(); + + /// + /// Maps a unique geometry id (a memory location) to a physics actor name. + /// + /// + /// Only actors participating in collisions have geometries. This has to be maintained separately from + /// actor_name_map because terrain and water currently don't conceptually have a physics actor of their own + /// apart from the singleton PANull + /// public Dictionary geom_name_map = new Dictionary(); + + /// + /// Maps a unique geometry id (a memory location) to a physics actor. + /// + /// + /// Only actors participating in collisions have geometries. + /// public Dictionary actor_name_map = new Dictionary(); + + /// + /// Defects list to remove characters that no longer have finite positions due to some other bug. + /// + /// + /// Used repeatedly in Simulate() but initialized once here. + /// + private readonly List defects = new List(); + private bool m_NINJA_physics_joints_enabled = false; //private Dictionary jointpart_name_map = new Dictionary(); private readonly Dictionary> joints_connecting_actor = new Dictionary>(); private d.ContactGeom[] contacts; - private readonly List requestedJointsToBeCreated = new List(); // lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active - private readonly List pendingJoints = new List(); // can lock for longer. accessed only by OdeScene. - private readonly List activeJoints = new List(); // can lock for longer. accessed only by OdeScene. - private readonly List requestedJointsToBeDeleted = new List(); // lock only briefly. accessed by external code (to request deletion of joints) and by OdeScene.Simulate() to move those joints out of pending/active + + /// + /// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active + /// + private readonly List requestedJointsToBeCreated = new List(); + + /// + /// can lock for longer. accessed only by OdeScene. + /// + private readonly List pendingJoints = new List(); + + /// + /// can lock for longer. accessed only by OdeScene. + /// + private readonly List activeJoints = new List(); + + /// + /// lock only briefly. accessed by external code (to request deletion of joints) and by OdeScene.Simulate() to move those joints out of pending/active + /// + private readonly List requestedJointsToBeDeleted = new List(); + private Object externalJointRequestsLock = new Object(); private readonly Dictionary SOPName_to_activeJoint = new Dictionary(); private readonly Dictionary SOPName_to_pendingJoint = new Dictionary(); @@ -318,8 +377,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// Name of the scene. Useful in debug messages. public OdeScene(string name) { - m_log - = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); + m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); Name = name; @@ -663,11 +721,11 @@ namespace OpenSim.Region.Physics.OdePlugin } } - internal void waitForSpaceUnlock(IntPtr space) - { - //if (space != IntPtr.Zero) - //while (d.SpaceLockQuery(space)) { } // Wait and do nothing - } +// internal void waitForSpaceUnlock(IntPtr space) +// { +// //if (space != IntPtr.Zero) +// //while (d.SpaceLockQuery(space)) { } // Wait and do nothing +// } // /// // /// Debug space message for printing the space that a prim/avatar is in. @@ -710,7 +768,7 @@ namespace OpenSim.Region.Physics.OdePlugin } catch (AccessViolationException) { - m_log.Warn("[PHYSICS]: Unable to collide test a space"); + m_log.Warn("[ODE SCENE]: Unable to collide test a space"); return; } //Colliding a space or a geom with a space or a geom. so drill down @@ -760,22 +818,19 @@ namespace OpenSim.Region.Physics.OdePlugin if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) return; - lock (contacts) - { - count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); - if (count > contacts.Length) - m_log.Error("[PHYSICS]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); - } + count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); + if (count > contacts.Length) + m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); } catch (SEHException) { m_log.Error( - "[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); + "[ODE SCENE]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); base.TriggerPhysicsBasedRestart(); } catch (Exception e) { - m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message); + m_log.WarnFormat("[ODE SCENE]: Unable to collide test an object: {0}", e.Message); return; } @@ -1029,6 +1084,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (!skipThisContact) { + _perloopContact.Add(curContact); + // If we're colliding against terrain if (name1 == "Terrain" || name2 == "Terrain") { @@ -1038,7 +1095,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the movement terrain contact AvatarMovementTerrainContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); @@ -1051,7 +1108,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the non moving terrain contact TerrainContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); @@ -1077,7 +1134,6 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, movintYN].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { @@ -1098,9 +1154,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (p2 is OdePrim) material = ((OdePrim)p2).m_material; + //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, movintYN].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { @@ -1133,8 +1189,9 @@ namespace OpenSim.Region.Physics.OdePlugin //contact.normal = new d.Vector3(0, 0, 1); //contact.pos = new d.Vector3(0, 0, contact.pos.Z - 5f); } + WaterContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref WaterContact); @@ -1152,7 +1209,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the Movement prim contact AvatarMovementprimContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); @@ -1182,13 +1239,11 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, 0].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]); m_global_contactcount++; - } } } @@ -1217,69 +1272,65 @@ namespace OpenSim.Region.Physics.OdePlugin private bool checkDupe(d.ContactGeom contactGeom, int atype) { - bool result = false; - //return result; if (!m_filterCollisions) return false; + bool result = false; + ActorTypes at = (ActorTypes)atype; - lock (_perloopContact) + + foreach (d.ContactGeom contact in _perloopContact) { - foreach (d.ContactGeom contact in _perloopContact) + //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) + //{ + // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2) + if (at == ActorTypes.Agent) { - //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) - //{ - // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2) - if (at == ActorTypes.Agent) + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) + && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) + && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) + && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) { - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) - { - - if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) - { - //contactGeom.depth *= .00005f; - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - result = true; - break; - } - else - { - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - } - } - else - { - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - //int i = 0; - } - } - else if (at == ActorTypes.Prim) - { - //d.AABB aabb1 = new d.AABB(); - //d.AABB aabb2 = new d.AABB(); - - //d.GeomGetAABB(contactGeom.g2, out aabb2); - //d.GeomGetAABB(contactGeom.g1, out aabb1); - //aabb1. - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) - { - if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) - { - if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) - { - result = true; - break; - } - } - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - } - + if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) + { + //contactGeom.depth *= .00005f; + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + result = true; + break; + } +// else +// { +// //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); +// } } - - //} +// else +// { +// //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); +// //int i = 0; +// } + } + else if (at == ActorTypes.Prim) + { + //d.AABB aabb1 = new d.AABB(); + //d.AABB aabb2 = new d.AABB(); + //d.GeomGetAABB(contactGeom.g2, out aabb2); + //d.GeomGetAABB(contactGeom.g1, out aabb1); + //aabb1. + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + { + if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) + { + if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) + { + result = true; + break; + } + } + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + } } } @@ -1482,90 +1533,77 @@ namespace OpenSim.Region.Physics.OdePlugin { _perloopContact.Clear(); - lock (_characters) + foreach (OdeCharacter chr in _characters) { - foreach (OdeCharacter chr in _characters) + // Reset the collision values to false + // since we don't know if we're colliding yet + if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) + continue; + + chr.IsColliding = false; + chr.CollidingGround = false; + chr.CollidingObj = false; + + // test the avatar's geometry for collision with the space + // This will return near and the space that they are the closest to + // And we'll run this again against the avatar and the space segment + // This will return with a bunch of possible objects in the space segment + // and we'll run it again on all of them. + try + { + d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); + } + catch (AccessViolationException) + { + m_log.WarnFormat("[ODE SCENE]: Unable to space collide {0}", Name); + } + + //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); + //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) + //{ + //chr.Position.Z = terrainheight + 10.0f; + //forcedZ = true; + //} + } + + List removeprims = null; + foreach (OdePrim chr in _activeprims) + { + if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) { - // Reset the collision values to false - // since we don't know if we're colliding yet - - // For some reason this can happen. Don't ask... - // - if (chr == null) - continue; - - if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) - continue; - - chr.IsColliding = false; - chr.CollidingGround = false; - chr.CollidingObj = false; - - // test the avatar's geometry for collision with the space - // This will return near and the space that they are the closest to - // And we'll run this again against the avatar and the space segment - // This will return with a bunch of possible objects in the space segment - // and we'll run it again on all of them. try { - d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); + lock (chr) + { + if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false) + { + d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); + } + else + { + if (removeprims == null) + { + removeprims = new List(); + } + removeprims.Add(chr); + m_log.Debug("[ODE SCENE]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!"); + } + } } catch (AccessViolationException) { - m_log.Warn("[PHYSICS]: Unable to space collide"); + m_log.Warn("[ODE SCENE]: Unable to space collide"); } - //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); - //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) - //{ - //chr.Position.Z = terrainheight + 10.0f; - //forcedZ = true; - //} } } - lock (_activeprims) + if (removeprims != null) { - List removeprims = null; - foreach (OdePrim chr in _activeprims) + foreach (OdePrim chr in removeprims) { - if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) - { - try - { - lock (chr) - { - if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false) - { - d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); - } - else - { - if (removeprims == null) - { - removeprims = new List(); - } - removeprims.Add(chr); - m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!"); - } - } - } - catch (AccessViolationException) - { - m_log.Warn("[PHYSICS]: Unable to space collide"); - } - } - } - - if (removeprims != null) - { - foreach (OdePrim chr in removeprims) - { - _activeprims.Remove(chr); - } + _activeprims.Remove(chr); } } - - _perloopContact.Clear(); } #endregion @@ -1685,35 +1723,29 @@ namespace OpenSim.Region.Physics.OdePlugin internal void AddCharacter(OdeCharacter chr) { - lock (_characters) + if (!_characters.Contains(chr)) { - if (!_characters.Contains(chr)) - { - _characters.Add(chr); - if (chr.bad) - m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); - } + _characters.Add(chr); + + if (chr.bad) + m_log.ErrorFormat("[ODE SCENE]: Added BAD actor {0} to characters list", chr.m_uuid); + } + else + { + m_log.ErrorFormat( + "[ODE SCENE]: Tried to add character {0} {1} but they are already in the set!", + chr.Name, chr.LocalID); } } internal void RemoveCharacter(OdeCharacter chr) { - lock (_characters) - { - if (_characters.Contains(chr)) - { - _characters.Remove(chr); - } - } - } - - internal void BadCharacter(OdeCharacter chr) - { - lock (_badCharacter) - { - if (!_badCharacter.Contains(chr)) - _badCharacter.Add(chr); - } + if (_characters.Contains(chr)) + _characters.Remove(chr); + else + m_log.ErrorFormat( + "[ODE SCENE]: Tried to remove character {0} {1} but they are not in the list!", + chr.Name, chr.LocalID); } private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, @@ -1742,13 +1774,10 @@ namespace OpenSim.Region.Physics.OdePlugin internal void ActivatePrim(OdePrim prim) { // adds active prim.. (ones that should be iterated over in collisions_optimized - lock (_activeprims) - { - if (!_activeprims.Contains(prim)) - _activeprims.Add(prim); - //else - // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); - } + if (!_activeprims.Contains(prim)) + _activeprims.Add(prim); + //else + // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); } public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, @@ -2027,7 +2056,6 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.Debug("RemoveAllJointsConnectedToActor: start"); if (actor.SOPName != null && joints_connecting_actor.ContainsKey(actor.SOPName) && joints_connecting_actor[actor.SOPName] != null) { - List jointsToRemove = new List(); //TODO: merge these 2 loops (originally it was needed to avoid altering a list being iterated over, but it is no longer needed due to the joint request queue mechanism) foreach (PhysicsJoint j in joints_connecting_actor[actor.SOPName]) @@ -2122,8 +2150,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// internal void DeactivatePrim(OdePrim prim) { - lock (_activeprims) - _activeprims.Remove(prim); + _activeprims.Remove(prim); } public override void RemovePrim(PhysicsActor prim) @@ -2138,7 +2165,6 @@ namespace OpenSim.Region.Physics.OdePlugin p.setPrimForRemoval(); AddPhysicsActorTaint(prim); - //RemovePrimThreadLocked(p); } } } @@ -2206,7 +2232,7 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.Warn(prim.prim_geom); if (!prim.RemoveGeom()) - m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); + m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene"); lock (_prims) _prims.Remove(prim); @@ -2293,12 +2319,12 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(currentspace); d.SpaceRemove(currentspace, geom); } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + currentspace + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2309,12 +2335,12 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(sGeomIsIn); +// waitForSpaceUnlock(sGeomIsIn); d.SpaceRemove(sGeomIsIn, geom); } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + sGeomIsIn + " Geom:" + geom); } } @@ -2327,8 +2353,8 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); - waitForSpaceUnlock(space); +// waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(space); d.SpaceRemove(space, currentspace); // free up memory used by the space. @@ -2337,7 +2363,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2352,12 +2378,12 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(currentspace); d.SpaceRemove(currentspace, geom); } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2368,12 +2394,12 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(sGeomIsIn)) { - waitForSpaceUnlock(sGeomIsIn); +// waitForSpaceUnlock(sGeomIsIn); d.SpaceRemove(sGeomIsIn, geom); } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + sGeomIsIn + " Geom:" + geom); } } @@ -2407,9 +2433,10 @@ namespace OpenSim.Region.Physics.OdePlugin // creating a new space for prim and inserting it into main space. staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space); - waitForSpaceUnlock(space); +// waitForSpaceUnlock(space); d.SpaceSetSublevel(space, 1); d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); + return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; } @@ -2584,15 +2611,17 @@ namespace OpenSim.Region.Physics.OdePlugin /// /// Called after our prim properties are set Scale, position etc. + /// + /// /// We use this event queue like method to keep changes to the physical scene occuring in the threadlocked mutex /// This assures us that we have no race conditions - /// - /// - public override void AddPhysicsActorTaint(PhysicsActor prim) + /// + /// + public override void AddPhysicsActorTaint(PhysicsActor actor) { - if (prim is OdePrim) + if (actor is OdePrim) { - OdePrim taintedprim = ((OdePrim) prim); + OdePrim taintedprim = ((OdePrim)actor); lock (_taintedPrimLock) { if (!(_taintedPrimH.Contains(taintedprim))) @@ -2604,18 +2633,17 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); _taintedPrimL.Add(taintedprim); // List for ordered readout } } - return; } - else if (prim is OdeCharacter) + else if (actor is OdeCharacter) { - OdeCharacter taintedchar = ((OdeCharacter)prim); + OdeCharacter taintedchar = ((OdeCharacter)actor); lock (_taintedActors) { if (!(_taintedActors.Contains(taintedchar))) { _taintedActors.Add(taintedchar); if (taintedchar.bad) - m_log.DebugFormat("[PHYSICS]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid); + m_log.DebugFormat("[ODE SCENE]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid); } } } @@ -2711,29 +2739,18 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { try { - // Insert, remove Characters - bool processedtaints = false; - lock (_taintedActors) { if (_taintedActors.Count > 0) { foreach (OdeCharacter character in _taintedActors) - { character.ProcessTaints(); - processedtaints = true; - //character.m_collisionscore = 0; - } - - if (processedtaints) + if (_taintedActors.Count > 0) _taintedActors.Clear(); } } - // Modify other objects in the scene. - processedtaints = false; - lock (_taintedPrimLock) { foreach (OdePrim prim in _taintedPrimL) @@ -2749,7 +2766,6 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); prim.ProcessTaints(); } - processedtaints = true; prim.m_collisionscore = 0; // This loop can block up the Heartbeat for a very long time on large regions. @@ -2762,7 +2778,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); if (SupportsNINJAJoints) SimulatePendingNINJAJoints(); - if (processedtaints) + if (_taintedPrimL.Count > 0) { //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); _taintedPrimH.Clear(); @@ -2771,31 +2787,25 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } // Move characters - lock (_characters) + foreach (OdeCharacter actor in _characters) + actor.Move(defects); + + if (defects.Count != 0) { - List defects = new List(); - foreach (OdeCharacter actor in _characters) + foreach (OdeCharacter actor in defects) { - if (actor != null) - actor.Move(defects); - } - if (0 != defects.Count) - { - foreach (OdeCharacter defect in defects) - { - RemoveCharacter(defect); - } + RemoveCharacter(actor); + actor.DestroyOdeStructures(); } + + defects.Clear(); } // Move other active objects - lock (_activeprims) + foreach (OdePrim prim in _activeprims) { - foreach (OdePrim prim in _activeprims) - { - prim.m_collisionscore = 0; - prim.Move(timeStep); - } + prim.m_collisionscore = 0; + prim.Move(timeStep); } //if ((framecount % m_randomizeWater) == 0) @@ -2836,53 +2846,41 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } catch (Exception e) { - m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); + m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e); } timeLeft -= ODE_STEPSIZE; } - lock (_characters) + foreach (OdeCharacter actor in _characters) { - foreach (OdeCharacter actor in _characters) - { - if (actor != null) - { - if (actor.bad) - m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + if (actor.bad) + m_log.WarnFormat("[ODE SCENE]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); - actor.UpdatePositionAndVelocity(); - } - } + actor.UpdatePositionAndVelocity(defects); } - lock (_badCharacter) + if (defects.Count != 0) { - if (_badCharacter.Count > 0) + foreach (OdeCharacter actor in defects) { - foreach (OdeCharacter chr in _badCharacter) - { - RemoveCharacter(chr); - } - - _badCharacter.Clear(); + RemoveCharacter(actor); + actor.DestroyOdeStructures(); } + + defects.Clear(); } - lock (_activeprims) - { - //if (timeStep < 0.2f) - { - foreach (OdePrim prim in _activeprims) - { - if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) - { - prim.UpdatePositionAndVelocity(); + //if (timeStep < 0.2f) - if (SupportsNINJAJoints) - SimulateActorPendingJoints(prim); - } - } + foreach (OdePrim prim in _activeprims) + { + if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) + { + prim.UpdatePositionAndVelocity(); + + if (SupportsNINJAJoints) + SimulateActorPendingJoints(prim); } } @@ -3417,7 +3415,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { if (Single.IsNaN(resultarr2[y, x]) || Single.IsInfinity(resultarr2[y, x])) { - m_log.Warn("[PHYSICS]: Non finite heightfield element detected. Setting it to 0"); + m_log.Warn("[ODE SCENE]: Non finite heightfield element detected. Setting it to 0"); resultarr2[y, x] = 0; } returnarr[i] = resultarr2[y, x]; @@ -3448,7 +3446,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); private void SetTerrain(float[] heightMap, Vector3 pOffset) { int startTime = Util.EnvironmentTickCount(); - m_log.DebugFormat("[PHYSICS]: Setting terrain for {0}", Name); + m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0}", Name); // this._heightmap[i] = (double)heightMap[i]; // dbm (danx0r) -- creating a buffer zone of one extra sample all around @@ -3573,7 +3571,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } m_log.DebugFormat( - "[PHYSICS]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); + "[ODE SCENE]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); } public override void DeleteTerrain() @@ -3590,64 +3588,64 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); return true; } - public override void UnCombine(PhysicsScene pScene) - { - IntPtr localGround = IntPtr.Zero; -// float[] localHeightfield; - bool proceed = false; - List geomDestroyList = new List(); - - lock (OdeLock) - { - if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround)) - { - foreach (IntPtr geom in TerrainHeightFieldHeights.Keys) - { - if (geom == localGround) - { -// localHeightfield = TerrainHeightFieldHeights[geom]; - proceed = true; - } - else - { - geomDestroyList.Add(geom); - } - } - - if (proceed) - { - m_worldOffset = Vector3.Zero; - WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); - m_parentScene = null; - - foreach (IntPtr g in geomDestroyList) - { - // removingHeightField needs to be done or the garbage collector will - // collect the terrain data before we tell ODE to destroy it causing - // memory corruption - if (TerrainHeightFieldHeights.ContainsKey(g)) - { -// float[] removingHeightField = TerrainHeightFieldHeights[g]; - TerrainHeightFieldHeights.Remove(g); - - if (RegionTerrain.ContainsKey(g)) - { - RegionTerrain.Remove(g); - } - - d.GeomDestroy(g); - //removingHeightField = new float[0]; - } - } - - } - else - { - m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); - } - } - } - } +// public override void UnCombine(PhysicsScene pScene) +// { +// IntPtr localGround = IntPtr.Zero; +//// float[] localHeightfield; +// bool proceed = false; +// List geomDestroyList = new List(); +// +// lock (OdeLock) +// { +// if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround)) +// { +// foreach (IntPtr geom in TerrainHeightFieldHeights.Keys) +// { +// if (geom == localGround) +// { +//// localHeightfield = TerrainHeightFieldHeights[geom]; +// proceed = true; +// } +// else +// { +// geomDestroyList.Add(geom); +// } +// } +// +// if (proceed) +// { +// m_worldOffset = Vector3.Zero; +// WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); +// m_parentScene = null; +// +// foreach (IntPtr g in geomDestroyList) +// { +// // removingHeightField needs to be done or the garbage collector will +// // collect the terrain data before we tell ODE to destroy it causing +// // memory corruption +// if (TerrainHeightFieldHeights.ContainsKey(g)) +// { +//// float[] removingHeightField = TerrainHeightFieldHeights[g]; +// TerrainHeightFieldHeights.Remove(g); +// +// if (RegionTerrain.ContainsKey(g)) +// { +// RegionTerrain.Remove(g); +// } +// +// d.GeomDestroy(g); +// //removingHeightField = new float[0]; +// } +// } +// +// } +// else +// { +// m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); +// } +// } +// } +// } public override void SetWaterLevel(float baseheight) { @@ -3894,30 +3892,28 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } ds.SetColor(1.0f, 0.0f, 0.0f); - lock (_characters) + + foreach (OdeCharacter chr in _characters) { - foreach (OdeCharacter chr in _characters) + if (chr.Shell != IntPtr.Zero) { - if (chr.Shell != IntPtr.Zero) - { - IntPtr body = d.GeomGetBody(chr.Shell); + IntPtr body = d.GeomGetBody(chr.Shell); - d.Vector3 pos; - d.GeomCopyPosition(chr.Shell, out pos); - //d.BodyCopyPosition(body, out pos); + d.Vector3 pos; + d.GeomCopyPosition(chr.Shell, out pos); + //d.BodyCopyPosition(body, out pos); - d.Matrix3 R; - d.GeomCopyRotation(chr.Shell, out R); - //d.BodyCopyRotation(body, out R); + d.Matrix3 R; + d.GeomCopyRotation(chr.Shell, out R); + //d.BodyCopyRotation(body, out R); - ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f); - d.Vector3 sides = new d.Vector3(); - sides.X = 0.5f; - sides.Y = 0.5f; - sides.Z = 0.5f; + ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f); + d.Vector3 sides = new d.Vector3(); + sides.X = 0.5f; + sides.Y = 0.5f; + sides.Z = 0.5f; - ds.DrawBox(ref pos, ref R, ref sides); - } + ds.DrawBox(ref pos, ref R, ref sides); } } } diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs index 1413535db7..e4a3ba0d24 100644 --- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs +++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs @@ -759,33 +759,33 @@ namespace OpenSim.Region.RegionCombinerModule { } - /// - /// TODO: - /// - /// - public void UnCombineRegion(RegionData rdata) - { - lock (m_regions) - { - if (m_regions.ContainsKey(rdata.RegionId)) - { - // uncombine root region and virtual regions - } - else - { - foreach (RegionConnections r in m_regions.Values) - { - foreach (RegionData rd in r.ConnectedRegions) - { - if (rd.RegionId == rdata.RegionId) - { - // uncombine virtual region - } - } - } - } - } - } +// /// +// /// TODO: +// /// +// /// +// public void UnCombineRegion(RegionData rdata) +// { +// lock (m_regions) +// { +// if (m_regions.ContainsKey(rdata.RegionId)) +// { +// // uncombine root region and virtual regions +// } +// else +// { +// foreach (RegionConnections r in m_regions.Values) +// { +// foreach (RegionData rd in r.ConnectedRegions) +// { +// if (rd.RegionId == rdata.RegionId) +// { +// // uncombine virtual region +// } +// } +// } +// } +// } +// } // Create a set of infinite borders around the whole aabb of the combined island. private void AdjustLargeRegionBounds() diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs index 2cae02d42a..888b072013 100644 --- a/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs @@ -87,12 +87,26 @@ namespace OpenSim.Services.Connectors public bool DoHelloNeighbourCall(GridRegion region, RegionInfo thisRegion) { string uri = region.ServerURI + "region/" + thisRegion.RegionID + "/"; - //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); +// m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); - WebRequest HelloNeighbourRequest = WebRequest.Create(uri); - HelloNeighbourRequest.Method = "POST"; - HelloNeighbourRequest.ContentType = "application/json"; - HelloNeighbourRequest.Timeout = 10000; + WebRequest helloNeighbourRequest; + + try + { + helloNeighbourRequest = WebRequest.Create(uri); + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Unable to parse uri {0} to send HelloNeighbour from {1} to {2}. Exception {3}{4}", + uri, thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + + return false; + } + + helloNeighbourRequest.Method = "POST"; + helloNeighbourRequest.ContentType = "application/json"; + helloNeighbourRequest.Timeout = 10000; // Fill it in OSDMap args = null; @@ -102,38 +116,48 @@ namespace OpenSim.Services.Connectors } catch (Exception e) { - m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: PackRegionInfoData failed for HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + return false; } + // Add the regionhandle of the destination region args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); string strBuffer = ""; byte[] buffer = new byte[1]; + try { strBuffer = OSDParser.SerializeJsonString(args); UTF8Encoding str = new UTF8Encoding(); buffer = str.GetBytes(strBuffer); - } catch (Exception e) { - m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message); + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Exception thrown on serialization of HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + return false; } Stream os = null; try { // send the Post - HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send - os = HelloNeighbourRequest.GetRequestStream(); + helloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send + os = helloNeighbourRequest.GetRequestStream(); os.Write(buffer, 0, strBuffer.Length); //Send it //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); } - catch (Exception ex) + catch (Exception e) { - m_log.InfoFormat("[REST COMMS]: Unable to send HelloNeighbour to {0}: {1}", region.RegionName, ex.Message); + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Unable to send HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + return false; } finally @@ -148,10 +172,12 @@ namespace OpenSim.Services.Connectors StreamReader sr = null; try { - WebResponse webResponse = HelloNeighbourRequest.GetResponse(); + WebResponse webResponse = helloNeighbourRequest.GetResponse(); if (webResponse == null) { - m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post"); + m_log.DebugFormat( + "[REST COMMS]: Null reply on DoHelloNeighbourCall post from {0} to {1}", + thisRegion.RegionName, region.RegionName); } sr = new StreamReader(webResponse.GetResponseStream()); @@ -160,9 +186,12 @@ namespace OpenSim.Services.Connectors //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); } - catch (Exception ex) + catch (Exception e) { - m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message); + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Exception on reply of DoHelloNeighbourCall from {0} back to {1}. Exception {2}{3}", + region.RegionName, thisRegion.RegionName, e.Message, e.StackTrace); + return false; } finally @@ -172,8 +201,6 @@ namespace OpenSim.Services.Connectors } return true; - } - } -} +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs index d8089ac8b1..9573e215cd 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs @@ -334,7 +334,9 @@ namespace OpenSim.Services.Connectors.SimianGrid // Make the remote storage request try { - HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl); + // Simian does not require the asset ID to be in the URL because it's in the post data. + // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs + HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString()); HttpWebResponse response = MultipartForm.Post(request, postParameters); using (Stream responseStream = response.GetResponseStream()) diff --git a/OpenSim/Tests/ConfigurationLoaderTest.cs b/OpenSim/Tests/ConfigurationLoaderTest.cs index c777acc0f1..067264d027 100644 --- a/OpenSim/Tests/ConfigurationLoaderTest.cs +++ b/OpenSim/Tests/ConfigurationLoaderTest.cs @@ -109,11 +109,13 @@ namespace OpenSim.Tests // Prepare call to ConfigurationLoader.LoadConfigSettings() ConfigurationLoader cl = new ConfigurationLoader(); IConfigSource argvSource = new IniConfigSource(); + EnvConfigSource envConfigSource = new EnvConfigSource(); argvSource.AddConfig("Startup").Set("inifile", mainIniFile); ConfigSettings configSettings; NetworkServersInfo networkInfo; - OpenSimConfigSource source = cl.LoadConfigSettings(argvSource, out configSettings, out networkInfo); + OpenSimConfigSource source = cl.LoadConfigSettings(argvSource, envConfigSource, + out configSettings, out networkInfo); // Remove default config config = source.Source.Configs["Startup"]; diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs index 7084ab41de..0a6d5d2b97 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs @@ -41,6 +41,8 @@ namespace pCampBot /// public class GrabbingBehaviour : IBehaviour { + public string Name { get { return "Grabbing"; } } + public void Action(Bot bot) { Dictionary objects = bot.Objects; diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs index 3ce08bf617..f782bb507c 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs @@ -42,6 +42,8 @@ namespace pCampBot /// public class PhysicsBehaviour : IBehaviour { + public string Name { get { return "Physics"; } } + private string[] talkarray; public PhysicsBehaviour() diff --git a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs new file mode 100644 index 0000000000..fc2ed2c92a --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs @@ -0,0 +1,75 @@ +/* + * 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 System.Linq; +using System.Reflection; +using log4net; +using OpenMetaverse; +using pCampBot.Interfaces; + +namespace pCampBot +{ + /// + /// Teleport to a random region on the grid. + /// + public class TeleportBehaviour : IBehaviour + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public string Name { get { return "Teleport"; } } + + public void Action(Bot bot) + { + Random rng = bot.Manager.Rng; + GridRegion[] knownRegions; + + lock (bot.Manager.RegionsKnown) + { + if (bot.Manager.RegionsKnown.Count == 0) + { + m_log.DebugFormat( + "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", bot.Name); + return; + } + + knownRegions = bot.Manager.RegionsKnown.Values.ToArray(); + } + + Simulator sourceRegion = bot.Client.Network.CurrentSim; + GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)]; + Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50); + + m_log.DebugFormat( + "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}", + bot.Name, sourceRegion.Name, bot.Client.Self.SimPosition, destRegion.Name, destPosition); + + bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition); + } + } +} \ No newline at end of file diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 7f941a497f..7a73e3f13a 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -49,8 +49,15 @@ namespace pCampBot public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events - public BotManager BotManager { get; private set; } - private IConfig startupConfig; // bot config, passed from BotManager + /// + /// Bot manager. + /// + public BotManager Manager { get; private set; } + + /// + /// Bot config, passed from BotManager. + /// + private IConfig startupConfig; /// /// Behaviours implemented by this bot. @@ -132,7 +139,7 @@ namespace pCampBot Password = password; LoginUri = loginUri; - BotManager = bm; + Manager = bm; startupConfig = bm.Config; readconfig(); @@ -218,7 +225,19 @@ namespace pCampBot { MakeDefaultAppearance(wear); } + Client.Self.Jump(true); + + // Extract nearby region information. + Client.Grid.GridRegion += Manager.Grid_GridRegion; + uint xUint, yUint; + Utils.LongToUInts(Client.Network.CurrentSim.Handle, out xUint, out yUint); + ushort minX, minY, maxX, maxY; + minX = (ushort)Math.Min(0, xUint - 5); + minY = (ushort)Math.Min(0, yUint - 5); + maxX = (ushort)(xUint + 5); + maxY = (ushort)(yUint + 5); + Client.Grid.RequestMapBlocks(GridLayerType.Terrain, minX, minY, maxX, maxY, false); } else { @@ -472,13 +491,13 @@ namespace pCampBot private void GetTexture(UUID textureID) { - lock (BotManager.AssetsReceived) + lock (Manager.AssetsReceived) { // Don't request assets more than once. - if (BotManager.AssetsReceived.ContainsKey(textureID)) + if (Manager.AssetsReceived.ContainsKey(textureID)) return; - BotManager.AssetsReceived[textureID] = false; + Manager.AssetsReceived[textureID] = false; Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); } } @@ -490,8 +509,8 @@ namespace pCampBot public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) { - lock (BotManager.AssetsReceived) - BotManager.AssetsReceived[asset.AssetID] = true; + lock (Manager.AssetsReceived) + Manager.AssetsReceived[asset.AssetID] = true; // if (wear == "save") // { diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index f5dd5e0847..29cb1ba98c 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading; using OpenMetaverse; @@ -48,9 +49,24 @@ namespace pCampBot { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// + /// Command console + /// protected CommandConsole m_console; + + /// + /// Created bots, whether active or inactive. + /// protected List m_lBot; - protected Random somthing = new Random(Environment.TickCount); + + /// + /// Random number generator. + /// + public Random Rng { get; private set; } + + /// + /// Overall configuration. + /// public IConfig Config { get; private set; } /// @@ -58,12 +74,19 @@ namespace pCampBot /// public Dictionary AssetsReceived { get; private set; } + /// + /// The regions that we know about. + /// + public Dictionary RegionsKnown { get; private set; } + /// /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// public BotManager() { + Rng = new Random(Environment.TickCount); AssetsReceived = new Dictionary(); + RegionsKnown = new Dictionary(); m_console = CreateConsole(); MainConsole.Instance = m_console; @@ -93,8 +116,13 @@ namespace pCampBot "Shutdown bots and exit", HandleShutdown); - m_console.Commands.AddCommand("bot", false, "show status", - "show status", + m_console.Commands.AddCommand("bot", false, "show regions", + "show regions", + "Show regions known to bots", + HandleShowRegions); + + m_console.Commands.AddCommand("bot", false, "show bots", + "show bots", "Shows the status of all bots", HandleShowStatus); @@ -123,19 +151,26 @@ namespace pCampBot Array.ForEach( cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); + List behaviours = new List(); + + // Hard-coded for now + if (behaviourSwitches.Contains("p")) + behaviours.Add(new PhysicsBehaviour()); + + if (behaviourSwitches.Contains("g")) + behaviours.Add(new GrabbingBehaviour()); + + if (behaviourSwitches.Contains("t")) + behaviours.Add(new TeleportBehaviour()); + + MainConsole.Instance.OutputFormat( + "[BOT MANAGER]: Bots configured for behaviours {0}", + string.Join(",", behaviours.ConvertAll(b => b.Name).ToArray())); + for (int i = 0; i < botcount; i++) { string lastName = string.Format("{0}_{1}", lastNameStem, i); - List behaviours = new List(); - - // Hard-coded for now - if (behaviourSwitches.Contains("p")) - behaviours.Add(new PhysicsBehaviour()); - - if (behaviourSwitches.Contains("g")) - behaviours.Add(new GrabbingBehaviour()); - StartBot(this, behaviours, firstName, lastName, password, loginUri); } } @@ -240,17 +275,33 @@ namespace pCampBot }); } + private void HandleShowRegions(string module, string[] cmd) + { + string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}"; + MainConsole.Instance.OutputFormat(outputFormat, "Name", "Handle", "X", "Y"); + + lock (RegionsKnown) + { + foreach (GridRegion region in RegionsKnown.Values) + { + MainConsole.Instance.OutputFormat( + outputFormat, region.Name, region.RegionHandle, region.X, region.Y); + } + } + } + private void HandleShowStatus(string module, string[] cmd) { - string outputFormat = "{0,-30} {1,-14}"; - MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status"); + string outputFormat = "{0,-30} {1, -30} {2,-14}"; + MainConsole.Instance.OutputFormat(outputFormat, "Name", "Region", "Status"); lock (m_lBot) { foreach (Bot pb in m_lBot) { MainConsole.Instance.OutputFormat( - outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); + outputFormat, + pb.Name, pb.Client.Network.CurrentSim.Name, pb.IsConnected ? "Connected" : "Disconnected"); } } } @@ -274,5 +325,24 @@ namespace pCampBot // if (newbots > 0) // addbots(newbots); // } + + internal void Grid_GridRegion(object o, GridRegionEventArgs args) + { + lock (RegionsKnown) + { + GridRegion newRegion = args.Region; + + if (RegionsKnown.ContainsKey(newRegion.RegionHandle)) + { + return; + } + else + { + m_log.DebugFormat( + "[BOT MANAGER]: Adding {0} {1} to known regions", newRegion.Name, newRegion.RegionHandle); + RegionsKnown[newRegion.RegionHandle] = newRegion; + } + } + } } } diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs index d4ae0f064b..912216f57a 100644 --- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs @@ -31,6 +31,15 @@ namespace pCampBot.Interfaces { public interface IBehaviour { + /// + /// Name of this behaviour. + /// + string Name { get; } + + /// + /// Action to take when this behaviour is invoked. + /// + /// void Action(Bot bot); } } \ No newline at end of file diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs index 4d3b06d5bf..e7288d53cf 100644 --- a/OpenSim/Tools/pCampBot/pCampBot.cs +++ b/OpenSim/Tools/pCampBot/pCampBot.cs @@ -111,7 +111,7 @@ namespace pCampBot " -firstname first name for the bots\n" + " -lastname lastname for the bots. Each lastname will have _ appended, e.g. Ima Bot_0\n" + " -password password for the bots\n" + - " -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p", + " -b, behaviours behaviours for bots. Current options p (physics), g (grab), t (teleport). Comma separated, e.g. p,g. Default is p", " -wear set appearance folder to load from (default: no)\n" + " -h, -help show this message" ); diff --git a/bin/Nini.dll b/bin/Nini.dll index 745057c3f6..c421005ba3 100755 Binary files a/bin/Nini.dll and b/bin/Nini.dll differ diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index e31d0f4244..d4e61a559b 100755 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -231,13 +231,6 @@ ;; server to send mail through. ; emailmodule = DefaultEmailModule - ;# {DeleteScriptsOnStartup} {} {Delete previously compiled script DLLs on startup?} (true false) true - ;; Controls whether previously compiled scripts DLLs are deleted on sim restart. If you set this to false - ;; then startup will be considerably faster since scripts won't need to be recompiled. However, then it becomes your responsibility to delete the - ;; compiled scripts if you're recompiling OpenSim from source code and internal interfaces used - ;; by scripts have changed. - ; DeleteScriptsOnStartup = true - [SMTP] ;; The SMTP server enabled the email module to send email to external ;; destinations. @@ -571,6 +564,13 @@ ;; Stack size per thread created ; ThreadStackSize = 262144 + ;# {DeleteScriptsOnStartup} {} {Delete previously compiled script DLLs on startup?} (true false) true + ;; Controls whether previously compiled scripts DLLs are deleted on sim restart. If you set this to false + ;; then startup will be considerably faster since scripts won't need to be recompiled. However, then it becomes your responsibility to delete the + ;; compiled scripts if you're recompiling OpenSim from source code and internal interfaces used + ;; by scripts have changed. + ; DeleteScriptsOnStartup = true + ;; Set this to true (the default) to load each script into a separate ;; AppDomain. Setting this to false will load all script assemblies into the ;; current AppDomain, which will reduce the per-script overhead at the