From fb26d32a5c1320e97c9288326ebe402658a0a1c7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 4 Dec 2012 22:33:25 +0000 Subject: minor: Put Scene.PhysicsRequestAsset() into standard C# xml format. --- OpenSim/Region/Framework/Scenes/Scene.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 1ad5edd..cca295c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5638,10 +5638,17 @@ namespace OpenSim.Region.Framework.Scenes return m_SpawnPoint - 1; } - // Wrappers to get physics modules retrieve assets. Has to be done this way - // because we can't assign the asset service to physics directly - at the - // time physics are instantiated it's not registered but it will be by - // the time the first prim exists. + /// + /// Wrappers to get physics modules retrieve assets. + /// + /// + /// Has to be done this way + /// because we can't assign the asset service to physics directly - at the + /// time physics are instantiated it's not registered but it will be by + /// the time the first prim exists. + /// + /// + /// public void PhysicsRequestAsset(UUID assetID, AssetReceivedDelegate callback) { AssetService.Get(assetID.ToString(), callback, PhysicsAssetReceived); -- cgit v1.1 From 0d4047e641bac2d7fa554097ad23cec930082e33 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 4 Dec 2012 23:06:02 +0000 Subject: minor: Comment out "Delivering IM to..." messages for now. --- .../CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index 3983369..a169748 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs @@ -146,7 +146,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage if (sp != null && !sp.IsChildAgent) { // Local message - m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", sp.Name, toAgentID); +// m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", sp.Name, toAgentID); sp.ControllingClient.SendInstantMessage(im); @@ -166,7 +166,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage if (sp != null) { // Local message - m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", sp.Name, toAgentID); +// m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", sp.Name, toAgentID); sp.ControllingClient.SendInstantMessage(im); @@ -176,7 +176,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID); +// m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID); SendGridInstantMessageViaXMLRPC(im, result); } -- cgit v1.1 From 1b5f21f761ae12be34d80a41d23c5b97cc10f4a9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 4 Dec 2012 23:07:26 +0000 Subject: minor: also comment out the debug log message which reports searching for child agents in simulator scenes for now. --- .../Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index a169748..fa935cd 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs @@ -159,8 +159,8 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage // try child avatar second foreach (Scene scene in m_Scenes) { - m_log.DebugFormat( - "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); +// m_log.DebugFormat( +// "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); ScenePresence sp = scene.GetScenePresence(toAgentID); if (sp != null) -- cgit v1.1 From d97440c7cf307ec701cc5351a0075239ece44727 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 21:37:41 +0000 Subject: On XEngine.ProcessEventHandler(), instead of creating a new CultureInfo on every call use the single one set by Culture.SetCurrentCulture() This is slightly different in that SetCurrentCulture() does not use overridden settings if the system culture matches en-US but some settings there have been changed. This is what we want - we do not want to use any system overriden settings. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 0460f22..1dab51e 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1415,8 +1415,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine /// private object ProcessEventHandler(object parms) { - CultureInfo USCulture = new CultureInfo("en-US"); - Thread.CurrentThread.CurrentCulture = USCulture; + Culture.SetCurrentCulture(); IScriptInstance instance = (ScriptInstance) parms; -- cgit v1.1 From ea786414c283ed04a32905b177afd342c88a7471 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 21:51:08 +0000 Subject: In XEngine.DoOnRezScript() use Culture.SetCurrentCulture() instead of constructing a new CultureInfo separately --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 1dab51e..d9d4494 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1018,8 +1018,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine string assembly = ""; - CultureInfo USCulture = new CultureInfo("en-US"); - Thread.CurrentThread.CurrentCulture = USCulture; + Culture.SetCurrentCulture(); Dictionary, KeyValuePair> linemap; -- cgit v1.1 From fdf8876e20e519e2c69f0bd0fed4aea7ff4bab8d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 21:52:10 +0000 Subject: In BaseHttpServer.HandleRequest(), use Culture.SetCurrentCulture() rather than creating a new CultureInfo separately --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 2cd626f..8a0340f 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -436,7 +436,7 @@ namespace OpenSim.Framework.Servers.HttpServer // reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]); //m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl); - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); + Culture.SetCurrentCulture(); // // This is the REST agent interface. We require an agent to properly identify // // itself. If the REST handler recognizes the prefix it will attempt to -- cgit v1.1 From 2342d20a7e249bc3006e47e85e03de6d532a7d2d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 21:53:25 +0000 Subject: minor: tidy up spacing at bottom of MundaneFrameworkTests --- OpenSim/Framework/Tests/MundaneFrameworkTests.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs index 47fe599..1dc8053 100644 --- a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs +++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs @@ -303,10 +303,6 @@ namespace OpenSim.Framework.Tests Culture.SetCurrentCulture(); Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US"); - } - - - + } } -} - +} \ No newline at end of file -- cgit v1.1 From b60c6bc3f8936f3a152e0609daa1081216d34768 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 22:01:47 +0000 Subject: Don't pointlessly set ExtraParams = byte[1] in PrimitiveBaseShape since this is ignored by the ExtraParams properly anyway --- OpenSim/Framework/PrimitiveBaseShape.cs | 3 --- 1 file changed, 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 76dcfca..3dbdd0f 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -193,7 +193,6 @@ namespace OpenSim.Framework public PrimitiveBaseShape() { PCode = (byte) PCodeEnum.Primitive; - ExtraParams = new byte[1]; m_textureEntry = DEFAULT_TEXTURE; } @@ -203,7 +202,6 @@ namespace OpenSim.Framework return; PCode = (byte)PCodeEnum.Primitive; - ExtraParams = new byte[1]; m_textureEntry = DEFAULT_TEXTURE; } @@ -216,7 +214,6 @@ namespace OpenSim.Framework // m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: Creating from {0}", prim.ID); PCode = (byte)prim.PrimData.PCode; - ExtraParams = new byte[1]; State = prim.PrimData.State; PathBegin = Primitive.PackBeginCut(prim.PrimData.PathBegin); -- cgit v1.1 From 0f3ebe09713cf67110ff24bf6cd10b9add5cc8c9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 22:12:45 +0000 Subject: Remove very probably unused PrimitiveBaseShape(bool) constructor to reduce code complexity --- OpenSim/Framework/PrimitiveBaseShape.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 3dbdd0f..4c36819 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -192,15 +192,6 @@ namespace OpenSim.Framework public PrimitiveBaseShape() { - PCode = (byte) PCodeEnum.Primitive; - m_textureEntry = DEFAULT_TEXTURE; - } - - public PrimitiveBaseShape(bool noShape) - { - if (noShape) - return; - PCode = (byte)PCodeEnum.Primitive; m_textureEntry = DEFAULT_TEXTURE; } @@ -245,7 +236,10 @@ namespace OpenSim.Framework SculptTexture = prim.Sculpt.SculptTexture; SculptType = (byte)prim.Sculpt.Type; } - else SculptType = (byte)OpenMetaverse.SculptType.None; + else + { + SculptType = (byte)OpenMetaverse.SculptType.None; + } } [XmlIgnore] @@ -337,9 +331,9 @@ namespace OpenSim.Framework _scale = new Vector3(side, side, side); } - public void SetHeigth(float heigth) + public void SetHeigth(float height) { - _scale.Z = heigth; + _scale.Z = height; } public void SetRadius(float radius) -- cgit v1.1 From e8df0f1b4c3194c7f5c1a354b5d5d2f67d6a250c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 22:33:28 +0000 Subject: Add IScriptInstance.EventsProcessed stat so that we can record this information and display in "show scripts" for debug purposes --- OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs | 5 +++++ OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 4 ++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 1 + 3 files changed, 10 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index b04f6b6..f3abd96 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -114,6 +114,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces UUID AssetID { get; } Queue EventQueue { get; } + /// + /// Number of events processed by this script instance. + /// + long EventsProcessed { get; } + void ClearQueue(); int StartParam { get; set; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 5793cc9..5bfe97a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -173,6 +173,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public Queue EventQueue { get; private set; } + public long EventsProcessed { get; private set; } + public int StartParam { get; set; } public TaskInventoryItem ScriptTask { get; private set; } @@ -808,6 +810,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // script engine to run the next event. lock (EventQueue) { + EventsProcessed++; + if (EventQueue.Count > 0 && Running && !ShuttingDown) { m_CurrentWorkItem = Engine.QueueEventHandler(this); diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index d9d4494..2136fe8 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -512,6 +512,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine lock (eq) sb.AppendFormat("Queued events : {0}\n", eq.Count); + sb.AppendFormat("Processed events : {0}\n", instance.EventsProcessed); sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); -- cgit v1.1 From 652f4bcb425646aab2096da99aa00016dfe639fd Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 23:27:50 +0000 Subject: For now, sort "show scripts" output in descending order sorted by events processed. For debug purposes - should later add options to allow different sorting or show only highest 10, etc. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 2136fe8..394826e 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -30,6 +30,7 @@ using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Reflection; using System.Security; using System.Security.Policy; @@ -377,9 +378,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine /// /// /// - /// true if we're okay to proceed, false if not. + /// Basis on which to sort output. Can be null if no sort needs to take place private void HandleScriptsAction(string[] cmdparams, Action action) { + HandleScriptsAction(cmdparams, action, null); + } + + /// + /// Parse the raw item id into a script instance from the command params if it's present. + /// + /// + /// + /// Basis on which to sort output. Can be null if no sort needs to take place + private void HandleScriptsAction( + string[] cmdparams, Action action, Func keySelector) + { if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) return; @@ -390,7 +403,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (cmdparams.Length == 2) { - foreach (IScriptInstance instance in m_Scripts.Values) + IEnumerable scripts = m_Scripts.Values; + + if (keySelector != null) + scripts = scripts.OrderBy(keySelector); + + foreach (IScriptInstance instance in scripts) action(instance); return; @@ -478,7 +496,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } - HandleScriptsAction(cmdparams, HandleShowScript); + HandleScriptsAction(cmdparams, HandleShowScript, si => si.EventsProcessed); } private void HandleShowScript(IScriptInstance instance) -- cgit v1.1 From 5ba99cbf554d965a6b11114a602c5317ca8f5ebd Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 23:33:48 +0000 Subject: Add IScriptInstance.EventsQueued to match EventsProcessed instead of asking callers to lock and directly inspect the EventQueue --- OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs | 5 +++++ OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 9 +++++++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 5 +---- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index f3abd96..0cef550 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -115,6 +115,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces Queue EventQueue { get; } /// + /// Number of events queued for processing. + /// + long EventsQueued { get; } + + /// /// Number of events processed by this script instance. /// long EventsProcessed { get; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 5bfe97a..8e81e9f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -173,6 +173,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public Queue EventQueue { get; private set; } + public long EventsQueued + { + get + { + lock (EventQueue) + return EventQueue.Count; + } + } + public long EventsProcessed { get; private set; } public int StartParam { get; set; } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 394826e..aeb807c 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -526,10 +526,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine sb.AppendFormat("Script name : {0}\n", instance.ScriptName); sb.AppendFormat("Status : {0}\n", status); - - lock (eq) - sb.AppendFormat("Queued events : {0}\n", eq.Count); - + sb.AppendFormat("Queued events : {0}\n", instance.EventsQueued); sb.AppendFormat("Processed events : {0}\n", instance.EventsProcessed); sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); -- cgit v1.1 From 66982c8a599eeeaf63f9e3c5bfdae743deab5528 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 23:36:15 +0000 Subject: Remove some mono warnings in script tests, chiefly where SetUp() wasn't properly calling to OpenSimTestCase.SetUp() --- OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs | 4 +++- OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs | 4 +++- OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs | 4 +++- OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | 4 +++- OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | 4 +--- 5 files changed, 13 insertions(+), 7 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs index 2c9d9e8..cb7291a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs @@ -57,8 +57,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests protected XEngine.XEngine m_engine; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + IConfigSource initConfigSource = new IniConfigSource(); IConfig config = initConfigSource.AddConfig("XEngine"); config.Set("Enabled", "true"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs index 57f19b9..d9b17d7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs @@ -62,8 +62,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests protected XEngine.XEngine m_engine; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + IConfigSource initConfigSource = new IniConfigSource(); IConfig config = initConfigSource.AddConfig("XEngine"); config.Set("Enabled", "true"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs index 182b07b..98017d8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs @@ -51,8 +51,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests private LSL_Api m_lslApi; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + IConfigSource initConfigSource = new IniConfigSource(); IConfig config = initConfigSource.AddConfig("XEngine"); config.Set("Enabled", "true"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs index 213f33f..1381d2b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs @@ -57,8 +57,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests protected XEngine.XEngine m_engine; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + IConfigSource initConfigSource = new IniConfigSource(); IConfig config = initConfigSource.AddConfig("XEngine"); config.Set("Enabled", "true"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index b49bcc2..d6c82f1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs @@ -127,12 +127,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests OSSL_Api osslApi = new OSSL_Api(); osslApi.Initialize(m_engine, so.RootPart, null); - string npcRaw; bool gotExpectedException = false; try { - npcRaw - = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); + osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); } catch (ScriptException) { -- cgit v1.1 From ec765de7e55893c24792c95c1356bfad67e02034 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 23:41:50 +0000 Subject: Add engine-wide events queued and events processed numbers to output of "xengine status" console command. For debugging purposes. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index aeb807c..965101a 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -455,9 +455,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine StringBuilder sb = new StringBuilder(); sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); + long scriptsLoaded, eventsQueued = 0, eventsProcessed = 0; + lock (m_Scripts) - sb.AppendFormat("Scripts loaded : {0}\n", m_Scripts.Count); + { + scriptsLoaded = m_Scripts.Count; + + foreach (IScriptInstance si in m_Scripts.Values) + { + eventsQueued += si.EventsQueued; + eventsProcessed += si.EventsProcessed; + } + } + sb.AppendFormat("Scripts loaded : {0}\n", scriptsLoaded); sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); @@ -466,6 +477,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); + sb.AppendFormat("Events queued : {0}\n", eventsQueued); + sb.AppendFormat("Events processed : {0}\n", eventsProcessed); SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); -- cgit v1.1 From e60fe958df1709d1443abaa44faa4736f515f977 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 5 Dec 2012 23:44:12 +0000 Subject: minor: Fix more compiler warnings in CoreModules tests by properly overriding OpenSimTestCase.SetUp() --- OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs | 4 +++- .../Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | 4 +++- .../ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs | 5 ++++- OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs | 4 +++- OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index 0872cc8..fd02b08 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -53,8 +53,10 @@ namespace OpenSim.Region.CoreModules.Asset.Tests protected FlotsamAssetCache m_cache; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + IConfigSource config = new IniConfigSource(); config.AddConfig("Modules"); diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs index b768257..ac25a93 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs @@ -57,8 +57,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests protected TestClient m_tc; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + m_iam = new BasicInventoryAccessModule(); IConfigSource config = new IniConfigSource(); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs index 7e365ca..69bac82 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs @@ -46,8 +46,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests public class PresenceConnectorsTests : OpenSimTestCase { LocalPresenceServicesConnector m_LocalConnector; - private void SetUp() + + public override void SetUp() { + base.SetUp(); + IConfigSource config = new IniConfigSource(); config.AddConfig("Modules"); config.AddConfig("PresenceService"); diff --git a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs index 14eca42..0945b43 100644 --- a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs +++ b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs @@ -60,8 +60,10 @@ namespace OpenSim.Region.CoreModules.World.Land.Tests protected ILandObject m_lo2; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + m_pcm = new PrimCountModule(); LandManagementModule lmm = new LandManagementModule(); m_scene = new SceneHelpers().SetupScene(); diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs b/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs index ba4b041..03a96a4 100644 --- a/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs +++ b/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs @@ -50,8 +50,10 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap.Tests protected MoapModule m_module; [SetUp] - public void SetUp() + public override void SetUp() { + base.SetUp(); + m_module = new MoapModule(); m_scene = new SceneHelpers().SetupScene(); SceneHelpers.SetupSceneModules(m_scene, m_module); -- cgit v1.1 From 1c9ecc55d3ae52548f974c4c19cc1f8ed6fb7d88 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 6 Dec 2012 00:22:52 +0000 Subject: Instead of printing script errors out to console, put to debug log so that we also get timestamps. This commit also adds script name, part name, uuid, etc. for later identification. This information has been sent to console since 2009 but may be turned down if it proves too noisy. However, I still currently need it to investigate some region problems probably triggered by scripting. --- .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 8e81e9f..5ad6eeb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -785,6 +785,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance ChatTypeEnum.DebugChannel, 2147483647, part.AbsolutePosition, part.Name, part.UUID, false); + + + m_log.DebugFormat( + "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", + ScriptName, + PrimName, + part.UUID, + part.AbsolutePosition, + part.ParentGroup.Scene.Name, + text.Replace("\n", "\\n"), + e.InnerException); } catch (Exception) { @@ -1026,7 +1037,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance "({0}): {1}", scriptLine - 1, e.InnerException.Message); - System.Console.WriteLine(e.ToString()+"\n"); return message; } } -- cgit v1.1 From acc01bb85d5c5f15a3943a908433b7fe08075c93 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 6 Dec 2012 01:12:12 +0000 Subject: Allow GetTexture calls with no second value in the range header (e.g. just 5333-) It looks like the latest Kokua is doing this. As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, leaving off the second value is legal This indicates the caller wants the rest of the entity. --- .../Handlers/GetTexture/GetTextureHandler.cs | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 04cc33a..6e9094a 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs @@ -246,6 +246,11 @@ namespace OpenSim.Capabilities.Handlers } else { + // Handle the case where no second range value was given. This is equivalent to requesting + // the rest of the entity. + if (end == -1) + end = int.MaxValue; + end = Utils.Clamp(end, 0, texture.Data.Length - 1); start = Utils.Clamp(start, 0, end); int len = end - start + 1; @@ -299,15 +304,43 @@ namespace OpenSim.Capabilities.Handlers // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); } + /// + /// Parse a range header. + /// + /// + /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, + /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). + /// Where there is no value, -1 is returned. + /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 + /// for start. + /// + /// + /// Undefined if the parse fails. + /// Undefined if the parse fails. private bool TryParseRange(string header, out int start, out int end) { + start = end = 0; + if (header.StartsWith("bytes=")) { string[] rangeValues = header.Substring(6).Split('-'); + if (rangeValues.Length == 2) { - if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) + if (!Int32.TryParse(rangeValues[0], out start)) + return false; + + string rawEnd = rangeValues[1]; + + if (rawEnd == "") + { + end = -1; + return true; + } + else if (Int32.TryParse(rawEnd, out end)) + { return true; + } } } -- cgit v1.1 From 68daeee4342757340177a015a30b78c54674fafc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 6 Dec 2012 01:36:30 +0000 Subject: minor: change method doc on GetTextureHandler.TryParseRange(), mainly to trigger another build --- OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 6e9094a..b497fde 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs @@ -315,8 +315,8 @@ namespace OpenSim.Capabilities.Handlers /// for start. /// /// - /// Undefined if the parse fails. - /// Undefined if the parse fails. + /// Start of the range. Undefined if this was not a number. + /// End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number. private bool TryParseRange(string header, out int start, out int end) { start = end = 0; -- cgit v1.1 From e599a8b2421ab51860c65e49bdfd38fa064fa9b8 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 5 Dec 2012 09:27:38 -0800 Subject: BulletSim: Vehicle angular vertical attraction works. Other vehicle angular forces commented out for the moment for debugging. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 55 ++++++++++++++-------- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 3 ++ 2 files changed, 38 insertions(+), 20 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index be8a502..a83d966 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -620,11 +620,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin private Vector3? m_knownVelocity; private Quaternion? m_knownOrientation; private Vector3? m_knownRotationalVelocity; + private Vector3? m_knownRotationalForce; private const int m_knownChangedPosition = 1 << 0; private const int m_knownChangedVelocity = 1 << 1; private const int m_knownChangedOrientation = 1 << 2; private const int m_knownChangedRotationalVelocity = 1 << 3; + private const int m_knownChangedRotationalForce = 1 << 4; private void ForgetKnownVehicleProperties() { @@ -634,6 +636,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownVelocity = null; m_knownOrientation = null; m_knownRotationalVelocity = null; + m_knownRotationalForce = null; m_knownChanged = 0; } private void PushKnownChanged() @@ -645,12 +648,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin if ((m_knownChanged & m_knownChangedOrientation) != 0) Prim.ForceOrientation = VehicleOrientation; if ((m_knownChanged & m_knownChangedVelocity) != 0) + { Prim.ForceVelocity = VehicleVelocity; + BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity); + } if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) { Prim.ForceRotationalVelocity = VehicleRotationalVelocity; + // Fake out Bullet by making it think the velocity is the same as last time. BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, VehicleRotationalVelocity); } + if ((m_knownChanged & m_knownChangedRotationalForce) != 0) + Prim.AddAngularForce((Vector3)m_knownRotationalForce, false, true); + // If we set one of the values (ie, the physics engine didn't do it) we must force // an UpdateProperties event to send the changes up to the simulator. BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); @@ -734,6 +744,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownChanged |= m_knownChangedRotationalVelocity; } } + private void VehicleAddAngularForce(Vector3 aForce) + { + m_knownRotationalForce += aForce; + m_knownChanged |= m_knownChangedRotationalForce; + } #endregion // Known vehicle value functions // One step of the vehicle properties for the next 'pTimestep' seconds. @@ -1013,11 +1028,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin + bankingContribution; // ================================================================== - // The correction is applied to the current orientation. + // Apply the correction velocity. + // TODO: Should this be applied as an angular force (torque)? if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f)) { Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep; - VehicleRotationalVelocity = scaledCorrection; VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}", @@ -1029,7 +1044,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin } else { - // The vehicle is not adding anything velocity wise. + // The vehicle is not adding anything angular wise. VehicleRotationalVelocity = Vector3.Zero; VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); } @@ -1060,8 +1075,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin torqueFromOffset.Y = 0; if (float.IsNaN(torqueFromOffset.Z)) torqueFromOffset.Z = 0; - torqueFromOffset *= m_vehicleMass; - Prim.ApplyTorqueImpulse(torqueFromOffset, true); + + VehicleAddAngularForce(torqueFromOffset * m_vehicleMass); VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); } @@ -1097,23 +1112,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin ret.Y = - verticalError.X; ret.Z = 0f; - // scale by the time scale and timestep + // Scale the correction force by how far we're off from vertical. + // Z error of one says little error. As Z gets smaller, the vehicle is leaning farther over. + // float clampedZError = ClampInRange(0.1f, Math.Abs(verticalError.Z), 1f); + float clampedSqrZError = ClampInRange(0.01f, verticalError.Z * verticalError.Z, 1f); + // float vertForce = 1f / clampedSqrZError * m_verticalAttractionEfficiency; + float vertForce = 1f / clampedSqrZError; + + ret *= vertForce; + + // Correction happens over a number of seconds. Vector3 unscaledContrib = ret; ret /= m_verticalAttractionTimescale; - // This returns the angular correction desired. Timestep is added later. - // ret *= pTimestep; - - // apply efficiency - Vector3 preEfficiencyContrib = ret; - // TODO: implement efficiency. - // Effenciency squared seems to give a more realistic effect - float efficencySquared = m_verticalAttractionEfficiency * m_verticalAttractionEfficiency; - // ret *= efficencySquared; - - VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},preEff={3},eff={4},effSq={5},vertAttr={6}", - Prim.LocalID, verticalError, unscaledContrib, preEfficiencyContrib, - m_verticalAttractionEfficiency, efficencySquared, - ret); + + VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},vertForce={3},eff={4},vertAttr={5}", + Prim.LocalID, verticalError, unscaledContrib, vertForce, m_verticalAttractionEfficiency, ret); } return ret; } @@ -1123,6 +1136,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin public Vector3 ComputeAngularDeflection() { Vector3 ret = Vector3.Zero; + return ret; // DEBUG DEBUG DEBUG debug the other contributors first if (m_angularDeflectionEfficiency != 0) { @@ -1151,6 +1165,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { Vector3 ret = Vector3.Zero; Vector3 computedBanking = Vector3.Zero; + return ret; // DEBUG DEBUG DEBUG debug the other contributors first if (m_bankingEfficiency != 0) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index ea1f71a..e392078 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -1010,6 +1010,9 @@ public sealed class BSPrim : BSPhysObject }); } // A torque impulse. + // ApplyTorqueImpulse adds torque directly to the angularVelocity. + // AddAngularForce accumulates the force and applied it to the angular velocity all at once. + // Computed as: angularVelocity += impulse * inertia; public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) { OMV.Vector3 applyImpulse = impulse; -- cgit v1.1 From 6d7f66f78192c686f2f9666bbb4c4517310c30a7 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 5 Dec 2012 09:45:33 -0800 Subject: BulletSim: Don't add gravity to down force -- let Bullet do that. Add VehicleAddForce to set of managed vehicle prim properties. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 42 ++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index a83d966..09aee17 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -618,15 +618,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin private float? m_knownWaterLevel; private Vector3? m_knownPosition; private Vector3? m_knownVelocity; + private Vector3? m_knownForce; private Quaternion? m_knownOrientation; private Vector3? m_knownRotationalVelocity; private Vector3? m_knownRotationalForce; private const int m_knownChangedPosition = 1 << 0; private const int m_knownChangedVelocity = 1 << 1; - private const int m_knownChangedOrientation = 1 << 2; - private const int m_knownChangedRotationalVelocity = 1 << 3; - private const int m_knownChangedRotationalForce = 1 << 4; + private const int m_knownChangedForce = 1 << 2; + private const int m_knownChangedOrientation = 1 << 3; + private const int m_knownChangedRotationalVelocity = 1 << 4; + private const int m_knownChangedRotationalForce = 1 << 5; private void ForgetKnownVehicleProperties() { @@ -634,6 +636,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownWaterLevel = null; m_knownPosition = null; m_knownVelocity = null; + m_knownForce = null; m_knownOrientation = null; m_knownRotationalVelocity = null; m_knownRotationalForce = null; @@ -652,6 +655,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin Prim.ForceVelocity = VehicleVelocity; BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity); } + if ((m_knownChanged & m_knownChangedForce) != 0) + Prim.AddForce((Vector3)m_knownForce, false, true); + if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) { Prim.ForceRotationalVelocity = VehicleRotationalVelocity; @@ -730,6 +736,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin } } + private void VehicleAddForce(Vector3 aForce) + { + m_knownForce += aForce; + m_knownChanged |= m_knownChangedForce; + } + private Vector3 VehicleRotationalVelocity { get @@ -784,10 +796,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin linearMotorContribution *= VehicleOrientation; // ================================================================== - // Gravity and Buoyancy - // There is some gravity, make a gravity force vector that is applied after object velocity. + // Buoyancy: force to overcome gravity. // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; - Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy); + Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * (m_VehicleBuoyancy - 1f); Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep); @@ -812,14 +823,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin newVelocity.Z = 0; // ================================================================== - // Clamp REALLY high or low velocities + // Clamp high or low velocities float newVelocityLengthSq = newVelocity.LengthSquared(); - if (newVelocityLengthSq > 1e6f) + // if (newVelocityLengthSq > 1e6f) + if (newVelocityLengthSq > 1000f) { newVelocity /= newVelocity.Length(); newVelocity *= 1000f; } - else if (newVelocityLengthSq < 1e-6f) + // else if (newVelocityLengthSq < 1e-6f) + else if (newVelocityLengthSq < 0.001f) newVelocity = Vector3.Zero; // ================================================================== @@ -828,15 +841,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleVelocity = newVelocity; // Other linear forces are applied as forces. - Vector3 totalDownForce = grav * m_vehicleMass * pTimestep; - if (totalDownForce != Vector3.Zero) + Vector3 totalDownForce = buoyancyContribution * m_vehicleMass; + if (!totalDownForce.ApproxEquals(Vector3.Zero, 0.01f)) { - Prim.AddForce(totalDownForce, false); + VehicleAddForce(totalDownForce); } - VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},linContrib={3},terrContrib={4},hoverContrib={5},limitContrib={6}", + VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},linContrib={3},terrContrib={4},hoverContrib={5},limitContrib={6},buoyContrib={7}", Prim.LocalID, newVelocity, totalDownForce, - linearMotorContribution, terrainHeightContribution, hoverContribution, limitMotorUpContribution + linearMotorContribution, terrainHeightContribution, hoverContribution, + limitMotorUpContribution, buoyancyContribution ); } // end MoveLinear() -- cgit v1.1 From 2ecd8e6720ebc9668aa30a8276c8b15a8650b8fe Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 6 Dec 2012 06:45:51 -0800 Subject: BulletSim: add values for material friction and restitution. Fix line endings in material definition file. --- .../Region/Physics/BulletSPlugin/BSMaterials.cs | 376 ++++++++++----------- 1 file changed, 185 insertions(+), 191 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs index 663b6f4..390c2f9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs @@ -1,191 +1,185 @@ -/* - * 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 copyrightD - * 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.Text; -using System.Reflection; -using Nini.Config; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ - -public struct MaterialAttributes -{ - // Material type values that correspond with definitions for LSL - public enum Material : int - { - Stone = 0, - Metal, - Glass, - Wood, - Flesh, - Plastic, - Rubber, - Light, - // Hereafter are BulletSim additions - Avatar, - NumberOfTypes // the count of types in the enum. - } - // Names must be in the order of the above enum. - public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", - "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; - public static string[] MaterialAttribs = { "Density", "Friction", "Restitution", - "ccdMotionThreshold", "ccdSweptSphereRadius" }; - - public MaterialAttributes(string t, float d, float f, float r, float ccdM, float ccdS) - { - type = t; - density = d; - friction = f; - restitution = r; - ccdMotionThreshold = ccdM; - ccdSweptSphereRadius = ccdS; - } - public string type; - public float density; - public float friction; - public float restitution; - public float ccdMotionThreshold; - public float ccdSweptSphereRadius; -} - -public static class BSMaterials -{ - public static MaterialAttributes[] Attributes; - - static BSMaterials() - { - // Attribute sets for both the non-physical and physical instances of materials. - Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; - } - - // This is where all the default material attributes are defined. - public static void InitializeFromDefaults(ConfigurationParameters parms) - { - // public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", - // "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; - float dFriction = parms.defaultFriction; - float dRestitution = parms.defaultRestitution; - float dDensity = parms.defaultDensity; - float dCcdM = parms.ccdMotionThreshold; - float dCcdS = parms.ccdSweptSphereRadius; - Attributes[(int)MaterialAttributes.Material.Stone] = - new MaterialAttributes("stone",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Metal] = - new MaterialAttributes("metal",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Glass] = - new MaterialAttributes("glass",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Wood] = - new MaterialAttributes("wood",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Flesh] = - new MaterialAttributes("flesh",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Plastic] = - new MaterialAttributes("plastic",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Rubber] = - new MaterialAttributes("rubber",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Light] = - new MaterialAttributes("light",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Avatar] = - new MaterialAttributes("avatar",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - - Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("stonePhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("metalPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("glassPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("woodPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("fleshPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("plasticPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("rubberPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("lightPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("avatarPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); - } - - // Under the [BulletSim] section, one can change the individual material - // attribute values. The format of the configuration parameter is: - // ["Physical"] = floatValue - // For instance: - // [BulletSim] - // StoneFriction = 0.2 - // FleshRestitutionPhysical = 0.8 - // Materials can have different parameters for their static and - // physical instantiations. When setting the non-physical value, - // both values are changed. Setting the physical value only changes - // the physical value. - public static void InitializefromParameters(IConfig pConfig) - { - int matType = 0; - foreach (string matName in MaterialAttributes.MaterialNames) - { - foreach (string attribName in MaterialAttributes.MaterialAttribs) - { - string paramName = matName + attribName; - if (pConfig.Contains(paramName)) - { - float paramValue = pConfig.GetFloat(paramName); - SetAttributeValue(matType, attribName, paramValue); - // set the physical value also - SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); - } - paramName += "Physical"; - if (pConfig.Contains(paramName)) - { - float paramValue = pConfig.GetFloat(paramName); - SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); - } - } - matType++; - } - } - - private static void SetAttributeValue(int matType, string attribName, float val) - { - MaterialAttributes thisAttrib = Attributes[matType]; - FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); - if (fieldInfo != null) - { - fieldInfo.SetValue(thisAttrib, val); - Attributes[matType] = thisAttrib; - } - } - - public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) - { - int ind = (int)type; - if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; - return Attributes[ind]; - } - -} -} +/* + * 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 copyrightD + * 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.Text; +using System.Reflection; +using Nini.Config; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ + +public struct MaterialAttributes +{ + // Material type values that correspond with definitions for LSL + public enum Material : int + { + Stone = 0, + Metal, + Glass, + Wood, + Flesh, + Plastic, + Rubber, + Light, + // Hereafter are BulletSim additions + Avatar, + NumberOfTypes // the count of types in the enum. + } + // Names must be in the order of the above enum. + public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", + "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; + public static string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; + + public MaterialAttributes(string t, float d, float f, float r) + { + type = t; + density = d; + friction = f; + restitution = r; + } + public string type; + public float density; + public float friction; + public float restitution; +} + +public static class BSMaterials +{ + public static MaterialAttributes[] Attributes; + + static BSMaterials() + { + // Attribute sets for both the non-physical and physical instances of materials. + Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; + } + + // This is where all the default material attributes are defined. + public static void InitializeFromDefaults(ConfigurationParameters parms) + { + // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL + // public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", + // "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; + float dFriction = parms.defaultFriction; + float dRestitution = parms.defaultRestitution; + float dDensity = parms.defaultDensity; + Attributes[(int)MaterialAttributes.Material.Stone] = + new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); + Attributes[(int)MaterialAttributes.Material.Metal] = + new MaterialAttributes("metal",dDensity, 0.3f, 0.4f); + Attributes[(int)MaterialAttributes.Material.Glass] = + new MaterialAttributes("glass",dDensity, 0.2f, 0.7f); + Attributes[(int)MaterialAttributes.Material.Wood] = + new MaterialAttributes("wood",dDensity, 0.6f, 0.5f); + Attributes[(int)MaterialAttributes.Material.Flesh] = + new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f); + Attributes[(int)MaterialAttributes.Material.Plastic] = + new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f); + Attributes[(int)MaterialAttributes.Material.Rubber] = + new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f); + Attributes[(int)MaterialAttributes.Material.Light] = + new MaterialAttributes("light",dDensity, dFriction, dRestitution); + Attributes[(int)MaterialAttributes.Material.Avatar] = + new MaterialAttributes("avatar",60f, 0.2f, 0f); + + Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); + Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f); + Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f); + Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f); + Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f); + Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f); + Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f); + Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); + Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = + new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f); + } + + // Under the [BulletSim] section, one can change the individual material + // attribute values. The format of the configuration parameter is: + // ["Physical"] = floatValue + // For instance: + // [BulletSim] + // StoneFriction = 0.2 + // FleshRestitutionPhysical = 0.8 + // Materials can have different parameters for their static and + // physical instantiations. When setting the non-physical value, + // both values are changed. Setting the physical value only changes + // the physical value. + public static void InitializefromParameters(IConfig pConfig) + { + int matType = 0; + foreach (string matName in MaterialAttributes.MaterialNames) + { + foreach (string attribName in MaterialAttributes.MaterialAttribs) + { + string paramName = matName + attribName; + if (pConfig.Contains(paramName)) + { + float paramValue = pConfig.GetFloat(paramName); + SetAttributeValue(matType, attribName, paramValue); + // set the physical value also + SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); + } + paramName += "Physical"; + if (pConfig.Contains(paramName)) + { + float paramValue = pConfig.GetFloat(paramName); + SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); + } + } + matType++; + } + } + + private static void SetAttributeValue(int matType, string attribName, float val) + { + MaterialAttributes thisAttrib = Attributes[matType]; + FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); + if (fieldInfo != null) + { + fieldInfo.SetValue(thisAttrib, val); + Attributes[matType] = thisAttrib; + } + } + + public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) + { + int ind = (int)type; + if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; + return Attributes[ind]; + } + +} +} -- cgit v1.1 From cc59e3cbdf2d660422bc8707816d7d30d7c72b92 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 6 Dec 2012 09:21:04 -0800 Subject: BulletSim: only check position sanity if the prim is physical -- the user can do anything dumb they wish. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index e392078..62aaf80 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -1399,7 +1399,7 @@ public sealed class BSPrim : BSPhysObject _rotationalVelocity = entprop.RotationalVelocity; // The sanity check can change the velocity and/or position. - if (PositionSanityCheck(true)) + if (IsPhysical && PositionSanityCheck(true)) { entprop.Position = _position; entprop.Velocity = _velocity; @@ -1413,8 +1413,6 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); - // BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, BSBody.ptr); // DEBUG DEBUG DEBUG - base.RequestPhysicsterseUpdate(); } /* -- cgit v1.1 From 18fe35906dd07ecfe8f8b439f5648982262aa17f Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 6 Dec 2012 09:22:29 -0800 Subject: BulletSim: add detail logging detail flag so I don't have to comment and uncomment the detail logging when changing the depth of logged info. --- .../Physics/BulletSPlugin/BSShapeCollection.cs | 61 ++++++++++++---------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index b94dcf6..e77b6ba 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -65,9 +65,16 @@ public sealed class BSShapeCollection : IDisposable private Dictionary Meshes = new Dictionary(); private Dictionary Hulls = new Dictionary(); + private bool DDetail = false; + public BSShapeCollection(BSScene physScene) { PhysicsScene = physScene; + // Set the next to 'true' for very detailed shape update detailed logging (detailed details?) + // While detailed debugging is still active, this is better than commenting out all the + // DetailLog statements. When debugging slows down, this and the protected logging + // statements can be commented/removed. + DDetail = true; } public void Dispose() @@ -126,13 +133,13 @@ public sealed class BSShapeCollection : IDisposable { lock (m_collectionActivityLock) { - DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() { if (!BulletSimAPI.IsInWorld2(body.ptr)) { BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); - DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); } }); } @@ -149,7 +156,7 @@ public sealed class BSShapeCollection : IDisposable { PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() { - DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}", body.ID, body, inTaintTime); // If the caller needs to know the old body is going away, pass the event up. if (bodyCallback != null) bodyCallback(body); @@ -157,7 +164,7 @@ public sealed class BSShapeCollection : IDisposable if (BulletSimAPI.IsInWorld2(body.ptr)) { BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); - DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); } // Zero any reference to the shape so it is not freed when the body is deleted. @@ -184,7 +191,7 @@ public sealed class BSShapeCollection : IDisposable { // There is an existing instance of this mesh. meshDesc.referenceCount++; - DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); } else @@ -194,7 +201,7 @@ public sealed class BSShapeCollection : IDisposable meshDesc.shapeKey = shape.shapeKey; // We keep a reference to the underlying IMesh data so a hull can be built meshDesc.referenceCount = 1; - DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); ret = true; } @@ -207,7 +214,7 @@ public sealed class BSShapeCollection : IDisposable { // There is an existing instance of this hull. hullDesc.referenceCount++; - DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); } else @@ -216,7 +223,7 @@ public sealed class BSShapeCollection : IDisposable hullDesc.ptr = shape.ptr; hullDesc.shapeKey = shape.shapeKey; hullDesc.referenceCount = 1; - DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); ret = true; @@ -246,7 +253,7 @@ public sealed class BSShapeCollection : IDisposable if (shape.isNativeShape) { // Native shapes are not tracked and are released immediately - DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); if (shapeCallback != null) shapeCallback(shape); BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); @@ -286,7 +293,7 @@ public sealed class BSShapeCollection : IDisposable if (shapeCallback != null) shapeCallback(shape); meshDesc.lastReferenced = System.DateTime.Now; Meshes[shape.shapeKey] = meshDesc; - DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", BSScene.DetailLogZero, shape, meshDesc.referenceCount); } @@ -307,7 +314,7 @@ public sealed class BSShapeCollection : IDisposable hullDesc.lastReferenced = System.DateTime.Now; Hulls[shape.shapeKey] = hullDesc; - DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", BSScene.DetailLogZero, shape, hullDesc.referenceCount); } } @@ -325,13 +332,13 @@ public sealed class BSShapeCollection : IDisposable // Failed the sanity check!! PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", LogHeader, shape.type, shape.ptr.ToString("X")); - DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); return; } int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); - DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); for (int ii = numChildren - 1; ii >= 0; ii--) { @@ -379,7 +386,7 @@ public sealed class BSShapeCollection : IDisposable } } - DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); + if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN) { @@ -410,7 +417,7 @@ public sealed class BSShapeCollection : IDisposable // an avatar capsule is close to a native shape (it is not shared) ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE, shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape); ret = true; haveShape = true; } @@ -420,7 +427,7 @@ public sealed class BSShapeCollection : IDisposable if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) { ret = GetReferenceToCompoundShape(prim, shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape); haveShape = true; } @@ -465,7 +472,7 @@ public sealed class BSShapeCollection : IDisposable { ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_SPHERE, FixedShapeKey.KEY_SPHERE, shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},shape={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},shape={2}", prim.LocalID, forceRebuild, prim.PhysShape); } } @@ -479,7 +486,7 @@ public sealed class BSShapeCollection : IDisposable { ret = GetReferenceToNativeShape( prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX, shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},shape={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},shape={2}", prim.LocalID, forceRebuild, prim.PhysShape); } } @@ -504,13 +511,13 @@ public sealed class BSShapeCollection : IDisposable { // Update prim.BSShape to reference a hull of this shape. ret = GetReferenceToHull(prim,shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); } else { ret = GetReferenceToMesh(prim, shapeCallback); - DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); } return ret; @@ -528,7 +535,7 @@ public sealed class BSShapeCollection : IDisposable BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey); // Don't need to do a 'ReferenceShape()' here because native shapes are not shared. - DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}", prim.LocalID, newShape, prim.Scale); prim.PhysShape = newShape; @@ -554,7 +561,7 @@ public sealed class BSShapeCollection : IDisposable newShape = new BulletShape( BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale) , shapeType); - DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); + if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); } else { @@ -589,7 +596,7 @@ public sealed class BSShapeCollection : IDisposable if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH) return false; - DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}", prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); // Since we're recreating new, get rid of the reference to the previous shape @@ -662,7 +669,7 @@ public sealed class BSShapeCollection : IDisposable if (newHullKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_HULL) return false; - DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}", prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X")); // Remove usage of the previous shape. @@ -808,7 +815,7 @@ public sealed class BSShapeCollection : IDisposable // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. CreateGeomMeshOrHull(prim, shapeCallback); BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); - DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", + if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", prim.LocalID, cShape, prim.PhysShape); prim.PhysShape = cShape; @@ -935,13 +942,13 @@ public sealed class BSShapeCollection : IDisposable { bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); - DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } else { bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); - DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } aBody = new BulletBody(prim.LocalID, bodyPtr); -- cgit v1.1 From edd1b353a5b683b7d9b22e80d97e15e05f34611c Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 6 Dec 2012 09:23:20 -0800 Subject: BulletSim: update and add to the TODO list. --- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 87 ++++++++++++++-------- 1 file changed, 56 insertions(+), 31 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 68f25fc..d51003c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -6,14 +6,34 @@ CRASHES Causes many errors. Doesn't stop after first error with box shape. Eventually crashes when deleting the object. -BULLETSIM TODO LIST: +VEHICLES TODO LIST: ================================================= Neb car jiggling left and right + Happens on terrain and any other mesh object. Flat cubes are much smoother. Vehicles (Move smoothly) -Light cycle falling over when driving -Light cycle not banking -Do single prim vehicles don't seem to properly vehiclize. -Gun sending shooter flying +Add vehicle collisions so IsColliding is properly reported. + Needed for banking, limitMotorUp, movementLimiting, ... +Some vehicles should not be able to turn if no speed or off ground. +For limitMotorUp, use raycast down to find if vehicle is in the air. +Implement function efficiency for lineaar and angular motion. +Should vehicle angular/linear movement friction happen after all the components + or does it only apply to the basic movement? +After getting off a vehicle, the root prim is phantom (can be walked through) + Need to force a position update for the root prim after compound shape destruction +Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint) +Implement referenceFrame for all the motion routines. +Cannot edit/move a vehicle being ridden: it jumps back to the origional position. + +BULLETSIM TODO LIST: +================================================= +Disable activity of passive linkset children. + Since the linkset is a compound object, the old prims are left lying + around and need to be phantomized so they don't collide, ... +Scenes with hundred of thousands of static objects take a lot of physics CPU time. +BSPrim.Force should set a continious force on the prim. The force should be + applied each tick. Some limits? +Single prim vehicles don't seem to properly vehiclize. +Gun sending shooter flying. Collision margin (gap between physical objects lying on each other) Boundry checking (crashes related to crossing boundry) Add check for border edge position for avatars and objects. @@ -28,10 +48,11 @@ Small physical objects do not interact correctly Add material type linkage and input all the material property definitions. Skeleton classes and table are in the sources but are not filled or used. Add PID motor for avatar movement (slow to stop, ...) -Implement function efficiency for lineaar and angular motion. +setForce should set a constant force. Different than AddImpulse. +Implement raycast. +Implement ShapeCollection.Dispose() +Implement water as a plain so raycasting and collisions can happen with same. -After getting off a vehicle, the root prim is phantom (can be walked through) - Need to force a position update for the root prim after compound shape destruction Find/remove avatar collision with ID=0. Test avatar walking up stairs. How does compare with SL. Radius of the capsule affects ability to climb edges. @@ -39,19 +60,16 @@ Tune terrain/object friction to be closer to SL. Debounce avatar contact so legs don't keep folding up when standing. Implement LSL physics controls. Like STATUS_ROTATE_X. Add border extensions to terrain to help region crossings and objects leaving region. -Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint) Speed up creation of large physical linksets For instance, sitting in Neb's car (130 prims) takes several seconds to become physical Performance test with lots of avatars. Can BulletSim support a thousand? Optimize collisions in C++: only send up to the object subscribed to collisions. Use collision subscription and remove the collsion(A,B) and collision(B,A) -Check wheter SimMotionState needs large if statement (see TODO). +Check whether SimMotionState needs large if statement (see TODO). Implement 'top colliders' info. Avatar jump -Implement meshes or just verify that they work. -Do prim hash codes work for sculpties and meshes? Performance measurement and changes to make quicker. Implement detailed physics stats (GetStats()). @@ -67,8 +85,6 @@ Performance of closures and delegates for taint processing Is there are more efficient method of implementing pre and post step actions? See http://www.codeproject.com/Articles/29922/Weak-Events-in-C -Package Bullet source mods for Bullet internal stats output - Physics Arena central pyramid: why is one side permiable? INTERNAL IMPROVEMENT/CLEANUP @@ -85,33 +101,42 @@ Complete implemention of preStepActions Replace vehicle step call with prestep event. Is there a need for postStepActions? postStepTaints? Implement linkset by setting position of children when root updated. (LinksetManual) + Linkset implementation using manual prim movement. LinkablePrim class? Would that simplify/centralize the linkset logic? -Linkset implementation using manual prim movement. -Linkset implementation using compound shapes. - Compound shapes will need the LocalID in the shapes and collision - processing to get it from there. BSScene.UpdateParameterSet() is broken. How to set params on objects? Remove HeightmapInfo from terrain specification. Since C++ code does not need terrain height, this structure et al are not needed. Add floating motor for BS_FLOATS_ON_WATER so prim and avatar will bob at the water level. BSPrim.PositionSanityCheck(). +THREADING +================================================= +Do taint action immediately if not actually executing Bullet. + Add lock around Bullet execution and just do taint actions if simulation is not happening. + DONE DONE DONE DONE ================================================= -Cleanup code in BSDynamics by using motors. -Consider implementing terrain with a mesh rather than heightmap. +Cleanup code in BSDynamics by using motors. (Resolution: started) +Consider implementing terrain with a mesh rather than heightmap. (Resolution: done) Would have better and adjustable resolution. -NOTDONE: Build terrain mesh so heighmap is height of the center of the square meter. - SL and ODE define meter square as being at one corner with one diagional. -Terrain as mesh. +Build terrain mesh so heighmap is height of the center of the square meter. + Resolution: NOT DONE: SL and ODE define meter square as being at one corner with one diagional. +Terrain as mesh. (Resolution: done) How are static linksets seen by the physics engine? - A: they are not linked in physics. When moved, all the children are repositioned. -Remember to remove BSScene.DetailLog Refresh call. -Convert BSCharacter to use all API2 + Resolution: they are not linked in physics. When moved, all the children are repositioned. +Convert BSCharacter to use all API2 (Resolution: done) Avatar pushing difficult (too heavy?) -Use asset service passed to BulletSim to get sculptie bodies, etc. -Vehicles (fix bouncing on terrain) -Remove old code in DLL (all non-API2 stuff). -Measurements of mega-physical prim performance (with graph) +Use asset service passed to BulletSim to get sculptie bodies, etc. (Resolution: done) +Remove old code in DLL (all non-API2 stuff). (Resolution: done) +Measurements of mega-physical prim performance (with graph) (Resolution: done, email) Debug Bullet internal stats output (why is timing all wrong?) - Bullet stats logging only works with a single instance of Bullet (one region). \ No newline at end of file + Resolution: Bullet stats logging only works with a single instance of Bullet (one region). +Implement meshes or just verify that they work. (Resolution: they do!) +Do prim hash codes work for sculpties and meshes? (Resolution: yes) +Linkset implementation using compound shapes. (Resolution: implemented LinksetCompound) + Compound shapes will need the LocalID in the shapes and collision + processing to get it from there. +Light cycle falling over when driving (Resolution: implemented VerticalAttractor) +Light cycle not banking (Resolution: It doesn't. Banking is roll adding yaw.) +Package Bullet source mods for Bullet internal stats output + (Resolution: move code into WorldData.h rather than relying on patches) \ No newline at end of file -- cgit v1.1 From 7fd8202ae3fbe5627396f34dfc03e3571f4f9fe4 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 6 Dec 2012 09:24:24 -0800 Subject: BulletSim: rewrite and improve vehicle angularDeflection, verticalAttraction, linearMotorUp and related vehicle forces. Fixed problems with downward vehicle position correction forces being too large. Add vehicle collision flag so can sense whether vehicle is on the ground. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 212 +++++++++++++-------- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 1 + 2 files changed, 130 insertions(+), 83 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 09aee17..fa3110c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -24,21 +24,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - -/* RA: June 14, 2011. Copied from ODEDynamics.cs and converted to - * call the BulletSim system. - */ -/* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces - * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised: - * ODEPrim.cs contains methods dealing with Prim editing, Prim - * characteristics and Kinetic motion. - * ODEDynamics.cs contains methods dealing with Prim Physical motion - * (dynamics) and the associated settings. Old Linear and angular - * motors for dynamic motion have been replace with MoveLinear() - * and MoveAngular(); 'Physical' is used only to switch ODE dynamic - * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_ is to - * switch between 'VEHICLE' parameter use and general dynamics - * settings use. + * The quotations from http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial + * are Copyright (c) 2009 Linden Research, Inc and are used under their license + * of Creative Commons Attribution-Share Alike 3.0 + * (http://creativecommons.org/licenses/by-sa/3.0/). */ using System; @@ -111,7 +100,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin private float m_bankingEfficiency = 0; private float m_bankingMix = 0; private float m_bankingTimescale = 0; - private Vector3 m_lastBanking = Vector3.Zero; //Hover and Buoyancy properties private float m_VhoverHeight = 0f; @@ -125,8 +113,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin //Attractor properties private BSVMotor m_verticalAttractionMotor = new BSVMotor("VerticalAttraction"); - private float m_verticalAttractionEfficiency = 1.0f; // damped - private float m_verticalAttractionTimescale = 600f; // Timescale > 500 means no vert attractor. + private float m_verticalAttractionEfficiency = 1.0f; // damped + private float m_verticalAttractionCutoff = 500f; // per the documentation + // Timescale > cutoff means no vert attractor. + private float m_verticalAttractionTimescale = 510f; public BSDynamics(BSScene myScene, BSPrim myPrim) { @@ -329,7 +319,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = 0; m_bankingTimescale = 1000; m_bankingMix = 1; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; m_flags = (VehicleFlag)0; @@ -364,7 +353,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = 0; m_bankingTimescale = 10; m_bankingMix = 1; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY @@ -374,6 +362,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP); + break; case Vehicle.TYPE_CAR: m_linearMotorDirection = Vector3.Zero; @@ -403,7 +392,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = -0.2f; m_bankingMix = 1; m_bankingTimescale = 1; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY @@ -442,7 +430,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = -0.3f; m_bankingMix = 0.8f; m_bankingTimescale = 1; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY @@ -481,7 +468,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = 1; m_bankingMix = 0.7f; m_bankingTimescale = 2; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY @@ -520,7 +506,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_bankingEfficiency = 0; m_bankingMix = 0.7f; m_bankingTimescale = 5; - m_lastBanking = Vector3.Zero; m_referenceFrame = Quaternion.Identity; @@ -554,8 +539,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Z goes away and we keep X and Y m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) - - // m_bankingMotor = new BSVMotor("BankingMotor", ...); } // Some of the properties of this prim may have changed. @@ -577,15 +560,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin float angularDamping = PhysicsScene.Params.vehicleAngularDamping; BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping); + // Vehicles report collision events so we know when it's on the ground + BulletSimAPI.AddToCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); + // DEBUG DEBUG DEBUG: use uniform inertia to smooth movement added by Bullet // Vector3 localInertia = new Vector3(1f, 1f, 1f); - Vector3 localInertia = new Vector3(m_vehicleMass, m_vehicleMass, m_vehicleMass); + // Vector3 localInertia = new Vector3(m_vehicleMass, m_vehicleMass, m_vehicleMass); + Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass); BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); VDetailLog("{0},BSDynamics.Refresh,frict={1},inert={2},aDamp={3}", Prim.LocalID, friction, localInertia, angularDamping); } + else + { + BulletSimAPI.RemoveFromCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); + } } public bool RemoveBodyDependencies(BSPhysObject prim) @@ -618,10 +609,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin private float? m_knownWaterLevel; private Vector3? m_knownPosition; private Vector3? m_knownVelocity; - private Vector3? m_knownForce; + private Vector3 m_knownForce; private Quaternion? m_knownOrientation; private Vector3? m_knownRotationalVelocity; - private Vector3? m_knownRotationalForce; + private Vector3 m_knownRotationalForce; + private float? m_knownForwardSpeed; private const int m_knownChangedPosition = 1 << 0; private const int m_knownChangedVelocity = 1 << 1; @@ -636,10 +628,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownWaterLevel = null; m_knownPosition = null; m_knownVelocity = null; - m_knownForce = null; + m_knownForce = Vector3.Zero; m_knownOrientation = null; m_knownRotationalVelocity = null; - m_knownRotationalForce = null; + m_knownRotationalForce = Vector3.Zero; + m_knownForwardSpeed = null; m_knownChanged = 0; } private void PushKnownChanged() @@ -761,6 +754,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownRotationalForce += aForce; m_knownChanged |= m_knownChangedRotationalForce; } + private float VehicleForwardSpeed + { + get + { + if (m_knownForwardSpeed == null) + m_knownForwardSpeed = (VehicleVelocity * Quaternion.Inverse(VehicleOrientation)).X; + return (float)m_knownForwardSpeed; + } + } + #endregion // Known vehicle value functions // One step of the vehicle properties for the next 'pTimestep' seconds. @@ -798,7 +801,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // ================================================================== // Buoyancy: force to overcome gravity. // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; - Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * (m_VehicleBuoyancy - 1f); + // So, if zero, don't change anything (let gravity happen). If one, negate the effect of gravity. + Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * m_VehicleBuoyancy; Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep); @@ -847,8 +851,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleAddForce(totalDownForce); } - VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},linContrib={3},terrContrib={4},hoverContrib={5},limitContrib={6},buoyContrib={7}", - Prim.LocalID, newVelocity, totalDownForce, + VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},IsColliding={3}", + Prim.LocalID, newVelocity, totalDownForce, Prim.IsColliding); + VDetailLog("{0}, MoveLinear,done,linContrib={1},terrContrib={2},hoverContrib={3},limitContrib={4},buoyContrib={5}", + Prim.LocalID, linearMotorContribution, terrainHeightContribution, hoverContribution, limitMotorUpContribution, buoyancyContribution ); @@ -971,21 +977,24 @@ namespace OpenSim.Region.Physics.BulletSPlugin } // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : - // Prevent ground vehicles from motoring into the sky.This flag has a subtle effect when + // Prevent ground vehicles from motoring into the sky. This flag has a subtle effect when // used with conjunction with banking: the strength of the banking will decay when the // vehicle no longer experiences collisions. The decay timescale is the same as // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering // when they are in mid jump. - // TODO: this code is wrong. Also, what should it do for boats? + // TODO: this code is wrong. Also, what should it do for boats (height from water)? + // This is just using the ground and a general collision check. Should really be using + // a downward raycast to find what is below. public Vector3 ComputeLinearMotorUp(float pTimestep) { Vector3 ret = Vector3.Zero; + if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) { // If the vehicle is motoring into the sky, get it going back down. - // float distanceAboveGround = pos.Z - Math.Max(GetTerrainHeight(pos), GetWaterLevel(pos)); float distanceAboveGround = VehiclePosition.Z - GetTerrainHeight(VehiclePosition); - if (distanceAboveGround > 1f) + // Not colliding if the vehicle is off the ground + if (!Prim.IsColliding) { // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep); // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); @@ -1006,8 +1015,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // ======================================================================= // Apply the effect of the angular motor. // The 'contribution' is how much angular correction velocity each function wants. - // All the contributions are added together and the orientation of the vehicle - // is changed by all the contributed corrections. + // All the contributions are added together and the resulting velocity is + // set directly on the vehicle. private void MoveAngular(float pTimestep) { // The user wants how many radians per second angular change? @@ -1030,7 +1039,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin Vector3 deflectionContribution = ComputeAngularDeflection(); - Vector3 bankingContribution = ComputeAngularBanking(angularMotorContribution.Z); + Vector3 bankingContribution = ComputeAngularBanking(); // ================================================================== m_lastVertAttractor = verticalAttractionContribution; @@ -1095,13 +1104,20 @@ namespace OpenSim.Region.Physics.BulletSPlugin } } - + // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: + // Some vehicles, like boats, should always keep their up-side up. This can be done by + // enabling the "vertical attractor" behavior that springs the vehicle's local z-axis to + // the world z-axis (a.k.a. "up"). To take advantage of this feature you would set the + // VEHICLE_VERTICAL_ATTRACTION_TIMESCALE to control the period of the spring frequency, + // and then set the VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY to control the damping. An + // efficiency of 0.0 will cause the spring to wobble around its equilibrium, while an + // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. public Vector3 ComputeAngularVerticalAttraction() { Vector3 ret = Vector3.Zero; // If vertical attaction timescale is reasonable and we applied an angular force last time... - if (m_verticalAttractionTimescale < 500) + if (m_verticalAttractionTimescale < m_verticalAttractionCutoff) { // Take a vector pointing up and convert it from world to vehicle relative coords. Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; @@ -1128,9 +1144,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Scale the correction force by how far we're off from vertical. // Z error of one says little error. As Z gets smaller, the vehicle is leaning farther over. - // float clampedZError = ClampInRange(0.1f, Math.Abs(verticalError.Z), 1f); float clampedSqrZError = ClampInRange(0.01f, verticalError.Z * verticalError.Z, 1f); - // float vertForce = 1f / clampedSqrZError * m_verticalAttractionEfficiency; float vertForce = 1f / clampedSqrZError; ret *= vertForce; @@ -1147,70 +1161,102 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Return the angular correction to correct the direction the vehicle is pointing to be // the direction is should want to be pointing. + // The vehicle is moving in some direction and correct its orientation to it is pointing + // in that direction. + // TODO: implement reference frame. public Vector3 ComputeAngularDeflection() { Vector3 ret = Vector3.Zero; - return ret; // DEBUG DEBUG DEBUG debug the other contributors first + return ret; // DEBUG DEBUG DEBUG debug one force at a time if (m_angularDeflectionEfficiency != 0) { - // Where the vehicle should want to point relative to the vehicle - Vector3 preferredDirection = Vector3.UnitX * m_referenceFrame; + // The direction the vehicle is moving + Vector3 movingDirection = VehicleVelocity; + movingDirection.Normalize(); - // Where the vehicle is pointing relative to the vehicle. - Vector3 currentDirection = Vector3.UnitX * Quaternion.Add(VehicleOrientation, m_referenceFrame); + // The direction the vehicle is pointing + Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; + pointingDirection.Normalize(); - // Difference between where vehicle is pointing and where it should wish to point - Vector3 directionCorrection = preferredDirection - currentDirection; + // The difference between what is and what should be + Vector3 deflectionError = movingDirection - pointingDirection; // Scale the correction by recovery timescale and efficiency - ret = directionCorrection * m_angularDeflectionEfficiency / m_angularDeflectionTimescale; + ret = (-deflectionError * VehicleForwardSpeed) * m_angularDeflectionEfficiency; + ret /= m_angularDeflectionTimescale; - VDetailLog("{0}, MoveAngular,Deflection,perfDir={1},currentDir={2},dirCorrection={3},ret={4}", - Prim.LocalID, preferredDirection, currentDirection, directionCorrection, ret); + VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", + Prim.LocalID, movingDirection, pointingDirection, deflectionError, ret); } return ret; } - // Return an angular change to tip the vehicle (around X axis) when turning (turned around Z). - // Remembers the last banking value calculated and returns the difference needed this tick. - // TurningFactor is rate going left or right (pos=left, neg=right, scale=0..1). - public Vector3 ComputeAngularBanking(float turningFactor) + // Return an angular change to rotate the vehicle around the Z axis when the vehicle + // is tipped around the X axis. + // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: + // The vertical attractor feature must be enabled in order for the banking behavior to + // function. The way banking works is this: a rotation around the vehicle's roll-axis will + // produce a angular velocity around the yaw-axis, causing the vehicle to turn. The magnitude + // of the yaw effect will be proportional to the + // VEHICLE_BANKING_EFFICIENCY, the angle of the roll rotation, and sometimes the vehicle's + // velocity along its preferred axis of motion. + // The VEHICLE_BANKING_EFFICIENCY can vary between -1 and +1. When it is positive then any + // positive rotation (by the right-hand rule) about the roll-axis will effect a + // (negative) torque around the yaw-axis, making it turn to the right--that is the + // vehicle will lean into the turn, which is how real airplanes and motorcycle's work. + // Negating the banking coefficient will make it so that the vehicle leans to the + // outside of the turn (not very "physical" but might allow interesting vehicles so why not?). + // The VEHICLE_BANKING_MIX is a fake (i.e. non-physical) parameter that is useful for making + // banking vehicles do what you want rather than what the laws of physics allow. + // For example, consider a real motorcycle...it must be moving forward in order for + // it to turn while banking, however video-game motorcycles are often configured + // to turn in place when at a dead stop--because they are often easier to control + // that way using the limited interface of the keyboard or game controller. The + // VEHICLE_BANKING_MIX enables combinations of both realistic and non-realistic + // banking by functioning as a slider between a banking that is correspondingly + // totally static (0.0) and totally dynamic (1.0). By "static" we mean that the + // banking effect depends only on the vehicle's rotation about its roll-axis compared + // to "dynamic" where the banking is also proportional to its velocity along its + // roll-axis. Finding the best value of the "mixture" will probably require trial and error. + // The time it takes for the banking behavior to defeat a preexisting angular velocity about the + // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to + // bank quickly then give it a banking timescale of about a second or less, otherwise you can + // make a sluggish vehicle by giving it a timescale of several seconds. + public Vector3 ComputeAngularBanking() { Vector3 ret = Vector3.Zero; - Vector3 computedBanking = Vector3.Zero; - return ret; // DEBUG DEBUG DEBUG debug the other contributors first - if (m_bankingEfficiency != 0) + if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) { - Vector3 currentDirection = Vector3.UnitX * VehicleOrientation; - - float mult = (m_bankingMix * m_bankingMix) * -1 * (m_bankingMix < 0 ? -1 : 1); + // This works by rotating a unit vector to the orientation of the vehicle. The + // roll (tilt) will be Y component of a tilting Z vector (zero for no tilt + // up to one for full over). + Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; - //Use the square of the efficiency, as it looks much more how SL banking works - float effSquared = (m_bankingEfficiency * m_bankingEfficiency); - if (m_bankingEfficiency < 0) - effSquared *= -1; //Keep the negative! + // Figure out the yaw value for this much roll. + float turnComponent = rollComponents.Y * rollComponents.Y * m_bankingEfficiency; + // Keep the sign + if (rollComponents.Y < 0f) + turnComponent = -turnComponent; - float mix = Math.Abs(m_bankingMix); - // TODO: Must include reference frame. - float forwardSpeed = VehicleVelocity.X; + // TODO: there must be a better computation of the banking force. + float bankingTurnForce = turnComponent; - if (!Prim.IsColliding && forwardSpeed > mix) - { - computedBanking.X = ClampInRange(-3f, turningFactor * (effSquared * mult), 3f); - } + // actual error = static turn error + dynamic turn error + float mixedBankingError = bankingTurnForce * (1f - m_bankingMix) + bankingTurnForce * m_bankingMix * VehicleForwardSpeed; + // TODO: the banking effect should not go to infinity but what to limit it to? + mixedBankingError = ClampInRange(-20f, mixedBankingError, 20f); - // 'computedBanking' is now how much banking that should be happening. - ret = computedBanking - m_lastBanking; + // Build the force vector to change rotation from what it is to what it should be + ret.Z = -mixedBankingError; - // Scale the correction by timescale and efficiency - ret /= m_bankingTimescale * m_bankingEfficiency; + // Don't do it all at once. + ret /= m_bankingTimescale; - VDetailLog("{0}, MoveAngular,Banking,computedB={1},lastB={2},bEff={3},effSq={4},mult={5},mix={6},banking={7}", - Prim.LocalID, computedBanking, m_lastBanking, m_bankingEfficiency, effSquared, mult, mix, ret); + VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},turnComp={3},bankErr={4},mixedBankErr={5},ret={6}", + Prim.LocalID, rollComponents, VehicleForwardSpeed, turnComponent, bankingTurnForce, mixedBankingError, ret); } - m_lastBanking = computedBanking; return ret; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index a5acfd1..2671995 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -360,6 +360,7 @@ public enum CollisionFlags : uint // Following used by BulletSim to control collisions and updates BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, BS_FLOATS_ON_WATER = 1 << 11, + BS_VEHICLE_COLLISIONS = 1 << 12, BS_NONE = 0, BS_ALL = 0xFFFFFFFF, -- cgit v1.1 From 0568c76a8801408665730702c97717d3c05cfe4d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 7 Dec 2012 00:47:04 +0000 Subject: Use a thread abort safe version of OpenMetaverse.DoubleDictionary with the aim of avoiding OpenSimulator problems due to script thread aborts. When an object is removed, its scripts are stopped and then the thread running them is aborted if stop takes too long. However, it appears that aborting a thread at just the wrong moment when it is obtaining a ReaderWriterLockSlim lock can leave this lock in an inconsistent state. One symptom of this is that mono leaps to 100% cpu and a vm thread dump reveals lots of threads waiting for a ReaderWriterLockSlim lock without any thread actually holding it. This is probably the same problem as encountered originally in commit 12cebb12 This commit looks to plaster this problem by putting lock obtaining methods inside finally blocks which should be uninterruptible by thread aborts. --- .../Framework/DoubleDictionaryThreadAbortSafe.cs | 508 +++++++++++++++++++++ OpenSim/Region/Framework/Scenes/EntityManager.cs | 4 +- 2 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs new file mode 100644 index 0000000..9056548 --- /dev/null +++ b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs @@ -0,0 +1,508 @@ +/* + * Copyright (c) 2008, openmetaverse.org, http://opensimulator.org/ + * All rights reserved. + * + * - 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. + * - Neither the name of the openmetaverse.org 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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.Threading; +using System.Collections.Generic; + +namespace OpenSim.Framework +{ + /// + /// A double dictionary that is thread abort safe. + /// + /// + /// This adapts OpenMetaverse.DoubleDictionary to be thread-abort safe by acquiring ReaderWriterLockSlim within + /// a finally section (which can't be interrupted by Thread.Abort()). + /// + public class DoubleDictionaryThreadAbortSafe + { + Dictionary Dictionary1; + Dictionary Dictionary2; + ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); + + public DoubleDictionaryThreadAbortSafe() + { + Dictionary1 = new Dictionary(); + Dictionary2 = new Dictionary(); + } + + public DoubleDictionaryThreadAbortSafe(int capacity) + { + Dictionary1 = new Dictionary(capacity); + Dictionary2 = new Dictionary(capacity); + } + + public void Add(TKey1 key1, TKey2 key2, TValue value) + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + } + + if (Dictionary1.ContainsKey(key1)) + { + if (!Dictionary2.ContainsKey(key2)) + throw new ArgumentException("key1 exists in the dictionary but not key2"); + } + else if (Dictionary2.ContainsKey(key2)) + { + if (!Dictionary1.ContainsKey(key1)) + throw new ArgumentException("key2 exists in the dictionary but not key1"); + } + + Dictionary1[key1] = value; + Dictionary2[key2] = value; + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + } + + public bool Remove(TKey1 key1, TKey2 key2) + { + bool success; + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + } + + Dictionary1.Remove(key1); + success = Dictionary2.Remove(key2); + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + + return success; + } + + public bool Remove(TKey1 key1) + { + bool found = false; + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + } + + // This is an O(n) operation! + TValue value; + if (Dictionary1.TryGetValue(key1, out value)) + { + foreach (KeyValuePair kvp in Dictionary2) + { + if (kvp.Value.Equals(value)) + { + Dictionary1.Remove(key1); + Dictionary2.Remove(kvp.Key); + found = true; + break; + } + } + } + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + + return found; + } + + public bool Remove(TKey2 key2) + { + bool found = false; + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + } + + // This is an O(n) operation! + TValue value; + if (Dictionary2.TryGetValue(key2, out value)) + { + foreach (KeyValuePair kvp in Dictionary1) + { + if (kvp.Value.Equals(value)) + { + Dictionary2.Remove(key2); + Dictionary1.Remove(kvp.Key); + found = true; + break; + } + } + } + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + + return found; + } + + public void Clear() + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + } + + Dictionary1.Clear(); + Dictionary2.Clear(); + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + } + + public int Count + { + get { return Dictionary1.Count; } + } + + public bool ContainsKey(TKey1 key) + { + return Dictionary1.ContainsKey(key); + } + + public bool ContainsKey(TKey2 key) + { + return Dictionary2.ContainsKey(key); + } + + public bool TryGetValue(TKey1 key, out TValue value) + { + bool success; + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + success = Dictionary1.TryGetValue(key, out value); + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + + return success; + } + + public bool TryGetValue(TKey2 key, out TValue value) + { + bool success; + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + success = Dictionary2.TryGetValue(key, out value); + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + + return success; + } + + public void ForEach(Action action) + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + foreach (TValue value in Dictionary1.Values) + action(value); + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + } + + public void ForEach(Action> action) + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + foreach (KeyValuePair entry in Dictionary1) + action(entry); + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + } + + public void ForEach(Action> action) + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + foreach (KeyValuePair entry in Dictionary2) + action(entry); + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + } + + public TValue FindValue(Predicate predicate) + { + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + foreach (TValue value in Dictionary1.Values) + { + if (predicate(value)) + return value; + } + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + + return default(TValue); + } + + public IList FindAll(Predicate predicate) + { + IList list = new List(); + bool gotLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterReadLock(); + gotLock = true; + } + + foreach (TValue value in Dictionary1.Values) + { + if (predicate(value)) + list.Add(value); + } + } + finally + { + if (gotLock) + rwLock.ExitReadLock(); + } + + return list; + } + + public int RemoveAll(Predicate predicate) + { + IList list = new List(); + bool gotUpgradeableLock = false; + + try + { + // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing + // the acquision inside the main try. The inner finally block is needed because thread aborts cannot + // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly). + try {} + finally + { + rwLock.EnterUpgradeableReadLock(); + gotUpgradeableLock = true; + } + + foreach (KeyValuePair kvp in Dictionary1) + { + if (predicate(kvp.Value)) + list.Add(kvp.Key); + } + + IList list2 = new List(list.Count); + foreach (KeyValuePair kvp in Dictionary2) + { + if (predicate(kvp.Value)) + list2.Add(kvp.Key); + } + + bool gotWriteLock = false; + + try + { + try {} + finally + { + rwLock.EnterUpgradeableReadLock(); + gotWriteLock = true; + } + + for (int i = 0; i < list.Count; i++) + Dictionary1.Remove(list[i]); + + for (int i = 0; i < list2.Count; i++) + Dictionary2.Remove(list2[i]); + } + finally + { + if (gotWriteLock) + rwLock.ExitWriteLock(); + } + } + finally + { + if (gotUpgradeableLock) + rwLock.ExitUpgradeableReadLock(); + } + + return list.Count; + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/EntityManager.cs b/OpenSim/Region/Framework/Scenes/EntityManager.cs index b788a3c..7181313 100644 --- a/OpenSim/Region/Framework/Scenes/EntityManager.cs +++ b/OpenSim/Region/Framework/Scenes/EntityManager.cs @@ -31,6 +31,7 @@ using System.Collections.Generic; using System.Reflection; using log4net; using OpenMetaverse; +using OpenSim.Framework; namespace OpenSim.Region.Framework.Scenes { @@ -38,7 +39,8 @@ namespace OpenSim.Region.Framework.Scenes { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private readonly DoubleDictionary m_entities = new DoubleDictionary(); + private readonly DoubleDictionaryThreadAbortSafe m_entities + = new DoubleDictionaryThreadAbortSafe(); public int Count { -- cgit v1.1