diff options
Diffstat (limited to '')
161 files changed, 12820 insertions, 4822 deletions
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 08e4023..e1cff69 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs | |||
@@ -236,18 +236,6 @@ namespace OpenSim | |||
236 | + "If an avatar name is given then only packets from that avatar are logged", | 236 | + "If an avatar name is given then only packets from that avatar are logged", |
237 | Debug); | 237 | Debug); |
238 | 238 | ||
239 | m_console.Commands.AddCommand("Debug", false, "debug teleport", "debug teleport", "Toggle teleport route debugging", Debug); | ||
240 | |||
241 | m_console.Commands.AddCommand("Debug", false, "debug scene", | ||
242 | "debug scene active|collisions|physics|scripting|teleport true|false", | ||
243 | "Turn on scene debugging.", | ||
244 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
245 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
246 | + "If physics is false then all physics objects are non-physical.\n" | ||
247 | + "If scripting is false then no scripting operations happen.\n" | ||
248 | + "If teleport is true then some extra teleport debug information is logged.", | ||
249 | Debug); | ||
250 | |||
251 | m_console.Commands.AddCommand("General", false, "change region", | 239 | m_console.Commands.AddCommand("General", false, "change region", |
252 | "change region <region name>", | 240 | "change region <region name>", |
253 | "Change current console region", ChangeSelectedRegion); | 241 | "Change current console region", ChangeSelectedRegion); |
@@ -744,31 +732,6 @@ namespace OpenSim | |||
744 | 732 | ||
745 | break; | 733 | break; |
746 | 734 | ||
747 | case "scene": | ||
748 | if (args.Length == 4) | ||
749 | { | ||
750 | if (SceneManager.CurrentScene == null) | ||
751 | { | ||
752 | MainConsole.Instance.Output("Please use 'change region <regioname>' first"); | ||
753 | } | ||
754 | else | ||
755 | { | ||
756 | string key = args[2]; | ||
757 | string value = args[3]; | ||
758 | SceneManager.CurrentScene.SetSceneCoreDebug( | ||
759 | new Dictionary<string, string>() { { key, value } }); | ||
760 | |||
761 | MainConsole.Instance.OutputFormat("Set debug scene {0} = {1}", key, value); | ||
762 | } | ||
763 | } | ||
764 | else | ||
765 | { | ||
766 | MainConsole.Instance.Output( | ||
767 | "Usage: debug scene active|scripting|collisions|physics|teleport true|false"); | ||
768 | } | ||
769 | |||
770 | break; | ||
771 | |||
772 | default: | 735 | default: |
773 | MainConsole.Instance.Output("Unknown debug command"); | 736 | MainConsole.Instance.Output("Unknown debug command"); |
774 | break; | 737 | break; |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index b06788b..83347e2 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | |||
@@ -105,7 +105,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
105 | private static readonly string m_ResourceCostSelectedPath = "0103/"; | 105 | private static readonly string m_ResourceCostSelectedPath = "0103/"; |
106 | private static readonly string m_UpdateAgentInformationPath = "0500/"; | 106 | private static readonly string m_UpdateAgentInformationPath = "0500/"; |
107 | 107 | ||
108 | |||
109 | // These are callbacks which will be setup by the scene so that we can update scene data when we | 108 | // These are callbacks which will be setup by the scene so that we can update scene data when we |
110 | // receive capability calls | 109 | // receive capability calls |
111 | public NewInventoryItem AddNewInventoryItem = null; | 110 | public NewInventoryItem AddNewInventoryItem = null; |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs index d604cf6..ed8ec16 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | |||
@@ -44,7 +44,7 @@ using OpenSim.Tests.Common.Mock; | |||
44 | namespace OpenSim.Region.ClientStack.Linden.Tests | 44 | namespace OpenSim.Region.ClientStack.Linden.Tests |
45 | { | 45 | { |
46 | [TestFixture] | 46 | [TestFixture] |
47 | public class EventQueueTests | 47 | public class EventQueueTests : OpenSimTestCase |
48 | { | 48 | { |
49 | private TestScene m_scene; | 49 | private TestScene m_scene; |
50 | 50 | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index fd82db7..bae41fb 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | |||
@@ -6575,19 +6575,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6575 | #endregion | 6575 | #endregion |
6576 | 6576 | ||
6577 | AgentRequestSit handlerAgentRequestSit = OnAgentRequestSit; | 6577 | AgentRequestSit handlerAgentRequestSit = OnAgentRequestSit; |
6578 | if (handlerAgentRequestSit != null) | ||
6579 | if (!(agentRequestSit.AgentData == null | ||
6580 | || agentRequestSit.TargetObject == null | ||
6581 | || agentRequestSit.TargetObject.TargetID == null | ||
6582 | || agentRequestSit.TargetObject.Offset == null)) | ||
6583 | { | ||
6584 | var sp = m_scene.GetScenePresence(agentRequestSit.AgentData.AgentID); | ||
6585 | if (sp == null || sp.ParentID != 0) // ignore packet if agent is already sitting | ||
6586 | return true; | ||
6587 | 6578 | ||
6588 | handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID, | 6579 | if (handlerAgentRequestSit != null) |
6589 | agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset); | 6580 | handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID, |
6590 | } | 6581 | agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset); |
6591 | } | 6582 | } |
6592 | return true; | 6583 | return true; |
6593 | } | 6584 | } |
@@ -12242,11 +12233,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12242 | if (logPacket) | 12233 | if (logPacket) |
12243 | m_log.DebugFormat( | 12234 | m_log.DebugFormat( |
12244 | "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}", | 12235 | "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}", |
12245 | Name, SceneAgent.IsChildAgent ? "child" : "root ", m_scene.RegionInfo.RegionName, packet.Type); | 12236 | Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name, packet.Type); |
12246 | } | 12237 | } |
12247 | 12238 | ||
12248 | if (!ProcessPacketMethod(packet)) | 12239 | if (!ProcessPacketMethod(packet)) |
12249 | m_log.Warn("[CLIENT]: unhandled packet " + packet.Type); | 12240 | m_log.WarnFormat( |
12241 | "[CLIENT]: Unhandled packet {0} from {1} ({2}) in {3}. Ignoring.", | ||
12242 | packet.Type, Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name); | ||
12250 | } | 12243 | } |
12251 | 12244 | ||
12252 | private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket) | 12245 | private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket) |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index 2aeb4cc..7035e38 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |||
@@ -204,9 +204,12 @@ namespace OpenMetaverse | |||
204 | { | 204 | { |
205 | UDPPacketBuffer buf; | 205 | UDPPacketBuffer buf; |
206 | 206 | ||
207 | if (UsePools) | 207 | // FIXME: Disabled for now as this causes issues with reused packet objects interfering with each other |
208 | buf = Pool.GetObject(); | 208 | // on Windows with m_asyncPacketHandling = true, though this has not been seen on Linux. |
209 | else | 209 | // Possibly some unexpected issue with fetching UDP data concurrently with multiple threads. Requires more investigation. |
210 | // if (UsePools) | ||
211 | // buf = Pool.GetObject(); | ||
212 | // else | ||
210 | buf = new UDPPacketBuffer(); | 213 | buf = new UDPPacketBuffer(); |
211 | 214 | ||
212 | if (IsRunningInbound) | 215 | if (IsRunningInbound) |
@@ -287,8 +290,8 @@ namespace OpenMetaverse | |||
287 | catch (ObjectDisposedException) { } | 290 | catch (ObjectDisposedException) { } |
288 | finally | 291 | finally |
289 | { | 292 | { |
290 | if (UsePools) | 293 | // if (UsePools) |
291 | Pool.ReturnObject(buffer); | 294 | // Pool.ReturnObject(buffer); |
292 | 295 | ||
293 | // Synchronous mode waits until the packet callback completes | 296 | // Synchronous mode waits until the packet callback completes |
294 | // before starting the receive to fetch another packet | 297 | // before starting the receive to fetch another packet |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs index 5fcf376..7d9f581 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs | |||
@@ -43,7 +43,7 @@ using OpenSim.Tests.Common.Mock; | |||
43 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | 43 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
44 | { | 44 | { |
45 | [TestFixture] | 45 | [TestFixture] |
46 | public class LLImageManagerTests | 46 | public class LLImageManagerTests : OpenSimTestCase |
47 | { | 47 | { |
48 | private AssetBase m_testImageAsset; | 48 | private AssetBase m_testImageAsset; |
49 | private Scene scene; | 49 | private Scene scene; |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs index 0f88ec6..5f73a94 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs | |||
@@ -39,7 +39,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
39 | /// Tests for the LL packet handler | 39 | /// Tests for the LL packet handler |
40 | /// </summary> | 40 | /// </summary> |
41 | [TestFixture] | 41 | [TestFixture] |
42 | public class PacketHandlerTests | 42 | public class PacketHandlerTests : OpenSimTestCase |
43 | { | 43 | { |
44 | // [Test] | 44 | // [Test] |
45 | // /// <summary> | 45 | // /// <summary> |
diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index 1c2bfd0..fd02b08 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs | |||
@@ -47,14 +47,16 @@ namespace OpenSim.Region.CoreModules.Asset.Tests | |||
47 | /// At the moment we're only test the in-memory part of the FlotsamAssetCache. This is a considerable weakness. | 47 | /// At the moment we're only test the in-memory part of the FlotsamAssetCache. This is a considerable weakness. |
48 | /// </summary> | 48 | /// </summary> |
49 | [TestFixture] | 49 | [TestFixture] |
50 | public class FlotsamAssetCacheTests | 50 | public class FlotsamAssetCacheTests : OpenSimTestCase |
51 | { | 51 | { |
52 | protected TestScene m_scene; | 52 | protected TestScene m_scene; |
53 | protected FlotsamAssetCache m_cache; | 53 | protected FlotsamAssetCache m_cache; |
54 | 54 | ||
55 | [SetUp] | 55 | [SetUp] |
56 | public void SetUp() | 56 | public override void SetUp() |
57 | { | 57 | { |
58 | base.SetUp(); | ||
59 | |||
58 | IConfigSource config = new IniConfigSource(); | 60 | IConfigSource config = new IniConfigSource(); |
59 | 61 | ||
60 | config.AddConfig("Modules"); | 62 | config.AddConfig("Modules"); |
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index acd156e..6323160 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -722,15 +722,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
722 | 722 | ||
723 | if (!silent) | 723 | if (!silent) |
724 | { | 724 | { |
725 | // Killing it here will cause the client to deselect it | 725 | if (so.HasPrivateAttachmentPoint) |
726 | // It then reappears on the avatar, deselected | ||
727 | // through the full update below | ||
728 | // | ||
729 | if (so.IsSelected) | ||
730 | { | ||
731 | m_scene.SendKillObject(new List<uint> { so.RootPart.LocalId }); | ||
732 | } | ||
733 | else if (so.HasPrivateAttachmentPoint) | ||
734 | { | 726 | { |
735 | // m_log.DebugFormat( | 727 | // m_log.DebugFormat( |
736 | // "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}", | 728 | // "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}", |
@@ -745,7 +737,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
745 | }); | 737 | }); |
746 | } | 738 | } |
747 | 739 | ||
748 | so.IsSelected = false; // fudge.... | 740 | // Fudge below is an extremely unhelpful comment. It's probably here so that the scheduled full update |
741 | // will succeed, as that will not update if an attachment is selected. | ||
742 | so.IsSelected = false; // fudge.... | ||
743 | |||
749 | so.ScheduleGroupForFullUpdate(); | 744 | so.ScheduleGroupForFullUpdate(); |
750 | } | 745 | } |
751 | 746 | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 7ec2860..a070ff8 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs | |||
@@ -322,6 +322,9 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
322 | 322 | ||
323 | if (asset != null) | 323 | if (asset != null) |
324 | { | 324 | { |
325 | // Replace an HG ID with the simple asset ID so that we can persist textures for foreign HG avatars | ||
326 | asset.ID = asset.FullID.ToString(); | ||
327 | |||
325 | asset.Temporary = false; | 328 | asset.Temporary = false; |
326 | asset.Local = false; | 329 | asset.Local = false; |
327 | m_scene.AssetService.Store(asset); | 330 | m_scene.AssetService.Store(asset); |
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs index e21547c..f090e15 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs | |||
@@ -39,7 +39,7 @@ using OpenSim.Tests.Common.Mock; | |||
39 | namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | 39 | namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory |
40 | { | 40 | { |
41 | [TestFixture] | 41 | [TestFixture] |
42 | public class AvatarFactoryModuleTests | 42 | public class AvatarFactoryModuleTests : OpenSimTestCase |
43 | { | 43 | { |
44 | /// <summary> | 44 | /// <summary> |
45 | /// Only partial right now since we don't yet test that it's ended up in the avatar appearance service. | 45 | /// Only partial right now since we don't yet test that it's ended up in the avatar appearance service. |
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs index 7a197f7..961117e 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs | |||
@@ -40,7 +40,7 @@ using OpenSim.Tests.Common.Mock; | |||
40 | namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests | 40 | namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests |
41 | { | 41 | { |
42 | [TestFixture] | 42 | [TestFixture] |
43 | public class FriendsModuleTests | 43 | public class FriendsModuleTests : OpenSimTestCase |
44 | { | 44 | { |
45 | private FriendsModule m_fm; | 45 | private FriendsModule m_fm; |
46 | private TestScene m_scene; | 46 | private TestScene m_scene; |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index cc266df..1627f6c 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | |||
@@ -153,7 +153,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
153 | if (sp != null && !sp.IsChildAgent) | 153 | if (sp != null && !sp.IsChildAgent) |
154 | { | 154 | { |
155 | // Local message | 155 | // Local message |
156 | m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", sp.Name, toAgentID); | 156 | // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", sp.Name, toAgentID); |
157 | 157 | ||
158 | sp.ControllingClient.SendInstantMessage(im); | 158 | sp.ControllingClient.SendInstantMessage(im); |
159 | 159 | ||
@@ -166,14 +166,14 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
166 | // try child avatar second | 166 | // try child avatar second |
167 | foreach (Scene scene in m_Scenes) | 167 | foreach (Scene scene in m_Scenes) |
168 | { | 168 | { |
169 | //m_log.DebugFormat( | 169 | // m_log.DebugFormat( |
170 | // "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); | 170 | // "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); |
171 | 171 | ||
172 | ScenePresence sp = scene.GetScenePresence(toAgentID); | 172 | ScenePresence sp = scene.GetScenePresence(toAgentID); |
173 | if (sp != null) | 173 | if (sp != null) |
174 | { | 174 | { |
175 | // Local message | 175 | // Local message |
176 | m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", sp.Name, toAgentID); | 176 | // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", sp.Name, toAgentID); |
177 | 177 | ||
178 | sp.ControllingClient.SendInstantMessage(im); | 178 | sp.ControllingClient.SendInstantMessage(im); |
179 | 179 | ||
@@ -183,7 +183,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID); | 186 | // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID); |
187 | 187 | ||
188 | SendGridInstantMessageViaXMLRPC(im, result); | 188 | SendGridInstantMessageViaXMLRPC(im, result); |
189 | } | 189 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs index 3a44cc5..2d46276 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs | |||
@@ -189,20 +189,24 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
189 | { | 189 | { |
190 | foreach (GridInstantMessage im in msglist) | 190 | foreach (GridInstantMessage im in msglist) |
191 | { | 191 | { |
192 | // client.SendInstantMessage(im); | 192 | if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) |
193 | 193 | // send it directly or else the item will be given twice | |
194 | // Send through scene event manager so all modules get a chance | 194 | client.SendInstantMessage(im); |
195 | // to look at this message before it gets delivered. | 195 | else |
196 | // | 196 | { |
197 | // Needed for proper state management for stored group | 197 | // Send through scene event manager so all modules get a chance |
198 | // invitations | 198 | // to look at this message before it gets delivered. |
199 | // | 199 | // |
200 | 200 | // Needed for proper state management for stored group | |
201 | im.offline = 1; | 201 | // invitations |
202 | 202 | // | |
203 | Scene s = FindScene(client.AgentId); | 203 | |
204 | if (s != null) | 204 | im.offline = 1; |
205 | s.EventManager.TriggerIncomingInstantMessage(im); | 205 | |
206 | Scene s = FindScene(client.AgentId); | ||
207 | if (s != null) | ||
208 | s.EventManager.TriggerIncomingInstantMessage(im); | ||
209 | } | ||
206 | } | 210 | } |
207 | } | 211 | } |
208 | } | 212 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index d0e88f6..4c85637 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -124,7 +124,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
124 | SaveAssets = true; | 124 | SaveAssets = true; |
125 | } | 125 | } |
126 | 126 | ||
127 | protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids) | 127 | protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids, bool timedOut) |
128 | { | 128 | { |
129 | Exception reportedException = null; | 129 | Exception reportedException = null; |
130 | bool succeeded = true; | 130 | bool succeeded = true; |
@@ -143,6 +143,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
143 | m_saveStream.Close(); | 143 | m_saveStream.Close(); |
144 | } | 144 | } |
145 | 145 | ||
146 | if (timedOut) | ||
147 | { | ||
148 | succeeded = false; | ||
149 | reportedException = new Exception("Loading assets timed out"); | ||
150 | } | ||
151 | |||
146 | m_module.TriggerInventoryArchiveSaved( | 152 | m_module.TriggerInventoryArchiveSaved( |
147 | m_id, succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); | 153 | m_id, succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); |
148 | } | 154 | } |
@@ -350,7 +356,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
350 | { | 356 | { |
351 | m_log.DebugFormat("[INVENTORY ARCHIVER]: Not saving assets since --noassets was specified"); | 357 | m_log.DebugFormat("[INVENTORY ARCHIVER]: Not saving assets since --noassets was specified"); |
352 | 358 | ||
353 | ReceivedAllAssets(new List<UUID>(), new List<UUID>()); | 359 | ReceivedAllAssets(new List<UUID>(), new List<UUID>(), false); |
354 | } | 360 | } |
355 | } | 361 | } |
356 | catch (Exception) | 362 | catch (Exception) |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs index 4cfa33d..ae58dfd 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs | |||
@@ -316,76 +316,74 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer | |||
316 | } | 316 | } |
317 | } | 317 | } |
318 | 318 | ||
319 | // Disabled for now as it looks like http://opensimulator.org/mantis/view.php?id=6311 was fixed by fixes | 319 | // XXX: This code was placed here to try and accomodate RLV which moves given folders named #RLV/~<name> |
320 | // to inventory folder versioning allowing the viewer to move the received folder itself as happens on the | 320 | // to the requested folder, which in this case is #RLV. However, it is the viewer that appears to be |
321 | // LL grid. Doing it again server-side then wrongly does a second create and move | 321 | // response from renaming the #RLV/~example folder to ~example. For some reason this is not yet |
322 | // // XXX: This code was placed here to try and accomdate RLV which moves given folders named #RLV/~<name> | 322 | // happening, possibly because we are not sending the correct inventory update messages with the correct |
323 | // // to a folder called name in #RLV. However, this approach may not be ultimately correct - from analysis | 323 | // transaction IDs |
324 | // // of Firestorm 4.2.2 on sending an InventoryOffered instead of TaskInventoryOffered (as was previously | 324 | else if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted) |
325 | // // done), the viewer itself would appear to move and rename the folder, rather than the simulator doing it here. | 325 | { |
326 | // else if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted) | 326 | UUID destinationFolderID = UUID.Zero; |
327 | // { | 327 | |
328 | // UUID destinationFolderID = UUID.Zero; | 328 | if (im.binaryBucket != null && im.binaryBucket.Length >= 16) |
329 | // | 329 | { |
330 | // if (im.binaryBucket != null && im.binaryBucket.Length >= 16) | 330 | destinationFolderID = new UUID(im.binaryBucket, 0); |
331 | // { | 331 | } |
332 | // destinationFolderID = new UUID(im.binaryBucket, 0); | 332 | |
333 | // } | 333 | if (destinationFolderID != UUID.Zero) |
334 | // | 334 | { |
335 | // if (destinationFolderID != UUID.Zero) | 335 | InventoryFolderBase destinationFolder = new InventoryFolderBase(destinationFolderID, client.AgentId); |
336 | // { | 336 | if (destinationFolder == null) |
337 | // InventoryFolderBase destinationFolder = new InventoryFolderBase(destinationFolderID, client.AgentId); | 337 | { |
338 | // if (destinationFolder == null) | 338 | m_log.WarnFormat( |
339 | // { | 339 | "[INVENTORY TRANSFER]: TaskInventoryAccepted message from {0} in {1} specified folder {2} which does not exist", |
340 | // m_log.WarnFormat( | 340 | client.Name, scene.Name, destinationFolderID); |
341 | // "[INVENTORY TRANSFER]: TaskInventoryAccepted message from {0} in {1} specified folder {2} which does not exist", | 341 | |
342 | // client.Name, scene.Name, destinationFolderID); | 342 | return; |
343 | // | 343 | } |
344 | // return; | 344 | |
345 | // } | 345 | IInventoryService invService = scene.InventoryService; |
346 | // | 346 | |
347 | // IInventoryService invService = scene.InventoryService; | 347 | UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip |
348 | // | 348 | |
349 | // UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip | 349 | InventoryItemBase item = new InventoryItemBase(inventoryID, client.AgentId); |
350 | // | 350 | item = invService.GetItem(item); |
351 | // InventoryItemBase item = new InventoryItemBase(inventoryID, client.AgentId); | 351 | InventoryFolderBase folder = null; |
352 | // item = invService.GetItem(item); | 352 | UUID? previousParentFolderID = null; |
353 | // InventoryFolderBase folder = null; | 353 | |
354 | // UUID? previousParentFolderID = null; | 354 | if (item != null) // It's an item |
355 | // | 355 | { |
356 | // if (item != null) // It's an item | 356 | previousParentFolderID = item.Folder; |
357 | // { | 357 | item.Folder = destinationFolderID; |
358 | // previousParentFolderID = item.Folder; | 358 | |
359 | // item.Folder = destinationFolderID; | 359 | invService.DeleteItems(item.Owner, new List<UUID>() { item.ID }); |
360 | // | 360 | scene.AddInventoryItem(client, item); |
361 | // invService.DeleteItems(item.Owner, new List<UUID>() { item.ID }); | 361 | } |
362 | // scene.AddInventoryItem(client, item); | 362 | else |
363 | // } | 363 | { |
364 | // else | 364 | folder = new InventoryFolderBase(inventoryID, client.AgentId); |
365 | // { | 365 | folder = invService.GetFolder(folder); |
366 | // folder = new InventoryFolderBase(inventoryID, client.AgentId); | 366 | |
367 | // folder = invService.GetFolder(folder); | 367 | if (folder != null) // It's a folder |
368 | // | 368 | { |
369 | // if (folder != null) // It's a folder | 369 | previousParentFolderID = folder.ParentID; |
370 | // { | 370 | folder.ParentID = destinationFolderID; |
371 | // previousParentFolderID = folder.ParentID; | 371 | invService.MoveFolder(folder); |
372 | // folder.ParentID = destinationFolderID; | 372 | } |
373 | // invService.MoveFolder(folder); | 373 | } |
374 | // } | 374 | |
375 | // } | 375 | // Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code). |
376 | // | 376 | if (previousParentFolderID != null) |
377 | // // Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code). | 377 | { |
378 | // if (previousParentFolderID != null) | 378 | InventoryFolderBase previousParentFolder |
379 | // { | 379 | = new InventoryFolderBase((UUID)previousParentFolderID, client.AgentId); |
380 | // InventoryFolderBase previousParentFolder | 380 | previousParentFolder = invService.GetFolder(previousParentFolder); |
381 | // = new InventoryFolderBase((UUID)previousParentFolderID, client.AgentId); | 381 | scene.SendInventoryUpdate(client, previousParentFolder, true, true); |
382 | // previousParentFolder = invService.GetFolder(previousParentFolder); | 382 | |
383 | // scene.SendInventoryUpdate(client, previousParentFolder, true, true); | 383 | scene.SendInventoryUpdate(client, destinationFolder, true, true); |
384 | // | 384 | } |
385 | // scene.SendInventoryUpdate(client, destinationFolder, true, true); | 385 | } |
386 | // } | 386 | } |
387 | // } | ||
388 | // } | ||
389 | else if ( | 387 | else if ( |
390 | im.dialog == (byte)InstantMessageDialog.InventoryDeclined | 388 | im.dialog == (byte)InstantMessageDialog.InventoryDeclined |
391 | || im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined) | 389 | || im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined) |
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index f3a0b01..9b78b3b 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs | |||
@@ -212,11 +212,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
212 | protected override GridRegion GetFinalDestination(GridRegion region) | 212 | protected override GridRegion GetFinalDestination(GridRegion region) |
213 | { | 213 | { |
214 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, region.RegionID); | 214 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, region.RegionID); |
215 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionID, flags); | 215 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionName, flags); |
216 | 216 | ||
217 | if ((flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) | 217 | if ((flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) |
218 | { | 218 | { |
219 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region {0} is hyperlink", region.RegionID); | 219 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region is hyperlink"); |
220 | GridRegion real_destination = m_GatekeeperConnector.GetHyperlinkRegion(region, region.RegionID); | 220 | GridRegion real_destination = m_GatekeeperConnector.GetHyperlinkRegion(region, region.RegionID); |
221 | if (real_destination != null) | 221 | if (real_destination != null) |
222 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: GetFinalDestination serveruri -> {0}", real_destination.ServerURI); | 222 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: GetFinalDestination serveruri -> {0}", real_destination.ServerURI); |
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index f8ec6de..7871eda 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | |||
@@ -71,7 +71,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
71 | 71 | ||
72 | #region Internal functions | 72 | #region Internal functions |
73 | 73 | ||
74 | public AssetMetadata FetchMetadata(string url, UUID assetID) | 74 | private AssetMetadata FetchMetadata(string url, UUID assetID) |
75 | { | 75 | { |
76 | if (!url.EndsWith("/") && !url.EndsWith("=")) | 76 | if (!url.EndsWith("/") && !url.EndsWith("=")) |
77 | url = url + "/"; | 77 | url = url + "/"; |
@@ -86,6 +86,27 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
86 | return meta; | 86 | return meta; |
87 | } | 87 | } |
88 | 88 | ||
89 | private AssetBase FetchAsset(string url, UUID assetID) | ||
90 | { | ||
91 | // Test if it's already here | ||
92 | AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); | ||
93 | if (asset == null) | ||
94 | { | ||
95 | if (!url.EndsWith("/") && !url.EndsWith("=")) | ||
96 | url = url + "/"; | ||
97 | |||
98 | asset = m_scene.AssetService.Get(url + assetID.ToString()); | ||
99 | |||
100 | //if (asset != null) | ||
101 | // m_log.DebugFormat("[HG ASSET MAPPER]: Fetched asset {0} of type {1} from {2} ", assetID, asset.Metadata.Type, url); | ||
102 | //else | ||
103 | // m_log.DebugFormat("[HG ASSET MAPPER]: Unable to fetch asset {0} from {1} ", assetID, url); | ||
104 | |||
105 | } | ||
106 | |||
107 | return asset; | ||
108 | } | ||
109 | |||
89 | public bool PostAsset(string url, AssetBase asset) | 110 | public bool PostAsset(string url, AssetBase asset) |
90 | { | 111 | { |
91 | if (asset != null) | 112 | if (asset != null) |
@@ -228,11 +249,22 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
228 | if (meta == null) | 249 | if (meta == null) |
229 | return; | 250 | return; |
230 | 251 | ||
231 | // The act of gathering UUIDs downloads the assets from the remote server | 252 | // The act of gathering UUIDs downloads some assets from the remote server |
253 | // but not all... | ||
232 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); | 254 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); |
233 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL); | 255 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL); |
234 | uuidGatherer.GatherAssetUuids(assetID, (AssetType)meta.Type, ids); | 256 | uuidGatherer.GatherAssetUuids(assetID, (AssetType)meta.Type, ids); |
235 | 257 | m_log.DebugFormat("[HG ASSET MAPPER]: Preparing to get {0} assets", ids.Count); | |
258 | bool success = true; | ||
259 | foreach (UUID uuid in ids.Keys) | ||
260 | if (FetchAsset(userAssetURL, uuid) == null) | ||
261 | success = false; | ||
262 | |||
263 | // maybe all pieces got here... | ||
264 | if (!success) | ||
265 | m_log.DebugFormat("[HG ASSET MAPPER]: Problems getting item {0} from asset server {1}", assetID, userAssetURL); | ||
266 | else | ||
267 | m_log.DebugFormat("[HG ASSET MAPPER]: Successfully got item {0} from asset server {1}", assetID, userAssetURL); | ||
236 | } | 268 | } |
237 | 269 | ||
238 | 270 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs index 21d8bd7..ac25a93 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | |||
@@ -49,7 +49,7 @@ using OpenSim.Tests.Common.Mock; | |||
49 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | 49 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests |
50 | { | 50 | { |
51 | [TestFixture] | 51 | [TestFixture] |
52 | public class InventoryAccessModuleTests | 52 | public class InventoryAccessModuleTests : OpenSimTestCase |
53 | { | 53 | { |
54 | protected TestScene m_scene; | 54 | protected TestScene m_scene; |
55 | protected BasicInventoryAccessModule m_iam; | 55 | protected BasicInventoryAccessModule m_iam; |
@@ -57,8 +57,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | |||
57 | protected TestClient m_tc; | 57 | protected TestClient m_tc; |
58 | 58 | ||
59 | [SetUp] | 59 | [SetUp] |
60 | public void SetUp() | 60 | public override void SetUp() |
61 | { | 61 | { |
62 | base.SetUp(); | ||
63 | |||
62 | m_iam = new BasicInventoryAccessModule(); | 64 | m_iam = new BasicInventoryAccessModule(); |
63 | 65 | ||
64 | IConfigSource config = new IniConfigSource(); | 66 | IConfigSource config = new IniConfigSource(); |
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 86e7004..77e8b00 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs | |||
@@ -181,6 +181,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
181 | 181 | ||
182 | m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query); | 182 | m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query); |
183 | 183 | ||
184 | // searhc the user accounts service | ||
184 | List<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query); | 185 | List<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query); |
185 | 186 | ||
186 | List<UserData> users = new List<UserData>(); | 187 | List<UserData> users = new List<UserData>(); |
@@ -196,6 +197,12 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
196 | } | 197 | } |
197 | } | 198 | } |
198 | 199 | ||
200 | // search the local cache | ||
201 | foreach (UserData data in m_UserCache.Values) | ||
202 | if (users.Find(delegate(UserData d) { return d.Id == data.Id; }) == null && | ||
203 | (data.FirstName.StartsWith(query) || data.LastName.StartsWith(query))) | ||
204 | users.Add(data); | ||
205 | |||
199 | AddAdditionalUsers(avatarID, query, users); | 206 | AddAdditionalUsers(avatarID, query, users); |
200 | 207 | ||
201 | AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply); | 208 | AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply); |
@@ -433,6 +440,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
433 | public void AddUser(UUID uuid, string first, string last, string homeURL) | 440 | public void AddUser(UUID uuid, string first, string last, string homeURL) |
434 | { | 441 | { |
435 | //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL); | 442 | //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL); |
443 | if (homeURL == string.Empty) | ||
444 | return; | ||
445 | |||
436 | AddUser(uuid, homeURL + ";" + first + " " + last); | 446 | AddUser(uuid, homeURL + ";" + first + " " + last); |
437 | } | 447 | } |
438 | 448 | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs index 32e47f9..69bac82 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs | |||
@@ -35,7 +35,6 @@ using NUnit.Framework; | |||
35 | using OpenMetaverse; | 35 | using OpenMetaverse; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | |||
39 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence; | 38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence; |
40 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | 40 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; |
@@ -44,11 +43,14 @@ using OpenSim.Tests.Common; | |||
44 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests | 43 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests |
45 | { | 44 | { |
46 | [TestFixture] | 45 | [TestFixture] |
47 | public class PresenceConnectorsTests | 46 | public class PresenceConnectorsTests : OpenSimTestCase |
48 | { | 47 | { |
49 | LocalPresenceServicesConnector m_LocalConnector; | 48 | LocalPresenceServicesConnector m_LocalConnector; |
50 | private void SetUp() | 49 | |
50 | public override void SetUp() | ||
51 | { | 51 | { |
52 | base.SetUp(); | ||
53 | |||
52 | IConfigSource config = new IniConfigSource(); | 54 | IConfigSource config = new IniConfigSource(); |
53 | config.AddConfig("Modules"); | 55 | config.AddConfig("Modules"); |
54 | config.AddConfig("PresenceService"); | 56 | config.AddConfig("PresenceService"); |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index ade5e76..fcfdf7c 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs | |||
@@ -570,13 +570,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
570 | 570 | ||
571 | // Validate User and Group UUID's | 571 | // Validate User and Group UUID's |
572 | 572 | ||
573 | if (!ResolveUserUuid(scene, parcel.OwnerID)) | 573 | if (parcel.IsGroupOwned) |
574 | parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; | 574 | { |
575 | 575 | if (!ResolveGroupUuid(parcel.GroupID)) | |
576 | if (!ResolveGroupUuid(parcel.GroupID)) | 576 | { |
577 | parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; | ||
578 | parcel.GroupID = UUID.Zero; | ||
579 | parcel.IsGroupOwned = false; | ||
580 | } | ||
581 | } | ||
582 | else | ||
577 | { | 583 | { |
578 | parcel.GroupID = UUID.Zero; | 584 | if (!ResolveUserUuid(scene, parcel.OwnerID)) |
579 | parcel.IsGroupOwned = false; | 585 | parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; |
586 | |||
587 | if (!ResolveGroupUuid(parcel.GroupID)) | ||
588 | parcel.GroupID = UUID.Zero; | ||
580 | } | 589 | } |
581 | 590 | ||
582 | List<LandAccessEntry> accessList = new List<LandAccessEntry>(); | 591 | List<LandAccessEntry> accessList = new List<LandAccessEntry>(); |
@@ -589,8 +598,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
589 | parcel.ParcelAccessList = accessList; | 598 | parcel.ParcelAccessList = accessList; |
590 | 599 | ||
591 | // m_log.DebugFormat( | 600 | // m_log.DebugFormat( |
592 | // "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}", | 601 | // "[ARCHIVER]: Adding parcel {0}, local id {1}, owner {2}, group {3}, isGroupOwned {4}, area {5}", |
593 | // parcel.Name, parcel.LocalID, parcel.Area); | 602 | // parcel.Name, parcel.LocalID, parcel.OwnerID, parcel.GroupID, parcel.IsGroupOwned, parcel.Area); |
594 | 603 | ||
595 | landData.Add(parcel); | 604 | landData.Add(parcel); |
596 | } | 605 | } |
@@ -613,13 +622,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
613 | /// <returns></returns> | 622 | /// <returns></returns> |
614 | private bool ResolveUserUuid(Scene scene, UUID uuid) | 623 | private bool ResolveUserUuid(Scene scene, UUID uuid) |
615 | { | 624 | { |
616 | if (!m_validUserUuids.ContainsKey(uuid)) | 625 | lock (m_validUserUuids) |
617 | { | 626 | { |
618 | UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, uuid); | 627 | if (!m_validUserUuids.ContainsKey(uuid)) |
619 | m_validUserUuids.Add(uuid, account != null); | 628 | { |
620 | } | 629 | // Note: we call GetUserAccount() inside the lock because this UserID is likely |
630 | // to occur many times, and we only want to query the users service once. | ||
631 | UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, uuid); | ||
632 | m_validUserUuids.Add(uuid, account != null); | ||
633 | } | ||
621 | 634 | ||
622 | return m_validUserUuids[uuid]; | 635 | return m_validUserUuids[uuid]; |
636 | } | ||
623 | } | 637 | } |
624 | 638 | ||
625 | /// <summary> | 639 | /// <summary> |
@@ -632,19 +646,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
632 | if (uuid == UUID.Zero) | 646 | if (uuid == UUID.Zero) |
633 | return true; // this means the object has no group | 647 | return true; // this means the object has no group |
634 | 648 | ||
635 | if (!m_validGroupUuids.ContainsKey(uuid)) | 649 | lock (m_validGroupUuids) |
636 | { | 650 | { |
637 | bool exists; | 651 | if (!m_validGroupUuids.ContainsKey(uuid)) |
638 | 652 | { | |
639 | if (m_groupsModule == null) | 653 | bool exists; |
640 | exists = false; | 654 | if (m_groupsModule == null) |
641 | else | 655 | { |
642 | exists = (m_groupsModule.GetGroupRecord(uuid) != null); | 656 | exists = false; |
657 | } | ||
658 | else | ||
659 | { | ||
660 | // Note: we call GetGroupRecord() inside the lock because this GroupID is likely | ||
661 | // to occur many times, and we only want to query the groups service once. | ||
662 | exists = (m_groupsModule.GetGroupRecord(uuid) != null); | ||
663 | } | ||
664 | m_validGroupUuids.Add(uuid, exists); | ||
665 | } | ||
643 | 666 | ||
644 | m_validGroupUuids.Add(uuid, exists); | 667 | return m_validGroupUuids[uuid]; |
645 | } | 668 | } |
646 | |||
647 | return m_validGroupUuids[uuid]; | ||
648 | } | 669 | } |
649 | 670 | ||
650 | /// Load an asset | 671 | /// Load an asset |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs index d751b1c..367693d 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs | |||
@@ -167,7 +167,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
167 | } | 167 | } |
168 | scenesGroup.CalcSceneLocations(); | 168 | scenesGroup.CalcSceneLocations(); |
169 | 169 | ||
170 | |||
171 | m_archiveWriter = new TarArchiveWriter(m_saveStream); | 170 | m_archiveWriter = new TarArchiveWriter(m_saveStream); |
172 | 171 | ||
173 | try | 172 | try |
@@ -216,7 +215,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
216 | } | 215 | } |
217 | } | 216 | } |
218 | 217 | ||
219 | |||
220 | private void ArchiveOneRegion(Scene scene, string regionDir, Dictionary<UUID, AssetType> assetUuids) | 218 | private void ArchiveOneRegion(Scene scene, string regionDir, Dictionary<UUID, AssetType> assetUuids) |
221 | { | 219 | { |
222 | m_log.InfoFormat("[ARCHIVER]: Writing region {0}", scene.RegionInfo.RegionName); | 220 | m_log.InfoFormat("[ARCHIVER]: Writing region {0}", scene.RegionInfo.RegionName); |
@@ -540,7 +538,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
540 | xtw.WriteElementString("size_in_meters", string.Format("{0},{1}", size.X, size.Y)); | 538 | xtw.WriteElementString("size_in_meters", string.Format("{0},{1}", size.X, size.Y)); |
541 | } | 539 | } |
542 | 540 | ||
543 | |||
544 | protected void Save(Scene scene, List<SceneObjectGroup> sceneObjects, string regionDir) | 541 | protected void Save(Scene scene, List<SceneObjectGroup> sceneObjects, string regionDir) |
545 | { | 542 | { |
546 | if (regionDir != string.Empty) | 543 | if (regionDir != string.Empty) |
@@ -560,8 +557,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
560 | foreach (ILandObject lo in landObjects) | 557 | foreach (ILandObject lo in landObjects) |
561 | { | 558 | { |
562 | LandData landData = lo.LandData; | 559 | LandData landData = lo.LandData; |
563 | string landDataPath = String.Format("{0}{1}{2}.xml", | 560 | string landDataPath |
564 | regionDir, ArchiveConstants.LANDDATA_PATH, landData.GlobalID.ToString()); | 561 | = String.Format("{0}{1}", regionDir, ArchiveConstants.CreateOarLandDataPath(landData)); |
565 | m_archiveWriter.WriteFile(landDataPath, LandDataSerializer.Serialize(landData, m_options)); | 562 | m_archiveWriter.WriteFile(landDataPath, LandDataSerializer.Serialize(landData, m_options)); |
566 | } | 563 | } |
567 | 564 | ||
@@ -590,21 +587,30 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
590 | } | 587 | } |
591 | } | 588 | } |
592 | 589 | ||
593 | protected void ReceivedAllAssets( | 590 | protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids, bool timedOut) |
594 | ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids) | ||
595 | { | 591 | { |
596 | foreach (UUID uuid in assetsNotFoundUuids) | 592 | string errorMessage; |
593 | |||
594 | if (timedOut) | ||
597 | { | 595 | { |
598 | m_log.DebugFormat("[ARCHIVER]: Could not find asset {0}", uuid); | 596 | errorMessage = "Loading assets timed out"; |
599 | } | 597 | } |
598 | else | ||
599 | { | ||
600 | foreach (UUID uuid in assetsNotFoundUuids) | ||
601 | { | ||
602 | m_log.DebugFormat("[ARCHIVER]: Could not find asset {0}", uuid); | ||
603 | } | ||
600 | 604 | ||
601 | // m_log.InfoFormat( | 605 | // m_log.InfoFormat( |
602 | // "[ARCHIVER]: Received {0} of {1} assets requested", | 606 | // "[ARCHIVER]: Received {0} of {1} assets requested", |
603 | // assetsFoundUuids.Count, assetsFoundUuids.Count + assetsNotFoundUuids.Count); | 607 | // assetsFoundUuids.Count, assetsFoundUuids.Count + assetsNotFoundUuids.Count); |
604 | 608 | ||
605 | CloseArchive(String.Empty); | 609 | errorMessage = String.Empty; |
610 | } | ||
611 | |||
612 | CloseArchive(errorMessage); | ||
606 | } | 613 | } |
607 | |||
608 | 614 | ||
609 | /// <summary> | 615 | /// <summary> |
610 | /// Closes the archive and notifies that we're done. | 616 | /// Closes the archive and notifies that we're done. |
@@ -629,6 +635,5 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
629 | 635 | ||
630 | m_rootScene.EventManager.TriggerOarFileSaved(m_requestId, errorMessage); | 636 | m_rootScene.EventManager.TriggerOarFileSaved(m_requestId, errorMessage); |
631 | } | 637 | } |
632 | |||
633 | } | 638 | } |
634 | } | 639 | } |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs index 95d109c..c1ff94d 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs | |||
@@ -150,12 +150,5 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
150 | m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", m_assetsWritten); | 150 | m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", m_assetsWritten); |
151 | } | 151 | } |
152 | 152 | ||
153 | /// <summary> | ||
154 | /// Only call this if you need to force a close on the underlying writer. | ||
155 | /// </summary> | ||
156 | public void ForceClose() | ||
157 | { | ||
158 | m_archiveWriter.Close(); | ||
159 | } | ||
160 | } | 153 | } |
161 | } | 154 | } |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs index e2f8833..715bf51 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs | |||
@@ -50,7 +50,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
50 | /// Method called when all the necessary assets for an archive request have been received. | 50 | /// Method called when all the necessary assets for an archive request have been received. |
51 | /// </summary> | 51 | /// </summary> |
52 | public delegate void AssetsRequestCallback( | 52 | public delegate void AssetsRequestCallback( |
53 | ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids); | 53 | ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids, bool timedOut); |
54 | 54 | ||
55 | enum RequestState | 55 | enum RequestState |
56 | { | 56 | { |
@@ -148,7 +148,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
148 | if (m_repliesRequired == 0) | 148 | if (m_repliesRequired == 0) |
149 | { | 149 | { |
150 | m_requestState = RequestState.Completed; | 150 | m_requestState = RequestState.Completed; |
151 | PerformAssetsRequestCallback(null); | 151 | PerformAssetsRequestCallback(false); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | 154 | ||
@@ -164,7 +164,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
164 | 164 | ||
165 | protected void OnRequestCallbackTimeout(object source, ElapsedEventArgs args) | 165 | protected void OnRequestCallbackTimeout(object source, ElapsedEventArgs args) |
166 | { | 166 | { |
167 | bool close = true; | 167 | bool timedOut = true; |
168 | 168 | ||
169 | try | 169 | try |
170 | { | 170 | { |
@@ -174,7 +174,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
174 | // the final request came in (assuming that such a thing is possible) | 174 | // the final request came in (assuming that such a thing is possible) |
175 | if (m_requestState == RequestState.Completed) | 175 | if (m_requestState == RequestState.Completed) |
176 | { | 176 | { |
177 | close = false; | 177 | timedOut = false; |
178 | return; | 178 | return; |
179 | } | 179 | } |
180 | 180 | ||
@@ -223,8 +223,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
223 | } | 223 | } |
224 | finally | 224 | finally |
225 | { | 225 | { |
226 | if (close) | 226 | if (timedOut) |
227 | m_assetsArchiver.ForceClose(); | 227 | Util.FireAndForget(PerformAssetsRequestCallback, true); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
@@ -290,7 +290,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
290 | 290 | ||
291 | // We want to stop using the asset cache thread asap | 291 | // We want to stop using the asset cache thread asap |
292 | // as we now need to do the work of producing the rest of the archive | 292 | // as we now need to do the work of producing the rest of the archive |
293 | Util.FireAndForget(PerformAssetsRequestCallback); | 293 | Util.FireAndForget(PerformAssetsRequestCallback, false); |
294 | } | 294 | } |
295 | else | 295 | else |
296 | { | 296 | { |
@@ -311,9 +311,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
311 | { | 311 | { |
312 | Culture.SetCurrentCulture(); | 312 | Culture.SetCurrentCulture(); |
313 | 313 | ||
314 | Boolean timedOut = (Boolean)o; | ||
315 | |||
314 | try | 316 | try |
315 | { | 317 | { |
316 | m_assetsRequestCallback(m_foundAssetUuids, m_notFoundAssetUuids); | 318 | m_assetsRequestCallback(m_foundAssetUuids, m_notFoundAssetUuids, timedOut); |
317 | } | 319 | } |
318 | catch (Exception e) | 320 | catch (Exception e) |
319 | { | 321 | { |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 82f49b0..eec1cec 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -31,16 +31,19 @@ using System.IO; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using log4net.Config; | 33 | using log4net.Config; |
34 | using Nini.Config; | ||
34 | using NUnit.Framework; | 35 | using NUnit.Framework; |
35 | using OpenMetaverse; | 36 | using OpenMetaverse; |
36 | using OpenMetaverse.Assets; | 37 | using OpenMetaverse.Assets; |
37 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Serialization; | 39 | using OpenSim.Framework.Serialization; |
39 | using OpenSim.Framework.Serialization.External; | 40 | using OpenSim.Framework.Serialization.External; |
41 | using OpenSim.Region.CoreModules.World.Land; | ||
40 | using OpenSim.Region.CoreModules.World.Serialiser; | 42 | using OpenSim.Region.CoreModules.World.Serialiser; |
41 | using OpenSim.Region.CoreModules.World.Terrain; | 43 | using OpenSim.Region.CoreModules.World.Terrain; |
42 | using OpenSim.Region.Framework.Scenes; | 44 | using OpenSim.Region.Framework.Scenes; |
43 | using OpenSim.Region.Framework.Scenes.Serialization; | 45 | using OpenSim.Region.Framework.Scenes.Serialization; |
46 | using OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups; | ||
44 | using OpenSim.Tests.Common; | 47 | using OpenSim.Tests.Common; |
45 | using OpenSim.Tests.Common.Mock; | 48 | using OpenSim.Tests.Common.Mock; |
46 | using ArchiveConstants = OpenSim.Framework.Serialization.ArchiveConstants; | 49 | using ArchiveConstants = OpenSim.Framework.Serialization.ArchiveConstants; |
@@ -69,9 +72,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
69 | { | 72 | { |
70 | base.SetUp(); | 73 | base.SetUp(); |
71 | 74 | ||
72 | // FIXME: Do something about this - relying on statics in unit tests causes trouble sooner or later | ||
73 | new SceneManager(); | ||
74 | |||
75 | m_archiverModule = new ArchiverModule(); | 75 | m_archiverModule = new ArchiverModule(); |
76 | m_serialiserModule = new SerialiserModule(); | 76 | m_serialiserModule = new SerialiserModule(); |
77 | TerrainModule terrainModule = new TerrainModule(); | 77 | TerrainModule terrainModule = new TerrainModule(); |
@@ -127,6 +127,53 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
127 | 127 | ||
128 | return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition) { Name = partName }; | 128 | return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition) { Name = partName }; |
129 | } | 129 | } |
130 | |||
131 | private void CreateTestObjects(Scene scene, out SceneObjectGroup sog1, out SceneObjectGroup sog2, out UUID ncAssetUuid) | ||
132 | { | ||
133 | SceneObjectPart part1 = CreateSceneObjectPart1(); | ||
134 | sog1 = new SceneObjectGroup(part1); | ||
135 | scene.AddNewSceneObject(sog1, false); | ||
136 | |||
137 | AssetNotecard nc = new AssetNotecard(); | ||
138 | nc.BodyText = "Hello World!"; | ||
139 | nc.Encode(); | ||
140 | ncAssetUuid = UUID.Random(); | ||
141 | UUID ncItemUuid = UUID.Random(); | ||
142 | AssetBase ncAsset | ||
143 | = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero); | ||
144 | m_scene.AssetService.Store(ncAsset); | ||
145 | |||
146 | TaskInventoryItem ncItem | ||
147 | = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid }; | ||
148 | SceneObjectPart part2 = CreateSceneObjectPart2(); | ||
149 | sog2 = new SceneObjectGroup(part2); | ||
150 | part2.Inventory.AddInventoryItem(ncItem, true); | ||
151 | |||
152 | scene.AddNewSceneObject(sog2, false); | ||
153 | } | ||
154 | |||
155 | private static void CreateSoundAsset(TarArchiveWriter tar, Assembly assembly, string soundDataResourceName, out byte[] soundData, out UUID soundUuid) | ||
156 | { | ||
157 | using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName)) | ||
158 | { | ||
159 | using (BinaryReader br = new BinaryReader(resource)) | ||
160 | { | ||
161 | // FIXME: Use the inspector instead | ||
162 | soundData = br.ReadBytes(99999999); | ||
163 | soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
164 | string soundAssetFileName | ||
165 | = ArchiveConstants.ASSETS_PATH + soundUuid | ||
166 | + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV]; | ||
167 | tar.WriteFile(soundAssetFileName, soundData); | ||
168 | |||
169 | /* | ||
170 | AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData); | ||
171 | scene.AssetService.Store(soundAsset); | ||
172 | asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav"; | ||
173 | */ | ||
174 | } | ||
175 | } | ||
176 | } | ||
130 | 177 | ||
131 | /// <summary> | 178 | /// <summary> |
132 | /// Test saving an OpenSim Region Archive. | 179 | /// Test saving an OpenSim Region Archive. |
@@ -204,30 +251,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
204 | // TODO: Test presence of more files and contents of files. | 251 | // TODO: Test presence of more files and contents of files. |
205 | } | 252 | } |
206 | 253 | ||
207 | private void CreateTestObjects(Scene scene, out SceneObjectGroup sog1, out SceneObjectGroup sog2, out UUID ncAssetUuid) | ||
208 | { | ||
209 | SceneObjectPart part1 = CreateSceneObjectPart1(); | ||
210 | sog1 = new SceneObjectGroup(part1); | ||
211 | scene.AddNewSceneObject(sog1, false); | ||
212 | |||
213 | AssetNotecard nc = new AssetNotecard(); | ||
214 | nc.BodyText = "Hello World!"; | ||
215 | nc.Encode(); | ||
216 | ncAssetUuid = UUID.Random(); | ||
217 | UUID ncItemUuid = UUID.Random(); | ||
218 | AssetBase ncAsset | ||
219 | = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero); | ||
220 | m_scene.AssetService.Store(ncAsset); | ||
221 | |||
222 | TaskInventoryItem ncItem | ||
223 | = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid }; | ||
224 | SceneObjectPart part2 = CreateSceneObjectPart2(); | ||
225 | sog2 = new SceneObjectGroup(part2); | ||
226 | part2.Inventory.AddInventoryItem(ncItem, true); | ||
227 | |||
228 | scene.AddNewSceneObject(sog2, false); | ||
229 | } | ||
230 | |||
231 | /// <summary> | 254 | /// <summary> |
232 | /// Test saving an OpenSim Region Archive with the no assets option | 255 | /// Test saving an OpenSim Region Archive with the no assets option |
233 | /// </summary> | 256 | /// </summary> |
@@ -309,59 +332,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
309 | } | 332 | } |
310 | 333 | ||
311 | /// <summary> | 334 | /// <summary> |
312 | /// Test loading an OpenSim Region Archive where the scene object parts are not ordered by link number (e.g. | ||
313 | /// 2 can come after 3). | ||
314 | /// </summary> | ||
315 | [Test] | ||
316 | public void TestLoadOarUnorderedParts() | ||
317 | { | ||
318 | TestHelpers.InMethod(); | ||
319 | |||
320 | UUID ownerId = TestHelpers.ParseTail(0xaaaa); | ||
321 | |||
322 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
323 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
324 | |||
325 | tar.WriteFile( | ||
326 | ArchiveConstants.CONTROL_FILE_PATH, | ||
327 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); | ||
328 | |||
329 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ownerId, "obj1-", 0x11); | ||
330 | SceneObjectPart sop2 | ||
331 | = SceneHelpers.CreateSceneObjectPart("obj1-Part2", TestHelpers.ParseTail(0x12), ownerId); | ||
332 | SceneObjectPart sop3 | ||
333 | = SceneHelpers.CreateSceneObjectPart("obj1-Part3", TestHelpers.ParseTail(0x13), ownerId); | ||
334 | |||
335 | // Add the parts so they will be written out in reverse order to the oar | ||
336 | sog1.AddPart(sop3); | ||
337 | sop3.LinkNum = 3; | ||
338 | sog1.AddPart(sop2); | ||
339 | sop2.LinkNum = 2; | ||
340 | |||
341 | tar.WriteFile( | ||
342 | ArchiveConstants.CreateOarObjectPath(sog1.Name, sog1.UUID, sog1.AbsolutePosition), | ||
343 | SceneObjectSerializer.ToXml2Format(sog1)); | ||
344 | |||
345 | tar.Close(); | ||
346 | |||
347 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
348 | |||
349 | lock (this) | ||
350 | { | ||
351 | m_scene.EventManager.OnOarFileLoaded += LoadCompleted; | ||
352 | m_archiverModule.DearchiveRegion(archiveReadStream); | ||
353 | } | ||
354 | |||
355 | Assert.That(m_lastErrorMessage, Is.Null); | ||
356 | |||
357 | SceneObjectPart part2 = m_scene.GetSceneObjectPart("obj1-Part2"); | ||
358 | Assert.That(part2.LinkNum, Is.EqualTo(2)); | ||
359 | |||
360 | SceneObjectPart part3 = m_scene.GetSceneObjectPart("obj1-Part3"); | ||
361 | Assert.That(part3.LinkNum, Is.EqualTo(3)); | ||
362 | } | ||
363 | |||
364 | /// <summary> | ||
365 | /// Test loading an OpenSim Region Archive. | 335 | /// Test loading an OpenSim Region Archive. |
366 | /// </summary> | 336 | /// </summary> |
367 | [Test] | 337 | [Test] |
@@ -435,50 +405,57 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
435 | TestLoadedRegion(part1, soundItemName, soundData); | 405 | TestLoadedRegion(part1, soundItemName, soundData); |
436 | } | 406 | } |
437 | 407 | ||
438 | private static void CreateSoundAsset(TarArchiveWriter tar, Assembly assembly, string soundDataResourceName, out byte[] soundData, out UUID soundUuid) | 408 | /// <summary> |
409 | /// Test loading an OpenSim Region Archive where the scene object parts are not ordered by link number (e.g. | ||
410 | /// 2 can come after 3). | ||
411 | /// </summary> | ||
412 | [Test] | ||
413 | public void TestLoadOarUnorderedParts() | ||
439 | { | 414 | { |
440 | using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName)) | 415 | TestHelpers.InMethod(); |
441 | { | ||
442 | using (BinaryReader br = new BinaryReader(resource)) | ||
443 | { | ||
444 | // FIXME: Use the inspector instead | ||
445 | soundData = br.ReadBytes(99999999); | ||
446 | soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
447 | string soundAssetFileName | ||
448 | = ArchiveConstants.ASSETS_PATH + soundUuid | ||
449 | + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV]; | ||
450 | tar.WriteFile(soundAssetFileName, soundData); | ||
451 | 416 | ||
452 | /* | 417 | UUID ownerId = TestHelpers.ParseTail(0xaaaa); |
453 | AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData); | ||
454 | scene.AssetService.Store(soundAsset); | ||
455 | asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav"; | ||
456 | */ | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | 418 | ||
461 | private void TestLoadedRegion(SceneObjectPart part1, string soundItemName, byte[] soundData) | 419 | MemoryStream archiveWriteStream = new MemoryStream(); |
462 | { | 420 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); |
463 | SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name); | ||
464 | 421 | ||
465 | Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); | 422 | tar.WriteFile( |
466 | Assert.That(object1PartLoaded.Name, Is.EqualTo(part1.Name), "object1 names not identical"); | 423 | ArchiveConstants.CONTROL_FILE_PATH, |
467 | Assert.That(object1PartLoaded.GroupPosition, Is.EqualTo(part1.GroupPosition), "object1 group position not equal"); | 424 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); |
468 | Assert.That( | ||
469 | object1PartLoaded.RotationOffset, Is.EqualTo(part1.RotationOffset), "object1 rotation offset not equal"); | ||
470 | Assert.That( | ||
471 | object1PartLoaded.OffsetPosition, Is.EqualTo(part1.OffsetPosition), "object1 offset position not equal"); | ||
472 | Assert.That(object1PartLoaded.SitTargetOrientation, Is.EqualTo(part1.SitTargetOrientation)); | ||
473 | Assert.That(object1PartLoaded.SitTargetPosition, Is.EqualTo(part1.SitTargetPosition)); | ||
474 | 425 | ||
475 | TaskInventoryItem loadedSoundItem = object1PartLoaded.Inventory.GetInventoryItems(soundItemName)[0]; | 426 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ownerId, "obj1-", 0x11); |
476 | Assert.That(loadedSoundItem, Is.Not.Null, "loaded sound item was null"); | 427 | SceneObjectPart sop2 |
477 | AssetBase loadedSoundAsset = m_scene.AssetService.Get(loadedSoundItem.AssetID.ToString()); | 428 | = SceneHelpers.CreateSceneObjectPart("obj1-Part2", TestHelpers.ParseTail(0x12), ownerId); |
478 | Assert.That(loadedSoundAsset, Is.Not.Null, "loaded sound asset was null"); | 429 | SceneObjectPart sop3 |
479 | Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match"); | 430 | = SceneHelpers.CreateSceneObjectPart("obj1-Part3", TestHelpers.ParseTail(0x13), ownerId); |
480 | 431 | ||
481 | Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels"); | 432 | // Add the parts so they will be written out in reverse order to the oar |
433 | sog1.AddPart(sop3); | ||
434 | sop3.LinkNum = 3; | ||
435 | sog1.AddPart(sop2); | ||
436 | sop2.LinkNum = 2; | ||
437 | |||
438 | tar.WriteFile( | ||
439 | ArchiveConstants.CreateOarObjectPath(sog1.Name, sog1.UUID, sog1.AbsolutePosition), | ||
440 | SceneObjectSerializer.ToXml2Format(sog1)); | ||
441 | |||
442 | tar.Close(); | ||
443 | |||
444 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
445 | |||
446 | lock (this) | ||
447 | { | ||
448 | m_scene.EventManager.OnOarFileLoaded += LoadCompleted; | ||
449 | m_archiverModule.DearchiveRegion(archiveReadStream); | ||
450 | } | ||
451 | |||
452 | Assert.That(m_lastErrorMessage, Is.Null); | ||
453 | |||
454 | SceneObjectPart part2 = m_scene.GetSceneObjectPart("obj1-Part2"); | ||
455 | Assert.That(part2.LinkNum, Is.EqualTo(2)); | ||
456 | |||
457 | SceneObjectPart part3 = m_scene.GetSceneObjectPart("obj1-Part3"); | ||
458 | Assert.That(part3.LinkNum, Is.EqualTo(3)); | ||
482 | } | 459 | } |
483 | 460 | ||
484 | /// <summary> | 461 | /// <summary> |
@@ -538,8 +515,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
538 | SerialiserModule serialiserModule = new SerialiserModule(); | 515 | SerialiserModule serialiserModule = new SerialiserModule(); |
539 | TerrainModule terrainModule = new TerrainModule(); | 516 | TerrainModule terrainModule = new TerrainModule(); |
540 | 517 | ||
541 | m_sceneHelpers = new SceneHelpers(); | 518 | SceneHelpers m_sceneHelpers2 = new SceneHelpers(); |
542 | TestScene scene2 = m_sceneHelpers.SetupScene(); | 519 | TestScene scene2 = m_sceneHelpers2.SetupScene(); |
543 | SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); | 520 | SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); |
544 | 521 | ||
545 | // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is | 522 | // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is |
@@ -563,6 +540,71 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
563 | } | 540 | } |
564 | 541 | ||
565 | /// <summary> | 542 | /// <summary> |
543 | /// Test OAR loading where the land parcel is group deeded. | ||
544 | /// </summary> | ||
545 | /// <remarks> | ||
546 | /// In this situation, the owner ID is set to the group ID. | ||
547 | /// </remarks> | ||
548 | [Test] | ||
549 | public void TestLoadOarDeededLand() | ||
550 | { | ||
551 | TestHelpers.InMethod(); | ||
552 | // TestHelpers.EnableLogging(); | ||
553 | |||
554 | UUID landID = TestHelpers.ParseTail(0x10); | ||
555 | |||
556 | MockGroupsServicesConnector groupsService = new MockGroupsServicesConnector(); | ||
557 | |||
558 | IConfigSource configSource = new IniConfigSource(); | ||
559 | IConfig config = configSource.AddConfig("Groups"); | ||
560 | config.Set("Enabled", true); | ||
561 | config.Set("Module", "GroupsModule"); | ||
562 | config.Set("DebugEnabled", true); | ||
563 | SceneHelpers.SetupSceneModules( | ||
564 | m_scene, configSource, new object[] { new GroupsModule(), groupsService, new LandManagementModule() }); | ||
565 | |||
566 | // Create group in scene for loading | ||
567 | // FIXME: For now we'll put up with the issue that we'll get a group ID that varies across tests. | ||
568 | UUID groupID | ||
569 | = groupsService.CreateGroup(UUID.Zero, "group1", "", true, UUID.Zero, 3, true, true, true, UUID.Zero); | ||
570 | |||
571 | // Construct OAR | ||
572 | MemoryStream oarStream = new MemoryStream(); | ||
573 | TarArchiveWriter tar = new TarArchiveWriter(oarStream); | ||
574 | |||
575 | tar.WriteDir(ArchiveConstants.LANDDATA_PATH); | ||
576 | tar.WriteFile( | ||
577 | ArchiveConstants.CONTROL_FILE_PATH, | ||
578 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); | ||
579 | |||
580 | LandObject lo = new LandObject(groupID, true, null); | ||
581 | lo.SetLandBitmap(lo.BasicFullRegionLandBitmap()); | ||
582 | LandData ld = lo.LandData; | ||
583 | ld.GlobalID = landID; | ||
584 | |||
585 | string ldPath = ArchiveConstants.CreateOarLandDataPath(ld); | ||
586 | tar.WriteFile(ldPath, LandDataSerializer.Serialize(ld, null)); | ||
587 | tar.Close(); | ||
588 | |||
589 | oarStream = new MemoryStream(oarStream.ToArray()); | ||
590 | |||
591 | // Load OAR | ||
592 | lock (this) | ||
593 | { | ||
594 | m_scene.EventManager.OnOarFileLoaded += LoadCompleted; | ||
595 | m_archiverModule.DearchiveRegion(oarStream); | ||
596 | } | ||
597 | |||
598 | ILandObject rLo = m_scene.LandChannel.GetLandObject(16, 16); | ||
599 | LandData rLd = rLo.LandData; | ||
600 | |||
601 | Assert.That(rLd.GlobalID, Is.EqualTo(landID)); | ||
602 | Assert.That(rLd.OwnerID, Is.EqualTo(groupID)); | ||
603 | Assert.That(rLd.GroupID, Is.EqualTo(groupID)); | ||
604 | Assert.That(rLd.IsGroupOwned, Is.EqualTo(true)); | ||
605 | } | ||
606 | |||
607 | /// <summary> | ||
566 | /// Test loading the region settings of an OpenSim Region Archive. | 608 | /// Test loading the region settings of an OpenSim Region Archive. |
567 | /// </summary> | 609 | /// </summary> |
568 | [Test] | 610 | [Test] |
@@ -781,9 +823,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
781 | } | 823 | } |
782 | } | 824 | } |
783 | 825 | ||
784 | |||
785 | // Save OAR | 826 | // Save OAR |
786 | |||
787 | MemoryStream archiveWriteStream = new MemoryStream(); | 827 | MemoryStream archiveWriteStream = new MemoryStream(); |
788 | m_scene.EventManager.OnOarFileSaved += SaveCompleted; | 828 | m_scene.EventManager.OnOarFileSaved += SaveCompleted; |
789 | 829 | ||
@@ -800,7 +840,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
800 | 840 | ||
801 | 841 | ||
802 | // Check that the OAR contains the expected data | 842 | // Check that the OAR contains the expected data |
803 | |||
804 | Assert.That(m_lastRequestId, Is.EqualTo(requestId)); | 843 | Assert.That(m_lastRequestId, Is.EqualTo(requestId)); |
805 | 844 | ||
806 | byte[] archive = archiveWriteStream.ToArray(); | 845 | byte[] archive = archiveWriteStream.ToArray(); |
@@ -892,7 +931,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
892 | } | 931 | } |
893 | 932 | ||
894 | ArchiveScenesGroup scenesGroup = new ArchiveScenesGroup(); | 933 | ArchiveScenesGroup scenesGroup = new ArchiveScenesGroup(); |
895 | SceneManager.Instance.ForEachScene(delegate(Scene scene) | 934 | m_sceneHelpers.SceneManager.ForEachScene(delegate(Scene scene) |
896 | { | 935 | { |
897 | scenesGroup.AddScene(scene); | 936 | scenesGroup.AddScene(scene); |
898 | }); | 937 | }); |
@@ -950,13 +989,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
950 | 989 | ||
951 | // Delete the current objects, to test that they're loaded from the OAR and didn't | 990 | // Delete the current objects, to test that they're loaded from the OAR and didn't |
952 | // just remain in the scene. | 991 | // just remain in the scene. |
953 | SceneManager.Instance.ForEachScene(delegate(Scene scene) | 992 | m_sceneHelpers.SceneManager.ForEachScene(delegate(Scene scene) |
954 | { | 993 | { |
955 | scene.DeleteAllSceneObjects(); | 994 | scene.DeleteAllSceneObjects(); |
956 | }); | 995 | }); |
957 | 996 | ||
958 | // Create a "hole", to test that that the corresponding region isn't loaded from the OAR | 997 | // Create a "hole", to test that that the corresponding region isn't loaded from the OAR |
959 | SceneManager.Instance.CloseScene(SceneManager.Instance.Scenes[1]); | 998 | m_sceneHelpers.SceneManager.CloseScene(SceneManager.Instance.Scenes[1]); |
960 | 999 | ||
961 | 1000 | ||
962 | // Check thay the OAR file contains the expected data | 1001 | // Check thay the OAR file contains the expected data |
@@ -971,10 +1010,32 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
971 | 1010 | ||
972 | Assert.That(m_lastErrorMessage, Is.Null); | 1011 | Assert.That(m_lastErrorMessage, Is.Null); |
973 | 1012 | ||
974 | Assert.AreEqual(3, SceneManager.Instance.Scenes.Count); | 1013 | Assert.AreEqual(3, m_sceneHelpers.SceneManager.Scenes.Count); |
975 | 1014 | ||
976 | TestLoadedRegion(part1, soundItemName, soundData); | 1015 | TestLoadedRegion(part1, soundItemName, soundData); |
977 | } | 1016 | } |
978 | 1017 | ||
1018 | private void TestLoadedRegion(SceneObjectPart part1, string soundItemName, byte[] soundData) | ||
1019 | { | ||
1020 | SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name); | ||
1021 | |||
1022 | Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); | ||
1023 | Assert.That(object1PartLoaded.Name, Is.EqualTo(part1.Name), "object1 names not identical"); | ||
1024 | Assert.That(object1PartLoaded.GroupPosition, Is.EqualTo(part1.GroupPosition), "object1 group position not equal"); | ||
1025 | Assert.That( | ||
1026 | object1PartLoaded.RotationOffset, Is.EqualTo(part1.RotationOffset), "object1 rotation offset not equal"); | ||
1027 | Assert.That( | ||
1028 | object1PartLoaded.OffsetPosition, Is.EqualTo(part1.OffsetPosition), "object1 offset position not equal"); | ||
1029 | Assert.That(object1PartLoaded.SitTargetOrientation, Is.EqualTo(part1.SitTargetOrientation)); | ||
1030 | Assert.That(object1PartLoaded.SitTargetPosition, Is.EqualTo(part1.SitTargetPosition)); | ||
1031 | |||
1032 | TaskInventoryItem loadedSoundItem = object1PartLoaded.Inventory.GetInventoryItems(soundItemName)[0]; | ||
1033 | Assert.That(loadedSoundItem, Is.Not.Null, "loaded sound item was null"); | ||
1034 | AssetBase loadedSoundAsset = m_scene.AssetService.Get(loadedSoundItem.AssetID.ToString()); | ||
1035 | Assert.That(loadedSoundAsset, Is.Not.Null, "loaded sound asset was null"); | ||
1036 | Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match"); | ||
1037 | |||
1038 | Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels"); | ||
1039 | } | ||
979 | } | 1040 | } |
980 | } | 1041 | } \ No newline at end of file |
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index dc062b6..a5f5749 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs | |||
@@ -55,6 +55,11 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
55 | 55 | ||
56 | protected EstateManagementCommands m_commands; | 56 | protected EstateManagementCommands m_commands; |
57 | 57 | ||
58 | /// <summary> | ||
59 | /// If false, region restart requests from the client are blocked even if they are otherwise legitimate. | ||
60 | /// </summary> | ||
61 | public bool AllowRegionRestartFromClient { get; set; } | ||
62 | |||
58 | private EstateTerrainXferHandler TerrainUploader; | 63 | private EstateTerrainXferHandler TerrainUploader; |
59 | public TelehubManager m_Telehub; | 64 | public TelehubManager m_Telehub; |
60 | 65 | ||
@@ -64,6 +69,53 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
64 | 69 | ||
65 | private int m_delayCount = 0; | 70 | private int m_delayCount = 0; |
66 | 71 | ||
72 | #region Region Module interface | ||
73 | |||
74 | public string Name { get { return "EstateManagementModule"; } } | ||
75 | |||
76 | public Type ReplaceableInterface { get { return null; } } | ||
77 | |||
78 | public void Initialise(IConfigSource source) | ||
79 | { | ||
80 | AllowRegionRestartFromClient = true; | ||
81 | |||
82 | IConfig config = source.Configs["EstateManagement"]; | ||
83 | |||
84 | if (config != null) | ||
85 | AllowRegionRestartFromClient = config.GetBoolean("AllowRegionRestartFromClient", true); | ||
86 | } | ||
87 | |||
88 | public void AddRegion(Scene scene) | ||
89 | { | ||
90 | Scene = scene; | ||
91 | Scene.RegisterModuleInterface<IEstateModule>(this); | ||
92 | Scene.EventManager.OnNewClient += EventManager_OnNewClient; | ||
93 | Scene.EventManager.OnRequestChangeWaterHeight += changeWaterHeight; | ||
94 | |||
95 | m_Telehub = new TelehubManager(scene); | ||
96 | |||
97 | m_commands = new EstateManagementCommands(this); | ||
98 | m_commands.Initialise(); | ||
99 | } | ||
100 | |||
101 | public void RemoveRegion(Scene scene) {} | ||
102 | |||
103 | public void RegionLoaded(Scene scene) | ||
104 | { | ||
105 | // Sets up the sun module based no the saved Estate and Region Settings | ||
106 | // DO NOT REMOVE or the sun will stop working | ||
107 | scene.TriggerEstateSunUpdate(); | ||
108 | |||
109 | UserManager = scene.RequestModuleInterface<IUserManagement>(); | ||
110 | } | ||
111 | |||
112 | public void Close() | ||
113 | { | ||
114 | m_commands.Close(); | ||
115 | } | ||
116 | |||
117 | #endregion | ||
118 | |||
67 | #region Packet Data Responders | 119 | #region Packet Data Responders |
68 | 120 | ||
69 | private void clientSendDetailedEstateData(IClientAPI remote_client, UUID invoice) | 121 | private void clientSendDetailedEstateData(IClientAPI remote_client, UUID invoice) |
@@ -76,7 +128,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
76 | { | 128 | { |
77 | uint sun = 0; | 129 | uint sun = 0; |
78 | 130 | ||
79 | if (!Scene.RegionInfo.EstateSettings.UseGlobalTime) | 131 | if (Scene.RegionInfo.EstateSettings.FixedSun) |
80 | sun = (uint)(Scene.RegionInfo.EstateSettings.SunPosition * 1024.0) + 0x1800; | 132 | sun = (uint)(Scene.RegionInfo.EstateSettings.SunPosition * 1024.0) + 0x1800; |
81 | UUID estateOwner; | 133 | UUID estateOwner; |
82 | estateOwner = Scene.RegionInfo.EstateSettings.EstateOwner; | 134 | estateOwner = Scene.RegionInfo.EstateSettings.EstateOwner; |
@@ -197,6 +249,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
197 | Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture; | 249 | Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture; |
198 | break; | 250 | break; |
199 | } | 251 | } |
252 | |||
200 | Scene.RegionInfo.RegionSettings.Save(); | 253 | Scene.RegionInfo.RegionSettings.Save(); |
201 | TriggerRegionInfoChange(); | 254 | TriggerRegionInfoChange(); |
202 | sendRegionInfoPacketToAll(); | 255 | sendRegionInfoPacketToAll(); |
@@ -228,6 +281,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
228 | Scene.RegionInfo.RegionSettings.Elevation2NE = highValue; | 281 | Scene.RegionInfo.RegionSettings.Elevation2NE = highValue; |
229 | break; | 282 | break; |
230 | } | 283 | } |
284 | |||
231 | Scene.RegionInfo.RegionSettings.Save(); | 285 | Scene.RegionInfo.RegionSettings.Save(); |
232 | TriggerRegionInfoChange(); | 286 | TriggerRegionInfoChange(); |
233 | sendRegionHandshakeToAll(); | 287 | sendRegionHandshakeToAll(); |
@@ -268,6 +322,12 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
268 | 322 | ||
269 | private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds) | 323 | private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds) |
270 | { | 324 | { |
325 | if (!AllowRegionRestartFromClient) | ||
326 | { | ||
327 | remoteClient.SendAlertMessage("Region restart has been disabled on this simulator."); | ||
328 | return; | ||
329 | } | ||
330 | |||
271 | IRestartModule restartModule = Scene.RequestModuleInterface<IRestartModule>(); | 331 | IRestartModule restartModule = Scene.RequestModuleInterface<IRestartModule>(); |
272 | if (restartModule != null) | 332 | if (restartModule != null) |
273 | { | 333 | { |
@@ -352,6 +412,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
352 | } | 412 | } |
353 | 413 | ||
354 | } | 414 | } |
415 | |||
355 | if ((estateAccessType & 8) != 0) // User remove | 416 | if ((estateAccessType & 8) != 0) // User remove |
356 | { | 417 | { |
357 | if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true)) | 418 | if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true)) |
@@ -383,6 +444,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
383 | remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions"); | 444 | remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions"); |
384 | } | 445 | } |
385 | } | 446 | } |
447 | |||
386 | if ((estateAccessType & 16) != 0) // Group add | 448 | if ((estateAccessType & 16) != 0) // Group add |
387 | { | 449 | { |
388 | if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true)) | 450 | if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true)) |
@@ -650,7 +712,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
650 | } | 712 | } |
651 | } | 713 | } |
652 | 714 | ||
653 | public void handleOnEstateManageTelehub (IClientAPI client, UUID invoice, UUID senderID, string cmd, uint param1) | 715 | public void handleOnEstateManageTelehub(IClientAPI client, UUID invoice, UUID senderID, string cmd, uint param1) |
654 | { | 716 | { |
655 | SceneObjectPart part; | 717 | SceneObjectPart part; |
656 | 718 | ||
@@ -718,13 +780,18 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
718 | Scene.RegionInfo.RegionSettings.Save(); | 780 | Scene.RegionInfo.RegionSettings.Save(); |
719 | TriggerRegionInfoChange(); | 781 | TriggerRegionInfoChange(); |
720 | 782 | ||
721 | Scene.SetSceneCoreDebug( | 783 | ISceneCommandsModule scm = Scene.RequestModuleInterface<ISceneCommandsModule>(); |
722 | new Dictionary<string, string>() { | 784 | |
723 | { "scripting", (!disableScripts).ToString() }, | 785 | if (scm != null) |
724 | { "collisions", (!disableCollisions).ToString() }, | 786 | { |
725 | { "physics", (!disablePhysics).ToString() } | 787 | scm.SetSceneDebugOptions( |
726 | } | 788 | new Dictionary<string, string>() { |
727 | ); | 789 | { "scripting", (!disableScripts).ToString() }, |
790 | { "collisions", (!disableCollisions).ToString() }, | ||
791 | { "physics", (!disablePhysics).ToString() } | ||
792 | } | ||
793 | ); | ||
794 | } | ||
728 | } | 795 | } |
729 | 796 | ||
730 | private void handleEstateTeleportOneUserHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID, UUID prey) | 797 | private void handleEstateTeleportOneUserHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID, UUID prey) |
@@ -1066,6 +1133,7 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
1066 | { | 1133 | { |
1067 | Scene.RegionInfo.EstateSettings.UseGlobalTime = false; | 1134 | Scene.RegionInfo.EstateSettings.UseGlobalTime = false; |
1068 | Scene.RegionInfo.EstateSettings.SunPosition = (parms2 - 0x1800)/1024.0; | 1135 | Scene.RegionInfo.EstateSettings.SunPosition = (parms2 - 0x1800)/1024.0; |
1136 | // Warning: FixedSun should be set to True, otherwise this sun position won't be used. | ||
1069 | } | 1137 | } |
1070 | 1138 | ||
1071 | if ((parms1 & 0x00000010) != 0) | 1139 | if ((parms1 & 0x00000010) != 0) |
@@ -1118,49 +1186,6 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
1118 | 1186 | ||
1119 | #endregion | 1187 | #endregion |
1120 | 1188 | ||
1121 | #region Region Module interface | ||
1122 | |||
1123 | public string Name { get { return "EstateManagementModule"; } } | ||
1124 | |||
1125 | public Type ReplaceableInterface { get { return null; } } | ||
1126 | |||
1127 | public void Initialise(IConfigSource source) {} | ||
1128 | |||
1129 | public void AddRegion(Scene scene) | ||
1130 | { | ||
1131 | m_regionChangeTimer.AutoReset = false; | ||
1132 | m_regionChangeTimer.Interval = 2000; | ||
1133 | m_regionChangeTimer.Elapsed += RaiseRegionInfoChange; | ||
1134 | |||
1135 | Scene = scene; | ||
1136 | Scene.RegisterModuleInterface<IEstateModule>(this); | ||
1137 | Scene.EventManager.OnNewClient += EventManager_OnNewClient; | ||
1138 | Scene.EventManager.OnRequestChangeWaterHeight += changeWaterHeight; | ||
1139 | |||
1140 | m_Telehub = new TelehubManager(scene); | ||
1141 | |||
1142 | m_commands = new EstateManagementCommands(this); | ||
1143 | m_commands.Initialise(); | ||
1144 | } | ||
1145 | |||
1146 | public void RemoveRegion(Scene scene) {} | ||
1147 | |||
1148 | public void RegionLoaded(Scene scene) | ||
1149 | { | ||
1150 | // Sets up the sun module based no the saved Estate and Region Settings | ||
1151 | // DO NOT REMOVE or the sun will stop working | ||
1152 | scene.TriggerEstateSunUpdate(); | ||
1153 | |||
1154 | UserManager = scene.RequestModuleInterface<IUserManagement>(); | ||
1155 | } | ||
1156 | |||
1157 | public void Close() | ||
1158 | { | ||
1159 | m_commands.Close(); | ||
1160 | } | ||
1161 | |||
1162 | #endregion | ||
1163 | |||
1164 | #region Other Functions | 1189 | #region Other Functions |
1165 | 1190 | ||
1166 | public void changeWaterHeight(float height) | 1191 | public void changeWaterHeight(float height) |
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index 1193057..b4f7d51 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs | |||
@@ -141,6 +141,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
141 | m_scene.EventManager.OnValidateLandBuy += EventManagerOnValidateLandBuy; | 141 | m_scene.EventManager.OnValidateLandBuy += EventManagerOnValidateLandBuy; |
142 | m_scene.EventManager.OnLandBuy += EventManagerOnLandBuy; | 142 | m_scene.EventManager.OnLandBuy += EventManagerOnLandBuy; |
143 | m_scene.EventManager.OnNewClient += EventManagerOnNewClient; | 143 | m_scene.EventManager.OnNewClient += EventManagerOnNewClient; |
144 | m_scene.EventManager.OnMakeChildAgent += EventMakeChildAgent; | ||
144 | m_scene.EventManager.OnSignificantClientMovement += EventManagerOnSignificantClientMovement; | 145 | m_scene.EventManager.OnSignificantClientMovement += EventManagerOnSignificantClientMovement; |
145 | m_scene.EventManager.OnNoticeNoLandDataFromStorage += EventManagerOnNoLandDataFromStorage; | 146 | m_scene.EventManager.OnNoticeNoLandDataFromStorage += EventManagerOnNoLandDataFromStorage; |
146 | m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage; | 147 | m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage; |
@@ -221,6 +222,11 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
221 | } | 222 | } |
222 | } | 223 | } |
223 | 224 | ||
225 | public void EventMakeChildAgent(ScenePresence avatar) | ||
226 | { | ||
227 | avatar.currentParcelUUID = UUID.Zero; | ||
228 | } | ||
229 | |||
224 | void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) | 230 | void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) |
225 | { | 231 | { |
226 | } | 232 | } |
@@ -249,17 +255,15 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
249 | newData.LocalID = local_id; | 255 | newData.LocalID = local_id; |
250 | ILandObject landobj = null; | 256 | ILandObject landobj = null; |
251 | 257 | ||
258 | ILandObject land; | ||
252 | lock (m_landList) | 259 | lock (m_landList) |
253 | { | 260 | { |
254 | if (m_landList.ContainsKey(local_id)) | 261 | if (m_landList.TryGetValue(local_id, out land)) |
255 | { | 262 | land.LandData = newData; |
256 | m_landList[local_id].LandData = newData; | ||
257 | landobj = m_landList[local_id]; | ||
258 | // m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, m_landList[local_id]); | ||
259 | } | ||
260 | } | 263 | } |
261 | if(landobj != null) | 264 | |
262 | m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, landobj); | 265 | if (land != null) |
266 | m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land); | ||
263 | } | 267 | } |
264 | 268 | ||
265 | public bool AllowedForcefulBans | 269 | public bool AllowedForcefulBans |
@@ -584,7 +588,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
584 | // Only now can we add the prim counts to the land object - we rely on the global ID which is generated | 588 | // Only now can we add the prim counts to the land object - we rely on the global ID which is generated |
585 | // as a random UUID inside LandData initialization | 589 | // as a random UUID inside LandData initialization |
586 | if (m_primCountModule != null) | 590 | if (m_primCountModule != null) |
587 | new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID); | 591 | new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID); |
588 | 592 | ||
589 | lock (m_landList) | 593 | lock (m_landList) |
590 | { | 594 | { |
@@ -621,6 +625,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
621 | /// <param name="local_id">Land.localID of the peice of land to remove.</param> | 625 | /// <param name="local_id">Land.localID of the peice of land to remove.</param> |
622 | public void removeLandObject(int local_id) | 626 | public void removeLandObject(int local_id) |
623 | { | 627 | { |
628 | ILandObject land; | ||
624 | lock (m_landList) | 629 | lock (m_landList) |
625 | { | 630 | { |
626 | for (int x = 0; x < 64; x++) | 631 | for (int x = 0; x < 64; x++) |
@@ -637,9 +642,11 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
637 | } | 642 | } |
638 | } | 643 | } |
639 | 644 | ||
640 | m_scene.EventManager.TriggerLandObjectRemoved(m_landList[local_id].LandData.GlobalID); | 645 | land = m_landList[local_id]; |
641 | m_landList.Remove(local_id); | 646 | m_landList.Remove(local_id); |
642 | } | 647 | } |
648 | |||
649 | m_scene.EventManager.TriggerLandObjectRemoved(land.LandData.GlobalID); | ||
643 | } | 650 | } |
644 | 651 | ||
645 | /// <summary> | 652 | /// <summary> |
@@ -1384,9 +1391,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1384 | } | 1391 | } |
1385 | 1392 | ||
1386 | for (int i = 0; i < data.Count; i++) | 1393 | for (int i = 0; i < data.Count; i++) |
1387 | { | ||
1388 | IncomingLandObjectFromStorage(data[i]); | 1394 | IncomingLandObjectFromStorage(data[i]); |
1389 | } | ||
1390 | } | 1395 | } |
1391 | 1396 | ||
1392 | public void IncomingLandObjectFromStorage(LandData data) | 1397 | public void IncomingLandObjectFromStorage(LandData data) |
@@ -1401,25 +1406,72 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1401 | 1406 | ||
1402 | public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient) | 1407 | public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient) |
1403 | { | 1408 | { |
1404 | ILandObject selectedParcel = null; | 1409 | if (localID != -1) |
1405 | lock (m_landList) | ||
1406 | { | 1410 | { |
1407 | m_landList.TryGetValue(localID, out selectedParcel); | 1411 | ILandObject selectedParcel = null; |
1412 | lock (m_landList) | ||
1413 | { | ||
1414 | m_landList.TryGetValue(localID, out selectedParcel); | ||
1415 | } | ||
1416 | |||
1417 | if (selectedParcel == null) | ||
1418 | return; | ||
1419 | |||
1420 | selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient); | ||
1408 | } | 1421 | } |
1422 | else | ||
1423 | { | ||
1424 | if (returnType != 1) | ||
1425 | { | ||
1426 | m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown return type {0}", returnType); | ||
1427 | return; | ||
1428 | } | ||
1429 | |||
1430 | // We get here when the user returns objects from the list of Top Colliders or Top Scripts. | ||
1431 | // In that case we receive specific object UUID's, but no parcel ID. | ||
1432 | |||
1433 | Dictionary<UUID, HashSet<SceneObjectGroup>> returns = new Dictionary<UUID, HashSet<SceneObjectGroup>>(); | ||
1434 | |||
1435 | foreach (UUID groupID in taskIDs) | ||
1436 | { | ||
1437 | SceneObjectGroup obj = m_scene.GetSceneObjectGroup(groupID); | ||
1438 | if (obj != null) | ||
1439 | { | ||
1440 | if (!returns.ContainsKey(obj.OwnerID)) | ||
1441 | returns[obj.OwnerID] = new HashSet<SceneObjectGroup>(); | ||
1442 | returns[obj.OwnerID].Add(obj); | ||
1443 | } | ||
1444 | else | ||
1445 | { | ||
1446 | m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown object {0}", groupID); | ||
1447 | } | ||
1448 | } | ||
1409 | 1449 | ||
1410 | if (selectedParcel == null) return; | 1450 | int num = 0; |
1451 | foreach (HashSet<SceneObjectGroup> objs in returns.Values) | ||
1452 | num += objs.Count; | ||
1453 | m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Returning {0} specific object(s)", num); | ||
1411 | 1454 | ||
1412 | selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient); | 1455 | foreach (HashSet<SceneObjectGroup> objs in returns.Values) |
1456 | { | ||
1457 | List<SceneObjectGroup> objs2 = new List<SceneObjectGroup>(objs); | ||
1458 | if (m_scene.Permissions.CanReturnObjects(null, remoteClient.AgentId, objs2)) | ||
1459 | { | ||
1460 | m_scene.returnObjects(objs2.ToArray(), remoteClient.AgentId); | ||
1461 | } | ||
1462 | else | ||
1463 | { | ||
1464 | m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: not permitted to return {0} object(s) belonging to user {1}", | ||
1465 | objs2.Count, objs2[0].OwnerID); | ||
1466 | } | ||
1467 | } | ||
1468 | } | ||
1413 | } | 1469 | } |
1414 | 1470 | ||
1415 | public void EventManagerOnNoLandDataFromStorage() | 1471 | public void EventManagerOnNoLandDataFromStorage() |
1416 | { | 1472 | { |
1417 | // called methods already have locks | 1473 | ResetSimLandObjects(); |
1418 | // lock (m_landList) | 1474 | CreateDefaultParcel(); |
1419 | { | ||
1420 | ResetSimLandObjects(); | ||
1421 | CreateDefaultParcel(); | ||
1422 | } | ||
1423 | } | 1475 | } |
1424 | 1476 | ||
1425 | #endregion | 1477 | #endregion |
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index fdac418..07d00c0 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs | |||
@@ -761,9 +761,10 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
761 | int ty = min_y * 4; | 761 | int ty = min_y * 4; |
762 | if (ty > ((int)Constants.RegionSize - 1)) | 762 | if (ty > ((int)Constants.RegionSize - 1)) |
763 | ty = ((int)Constants.RegionSize - 1); | 763 | ty = ((int)Constants.RegionSize - 1); |
764 | |||
764 | LandData.AABBMin = | 765 | LandData.AABBMin = |
765 | new Vector3((float) (min_x * 4), (float) (min_y * 4), | 766 | new Vector3( |
766 | (float) m_scene.Heightmap[tx, ty]); | 767 | (float)(min_x * 4), (float)(min_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); |
767 | 768 | ||
768 | tx = max_x * 4; | 769 | tx = max_x * 4; |
769 | if (tx > ((int)Constants.RegionSize - 1)) | 770 | if (tx > ((int)Constants.RegionSize - 1)) |
@@ -771,9 +772,11 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
771 | ty = max_y * 4; | 772 | ty = max_y * 4; |
772 | if (ty > ((int)Constants.RegionSize - 1)) | 773 | if (ty > ((int)Constants.RegionSize - 1)) |
773 | ty = ((int)Constants.RegionSize - 1); | 774 | ty = ((int)Constants.RegionSize - 1); |
774 | LandData.AABBMax = | 775 | |
775 | new Vector3((float) (max_x * 4), (float) (max_y * 4), | 776 | LandData.AABBMax |
776 | (float) m_scene.Heightmap[tx, ty]); | 777 | = new Vector3( |
778 | (float)(max_x * 4), (float)(max_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); | ||
779 | |||
777 | LandData.Area = tempArea; | 780 | LandData.Area = tempArea; |
778 | } | 781 | } |
779 | 782 | ||
diff --git a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs index 55b8227..771fdd2 100644 --- a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs | |||
@@ -490,11 +490,14 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
490 | 490 | ||
491 | m_Scene.ForEachSOG(AddObject); | 491 | m_Scene.ForEachSOG(AddObject); |
492 | 492 | ||
493 | List<UUID> primcountKeys = new List<UUID>(m_PrimCounts.Keys); | 493 | lock (m_PrimCounts) |
494 | foreach (UUID k in primcountKeys) | ||
495 | { | 494 | { |
496 | if (!m_OwnerMap.ContainsKey(k)) | 495 | List<UUID> primcountKeys = new List<UUID>(m_PrimCounts.Keys); |
497 | m_PrimCounts.Remove(k); | 496 | foreach (UUID k in primcountKeys) |
497 | { | ||
498 | if (!m_OwnerMap.ContainsKey(k)) | ||
499 | m_PrimCounts.Remove(k); | ||
500 | } | ||
498 | } | 501 | } |
499 | 502 | ||
500 | m_Tainted = false; | 503 | m_Tainted = false; |
diff --git a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs index b5ee4d2..0945b43 100644 --- a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs +++ b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs | |||
@@ -41,7 +41,7 @@ using OpenSim.Tests.Common.Mock; | |||
41 | namespace OpenSim.Region.CoreModules.World.Land.Tests | 41 | namespace OpenSim.Region.CoreModules.World.Land.Tests |
42 | { | 42 | { |
43 | [TestFixture] | 43 | [TestFixture] |
44 | public class PrimCountModuleTests | 44 | public class PrimCountModuleTests : OpenSimTestCase |
45 | { | 45 | { |
46 | protected UUID m_userId = new UUID("00000000-0000-0000-0000-100000000000"); | 46 | protected UUID m_userId = new UUID("00000000-0000-0000-0000-100000000000"); |
47 | protected UUID m_groupId = new UUID("00000000-0000-0000-8888-000000000000"); | 47 | protected UUID m_groupId = new UUID("00000000-0000-0000-8888-000000000000"); |
@@ -60,8 +60,10 @@ namespace OpenSim.Region.CoreModules.World.Land.Tests | |||
60 | protected ILandObject m_lo2; | 60 | protected ILandObject m_lo2; |
61 | 61 | ||
62 | [SetUp] | 62 | [SetUp] |
63 | public void SetUp() | 63 | public override void SetUp() |
64 | { | 64 | { |
65 | base.SetUp(); | ||
66 | |||
65 | m_pcm = new PrimCountModule(); | 67 | m_pcm = new PrimCountModule(); |
66 | LandManagementModule lmm = new LandManagementModule(); | 68 | LandManagementModule lmm = new LandManagementModule(); |
67 | m_scene = new SceneHelpers().SetupScene(); | 69 | 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 396095a..03a96a4 100644 --- a/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs +++ b/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs | |||
@@ -44,14 +44,16 @@ using OpenSim.Tests.Common.Mock; | |||
44 | namespace OpenSim.Region.CoreModules.World.Media.Moap.Tests | 44 | namespace OpenSim.Region.CoreModules.World.Media.Moap.Tests |
45 | { | 45 | { |
46 | [TestFixture] | 46 | [TestFixture] |
47 | public class MoapTests | 47 | public class MoapTests : OpenSimTestCase |
48 | { | 48 | { |
49 | protected TestScene m_scene; | 49 | protected TestScene m_scene; |
50 | protected MoapModule m_module; | 50 | protected MoapModule m_module; |
51 | 51 | ||
52 | [SetUp] | 52 | [SetUp] |
53 | public void SetUp() | 53 | public override void SetUp() |
54 | { | 54 | { |
55 | base.SetUp(); | ||
56 | |||
55 | m_module = new MoapModule(); | 57 | m_module = new MoapModule(); |
56 | m_scene = new SceneHelpers().SetupScene(); | 58 | m_scene = new SceneHelpers().SetupScene(); |
57 | SceneHelpers.SetupSceneModules(m_scene, m_module); | 59 | SceneHelpers.SetupSceneModules(m_scene, m_module); |
diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs index ab8f143..7b235ae 100644 --- a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs | |||
@@ -365,7 +365,8 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands | |||
365 | 365 | ||
366 | if (mainParams.Count < 4) | 366 | if (mainParams.Count < 4) |
367 | { | 367 | { |
368 | m_console.OutputFormat("Usage: show part id [--full] <UUID-or-localID>"); | 368 | //m_console.OutputFormat("Usage: show part id [--full] <UUID-or-localID>"); |
369 | m_console.OutputFormat("Usage: show part id <UUID-or-localID>"); | ||
369 | return; | 370 | return; |
370 | } | 371 | } |
371 | 372 | ||
@@ -405,6 +406,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands | |||
405 | 406 | ||
406 | if (mainParams.Count < 5) | 407 | if (mainParams.Count < 5) |
407 | { | 408 | { |
409 | //m_console.OutputFormat("Usage: show part pos <start-coord> to <end-coord>"); | ||
408 | m_console.OutputFormat("Usage: show part pos [--full] <start-coord> to <end-coord>"); | 410 | m_console.OutputFormat("Usage: show part pos [--full] <start-coord> to <end-coord>"); |
409 | return; | 411 | return; |
410 | } | 412 | } |
@@ -445,7 +447,8 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands | |||
445 | 447 | ||
446 | if (mainParams.Count < 4) | 448 | if (mainParams.Count < 4) |
447 | { | 449 | { |
448 | m_console.OutputFormat("Usage: show part name [--full] [--regex] <name>"); | 450 | m_console.OutputFormat("Usage: show part name [--regex] <name>"); |
451 | //m_console.OutputFormat("Usage: show part name [--full] [--regex] <name>"); | ||
449 | return; | 452 | return; |
450 | } | 453 | } |
451 | 454 | ||
@@ -577,6 +580,58 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands | |||
577 | cdl.AddRow("Link number", sop.LinkNum); | 580 | cdl.AddRow("Link number", sop.LinkNum); |
578 | cdl.AddRow("Flags", sop.Flags); | 581 | cdl.AddRow("Flags", sop.Flags); |
579 | 582 | ||
583 | if (showFull) | ||
584 | { | ||
585 | PrimitiveBaseShape s = sop.Shape; | ||
586 | cdl.AddRow("FlexiDrag", s.FlexiDrag); | ||
587 | cdl.AddRow("FlexiEntry", s.FlexiEntry); | ||
588 | cdl.AddRow("FlexiForce", string.Format("<{0},{1},{2}>", s.FlexiForceX, s.FlexiForceY, s.FlexiForceZ)); | ||
589 | cdl.AddRow("FlexiGravity", s.FlexiGravity); | ||
590 | cdl.AddRow("FlexiSoftness", s.FlexiSoftness); | ||
591 | cdl.AddRow("HollowShape", s.HollowShape); | ||
592 | cdl.AddRow( | ||
593 | "LightColor", | ||
594 | string.Format("<{0},{1},{2},{3}>", s.LightColorR, s.LightColorB, s.LightColorG, s.LightColorA)); | ||
595 | cdl.AddRow("FlexiDrag", s.LightCutoff); | ||
596 | cdl.AddRow("FlexiDrag", s.LightEntry); | ||
597 | cdl.AddRow("FlexiDrag", s.LightFalloff); | ||
598 | cdl.AddRow("FlexiDrag", s.LightIntensity); | ||
599 | cdl.AddRow("FlexiDrag", s.LightRadius); | ||
600 | cdl.AddRow("Media", string.Format("{0} entries", s.Media != null ? s.Media.Count.ToString() : "n/a")); | ||
601 | cdl.AddRow("PathBegin", s.PathBegin); | ||
602 | cdl.AddRow("PathEnd", s.PathEnd); | ||
603 | cdl.AddRow("PathCurve", s.PathCurve); | ||
604 | cdl.AddRow("PathRadiusOffset", s.PathRadiusOffset); | ||
605 | cdl.AddRow("PathRevolutions", s.PathRevolutions); | ||
606 | cdl.AddRow("PathScale", string.Format("<{0},{1}>", s.PathScaleX, s.PathScaleY)); | ||
607 | cdl.AddRow("PathSkew", string.Format("<{0},{1}>", s.PathShearX, s.PathShearY)); | ||
608 | cdl.AddRow("FlexiDrag", s.PathSkew); | ||
609 | cdl.AddRow("PathTaper", string.Format("<{0},{1}>", s.PathTaperX, s.PathTaperY)); | ||
610 | cdl.AddRow("PathTwist", s.PathTwist); | ||
611 | cdl.AddRow("PathTwistBegin", s.PathTwistBegin); | ||
612 | cdl.AddRow("PCode", s.PCode); | ||
613 | cdl.AddRow("ProfileBegin", s.ProfileBegin); | ||
614 | cdl.AddRow("ProfileEnd", s.ProfileEnd); | ||
615 | cdl.AddRow("ProfileHollow", s.ProfileHollow); | ||
616 | cdl.AddRow("ProfileShape", s.ProfileShape); | ||
617 | cdl.AddRow("ProjectionAmbiance", s.ProjectionAmbiance); | ||
618 | cdl.AddRow("ProjectionEntry", s.ProjectionEntry); | ||
619 | cdl.AddRow("ProjectionFocus", s.ProjectionFocus); | ||
620 | cdl.AddRow("ProjectionFOV", s.ProjectionFOV); | ||
621 | cdl.AddRow("ProjectionTextureUUID", s.ProjectionTextureUUID); | ||
622 | cdl.AddRow("Scale", s.Scale); | ||
623 | cdl.AddRow( | ||
624 | "SculptData", | ||
625 | string.Format("{0} bytes", s.SculptData != null ? s.SculptData.Length.ToString() : "n/a")); | ||
626 | cdl.AddRow("SculptEntry", s.SculptEntry); | ||
627 | cdl.AddRow("SculptTexture", s.SculptTexture); | ||
628 | cdl.AddRow("SculptType", s.SculptType); | ||
629 | cdl.AddRow("State", s.State); | ||
630 | |||
631 | // TODO, unpack and display texture entries | ||
632 | //cdl.AddRow("Textures", string.Format("{0} entries", s.Textures. | ||
633 | } | ||
634 | |||
580 | object itemsOutput; | 635 | object itemsOutput; |
581 | if (showFull) | 636 | if (showFull) |
582 | { | 637 | { |
@@ -588,7 +643,6 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands | |||
588 | itemsOutput = sop.Inventory.Count; | 643 | itemsOutput = sop.Inventory.Count; |
589 | } | 644 | } |
590 | 645 | ||
591 | |||
592 | cdl.AddRow("Items", itemsOutput); | 646 | cdl.AddRow("Items", itemsOutput); |
593 | 647 | ||
594 | return sb.Append(cdl.ToString()); | 648 | return sb.Append(cdl.ToString()); |
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs index 7825e3e..bcb8e2f 100644 --- a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs +++ b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs | |||
@@ -39,7 +39,7 @@ using OpenSim.Tests.Common; | |||
39 | namespace OpenSim.Region.CoreModules.World.Serialiser.Tests | 39 | namespace OpenSim.Region.CoreModules.World.Serialiser.Tests |
40 | { | 40 | { |
41 | [TestFixture] | 41 | [TestFixture] |
42 | public class SerialiserTests | 42 | public class SerialiserTests : OpenSimTestCase |
43 | { | 43 | { |
44 | private string xml = @" | 44 | private string xml = @" |
45 | <SceneObjectGroup> | 45 | <SceneObjectGroup> |
diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs index 513a8f5..883045a 100644 --- a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs +++ b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs | |||
@@ -43,8 +43,8 @@ namespace OpenSim.Region.CoreModules.World.Sound | |||
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SoundModule")] | 43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SoundModule")] |
44 | public class SoundModule : INonSharedRegionModule, ISoundModule | 44 | public class SoundModule : INonSharedRegionModule, ISoundModule |
45 | { | 45 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger( | 46 | // private static readonly ILog m_log = LogManager.GetLogger( |
47 | MethodBase.GetCurrentMethod().DeclaringType); | 47 | // MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | private Scene m_scene; | 49 | private Scene m_scene; |
50 | 50 | ||
@@ -76,7 +76,7 @@ namespace OpenSim.Region.CoreModules.World.Sound | |||
76 | 76 | ||
77 | public void RemoveRegion(Scene scene) | 77 | public void RemoveRegion(Scene scene) |
78 | { | 78 | { |
79 | m_scene.EventManager.OnClientLogin -= OnNewClient; | 79 | m_scene.EventManager.OnNewClient -= OnNewClient; |
80 | } | 80 | } |
81 | 81 | ||
82 | public void RegionLoaded(Scene scene) | 82 | public void RegionLoaded(Scene scene) |
@@ -85,7 +85,7 @@ namespace OpenSim.Region.CoreModules.World.Sound | |||
85 | return; | 85 | return; |
86 | 86 | ||
87 | m_scene = scene; | 87 | m_scene = scene; |
88 | m_scene.EventManager.OnClientLogin += OnNewClient; | 88 | m_scene.EventManager.OnNewClient += OnNewClient; |
89 | 89 | ||
90 | m_scene.RegisterModuleInterface<ISoundModule>(this); | 90 | m_scene.RegisterModuleInterface<ISoundModule>(this); |
91 | } | 91 | } |
diff --git a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs index a321c09..6f344c8 100644 --- a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs +++ b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs | |||
@@ -252,12 +252,11 @@ namespace OpenSim.Region.CoreModules | |||
252 | } | 252 | } |
253 | 253 | ||
254 | // TODO: Decouple this, so we can get rid of Linden Hour info | 254 | // TODO: Decouple this, so we can get rid of Linden Hour info |
255 | // Update Region infor with new Sun Position and Hour | 255 | // Update Region with new Sun Vector |
256 | // set estate settings for region access to sun position | 256 | // set estate settings for region access to sun position |
257 | if (receivedEstateToolsSunUpdate) | 257 | if (receivedEstateToolsSunUpdate) |
258 | { | 258 | { |
259 | m_scene.RegionInfo.RegionSettings.SunVector = Position; | 259 | m_scene.RegionInfo.RegionSettings.SunVector = Position; |
260 | m_scene.RegionInfo.RegionSettings.SunPosition = GetCurrentTimeAsLindenSunHour(); | ||
261 | } | 260 | } |
262 | } | 261 | } |
263 | 262 | ||
@@ -395,7 +394,7 @@ namespace OpenSim.Region.CoreModules | |||
395 | ready = false; | 394 | ready = false; |
396 | 395 | ||
397 | // Remove our hooks | 396 | // Remove our hooks |
398 | m_scene.EventManager.OnFrame -= SunUpdate; | 397 | m_scene.EventManager.OnFrame -= SunUpdate; |
399 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; | 398 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; |
400 | m_scene.EventManager.OnEstateToolsSunUpdate -= EstateToolsSunUpdate; | 399 | m_scene.EventManager.OnEstateToolsSunUpdate -= EstateToolsSunUpdate; |
401 | m_scene.EventManager.OnGetCurrentTimeAsLindenSunHour -= GetCurrentTimeAsLindenSunHour; | 400 | m_scene.EventManager.OnGetCurrentTimeAsLindenSunHour -= GetCurrentTimeAsLindenSunHour; |
@@ -459,26 +458,33 @@ namespace OpenSim.Region.CoreModules | |||
459 | SunToClient(avatar.ControllingClient); | 458 | SunToClient(avatar.ControllingClient); |
460 | } | 459 | } |
461 | 460 | ||
462 | /// <summary> | 461 | public void EstateToolsSunUpdate(ulong regionHandle) |
463 | /// | ||
464 | /// </summary> | ||
465 | /// <param name="regionHandle"></param> | ||
466 | /// <param name="FixedTime">Is the sun's position fixed?</param> | ||
467 | /// <param name="useEstateTime">Use the Region or Estate Sun hour?</param> | ||
468 | /// <param name="FixedSunHour">What hour of the day is the Sun Fixed at?</param> | ||
469 | public void EstateToolsSunUpdate(ulong regionHandle, bool FixedSun, bool useEstateTime, float FixedSunHour) | ||
470 | { | 462 | { |
471 | if (m_scene.RegionInfo.RegionHandle == regionHandle) | 463 | if (m_scene.RegionInfo.RegionHandle == regionHandle) |
472 | { | 464 | { |
473 | // Must limit the Sun Hour to 0 ... 24 | 465 | float sunFixedHour; |
474 | while (FixedSunHour > 24.0f) | 466 | bool fixedSun; |
475 | FixedSunHour -= 24; | ||
476 | 467 | ||
477 | while (FixedSunHour < 0) | 468 | if (m_scene.RegionInfo.RegionSettings.UseEstateSun) |
478 | FixedSunHour += 24; | 469 | { |
470 | sunFixedHour = (float)m_scene.RegionInfo.EstateSettings.SunPosition; | ||
471 | fixedSun = m_scene.RegionInfo.EstateSettings.FixedSun; | ||
472 | } | ||
473 | else | ||
474 | { | ||
475 | sunFixedHour = (float)m_scene.RegionInfo.RegionSettings.SunPosition - 6.0f; | ||
476 | fixedSun = m_scene.RegionInfo.RegionSettings.FixedSun; | ||
477 | } | ||
478 | |||
479 | // Must limit the Sun Hour to 0 ... 24 | ||
480 | while (sunFixedHour > 24.0f) | ||
481 | sunFixedHour -= 24; | ||
479 | 482 | ||
480 | m_SunFixedHour = FixedSunHour; | 483 | while (sunFixedHour < 0) |
481 | m_SunFixed = FixedSun; | 484 | sunFixedHour += 24; |
485 | |||
486 | m_SunFixedHour = sunFixedHour; | ||
487 | m_SunFixed = fixedSun; | ||
482 | 488 | ||
483 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Fixed Sun? : {0}", m_SunFixed.ToString()); | 489 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Fixed Sun? : {0}", m_SunFixed.ToString()); |
484 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Sun Hour : {0}", m_SunFixedHour.ToString()); | 490 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Sun Hour : {0}", m_SunFixedHour.ToString()); |
@@ -501,7 +507,7 @@ namespace OpenSim.Region.CoreModules | |||
501 | { | 507 | { |
502 | m_scene.ForEachRootClient(delegate(IClientAPI client) | 508 | m_scene.ForEachRootClient(delegate(IClientAPI client) |
503 | { | 509 | { |
504 | SunToClient(client); | 510 | SunToClient(client); |
505 | }); | 511 | }); |
506 | } | 512 | } |
507 | 513 | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index 33aabe4..4d738a5 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -480,7 +480,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
480 | else | 480 | else |
481 | { | 481 | { |
482 | m_plugineffects[pluginName] = effect; | 482 | m_plugineffects[pluginName] = effect; |
483 | m_log.Warn("E ... " + pluginName + " (Replaced)"); | 483 | m_log.Info("E ... " + pluginName + " (Replaced)"); |
484 | } | 484 | } |
485 | } | 485 | } |
486 | } | 486 | } |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs index 3d4f762..be719ea 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs | |||
@@ -30,11 +30,12 @@ using NUnit.Framework; | |||
30 | using OpenSim.Framework; | 30 | using OpenSim.Framework; |
31 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; | 31 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; |
32 | using OpenSim.Region.Framework.Scenes; | 32 | using OpenSim.Region.Framework.Scenes; |
33 | using OpenSim.Tests.Common; | ||
33 | 34 | ||
34 | namespace OpenSim.Region.CoreModules.World.Terrain.Tests | 35 | namespace OpenSim.Region.CoreModules.World.Terrain.Tests |
35 | { | 36 | { |
36 | [TestFixture] | 37 | [TestFixture] |
37 | public class TerrainTest | 38 | public class TerrainTest : OpenSimTestCase |
38 | { | 39 | { |
39 | [Test] | 40 | [Test] |
40 | public void BrushTest() | 41 | public void BrushTest() |
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index fd8e2b4..9de588c 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs | |||
@@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules | |||
66 | public void Initialise(IConfigSource config) | 66 | public void Initialise(IConfigSource config) |
67 | { | 67 | { |
68 | m_windConfig = config.Configs["Wind"]; | 68 | m_windConfig = config.Configs["Wind"]; |
69 | string desiredWindPlugin = m_dWindPluginName; | 69 | // string desiredWindPlugin = m_dWindPluginName; |
70 | 70 | ||
71 | if (m_windConfig != null) | 71 | if (m_windConfig != null) |
72 | { | 72 | { |
diff --git a/OpenSim/Region/Framework/Interfaces/ISceneCommandsModule.cs b/OpenSim/Region/Framework/Interfaces/ISceneCommandsModule.cs new file mode 100644 index 0000000..c5e678b --- /dev/null +++ b/OpenSim/Region/Framework/Interfaces/ISceneCommandsModule.cs | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | |||
34 | namespace OpenSim.Region.Framework.Interfaces | ||
35 | { | ||
36 | public interface ISceneCommandsModule | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Sets the scene debug options. | ||
40 | /// </summary> | ||
41 | void SetSceneDebugOptions(Dictionary<string, string> options); | ||
42 | } | ||
43 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Interfaces/IXmlRpcRouter.cs b/OpenSim/Region/Framework/Interfaces/IXmlRpcRouter.cs index 6db6674..093d3f0 100644 --- a/OpenSim/Region/Framework/Interfaces/IXmlRpcRouter.cs +++ b/OpenSim/Region/Framework/Interfaces/IXmlRpcRouter.cs | |||
@@ -34,5 +34,6 @@ namespace OpenSim.Region.Framework.Interfaces | |||
34 | void RegisterNewReceiver(IScriptModule scriptEngine, UUID channelID, UUID objectID, UUID itemID, string url); | 34 | void RegisterNewReceiver(IScriptModule scriptEngine, UUID channelID, UUID objectID, UUID itemID, string url); |
35 | void ScriptRemoved(UUID itemID); | 35 | void ScriptRemoved(UUID itemID); |
36 | void ObjectRemoved(UUID objectID); | 36 | void ObjectRemoved(UUID objectID); |
37 | void UnRegisterReceiver(string channelID, UUID itemID); | ||
37 | } | 38 | } |
38 | } | 39 | } |
diff --git a/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs index 65ae445..66edfed 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs | |||
@@ -87,13 +87,24 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
87 | return false; | 87 | return false; |
88 | } | 88 | } |
89 | 89 | ||
90 | public bool Remove(UUID animID) | 90 | /// <summary> |
91 | /// Remove the specified animation | ||
92 | /// </summary> | ||
93 | /// <param name='animID'></param> | ||
94 | /// <param name='allowNoDefault'> | ||
95 | /// If true, then the default animation can be entirely removed. | ||
96 | /// If false, then removing the default animation will reset it to the simulator default (currently STAND). | ||
97 | /// </param> | ||
98 | public bool Remove(UUID animID, bool allowNoDefault) | ||
91 | { | 99 | { |
92 | lock (m_animations) | 100 | lock (m_animations) |
93 | { | 101 | { |
94 | if (m_defaultAnimation.AnimID == animID) | 102 | if (m_defaultAnimation.AnimID == animID) |
95 | { | 103 | { |
96 | m_defaultAnimation = new OpenSim.Framework.Animation(UUID.Zero, 1, UUID.Zero); | 104 | if (allowNoDefault) |
105 | m_defaultAnimation = new OpenSim.Framework.Animation(UUID.Zero, 1, UUID.Zero); | ||
106 | else | ||
107 | ResetDefaultAnimation(); | ||
97 | } | 108 | } |
98 | else if (HasAnimation(animID)) | 109 | else if (HasAnimation(animID)) |
99 | { | 110 | { |
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs index 9458079..65c279e 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |||
@@ -26,9 +26,10 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Threading; | ||
30 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | ||
32 | using log4net; | 33 | using log4net; |
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
@@ -86,6 +87,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
86 | return; | 87 | return; |
87 | 88 | ||
88 | // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Adding animation {0} for {1}", animID, m_scenePresence.Name); | 89 | // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Adding animation {0} for {1}", animID, m_scenePresence.Name); |
90 | if (m_scenePresence.Scene.DebugAnimations) | ||
91 | m_log.DebugFormat( | ||
92 | "[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}", | ||
93 | GetAnimName(animID), animID, m_scenePresence.Name); | ||
89 | 94 | ||
90 | if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID)) | 95 | if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID)) |
91 | SendAnimPack(); | 96 | SendAnimPack(); |
@@ -108,12 +113,25 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
108 | AddAnimation(animID, objectID); | 113 | AddAnimation(animID, objectID); |
109 | } | 114 | } |
110 | 115 | ||
111 | public void RemoveAnimation(UUID animID) | 116 | /// <summary> |
117 | /// Remove the specified animation | ||
118 | /// </summary> | ||
119 | /// <param name='animID'></param> | ||
120 | /// <param name='allowNoDefault'> | ||
121 | /// If true, then the default animation can be entirely removed. | ||
122 | /// If false, then removing the default animation will reset it to the simulator default (currently STAND). | ||
123 | /// </param> | ||
124 | public void RemoveAnimation(UUID animID, bool allowNoDefault) | ||
112 | { | 125 | { |
113 | if (m_scenePresence.IsChildAgent) | 126 | if (m_scenePresence.IsChildAgent) |
114 | return; | 127 | return; |
115 | 128 | ||
116 | if (m_animations.Remove(animID)) | 129 | if (m_scenePresence.Scene.DebugAnimations) |
130 | m_log.DebugFormat( | ||
131 | "[SCENE PRESENCE ANIMATOR]: Removing animation {0} {1} for {2}", | ||
132 | GetAnimName(animID), animID, m_scenePresence.Name); | ||
133 | |||
134 | if (m_animations.Remove(animID, allowNoDefault)) | ||
117 | SendAnimPack(); | 135 | SendAnimPack(); |
118 | } | 136 | } |
119 | 137 | ||
@@ -127,7 +145,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
127 | if (addRemove) | 145 | if (addRemove) |
128 | m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero); | 146 | m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero); |
129 | else | 147 | else |
130 | m_animations.Remove(animID); | 148 | m_animations.Remove(animID, true); |
131 | } | 149 | } |
132 | if(sendPack) | 150 | if(sendPack) |
133 | SendAnimPack(); | 151 | SendAnimPack(); |
@@ -145,14 +163,15 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
145 | if (animID == UUID.Zero) | 163 | if (animID == UUID.Zero) |
146 | return; | 164 | return; |
147 | 165 | ||
148 | RemoveAnimation(animID); | 166 | RemoveAnimation(animID, true); |
149 | } | 167 | } |
150 | 168 | ||
151 | public void ResetAnimations() | 169 | public void ResetAnimations() |
152 | { | 170 | { |
153 | // m_log.DebugFormat( | 171 | if (m_scenePresence.Scene.DebugAnimations) |
154 | // "[SCENE PRESENCE ANIMATOR]: Resetting animations for {0} in {1}", | 172 | m_log.DebugFormat( |
155 | // m_scenePresence.Name, m_scenePresence.Scene.RegionInfo.RegionName); | 173 | "[SCENE PRESENCE ANIMATOR]: Resetting animations for {0} in {1}", |
174 | m_scenePresence.Name, m_scenePresence.Scene.RegionInfo.RegionName); | ||
156 | 175 | ||
157 | m_animations.Clear(); | 176 | m_animations.Clear(); |
158 | } | 177 | } |
@@ -519,6 +538,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
519 | if (m_scenePresence.IsChildAgent) | 538 | if (m_scenePresence.IsChildAgent) |
520 | return; | 539 | return; |
521 | 540 | ||
541 | // m_log.DebugFormat( | ||
542 | // "[SCENE PRESENCE ANIMATOR]: Sending anim pack with animations '{0}', sequence '{1}', uuids '{2}'", | ||
543 | // string.Join(",", Array.ConvertAll<UUID, string>(animations, a => a.ToString())), | ||
544 | // string.Join(",", Array.ConvertAll<int, string>(seqs, s => s.ToString())), | ||
545 | // string.Join(",", Array.ConvertAll<UUID, string>(objectIDs, o => o.ToString()))); | ||
546 | |||
522 | m_scenePresence.Scene.ForEachClient( | 547 | m_scenePresence.Scene.ForEachClient( |
523 | delegate(IClientAPI client) | 548 | delegate(IClientAPI client) |
524 | { | 549 | { |
@@ -557,5 +582,21 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
557 | 582 | ||
558 | SendAnimPack(animIDs, sequenceNums, objectIDs); | 583 | SendAnimPack(animIDs, sequenceNums, objectIDs); |
559 | } | 584 | } |
585 | |||
586 | public string GetAnimName(UUID animId) | ||
587 | { | ||
588 | string animName; | ||
589 | |||
590 | if (!DefaultAvatarAnimations.AnimsNames.TryGetValue(animId, out animName)) | ||
591 | { | ||
592 | AssetMetadata amd = m_scenePresence.Scene.AssetService.GetMetadata(animId.ToString()); | ||
593 | if (amd != null) | ||
594 | animName = amd.Name; | ||
595 | else | ||
596 | animName = "Unknown"; | ||
597 | } | ||
598 | |||
599 | return animName; | ||
600 | } | ||
560 | } | 601 | } |
561 | } | 602 | } |
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; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using log4net; | 32 | using log4net; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | ||
34 | 35 | ||
35 | namespace OpenSim.Region.Framework.Scenes | 36 | namespace OpenSim.Region.Framework.Scenes |
36 | { | 37 | { |
@@ -38,7 +39,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
38 | { | 39 | { |
39 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 40 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
40 | 41 | ||
41 | private readonly DoubleDictionary<UUID, uint, EntityBase> m_entities = new DoubleDictionary<UUID, uint, EntityBase>(); | 42 | private readonly DoubleDictionaryThreadAbortSafe<UUID, uint, EntityBase> m_entities |
43 | = new DoubleDictionaryThreadAbortSafe<UUID, uint, EntityBase>(); | ||
42 | 44 | ||
43 | public int Count | 45 | public int Count |
44 | { | 46 | { |
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 5b1c9f4..ac5f433 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs | |||
@@ -755,7 +755,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
755 | public event ScriptTimerEvent OnScriptTimerEvent; | 755 | public event ScriptTimerEvent OnScriptTimerEvent; |
756 | */ | 756 | */ |
757 | 757 | ||
758 | public delegate void EstateToolsSunUpdate(ulong regionHandle, bool FixedTime, bool EstateSun, float LindenHour); | 758 | public delegate void EstateToolsSunUpdate(ulong regionHandle); |
759 | public delegate void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID); | 759 | public delegate void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID); |
760 | 760 | ||
761 | public event EstateToolsSunUpdate OnEstateToolsSunUpdate; | 761 | public event EstateToolsSunUpdate OnEstateToolsSunUpdate; |
@@ -2536,13 +2536,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
2536 | } | 2536 | } |
2537 | 2537 | ||
2538 | /// <summary> | 2538 | /// <summary> |
2539 | /// Updates the system as to how the position of the sun should be handled. | 2539 | /// Called when the sun's position parameters have changed in the Region and/or Estate |
2540 | /// </summary> | 2540 | /// </summary> |
2541 | /// <param name="regionHandle"></param> | 2541 | /// <param name="regionHandle">The region that changed</param> |
2542 | /// <param name="FixedTime">True if the Sun Position is fixed</param> | 2542 | public void TriggerEstateToolsSunUpdate(ulong regionHandle) |
2543 | /// <param name="useEstateTime">True if the Estate Settings should be used instead of region</param> | ||
2544 | /// <param name="FixedSunHour">The hour 0.0 <= FixedSunHour <= 24.0 at which the sun is fixed at. Sun Hour 0 is sun-rise, when Day/Night ratio is 1:1</param> | ||
2545 | public void TriggerEstateToolsSunUpdate(ulong regionHandle, bool FixedTime, bool useEstateTime, float FixedSunHour) | ||
2546 | { | 2543 | { |
2547 | EstateToolsSunUpdate handlerEstateToolsSunUpdate = OnEstateToolsSunUpdate; | 2544 | EstateToolsSunUpdate handlerEstateToolsSunUpdate = OnEstateToolsSunUpdate; |
2548 | if (handlerEstateToolsSunUpdate != null) | 2545 | if (handlerEstateToolsSunUpdate != null) |
@@ -2551,7 +2548,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2551 | { | 2548 | { |
2552 | try | 2549 | try |
2553 | { | 2550 | { |
2554 | d(regionHandle, FixedTime, useEstateTime, FixedSunHour); | 2551 | d(regionHandle); |
2555 | } | 2552 | } |
2556 | catch (Exception e) | 2553 | catch (Exception e) |
2557 | { | 2554 | { |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index c9d1205..9f0a0e2 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -683,12 +683,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
683 | itemCopy.SalePrice = item.SalePrice; | 683 | itemCopy.SalePrice = item.SalePrice; |
684 | itemCopy.SaleType = item.SaleType; | 684 | itemCopy.SaleType = item.SaleType; |
685 | 685 | ||
686 | if (AddInventoryItem(itemCopy)) | 686 | IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>(); |
687 | { | 687 | if (invAccess != null) |
688 | IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>(); | 688 | invAccess.TransferInventoryAssets(itemCopy, senderId, recipient); |
689 | if (invAccess != null) | 689 | AddInventoryItem(itemCopy); |
690 | Util.FireAndForget(delegate { invAccess.TransferInventoryAssets(itemCopy, senderId, recipient); }); | ||
691 | } | ||
692 | 690 | ||
693 | if (!Permissions.BypassPermissions()) | 691 | if (!Permissions.BypassPermissions()) |
694 | { | 692 | { |
@@ -1785,6 +1783,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1785 | /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> | 1783 | /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> |
1786 | public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase) | 1784 | public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase) |
1787 | { | 1785 | { |
1786 | return RezNewScript( | ||
1787 | agentID, | ||
1788 | itemBase, | ||
1789 | "default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"); | ||
1790 | } | ||
1791 | |||
1792 | /// <summary> | ||
1793 | /// Rez a new script from nothing with given script text. | ||
1794 | /// </summary> | ||
1795 | /// <param name="remoteClient"></param> | ||
1796 | /// <param name="itemBase">Template item.</param> | ||
1797 | /// <param name="scriptText"></param> | ||
1798 | /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> | ||
1799 | public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase, string scriptText) | ||
1800 | { | ||
1788 | // The part ID is the folder ID! | 1801 | // The part ID is the folder ID! |
1789 | SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); | 1802 | SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); |
1790 | if (part == null) | 1803 | if (part == null) |
@@ -1804,9 +1817,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
1804 | return null; | 1817 | return null; |
1805 | } | 1818 | } |
1806 | 1819 | ||
1807 | AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, | 1820 | AssetBase asset |
1808 | Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n\n touch_start(integer num)\n {\n }\n}"), | 1821 | = CreateAsset( |
1809 | agentID); | 1822 | itemBase.Name, |
1823 | itemBase.Description, | ||
1824 | (sbyte)itemBase.AssetType, | ||
1825 | Encoding.ASCII.GetBytes(scriptText), | ||
1826 | agentID); | ||
1827 | |||
1810 | AssetService.Store(asset); | 1828 | AssetService.Store(asset); |
1811 | 1829 | ||
1812 | TaskInventoryItem taskItem = new TaskInventoryItem(); | 1830 | TaskInventoryItem taskItem = new TaskInventoryItem(); |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 9d07537..f229e33 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -68,14 +68,84 @@ namespace OpenSim.Region.Framework.Scenes | |||
68 | public bool EmergencyMonitoring = false; | 68 | public bool EmergencyMonitoring = false; |
69 | 69 | ||
70 | /// <summary> | 70 | /// <summary> |
71 | /// Show debug information about animations. | ||
72 | /// </summary> | ||
73 | public bool DebugAnimations { get; set; } | ||
74 | |||
75 | /// <summary> | ||
71 | /// Show debug information about teleports. | 76 | /// Show debug information about teleports. |
72 | /// </summary> | 77 | /// </summary> |
73 | public bool DebugTeleporting { get; private set; } | 78 | public bool DebugTeleporting { get; set; } |
74 | 79 | ||
75 | /// <summary> | 80 | /// <summary> |
76 | /// Show debug information about the scene loop. | 81 | /// Show debug information about the scene loop. |
77 | /// </summary> | 82 | /// </summary> |
78 | public bool DebugUpdates { get; private set; } | 83 | public bool DebugUpdates { get; set; } |
84 | |||
85 | /// <summary> | ||
86 | /// If true then the scene is saved to persistent storage periodically, every m_update_backup frames and | ||
87 | /// if objects meet required conditions (m_dontPersistBefore and m_dontPersistAfter). | ||
88 | /// </summary> | ||
89 | /// <remarks> | ||
90 | /// Even if false, the scene will still be saved on clean shutdown. | ||
91 | /// FIXME: Currently, setting this to false will mean that objects are not periodically returned from parcels. | ||
92 | /// This needs to be fixed. | ||
93 | /// </remarks> | ||
94 | public bool PeriodicBackup { get; set; } | ||
95 | |||
96 | /// <summary> | ||
97 | /// If false then the scene is never saved to persistence storage even if PeriodicBackup == true and even | ||
98 | /// if the scene is being shut down for the final time. | ||
99 | /// </summary> | ||
100 | public bool UseBackup { get; set; } | ||
101 | |||
102 | /// <summary> | ||
103 | /// If false then physical objects are disabled, though collisions will continue as normal. | ||
104 | /// </summary> | ||
105 | public bool PhysicsEnabled { get; set; } | ||
106 | |||
107 | /// <summary> | ||
108 | /// If false then scripts are not enabled on the smiulator | ||
109 | /// </summary> | ||
110 | public bool ScriptsEnabled | ||
111 | { | ||
112 | get { return m_scripts_enabled; } | ||
113 | set | ||
114 | { | ||
115 | if (m_scripts_enabled != value) | ||
116 | { | ||
117 | if (!value) | ||
118 | { | ||
119 | m_log.Info("Stopping all Scripts in Scene"); | ||
120 | |||
121 | EntityBase[] entities = Entities.GetEntities(); | ||
122 | foreach (EntityBase ent in entities) | ||
123 | { | ||
124 | if (ent is SceneObjectGroup) | ||
125 | ((SceneObjectGroup)ent).RemoveScriptInstances(false); | ||
126 | } | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | m_log.Info("Starting all Scripts in Scene"); | ||
131 | |||
132 | EntityBase[] entities = Entities.GetEntities(); | ||
133 | foreach (EntityBase ent in entities) | ||
134 | { | ||
135 | if (ent is SceneObjectGroup) | ||
136 | { | ||
137 | SceneObjectGroup sog = (SceneObjectGroup)ent; | ||
138 | sog.CreateScriptInstances(0, false, DefaultScriptEngine, 0); | ||
139 | sog.ResumeScripts(); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | m_scripts_enabled = value; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | private bool m_scripts_enabled; | ||
79 | 149 | ||
80 | public SynchronizeSceneHandler SynchronizeScene; | 150 | public SynchronizeSceneHandler SynchronizeScene; |
81 | 151 | ||
@@ -284,8 +354,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
284 | private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); | 354 | private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); |
285 | private Dictionary<UUID, int> m_groupsWithTargets = new Dictionary<UUID, int>(); | 355 | private Dictionary<UUID, int> m_groupsWithTargets = new Dictionary<UUID, int>(); |
286 | 356 | ||
287 | private bool m_physics_enabled = true; | ||
288 | private bool m_scripts_enabled = true; | ||
289 | private string m_defaultScriptEngine; | 357 | private string m_defaultScriptEngine; |
290 | 358 | ||
291 | /// <summary> | 359 | /// <summary> |
@@ -348,7 +416,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
348 | 416 | ||
349 | private Timer m_mapGenerationTimer = new Timer(); | 417 | private Timer m_mapGenerationTimer = new Timer(); |
350 | private bool m_generateMaptiles; | 418 | private bool m_generateMaptiles; |
351 | private bool m_useBackup = true; | ||
352 | 419 | ||
353 | #endregion Fields | 420 | #endregion Fields |
354 | 421 | ||
@@ -614,11 +681,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
614 | get { return m_authenticateHandler; } | 681 | get { return m_authenticateHandler; } |
615 | } | 682 | } |
616 | 683 | ||
617 | public bool UseBackup | ||
618 | { | ||
619 | get { return m_useBackup; } | ||
620 | } | ||
621 | |||
622 | // an instance to the physics plugin's Scene object. | 684 | // an instance to the physics plugin's Scene object. |
623 | public PhysicsScene PhysicsScene | 685 | public PhysicsScene PhysicsScene |
624 | { | 686 | { |
@@ -762,15 +824,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
762 | // | 824 | // |
763 | // Out of memory | 825 | // Out of memory |
764 | // Operating system has killed the plugin | 826 | // Operating system has killed the plugin |
765 | m_sceneGraph.UnRecoverableError += RestartNow; | 827 | m_sceneGraph.UnRecoverableError |
828 | += () => | ||
829 | { | ||
830 | m_log.ErrorFormat("[SCENE]: Restarting region {0} due to unrecoverable physics crash", Name); | ||
831 | RestartNow(); | ||
832 | }; | ||
766 | 833 | ||
767 | RegisterDefaultSceneEvents(); | 834 | RegisterDefaultSceneEvents(); |
768 | 835 | ||
769 | DumpAssetsToFile = dumpAssetsToFile; | 836 | DumpAssetsToFile = dumpAssetsToFile; |
770 | 837 | ||
838 | // XXX: Don't set the public property since we don't want to activate here. This needs to be handled | ||
839 | // better in the future. | ||
771 | m_scripts_enabled = !RegionInfo.RegionSettings.DisableScripts; | 840 | m_scripts_enabled = !RegionInfo.RegionSettings.DisableScripts; |
772 | 841 | ||
773 | m_physics_enabled = !RegionInfo.RegionSettings.DisablePhysics; | 842 | PhysicsEnabled = !RegionInfo.RegionSettings.DisablePhysics; |
774 | 843 | ||
775 | m_simulatorVersion = simulatorVersion + " (" + Util.GetRuntimeInformation() + ")"; | 844 | m_simulatorVersion = simulatorVersion + " (" + Util.GetRuntimeInformation() + ")"; |
776 | 845 | ||
@@ -787,8 +856,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
787 | StartDisabled = startupConfig.GetBoolean("StartDisabled", false); | 856 | StartDisabled = startupConfig.GetBoolean("StartDisabled", false); |
788 | 857 | ||
789 | m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance); | 858 | m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance); |
790 | m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup); | 859 | UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup); |
791 | if (!m_useBackup) | 860 | if (!UseBackup) |
792 | m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); | 861 | m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); |
793 | 862 | ||
794 | //Animation states | 863 | //Animation states |
@@ -965,6 +1034,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
965 | { | 1034 | { |
966 | PhysicalPrims = true; | 1035 | PhysicalPrims = true; |
967 | CollidablePrims = true; | 1036 | CollidablePrims = true; |
1037 | PhysicsEnabled = true; | ||
1038 | |||
1039 | PeriodicBackup = true; | ||
1040 | UseBackup = true; | ||
968 | 1041 | ||
969 | BordersLocked = true; | 1042 | BordersLocked = true; |
970 | Border northBorder = new Border(); | 1043 | Border northBorder = new Border(); |
@@ -1207,83 +1280,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
1207 | } | 1280 | } |
1208 | } | 1281 | } |
1209 | 1282 | ||
1210 | public void SetSceneCoreDebug(Dictionary<string, string> options) | ||
1211 | { | ||
1212 | if (options.ContainsKey("active")) | ||
1213 | { | ||
1214 | bool active; | ||
1215 | |||
1216 | if (bool.TryParse(options["active"], out active)) | ||
1217 | Active = active; | ||
1218 | } | ||
1219 | |||
1220 | if (options.ContainsKey("scripting")) | ||
1221 | { | ||
1222 | bool enableScripts = true; | ||
1223 | if (bool.TryParse(options["scripting"], out enableScripts) && m_scripts_enabled != enableScripts) | ||
1224 | { | ||
1225 | if (!enableScripts) | ||
1226 | { | ||
1227 | m_log.Info("Stopping all Scripts in Scene"); | ||
1228 | |||
1229 | EntityBase[] entities = Entities.GetEntities(); | ||
1230 | foreach (EntityBase ent in entities) | ||
1231 | { | ||
1232 | if (ent is SceneObjectGroup) | ||
1233 | ((SceneObjectGroup)ent).RemoveScriptInstances(false); | ||
1234 | } | ||
1235 | } | ||
1236 | else | ||
1237 | { | ||
1238 | m_log.Info("Starting all Scripts in Scene"); | ||
1239 | |||
1240 | EntityBase[] entities = Entities.GetEntities(); | ||
1241 | foreach (EntityBase ent in entities) | ||
1242 | { | ||
1243 | if (ent is SceneObjectGroup) | ||
1244 | { | ||
1245 | SceneObjectGroup sog = (SceneObjectGroup)ent; | ||
1246 | sog.CreateScriptInstances(0, false, DefaultScriptEngine, 0); | ||
1247 | sog.ResumeScripts(); | ||
1248 | } | ||
1249 | } | ||
1250 | } | ||
1251 | |||
1252 | m_scripts_enabled = enableScripts; | ||
1253 | } | ||
1254 | } | ||
1255 | |||
1256 | if (options.ContainsKey("physics")) | ||
1257 | { | ||
1258 | bool enablePhysics; | ||
1259 | if (bool.TryParse(options["physics"], out enablePhysics)) | ||
1260 | m_physics_enabled = enablePhysics; | ||
1261 | } | ||
1262 | |||
1263 | // if (options.ContainsKey("collisions")) | ||
1264 | // { | ||
1265 | // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow | ||
1266 | // // the avatar themselves to collide with the ground. | ||
1267 | // } | ||
1268 | |||
1269 | if (options.ContainsKey("teleport")) | ||
1270 | { | ||
1271 | bool enableTeleportDebugging; | ||
1272 | if (bool.TryParse(options["teleport"], out enableTeleportDebugging)) | ||
1273 | DebugTeleporting = enableTeleportDebugging; | ||
1274 | } | ||
1275 | |||
1276 | if (options.ContainsKey("updates")) | ||
1277 | { | ||
1278 | bool enableUpdateDebugging; | ||
1279 | if (bool.TryParse(options["updates"], out enableUpdateDebugging)) | ||
1280 | { | ||
1281 | DebugUpdates = enableUpdateDebugging; | ||
1282 | GcNotify.Enabled = DebugUpdates; | ||
1283 | } | ||
1284 | } | ||
1285 | } | ||
1286 | |||
1287 | public int GetInaccurateNeighborCount() | 1283 | public int GetInaccurateNeighborCount() |
1288 | { | 1284 | { |
1289 | return m_neighbours.Count; | 1285 | return m_neighbours.Count; |
@@ -1332,16 +1328,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1332 | 1328 | ||
1333 | m_log.Debug("[SCENE]: Persisting changed objects"); | 1329 | m_log.Debug("[SCENE]: Persisting changed objects"); |
1334 | 1330 | ||
1335 | EntityBase[] entities = GetEntities(); | 1331 | Backup(false); |
1336 | foreach (EntityBase entity in entities) | ||
1337 | { | ||
1338 | if (!entity.IsDeleted && entity is SceneObjectGroup && ((SceneObjectGroup)entity).HasGroupChanged) | ||
1339 | { | ||
1340 | ((SceneObjectGroup)entity).ProcessBackup(SimulationDataService, false); | ||
1341 | } | ||
1342 | } | ||
1343 | |||
1344 | m_log.Debug("[SCENE]: Graph close"); | ||
1345 | m_sceneGraph.Close(); | 1332 | m_sceneGraph.Close(); |
1346 | 1333 | ||
1347 | if (!GridService.DeregisterRegion(RegionInfo.RegionID)) | 1334 | if (!GridService.DeregisterRegion(RegionInfo.RegionID)) |
@@ -1568,7 +1555,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1568 | } | 1555 | } |
1569 | 1556 | ||
1570 | tmpMS = Util.EnvironmentTickCount(); | 1557 | tmpMS = Util.EnvironmentTickCount(); |
1571 | if ((Frame % m_update_physics == 0) && m_physics_enabled) | 1558 | if (PhysicsEnabled && Frame % m_update_physics == 0) |
1572 | m_sceneGraph.UpdatePreparePhysics(); | 1559 | m_sceneGraph.UpdatePreparePhysics(); |
1573 | physicsMS2 = Util.EnvironmentTickCountSubtract(tmpMS); | 1560 | physicsMS2 = Util.EnvironmentTickCountSubtract(tmpMS); |
1574 | 1561 | ||
@@ -1583,7 +1570,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1583 | tmpMS = Util.EnvironmentTickCount(); | 1570 | tmpMS = Util.EnvironmentTickCount(); |
1584 | if (Frame % m_update_physics == 0) | 1571 | if (Frame % m_update_physics == 0) |
1585 | { | 1572 | { |
1586 | if (m_physics_enabled) | 1573 | if (PhysicsEnabled) |
1587 | physicsFPS = m_sceneGraph.UpdatePhysics(MinFrameTime); | 1574 | physicsFPS = m_sceneGraph.UpdatePhysics(MinFrameTime); |
1588 | 1575 | ||
1589 | if (SynchronizeScene != null) | 1576 | if (SynchronizeScene != null) |
@@ -1625,7 +1612,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1625 | eventMS = Util.EnvironmentTickCountSubtract(tmpMS); | 1612 | eventMS = Util.EnvironmentTickCountSubtract(tmpMS); |
1626 | } | 1613 | } |
1627 | 1614 | ||
1628 | if (Frame % m_update_backup == 0) | 1615 | if (PeriodicBackup && Frame % m_update_backup == 0) |
1629 | { | 1616 | { |
1630 | tmpMS = Util.EnvironmentTickCount(); | 1617 | tmpMS = Util.EnvironmentTickCount(); |
1631 | UpdateStorageBackup(); | 1618 | UpdateStorageBackup(); |
@@ -5621,33 +5608,7 @@ Environment.Exit(1); | |||
5621 | 5608 | ||
5622 | public void TriggerEstateSunUpdate() | 5609 | public void TriggerEstateSunUpdate() |
5623 | { | 5610 | { |
5624 | float sun; | 5611 | EventManager.TriggerEstateToolsSunUpdate(RegionInfo.RegionHandle); |
5625 | if (RegionInfo.RegionSettings.UseEstateSun) | ||
5626 | { | ||
5627 | sun = (float)RegionInfo.EstateSettings.SunPosition; | ||
5628 | if (RegionInfo.EstateSettings.UseGlobalTime) | ||
5629 | { | ||
5630 | sun = EventManager.GetCurrentTimeAsSunLindenHour() - 6.0f; | ||
5631 | } | ||
5632 | |||
5633 | // | ||
5634 | EventManager.TriggerEstateToolsSunUpdate( | ||
5635 | RegionInfo.RegionHandle, | ||
5636 | RegionInfo.EstateSettings.FixedSun, | ||
5637 | RegionInfo.RegionSettings.UseEstateSun, | ||
5638 | sun); | ||
5639 | } | ||
5640 | else | ||
5641 | { | ||
5642 | // Use the Sun Position from the Region Settings | ||
5643 | sun = (float)RegionInfo.RegionSettings.SunPosition - 6.0f; | ||
5644 | |||
5645 | EventManager.TriggerEstateToolsSunUpdate( | ||
5646 | RegionInfo.RegionHandle, | ||
5647 | RegionInfo.RegionSettings.FixedSun, | ||
5648 | RegionInfo.RegionSettings.UseEstateSun, | ||
5649 | sun); | ||
5650 | } | ||
5651 | } | 5612 | } |
5652 | 5613 | ||
5653 | private void HandleReloadEstate(string module, string[] cmd) | 5614 | private void HandleReloadEstate(string module, string[] cmd) |
@@ -6043,10 +6004,17 @@ Environment.Exit(1); | |||
6043 | GC.Collect(); | 6004 | GC.Collect(); |
6044 | } | 6005 | } |
6045 | 6006 | ||
6046 | // Wrappers to get physics modules retrieve assets. Has to be done this way | 6007 | /// <summary> |
6047 | // because we can't assign the asset service to physics directly - at the | 6008 | /// Wrappers to get physics modules retrieve assets. |
6048 | // time physics are instantiated it's not registered but it will be by | 6009 | /// </summary> |
6049 | // the time the first prim exists. | 6010 | /// <remarks> |
6011 | /// Has to be done this way | ||
6012 | /// because we can't assign the asset service to physics directly - at the | ||
6013 | /// time physics are instantiated it's not registered but it will be by | ||
6014 | /// the time the first prim exists. | ||
6015 | /// </remarks> | ||
6016 | /// <param name="assetID"></param> | ||
6017 | /// <param name="callback"></param> | ||
6050 | public void PhysicsRequestAsset(UUID assetID, AssetReceivedDelegate callback) | 6018 | public void PhysicsRequestAsset(UUID assetID, AssetReceivedDelegate callback) |
6051 | { | 6019 | { |
6052 | AssetService.Get(assetID.ToString(), callback, PhysicsAssetReceived); | 6020 | AssetService.Get(assetID.ToString(), callback, PhysicsAssetReceived); |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index ed1bbd8..0f5d116 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |||
@@ -101,6 +101,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
101 | /// </summary> | 101 | /// </summary> |
102 | public partial class SceneObjectGroup : EntityBase, ISceneObject | 102 | public partial class SceneObjectGroup : EntityBase, ISceneObject |
103 | { | 103 | { |
104 | // Axis selection bitmask used by SetAxisRotation() | ||
105 | // Just happen to be the same bits used by llSetStatus() and defined in ScriptBaseClass. | ||
106 | public enum axisSelect : int | ||
107 | { | ||
108 | STATUS_ROTATE_X = 0x002, | ||
109 | STATUS_ROTATE_Y = 0x004, | ||
110 | STATUS_ROTATE_Z = 0x008, | ||
111 | } | ||
112 | |||
104 | // private PrimCountTaintedDelegate handlerPrimCountTainted = null; | 113 | // private PrimCountTaintedDelegate handlerPrimCountTainted = null; |
105 | 114 | ||
106 | /// <summary> | 115 | /// <summary> |
@@ -512,11 +521,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
512 | 521 | ||
513 | if (Scene != null) | 522 | if (Scene != null) |
514 | { | 523 | { |
515 | // if ((Scene.TestBorderCross(val - Vector3.UnitX, Cardinals.E) || Scene.TestBorderCross(val + Vector3.UnitX, Cardinals.W) | 524 | if ( |
516 | // || Scene.TestBorderCross(val - Vector3.UnitY, Cardinals.N) || Scene.TestBorderCross(val + Vector3.UnitY, Cardinals.S)) | 525 | // (Scene.TestBorderCross(val - Vector3.UnitX, Cardinals.E) |
517 | // && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) | 526 | // || Scene.TestBorderCross(val + Vector3.UnitX, Cardinals.W) |
518 | if ((Scene.TestBorderCross(val, Cardinals.E) || Scene.TestBorderCross(val, Cardinals.W) | 527 | // || Scene.TestBorderCross(val - Vector3.UnitY, Cardinals.N) |
519 | || Scene.TestBorderCross(val, Cardinals.N) || Scene.TestBorderCross(val, Cardinals.S)) | 528 | // || Scene.TestBorderCross(val + Vector3.UnitY, Cardinals.S)) |
529 | // Experimental change for better border crossings. | ||
530 | // The commented out original lines above would, it seems, trigger | ||
531 | // a border crossing a little early or late depending on which | ||
532 | // direction the object was moving. | ||
533 | (Scene.TestBorderCross(val, Cardinals.E) | ||
534 | || Scene.TestBorderCross(val, Cardinals.W) | ||
535 | || Scene.TestBorderCross(val, Cardinals.N) | ||
536 | || Scene.TestBorderCross(val, Cardinals.S)) | ||
520 | && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) | 537 | && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) |
521 | { | 538 | { |
522 | IEntityTransferModule entityTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); | 539 | IEntityTransferModule entityTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); |
@@ -935,6 +952,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
935 | /// </remarks> | 952 | /// </remarks> |
936 | public UUID FromFolderID { get; set; } | 953 | public UUID FromFolderID { get; set; } |
937 | 954 | ||
955 | /// <summary> | ||
956 | /// IDs of all avatars sat on this scene object. | ||
957 | /// </summary> | ||
958 | /// <remarks> | ||
959 | /// We need this so that we can maintain a linkset wide ordering of avatars sat on different parts. | ||
960 | /// This must be locked before it is read or written. | ||
961 | /// SceneObjectPart sitting avatar add/remove code also locks on this object to avoid race conditions. | ||
962 | /// No avatar should appear more than once in this list. | ||
963 | /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart. | ||
964 | /// </remarks> | ||
965 | protected internal List<UUID> m_sittingAvatars = new List<UUID>(); | ||
966 | |||
938 | #endregion | 967 | #endregion |
939 | 968 | ||
940 | // ~SceneObjectGroup() | 969 | // ~SceneObjectGroup() |
@@ -4509,17 +4538,28 @@ namespace OpenSim.Region.Framework.Scenes | |||
4509 | } | 4538 | } |
4510 | 4539 | ||
4511 | /// <summary> | 4540 | /// <summary> |
4541 | /// Get a copy of the list of sitting avatars on all prims of this object. | ||
4542 | /// </summary> | ||
4543 | /// <remarks> | ||
4544 | /// This is sorted by the order in which avatars sat down. If an avatar stands up then all avatars that sat | ||
4545 | /// down after it move one place down the list. | ||
4546 | /// </remarks> | ||
4547 | /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns> | ||
4548 | public List<UUID> GetSittingAvatars() | ||
4549 | { | ||
4550 | lock (m_sittingAvatars) | ||
4551 | return new List<UUID>(m_sittingAvatars); | ||
4552 | } | ||
4553 | |||
4554 | /// <summary> | ||
4512 | /// Gets the number of sitting avatars. | 4555 | /// Gets the number of sitting avatars. |
4513 | /// </summary> | 4556 | /// </summary> |
4514 | /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks> | 4557 | /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks> |
4515 | /// <returns></returns> | 4558 | /// <returns></returns> |
4516 | public int GetSittingAvatarsCount() | 4559 | public int GetSittingAvatarsCount() |
4517 | { | 4560 | { |
4518 | int count = 0; | 4561 | lock (m_sittingAvatars) |
4519 | 4562 | return m_sittingAvatars.Count; | |
4520 | Array.ForEach<SceneObjectPart>(m_parts.GetArray(), p => count += p.GetSittingAvatarsCount()); | ||
4521 | |||
4522 | return count; | ||
4523 | } | 4563 | } |
4524 | 4564 | ||
4525 | public override string ToString() | 4565 | public override string ToString() |
@@ -4528,7 +4568,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
4528 | } | 4568 | } |
4529 | 4569 | ||
4530 | #region ISceneObject | 4570 | #region ISceneObject |
4531 | 4571 | ||
4532 | public virtual ISceneObject CloneForNewScene() | 4572 | public virtual ISceneObject CloneForNewScene() |
4533 | { | 4573 | { |
4534 | SceneObjectGroup sog = Copy(false); | 4574 | SceneObjectGroup sog = Copy(false); |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 8528edc..0fe9842 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | |||
@@ -1342,7 +1342,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1342 | public UUID SitTargetAvatar { get; set; } | 1342 | public UUID SitTargetAvatar { get; set; } |
1343 | 1343 | ||
1344 | /// <summary> | 1344 | /// <summary> |
1345 | /// IDs of all avatars start on this object part. | 1345 | /// IDs of all avatars sat on this part. |
1346 | /// </summary> | 1346 | /// </summary> |
1347 | /// <remarks> | 1347 | /// <remarks> |
1348 | /// We need to track this so that we can stop sat upon prims from being attached. | 1348 | /// We need to track this so that we can stop sat upon prims from being attached. |
@@ -2431,11 +2431,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
2431 | public int GetAxisRotation(int axis) | 2431 | public int GetAxisRotation(int axis) |
2432 | { | 2432 | { |
2433 | //Cannot use ScriptBaseClass constants as no referance to it currently. | 2433 | //Cannot use ScriptBaseClass constants as no referance to it currently. |
2434 | if (axis == 2)//STATUS_ROTATE_X | 2434 | if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) |
2435 | return STATUS_ROTATE_X; | 2435 | return STATUS_ROTATE_X; |
2436 | if (axis == 4)//STATUS_ROTATE_Y | 2436 | if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) |
2437 | return STATUS_ROTATE_Y; | 2437 | return STATUS_ROTATE_Y; |
2438 | if (axis == 8)//STATUS_ROTATE_Z | 2438 | if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) |
2439 | return STATUS_ROTATE_Z; | 2439 | return STATUS_ROTATE_Z; |
2440 | 2440 | ||
2441 | return 0; | 2441 | return 0; |
@@ -2470,18 +2470,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2470 | return new Vector3(0, 0, 0); | 2470 | return new Vector3(0, 0, 0); |
2471 | 2471 | ||
2472 | return ParentGroup.GetGeometricCenter(); | 2472 | return ParentGroup.GetGeometricCenter(); |
2473 | |||
2474 | /* | ||
2475 | PhysicsActor pa = PhysActor; | ||
2476 | |||
2477 | if (pa != null) | ||
2478 | { | ||
2479 | Vector3 vtmp = pa.CenterOfMass; | ||
2480 | return vtmp; | ||
2481 | } | ||
2482 | else | ||
2483 | return new Vector3(0, 0, 0); | ||
2484 | */ | ||
2485 | } | 2473 | } |
2486 | 2474 | ||
2487 | public float GetMass() | 2475 | public float GetMass() |
@@ -2895,11 +2883,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
2895 | 2883 | ||
2896 | public void PhysicsOutOfBounds(Vector3 pos) | 2884 | public void PhysicsOutOfBounds(Vector3 pos) |
2897 | { | 2885 | { |
2898 | m_log.Error("[PHYSICS]: Physical Object went out of bounds."); | 2886 | // Note: This is only being called on the root prim at this time. |
2887 | |||
2888 | m_log.ErrorFormat( | ||
2889 | "[SCENE OBJECT PART]: Physical object {0}, localID {1} went out of bounds at {2} in {3}. Stopping at {4} and making non-physical.", | ||
2890 | Name, LocalId, pos, ParentGroup.Scene.Name, AbsolutePosition); | ||
2899 | 2891 | ||
2900 | RemFlag(PrimFlags.Physics); | 2892 | RemFlag(PrimFlags.Physics); |
2901 | DoPhysicsPropertyUpdate(false, true); | 2893 | DoPhysicsPropertyUpdate(false, true); |
2902 | //ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); | ||
2903 | } | 2894 | } |
2904 | 2895 | ||
2905 | public void PhysicsRequestingTerseUpdate() | 2896 | public void PhysicsRequestingTerseUpdate() |
@@ -3322,13 +3313,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
3322 | ParentGroup.SetAxisRotation(axis, rotate); | 3313 | ParentGroup.SetAxisRotation(axis, rotate); |
3323 | 3314 | ||
3324 | //Cannot use ScriptBaseClass constants as no referance to it currently. | 3315 | //Cannot use ScriptBaseClass constants as no referance to it currently. |
3325 | if (axis == 2)//STATUS_ROTATE_X | 3316 | if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0) |
3326 | STATUS_ROTATE_X = rotate; | 3317 | STATUS_ROTATE_X = rotate; |
3327 | 3318 | ||
3328 | if (axis == 4)//STATUS_ROTATE_Y | 3319 | if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0) |
3329 | STATUS_ROTATE_Y = rotate; | 3320 | STATUS_ROTATE_Y = rotate; |
3330 | 3321 | ||
3331 | if (axis == 8)//STATUS_ROTATE_Z | 3322 | if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0) |
3332 | STATUS_ROTATE_Z = rotate; | 3323 | STATUS_ROTATE_Z = rotate; |
3333 | } | 3324 | } |
3334 | 3325 | ||
@@ -4558,7 +4549,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
4558 | if (ParentGroup.RootPart == this) | 4549 | if (ParentGroup.RootPart == this) |
4559 | AngularVelocity = new Vector3(0, 0, 0); | 4550 | AngularVelocity = new Vector3(0, 0, 0); |
4560 | } | 4551 | } |
4561 | else | 4552 | else if (SetVD != wasVD) |
4562 | { | 4553 | { |
4563 | if (ParentGroup.Scene.CollidablePrims) | 4554 | if (ParentGroup.Scene.CollidablePrims) |
4564 | { | 4555 | { |
@@ -4646,9 +4637,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
4646 | PhysicsShapeType, | 4637 | PhysicsShapeType, |
4647 | m_localId); | 4638 | m_localId); |
4648 | } | 4639 | } |
4649 | catch (Exception ex) | 4640 | catch (Exception e) |
4650 | { | 4641 | { |
4651 | m_log.ErrorFormat("[SCENE]: AddToPhysics object {0} failed: {1}", m_uuid, ex.Message); | 4642 | m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom. e={1}", m_uuid, e); |
4652 | pa = null; | 4643 | pa = null; |
4653 | } | 4644 | } |
4654 | 4645 | ||
@@ -5202,18 +5193,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
5202 | /// <param name='avatarId'></param> | 5193 | /// <param name='avatarId'></param> |
5203 | protected internal bool AddSittingAvatar(UUID avatarId) | 5194 | protected internal bool AddSittingAvatar(UUID avatarId) |
5204 | { | 5195 | { |
5205 | if (IsSitTargetSet && SitTargetAvatar == UUID.Zero) | 5196 | lock (ParentGroup.m_sittingAvatars) |
5206 | SitTargetAvatar = avatarId; | 5197 | { |
5198 | if (IsSitTargetSet && SitTargetAvatar == UUID.Zero) | ||
5199 | SitTargetAvatar = avatarId; | ||
5207 | 5200 | ||
5208 | HashSet<UUID> sittingAvatars = m_sittingAvatars; | 5201 | if (m_sittingAvatars == null) |
5202 | m_sittingAvatars = new HashSet<UUID>(); | ||
5209 | 5203 | ||
5210 | if (sittingAvatars == null) | 5204 | if (m_sittingAvatars.Add(avatarId)) |
5211 | sittingAvatars = new HashSet<UUID>(); | 5205 | { |
5206 | ParentGroup.m_sittingAvatars.Add(avatarId); | ||
5212 | 5207 | ||
5213 | lock (sittingAvatars) | 5208 | return true; |
5214 | { | 5209 | } |
5215 | m_sittingAvatars = sittingAvatars; | 5210 | |
5216 | return m_sittingAvatars.Add(avatarId); | 5211 | return false; |
5217 | } | 5212 | } |
5218 | } | 5213 | } |
5219 | 5214 | ||
@@ -5227,27 +5222,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
5227 | /// <param name='avatarId'></param> | 5222 | /// <param name='avatarId'></param> |
5228 | protected internal bool RemoveSittingAvatar(UUID avatarId) | 5223 | protected internal bool RemoveSittingAvatar(UUID avatarId) |
5229 | { | 5224 | { |
5230 | if (SitTargetAvatar == avatarId) | 5225 | lock (ParentGroup.m_sittingAvatars) |
5231 | SitTargetAvatar = UUID.Zero; | 5226 | { |
5232 | 5227 | if (SitTargetAvatar == avatarId) | |
5233 | HashSet<UUID> sittingAvatars = m_sittingAvatars; | 5228 | SitTargetAvatar = UUID.Zero; |
5234 | 5229 | ||
5235 | // This can occur under a race condition where another thread | 5230 | if (m_sittingAvatars == null) |
5236 | if (sittingAvatars == null) | 5231 | return false; |
5237 | return false; | ||
5238 | 5232 | ||
5239 | lock (sittingAvatars) | 5233 | if (m_sittingAvatars.Remove(avatarId)) |
5240 | { | ||
5241 | if (sittingAvatars.Remove(avatarId)) | ||
5242 | { | 5234 | { |
5243 | if (sittingAvatars.Count == 0) | 5235 | if (m_sittingAvatars.Count == 0) |
5244 | m_sittingAvatars = null; | 5236 | m_sittingAvatars = null; |
5245 | 5237 | ||
5238 | ParentGroup.m_sittingAvatars.Remove(avatarId); | ||
5239 | |||
5246 | return true; | 5240 | return true; |
5247 | } | 5241 | } |
5248 | } | ||
5249 | 5242 | ||
5250 | return false; | 5243 | return false; |
5244 | } | ||
5251 | } | 5245 | } |
5252 | 5246 | ||
5253 | /// <summary> | 5247 | /// <summary> |
@@ -5257,16 +5251,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
5257 | /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns> | 5251 | /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns> |
5258 | public HashSet<UUID> GetSittingAvatars() | 5252 | public HashSet<UUID> GetSittingAvatars() |
5259 | { | 5253 | { |
5260 | HashSet<UUID> sittingAvatars = m_sittingAvatars; | 5254 | lock (ParentGroup.m_sittingAvatars) |
5261 | |||
5262 | if (sittingAvatars == null) | ||
5263 | { | 5255 | { |
5264 | return null; | 5256 | if (m_sittingAvatars == null) |
5265 | } | 5257 | return null; |
5266 | else | 5258 | else |
5267 | { | 5259 | return new HashSet<UUID>(m_sittingAvatars); |
5268 | lock (sittingAvatars) | ||
5269 | return new HashSet<UUID>(sittingAvatars); | ||
5270 | } | 5260 | } |
5271 | } | 5261 | } |
5272 | 5262 | ||
@@ -5277,13 +5267,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
5277 | /// <returns></returns> | 5267 | /// <returns></returns> |
5278 | public int GetSittingAvatarsCount() | 5268 | public int GetSittingAvatarsCount() |
5279 | { | 5269 | { |
5280 | HashSet<UUID> sittingAvatars = m_sittingAvatars; | 5270 | lock (ParentGroup.m_sittingAvatars) |
5281 | 5271 | { | |
5282 | if (sittingAvatars == null) | 5272 | if (m_sittingAvatars == null) |
5283 | return 0; | 5273 | return 0; |
5284 | 5274 | else | |
5285 | lock (sittingAvatars) | 5275 | return m_sittingAvatars.Count; |
5286 | return sittingAvatars.Count; | 5276 | } |
5287 | } | 5277 | } |
5288 | } | 5278 | } |
5289 | } | 5279 | } |
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index a9195f7..f024f52 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -216,8 +216,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
216 | 216 | ||
217 | private Quaternion m_headrotation = Quaternion.Identity; | 217 | private Quaternion m_headrotation = Quaternion.Identity; |
218 | 218 | ||
219 | private string m_nextSitAnimation = String.Empty; | ||
220 | |||
221 | //PauPaw:Proper PID Controler for autopilot************ | 219 | //PauPaw:Proper PID Controler for autopilot************ |
222 | public bool MovingToTarget { get; private set; } | 220 | public bool MovingToTarget { get; private set; } |
223 | public Vector3 MoveToPositionTarget { get; private set; } | 221 | public Vector3 MoveToPositionTarget { get; private set; } |
@@ -591,18 +589,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
591 | set | 589 | set |
592 | { | 590 | { |
593 | m_bodyRot = value; | 591 | m_bodyRot = value; |
594 | // m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); | ||
595 | if (PhysicsActor != null) | 592 | if (PhysicsActor != null) |
596 | { | 593 | { |
597 | try | 594 | try |
598 | { | 595 | { |
599 | PhysicsActor.Orientation = value; | 596 | PhysicsActor.Orientation = m_bodyRot; |
600 | } | 597 | } |
601 | catch (Exception e) | 598 | catch (Exception e) |
602 | { | 599 | { |
603 | m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message); | 600 | m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message); |
604 | } | 601 | } |
605 | } | 602 | } |
603 | // m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); | ||
606 | } | 604 | } |
607 | } | 605 | } |
608 | 606 | ||
@@ -2199,28 +2197,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
2199 | 2197 | ||
2200 | if (ParentID != 0) | 2198 | if (ParentID != 0) |
2201 | { | 2199 | { |
2200 | if (ParentPart.UUID == targetID) | ||
2201 | return; // already sitting here, ignore | ||
2202 | |||
2202 | StandUp(); | 2203 | StandUp(); |
2203 | } | 2204 | } |
2204 | 2205 | ||
2205 | // if (!String.IsNullOrEmpty(sitAnimation)) | ||
2206 | // { | ||
2207 | // m_nextSitAnimation = sitAnimation; | ||
2208 | // } | ||
2209 | // else | ||
2210 | // { | ||
2211 | m_nextSitAnimation = "SIT"; | ||
2212 | // } | ||
2213 | |||
2214 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); | ||
2215 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); | 2206 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); |
2216 | 2207 | ||
2217 | if (part != null) | 2208 | if (part != null) |
2218 | { | 2209 | { |
2219 | if (!String.IsNullOrEmpty(part.SitAnimation)) | ||
2220 | { | ||
2221 | m_nextSitAnimation = part.SitAnimation; | ||
2222 | } | ||
2223 | |||
2224 | m_requestedSitTargetID = part.LocalId; | 2210 | m_requestedSitTargetID = part.LocalId; |
2225 | m_requestedSitTargetUUID = targetID; | 2211 | m_requestedSitTargetUUID = targetID; |
2226 | 2212 | ||
@@ -2341,18 +2327,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2341 | 2327 | ||
2342 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) | 2328 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) |
2343 | { | 2329 | { |
2344 | if (!String.IsNullOrEmpty(m_nextSitAnimation)) | ||
2345 | { | ||
2346 | HandleAgentSit(remoteClient, agentID, m_nextSitAnimation); | ||
2347 | } | ||
2348 | else | ||
2349 | { | ||
2350 | HandleAgentSit(remoteClient, agentID, "SIT"); | ||
2351 | } | ||
2352 | } | ||
2353 | |||
2354 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation) | ||
2355 | { | ||
2356 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); | 2330 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); |
2357 | 2331 | ||
2358 | if (part != null) | 2332 | if (part != null) |
@@ -2425,7 +2399,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2425 | 2399 | ||
2426 | Velocity = Vector3.Zero; | 2400 | Velocity = Vector3.Zero; |
2427 | RemoveFromPhysicalScene(); | 2401 | RemoveFromPhysicalScene(); |
2428 | 2402 | ||
2403 | String sitAnimation = "SIT"; | ||
2404 | if (!String.IsNullOrEmpty(part.SitAnimation)) | ||
2405 | { | ||
2406 | sitAnimation = part.SitAnimation; | ||
2407 | } | ||
2429 | Animator.TrySetMovementAnimation(sitAnimation); | 2408 | Animator.TrySetMovementAnimation(sitAnimation); |
2430 | SendAvatarDataToAllAgents(); | 2409 | SendAvatarDataToAllAgents(); |
2431 | } | 2410 | } |
@@ -2455,7 +2434,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2455 | 2434 | ||
2456 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) | 2435 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) |
2457 | { | 2436 | { |
2458 | Animator.RemoveAnimation(animID); | 2437 | Animator.RemoveAnimation(animID, false); |
2459 | } | 2438 | } |
2460 | 2439 | ||
2461 | public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack) | 2440 | public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack) |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs index 4a21dc9..e209221 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs | |||
@@ -37,7 +37,7 @@ using OpenSim.Tests.Common; | |||
37 | namespace OpenSim.Region.Framework.Scenes.Tests | 37 | namespace OpenSim.Region.Framework.Scenes.Tests |
38 | { | 38 | { |
39 | [TestFixture] | 39 | [TestFixture] |
40 | public class BorderTests | 40 | public class BorderTests : OpenSimTestCase |
41 | { | 41 | { |
42 | [Test] | 42 | [Test] |
43 | public void TestCross() | 43 | public void TestCross() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs index ea9fc93..766ce83 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs | |||
@@ -41,7 +41,7 @@ using OpenSim.Tests.Common; | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | 41 | namespace OpenSim.Region.Framework.Scenes.Tests |
42 | { | 42 | { |
43 | [TestFixture, LongRunning] | 43 | [TestFixture, LongRunning] |
44 | public class EntityManagerTests | 44 | public class EntityManagerTests : OpenSimTestCase |
45 | { | 45 | { |
46 | static public Random random; | 46 | static public Random random; |
47 | SceneObjectGroup found; | 47 | SceneObjectGroup found; |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs index d23c965..575a081 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs | |||
@@ -40,7 +40,7 @@ using OpenSim.Tests.Common.Mock; | |||
40 | namespace OpenSim.Region.Framework.Scenes.Tests | 40 | namespace OpenSim.Region.Framework.Scenes.Tests |
41 | { | 41 | { |
42 | [TestFixture] | 42 | [TestFixture] |
43 | public class SceneGraphTests | 43 | public class SceneGraphTests : OpenSimTestCase |
44 | { | 44 | { |
45 | [Test] | 45 | [Test] |
46 | public void TestDuplicateObject() | 46 | public void TestDuplicateObject() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs index ab56f4e..2d831fa 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs | |||
@@ -41,7 +41,7 @@ using OpenSim.Tests.Common.Mock; | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | 41 | namespace OpenSim.Region.Framework.Scenes.Tests |
42 | { | 42 | { |
43 | [TestFixture] | 43 | [TestFixture] |
44 | public class SceneManagerTests | 44 | public class SceneManagerTests : OpenSimTestCase |
45 | { | 45 | { |
46 | [Test] | 46 | [Test] |
47 | public void TestClose() | 47 | public void TestClose() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs index 5b334c6..a07d64c 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using Nini.Config; | ||
32 | using NUnit.Framework; | 33 | using NUnit.Framework; |
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
@@ -182,6 +183,10 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
182 | /// <summary> | 183 | /// <summary> |
183 | /// Test deleting an object from a scene. | 184 | /// Test deleting an object from a scene. |
184 | /// </summary> | 185 | /// </summary> |
186 | /// <remarks> | ||
187 | /// This is the most basic form of delete. For all more sophisticated forms of derez (done asynchrnously | ||
188 | /// and where object can be taken to user inventory, etc.), see SceneObjectDeRezTests. | ||
189 | /// </remarks> | ||
185 | [Test] | 190 | [Test] |
186 | public void TestDeleteSceneObject() | 191 | public void TestDeleteSceneObject() |
187 | { | 192 | { |
@@ -201,100 +206,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
201 | } | 206 | } |
202 | 207 | ||
203 | /// <summary> | 208 | /// <summary> |
204 | /// Test deleting an object asynchronously | ||
205 | /// </summary> | ||
206 | [Test] | ||
207 | public void TestDeleteSceneObjectAsync() | ||
208 | { | ||
209 | TestHelpers.InMethod(); | ||
210 | //log4net.Config.XmlConfigurator.Configure(); | ||
211 | |||
212 | UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
213 | |||
214 | TestScene scene = new SceneHelpers().SetupScene(); | ||
215 | |||
216 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
217 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
218 | sogd.Enabled = false; | ||
219 | |||
220 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene); | ||
221 | |||
222 | IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient; | ||
223 | scene.DeRezObjects(client, new System.Collections.Generic.List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Delete, UUID.Zero); | ||
224 | |||
225 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
226 | |||
227 | Assert.That(retrievedPart, Is.Not.Null); | ||
228 | |||
229 | Assert.That(so.IsDeleted, Is.False); | ||
230 | |||
231 | sogd.InventoryDeQueueAndDelete(); | ||
232 | |||
233 | Assert.That(so.IsDeleted, Is.True); | ||
234 | |||
235 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
236 | Assert.That(retrievedPart2, Is.Null); | ||
237 | } | ||
238 | |||
239 | /// <summary> | ||
240 | /// Test deleting an object asynchronously to user inventory. | ||
241 | /// </summary> | ||
242 | // [Test] | ||
243 | public void TestDeleteSceneObjectAsyncToUserInventory() | ||
244 | { | ||
245 | TestHelpers.InMethod(); | ||
246 | TestHelpers.EnableLogging(); | ||
247 | |||
248 | UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
249 | string myObjectName = "Fred"; | ||
250 | |||
251 | TestScene scene = new SceneHelpers().SetupScene(); | ||
252 | |||
253 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
254 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
255 | sogd.Enabled = false; | ||
256 | |||
257 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId); | ||
258 | |||
259 | // Assert.That( | ||
260 | // scene.CommsManager.UserAdminService.AddUser( | ||
261 | // "Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId), | ||
262 | // Is.EqualTo(agentId)); | ||
263 | |||
264 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId); | ||
265 | InventoryFolderBase folder1 | ||
266 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1"); | ||
267 | |||
268 | IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient; | ||
269 | scene.DeRezObjects(client, new List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Take, folder1.ID); | ||
270 | |||
271 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
272 | |||
273 | Assert.That(retrievedPart, Is.Not.Null); | ||
274 | Assert.That(so.IsDeleted, Is.False); | ||
275 | |||
276 | sogd.InventoryDeQueueAndDelete(); | ||
277 | |||
278 | Assert.That(so.IsDeleted, Is.True); | ||
279 | |||
280 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
281 | Assert.That(retrievedPart2, Is.Null); | ||
282 | |||
283 | // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client); | ||
284 | |||
285 | InventoryItemBase retrievedItem | ||
286 | = UserInventoryHelpers.GetInventoryItem( | ||
287 | scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName); | ||
288 | |||
289 | // Check that we now have the taken part in our inventory | ||
290 | Assert.That(retrievedItem, Is.Not.Null); | ||
291 | |||
292 | // Check that the taken part has actually disappeared | ||
293 | // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | ||
294 | // Assert.That(retrievedPart, Is.Null); | ||
295 | } | ||
296 | |||
297 | /// <summary> | ||
298 | /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not | 209 | /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not |
299 | /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by | 210 | /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by |
300 | /// OpenSim. | 211 | /// OpenSim. |
@@ -329,4 +240,4 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
329 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); | 240 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); |
330 | } | 241 | } |
331 | } | 242 | } |
332 | } | 243 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs index 0076f41..c1522e7 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs | |||
@@ -33,22 +33,24 @@ using NUnit.Framework; | |||
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Communications; | 35 | using OpenSim.Framework.Communications; |
36 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
36 | using OpenSim.Region.CoreModules.World.Permissions; | 37 | using OpenSim.Region.CoreModules.World.Permissions; |
37 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Tests.Common; | 40 | using OpenSim.Tests.Common; |
39 | using OpenSim.Tests.Common.Mock; | 41 | using OpenSim.Tests.Common.Mock; |
40 | 42 | ||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | 43 | namespace OpenSim.Region.Framework.Scenes.Tests |
42 | { | 44 | { |
43 | /// <summary> | 45 | /// <summary> |
44 | /// Tests derez of scene objects by users. | 46 | /// Tests derez of scene objects. |
45 | /// </summary> | 47 | /// </summary> |
46 | /// <remarks> | 48 | /// <remarks> |
47 | /// This is at a level above the SceneObjectBasicTests, which act on the scene directly. | 49 | /// This is at a level above the SceneObjectBasicTests, which act on the scene directly. |
48 | /// TODO: These tests are very incomplete - they only test for a few conditions. | 50 | /// TODO: These tests are incomplete - need to test more kinds of derez (e.g. return object). |
49 | /// </remarks> | 51 | /// </remarks> |
50 | [TestFixture] | 52 | [TestFixture] |
51 | public class SceneObjectDeRezTests | 53 | public class SceneObjectDeRezTests : OpenSimTestCase |
52 | { | 54 | { |
53 | /// <summary> | 55 | /// <summary> |
54 | /// Test deleting an object from a scene. | 56 | /// Test deleting an object from a scene. |
@@ -76,14 +78,20 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
76 | = new SceneObjectPart(userId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); | 78 | = new SceneObjectPart(userId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); |
77 | part.Name = "obj1"; | 79 | part.Name = "obj1"; |
78 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); | 80 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); |
81 | |||
79 | List<uint> localIds = new List<uint>(); | 82 | List<uint> localIds = new List<uint>(); |
80 | localIds.Add(part.LocalId); | 83 | localIds.Add(part.LocalId); |
81 | |||
82 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero); | 84 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero); |
85 | |||
86 | // Check that object isn't deleted until we crank the sogd handle. | ||
87 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | ||
88 | Assert.That(retrievedPart, Is.Not.Null); | ||
89 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
90 | |||
83 | sogd.InventoryDeQueueAndDelete(); | 91 | sogd.InventoryDeQueueAndDelete(); |
84 | 92 | ||
85 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | 93 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId); |
86 | Assert.That(retrievedPart, Is.Null); | 94 | Assert.That(retrievedPart2, Is.Null); |
87 | } | 95 | } |
88 | 96 | ||
89 | /// <summary> | 97 | /// <summary> |
@@ -124,6 +132,67 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
124 | // Object should still be in the scene. | 132 | // Object should still be in the scene. |
125 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | 133 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); |
126 | Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID)); | 134 | Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID)); |
127 | } | 135 | } |
136 | |||
137 | /// <summary> | ||
138 | /// Test deleting an object asynchronously to user inventory. | ||
139 | /// </summary> | ||
140 | [Test] | ||
141 | public void TestDeleteSceneObjectAsyncToUserInventory() | ||
142 | { | ||
143 | TestHelpers.InMethod(); | ||
144 | // TestHelpers.EnableLogging(); | ||
145 | |||
146 | UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
147 | string myObjectName = "Fred"; | ||
148 | |||
149 | TestScene scene = new SceneHelpers().SetupScene(); | ||
150 | |||
151 | IConfigSource configSource = new IniConfigSource(); | ||
152 | IConfig config = configSource.AddConfig("Modules"); | ||
153 | config.Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
154 | SceneHelpers.SetupSceneModules( | ||
155 | scene, configSource, new object[] { new BasicInventoryAccessModule() }); | ||
156 | |||
157 | SceneHelpers.SetupSceneModules(scene, new object[] { }); | ||
158 | |||
159 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
160 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
161 | sogd.Enabled = false; | ||
162 | |||
163 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId); | ||
164 | |||
165 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId); | ||
166 | InventoryFolderBase folder1 | ||
167 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1"); | ||
168 | |||
169 | IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient; | ||
170 | scene.DeRezObjects(client, new List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Take, folder1.ID); | ||
171 | |||
172 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
173 | |||
174 | Assert.That(retrievedPart, Is.Not.Null); | ||
175 | Assert.That(so.IsDeleted, Is.False); | ||
176 | |||
177 | sogd.InventoryDeQueueAndDelete(); | ||
178 | |||
179 | Assert.That(so.IsDeleted, Is.True); | ||
180 | |||
181 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
182 | Assert.That(retrievedPart2, Is.Null); | ||
183 | |||
184 | // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client); | ||
185 | |||
186 | InventoryItemBase retrievedItem | ||
187 | = UserInventoryHelpers.GetInventoryItem( | ||
188 | scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName); | ||
189 | |||
190 | // Check that we now have the taken part in our inventory | ||
191 | Assert.That(retrievedItem, Is.Not.Null); | ||
192 | |||
193 | // Check that the taken part has actually disappeared | ||
194 | // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | ||
195 | // Assert.That(retrievedPart, Is.Null); | ||
196 | } | ||
128 | } | 197 | } |
129 | } \ No newline at end of file | 198 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs index 0e525c9..9378e20 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs | |||
@@ -40,7 +40,7 @@ using log4net; | |||
40 | namespace OpenSim.Region.Framework.Scenes.Tests | 40 | namespace OpenSim.Region.Framework.Scenes.Tests |
41 | { | 41 | { |
42 | [TestFixture] | 42 | [TestFixture] |
43 | public class SceneObjectLinkingTests | 43 | public class SceneObjectLinkingTests : OpenSimTestCase |
44 | { | 44 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 46 | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs index e931859..1182c96 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs | |||
@@ -41,7 +41,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
41 | /// Basic scene object resize tests | 41 | /// Basic scene object resize tests |
42 | /// </summary> | 42 | /// </summary> |
43 | [TestFixture] | 43 | [TestFixture] |
44 | public class SceneObjectResizeTests | 44 | public class SceneObjectResizeTests : OpenSimTestCase |
45 | { | 45 | { |
46 | /// <summary> | 46 | /// <summary> |
47 | /// Test resizing an object | 47 | /// Test resizing an object |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs index d2361f8..a58e735 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs | |||
@@ -40,7 +40,7 @@ using OpenSim.Tests.Common.Mock; | |||
40 | namespace OpenSim.Region.Framework.Scenes.Tests | 40 | namespace OpenSim.Region.Framework.Scenes.Tests |
41 | { | 41 | { |
42 | [TestFixture] | 42 | [TestFixture] |
43 | public class SceneObjectScriptTests | 43 | public class SceneObjectScriptTests : OpenSimTestCase |
44 | { | 44 | { |
45 | [Test] | 45 | [Test] |
46 | public void TestAddScript() | 46 | public void TestAddScript() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index 6d255aa..abaa1d1 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs | |||
@@ -42,14 +42,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
42 | /// Spatial scene object tests (will eventually cover root and child part position, rotation properties, etc.) | 42 | /// Spatial scene object tests (will eventually cover root and child part position, rotation properties, etc.) |
43 | /// </summary> | 43 | /// </summary> |
44 | [TestFixture] | 44 | [TestFixture] |
45 | public class SceneObjectSpatialTests | 45 | public class SceneObjectSpatialTests : OpenSimTestCase |
46 | { | 46 | { |
47 | TestScene m_scene; | 47 | TestScene m_scene; |
48 | UUID m_ownerId = TestHelpers.ParseTail(0x1); | 48 | UUID m_ownerId = TestHelpers.ParseTail(0x1); |
49 | 49 | ||
50 | [SetUp] | 50 | [SetUp] |
51 | public void SetUp() | 51 | public override void SetUp() |
52 | { | 52 | { |
53 | base.SetUp(); | ||
54 | |||
53 | m_scene = new SceneHelpers().SetupScene(); | 55 | m_scene = new SceneHelpers().SetupScene(); |
54 | } | 56 | } |
55 | 57 | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs index 742c769..8eb3191 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs | |||
@@ -42,7 +42,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
42 | /// Basic scene object status tests | 42 | /// Basic scene object status tests |
43 | /// </summary> | 43 | /// </summary> |
44 | [TestFixture] | 44 | [TestFixture] |
45 | public class SceneObjectStatusTests | 45 | public class SceneObjectStatusTests : OpenSimTestCase |
46 | { | 46 | { |
47 | private TestScene m_scene; | 47 | private TestScene m_scene; |
48 | private UUID m_ownerId = TestHelpers.ParseTail(0x1); | 48 | private UUID m_ownerId = TestHelpers.ParseTail(0x1); |
@@ -78,6 +78,26 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
78 | } | 78 | } |
79 | 79 | ||
80 | [Test] | 80 | [Test] |
81 | public void TestSetNonPhysicsVolumeDetectSinglePrim() | ||
82 | { | ||
83 | TestHelpers.InMethod(); | ||
84 | |||
85 | m_scene.AddSceneObject(m_so1); | ||
86 | |||
87 | SceneObjectPart rootPart = m_so1.RootPart; | ||
88 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
89 | |||
90 | m_so1.ScriptSetVolumeDetect(true); | ||
91 | |||
92 | // Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags); | ||
93 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom)); | ||
94 | |||
95 | m_so1.ScriptSetVolumeDetect(false); | ||
96 | |||
97 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
98 | } | ||
99 | |||
100 | [Test] | ||
81 | public void TestSetPhysicsSinglePrim() | 101 | public void TestSetPhysicsSinglePrim() |
82 | { | 102 | { |
83 | TestHelpers.InMethod(); | 103 | TestHelpers.InMethod(); |
@@ -89,13 +109,32 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
89 | 109 | ||
90 | m_so1.ScriptSetPhysicsStatus(true); | 110 | m_so1.ScriptSetPhysicsStatus(true); |
91 | 111 | ||
92 | // Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags); | ||
93 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | 112 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics)); |
94 | 113 | ||
95 | m_so1.ScriptSetPhysicsStatus(false); | 114 | m_so1.ScriptSetPhysicsStatus(false); |
96 | 115 | ||
97 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | 116 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); |
98 | } | 117 | } |
118 | |||
119 | [Test] | ||
120 | public void TestSetPhysicsVolumeDetectSinglePrim() | ||
121 | { | ||
122 | TestHelpers.InMethod(); | ||
123 | |||
124 | m_scene.AddSceneObject(m_so1); | ||
125 | |||
126 | SceneObjectPart rootPart = m_so1.RootPart; | ||
127 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
128 | |||
129 | m_so1.ScriptSetPhysicsStatus(true); | ||
130 | m_so1.ScriptSetVolumeDetect(true); | ||
131 | |||
132 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom | PrimFlags.Physics)); | ||
133 | |||
134 | m_so1.ScriptSetVolumeDetect(false); | ||
135 | |||
136 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
137 | } | ||
99 | 138 | ||
100 | [Test] | 139 | [Test] |
101 | public void TestSetPhysicsLinkset() | 140 | public void TestSetPhysicsLinkset() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs index 646e5fa..1cd8ae9 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs | |||
@@ -51,7 +51,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
51 | /// Scene presence animation tests | 51 | /// Scene presence animation tests |
52 | /// </summary> | 52 | /// </summary> |
53 | [TestFixture] | 53 | [TestFixture] |
54 | public class ScenePresenceAnimationTests | 54 | public class ScenePresenceAnimationTests : OpenSimTestCase |
55 | { | 55 | { |
56 | [Test] | 56 | [Test] |
57 | public void TestFlyingAnimation() | 57 | public void TestFlyingAnimation() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs index 1d1ff88..d80afd3 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs | |||
@@ -42,7 +42,7 @@ using OpenSim.Tests.Common.Mock; | |||
42 | namespace OpenSim.Region.Framework.Scenes.Tests | 42 | namespace OpenSim.Region.Framework.Scenes.Tests |
43 | { | 43 | { |
44 | [TestFixture] | 44 | [TestFixture] |
45 | public class ScenePresenceAutopilotTests | 45 | public class ScenePresenceAutopilotTests : OpenSimTestCase |
46 | { | 46 | { |
47 | private TestScene m_scene; | 47 | private TestScene m_scene; |
48 | 48 | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index 493ab70..acaeb90 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs | |||
@@ -43,7 +43,7 @@ using System.Threading; | |||
43 | namespace OpenSim.Region.Framework.Scenes.Tests | 43 | namespace OpenSim.Region.Framework.Scenes.Tests |
44 | { | 44 | { |
45 | [TestFixture] | 45 | [TestFixture] |
46 | public class ScenePresenceSitTests | 46 | public class ScenePresenceSitTests : OpenSimTestCase |
47 | { | 47 | { |
48 | private TestScene m_scene; | 48 | private TestScene m_scene; |
49 | private ScenePresence m_sp; | 49 | private ScenePresence m_sp; |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs index 37b5184..8dd1f3d 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
49 | /// Teleport tests in a standalone OpenSim | 49 | /// Teleport tests in a standalone OpenSim |
50 | /// </summary> | 50 | /// </summary> |
51 | [TestFixture] | 51 | [TestFixture] |
52 | public class ScenePresenceTeleportTests | 52 | public class ScenePresenceTeleportTests : OpenSimTestCase |
53 | { | 53 | { |
54 | [TestFixtureSetUp] | 54 | [TestFixtureSetUp] |
55 | public void FixtureInit() | 55 | public void FixtureInit() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs index ac3da1e..9d8eb0b 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs | |||
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
50 | /// Scene presence tests | 50 | /// Scene presence tests |
51 | /// </summary> | 51 | /// </summary> |
52 | [TestFixture] | 52 | [TestFixture] |
53 | public class SceneTests | 53 | public class SceneTests : OpenSimTestCase |
54 | { | 54 | { |
55 | /// <summary> | 55 | /// <summary> |
56 | /// Very basic scene update test. Should become more elaborate with time. | 56 | /// Very basic scene update test. Should become more elaborate with time. |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs index a51e4e3..0b461f5 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs | |||
@@ -50,7 +50,7 @@ using OpenSim.Tests.Common.Mock; | |||
50 | namespace OpenSim.Region.Framework.Tests | 50 | namespace OpenSim.Region.Framework.Tests |
51 | { | 51 | { |
52 | [TestFixture] | 52 | [TestFixture] |
53 | public class TaskInventoryTests | 53 | public class TaskInventoryTests : OpenSimTestCase |
54 | { | 54 | { |
55 | [Test] | 55 | [Test] |
56 | public void TestAddTaskInventoryItem() | 56 | public void TestAddTaskInventoryItem() |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs index 198e487..dd27294 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs | |||
@@ -38,7 +38,7 @@ using OpenSim.Tests.Common.Mock; | |||
38 | namespace OpenSim.Region.Framework.Scenes.Tests | 38 | namespace OpenSim.Region.Framework.Scenes.Tests |
39 | { | 39 | { |
40 | [TestFixture] | 40 | [TestFixture] |
41 | public class UuidGathererTests | 41 | public class UuidGathererTests : OpenSimTestCase |
42 | { | 42 | { |
43 | protected IAssetService m_assetService; | 43 | protected IAssetService m_assetService; |
44 | protected UuidGatherer m_uuidGatherer; | 44 | protected UuidGatherer m_uuidGatherer; |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs new file mode 100644 index 0000000..84211a9 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs | |||
@@ -0,0 +1,200 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Monitoring; | ||
40 | using OpenSim.Region.ClientStack.LindenUDP; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Region.Framework.Scenes.Animation; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | |||
46 | namespace OpenSim.Region.OptionalModules.Avatar.Animations | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// A module that just holds commands for inspecting avatar animations. | ||
50 | /// </summary> | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")] | ||
52 | public class AnimationsCommandModule : ISharedRegionModule | ||
53 | { | ||
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private List<Scene> m_scenes = new List<Scene>(); | ||
57 | |||
58 | public string Name { get { return "Animations Command Module"; } } | ||
59 | |||
60 | public Type ReplaceableInterface { get { return null; } } | ||
61 | |||
62 | public void Initialise(IConfigSource source) | ||
63 | { | ||
64 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE"); | ||
65 | } | ||
66 | |||
67 | public void PostInitialise() | ||
68 | { | ||
69 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE"); | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene scene) | ||
78 | { | ||
79 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
80 | } | ||
81 | |||
82 | public void RemoveRegion(Scene scene) | ||
83 | { | ||
84 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
85 | |||
86 | lock (m_scenes) | ||
87 | m_scenes.Remove(scene); | ||
88 | } | ||
89 | |||
90 | public void RegionLoaded(Scene scene) | ||
91 | { | ||
92 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
93 | |||
94 | lock (m_scenes) | ||
95 | m_scenes.Add(scene); | ||
96 | |||
97 | scene.AddCommand( | ||
98 | "Users", this, "show animations", | ||
99 | "show animations [<first-name> <last-name>]", | ||
100 | "Show animation information for avatars in this simulator.", | ||
101 | "If no name is supplied then information for all avatars is shown.\n" | ||
102 | + "Please note that for inventory animations, the animation name is the name under which the animation was originally uploaded\n" | ||
103 | + ", which is not necessarily the current inventory name.", | ||
104 | HandleShowAnimationsCommand); | ||
105 | } | ||
106 | |||
107 | protected void HandleShowAnimationsCommand(string module, string[] cmd) | ||
108 | { | ||
109 | if (cmd.Length != 2 && cmd.Length < 4) | ||
110 | { | ||
111 | MainConsole.Instance.OutputFormat("Usage: show animations [<first-name> <last-name>]"); | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | bool targetNameSupplied = false; | ||
116 | string optionalTargetFirstName = null; | ||
117 | string optionalTargetLastName = null; | ||
118 | |||
119 | if (cmd.Length >= 4) | ||
120 | { | ||
121 | targetNameSupplied = true; | ||
122 | optionalTargetFirstName = cmd[2]; | ||
123 | optionalTargetLastName = cmd[3]; | ||
124 | } | ||
125 | |||
126 | StringBuilder sb = new StringBuilder(); | ||
127 | |||
128 | lock (m_scenes) | ||
129 | { | ||
130 | foreach (Scene scene in m_scenes) | ||
131 | { | ||
132 | if (targetNameSupplied) | ||
133 | { | ||
134 | ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName); | ||
135 | if (sp != null && !sp.IsChildAgent) | ||
136 | GetAttachmentsReport(sp, sb); | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb)); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | MainConsole.Instance.Output(sb.ToString()); | ||
146 | } | ||
147 | |||
148 | private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb) | ||
149 | { | ||
150 | sb.AppendFormat("Animations for {0}\n", sp.Name); | ||
151 | |||
152 | ConsoleDisplayList cdl = new ConsoleDisplayList() { Indent = 2 }; | ||
153 | ScenePresenceAnimator spa = sp.Animator; | ||
154 | AnimationSet anims = sp.Animator.Animations; | ||
155 | |||
156 | string cma = spa.CurrentMovementAnimation; | ||
157 | cdl.AddRow( | ||
158 | "Current movement anim", | ||
159 | string.Format("{0}, {1}", DefaultAvatarAnimations.GetDefaultAnimation(cma), cma)); | ||
160 | |||
161 | UUID defaultAnimId = anims.DefaultAnimation.AnimID; | ||
162 | cdl.AddRow( | ||
163 | "Default anim", | ||
164 | string.Format("{0}, {1}", defaultAnimId, sp.Animator.GetAnimName(defaultAnimId))); | ||
165 | |||
166 | UUID implicitDefaultAnimId = anims.ImplicitDefaultAnimation.AnimID; | ||
167 | cdl.AddRow( | ||
168 | "Implicit default anim", | ||
169 | string.Format("{0}, {1}", | ||
170 | implicitDefaultAnimId, sp.Animator.GetAnimName(implicitDefaultAnimId))); | ||
171 | |||
172 | cdl.AddToStringBuilder(sb); | ||
173 | |||
174 | ConsoleDisplayTable cdt = new ConsoleDisplayTable() { Indent = 2 }; | ||
175 | cdt.AddColumn("Animation ID", 36); | ||
176 | cdt.AddColumn("Name", 20); | ||
177 | cdt.AddColumn("Seq", 3); | ||
178 | cdt.AddColumn("Object ID", 36); | ||
179 | |||
180 | UUID[] animIds; | ||
181 | int[] sequenceNumbers; | ||
182 | UUID[] objectIds; | ||
183 | |||
184 | sp.Animator.Animations.GetArrays(out animIds, out sequenceNumbers, out objectIds); | ||
185 | |||
186 | for (int i = 0; i < animIds.Length; i++) | ||
187 | { | ||
188 | UUID animId = animIds[i]; | ||
189 | string animName = sp.Animator.GetAnimName(animId); | ||
190 | int seq = sequenceNumbers[i]; | ||
191 | UUID objectId = objectIds[i]; | ||
192 | |||
193 | cdt.AddRow(animId, animName, seq, objectId); | ||
194 | } | ||
195 | |||
196 | cdt.AddToStringBuilder(sb); | ||
197 | sb.Append("\n"); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs index 68bcb4a..d97e3b3 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs | |||
@@ -97,6 +97,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments | |||
97 | "Users", this, "attachments show", | 97 | "Users", this, "attachments show", |
98 | "attachments show [<first-name> <last-name>]", | 98 | "attachments show [<first-name> <last-name>]", |
99 | "Show attachment information for avatars in this simulator.", | 99 | "Show attachment information for avatars in this simulator.", |
100 | "If no name is supplied then information for all avatars is shown.", | ||
100 | HandleShowAttachmentsCommand); | 101 | HandleShowAttachmentsCommand); |
101 | } | 102 | } |
102 | 103 | ||
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs index 66265d8..5a37fad 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs | |||
@@ -55,42 +55,42 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
55 | // These are the IRC Connector configurable parameters with hard-wired | 55 | // These are the IRC Connector configurable parameters with hard-wired |
56 | // default values (retained for compatability). | 56 | // default values (retained for compatability). |
57 | 57 | ||
58 | internal string Server = null; | 58 | internal string Server = null; |
59 | internal string Password = null; | 59 | internal string Password = null; |
60 | internal string IrcChannel = null; | 60 | internal string IrcChannel = null; |
61 | internal string BaseNickname = "OSimBot"; | 61 | internal string BaseNickname = "OSimBot"; |
62 | internal uint Port = 6667; | 62 | internal uint Port = 6667; |
63 | internal string User = null; | 63 | internal string User = null; |
64 | 64 | ||
65 | internal bool ClientReporting = true; | 65 | internal bool ClientReporting = true; |
66 | internal bool RelayChat = true; | 66 | internal bool RelayChat = true; |
67 | internal bool RelayPrivateChannels = false; | 67 | internal bool RelayPrivateChannels = false; |
68 | internal int RelayChannel = 1; | 68 | internal int RelayChannel = 1; |
69 | internal List<int> ValidInWorldChannels = new List<int>(); | 69 | internal List<int> ValidInWorldChannels = new List<int>(); |
70 | 70 | ||
71 | // Connector agnostic parameters. These values are NOT shared with the | 71 | // Connector agnostic parameters. These values are NOT shared with the |
72 | // connector and do not differentiate at an IRC level | 72 | // connector and do not differentiate at an IRC level |
73 | 73 | ||
74 | internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}"; | 74 | internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}"; |
75 | internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}"; | 75 | internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}"; |
76 | internal int RelayChannelOut = -1; | 76 | internal int RelayChannelOut = -1; |
77 | internal bool RandomizeNickname = true; | 77 | internal bool RandomizeNickname = true; |
78 | internal bool CommandsEnabled = false; | 78 | internal bool CommandsEnabled = false; |
79 | internal int CommandChannel = -1; | 79 | internal int CommandChannel = -1; |
80 | internal int ConnectDelay = 10; | 80 | internal int ConnectDelay = 10; |
81 | internal int PingDelay = 15; | 81 | internal int PingDelay = 15; |
82 | internal string DefaultZone = "Sim"; | 82 | internal string DefaultZone = "Sim"; |
83 | 83 | ||
84 | internal string _accessPassword = String.Empty; | 84 | internal string _accessPassword = String.Empty; |
85 | internal Regex AccessPasswordRegex = null; | 85 | internal Regex AccessPasswordRegex = null; |
86 | internal List<string> ExcludeList = new List<string>(); | 86 | internal List<string> ExcludeList = new List<string>(); |
87 | internal string AccessPassword | 87 | internal string AccessPassword |
88 | { | 88 | { |
89 | get { return _accessPassword; } | 89 | get { return _accessPassword; } |
90 | set | 90 | set |
91 | { | 91 | { |
92 | _accessPassword = value; | 92 | _accessPassword = value; |
93 | AccessPasswordRegex = new Regex(String.Format(@"^{0},\s*(?<avatar>[^,]+),\s*(?<message>.+)$", _accessPassword), | 93 | AccessPasswordRegex = new Regex(String.Format(@"^{0},\s*(?<avatar>[^,]+),\s*(?<message>.+)$", _accessPassword), |
94 | RegexOptions.Compiled); | 94 | RegexOptions.Compiled); |
95 | } | 95 | } |
96 | } | 96 | } |
@@ -99,9 +99,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
99 | 99 | ||
100 | // IRC connector reference | 100 | // IRC connector reference |
101 | 101 | ||
102 | internal IRCConnector irc = null; | 102 | internal IRCConnector irc = null; |
103 | 103 | ||
104 | internal int idn = _idk_++; | 104 | internal int idn = _idk_++; |
105 | 105 | ||
106 | // List of regions dependent upon this connection | 106 | // List of regions dependent upon this connection |
107 | 107 | ||
@@ -119,29 +119,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
119 | 119 | ||
120 | internal ChannelState(ChannelState model) | 120 | internal ChannelState(ChannelState model) |
121 | { | 121 | { |
122 | Server = model.Server; | 122 | Server = model.Server; |
123 | Password = model.Password; | 123 | Password = model.Password; |
124 | IrcChannel = model.IrcChannel; | 124 | IrcChannel = model.IrcChannel; |
125 | Port = model.Port; | 125 | Port = model.Port; |
126 | BaseNickname = model.BaseNickname; | 126 | BaseNickname = model.BaseNickname; |
127 | RandomizeNickname = model.RandomizeNickname; | 127 | RandomizeNickname = model.RandomizeNickname; |
128 | User = model.User; | 128 | User = model.User; |
129 | CommandsEnabled = model.CommandsEnabled; | 129 | CommandsEnabled = model.CommandsEnabled; |
130 | CommandChannel = model.CommandChannel; | 130 | CommandChannel = model.CommandChannel; |
131 | RelayChat = model.RelayChat; | 131 | RelayChat = model.RelayChat; |
132 | RelayPrivateChannels = model.RelayPrivateChannels; | 132 | RelayPrivateChannels = model.RelayPrivateChannels; |
133 | RelayChannelOut = model.RelayChannelOut; | 133 | RelayChannelOut = model.RelayChannelOut; |
134 | RelayChannel = model.RelayChannel; | 134 | RelayChannel = model.RelayChannel; |
135 | ValidInWorldChannels = model.ValidInWorldChannels; | 135 | ValidInWorldChannels = model.ValidInWorldChannels; |
136 | PrivateMessageFormat = model.PrivateMessageFormat; | 136 | PrivateMessageFormat = model.PrivateMessageFormat; |
137 | NoticeMessageFormat = model.NoticeMessageFormat; | 137 | NoticeMessageFormat = model.NoticeMessageFormat; |
138 | ClientReporting = model.ClientReporting; | 138 | ClientReporting = model.ClientReporting; |
139 | AccessPassword = model.AccessPassword; | 139 | AccessPassword = model.AccessPassword; |
140 | DefaultZone = model.DefaultZone; | 140 | DefaultZone = model.DefaultZone; |
141 | ConnectDelay = model.ConnectDelay; | 141 | ConnectDelay = model.ConnectDelay; |
142 | PingDelay = model.PingDelay; | 142 | PingDelay = model.PingDelay; |
143 | } | 143 | } |
144 | 144 | ||
145 | // Read the configuration file, performing variable substitution and any | 145 | // Read the configuration file, performing variable substitution and any |
146 | // necessary aliasing. See accompanying documentation for how this works. | 146 | // necessary aliasing. See accompanying documentation for how this works. |
147 | // If you don't need variables, then this works exactly as before. | 147 | // If you don't need variables, then this works exactly as before. |
@@ -160,54 +160,54 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
160 | 160 | ||
161 | m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region); | 161 | m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region); |
162 | 162 | ||
163 | cs.Server = Substitute(rs, config.GetString("server", null)); | 163 | cs.Server = Substitute(rs, config.GetString("server", null)); |
164 | m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server); | 164 | m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server); |
165 | cs.Password = Substitute(rs, config.GetString("password", null)); | 165 | cs.Password = Substitute(rs, config.GetString("password", null)); |
166 | // probably not a good idea to put a password in the log file | 166 | // probably not a good idea to put a password in the log file |
167 | cs.User = Substitute(rs, config.GetString("user", null)); | 167 | cs.User = Substitute(rs, config.GetString("user", null)); |
168 | cs.IrcChannel = Substitute(rs, config.GetString("channel", null)); | 168 | cs.IrcChannel = Substitute(rs, config.GetString("channel", null)); |
169 | m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel); | 169 | m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel); |
170 | cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port)))); | 170 | cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port)))); |
171 | m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port); | 171 | m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port); |
172 | cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname)); | 172 | cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname)); |
173 | m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname); | 173 | m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname); |
174 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname)))); | 174 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname)))); |
175 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); | 175 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); |
176 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname)))); | 176 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname)))); |
177 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); | 177 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); |
178 | cs.User = Substitute(rs, config.GetString("username", cs.User)); | 178 | cs.User = Substitute(rs, config.GetString("username", cs.User)); |
179 | m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User); | 179 | m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User); |
180 | cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled)))); | 180 | cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled)))); |
181 | m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled); | 181 | m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled); |
182 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel)))); | 182 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel)))); |
183 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); | 183 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); |
184 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("command_channel", Convert.ToString(cs.CommandChannel)))); | 184 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("command_channel", Convert.ToString(cs.CommandChannel)))); |
185 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); | 185 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); |
186 | cs.RelayChat = Convert.ToBoolean(Substitute(rs, config.GetString("relay_chat", Convert.ToString(cs.RelayChat)))); | 186 | cs.RelayChat = Convert.ToBoolean(Substitute(rs, config.GetString("relay_chat", Convert.ToString(cs.RelayChat)))); |
187 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChat : <{1}>", cs.idn, cs.RelayChat); | 187 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChat : <{1}>", cs.idn, cs.RelayChat); |
188 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("relay_private_channels", Convert.ToString(cs.RelayPrivateChannels)))); | 188 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("relay_private_channels", Convert.ToString(cs.RelayPrivateChannels)))); |
189 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); | 189 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); |
190 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels)))); | 190 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels)))); |
191 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); | 191 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); |
192 | cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut)))); | 192 | cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut)))); |
193 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut); | 193 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut); |
194 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel)))); | 194 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel)))); |
195 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); | 195 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); |
196 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel)))); | 196 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel)))); |
197 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); | 197 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); |
198 | cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat)); | 198 | cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat)); |
199 | m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat); | 199 | m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat); |
200 | cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat)); | 200 | cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat)); |
201 | m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat); | 201 | m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat); |
202 | cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting?"1":"0"))) > 0; | 202 | cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting ? "1" : "0"))) > 0; |
203 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); | 203 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); |
204 | cs.ClientReporting = Convert.ToBoolean(Substitute(rs, config.GetString("report_clients", Convert.ToString(cs.ClientReporting)))); | 204 | cs.ClientReporting = Convert.ToBoolean(Substitute(rs, config.GetString("report_clients", Convert.ToString(cs.ClientReporting)))); |
205 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); | 205 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); |
206 | cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone)); | 206 | cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone)); |
207 | m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, cs.DefaultZone); | 207 | m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, cs.DefaultZone); |
208 | cs.ConnectDelay = Convert.ToInt32(Substitute(rs, config.GetString("connect_delay", Convert.ToString(cs.ConnectDelay)))); | 208 | cs.ConnectDelay = Convert.ToInt32(Substitute(rs, config.GetString("connect_delay", Convert.ToString(cs.ConnectDelay)))); |
209 | m_log.DebugFormat("[IRC-Channel-{0}] ConnectDelay : <{1}>", cs.idn, cs.ConnectDelay); | 209 | m_log.DebugFormat("[IRC-Channel-{0}] ConnectDelay : <{1}>", cs.idn, cs.ConnectDelay); |
210 | cs.PingDelay = Convert.ToInt32(Substitute(rs, config.GetString("ping_delay", Convert.ToString(cs.PingDelay)))); | 210 | cs.PingDelay = Convert.ToInt32(Substitute(rs, config.GetString("ping_delay", Convert.ToString(cs.PingDelay)))); |
211 | m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay); | 211 | m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay); |
212 | cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword)); | 212 | cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword)); |
213 | m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword); | 213 | m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword); |
@@ -217,7 +217,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
217 | { | 217 | { |
218 | cs.ExcludeList.Add(name.Trim().ToLower()); | 218 | cs.ExcludeList.Add(name.Trim().ToLower()); |
219 | } | 219 | } |
220 | 220 | ||
221 | // Fail if fundamental information is still missing | 221 | // Fail if fundamental information is still missing |
222 | 222 | ||
223 | if (cs.Server == null) | 223 | if (cs.Server == null) |
@@ -306,8 +306,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
306 | 306 | ||
307 | IRCBridgeModule.m_channels.Add(cs); | 307 | IRCBridgeModule.m_channels.Add(cs); |
308 | 308 | ||
309 | m_log.InfoFormat("[IRC-Channel-{0}] New channel initialized for {1}, nick: {2}, commands {3}, private channels {4}", | 309 | m_log.InfoFormat("[IRC-Channel-{0}] New channel initialized for {1}, nick: {2}, commands {3}, private channels {4}", |
310 | cs.idn, rs.Region, cs.DefaultZone, | 310 | cs.idn, rs.Region, cs.DefaultZone, |
311 | cs.CommandsEnabled ? "enabled" : "not enabled", | 311 | cs.CommandsEnabled ? "enabled" : "not enabled", |
312 | cs.RelayPrivateChannels ? "relayed" : "not relayed"); | 312 | cs.RelayPrivateChannels ? "relayed" : "not relayed"); |
313 | } | 313 | } |
@@ -417,7 +417,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
417 | private bool IsAConnectionMatchFor(ChannelState cs) | 417 | private bool IsAConnectionMatchFor(ChannelState cs) |
418 | { | 418 | { |
419 | return ( | 419 | return ( |
420 | Server == cs.Server && | 420 | Server == cs.Server && |
421 | IrcChannel == cs.IrcChannel && | 421 | IrcChannel == cs.IrcChannel && |
422 | Port == cs.Port && | 422 | Port == cs.Port && |
423 | BaseNickname == cs.BaseNickname && | 423 | BaseNickname == cs.BaseNickname && |
@@ -473,27 +473,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
473 | { | 473 | { |
474 | 474 | ||
475 | string vvar = arg.Match(result).ToString(); | 475 | string vvar = arg.Match(result).ToString(); |
476 | string var = vvar.Substring(1,vvar.Length-2).Trim(); | 476 | string var = vvar.Substring(1, vvar.Length - 2).Trim(); |
477 | 477 | ||
478 | switch (var.ToLower()) | 478 | switch (var.ToLower()) |
479 | { | 479 | { |
480 | case "%region" : | 480 | case "%region": |
481 | result = result.Replace(vvar, rs.Region); | 481 | result = result.Replace(vvar, rs.Region); |
482 | break; | 482 | break; |
483 | case "%host" : | 483 | case "%host": |
484 | result = result.Replace(vvar, rs.Host); | 484 | result = result.Replace(vvar, rs.Host); |
485 | break; | 485 | break; |
486 | case "%locx" : | 486 | case "%locx": |
487 | result = result.Replace(vvar, rs.LocX); | 487 | result = result.Replace(vvar, rs.LocX); |
488 | break; | 488 | break; |
489 | case "%locy" : | 489 | case "%locy": |
490 | result = result.Replace(vvar, rs.LocY); | 490 | result = result.Replace(vvar, rs.LocY); |
491 | break; | 491 | break; |
492 | case "%k" : | 492 | case "%k": |
493 | result = result.Replace(vvar, rs.IDK); | 493 | result = result.Replace(vvar, rs.IDK); |
494 | break; | 494 | break; |
495 | default : | 495 | default: |
496 | result = result.Replace(vvar, rs.config.GetString(var,var)); | 496 | result = result.Replace(vvar, rs.config.GetString(var, var)); |
497 | break; | 497 | break; |
498 | } | 498 | } |
499 | // m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result); | 499 | // m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result); |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs index 2e1d03d..351dbfe 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs | |||
@@ -46,18 +46,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | internal static bool m_pluginEnabled = false; | 49 | internal static bool Enabled = false; |
50 | internal static IConfig m_config = null; | 50 | internal static IConfig m_config = null; |
51 | 51 | ||
52 | internal static List<ChannelState> m_channels = new List<ChannelState>(); | 52 | internal static List<ChannelState> m_channels = new List<ChannelState>(); |
53 | internal static List<RegionState> m_regions = new List<RegionState>(); | 53 | internal static List<RegionState> m_regions = new List<RegionState>(); |
54 | 54 | ||
55 | internal static string m_password = String.Empty; | 55 | internal static string m_password = String.Empty; |
56 | internal RegionState m_region = null; | 56 | internal RegionState m_region = null; |
57 | 57 | ||
58 | #region INonSharedRegionModule Members | 58 | #region INonSharedRegionModule Members |
59 | 59 | ||
60 | public Type ReplaceableInterface | 60 | public Type ReplaceableInterface |
61 | { | 61 | { |
62 | get { return null; } | 62 | get { return null; } |
63 | } | 63 | } |
@@ -72,13 +72,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
72 | m_config = config.Configs["IRC"]; | 72 | m_config = config.Configs["IRC"]; |
73 | if (m_config == null) | 73 | if (m_config == null) |
74 | { | 74 | { |
75 | // m_log.InfoFormat("[IRC-Bridge] module not configured"); | 75 | // m_log.InfoFormat("[IRC-Bridge] module not configured"); |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!m_config.GetBoolean("enabled", false)) | 79 | if (!m_config.GetBoolean("enabled", false)) |
80 | { | 80 | { |
81 | // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration"); | 81 | // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration"); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | 84 | ||
@@ -87,19 +87,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
87 | m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password); | 87 | m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password); |
88 | } | 88 | } |
89 | 89 | ||
90 | m_pluginEnabled = true; | 90 | Enabled = true; |
91 | m_log.InfoFormat("[IRC-Bridge]: Module enabled"); | 91 | |
92 | m_log.InfoFormat("[IRC-Bridge]: Module is enabled"); | ||
92 | } | 93 | } |
93 | 94 | ||
94 | public void AddRegion(Scene scene) | 95 | public void AddRegion(Scene scene) |
95 | { | 96 | { |
96 | if (m_pluginEnabled) | 97 | if (Enabled) |
97 | { | 98 | { |
98 | try | 99 | try |
99 | { | 100 | { |
100 | m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); | 101 | m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); |
102 | |||
101 | if (!String.IsNullOrEmpty(m_password)) | 103 | if (!String.IsNullOrEmpty(m_password)) |
102 | MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false); | 104 | MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false); |
105 | |||
103 | m_region = new RegionState(scene, m_config); | 106 | m_region = new RegionState(scene, m_config); |
104 | lock (m_regions) m_regions.Add(m_region); | 107 | lock (m_regions) m_regions.Add(m_region); |
105 | m_region.Open(); | 108 | m_region.Open(); |
@@ -123,7 +126,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
123 | 126 | ||
124 | public void RemoveRegion(Scene scene) | 127 | public void RemoveRegion(Scene scene) |
125 | { | 128 | { |
126 | if (!m_pluginEnabled) | 129 | if (!Enabled) |
127 | return; | 130 | return; |
128 | 131 | ||
129 | if (m_region == null) | 132 | if (m_region == null) |
@@ -150,12 +153,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
150 | m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry"); | 153 | m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry"); |
151 | 154 | ||
152 | XmlRpcResponse response = new XmlRpcResponse(); | 155 | XmlRpcResponse response = new XmlRpcResponse(); |
153 | Hashtable responseData = new Hashtable(); | 156 | Hashtable responseData = new Hashtable(); |
154 | 157 | ||
155 | try | 158 | try |
156 | { | 159 | { |
157 | Hashtable requestData = (Hashtable)request.Params[0]; | 160 | Hashtable requestData = (Hashtable)request.Params[0]; |
158 | bool found = false; | 161 | bool found = false; |
159 | string region = String.Empty; | 162 | string region = String.Empty; |
160 | 163 | ||
161 | if (m_password != String.Empty) | 164 | if (m_password != String.Empty) |
@@ -169,18 +172,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
169 | if (!requestData.ContainsKey("region")) | 172 | if (!requestData.ContainsKey("region")) |
170 | throw new Exception("No region name specified"); | 173 | throw new Exception("No region name specified"); |
171 | region = (string)requestData["region"]; | 174 | region = (string)requestData["region"]; |
172 | 175 | ||
173 | foreach (RegionState rs in m_regions) | 176 | foreach (RegionState rs in m_regions) |
174 | { | 177 | { |
175 | if (rs.Region == region) | 178 | if (rs.Region == region) |
176 | { | 179 | { |
177 | responseData["server"] = rs.cs.Server; | 180 | responseData["server"] = rs.cs.Server; |
178 | responseData["port"] = (int)rs.cs.Port; | 181 | responseData["port"] = (int)rs.cs.Port; |
179 | responseData["user"] = rs.cs.User; | 182 | responseData["user"] = rs.cs.User; |
180 | responseData["channel"] = rs.cs.IrcChannel; | 183 | responseData["channel"] = rs.cs.IrcChannel; |
181 | responseData["enabled"] = rs.cs.irc.Enabled; | 184 | responseData["enabled"] = rs.cs.irc.Enabled; |
182 | responseData["connected"] = rs.cs.irc.Connected; | 185 | responseData["connected"] = rs.cs.irc.Connected; |
183 | responseData["nickname"] = rs.cs.irc.Nick; | 186 | responseData["nickname"] = rs.cs.irc.Nick; |
184 | found = true; | 187 | found = true; |
185 | break; | 188 | break; |
186 | } | 189 | } |
@@ -195,7 +198,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
195 | m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message); | 198 | m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message); |
196 | 199 | ||
197 | responseData["success"] = "false"; | 200 | responseData["success"] = "false"; |
198 | responseData["error"] = e.Message; | 201 | responseData["error"] = e.Message; |
199 | } | 202 | } |
200 | finally | 203 | finally |
201 | { | 204 | { |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs index a014798..c5cba8e 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs | |||
@@ -53,16 +53,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
53 | // Local constants | 53 | // Local constants |
54 | 54 | ||
55 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); | 55 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); |
56 | private static readonly char[] CS_SPACE = { ' ' }; | 56 | private static readonly char[] CS_SPACE = { ' ' }; |
57 | 57 | ||
58 | private const int WD_INTERVAL = 1000; // base watchdog interval | 58 | private const int WD_INTERVAL = 1000; // base watchdog interval |
59 | private static int PING_PERIOD = 15; // WD intervals per PING | 59 | private static int PING_PERIOD = 15; // WD intervals per PING |
60 | private static int ICCD_PERIOD = 10; // WD intervals between Connects | 60 | private static int ICCD_PERIOD = 10; // WD intervals between Connects |
61 | private static int L_TIMEOUT = 25; // Login time out interval | 61 | private static int L_TIMEOUT = 25; // Login time out interval |
62 | 62 | ||
63 | private static int _idk_ = 0; // core connector identifier | 63 | private static int _idk_ = 0; // core connector identifier |
64 | private static int _pdk_ = 0; // ping interval counter | 64 | private static int _pdk_ = 0; // ping interval counter |
65 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter | 65 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter |
66 | 66 | ||
67 | // List of configured connectors | 67 | // List of configured connectors |
68 | 68 | ||
@@ -113,7 +113,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
113 | 113 | ||
114 | private Object msyncConnect = new Object(); | 114 | private Object msyncConnect = new Object(); |
115 | 115 | ||
116 | internal bool m_randomizeNick = true; // add random suffix | 116 | internal bool m_randomizeNick = true; // add random suffix |
117 | internal string m_baseNick = null; // base name for randomizing | 117 | internal string m_baseNick = null; // base name for randomizing |
118 | internal string m_nick = null; // effective nickname | 118 | internal string m_nick = null; // effective nickname |
119 | 119 | ||
@@ -122,7 +122,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
122 | get { return m_nick; } | 122 | get { return m_nick; } |
123 | set { m_nick = value; } | 123 | set { m_nick = value; } |
124 | } | 124 | } |
125 | 125 | ||
126 | private bool m_enabled = false; // connector enablement | 126 | private bool m_enabled = false; // connector enablement |
127 | public bool Enabled | 127 | public bool Enabled |
128 | { | 128 | { |
@@ -130,8 +130,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
130 | } | 130 | } |
131 | 131 | ||
132 | private bool m_connected = false; // connection status | 132 | private bool m_connected = false; // connection status |
133 | private bool m_pending = false; // login disposition | 133 | private bool m_pending = false; // login disposition |
134 | private int m_timeout = L_TIMEOUT; // login timeout counter | 134 | private int m_timeout = L_TIMEOUT; // login timeout counter |
135 | public bool Connected | 135 | public bool Connected |
136 | { | 136 | { |
137 | get { return m_connected; } | 137 | get { return m_connected; } |
@@ -143,9 +143,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
143 | get { return m_ircChannel; } | 143 | get { return m_ircChannel; } |
144 | set { m_ircChannel = value; } | 144 | set { m_ircChannel = value; } |
145 | } | 145 | } |
146 | 146 | ||
147 | private uint m_port = 6667; // session port | 147 | private uint m_port = 6667; // session port |
148 | public uint Port | 148 | public uint Port |
149 | { | 149 | { |
150 | get { return m_port; } | 150 | get { return m_port; } |
151 | set { m_port = value; } | 151 | set { m_port = value; } |
@@ -172,10 +172,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
172 | 172 | ||
173 | // Network interface | 173 | // Network interface |
174 | 174 | ||
175 | private TcpClient m_tcp; | 175 | private TcpClient m_tcp; |
176 | private NetworkStream m_stream = null; | 176 | private NetworkStream m_stream = null; |
177 | private StreamReader m_reader; | 177 | private StreamReader m_reader; |
178 | private StreamWriter m_writer; | 178 | private StreamWriter m_writer; |
179 | 179 | ||
180 | // Channel characteristic info (if available) | 180 | // Channel characteristic info (if available) |
181 | 181 | ||
@@ -193,26 +193,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
193 | 193 | ||
194 | // Prepare network interface | 194 | // Prepare network interface |
195 | 195 | ||
196 | m_tcp = null; | 196 | m_tcp = null; |
197 | m_writer = null; | 197 | m_writer = null; |
198 | m_reader = null; | 198 | m_reader = null; |
199 | 199 | ||
200 | // Setup IRC session parameters | 200 | // Setup IRC session parameters |
201 | 201 | ||
202 | m_server = cs.Server; | 202 | m_server = cs.Server; |
203 | m_password = cs.Password; | 203 | m_password = cs.Password; |
204 | m_baseNick = cs.BaseNickname; | 204 | m_baseNick = cs.BaseNickname; |
205 | m_randomizeNick = cs.RandomizeNickname; | 205 | m_randomizeNick = cs.RandomizeNickname; |
206 | m_ircChannel = cs.IrcChannel; | 206 | m_ircChannel = cs.IrcChannel; |
207 | m_port = cs.Port; | 207 | m_port = cs.Port; |
208 | m_user = cs.User; | 208 | m_user = cs.User; |
209 | 209 | ||
210 | if (m_watchdog == null) | 210 | if (m_watchdog == null) |
211 | { | 211 | { |
212 | // Non-differentiating | 212 | // Non-differentiating |
213 | 213 | ||
214 | ICCD_PERIOD = cs.ConnectDelay; | 214 | ICCD_PERIOD = cs.ConnectDelay; |
215 | PING_PERIOD = cs.PingDelay; | 215 | PING_PERIOD = cs.PingDelay; |
216 | 216 | ||
217 | // Smaller values are not reasonable | 217 | // Smaller values are not reasonable |
218 | 218 | ||
@@ -235,7 +235,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
235 | 235 | ||
236 | if (m_randomizeNick) | 236 | if (m_randomizeNick) |
237 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 237 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
238 | else | 238 | else |
239 | m_nick = m_baseNick; | 239 | m_nick = m_baseNick; |
240 | 240 | ||
241 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); | 241 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); |
@@ -295,18 +295,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
295 | m_nick, m_ircChannel, m_server)); | 295 | m_nick, m_ircChannel, m_server)); |
296 | m_writer.Flush(); | 296 | m_writer.Flush(); |
297 | } | 297 | } |
298 | catch (Exception) {} | 298 | catch (Exception) { } |
299 | 299 | ||
300 | 300 | ||
301 | m_connected = false; | 301 | m_connected = false; |
302 | 302 | ||
303 | try { m_writer.Close(); } catch (Exception) {} | 303 | try { m_writer.Close(); } |
304 | try { m_reader.Close(); } catch (Exception) {} | 304 | catch (Exception) { } |
305 | try { m_stream.Close(); } catch (Exception) {} | 305 | try { m_reader.Close(); } |
306 | try { m_tcp.Close(); } catch (Exception) {} | 306 | catch (Exception) { } |
307 | try { m_stream.Close(); } | ||
308 | catch (Exception) { } | ||
309 | try { m_tcp.Close(); } | ||
310 | catch (Exception) { } | ||
307 | 311 | ||
308 | } | 312 | } |
309 | 313 | ||
310 | lock (m_connectors) | 314 | lock (m_connectors) |
311 | m_connectors.Remove(this); | 315 | m_connectors.Remove(this); |
312 | 316 | ||
@@ -347,15 +351,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
347 | if (m_connected) return; | 351 | if (m_connected) return; |
348 | 352 | ||
349 | m_connected = true; | 353 | m_connected = true; |
350 | m_pending = true; | 354 | m_pending = true; |
351 | m_timeout = L_TIMEOUT; | 355 | m_timeout = L_TIMEOUT; |
352 | 356 | ||
353 | m_tcp = new TcpClient(m_server, (int)m_port); | 357 | m_tcp = new TcpClient(m_server, (int)m_port); |
354 | m_stream = m_tcp.GetStream(); | 358 | m_stream = m_tcp.GetStream(); |
355 | m_reader = new StreamReader(m_stream); | 359 | m_reader = new StreamReader(m_stream); |
356 | m_writer = new StreamWriter(m_stream); | 360 | m_writer = new StreamWriter(m_stream); |
357 | 361 | ||
358 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); | 362 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); |
359 | 363 | ||
360 | m_listener = new Thread(new ThreadStart(ListenerRun)); | 364 | m_listener = new Thread(new ThreadStart(ListenerRun)); |
361 | m_listener.Name = "IRCConnectorListenerThread"; | 365 | m_listener.Name = "IRCConnectorListenerThread"; |
@@ -418,12 +422,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
418 | // the socket and it will disappear of its own accord, once this | 422 | // the socket and it will disappear of its own accord, once this |
419 | // processing is completed. | 423 | // processing is completed. |
420 | 424 | ||
421 | try { m_writer.Close(); } catch (Exception) {} | 425 | try { m_writer.Close(); } |
422 | try { m_reader.Close(); } catch (Exception) {} | 426 | catch (Exception) { } |
423 | try { m_tcp.Close(); } catch (Exception) {} | 427 | try { m_reader.Close(); } |
428 | catch (Exception) { } | ||
429 | try { m_tcp.Close(); } | ||
430 | catch (Exception) { } | ||
424 | 431 | ||
425 | m_connected = false; | 432 | m_connected = false; |
426 | m_pending = false; | 433 | m_pending = false; |
427 | m_resetk++; | 434 | m_resetk++; |
428 | 435 | ||
429 | } | 436 | } |
@@ -495,7 +502,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
495 | { | 502 | { |
496 | 503 | ||
497 | string inputLine; | 504 | string inputLine; |
498 | int resetk = m_resetk; | 505 | int resetk = m_resetk; |
499 | 506 | ||
500 | try | 507 | try |
501 | { | 508 | { |
@@ -555,7 +562,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
555 | Reconnect(); | 562 | Reconnect(); |
556 | } | 563 | } |
557 | 564 | ||
558 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", | 565 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", |
559 | RegexOptions.Multiline); | 566 | RegexOptions.Multiline); |
560 | 567 | ||
561 | private Dictionary<string, string> ExtractMsg(string input) | 568 | private Dictionary<string, string> ExtractMsg(string input) |
@@ -617,8 +624,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
617 | string[] commArgs; | 624 | string[] commArgs; |
618 | string c_server = m_server; | 625 | string c_server = m_server; |
619 | 626 | ||
620 | string pfx = String.Empty; | 627 | string pfx = String.Empty; |
621 | string cmd = String.Empty; | 628 | string cmd = String.Empty; |
622 | string parms = String.Empty; | 629 | string parms = String.Empty; |
623 | 630 | ||
624 | // ":" indicates that a prefix is present | 631 | // ":" indicates that a prefix is present |
@@ -627,15 +634,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
627 | // ":" indicates that the remainder of the | 634 | // ":" indicates that the remainder of the |
628 | // line is a single parameter value. | 635 | // line is a single parameter value. |
629 | 636 | ||
630 | commArgs = command.Split(CS_SPACE,2); | 637 | commArgs = command.Split(CS_SPACE, 2); |
631 | 638 | ||
632 | if (commArgs[0].StartsWith(":")) | 639 | if (commArgs[0].StartsWith(":")) |
633 | { | 640 | { |
634 | pfx = commArgs[0].Substring(1); | 641 | pfx = commArgs[0].Substring(1); |
635 | commArgs = commArgs[1].Split(CS_SPACE,2); | 642 | commArgs = commArgs[1].Split(CS_SPACE, 2); |
636 | } | 643 | } |
637 | 644 | ||
638 | cmd = commArgs[0]; | 645 | cmd = commArgs[0]; |
639 | parms = commArgs[1]; | 646 | parms = commArgs[1]; |
640 | 647 | ||
641 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); | 648 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); |
@@ -646,44 +653,44 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
646 | // Messages 001-004 are always sent | 653 | // Messages 001-004 are always sent |
647 | // following signon. | 654 | // following signon. |
648 | 655 | ||
649 | case "001" : // Welcome ... | 656 | case "001": // Welcome ... |
650 | case "002" : // Server information | 657 | case "002": // Server information |
651 | case "003" : // Welcome ... | 658 | case "003": // Welcome ... |
652 | break; | 659 | break; |
653 | case "004" : // Server information | 660 | case "004": // Server information |
654 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 661 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
655 | commArgs = parms.Split(CS_SPACE); | 662 | commArgs = parms.Split(CS_SPACE); |
656 | c_server = commArgs[1]; | 663 | c_server = commArgs[1]; |
657 | m_server = c_server; | 664 | m_server = c_server; |
658 | version = commArgs[2]; | 665 | version = commArgs[2]; |
659 | usermod = commArgs[3]; | 666 | usermod = commArgs[3]; |
660 | chanmod = commArgs[4]; | 667 | chanmod = commArgs[4]; |
661 | break; | 668 | break; |
662 | case "005" : // Server information | 669 | case "005": // Server information |
663 | break; | 670 | break; |
664 | case "042" : | 671 | case "042": |
665 | case "250" : | 672 | case "250": |
666 | case "251" : | 673 | case "251": |
667 | case "252" : | 674 | case "252": |
668 | case "254" : | 675 | case "254": |
669 | case "255" : | 676 | case "255": |
670 | case "265" : | 677 | case "265": |
671 | case "266" : | 678 | case "266": |
672 | case "332" : // Subject | 679 | case "332": // Subject |
673 | case "333" : // Subject owner (?) | 680 | case "333": // Subject owner (?) |
674 | case "353" : // Name list | 681 | case "353": // Name list |
675 | case "366" : // End-of-Name list marker | 682 | case "366": // End-of-Name list marker |
676 | case "372" : // MOTD body | 683 | case "372": // MOTD body |
677 | case "375" : // MOTD start | 684 | case "375": // MOTD start |
678 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 685 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
679 | break; | 686 | break; |
680 | case "376" : // MOTD end | 687 | case "376": // MOTD end |
681 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 688 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
682 | motd = true; | 689 | motd = true; |
683 | break; | 690 | break; |
684 | case "451" : // Not registered | 691 | case "451": // Not registered |
685 | break; | 692 | break; |
686 | case "433" : // Nickname in use | 693 | case "433": // Nickname in use |
687 | // Gen a new name | 694 | // Gen a new name |
688 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 695 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
689 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); | 696 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); |
@@ -695,29 +702,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
695 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); | 702 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); |
696 | m_writer.Flush(); | 703 | m_writer.Flush(); |
697 | break; | 704 | break; |
698 | case "479" : // Bad channel name, etc. This will never work, so disable the connection | 705 | case "479": // Bad channel name, etc. This will never work, so disable the connection |
699 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 706 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
700 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); | 707 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); |
701 | m_enabled = false; | 708 | m_enabled = false; |
702 | m_connected = false; | 709 | m_connected = false; |
703 | m_pending = false; | 710 | m_pending = false; |
704 | break; | 711 | break; |
705 | case "NOTICE" : | 712 | case "NOTICE": |
706 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 713 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
707 | break; | 714 | break; |
708 | case "ERROR" : | 715 | case "ERROR": |
709 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 716 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
710 | if (parms.Contains("reconnect too fast")) | 717 | if (parms.Contains("reconnect too fast")) |
711 | ICCD_PERIOD++; | 718 | ICCD_PERIOD++; |
712 | m_pending = false; | 719 | m_pending = false; |
713 | Reconnect(); | 720 | Reconnect(); |
714 | break; | 721 | break; |
715 | case "PING" : | 722 | case "PING": |
716 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 723 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
717 | m_writer.WriteLine(String.Format("PONG {0}", parms)); | 724 | m_writer.WriteLine(String.Format("PONG {0}", parms)); |
718 | m_writer.Flush(); | 725 | m_writer.Flush(); |
719 | break; | 726 | break; |
720 | case "PONG" : | 727 | case "PONG": |
721 | break; | 728 | break; |
722 | case "JOIN": | 729 | case "JOIN": |
723 | if (m_pending) | 730 | if (m_pending) |
@@ -748,19 +755,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
748 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 755 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
749 | eventIrcQuit(pfx, cmd, parms); | 756 | eventIrcQuit(pfx, cmd, parms); |
750 | break; | 757 | break; |
751 | default : | 758 | default: |
752 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); | 759 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); |
753 | break; | 760 | break; |
754 | } | 761 | } |
755 | 762 | ||
756 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); | 763 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); |
757 | 764 | ||
758 | } | 765 | } |
759 | 766 | ||
760 | public void eventIrcJoin(string prefix, string command, string parms) | 767 | public void eventIrcJoin(string prefix, string command, string parms) |
761 | { | 768 | { |
762 | string[] args = parms.Split(CS_SPACE,2); | 769 | string[] args = parms.Split(CS_SPACE, 2); |
763 | string IrcUser = prefix.Split('!')[0]; | 770 | string IrcUser = prefix.Split('!')[0]; |
764 | string IrcChannel = args[0]; | 771 | string IrcChannel = args[0]; |
765 | 772 | ||
766 | if (IrcChannel.StartsWith(":")) | 773 | if (IrcChannel.StartsWith(":")) |
@@ -772,8 +779,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
772 | 779 | ||
773 | public void eventIrcPart(string prefix, string command, string parms) | 780 | public void eventIrcPart(string prefix, string command, string parms) |
774 | { | 781 | { |
775 | string[] args = parms.Split(CS_SPACE,2); | 782 | string[] args = parms.Split(CS_SPACE, 2); |
776 | string IrcUser = prefix.Split('!')[0]; | 783 | string IrcUser = prefix.Split('!')[0]; |
777 | string IrcChannel = args[0]; | 784 | string IrcChannel = args[0]; |
778 | 785 | ||
779 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); | 786 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); |
@@ -782,7 +789,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
782 | 789 | ||
783 | public void eventIrcMode(string prefix, string command, string parms) | 790 | public void eventIrcMode(string prefix, string command, string parms) |
784 | { | 791 | { |
785 | string[] args = parms.Split(CS_SPACE,2); | 792 | string[] args = parms.Split(CS_SPACE, 2); |
786 | string UserMode = args[1]; | 793 | string UserMode = args[1]; |
787 | 794 | ||
788 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); | 795 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); |
@@ -794,7 +801,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
794 | 801 | ||
795 | public void eventIrcNickChange(string prefix, string command, string parms) | 802 | public void eventIrcNickChange(string prefix, string command, string parms) |
796 | { | 803 | { |
797 | string[] args = parms.Split(CS_SPACE,2); | 804 | string[] args = parms.Split(CS_SPACE, 2); |
798 | string UserOldNick = prefix.Split('!')[0]; | 805 | string UserOldNick = prefix.Split('!')[0]; |
799 | string UserNewNick = args[0].Remove(0, 1); | 806 | string UserNewNick = args[0].Remove(0, 1); |
800 | 807 | ||
@@ -804,11 +811,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
804 | 811 | ||
805 | public void eventIrcKick(string prefix, string command, string parms) | 812 | public void eventIrcKick(string prefix, string command, string parms) |
806 | { | 813 | { |
807 | string[] args = parms.Split(CS_SPACE,3); | 814 | string[] args = parms.Split(CS_SPACE, 3); |
808 | string UserKicker = prefix.Split('!')[0]; | 815 | string UserKicker = prefix.Split('!')[0]; |
809 | string IrcChannel = args[0]; | 816 | string IrcChannel = args[0]; |
810 | string UserKicked = args[1]; | 817 | string UserKicked = args[1]; |
811 | string KickMessage = args[2]; | 818 | string KickMessage = args[2]; |
812 | 819 | ||
813 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); | 820 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); |
814 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); | 821 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); |
@@ -822,7 +829,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
822 | 829 | ||
823 | public void eventIrcQuit(string prefix, string command, string parms) | 830 | public void eventIrcQuit(string prefix, string command, string parms) |
824 | { | 831 | { |
825 | string IrcUser = prefix.Split('!')[0]; | 832 | string IrcUser = prefix.Split('!')[0]; |
826 | string QuitMessage = parms; | 833 | string QuitMessage = parms; |
827 | 834 | ||
828 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); | 835 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); |
@@ -842,65 +849,65 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
842 | 849 | ||
843 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); | 850 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); |
844 | 851 | ||
845 | _pdk_ = (_pdk_+1)%PING_PERIOD; // cycle the ping trigger | 852 | _pdk_ = (_pdk_ + 1) % PING_PERIOD; // cycle the ping trigger |
846 | _icc_++; // increment the inter-consecutive-connect-delay counter | 853 | _icc_++; // increment the inter-consecutive-connect-delay counter |
847 | 854 | ||
848 | lock (m_connectors) | 855 | lock (m_connectors) |
849 | foreach (IRCConnector connector in m_connectors) | 856 | foreach (IRCConnector connector in m_connectors) |
850 | { | 857 | { |
851 | 858 | ||
852 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); | 859 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); |
853 | 860 | ||
854 | if (connector.Enabled) | 861 | if (connector.Enabled) |
855 | { | ||
856 | if (!connector.Connected) | ||
857 | { | 862 | { |
858 | try | 863 | if (!connector.Connected) |
859 | { | 864 | { |
860 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | 865 | try |
861 | connector.Connect(); | 866 | { |
867 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | ||
868 | connector.Connect(); | ||
869 | } | ||
870 | catch (Exception e) | ||
871 | { | ||
872 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
873 | } | ||
862 | } | 874 | } |
863 | catch (Exception e) | 875 | else |
864 | { | 876 | { |
865 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
866 | } | ||
867 | } | ||
868 | else | ||
869 | { | ||
870 | 877 | ||
871 | if (connector.m_pending) | 878 | if (connector.m_pending) |
872 | { | ||
873 | if (connector.m_timeout == 0) | ||
874 | { | 879 | { |
875 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | 880 | if (connector.m_timeout == 0) |
876 | connector.Reconnect(); | 881 | { |
882 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | ||
883 | connector.Reconnect(); | ||
884 | } | ||
885 | else | ||
886 | connector.m_timeout--; | ||
877 | } | 887 | } |
878 | else | ||
879 | connector.m_timeout--; | ||
880 | } | ||
881 | 888 | ||
882 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long | 889 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long |
883 | // time, in which case the watch dog might try to ping the server before the socket has been | 890 | // time, in which case the watch dog might try to ping the server before the socket has been |
884 | // set up, with nasty side-effects. | 891 | // set up, with nasty side-effects. |
885 | 892 | ||
886 | else if (_pdk_ == 0) | 893 | else if (_pdk_ == 0) |
887 | { | ||
888 | try | ||
889 | { | ||
890 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); | ||
891 | connector.m_writer.Flush(); | ||
892 | } | ||
893 | catch (Exception e) | ||
894 | { | 894 | { |
895 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | 895 | try |
896 | m_log.Debug(e); | 896 | { |
897 | connector.Reconnect(); | 897 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); |
898 | connector.m_writer.Flush(); | ||
899 | } | ||
900 | catch (Exception e) | ||
901 | { | ||
902 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
903 | m_log.Debug(e); | ||
904 | connector.Reconnect(); | ||
905 | } | ||
898 | } | 906 | } |
899 | } | ||
900 | 907 | ||
908 | } | ||
901 | } | 909 | } |
902 | } | 910 | } |
903 | } | ||
904 | 911 | ||
905 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); | 912 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); |
906 | 913 | ||
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs index 53b103e..d4fe5e0 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs | |||
@@ -41,49 +41,71 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
41 | 41 | ||
42 | internal class RegionState | 42 | internal class RegionState |
43 | { | 43 | { |
44 | |||
45 | private static readonly ILog m_log = | 44 | private static readonly ILog m_log = |
46 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 46 | ||
48 | private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); | 47 | private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); |
49 | private const int DEBUG_CHANNEL = 2147483647; | 48 | private const int DEBUG_CHANNEL = 2147483647; |
50 | 49 | ||
51 | private static int _idk_ = 0; | 50 | private static int _idk_ = 0; |
52 | 51 | ||
53 | // Runtime variables; these values are assigned when the | 52 | // Runtime variables; these values are assigned when the |
54 | // IrcState is created and remain constant thereafter. | 53 | // IrcState is created and remain constant thereafter. |
55 | 54 | ||
56 | internal string Region = String.Empty; | 55 | internal string Region = String.Empty; |
57 | internal string Host = String.Empty; | 56 | internal string Host = String.Empty; |
58 | internal string LocX = String.Empty; | 57 | internal string LocX = String.Empty; |
59 | internal string LocY = String.Empty; | 58 | internal string LocY = String.Empty; |
60 | internal string IDK = String.Empty; | 59 | internal string IDK = String.Empty; |
61 | 60 | ||
62 | // System values - used only be the IRC classes themselves | 61 | // System values - used only be the IRC classes themselves |
63 | 62 | ||
64 | internal ChannelState cs = null; // associated IRC configuration | 63 | internal ChannelState cs = null; // associated IRC configuration |
65 | internal Scene scene = null; // associated scene | 64 | internal Scene scene = null; // associated scene |
66 | internal IConfig config = null; // configuration file reference | 65 | internal IConfig config = null; // configuration file reference |
67 | internal bool enabled = true; | 66 | internal bool enabled = true; |
68 | 67 | ||
68 | //AgentAlert | ||
69 | internal bool showAlert = false; | ||
70 | internal string alertMessage = String.Empty; | ||
71 | internal IDialogModule dialogModule = null; | ||
72 | |||
69 | // This list is used to keep track of who is here, and by | 73 | // This list is used to keep track of who is here, and by |
70 | // implication, who is not. | 74 | // implication, who is not. |
71 | 75 | ||
72 | internal List<IClientAPI> clients = new List<IClientAPI>(); | 76 | internal List<IClientAPI> clients = new List<IClientAPI>(); |
73 | 77 | ||
74 | // Setup runtime variable values | 78 | // Setup runtime variable values |
75 | 79 | ||
76 | public RegionState(Scene p_scene, IConfig p_config) | 80 | public RegionState(Scene p_scene, IConfig p_config) |
77 | { | 81 | { |
78 | 82 | scene = p_scene; | |
79 | scene = p_scene; | ||
80 | config = p_config; | 83 | config = p_config; |
81 | 84 | ||
82 | Region = scene.RegionInfo.RegionName; | 85 | Region = scene.RegionInfo.RegionName; |
83 | Host = scene.RegionInfo.ExternalHostName; | 86 | Host = scene.RegionInfo.ExternalHostName; |
84 | LocX = Convert.ToString(scene.RegionInfo.RegionLocX); | 87 | LocX = Convert.ToString(scene.RegionInfo.RegionLocX); |
85 | LocY = Convert.ToString(scene.RegionInfo.RegionLocY); | 88 | LocY = Convert.ToString(scene.RegionInfo.RegionLocY); |
86 | IDK = Convert.ToString(_idk_++); | 89 | IDK = Convert.ToString(_idk_++); |
90 | |||
91 | showAlert = config.GetBoolean("alert_show", false); | ||
92 | string alertServerInfo = String.Empty; | ||
93 | |||
94 | if (showAlert) | ||
95 | { | ||
96 | bool showAlertServerInfo = config.GetBoolean("alert_show_serverinfo", true); | ||
97 | |||
98 | if (showAlertServerInfo) | ||
99 | alertServerInfo = String.Format("\nServer: {0}\nPort: {1}\nChannel: {2}\n\n", | ||
100 | config.GetString("server", ""), config.GetString("port", ""), config.GetString("channel", "")); | ||
101 | |||
102 | string alertPreMessage = config.GetString("alert_msg_pre", "This region is linked to Irc."); | ||
103 | string alertPostMessage = config.GetString("alert_msg_post", "Everything you say in public chat can be listened."); | ||
104 | |||
105 | alertMessage = String.Format("{0}\n{1}{2}", alertPreMessage, alertServerInfo, alertPostMessage); | ||
106 | |||
107 | dialogModule = scene.RequestModuleInterface<IDialogModule>(); | ||
108 | } | ||
87 | 109 | ||
88 | // OpenChannel conditionally establishes a connection to the | 110 | // OpenChannel conditionally establishes a connection to the |
89 | // IRC server. The request will either succeed, or it will | 111 | // IRC server. The request will either succeed, or it will |
@@ -93,9 +115,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
93 | 115 | ||
94 | // Connect channel to world events | 116 | // Connect channel to world events |
95 | 117 | ||
96 | scene.EventManager.OnChatFromWorld += OnSimChat; | 118 | scene.EventManager.OnChatFromWorld += OnSimChat; |
97 | scene.EventManager.OnChatFromClient += OnSimChat; | 119 | scene.EventManager.OnChatFromClient += OnSimChat; |
98 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | 120 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; |
99 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; | 121 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; |
100 | 122 | ||
101 | m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region); | 123 | m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region); |
@@ -106,8 +128,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
106 | 128 | ||
107 | ~RegionState() | 129 | ~RegionState() |
108 | { | 130 | { |
109 | if (cs != null) | 131 | if (cs != null) |
110 | cs.RemoveRegion(this); | 132 | cs.RemoveRegion(this); |
111 | } | 133 | } |
112 | 134 | ||
113 | // Called by PostInitialize after all regions have been created | 135 | // Called by PostInitialize after all regions have been created |
@@ -138,7 +160,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
138 | { | 160 | { |
139 | if (clients.Contains(client)) | 161 | if (clients.Contains(client)) |
140 | { | 162 | { |
141 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) | 163 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) |
142 | { | 164 | { |
143 | m_log.InfoFormat("[IRC-Region {0}]: {1} has left", Region, client.Name); | 165 | m_log.InfoFormat("[IRC-Region {0}]: {1} has left", Region, client.Name); |
144 | //Check if this person is excluded from IRC | 166 | //Check if this person is excluded from IRC |
@@ -147,7 +169,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
147 | cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name)); | 169 | cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name)); |
148 | } | 170 | } |
149 | } | 171 | } |
150 | client.OnLogout -= OnClientLoggedOut; | 172 | client.OnLogout -= OnClientLoggedOut; |
151 | client.OnConnectionClosed -= OnClientLoggedOut; | 173 | client.OnConnectionClosed -= OnClientLoggedOut; |
152 | clients.Remove(client); | 174 | clients.Remove(client); |
153 | } | 175 | } |
@@ -171,13 +193,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
171 | { | 193 | { |
172 | if (clients.Contains(client)) | 194 | if (clients.Contains(client)) |
173 | { | 195 | { |
174 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) | 196 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) |
175 | { | 197 | { |
176 | string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname); | 198 | string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname); |
177 | m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName); | 199 | m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName); |
178 | cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName)); | 200 | cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName)); |
179 | } | 201 | } |
180 | client.OnLogout -= OnClientLoggedOut; | 202 | client.OnLogout -= OnClientLoggedOut; |
181 | client.OnConnectionClosed -= OnClientLoggedOut; | 203 | client.OnConnectionClosed -= OnClientLoggedOut; |
182 | clients.Remove(client); | 204 | clients.Remove(client); |
183 | } | 205 | } |
@@ -195,14 +217,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
195 | 217 | ||
196 | private void OnMakeRootAgent(ScenePresence presence) | 218 | private void OnMakeRootAgent(ScenePresence presence) |
197 | { | 219 | { |
198 | |||
199 | IClientAPI client = presence.ControllingClient; | 220 | IClientAPI client = presence.ControllingClient; |
200 | 221 | ||
201 | try | 222 | try |
202 | { | 223 | { |
203 | if (!clients.Contains(client)) | 224 | if (!clients.Contains(client)) |
204 | { | 225 | { |
205 | client.OnLogout += OnClientLoggedOut; | 226 | client.OnLogout += OnClientLoggedOut; |
206 | client.OnConnectionClosed += OnClientLoggedOut; | 227 | client.OnConnectionClosed += OnClientLoggedOut; |
207 | clients.Add(client); | 228 | clients.Add(client); |
208 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) | 229 | if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) |
@@ -216,17 +237,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
216 | } | 237 | } |
217 | } | 238 | } |
218 | } | 239 | } |
240 | |||
241 | if (dialogModule != null && showAlert) | ||
242 | dialogModule.SendAlertToUser(client, alertMessage, true); | ||
219 | } | 243 | } |
220 | catch (Exception ex) | 244 | catch (Exception ex) |
221 | { | 245 | { |
222 | m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message); | 246 | m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message); |
223 | m_log.Debug(ex); | 247 | m_log.Debug(ex); |
224 | } | 248 | } |
225 | |||
226 | } | 249 | } |
227 | 250 | ||
228 | // This handler detects chat events int he virtual world. | 251 | // This handler detects chat events int he virtual world. |
229 | |||
230 | public void OnSimChat(Object sender, OSChatMessage msg) | 252 | public void OnSimChat(Object sender, OSChatMessage msg) |
231 | { | 253 | { |
232 | 254 | ||
@@ -317,14 +339,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
317 | // that evident. | 339 | // that evident. |
318 | 340 | ||
319 | default: | 341 | default: |
320 | m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}", | 342 | m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}", |
321 | Region, msg.Message); | 343 | Region, msg.Message); |
322 | cs.irc.Send(msg.Message); | 344 | cs.irc.Send(msg.Message); |
323 | break; | 345 | break; |
324 | } | 346 | } |
325 | } | 347 | } |
326 | catch (Exception ex) | 348 | catch (Exception ex) |
327 | { | 349 | { |
328 | m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}", | 350 | m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}", |
329 | Region, ex.Message); | 351 | Region, ex.Message); |
330 | m_log.Debug(ex); | 352 | m_log.Debug(ex); |
@@ -366,7 +388,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
366 | 388 | ||
367 | m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message); | 389 | m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message); |
368 | 390 | ||
369 | if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL)) | 391 | if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL)) |
370 | { | 392 | { |
371 | string txt = msg.Message; | 393 | string txt = msg.Message; |
372 | if (txt.StartsWith("/me ")) | 394 | if (txt.StartsWith("/me ")) |
@@ -376,13 +398,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
376 | return; | 398 | return; |
377 | } | 399 | } |
378 | 400 | ||
379 | if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword && | 401 | if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword && |
380 | msg.Channel == cs.RelayChannelOut) | 402 | msg.Channel == cs.RelayChannelOut) |
381 | { | 403 | { |
382 | Match m = cs.AccessPasswordRegex.Match(msg.Message); | 404 | Match m = cs.AccessPasswordRegex.Match(msg.Message); |
383 | if (null != m) | 405 | if (null != m) |
384 | { | 406 | { |
385 | m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), | 407 | m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), |
386 | m.Groups["message"].ToString()); | 408 | m.Groups["message"].ToString()); |
387 | cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(), | 409 | cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(), |
388 | scene.RegionInfo.RegionName, m.Groups["message"].ToString()); | 410 | scene.RegionInfo.RegionName, m.Groups["message"].ToString()); |
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index ae0ad02..d764936 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs | |||
@@ -126,7 +126,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
126 | { | 126 | { |
127 | scene.RegisterModuleInterface<IGroupsModule>(this); | 127 | scene.RegisterModuleInterface<IGroupsModule>(this); |
128 | scene.AddCommand( | 128 | scene.AddCommand( |
129 | "debug", | 129 | "Debug", |
130 | this, | 130 | this, |
131 | "debug groups verbose", | 131 | "debug groups verbose", |
132 | "debug groups verbose <true|false>", | 132 | "debug groups verbose <true|false>", |
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs index 6d26075..6b5b40a 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs | |||
@@ -36,7 +36,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
36 | { | 36 | { |
37 | UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, UUID founderID); | 37 | UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, UUID founderID); |
38 | void UpdateGroup(UUID RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish); | 38 | void UpdateGroup(UUID RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish); |
39 | |||
40 | /// <summary> | ||
41 | /// Get the group record. | ||
42 | /// </summary> | ||
43 | /// <returns></returns> | ||
44 | /// <param name='RequestingAgentID'>The UUID of the user making the request.</param> | ||
45 | /// <param name='GroupID'> | ||
46 | /// The ID of the record to retrieve. | ||
47 | /// GroupName may be specified instead, in which case this parameter will be UUID.Zero | ||
48 | /// </param> | ||
49 | /// <param name='GroupName'> | ||
50 | /// The name of the group to retrieve. | ||
51 | /// GroupID may be specified instead, in which case this parmeter will be null. | ||
52 | /// </param> | ||
39 | GroupRecord GetGroupRecord(UUID RequestingAgentID, UUID GroupID, string GroupName); | 53 | GroupRecord GetGroupRecord(UUID RequestingAgentID, UUID GroupID, string GroupName); |
54 | |||
40 | List<DirGroupsReplyData> FindGroups(UUID RequestingAgentID, string search); | 55 | List<DirGroupsReplyData> FindGroups(UUID RequestingAgentID, string search); |
41 | List<GroupMembersData> GetGroupMembers(UUID RequestingAgentID, UUID GroupID); | 56 | List<GroupMembersData> GetGroupMembers(UUID RequestingAgentID, UUID GroupID); |
42 | 57 | ||
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs index ac638f1..c1bdacb 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs | |||
@@ -42,7 +42,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests | |||
42 | /// Basic groups module tests | 42 | /// Basic groups module tests |
43 | /// </summary> | 43 | /// </summary> |
44 | [TestFixture] | 44 | [TestFixture] |
45 | public class GroupsModuleTests | 45 | public class GroupsModuleTests : OpenSimTestCase |
46 | { | 46 | { |
47 | [Test] | 47 | [Test] |
48 | public void TestBasic() | 48 | public void TestBasic() |
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index d0c3ea5..1101851 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | |||
@@ -54,13 +54,62 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
54 | 54 | ||
55 | private bool m_debugEnabled = false; | 55 | private bool m_debugEnabled = false; |
56 | 56 | ||
57 | public const GroupPowers m_DefaultEveryonePowers = GroupPowers.AllowSetHome | | 57 | public const GroupPowers DefaultEveryonePowers |
58 | GroupPowers.Accountable | | 58 | = GroupPowers.AllowSetHome |
59 | GroupPowers.JoinChat | | 59 | | GroupPowers.Accountable |
60 | GroupPowers.AllowVoiceChat | | 60 | | GroupPowers.JoinChat |
61 | GroupPowers.ReceiveNotices | | 61 | | GroupPowers.AllowVoiceChat |
62 | GroupPowers.StartProposal | | 62 | | GroupPowers.ReceiveNotices |
63 | GroupPowers.VoteOnProposal; | 63 | | GroupPowers.StartProposal |
64 | | GroupPowers.VoteOnProposal; | ||
65 | |||
66 | // Would this be cleaner as (GroupPowers)ulong.MaxValue? | ||
67 | public const GroupPowers DefaultOwnerPowers | ||
68 | = GroupPowers.Accountable | ||
69 | | GroupPowers.AllowEditLand | ||
70 | | GroupPowers.AllowFly | ||
71 | | GroupPowers.AllowLandmark | ||
72 | | GroupPowers.AllowRez | ||
73 | | GroupPowers.AllowSetHome | ||
74 | | GroupPowers.AllowVoiceChat | ||
75 | | GroupPowers.AssignMember | ||
76 | | GroupPowers.AssignMemberLimited | ||
77 | | GroupPowers.ChangeActions | ||
78 | | GroupPowers.ChangeIdentity | ||
79 | | GroupPowers.ChangeMedia | ||
80 | | GroupPowers.ChangeOptions | ||
81 | | GroupPowers.CreateRole | ||
82 | | GroupPowers.DeedObject | ||
83 | | GroupPowers.DeleteRole | ||
84 | | GroupPowers.Eject | ||
85 | | GroupPowers.FindPlaces | ||
86 | | GroupPowers.Invite | ||
87 | | GroupPowers.JoinChat | ||
88 | | GroupPowers.LandChangeIdentity | ||
89 | | GroupPowers.LandDeed | ||
90 | | GroupPowers.LandDivideJoin | ||
91 | | GroupPowers.LandEdit | ||
92 | | GroupPowers.LandEjectAndFreeze | ||
93 | | GroupPowers.LandGardening | ||
94 | | GroupPowers.LandManageAllowed | ||
95 | | GroupPowers.LandManageBanned | ||
96 | | GroupPowers.LandManagePasses | ||
97 | | GroupPowers.LandOptions | ||
98 | | GroupPowers.LandRelease | ||
99 | | GroupPowers.LandSetSale | ||
100 | | GroupPowers.ModerateChat | ||
101 | | GroupPowers.ObjectManipulate | ||
102 | | GroupPowers.ObjectSetForSale | ||
103 | | GroupPowers.ReceiveNotices | ||
104 | | GroupPowers.RemoveMember | ||
105 | | GroupPowers.ReturnGroupOwned | ||
106 | | GroupPowers.ReturnGroupSet | ||
107 | | GroupPowers.ReturnNonGroup | ||
108 | | GroupPowers.RoleProperties | ||
109 | | GroupPowers.SendNotices | ||
110 | | GroupPowers.SetLandingPoint | ||
111 | | GroupPowers.StartProposal | ||
112 | | GroupPowers.VoteOnProposal; | ||
64 | 113 | ||
65 | private bool m_connectorEnabled = false; | 114 | private bool m_connectorEnabled = false; |
66 | 115 | ||
@@ -219,59 +268,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
219 | param["AllowPublish"] = allowPublish == true ? 1 : 0; | 268 | param["AllowPublish"] = allowPublish == true ? 1 : 0; |
220 | param["MaturePublish"] = maturePublish == true ? 1 : 0; | 269 | param["MaturePublish"] = maturePublish == true ? 1 : 0; |
221 | param["FounderID"] = founderID.ToString(); | 270 | param["FounderID"] = founderID.ToString(); |
222 | param["EveryonePowers"] = ((ulong)m_DefaultEveryonePowers).ToString(); | 271 | param["EveryonePowers"] = ((ulong)DefaultEveryonePowers).ToString(); |
223 | param["OwnerRoleID"] = OwnerRoleID.ToString(); | 272 | param["OwnerRoleID"] = OwnerRoleID.ToString(); |
224 | 273 | param["OwnersPowers"] = ((ulong)DefaultOwnerPowers).ToString(); | |
225 | // Would this be cleaner as (GroupPowers)ulong.MaxValue; | ||
226 | GroupPowers OwnerPowers = GroupPowers.Accountable | ||
227 | | GroupPowers.AllowEditLand | ||
228 | | GroupPowers.AllowFly | ||
229 | | GroupPowers.AllowLandmark | ||
230 | | GroupPowers.AllowRez | ||
231 | | GroupPowers.AllowSetHome | ||
232 | | GroupPowers.AllowVoiceChat | ||
233 | | GroupPowers.AssignMember | ||
234 | | GroupPowers.AssignMemberLimited | ||
235 | | GroupPowers.ChangeActions | ||
236 | | GroupPowers.ChangeIdentity | ||
237 | | GroupPowers.ChangeMedia | ||
238 | | GroupPowers.ChangeOptions | ||
239 | | GroupPowers.CreateRole | ||
240 | | GroupPowers.DeedObject | ||
241 | | GroupPowers.DeleteRole | ||
242 | | GroupPowers.Eject | ||
243 | | GroupPowers.FindPlaces | ||
244 | | GroupPowers.Invite | ||
245 | | GroupPowers.JoinChat | ||
246 | | GroupPowers.LandChangeIdentity | ||
247 | | GroupPowers.LandDeed | ||
248 | | GroupPowers.LandDivideJoin | ||
249 | | GroupPowers.LandEdit | ||
250 | | GroupPowers.LandEjectAndFreeze | ||
251 | | GroupPowers.LandGardening | ||
252 | | GroupPowers.LandManageAllowed | ||
253 | | GroupPowers.LandManageBanned | ||
254 | | GroupPowers.LandManagePasses | ||
255 | | GroupPowers.LandOptions | ||
256 | | GroupPowers.LandRelease | ||
257 | | GroupPowers.LandSetSale | ||
258 | | GroupPowers.ModerateChat | ||
259 | | GroupPowers.ObjectManipulate | ||
260 | | GroupPowers.ObjectSetForSale | ||
261 | | GroupPowers.ReceiveNotices | ||
262 | | GroupPowers.RemoveMember | ||
263 | | GroupPowers.ReturnGroupOwned | ||
264 | | GroupPowers.ReturnGroupSet | ||
265 | | GroupPowers.ReturnNonGroup | ||
266 | | GroupPowers.RoleProperties | ||
267 | | GroupPowers.SendNotices | ||
268 | | GroupPowers.SetLandingPoint | ||
269 | | GroupPowers.StartProposal | ||
270 | | GroupPowers.VoteOnProposal; | ||
271 | param["OwnersPowers"] = ((ulong)OwnerPowers).ToString(); | ||
272 | |||
273 | |||
274 | |||
275 | 274 | ||
276 | Hashtable respData = XmlRpcCall(requestingAgentID, "groups.createGroup", param); | 275 | Hashtable respData = XmlRpcCall(requestingAgentID, "groups.createGroup", param); |
277 | 276 | ||
@@ -612,8 +611,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
612 | } | 611 | } |
613 | 612 | ||
614 | return Roles; | 613 | return Roles; |
615 | |||
616 | |||
617 | } | 614 | } |
618 | 615 | ||
619 | public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID GroupID) | 616 | public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID GroupID) |
@@ -676,7 +673,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
676 | } | 673 | } |
677 | 674 | ||
678 | return members; | 675 | return members; |
679 | |||
680 | } | 676 | } |
681 | 677 | ||
682 | public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID) | 678 | public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID) |
@@ -727,9 +723,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
727 | values.Add(data); | 723 | values.Add(data); |
728 | } | 724 | } |
729 | } | 725 | } |
730 | return values; | ||
731 | 726 | ||
727 | return values; | ||
732 | } | 728 | } |
729 | |||
733 | public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID) | 730 | public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID) |
734 | { | 731 | { |
735 | Hashtable param = new Hashtable(); | 732 | Hashtable param = new Hashtable(); |
@@ -737,7 +734,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
737 | 734 | ||
738 | Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotice", param); | 735 | Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotice", param); |
739 | 736 | ||
740 | |||
741 | if (respData.Contains("error")) | 737 | if (respData.Contains("error")) |
742 | { | 738 | { |
743 | return null; | 739 | return null; |
@@ -761,6 +757,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
761 | 757 | ||
762 | return data; | 758 | return data; |
763 | } | 759 | } |
760 | |||
764 | public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket) | 761 | public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket) |
765 | { | 762 | { |
766 | string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, ""); | 763 | string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, ""); |
@@ -777,8 +774,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
777 | XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param); | 774 | XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param); |
778 | } | 775 | } |
779 | 776 | ||
780 | |||
781 | |||
782 | #endregion | 777 | #endregion |
783 | 778 | ||
784 | #region GroupSessionTracking | 779 | #region GroupSessionTracking |
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs index 6120a81..709d389 100644 --- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs | |||
@@ -46,6 +46,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
46 | { | 46 | { |
47 | public class XmlRpcInfo | 47 | public class XmlRpcInfo |
48 | { | 48 | { |
49 | public UUID item; | ||
49 | public UUID channel; | 50 | public UUID channel; |
50 | public string uri; | 51 | public string uri; |
51 | } | 52 | } |
@@ -88,6 +89,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
88 | return; | 89 | return; |
89 | 90 | ||
90 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); | 91 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); |
92 | |||
93 | IScriptModule scriptEngine = scene.RequestModuleInterface<IScriptModule>(); | ||
94 | if ( scriptEngine != null ) | ||
95 | { | ||
96 | scriptEngine.OnScriptRemoved += this.ScriptRemoved; | ||
97 | scriptEngine.OnObjectRemoved += this.ObjectRemoved; | ||
98 | |||
99 | } | ||
91 | } | 100 | } |
92 | 101 | ||
93 | public void RegionLoaded(Scene scene) | 102 | public void RegionLoaded(Scene scene) |
@@ -120,22 +129,36 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
120 | 129 | ||
121 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) | 130 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) |
122 | { | 131 | { |
123 | if (!m_Channels.ContainsKey(itemID)) | 132 | if (!m_Enabled) |
124 | { | 133 | return; |
125 | XmlRpcInfo info = new XmlRpcInfo(); | ||
126 | info.channel = channel; | ||
127 | info.uri = uri; | ||
128 | 134 | ||
129 | bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>( | 135 | m_log.InfoFormat("[XMLRPC GRID ROUTER]: New receiver Obj: {0} Ch: {1} ID: {2} URI: {3}", |
130 | "POST", m_ServerURI+"/RegisterChannel/", info); | 136 | objectID.ToString(), channel.ToString(), itemID.ToString(), uri); |
131 | 137 | ||
132 | if (!success) | 138 | XmlRpcInfo info = new XmlRpcInfo(); |
133 | { | 139 | info.channel = channel; |
134 | m_log.Error("[XMLRPC GRID ROUTER] Error contacting server"); | 140 | info.uri = uri; |
135 | } | 141 | info.item = itemID; |
142 | |||
143 | bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>( | ||
144 | "POST", m_ServerURI+"/RegisterChannel/", info); | ||
136 | 145 | ||
137 | m_Channels[itemID] = channel; | 146 | if (!success) |
147 | { | ||
148 | m_log.Error("[XMLRPC GRID ROUTER] Error contacting server"); | ||
138 | } | 149 | } |
150 | |||
151 | m_Channels[itemID] = channel; | ||
152 | |||
153 | } | ||
154 | |||
155 | public void UnRegisterReceiver(string channelID, UUID itemID) | ||
156 | { | ||
157 | if (!m_Enabled) | ||
158 | return; | ||
159 | |||
160 | RemoveChannel(itemID); | ||
161 | |||
139 | } | 162 | } |
140 | 163 | ||
141 | public void ScriptRemoved(UUID itemID) | 164 | public void ScriptRemoved(UUID itemID) |
@@ -143,10 +166,33 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
143 | if (!m_Enabled) | 166 | if (!m_Enabled) |
144 | return; | 167 | return; |
145 | 168 | ||
146 | if (m_Channels.ContainsKey(itemID)) | 169 | RemoveChannel(itemID); |
170 | |||
171 | } | ||
172 | |||
173 | public void ObjectRemoved(UUID objectID) | ||
174 | { | ||
175 | // m_log.InfoFormat("[XMLRPC GRID ROUTER]: Object Removed {0}",objectID.ToString()); | ||
176 | } | ||
177 | |||
178 | private bool RemoveChannel(UUID itemID) | ||
179 | { | ||
180 | if(!m_Channels.ContainsKey(itemID)) | ||
181 | { | ||
182 | m_log.InfoFormat("[XMLRPC GRID ROUTER]: Attempted to unregister non-existing Item: {0}", itemID.ToString()); | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | XmlRpcInfo info = new XmlRpcInfo(); | ||
187 | |||
188 | info.channel = m_Channels[itemID]; | ||
189 | info.item = itemID; | ||
190 | info.uri = "http://0.0.0.0:00"; | ||
191 | |||
192 | if (info != null) | ||
147 | { | 193 | { |
148 | bool success = SynchronousRestObjectRequester.MakeRequest<UUID, bool>( | 194 | bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>( |
149 | "POST", m_ServerURI+"/RemoveChannel/", m_Channels[itemID]); | 195 | "POST", m_ServerURI+"/RemoveChannel/", info); |
150 | 196 | ||
151 | if (!success) | 197 | if (!success) |
152 | { | 198 | { |
@@ -154,11 +200,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
154 | } | 200 | } |
155 | 201 | ||
156 | m_Channels.Remove(itemID); | 202 | m_Channels.Remove(itemID); |
203 | return true; | ||
157 | } | 204 | } |
158 | } | 205 | return false; |
159 | |||
160 | public void ObjectRemoved(UUID objectID) | ||
161 | { | ||
162 | } | 206 | } |
163 | } | 207 | } |
164 | } | 208 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs index 4bde52a..32549d6 100644 --- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs | |||
@@ -104,12 +104,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | public void UnRegisterReceiver(string channelID, UUID itemID) | ||
108 | { | ||
109 | } | ||
110 | |||
107 | public void ScriptRemoved(UUID itemID) | 111 | public void ScriptRemoved(UUID itemID) |
108 | { | 112 | { |
113 | // System.Console.WriteLine("TEST Script Removed!"); | ||
109 | } | 114 | } |
110 | 115 | ||
111 | public void ObjectRemoved(UUID objectID) | 116 | public void ObjectRemoved(UUID objectID) |
112 | { | 117 | { |
118 | // System.Console.WriteLine("TEST Obj Removed!"); | ||
113 | } | 119 | } |
114 | } | 120 | } |
115 | } | 121 | } |
diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs index c7e3a7a..57d9217 100644 --- a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs +++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule | |||
49 | /// (such as land transfers). There is no money code here! Use FORGE as an example for money code. | 49 | /// (such as land transfers). There is no money code here! Use FORGE as an example for money code. |
50 | /// Demo Economy/Money Module. This is a purposely crippled module! | 50 | /// Demo Economy/Money Module. This is a purposely crippled module! |
51 | /// // To land transfer you need to add: | 51 | /// // To land transfer you need to add: |
52 | /// -helperuri <ADDRESS TO THIS SERVER> | 52 | /// -helperuri http://serveraddress:port/ |
53 | /// to the command line parameters you use to start up your client | 53 | /// to the command line parameters you use to start up your client |
54 | /// This commonly looks like -helperuri http://127.0.0.1:9000/ | 54 | /// This commonly looks like -helperuri http://127.0.0.1:9000/ |
55 | /// | 55 | /// |
@@ -116,10 +116,9 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule | |||
116 | } | 116 | } |
117 | 117 | ||
118 | /// <summary> | 118 | /// <summary> |
119 | /// Startup | 119 | /// Called on startup so the module can be configured. |
120 | /// </summary> | 120 | /// </summary> |
121 | /// <param name="scene"></param> | 121 | /// <param name="config">Configuration source.</param> |
122 | /// <param name="config"></param> | ||
123 | public void Initialise(IConfigSource config) | 122 | public void Initialise(IConfigSource config) |
124 | { | 123 | { |
125 | m_gConfig = config; | 124 | m_gConfig = config; |
@@ -674,9 +673,12 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule | |||
674 | } | 673 | } |
675 | 674 | ||
676 | /// <summary> | 675 | /// <summary> |
677 | /// When the client closes the connection we remove their accounting info from memory to free up resources. | 676 | /// When the client closes the connection we remove their accounting |
677 | /// info from memory to free up resources. | ||
678 | /// </summary> | 678 | /// </summary> |
679 | /// <param name="AgentID"></param> | 679 | /// <param name="AgentID">UUID of agent</param> |
680 | /// <param name="scene">Scene the agent was connected to.</param> | ||
681 | /// <see cref="OpenSim.Region.Framework.Scenes.EventManager.ClientClosed"/> | ||
680 | public void ClientClosed(UUID AgentID, Scene scene) | 682 | public void ClientClosed(UUID AgentID, Scene scene) |
681 | { | 683 | { |
682 | 684 | ||
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index ef4005b..365fd78 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -48,7 +48,7 @@ using OpenSim.Tests.Common.Mock; | |||
48 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests | 48 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests |
49 | { | 49 | { |
50 | [TestFixture] | 50 | [TestFixture] |
51 | public class NPCModuleTests | 51 | public class NPCModuleTests : OpenSimTestCase |
52 | { | 52 | { |
53 | private TestScene m_scene; | 53 | private TestScene m_scene; |
54 | private AvatarFactoryModule m_afMod; | 54 | private AvatarFactoryModule m_afMod; |
diff --git a/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs new file mode 100644 index 0000000..12169ab --- /dev/null +++ b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Monitoring; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | |||
43 | namespace OpenSim.Region.OptionalModules.Avatar.Attachments | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// A module that just holds commands for inspecting avatar appearance. | ||
47 | /// </summary> | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")] | ||
49 | public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private Scene m_scene; | ||
54 | |||
55 | public string Name { get { return "Scene Commands Module"; } } | ||
56 | |||
57 | public Type ReplaceableInterface { get { return null; } } | ||
58 | |||
59 | public void Initialise(IConfigSource source) | ||
60 | { | ||
61 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE"); | ||
62 | } | ||
63 | |||
64 | public void PostInitialise() | ||
65 | { | ||
66 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE"); | ||
67 | } | ||
68 | |||
69 | public void Close() | ||
70 | { | ||
71 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE"); | ||
72 | } | ||
73 | |||
74 | public void AddRegion(Scene scene) | ||
75 | { | ||
76 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
77 | |||
78 | m_scene = scene; | ||
79 | |||
80 | m_scene.RegisterModuleInterface<ISceneCommandsModule>(this); | ||
81 | } | ||
82 | |||
83 | public void RemoveRegion(Scene scene) | ||
84 | { | ||
85 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
86 | } | ||
87 | |||
88 | public void RegionLoaded(Scene scene) | ||
89 | { | ||
90 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
91 | |||
92 | scene.AddCommand( | ||
93 | "Debug", this, "debug scene get", | ||
94 | "debug scene get", | ||
95 | "List current scene options.", | ||
96 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
97 | + "If animations is true then extra animations debug information is logged.\n" | ||
98 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
99 | + "If pbackup is false then periodic scene backup is turned off.\n" | ||
100 | + "If physics is false then all physics objects are non-physical.\n" | ||
101 | + "If scripting is false then no scripting operations happen.\n" | ||
102 | + "If teleport is true then some extra teleport debug information is logged.\n" | ||
103 | + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.", | ||
104 | HandleDebugSceneGetCommand); | ||
105 | |||
106 | scene.AddCommand( | ||
107 | "Debug", this, "debug scene set", | ||
108 | "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false", | ||
109 | "Turn on scene debugging options.", | ||
110 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
111 | + "If animations is true then extra animations debug information is logged.\n" | ||
112 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
113 | + "If pbackup is false then periodic scene backup is turned off.\n" | ||
114 | + "If physics is false then all physics objects are non-physical.\n" | ||
115 | + "If scripting is false then no scripting operations happen.\n" | ||
116 | + "If teleport is true then some extra teleport debug information is logged.\n" | ||
117 | + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.", | ||
118 | HandleDebugSceneSetCommand); | ||
119 | } | ||
120 | |||
121 | private void HandleDebugSceneGetCommand(string module, string[] args) | ||
122 | { | ||
123 | if (args.Length == 3) | ||
124 | { | ||
125 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) | ||
126 | return; | ||
127 | |||
128 | OutputSceneDebugOptions(); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | MainConsole.Instance.Output("Usage: debug scene get"); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | private void OutputSceneDebugOptions() | ||
137 | { | ||
138 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | ||
139 | cdl.AddRow("active", m_scene.Active); | ||
140 | cdl.AddRow("animations", m_scene.DebugAnimations); | ||
141 | cdl.AddRow("pbackup", m_scene.PeriodicBackup); | ||
142 | cdl.AddRow("physics", m_scene.PhysicsEnabled); | ||
143 | cdl.AddRow("scripting", m_scene.ScriptsEnabled); | ||
144 | cdl.AddRow("teleport", m_scene.DebugTeleporting); | ||
145 | cdl.AddRow("updates", m_scene.DebugUpdates); | ||
146 | |||
147 | MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name); | ||
148 | MainConsole.Instance.Output(cdl.ToString()); | ||
149 | } | ||
150 | |||
151 | private void HandleDebugSceneSetCommand(string module, string[] args) | ||
152 | { | ||
153 | if (args.Length == 5) | ||
154 | { | ||
155 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) | ||
156 | return; | ||
157 | |||
158 | string key = args[3]; | ||
159 | string value = args[4]; | ||
160 | SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } }); | ||
161 | |||
162 | MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value); | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | MainConsole.Instance.Output( | ||
167 | "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false"); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | public void SetSceneDebugOptions(Dictionary<string, string> options) | ||
172 | { | ||
173 | if (options.ContainsKey("active")) | ||
174 | { | ||
175 | bool active; | ||
176 | |||
177 | if (bool.TryParse(options["active"], out active)) | ||
178 | m_scene.Active = active; | ||
179 | } | ||
180 | |||
181 | if (options.ContainsKey("animations")) | ||
182 | { | ||
183 | bool active; | ||
184 | |||
185 | if (bool.TryParse(options["animations"], out active)) | ||
186 | m_scene.DebugAnimations = active; | ||
187 | } | ||
188 | |||
189 | if (options.ContainsKey("pbackup")) | ||
190 | { | ||
191 | bool active; | ||
192 | |||
193 | if (bool.TryParse(options["pbackup"], out active)) | ||
194 | m_scene.PeriodicBackup = active; | ||
195 | } | ||
196 | |||
197 | if (options.ContainsKey("scripting")) | ||
198 | { | ||
199 | bool enableScripts = true; | ||
200 | if (bool.TryParse(options["scripting"], out enableScripts)) | ||
201 | m_scene.ScriptsEnabled = enableScripts; | ||
202 | } | ||
203 | |||
204 | if (options.ContainsKey("physics")) | ||
205 | { | ||
206 | bool enablePhysics; | ||
207 | if (bool.TryParse(options["physics"], out enablePhysics)) | ||
208 | m_scene.PhysicsEnabled = enablePhysics; | ||
209 | } | ||
210 | |||
211 | // if (options.ContainsKey("collisions")) | ||
212 | // { | ||
213 | // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow | ||
214 | // // the avatar themselves to collide with the ground. | ||
215 | // } | ||
216 | |||
217 | if (options.ContainsKey("teleport")) | ||
218 | { | ||
219 | bool enableTeleportDebugging; | ||
220 | if (bool.TryParse(options["teleport"], out enableTeleportDebugging)) | ||
221 | m_scene.DebugTeleporting = enableTeleportDebugging; | ||
222 | } | ||
223 | |||
224 | if (options.ContainsKey("updates")) | ||
225 | { | ||
226 | bool enableUpdateDebugging; | ||
227 | if (bool.TryParse(options["updates"], out enableUpdateDebugging)) | ||
228 | { | ||
229 | m_scene.DebugUpdates = enableUpdateDebugging; | ||
230 | GcNotify.Enabled = enableUpdateDebugging; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs index 7ab2a03..373c7e0 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin | |||
49 | 49 | ||
50 | public PhysicsScene GetScene(string sceneIdentifier) | 50 | public PhysicsScene GetScene(string sceneIdentifier) |
51 | { | 51 | { |
52 | return new BasicScene(sceneIdentifier); | 52 | return new BasicScene(GetName(), sceneIdentifier); |
53 | } | 53 | } |
54 | 54 | ||
55 | public string GetName() | 55 | public string GetName() |
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs index f5826ed..c4b9117 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs | |||
@@ -49,8 +49,10 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin | |||
49 | 49 | ||
50 | //protected internal string sceneIdentifier; | 50 | //protected internal string sceneIdentifier; |
51 | 51 | ||
52 | public BasicScene(string _sceneIdentifier) | 52 | public BasicScene(string engineType, string _sceneIdentifier) |
53 | { | 53 | { |
54 | EngineType = engineType; | ||
55 | Name = EngineType + "/" + _sceneIdentifier; | ||
54 | //sceneIdentifier = _sceneIdentifier; | 56 | //sceneIdentifier = _sceneIdentifier; |
55 | } | 57 | } |
56 | 58 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs new file mode 100755 index 0000000..ae54499 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | |||
@@ -0,0 +1,1885 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Runtime.InteropServices; | ||
31 | using System.Security; | ||
32 | using System.Text; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | |||
36 | using OpenMetaverse; | ||
37 | |||
38 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
39 | { | ||
40 | public sealed class BSAPIUnman : BSAPITemplate | ||
41 | { | ||
42 | |||
43 | private sealed class BulletWorldUnman : BulletWorld | ||
44 | { | ||
45 | public IntPtr ptr; | ||
46 | public BulletWorldUnman(uint id, BSScene physScene, IntPtr xx) | ||
47 | : base(id, physScene) | ||
48 | { | ||
49 | ptr = xx; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | private sealed class BulletBodyUnman : BulletBody | ||
54 | { | ||
55 | public IntPtr ptr; | ||
56 | public BulletBodyUnman(uint id, IntPtr xx) | ||
57 | : base(id) | ||
58 | { | ||
59 | ptr = xx; | ||
60 | } | ||
61 | public override bool HasPhysicalBody | ||
62 | { | ||
63 | get { return ptr != IntPtr.Zero; } | ||
64 | } | ||
65 | public override void Clear() | ||
66 | { | ||
67 | ptr = IntPtr.Zero; | ||
68 | } | ||
69 | public override string AddrString | ||
70 | { | ||
71 | get { return ptr.ToString("X"); } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | private sealed class BulletShapeUnman : BulletShape | ||
76 | { | ||
77 | public IntPtr ptr; | ||
78 | public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ) | ||
79 | : base() | ||
80 | { | ||
81 | ptr = xx; | ||
82 | type = typ; | ||
83 | } | ||
84 | public override bool HasPhysicalShape | ||
85 | { | ||
86 | get { return ptr != IntPtr.Zero; } | ||
87 | } | ||
88 | public override void Clear() | ||
89 | { | ||
90 | ptr = IntPtr.Zero; | ||
91 | } | ||
92 | public override BulletShape Clone() | ||
93 | { | ||
94 | return new BulletShapeUnman(ptr, type); | ||
95 | } | ||
96 | public override bool ReferenceSame(BulletShape other) | ||
97 | { | ||
98 | BulletShapeUnman otheru = other as BulletShapeUnman; | ||
99 | return (otheru != null) && (this.ptr == otheru.ptr); | ||
100 | |||
101 | } | ||
102 | public override string AddrString | ||
103 | { | ||
104 | get { return ptr.ToString("X"); } | ||
105 | } | ||
106 | } | ||
107 | private sealed class BulletConstraintUnman : BulletConstraint | ||
108 | { | ||
109 | public BulletConstraintUnman(IntPtr xx) : base() | ||
110 | { | ||
111 | ptr = xx; | ||
112 | } | ||
113 | public IntPtr ptr; | ||
114 | |||
115 | public override void Clear() | ||
116 | { | ||
117 | ptr = IntPtr.Zero; | ||
118 | } | ||
119 | public override bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } | ||
120 | |||
121 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
122 | public override string AddrString | ||
123 | { | ||
124 | get { return ptr.ToString("X"); } | ||
125 | } | ||
126 | } | ||
127 | |||
128 | // We pin the memory passed between the managed and unmanaged code. | ||
129 | GCHandle m_paramsHandle; | ||
130 | private GCHandle m_collisionArrayPinnedHandle; | ||
131 | private GCHandle m_updateArrayPinnedHandle; | ||
132 | |||
133 | // Handle to the callback used by the unmanaged code to call into the managed code. | ||
134 | // Used for debug logging. | ||
135 | // Need to store the handle in a persistant variable so it won't be freed. | ||
136 | private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle; | ||
137 | |||
138 | private BSScene PhysicsScene { get; set; } | ||
139 | |||
140 | public override string BulletEngineName { get { return "BulletUnmanaged"; } } | ||
141 | public override string BulletEngineVersion { get; protected set; } | ||
142 | |||
143 | public BSAPIUnman(string paramName, BSScene physScene) | ||
144 | { | ||
145 | PhysicsScene = physScene; | ||
146 | |||
147 | // Do something fancy with the paramName to get the right DLL implementation | ||
148 | // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc. | ||
149 | if (Util.IsWindows()) | ||
150 | Util.LoadArchSpecificWindowsDll("BulletSim.dll"); | ||
151 | // If not Windows, loading is performed by the | ||
152 | // Mono loader as specified in | ||
153 | // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config". | ||
154 | } | ||
155 | |||
156 | // Initialization and simulation | ||
157 | public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, | ||
158 | int maxCollisions, ref CollisionDesc[] collisionArray, | ||
159 | int maxUpdates, ref EntityProperties[] updateArray | ||
160 | ) | ||
161 | { | ||
162 | // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code | ||
163 | m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned); | ||
164 | m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned); | ||
165 | m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned); | ||
166 | |||
167 | // If Debug logging level, enable logging from the unmanaged code | ||
168 | m_DebugLogCallbackHandle = null; | ||
169 | if (BSScene.m_log.IsDebugEnabled && PhysicsScene.PhysicsLogging.Enabled) | ||
170 | { | ||
171 | BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader); | ||
172 | if (PhysicsScene.PhysicsLogging.Enabled) | ||
173 | // The handle is saved in a variable to make sure it doesn't get freed after this call | ||
174 | m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog); | ||
175 | else | ||
176 | m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger); | ||
177 | } | ||
178 | |||
179 | // Get the version of the DLL | ||
180 | // TODO: this doesn't work yet. Something wrong with marshaling the returned string. | ||
181 | // BulletEngineVersion = BulletSimAPI.GetVersion2(); | ||
182 | BulletEngineVersion = ""; | ||
183 | |||
184 | // Call the unmanaged code with the buffers and other information | ||
185 | return new BulletWorldUnman(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(), | ||
186 | maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), | ||
187 | maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(), | ||
188 | m_DebugLogCallbackHandle)); | ||
189 | |||
190 | } | ||
191 | |||
192 | // Called directly from unmanaged code so don't do much | ||
193 | private void BulletLogger(string msg) | ||
194 | { | ||
195 | BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg); | ||
196 | } | ||
197 | |||
198 | // Called directly from unmanaged code so don't do much | ||
199 | private void BulletLoggerPhysLog(string msg) | ||
200 | { | ||
201 | PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg); | ||
202 | } | ||
203 | |||
204 | public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
205 | out int updatedEntityCount, out int collidersCount) | ||
206 | { | ||
207 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
208 | return BSAPICPP.PhysicsStep2(worldu.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount); | ||
209 | } | ||
210 | |||
211 | public override void Shutdown(BulletWorld world) | ||
212 | { | ||
213 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
214 | BSAPICPP.Shutdown2(worldu.ptr); | ||
215 | |||
216 | if (m_paramsHandle.IsAllocated) | ||
217 | { | ||
218 | m_paramsHandle.Free(); | ||
219 | } | ||
220 | if (m_collisionArrayPinnedHandle.IsAllocated) | ||
221 | { | ||
222 | m_collisionArrayPinnedHandle.Free(); | ||
223 | } | ||
224 | if (m_updateArrayPinnedHandle.IsAllocated) | ||
225 | { | ||
226 | m_updateArrayPinnedHandle.Free(); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | public override bool PushUpdate(BulletBody obj) | ||
231 | { | ||
232 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
233 | return BSAPICPP.PushUpdate2(bodyu.ptr); | ||
234 | } | ||
235 | |||
236 | public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) | ||
237 | { | ||
238 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
239 | return BSAPICPP.UpdateParameter2(worldu.ptr, localID, parm, value); | ||
240 | } | ||
241 | |||
242 | // ===================================================================================== | ||
243 | // Mesh, hull, shape and body creation helper routines | ||
244 | public override BulletShape CreateMeshShape(BulletWorld world, | ||
245 | int indicesCount, int[] indices, | ||
246 | int verticesCount, float[] vertices) | ||
247 | { | ||
248 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
249 | return new BulletShapeUnman( | ||
250 | BSAPICPP.CreateMeshShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices), | ||
251 | BSPhysicsShapeType.SHAPE_MESH); | ||
252 | } | ||
253 | |||
254 | public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) | ||
255 | { | ||
256 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
257 | return new BulletShapeUnman( | ||
258 | BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls), | ||
259 | BSPhysicsShapeType.SHAPE_HULL); | ||
260 | } | ||
261 | |||
262 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | ||
263 | { | ||
264 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
265 | BulletShapeUnman shapeu = meshShape as BulletShapeUnman; | ||
266 | return new BulletShapeUnman( | ||
267 | BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr), | ||
268 | BSPhysicsShapeType.SHAPE_HULL); | ||
269 | } | ||
270 | |||
271 | public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData) | ||
272 | { | ||
273 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
274 | return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type); | ||
275 | } | ||
276 | |||
277 | public override bool IsNativeShape(BulletShape shape) | ||
278 | { | ||
279 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
280 | if (shapeu != null && shapeu.HasPhysicalShape) | ||
281 | return BSAPICPP.IsNativeShape2(shapeu.ptr); | ||
282 | return false; | ||
283 | } | ||
284 | |||
285 | public override void SetShapeCollisionMargin(BulletShape shape, float margin) | ||
286 | { | ||
287 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
288 | if (shapeu != null && shapeu.HasPhysicalShape) | ||
289 | BSAPICPP.SetShapeCollisionMargin2(shapeu.ptr, margin); | ||
290 | } | ||
291 | |||
292 | public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale) | ||
293 | { | ||
294 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
295 | return new BulletShapeUnman( | ||
296 | BSAPICPP.BuildCapsuleShape2(worldu.ptr, radius, height, scale), | ||
297 | BSPhysicsShapeType.SHAPE_CAPSULE); | ||
298 | } | ||
299 | |||
300 | public override BulletShape CreateCompoundShape(BulletWorld world, bool enableDynamicAabbTree) | ||
301 | { | ||
302 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
303 | return new BulletShapeUnman( | ||
304 | BSAPICPP.CreateCompoundShape2(worldu.ptr, enableDynamicAabbTree), | ||
305 | BSPhysicsShapeType.SHAPE_COMPOUND); | ||
306 | |||
307 | } | ||
308 | |||
309 | public override int GetNumberOfCompoundChildren(BulletShape shape) | ||
310 | { | ||
311 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
312 | if (shapeu != null && shapeu.HasPhysicalShape) | ||
313 | return BSAPICPP.GetNumberOfCompoundChildren2(shapeu.ptr); | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | public override void AddChildShapeToCompoundShape(BulletShape shape, BulletShape addShape, Vector3 pos, Quaternion rot) | ||
318 | { | ||
319 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
320 | BulletShapeUnman addShapeu = addShape as BulletShapeUnman; | ||
321 | BSAPICPP.AddChildShapeToCompoundShape2(shapeu.ptr, addShapeu.ptr, pos, rot); | ||
322 | } | ||
323 | |||
324 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape shape, int indx) | ||
325 | { | ||
326 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
327 | return new BulletShapeUnman(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
328 | } | ||
329 | |||
330 | public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape shape, int indx) | ||
331 | { | ||
332 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
333 | return new BulletShapeUnman(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
334 | } | ||
335 | |||
336 | public override void RemoveChildShapeFromCompoundShape(BulletShape shape, BulletShape removeShape) | ||
337 | { | ||
338 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
339 | BulletShapeUnman removeShapeu = removeShape as BulletShapeUnman; | ||
340 | BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr); | ||
341 | } | ||
342 | |||
343 | public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb) | ||
344 | { | ||
345 | BulletShapeUnman shapeu = pShape as BulletShapeUnman; | ||
346 | BSAPICPP.UpdateChildTransform2(shapeu.ptr, childIndex, pos, rot, shouldRecalculateLocalAabb); | ||
347 | } | ||
348 | |||
349 | public override void RecalculateCompoundShapeLocalAabb(BulletShape shape) | ||
350 | { | ||
351 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
352 | BSAPICPP.RecalculateCompoundShapeLocalAabb2(shapeu.ptr); | ||
353 | } | ||
354 | |||
355 | public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletShape srcShape, uint id) | ||
356 | { | ||
357 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
358 | BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman; | ||
359 | return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.type); | ||
360 | } | ||
361 | |||
362 | public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) | ||
363 | { | ||
364 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
365 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
366 | return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr); | ||
367 | } | ||
368 | |||
369 | public override CollisionObjectTypes GetBodyType(BulletBody obj) | ||
370 | { | ||
371 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
372 | return (CollisionObjectTypes)BSAPICPP.GetBodyType2(bodyu.ptr); | ||
373 | } | ||
374 | |||
375 | public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot) | ||
376 | { | ||
377 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
378 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
379 | return new BulletBodyUnman(id, BSAPICPP.CreateBodyFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot)); | ||
380 | } | ||
381 | |||
382 | public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot) | ||
383 | { | ||
384 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
385 | return new BulletBodyUnman(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shapeu.ptr, id, pos, rot)); | ||
386 | } | ||
387 | |||
388 | public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot) | ||
389 | { | ||
390 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
391 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
392 | return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot)); | ||
393 | } | ||
394 | |||
395 | public override void DestroyObject(BulletWorld world, BulletBody obj) | ||
396 | { | ||
397 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
398 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
399 | BSAPICPP.DestroyObject2(worldu.ptr, bodyu.ptr); | ||
400 | } | ||
401 | |||
402 | // ===================================================================================== | ||
403 | // Terrain creation and helper routines | ||
404 | public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin) | ||
405 | { | ||
406 | return new BulletShapeUnman(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); | ||
407 | } | ||
408 | |||
409 | public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, | ||
410 | float scaleFactor, float collisionMargin) | ||
411 | { | ||
412 | return new BulletShapeUnman(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin), | ||
413 | BSPhysicsShapeType.SHAPE_TERRAIN); | ||
414 | } | ||
415 | |||
416 | // ===================================================================================== | ||
417 | // Constraint creation and helper routines | ||
418 | public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
419 | Vector3 frame1loc, Quaternion frame1rot, | ||
420 | Vector3 frame2loc, Quaternion frame2rot, | ||
421 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
422 | { | ||
423 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
424 | BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman; | ||
425 | BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman; | ||
426 | return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot, | ||
427 | frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
428 | } | ||
429 | |||
430 | public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
431 | Vector3 joinPoint, | ||
432 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
433 | { | ||
434 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
435 | BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman; | ||
436 | BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman; | ||
437 | return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, | ||
438 | joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
439 | } | ||
440 | |||
441 | public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
442 | Vector3 pivotinA, Vector3 pivotinB, | ||
443 | Vector3 axisInA, Vector3 axisInB, | ||
444 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
445 | { | ||
446 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
447 | BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman; | ||
448 | BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman; | ||
449 | return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, | ||
450 | pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
451 | } | ||
452 | |||
453 | public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse) | ||
454 | { | ||
455 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
456 | BSAPICPP.SetConstraintEnable2(constrainu.ptr, numericTrueFalse); | ||
457 | } | ||
458 | |||
459 | public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations) | ||
460 | { | ||
461 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
462 | BSAPICPP.SetConstraintNumSolverIterations2(constrainu.ptr, iterations); | ||
463 | } | ||
464 | |||
465 | public override bool SetFrames(BulletConstraint constrain, | ||
466 | Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) | ||
467 | { | ||
468 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
469 | return BSAPICPP.SetFrames2(constrainu.ptr, frameA, frameArot, frameB, frameBrot); | ||
470 | } | ||
471 | |||
472 | public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) | ||
473 | { | ||
474 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
475 | return BSAPICPP.SetLinearLimits2(constrainu.ptr, low, hi); | ||
476 | } | ||
477 | |||
478 | public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) | ||
479 | { | ||
480 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
481 | return BSAPICPP.SetAngularLimits2(constrainu.ptr, low, hi); | ||
482 | } | ||
483 | |||
484 | public override bool UseFrameOffset(BulletConstraint constrain, float enable) | ||
485 | { | ||
486 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
487 | return BSAPICPP.UseFrameOffset2(constrainu.ptr, enable); | ||
488 | } | ||
489 | |||
490 | public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce) | ||
491 | { | ||
492 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
493 | return BSAPICPP.TranslationalLimitMotor2(constrainu.ptr, enable, targetVel, maxMotorForce); | ||
494 | } | ||
495 | |||
496 | public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold) | ||
497 | { | ||
498 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
499 | return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold); | ||
500 | } | ||
501 | |||
502 | public override bool CalculateTransforms(BulletConstraint constrain) | ||
503 | { | ||
504 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
505 | return BSAPICPP.CalculateTransforms2(constrainu.ptr); | ||
506 | } | ||
507 | |||
508 | public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis) | ||
509 | { | ||
510 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
511 | return BSAPICPP.SetConstraintParam2(constrainu.ptr, paramIndex, value, axis); | ||
512 | } | ||
513 | |||
514 | public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain) | ||
515 | { | ||
516 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
517 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
518 | return BSAPICPP.DestroyConstraint2(worldu.ptr, constrainu.ptr); | ||
519 | } | ||
520 | |||
521 | // ===================================================================================== | ||
522 | // btCollisionWorld entries | ||
523 | public override void UpdateSingleAabb(BulletWorld world, BulletBody obj) | ||
524 | { | ||
525 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
526 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
527 | BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr); | ||
528 | } | ||
529 | |||
530 | public override void UpdateAabbs(BulletWorld world) | ||
531 | { | ||
532 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
533 | BSAPICPP.UpdateAabbs2(worldu.ptr); | ||
534 | } | ||
535 | |||
536 | public override bool GetForceUpdateAllAabbs(BulletWorld world) | ||
537 | { | ||
538 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
539 | return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr); | ||
540 | } | ||
541 | |||
542 | public override void SetForceUpdateAllAabbs(BulletWorld world, bool force) | ||
543 | { | ||
544 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
545 | BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force); | ||
546 | } | ||
547 | |||
548 | // ===================================================================================== | ||
549 | // btDynamicsWorld entries | ||
550 | public override bool AddObjectToWorld(BulletWorld world, BulletBody obj) | ||
551 | { | ||
552 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
553 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
554 | |||
555 | // Bullet resets several variables when an object is added to the world. | ||
556 | // Gravity is reset to world default depending on the static/dynamic | ||
557 | // type. Of course, the collision flags in the broadphase proxy are initialized to default. | ||
558 | Vector3 origGrav = BSAPICPP.GetGravity2(bodyu.ptr); | ||
559 | |||
560 | bool ret = BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr); | ||
561 | |||
562 | if (ret) | ||
563 | { | ||
564 | BSAPICPP.SetGravity2(bodyu.ptr, origGrav); | ||
565 | obj.ApplyCollisionMask(world.physicsScene); | ||
566 | } | ||
567 | return ret; | ||
568 | } | ||
569 | |||
570 | public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj) | ||
571 | { | ||
572 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
573 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
574 | return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr); | ||
575 | } | ||
576 | |||
577 | public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) | ||
578 | { | ||
579 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
580 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
581 | return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects); | ||
582 | } | ||
583 | |||
584 | public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain) | ||
585 | { | ||
586 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
587 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
588 | return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr); | ||
589 | } | ||
590 | // ===================================================================================== | ||
591 | // btCollisionObject entries | ||
592 | public override Vector3 GetAnisotripicFriction(BulletConstraint constrain) | ||
593 | { | ||
594 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
595 | return BSAPICPP.GetAnisotripicFriction2(constrainu.ptr); | ||
596 | } | ||
597 | |||
598 | public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict) | ||
599 | { | ||
600 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
601 | return BSAPICPP.SetAnisotripicFriction2(constrainu.ptr, frict); | ||
602 | } | ||
603 | |||
604 | public override bool HasAnisotripicFriction(BulletConstraint constrain) | ||
605 | { | ||
606 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
607 | return BSAPICPP.HasAnisotripicFriction2(constrainu.ptr); | ||
608 | } | ||
609 | |||
610 | public override void SetContactProcessingThreshold(BulletBody obj, float val) | ||
611 | { | ||
612 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
613 | BSAPICPP.SetContactProcessingThreshold2(bodyu.ptr, val); | ||
614 | } | ||
615 | |||
616 | public override float GetContactProcessingThreshold(BulletBody obj) | ||
617 | { | ||
618 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
619 | return BSAPICPP.GetContactProcessingThreshold2(bodyu.ptr); | ||
620 | } | ||
621 | |||
622 | public override bool IsStaticObject(BulletBody obj) | ||
623 | { | ||
624 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
625 | return BSAPICPP.IsStaticObject2(bodyu.ptr); | ||
626 | } | ||
627 | |||
628 | public override bool IsKinematicObject(BulletBody obj) | ||
629 | { | ||
630 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
631 | return BSAPICPP.IsKinematicObject2(bodyu.ptr); | ||
632 | } | ||
633 | |||
634 | public override bool IsStaticOrKinematicObject(BulletBody obj) | ||
635 | { | ||
636 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
637 | return BSAPICPP.IsStaticOrKinematicObject2(bodyu.ptr); | ||
638 | } | ||
639 | |||
640 | public override bool HasContactResponse(BulletBody obj) | ||
641 | { | ||
642 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
643 | return BSAPICPP.HasContactResponse2(bodyu.ptr); | ||
644 | } | ||
645 | |||
646 | public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape) | ||
647 | { | ||
648 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
649 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
650 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
651 | if (worldu != null && bodyu != null) | ||
652 | { | ||
653 | // Special case to allow the caller to zero out the reference to any physical shape | ||
654 | if (shapeu != null) | ||
655 | BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr); | ||
656 | else | ||
657 | BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero); | ||
658 | } | ||
659 | } | ||
660 | |||
661 | public override BulletShape GetCollisionShape(BulletBody obj) | ||
662 | { | ||
663 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
664 | return new BulletShapeUnman(BSAPICPP.GetCollisionShape2(bodyu.ptr), BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
665 | } | ||
666 | |||
667 | public override int GetActivationState(BulletBody obj) | ||
668 | { | ||
669 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
670 | return BSAPICPP.GetActivationState2(bodyu.ptr); | ||
671 | } | ||
672 | |||
673 | public override void SetActivationState(BulletBody obj, int state) | ||
674 | { | ||
675 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
676 | BSAPICPP.SetActivationState2(bodyu.ptr, state); | ||
677 | } | ||
678 | |||
679 | public override void SetDeactivationTime(BulletBody obj, float dtime) | ||
680 | { | ||
681 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
682 | BSAPICPP.SetDeactivationTime2(bodyu.ptr, dtime); | ||
683 | } | ||
684 | |||
685 | public override float GetDeactivationTime(BulletBody obj) | ||
686 | { | ||
687 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
688 | return BSAPICPP.GetDeactivationTime2(bodyu.ptr); | ||
689 | } | ||
690 | |||
691 | public override void ForceActivationState(BulletBody obj, ActivationState state) | ||
692 | { | ||
693 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
694 | BSAPICPP.ForceActivationState2(bodyu.ptr, state); | ||
695 | } | ||
696 | |||
697 | public override void Activate(BulletBody obj, bool forceActivation) | ||
698 | { | ||
699 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
700 | BSAPICPP.Activate2(bodyu.ptr, forceActivation); | ||
701 | } | ||
702 | |||
703 | public override bool IsActive(BulletBody obj) | ||
704 | { | ||
705 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
706 | return BSAPICPP.IsActive2(bodyu.ptr); | ||
707 | } | ||
708 | |||
709 | public override void SetRestitution(BulletBody obj, float val) | ||
710 | { | ||
711 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
712 | BSAPICPP.SetRestitution2(bodyu.ptr, val); | ||
713 | } | ||
714 | |||
715 | public override float GetRestitution(BulletBody obj) | ||
716 | { | ||
717 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
718 | return BSAPICPP.GetRestitution2(bodyu.ptr); | ||
719 | } | ||
720 | |||
721 | public override void SetFriction(BulletBody obj, float val) | ||
722 | { | ||
723 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
724 | BSAPICPP.SetFriction2(bodyu.ptr, val); | ||
725 | } | ||
726 | |||
727 | public override float GetFriction(BulletBody obj) | ||
728 | { | ||
729 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
730 | return BSAPICPP.GetFriction2(bodyu.ptr); | ||
731 | } | ||
732 | |||
733 | public override Vector3 GetPosition(BulletBody obj) | ||
734 | { | ||
735 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
736 | return BSAPICPP.GetPosition2(bodyu.ptr); | ||
737 | } | ||
738 | |||
739 | public override Quaternion GetOrientation(BulletBody obj) | ||
740 | { | ||
741 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
742 | return BSAPICPP.GetOrientation2(bodyu.ptr); | ||
743 | } | ||
744 | |||
745 | public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation) | ||
746 | { | ||
747 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
748 | BSAPICPP.SetTranslation2(bodyu.ptr, position, rotation); | ||
749 | } | ||
750 | |||
751 | /* | ||
752 | public override IntPtr GetBroadphaseHandle(BulletBody obj) | ||
753 | { | ||
754 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
755 | return BSAPICPP.GetBroadphaseHandle2(bodyu.ptr); | ||
756 | } | ||
757 | |||
758 | public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle) | ||
759 | { | ||
760 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
761 | BSAPICPP.SetUserPointer2(bodyu.ptr, handle); | ||
762 | } | ||
763 | */ | ||
764 | |||
765 | public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel) | ||
766 | { | ||
767 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
768 | BSAPICPP.SetInterpolationLinearVelocity2(bodyu.ptr, vel); | ||
769 | } | ||
770 | |||
771 | public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel) | ||
772 | { | ||
773 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
774 | BSAPICPP.SetInterpolationAngularVelocity2(bodyu.ptr, vel); | ||
775 | } | ||
776 | |||
777 | public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel) | ||
778 | { | ||
779 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
780 | BSAPICPP.SetInterpolationVelocity2(bodyu.ptr, linearVel, angularVel); | ||
781 | } | ||
782 | |||
783 | public override float GetHitFraction(BulletBody obj) | ||
784 | { | ||
785 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
786 | return BSAPICPP.GetHitFraction2(bodyu.ptr); | ||
787 | } | ||
788 | |||
789 | public override void SetHitFraction(BulletBody obj, float val) | ||
790 | { | ||
791 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
792 | BSAPICPP.SetHitFraction2(bodyu.ptr, val); | ||
793 | } | ||
794 | |||
795 | public override CollisionFlags GetCollisionFlags(BulletBody obj) | ||
796 | { | ||
797 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
798 | return BSAPICPP.GetCollisionFlags2(bodyu.ptr); | ||
799 | } | ||
800 | |||
801 | public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags) | ||
802 | { | ||
803 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
804 | return BSAPICPP.SetCollisionFlags2(bodyu.ptr, flags); | ||
805 | } | ||
806 | |||
807 | public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags) | ||
808 | { | ||
809 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
810 | return BSAPICPP.AddToCollisionFlags2(bodyu.ptr, flags); | ||
811 | } | ||
812 | |||
813 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags) | ||
814 | { | ||
815 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
816 | return BSAPICPP.RemoveFromCollisionFlags2(bodyu.ptr, flags); | ||
817 | } | ||
818 | |||
819 | public override float GetCcdMotionThreshold(BulletBody obj) | ||
820 | { | ||
821 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
822 | return BSAPICPP.GetCcdMotionThreshold2(bodyu.ptr); | ||
823 | } | ||
824 | |||
825 | |||
826 | public override void SetCcdMotionThreshold(BulletBody obj, float val) | ||
827 | { | ||
828 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
829 | BSAPICPP.SetCcdMotionThreshold2(bodyu.ptr, val); | ||
830 | } | ||
831 | |||
832 | public override float GetCcdSweptSphereRadius(BulletBody obj) | ||
833 | { | ||
834 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
835 | return BSAPICPP.GetCcdSweptSphereRadius2(bodyu.ptr); | ||
836 | } | ||
837 | |||
838 | public override void SetCcdSweptSphereRadius(BulletBody obj, float val) | ||
839 | { | ||
840 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
841 | BSAPICPP.SetCcdSweptSphereRadius2(bodyu.ptr, val); | ||
842 | } | ||
843 | |||
844 | public override IntPtr GetUserPointer(BulletBody obj) | ||
845 | { | ||
846 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
847 | return BSAPICPP.GetUserPointer2(bodyu.ptr); | ||
848 | } | ||
849 | |||
850 | public override void SetUserPointer(BulletBody obj, IntPtr val) | ||
851 | { | ||
852 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
853 | BSAPICPP.SetUserPointer2(bodyu.ptr, val); | ||
854 | } | ||
855 | |||
856 | // ===================================================================================== | ||
857 | // btRigidBody entries | ||
858 | public override void ApplyGravity(BulletBody obj) | ||
859 | { | ||
860 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
861 | BSAPICPP.ApplyGravity2(bodyu.ptr); | ||
862 | } | ||
863 | |||
864 | public override void SetGravity(BulletBody obj, Vector3 val) | ||
865 | { | ||
866 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
867 | BSAPICPP.SetGravity2(bodyu.ptr, val); | ||
868 | } | ||
869 | |||
870 | public override Vector3 GetGravity(BulletBody obj) | ||
871 | { | ||
872 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
873 | return BSAPICPP.GetGravity2(bodyu.ptr); | ||
874 | } | ||
875 | |||
876 | public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping) | ||
877 | { | ||
878 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
879 | BSAPICPP.SetDamping2(bodyu.ptr, lin_damping, ang_damping); | ||
880 | } | ||
881 | |||
882 | public override void SetLinearDamping(BulletBody obj, float lin_damping) | ||
883 | { | ||
884 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
885 | BSAPICPP.SetLinearDamping2(bodyu.ptr, lin_damping); | ||
886 | } | ||
887 | |||
888 | public override void SetAngularDamping(BulletBody obj, float ang_damping) | ||
889 | { | ||
890 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
891 | BSAPICPP.SetAngularDamping2(bodyu.ptr, ang_damping); | ||
892 | } | ||
893 | |||
894 | public override float GetLinearDamping(BulletBody obj) | ||
895 | { | ||
896 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
897 | return BSAPICPP.GetLinearDamping2(bodyu.ptr); | ||
898 | } | ||
899 | |||
900 | public override float GetAngularDamping(BulletBody obj) | ||
901 | { | ||
902 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
903 | return BSAPICPP.GetAngularDamping2(bodyu.ptr); | ||
904 | } | ||
905 | |||
906 | public override float GetLinearSleepingThreshold(BulletBody obj) | ||
907 | { | ||
908 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
909 | return BSAPICPP.GetLinearSleepingThreshold2(bodyu.ptr); | ||
910 | } | ||
911 | |||
912 | public override void ApplyDamping(BulletBody obj, float timeStep) | ||
913 | { | ||
914 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
915 | BSAPICPP.ApplyDamping2(bodyu.ptr, timeStep); | ||
916 | } | ||
917 | |||
918 | public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia) | ||
919 | { | ||
920 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
921 | BSAPICPP.SetMassProps2(bodyu.ptr, mass, inertia); | ||
922 | } | ||
923 | |||
924 | public override Vector3 GetLinearFactor(BulletBody obj) | ||
925 | { | ||
926 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
927 | return BSAPICPP.GetLinearFactor2(bodyu.ptr); | ||
928 | } | ||
929 | |||
930 | public override void SetLinearFactor(BulletBody obj, Vector3 factor) | ||
931 | { | ||
932 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
933 | BSAPICPP.SetLinearFactor2(bodyu.ptr, factor); | ||
934 | } | ||
935 | |||
936 | public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot) | ||
937 | { | ||
938 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
939 | BSAPICPP.SetCenterOfMassByPosRot2(bodyu.ptr, pos, rot); | ||
940 | } | ||
941 | |||
942 | // Add a force to the object as if its mass is one. | ||
943 | // Deep down in Bullet: m_totalForce += force*m_linearFactor; | ||
944 | public override void ApplyCentralForce(BulletBody obj, Vector3 force) | ||
945 | { | ||
946 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
947 | BSAPICPP.ApplyCentralForce2(bodyu.ptr, force); | ||
948 | } | ||
949 | |||
950 | // Set the force being applied to the object as if its mass is one. | ||
951 | public override void SetObjectForce(BulletBody obj, Vector3 force) | ||
952 | { | ||
953 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
954 | BSAPICPP.SetObjectForce2(bodyu.ptr, force); | ||
955 | } | ||
956 | |||
957 | public override Vector3 GetTotalForce(BulletBody obj) | ||
958 | { | ||
959 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
960 | return BSAPICPP.GetTotalForce2(bodyu.ptr); | ||
961 | } | ||
962 | |||
963 | public override Vector3 GetTotalTorque(BulletBody obj) | ||
964 | { | ||
965 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
966 | return BSAPICPP.GetTotalTorque2(bodyu.ptr); | ||
967 | } | ||
968 | |||
969 | public override Vector3 GetInvInertiaDiagLocal(BulletBody obj) | ||
970 | { | ||
971 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
972 | return BSAPICPP.GetInvInertiaDiagLocal2(bodyu.ptr); | ||
973 | } | ||
974 | |||
975 | public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert) | ||
976 | { | ||
977 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
978 | BSAPICPP.SetInvInertiaDiagLocal2(bodyu.ptr, inert); | ||
979 | } | ||
980 | |||
981 | public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold) | ||
982 | { | ||
983 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
984 | BSAPICPP.SetSleepingThresholds2(bodyu.ptr, lin_threshold, ang_threshold); | ||
985 | } | ||
986 | |||
987 | // Deep down in Bullet: m_totalTorque += torque*m_angularFactor; | ||
988 | public override void ApplyTorque(BulletBody obj, Vector3 torque) | ||
989 | { | ||
990 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
991 | BSAPICPP.ApplyTorque2(bodyu.ptr, torque); | ||
992 | } | ||
993 | |||
994 | // Apply force at the given point. Will add torque to the object. | ||
995 | // Deep down in Bullet: applyCentralForce(force); | ||
996 | // applyTorque(rel_pos.cross(force*m_linearFactor)); | ||
997 | public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos) | ||
998 | { | ||
999 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1000 | BSAPICPP.ApplyForce2(bodyu.ptr, force, pos); | ||
1001 | } | ||
1002 | |||
1003 | // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. | ||
1004 | // Deep down in Bullet: m_linearVelocity += impulse *m_linearFactor * m_inverseMass; | ||
1005 | public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp) | ||
1006 | { | ||
1007 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1008 | BSAPICPP.ApplyCentralImpulse2(bodyu.ptr, imp); | ||
1009 | } | ||
1010 | |||
1011 | // Apply impulse to the object's torque. Force is scaled by object's mass. | ||
1012 | // Deep down in Bullet: m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor; | ||
1013 | public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp) | ||
1014 | { | ||
1015 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1016 | BSAPICPP.ApplyTorqueImpulse2(bodyu.ptr, imp); | ||
1017 | } | ||
1018 | |||
1019 | // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. | ||
1020 | // Deep down in Bullet: applyCentralImpulse(impulse); | ||
1021 | // applyTorqueImpulse(rel_pos.cross(impulse*m_linearFactor)); | ||
1022 | public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos) | ||
1023 | { | ||
1024 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1025 | BSAPICPP.ApplyImpulse2(bodyu.ptr, imp, pos); | ||
1026 | } | ||
1027 | |||
1028 | public override void ClearForces(BulletBody obj) | ||
1029 | { | ||
1030 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1031 | BSAPICPP.ClearForces2(bodyu.ptr); | ||
1032 | } | ||
1033 | |||
1034 | public override void ClearAllForces(BulletBody obj) | ||
1035 | { | ||
1036 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1037 | BSAPICPP.ClearAllForces2(bodyu.ptr); | ||
1038 | } | ||
1039 | |||
1040 | public override void UpdateInertiaTensor(BulletBody obj) | ||
1041 | { | ||
1042 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1043 | BSAPICPP.UpdateInertiaTensor2(bodyu.ptr); | ||
1044 | } | ||
1045 | |||
1046 | public override Vector3 GetLinearVelocity(BulletBody obj) | ||
1047 | { | ||
1048 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1049 | return BSAPICPP.GetLinearVelocity2(bodyu.ptr); | ||
1050 | } | ||
1051 | |||
1052 | public override Vector3 GetAngularVelocity(BulletBody obj) | ||
1053 | { | ||
1054 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1055 | return BSAPICPP.GetAngularVelocity2(bodyu.ptr); | ||
1056 | } | ||
1057 | |||
1058 | public override void SetLinearVelocity(BulletBody obj, Vector3 vel) | ||
1059 | { | ||
1060 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1061 | BSAPICPP.SetLinearVelocity2(bodyu.ptr, vel); | ||
1062 | } | ||
1063 | |||
1064 | public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity) | ||
1065 | { | ||
1066 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1067 | BSAPICPP.SetAngularVelocity2(bodyu.ptr, angularVelocity); | ||
1068 | } | ||
1069 | |||
1070 | public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos) | ||
1071 | { | ||
1072 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1073 | return BSAPICPP.GetVelocityInLocalPoint2(bodyu.ptr, pos); | ||
1074 | } | ||
1075 | |||
1076 | public override void Translate(BulletBody obj, Vector3 trans) | ||
1077 | { | ||
1078 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1079 | BSAPICPP.Translate2(bodyu.ptr, trans); | ||
1080 | } | ||
1081 | |||
1082 | public override void UpdateDeactivation(BulletBody obj, float timeStep) | ||
1083 | { | ||
1084 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1085 | BSAPICPP.UpdateDeactivation2(bodyu.ptr, timeStep); | ||
1086 | } | ||
1087 | |||
1088 | public override bool WantsSleeping(BulletBody obj) | ||
1089 | { | ||
1090 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1091 | return BSAPICPP.WantsSleeping2(bodyu.ptr); | ||
1092 | } | ||
1093 | |||
1094 | public override void SetAngularFactor(BulletBody obj, float factor) | ||
1095 | { | ||
1096 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1097 | BSAPICPP.SetAngularFactor2(bodyu.ptr, factor); | ||
1098 | } | ||
1099 | |||
1100 | public override void SetAngularFactorV(BulletBody obj, Vector3 factor) | ||
1101 | { | ||
1102 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1103 | BSAPICPP.SetAngularFactorV2(bodyu.ptr, factor); | ||
1104 | } | ||
1105 | |||
1106 | public override Vector3 GetAngularFactor(BulletBody obj) | ||
1107 | { | ||
1108 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1109 | return BSAPICPP.GetAngularFactor2(bodyu.ptr); | ||
1110 | } | ||
1111 | |||
1112 | public override bool IsInWorld(BulletWorld world, BulletBody obj) | ||
1113 | { | ||
1114 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1115 | return BSAPICPP.IsInWorld2(bodyu.ptr); | ||
1116 | } | ||
1117 | |||
1118 | public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain) | ||
1119 | { | ||
1120 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1121 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
1122 | BSAPICPP.AddConstraintRef2(bodyu.ptr, constrainu.ptr); | ||
1123 | } | ||
1124 | |||
1125 | public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain) | ||
1126 | { | ||
1127 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1128 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
1129 | BSAPICPP.RemoveConstraintRef2(bodyu.ptr, constrainu.ptr); | ||
1130 | } | ||
1131 | |||
1132 | public override BulletConstraint GetConstraintRef(BulletBody obj, int index) | ||
1133 | { | ||
1134 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1135 | return new BulletConstraintUnman(BSAPICPP.GetConstraintRef2(bodyu.ptr, index)); | ||
1136 | } | ||
1137 | |||
1138 | public override int GetNumConstraintRefs(BulletBody obj) | ||
1139 | { | ||
1140 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
1141 | return BSAPICPP.GetNumConstraintRefs2(bodyu.ptr); | ||
1142 | } | ||
1143 | |||
1144 | public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask) | ||
1145 | { | ||
1146 | BulletBodyUnman bodyu = body as BulletBodyUnman; | ||
1147 | return BSAPICPP.SetCollisionGroupMask2(bodyu.ptr, filter, mask); | ||
1148 | } | ||
1149 | |||
1150 | // ===================================================================================== | ||
1151 | // btCollisionShape entries | ||
1152 | |||
1153 | public override float GetAngularMotionDisc(BulletShape shape) | ||
1154 | { | ||
1155 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1156 | return BSAPICPP.GetAngularMotionDisc2(shapeu.ptr); | ||
1157 | } | ||
1158 | |||
1159 | public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor) | ||
1160 | { | ||
1161 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1162 | return BSAPICPP.GetContactBreakingThreshold2(shapeu.ptr, defaultFactor); | ||
1163 | } | ||
1164 | |||
1165 | public override bool IsPolyhedral(BulletShape shape) | ||
1166 | { | ||
1167 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1168 | return BSAPICPP.IsPolyhedral2(shapeu.ptr); | ||
1169 | } | ||
1170 | |||
1171 | public override bool IsConvex2d(BulletShape shape) | ||
1172 | { | ||
1173 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1174 | return BSAPICPP.IsConvex2d2(shapeu.ptr); | ||
1175 | } | ||
1176 | |||
1177 | public override bool IsConvex(BulletShape shape) | ||
1178 | { | ||
1179 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1180 | return BSAPICPP.IsConvex2(shapeu.ptr); | ||
1181 | } | ||
1182 | |||
1183 | public override bool IsNonMoving(BulletShape shape) | ||
1184 | { | ||
1185 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1186 | return BSAPICPP.IsNonMoving2(shapeu.ptr); | ||
1187 | } | ||
1188 | |||
1189 | public override bool IsConcave(BulletShape shape) | ||
1190 | { | ||
1191 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1192 | return BSAPICPP.IsConcave2(shapeu.ptr); | ||
1193 | } | ||
1194 | |||
1195 | public override bool IsCompound(BulletShape shape) | ||
1196 | { | ||
1197 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1198 | return BSAPICPP.IsCompound2(shapeu.ptr); | ||
1199 | } | ||
1200 | |||
1201 | public override bool IsSoftBody(BulletShape shape) | ||
1202 | { | ||
1203 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1204 | return BSAPICPP.IsSoftBody2(shapeu.ptr); | ||
1205 | } | ||
1206 | |||
1207 | public override bool IsInfinite(BulletShape shape) | ||
1208 | { | ||
1209 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1210 | return BSAPICPP.IsInfinite2(shapeu.ptr); | ||
1211 | } | ||
1212 | |||
1213 | public override void SetLocalScaling(BulletShape shape, Vector3 scale) | ||
1214 | { | ||
1215 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1216 | BSAPICPP.SetLocalScaling2(shapeu.ptr, scale); | ||
1217 | } | ||
1218 | |||
1219 | public override Vector3 GetLocalScaling(BulletShape shape) | ||
1220 | { | ||
1221 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1222 | return BSAPICPP.GetLocalScaling2(shapeu.ptr); | ||
1223 | } | ||
1224 | |||
1225 | public override Vector3 CalculateLocalInertia(BulletShape shape, float mass) | ||
1226 | { | ||
1227 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1228 | return BSAPICPP.CalculateLocalInertia2(shapeu.ptr, mass); | ||
1229 | } | ||
1230 | |||
1231 | public override int GetShapeType(BulletShape shape) | ||
1232 | { | ||
1233 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1234 | return BSAPICPP.GetShapeType2(shapeu.ptr); | ||
1235 | } | ||
1236 | |||
1237 | public override void SetMargin(BulletShape shape, float val) | ||
1238 | { | ||
1239 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1240 | BSAPICPP.SetMargin2(shapeu.ptr, val); | ||
1241 | } | ||
1242 | |||
1243 | public override float GetMargin(BulletShape shape) | ||
1244 | { | ||
1245 | BulletShapeUnman shapeu = shape as BulletShapeUnman; | ||
1246 | return BSAPICPP.GetMargin2(shapeu.ptr); | ||
1247 | } | ||
1248 | |||
1249 | // ===================================================================================== | ||
1250 | // Debugging | ||
1251 | public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject) | ||
1252 | { | ||
1253 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1254 | BulletBodyUnman bodyu = collisionObject as BulletBodyUnman; | ||
1255 | BSAPICPP.DumpRigidBody2(worldu.ptr, bodyu.ptr); | ||
1256 | } | ||
1257 | |||
1258 | public override void DumpCollisionShape(BulletWorld world, BulletShape collisionShape) | ||
1259 | { | ||
1260 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1261 | BulletShapeUnman shapeu = collisionShape as BulletShapeUnman; | ||
1262 | BSAPICPP.DumpCollisionShape2(worldu.ptr, shapeu.ptr); | ||
1263 | } | ||
1264 | |||
1265 | public override void DumpConstraint(BulletWorld world, BulletConstraint constrain) | ||
1266 | { | ||
1267 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1268 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
1269 | BSAPICPP.DumpConstraint2(worldu.ptr, constrainu.ptr); | ||
1270 | } | ||
1271 | |||
1272 | public override void DumpActivationInfo(BulletWorld world) | ||
1273 | { | ||
1274 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1275 | BSAPICPP.DumpActivationInfo2(worldu.ptr); | ||
1276 | } | ||
1277 | |||
1278 | public override void DumpAllInfo(BulletWorld world) | ||
1279 | { | ||
1280 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1281 | BSAPICPP.DumpAllInfo2(worldu.ptr); | ||
1282 | } | ||
1283 | |||
1284 | public override void DumpPhysicsStatistics(BulletWorld world) | ||
1285 | { | ||
1286 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1287 | BSAPICPP.DumpPhysicsStatistics2(worldu.ptr); | ||
1288 | } | ||
1289 | public override void ResetBroadphasePool(BulletWorld world) | ||
1290 | { | ||
1291 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1292 | BSAPICPP.ResetBroadphasePool(worldu.ptr); | ||
1293 | } | ||
1294 | public override void ResetConstraintSolver(BulletWorld world) | ||
1295 | { | ||
1296 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
1297 | BSAPICPP.ResetConstraintSolver(worldu.ptr); | ||
1298 | } | ||
1299 | |||
1300 | // ===================================================================================== | ||
1301 | // ===================================================================================== | ||
1302 | // ===================================================================================== | ||
1303 | // ===================================================================================== | ||
1304 | // ===================================================================================== | ||
1305 | // The actual interface to the unmanaged code | ||
1306 | static class BSAPICPP | ||
1307 | { | ||
1308 | // =============================================================================== | ||
1309 | // Link back to the managed code for outputting log messages | ||
1310 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
1311 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | ||
1312 | |||
1313 | // =============================================================================== | ||
1314 | // Initialization and simulation | ||
1315 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1316 | public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, | ||
1317 | int maxCollisions, IntPtr collisionArray, | ||
1318 | int maxUpdates, IntPtr updateArray, | ||
1319 | DebugLogCallback logRoutine); | ||
1320 | |||
1321 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1322 | public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
1323 | out int updatedEntityCount, out int collidersCount); | ||
1324 | |||
1325 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1326 | public static extern void Shutdown2(IntPtr sim); | ||
1327 | |||
1328 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1329 | public static extern bool PushUpdate2(IntPtr obj); | ||
1330 | |||
1331 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1332 | public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); | ||
1333 | |||
1334 | // ===================================================================================== | ||
1335 | // Mesh, hull, shape and body creation helper routines | ||
1336 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1337 | public static extern IntPtr CreateMeshShape2(IntPtr world, | ||
1338 | int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
1339 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | ||
1340 | |||
1341 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1342 | public static extern IntPtr CreateHullShape2(IntPtr world, | ||
1343 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); | ||
1344 | |||
1345 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1346 | public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); | ||
1347 | |||
1348 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1349 | public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); | ||
1350 | |||
1351 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1352 | public static extern bool IsNativeShape2(IntPtr shape); | ||
1353 | |||
1354 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1355 | public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin); | ||
1356 | |||
1357 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1358 | public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); | ||
1359 | |||
1360 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1361 | public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); | ||
1362 | |||
1363 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1364 | public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); | ||
1365 | |||
1366 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1367 | public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); | ||
1368 | |||
1369 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1370 | public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); | ||
1371 | |||
1372 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1373 | public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); | ||
1374 | |||
1375 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1376 | public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); | ||
1377 | |||
1378 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1379 | public static extern void UpdateChildTransform2(IntPtr pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb); | ||
1380 | |||
1381 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1382 | public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); | ||
1383 | |||
1384 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1385 | public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); | ||
1386 | |||
1387 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1388 | public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); | ||
1389 | |||
1390 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1391 | public static extern int GetBodyType2(IntPtr obj); | ||
1392 | |||
1393 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1394 | public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
1395 | |||
1396 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1397 | public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
1398 | |||
1399 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1400 | public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
1401 | |||
1402 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1403 | public static extern void DestroyObject2(IntPtr sim, IntPtr obj); | ||
1404 | |||
1405 | // ===================================================================================== | ||
1406 | // Terrain creation and helper routines | ||
1407 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1408 | public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); | ||
1409 | |||
1410 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1411 | public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight, | ||
1412 | [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, | ||
1413 | float scaleFactor, float collisionMargin); | ||
1414 | |||
1415 | // ===================================================================================== | ||
1416 | // Constraint creation and helper routines | ||
1417 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1418 | public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
1419 | Vector3 frame1loc, Quaternion frame1rot, | ||
1420 | Vector3 frame2loc, Quaternion frame2rot, | ||
1421 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
1422 | |||
1423 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1424 | public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
1425 | Vector3 joinPoint, | ||
1426 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
1427 | |||
1428 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1429 | public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
1430 | Vector3 pivotinA, Vector3 pivotinB, | ||
1431 | Vector3 axisInA, Vector3 axisInB, | ||
1432 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
1433 | |||
1434 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1435 | public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); | ||
1436 | |||
1437 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1438 | public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); | ||
1439 | |||
1440 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1441 | public static extern bool SetFrames2(IntPtr constrain, | ||
1442 | Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); | ||
1443 | |||
1444 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1445 | public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); | ||
1446 | |||
1447 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1448 | public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); | ||
1449 | |||
1450 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1451 | public static extern bool UseFrameOffset2(IntPtr constrain, float enable); | ||
1452 | |||
1453 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1454 | public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); | ||
1455 | |||
1456 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1457 | public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); | ||
1458 | |||
1459 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1460 | public static extern bool CalculateTransforms2(IntPtr constrain); | ||
1461 | |||
1462 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1463 | public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); | ||
1464 | |||
1465 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1466 | public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); | ||
1467 | |||
1468 | // ===================================================================================== | ||
1469 | // btCollisionWorld entries | ||
1470 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1471 | public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); | ||
1472 | |||
1473 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1474 | public static extern void UpdateAabbs2(IntPtr world); | ||
1475 | |||
1476 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1477 | public static extern bool GetForceUpdateAllAabbs2(IntPtr world); | ||
1478 | |||
1479 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1480 | public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); | ||
1481 | |||
1482 | // ===================================================================================== | ||
1483 | // btDynamicsWorld entries | ||
1484 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1485 | public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); | ||
1486 | |||
1487 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1488 | public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); | ||
1489 | |||
1490 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1491 | public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); | ||
1492 | |||
1493 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1494 | public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); | ||
1495 | // ===================================================================================== | ||
1496 | // btCollisionObject entries | ||
1497 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1498 | public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); | ||
1499 | |||
1500 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1501 | public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); | ||
1502 | |||
1503 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1504 | public static extern bool HasAnisotripicFriction2(IntPtr constrain); | ||
1505 | |||
1506 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1507 | public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); | ||
1508 | |||
1509 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1510 | public static extern float GetContactProcessingThreshold2(IntPtr obj); | ||
1511 | |||
1512 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1513 | public static extern bool IsStaticObject2(IntPtr obj); | ||
1514 | |||
1515 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1516 | public static extern bool IsKinematicObject2(IntPtr obj); | ||
1517 | |||
1518 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1519 | public static extern bool IsStaticOrKinematicObject2(IntPtr obj); | ||
1520 | |||
1521 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1522 | public static extern bool HasContactResponse2(IntPtr obj); | ||
1523 | |||
1524 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1525 | public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); | ||
1526 | |||
1527 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1528 | public static extern IntPtr GetCollisionShape2(IntPtr obj); | ||
1529 | |||
1530 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1531 | public static extern int GetActivationState2(IntPtr obj); | ||
1532 | |||
1533 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1534 | public static extern void SetActivationState2(IntPtr obj, int state); | ||
1535 | |||
1536 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1537 | public static extern void SetDeactivationTime2(IntPtr obj, float dtime); | ||
1538 | |||
1539 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1540 | public static extern float GetDeactivationTime2(IntPtr obj); | ||
1541 | |||
1542 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1543 | public static extern void ForceActivationState2(IntPtr obj, ActivationState state); | ||
1544 | |||
1545 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1546 | public static extern void Activate2(IntPtr obj, bool forceActivation); | ||
1547 | |||
1548 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1549 | public static extern bool IsActive2(IntPtr obj); | ||
1550 | |||
1551 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1552 | public static extern void SetRestitution2(IntPtr obj, float val); | ||
1553 | |||
1554 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1555 | public static extern float GetRestitution2(IntPtr obj); | ||
1556 | |||
1557 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1558 | public static extern void SetFriction2(IntPtr obj, float val); | ||
1559 | |||
1560 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1561 | public static extern float GetFriction2(IntPtr obj); | ||
1562 | |||
1563 | /* Haven't defined the type 'Transform' | ||
1564 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1565 | public static extern Transform GetWorldTransform2(IntPtr obj); | ||
1566 | |||
1567 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1568 | public static extern void setWorldTransform2(IntPtr obj, Transform trans); | ||
1569 | */ | ||
1570 | |||
1571 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1572 | public static extern Vector3 GetPosition2(IntPtr obj); | ||
1573 | |||
1574 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1575 | public static extern Quaternion GetOrientation2(IntPtr obj); | ||
1576 | |||
1577 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1578 | public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); | ||
1579 | |||
1580 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1581 | public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); | ||
1582 | |||
1583 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1584 | public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); | ||
1585 | |||
1586 | /* | ||
1587 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1588 | public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); | ||
1589 | |||
1590 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1591 | public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); | ||
1592 | */ | ||
1593 | |||
1594 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1595 | public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); | ||
1596 | |||
1597 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1598 | public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); | ||
1599 | |||
1600 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1601 | public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); | ||
1602 | |||
1603 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1604 | public static extern float GetHitFraction2(IntPtr obj); | ||
1605 | |||
1606 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1607 | public static extern void SetHitFraction2(IntPtr obj, float val); | ||
1608 | |||
1609 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1610 | public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); | ||
1611 | |||
1612 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1613 | public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
1614 | |||
1615 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1616 | public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
1617 | |||
1618 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1619 | public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
1620 | |||
1621 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1622 | public static extern float GetCcdMotionThreshold2(IntPtr obj); | ||
1623 | |||
1624 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1625 | public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); | ||
1626 | |||
1627 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1628 | public static extern float GetCcdSweptSphereRadius2(IntPtr obj); | ||
1629 | |||
1630 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1631 | public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); | ||
1632 | |||
1633 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1634 | public static extern IntPtr GetUserPointer2(IntPtr obj); | ||
1635 | |||
1636 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1637 | public static extern void SetUserPointer2(IntPtr obj, IntPtr val); | ||
1638 | |||
1639 | // ===================================================================================== | ||
1640 | // btRigidBody entries | ||
1641 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1642 | public static extern void ApplyGravity2(IntPtr obj); | ||
1643 | |||
1644 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1645 | public static extern void SetGravity2(IntPtr obj, Vector3 val); | ||
1646 | |||
1647 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1648 | public static extern Vector3 GetGravity2(IntPtr obj); | ||
1649 | |||
1650 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1651 | public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); | ||
1652 | |||
1653 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1654 | public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); | ||
1655 | |||
1656 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1657 | public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); | ||
1658 | |||
1659 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1660 | public static extern float GetLinearDamping2(IntPtr obj); | ||
1661 | |||
1662 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1663 | public static extern float GetAngularDamping2(IntPtr obj); | ||
1664 | |||
1665 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1666 | public static extern float GetLinearSleepingThreshold2(IntPtr obj); | ||
1667 | |||
1668 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1669 | public static extern float GetAngularSleepingThreshold2(IntPtr obj); | ||
1670 | |||
1671 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1672 | public static extern void ApplyDamping2(IntPtr obj, float timeStep); | ||
1673 | |||
1674 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1675 | public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); | ||
1676 | |||
1677 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1678 | public static extern Vector3 GetLinearFactor2(IntPtr obj); | ||
1679 | |||
1680 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1681 | public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); | ||
1682 | |||
1683 | /* | ||
1684 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1685 | public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); | ||
1686 | */ | ||
1687 | |||
1688 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1689 | public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); | ||
1690 | |||
1691 | // Add a force to the object as if its mass is one. | ||
1692 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1693 | public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); | ||
1694 | |||
1695 | // Set the force being applied to the object as if its mass is one. | ||
1696 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1697 | public static extern void SetObjectForce2(IntPtr obj, Vector3 force); | ||
1698 | |||
1699 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1700 | public static extern Vector3 GetTotalForce2(IntPtr obj); | ||
1701 | |||
1702 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1703 | public static extern Vector3 GetTotalTorque2(IntPtr obj); | ||
1704 | |||
1705 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1706 | public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); | ||
1707 | |||
1708 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1709 | public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); | ||
1710 | |||
1711 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1712 | public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); | ||
1713 | |||
1714 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1715 | public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); | ||
1716 | |||
1717 | // Apply force at the given point. Will add torque to the object. | ||
1718 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1719 | public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); | ||
1720 | |||
1721 | // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. | ||
1722 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1723 | public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); | ||
1724 | |||
1725 | // Apply impulse to the object's torque. Force is scaled by object's mass. | ||
1726 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1727 | public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); | ||
1728 | |||
1729 | // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. | ||
1730 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1731 | public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); | ||
1732 | |||
1733 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1734 | public static extern void ClearForces2(IntPtr obj); | ||
1735 | |||
1736 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1737 | public static extern void ClearAllForces2(IntPtr obj); | ||
1738 | |||
1739 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1740 | public static extern void UpdateInertiaTensor2(IntPtr obj); | ||
1741 | |||
1742 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1743 | public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); | ||
1744 | |||
1745 | /* | ||
1746 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1747 | public static extern Transform GetCenterOfMassTransform2(IntPtr obj); | ||
1748 | */ | ||
1749 | |||
1750 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1751 | public static extern Vector3 GetLinearVelocity2(IntPtr obj); | ||
1752 | |||
1753 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1754 | public static extern Vector3 GetAngularVelocity2(IntPtr obj); | ||
1755 | |||
1756 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1757 | public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); | ||
1758 | |||
1759 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1760 | public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); | ||
1761 | |||
1762 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1763 | public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); | ||
1764 | |||
1765 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1766 | public static extern void Translate2(IntPtr obj, Vector3 trans); | ||
1767 | |||
1768 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1769 | public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); | ||
1770 | |||
1771 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1772 | public static extern bool WantsSleeping2(IntPtr obj); | ||
1773 | |||
1774 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1775 | public static extern void SetAngularFactor2(IntPtr obj, float factor); | ||
1776 | |||
1777 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1778 | public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); | ||
1779 | |||
1780 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1781 | public static extern Vector3 GetAngularFactor2(IntPtr obj); | ||
1782 | |||
1783 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1784 | public static extern bool IsInWorld2(IntPtr obj); | ||
1785 | |||
1786 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1787 | public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); | ||
1788 | |||
1789 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1790 | public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); | ||
1791 | |||
1792 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1793 | public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); | ||
1794 | |||
1795 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1796 | public static extern int GetNumConstraintRefs2(IntPtr obj); | ||
1797 | |||
1798 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1799 | public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask); | ||
1800 | |||
1801 | // ===================================================================================== | ||
1802 | // btCollisionShape entries | ||
1803 | |||
1804 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1805 | public static extern float GetAngularMotionDisc2(IntPtr shape); | ||
1806 | |||
1807 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1808 | public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); | ||
1809 | |||
1810 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1811 | public static extern bool IsPolyhedral2(IntPtr shape); | ||
1812 | |||
1813 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1814 | public static extern bool IsConvex2d2(IntPtr shape); | ||
1815 | |||
1816 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1817 | public static extern bool IsConvex2(IntPtr shape); | ||
1818 | |||
1819 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1820 | public static extern bool IsNonMoving2(IntPtr shape); | ||
1821 | |||
1822 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1823 | public static extern bool IsConcave2(IntPtr shape); | ||
1824 | |||
1825 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1826 | public static extern bool IsCompound2(IntPtr shape); | ||
1827 | |||
1828 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1829 | public static extern bool IsSoftBody2(IntPtr shape); | ||
1830 | |||
1831 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1832 | public static extern bool IsInfinite2(IntPtr shape); | ||
1833 | |||
1834 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1835 | public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); | ||
1836 | |||
1837 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1838 | public static extern Vector3 GetLocalScaling2(IntPtr shape); | ||
1839 | |||
1840 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1841 | public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); | ||
1842 | |||
1843 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1844 | public static extern int GetShapeType2(IntPtr shape); | ||
1845 | |||
1846 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1847 | public static extern void SetMargin2(IntPtr shape, float val); | ||
1848 | |||
1849 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1850 | public static extern float GetMargin2(IntPtr shape); | ||
1851 | |||
1852 | // ===================================================================================== | ||
1853 | // Debugging | ||
1854 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1855 | public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); | ||
1856 | |||
1857 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1858 | public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); | ||
1859 | |||
1860 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1861 | public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); | ||
1862 | |||
1863 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1864 | public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); | ||
1865 | |||
1866 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1867 | public static extern void DumpActivationInfo2(IntPtr sim); | ||
1868 | |||
1869 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1870 | public static extern void DumpAllInfo2(IntPtr sim); | ||
1871 | |||
1872 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1873 | public static extern void DumpPhysicsStatistics2(IntPtr sim); | ||
1874 | |||
1875 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1876 | public static extern void ResetBroadphasePool(IntPtr sim); | ||
1877 | |||
1878 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1879 | public static extern void ResetConstraintSolver(IntPtr sim); | ||
1880 | |||
1881 | } | ||
1882 | |||
1883 | } | ||
1884 | |||
1885 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs new file mode 100755 index 0000000..49b1730 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | |||
@@ -0,0 +1,1959 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.IO; | ||
30 | using System.Text; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | |||
34 | using OpenMetaverse; | ||
35 | |||
36 | using BulletXNA; | ||
37 | using BulletXNA.LinearMath; | ||
38 | using BulletXNA.BulletCollision; | ||
39 | using BulletXNA.BulletDynamics; | ||
40 | using BulletXNA.BulletCollision.CollisionDispatch; | ||
41 | |||
42 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
43 | { | ||
44 | public sealed class BSAPIXNA : BSAPITemplate | ||
45 | { | ||
46 | private sealed class BulletWorldXNA : BulletWorld | ||
47 | { | ||
48 | public DiscreteDynamicsWorld world; | ||
49 | public BulletWorldXNA(uint id, BSScene physScene, DiscreteDynamicsWorld xx) | ||
50 | : base(id, physScene) | ||
51 | { | ||
52 | world = xx; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | private sealed class BulletBodyXNA : BulletBody | ||
57 | { | ||
58 | public CollisionObject body; | ||
59 | public RigidBody rigidBody { get { return RigidBody.Upcast(body); } } | ||
60 | |||
61 | public BulletBodyXNA(uint id, CollisionObject xx) | ||
62 | : base(id) | ||
63 | { | ||
64 | body = xx; | ||
65 | } | ||
66 | public override bool HasPhysicalBody | ||
67 | { | ||
68 | get { return body != null; } | ||
69 | } | ||
70 | public override void Clear() | ||
71 | { | ||
72 | body = null; | ||
73 | } | ||
74 | public override string AddrString | ||
75 | { | ||
76 | get { return "XNARigidBody"; } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | private sealed class BulletShapeXNA : BulletShape | ||
81 | { | ||
82 | public CollisionShape shape; | ||
83 | public BulletShapeXNA(CollisionShape xx, BSPhysicsShapeType typ) | ||
84 | : base() | ||
85 | { | ||
86 | shape = xx; | ||
87 | type = typ; | ||
88 | } | ||
89 | public override bool HasPhysicalShape | ||
90 | { | ||
91 | get { return shape != null; } | ||
92 | } | ||
93 | public override void Clear() | ||
94 | { | ||
95 | shape = null; | ||
96 | } | ||
97 | public override BulletShape Clone() | ||
98 | { | ||
99 | return new BulletShapeXNA(shape, type); | ||
100 | } | ||
101 | public override bool ReferenceSame(BulletShape other) | ||
102 | { | ||
103 | BulletShapeXNA otheru = other as BulletShapeXNA; | ||
104 | return (otheru != null) && (this.shape == otheru.shape); | ||
105 | |||
106 | } | ||
107 | public override string AddrString | ||
108 | { | ||
109 | get { return "XNACollisionShape"; } | ||
110 | } | ||
111 | } | ||
112 | private sealed class BulletConstraintXNA : BulletConstraint | ||
113 | { | ||
114 | public TypedConstraint constrain; | ||
115 | public BulletConstraintXNA(TypedConstraint xx) : base() | ||
116 | { | ||
117 | constrain = xx; | ||
118 | } | ||
119 | |||
120 | public override void Clear() | ||
121 | { | ||
122 | constrain = null; | ||
123 | } | ||
124 | public override bool HasPhysicalConstraint { get { return constrain != null; } } | ||
125 | |||
126 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
127 | public override string AddrString | ||
128 | { | ||
129 | get { return "XNAConstraint"; } | ||
130 | } | ||
131 | } | ||
132 | internal int m_maxCollisions; | ||
133 | internal CollisionDesc[] m_collisionArray; | ||
134 | |||
135 | internal int m_maxUpdatesPerFrame; | ||
136 | internal EntityProperties[] m_updateArray; | ||
137 | |||
138 | private static int m_collisionsThisFrame; | ||
139 | private BSScene PhysicsScene { get; set; } | ||
140 | |||
141 | public override string BulletEngineName { get { return "BulletXNA"; } } | ||
142 | public override string BulletEngineVersion { get; protected set; } | ||
143 | |||
144 | public BSAPIXNA(string paramName, BSScene physScene) | ||
145 | { | ||
146 | PhysicsScene = physScene; | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// | ||
151 | /// </summary> | ||
152 | /// <param name="p"></param> | ||
153 | /// <param name="p_2"></param> | ||
154 | public override bool RemoveObjectFromWorld(BulletWorld pWorld, BulletBody pBody) | ||
155 | { | ||
156 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
157 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | ||
158 | world.RemoveRigidBody(body); | ||
159 | return true; | ||
160 | } | ||
161 | |||
162 | public override bool AddConstraintToWorld(BulletWorld pWorld, BulletConstraint pConstraint, bool pDisableCollisionsBetweenLinkedObjects) | ||
163 | { | ||
164 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
165 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; | ||
166 | world.AddConstraint(constraint, pDisableCollisionsBetweenLinkedObjects); | ||
167 | |||
168 | return true; | ||
169 | |||
170 | } | ||
171 | |||
172 | public override bool RemoveConstraintFromWorld(BulletWorld pWorld, BulletConstraint pConstraint) | ||
173 | { | ||
174 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
175 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; | ||
176 | world.RemoveConstraint(constraint); | ||
177 | return true; | ||
178 | } | ||
179 | |||
180 | public override void SetRestitution(BulletBody pCollisionObject, float pRestitution) | ||
181 | { | ||
182 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
183 | collisionObject.SetRestitution(pRestitution); | ||
184 | } | ||
185 | |||
186 | public override int GetShapeType(BulletShape pShape) | ||
187 | { | ||
188 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
189 | return (int)shape.GetShapeType(); | ||
190 | } | ||
191 | public override void SetMargin(BulletShape pShape, float pMargin) | ||
192 | { | ||
193 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
194 | shape.SetMargin(pMargin); | ||
195 | } | ||
196 | |||
197 | public override float GetMargin(BulletShape pShape) | ||
198 | { | ||
199 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
200 | return shape.GetMargin(); | ||
201 | } | ||
202 | |||
203 | public override void SetLocalScaling(BulletShape pShape, Vector3 pScale) | ||
204 | { | ||
205 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
206 | IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | ||
207 | shape.SetLocalScaling(ref vec); | ||
208 | |||
209 | } | ||
210 | |||
211 | public override void SetContactProcessingThreshold(BulletBody pCollisionObject, float contactprocessingthreshold) | ||
212 | { | ||
213 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
214 | collisionObject.SetContactProcessingThreshold(contactprocessingthreshold); | ||
215 | } | ||
216 | |||
217 | public override void SetCcdMotionThreshold(BulletBody pCollisionObject, float pccdMotionThreashold) | ||
218 | { | ||
219 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
220 | collisionObject.SetCcdMotionThreshold(pccdMotionThreashold); | ||
221 | } | ||
222 | |||
223 | public override void SetCcdSweptSphereRadius(BulletBody pCollisionObject, float pCcdSweptSphereRadius) | ||
224 | { | ||
225 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
226 | collisionObject.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); | ||
227 | } | ||
228 | |||
229 | public override void SetAngularFactorV(BulletBody pBody, Vector3 pAngularFactor) | ||
230 | { | ||
231 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
232 | body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z)); | ||
233 | } | ||
234 | |||
235 | public override CollisionFlags AddToCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) | ||
236 | { | ||
237 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
238 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); | ||
239 | existingcollisionFlags |= pcollisionFlags; | ||
240 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | ||
241 | return (CollisionFlags) (uint) existingcollisionFlags; | ||
242 | } | ||
243 | |||
244 | public override bool AddObjectToWorld(BulletWorld pWorld, BulletBody pBody) | ||
245 | { | ||
246 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
247 | CollisionObject cbody = (pBody as BulletBodyXNA).body; | ||
248 | RigidBody rbody = cbody as RigidBody; | ||
249 | |||
250 | // Bullet resets several variables when an object is added to the world. In particular, | ||
251 | // BulletXNA resets position and rotation. Gravity is also reset depending on the static/dynamic | ||
252 | // type. Of course, the collision flags in the broadphase proxy are initialized to default. | ||
253 | IndexedMatrix origPos = cbody.GetWorldTransform(); | ||
254 | if (rbody != null) | ||
255 | { | ||
256 | IndexedVector3 origGrav = rbody.GetGravity(); | ||
257 | world.AddRigidBody(rbody); | ||
258 | rbody.SetGravity(origGrav); | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | world.AddCollisionObject(rbody); | ||
263 | } | ||
264 | cbody.SetWorldTransform(origPos); | ||
265 | |||
266 | pBody.ApplyCollisionMask(pWorld.physicsScene); | ||
267 | |||
268 | //if (body.GetBroadphaseHandle() != null) | ||
269 | // world.UpdateSingleAabb(body); | ||
270 | return true; | ||
271 | } | ||
272 | |||
273 | public override void ForceActivationState(BulletBody pCollisionObject, ActivationState pActivationState) | ||
274 | { | ||
275 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
276 | collisionObject.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState); | ||
277 | } | ||
278 | |||
279 | public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pCollisionObject) | ||
280 | { | ||
281 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
282 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
283 | world.UpdateSingleAabb(collisionObject); | ||
284 | } | ||
285 | |||
286 | public override void UpdateAabbs(BulletWorld pWorld) { | ||
287 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
288 | world.UpdateAabbs(); | ||
289 | } | ||
290 | public override bool GetForceUpdateAllAabbs(BulletWorld pWorld) { | ||
291 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
292 | return world.GetForceUpdateAllAabbs(); | ||
293 | |||
294 | } | ||
295 | public override void SetForceUpdateAllAabbs(BulletWorld pWorld, bool pForce) | ||
296 | { | ||
297 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
298 | world.SetForceUpdateAllAabbs(pForce); | ||
299 | } | ||
300 | |||
301 | public override bool SetCollisionGroupMask(BulletBody pCollisionObject, uint pGroup, uint pMask) | ||
302 | { | ||
303 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
304 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | ||
305 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | ||
306 | if ((uint) collisionObject.GetBroadphaseHandle().m_collisionFilterGroup == 0) | ||
307 | return false; | ||
308 | return true; | ||
309 | } | ||
310 | |||
311 | public override void ClearAllForces(BulletBody pCollisionObject) | ||
312 | { | ||
313 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
314 | IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0); | ||
315 | collisionObject.SetInterpolationLinearVelocity(ref zeroVector); | ||
316 | collisionObject.SetInterpolationAngularVelocity(ref zeroVector); | ||
317 | IndexedMatrix bodytransform = collisionObject.GetWorldTransform(); | ||
318 | |||
319 | collisionObject.SetInterpolationWorldTransform(ref bodytransform); | ||
320 | |||
321 | if (collisionObject is RigidBody) | ||
322 | { | ||
323 | RigidBody rigidbody = collisionObject as RigidBody; | ||
324 | rigidbody.SetLinearVelocity(zeroVector); | ||
325 | rigidbody.SetAngularVelocity(zeroVector); | ||
326 | rigidbody.ClearForces(); | ||
327 | } | ||
328 | } | ||
329 | |||
330 | public override void SetInterpolationAngularVelocity(BulletBody pCollisionObject, Vector3 pVector3) | ||
331 | { | ||
332 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
333 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | ||
334 | collisionObject.SetInterpolationAngularVelocity(ref vec); | ||
335 | } | ||
336 | |||
337 | public override void SetAngularVelocity(BulletBody pBody, Vector3 pVector3) | ||
338 | { | ||
339 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
340 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | ||
341 | body.SetAngularVelocity(ref vec); | ||
342 | } | ||
343 | public override Vector3 GetTotalForce(BulletBody pBody) | ||
344 | { | ||
345 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
346 | IndexedVector3 iv3 = body.GetTotalForce(); | ||
347 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
348 | } | ||
349 | public override Vector3 GetTotalTorque(BulletBody pBody) | ||
350 | { | ||
351 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
352 | IndexedVector3 iv3 = body.GetTotalTorque(); | ||
353 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
354 | } | ||
355 | public override Vector3 GetInvInertiaDiagLocal(BulletBody pBody) | ||
356 | { | ||
357 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
358 | IndexedVector3 iv3 = body.GetInvInertiaDiagLocal(); | ||
359 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
360 | } | ||
361 | public override void SetInvInertiaDiagLocal(BulletBody pBody, Vector3 inert) | ||
362 | { | ||
363 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
364 | IndexedVector3 iv3 = new IndexedVector3(inert.X, inert.Y, inert.Z); | ||
365 | body.SetInvInertiaDiagLocal(ref iv3); | ||
366 | } | ||
367 | public override void ApplyForce(BulletBody pBody, Vector3 force, Vector3 pos) | ||
368 | { | ||
369 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
370 | IndexedVector3 forceiv3 = new IndexedVector3(force.X, force.Y, force.Z); | ||
371 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | ||
372 | body.ApplyForce(ref forceiv3, ref posiv3); | ||
373 | } | ||
374 | public override void ApplyImpulse(BulletBody pBody, Vector3 imp, Vector3 pos) | ||
375 | { | ||
376 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
377 | IndexedVector3 impiv3 = new IndexedVector3(imp.X, imp.Y, imp.Z); | ||
378 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | ||
379 | body.ApplyImpulse(ref impiv3, ref posiv3); | ||
380 | } | ||
381 | |||
382 | public override void ClearForces(BulletBody pBody) | ||
383 | { | ||
384 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
385 | body.ClearForces(); | ||
386 | } | ||
387 | |||
388 | public override void SetTranslation(BulletBody pCollisionObject, Vector3 _position, Quaternion _orientation) | ||
389 | { | ||
390 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
391 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); | ||
392 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, | ||
393 | _orientation.W); | ||
394 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); | ||
395 | mat._origin = vposition; | ||
396 | collisionObject.SetWorldTransform(mat); | ||
397 | |||
398 | } | ||
399 | |||
400 | public override Vector3 GetPosition(BulletBody pCollisionObject) | ||
401 | { | ||
402 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
403 | IndexedVector3 pos = collisionObject.GetInterpolationWorldTransform()._origin; | ||
404 | return new Vector3(pos.X, pos.Y, pos.Z); | ||
405 | } | ||
406 | |||
407 | public override Vector3 CalculateLocalInertia(BulletShape pShape, float pphysMass) | ||
408 | { | ||
409 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
410 | IndexedVector3 inertia = IndexedVector3.Zero; | ||
411 | shape.CalculateLocalInertia(pphysMass, out inertia); | ||
412 | return new Vector3(inertia.X, inertia.Y, inertia.Z); | ||
413 | } | ||
414 | |||
415 | public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia) | ||
416 | { | ||
417 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
418 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); | ||
419 | body.SetMassProps(pphysMass, inertia); | ||
420 | } | ||
421 | |||
422 | |||
423 | public override void SetObjectForce(BulletBody pBody, Vector3 _force) | ||
424 | { | ||
425 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
426 | IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z); | ||
427 | body.SetTotalForce(ref force); | ||
428 | } | ||
429 | |||
430 | public override void SetFriction(BulletBody pCollisionObject, float _currentFriction) | ||
431 | { | ||
432 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
433 | collisionObject.SetFriction(_currentFriction); | ||
434 | } | ||
435 | |||
436 | public override void SetLinearVelocity(BulletBody pBody, Vector3 _velocity) | ||
437 | { | ||
438 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
439 | IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z); | ||
440 | body.SetLinearVelocity(velocity); | ||
441 | } | ||
442 | |||
443 | public override void Activate(BulletBody pCollisionObject, bool pforceactivation) | ||
444 | { | ||
445 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
446 | collisionObject.Activate(pforceactivation); | ||
447 | |||
448 | } | ||
449 | |||
450 | public override Quaternion GetOrientation(BulletBody pCollisionObject) | ||
451 | { | ||
452 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
453 | IndexedQuaternion mat = collisionObject.GetInterpolationWorldTransform().GetRotation(); | ||
454 | return new Quaternion(mat.X, mat.Y, mat.Z, mat.W); | ||
455 | } | ||
456 | |||
457 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) | ||
458 | { | ||
459 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
460 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); | ||
461 | existingcollisionFlags &= ~pcollisionFlags; | ||
462 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | ||
463 | return (CollisionFlags)(uint)existingcollisionFlags; | ||
464 | } | ||
465 | |||
466 | public override float GetCcdMotionThreshold(BulletBody pCollisionObject) | ||
467 | { | ||
468 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
469 | return collisionObject.GetCcdSquareMotionThreshold(); | ||
470 | } | ||
471 | |||
472 | public override float GetCcdSweptSphereRadius(BulletBody pCollisionObject) | ||
473 | { | ||
474 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
475 | return collisionObject.GetCcdSweptSphereRadius(); | ||
476 | |||
477 | } | ||
478 | |||
479 | public override IntPtr GetUserPointer(BulletBody pCollisionObject) | ||
480 | { | ||
481 | CollisionObject shape = (pCollisionObject as BulletBodyXNA).body; | ||
482 | return (IntPtr)shape.GetUserPointer(); | ||
483 | } | ||
484 | |||
485 | public override void SetUserPointer(BulletBody pCollisionObject, IntPtr val) | ||
486 | { | ||
487 | CollisionObject shape = (pCollisionObject as BulletBodyXNA).body; | ||
488 | shape.SetUserPointer(val); | ||
489 | } | ||
490 | |||
491 | public override void SetGravity(BulletBody pBody, Vector3 pGravity) | ||
492 | { | ||
493 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
494 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); | ||
495 | body.SetGravity(gravity); | ||
496 | } | ||
497 | |||
498 | public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint) | ||
499 | { | ||
500 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
501 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; | ||
502 | world.RemoveConstraint(constraint); | ||
503 | return true; | ||
504 | } | ||
505 | |||
506 | public override bool SetLinearLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) | ||
507 | { | ||
508 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
509 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | ||
510 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | ||
511 | constraint.SetLinearLowerLimit(lowlimit); | ||
512 | constraint.SetLinearUpperLimit(highlimit); | ||
513 | return true; | ||
514 | } | ||
515 | |||
516 | public override bool SetAngularLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) | ||
517 | { | ||
518 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
519 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | ||
520 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | ||
521 | constraint.SetAngularLowerLimit(lowlimit); | ||
522 | constraint.SetAngularUpperLimit(highlimit); | ||
523 | return true; | ||
524 | } | ||
525 | |||
526 | public override void SetConstraintNumSolverIterations(BulletConstraint pConstraint, float cnt) | ||
527 | { | ||
528 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
529 | constraint.SetOverrideNumSolverIterations((int)cnt); | ||
530 | } | ||
531 | |||
532 | public override bool CalculateTransforms(BulletConstraint pConstraint) | ||
533 | { | ||
534 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
535 | constraint.CalculateTransforms(); | ||
536 | return true; | ||
537 | } | ||
538 | |||
539 | public override void SetConstraintEnable(BulletConstraint pConstraint, float p_2) | ||
540 | { | ||
541 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
542 | constraint.SetEnabled((p_2 == 0) ? false : true); | ||
543 | } | ||
544 | |||
545 | |||
546 | //BulletSimAPI.Create6DofConstraint(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
547 | public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
548 | |||
549 | { | ||
550 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
551 | RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody; | ||
552 | RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody; | ||
553 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | ||
554 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | ||
555 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | ||
556 | frame1._origin = frame1v; | ||
557 | |||
558 | IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z); | ||
559 | IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W); | ||
560 | IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot); | ||
561 | frame2._origin = frame1v; | ||
562 | |||
563 | Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, | ||
564 | puseLinearReferenceFrameA); | ||
565 | consttr.CalculateTransforms(); | ||
566 | world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies); | ||
567 | |||
568 | return new BulletConstraintXNA(consttr); | ||
569 | } | ||
570 | |||
571 | |||
572 | /// <summary> | ||
573 | /// | ||
574 | /// </summary> | ||
575 | /// <param name="pWorld"></param> | ||
576 | /// <param name="pBody1"></param> | ||
577 | /// <param name="pBody2"></param> | ||
578 | /// <param name="pjoinPoint"></param> | ||
579 | /// <param name="puseLinearReferenceFrameA"></param> | ||
580 | /// <param name="pdisableCollisionsBetweenLinkedBodies"></param> | ||
581 | /// <returns></returns> | ||
582 | public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
583 | { | ||
584 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
585 | RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody; | ||
586 | RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody; | ||
587 | IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | ||
588 | IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | ||
589 | |||
590 | IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z); | ||
591 | IndexedMatrix mat = IndexedMatrix.Identity; | ||
592 | mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z); | ||
593 | frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint; | ||
594 | frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint; | ||
595 | |||
596 | Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA); | ||
597 | consttr.CalculateTransforms(); | ||
598 | world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies); | ||
599 | |||
600 | return new BulletConstraintXNA(consttr); | ||
601 | } | ||
602 | //SetFrames(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); | ||
603 | public override bool SetFrames(BulletConstraint pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot) | ||
604 | { | ||
605 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
606 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | ||
607 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | ||
608 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | ||
609 | frame1._origin = frame1v; | ||
610 | |||
611 | IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z); | ||
612 | IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W); | ||
613 | IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot); | ||
614 | frame2._origin = frame1v; | ||
615 | constraint.SetFrames(ref frame1, ref frame2); | ||
616 | return true; | ||
617 | } | ||
618 | |||
619 | public override Vector3 GetLinearVelocity(BulletBody pBody) | ||
620 | { | ||
621 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
622 | IndexedVector3 iv3 = body.GetLinearVelocity(); | ||
623 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
624 | } | ||
625 | public override Vector3 GetAngularVelocity(BulletBody pBody) | ||
626 | { | ||
627 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
628 | IndexedVector3 iv3 = body.GetAngularVelocity(); | ||
629 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
630 | } | ||
631 | public override Vector3 GetVelocityInLocalPoint(BulletBody pBody, Vector3 pos) | ||
632 | { | ||
633 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
634 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | ||
635 | IndexedVector3 iv3 = body.GetVelocityInLocalPoint(ref posiv3); | ||
636 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
637 | } | ||
638 | public override void Translate(BulletBody pCollisionObject, Vector3 trans) | ||
639 | { | ||
640 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
641 | collisionObject.Translate(new IndexedVector3(trans.X,trans.Y,trans.Z)); | ||
642 | } | ||
643 | public override void UpdateDeactivation(BulletBody pBody, float timeStep) | ||
644 | { | ||
645 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
646 | body.UpdateDeactivation(timeStep); | ||
647 | } | ||
648 | |||
649 | public override bool WantsSleeping(BulletBody pBody) | ||
650 | { | ||
651 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
652 | return body.WantsSleeping(); | ||
653 | } | ||
654 | |||
655 | public override void SetAngularFactor(BulletBody pBody, float factor) | ||
656 | { | ||
657 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
658 | body.SetAngularFactor(factor); | ||
659 | } | ||
660 | |||
661 | public override Vector3 GetAngularFactor(BulletBody pBody) | ||
662 | { | ||
663 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
664 | IndexedVector3 iv3 = body.GetAngularFactor(); | ||
665 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | ||
666 | } | ||
667 | |||
668 | public override bool IsInWorld(BulletWorld pWorld, BulletBody pCollisionObject) | ||
669 | { | ||
670 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
671 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
672 | return world.IsInWorld(collisionObject); | ||
673 | } | ||
674 | |||
675 | public override void AddConstraintRef(BulletBody pBody, BulletConstraint pConstraint) | ||
676 | { | ||
677 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
678 | TypedConstraint constrain = (pConstraint as BulletConstraintXNA).constrain; | ||
679 | body.AddConstraintRef(constrain); | ||
680 | } | ||
681 | |||
682 | public override void RemoveConstraintRef(BulletBody pBody, BulletConstraint pConstraint) | ||
683 | { | ||
684 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
685 | TypedConstraint constrain = (pConstraint as BulletConstraintXNA).constrain; | ||
686 | body.RemoveConstraintRef(constrain); | ||
687 | } | ||
688 | |||
689 | public override BulletConstraint GetConstraintRef(BulletBody pBody, int index) | ||
690 | { | ||
691 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
692 | return new BulletConstraintXNA(body.GetConstraintRef(index)); | ||
693 | } | ||
694 | |||
695 | public override int GetNumConstraintRefs(BulletBody pBody) | ||
696 | { | ||
697 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
698 | return body.GetNumConstraintRefs(); | ||
699 | } | ||
700 | |||
701 | public override void SetInterpolationLinearVelocity(BulletBody pCollisionObject, Vector3 VehicleVelocity) | ||
702 | { | ||
703 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
704 | IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z); | ||
705 | collisionObject.SetInterpolationLinearVelocity(ref velocity); | ||
706 | } | ||
707 | |||
708 | public override bool UseFrameOffset(BulletConstraint pConstraint, float onOff) | ||
709 | { | ||
710 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
711 | constraint.SetUseFrameOffset((onOff == 0) ? false : true); | ||
712 | return true; | ||
713 | } | ||
714 | //SetBreakingImpulseThreshold(m_constraint.ptr, threshold); | ||
715 | public override bool SetBreakingImpulseThreshold(BulletConstraint pConstraint, float threshold) | ||
716 | { | ||
717 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
718 | constraint.SetBreakingImpulseThreshold(threshold); | ||
719 | return true; | ||
720 | } | ||
721 | //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping); | ||
722 | public override void SetAngularDamping(BulletBody pBody, float angularDamping) | ||
723 | { | ||
724 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
725 | float lineardamping = body.GetLinearDamping(); | ||
726 | body.SetDamping(lineardamping, angularDamping); | ||
727 | |||
728 | } | ||
729 | |||
730 | public override void UpdateInertiaTensor(BulletBody pBody) | ||
731 | { | ||
732 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
733 | body.UpdateInertiaTensor(); | ||
734 | } | ||
735 | |||
736 | public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape) | ||
737 | { | ||
738 | CompoundShape shape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape; | ||
739 | shape.RecalculateLocalAabb(); | ||
740 | } | ||
741 | |||
742 | //BulletSimAPI.GetCollisionFlags(PhysBody.ptr) | ||
743 | public override CollisionFlags GetCollisionFlags(BulletBody pCollisionObject) | ||
744 | { | ||
745 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
746 | uint flags = (uint)collisionObject.GetCollisionFlags(); | ||
747 | return (CollisionFlags) flags; | ||
748 | } | ||
749 | |||
750 | public override void SetDamping(BulletBody pBody, float pLinear, float pAngular) | ||
751 | { | ||
752 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
753 | body.SetDamping(pLinear, pAngular); | ||
754 | } | ||
755 | //PhysBody.ptr, PhysicsScene.Params.deactivationTime); | ||
756 | public override void SetDeactivationTime(BulletBody pCollisionObject, float pDeactivationTime) | ||
757 | { | ||
758 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
759 | collisionObject.SetDeactivationTime(pDeactivationTime); | ||
760 | } | ||
761 | //SetSleepingThresholds(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | ||
762 | public override void SetSleepingThresholds(BulletBody pBody, float plinearSleepingThreshold, float pangularSleepingThreshold) | ||
763 | { | ||
764 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
765 | body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold); | ||
766 | } | ||
767 | |||
768 | public override CollisionObjectTypes GetBodyType(BulletBody pCollisionObject) | ||
769 | { | ||
770 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
771 | return (CollisionObjectTypes)(int) collisionObject.GetInternalType(); | ||
772 | } | ||
773 | |||
774 | public override void ApplyGravity(BulletBody pBody) | ||
775 | { | ||
776 | |||
777 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
778 | body.ApplyGravity(); | ||
779 | } | ||
780 | |||
781 | public override Vector3 GetGravity(BulletBody pBody) | ||
782 | { | ||
783 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
784 | IndexedVector3 gravity = body.GetGravity(); | ||
785 | return new Vector3(gravity.X, gravity.Y, gravity.Z); | ||
786 | } | ||
787 | |||
788 | public override void SetLinearDamping(BulletBody pBody, float lin_damping) | ||
789 | { | ||
790 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
791 | float angularDamping = body.GetAngularDamping(); | ||
792 | body.SetDamping(lin_damping, angularDamping); | ||
793 | } | ||
794 | |||
795 | public override float GetLinearDamping(BulletBody pBody) | ||
796 | { | ||
797 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
798 | return body.GetLinearDamping(); | ||
799 | } | ||
800 | |||
801 | public override float GetAngularDamping(BulletBody pBody) | ||
802 | { | ||
803 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
804 | return body.GetAngularDamping(); | ||
805 | } | ||
806 | |||
807 | public override float GetLinearSleepingThreshold(BulletBody pBody) | ||
808 | { | ||
809 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
810 | return body.GetLinearSleepingThreshold(); | ||
811 | } | ||
812 | |||
813 | public override void ApplyDamping(BulletBody pBody, float timeStep) | ||
814 | { | ||
815 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
816 | body.ApplyDamping(timeStep); | ||
817 | } | ||
818 | |||
819 | public override Vector3 GetLinearFactor(BulletBody pBody) | ||
820 | { | ||
821 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
822 | IndexedVector3 linearFactor = body.GetLinearFactor(); | ||
823 | return new Vector3(linearFactor.X, linearFactor.Y, linearFactor.Z); | ||
824 | } | ||
825 | |||
826 | public override void SetLinearFactor(BulletBody pBody, Vector3 factor) | ||
827 | { | ||
828 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
829 | body.SetLinearFactor(new IndexedVector3(factor.X, factor.Y, factor.Z)); | ||
830 | } | ||
831 | |||
832 | public override void SetCenterOfMassByPosRot(BulletBody pBody, Vector3 pos, Quaternion rot) | ||
833 | { | ||
834 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
835 | IndexedQuaternion quat = new IndexedQuaternion(rot.X, rot.Y, rot.Z,rot.W); | ||
836 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(quat); | ||
837 | mat._origin = new IndexedVector3(pos.X, pos.Y, pos.Z); | ||
838 | body.SetCenterOfMassTransform( ref mat); | ||
839 | /* TODO: double check this */ | ||
840 | } | ||
841 | |||
842 | //BulletSimAPI.ApplyCentralForce(PhysBody.ptr, fSum); | ||
843 | public override void ApplyCentralForce(BulletBody pBody, Vector3 pfSum) | ||
844 | { | ||
845 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
846 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
847 | body.ApplyCentralForce(ref fSum); | ||
848 | } | ||
849 | public override void ApplyCentralImpulse(BulletBody pBody, Vector3 pfSum) | ||
850 | { | ||
851 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
852 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
853 | body.ApplyCentralImpulse(ref fSum); | ||
854 | } | ||
855 | public override void ApplyTorque(BulletBody pBody, Vector3 pfSum) | ||
856 | { | ||
857 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
858 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
859 | body.ApplyTorque(ref fSum); | ||
860 | } | ||
861 | public override void ApplyTorqueImpulse(BulletBody pBody, Vector3 pfSum) | ||
862 | { | ||
863 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
864 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
865 | body.ApplyTorqueImpulse(ref fSum); | ||
866 | } | ||
867 | |||
868 | public override void DestroyObject(BulletWorld pWorld, BulletBody pBody) | ||
869 | { | ||
870 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
871 | CollisionObject co = (pBody as BulletBodyXNA).rigidBody; | ||
872 | RigidBody bo = co as RigidBody; | ||
873 | if (bo == null) | ||
874 | { | ||
875 | |||
876 | if (world.IsInWorld(co)) | ||
877 | { | ||
878 | world.RemoveCollisionObject(co); | ||
879 | } | ||
880 | } | ||
881 | else | ||
882 | { | ||
883 | |||
884 | if (world.IsInWorld(bo)) | ||
885 | { | ||
886 | world.RemoveRigidBody(bo); | ||
887 | } | ||
888 | } | ||
889 | |||
890 | } | ||
891 | |||
892 | public override void Shutdown(BulletWorld pWorld) | ||
893 | { | ||
894 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
895 | world.Cleanup(); | ||
896 | } | ||
897 | |||
898 | public override BulletShape DuplicateCollisionShape(BulletWorld pWorld, BulletShape pShape, uint id) | ||
899 | { | ||
900 | CollisionShape shape1 = (pShape as BulletShapeXNA).shape; | ||
901 | |||
902 | // TODO: Turn this from a reference copy to a Value Copy. | ||
903 | BulletShapeXNA shape2 = new BulletShapeXNA(shape1, BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
904 | |||
905 | return shape2; | ||
906 | } | ||
907 | |||
908 | public override bool DeleteCollisionShape(BulletWorld pWorld, BulletShape pShape) | ||
909 | { | ||
910 | //TODO: | ||
911 | return false; | ||
912 | } | ||
913 | //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); | ||
914 | |||
915 | public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
916 | { | ||
917 | CollisionWorld world = (pWorld as BulletWorldXNA).world; | ||
918 | IndexedMatrix mat = | ||
919 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, | ||
920 | pRawOrientation.Z, pRawOrientation.W)); | ||
921 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
922 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
923 | //UpdateSingleAabb(world, shape); | ||
924 | // TODO: Feed Update array into null | ||
925 | SimMotionState motionState = new SimMotionState(world, pLocalID, mat, null); | ||
926 | RigidBody body = new RigidBody(0,motionState,shape,IndexedVector3.Zero); | ||
927 | RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(0, new SimMotionState(world, pLocalID, mat, null),shape,IndexedVector3.Zero) | ||
928 | { | ||
929 | m_mass = 0 | ||
930 | }; | ||
931 | /* | ||
932 | m_mass = mass; | ||
933 | m_motionState =motionState; | ||
934 | m_collisionShape = collisionShape; | ||
935 | m_localInertia = localInertia; | ||
936 | m_linearDamping = 0f; | ||
937 | m_angularDamping = 0f; | ||
938 | m_friction = 0.5f; | ||
939 | m_restitution = 0f; | ||
940 | m_linearSleepingThreshold = 0.8f; | ||
941 | m_angularSleepingThreshold = 1f; | ||
942 | m_additionalDamping = false; | ||
943 | m_additionalDampingFactor = 0.005f; | ||
944 | m_additionalLinearDampingThresholdSqr = 0.01f; | ||
945 | m_additionalAngularDampingThresholdSqr = 0.01f; | ||
946 | m_additionalAngularDampingFactor = 0.01f; | ||
947 | m_startWorldTransform = IndexedMatrix.Identity; | ||
948 | */ | ||
949 | body.SetUserPointer(pLocalID); | ||
950 | |||
951 | return new BulletBodyXNA(pLocalID, body); | ||
952 | } | ||
953 | |||
954 | |||
955 | public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
956 | { | ||
957 | |||
958 | IndexedMatrix mat = | ||
959 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, | ||
960 | pRawOrientation.Z, pRawOrientation.W)); | ||
961 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
962 | |||
963 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
964 | |||
965 | // TODO: Feed Update array into null | ||
966 | RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero); | ||
967 | body.SetWorldTransform(mat); | ||
968 | body.SetUserPointer(pLocalID); | ||
969 | return new BulletBodyXNA(pLocalID, body); | ||
970 | } | ||
971 | //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | ||
972 | public override CollisionFlags SetCollisionFlags(BulletBody pCollisionObject, CollisionFlags collisionFlags) | ||
973 | { | ||
974 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
975 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags); | ||
976 | return (CollisionFlags)collisionObject.GetCollisionFlags(); | ||
977 | } | ||
978 | |||
979 | public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) | ||
980 | { | ||
981 | |||
982 | /* TODO */ | ||
983 | return Vector3.Zero; | ||
984 | } | ||
985 | public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; } | ||
986 | public override bool HasAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return false; } | ||
987 | public override float GetContactProcessingThreshold(BulletBody pBody) { /* TODO */ return 0f; } | ||
988 | public override bool IsStaticObject(BulletBody pCollisionObject) | ||
989 | { | ||
990 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
991 | return collisionObject.IsStaticObject(); | ||
992 | |||
993 | } | ||
994 | public override bool IsKinematicObject(BulletBody pCollisionObject) | ||
995 | { | ||
996 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
997 | return collisionObject.IsKinematicObject(); | ||
998 | } | ||
999 | public override bool IsStaticOrKinematicObject(BulletBody pCollisionObject) | ||
1000 | { | ||
1001 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1002 | return collisionObject.IsStaticOrKinematicObject(); | ||
1003 | } | ||
1004 | public override bool HasContactResponse(BulletBody pCollisionObject) | ||
1005 | { | ||
1006 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1007 | return collisionObject.HasContactResponse(); | ||
1008 | } | ||
1009 | public override int GetActivationState(BulletBody pBody) { /* TODO */ return 0; } | ||
1010 | public override void SetActivationState(BulletBody pBody, int state) { /* TODO */ } | ||
1011 | public override float GetDeactivationTime(BulletBody pBody) { /* TODO */ return 0f; } | ||
1012 | public override bool IsActive(BulletBody pBody) { /* TODO */ return false; } | ||
1013 | public override float GetRestitution(BulletBody pBody) { /* TODO */ return 0f; } | ||
1014 | public override float GetFriction(BulletBody pBody) { /* TODO */ return 0f; } | ||
1015 | public override void SetInterpolationVelocity(BulletBody pBody, Vector3 linearVel, Vector3 angularVel) { /* TODO */ } | ||
1016 | public override float GetHitFraction(BulletBody pBody) { /* TODO */ return 0f; } | ||
1017 | |||
1018 | //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | ||
1019 | public override void SetHitFraction(BulletBody pCollisionObject, float pHitFraction) | ||
1020 | { | ||
1021 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1022 | collisionObject.SetHitFraction(pHitFraction); | ||
1023 | } | ||
1024 | //BuildCapsuleShape(physicsScene.World.ptr, 1f, 1f, prim.Scale); | ||
1025 | public override BulletShape BuildCapsuleShape(BulletWorld pWorld, float pRadius, float pHeight, Vector3 pScale) | ||
1026 | { | ||
1027 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1028 | IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | ||
1029 | CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight); | ||
1030 | capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1031 | capsuleShapeZ.SetLocalScaling(ref scale); | ||
1032 | |||
1033 | return new BulletShapeXNA(capsuleShapeZ, BSPhysicsShapeType.SHAPE_CAPSULE); ; | ||
1034 | } | ||
1035 | |||
1036 | public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, | ||
1037 | int maxCollisions, ref CollisionDesc[] collisionArray, | ||
1038 | int maxUpdates, ref EntityProperties[] updateArray | ||
1039 | ) | ||
1040 | { | ||
1041 | |||
1042 | m_updateArray = updateArray; | ||
1043 | m_collisionArray = collisionArray; | ||
1044 | /* TODO */ | ||
1045 | ConfigurationParameters[] configparms = new ConfigurationParameters[1]; | ||
1046 | configparms[0] = parms; | ||
1047 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | ||
1048 | m_maxCollisions = maxCollisions; | ||
1049 | m_maxUpdatesPerFrame = maxUpdates; | ||
1050 | |||
1051 | |||
1052 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); | ||
1053 | } | ||
1054 | |||
1055 | private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent, | ||
1056 | ConfigurationParameters[] o, | ||
1057 | int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray, | ||
1058 | int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray, | ||
1059 | object mDebugLogCallbackHandle) | ||
1060 | { | ||
1061 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); | ||
1062 | |||
1063 | p.angularDamping = o[0].XangularDamping; | ||
1064 | p.defaultFriction = o[0].defaultFriction; | ||
1065 | p.defaultFriction = o[0].defaultFriction; | ||
1066 | p.defaultDensity = o[0].defaultDensity; | ||
1067 | p.defaultRestitution = o[0].defaultRestitution; | ||
1068 | p.collisionMargin = o[0].collisionMargin; | ||
1069 | p.gravity = o[0].gravity; | ||
1070 | |||
1071 | p.linearDamping = o[0].XlinearDamping; | ||
1072 | p.angularDamping = o[0].XangularDamping; | ||
1073 | p.deactivationTime = o[0].XdeactivationTime; | ||
1074 | p.linearSleepingThreshold = o[0].XlinearSleepingThreshold; | ||
1075 | p.angularSleepingThreshold = o[0].XangularSleepingThreshold; | ||
1076 | p.ccdMotionThreshold = o[0].XccdMotionThreshold; | ||
1077 | p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius; | ||
1078 | p.contactProcessingThreshold = o[0].XcontactProcessingThreshold; | ||
1079 | |||
1080 | p.terrainImplementation = o[0].XterrainImplementation; | ||
1081 | p.terrainFriction = o[0].XterrainFriction; | ||
1082 | |||
1083 | p.terrainHitFraction = o[0].XterrainHitFraction; | ||
1084 | p.terrainRestitution = o[0].XterrainRestitution; | ||
1085 | p.terrainCollisionMargin = o[0].XterrainCollisionMargin; | ||
1086 | |||
1087 | p.avatarFriction = o[0].XavatarFriction; | ||
1088 | p.avatarStandingFriction = o[0].XavatarStandingFriction; | ||
1089 | p.avatarDensity = o[0].XavatarDensity; | ||
1090 | p.avatarRestitution = o[0].XavatarRestitution; | ||
1091 | p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth; | ||
1092 | p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth; | ||
1093 | p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight; | ||
1094 | p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold; | ||
1095 | |||
1096 | p.vehicleAngularDamping = o[0].XvehicleAngularDamping; | ||
1097 | |||
1098 | p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; | ||
1099 | p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; | ||
1100 | p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; | ||
1101 | p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs; | ||
1102 | p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder; | ||
1103 | p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands; | ||
1104 | p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching; | ||
1105 | p.numberOfSolverIterations = o[0].numberOfSolverIterations; | ||
1106 | |||
1107 | p.linksetImplementation = o[0].XlinksetImplementation; | ||
1108 | p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset; | ||
1109 | p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor; | ||
1110 | p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel; | ||
1111 | p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce; | ||
1112 | p.linkConstraintERP = o[0].XlinkConstraintERP; | ||
1113 | p.linkConstraintCFM = o[0].XlinkConstraintCFM; | ||
1114 | p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations; | ||
1115 | p.physicsLoggingFrames = o[0].XphysicsLoggingFrames; | ||
1116 | DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); | ||
1117 | |||
1118 | DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); | ||
1119 | CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); | ||
1120 | |||
1121 | |||
1122 | if (p.maxPersistantManifoldPoolSize > 0) | ||
1123 | cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize; | ||
1124 | if (p.shouldDisableContactPoolDynamicAllocation !=0) | ||
1125 | m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION); | ||
1126 | //if (p.maxCollisionAlgorithmPoolSize >0 ) | ||
1127 | |||
1128 | DbvtBroadphase m_broadphase = new DbvtBroadphase(); | ||
1129 | //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0); | ||
1130 | //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256); | ||
1131 | |||
1132 | //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true); | ||
1133 | m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); | ||
1134 | |||
1135 | SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); | ||
1136 | |||
1137 | DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); | ||
1138 | |||
1139 | |||
1140 | world.UpdatedObjects = BSAPIXNA.GetBulletXNAEntityStruct(BSAPIXNA.BulletSimEntityStructToByteArray(updateArray, updateArray.Length)); | ||
1141 | world.UpdatedCollisions = BSAPIXNA.GetBulletXNACollisionStruct(BSAPIXNA.BulletSimCollisionStructToByteArray(collisionArray, collisionArray.Length)); | ||
1142 | world.LastCollisionDesc = 0; | ||
1143 | world.LastEntityProperty = 0; | ||
1144 | |||
1145 | world.WorldSettings.Params = p; | ||
1146 | world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); | ||
1147 | world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; | ||
1148 | if (p.shouldRandomizeSolverOrder != 0) | ||
1149 | world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER; | ||
1150 | |||
1151 | world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0); | ||
1152 | //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port | ||
1153 | |||
1154 | if (p.shouldEnableFrictionCaching != 0) | ||
1155 | world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING; | ||
1156 | |||
1157 | if (p.numberOfSolverIterations > 0) | ||
1158 | world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations; | ||
1159 | |||
1160 | |||
1161 | world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping; | ||
1162 | world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution; | ||
1163 | world.GetSolverInfo().m_globalCfm = 0.0f; | ||
1164 | world.GetSolverInfo().m_tau = 0.6f; | ||
1165 | world.GetSolverInfo().m_friction = 0.3f; | ||
1166 | world.GetSolverInfo().m_maxErrorReduction = 20f; | ||
1167 | world.GetSolverInfo().m_numIterations = 10; | ||
1168 | world.GetSolverInfo().m_erp = 0.2f; | ||
1169 | world.GetSolverInfo().m_erp2 = 0.1f; | ||
1170 | world.GetSolverInfo().m_sor = 1.0f; | ||
1171 | world.GetSolverInfo().m_splitImpulse = false; | ||
1172 | world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f; | ||
1173 | world.GetSolverInfo().m_linearSlop = 0.0f; | ||
1174 | world.GetSolverInfo().m_warmstartingFactor = 0.85f; | ||
1175 | world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; | ||
1176 | world.SetForceUpdateAllAabbs(true); | ||
1177 | |||
1178 | //BSParam.TerrainImplementation = 0; | ||
1179 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); | ||
1180 | |||
1181 | return world; | ||
1182 | } | ||
1183 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL | ||
1184 | public override bool SetConstraintParam(BulletConstraint pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis) | ||
1185 | { | ||
1186 | Generic6DofConstraint constrain = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; | ||
1187 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) | ||
1188 | { | ||
1189 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0); | ||
1190 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1); | ||
1191 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2); | ||
1192 | } | ||
1193 | if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) | ||
1194 | { | ||
1195 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3); | ||
1196 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4); | ||
1197 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5); | ||
1198 | } | ||
1199 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL) | ||
1200 | { | ||
1201 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis); | ||
1202 | } | ||
1203 | return true; | ||
1204 | } | ||
1205 | |||
1206 | public override bool PushUpdate(BulletBody pCollisionObject) | ||
1207 | { | ||
1208 | bool ret = false; | ||
1209 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1210 | RigidBody rb = collisionObject as RigidBody; | ||
1211 | if (rb != null) | ||
1212 | { | ||
1213 | SimMotionState sms = rb.GetMotionState() as SimMotionState; | ||
1214 | if (sms != null) | ||
1215 | { | ||
1216 | IndexedMatrix wt = IndexedMatrix.Identity; | ||
1217 | sms.GetWorldTransform(out wt); | ||
1218 | sms.SetWorldTransform(ref wt, true); | ||
1219 | ret = true; | ||
1220 | } | ||
1221 | } | ||
1222 | return ret; | ||
1223 | |||
1224 | } | ||
1225 | |||
1226 | public override float GetAngularMotionDisc(BulletShape pShape) | ||
1227 | { | ||
1228 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1229 | return shape.GetAngularMotionDisc(); | ||
1230 | } | ||
1231 | public override float GetContactBreakingThreshold(BulletShape pShape, float defaultFactor) | ||
1232 | { | ||
1233 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1234 | return shape.GetContactBreakingThreshold(defaultFactor); | ||
1235 | } | ||
1236 | public override bool IsCompound(BulletShape pShape) | ||
1237 | { | ||
1238 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1239 | return shape.IsCompound(); | ||
1240 | } | ||
1241 | public override bool IsSoftBody(BulletShape pShape) | ||
1242 | { | ||
1243 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1244 | return shape.IsSoftBody(); | ||
1245 | } | ||
1246 | public override bool IsPolyhedral(BulletShape pShape) | ||
1247 | { | ||
1248 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1249 | return shape.IsPolyhedral(); | ||
1250 | } | ||
1251 | public override bool IsConvex2d(BulletShape pShape) | ||
1252 | { | ||
1253 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1254 | return shape.IsConvex2d(); | ||
1255 | } | ||
1256 | public override bool IsConvex(BulletShape pShape) | ||
1257 | { | ||
1258 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1259 | return shape.IsConvex(); | ||
1260 | } | ||
1261 | public override bool IsNonMoving(BulletShape pShape) | ||
1262 | { | ||
1263 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1264 | return shape.IsNonMoving(); | ||
1265 | } | ||
1266 | public override bool IsConcave(BulletShape pShape) | ||
1267 | { | ||
1268 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1269 | return shape.IsConcave(); | ||
1270 | } | ||
1271 | public override bool IsInfinite(BulletShape pShape) | ||
1272 | { | ||
1273 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1274 | return shape.IsInfinite(); | ||
1275 | } | ||
1276 | public override bool IsNativeShape(BulletShape pShape) | ||
1277 | { | ||
1278 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1279 | bool ret; | ||
1280 | switch (shape.GetShapeType()) | ||
1281 | { | ||
1282 | case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE: | ||
1283 | case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE: | ||
1284 | case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE: | ||
1285 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: | ||
1286 | ret = true; | ||
1287 | break; | ||
1288 | default: | ||
1289 | ret = false; | ||
1290 | break; | ||
1291 | } | ||
1292 | return ret; | ||
1293 | } | ||
1294 | |||
1295 | public override void SetShapeCollisionMargin(BulletShape pShape, float pMargin) | ||
1296 | { | ||
1297 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1298 | shape.SetMargin(pMargin); | ||
1299 | } | ||
1300 | |||
1301 | //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation | ||
1302 | public override BulletBody CreateGhostFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
1303 | { | ||
1304 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1305 | IndexedMatrix bodyTransform = new IndexedMatrix(); | ||
1306 | bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
1307 | bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W)); | ||
1308 | GhostObject gObj = new PairCachingGhostObject(); | ||
1309 | gObj.SetWorldTransform(bodyTransform); | ||
1310 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1311 | gObj.SetCollisionShape(shape); | ||
1312 | gObj.SetUserPointer(pLocalID); | ||
1313 | // TODO: Add to Special CollisionObjects! | ||
1314 | return new BulletBodyXNA(pLocalID, gObj); | ||
1315 | } | ||
1316 | |||
1317 | public override void SetCollisionShape(BulletWorld pWorld, BulletBody pCollisionObject, BulletShape pShape) | ||
1318 | { | ||
1319 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1320 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; | ||
1321 | if (pShape == null) | ||
1322 | { | ||
1323 | collisionObject.SetCollisionShape(new EmptyShape()); | ||
1324 | } | ||
1325 | else | ||
1326 | { | ||
1327 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1328 | collisionObject.SetCollisionShape(shape); | ||
1329 | } | ||
1330 | } | ||
1331 | public override BulletShape GetCollisionShape(BulletBody pCollisionObject) | ||
1332 | { | ||
1333 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1334 | CollisionShape shape = collisionObject.GetCollisionShape(); | ||
1335 | return new BulletShapeXNA(shape,BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
1336 | } | ||
1337 | |||
1338 | //(PhysicsScene.World.ptr, nativeShapeData) | ||
1339 | public override BulletShape BuildNativeShape(BulletWorld pWorld, ShapeData pShapeData) | ||
1340 | { | ||
1341 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1342 | CollisionShape shape = null; | ||
1343 | switch (pShapeData.Type) | ||
1344 | { | ||
1345 | case BSPhysicsShapeType.SHAPE_BOX: | ||
1346 | shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f)); | ||
1347 | break; | ||
1348 | case BSPhysicsShapeType.SHAPE_CONE: | ||
1349 | shape = new ConeShapeZ(0.5f, 1.0f); | ||
1350 | break; | ||
1351 | case BSPhysicsShapeType.SHAPE_CYLINDER: | ||
1352 | shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f)); | ||
1353 | break; | ||
1354 | case BSPhysicsShapeType.SHAPE_SPHERE: | ||
1355 | shape = new SphereShape(0.5f); | ||
1356 | break; | ||
1357 | |||
1358 | } | ||
1359 | if (shape != null) | ||
1360 | { | ||
1361 | IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z); | ||
1362 | shape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1363 | shape.SetLocalScaling(ref scaling); | ||
1364 | |||
1365 | } | ||
1366 | return new BulletShapeXNA(shape, pShapeData.Type); | ||
1367 | } | ||
1368 | //PhysicsScene.World.ptr, false | ||
1369 | public override BulletShape CreateCompoundShape(BulletWorld pWorld, bool enableDynamicAabbTree) | ||
1370 | { | ||
1371 | return new BulletShapeXNA(new CompoundShape(enableDynamicAabbTree), BSPhysicsShapeType.SHAPE_COMPOUND); | ||
1372 | } | ||
1373 | |||
1374 | public override int GetNumberOfCompoundChildren(BulletShape pCompoundShape) | ||
1375 | { | ||
1376 | CompoundShape compoundshape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape; | ||
1377 | return compoundshape.GetNumChildShapes(); | ||
1378 | } | ||
1379 | //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot | ||
1380 | public override void AddChildShapeToCompoundShape(BulletShape pCShape, BulletShape paddShape, Vector3 displacementPos, Quaternion displacementRot) | ||
1381 | { | ||
1382 | IndexedMatrix relativeTransform = new IndexedMatrix(); | ||
1383 | CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape; | ||
1384 | CollisionShape addshape = (paddShape as BulletShapeXNA).shape; | ||
1385 | |||
1386 | relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z); | ||
1387 | relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W)); | ||
1388 | compoundshape.AddChildShape(ref relativeTransform, addshape); | ||
1389 | |||
1390 | } | ||
1391 | |||
1392 | public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape pCShape, int pii) | ||
1393 | { | ||
1394 | CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape; | ||
1395 | CollisionShape ret = null; | ||
1396 | ret = compoundshape.GetChildShape(pii); | ||
1397 | compoundshape.RemoveChildShapeByIndex(pii); | ||
1398 | return new BulletShapeXNA(ret, BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
1399 | } | ||
1400 | |||
1401 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { /* TODO */ return null; } | ||
1402 | public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ } | ||
1403 | public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb) { /* TODO */ } | ||
1404 | |||
1405 | public override BulletShape CreateGroundPlaneShape(uint pLocalId, float pheight, float pcollisionMargin) | ||
1406 | { | ||
1407 | StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight ); | ||
1408 | m_planeshape.SetMargin(pcollisionMargin); | ||
1409 | m_planeshape.SetUserPointer(pLocalId); | ||
1410 | return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE); | ||
1411 | } | ||
1412 | |||
1413 | public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
1414 | { | ||
1415 | HingeConstraint constrain = null; | ||
1416 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1417 | RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody; | ||
1418 | RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody; | ||
1419 | if (rb1 != null && rb2 != null) | ||
1420 | { | ||
1421 | IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z); | ||
1422 | IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z); | ||
1423 | IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z); | ||
1424 | IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z); | ||
1425 | world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies); | ||
1426 | } | ||
1427 | return new BulletConstraintXNA(constrain); | ||
1428 | } | ||
1429 | |||
1430 | public override BulletShape CreateHullShape(BulletWorld pWorld, int pHullCount, float[] pConvHulls) | ||
1431 | { | ||
1432 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1433 | CompoundShape compoundshape = new CompoundShape(false); | ||
1434 | |||
1435 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1436 | int ii = 1; | ||
1437 | |||
1438 | for (int i = 0; i < pHullCount; i++) | ||
1439 | { | ||
1440 | int vertexCount = (int) pConvHulls[ii]; | ||
1441 | |||
1442 | IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]); | ||
1443 | IndexedMatrix childTrans = IndexedMatrix.Identity; | ||
1444 | childTrans._origin = centroid; | ||
1445 | |||
1446 | List<IndexedVector3> virts = new List<IndexedVector3>(); | ||
1447 | int ender = ((ii + 4) + (vertexCount*3)); | ||
1448 | for (int iii = ii + 4; iii < ender; iii+=3) | ||
1449 | { | ||
1450 | |||
1451 | virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2])); | ||
1452 | } | ||
1453 | ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount); | ||
1454 | convexShape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1455 | compoundshape.AddChildShape(ref childTrans, convexShape); | ||
1456 | ii += (vertexCount*3 + 4); | ||
1457 | } | ||
1458 | |||
1459 | return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); | ||
1460 | } | ||
1461 | |||
1462 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | ||
1463 | { | ||
1464 | /* TODO */ return null; | ||
1465 | |||
1466 | } | ||
1467 | |||
1468 | public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | ||
1469 | { | ||
1470 | //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount); | ||
1471 | |||
1472 | for (int iter = 0; iter < pVerticesCount; iter++) | ||
1473 | { | ||
1474 | if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0; | ||
1475 | if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0; | ||
1476 | } | ||
1477 | |||
1478 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); | ||
1479 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); | ||
1480 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); | ||
1481 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1482 | IndexedMesh mesh = new IndexedMesh(); | ||
1483 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1484 | mesh.m_numTriangles = pIndicesCount/3; | ||
1485 | mesh.m_numVertices = pVerticesCount; | ||
1486 | mesh.m_triangleIndexBase = indicesarr; | ||
1487 | mesh.m_vertexBase = vertices; | ||
1488 | mesh.m_vertexStride = 3; | ||
1489 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1490 | mesh.m_triangleIndexStride = 3; | ||
1491 | |||
1492 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1493 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1494 | BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true); | ||
1495 | meshShape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1496 | // world.UpdateSingleAabb(meshShape); | ||
1497 | return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH); | ||
1498 | |||
1499 | } | ||
1500 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) | ||
1501 | { | ||
1502 | |||
1503 | String fileName = "objTest3.raw"; | ||
1504 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); | ||
1505 | StreamWriter sw = new StreamWriter(completePath); | ||
1506 | IndexedMesh mesh = new IndexedMesh(); | ||
1507 | |||
1508 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1509 | mesh.m_numTriangles = pIndicesCount / 3; | ||
1510 | mesh.m_numVertices = pVerticesCount; | ||
1511 | mesh.m_triangleIndexBase = indices; | ||
1512 | mesh.m_vertexBase = vertices; | ||
1513 | mesh.m_vertexStride = 3; | ||
1514 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1515 | mesh.m_triangleIndexStride = 3; | ||
1516 | |||
1517 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1518 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1519 | |||
1520 | |||
1521 | |||
1522 | for (int i = 0; i < pVerticesCount; i++) | ||
1523 | { | ||
1524 | |||
1525 | string s = vertices[indices[i * 3]].ToString("0.0000"); | ||
1526 | s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); | ||
1527 | s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); | ||
1528 | |||
1529 | sw.Write(s + "\n"); | ||
1530 | } | ||
1531 | |||
1532 | sw.Close(); | ||
1533 | } | ||
1534 | public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount) | ||
1535 | { | ||
1536 | |||
1537 | String fileName = "objTest6.raw"; | ||
1538 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); | ||
1539 | StreamWriter sw = new StreamWriter(completePath); | ||
1540 | IndexedMesh mesh = new IndexedMesh(); | ||
1541 | |||
1542 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1543 | mesh.m_numTriangles = pIndicesCount / 3; | ||
1544 | mesh.m_numVertices = pVerticesCount; | ||
1545 | mesh.m_triangleIndexBase = indices; | ||
1546 | mesh.m_vertexBase = vertices; | ||
1547 | mesh.m_vertexStride = 3; | ||
1548 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1549 | mesh.m_triangleIndexStride = 3; | ||
1550 | |||
1551 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1552 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1553 | |||
1554 | |||
1555 | sw.WriteLine("Indices"); | ||
1556 | sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount)); | ||
1557 | for (int iter = 0; iter < indices.Length; iter++) | ||
1558 | { | ||
1559 | sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter])); | ||
1560 | } | ||
1561 | sw.WriteLine("VerticesFloats"); | ||
1562 | sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount)); | ||
1563 | for (int iter = 0; iter < vertices.Length; iter++) | ||
1564 | { | ||
1565 | sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000"))); | ||
1566 | } | ||
1567 | |||
1568 | // for (int i = 0; i < pVerticesCount; i++) | ||
1569 | // { | ||
1570 | // | ||
1571 | // string s = vertices[indices[i * 3]].ToString("0.0000"); | ||
1572 | // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); | ||
1573 | // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); | ||
1574 | // | ||
1575 | // sw.Write(s + "\n"); | ||
1576 | //} | ||
1577 | |||
1578 | sw.Close(); | ||
1579 | } | ||
1580 | |||
1581 | public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, | ||
1582 | float scaleFactor, float collisionMargin) | ||
1583 | { | ||
1584 | const int upAxis = 2; | ||
1585 | HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)size.X, (int)size.Y, | ||
1586 | heightMap, scaleFactor, | ||
1587 | minHeight, maxHeight, upAxis, | ||
1588 | false); | ||
1589 | terrainShape.SetMargin(collisionMargin + 0.5f); | ||
1590 | terrainShape.SetUseDiamondSubdivision(true); | ||
1591 | terrainShape.SetUserPointer(id); | ||
1592 | return new BulletShapeXNA(terrainShape, BSPhysicsShapeType.SHAPE_TERRAIN); | ||
1593 | } | ||
1594 | |||
1595 | public override bool TranslationalLimitMotor(BulletConstraint pConstraint, float ponOff, float targetVelocity, float maxMotorForce) | ||
1596 | { | ||
1597 | TypedConstraint tconstrain = (pConstraint as BulletConstraintXNA).constrain; | ||
1598 | bool onOff = ponOff != 0; | ||
1599 | bool ret = false; | ||
1600 | |||
1601 | switch (tconstrain.GetConstraintType()) | ||
1602 | { | ||
1603 | case TypedConstraintType.D6_CONSTRAINT_TYPE: | ||
1604 | Generic6DofConstraint constrain = tconstrain as Generic6DofConstraint; | ||
1605 | constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff; | ||
1606 | constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity; | ||
1607 | constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce; | ||
1608 | ret = true; | ||
1609 | break; | ||
1610 | } | ||
1611 | |||
1612 | |||
1613 | return ret; | ||
1614 | |||
1615 | } | ||
1616 | |||
1617 | public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
1618 | out int updatedEntityCount, out int collidersCount) | ||
1619 | { | ||
1620 | /* TODO */ | ||
1621 | updatedEntityCount = 0; | ||
1622 | collidersCount = 0; | ||
1623 | |||
1624 | |||
1625 | int ret = PhysicsStep2(world,timeStep,maxSubSteps,fixedTimeStep,out updatedEntityCount,out world.physicsScene.m_updateArray, out collidersCount, out world.physicsScene.m_collisionArray); | ||
1626 | |||
1627 | return ret; | ||
1628 | } | ||
1629 | |||
1630 | private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, | ||
1631 | out int updatedEntityCount, out EntityProperties[] updatedEntities, | ||
1632 | out int collidersCount, out CollisionDesc[] colliders) | ||
1633 | { | ||
1634 | int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities, | ||
1635 | out collidersCount, out colliders, m_maxCollisions, m_maxUpdatesPerFrame); | ||
1636 | return epic; | ||
1637 | } | ||
1638 | |||
1639 | private static int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, | ||
1640 | out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates) | ||
1641 | { | ||
1642 | int numSimSteps = 0; | ||
1643 | |||
1644 | updatedEntityCount = 0; | ||
1645 | collidersCount = 0; | ||
1646 | |||
1647 | |||
1648 | if (pWorld is BulletWorldXNA) | ||
1649 | { | ||
1650 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1651 | |||
1652 | world.LastCollisionDesc = 0; | ||
1653 | world.LastEntityProperty = 0; | ||
1654 | world.UpdatedObjects = new BulletXNA.EntityProperties[maxUpdates]; | ||
1655 | world.UpdatedCollisions = new BulletXNA.CollisionDesc[maxCollisions]; | ||
1656 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); | ||
1657 | int updates = 0; | ||
1658 | |||
1659 | |||
1660 | |||
1661 | |||
1662 | m_collisionsThisFrame = 0; | ||
1663 | int numManifolds = world.GetDispatcher().GetNumManifolds(); | ||
1664 | for (int j = 0; j < numManifolds; j++) | ||
1665 | { | ||
1666 | PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j); | ||
1667 | int numContacts = contactManifold.GetNumContacts(); | ||
1668 | if (numContacts == 0) | ||
1669 | continue; | ||
1670 | |||
1671 | CollisionObject objA = contactManifold.GetBody0() as CollisionObject; | ||
1672 | CollisionObject objB = contactManifold.GetBody1() as CollisionObject; | ||
1673 | |||
1674 | ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0); | ||
1675 | IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB(); | ||
1676 | IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A | ||
1677 | |||
1678 | RecordCollision(world, objA, objB, contactPoint, contactNormal); | ||
1679 | m_collisionsThisFrame ++; | ||
1680 | if (m_collisionsThisFrame >= 9999999) | ||
1681 | break; | ||
1682 | |||
1683 | |||
1684 | } | ||
1685 | |||
1686 | updatedEntityCount = world.LastEntityProperty; | ||
1687 | updatedEntities = GetBulletSimEntityStruct(BulletXNAEntityStructToByteArray(world.UpdatedObjects, world.LastEntityProperty)); | ||
1688 | |||
1689 | |||
1690 | |||
1691 | |||
1692 | collidersCount = world.LastCollisionDesc; | ||
1693 | colliders = | ||
1694 | GetBulletSimCollisionStruct(BulletXNACollisionStructToByteArray(world.UpdatedCollisions, world.LastCollisionDesc));//new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions); | ||
1695 | |||
1696 | } | ||
1697 | else | ||
1698 | { | ||
1699 | //if (updatedEntities is null) | ||
1700 | //updatedEntities = new List<BulletXNA.EntityProperties>(); | ||
1701 | //updatedEntityCount = 0; | ||
1702 | //if (colliders is null) | ||
1703 | //colliders = new List<BulletXNA.CollisionDesc>(); | ||
1704 | //collidersCount = 0; | ||
1705 | |||
1706 | updatedEntities = new EntityProperties[0]; | ||
1707 | |||
1708 | |||
1709 | colliders = new CollisionDesc[0]; | ||
1710 | |||
1711 | } | ||
1712 | return numSimSteps; | ||
1713 | } | ||
1714 | |||
1715 | private static void RecordCollision(CollisionWorld world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm) | ||
1716 | { | ||
1717 | |||
1718 | IndexedVector3 contactNormal = norm; | ||
1719 | if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 && | ||
1720 | (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0) | ||
1721 | { | ||
1722 | return; | ||
1723 | } | ||
1724 | uint idA = (uint)objA.GetUserPointer(); | ||
1725 | uint idB = (uint)objB.GetUserPointer(); | ||
1726 | if (idA > idB) | ||
1727 | { | ||
1728 | uint temp = idA; | ||
1729 | idA = idB; | ||
1730 | idB = temp; | ||
1731 | contactNormal = -contactNormal; | ||
1732 | } | ||
1733 | |||
1734 | ulong collisionID = ((ulong) idA << 32) | idB; | ||
1735 | |||
1736 | BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc() | ||
1737 | { | ||
1738 | aID = idA, | ||
1739 | bID = idB, | ||
1740 | point = contact, | ||
1741 | normal = contactNormal | ||
1742 | }; | ||
1743 | if (world.LastCollisionDesc < world.UpdatedCollisions.Length) | ||
1744 | world.UpdatedCollisions[world.LastCollisionDesc++] = (cDesc); | ||
1745 | m_collisionsThisFrame++; | ||
1746 | |||
1747 | |||
1748 | } | ||
1749 | private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pCollisionObject) | ||
1750 | { | ||
1751 | EntityProperties ent = new EntityProperties(); | ||
1752 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1753 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1754 | IndexedMatrix transform = collisionObject.GetWorldTransform(); | ||
1755 | IndexedVector3 LinearVelocity = collisionObject.GetInterpolationLinearVelocity(); | ||
1756 | IndexedVector3 AngularVelocity = collisionObject.GetInterpolationAngularVelocity(); | ||
1757 | IndexedQuaternion rotation = transform.GetRotation(); | ||
1758 | ent.Acceleration = Vector3.Zero; | ||
1759 | ent.ID = (uint)collisionObject.GetUserPointer(); | ||
1760 | ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z); | ||
1761 | ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W); | ||
1762 | ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z); | ||
1763 | ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z); | ||
1764 | return ent; | ||
1765 | } | ||
1766 | |||
1767 | public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) { /* TODO */ return false; } | ||
1768 | |||
1769 | public override Vector3 GetLocalScaling(BulletShape pShape) | ||
1770 | { | ||
1771 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1772 | IndexedVector3 scale = shape.GetLocalScaling(); | ||
1773 | return new Vector3(scale.X,scale.Y,scale.Z); | ||
1774 | } | ||
1775 | |||
1776 | public bool RayCastGround(BulletWorld pWorld, Vector3 _RayOrigin, float pRayHeight, BulletBody NotMe) | ||
1777 | { | ||
1778 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
1779 | if (world != null) | ||
1780 | { | ||
1781 | if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody) | ||
1782 | { | ||
1783 | CollisionObject AvoidBody = (NotMe as BulletBodyXNA).body; | ||
1784 | |||
1785 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); | ||
1786 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); | ||
1787 | using ( | ||
1788 | ClosestNotMeRayResultCallback rayCallback = | ||
1789 | new ClosestNotMeRayResultCallback(rOrigin, rEnd, AvoidBody) | ||
1790 | ) | ||
1791 | { | ||
1792 | world.RayTest(ref rOrigin, ref rEnd, rayCallback); | ||
1793 | if (rayCallback.HasHit()) | ||
1794 | { | ||
1795 | IndexedVector3 hitLocation = rayCallback.m_hitPointWorld; | ||
1796 | } | ||
1797 | return rayCallback.HasHit(); | ||
1798 | } | ||
1799 | } | ||
1800 | } | ||
1801 | return false; | ||
1802 | } | ||
1803 | |||
1804 | public static unsafe BulletXNA.CollisionDesc[] GetBulletXNACollisionStruct(byte[] buffer) | ||
1805 | { | ||
1806 | int count = buffer.Length/sizeof (BulletXNA.CollisionDesc); | ||
1807 | BulletXNA.CollisionDesc[] result = new BulletXNA.CollisionDesc[count]; | ||
1808 | BulletXNA.CollisionDesc* ptr; | ||
1809 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1810 | { | ||
1811 | for (int i = 0; i < buffer.Length; i++) | ||
1812 | { | ||
1813 | localBytes[i] = buffer[i]; | ||
1814 | } | ||
1815 | for (int i=0;i<count;i++) | ||
1816 | { | ||
1817 | ptr = (BulletXNA.CollisionDesc*) (localBytes + sizeof (BulletXNA.CollisionDesc)*i); | ||
1818 | result[i] = new BulletXNA.CollisionDesc(); | ||
1819 | result[i] = *ptr; | ||
1820 | } | ||
1821 | } | ||
1822 | return result; | ||
1823 | } | ||
1824 | |||
1825 | public static unsafe CollisionDesc[] GetBulletSimCollisionStruct(byte[] buffer) | ||
1826 | { | ||
1827 | int count = buffer.Length / sizeof(CollisionDesc); | ||
1828 | CollisionDesc[] result = new CollisionDesc[count]; | ||
1829 | CollisionDesc* ptr; | ||
1830 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1831 | { | ||
1832 | for (int i = 0; i < buffer.Length; i++) | ||
1833 | { | ||
1834 | localBytes[i] = buffer[i]; | ||
1835 | } | ||
1836 | for (int i = 0; i < count; i++) | ||
1837 | { | ||
1838 | ptr = (CollisionDesc*)(localBytes + sizeof(CollisionDesc) * i); | ||
1839 | result[i] = new CollisionDesc(); | ||
1840 | result[i] = *ptr; | ||
1841 | } | ||
1842 | } | ||
1843 | return result; | ||
1844 | } | ||
1845 | public static unsafe byte[] BulletSimCollisionStructToByteArray(CollisionDesc[] CollisionDescArray, int count) | ||
1846 | { | ||
1847 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1848 | byte[] byteArray = new byte[sizeof(CollisionDesc) * arrayLength]; | ||
1849 | fixed (CollisionDesc* floatPointer = CollisionDescArray) | ||
1850 | { | ||
1851 | fixed (byte* bytePointer = byteArray) | ||
1852 | { | ||
1853 | CollisionDesc* read = floatPointer; | ||
1854 | CollisionDesc* write = (CollisionDesc*)bytePointer; | ||
1855 | for (int i = 0; i < arrayLength; i++) | ||
1856 | { | ||
1857 | *write++ = *read++; | ||
1858 | } | ||
1859 | } | ||
1860 | } | ||
1861 | return byteArray; | ||
1862 | } | ||
1863 | public static unsafe byte[] BulletXNACollisionStructToByteArray(BulletXNA.CollisionDesc[] CollisionDescArray, int count) | ||
1864 | { | ||
1865 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1866 | byte[] byteArray = new byte[sizeof(BulletXNA.CollisionDesc) * arrayLength]; | ||
1867 | fixed (BulletXNA.CollisionDesc* floatPointer = CollisionDescArray) | ||
1868 | { | ||
1869 | fixed (byte* bytePointer = byteArray) | ||
1870 | { | ||
1871 | BulletXNA.CollisionDesc* read = floatPointer; | ||
1872 | BulletXNA.CollisionDesc* write = (BulletXNA.CollisionDesc*)bytePointer; | ||
1873 | for (int i = 0; i < arrayLength; i++) | ||
1874 | { | ||
1875 | *write++ = *read++; | ||
1876 | } | ||
1877 | } | ||
1878 | } | ||
1879 | return byteArray; | ||
1880 | } | ||
1881 | public static unsafe BulletXNA.EntityProperties[] GetBulletXNAEntityStruct(byte[] buffer) | ||
1882 | { | ||
1883 | int count = buffer.Length / sizeof(BulletXNA.EntityProperties); | ||
1884 | BulletXNA.EntityProperties[] result = new BulletXNA.EntityProperties[count]; | ||
1885 | BulletXNA.EntityProperties* ptr; | ||
1886 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1887 | { | ||
1888 | for (int i = 0; i < buffer.Length; i++) | ||
1889 | { | ||
1890 | localBytes[i] = buffer[i]; | ||
1891 | } | ||
1892 | for (int i = 0; i < count; i++) | ||
1893 | { | ||
1894 | ptr = (BulletXNA.EntityProperties*)(localBytes + sizeof(BulletXNA.EntityProperties) * i); | ||
1895 | result[i] = new BulletXNA.EntityProperties(); | ||
1896 | result[i] = *ptr; | ||
1897 | } | ||
1898 | } | ||
1899 | return result; | ||
1900 | } | ||
1901 | |||
1902 | public static unsafe EntityProperties[] GetBulletSimEntityStruct(byte[] buffer) | ||
1903 | { | ||
1904 | int count = buffer.Length / sizeof(EntityProperties); | ||
1905 | EntityProperties[] result = new EntityProperties[count]; | ||
1906 | EntityProperties* ptr; | ||
1907 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1908 | { | ||
1909 | for (int i = 0; i < buffer.Length; i++) | ||
1910 | { | ||
1911 | localBytes[i] = buffer[i]; | ||
1912 | } | ||
1913 | for (int i = 0; i < count; i++) | ||
1914 | { | ||
1915 | ptr = (EntityProperties*)(localBytes + sizeof(EntityProperties) * i); | ||
1916 | result[i] = new EntityProperties(); | ||
1917 | result[i] = *ptr; | ||
1918 | } | ||
1919 | } | ||
1920 | return result; | ||
1921 | } | ||
1922 | public static unsafe byte[] BulletSimEntityStructToByteArray(EntityProperties[] CollisionDescArray, int count) | ||
1923 | { | ||
1924 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1925 | byte[] byteArray = new byte[sizeof(EntityProperties) * arrayLength]; | ||
1926 | fixed (EntityProperties* floatPointer = CollisionDescArray) | ||
1927 | { | ||
1928 | fixed (byte* bytePointer = byteArray) | ||
1929 | { | ||
1930 | EntityProperties* read = floatPointer; | ||
1931 | EntityProperties* write = (EntityProperties*)bytePointer; | ||
1932 | for (int i = 0; i < arrayLength; i++) | ||
1933 | { | ||
1934 | *write++ = *read++; | ||
1935 | } | ||
1936 | } | ||
1937 | } | ||
1938 | return byteArray; | ||
1939 | } | ||
1940 | public static unsafe byte[] BulletXNAEntityStructToByteArray(BulletXNA.EntityProperties[] CollisionDescArray, int count) | ||
1941 | { | ||
1942 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1943 | byte[] byteArray = new byte[sizeof(BulletXNA.EntityProperties) * arrayLength]; | ||
1944 | fixed (BulletXNA.EntityProperties* floatPointer = CollisionDescArray) | ||
1945 | { | ||
1946 | fixed (byte* bytePointer = byteArray) | ||
1947 | { | ||
1948 | BulletXNA.EntityProperties* read = floatPointer; | ||
1949 | BulletXNA.EntityProperties* write = (BulletXNA.EntityProperties*)bytePointer; | ||
1950 | for (int i = 0; i < arrayLength; i++) | ||
1951 | { | ||
1952 | *write++ = *read++; | ||
1953 | } | ||
1954 | } | ||
1955 | } | ||
1956 | return byteArray; | ||
1957 | } | ||
1958 | } | ||
1959 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs new file mode 100644 index 0000000..bc163eb --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | |||
@@ -0,0 +1,668 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Runtime.InteropServices; | ||
30 | using System.Security; | ||
31 | using System.Text; | ||
32 | using OpenMetaverse; | ||
33 | |||
34 | namespace OpenSim.Region.Physics.BulletSPlugin { | ||
35 | |||
36 | // Constraint type values as defined by Bullet | ||
37 | public enum ConstraintType : int | ||
38 | { | ||
39 | POINT2POINT_CONSTRAINT_TYPE = 3, | ||
40 | HINGE_CONSTRAINT_TYPE, | ||
41 | CONETWIST_CONSTRAINT_TYPE, | ||
42 | D6_CONSTRAINT_TYPE, | ||
43 | SLIDER_CONSTRAINT_TYPE, | ||
44 | CONTACT_CONSTRAINT_TYPE, | ||
45 | D6_SPRING_CONSTRAINT_TYPE, | ||
46 | MAX_CONSTRAINT_TYPE | ||
47 | } | ||
48 | |||
49 | // =============================================================================== | ||
50 | [StructLayout(LayoutKind.Sequential)] | ||
51 | public struct ConvexHull | ||
52 | { | ||
53 | Vector3 Offset; | ||
54 | int VertexCount; | ||
55 | Vector3[] Vertices; | ||
56 | } | ||
57 | public enum BSPhysicsShapeType | ||
58 | { | ||
59 | SHAPE_UNKNOWN = 0, | ||
60 | SHAPE_CAPSULE = 1, | ||
61 | SHAPE_BOX = 2, | ||
62 | SHAPE_CONE = 3, | ||
63 | SHAPE_CYLINDER = 4, | ||
64 | SHAPE_SPHERE = 5, | ||
65 | SHAPE_MESH = 6, | ||
66 | SHAPE_HULL = 7, | ||
67 | // following defined by BulletSim | ||
68 | SHAPE_GROUNDPLANE = 20, | ||
69 | SHAPE_TERRAIN = 21, | ||
70 | SHAPE_COMPOUND = 22, | ||
71 | SHAPE_HEIGHTMAP = 23, | ||
72 | SHAPE_AVATAR = 24, | ||
73 | }; | ||
74 | |||
75 | // The native shapes have predefined shape hash keys | ||
76 | public enum FixedShapeKey : ulong | ||
77 | { | ||
78 | KEY_NONE = 0, | ||
79 | KEY_BOX = 1, | ||
80 | KEY_SPHERE = 2, | ||
81 | KEY_CONE = 3, | ||
82 | KEY_CYLINDER = 4, | ||
83 | KEY_CAPSULE = 5, | ||
84 | KEY_AVATAR = 6, | ||
85 | } | ||
86 | |||
87 | [StructLayout(LayoutKind.Sequential)] | ||
88 | public struct ShapeData | ||
89 | { | ||
90 | public uint ID; | ||
91 | public BSPhysicsShapeType Type; | ||
92 | public Vector3 Position; | ||
93 | public Quaternion Rotation; | ||
94 | public Vector3 Velocity; | ||
95 | public Vector3 Scale; | ||
96 | public float Mass; | ||
97 | public float Buoyancy; | ||
98 | public System.UInt64 HullKey; | ||
99 | public System.UInt64 MeshKey; | ||
100 | public float Friction; | ||
101 | public float Restitution; | ||
102 | public float Collidable; // true of things bump into this | ||
103 | public float Static; // true if a static object. Otherwise gravity, etc. | ||
104 | public float Solid; // true if object cannot be passed through | ||
105 | public Vector3 Size; | ||
106 | |||
107 | // note that bools are passed as floats since bool size changes by language and architecture | ||
108 | public const float numericTrue = 1f; | ||
109 | public const float numericFalse = 0f; | ||
110 | } | ||
111 | [StructLayout(LayoutKind.Sequential)] | ||
112 | public struct SweepHit | ||
113 | { | ||
114 | public uint ID; | ||
115 | public float Fraction; | ||
116 | public Vector3 Normal; | ||
117 | public Vector3 Point; | ||
118 | } | ||
119 | [StructLayout(LayoutKind.Sequential)] | ||
120 | public struct RaycastHit | ||
121 | { | ||
122 | public uint ID; | ||
123 | public float Fraction; | ||
124 | public Vector3 Normal; | ||
125 | } | ||
126 | [StructLayout(LayoutKind.Sequential)] | ||
127 | public struct CollisionDesc | ||
128 | { | ||
129 | public uint aID; | ||
130 | public uint bID; | ||
131 | public Vector3 point; | ||
132 | public Vector3 normal; | ||
133 | } | ||
134 | [StructLayout(LayoutKind.Sequential)] | ||
135 | public struct EntityProperties | ||
136 | { | ||
137 | public uint ID; | ||
138 | public Vector3 Position; | ||
139 | public Quaternion Rotation; | ||
140 | public Vector3 Velocity; | ||
141 | public Vector3 Acceleration; | ||
142 | public Vector3 RotationalVelocity; | ||
143 | } | ||
144 | |||
145 | // Format of this structure must match the definition in the C++ code | ||
146 | // NOTE: adding the X causes compile breaks if used. These are unused symbols | ||
147 | // that can be removed from both here and the unmanaged definition of this structure. | ||
148 | [StructLayout(LayoutKind.Sequential)] | ||
149 | public struct ConfigurationParameters | ||
150 | { | ||
151 | public float defaultFriction; | ||
152 | public float defaultDensity; | ||
153 | public float defaultRestitution; | ||
154 | public float collisionMargin; | ||
155 | public float gravity; | ||
156 | |||
157 | public float XlinearDamping; | ||
158 | public float XangularDamping; | ||
159 | public float XdeactivationTime; | ||
160 | public float XlinearSleepingThreshold; | ||
161 | public float XangularSleepingThreshold; | ||
162 | public float XccdMotionThreshold; | ||
163 | public float XccdSweptSphereRadius; | ||
164 | public float XcontactProcessingThreshold; | ||
165 | |||
166 | public float XterrainImplementation; | ||
167 | public float XterrainFriction; | ||
168 | public float XterrainHitFraction; | ||
169 | public float XterrainRestitution; | ||
170 | public float XterrainCollisionMargin; | ||
171 | |||
172 | public float XavatarFriction; | ||
173 | public float XavatarStandingFriction; | ||
174 | public float XavatarDensity; | ||
175 | public float XavatarRestitution; | ||
176 | public float XavatarCapsuleWidth; | ||
177 | public float XavatarCapsuleDepth; | ||
178 | public float XavatarCapsuleHeight; | ||
179 | public float XavatarContactProcessingThreshold; | ||
180 | |||
181 | public float XvehicleAngularDamping; | ||
182 | |||
183 | public float maxPersistantManifoldPoolSize; | ||
184 | public float maxCollisionAlgorithmPoolSize; | ||
185 | public float shouldDisableContactPoolDynamicAllocation; | ||
186 | public float shouldForceUpdateAllAabbs; | ||
187 | public float shouldRandomizeSolverOrder; | ||
188 | public float shouldSplitSimulationIslands; | ||
189 | public float shouldEnableFrictionCaching; | ||
190 | public float numberOfSolverIterations; | ||
191 | |||
192 | public float XlinksetImplementation; | ||
193 | public float XlinkConstraintUseFrameOffset; | ||
194 | public float XlinkConstraintEnableTransMotor; | ||
195 | public float XlinkConstraintTransMotorMaxVel; | ||
196 | public float XlinkConstraintTransMotorMaxForce; | ||
197 | public float XlinkConstraintERP; | ||
198 | public float XlinkConstraintCFM; | ||
199 | public float XlinkConstraintSolverIterations; | ||
200 | |||
201 | public float XphysicsLoggingFrames; | ||
202 | |||
203 | public const float numericTrue = 1f; | ||
204 | public const float numericFalse = 0f; | ||
205 | } | ||
206 | |||
207 | |||
208 | // The states a bullet collision object can have | ||
209 | public enum ActivationState : uint | ||
210 | { | ||
211 | ACTIVE_TAG = 1, | ||
212 | ISLAND_SLEEPING, | ||
213 | WANTS_DEACTIVATION, | ||
214 | DISABLE_DEACTIVATION, | ||
215 | DISABLE_SIMULATION, | ||
216 | } | ||
217 | |||
218 | public enum CollisionObjectTypes : int | ||
219 | { | ||
220 | CO_COLLISION_OBJECT = 1 << 0, | ||
221 | CO_RIGID_BODY = 1 << 1, | ||
222 | CO_GHOST_OBJECT = 1 << 2, | ||
223 | CO_SOFT_BODY = 1 << 3, | ||
224 | CO_HF_FLUID = 1 << 4, | ||
225 | CO_USER_TYPE = 1 << 5, | ||
226 | } | ||
227 | |||
228 | // Values used by Bullet and BulletSim to control object properties. | ||
229 | // Bullet's "CollisionFlags" has more to do with operations on the | ||
230 | // object (if collisions happen, if gravity effects it, ...). | ||
231 | public enum CollisionFlags : uint | ||
232 | { | ||
233 | CF_STATIC_OBJECT = 1 << 0, | ||
234 | CF_KINEMATIC_OBJECT = 1 << 1, | ||
235 | CF_NO_CONTACT_RESPONSE = 1 << 2, | ||
236 | CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3, | ||
237 | CF_CHARACTER_OBJECT = 1 << 4, | ||
238 | CF_DISABLE_VISUALIZE_OBJECT = 1 << 5, | ||
239 | CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, | ||
240 | // Following used by BulletSim to control collisions and updates | ||
241 | BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, | ||
242 | BS_FLOATS_ON_WATER = 1 << 11, | ||
243 | BS_VEHICLE_COLLISIONS = 1 << 12, | ||
244 | BS_NONE = 0, | ||
245 | BS_ALL = 0xFFFFFFFF | ||
246 | }; | ||
247 | |||
248 | // Values f collisions groups and masks | ||
249 | public enum CollisionFilterGroups : uint | ||
250 | { | ||
251 | // Don't use the bit definitions!! Define the use in a | ||
252 | // filter/mask definition below. This way collision interactions | ||
253 | // are more easily found and debugged. | ||
254 | BNoneGroup = 0, | ||
255 | BDefaultGroup = 1 << 0, // 0001 | ||
256 | BStaticGroup = 1 << 1, // 0002 | ||
257 | BKinematicGroup = 1 << 2, // 0004 | ||
258 | BDebrisGroup = 1 << 3, // 0008 | ||
259 | BSensorTrigger = 1 << 4, // 0010 | ||
260 | BCharacterGroup = 1 << 5, // 0020 | ||
261 | BAllGroup = 0x000FFFFF, | ||
262 | // Filter groups defined by BulletSim | ||
263 | BGroundPlaneGroup = 1 << 10, // 0400 | ||
264 | BTerrainGroup = 1 << 11, // 0800 | ||
265 | BRaycastGroup = 1 << 12, // 1000 | ||
266 | BSolidGroup = 1 << 13, // 2000 | ||
267 | // BLinksetGroup = xx // a linkset proper is either static or dynamic | ||
268 | BLinksetChildGroup = 1 << 14, // 4000 | ||
269 | }; | ||
270 | |||
271 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | ||
272 | // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2. | ||
273 | public enum ConstraintParams : int | ||
274 | { | ||
275 | BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730 | ||
276 | BT_CONSTRAINT_STOP_ERP, | ||
277 | BT_CONSTRAINT_CFM, | ||
278 | BT_CONSTRAINT_STOP_CFM, | ||
279 | }; | ||
280 | public enum ConstraintParamAxis : int | ||
281 | { | ||
282 | AXIS_LINEAR_X = 0, | ||
283 | AXIS_LINEAR_Y, | ||
284 | AXIS_LINEAR_Z, | ||
285 | AXIS_ANGULAR_X, | ||
286 | AXIS_ANGULAR_Y, | ||
287 | AXIS_ANGULAR_Z, | ||
288 | AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls | ||
289 | AXIS_ANGULAR_ALL, | ||
290 | AXIS_ALL | ||
291 | }; | ||
292 | |||
293 | public abstract class BSAPITemplate | ||
294 | { | ||
295 | // Returns the name of the underlying Bullet engine | ||
296 | public abstract string BulletEngineName { get; } | ||
297 | public abstract string BulletEngineVersion { get; protected set;} | ||
298 | |||
299 | // Initialization and simulation | ||
300 | public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, | ||
301 | int maxCollisions, ref CollisionDesc[] collisionArray, | ||
302 | int maxUpdates, ref EntityProperties[] updateArray | ||
303 | ); | ||
304 | |||
305 | public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
306 | out int updatedEntityCount, out int collidersCount); | ||
307 | |||
308 | public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); | ||
309 | |||
310 | public abstract void Shutdown(BulletWorld sim); | ||
311 | |||
312 | public abstract bool PushUpdate(BulletBody obj); | ||
313 | |||
314 | // ===================================================================================== | ||
315 | // Mesh, hull, shape and body creation helper routines | ||
316 | public abstract BulletShape CreateMeshShape(BulletWorld world, | ||
317 | int indicesCount, int[] indices, | ||
318 | int verticesCount, float[] vertices ); | ||
319 | |||
320 | public abstract BulletShape CreateHullShape(BulletWorld world, | ||
321 | int hullCount, float[] hulls); | ||
322 | |||
323 | public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape); | ||
324 | |||
325 | public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); | ||
326 | |||
327 | public abstract bool IsNativeShape(BulletShape shape); | ||
328 | |||
329 | public abstract void SetShapeCollisionMargin(BulletShape shape, float margin); | ||
330 | |||
331 | public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale); | ||
332 | |||
333 | public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree); | ||
334 | |||
335 | public abstract int GetNumberOfCompoundChildren(BulletShape cShape); | ||
336 | |||
337 | public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot); | ||
338 | |||
339 | public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); | ||
340 | |||
341 | public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); | ||
342 | |||
343 | public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape); | ||
344 | |||
345 | public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb); | ||
346 | |||
347 | public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); | ||
348 | |||
349 | public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); | ||
350 | |||
351 | public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape); | ||
352 | |||
353 | public abstract CollisionObjectTypes GetBodyType(BulletBody obj); | ||
354 | |||
355 | public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); | ||
356 | |||
357 | public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot); | ||
358 | |||
359 | public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); | ||
360 | |||
361 | public abstract void DestroyObject(BulletWorld sim, BulletBody obj); | ||
362 | |||
363 | // ===================================================================================== | ||
364 | public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); | ||
365 | |||
366 | public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, | ||
367 | float scaleFactor, float collisionMargin); | ||
368 | |||
369 | // ===================================================================================== | ||
370 | // Constraint creation and helper routines | ||
371 | public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
372 | Vector3 frame1loc, Quaternion frame1rot, | ||
373 | Vector3 frame2loc, Quaternion frame2rot, | ||
374 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
375 | |||
376 | public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
377 | Vector3 joinPoint, | ||
378 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
379 | |||
380 | public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
381 | Vector3 pivotinA, Vector3 pivotinB, | ||
382 | Vector3 axisInA, Vector3 axisInB, | ||
383 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
384 | |||
385 | public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse); | ||
386 | |||
387 | public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations); | ||
388 | |||
389 | public abstract bool SetFrames(BulletConstraint constrain, | ||
390 | Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); | ||
391 | |||
392 | public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); | ||
393 | |||
394 | public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); | ||
395 | |||
396 | public abstract bool UseFrameOffset(BulletConstraint constrain, float enable); | ||
397 | |||
398 | public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); | ||
399 | |||
400 | public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); | ||
401 | |||
402 | public abstract bool CalculateTransforms(BulletConstraint constrain); | ||
403 | |||
404 | public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); | ||
405 | |||
406 | public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain); | ||
407 | |||
408 | // ===================================================================================== | ||
409 | // btCollisionWorld entries | ||
410 | public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj); | ||
411 | |||
412 | public abstract void UpdateAabbs(BulletWorld world); | ||
413 | |||
414 | public abstract bool GetForceUpdateAllAabbs(BulletWorld world); | ||
415 | |||
416 | public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force); | ||
417 | |||
418 | // ===================================================================================== | ||
419 | // btDynamicsWorld entries | ||
420 | // public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj, Vector3 pos, Quaternion rot); | ||
421 | public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj); | ||
422 | |||
423 | public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); | ||
424 | |||
425 | public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); | ||
426 | |||
427 | public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); | ||
428 | // ===================================================================================== | ||
429 | // btCollisionObject entries | ||
430 | public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain); | ||
431 | |||
432 | public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict); | ||
433 | |||
434 | public abstract bool HasAnisotripicFriction(BulletConstraint constrain); | ||
435 | |||
436 | public abstract void SetContactProcessingThreshold(BulletBody obj, float val); | ||
437 | |||
438 | public abstract float GetContactProcessingThreshold(BulletBody obj); | ||
439 | |||
440 | public abstract bool IsStaticObject(BulletBody obj); | ||
441 | |||
442 | public abstract bool IsKinematicObject(BulletBody obj); | ||
443 | |||
444 | public abstract bool IsStaticOrKinematicObject(BulletBody obj); | ||
445 | |||
446 | public abstract bool HasContactResponse(BulletBody obj); | ||
447 | |||
448 | public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape); | ||
449 | |||
450 | public abstract BulletShape GetCollisionShape(BulletBody obj); | ||
451 | |||
452 | public abstract int GetActivationState(BulletBody obj); | ||
453 | |||
454 | public abstract void SetActivationState(BulletBody obj, int state); | ||
455 | |||
456 | public abstract void SetDeactivationTime(BulletBody obj, float dtime); | ||
457 | |||
458 | public abstract float GetDeactivationTime(BulletBody obj); | ||
459 | |||
460 | public abstract void ForceActivationState(BulletBody obj, ActivationState state); | ||
461 | |||
462 | public abstract void Activate(BulletBody obj, bool forceActivation); | ||
463 | |||
464 | public abstract bool IsActive(BulletBody obj); | ||
465 | |||
466 | public abstract void SetRestitution(BulletBody obj, float val); | ||
467 | |||
468 | public abstract float GetRestitution(BulletBody obj); | ||
469 | |||
470 | public abstract void SetFriction(BulletBody obj, float val); | ||
471 | |||
472 | public abstract float GetFriction(BulletBody obj); | ||
473 | |||
474 | public abstract Vector3 GetPosition(BulletBody obj); | ||
475 | |||
476 | public abstract Quaternion GetOrientation(BulletBody obj); | ||
477 | |||
478 | public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); | ||
479 | |||
480 | // public abstract IntPtr GetBroadphaseHandle(BulletBody obj); | ||
481 | |||
482 | // public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle); | ||
483 | |||
484 | public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); | ||
485 | |||
486 | public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel); | ||
487 | |||
488 | public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel); | ||
489 | |||
490 | public abstract float GetHitFraction(BulletBody obj); | ||
491 | |||
492 | public abstract void SetHitFraction(BulletBody obj, float val); | ||
493 | |||
494 | public abstract CollisionFlags GetCollisionFlags(BulletBody obj); | ||
495 | |||
496 | public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags); | ||
497 | |||
498 | public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags); | ||
499 | |||
500 | public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags); | ||
501 | |||
502 | public abstract float GetCcdMotionThreshold(BulletBody obj); | ||
503 | |||
504 | public abstract void SetCcdMotionThreshold(BulletBody obj, float val); | ||
505 | |||
506 | public abstract float GetCcdSweptSphereRadius(BulletBody obj); | ||
507 | |||
508 | public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val); | ||
509 | |||
510 | public abstract IntPtr GetUserPointer(BulletBody obj); | ||
511 | |||
512 | public abstract void SetUserPointer(BulletBody obj, IntPtr val); | ||
513 | |||
514 | // ===================================================================================== | ||
515 | // btRigidBody entries | ||
516 | public abstract void ApplyGravity(BulletBody obj); | ||
517 | |||
518 | public abstract void SetGravity(BulletBody obj, Vector3 val); | ||
519 | |||
520 | public abstract Vector3 GetGravity(BulletBody obj); | ||
521 | |||
522 | public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping); | ||
523 | |||
524 | public abstract void SetLinearDamping(BulletBody obj, float lin_damping); | ||
525 | |||
526 | public abstract void SetAngularDamping(BulletBody obj, float ang_damping); | ||
527 | |||
528 | public abstract float GetLinearDamping(BulletBody obj); | ||
529 | |||
530 | public abstract float GetAngularDamping(BulletBody obj); | ||
531 | |||
532 | public abstract float GetLinearSleepingThreshold(BulletBody obj); | ||
533 | |||
534 | public abstract void ApplyDamping(BulletBody obj, float timeStep); | ||
535 | |||
536 | public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia); | ||
537 | |||
538 | public abstract Vector3 GetLinearFactor(BulletBody obj); | ||
539 | |||
540 | public abstract void SetLinearFactor(BulletBody obj, Vector3 factor); | ||
541 | |||
542 | public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); | ||
543 | |||
544 | // Add a force to the object as if its mass is one. | ||
545 | public abstract void ApplyCentralForce(BulletBody obj, Vector3 force); | ||
546 | |||
547 | // Set the force being applied to the object as if its mass is one. | ||
548 | public abstract void SetObjectForce(BulletBody obj, Vector3 force); | ||
549 | |||
550 | public abstract Vector3 GetTotalForce(BulletBody obj); | ||
551 | |||
552 | public abstract Vector3 GetTotalTorque(BulletBody obj); | ||
553 | |||
554 | public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj); | ||
555 | |||
556 | public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); | ||
557 | |||
558 | public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); | ||
559 | |||
560 | public abstract void ApplyTorque(BulletBody obj, Vector3 torque); | ||
561 | |||
562 | // Apply force at the given point. Will add torque to the object. | ||
563 | public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); | ||
564 | |||
565 | // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. | ||
566 | public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp); | ||
567 | |||
568 | // Apply impulse to the object's torque. Force is scaled by object's mass. | ||
569 | public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); | ||
570 | |||
571 | // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. | ||
572 | public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); | ||
573 | |||
574 | public abstract void ClearForces(BulletBody obj); | ||
575 | |||
576 | public abstract void ClearAllForces(BulletBody obj); | ||
577 | |||
578 | public abstract void UpdateInertiaTensor(BulletBody obj); | ||
579 | |||
580 | public abstract Vector3 GetLinearVelocity(BulletBody obj); | ||
581 | |||
582 | public abstract Vector3 GetAngularVelocity(BulletBody obj); | ||
583 | |||
584 | public abstract void SetLinearVelocity(BulletBody obj, Vector3 val); | ||
585 | |||
586 | public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); | ||
587 | |||
588 | public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); | ||
589 | |||
590 | public abstract void Translate(BulletBody obj, Vector3 trans); | ||
591 | |||
592 | public abstract void UpdateDeactivation(BulletBody obj, float timeStep); | ||
593 | |||
594 | public abstract bool WantsSleeping(BulletBody obj); | ||
595 | |||
596 | public abstract void SetAngularFactor(BulletBody obj, float factor); | ||
597 | |||
598 | public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor); | ||
599 | |||
600 | public abstract Vector3 GetAngularFactor(BulletBody obj); | ||
601 | |||
602 | public abstract bool IsInWorld(BulletWorld world, BulletBody obj); | ||
603 | |||
604 | public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain); | ||
605 | |||
606 | public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); | ||
607 | |||
608 | public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index); | ||
609 | |||
610 | public abstract int GetNumConstraintRefs(BulletBody obj); | ||
611 | |||
612 | public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); | ||
613 | |||
614 | // ===================================================================================== | ||
615 | // btCollisionShape entries | ||
616 | |||
617 | public abstract float GetAngularMotionDisc(BulletShape shape); | ||
618 | |||
619 | public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); | ||
620 | |||
621 | public abstract bool IsPolyhedral(BulletShape shape); | ||
622 | |||
623 | public abstract bool IsConvex2d(BulletShape shape); | ||
624 | |||
625 | public abstract bool IsConvex(BulletShape shape); | ||
626 | |||
627 | public abstract bool IsNonMoving(BulletShape shape); | ||
628 | |||
629 | public abstract bool IsConcave(BulletShape shape); | ||
630 | |||
631 | public abstract bool IsCompound(BulletShape shape); | ||
632 | |||
633 | public abstract bool IsSoftBody(BulletShape shape); | ||
634 | |||
635 | public abstract bool IsInfinite(BulletShape shape); | ||
636 | |||
637 | public abstract void SetLocalScaling(BulletShape shape, Vector3 scale); | ||
638 | |||
639 | public abstract Vector3 GetLocalScaling(BulletShape shape); | ||
640 | |||
641 | public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass); | ||
642 | |||
643 | public abstract int GetShapeType(BulletShape shape); | ||
644 | |||
645 | public abstract void SetMargin(BulletShape shape, float val); | ||
646 | |||
647 | public abstract float GetMargin(BulletShape shape); | ||
648 | |||
649 | // ===================================================================================== | ||
650 | // Debugging | ||
651 | public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { } | ||
652 | |||
653 | public virtual void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) { } | ||
654 | |||
655 | public virtual void DumpConstraint(BulletWorld sim, BulletConstraint constrain) { } | ||
656 | |||
657 | public virtual void DumpActivationInfo(BulletWorld sim) { } | ||
658 | |||
659 | public virtual void DumpAllInfo(BulletWorld sim) { } | ||
660 | |||
661 | public virtual void DumpPhysicsStatistics(BulletWorld sim) { } | ||
662 | |||
663 | public virtual void ResetBroadphasePool(BulletWorld sim) { } | ||
664 | |||
665 | public virtual void ResetConstraintSolver(BulletWorld sim) { } | ||
666 | |||
667 | }; | ||
668 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 4c195e1..7603254 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -56,19 +56,19 @@ public sealed class BSCharacter : BSPhysObject | |||
56 | private int _physicsActorType; | 56 | private int _physicsActorType; |
57 | private bool _isPhysical; | 57 | private bool _isPhysical; |
58 | private bool _flying; | 58 | private bool _flying; |
59 | private bool _wasWalking; // 'true' if the avatar was walking/moving last frame | ||
59 | private bool _setAlwaysRun; | 60 | private bool _setAlwaysRun; |
60 | private bool _throttleUpdates; | 61 | private bool _throttleUpdates; |
61 | private bool _isColliding; | ||
62 | private bool _collidingObj; | ||
63 | private bool _floatOnWater; | 62 | private bool _floatOnWater; |
64 | private OMV.Vector3 _rotationalVelocity; | 63 | private OMV.Vector3 _rotationalVelocity; |
65 | private bool _kinematic; | 64 | private bool _kinematic; |
66 | private float _buoyancy; | 65 | private float _buoyancy; |
67 | 66 | ||
68 | // The friction and velocity of the avatar is modified depending on whether walking or not. | 67 | // The friction and velocity of the avatar is modified depending on whether walking or not. |
69 | private OMV.Vector3 _appliedVelocity; // the last velocity applied to the avatar | ||
70 | private float _currentFriction; // the friction currently being used (changed by setVelocity). | 68 | private float _currentFriction; // the friction currently being used (changed by setVelocity). |
71 | 69 | ||
70 | private BSVMotor _velocityMotor; | ||
71 | |||
72 | private OMV.Vector3 _PIDTarget; | 72 | private OMV.Vector3 _PIDTarget; |
73 | private bool _usePID; | 73 | private bool _usePID; |
74 | private float _PIDTau; | 74 | private float _PIDTau; |
@@ -83,34 +83,37 @@ public sealed class BSCharacter : BSPhysObject | |||
83 | _physicsActorType = (int)ActorTypes.Agent; | 83 | _physicsActorType = (int)ActorTypes.Agent; |
84 | _position = pos; | 84 | _position = pos; |
85 | 85 | ||
86 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | ||
87 | // replace with the default values. | ||
88 | _size = size; | ||
89 | if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth; | ||
90 | if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth; | ||
91 | |||
92 | _flying = isFlying; | 86 | _flying = isFlying; |
87 | _wasWalking = true; // causes first step to initialize standing | ||
93 | _orientation = OMV.Quaternion.Identity; | 88 | _orientation = OMV.Quaternion.Identity; |
94 | _velocity = OMV.Vector3.Zero; | 89 | _velocity = OMV.Vector3.Zero; |
95 | _appliedVelocity = OMV.Vector3.Zero; | ||
96 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 90 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
97 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | 91 | _currentFriction = BSParam.AvatarStandingFriction; |
98 | _avatarDensity = PhysicsScene.Params.avatarDensity; | 92 | _avatarDensity = BSParam.AvatarDensity; |
93 | |||
94 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | ||
95 | // replace with the default values. | ||
96 | _size = size; | ||
97 | if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth; | ||
98 | if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth; | ||
99 | 99 | ||
100 | // The dimensions of the avatar capsule are kept in the scale. | 100 | // The dimensions of the physical capsule are kept in the scale. |
101 | // Physics creates a unit capsule which is scaled by the physics engine. | 101 | // Physics creates a unit capsule which is scaled by the physics engine. |
102 | ComputeAvatarScale(_size); | 102 | Scale = ComputeAvatarScale(_size); |
103 | // set _avatarVolume and _mass based on capsule size, _density and Scale | 103 | // set _avatarVolume and _mass based on capsule size, _density and Scale |
104 | ComputeAvatarVolumeAndMass(); | 104 | ComputeAvatarVolumeAndMass(); |
105 | |||
106 | SetupMovementMotor(); | ||
107 | |||
105 | DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", | 108 | DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", |
106 | LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); | 109 | LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); |
107 | 110 | ||
108 | // do actual create at taint time | 111 | // do actual creation in taint time |
109 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() | 112 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() |
110 | { | 113 | { |
111 | DetailLog("{0},BSCharacter.create,taint", LocalID); | 114 | DetailLog("{0},BSCharacter.create,taint", LocalID); |
112 | // New body and shape into PhysBody and PhysShape | 115 | // New body and shape into PhysBody and PhysShape |
113 | PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, null, null); | 116 | PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this); |
114 | 117 | ||
115 | SetPhysicalProperties(); | 118 | SetPhysicalProperties(); |
116 | }); | 119 | }); |
@@ -120,54 +123,198 @@ public sealed class BSCharacter : BSPhysObject | |||
120 | // called when this character is being destroyed and the resources should be released | 123 | // called when this character is being destroyed and the resources should be released |
121 | public override void Destroy() | 124 | public override void Destroy() |
122 | { | 125 | { |
126 | base.Destroy(); | ||
127 | |||
123 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 128 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
124 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() | 129 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() |
125 | { | 130 | { |
126 | PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); | 131 | PhysicsScene.Shapes.DereferenceBody(PhysBody, true /* inTaintTime */, null /* bodyCallback */); |
127 | PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); | 132 | PhysBody.Clear(); |
133 | PhysicsScene.Shapes.DereferenceShape(PhysShape, true /* inTaintTime */, null /* bodyCallback */); | ||
134 | PhysShape.Clear(); | ||
128 | }); | 135 | }); |
129 | } | 136 | } |
130 | 137 | ||
131 | private void SetPhysicalProperties() | 138 | private void SetPhysicalProperties() |
132 | { | 139 | { |
133 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 140 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); |
134 | 141 | ||
135 | ZeroMotion(true); | 142 | ZeroMotion(true); |
136 | ForcePosition = _position; | 143 | ForcePosition = _position; |
144 | |||
137 | // Set the velocity and compute the proper friction | 145 | // Set the velocity and compute the proper friction |
146 | _velocityMotor.Reset(); | ||
147 | _velocityMotor.SetTarget(_velocity); | ||
148 | _velocityMotor.SetCurrent(_velocity); | ||
138 | ForceVelocity = _velocity; | 149 | ForceVelocity = _velocity; |
139 | 150 | ||
140 | // This will enable or disable the flying buoyancy of the avatar. | 151 | // This will enable or disable the flying buoyancy of the avatar. |
141 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. | 152 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. |
142 | Flying = _flying; | 153 | Flying = _flying; |
143 | 154 | ||
144 | BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.avatarRestitution); | 155 | PhysicsScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution); |
145 | BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin); | 156 | PhysicsScene.PE.SetMargin(PhysShape, PhysicsScene.Params.collisionMargin); |
146 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); | 157 | PhysicsScene.PE.SetLocalScaling(PhysShape, Scale); |
147 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | 158 | PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); |
148 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 159 | if (BSParam.CcdMotionThreshold > 0f) |
149 | { | 160 | { |
150 | BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | 161 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
151 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | 162 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
152 | } | 163 | } |
153 | 164 | ||
154 | UpdatePhysicalMassProperties(RawMass); | 165 | UpdatePhysicalMassProperties(RawMass, false); |
155 | 166 | ||
156 | // Make so capsule does not fall over | 167 | // Make so capsule does not fall over |
157 | BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); | 168 | PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero); |
158 | 169 | ||
159 | BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT); | 170 | PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); |
160 | 171 | ||
161 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 172 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); |
162 | 173 | ||
163 | // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG); | 174 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); |
164 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_DEACTIVATION); | 175 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION); |
165 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 176 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); |
166 | 177 | ||
167 | // Do this after the object has been added to the world | 178 | // Do this after the object has been added to the world |
168 | BulletSimAPI.SetCollisionFilterMask2(PhysBody.ptr, | 179 | PhysBody.collisionType = CollisionType.Avatar; |
169 | (uint)CollisionFilterGroups.AvatarFilter, | 180 | PhysBody.ApplyCollisionMask(PhysicsScene); |
170 | (uint)CollisionFilterGroups.AvatarMask); | 181 | } |
182 | |||
183 | // The avatar's movement is controlled by this motor that speeds up and slows down | ||
184 | // the avatar seeking to reach the motor's target speed. | ||
185 | // This motor runs as a prestep action for the avatar so it will keep the avatar | ||
186 | // standing as well as moving. Destruction of the avatar will destroy the pre-step action. | ||
187 | private void SetupMovementMotor() | ||
188 | { | ||
189 | // Infinite decay and timescale values so motor only changes current to target values. | ||
190 | _velocityMotor = new BSVMotor("BSCharacter.Velocity", | ||
191 | 0.2f, // time scale | ||
192 | BSMotor.Infinite, // decay time scale | ||
193 | BSMotor.InfiniteVector, // friction timescale | ||
194 | 1f // efficiency | ||
195 | ); | ||
196 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
197 | |||
198 | RegisterPreStepAction("BSCharactor.Movement", LocalID, delegate(float timeStep) | ||
199 | { | ||
200 | // TODO: Decide if the step parameters should be changed depending on the avatar's | ||
201 | // state (flying, colliding, ...). There is code in ODE to do this. | ||
202 | |||
203 | // COMMENTARY: when the user is making the avatar walk, except for falling, the velocity | ||
204 | // specified for the avatar is the one that should be used. For falling, if the avatar | ||
205 | // is not flying and is not colliding then it is presumed to be falling and the Z | ||
206 | // component is not fooled with (thus allowing gravity to do its thing). | ||
207 | // When the avatar is standing, though, the user has specified a velocity of zero and | ||
208 | // the avatar should be standing. But if the avatar is pushed by something in the world | ||
209 | // (raising elevator platform, moving vehicle, ...) the avatar should be allowed to | ||
210 | // move. Thus, the velocity cannot be forced to zero. The problem is that small velocity | ||
211 | // errors can creap in and the avatar will slowly float off in some direction. | ||
212 | // So, the problem is that, when an avatar is standing, we cannot tell creaping error | ||
213 | // from real pushing.OMV.Vector3.Zero; | ||
214 | // The code below keeps setting the velocity to zero hoping the world will keep pushing. | ||
215 | |||
216 | _velocityMotor.Step(timeStep); | ||
217 | |||
218 | // If we're not supposed to be moving, make sure things are zero. | ||
219 | if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue == OMV.Vector3.Zero && IsColliding) | ||
220 | { | ||
221 | // The avatar shouldn't be moving | ||
222 | _velocityMotor.Zero(); | ||
223 | ZeroMotion(true /* inTaintTime */); | ||
224 | |||
225 | // Standing has more friction on the ground | ||
226 | if (_currentFriction != BSParam.AvatarStandingFriction) | ||
227 | { | ||
228 | _currentFriction = BSParam.AvatarStandingFriction; | ||
229 | PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); | ||
230 | } | ||
231 | DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); | ||
232 | |||
233 | _wasWalking = false; | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; | ||
238 | |||
239 | if (_currentFriction != BSParam.AvatarFriction) | ||
240 | { | ||
241 | // Probably starting up walking. Set friction to moving friction. | ||
242 | _currentFriction = BSParam.AvatarFriction; | ||
243 | PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); | ||
244 | } | ||
245 | |||
246 | // If falling, we keep the world's downward vector no matter what the other axis specify. | ||
247 | if (!Flying && !IsColliding) | ||
248 | { | ||
249 | stepVelocity.Z = _velocity.Z; | ||
250 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
251 | } | ||
252 | |||
253 | // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. | ||
254 | OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass; | ||
255 | |||
256 | // Should we check for move force being small and forcing velocity to zero? | ||
257 | |||
258 | // Add special movement force to allow avatars to walk up stepped surfaces. | ||
259 | moveForce += WalkUpStairs(); | ||
260 | |||
261 | DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); | ||
262 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); | ||
263 | _wasWalking = true; | ||
264 | } | ||
265 | }); | ||
266 | } | ||
267 | |||
268 | // Decide of the character is colliding with a low object and compute a force to pop the | ||
269 | // avatar up so it has a chance of walking up and over the low object. | ||
270 | private OMV.Vector3 WalkUpStairs() | ||
271 | { | ||
272 | OMV.Vector3 ret = OMV.Vector3.Zero; | ||
273 | |||
274 | // This test is done if moving forward, not flying and is colliding with something. | ||
275 | // DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4}", | ||
276 | // LocalID, IsColliding, Flying, TargetSpeed, CollisionsLastTick.Count); | ||
277 | if (IsColliding && !Flying && TargetSpeed > 0.1f /* && ForwardSpeed < 0.1f */) | ||
278 | { | ||
279 | // The range near the character's feet where we will consider stairs | ||
280 | float nearFeetHeightMin = RawPosition.Z - (Size.Z / 2f) + 0.05f; | ||
281 | float nearFeetHeightMax = nearFeetHeightMin + BSParam.AvatarStepHeight; | ||
282 | |||
283 | // Look for a collision point that is near the character's feet and is oriented the same as the charactor is | ||
284 | foreach (KeyValuePair<uint, ContactPoint> kvp in CollisionsLastTick.m_objCollisionList) | ||
285 | { | ||
286 | // Don't care about collisions with the terrain | ||
287 | if (kvp.Key > PhysicsScene.TerrainManager.HighestTerrainID) | ||
288 | { | ||
289 | OMV.Vector3 touchPosition = kvp.Value.Position; | ||
290 | // DetailLog("{0},BSCharacter.WalkUpStairs,min={1},max={2},touch={3}", | ||
291 | // LocalID, nearFeetHeightMin, nearFeetHeightMax, touchPosition); | ||
292 | if (touchPosition.Z >= nearFeetHeightMin && touchPosition.Z <= nearFeetHeightMax) | ||
293 | { | ||
294 | // This contact is within the 'near the feet' range. | ||
295 | // The normal should be our contact point to the object so it is pointing away | ||
296 | // thus the difference between our facing orientation and the normal should be small. | ||
297 | OMV.Vector3 directionFacing = OMV.Vector3.UnitX * RawOrientation; | ||
298 | OMV.Vector3 touchNormal = OMV.Vector3.Normalize(kvp.Value.SurfaceNormal); | ||
299 | float diff = Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal)); | ||
300 | if (diff < BSParam.AvatarStepApproachFactor) | ||
301 | { | ||
302 | // Found the stairs contact point. Push up a little to raise the character. | ||
303 | float upForce = (touchPosition.Z - nearFeetHeightMin) * Mass * BSParam.AvatarStepForceFactor; | ||
304 | ret = new OMV.Vector3(0f, 0f, upForce); | ||
305 | |||
306 | // Also move the avatar up for the new height | ||
307 | OMV.Vector3 displacement = new OMV.Vector3(0f, 0f, BSParam.AvatarStepHeight / 2f); | ||
308 | ForcePosition = RawPosition + displacement; | ||
309 | } | ||
310 | DetailLog("{0},BSCharacter.WalkUpStairs,touchPos={1},nearFeetMin={2},faceDir={3},norm={4},diff={5},ret={6}", | ||
311 | LocalID, touchPosition, nearFeetHeightMin, directionFacing, touchNormal, diff, ret); | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | |||
317 | return ret; | ||
171 | } | 318 | } |
172 | 319 | ||
173 | public override void RequestPhysicsterseUpdate() | 320 | public override void RequestPhysicsterseUpdate() |
@@ -185,24 +332,31 @@ public sealed class BSCharacter : BSPhysObject | |||
185 | } | 332 | } |
186 | 333 | ||
187 | set { | 334 | set { |
188 | // When an avatar's size is set, only the height is changed. | ||
189 | _size = value; | 335 | _size = value; |
190 | ComputeAvatarScale(_size); | 336 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, |
337 | // replace with the default values. | ||
338 | if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth; | ||
339 | if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth; | ||
340 | |||
341 | Scale = ComputeAvatarScale(_size); | ||
191 | ComputeAvatarVolumeAndMass(); | 342 | ComputeAvatarVolumeAndMass(); |
192 | DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", | 343 | DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", |
193 | LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); | 344 | LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); |
194 | 345 | ||
195 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() | 346 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() |
196 | { | 347 | { |
197 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); | 348 | if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) |
198 | UpdatePhysicalMassProperties(RawMass); | 349 | { |
350 | PhysicsScene.PE.SetLocalScaling(PhysShape, Scale); | ||
351 | UpdatePhysicalMassProperties(RawMass, true); | ||
352 | // Make sure this change appears as a property update event | ||
353 | PhysicsScene.PE.PushUpdate(PhysBody); | ||
354 | } | ||
199 | }); | 355 | }); |
200 | 356 | ||
201 | } | 357 | } |
202 | } | 358 | } |
203 | 359 | ||
204 | public override OMV.Vector3 Scale { get; set; } | ||
205 | |||
206 | public override PrimitiveBaseShape Shape | 360 | public override PrimitiveBaseShape Shape |
207 | { | 361 | { |
208 | set { BaseShape = value; } | 362 | set { BaseShape = value; } |
@@ -219,6 +373,10 @@ public sealed class BSCharacter : BSPhysObject | |||
219 | public override bool Selected { | 373 | public override bool Selected { |
220 | set { _selected = value; } | 374 | set { _selected = value; } |
221 | } | 375 | } |
376 | public override bool IsSelected | ||
377 | { | ||
378 | get { return _selected; } | ||
379 | } | ||
222 | public override void CrossingFailure() { return; } | 380 | public override void CrossingFailure() { return; } |
223 | public override void link(PhysicsActor obj) { return; } | 381 | public override void link(PhysicsActor obj) { return; } |
224 | public override void delink() { return; } | 382 | public override void delink() { return; } |
@@ -236,7 +394,8 @@ public sealed class BSCharacter : BSPhysObject | |||
236 | // Zero some other properties directly into the physics engine | 394 | // Zero some other properties directly into the physics engine |
237 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() | 395 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() |
238 | { | 396 | { |
239 | BulletSimAPI.ClearAllForces2(PhysBody.ptr); | 397 | if (PhysBody.HasPhysicalBody) |
398 | PhysicsScene.PE.ClearAllForces(PhysBody); | ||
240 | }); | 399 | }); |
241 | } | 400 | } |
242 | public override void ZeroAngularMotion(bool inTaintTime) | 401 | public override void ZeroAngularMotion(bool inTaintTime) |
@@ -245,10 +404,13 @@ public sealed class BSCharacter : BSPhysObject | |||
245 | 404 | ||
246 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() | 405 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() |
247 | { | 406 | { |
248 | BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 407 | if (PhysBody.HasPhysicalBody) |
249 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 408 | { |
250 | // The next also get rid of applied linear force but the linear velocity is untouched. | 409 | PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero); |
251 | BulletSimAPI.ClearForces2(PhysBody.ptr); | 410 | PhysicsScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero); |
411 | // The next also get rid of applied linear force but the linear velocity is untouched. | ||
412 | PhysicsScene.PE.ClearForces(PhysBody); | ||
413 | } | ||
252 | }); | 414 | }); |
253 | } | 415 | } |
254 | 416 | ||
@@ -263,29 +425,31 @@ public sealed class BSCharacter : BSPhysObject | |||
263 | public override OMV.Vector3 Position { | 425 | public override OMV.Vector3 Position { |
264 | get { | 426 | get { |
265 | // Don't refetch the position because this function is called a zillion times | 427 | // Don't refetch the position because this function is called a zillion times |
266 | // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); | 428 | // _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID); |
267 | return _position; | 429 | return _position; |
268 | } | 430 | } |
269 | set { | 431 | set { |
270 | _position = value; | 432 | _position = value; |
271 | PositionSanityCheck(); | ||
272 | 433 | ||
273 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() | 434 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() |
274 | { | 435 | { |
275 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 436 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
276 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 437 | ForcePosition = _position; |
277 | }); | 438 | }); |
278 | } | 439 | } |
279 | } | 440 | } |
280 | public override OMV.Vector3 ForcePosition { | 441 | public override OMV.Vector3 ForcePosition { |
281 | get { | 442 | get { |
282 | _position = BulletSimAPI.GetPosition2(PhysBody.ptr); | 443 | _position = PhysicsScene.PE.GetPosition(PhysBody); |
283 | return _position; | 444 | return _position; |
284 | } | 445 | } |
285 | set { | 446 | set { |
286 | _position = value; | 447 | _position = value; |
287 | PositionSanityCheck(); | 448 | if (PhysBody.HasPhysicalBody) |
288 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 449 | { |
450 | PositionSanityCheck(); | ||
451 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | ||
452 | } | ||
289 | } | 453 | } |
290 | } | 454 | } |
291 | 455 | ||
@@ -297,8 +461,17 @@ public sealed class BSCharacter : BSPhysObject | |||
297 | { | 461 | { |
298 | bool ret = false; | 462 | bool ret = false; |
299 | 463 | ||
464 | // TODO: check for out of bounds | ||
465 | if (!PhysicsScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) | ||
466 | { | ||
467 | // The character is out of the known/simulated area. | ||
468 | // Upper levels of code will handle the transition to other areas so, for | ||
469 | // the time, we just ignore the position. | ||
470 | return ret; | ||
471 | } | ||
472 | |||
300 | // If below the ground, move the avatar up | 473 | // If below the ground, move the avatar up |
301 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); | 474 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); |
302 | if (Position.Z < terrainHeight) | 475 | if (Position.Z < terrainHeight) |
303 | { | 476 | { |
304 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 477 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); |
@@ -307,7 +480,7 @@ public sealed class BSCharacter : BSPhysObject | |||
307 | } | 480 | } |
308 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | 481 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) |
309 | { | 482 | { |
310 | float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position); | 483 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); |
311 | if (Position.Z < waterHeight) | 484 | if (Position.Z < waterHeight) |
312 | { | 485 | { |
313 | _position.Z = waterHeight; | 486 | _position.Z = waterHeight; |
@@ -315,7 +488,6 @@ public sealed class BSCharacter : BSPhysObject | |||
315 | } | 488 | } |
316 | } | 489 | } |
317 | 490 | ||
318 | // TODO: check for out of bounds | ||
319 | return ret; | 491 | return ret; |
320 | } | 492 | } |
321 | 493 | ||
@@ -332,7 +504,8 @@ public sealed class BSCharacter : BSPhysObject | |||
332 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() | 504 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() |
333 | { | 505 | { |
334 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 506 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
335 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 507 | if (PhysBody.HasPhysicalBody) |
508 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | ||
336 | }); | 509 | }); |
337 | ret = true; | 510 | ret = true; |
338 | } | 511 | } |
@@ -345,10 +518,10 @@ public sealed class BSCharacter : BSPhysObject | |||
345 | public override float RawMass { | 518 | public override float RawMass { |
346 | get {return _mass; } | 519 | get {return _mass; } |
347 | } | 520 | } |
348 | public override void UpdatePhysicalMassProperties(float physMass) | 521 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
349 | { | 522 | { |
350 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 523 | OMV.Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); |
351 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); | 524 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, localInertia); |
352 | } | 525 | } |
353 | 526 | ||
354 | public override OMV.Vector3 Force { | 527 | public override OMV.Vector3 Force { |
@@ -359,7 +532,8 @@ public sealed class BSCharacter : BSPhysObject | |||
359 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() | 532 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() |
360 | { | 533 | { |
361 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); | 534 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); |
362 | BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); | 535 | if (PhysBody.HasPhysicalBody) |
536 | PhysicsScene.PE.SetObjectForce(PhysBody, _force); | ||
363 | }); | 537 | }); |
364 | } | 538 | } |
365 | } | 539 | } |
@@ -376,6 +550,36 @@ public sealed class BSCharacter : BSPhysObject | |||
376 | 550 | ||
377 | public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } | 551 | public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } |
378 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } | 552 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } |
553 | |||
554 | // Sets the target in the motor. This starts the changing of the avatar's velocity. | ||
555 | public override OMV.Vector3 TargetVelocity | ||
556 | { | ||
557 | get | ||
558 | { | ||
559 | return _velocityMotor.TargetValue; | ||
560 | } | ||
561 | set | ||
562 | { | ||
563 | DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); | ||
564 | OMV.Vector3 targetVel = value; | ||
565 | if (_setAlwaysRun) | ||
566 | targetVel *= BSParam.AvatarAlwaysRunFactor; | ||
567 | |||
568 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() | ||
569 | { | ||
570 | _velocityMotor.Reset(); | ||
571 | _velocityMotor.SetTarget(targetVel); | ||
572 | _velocityMotor.SetCurrent(_velocity); | ||
573 | _velocityMotor.Enabled = true; | ||
574 | }); | ||
575 | } | ||
576 | } | ||
577 | public override OMV.Vector3 RawVelocity | ||
578 | { | ||
579 | get { return _velocity; } | ||
580 | set { _velocity = value; } | ||
581 | } | ||
582 | // Directly setting velocity means this is what the user really wants now. | ||
379 | public override OMV.Vector3 Velocity { | 583 | public override OMV.Vector3 Velocity { |
380 | get { return _velocity; } | 584 | get { return _velocity; } |
381 | set { | 585 | set { |
@@ -383,6 +587,12 @@ public sealed class BSCharacter : BSPhysObject | |||
383 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 587 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
384 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() | 588 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() |
385 | { | 589 | { |
590 | _velocityMotor.Reset(); | ||
591 | _velocityMotor.SetCurrent(_velocity); | ||
592 | _velocityMotor.SetTarget(_velocity); | ||
593 | // Even though the motor is initialized, it's not used and the velocity goes straight into the avatar. | ||
594 | _velocityMotor.Enabled = false; | ||
595 | |||
386 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 596 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
387 | ForceVelocity = _velocity; | 597 | ForceVelocity = _velocity; |
388 | }); | 598 | }); |
@@ -391,30 +601,11 @@ public sealed class BSCharacter : BSPhysObject | |||
391 | public override OMV.Vector3 ForceVelocity { | 601 | public override OMV.Vector3 ForceVelocity { |
392 | get { return _velocity; } | 602 | get { return _velocity; } |
393 | set { | 603 | set { |
394 | // Depending on whether the avatar is moving or not, change the friction | 604 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); |
395 | // to keep the avatar from slipping around | ||
396 | if (_velocity.Length() == 0) | ||
397 | { | ||
398 | if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) | ||
399 | { | ||
400 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | ||
401 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); | ||
402 | } | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | if (_currentFriction != PhysicsScene.Params.avatarFriction) | ||
407 | { | ||
408 | _currentFriction = PhysicsScene.Params.avatarFriction; | ||
409 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); | ||
410 | } | ||
411 | } | ||
412 | _velocity = value; | ||
413 | // Remember the set velocity so we can suppress the reduction by friction, ... | ||
414 | _appliedVelocity = value; | ||
415 | 605 | ||
416 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | 606 | _velocity = value; |
417 | BulletSimAPI.Activate2(PhysBody.ptr, true); | 607 | PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); |
608 | PhysicsScene.PE.Activate(PhysBody, true); | ||
418 | } | 609 | } |
419 | } | 610 | } |
420 | public override OMV.Vector3 Torque { | 611 | public override OMV.Vector3 Torque { |
@@ -439,13 +630,16 @@ public sealed class BSCharacter : BSPhysObject | |||
439 | public override OMV.Quaternion Orientation { | 630 | public override OMV.Quaternion Orientation { |
440 | get { return _orientation; } | 631 | get { return _orientation; } |
441 | set { | 632 | set { |
442 | _orientation = value; | 633 | // Orientation is set zillions of times when an avatar is walking. It's like |
443 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); | 634 | // the viewer doesn't trust us. |
444 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() | 635 | if (_orientation != value) |
445 | { | 636 | { |
446 | // _position = BulletSimAPI.GetPosition2(BSBody.ptr); | 637 | _orientation = value; |
447 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 638 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() |
448 | }); | 639 | { |
640 | ForceOrientation = _orientation; | ||
641 | }); | ||
642 | } | ||
449 | } | 643 | } |
450 | } | 644 | } |
451 | // Go directly to Bullet to get/set the value. | 645 | // Go directly to Bullet to get/set the value. |
@@ -453,13 +647,17 @@ public sealed class BSCharacter : BSPhysObject | |||
453 | { | 647 | { |
454 | get | 648 | get |
455 | { | 649 | { |
456 | _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); | 650 | _orientation = PhysicsScene.PE.GetOrientation(PhysBody); |
457 | return _orientation; | 651 | return _orientation; |
458 | } | 652 | } |
459 | set | 653 | set |
460 | { | 654 | { |
461 | _orientation = value; | 655 | _orientation = value; |
462 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 656 | if (PhysBody.HasPhysicalBody) |
657 | { | ||
658 | // _position = PhysicsScene.PE.GetPosition(BSBody); | ||
659 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | ||
660 | } | ||
463 | } | 661 | } |
464 | } | 662 | } |
465 | public override int PhysicsActorType { | 663 | public override int PhysicsActorType { |
@@ -478,10 +676,14 @@ public sealed class BSCharacter : BSPhysObject | |||
478 | public override bool IsStatic { | 676 | public override bool IsStatic { |
479 | get { return false; } | 677 | get { return false; } |
480 | } | 678 | } |
679 | public override bool IsPhysicallyActive { | ||
680 | get { return true; } | ||
681 | } | ||
481 | public override bool Flying { | 682 | public override bool Flying { |
482 | get { return _flying; } | 683 | get { return _flying; } |
483 | set { | 684 | set { |
484 | _flying = value; | 685 | _flying = value; |
686 | |||
485 | // simulate flying by changing the effect of gravity | 687 | // simulate flying by changing the effect of gravity |
486 | Buoyancy = ComputeBuoyancyFromFlying(_flying); | 688 | Buoyancy = ComputeBuoyancyFromFlying(_flying); |
487 | } | 689 | } |
@@ -500,27 +702,18 @@ public sealed class BSCharacter : BSPhysObject | |||
500 | get { return _throttleUpdates; } | 702 | get { return _throttleUpdates; } |
501 | set { _throttleUpdates = value; } | 703 | set { _throttleUpdates = value; } |
502 | } | 704 | } |
503 | public override bool IsColliding { | ||
504 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
505 | set { _isColliding = value; } | ||
506 | } | ||
507 | public override bool CollidingGround { | ||
508 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
509 | set { CollidingGround = value; } | ||
510 | } | ||
511 | public override bool CollidingObj { | ||
512 | get { return _collidingObj; } | ||
513 | set { _collidingObj = value; } | ||
514 | } | ||
515 | public override bool FloatOnWater { | 705 | public override bool FloatOnWater { |
516 | set { | 706 | set { |
517 | _floatOnWater = value; | 707 | _floatOnWater = value; |
518 | PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() | 708 | PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() |
519 | { | 709 | { |
520 | if (_floatOnWater) | 710 | if (PhysBody.HasPhysicalBody) |
521 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | 711 | { |
522 | else | 712 | if (_floatOnWater) |
523 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | 713 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
714 | else | ||
715 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); | ||
716 | } | ||
524 | }); | 717 | }); |
525 | } | 718 | } |
526 | } | 719 | } |
@@ -549,11 +742,15 @@ public sealed class BSCharacter : BSPhysObject | |||
549 | } | 742 | } |
550 | public override float ForceBuoyancy { | 743 | public override float ForceBuoyancy { |
551 | get { return _buoyancy; } | 744 | get { return _buoyancy; } |
552 | set { _buoyancy = value; | 745 | set { |
746 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceBuoyancy"); | ||
747 | |||
748 | _buoyancy = value; | ||
553 | DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 749 | DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
554 | // Buoyancy is faked by changing the gravity applied to the object | 750 | // Buoyancy is faked by changing the gravity applied to the object |
555 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 751 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); |
556 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | 752 | if (PhysBody.HasPhysicalBody) |
753 | PhysicsScene.PE.SetGravity(PhysBody, new OMV.Vector3(0f, 0f, grav)); | ||
557 | } | 754 | } |
558 | } | 755 | } |
559 | 756 | ||
@@ -589,24 +786,40 @@ public sealed class BSCharacter : BSPhysObject | |||
589 | public override float APIDStrength { set { return; } } | 786 | public override float APIDStrength { set { return; } } |
590 | public override float APIDDamping { set { return; } } | 787 | public override float APIDDamping { set { return; } } |
591 | 788 | ||
592 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 789 | public override void AddForce(OMV.Vector3 force, bool pushforce) |
790 | { | ||
791 | // Since this force is being applied in only one step, make this a force per second. | ||
792 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | ||
793 | AddForce(addForce, pushforce, false); | ||
794 | } | ||
795 | private void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | ||
593 | if (force.IsFinite()) | 796 | if (force.IsFinite()) |
594 | { | 797 | { |
595 | _force.X += force.X; | 798 | float magnitude = force.Length(); |
596 | _force.Y += force.Y; | 799 | if (magnitude > BSParam.MaxAddForceMagnitude) |
597 | _force.Z += force.Z; | ||
598 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | ||
599 | PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() | ||
600 | { | 800 | { |
601 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); | 801 | // Force has a limit |
602 | BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); | 802 | force = force / magnitude * BSParam.MaxAddForceMagnitude; |
803 | } | ||
804 | |||
805 | OMV.Vector3 addForce = force; | ||
806 | // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce); | ||
807 | |||
808 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate() | ||
809 | { | ||
810 | // Bullet adds this central force to the total force for this tick | ||
811 | // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); | ||
812 | if (PhysBody.HasPhysicalBody) | ||
813 | { | ||
814 | PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); | ||
815 | } | ||
603 | }); | 816 | }); |
604 | } | 817 | } |
605 | else | 818 | else |
606 | { | 819 | { |
607 | m_log.ErrorFormat("{0}: Got a NaN force applied to a Character", LogHeader); | 820 | m_log.WarnFormat("{0}: Got a NaN force applied to a character. LocalID={1}", LogHeader, LocalID); |
821 | return; | ||
608 | } | 822 | } |
609 | //m_lastUpdateSent = false; | ||
610 | } | 823 | } |
611 | 824 | ||
612 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 825 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
@@ -614,24 +827,31 @@ public sealed class BSCharacter : BSPhysObject | |||
614 | public override void SetMomentum(OMV.Vector3 momentum) { | 827 | public override void SetMomentum(OMV.Vector3 momentum) { |
615 | } | 828 | } |
616 | 829 | ||
617 | private void ComputeAvatarScale(OMV.Vector3 size) | 830 | private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size) |
618 | { | 831 | { |
619 | // The 'size' given by the simulator is the mid-point of the avatar | 832 | OMV.Vector3 newScale; |
620 | // and X and Y are unspecified. | 833 | |
621 | 834 | // Bullet's capsule total height is the "passed height + radius * 2"; | |
622 | OMV.Vector3 newScale = size; | 835 | // The base capsule is 1 diameter and 2 height (passed radius=0.5, passed height = 1) |
623 | // newScale.X = PhysicsScene.Params.avatarCapsuleWidth; | 836 | // The number we pass in for 'scaling' is the multiplier to get that base |
624 | // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth; | 837 | // shape to be the size desired. |
625 | 838 | // So, when creating the scale for the avatar height, we take the passed height | |
626 | // From the total height, remove the capsule half spheres that are at each end | 839 | // (size.Z) and remove the caps. |
627 | // The 1.15f came from ODE. Not sure what this factors in. | 840 | // Another oddity of the Bullet capsule implementation is that it presumes the Y |
628 | // newScale.Z = (size.Z * 1.15f) - (newScale.X + newScale.Y); | 841 | // dimension is the radius of the capsule. Even though some of the code allows |
842 | // for a asymmetrical capsule, other parts of the code presume it is cylindrical. | ||
843 | |||
844 | // Scale is multiplier of radius with one of "0.5" | ||
845 | newScale.X = size.X / 2f; | ||
846 | newScale.Y = size.Y / 2f; | ||
629 | 847 | ||
630 | // The total scale height is the central cylindar plus the caps on the two ends. | 848 | // The total scale height is the central cylindar plus the caps on the two ends. |
631 | newScale.Z = size.Z + (Math.Min(size.X, size.Y) * 2f); | 849 | newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2)) / 2f; |
850 | // If smaller than the endcaps, just fake like we're almost that small | ||
851 | if (newScale.Z < 0) | ||
852 | newScale.Z = 0.1f; | ||
632 | 853 | ||
633 | // Convert diameters to radii and height to half height -- the way Bullet expects it. | 854 | return newScale; |
634 | Scale = newScale / 2f; | ||
635 | } | 855 | } |
636 | 856 | ||
637 | // set _avatarVolume and _mass based on capsule size, _density and Scale | 857 | // set _avatarVolume and _mass based on capsule size, _density and Scale |
@@ -639,14 +859,14 @@ public sealed class BSCharacter : BSPhysObject | |||
639 | { | 859 | { |
640 | _avatarVolume = (float)( | 860 | _avatarVolume = (float)( |
641 | Math.PI | 861 | Math.PI |
642 | * Scale.X | 862 | * Size.X / 2f |
643 | * Scale.Y // the area of capsule cylinder | 863 | * Size.Y / 2f // the area of capsule cylinder |
644 | * Scale.Z // times height of capsule cylinder | 864 | * Size.Z // times height of capsule cylinder |
645 | + 1.33333333f | 865 | + 1.33333333f |
646 | * Math.PI | 866 | * Math.PI |
647 | * Scale.X | 867 | * Size.X / 2f |
648 | * Math.Min(Scale.X, Scale.Y) | 868 | * Math.Min(Size.X, Size.Y) / 2 |
649 | * Scale.Y // plus the volume of the capsule end caps | 869 | * Size.Y / 2f // plus the volume of the capsule end caps |
650 | ); | 870 | ); |
651 | _mass = _avatarDensity * _avatarVolume; | 871 | _mass = _avatarDensity * _avatarVolume; |
652 | } | 872 | } |
@@ -657,27 +877,29 @@ public sealed class BSCharacter : BSPhysObject | |||
657 | { | 877 | { |
658 | _position = entprop.Position; | 878 | _position = entprop.Position; |
659 | _orientation = entprop.Rotation; | 879 | _orientation = entprop.Rotation; |
660 | _velocity = entprop.Velocity; | 880 | |
881 | // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar | ||
882 | // and will send agent updates to the clients if velocity changes by more than | ||
883 | // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many | ||
884 | // extra updates. | ||
885 | if (!entprop.Velocity.ApproxEquals(_velocity, 0.1f)) | ||
886 | _velocity = entprop.Velocity; | ||
887 | |||
661 | _acceleration = entprop.Acceleration; | 888 | _acceleration = entprop.Acceleration; |
662 | _rotationalVelocity = entprop.RotationalVelocity; | 889 | _rotationalVelocity = entprop.RotationalVelocity; |
890 | |||
663 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 891 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
664 | PositionSanityCheck(true); | 892 | if (PositionSanityCheck(true)) |
893 | { | ||
894 | entprop.Position = _position; | ||
895 | } | ||
665 | 896 | ||
666 | // remember the current and last set values | 897 | // remember the current and last set values |
667 | LastEntityProperties = CurrentEntityProperties; | 898 | LastEntityProperties = CurrentEntityProperties; |
668 | CurrentEntityProperties = entprop; | 899 | CurrentEntityProperties = entprop; |
669 | 900 | ||
670 | if (entprop.Velocity != LastEntityProperties.Velocity) | ||
671 | { | ||
672 | // Changes in the velocity are suppressed in avatars. | ||
673 | // That's just the way they are defined. | ||
674 | OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z); | ||
675 | _velocity = avVel; | ||
676 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); | ||
677 | } | ||
678 | |||
679 | // Tell the linkset about value changes | 901 | // Tell the linkset about value changes |
680 | Linkset.UpdateProperties(this); | 902 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
681 | 903 | ||
682 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. | 904 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. |
683 | // base.RequestPhysicsterseUpdate(); | 905 | // base.RequestPhysicsterseUpdate(); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index 65fac00..b813974 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs | |||
@@ -36,7 +36,8 @@ public abstract class BSConstraint : IDisposable | |||
36 | { | 36 | { |
37 | private static string LogHeader = "[BULLETSIM CONSTRAINT]"; | 37 | private static string LogHeader = "[BULLETSIM CONSTRAINT]"; |
38 | 38 | ||
39 | protected BulletSim m_world; | 39 | protected BulletWorld m_world; |
40 | protected BSScene PhysicsScene; | ||
40 | protected BulletBody m_body1; | 41 | protected BulletBody m_body1; |
41 | protected BulletBody m_body2; | 42 | protected BulletBody m_body2; |
42 | protected BulletConstraint m_constraint; | 43 | protected BulletConstraint m_constraint; |
@@ -48,8 +49,10 @@ public abstract class BSConstraint : IDisposable | |||
48 | public abstract ConstraintType Type { get; } | 49 | public abstract ConstraintType Type { get; } |
49 | public bool IsEnabled { get { return m_enabled; } } | 50 | public bool IsEnabled { get { return m_enabled; } } |
50 | 51 | ||
51 | public BSConstraint() | 52 | public BSConstraint(BulletWorld world) |
52 | { | 53 | { |
54 | m_world = world; | ||
55 | PhysicsScene = m_world.physicsScene; | ||
53 | } | 56 | } |
54 | 57 | ||
55 | public virtual void Dispose() | 58 | public virtual void Dispose() |
@@ -57,15 +60,15 @@ public abstract class BSConstraint : IDisposable | |||
57 | if (m_enabled) | 60 | if (m_enabled) |
58 | { | 61 | { |
59 | m_enabled = false; | 62 | m_enabled = false; |
60 | if (m_constraint.ptr != IntPtr.Zero) | 63 | if (m_constraint.HasPhysicalConstraint) |
61 | { | 64 | { |
62 | bool success = BulletSimAPI.DestroyConstraint2(m_world.ptr, m_constraint.ptr); | 65 | bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint); |
63 | m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", | 66 | m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", |
64 | BSScene.DetailLogZero, | 67 | BSScene.DetailLogZero, |
65 | m_body1.ID, m_body1.ptr.ToString("X"), | 68 | m_body1.ID, m_body1.AddrString, |
66 | m_body2.ID, m_body2.ptr.ToString("X"), | 69 | m_body2.ID, m_body2.AddrString, |
67 | success); | 70 | success); |
68 | m_constraint.ptr = System.IntPtr.Zero; | 71 | m_constraint.Clear(); |
69 | } | 72 | } |
70 | } | 73 | } |
71 | } | 74 | } |
@@ -74,7 +77,7 @@ public abstract class BSConstraint : IDisposable | |||
74 | { | 77 | { |
75 | bool ret = false; | 78 | bool ret = false; |
76 | if (m_enabled) | 79 | if (m_enabled) |
77 | ret = BulletSimAPI.SetLinearLimits2(m_constraint.ptr, low, high); | 80 | ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high); |
78 | return ret; | 81 | return ret; |
79 | } | 82 | } |
80 | 83 | ||
@@ -82,7 +85,7 @@ public abstract class BSConstraint : IDisposable | |||
82 | { | 85 | { |
83 | bool ret = false; | 86 | bool ret = false; |
84 | if (m_enabled) | 87 | if (m_enabled) |
85 | ret = BulletSimAPI.SetAngularLimits2(m_constraint.ptr, low, high); | 88 | ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); |
86 | return ret; | 89 | return ret; |
87 | } | 90 | } |
88 | 91 | ||
@@ -91,7 +94,7 @@ public abstract class BSConstraint : IDisposable | |||
91 | bool ret = false; | 94 | bool ret = false; |
92 | if (m_enabled) | 95 | if (m_enabled) |
93 | { | 96 | { |
94 | BulletSimAPI.SetConstraintNumSolverIterations2(m_constraint.ptr, cnt); | 97 | PhysicsScene.PE.SetConstraintNumSolverIterations(m_constraint, cnt); |
95 | ret = true; | 98 | ret = true; |
96 | } | 99 | } |
97 | return ret; | 100 | return ret; |
@@ -103,7 +106,7 @@ public abstract class BSConstraint : IDisposable | |||
103 | if (m_enabled) | 106 | if (m_enabled) |
104 | { | 107 | { |
105 | // Recompute the internal transforms | 108 | // Recompute the internal transforms |
106 | BulletSimAPI.CalculateTransforms2(m_constraint.ptr); | 109 | PhysicsScene.PE.CalculateTransforms(m_constraint); |
107 | ret = true; | 110 | ret = true; |
108 | } | 111 | } |
109 | return ret; | 112 | return ret; |
@@ -122,7 +125,7 @@ public abstract class BSConstraint : IDisposable | |||
122 | // Setting an object's mass to zero (making it static like when it's selected) | 125 | // Setting an object's mass to zero (making it static like when it's selected) |
123 | // automatically disables the constraints. | 126 | // automatically disables the constraints. |
124 | // If the link is enabled, be sure to set the constraint itself to enabled. | 127 | // If the link is enabled, be sure to set the constraint itself to enabled. |
125 | BulletSimAPI.SetConstraintEnable2(m_constraint.ptr, m_world.physicsScene.NumericBool(true)); | 128 | PhysicsScene.PE.SetConstraintEnable(m_constraint, BSParam.NumericBool(true)); |
126 | } | 129 | } |
127 | else | 130 | else |
128 | { | 131 | { |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index 23ef052..ecb1b32 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs | |||
@@ -39,51 +39,49 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } | 39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } |
40 | 40 | ||
41 | // Create a btGeneric6DofConstraint | 41 | // Create a btGeneric6DofConstraint |
42 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | 42 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, |
43 | Vector3 frame1, Quaternion frame1rot, | 43 | Vector3 frame1, Quaternion frame1rot, |
44 | Vector3 frame2, Quaternion frame2rot, | 44 | Vector3 frame2, Quaternion frame2rot, |
45 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 45 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
46 | : base(world) | ||
46 | { | 47 | { |
47 | m_world = world; | ||
48 | m_body1 = obj1; | 48 | m_body1 = obj1; |
49 | m_body2 = obj2; | 49 | m_body2 = obj2; |
50 | m_constraint = new BulletConstraint( | 50 | m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2, |
51 | BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, | ||
52 | frame1, frame1rot, | 51 | frame1, frame1rot, |
53 | frame2, frame2rot, | 52 | frame2, frame2rot, |
54 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | 53 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
55 | m_enabled = true; | 54 | m_enabled = true; |
56 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | 55 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", |
57 | BSScene.DetailLogZero, world.worldID, | 56 | BSScene.DetailLogZero, world.worldID, |
58 | obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); | 57 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
59 | } | 58 | } |
60 | 59 | ||
61 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | 60 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, |
62 | Vector3 joinPoint, | 61 | Vector3 joinPoint, |
63 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 62 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
63 | : base(world) | ||
64 | { | 64 | { |
65 | m_world = world; | ||
66 | m_body1 = obj1; | 65 | m_body1 = obj1; |
67 | m_body2 = obj2; | 66 | m_body2 = obj2; |
68 | if (obj1.ptr == IntPtr.Zero || obj2.ptr == IntPtr.Zero) | 67 | if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody) |
69 | { | 68 | { |
70 | world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | 69 | world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", |
71 | BSScene.DetailLogZero, world.worldID, | 70 | BSScene.DetailLogZero, world.worldID, |
72 | obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); | 71 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
73 | world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | 72 | world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", |
74 | LogHeader, world.worldID, obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); | 73 | LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
75 | m_enabled = false; | 74 | m_enabled = false; |
76 | } | 75 | } |
77 | else | 76 | else |
78 | { | 77 | { |
79 | m_constraint = new BulletConstraint( | 78 | m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2, |
80 | BulletSimAPI.Create6DofConstraintToPoint2(m_world.ptr, m_body1.ptr, m_body2.ptr, | ||
81 | joinPoint, | 79 | joinPoint, |
82 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | 80 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
83 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", | 81 | PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", |
84 | BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"), | 82 | BSScene.DetailLogZero, world.worldID, m_constraint.AddrString, |
85 | obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); | 83 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
86 | if (m_constraint.ptr == IntPtr.Zero) | 84 | if (!m_constraint.HasPhysicalConstraint) |
87 | { | 85 | { |
88 | world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", | 86 | world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", |
89 | LogHeader, obj1.ID, obj2.ID); | 87 | LogHeader, obj1.ID, obj2.ID); |
@@ -101,7 +99,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
101 | bool ret = false; | 99 | bool ret = false; |
102 | if (m_enabled) | 100 | if (m_enabled) |
103 | { | 101 | { |
104 | BulletSimAPI.SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); | 102 | PhysicsScene.PE.SetFrames(m_constraint, frameA, frameArot, frameB, frameBrot); |
105 | ret = true; | 103 | ret = true; |
106 | } | 104 | } |
107 | return ret; | 105 | return ret; |
@@ -112,9 +110,9 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
112 | bool ret = false; | 110 | bool ret = false; |
113 | if (m_enabled) | 111 | if (m_enabled) |
114 | { | 112 | { |
115 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); | 113 | PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); |
116 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); | 114 | PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); |
117 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); | 115 | PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); |
118 | ret = true; | 116 | ret = true; |
119 | } | 117 | } |
120 | return ret; | 118 | return ret; |
@@ -125,7 +123,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
125 | bool ret = false; | 123 | bool ret = false; |
126 | float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; | 124 | float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; |
127 | if (m_enabled) | 125 | if (m_enabled) |
128 | ret = BulletSimAPI.UseFrameOffset2(m_constraint.ptr, onOff); | 126 | ret = PhysicsScene.PE.UseFrameOffset(m_constraint, onOff); |
129 | return ret; | 127 | return ret; |
130 | } | 128 | } |
131 | 129 | ||
@@ -135,7 +133,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
135 | float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; | 133 | float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; |
136 | if (m_enabled) | 134 | if (m_enabled) |
137 | { | 135 | { |
138 | ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.ptr, onOff, targetVelocity, maxMotorForce); | 136 | ret = PhysicsScene.PE.TranslationalLimitMotor(m_constraint, onOff, targetVelocity, maxMotorForce); |
139 | m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}", | 137 | m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}", |
140 | BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce); | 138 | BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce); |
141 | } | 139 | } |
@@ -146,7 +144,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
146 | { | 144 | { |
147 | bool ret = false; | 145 | bool ret = false; |
148 | if (m_enabled) | 146 | if (m_enabled) |
149 | ret = BulletSimAPI.SetBreakingImpulseThreshold2(m_constraint.ptr, threshold); | 147 | ret = PhysicsScene.PE.SetBreakingImpulseThreshold(m_constraint, threshold); |
150 | return ret; | 148 | return ret; |
151 | } | 149 | } |
152 | } | 150 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs index a9fd826..2aeff25 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | |||
@@ -41,9 +41,9 @@ public sealed class BSConstraintCollection : IDisposable | |||
41 | delegate bool ConstraintAction(BSConstraint constrain); | 41 | delegate bool ConstraintAction(BSConstraint constrain); |
42 | 42 | ||
43 | private List<BSConstraint> m_constraints; | 43 | private List<BSConstraint> m_constraints; |
44 | private BulletSim m_world; | 44 | private BulletWorld m_world; |
45 | 45 | ||
46 | public BSConstraintCollection(BulletSim world) | 46 | public BSConstraintCollection(BulletWorld world) |
47 | { | 47 | { |
48 | m_world = world; | 48 | m_world = world; |
49 | m_constraints = new List<BSConstraint>(); | 49 | m_constraints = new List<BSConstraint>(); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs index ed3ffa7..7714a03 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs | |||
@@ -36,19 +36,17 @@ public sealed class BSConstraintHinge : BSConstraint | |||
36 | { | 36 | { |
37 | public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } } | 37 | public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } } |
38 | 38 | ||
39 | public BSConstraintHinge(BulletSim world, BulletBody obj1, BulletBody obj2, | 39 | public BSConstraintHinge(BulletWorld world, BulletBody obj1, BulletBody obj2, |
40 | Vector3 pivotInA, Vector3 pivotInB, | 40 | Vector3 pivotInA, Vector3 pivotInB, |
41 | Vector3 axisInA, Vector3 axisInB, | 41 | Vector3 axisInA, Vector3 axisInB, |
42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
43 | : base(world) | ||
43 | { | 44 | { |
44 | m_world = world; | ||
45 | m_body1 = obj1; | 45 | m_body1 = obj1; |
46 | m_body2 = obj2; | 46 | m_body2 = obj2; |
47 | m_constraint = new BulletConstraint( | 47 | m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2, |
48 | BulletSimAPI.CreateHingeConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, | 48 | pivotInA, pivotInB, axisInA, axisInB, |
49 | pivotInA, pivotInB, | 49 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
50 | axisInA, axisInB, | ||
51 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
52 | m_enabled = true; | 50 | m_enabled = true; |
53 | } | 51 | } |
54 | 52 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index dbc9039..dbe44de 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -24,28 +24,16 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | 27 | * The quotations from http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial | |
28 | /* RA: June 14, 2011. Copied from ODEDynamics.cs and converted to | 28 | * are Copyright (c) 2009 Linden Research, Inc and are used under their license |
29 | * call the BulletSim system. | 29 | * of Creative Commons Attribution-Share Alike 3.0 |
30 | */ | 30 | * (http://creativecommons.org/licenses/by-sa/3.0/). |
31 | /* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces | ||
32 | * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised: | ||
33 | * ODEPrim.cs contains methods dealing with Prim editing, Prim | ||
34 | * characteristics and Kinetic motion. | ||
35 | * ODEDynamics.cs contains methods dealing with Prim Physical motion | ||
36 | * (dynamics) and the associated settings. Old Linear and angular | ||
37 | * motors for dynamic motion have been replace with MoveLinear() | ||
38 | * and MoveAngular(); 'Physical' is used only to switch ODE dynamic | ||
39 | * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to | ||
40 | * switch between 'VEHICLE' parameter use and general dynamics | ||
41 | * settings use. | ||
42 | */ | 31 | */ |
43 | 32 | ||
44 | using System; | 33 | using System; |
45 | using System.Collections.Generic; | 34 | using System.Collections.Generic; |
46 | using System.Reflection; | 35 | using System.Reflection; |
47 | using System.Runtime.InteropServices; | 36 | using System.Runtime.InteropServices; |
48 | using log4net; | ||
49 | using OpenMetaverse; | 37 | using OpenMetaverse; |
50 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
51 | using OpenSim.Region.Physics.Manager; | 39 | using OpenSim.Region.Physics.Manager; |
@@ -80,10 +68,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
80 | private Quaternion m_referenceFrame = Quaternion.Identity; | 68 | private Quaternion m_referenceFrame = Quaternion.Identity; |
81 | 69 | ||
82 | // Linear properties | 70 | // Linear properties |
71 | private BSVMotor m_linearMotor = new BSVMotor("LinearMotor"); | ||
83 | private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time | 72 | private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time |
84 | private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center | 73 | private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center |
85 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL | 74 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL |
86 | private Vector3 m_newVelocity = Vector3.Zero; // velocity computed to be applied to body | ||
87 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; | 75 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; |
88 | private float m_linearMotorDecayTimescale = 0; | 76 | private float m_linearMotorDecayTimescale = 0; |
89 | private float m_linearMotorTimescale = 0; | 77 | private float m_linearMotorTimescale = 0; |
@@ -93,16 +81,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
93 | // private Vector3 m_linearMotorOffset = Vector3.Zero; | 81 | // private Vector3 m_linearMotorOffset = Vector3.Zero; |
94 | 82 | ||
95 | //Angular properties | 83 | //Angular properties |
84 | private BSVMotor m_angularMotor = new BSVMotor("AngularMotor"); | ||
96 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor | 85 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor |
97 | // private int m_angularMotorApply = 0; // application frame counter | 86 | // private int m_angularMotorApply = 0; // application frame counter |
98 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity | 87 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity |
99 | private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate | 88 | private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate |
100 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate | 89 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate |
101 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate | 90 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate |
102 | private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body | 91 | private Vector3 m_lastAngularVelocity = Vector3.Zero; |
103 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body | 92 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body |
104 | 93 | ||
105 | //Deflection properties | 94 | //Deflection properties |
95 | private BSVMotor m_angularDeflectionMotor = new BSVMotor("AngularDeflection"); | ||
106 | private float m_angularDeflectionEfficiency = 0; | 96 | private float m_angularDeflectionEfficiency = 0; |
107 | private float m_angularDeflectionTimescale = 0; | 97 | private float m_angularDeflectionTimescale = 0; |
108 | private float m_linearDeflectionEfficiency = 0; | 98 | private float m_linearDeflectionEfficiency = 0; |
@@ -114,32 +104,61 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
114 | private float m_bankingTimescale = 0; | 104 | private float m_bankingTimescale = 0; |
115 | 105 | ||
116 | //Hover and Buoyancy properties | 106 | //Hover and Buoyancy properties |
107 | private BSVMotor m_hoverMotor = new BSVMotor("Hover"); | ||
117 | private float m_VhoverHeight = 0f; | 108 | private float m_VhoverHeight = 0f; |
118 | private float m_VhoverEfficiency = 0f; | 109 | private float m_VhoverEfficiency = 0f; |
119 | private float m_VhoverTimescale = 0f; | 110 | private float m_VhoverTimescale = 0f; |
120 | private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height | 111 | private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height |
121 | private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle. | 112 | // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity) |
122 | // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity) | 113 | private float m_VehicleBuoyancy = 0f; |
123 | // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity. | 114 | private Vector3 m_VehicleGravity = Vector3.Zero; // Gravity computed when buoyancy set |
124 | // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity. | ||
125 | 115 | ||
126 | //Attractor properties | 116 | //Attractor properties |
127 | private float m_verticalAttractionEfficiency = 1.0f; // damped | 117 | private BSVMotor m_verticalAttractionMotor = new BSVMotor("VerticalAttraction"); |
128 | private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor. | 118 | private float m_verticalAttractionEfficiency = 1.0f; // damped |
119 | private float m_verticalAttractionCutoff = 500f; // per the documentation | ||
120 | // Timescale > cutoff means no vert attractor. | ||
121 | private float m_verticalAttractionTimescale = 510f; | ||
122 | |||
123 | // Just some recomputed constants: | ||
124 | static readonly float PIOverFour = ((float)Math.PI) / 4f; | ||
125 | static readonly float PIOverTwo = ((float)Math.PI) / 2f; | ||
126 | |||
127 | // For debugging, flags to turn on and off individual corrections. | ||
128 | private bool enableAngularVerticalAttraction; | ||
129 | private bool enableAngularDeflection; | ||
130 | private bool enableAngularBanking; | ||
129 | 131 | ||
130 | public BSDynamics(BSScene myScene, BSPrim myPrim) | 132 | public BSDynamics(BSScene myScene, BSPrim myPrim) |
131 | { | 133 | { |
132 | PhysicsScene = myScene; | 134 | PhysicsScene = myScene; |
133 | Prim = myPrim; | 135 | Prim = myPrim; |
134 | Type = Vehicle.TYPE_NONE; | 136 | Type = Vehicle.TYPE_NONE; |
137 | SetupVehicleDebugging(); | ||
138 | } | ||
139 | |||
140 | // Stopgap debugging enablement. Allows source level debugging but still checking | ||
141 | // in changes by making enablement of debugging flags from INI file. | ||
142 | public void SetupVehicleDebugging() | ||
143 | { | ||
144 | enableAngularVerticalAttraction = true; | ||
145 | enableAngularDeflection = false; | ||
146 | enableAngularBanking = false; | ||
147 | if (BSParam.VehicleDebuggingEnabled != ConfigurationParameters.numericFalse) | ||
148 | { | ||
149 | enableAngularVerticalAttraction = false; | ||
150 | enableAngularDeflection = false; | ||
151 | enableAngularBanking = false; | ||
152 | } | ||
135 | } | 153 | } |
136 | 154 | ||
137 | // Return 'true' if this vehicle is doing vehicle things | 155 | // Return 'true' if this vehicle is doing vehicle things |
138 | public bool IsActive | 156 | public bool IsActive |
139 | { | 157 | { |
140 | get { return Type != Vehicle.TYPE_NONE; } | 158 | get { return (Type != Vehicle.TYPE_NONE && Prim.IsPhysicallyActive); } |
141 | } | 159 | } |
142 | 160 | ||
161 | #region Vehicle parameter setting | ||
143 | internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) | 162 | internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) |
144 | { | 163 | { |
145 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); | 164 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); |
@@ -152,13 +171,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
152 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); | 171 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); |
153 | break; | 172 | break; |
154 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: | 173 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: |
155 | m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f); | 174 | m_angularMotorDecayTimescale = ClampInRange(0.01f, pValue, 120); |
175 | m_angularMotor.TargetValueDecayTimeScale = m_angularMotorDecayTimescale; | ||
156 | break; | 176 | break; |
157 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: | 177 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: |
158 | m_angularMotorTimescale = Math.Max(pValue, 0.01f); | 178 | m_angularMotorTimescale = Math.Max(pValue, 0.01f); |
179 | m_angularMotor.TimeScale = m_angularMotorTimescale; | ||
159 | break; | 180 | break; |
160 | case Vehicle.BANKING_EFFICIENCY: | 181 | case Vehicle.BANKING_EFFICIENCY: |
161 | m_bankingEfficiency = Math.Max(-1f, Math.Min(pValue, 1f)); | 182 | m_bankingEfficiency = ClampInRange(-1f, pValue, 1f); |
162 | break; | 183 | break; |
163 | case Vehicle.BANKING_MIX: | 184 | case Vehicle.BANKING_MIX: |
164 | m_bankingMix = Math.Max(pValue, 0.01f); | 185 | m_bankingMix = Math.Max(pValue, 0.01f); |
@@ -167,10 +188,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
167 | m_bankingTimescale = Math.Max(pValue, 0.01f); | 188 | m_bankingTimescale = Math.Max(pValue, 0.01f); |
168 | break; | 189 | break; |
169 | case Vehicle.BUOYANCY: | 190 | case Vehicle.BUOYANCY: |
170 | m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f)); | 191 | m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); |
192 | m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); | ||
171 | break; | 193 | break; |
172 | case Vehicle.HOVER_EFFICIENCY: | 194 | case Vehicle.HOVER_EFFICIENCY: |
173 | m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f)); | 195 | m_VhoverEfficiency = ClampInRange(0f, pValue, 1f); |
174 | break; | 196 | break; |
175 | case Vehicle.HOVER_HEIGHT: | 197 | case Vehicle.HOVER_HEIGHT: |
176 | m_VhoverHeight = pValue; | 198 | m_VhoverHeight = pValue; |
@@ -185,33 +207,41 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
185 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); | 207 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); |
186 | break; | 208 | break; |
187 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: | 209 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: |
188 | m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f); | 210 | m_linearMotorDecayTimescale = ClampInRange(0.01f, pValue, 120); |
211 | m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale; | ||
189 | break; | 212 | break; |
190 | case Vehicle.LINEAR_MOTOR_TIMESCALE: | 213 | case Vehicle.LINEAR_MOTOR_TIMESCALE: |
191 | m_linearMotorTimescale = Math.Max(pValue, 0.01f); | 214 | m_linearMotorTimescale = Math.Max(pValue, 0.01f); |
215 | m_linearMotor.TimeScale = m_linearMotorTimescale; | ||
192 | break; | 216 | break; |
193 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: | 217 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: |
194 | m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f)); | 218 | m_verticalAttractionEfficiency = ClampInRange(0.1f, pValue, 1f); |
219 | m_verticalAttractionMotor.Efficiency = m_verticalAttractionEfficiency; | ||
195 | break; | 220 | break; |
196 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: | 221 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: |
197 | m_verticalAttractionTimescale = Math.Max(pValue, 0.01f); | 222 | m_verticalAttractionTimescale = Math.Max(pValue, 0.01f); |
223 | m_verticalAttractionMotor.TimeScale = m_verticalAttractionTimescale; | ||
198 | break; | 224 | break; |
199 | 225 | ||
200 | // These are vector properties but the engine lets you use a single float value to | 226 | // These are vector properties but the engine lets you use a single float value to |
201 | // set all of the components to the same value | 227 | // set all of the components to the same value |
202 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 228 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
203 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); | 229 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); |
230 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
204 | break; | 231 | break; |
205 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 232 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
206 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 233 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
207 | // m_angularMotorApply = 100; | 234 | m_angularMotor.Zero(); |
235 | m_angularMotor.SetTarget(m_angularMotorDirection); | ||
208 | break; | 236 | break; |
209 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 237 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
210 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 238 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); |
239 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
211 | break; | 240 | break; |
212 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 241 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
213 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 242 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); |
214 | m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); | 243 | m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); |
244 | m_linearMotor.SetTarget(m_linearMotorDirection); | ||
215 | break; | 245 | break; |
216 | case Vehicle.LINEAR_MOTOR_OFFSET: | 246 | case Vehicle.LINEAR_MOTOR_OFFSET: |
217 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); | 247 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); |
@@ -227,21 +257,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
227 | { | 257 | { |
228 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 258 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
229 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 259 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
260 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
230 | break; | 261 | break; |
231 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 262 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
232 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 263 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
233 | pValue.X = Math.Max(-12.56f, Math.Min(pValue.X, 12.56f)); | 264 | pValue.X = ClampInRange(-12.56f, pValue.X, 12.56f); |
234 | pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f)); | 265 | pValue.Y = ClampInRange(-12.56f, pValue.Y, 12.56f); |
235 | pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f)); | 266 | pValue.Z = ClampInRange(-12.56f, pValue.Z, 12.56f); |
236 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 267 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
237 | // m_angularMotorApply = 100; | 268 | m_angularMotor.Zero(); |
269 | m_angularMotor.SetTarget(m_angularMotorDirection); | ||
238 | break; | 270 | break; |
239 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 271 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
240 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 272 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
273 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
241 | break; | 274 | break; |
242 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 275 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
243 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 276 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
244 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); | 277 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); |
278 | m_linearMotor.SetTarget(m_linearMotorDirection); | ||
245 | break; | 279 | break; |
246 | case Vehicle.LINEAR_MOTOR_OFFSET: | 280 | case Vehicle.LINEAR_MOTOR_OFFSET: |
247 | m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); | 281 | m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -303,7 +337,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
303 | m_VhoverEfficiency = 0; | 337 | m_VhoverEfficiency = 0; |
304 | m_VhoverTimescale = 0; | 338 | m_VhoverTimescale = 0; |
305 | m_VehicleBuoyancy = 0; | 339 | m_VehicleBuoyancy = 0; |
306 | 340 | ||
307 | m_linearDeflectionEfficiency = 1; | 341 | m_linearDeflectionEfficiency = 1; |
308 | m_linearDeflectionTimescale = 1; | 342 | m_linearDeflectionTimescale = 1; |
309 | 343 | ||
@@ -319,6 +353,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
319 | 353 | ||
320 | m_referenceFrame = Quaternion.Identity; | 354 | m_referenceFrame = Quaternion.Identity; |
321 | m_flags = (VehicleFlag)0; | 355 | m_flags = (VehicleFlag)0; |
356 | |||
322 | break; | 357 | break; |
323 | 358 | ||
324 | case Vehicle.TYPE_SLED: | 359 | case Vehicle.TYPE_SLED: |
@@ -351,10 +386,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
351 | m_bankingMix = 1; | 386 | m_bankingMix = 1; |
352 | 387 | ||
353 | m_referenceFrame = Quaternion.Identity; | 388 | m_referenceFrame = Quaternion.Identity; |
354 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP); | 389 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
355 | m_flags &= | 390 | | VehicleFlag.HOVER_TERRAIN_ONLY |
356 | ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 391 | | VehicleFlag.HOVER_GLOBAL_HEIGHT |
357 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 392 | | VehicleFlag.HOVER_UP_ONLY); |
393 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | ||
394 | | VehicleFlag.LIMIT_ROLL_ONLY | ||
395 | | VehicleFlag.LIMIT_MOTOR_UP); | ||
396 | |||
358 | break; | 397 | break; |
359 | case Vehicle.TYPE_CAR: | 398 | case Vehicle.TYPE_CAR: |
360 | m_linearMotorDirection = Vector3.Zero; | 399 | m_linearMotorDirection = Vector3.Zero; |
@@ -498,6 +537,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
498 | m_bankingEfficiency = 0; | 537 | m_bankingEfficiency = 0; |
499 | m_bankingMix = 0.7f; | 538 | m_bankingMix = 0.7f; |
500 | m_bankingTimescale = 5; | 539 | m_bankingTimescale = 5; |
540 | |||
501 | m_referenceFrame = Quaternion.Identity; | 541 | m_referenceFrame = Quaternion.Identity; |
502 | 542 | ||
503 | m_referenceFrame = Quaternion.Identity; | 543 | m_referenceFrame = Quaternion.Identity; |
@@ -510,7 +550,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
510 | | VehicleFlag.HOVER_GLOBAL_HEIGHT); | 550 | | VehicleFlag.HOVER_GLOBAL_HEIGHT); |
511 | break; | 551 | break; |
512 | } | 552 | } |
553 | |||
554 | // Update any physical parameters based on this type. | ||
555 | Refresh(); | ||
556 | |||
557 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, | ||
558 | m_linearMotorDecayTimescale, m_linearFrictionTimescale, | ||
559 | 1f); | ||
560 | m_linearMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | ||
561 | |||
562 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, | ||
563 | m_angularMotorDecayTimescale, m_angularFrictionTimescale, | ||
564 | 1f); | ||
565 | m_angularMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | ||
566 | |||
567 | /* Not implemented | ||
568 | m_verticalAttractionMotor = new BSVMotor("VerticalAttraction", m_verticalAttractionTimescale, | ||
569 | BSMotor.Infinite, BSMotor.InfiniteVector, | ||
570 | m_verticalAttractionEfficiency); | ||
571 | // Z goes away and we keep X and Y | ||
572 | m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); | ||
573 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | ||
574 | */ | ||
513 | } | 575 | } |
576 | #endregion // Vehicle parameter setting | ||
514 | 577 | ||
515 | // Some of the properties of this prim may have changed. | 578 | // Some of the properties of this prim may have changed. |
516 | // Do any updating needed for a vehicle | 579 | // Do any updating needed for a vehicle |
@@ -518,13 +581,38 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
518 | { | 581 | { |
519 | if (IsActive) | 582 | if (IsActive) |
520 | { | 583 | { |
521 | // Friction effects are handled by this vehicle code | 584 | // Remember the mass so we don't have to fetch it every step |
522 | BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f); | 585 | m_vehicleMass = Prim.Linkset.LinksetMass; |
523 | BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f); | 586 | |
524 | 587 | // Friction affects are handled by this vehicle code | |
525 | // BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, 0.8f); | 588 | float friction = 0f; |
526 | 589 | PhysicsScene.PE.SetFriction(Prim.PhysBody, friction); | |
527 | VDetailLog("{0},BSDynamics.Refresh,zeroingFriction and adding damping", Prim.LocalID); | 590 | |
591 | // Moderate angular movement introduced by Bullet. | ||
592 | // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. | ||
593 | // Maybe compute linear and angular factor and damping from params. | ||
594 | float angularDamping = BSParam.VehicleAngularDamping; | ||
595 | PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); | ||
596 | |||
597 | // Vehicles report collision events so we know when it's on the ground | ||
598 | PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
599 | |||
600 | Prim.Inertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass); | ||
601 | PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, Prim.Inertia); | ||
602 | PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody); | ||
603 | |||
604 | // Set the gravity for the vehicle depending on the buoyancy | ||
605 | // TODO: what should be done if prim and vehicle buoyancy differ? | ||
606 | m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); | ||
607 | // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. | ||
608 | PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); | ||
609 | |||
610 | VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}", | ||
611 | Prim.LocalID, m_vehicleMass, friction, Prim.Inertia, angularDamping, m_VehicleGravity); | ||
612 | } | ||
613 | else | ||
614 | { | ||
615 | PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
528 | } | 616 | } |
529 | } | 617 | } |
530 | 618 | ||
@@ -546,116 +634,371 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
546 | Refresh(); | 634 | Refresh(); |
547 | } | 635 | } |
548 | 636 | ||
637 | #region Known vehicle value functions | ||
638 | // Vehicle physical parameters that we buffer from constant getting and setting. | ||
639 | // The "m_known*" values are unknown until they are fetched and the m_knownHas flag is set. | ||
640 | // Changing is remembered and the parameter is stored back into the physics engine only if updated. | ||
641 | // This does two things: 1) saves continuious calls into unmanaged code, and | ||
642 | // 2) signals when a physics property update must happen back to the simulator | ||
643 | // to update values modified for the vehicle. | ||
644 | private int m_knownChanged; | ||
645 | private int m_knownHas; | ||
646 | private float m_knownTerrainHeight; | ||
647 | private float m_knownWaterLevel; | ||
648 | private Vector3 m_knownPosition; | ||
649 | private Vector3 m_knownVelocity; | ||
650 | private Vector3 m_knownForce; | ||
651 | private Vector3 m_knownForceImpulse; | ||
652 | private Quaternion m_knownOrientation; | ||
653 | private Vector3 m_knownRotationalVelocity; | ||
654 | private Vector3 m_knownRotationalForce; | ||
655 | private Vector3 m_knownRotationalImpulse; | ||
656 | private Vector3 m_knownForwardVelocity; // vehicle relative forward speed | ||
657 | |||
658 | private const int m_knownChangedPosition = 1 << 0; | ||
659 | private const int m_knownChangedVelocity = 1 << 1; | ||
660 | private const int m_knownChangedForce = 1 << 2; | ||
661 | private const int m_knownChangedForceImpulse = 1 << 3; | ||
662 | private const int m_knownChangedOrientation = 1 << 4; | ||
663 | private const int m_knownChangedRotationalVelocity = 1 << 5; | ||
664 | private const int m_knownChangedRotationalForce = 1 << 6; | ||
665 | private const int m_knownChangedRotationalImpulse = 1 << 7; | ||
666 | private const int m_knownChangedTerrainHeight = 1 << 8; | ||
667 | private const int m_knownChangedWaterLevel = 1 << 9; | ||
668 | private const int m_knownChangedForwardVelocity = 1 <<10; | ||
669 | |||
670 | private void ForgetKnownVehicleProperties() | ||
671 | { | ||
672 | m_knownHas = 0; | ||
673 | m_knownChanged = 0; | ||
674 | } | ||
675 | // Push all the changed values back into the physics engine | ||
676 | private void PushKnownChanged() | ||
677 | { | ||
678 | if (m_knownChanged != 0) | ||
679 | { | ||
680 | if ((m_knownChanged & m_knownChangedPosition) != 0) | ||
681 | Prim.ForcePosition = m_knownPosition; | ||
682 | |||
683 | if ((m_knownChanged & m_knownChangedOrientation) != 0) | ||
684 | Prim.ForceOrientation = m_knownOrientation; | ||
685 | |||
686 | if ((m_knownChanged & m_knownChangedVelocity) != 0) | ||
687 | { | ||
688 | Prim.ForceVelocity = m_knownVelocity; | ||
689 | // Fake out Bullet by making it think the velocity is the same as last time. | ||
690 | // Bullet does a bunch of smoothing for changing parameters. | ||
691 | // Since the vehicle is demanding this setting, we override Bullet's smoothing | ||
692 | // by telling Bullet the value was the same last time. | ||
693 | PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, m_knownVelocity); | ||
694 | } | ||
695 | |||
696 | if ((m_knownChanged & m_knownChangedForce) != 0) | ||
697 | Prim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/); | ||
698 | |||
699 | if ((m_knownChanged & m_knownChangedForceImpulse) != 0) | ||
700 | Prim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/); | ||
701 | |||
702 | if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) | ||
703 | { | ||
704 | Prim.ForceRotationalVelocity = m_knownRotationalVelocity; | ||
705 | PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); | ||
706 | } | ||
707 | |||
708 | if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) | ||
709 | Prim.ApplyTorqueImpulse((Vector3)m_knownRotationalImpulse, true /*inTaintTime*/); | ||
710 | |||
711 | if ((m_knownChanged & m_knownChangedRotationalForce) != 0) | ||
712 | { | ||
713 | Prim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/); | ||
714 | } | ||
715 | |||
716 | // If we set one of the values (ie, the physics engine didn't do it) we must force | ||
717 | // an UpdateProperties event to send the changes up to the simulator. | ||
718 | PhysicsScene.PE.PushUpdate(Prim.PhysBody); | ||
719 | } | ||
720 | m_knownChanged = 0; | ||
721 | } | ||
722 | |||
723 | // Since the computation of terrain height can be a little involved, this routine | ||
724 | // is used to fetch the height only once for each vehicle simulation step. | ||
725 | Vector3 lastRememberedHeightPos; | ||
726 | private float GetTerrainHeight(Vector3 pos) | ||
727 | { | ||
728 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) | ||
729 | { | ||
730 | lastRememberedHeightPos = pos; | ||
731 | m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); | ||
732 | m_knownHas |= m_knownChangedTerrainHeight; | ||
733 | } | ||
734 | return m_knownTerrainHeight; | ||
735 | } | ||
736 | |||
737 | // Since the computation of water level can be a little involved, this routine | ||
738 | // is used ot fetch the level only once for each vehicle simulation step. | ||
739 | private float GetWaterLevel(Vector3 pos) | ||
740 | { | ||
741 | if ((m_knownHas & m_knownChangedWaterLevel) == 0) | ||
742 | { | ||
743 | m_knownWaterLevel = Prim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos); | ||
744 | m_knownHas |= m_knownChangedWaterLevel; | ||
745 | } | ||
746 | return (float)m_knownWaterLevel; | ||
747 | } | ||
748 | |||
749 | private Vector3 VehiclePosition | ||
750 | { | ||
751 | get | ||
752 | { | ||
753 | if ((m_knownHas & m_knownChangedPosition) == 0) | ||
754 | { | ||
755 | m_knownPosition = Prim.ForcePosition; | ||
756 | m_knownHas |= m_knownChangedPosition; | ||
757 | } | ||
758 | return m_knownPosition; | ||
759 | } | ||
760 | set | ||
761 | { | ||
762 | m_knownPosition = value; | ||
763 | m_knownChanged |= m_knownChangedPosition; | ||
764 | m_knownHas |= m_knownChangedPosition; | ||
765 | } | ||
766 | } | ||
767 | |||
768 | private Quaternion VehicleOrientation | ||
769 | { | ||
770 | get | ||
771 | { | ||
772 | if ((m_knownHas & m_knownChangedOrientation) == 0) | ||
773 | { | ||
774 | m_knownOrientation = Prim.ForceOrientation; | ||
775 | m_knownHas |= m_knownChangedOrientation; | ||
776 | } | ||
777 | return m_knownOrientation; | ||
778 | } | ||
779 | set | ||
780 | { | ||
781 | m_knownOrientation = value; | ||
782 | m_knownChanged |= m_knownChangedOrientation; | ||
783 | m_knownHas |= m_knownChangedOrientation; | ||
784 | } | ||
785 | } | ||
786 | |||
787 | private Vector3 VehicleVelocity | ||
788 | { | ||
789 | get | ||
790 | { | ||
791 | if ((m_knownHas & m_knownChangedVelocity) == 0) | ||
792 | { | ||
793 | m_knownVelocity = Prim.ForceVelocity; | ||
794 | m_knownHas |= m_knownChangedVelocity; | ||
795 | } | ||
796 | return (Vector3)m_knownVelocity; | ||
797 | } | ||
798 | set | ||
799 | { | ||
800 | m_knownVelocity = value; | ||
801 | m_knownChanged |= m_knownChangedVelocity; | ||
802 | m_knownHas |= m_knownChangedVelocity; | ||
803 | } | ||
804 | } | ||
805 | |||
806 | private void VehicleAddForce(Vector3 pForce) | ||
807 | { | ||
808 | if ((m_knownHas & m_knownChangedForce) == 0) | ||
809 | { | ||
810 | m_knownForce = Vector3.Zero; | ||
811 | m_knownHas |= m_knownChangedForce; | ||
812 | } | ||
813 | m_knownForce += pForce; | ||
814 | m_knownChanged |= m_knownChangedForce; | ||
815 | } | ||
816 | |||
817 | private void VehicleAddForceImpulse(Vector3 pImpulse) | ||
818 | { | ||
819 | if ((m_knownHas & m_knownChangedForceImpulse) == 0) | ||
820 | { | ||
821 | m_knownForceImpulse = Vector3.Zero; | ||
822 | m_knownHas |= m_knownChangedForceImpulse; | ||
823 | } | ||
824 | m_knownForceImpulse += pImpulse; | ||
825 | m_knownChanged |= m_knownChangedForceImpulse; | ||
826 | } | ||
827 | |||
828 | private Vector3 VehicleRotationalVelocity | ||
829 | { | ||
830 | get | ||
831 | { | ||
832 | if ((m_knownHas & m_knownChangedRotationalVelocity) == 0) | ||
833 | { | ||
834 | m_knownRotationalVelocity = Prim.ForceRotationalVelocity; | ||
835 | m_knownHas |= m_knownChangedRotationalVelocity; | ||
836 | } | ||
837 | return (Vector3)m_knownRotationalVelocity; | ||
838 | } | ||
839 | set | ||
840 | { | ||
841 | m_knownRotationalVelocity = value; | ||
842 | m_knownChanged |= m_knownChangedRotationalVelocity; | ||
843 | m_knownHas |= m_knownChangedRotationalVelocity; | ||
844 | } | ||
845 | } | ||
846 | private void VehicleAddAngularForce(Vector3 aForce) | ||
847 | { | ||
848 | if ((m_knownHas & m_knownChangedRotationalForce) == 0) | ||
849 | { | ||
850 | m_knownRotationalForce = Vector3.Zero; | ||
851 | } | ||
852 | m_knownRotationalForce += aForce; | ||
853 | m_knownChanged |= m_knownChangedRotationalForce; | ||
854 | m_knownHas |= m_knownChangedRotationalForce; | ||
855 | } | ||
856 | private void VehicleAddRotationalImpulse(Vector3 pImpulse) | ||
857 | { | ||
858 | if ((m_knownHas & m_knownChangedRotationalImpulse) == 0) | ||
859 | { | ||
860 | m_knownRotationalImpulse = Vector3.Zero; | ||
861 | m_knownHas |= m_knownChangedRotationalImpulse; | ||
862 | } | ||
863 | m_knownRotationalImpulse += pImpulse; | ||
864 | m_knownChanged |= m_knownChangedRotationalImpulse; | ||
865 | } | ||
866 | |||
867 | // Vehicle relative forward velocity | ||
868 | private Vector3 VehicleForwardVelocity | ||
869 | { | ||
870 | get | ||
871 | { | ||
872 | if ((m_knownHas & m_knownChangedForwardVelocity) == 0) | ||
873 | { | ||
874 | m_knownForwardVelocity = VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); | ||
875 | m_knownHas |= m_knownChangedForwardVelocity; | ||
876 | } | ||
877 | return m_knownForwardVelocity; | ||
878 | } | ||
879 | } | ||
880 | private float VehicleForwardSpeed | ||
881 | { | ||
882 | get | ||
883 | { | ||
884 | return VehicleForwardVelocity.X; | ||
885 | } | ||
886 | } | ||
887 | |||
888 | #endregion // Known vehicle value functions | ||
889 | |||
549 | // One step of the vehicle properties for the next 'pTimestep' seconds. | 890 | // One step of the vehicle properties for the next 'pTimestep' seconds. |
550 | internal void Step(float pTimestep) | 891 | internal void Step(float pTimestep) |
551 | { | 892 | { |
552 | if (!IsActive) return; | 893 | if (!IsActive) return; |
553 | 894 | ||
554 | // DEBUG | 895 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) |
555 | // Because Bullet does apply forces to the vehicle, our last computed | 896 | PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); |
556 | // linear and angular velocities are not what is happening now. | ||
557 | // Vector3 externalAngularVelocity = Prim.ForceRotationalVelocity - m_lastAngularVelocity; | ||
558 | // m_lastAngularVelocity += (externalAngularVelocity * 0.5f) * pTimestep; | ||
559 | // m_lastAngularVelocity = Prim.ForceRotationalVelocity; // DEBUG: account for what Bullet did last time | ||
560 | // m_lastLinearVelocityVector = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG: | ||
561 | // END DEBUG | ||
562 | 897 | ||
563 | m_vehicleMass = Prim.Linkset.LinksetMass; | 898 | ForgetKnownVehicleProperties(); |
564 | 899 | ||
565 | MoveLinear(pTimestep); | 900 | MoveLinear(pTimestep); |
566 | // Commented out for debug | ||
567 | MoveAngular(pTimestep); | 901 | MoveAngular(pTimestep); |
568 | // Prim.ApplyTorqueImpulse(-Prim.RotationalVelocity * m_vehicleMass, false); // DEBUG DEBUG | ||
569 | // Prim.ForceRotationalVelocity = -Prim.RotationalVelocity; // DEBUG DEBUG | ||
570 | 902 | ||
571 | LimitRotation(pTimestep); | 903 | LimitRotation(pTimestep); |
572 | 904 | ||
573 | // remember the position so next step we can limit absolute movement effects | 905 | // remember the position so next step we can limit absolute movement effects |
574 | m_lastPositionVector = Prim.ForcePosition; | 906 | m_lastPositionVector = VehiclePosition; |
575 | 907 | ||
576 | VDetailLog("{0},BSDynamics.Step,frict={1},grav={2},inertia={3},mass={4}", // DEBUG DEBUG | 908 | // If we forced the changing of some vehicle parameters, update the values and |
577 | Prim.LocalID, | 909 | // for the physics engine to note the changes so an UpdateProperties event will happen. |
578 | BulletSimAPI.GetFriction2(Prim.PhysBody.ptr), | 910 | PushKnownChanged(); |
579 | BulletSimAPI.GetGravity2(Prim.PhysBody.ptr), | 911 | |
580 | Prim.Inertia, | 912 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) |
581 | m_vehicleMass | 913 | PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); |
582 | ); | 914 | |
583 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", | 915 | VDetailLog("{0},BSDynamics.Step,done,pos={1}, force={2},velocity={3},angvel={4}", |
584 | Prim.LocalID, Prim.ForcePosition, Prim.Force, Prim.ForceVelocity, Prim.RotationalVelocity); | 916 | Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); |
585 | }// end Step | 917 | } |
586 | 918 | ||
587 | // Apply the effect of the linear motor. | 919 | // Apply the effect of the linear motor and other linear motions (like hover and float). |
588 | // Also does hover and float. | ||
589 | private void MoveLinear(float pTimestep) | 920 | private void MoveLinear(float pTimestep) |
590 | { | 921 | { |
591 | // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates | 922 | ComputeLinearVelocity(pTimestep); |
592 | // m_lastLinearVelocityVector is the current speed we are moving in that direction | ||
593 | if (m_linearMotorDirection.LengthSquared() > 0.001f) | ||
594 | { | ||
595 | Vector3 origDir = m_linearMotorDirection; // DEBUG | ||
596 | Vector3 origVel = m_lastLinearVelocityVector; // DEBUG | ||
597 | // DEBUG: the vehicle velocity rotated to be relative to vehicle coordinates for comparison | ||
598 | Vector3 vehicleVelocity = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG | ||
599 | 923 | ||
600 | // Add (desiredVelocity - lastAppliedVelocity) / howLongItShouldTakeToComplete | 924 | ComputeLinearTerrainHeightCorrection(pTimestep); |
601 | Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale) * pTimestep; | ||
602 | m_lastLinearVelocityVector += addAmount; | ||
603 | 925 | ||
604 | float decayFactor = (1.0f / m_linearMotorDecayTimescale) * pTimestep; | 926 | ComputeLinearHover(pTimestep); |
605 | m_linearMotorDirection *= (1f - decayFactor); | ||
606 | 927 | ||
607 | // Rotate new object velocity from vehicle relative to world coordinates | 928 | ComputeLinearBlockingEndPoint(pTimestep); |
608 | m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation; | ||
609 | 929 | ||
610 | // Apply friction for next time | 930 | ComputeLinearMotorUp(pTimestep); |
611 | Vector3 frictionFactor = (Vector3.One / m_linearFrictionTimescale) * pTimestep; | ||
612 | m_lastLinearVelocityVector *= (Vector3.One - frictionFactor); | ||
613 | 931 | ||
614 | VDetailLog("{0},MoveLinear,nonZero,origlmDir={1},origlvVel={2},vehVel={3},add={4},decay={5},frict={6},lmDir={7},lvVec={8},newVel={9}", | 932 | ApplyGravity(pTimestep); |
615 | Prim.LocalID, origDir, origVel, vehicleVelocity, addAmount, decayFactor, frictionFactor, | 933 | |
616 | m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity); | 934 | // If not changing some axis, reduce out velocity |
617 | } | 935 | if ((m_flags & (VehicleFlag.NO_X | VehicleFlag.NO_Y | VehicleFlag.NO_Z)) != 0) |
618 | else | ||
619 | { | 936 | { |
620 | // if what remains of direction is very small, zero it. | 937 | Vector3 vel = VehicleVelocity; |
621 | m_linearMotorDirection = Vector3.Zero; | 938 | if ((m_flags & (VehicleFlag.NO_X)) != 0) |
622 | m_lastLinearVelocityVector = Vector3.Zero; | 939 | vel.X = 0; |
623 | m_newVelocity = Vector3.Zero; | 940 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) |
941 | vel.Y = 0; | ||
942 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) | ||
943 | vel.Z = 0; | ||
944 | VehicleVelocity = vel; | ||
945 | } | ||
624 | 946 | ||
625 | VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); | 947 | // ================================================================== |
948 | // Clamp high or low velocities | ||
949 | float newVelocityLengthSq = VehicleVelocity.LengthSquared(); | ||
950 | if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocity) | ||
951 | { | ||
952 | VehicleVelocity /= VehicleVelocity.Length(); | ||
953 | VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; | ||
626 | } | 954 | } |
955 | else if (newVelocityLengthSq < 0.001f) | ||
956 | VehicleVelocity = Vector3.Zero; | ||
627 | 957 | ||
628 | // m_newVelocity is velocity computed from linear motor in world coordinates | 958 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", Prim.LocalID, Prim.IsColliding, VehicleVelocity ); |
629 | 959 | ||
630 | // Gravity and Buoyancy | 960 | } // end MoveLinear() |
631 | // There is some gravity, make a gravity force vector that is applied after object velocity. | ||
632 | // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; | ||
633 | Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy); | ||
634 | 961 | ||
635 | /* | 962 | public void ComputeLinearVelocity(float pTimestep) |
636 | * RA: Not sure why one would do this unless we are hoping external forces are doing gravity, ... | 963 | { |
637 | // Preserve the current Z velocity | 964 | // Step the motor from the current value. Get the correction needed this step. |
638 | Vector3 vel_now = m_prim.Velocity; | 965 | Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); |
639 | m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity | 966 | Vector3 linearMotorCorrection = m_linearMotor.Step(pTimestep, currentVel); |
640 | */ | ||
641 | 967 | ||
642 | Vector3 pos = Prim.ForcePosition; | 968 | // Motor is vehicle coordinates. Rotate it to world coordinates |
643 | // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); | 969 | Vector3 linearMotorVelocity = linearMotorCorrection * VehicleOrientation; |
644 | 970 | ||
971 | // If we're a ground vehicle, don't add any upward Z movement | ||
972 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) | ||
973 | { | ||
974 | if (linearMotorVelocity.Z > 0f) | ||
975 | linearMotorVelocity.Z = 0f; | ||
976 | } | ||
977 | |||
978 | // Add this correction to the velocity to make it faster/slower. | ||
979 | VehicleVelocity += linearMotorVelocity; | ||
980 | |||
981 | VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", | ||
982 | Prim.LocalID, VehicleVelocity, linearMotorCorrection, linearMotorVelocity); | ||
983 | } | ||
984 | |||
985 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | ||
986 | { | ||
645 | // If below the terrain, move us above the ground a little. | 987 | // If below the terrain, move us above the ground a little. |
646 | float terrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); | 988 | // TODO: Consider taking the rotated size of the object or possibly casting a ray. |
647 | // Taking the rotated size doesn't work here because m_prim.Size is the size of the root prim and not the linkset. | 989 | if (VehiclePosition.Z < GetTerrainHeight(VehiclePosition)) |
648 | // TODO: Add a m_prim.LinkSet.Size similar to m_prim.LinkSet.Mass. | ||
649 | // Vector3 rotatedSize = m_prim.Size * m_prim.ForceOrientation; | ||
650 | // if (rotatedSize.Z < terrainHeight) | ||
651 | if (pos.Z < terrainHeight) | ||
652 | { | 990 | { |
653 | pos.Z = terrainHeight + 2; | 991 | // Force position because applying force won't get the vehicle through the terrain |
654 | Prim.ForcePosition = pos; | 992 | Vector3 newPosition = VehiclePosition; |
655 | VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos); | 993 | newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f; |
994 | VehiclePosition = newPosition; | ||
995 | VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", | ||
996 | Prim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition); | ||
656 | } | 997 | } |
998 | } | ||
657 | 999 | ||
658 | // Check if hovering | 1000 | public void ComputeLinearHover(float pTimestep) |
1001 | { | ||
659 | // m_VhoverEfficiency: 0=bouncy, 1=totally damped | 1002 | // m_VhoverEfficiency: 0=bouncy, 1=totally damped |
660 | // m_VhoverTimescale: time to achieve height | 1003 | // m_VhoverTimescale: time to achieve height |
661 | if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) | 1004 | if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) |
@@ -663,11 +1006,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
663 | // We should hover, get the target height | 1006 | // We should hover, get the target height |
664 | if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) | 1007 | if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) |
665 | { | 1008 | { |
666 | m_VhoverTargetHeight = Prim.PhysicsScene.GetWaterLevelAtXYZ(pos) + m_VhoverHeight; | 1009 | m_VhoverTargetHeight = GetWaterLevel(VehiclePosition) + m_VhoverHeight; |
667 | } | 1010 | } |
668 | if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0) | 1011 | if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0) |
669 | { | 1012 | { |
670 | m_VhoverTargetHeight = terrainHeight + m_VhoverHeight; | 1013 | m_VhoverTargetHeight = GetTerrainHeight(VehiclePosition) + m_VhoverHeight; |
671 | } | 1014 | } |
672 | if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0) | 1015 | if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0) |
673 | { | 1016 | { |
@@ -677,45 +1020,63 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
677 | if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) | 1020 | if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) |
678 | { | 1021 | { |
679 | // If body is already heigher, use its height as target height | 1022 | // If body is already heigher, use its height as target height |
680 | if (pos.Z > m_VhoverTargetHeight) | 1023 | if (VehiclePosition.Z > m_VhoverTargetHeight) |
681 | m_VhoverTargetHeight = pos.Z; | 1024 | m_VhoverTargetHeight = VehiclePosition.Z; |
682 | } | 1025 | } |
1026 | |||
683 | if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) | 1027 | if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) |
684 | { | 1028 | { |
685 | if (Math.Abs(pos.Z - m_VhoverTargetHeight) > 0.2f) | 1029 | if (Math.Abs(VehiclePosition.Z - m_VhoverTargetHeight) > 0.2f) |
686 | { | 1030 | { |
1031 | Vector3 pos = VehiclePosition; | ||
687 | pos.Z = m_VhoverTargetHeight; | 1032 | pos.Z = m_VhoverTargetHeight; |
688 | Prim.ForcePosition = pos; | 1033 | VehiclePosition = pos; |
1034 | |||
1035 | VDetailLog("{0}, MoveLinear,hover,pos={1},lockHoverHeight", Prim.LocalID, pos); | ||
689 | } | 1036 | } |
690 | } | 1037 | } |
691 | else | 1038 | else |
692 | { | 1039 | { |
693 | float verticalError = pos.Z - m_VhoverTargetHeight; | 1040 | // Error is positive if below the target and negative if above. |
694 | // RA: where does the 50 come from? | 1041 | Vector3 hpos = VehiclePosition; |
695 | float verticalCorrectionVelocity = pTimestep * ((verticalError * 50.0f) / m_VhoverTimescale); | 1042 | float verticalError = m_VhoverTargetHeight - hpos.Z; |
696 | // Replace Vertical speed with correction figure if significant | 1043 | float verticalCorrection = verticalError / m_VhoverTimescale; |
697 | if (Math.Abs(verticalError) > 0.01f) | 1044 | verticalCorrection *= m_VhoverEfficiency; |
698 | { | 1045 | |
699 | m_newVelocity.Z += verticalCorrectionVelocity; | 1046 | hpos.Z += verticalCorrection; |
700 | //KF: m_VhoverEfficiency is not yet implemented | 1047 | VehiclePosition = hpos; |
701 | } | 1048 | |
702 | else if (verticalError < -0.01) | 1049 | // Since we are hovering, we need to do the opposite of falling -- get rid of world Z |
703 | { | 1050 | Vector3 vel = VehicleVelocity; |
704 | m_newVelocity.Z -= verticalCorrectionVelocity; | 1051 | vel.Z = 0f; |
705 | } | 1052 | VehicleVelocity = vel; |
706 | else | 1053 | |
707 | { | 1054 | /* |
708 | m_newVelocity.Z = 0f; | 1055 | float verticalCorrectionVelocity = verticalError / m_VhoverTimescale; |
709 | } | 1056 | Vector3 verticalCorrection = new Vector3(0f, 0f, verticalCorrectionVelocity); |
1057 | verticalCorrection *= m_vehicleMass; | ||
1058 | |||
1059 | // TODO: implement m_VhoverEfficiency correctly | ||
1060 | VehicleAddForceImpulse(verticalCorrection); | ||
1061 | */ | ||
1062 | |||
1063 | VDetailLog("{0}, MoveLinear,hover,pos={1},eff={2},hoverTS={3},height={4},target={5},err={6},corr={7}", | ||
1064 | Prim.LocalID, VehiclePosition, m_VhoverEfficiency, | ||
1065 | m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, | ||
1066 | verticalError, verticalCorrection); | ||
710 | } | 1067 | } |
711 | 1068 | ||
712 | VDetailLog("{0},MoveLinear,hover,pos={1},dir={2},height={3},target={4}", Prim.LocalID, pos, m_newVelocity, m_VhoverHeight, m_VhoverTargetHeight); | ||
713 | } | 1069 | } |
1070 | } | ||
714 | 1071 | ||
1072 | public bool ComputeLinearBlockingEndPoint(float pTimestep) | ||
1073 | { | ||
1074 | bool changed = false; | ||
1075 | |||
1076 | Vector3 pos = VehiclePosition; | ||
715 | Vector3 posChange = pos - m_lastPositionVector; | 1077 | Vector3 posChange = pos - m_lastPositionVector; |
716 | if (m_BlockingEndPoint != Vector3.Zero) | 1078 | if (m_BlockingEndPoint != Vector3.Zero) |
717 | { | 1079 | { |
718 | bool changed = false; | ||
719 | if (pos.X >= (m_BlockingEndPoint.X - (float)1)) | 1080 | if (pos.X >= (m_BlockingEndPoint.X - (float)1)) |
720 | { | 1081 | { |
721 | pos.X -= posChange.X + 1; | 1082 | pos.X -= posChange.X + 1; |
@@ -743,233 +1104,117 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
743 | } | 1104 | } |
744 | if (changed) | 1105 | if (changed) |
745 | { | 1106 | { |
746 | Prim.ForcePosition = pos; | 1107 | VehiclePosition = pos; |
747 | VDetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", | 1108 | VDetailLog("{0}, MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", |
748 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); | 1109 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); |
749 | } | 1110 | } |
750 | } | 1111 | } |
1112 | return changed; | ||
1113 | } | ||
751 | 1114 | ||
752 | #region downForce | 1115 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : |
753 | Vector3 downForce = Vector3.Zero; | 1116 | // Prevent ground vehicles from motoring into the sky. This flag has a subtle effect when |
1117 | // used with conjunction with banking: the strength of the banking will decay when the | ||
1118 | // vehicle no longer experiences collisions. The decay timescale is the same as | ||
1119 | // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering | ||
1120 | // when they are in mid jump. | ||
1121 | // TODO: this code is wrong. Also, what should it do for boats (height from water)? | ||
1122 | // This is just using the ground and a general collision check. Should really be using | ||
1123 | // a downward raycast to find what is below. | ||
1124 | public void ComputeLinearMotorUp(float pTimestep) | ||
1125 | { | ||
1126 | Vector3 ret = Vector3.Zero; | ||
754 | 1127 | ||
755 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) | 1128 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) |
756 | { | 1129 | { |
757 | // If the vehicle is motoring into the sky, get it going back down. | 1130 | // This code tries to decide if the object is not on the ground and then pushing down |
758 | // Is this an angular force or both linear and angular?? | 1131 | /* |
759 | float distanceAboveGround = pos.Z - terrainHeight; | 1132 | float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); |
760 | if (distanceAboveGround > 2f) | 1133 | distanceAboveGround = VehiclePosition.Z - targetHeight; |
1134 | // Not colliding if the vehicle is off the ground | ||
1135 | if (!Prim.IsColliding) | ||
761 | { | 1136 | { |
762 | // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep); | ||
763 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); | 1137 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); |
764 | downForce = new Vector3(0, 0, -distanceAboveGround); | 1138 | VehicleVelocity += new Vector3(0, 0, -distanceAboveGround); |
765 | } | 1139 | } |
766 | // TODO: this calculation is all wrong. From the description at | 1140 | // TODO: this calculation is wrong. From the description at |
767 | // (http://wiki.secondlife.com/wiki/Category:LSL_Vehicle), the downForce | 1141 | // (http://wiki.secondlife.com/wiki/Category:LSL_Vehicle), the downForce |
768 | // has a decay factor. This says this force should | 1142 | // has a decay factor. This says this force should |
769 | // be computed with a motor. | 1143 | // be computed with a motor. |
770 | VDetailLog("{0},MoveLinear,limitMotorUp,distAbove={1},downForce={2}", | 1144 | // TODO: add interaction with banking. |
771 | Prim.LocalID, distanceAboveGround, downForce); | 1145 | VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", |
772 | } | 1146 | Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret); |
773 | #endregion // downForce | 1147 | */ |
774 | 1148 | ||
775 | // If not changing some axis, reduce out velocity | 1149 | // Another approach is to measure if we're going up. If going up and not colliding, |
776 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | 1150 | // the vehicle is in the air. Fix that by pushing down. |
777 | m_newVelocity.X = 0; | 1151 | if (!Prim.IsColliding && VehicleVelocity.Z > 0.1) |
778 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) | 1152 | { |
779 | m_newVelocity.Y = 0; | 1153 | // Get rid of any of the velocity vector that is pushing us up. |
780 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) | 1154 | float upVelocity = VehicleVelocity.Z; |
781 | m_newVelocity.Z = 0; | 1155 | VehicleVelocity += new Vector3(0, 0, -upVelocity); |
782 | 1156 | ||
783 | // Clamp REALLY high or low velocities | 1157 | /* |
784 | if (m_newVelocity.LengthSquared() > 1e6f) | 1158 | // If we're pointed up into the air, we should nose down |
785 | { | 1159 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; |
786 | m_newVelocity /= m_newVelocity.Length(); | 1160 | // The rotation around the Y axis is pitch up or down |
787 | m_newVelocity *= 1000f; | 1161 | if (pointingDirection.Y > 0.01f) |
788 | } | 1162 | { |
789 | else if (m_newVelocity.LengthSquared() < 1e-6f) | 1163 | float angularCorrectionForce = -(float)Math.Asin(pointingDirection.Y); |
790 | m_newVelocity = Vector3.Zero; | 1164 | Vector3 angularCorrectionVector = new Vector3(0f, angularCorrectionForce, 0f); |
791 | 1165 | // Rotate into world coordinates and apply to vehicle | |
792 | // Stuff new linear velocity into the vehicle | 1166 | angularCorrectionVector *= VehicleOrientation; |
793 | Prim.ForceVelocity = m_newVelocity; | 1167 | VehicleAddAngularForce(angularCorrectionVector); |
794 | // Prim.ApplyForceImpulse((m_newVelocity - Prim.Velocity) * m_vehicleMass, false); // DEBUG DEBUG | 1168 | VDetailLog("{0}, MoveLinear,limitMotorUp,newVel={1},pntDir={2},corrFrc={3},aCorr={4}", |
795 | 1169 | Prim.LocalID, VehicleVelocity, pointingDirection, angularCorrectionForce, angularCorrectionVector); | |
796 | Vector3 totalDownForce = downForce + grav; | 1170 | } |
797 | if (totalDownForce != Vector3.Zero) | 1171 | */ |
798 | { | 1172 | VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", |
799 | Prim.AddForce(totalDownForce * m_vehicleMass, false); | 1173 | Prim.LocalID, Prim.IsColliding, upVelocity, VehicleVelocity); |
800 | // Prim.ApplyForceImpulse(totalDownForce * m_vehicleMass, false); | 1174 | } |
801 | } | 1175 | } |
1176 | } | ||
802 | 1177 | ||
803 | VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},primVel={4},totalDown={5}", | 1178 | private void ApplyGravity(float pTimeStep) |
804 | Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, Prim.Velocity, totalDownForce); | 1179 | { |
1180 | Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; | ||
1181 | VehicleAddForce(appliedGravity); | ||
805 | 1182 | ||
806 | } // end MoveLinear() | 1183 | VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},appliedForce-{2}", |
1184 | Prim.LocalID, m_VehicleGravity, appliedGravity); | ||
1185 | } | ||
807 | 1186 | ||
808 | // ======================================================================= | 1187 | // ======================================================================= |
1188 | // ======================================================================= | ||
809 | // Apply the effect of the angular motor. | 1189 | // Apply the effect of the angular motor. |
1190 | // The 'contribution' is how much angular correction velocity each function wants. | ||
1191 | // All the contributions are added together and the resulting velocity is | ||
1192 | // set directly on the vehicle. | ||
810 | private void MoveAngular(float pTimestep) | 1193 | private void MoveAngular(float pTimestep) |
811 | { | 1194 | { |
812 | // m_angularMotorDirection // angular velocity requested by LSL motor | 1195 | // VehicleRotationalVelocity = Vector3.Zero; |
813 | // m_angularMotorApply // application frame counter | ||
814 | // m_angularMotorVelocity // current angular motor velocity (ramps up and down) | ||
815 | // m_angularMotorTimescale // motor angular velocity ramp up rate | ||
816 | // m_angularMotorDecayTimescale // motor angular velocity decay rate | ||
817 | // m_angularFrictionTimescale // body angular velocity decay rate | ||
818 | // m_lastAngularVelocity // what was last applied to body | ||
819 | |||
820 | if (m_angularMotorDirection.LengthSquared() > 0.0001) | ||
821 | { | ||
822 | Vector3 origVel = m_angularMotorVelocity; | ||
823 | Vector3 origDir = m_angularMotorDirection; | ||
824 | |||
825 | // new velocity += error / ( time to get there / step interval) | ||
826 | // requested direction - current vehicle direction | ||
827 | m_angularMotorVelocity += (m_angularMotorDirection - m_angularMotorVelocity) / (m_angularMotorTimescale / pTimestep); | ||
828 | // decay requested direction | ||
829 | m_angularMotorDirection *= (1.0f - (pTimestep * 1.0f/m_angularMotorDecayTimescale)); | ||
830 | |||
831 | VDetailLog("{0},MoveAngular,angularMotorApply,angTScale={1},timeStep={2},origvel={3},origDir={4},vel={5}", | ||
832 | Prim.LocalID, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity); | ||
833 | } | ||
834 | else | ||
835 | { | ||
836 | m_angularMotorVelocity = Vector3.Zero; | ||
837 | } | ||
838 | |||
839 | #region Vertical attactor | ||
840 | |||
841 | Vector3 vertattr = Vector3.Zero; | ||
842 | Vector3 deflection = Vector3.Zero; | ||
843 | Vector3 banking = Vector3.Zero; | ||
844 | |||
845 | // If vertical attaction timescale is reasonable and we applied an angular force last time... | ||
846 | if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero) | ||
847 | { | ||
848 | float VAservo = pTimestep * 0.2f / m_verticalAttractionTimescale; | ||
849 | if (Prim.IsColliding) | ||
850 | VAservo = pTimestep * 0.05f / (m_verticalAttractionTimescale); | ||
851 | |||
852 | VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); | ||
853 | |||
854 | // Create a vector of the vehicle "up" in world coordinates | ||
855 | Vector3 verticalError = Vector3.UnitZ * Prim.ForceOrientation; | ||
856 | // verticalError.X and .Y are the World error amounts. They are 0 when there is no | ||
857 | // error (Vehicle Body is 'vertical'), and .Z will be 1. As the body leans to its | ||
858 | // side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall | ||
859 | // and .Z will go // negative. Similar for tilt and |.Y|. .X and .Y must be | ||
860 | // modulated to prevent a stable inverted body. | ||
861 | |||
862 | // Error is 0 (no error) to +/- 2 (max error) | ||
863 | if (verticalError.Z < 0.0f) | ||
864 | { | ||
865 | verticalError.X = 2.0f - verticalError.X; | ||
866 | verticalError.Y = 2.0f - verticalError.Y; | ||
867 | } | ||
868 | // scale it by VAservo (timestep and timescale) | ||
869 | verticalError = verticalError * VAservo; | ||
870 | |||
871 | // As the body rotates around the X axis, then verticalError.Y increases; Rotated around Y | ||
872 | // then .X increases, so change Body angular velocity X based on Y, and Y based on X. | ||
873 | // Z is not changed. | ||
874 | vertattr.X = verticalError.Y; | ||
875 | vertattr.Y = - verticalError.X; | ||
876 | vertattr.Z = 0f; | ||
877 | 1196 | ||
878 | // scaling appears better usingsquare-law | 1197 | ComputeAngularTurning(pTimestep); |
879 | Vector3 angularVelocity = Prim.ForceRotationalVelocity; | ||
880 | float bounce = 1.0f - (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); | ||
881 | vertattr.X += bounce * angularVelocity.X; | ||
882 | vertattr.Y += bounce * angularVelocity.Y; | ||
883 | 1198 | ||
884 | VDetailLog("{0},MoveAngular,verticalAttraction,VAservo={1},effic={2},verticalError={3},bounce={4},vertattr={5}", | 1199 | ComputeAngularVerticalAttraction(); |
885 | Prim.LocalID, VAservo, m_verticalAttractionEfficiency, verticalError, bounce, vertattr); | ||
886 | 1200 | ||
887 | } | 1201 | ComputeAngularDeflection(); |
888 | #endregion // Vertical attactor | ||
889 | 1202 | ||
890 | #region Deflection | 1203 | ComputeAngularBanking(); |
891 | 1204 | ||
892 | if (m_angularDeflectionEfficiency != 0) | 1205 | // ================================================================== |
1206 | if (VehicleRotationalVelocity.ApproxEquals(Vector3.Zero, 0.01f)) | ||
893 | { | 1207 | { |
894 | // Compute a scaled vector that points in the preferred axis (X direction) | 1208 | // The vehicle is not adding anything angular wise. |
895 | Vector3 scaledDefaultDirection = | 1209 | VehicleRotationalVelocity = Vector3.Zero; |
896 | new Vector3((pTimestep * 10 * (m_angularDeflectionEfficiency / m_angularDeflectionTimescale)), 0, 0); | 1210 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); |
897 | // Adding the current vehicle orientation and reference frame displaces the orientation to the frame. | ||
898 | // Rotate the scaled default axix relative to the actual vehicle direction giving where it should point. | ||
899 | Vector3 preferredAxisOfMotion = scaledDefaultDirection * Quaternion.Add(Prim.ForceOrientation, m_referenceFrame); | ||
900 | |||
901 | // Scale by efficiency and timescale | ||
902 | deflection = (preferredAxisOfMotion * (m_angularDeflectionEfficiency) / m_angularDeflectionTimescale) * pTimestep; | ||
903 | |||
904 | VDetailLog("{0},MoveAngular,Deflection,perfAxis={1},deflection={2}", | ||
905 | Prim.LocalID, preferredAxisOfMotion, deflection); | ||
906 | // This deflection computation is not correct. | ||
907 | deflection = Vector3.Zero; | ||
908 | } | 1211 | } |
909 | 1212 | else | |
910 | #endregion | ||
911 | |||
912 | #region Banking | ||
913 | |||
914 | if (m_bankingEfficiency != 0) | ||
915 | { | 1213 | { |
916 | Vector3 dir = Vector3.One * Prim.ForceOrientation; | 1214 | VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", Prim.LocalID, VehicleRotationalVelocity); |
917 | float mult = (m_bankingMix*m_bankingMix)*-1*(m_bankingMix < 0 ? -1 : 1); | ||
918 | //Changes which way it banks in and out of turns | ||
919 | |||
920 | //Use the square of the efficiency, as it looks much more how SL banking works | ||
921 | float effSquared = (m_bankingEfficiency*m_bankingEfficiency); | ||
922 | if (m_bankingEfficiency < 0) | ||
923 | effSquared *= -1; //Keep the negative! | ||
924 | |||
925 | float mix = Math.Abs(m_bankingMix); | ||
926 | if (m_angularMotorVelocity.X == 0) | ||
927 | { | ||
928 | /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f)) | ||
929 | { | ||
930 | Vector3 axisAngle; | ||
931 | float angle; | ||
932 | parent.Orientation.GetAxisAngle(out axisAngle, out angle); | ||
933 | Vector3 rotatedVel = parent.Velocity * parent.Orientation; | ||
934 | if ((rotatedVel.X < 0 && axisAngle.Y > 0) || (rotatedVel.X > 0 && axisAngle.Y < 0)) | ||
935 | m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (1f) * 10; | ||
936 | else | ||
937 | m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (-1f) * 10; | ||
938 | }*/ | ||
939 | } | ||
940 | else | ||
941 | banking.Z += (effSquared*(mult*mix))*(m_angularMotorVelocity.X) * 4; | ||
942 | if (!Prim.IsColliding && Math.Abs(m_angularMotorVelocity.X) > mix) | ||
943 | //If they are colliding, we probably shouldn't shove the prim around... probably | ||
944 | { | ||
945 | float angVelZ = m_angularMotorVelocity.X*-1; | ||
946 | /*if(angVelZ > mix) | ||
947 | angVelZ = mix; | ||
948 | else if(angVelZ < -mix) | ||
949 | angVelZ = -mix;*/ | ||
950 | //This controls how fast and how far the banking occurs | ||
951 | Vector3 bankingRot = new Vector3(angVelZ*(effSquared*mult), 0, 0); | ||
952 | if (bankingRot.X > 3) | ||
953 | bankingRot.X = 3; | ||
954 | else if (bankingRot.X < -3) | ||
955 | bankingRot.X = -3; | ||
956 | bankingRot *= Prim.ForceOrientation; | ||
957 | banking += bankingRot; | ||
958 | } | ||
959 | m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency; | ||
960 | VDetailLog("{0},MoveAngular,Banking,bEff={1},angMotVel={2},banking={3}", | ||
961 | Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, banking); | ||
962 | } | 1215 | } |
963 | 1216 | ||
964 | #endregion | 1217 | // ================================================================== |
965 | |||
966 | m_lastVertAttractor = vertattr; | ||
967 | |||
968 | // Sum velocities | ||
969 | m_lastAngularVelocity = m_angularMotorVelocity + vertattr + banking + deflection; | ||
970 | |||
971 | #region Linear Motor Offset | ||
972 | |||
973 | //Offset section | 1218 | //Offset section |
974 | if (m_linearMotorOffset != Vector3.Zero) | 1219 | if (m_linearMotorOffset != Vector3.Zero) |
975 | { | 1220 | { |
@@ -985,8 +1230,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
985 | // | 1230 | // |
986 | // The torque created is the linear velocity crossed with the offset | 1231 | // The torque created is the linear velocity crossed with the offset |
987 | 1232 | ||
988 | // NOTE: this computation does should be in the linear section | 1233 | // TODO: this computation should be in the linear section |
989 | // because there we know the impulse being applied. | 1234 | // because that is where we know the impulse being applied. |
990 | Vector3 torqueFromOffset = Vector3.Zero; | 1235 | Vector3 torqueFromOffset = Vector3.Zero; |
991 | // torqueFromOffset = Vector3.Cross(m_linearMotorOffset, appliedImpulse); | 1236 | // torqueFromOffset = Vector3.Cross(m_linearMotorOffset, appliedImpulse); |
992 | if (float.IsNaN(torqueFromOffset.X)) | 1237 | if (float.IsNaN(torqueFromOffset.X)) |
@@ -995,47 +1240,213 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
995 | torqueFromOffset.Y = 0; | 1240 | torqueFromOffset.Y = 0; |
996 | if (float.IsNaN(torqueFromOffset.Z)) | 1241 | if (float.IsNaN(torqueFromOffset.Z)) |
997 | torqueFromOffset.Z = 0; | 1242 | torqueFromOffset.Z = 0; |
998 | torqueFromOffset *= m_vehicleMass; | 1243 | |
999 | Prim.ApplyTorqueImpulse(torqueFromOffset, true); | 1244 | VehicleAddAngularForce(torqueFromOffset * m_vehicleMass); |
1000 | VDetailLog("{0},BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); | 1245 | VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); |
1001 | } | 1246 | } |
1002 | 1247 | ||
1003 | #endregion | 1248 | } |
1004 | 1249 | ||
1250 | private void ComputeAngularTurning(float pTimestep) | ||
1251 | { | ||
1252 | // The user wants this many radians per second angular change? | ||
1253 | Vector3 currentAngular = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | ||
1254 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep, currentAngular); | ||
1255 | |||
1256 | // ================================================================== | ||
1257 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | ||
1258 | // This flag prevents linear deflection parallel to world z-axis. This is useful | ||
1259 | // for preventing ground vehicles with large linear deflection, like bumper cars, | ||
1260 | // from climbing their linear deflection into the sky. | ||
1261 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement | ||
1262 | // TODO: This is here because this is where ODE put it but documentation says it | ||
1263 | // is a linear effect. Where should this check go? | ||
1005 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | 1264 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) |
1006 | { | 1265 | { |
1007 | m_lastAngularVelocity.X = 0; | 1266 | angularMotorContribution.X = 0f; |
1008 | m_lastAngularVelocity.Y = 0; | 1267 | angularMotorContribution.Y = 0f; |
1009 | VDetailLog("{0},MoveAngular,noDeflectionUp,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity); | 1268 | } |
1269 | |||
1270 | VehicleRotationalVelocity += angularMotorContribution * VehicleOrientation; | ||
1271 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", Prim.LocalID, angularMotorContribution); | ||
1272 | } | ||
1273 | |||
1274 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | ||
1275 | // Some vehicles, like boats, should always keep their up-side up. This can be done by | ||
1276 | // enabling the "vertical attractor" behavior that springs the vehicle's local z-axis to | ||
1277 | // the world z-axis (a.k.a. "up"). To take advantage of this feature you would set the | ||
1278 | // VEHICLE_VERTICAL_ATTRACTION_TIMESCALE to control the period of the spring frequency, | ||
1279 | // and then set the VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY to control the damping. An | ||
1280 | // efficiency of 0.0 will cause the spring to wobble around its equilibrium, while an | ||
1281 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. | ||
1282 | public void ComputeAngularVerticalAttraction() | ||
1283 | { | ||
1284 | // If vertical attaction timescale is reasonable | ||
1285 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | ||
1286 | { | ||
1287 | Vector3 vertContribution = Vector3.Zero; | ||
1288 | |||
1289 | // Take a vector pointing up and convert it from world to vehicle relative coords. | ||
1290 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; | ||
1291 | |||
1292 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | ||
1293 | // is now: | ||
1294 | // leaning to one side: rotated around the X axis with the Y value going | ||
1295 | // from zero (nearly straight up) to one (completely to the side)) or | ||
1296 | // leaning front-to-back: rotated around the Y axis with the value of X being between | ||
1297 | // zero and one. | ||
1298 | // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. | ||
1299 | |||
1300 | // Y error means needed rotation around X axis and visa versa. | ||
1301 | // Since the error goes from zero to one, the asin is the corresponding angle. | ||
1302 | vertContribution.X = (float)Math.Asin(verticalError.Y); | ||
1303 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) | ||
1304 | vertContribution.Y = -(float)Math.Asin(verticalError.X); | ||
1305 | |||
1306 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | ||
1307 | if (verticalError.Z < 0f) | ||
1308 | { | ||
1309 | vertContribution.X += PIOverFour; | ||
1310 | // vertContribution.Y -= PIOverFour; | ||
1311 | } | ||
1312 | |||
1313 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. | ||
1314 | // Correction happens over a number of seconds. | ||
1315 | Vector3 unscaledContrib = vertContribution; // DEBUG DEBUG | ||
1316 | vertContribution /= m_verticalAttractionTimescale; | ||
1317 | |||
1318 | VehicleRotationalVelocity += vertContribution * VehicleOrientation; | ||
1319 | |||
1320 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", | ||
1321 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContribution); | ||
1010 | } | 1322 | } |
1323 | } | ||
1324 | |||
1325 | // Angular correction to correct the direction the vehicle is pointing to be | ||
1326 | // the direction is should want to be pointing. | ||
1327 | // The vehicle is moving in some direction and correct its orientation to it is pointing | ||
1328 | // in that direction. | ||
1329 | // TODO: implement reference frame. | ||
1330 | public void ComputeAngularDeflection() | ||
1331 | { | ||
1332 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | ||
1333 | // approximately the same X or Y correction. When added together (when contributions are combined) | ||
1334 | // this creates an over-correction and then wabbling as the target is overshot. | ||
1335 | // TODO: rethink how the different correction computations inter-relate. | ||
1011 | 1336 | ||
1012 | if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) | 1337 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1013 | { | 1338 | { |
1014 | m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero. | 1339 | Vector3 deflectContribution = Vector3.Zero; |
1015 | Prim.ZeroAngularMotion(true); | 1340 | |
1016 | VDetailLog("{0},MoveAngular,zeroAngularMotion,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity); | 1341 | // The direction the vehicle is moving |
1342 | Vector3 movingDirection = VehicleVelocity; | ||
1343 | movingDirection.Normalize(); | ||
1344 | |||
1345 | // If the vehicle is going backward, it is still pointing forward | ||
1346 | movingDirection *= Math.Sign(VehicleForwardSpeed); | ||
1347 | |||
1348 | // The direction the vehicle is pointing | ||
1349 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | ||
1350 | pointingDirection.Normalize(); | ||
1351 | |||
1352 | // The difference between what is and what should be. | ||
1353 | Vector3 deflectionError = movingDirection - pointingDirection; | ||
1354 | |||
1355 | // Don't try to correct very large errors (not our job) | ||
1356 | // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X); | ||
1357 | // if (Math.Abs(deflectionError.Y) > PIOverFour) deflectionError.Y = PIOverTwo * Math.Sign(deflectionError.Y); | ||
1358 | // if (Math.Abs(deflectionError.Z) > PIOverFour) deflectionError.Z = PIOverTwo * Math.Sign(deflectionError.Z); | ||
1359 | if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = 0f; | ||
1360 | if (Math.Abs(deflectionError.Y) > PIOverFour) deflectionError.Y = 0f; | ||
1361 | if (Math.Abs(deflectionError.Z) > PIOverFour) deflectionError.Z = 0f; | ||
1362 | |||
1363 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | ||
1364 | |||
1365 | // Scale the correction by recovery timescale and efficiency | ||
1366 | deflectContribution = (-deflectionError) * m_angularDeflectionEfficiency; | ||
1367 | deflectContribution /= m_angularDeflectionTimescale; | ||
1368 | |||
1369 | VehicleRotationalVelocity += deflectContribution * VehicleOrientation; | ||
1370 | |||
1371 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | ||
1372 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContribution); | ||
1373 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | ||
1374 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | ||
1017 | } | 1375 | } |
1018 | else | 1376 | } |
1377 | |||
1378 | // Angular change to rotate the vehicle around the Z axis when the vehicle | ||
1379 | // is tipped around the X axis. | ||
1380 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | ||
1381 | // The vertical attractor feature must be enabled in order for the banking behavior to | ||
1382 | // function. The way banking works is this: a rotation around the vehicle's roll-axis will | ||
1383 | // produce a angular velocity around the yaw-axis, causing the vehicle to turn. The magnitude | ||
1384 | // of the yaw effect will be proportional to the | ||
1385 | // VEHICLE_BANKING_EFFICIENCY, the angle of the roll rotation, and sometimes the vehicle's | ||
1386 | // velocity along its preferred axis of motion. | ||
1387 | // The VEHICLE_BANKING_EFFICIENCY can vary between -1 and +1. When it is positive then any | ||
1388 | // positive rotation (by the right-hand rule) about the roll-axis will effect a | ||
1389 | // (negative) torque around the yaw-axis, making it turn to the right--that is the | ||
1390 | // vehicle will lean into the turn, which is how real airplanes and motorcycle's work. | ||
1391 | // Negating the banking coefficient will make it so that the vehicle leans to the | ||
1392 | // outside of the turn (not very "physical" but might allow interesting vehicles so why not?). | ||
1393 | // The VEHICLE_BANKING_MIX is a fake (i.e. non-physical) parameter that is useful for making | ||
1394 | // banking vehicles do what you want rather than what the laws of physics allow. | ||
1395 | // For example, consider a real motorcycle...it must be moving forward in order for | ||
1396 | // it to turn while banking, however video-game motorcycles are often configured | ||
1397 | // to turn in place when at a dead stop--because they are often easier to control | ||
1398 | // that way using the limited interface of the keyboard or game controller. The | ||
1399 | // VEHICLE_BANKING_MIX enables combinations of both realistic and non-realistic | ||
1400 | // banking by functioning as a slider between a banking that is correspondingly | ||
1401 | // totally static (0.0) and totally dynamic (1.0). By "static" we mean that the | ||
1402 | // banking effect depends only on the vehicle's rotation about its roll-axis compared | ||
1403 | // to "dynamic" where the banking is also proportional to its velocity along its | ||
1404 | // roll-axis. Finding the best value of the "mixture" will probably require trial and error. | ||
1405 | // The time it takes for the banking behavior to defeat a preexisting angular velocity about the | ||
1406 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to | ||
1407 | // bank quickly then give it a banking timescale of about a second or less, otherwise you can | ||
1408 | // make a sluggish vehicle by giving it a timescale of several seconds. | ||
1409 | public void ComputeAngularBanking() | ||
1410 | { | ||
1411 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | ||
1019 | { | 1412 | { |
1020 | // Apply to the body. | 1413 | Vector3 bankingContribution = Vector3.Zero; |
1021 | // The above calculates the absolute angular velocity needed. Angular velocity is massless. | 1414 | |
1022 | // Since we are stuffing the angular velocity directly into the object, the computed | 1415 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. |
1023 | // velocity needs to be scaled by the timestep. | 1416 | // As the vehicle rolls to the right or left, the Y value will increase from |
1024 | Vector3 applyAngularForce = ((m_lastAngularVelocity * pTimestep) - Prim.ForceRotationalVelocity); | 1417 | // zero (straight up) to 1 or -1 (full tilt right or left) |
1025 | Prim.ForceRotationalVelocity = applyAngularForce; | 1418 | Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; |
1026 | 1419 | ||
1027 | // Decay the angular movement for next time | 1420 | // Figure out the yaw value for this much roll. |
1028 | Vector3 decayamount = (Vector3.One / m_angularFrictionTimescale) * pTimestep; | 1421 | // Squared because that seems to give a good value |
1029 | m_lastAngularVelocity *= Vector3.One - decayamount; | 1422 | float yawAngle = (float)Math.Asin(rollComponents.Y * rollComponents.Y) * m_bankingEfficiency; |
1030 | 1423 | ||
1031 | VDetailLog("{0},MoveAngular,done,newRotVel={1},decay={2},lastAngular={3}", | 1424 | // actual error = static turn error + dynamic turn error |
1032 | Prim.LocalID, applyAngularForce, decayamount, m_lastAngularVelocity); | 1425 | float mixedYawAngle = yawAngle * (1f - m_bankingMix) + yawAngle * m_bankingMix * VehicleForwardSpeed; |
1426 | |||
1427 | // TODO: the banking effect should not go to infinity but what to limit it to? | ||
1428 | mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f); | ||
1429 | |||
1430 | // Build the force vector to change rotation from what it is to what it should be | ||
1431 | bankingContribution.Z = -mixedYawAngle; | ||
1432 | |||
1433 | // Don't do it all at once. | ||
1434 | bankingContribution /= m_bankingTimescale; | ||
1435 | |||
1436 | VehicleRotationalVelocity += bankingContribution * VehicleOrientation; | ||
1437 | |||
1438 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", | ||
1439 | Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContribution); | ||
1033 | } | 1440 | } |
1034 | } //end MoveAngular | 1441 | } |
1035 | 1442 | ||
1443 | // This is from previous instantiations of XXXDynamics.cs. | ||
1444 | // Applies roll reference frame. | ||
1445 | // TODO: is this the right way to separate the code to do this operation? | ||
1446 | // Should this be in MoveAngular()? | ||
1036 | internal void LimitRotation(float timestep) | 1447 | internal void LimitRotation(float timestep) |
1037 | { | 1448 | { |
1038 | Quaternion rotq = Prim.ForceOrientation; | 1449 | Quaternion rotq = VehicleOrientation; |
1039 | Quaternion m_rot = rotq; | 1450 | Quaternion m_rot = rotq; |
1040 | if (m_RollreferenceFrame != Quaternion.Identity) | 1451 | if (m_RollreferenceFrame != Quaternion.Identity) |
1041 | { | 1452 | { |
@@ -1063,12 +1474,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1063 | } | 1474 | } |
1064 | if (rotq != m_rot) | 1475 | if (rotq != m_rot) |
1065 | { | 1476 | { |
1066 | Prim.ForceOrientation = m_rot; | 1477 | VehicleOrientation = m_rot; |
1067 | VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); | 1478 | VDetailLog("{0}, LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); |
1068 | } | 1479 | } |
1069 | 1480 | ||
1070 | } | 1481 | } |
1071 | 1482 | ||
1483 | private float ClampInRange(float low, float val, float high) | ||
1484 | { | ||
1485 | return Math.Max(low, Math.Min(val, high)); | ||
1486 | // return Utils.Clamp(val, low, high); | ||
1487 | } | ||
1488 | |||
1072 | // Invoke the detailed logger and output something if it's enabled. | 1489 | // Invoke the detailed logger and output something if it's enabled. |
1073 | private void VDetailLog(string msg, params Object[] args) | 1490 | private void VDetailLog(string msg, params Object[] args) |
1074 | { | 1491 | { |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 0df4310..580ea4e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |||
@@ -32,6 +32,15 @@ using OMV = OpenMetaverse; | |||
32 | 32 | ||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | 33 | namespace OpenSim.Region.Physics.BulletSPlugin |
34 | { | 34 | { |
35 | |||
36 | // A BSPrim can get individual information about its linkedness attached | ||
37 | // to it through an instance of a subclass of LinksetInfo. | ||
38 | // Each type of linkset will define the information needed for its type. | ||
39 | public abstract class BSLinksetInfo | ||
40 | { | ||
41 | public virtual void Clear() { } | ||
42 | } | ||
43 | |||
35 | public abstract class BSLinkset | 44 | public abstract class BSLinkset |
36 | { | 45 | { |
37 | // private static string LogHeader = "[BULLETSIM LINKSET]"; | 46 | // private static string LogHeader = "[BULLETSIM LINKSET]"; |
@@ -47,7 +56,7 @@ public abstract class BSLinkset | |||
47 | { | 56 | { |
48 | BSLinkset ret = null; | 57 | BSLinkset ret = null; |
49 | 58 | ||
50 | switch ((int)physScene.Params.linksetImplementation) | 59 | switch ((int)BSParam.LinksetImplementation) |
51 | { | 60 | { |
52 | case (int)LinksetImplementation.Constraint: | 61 | case (int)LinksetImplementation.Constraint: |
53 | ret = new BSLinksetConstraints(physScene, parent); | 62 | ret = new BSLinksetConstraints(physScene, parent); |
@@ -87,22 +96,8 @@ public abstract class BSLinkset | |||
87 | return BSPhysicsShapeType.SHAPE_UNKNOWN; | 96 | return BSPhysicsShapeType.SHAPE_UNKNOWN; |
88 | } | 97 | } |
89 | 98 | ||
90 | // Linksets move around the children so the linkset might need to compute the child position | ||
91 | public virtual OMV.Vector3 Position(BSPhysObject member) | ||
92 | { return member.RawPosition; } | ||
93 | public virtual OMV.Quaternion Orientation(BSPhysObject member) | ||
94 | { return member.RawOrientation; } | ||
95 | // TODO: does this need to be done for Velocity and RotationalVelocityy? | ||
96 | |||
97 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims | 99 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims |
98 | protected float m_mass; | 100 | public float LinksetMass { get; protected set; } |
99 | public float LinksetMass | ||
100 | { | ||
101 | get | ||
102 | { | ||
103 | return m_mass; | ||
104 | } | ||
105 | } | ||
106 | 101 | ||
107 | public virtual bool LinksetIsColliding { get { return false; } } | 102 | public virtual bool LinksetIsColliding { get { return false; } } |
108 | 103 | ||
@@ -116,7 +111,7 @@ public abstract class BSLinkset | |||
116 | get { return ComputeLinksetGeometricCenter(); } | 111 | get { return ComputeLinksetGeometricCenter(); } |
117 | } | 112 | } |
118 | 113 | ||
119 | protected void Initialize(BSScene scene, BSPhysObject parent) | 114 | protected BSLinkset(BSScene scene, BSPhysObject parent) |
120 | { | 115 | { |
121 | // A simple linkset of one (no children) | 116 | // A simple linkset of one (no children) |
122 | LinksetID = m_nextLinksetID++; | 117 | LinksetID = m_nextLinksetID++; |
@@ -126,7 +121,8 @@ public abstract class BSLinkset | |||
126 | PhysicsScene = scene; | 121 | PhysicsScene = scene; |
127 | LinksetRoot = parent; | 122 | LinksetRoot = parent; |
128 | m_children = new HashSet<BSPhysObject>(); | 123 | m_children = new HashSet<BSPhysObject>(); |
129 | m_mass = parent.RawMass; | 124 | LinksetMass = parent.RawMass; |
125 | Rebuilding = false; | ||
130 | } | 126 | } |
131 | 127 | ||
132 | // Link to a linkset where the child knows the parent. | 128 | // Link to a linkset where the child knows the parent. |
@@ -140,7 +136,7 @@ public abstract class BSLinkset | |||
140 | // Don't add the root to its own linkset | 136 | // Don't add the root to its own linkset |
141 | if (!IsRoot(child)) | 137 | if (!IsRoot(child)) |
142 | AddChildToLinkset(child); | 138 | AddChildToLinkset(child); |
143 | m_mass = ComputeLinksetMass(); | 139 | LinksetMass = ComputeLinksetMass(); |
144 | } | 140 | } |
145 | return this; | 141 | return this; |
146 | } | 142 | } |
@@ -156,13 +152,15 @@ public abstract class BSLinkset | |||
156 | if (IsRoot(child)) | 152 | if (IsRoot(child)) |
157 | { | 153 | { |
158 | // Cannot remove the root from a linkset. | 154 | // Cannot remove the root from a linkset. |
155 | child.PositionDisplacement = OMV.Vector3.Zero; | ||
159 | return this; | 156 | return this; |
160 | } | 157 | } |
161 | RemoveChildFromLinkset(child); | 158 | RemoveChildFromLinkset(child); |
162 | m_mass = ComputeLinksetMass(); | 159 | LinksetMass = ComputeLinksetMass(); |
163 | } | 160 | } |
164 | 161 | ||
165 | // The child is down to a linkset of just itself | 162 | // The child is down to a linkset of just itself |
163 | child.PositionDisplacement = OMV.Vector3.Zero; | ||
166 | return BSLinkset.Factory(PhysicsScene, child); | 164 | return BSLinkset.Factory(PhysicsScene, child); |
167 | } | 165 | } |
168 | 166 | ||
@@ -219,7 +217,7 @@ public abstract class BSLinkset | |||
219 | // I am the root of a linkset and a new child is being added | 217 | // I am the root of a linkset and a new child is being added |
220 | // Called while LinkActivity is locked. | 218 | // Called while LinkActivity is locked. |
221 | protected abstract void AddChildToLinkset(BSPhysObject child); | 219 | protected abstract void AddChildToLinkset(BSPhysObject child); |
222 | 220 | ||
223 | // I am the root of a linkset and one of my children is being removed. | 221 | // I am the root of a linkset and one of my children is being removed. |
224 | // Safe to call even if the child is not really in my linkset. | 222 | // Safe to call even if the child is not really in my linkset. |
225 | protected abstract void RemoveChildFromLinkset(BSPhysObject child); | 223 | protected abstract void RemoveChildFromLinkset(BSPhysObject child); |
@@ -227,7 +225,14 @@ public abstract class BSLinkset | |||
227 | // When physical properties are changed the linkset needs to recalculate | 225 | // When physical properties are changed the linkset needs to recalculate |
228 | // its internal properties. | 226 | // its internal properties. |
229 | // May be called at runtime or taint-time. | 227 | // May be called at runtime or taint-time. |
230 | public abstract void Refresh(BSPhysObject requestor); | 228 | public virtual void Refresh(BSPhysObject requestor) |
229 | { | ||
230 | LinksetMass = ComputeLinksetMass(); | ||
231 | } | ||
232 | |||
233 | // Flag denoting the linkset is in the process of being rebuilt. | ||
234 | // Used to know not the schedule a rebuild in the middle of a rebuild. | ||
235 | protected bool Rebuilding { get; set; } | ||
231 | 236 | ||
232 | // The object is going dynamic (physical). Do any setup necessary | 237 | // The object is going dynamic (physical). Do any setup necessary |
233 | // for a dynamic linkset. | 238 | // for a dynamic linkset. |
@@ -245,8 +250,9 @@ public abstract class BSLinkset | |||
245 | 250 | ||
246 | // Called when a parameter update comes from the physics engine for any object | 251 | // Called when a parameter update comes from the physics engine for any object |
247 | // of the linkset is received. | 252 | // of the linkset is received. |
253 | // Passed flag is update came from physics engine (true) or the user (false). | ||
248 | // Called at taint-time!! | 254 | // Called at taint-time!! |
249 | public abstract void UpdateProperties(BSPhysObject physObject); | 255 | public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPhysObject physObject); |
250 | 256 | ||
251 | // Routine used when rebuilding the body of the root of the linkset | 257 | // Routine used when rebuilding the body of the root of the linkset |
252 | // Destroy all the constraints have have been made to root. | 258 | // Destroy all the constraints have have been made to root. |
@@ -306,7 +312,7 @@ public abstract class BSLinkset | |||
306 | 312 | ||
307 | foreach (BSPhysObject bp in m_children) | 313 | foreach (BSPhysObject bp in m_children) |
308 | { | 314 | { |
309 | com += bp.Position * bp.RawMass; | 315 | com += bp.Position; |
310 | } | 316 | } |
311 | com /= (m_children.Count + 1); | 317 | com /= (m_children.Count + 1); |
312 | } | 318 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index b9c2cf9..27d8ad0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -28,22 +28,79 @@ using System; | |||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | 30 | ||
31 | using OpenSim.Framework; | ||
32 | |||
31 | using OMV = OpenMetaverse; | 33 | using OMV = OpenMetaverse; |
32 | 34 | ||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | 35 | namespace OpenSim.Region.Physics.BulletSPlugin |
34 | { | 36 | { |
37 | |||
38 | // When a child is linked, the relationship position of the child to the parent | ||
39 | // is remembered so the child's world position can be recomputed when it is | ||
40 | // removed from the linkset. | ||
41 | sealed class BSLinksetCompoundInfo : BSLinksetInfo | ||
42 | { | ||
43 | public int Index; | ||
44 | public OMV.Vector3 OffsetFromRoot; | ||
45 | public OMV.Vector3 OffsetFromCenterOfMass; | ||
46 | public OMV.Quaternion OffsetRot; | ||
47 | public BSLinksetCompoundInfo(int indx, OMV.Vector3 p, OMV.Quaternion r) | ||
48 | { | ||
49 | Index = indx; | ||
50 | OffsetFromRoot = p; | ||
51 | OffsetFromCenterOfMass = p; | ||
52 | OffsetRot = r; | ||
53 | } | ||
54 | // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape) | ||
55 | public BSLinksetCompoundInfo(int indx, BSPhysObject root, BSPhysObject child, OMV.Vector3 centerDisplacement) | ||
56 | { | ||
57 | // Each child position and rotation is given relative to the center-of-mass. | ||
58 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(root.RawOrientation); | ||
59 | OMV.Vector3 displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation; | ||
60 | OMV.Vector3 displacementFromCOM = displacementFromRoot - centerDisplacement; | ||
61 | OMV.Quaternion displacementRot = child.RawOrientation * invRootOrientation; | ||
62 | |||
63 | // Save relative position for recomputing child's world position after moving linkset. | ||
64 | Index = indx; | ||
65 | OffsetFromRoot = displacementFromRoot; | ||
66 | OffsetFromCenterOfMass = displacementFromCOM; | ||
67 | OffsetRot = displacementRot; | ||
68 | } | ||
69 | public override void Clear() | ||
70 | { | ||
71 | Index = 0; | ||
72 | OffsetFromRoot = OMV.Vector3.Zero; | ||
73 | OffsetFromCenterOfMass = OMV.Vector3.Zero; | ||
74 | OffsetRot = OMV.Quaternion.Identity; | ||
75 | } | ||
76 | public override string ToString() | ||
77 | { | ||
78 | StringBuilder buff = new StringBuilder(); | ||
79 | buff.Append("<i="); | ||
80 | buff.Append(Index.ToString()); | ||
81 | buff.Append(",p="); | ||
82 | buff.Append(OffsetFromRoot.ToString()); | ||
83 | buff.Append(",m="); | ||
84 | buff.Append(OffsetFromCenterOfMass.ToString()); | ||
85 | buff.Append(",r="); | ||
86 | buff.Append(OffsetRot.ToString()); | ||
87 | buff.Append(">"); | ||
88 | return buff.ToString(); | ||
89 | } | ||
90 | }; | ||
91 | |||
35 | public sealed class BSLinksetCompound : BSLinkset | 92 | public sealed class BSLinksetCompound : BSLinkset |
36 | { | 93 | { |
37 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; | 94 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; |
38 | 95 | ||
39 | public BSLinksetCompound(BSScene scene, BSPhysObject parent) | 96 | public BSLinksetCompound(BSScene scene, BSPhysObject parent) : base(scene, parent) |
40 | { | 97 | { |
41 | base.Initialize(scene, parent); | ||
42 | } | 98 | } |
43 | 99 | ||
44 | // For compound implimented linksets, if there are children, use compound shape for the root. | 100 | // For compound implimented linksets, if there are children, use compound shape for the root. |
45 | public override BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor) | 101 | public override BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor) |
46 | { | 102 | { |
103 | // Returning 'unknown' means we don't have a preference. | ||
47 | BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 104 | BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN; |
48 | if (IsRoot(requestor) && HasAnyChildren) | 105 | if (IsRoot(requestor) && HasAnyChildren) |
49 | { | 106 | { |
@@ -55,27 +112,33 @@ public sealed class BSLinksetCompound : BSLinkset | |||
55 | 112 | ||
56 | // When physical properties are changed the linkset needs to recalculate | 113 | // When physical properties are changed the linkset needs to recalculate |
57 | // its internal properties. | 114 | // its internal properties. |
58 | // This is queued in the 'post taint' queue so the | ||
59 | // refresh will happen once after all the other taints are applied. | ||
60 | public override void Refresh(BSPhysObject requestor) | 115 | public override void Refresh(BSPhysObject requestor) |
61 | { | 116 | { |
62 | // External request for Refresh (from BSPrim) is not necessary | 117 | base.Refresh(requestor); |
63 | // InternalRefresh(requestor); | 118 | |
119 | // Something changed so do the rebuilding thing | ||
120 | // ScheduleRebuild(); | ||
64 | } | 121 | } |
65 | 122 | ||
66 | private void InternalRefresh(BSPhysObject requestor) | 123 | // Schedule a refresh to happen after all the other taint processing. |
124 | private void ScheduleRebuild(BSPhysObject requestor) | ||
67 | { | 125 | { |
68 | DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); | 126 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2},actuallyScheduling={3}", |
69 | // Queue to happen after all the other taint processing | 127 | requestor.LocalID, Rebuilding, HasAnyChildren, (!Rebuilding && HasAnyChildren)); |
70 | PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() | 128 | // When rebuilding, it is possible to set properties that would normally require a rebuild. |
129 | // If already rebuilding, don't request another rebuild. | ||
130 | // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding. | ||
131 | if (!Rebuilding && HasAnyChildren) | ||
71 | { | 132 | { |
72 | if (IsRoot(requestor) && HasAnyChildren) | 133 | PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() |
73 | RecomputeLinksetCompound(); | 134 | { |
74 | }); | 135 | if (HasAnyChildren) |
136 | RecomputeLinksetCompound(); | ||
137 | }); | ||
138 | } | ||
75 | } | 139 | } |
76 | 140 | ||
77 | // The object is going dynamic (physical). Do any setup necessary | 141 | // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset. |
78 | // for a dynamic linkset. | ||
79 | // Only the state of the passed object can be modified. The rest of the linkset | 142 | // Only the state of the passed object can be modified. The rest of the linkset |
80 | // has not yet been fully constructed. | 143 | // has not yet been fully constructed. |
81 | // Return 'true' if any properties updated on the passed object. | 144 | // Return 'true' if any properties updated on the passed object. |
@@ -84,12 +147,22 @@ public sealed class BSLinksetCompound : BSLinkset | |||
84 | { | 147 | { |
85 | bool ret = false; | 148 | bool ret = false; |
86 | DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); | 149 | DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); |
87 | if (!IsRoot(child)) | 150 | if (IsRoot(child)) |
151 | { | ||
152 | // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly. | ||
153 | ScheduleRebuild(LinksetRoot); | ||
154 | } | ||
155 | else | ||
88 | { | 156 | { |
89 | // Physical children are removed from the world as the shape ofthe root compound | 157 | // The origional prims are removed from the world as the shape of the root compound |
90 | // shape takes over. | 158 | // shape takes over. |
91 | BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 159 | PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
92 | BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION); | 160 | PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION); |
161 | // We don't want collisions from the old linkset children. | ||
162 | PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
163 | |||
164 | child.PhysBody.collisionType = CollisionType.LinksetChild; | ||
165 | |||
93 | ret = true; | 166 | ret = true; |
94 | } | 167 | } |
95 | return ret; | 168 | return ret; |
@@ -104,33 +177,92 @@ public sealed class BSLinksetCompound : BSLinkset | |||
104 | { | 177 | { |
105 | bool ret = false; | 178 | bool ret = false; |
106 | DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); | 179 | DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); |
107 | if (!IsRoot(child)) | 180 | if (IsRoot(child)) |
181 | { | ||
182 | ScheduleRebuild(LinksetRoot); | ||
183 | } | ||
184 | else | ||
108 | { | 185 | { |
109 | // The non-physical children can come back to life. | 186 | // The non-physical children can come back to life. |
110 | BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 187 | PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
111 | // Don't force activation so setting of DISABLE_SIMULATION can stay. | 188 | |
112 | BulletSimAPI.Activate2(child.PhysBody.ptr, false); | 189 | child.PhysBody.collisionType = CollisionType.LinksetChild; |
190 | |||
191 | // Don't force activation so setting of DISABLE_SIMULATION can stay if used. | ||
192 | PhysicsScene.PE.Activate(child.PhysBody, false); | ||
113 | ret = true; | 193 | ret = true; |
114 | } | 194 | } |
115 | return ret; | 195 | return ret; |
116 | } | 196 | } |
117 | 197 | ||
118 | // Called at taint-time!! | 198 | // 'physicalUpdate' is true if these changes came directly from the physics engine. Don't need to rebuild then. |
119 | public override void UpdateProperties(BSPhysObject updated) | 199 | // Called at taint-time. |
120 | { | 200 | public override void UpdateProperties(UpdatedProperties whichUpdated, BSPhysObject updated) |
121 | // Nothing to do for constraints on property updates | ||
122 | } | ||
123 | |||
124 | // The children move around in relationship to the root. | ||
125 | // Just grab the current values of wherever it is right now. | ||
126 | public override OMV.Vector3 Position(BSPhysObject member) | ||
127 | { | 201 | { |
128 | return BulletSimAPI.GetPosition2(member.PhysBody.ptr); | 202 | // The user moving a child around requires the rebuilding of the linkset compound shape |
129 | } | 203 | // One problem is this happens when a border is crossed -- the simulator implementation |
130 | 204 | // stores the position into the group which causes the move of the object | |
131 | public override OMV.Quaternion Orientation(BSPhysObject member) | 205 | // but it also means all the child positions get updated. |
132 | { | 206 | // What would cause an unnecessary rebuild so we make sure the linkset is in a |
133 | return BulletSimAPI.GetOrientation2(member.PhysBody.ptr); | 207 | // region before bothering to do a rebuild. |
208 | if (!IsRoot(updated) && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition)) | ||
209 | { | ||
210 | // If a child of the linkset is updating only the position or rotation, that can be done | ||
211 | // without rebuilding the linkset. | ||
212 | // If a handle for the child can be fetch, we update the child here. If a rebuild was | ||
213 | // scheduled by someone else, the rebuild will just replace this setting. | ||
214 | |||
215 | bool updatedChild = false; | ||
216 | // Anything other than updating position or orientation usually means a physical update | ||
217 | // and that is caused by us updating the object. | ||
218 | if ((whichUpdated & ~(UpdatedProperties.Position | UpdatedProperties.Orientation)) == 0) | ||
219 | { | ||
220 | // Gather the child info. It might not be there if the linkset is in transition. | ||
221 | BSLinksetCompoundInfo lsi = updated.LinksetInfo as BSLinksetCompoundInfo; | ||
222 | if (LinksetRoot.PhysShape.HasPhysicalShape && lsi != null) | ||
223 | { | ||
224 | if (PhysicsScene.PE.IsCompound(LinksetRoot.PhysShape)) | ||
225 | { | ||
226 | BulletShape linksetChildShape = PhysicsScene.PE.GetChildShapeFromCompoundShapeIndex(LinksetRoot.PhysShape, lsi.Index); | ||
227 | if (linksetChildShape.HasPhysicalShape) | ||
228 | { | ||
229 | // Compute the offset from the center-of-gravity | ||
230 | BSLinksetCompoundInfo newLsi = new BSLinksetCompoundInfo(lsi.Index, LinksetRoot, updated, LinksetRoot.PositionDisplacement); | ||
231 | PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape, lsi.Index, | ||
232 | newLsi.OffsetFromCenterOfMass, | ||
233 | newLsi.OffsetRot, | ||
234 | true /* shouldRecalculateLocalAabb */); | ||
235 | DetailLog("{0},BSLinksetCompound.UpdateProperties,changeChildPosRot,whichUpdated={1}newLsi={2}", | ||
236 | updated.LocalID, whichUpdated, newLsi); | ||
237 | updated.LinksetInfo = newLsi; | ||
238 | updatedChild = true; | ||
239 | } | ||
240 | else // DEBUG DEBUG | ||
241 | { // DEBUG DEBUG | ||
242 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,noChildShape,shape={1}", | ||
243 | updated.LocalID, linksetChildShape); | ||
244 | } // DEBUG DEBUG | ||
245 | } | ||
246 | else // DEBUG DEBUG | ||
247 | { // DEBUG DEBUG | ||
248 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,notCompound", updated.LocalID); | ||
249 | } // DEBUG DEBUG | ||
250 | } | ||
251 | else // DEBUG DEBUG | ||
252 | { // DEBUG DEBUG | ||
253 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,rootPhysShape={1},lsi={2}", | ||
254 | updated.LocalID, LinksetRoot.PhysShape, lsi == null ? "NULL" : lsi.ToString()); | ||
255 | } // DEBUG DEBUG | ||
256 | if (!updatedChild) | ||
257 | { | ||
258 | // If couldn't do the individual child, the linkset needs a rebuild to incorporate the new child info. | ||
259 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild.schedulingRebuild,whichUpdated={1}", | ||
260 | updated.LocalID, whichUpdated); | ||
261 | updated.LinksetInfo = null; // setting to 'null' causes relative position to be recomputed. | ||
262 | ScheduleRebuild(updated); | ||
263 | } | ||
264 | } | ||
265 | } | ||
134 | } | 266 | } |
135 | 267 | ||
136 | // Routine called when rebuilding the body of some member of the linkset. | 268 | // Routine called when rebuilding the body of some member of the linkset. |
@@ -142,24 +274,62 @@ public sealed class BSLinksetCompound : BSLinkset | |||
142 | bool ret = false; | 274 | bool ret = false; |
143 | 275 | ||
144 | DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", | 276 | DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", |
145 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child)); | 277 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, IsRoot(child)); |
146 | 278 | ||
147 | if (!IsRoot(child)) | 279 | if (!IsRoot(child)) |
148 | { | 280 | { |
149 | // Cause the current shape to be freed and the new one to be built. | 281 | // Because it is a convenient time, recompute child world position and rotation based on |
150 | InternalRefresh(LinksetRoot); | 282 | // its position in the linkset. |
151 | ret = true; | 283 | RecomputeChildWorldPosition(child, true); |
152 | } | 284 | } |
153 | 285 | ||
286 | // Cannot schedule a refresh/rebuild here because this routine is called when | ||
287 | // the linkset is being rebuilt. | ||
288 | // InternalRefresh(LinksetRoot); | ||
289 | |||
154 | return ret; | 290 | return ret; |
155 | } | 291 | } |
156 | 292 | ||
157 | // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', | 293 | // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', |
158 | // this routine will restore the removed constraints. | 294 | // this routine will restore the removed constraints. |
159 | // Called at taint-time!! | 295 | // Called at taint-time!! |
160 | public override void RestoreBodyDependencies(BSPrim child) | 296 | public override void RestoreBodyDependencies(BSPrim child) |
161 | { | 297 | { |
162 | // The Refresh operation queued by RemoveBodyDependencies() will build any missing constraints. | 298 | } |
299 | |||
300 | // When the linkset is built, the child shape is added to the compound shape relative to the | ||
301 | // root shape. The linkset then moves around but this does not move the actual child | ||
302 | // prim. The child prim's location must be recomputed based on the location of the root shape. | ||
303 | private void RecomputeChildWorldPosition(BSPhysObject child, bool inTaintTime) | ||
304 | { | ||
305 | BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo; | ||
306 | if (lci != null) | ||
307 | { | ||
308 | if (inTaintTime) | ||
309 | { | ||
310 | OMV.Vector3 oldPos = child.RawPosition; | ||
311 | child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetFromRoot; | ||
312 | child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot; | ||
313 | DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}", | ||
314 | child.LocalID, oldPos, lci, child.RawPosition); | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | // TaintedObject is not used here so the raw position is set now and not at taint-time. | ||
319 | child.Position = LinksetRoot.RawPosition + lci.OffsetFromRoot; | ||
320 | child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot; | ||
321 | } | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | // This happens when children have been added to the linkset but the linkset | ||
326 | // has not been constructed yet. So like, at taint time, adding children to a linkset | ||
327 | // and then changing properties of the children (makePhysical, for instance) | ||
328 | // but the post-print action of actually rebuilding the linkset has not yet happened. | ||
329 | // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}", | ||
330 | // LogHeader, child.LocalID); | ||
331 | DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID); | ||
332 | } | ||
163 | } | 333 | } |
164 | 334 | ||
165 | // ================================================================ | 335 | // ================================================================ |
@@ -174,24 +344,25 @@ public sealed class BSLinksetCompound : BSLinkset | |||
174 | 344 | ||
175 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); | 345 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); |
176 | 346 | ||
177 | // Cause constraints and assorted properties to be recomputed before the next simulation step. | 347 | // Rebuild the compound shape with the new child shape included |
178 | InternalRefresh(LinksetRoot); | 348 | ScheduleRebuild(child); |
179 | } | 349 | } |
180 | return; | 350 | return; |
181 | } | 351 | } |
182 | 352 | ||
183 | // Remove the specified child from the linkset. | 353 | // Remove the specified child from the linkset. |
184 | // Safe to call even if the child is not really in my linkset. | 354 | // Safe to call even if the child is not really in the linkset. |
185 | protected override void RemoveChildFromLinkset(BSPhysObject child) | 355 | protected override void RemoveChildFromLinkset(BSPhysObject child) |
186 | { | 356 | { |
187 | if (m_children.Remove(child)) | 357 | if (m_children.Remove(child)) |
188 | { | 358 | { |
189 | DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", | 359 | DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", |
190 | child.LocalID, | 360 | child.LocalID, |
191 | LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), | 361 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, |
192 | child.LocalID, child.PhysBody.ptr.ToString("X")); | 362 | child.LocalID, child.PhysBody.AddrString); |
193 | 363 | ||
194 | // Cause the child's body to be rebuilt and thus restored to normal operation | 364 | // Cause the child's body to be rebuilt and thus restored to normal operation |
365 | RecomputeChildWorldPosition(child, false); | ||
195 | child.ForceBodyShapeRebuild(false); | 366 | child.ForceBodyShapeRebuild(false); |
196 | 367 | ||
197 | if (!HasAnyChildren) | 368 | if (!HasAnyChildren) |
@@ -201,8 +372,8 @@ public sealed class BSLinksetCompound : BSLinkset | |||
201 | } | 372 | } |
202 | else | 373 | else |
203 | { | 374 | { |
204 | // Schedule a rebuild of the linkset before the next simulation tick. | 375 | // Rebuild the compound shape with the child removed |
205 | InternalRefresh(LinksetRoot); | 376 | ScheduleRebuild(LinksetRoot); |
206 | } | 377 | } |
207 | } | 378 | } |
208 | return; | 379 | return; |
@@ -213,63 +384,108 @@ public sealed class BSLinksetCompound : BSLinkset | |||
213 | // Constraint linksets are rebuilt every time. | 384 | // Constraint linksets are rebuilt every time. |
214 | // Note that this works for rebuilding just the root after a linkset is taken apart. | 385 | // Note that this works for rebuilding just the root after a linkset is taken apart. |
215 | // Called at taint time!! | 386 | // Called at taint time!! |
387 | private bool disableCOM = true; // disable until we get this debugged | ||
216 | private void RecomputeLinksetCompound() | 388 | private void RecomputeLinksetCompound() |
217 | { | 389 | { |
218 | // Cause the root shape to be rebuilt as a compound object with just the root in it | 390 | try |
219 | LinksetRoot.ForceBodyShapeRebuild(true); | ||
220 | |||
221 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", | ||
222 | LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); | ||
223 | |||
224 | // Add a shape for each of the other children in the linkset | ||
225 | ForEachMember(delegate(BSPhysObject cPrim) | ||
226 | { | 391 | { |
227 | if (!IsRoot(cPrim)) | 392 | // Suppress rebuilding while rebuilding |
393 | Rebuilding = true; | ||
394 | |||
395 | // Cause the root shape to be rebuilt as a compound object with just the root in it | ||
396 | LinksetRoot.ForceBodyShapeRebuild(true); | ||
397 | |||
398 | // The center of mass for the linkset is the geometric center of the group. | ||
399 | // Compute a displacement for each component so it is relative to the center-of-mass. | ||
400 | // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass | ||
401 | OMV.Vector3 centerOfMass; | ||
402 | OMV.Vector3 centerDisplacement = OMV.Vector3.Zero; | ||
403 | if (disableCOM) // DEBUG DEBUG | ||
404 | { // DEBUG DEBUG | ||
405 | centerOfMass = LinksetRoot.RawPosition; // DEBUG DEBUG | ||
406 | LinksetRoot.PositionDisplacement = OMV.Vector3.Zero; | ||
407 | } // DEBUG DEBUG | ||
408 | else | ||
228 | { | 409 | { |
229 | // Each child position and rotation is given relative to the root. | 410 | centerOfMass = ComputeLinksetGeometricCenter(); |
230 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); | 411 | centerDisplacement = centerOfMass - LinksetRoot.RawPosition; |
231 | OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; | ||
232 | OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; | ||
233 | 412 | ||
234 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", | 413 | // Since we're displacing the center of the shape, we need to move the body in the world |
235 | LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, displacementPos, displacementRot); | 414 | LinksetRoot.PositionDisplacement = centerDisplacement; |
236 | 415 | ||
237 | if (cPrim.PhysShape.isNativeShape) | 416 | PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape, 0, -centerDisplacement, OMV.Quaternion.Identity, false); |
238 | { | 417 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,com={1},rootPos={2},centerDisp={3}", |
239 | // Native shapes are not shared so we need to create a new one. | 418 | LinksetRoot.LocalID, centerOfMass, LinksetRoot.RawPosition, centerDisplacement); |
240 | // A mesh or hull is created because scale is not available on a native shape. | 419 | } |
241 | // (TODO: Bullet does have a btScaledCollisionShape. Can that be used?) | 420 | |
242 | BulletShape saveShape = cPrim.PhysShape; | 421 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", |
243 | cPrim.PhysShape.ptr = IntPtr.Zero; // Don't let the create free the child's shape | 422 | LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); |
244 | PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); | 423 | |
245 | BulletShape newShape = cPrim.PhysShape; | 424 | // Add a shape for each of the other children in the linkset |
246 | cPrim.PhysShape = saveShape; | 425 | int memberIndex = 1; |
247 | BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot); | 426 | ForEachMember(delegate(BSPhysObject cPrim) |
248 | } | 427 | { |
249 | else | 428 | if (!IsRoot(cPrim)) |
250 | { | 429 | { |
251 | // For the shared shapes (meshes and hulls), just use the shape in the child. | 430 | // Compute the displacement of the child from the root of the linkset. |
252 | if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) | 431 | // This info is saved in the child prim so the relationship does not |
432 | // change over time and the new child position can be computed | ||
433 | // when the linkset is being disassembled (the linkset may have moved). | ||
434 | BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo; | ||
435 | if (lci == null) | ||
253 | { | 436 | { |
254 | PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", | 437 | lci = new BSLinksetCompoundInfo(memberIndex, LinksetRoot, cPrim, centerDisplacement); |
255 | LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); | 438 | cPrim.LinksetInfo = lci; |
439 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); | ||
256 | } | 440 | } |
257 | BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); | ||
258 | } | ||
259 | } | ||
260 | return false; // 'false' says to move onto the next child in the list | ||
261 | }); | ||
262 | 441 | ||
263 | // With all of the linkset packed into the root prim, it has the mass of everyone. | 442 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},lci={3}", |
264 | float linksetMass = LinksetMass; | 443 | LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci); |
265 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); | ||
266 | 444 | ||
267 | BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr); | 445 | if (cPrim.PhysShape.isNativeShape) |
446 | { | ||
447 | // A native shape is turning into a hull collision shape because native | ||
448 | // shapes are not shared so we have to hullify it so it will be tracked | ||
449 | // and freed at the correct time. This also solves the scaling problem | ||
450 | // (native shapes scaled but hull/meshes are assumed to not be). | ||
451 | // TODO: decide of the native shape can just be used in the compound shape. | ||
452 | // Use call to CreateGeomNonSpecial(). | ||
453 | BulletShape saveShape = cPrim.PhysShape; | ||
454 | cPrim.PhysShape.Clear(); // Don't let the create free the child's shape | ||
455 | // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null); | ||
456 | PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); | ||
457 | BulletShape newShape = cPrim.PhysShape; | ||
458 | cPrim.PhysShape = saveShape; | ||
459 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetFromCenterOfMass, lci.OffsetRot); | ||
460 | } | ||
461 | else | ||
462 | { | ||
463 | // For the shared shapes (meshes and hulls), just use the shape in the child. | ||
464 | // The reference count added here will be decremented when the compound shape | ||
465 | // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). | ||
466 | if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) | ||
467 | { | ||
468 | PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", | ||
469 | LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); | ||
470 | } | ||
471 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetFromCenterOfMass, lci.OffsetRot); | ||
472 | } | ||
473 | lci.Index = memberIndex; | ||
474 | memberIndex++; | ||
475 | } | ||
476 | return false; // 'false' says to move onto the next child in the list | ||
477 | }); | ||
268 | 478 | ||
269 | // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets. | 479 | // With all of the linkset packed into the root prim, it has the mass of everyone. |
270 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, | 480 | LinksetMass = ComputeLinksetMass(); |
271 | // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); | 481 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); |
482 | } | ||
483 | finally | ||
484 | { | ||
485 | Rebuilding = false; | ||
486 | } | ||
272 | 487 | ||
488 | PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape); | ||
273 | } | 489 | } |
274 | } | 490 | } |
275 | } \ No newline at end of file | 491 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index c855fda..89f186c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | |||
@@ -36,9 +36,8 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
36 | { | 36 | { |
37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; | 37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; |
38 | 38 | ||
39 | public BSLinksetConstraints(BSScene scene, BSPhysObject parent) | 39 | public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent) |
40 | { | 40 | { |
41 | base.Initialize(scene, parent); | ||
42 | } | 41 | } |
43 | 42 | ||
44 | // When physical properties are changed the linkset needs to recalculate | 43 | // When physical properties are changed the linkset needs to recalculate |
@@ -47,12 +46,17 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
47 | // refresh will happen once after all the other taints are applied. | 46 | // refresh will happen once after all the other taints are applied. |
48 | public override void Refresh(BSPhysObject requestor) | 47 | public override void Refresh(BSPhysObject requestor) |
49 | { | 48 | { |
50 | // Queue to happen after all the other taint processing | 49 | base.Refresh(requestor); |
51 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() | 50 | |
52 | { | 51 | if (HasAnyChildren && IsRoot(requestor)) |
53 | if (HasAnyChildren && IsRoot(requestor)) | 52 | { |
54 | RecomputeLinksetConstraints(); | 53 | // Queue to happen after all the other taint processing |
55 | }); | 54 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() |
55 | { | ||
56 | if (HasAnyChildren && IsRoot(requestor)) | ||
57 | RecomputeLinksetConstraints(); | ||
58 | }); | ||
59 | } | ||
56 | } | 60 | } |
57 | 61 | ||
58 | // The object is going dynamic (physical). Do any setup necessary | 62 | // The object is going dynamic (physical). Do any setup necessary |
@@ -79,23 +83,11 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
79 | } | 83 | } |
80 | 84 | ||
81 | // Called at taint-time!! | 85 | // Called at taint-time!! |
82 | public override void UpdateProperties(BSPhysObject updated) | 86 | public override void UpdateProperties(UpdatedProperties whichUpdated, BSPhysObject pObj) |
83 | { | 87 | { |
84 | // Nothing to do for constraints on property updates | 88 | // Nothing to do for constraints on property updates |
85 | } | 89 | } |
86 | 90 | ||
87 | // The children of the linkset are moved around by the constraints. | ||
88 | // Just grab the current values of wherever it is right now. | ||
89 | public override OMV.Vector3 Position(BSPhysObject member) | ||
90 | { | ||
91 | return BulletSimAPI.GetPosition2(member.PhysBody.ptr); | ||
92 | } | ||
93 | |||
94 | public override OMV.Quaternion Orientation(BSPhysObject member) | ||
95 | { | ||
96 | return BulletSimAPI.GetOrientation2(member.PhysBody.ptr); | ||
97 | } | ||
98 | |||
99 | // Routine called when rebuilding the body of some member of the linkset. | 91 | // Routine called when rebuilding the body of some member of the linkset. |
100 | // Destroy all the constraints have have been made to root and set | 92 | // Destroy all the constraints have have been made to root and set |
101 | // up to rebuild the constraints before the next simulation step. | 93 | // up to rebuild the constraints before the next simulation step. |
@@ -106,7 +98,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
106 | bool ret = false; | 98 | bool ret = false; |
107 | 99 | ||
108 | DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", | 100 | DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", |
109 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X")); | 101 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); |
110 | 102 | ||
111 | lock (m_linksetActivityLock) | 103 | lock (m_linksetActivityLock) |
112 | { | 104 | { |
@@ -155,8 +147,8 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
155 | 147 | ||
156 | DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", | 148 | DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", |
157 | childx.LocalID, | 149 | childx.LocalID, |
158 | rootx.LocalID, rootx.PhysBody.ptr.ToString("X"), | 150 | rootx.LocalID, rootx.PhysBody.AddrString, |
159 | childx.LocalID, childx.PhysBody.ptr.ToString("X")); | 151 | childx.LocalID, childx.PhysBody.AddrString); |
160 | 152 | ||
161 | PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() | 153 | PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() |
162 | { | 154 | { |
@@ -195,8 +187,8 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
195 | 187 | ||
196 | DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", | 188 | DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", |
197 | rootPrim.LocalID, | 189 | rootPrim.LocalID, |
198 | rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), | 190 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, |
199 | childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X"), | 191 | childPrim.LocalID, childPrim.PhysBody.AddrString, |
200 | rootPrim.Position, childPrim.Position, midPoint); | 192 | rootPrim.Position, childPrim.Position, midPoint); |
201 | 193 | ||
202 | // create a constraint that allows no freedom of movement between the two objects | 194 | // create a constraint that allows no freedom of movement between the two objects |
@@ -239,14 +231,14 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
239 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | 231 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); |
240 | 232 | ||
241 | // tweek the constraint to increase stability | 233 | // tweek the constraint to increase stability |
242 | constrain.UseFrameOffset(PhysicsScene.BoolNumeric(PhysicsScene.Params.linkConstraintUseFrameOffset)); | 234 | constrain.UseFrameOffset(BSParam.BoolNumeric(BSParam.LinkConstraintUseFrameOffset)); |
243 | constrain.TranslationalLimitMotor(PhysicsScene.BoolNumeric(PhysicsScene.Params.linkConstraintEnableTransMotor), | 235 | constrain.TranslationalLimitMotor(BSParam.BoolNumeric(BSParam.LinkConstraintEnableTransMotor), |
244 | PhysicsScene.Params.linkConstraintTransMotorMaxVel, | 236 | BSParam.LinkConstraintTransMotorMaxVel, |
245 | PhysicsScene.Params.linkConstraintTransMotorMaxForce); | 237 | BSParam.LinkConstraintTransMotorMaxForce); |
246 | constrain.SetCFMAndERP(PhysicsScene.Params.linkConstraintCFM, PhysicsScene.Params.linkConstraintERP); | 238 | constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP); |
247 | if (PhysicsScene.Params.linkConstraintSolverIterations != 0f) | 239 | if (BSParam.LinkConstraintSolverIterations != 0f) |
248 | { | 240 | { |
249 | constrain.SetSolverIterations(PhysicsScene.Params.linkConstraintSolverIterations); | 241 | constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations); |
250 | } | 242 | } |
251 | return constrain; | 243 | return constrain; |
252 | } | 244 | } |
@@ -260,14 +252,14 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
260 | bool ret = false; | 252 | bool ret = false; |
261 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", | 253 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", |
262 | rootPrim.LocalID, | 254 | rootPrim.LocalID, |
263 | rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), | 255 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, |
264 | childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X")); | 256 | childPrim.LocalID, childPrim.PhysBody.AddrString); |
265 | 257 | ||
266 | // Find the constraint for this link and get rid of it from the overall collection and from my list | 258 | // Find the constraint for this link and get rid of it from the overall collection and from my list |
267 | if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) | 259 | if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) |
268 | { | 260 | { |
269 | // Make the child refresh its location | 261 | // Make the child refresh its location |
270 | BulletSimAPI.PushUpdate2(childPrim.PhysBody.ptr); | 262 | PhysicsScene.PE.PushUpdate(childPrim.PhysBody); |
271 | ret = true; | 263 | ret = true; |
272 | } | 264 | } |
273 | 265 | ||
@@ -292,20 +284,17 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
292 | private void RecomputeLinksetConstraints() | 284 | private void RecomputeLinksetConstraints() |
293 | { | 285 | { |
294 | float linksetMass = LinksetMass; | 286 | float linksetMass = LinksetMass; |
295 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); | 287 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true); |
296 | 288 | ||
297 | // DEBUG: see of inter-linkset collisions are causing problems | ||
298 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, | ||
299 | // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); | ||
300 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", | 289 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", |
301 | LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), linksetMass); | 290 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); |
302 | 291 | ||
303 | foreach (BSPhysObject child in m_children) | 292 | foreach (BSPhysObject child in m_children) |
304 | { | 293 | { |
305 | // A child in the linkset physically shows the mass of the whole linkset. | 294 | // A child in the linkset physically shows the mass of the whole linkset. |
306 | // This allows Bullet to apply enough force on the child to move the whole linkset. | 295 | // This allows Bullet to apply enough force on the child to move the whole linkset. |
307 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) | 296 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) |
308 | child.UpdatePhysicalMassProperties(linksetMass); | 297 | child.UpdatePhysicalMassProperties(linksetMass, true); |
309 | 298 | ||
310 | BSConstraint constrain; | 299 | BSConstraint constrain; |
311 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) | 300 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) |
@@ -315,11 +304,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
315 | } | 304 | } |
316 | constrain.RecomputeConstraintVariables(linksetMass); | 305 | constrain.RecomputeConstraintVariables(linksetMass); |
317 | 306 | ||
318 | // DEBUG: see of inter-linkset collisions are causing problems | 307 | // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG |
319 | // BulletSimAPI.SetCollisionFilterMask2(child.BSBody.ptr, | ||
320 | // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); | ||
321 | |||
322 | // BulletSimAPI.DumpConstraint2(PhysicsScene.World.ptr, constrain.Constraint.ptr); // DEBUG DEBUG | ||
323 | } | 308 | } |
324 | 309 | ||
325 | } | 310 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs new file mode 100755 index 0000000..92d62ff --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs | |||
@@ -0,0 +1,200 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
34 | { | ||
35 | |||
36 | public struct MaterialAttributes | ||
37 | { | ||
38 | // Material type values that correspond with definitions for LSL | ||
39 | public enum Material : int | ||
40 | { | ||
41 | Stone = 0, | ||
42 | Metal, | ||
43 | Glass, | ||
44 | Wood, | ||
45 | Flesh, | ||
46 | Plastic, | ||
47 | Rubber, | ||
48 | Light, | ||
49 | // Hereafter are BulletSim additions | ||
50 | Avatar, | ||
51 | NumberOfTypes // the count of types in the enum. | ||
52 | } | ||
53 | |||
54 | // Names must be in the order of the above enum. | ||
55 | // These names must coorespond to the lower case field names in the MaterialAttributes | ||
56 | // structure as reflection is used to select the field to put the value in. | ||
57 | public static readonly string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; | ||
58 | |||
59 | public MaterialAttributes(string t, float d, float f, float r) | ||
60 | { | ||
61 | type = t; | ||
62 | density = d; | ||
63 | friction = f; | ||
64 | restitution = r; | ||
65 | } | ||
66 | public string type; | ||
67 | public float density; | ||
68 | public float friction; | ||
69 | public float restitution; | ||
70 | } | ||
71 | |||
72 | public static class BSMaterials | ||
73 | { | ||
74 | // Attributes for each material type | ||
75 | private static readonly MaterialAttributes[] Attributes; | ||
76 | |||
77 | // Map of material name to material type code | ||
78 | public static readonly Dictionary<string, MaterialAttributes.Material> MaterialMap; | ||
79 | |||
80 | static BSMaterials() | ||
81 | { | ||
82 | // Attribute sets for both the non-physical and physical instances of materials. | ||
83 | Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; | ||
84 | |||
85 | // Map of name to type code. | ||
86 | MaterialMap = new Dictionary<string, MaterialAttributes.Material>(); | ||
87 | MaterialMap.Add("Stone", MaterialAttributes.Material.Stone); | ||
88 | MaterialMap.Add("Metal", MaterialAttributes.Material.Metal); | ||
89 | MaterialMap.Add("Glass", MaterialAttributes.Material.Glass); | ||
90 | MaterialMap.Add("Wood", MaterialAttributes.Material.Wood); | ||
91 | MaterialMap.Add("Flesh", MaterialAttributes.Material.Flesh); | ||
92 | MaterialMap.Add("Plastic", MaterialAttributes.Material.Plastic); | ||
93 | MaterialMap.Add("Rubber", MaterialAttributes.Material.Rubber); | ||
94 | MaterialMap.Add("Light", MaterialAttributes.Material.Light); | ||
95 | MaterialMap.Add("Avatar", MaterialAttributes.Material.Avatar); | ||
96 | } | ||
97 | |||
98 | // This is where all the default material attributes are defined. | ||
99 | public static void InitializeFromDefaults(ConfigurationParameters parms) | ||
100 | { | ||
101 | // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL | ||
102 | float dDensity = parms.defaultDensity; | ||
103 | float dFriction = parms.defaultFriction; | ||
104 | float dRestitution = parms.defaultRestitution; | ||
105 | Attributes[(int)MaterialAttributes.Material.Stone] = | ||
106 | new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); | ||
107 | Attributes[(int)MaterialAttributes.Material.Metal] = | ||
108 | new MaterialAttributes("metal",dDensity, 0.3f, 0.4f); | ||
109 | Attributes[(int)MaterialAttributes.Material.Glass] = | ||
110 | new MaterialAttributes("glass",dDensity, 0.2f, 0.7f); | ||
111 | Attributes[(int)MaterialAttributes.Material.Wood] = | ||
112 | new MaterialAttributes("wood",dDensity, 0.6f, 0.5f); | ||
113 | Attributes[(int)MaterialAttributes.Material.Flesh] = | ||
114 | new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f); | ||
115 | Attributes[(int)MaterialAttributes.Material.Plastic] = | ||
116 | new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f); | ||
117 | Attributes[(int)MaterialAttributes.Material.Rubber] = | ||
118 | new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f); | ||
119 | Attributes[(int)MaterialAttributes.Material.Light] = | ||
120 | new MaterialAttributes("light",dDensity, dFriction, dRestitution); | ||
121 | Attributes[(int)MaterialAttributes.Material.Avatar] = | ||
122 | new MaterialAttributes("avatar",3.5f, 0.2f, 0f); | ||
123 | |||
124 | Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
125 | new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); | ||
126 | Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
127 | new MaterialAttributes("metalPhysical",dDensity, 0.3f, 0.4f); | ||
128 | Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
129 | new MaterialAttributes("glassPhysical",dDensity, 0.2f, 0.7f); | ||
130 | Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
131 | new MaterialAttributes("woodPhysical",dDensity, 0.6f, 0.5f); | ||
132 | Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
133 | new MaterialAttributes("fleshPhysical",dDensity, 0.9f, 0.3f); | ||
134 | Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
135 | new MaterialAttributes("plasticPhysical",dDensity, 0.4f, 0.7f); | ||
136 | Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
137 | new MaterialAttributes("rubberPhysical",dDensity, 0.9f, 0.9f); | ||
138 | Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
139 | new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); | ||
140 | Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = | ||
141 | new MaterialAttributes("avatarPhysical",3.5f, 0.2f, 0f); | ||
142 | } | ||
143 | |||
144 | // Under the [BulletSim] section, one can change the individual material | ||
145 | // attribute values. The format of the configuration parameter is: | ||
146 | // <materialName><Attribute>["Physical"] = floatValue | ||
147 | // For instance: | ||
148 | // [BulletSim] | ||
149 | // StoneFriction = 0.2 | ||
150 | // FleshRestitutionPhysical = 0.8 | ||
151 | // Materials can have different parameters for their static and | ||
152 | // physical instantiations. When setting the non-physical value, | ||
153 | // both values are changed. Setting the physical value only changes | ||
154 | // the physical value. | ||
155 | public static void InitializefromParameters(IConfig pConfig) | ||
156 | { | ||
157 | foreach (KeyValuePair<string, MaterialAttributes.Material> kvp in MaterialMap) | ||
158 | { | ||
159 | string matName = kvp.Key; | ||
160 | foreach (string attribName in MaterialAttributes.MaterialAttribs) | ||
161 | { | ||
162 | string paramName = matName + attribName; | ||
163 | if (pConfig.Contains(paramName)) | ||
164 | { | ||
165 | float paramValue = pConfig.GetFloat(paramName); | ||
166 | SetAttributeValue((int)kvp.Value, attribName, paramValue); | ||
167 | // set the physical value also | ||
168 | SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||
169 | } | ||
170 | paramName += "Physical"; | ||
171 | if (pConfig.Contains(paramName)) | ||
172 | { | ||
173 | float paramValue = pConfig.GetFloat(paramName); | ||
174 | SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | // Use reflection to set the value in the attribute structure. | ||
181 | private static void SetAttributeValue(int matType, string attribName, float val) | ||
182 | { | ||
183 | MaterialAttributes thisAttrib = Attributes[matType]; | ||
184 | FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower()); | ||
185 | if (fieldInfo != null) | ||
186 | { | ||
187 | fieldInfo.SetValue(thisAttrib, val); | ||
188 | Attributes[matType] = thisAttrib; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | // Given a material type, return a structure of attributes. | ||
193 | public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) | ||
194 | { | ||
195 | int ind = (int)type; | ||
196 | if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; | ||
197 | return Attributes[ind]; | ||
198 | } | ||
199 | } | ||
200 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index bc6e4c4..9501e2d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -1,104 +1,486 @@ | |||
1 | using System; | 1 | /* |
2 | using System.Collections.Generic; | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | using System.Text; | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | using OpenMetaverse; | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without | |
6 | namespace OpenSim.Region.Physics.BulletSPlugin | 6 | * modification, are permitted provided that the following conditions are met: |
7 | { | 7 | * * Redistributions of source code must retain the above copyright |
8 | public abstract class BSMotor | 8 | * notice, this list of conditions and the following disclaimer. |
9 | { | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | public virtual void Reset() { } | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | public virtual void Zero() { } | 11 | * documentation and/or other materials provided with the distribution. |
12 | } | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | // Can all the incremental stepping be replaced with motor classes? | 13 | * names of its contributors may be used to endorse or promote products |
14 | public class BSVMotor : BSMotor | 14 | * derived from this software without specific prior written permission. |
15 | { | 15 | * |
16 | public Vector3 FrameOfReference { get; set; } | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | public Vector3 Offset { get; set; } | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | public float TimeScale { get; set; } | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | public float TargetValueDecayTimeScale { get; set; } | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | public Vector3 CurrentValueReductionTimescale { get; set; } | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | public float Efficiency { get; set; } | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | public Vector3 TargetValue { get; private set; } | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | public Vector3 CurrentValue { get; private set; } | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | 26 | * | |
27 | 27 | */ | |
28 | 28 | using System; | |
29 | BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | 29 | using System.Collections.Generic; |
30 | { | 30 | using System.Text; |
31 | TimeScale = timeScale; | 31 | using OpenMetaverse; |
32 | TargetValueDecayTimeScale = decayTimeScale; | 32 | using OpenSim.Framework; |
33 | CurrentValueReductionTimescale = frictionTimeScale; | 33 | |
34 | Efficiency = efficiency; | 34 | namespace OpenSim.Region.Physics.BulletSPlugin |
35 | } | 35 | { |
36 | public void SetCurrent(Vector3 current) | 36 | public abstract class BSMotor |
37 | { | 37 | { |
38 | CurrentValue = current; | 38 | // Timescales and other things can be turned off by setting them to 'infinite'. |
39 | } | 39 | public const float Infinite = 12345.6f; |
40 | public void SetTarget(Vector3 target) | 40 | public readonly static Vector3 InfiniteVector = new Vector3(BSMotor.Infinite, BSMotor.Infinite, BSMotor.Infinite); |
41 | { | 41 | |
42 | TargetValue = target; | 42 | public BSMotor(string useName) |
43 | } | 43 | { |
44 | public Vector3 Step(float timeStep) | 44 | UseName = useName; |
45 | { | 45 | PhysicsScene = null; |
46 | if (CurrentValue.LengthSquared() > 0.001f) | 46 | Enabled = true; |
47 | { | 47 | } |
48 | // Vector3 origDir = Target; // DEBUG | 48 | public virtual bool Enabled { get; set; } |
49 | // Vector3 origVel = CurrentValue; // DEBUG | 49 | public virtual void Reset() { } |
50 | 50 | public virtual void Zero() { } | |
51 | // Add (desiredVelocity - currentAppliedVelocity) / howLongItShouldTakeToComplete | 51 | public virtual void GenerateTestOutput(float timeStep) { } |
52 | Vector3 addAmount = (TargetValue - CurrentValue)/(TargetValue) * timeStep; | 52 | |
53 | CurrentValue += addAmount; | 53 | // A name passed at motor creation for easily identifyable debugging messages. |
54 | 54 | public string UseName { get; private set; } | |
55 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | 55 | |
56 | TargetValue *= (1f - decayFactor); | 56 | // Used only for outputting debug information. Might not be set so check for null. |
57 | 57 | public BSScene PhysicsScene { get; set; } | |
58 | Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep; | 58 | protected void MDetailLog(string msg, params Object[] parms) |
59 | CurrentValue *= (Vector3.One - frictionFactor); | 59 | { |
60 | } | 60 | if (PhysicsScene != null) |
61 | else | 61 | { |
62 | { | 62 | PhysicsScene.DetailLog(msg, parms); |
63 | // if what remains of direction is very small, zero it. | 63 | } |
64 | TargetValue = Vector3.Zero; | 64 | } |
65 | CurrentValue = Vector3.Zero; | 65 | } |
66 | 66 | ||
67 | // VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); | 67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. |
68 | } | 68 | // The TargetValue decays in TargetValueDecayTimeScale and |
69 | return CurrentValue; | 69 | // the CurrentValue will be held back by FrictionTimeScale. |
70 | } | 70 | // This motor will "zero itself" over time in that the targetValue will |
71 | } | 71 | // decay to zero and the currentValue will follow it to that zero. |
72 | 72 | // The overall effect is for the returned correction value to go from large | |
73 | public class BSFMotor : BSMotor | 73 | // values (the total difference between current and target minus friction) |
74 | { | 74 | // to small and eventually zero values. |
75 | public float TimeScale { get; set; } | 75 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay. |
76 | public float DecayTimeScale { get; set; } | 76 | |
77 | public float Friction { get; set; } | 77 | // For instance, if something is moving at speed X and the desired speed is Y, |
78 | public float Efficiency { get; set; } | 78 | // CurrentValue is X and TargetValue is Y. As the motor is stepped, new |
79 | 79 | // values of CurrentValue are returned that approach the TargetValue. | |
80 | public float Target { get; private set; } | 80 | // The feature of decaying TargetValue is so vehicles will eventually |
81 | public float CurrentValue { get; private set; } | 81 | // come to a stop rather than run forever. This can be disabled by |
82 | 82 | // setting TargetValueDecayTimescale to 'infinite'. | |
83 | BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) | 83 | // The change from CurrentValue to TargetValue is linear over TimeScale seconds. |
84 | { | 84 | public class BSVMotor : BSMotor |
85 | } | 85 | { |
86 | public void SetCurrent(float target) | 86 | // public Vector3 FrameOfReference { get; set; } |
87 | { | 87 | // public Vector3 Offset { get; set; } |
88 | } | 88 | |
89 | public void SetTarget(float target) | 89 | public virtual float TimeScale { get; set; } |
90 | { | 90 | public virtual float TargetValueDecayTimeScale { get; set; } |
91 | } | 91 | public virtual Vector3 FrictionTimescale { get; set; } |
92 | public float Step(float timeStep) | 92 | public virtual float Efficiency { get; set; } |
93 | { | 93 | |
94 | return 0f; | 94 | public virtual float ErrorZeroThreshold { get; set; } |
95 | } | 95 | |
96 | } | 96 | public virtual Vector3 TargetValue { get; protected set; } |
97 | public class BSPIDMotor : BSMotor | 97 | public virtual Vector3 CurrentValue { get; protected set; } |
98 | { | 98 | public virtual Vector3 LastError { get; protected set; } |
99 | // TODO: write and use this one | 99 | |
100 | BSPIDMotor() | 100 | public virtual bool ErrorIsZero() |
101 | { | 101 | { |
102 | } | 102 | return ErrorIsZero(LastError); |
103 | } | 103 | } |
104 | } | 104 | public virtual bool ErrorIsZero(Vector3 err) |
105 | { | ||
106 | return (err == Vector3.Zero || err.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)); | ||
107 | } | ||
108 | |||
109 | public BSVMotor(string useName) | ||
110 | : base(useName) | ||
111 | { | ||
112 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | ||
113 | Efficiency = 1f; | ||
114 | FrictionTimescale = BSMotor.InfiniteVector; | ||
115 | CurrentValue = TargetValue = Vector3.Zero; | ||
116 | ErrorZeroThreshold = 0.001f; | ||
117 | } | ||
118 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | ||
119 | : this(useName) | ||
120 | { | ||
121 | TimeScale = timeScale; | ||
122 | TargetValueDecayTimeScale = decayTimeScale; | ||
123 | FrictionTimescale = frictionTimeScale; | ||
124 | Efficiency = efficiency; | ||
125 | CurrentValue = TargetValue = Vector3.Zero; | ||
126 | } | ||
127 | public void SetCurrent(Vector3 current) | ||
128 | { | ||
129 | CurrentValue = current; | ||
130 | } | ||
131 | public void SetTarget(Vector3 target) | ||
132 | { | ||
133 | TargetValue = target; | ||
134 | } | ||
135 | public override void Zero() | ||
136 | { | ||
137 | base.Zero(); | ||
138 | CurrentValue = TargetValue = Vector3.Zero; | ||
139 | } | ||
140 | |||
141 | // Compute the next step and return the new current value. | ||
142 | // Returns the correction needed to move 'current' to 'target'. | ||
143 | public virtual Vector3 Step(float timeStep) | ||
144 | { | ||
145 | if (!Enabled) return TargetValue; | ||
146 | |||
147 | Vector3 origTarget = TargetValue; // DEBUG | ||
148 | Vector3 origCurrVal = CurrentValue; // DEBUG | ||
149 | |||
150 | Vector3 correction = Vector3.Zero; | ||
151 | Vector3 error = TargetValue - CurrentValue; | ||
152 | LastError = error; | ||
153 | if (!ErrorIsZero(error)) | ||
154 | { | ||
155 | correction = StepError(timeStep, error); | ||
156 | |||
157 | CurrentValue += correction; | ||
158 | |||
159 | // The desired value reduces to zero which also reduces the difference with current. | ||
160 | // If the decay time is infinite, don't decay at all. | ||
161 | float decayFactor = 0f; | ||
162 | if (TargetValueDecayTimeScale != BSMotor.Infinite) | ||
163 | { | ||
164 | decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | ||
165 | TargetValue *= (1f - decayFactor); | ||
166 | } | ||
167 | |||
168 | // The amount we can correct the error is reduced by the friction | ||
169 | Vector3 frictionFactor = Vector3.Zero; | ||
170 | if (FrictionTimescale != BSMotor.InfiniteVector) | ||
171 | { | ||
172 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
173 | // Individual friction components can be 'infinite' so compute each separately. | ||
174 | frictionFactor.X = (FrictionTimescale.X == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.X); | ||
175 | frictionFactor.Y = (FrictionTimescale.Y == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Y); | ||
176 | frictionFactor.Z = (FrictionTimescale.Z == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Z); | ||
177 | frictionFactor *= timeStep; | ||
178 | CurrentValue *= (Vector3.One - frictionFactor); | ||
179 | } | ||
180 | |||
181 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | ||
182 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | ||
183 | timeStep, error, correction); | ||
184 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | ||
185 | BSScene.DetailLogZero, UseName, | ||
186 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
187 | TargetValue, CurrentValue); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | // Difference between what we have and target is small. Motor is done. | ||
192 | if (TargetValue.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)) | ||
193 | { | ||
194 | // The target can step down to nearly zero but not get there. If close to zero | ||
195 | // it is really zero. | ||
196 | TargetValue = Vector3.Zero; | ||
197 | } | ||
198 | CurrentValue = TargetValue; | ||
199 | MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},currTgt={4},currCurr={5}", | ||
200 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, TargetValue, CurrentValue); | ||
201 | } | ||
202 | |||
203 | return correction; | ||
204 | } | ||
205 | // version of step that sets the current value before doing the step | ||
206 | public virtual Vector3 Step(float timeStep, Vector3 current) | ||
207 | { | ||
208 | CurrentValue = current; | ||
209 | return Step(timeStep); | ||
210 | } | ||
211 | public virtual Vector3 StepError(float timeStep, Vector3 error) | ||
212 | { | ||
213 | if (!Enabled) return Vector3.Zero; | ||
214 | |||
215 | Vector3 returnCorrection = Vector3.Zero; | ||
216 | if (!ErrorIsZero(error)) | ||
217 | { | ||
218 | // correction = error / secondsItShouldTakeToCorrect | ||
219 | Vector3 correctionAmount; | ||
220 | if (TimeScale == 0f || TimeScale == BSMotor.Infinite) | ||
221 | correctionAmount = error * timeStep; | ||
222 | else | ||
223 | correctionAmount = error / TimeScale * timeStep; | ||
224 | |||
225 | returnCorrection = correctionAmount; | ||
226 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},timeStep={2},timeScale={3},err={4},corr={5}", | ||
227 | BSScene.DetailLogZero, UseName, timeStep, TimeScale, error, correctionAmount); | ||
228 | } | ||
229 | return returnCorrection; | ||
230 | } | ||
231 | |||
232 | // The user sets all the parameters and calls this which outputs values until error is zero. | ||
233 | public override void GenerateTestOutput(float timeStep) | ||
234 | { | ||
235 | // maximum number of outputs to generate. | ||
236 | int maxOutput = 50; | ||
237 | MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName); | ||
238 | MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},frictTS={4},eff={5},curr={6},tgt={7}", | ||
239 | BSScene.DetailLogZero, UseName, | ||
240 | TimeScale, TargetValueDecayTimeScale, FrictionTimescale, Efficiency, | ||
241 | CurrentValue, TargetValue); | ||
242 | |||
243 | LastError = BSMotor.InfiniteVector; | ||
244 | while (maxOutput-- > 0 && !LastError.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)) | ||
245 | { | ||
246 | Vector3 lastStep = Step(timeStep); | ||
247 | MDetailLog("{0},BSVMotor.Test,{1},cur={2},tgt={3},lastError={4},lastStep={5}", | ||
248 | BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, LastError, lastStep); | ||
249 | } | ||
250 | MDetailLog("{0},BSVMotor.Test,{1},===================================== END Test Output", BSScene.DetailLogZero, UseName); | ||
251 | |||
252 | |||
253 | } | ||
254 | |||
255 | public override string ToString() | ||
256 | { | ||
257 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | ||
258 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | // ============================================================================ | ||
263 | // ============================================================================ | ||
264 | public class BSFMotor : BSMotor | ||
265 | { | ||
266 | public virtual float TimeScale { get; set; } | ||
267 | public virtual float TargetValueDecayTimeScale { get; set; } | ||
268 | public virtual float FrictionTimescale { get; set; } | ||
269 | public virtual float Efficiency { get; set; } | ||
270 | |||
271 | public virtual float ErrorZeroThreshold { get; set; } | ||
272 | |||
273 | public virtual float TargetValue { get; protected set; } | ||
274 | public virtual float CurrentValue { get; protected set; } | ||
275 | public virtual float LastError { get; protected set; } | ||
276 | |||
277 | public virtual bool ErrorIsZero() | ||
278 | { | ||
279 | return ErrorIsZero(LastError); | ||
280 | } | ||
281 | public virtual bool ErrorIsZero(float err) | ||
282 | { | ||
283 | return (err >= -ErrorZeroThreshold && err <= ErrorZeroThreshold); | ||
284 | } | ||
285 | |||
286 | public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency) | ||
287 | : base(useName) | ||
288 | { | ||
289 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | ||
290 | Efficiency = 1f; | ||
291 | FrictionTimescale = BSMotor.Infinite; | ||
292 | CurrentValue = TargetValue = 0f; | ||
293 | ErrorZeroThreshold = 0.01f; | ||
294 | } | ||
295 | public void SetCurrent(float current) | ||
296 | { | ||
297 | CurrentValue = current; | ||
298 | } | ||
299 | public void SetTarget(float target) | ||
300 | { | ||
301 | TargetValue = target; | ||
302 | } | ||
303 | public override void Zero() | ||
304 | { | ||
305 | base.Zero(); | ||
306 | CurrentValue = TargetValue = 0f; | ||
307 | } | ||
308 | |||
309 | public virtual float Step(float timeStep) | ||
310 | { | ||
311 | if (!Enabled) return TargetValue; | ||
312 | |||
313 | float origTarget = TargetValue; // DEBUG | ||
314 | float origCurrVal = CurrentValue; // DEBUG | ||
315 | |||
316 | float correction = 0f; | ||
317 | float error = TargetValue - CurrentValue; | ||
318 | LastError = error; | ||
319 | if (!ErrorIsZero(error)) | ||
320 | { | ||
321 | correction = StepError(timeStep, error); | ||
322 | |||
323 | CurrentValue += correction; | ||
324 | |||
325 | // The desired value reduces to zero which also reduces the difference with current. | ||
326 | // If the decay time is infinite, don't decay at all. | ||
327 | float decayFactor = 0f; | ||
328 | if (TargetValueDecayTimeScale != BSMotor.Infinite) | ||
329 | { | ||
330 | decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | ||
331 | TargetValue *= (1f - decayFactor); | ||
332 | } | ||
333 | |||
334 | // The amount we can correct the error is reduced by the friction | ||
335 | float frictionFactor = 0f; | ||
336 | if (FrictionTimescale != BSMotor.Infinite) | ||
337 | { | ||
338 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
339 | // Individual friction components can be 'infinite' so compute each separately. | ||
340 | frictionFactor = 1f / FrictionTimescale; | ||
341 | frictionFactor *= timeStep; | ||
342 | CurrentValue *= (1f - frictionFactor); | ||
343 | } | ||
344 | |||
345 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | ||
346 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | ||
347 | timeStep, error, correction); | ||
348 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | ||
349 | BSScene.DetailLogZero, UseName, | ||
350 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
351 | TargetValue, CurrentValue); | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | // Difference between what we have and target is small. Motor is done. | ||
356 | if (Util.InRange<float>(TargetValue, -ErrorZeroThreshold, ErrorZeroThreshold)) | ||
357 | { | ||
358 | // The target can step down to nearly zero but not get there. If close to zero | ||
359 | // it is really zero. | ||
360 | TargetValue = 0f; | ||
361 | } | ||
362 | CurrentValue = TargetValue; | ||
363 | MDetailLog("{0}, BSFMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", | ||
364 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); | ||
365 | } | ||
366 | |||
367 | return CurrentValue; | ||
368 | } | ||
369 | |||
370 | public virtual float StepError(float timeStep, float error) | ||
371 | { | ||
372 | if (!Enabled) return 0f; | ||
373 | |||
374 | float returnCorrection = 0f; | ||
375 | if (!ErrorIsZero(error)) | ||
376 | { | ||
377 | // correction = error / secondsItShouldTakeToCorrect | ||
378 | float correctionAmount; | ||
379 | if (TimeScale == 0f || TimeScale == BSMotor.Infinite) | ||
380 | correctionAmount = error * timeStep; | ||
381 | else | ||
382 | correctionAmount = error / TimeScale * timeStep; | ||
383 | |||
384 | returnCorrection = correctionAmount; | ||
385 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},timeStep={2},timeScale={3},err={4},corr={5}", | ||
386 | BSScene.DetailLogZero, UseName, timeStep, TimeScale, error, correctionAmount); | ||
387 | } | ||
388 | return returnCorrection; | ||
389 | } | ||
390 | |||
391 | public override string ToString() | ||
392 | { | ||
393 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | ||
394 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | ||
395 | } | ||
396 | |||
397 | } | ||
398 | |||
399 | // ============================================================================ | ||
400 | // ============================================================================ | ||
401 | // Proportional, Integral, Derivitive Motor | ||
402 | // Good description at http://www.answers.com/topic/pid-controller . Includes processes for choosing p, i and d factors. | ||
403 | public class BSPIDVMotor : BSVMotor | ||
404 | { | ||
405 | // Larger makes more overshoot, smaller means converge quicker. Range of 0.1 to 10. | ||
406 | public Vector3 proportionFactor { get; set; } | ||
407 | public Vector3 integralFactor { get; set; } | ||
408 | public Vector3 derivFactor { get; set; } | ||
409 | |||
410 | // The factors are vectors for the three dimensions. This is the proportional of each | ||
411 | // that is applied. This could be multiplied through the actual factors but it | ||
412 | // is sometimes easier to manipulate the factors and their mix separately. | ||
413 | // to | ||
414 | public Vector3 FactorMix; | ||
415 | |||
416 | // Arbritrary factor range. | ||
417 | // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct. | ||
418 | public float EfficiencyHigh = 0.4f; | ||
419 | public float EfficiencyLow = 4.0f; | ||
420 | |||
421 | // Running integration of the error | ||
422 | Vector3 RunningIntegration { get; set; } | ||
423 | |||
424 | public BSPIDVMotor(string useName) | ||
425 | : base(useName) | ||
426 | { | ||
427 | proportionFactor = new Vector3(1.00f, 1.00f, 1.00f); | ||
428 | integralFactor = new Vector3(1.00f, 1.00f, 1.00f); | ||
429 | derivFactor = new Vector3(1.00f, 1.00f, 1.00f); | ||
430 | FactorMix = new Vector3(0.5f, 0.25f, 0.25f); | ||
431 | RunningIntegration = Vector3.Zero; | ||
432 | LastError = Vector3.Zero; | ||
433 | } | ||
434 | |||
435 | public override void Zero() | ||
436 | { | ||
437 | base.Zero(); | ||
438 | } | ||
439 | |||
440 | public override float Efficiency | ||
441 | { | ||
442 | get { return base.Efficiency; } | ||
443 | set | ||
444 | { | ||
445 | base.Efficiency = Util.Clamp(value, 0f, 1f); | ||
446 | |||
447 | // Compute factors based on efficiency. | ||
448 | // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot. | ||
449 | // If efficiency is low (0f), use a factor value that overcorrects. | ||
450 | // TODO: might want to vary contribution of different factor depending on efficiency. | ||
451 | float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f; | ||
452 | // float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow; | ||
453 | |||
454 | proportionFactor = new Vector3(factor, factor, factor); | ||
455 | integralFactor = new Vector3(factor, factor, factor); | ||
456 | derivFactor = new Vector3(factor, factor, factor); | ||
457 | |||
458 | MDetailLog("{0},BSPIDVMotor.setEfficiency,eff={1},factor={2}", BSScene.DetailLogZero, Efficiency, factor); | ||
459 | } | ||
460 | } | ||
461 | |||
462 | // Advance the PID computation on this error. | ||
463 | public override Vector3 StepError(float timeStep, Vector3 error) | ||
464 | { | ||
465 | if (!Enabled) return Vector3.Zero; | ||
466 | |||
467 | // Add up the error so we can integrate over the accumulated errors | ||
468 | RunningIntegration += error * timeStep; | ||
469 | |||
470 | // A simple derivitive is the rate of change from the last error. | ||
471 | Vector3 derivitive = (error - LastError) * timeStep; | ||
472 | LastError = error; | ||
473 | |||
474 | // Correction = (proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) | ||
475 | Vector3 ret = error * timeStep * proportionFactor * FactorMix.X | ||
476 | + RunningIntegration * integralFactor * FactorMix.Y | ||
477 | + derivitive * derivFactor * FactorMix.Z | ||
478 | ; | ||
479 | |||
480 | MDetailLog("{0},BSPIDVMotor.step,ts={1},err={2},runnInt={3},deriv={4},ret={5}", | ||
481 | BSScene.DetailLogZero, timeStep, error, RunningIntegration, derivitive, ret); | ||
482 | |||
483 | return ret; | ||
484 | } | ||
485 | } | ||
486 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs new file mode 100755 index 0000000..da7438a --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -0,0 +1,660 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | using OpenSim.Region.Physics.Manager; | ||
32 | |||
33 | using OpenMetaverse; | ||
34 | using Nini.Config; | ||
35 | |||
36 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
37 | { | ||
38 | public static class BSParam | ||
39 | { | ||
40 | // Level of Detail values kept as float because that's what the Meshmerizer wants | ||
41 | public static float MeshLOD { get; private set; } | ||
42 | public static float MeshMegaPrimLOD { get; private set; } | ||
43 | public static float MeshMegaPrimThreshold { get; private set; } | ||
44 | public static float SculptLOD { get; private set; } | ||
45 | |||
46 | public static float MinimumObjectMass { get; private set; } | ||
47 | public static float MaximumObjectMass { get; private set; } | ||
48 | public static float MaxLinearVelocity { get; private set; } | ||
49 | public static float MaxAngularVelocity { get; private set; } | ||
50 | public static float MaxAddForceMagnitude { get; private set; } | ||
51 | |||
52 | public static float LinearDamping { get; private set; } | ||
53 | public static float AngularDamping { get; private set; } | ||
54 | public static float DeactivationTime { get; private set; } | ||
55 | public static float LinearSleepingThreshold { get; private set; } | ||
56 | public static float AngularSleepingThreshold { get; private set; } | ||
57 | public static float CcdMotionThreshold { get; private set; } | ||
58 | public static float CcdSweptSphereRadius { get; private set; } | ||
59 | public static float ContactProcessingThreshold { get; private set; } | ||
60 | |||
61 | public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed | ||
62 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes | ||
63 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | ||
64 | |||
65 | public static float TerrainImplementation { get; private set; } | ||
66 | public static float TerrainFriction { get; private set; } | ||
67 | public static float TerrainHitFraction { get; private set; } | ||
68 | public static float TerrainRestitution { get; private set; } | ||
69 | public static float TerrainCollisionMargin { get; private set; } | ||
70 | |||
71 | // Avatar parameters | ||
72 | public static float AvatarFriction { get; private set; } | ||
73 | public static float AvatarStandingFriction { get; private set; } | ||
74 | public static float AvatarAlwaysRunFactor { get; private set; } | ||
75 | public static float AvatarDensity { get; private set; } | ||
76 | public static float AvatarRestitution { get; private set; } | ||
77 | public static float AvatarCapsuleWidth { get; private set; } | ||
78 | public static float AvatarCapsuleDepth { get; private set; } | ||
79 | public static float AvatarCapsuleHeight { get; private set; } | ||
80 | public static float AvatarContactProcessingThreshold { get; private set; } | ||
81 | public static float AvatarStepHeight { get; private set; } | ||
82 | public static float AvatarStepApproachFactor { get; private set; } | ||
83 | public static float AvatarStepForceFactor { get; private set; } | ||
84 | |||
85 | public static float VehicleMaxLinearVelocity { get; private set; } | ||
86 | public static float VehicleMaxAngularVelocity { get; private set; } | ||
87 | public static float VehicleAngularDamping { get; private set; } | ||
88 | public static float VehicleDebuggingEnabled { get; private set; } | ||
89 | |||
90 | public static float LinksetImplementation { get; private set; } | ||
91 | public static float LinkConstraintUseFrameOffset { get; private set; } | ||
92 | public static float LinkConstraintEnableTransMotor { get; private set; } | ||
93 | public static float LinkConstraintTransMotorMaxVel { get; private set; } | ||
94 | public static float LinkConstraintTransMotorMaxForce { get; private set; } | ||
95 | public static float LinkConstraintERP { get; private set; } | ||
96 | public static float LinkConstraintCFM { get; private set; } | ||
97 | public static float LinkConstraintSolverIterations { get; private set; } | ||
98 | |||
99 | public static float PID_D { get; private set; } // derivative | ||
100 | public static float PID_P { get; private set; } // proportional | ||
101 | |||
102 | // Various constants that come from that other virtual world that shall not be named. | ||
103 | public const float MinGravityZ = -1f; | ||
104 | public const float MaxGravityZ = 28f; | ||
105 | public const float MinFriction = 0f; | ||
106 | public const float MaxFriction = 255f; | ||
107 | public const float MinDensity = 0.01f; | ||
108 | public const float MaxDensity = 22587f; | ||
109 | public const float MinRestitution = 0f; | ||
110 | public const float MaxRestitution = 1f; | ||
111 | |||
112 | // =========================================================================== | ||
113 | public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); | ||
114 | public delegate float ParamGet(BSScene scene); | ||
115 | public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); | ||
116 | public delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val); | ||
117 | |||
118 | public struct ParameterDefn | ||
119 | { | ||
120 | public string name; // string name of the parameter | ||
121 | public string desc; // a short description of what the parameter means | ||
122 | public float defaultValue; // default value if not specified anywhere else | ||
123 | public ParamUser userParam; // get the value from the configuration file | ||
124 | public ParamGet getter; // return the current value stored for this parameter | ||
125 | public ParamSet setter; // set the current value for this parameter | ||
126 | public SetOnObject onObject; // set the value on an object in the physical domain | ||
127 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) | ||
128 | { | ||
129 | name = n; | ||
130 | desc = d; | ||
131 | defaultValue = v; | ||
132 | userParam = u; | ||
133 | getter = g; | ||
134 | setter = s; | ||
135 | onObject = null; | ||
136 | } | ||
137 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o) | ||
138 | { | ||
139 | name = n; | ||
140 | desc = d; | ||
141 | defaultValue = v; | ||
142 | userParam = u; | ||
143 | getter = g; | ||
144 | setter = s; | ||
145 | onObject = o; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | // List of all of the externally visible parameters. | ||
150 | // For each parameter, this table maps a text name to getter and setters. | ||
151 | // To add a new externally referencable/settable parameter, add the paramter storage | ||
152 | // location somewhere in the program and make an entry in this table with the | ||
153 | // getters and setters. | ||
154 | // It is easiest to find an existing definition and copy it. | ||
155 | // Parameter values are floats. Booleans are converted to a floating value. | ||
156 | // | ||
157 | // A ParameterDefn() takes the following parameters: | ||
158 | // -- the text name of the parameter. This is used for console input and ini file. | ||
159 | // -- a short text description of the parameter. This shows up in the console listing. | ||
160 | // -- a default value (float) | ||
161 | // -- a delegate for fetching the parameter from the ini file. | ||
162 | // Should handle fetching the right type from the ini file and converting it. | ||
163 | // -- a delegate for getting the value as a float | ||
164 | // -- a delegate for setting the value from a float | ||
165 | // -- an optional delegate to update the value in the world. Most often used to | ||
166 | // push the new value to an in-world object. | ||
167 | // | ||
168 | // The single letter parameters for the delegates are: | ||
169 | // s = BSScene | ||
170 | // o = BSPhysObject | ||
171 | // p = string parameter name | ||
172 | // l = localID of referenced object | ||
173 | // v = value (float) | ||
174 | // cf = parameter configuration class (for fetching values from ini file) | ||
175 | private static ParameterDefn[] ParameterDefinitions = | ||
176 | { | ||
177 | new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties", | ||
178 | ConfigurationParameters.numericTrue, | ||
179 | (s,cf,p,v) => { ShouldMeshSculptedPrim = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, | ||
180 | (s) => { return BSParam.NumericBool(ShouldMeshSculptedPrim); }, | ||
181 | (s,p,l,v) => { ShouldMeshSculptedPrim = BSParam.BoolNumeric(v); } ), | ||
182 | new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects", | ||
183 | ConfigurationParameters.numericFalse, | ||
184 | (s,cf,p,v) => { ShouldForceSimplePrimMeshing = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, | ||
185 | (s) => { return BSParam.NumericBool(ShouldForceSimplePrimMeshing); }, | ||
186 | (s,p,l,v) => { ShouldForceSimplePrimMeshing = BSParam.BoolNumeric(v); } ), | ||
187 | new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects", | ||
188 | ConfigurationParameters.numericTrue, | ||
189 | (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, | ||
190 | (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, | ||
191 | (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ), | ||
192 | |||
193 | new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | ||
194 | 8f, | ||
195 | (s,cf,p,v) => { MeshLOD = (float)cf.GetInt(p, (int)v); }, | ||
196 | (s) => { return MeshLOD; }, | ||
197 | (s,p,l,v) => { MeshLOD = v; } ), | ||
198 | new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters", | ||
199 | 16f, | ||
200 | (s,cf,p,v) => { MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); }, | ||
201 | (s) => { return MeshMegaPrimLOD; }, | ||
202 | (s,p,l,v) => { MeshMegaPrimLOD = v; } ), | ||
203 | new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD", | ||
204 | 10f, | ||
205 | (s,cf,p,v) => { MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); }, | ||
206 | (s) => { return MeshMegaPrimThreshold; }, | ||
207 | (s,p,l,v) => { MeshMegaPrimThreshold = v; } ), | ||
208 | new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | ||
209 | 32f, | ||
210 | (s,cf,p,v) => { SculptLOD = (float)cf.GetInt(p, (int)v); }, | ||
211 | (s) => { return SculptLOD; }, | ||
212 | (s,p,l,v) => { SculptLOD = v; } ), | ||
213 | |||
214 | new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps", | ||
215 | 10f, | ||
216 | (s,cf,p,v) => { s.m_maxSubSteps = cf.GetInt(p, (int)v); }, | ||
217 | (s) => { return (float)s.m_maxSubSteps; }, | ||
218 | (s,p,l,v) => { s.m_maxSubSteps = (int)v; } ), | ||
219 | new ParameterDefn("FixedTimeStep", "In simulation step, seconds of one substep (1/60)", | ||
220 | 1f / 60f, | ||
221 | (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); }, | ||
222 | (s) => { return (float)s.m_fixedTimeStep; }, | ||
223 | (s,p,l,v) => { s.m_fixedTimeStep = v; } ), | ||
224 | new ParameterDefn("NominalFrameRate", "The base frame rate we claim", | ||
225 | 55f, | ||
226 | (s,cf,p,v) => { s.NominalFrameRate = cf.GetInt(p, (int)v); }, | ||
227 | (s) => { return (float)s.NominalFrameRate; }, | ||
228 | (s,p,l,v) => { s.NominalFrameRate = (int)v; } ), | ||
229 | new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame", | ||
230 | 2048f, | ||
231 | (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); }, | ||
232 | (s) => { return (float)s.m_maxCollisionsPerFrame; }, | ||
233 | (s,p,l,v) => { s.m_maxCollisionsPerFrame = (int)v; } ), | ||
234 | new ParameterDefn("MaxUpdatesPerFrame", "Max updates returned at end of each frame", | ||
235 | 8000f, | ||
236 | (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); }, | ||
237 | (s) => { return (float)s.m_maxUpdatesPerFrame; }, | ||
238 | (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ), | ||
239 | |||
240 | new ParameterDefn("MinObjectMass", "Minimum object mass (0.0001)", | ||
241 | 0.0001f, | ||
242 | (s,cf,p,v) => { MinimumObjectMass = cf.GetFloat(p, v); }, | ||
243 | (s) => { return (float)MinimumObjectMass; }, | ||
244 | (s,p,l,v) => { MinimumObjectMass = v; } ), | ||
245 | new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)", | ||
246 | 10000.01f, | ||
247 | (s,cf,p,v) => { MaximumObjectMass = cf.GetFloat(p, v); }, | ||
248 | (s) => { return (float)MaximumObjectMass; }, | ||
249 | (s,p,l,v) => { MaximumObjectMass = v; } ), | ||
250 | new ParameterDefn("MaxLinearVelocity", "Maximum velocity magnitude that can be assigned to an object", | ||
251 | 1000.0f, | ||
252 | (s,cf,p,v) => { MaxLinearVelocity = cf.GetFloat(p, v); }, | ||
253 | (s) => { return (float)MaxLinearVelocity; }, | ||
254 | (s,p,l,v) => { MaxLinearVelocity = v; } ), | ||
255 | new ParameterDefn("MaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to an object", | ||
256 | 1000.0f, | ||
257 | (s,cf,p,v) => { MaxAngularVelocity = cf.GetFloat(p, v); }, | ||
258 | (s) => { return (float)MaxAngularVelocity; }, | ||
259 | (s,p,l,v) => { MaxAngularVelocity = v; } ), | ||
260 | // LL documentation says thie number should be 20f for llApplyImpulse and 200f for llRezObject | ||
261 | new ParameterDefn("MaxAddForceMagnitude", "Maximum force that can be applied by llApplyImpulse (SL says 20f)", | ||
262 | 20000.0f, | ||
263 | (s,cf,p,v) => { MaxAddForceMagnitude = cf.GetFloat(p, v); }, | ||
264 | (s) => { return (float)MaxAddForceMagnitude; }, | ||
265 | (s,p,l,v) => { MaxAddForceMagnitude = v; } ), | ||
266 | |||
267 | new ParameterDefn("PID_D", "Derivitive factor for motion smoothing", | ||
268 | 2200f, | ||
269 | (s,cf,p,v) => { PID_D = cf.GetFloat(p, v); }, | ||
270 | (s) => { return (float)PID_D; }, | ||
271 | (s,p,l,v) => { PID_D = v; } ), | ||
272 | new ParameterDefn("PID_P", "Parameteric factor for motion smoothing", | ||
273 | 900f, | ||
274 | (s,cf,p,v) => { PID_P = cf.GetFloat(p, v); }, | ||
275 | (s) => { return (float)PID_P; }, | ||
276 | (s,p,l,v) => { PID_P = v; } ), | ||
277 | |||
278 | new ParameterDefn("DefaultFriction", "Friction factor used on new objects", | ||
279 | 0.2f, | ||
280 | (s,cf,p,v) => { s.UnmanagedParams[0].defaultFriction = cf.GetFloat(p, v); }, | ||
281 | (s) => { return s.UnmanagedParams[0].defaultFriction; }, | ||
282 | (s,p,l,v) => { s.UnmanagedParams[0].defaultFriction = v; } ), | ||
283 | new ParameterDefn("DefaultDensity", "Density for new objects" , | ||
284 | 10.000006836f, // Aluminum g/cm3 | ||
285 | (s,cf,p,v) => { s.UnmanagedParams[0].defaultDensity = cf.GetFloat(p, v); }, | ||
286 | (s) => { return s.UnmanagedParams[0].defaultDensity; }, | ||
287 | (s,p,l,v) => { s.UnmanagedParams[0].defaultDensity = v; } ), | ||
288 | new ParameterDefn("DefaultRestitution", "Bouncyness of an object" , | ||
289 | 0f, | ||
290 | (s,cf,p,v) => { s.UnmanagedParams[0].defaultRestitution = cf.GetFloat(p, v); }, | ||
291 | (s) => { return s.UnmanagedParams[0].defaultRestitution; }, | ||
292 | (s,p,l,v) => { s.UnmanagedParams[0].defaultRestitution = v; } ), | ||
293 | new ParameterDefn("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)", | ||
294 | 0.04f, | ||
295 | (s,cf,p,v) => { s.UnmanagedParams[0].collisionMargin = cf.GetFloat(p, v); }, | ||
296 | (s) => { return s.UnmanagedParams[0].collisionMargin; }, | ||
297 | (s,p,l,v) => { s.UnmanagedParams[0].collisionMargin = v; } ), | ||
298 | new ParameterDefn("Gravity", "Vertical force of gravity (negative means down)", | ||
299 | -9.80665f, | ||
300 | (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); }, | ||
301 | (s) => { return s.UnmanagedParams[0].gravity; }, | ||
302 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); }, | ||
303 | (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ), | ||
304 | |||
305 | |||
306 | new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", | ||
307 | 0f, | ||
308 | (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); }, | ||
309 | (s) => { return LinearDamping; }, | ||
310 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); }, | ||
311 | (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ), | ||
312 | new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", | ||
313 | 0f, | ||
314 | (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); }, | ||
315 | (s) => { return AngularDamping; }, | ||
316 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); }, | ||
317 | (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ), | ||
318 | new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", | ||
319 | 0.2f, | ||
320 | (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); }, | ||
321 | (s) => { return DeactivationTime; }, | ||
322 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); }, | ||
323 | (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ), | ||
324 | new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", | ||
325 | 0.8f, | ||
326 | (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); }, | ||
327 | (s) => { return LinearSleepingThreshold; }, | ||
328 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); }, | ||
329 | (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ), | ||
330 | new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", | ||
331 | 1.0f, | ||
332 | (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); }, | ||
333 | (s) => { return AngularSleepingThreshold; }, | ||
334 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); }, | ||
335 | (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ), | ||
336 | new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , | ||
337 | 0.3f, // set to zero to disable | ||
338 | (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); }, | ||
339 | (s) => { return CcdMotionThreshold; }, | ||
340 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); }, | ||
341 | (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ), | ||
342 | new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , | ||
343 | 0.2f, | ||
344 | (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); }, | ||
345 | (s) => { return CcdSweptSphereRadius; }, | ||
346 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); }, | ||
347 | (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ), | ||
348 | new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , | ||
349 | 0.1f, | ||
350 | (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); }, | ||
351 | (s) => { return ContactProcessingThreshold; }, | ||
352 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); }, | ||
353 | (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ), | ||
354 | |||
355 | new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", | ||
356 | (float)BSTerrainPhys.TerrainImplementation.Mesh, | ||
357 | (s,cf,p,v) => { TerrainImplementation = cf.GetFloat(p,v); }, | ||
358 | (s) => { return TerrainImplementation; }, | ||
359 | (s,p,l,v) => { TerrainImplementation = v; } ), | ||
360 | new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" , | ||
361 | 0.3f, | ||
362 | (s,cf,p,v) => { TerrainFriction = cf.GetFloat(p, v); }, | ||
363 | (s) => { return TerrainFriction; }, | ||
364 | (s,p,l,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ), | ||
365 | new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" , | ||
366 | 0.8f, | ||
367 | (s,cf,p,v) => { TerrainHitFraction = cf.GetFloat(p, v); }, | ||
368 | (s) => { return TerrainHitFraction; }, | ||
369 | (s,p,l,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ), | ||
370 | new ParameterDefn("TerrainRestitution", "Bouncyness" , | ||
371 | 0f, | ||
372 | (s,cf,p,v) => { TerrainRestitution = cf.GetFloat(p, v); }, | ||
373 | (s) => { return TerrainRestitution; }, | ||
374 | (s,p,l,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ), | ||
375 | new ParameterDefn("TerrainCollisionMargin", "Margin where collision checking starts" , | ||
376 | 0.04f, | ||
377 | (s,cf,p,v) => { TerrainCollisionMargin = cf.GetFloat(p, v); }, | ||
378 | (s) => { return TerrainCollisionMargin; }, | ||
379 | (s,p,l,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ), | ||
380 | |||
381 | new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", | ||
382 | 0.2f, | ||
383 | (s,cf,p,v) => { AvatarFriction = cf.GetFloat(p, v); }, | ||
384 | (s) => { return AvatarFriction; }, | ||
385 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarFriction=x;}, p, l, v); } ), | ||
386 | new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | ||
387 | 10.0f, | ||
388 | (s,cf,p,v) => { AvatarStandingFriction = cf.GetFloat(p, v); }, | ||
389 | (s) => { return AvatarStandingFriction; }, | ||
390 | (s,p,l,v) => { AvatarStandingFriction = v; } ), | ||
391 | new ParameterDefn("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run", | ||
392 | 1.3f, | ||
393 | (s,cf,p,v) => { AvatarAlwaysRunFactor = cf.GetFloat(p, v); }, | ||
394 | (s) => { return AvatarAlwaysRunFactor; }, | ||
395 | (s,p,l,v) => { AvatarAlwaysRunFactor = v; } ), | ||
396 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | ||
397 | 3.5f, | ||
398 | (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); }, | ||
399 | (s) => { return AvatarDensity; }, | ||
400 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ), | ||
401 | new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | ||
402 | 0f, | ||
403 | (s,cf,p,v) => { AvatarRestitution = cf.GetFloat(p, v); }, | ||
404 | (s) => { return AvatarRestitution; }, | ||
405 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarRestitution=x;}, p, l, v); } ), | ||
406 | new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", | ||
407 | 0.6f, | ||
408 | (s,cf,p,v) => { AvatarCapsuleWidth = cf.GetFloat(p, v); }, | ||
409 | (s) => { return AvatarCapsuleWidth; }, | ||
410 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleWidth=x;}, p, l, v); } ), | ||
411 | new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", | ||
412 | 0.45f, | ||
413 | (s,cf,p,v) => { AvatarCapsuleDepth = cf.GetFloat(p, v); }, | ||
414 | (s) => { return AvatarCapsuleDepth; }, | ||
415 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleDepth=x;}, p, l, v); } ), | ||
416 | new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", | ||
417 | 1.5f, | ||
418 | (s,cf,p,v) => { AvatarCapsuleHeight = cf.GetFloat(p, v); }, | ||
419 | (s) => { return AvatarCapsuleHeight; }, | ||
420 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleHeight=x;}, p, l, v); } ), | ||
421 | new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | ||
422 | 0.1f, | ||
423 | (s,cf,p,v) => { AvatarContactProcessingThreshold = cf.GetFloat(p, v); }, | ||
424 | (s) => { return AvatarContactProcessingThreshold; }, | ||
425 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarContactProcessingThreshold=x;}, p, l, v); } ), | ||
426 | new ParameterDefn("AvatarStepHeight", "Height of a step obstacle to consider step correction", | ||
427 | 0.3f, | ||
428 | (s,cf,p,v) => { AvatarStepHeight = cf.GetFloat(p, v); }, | ||
429 | (s) => { return AvatarStepHeight; }, | ||
430 | (s,p,l,v) => { AvatarStepHeight = v; } ), | ||
431 | new ParameterDefn("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", | ||
432 | 0.6f, | ||
433 | (s,cf,p,v) => { AvatarStepApproachFactor = cf.GetFloat(p, v); }, | ||
434 | (s) => { return AvatarStepApproachFactor; }, | ||
435 | (s,p,l,v) => { AvatarStepApproachFactor = v; } ), | ||
436 | new ParameterDefn("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step", | ||
437 | 2.0f, | ||
438 | (s,cf,p,v) => { AvatarStepForceFactor = cf.GetFloat(p, v); }, | ||
439 | (s) => { return AvatarStepForceFactor; }, | ||
440 | (s,p,l,v) => { AvatarStepForceFactor = v; } ), | ||
441 | |||
442 | new ParameterDefn("VehicleMaxLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle", | ||
443 | 1000.0f, | ||
444 | (s,cf,p,v) => { VehicleMaxLinearVelocity = cf.GetFloat(p, v); }, | ||
445 | (s) => { return (float)VehicleMaxLinearVelocity; }, | ||
446 | (s,p,l,v) => { VehicleMaxLinearVelocity = v; } ), | ||
447 | new ParameterDefn("VehicleMaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to a vehicle", | ||
448 | 12.0f, | ||
449 | (s,cf,p,v) => { VehicleMaxAngularVelocity = cf.GetFloat(p, v); }, | ||
450 | (s) => { return (float)VehicleMaxAngularVelocity; }, | ||
451 | (s,p,l,v) => { VehicleMaxAngularVelocity = v; } ), | ||
452 | new ParameterDefn("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)", | ||
453 | 0.0f, | ||
454 | (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); }, | ||
455 | (s) => { return VehicleAngularDamping; }, | ||
456 | (s,p,l,v) => { VehicleAngularDamping = v; } ), | ||
457 | new ParameterDefn("VehicleDebuggingEnable", "Turn on/off vehicle debugging", | ||
458 | ConfigurationParameters.numericFalse, | ||
459 | (s,cf,p,v) => { VehicleDebuggingEnabled = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
460 | (s) => { return VehicleDebuggingEnabled; }, | ||
461 | (s,p,l,v) => { VehicleDebuggingEnabled = v; } ), | ||
462 | |||
463 | new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", | ||
464 | 0f, | ||
465 | (s,cf,p,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); }, | ||
466 | (s) => { return s.UnmanagedParams[0].maxPersistantManifoldPoolSize; }, | ||
467 | (s,p,l,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ), | ||
468 | new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", | ||
469 | 0f, | ||
470 | (s,cf,p,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); }, | ||
471 | (s) => { return s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize; }, | ||
472 | (s,p,l,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ), | ||
473 | new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", | ||
474 | ConfigurationParameters.numericFalse, | ||
475 | (s,cf,p,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
476 | (s) => { return s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation; }, | ||
477 | (s,p,l,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = v; } ), | ||
478 | new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", | ||
479 | ConfigurationParameters.numericFalse, | ||
480 | (s,cf,p,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
481 | (s) => { return s.UnmanagedParams[0].shouldForceUpdateAllAabbs; }, | ||
482 | (s,p,l,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = v; } ), | ||
483 | new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction", | ||
484 | ConfigurationParameters.numericTrue, | ||
485 | (s,cf,p,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
486 | (s) => { return s.UnmanagedParams[0].shouldRandomizeSolverOrder; }, | ||
487 | (s,p,l,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = v; } ), | ||
488 | new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", | ||
489 | ConfigurationParameters.numericTrue, | ||
490 | (s,cf,p,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
491 | (s) => { return s.UnmanagedParams[0].shouldSplitSimulationIslands; }, | ||
492 | (s,p,l,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = v; } ), | ||
493 | new ParameterDefn("ShouldEnableFrictionCaching", "Enable friction computation caching", | ||
494 | ConfigurationParameters.numericTrue, | ||
495 | (s,cf,p,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
496 | (s) => { return s.UnmanagedParams[0].shouldEnableFrictionCaching; }, | ||
497 | (s,p,l,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = v; } ), | ||
498 | new ParameterDefn("NumberOfSolverIterations", "Number of internal iterations (0 means default)", | ||
499 | 0f, // zero says use Bullet default | ||
500 | (s,cf,p,v) => { s.UnmanagedParams[0].numberOfSolverIterations = cf.GetFloat(p, v); }, | ||
501 | (s) => { return s.UnmanagedParams[0].numberOfSolverIterations; }, | ||
502 | (s,p,l,v) => { s.UnmanagedParams[0].numberOfSolverIterations = v; } ), | ||
503 | |||
504 | new ParameterDefn("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | ||
505 | (float)BSLinkset.LinksetImplementation.Compound, | ||
506 | (s,cf,p,v) => { LinksetImplementation = cf.GetFloat(p,v); }, | ||
507 | (s) => { return LinksetImplementation; }, | ||
508 | (s,p,l,v) => { LinksetImplementation = v; } ), | ||
509 | new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", | ||
510 | ConfigurationParameters.numericFalse, | ||
511 | (s,cf,p,v) => { LinkConstraintUseFrameOffset = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
512 | (s) => { return LinkConstraintUseFrameOffset; }, | ||
513 | (s,p,l,v) => { LinkConstraintUseFrameOffset = v; } ), | ||
514 | new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", | ||
515 | ConfigurationParameters.numericTrue, | ||
516 | (s,cf,p,v) => { LinkConstraintEnableTransMotor = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, | ||
517 | (s) => { return LinkConstraintEnableTransMotor; }, | ||
518 | (s,p,l,v) => { LinkConstraintEnableTransMotor = v; } ), | ||
519 | new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints", | ||
520 | 5.0f, | ||
521 | (s,cf,p,v) => { LinkConstraintTransMotorMaxVel = cf.GetFloat(p, v); }, | ||
522 | (s) => { return LinkConstraintTransMotorMaxVel; }, | ||
523 | (s,p,l,v) => { LinkConstraintTransMotorMaxVel = v; } ), | ||
524 | new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints", | ||
525 | 0.1f, | ||
526 | (s,cf,p,v) => { LinkConstraintTransMotorMaxForce = cf.GetFloat(p, v); }, | ||
527 | (s) => { return LinkConstraintTransMotorMaxForce; }, | ||
528 | (s,p,l,v) => { LinkConstraintTransMotorMaxForce = v; } ), | ||
529 | new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", | ||
530 | 0.1f, | ||
531 | (s,cf,p,v) => { LinkConstraintCFM = cf.GetFloat(p, v); }, | ||
532 | (s) => { return LinkConstraintCFM; }, | ||
533 | (s,p,l,v) => { LinkConstraintCFM = v; } ), | ||
534 | new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", | ||
535 | 0.1f, | ||
536 | (s,cf,p,v) => { LinkConstraintERP = cf.GetFloat(p, v); }, | ||
537 | (s) => { return LinkConstraintERP; }, | ||
538 | (s,p,l,v) => { LinkConstraintERP = v; } ), | ||
539 | new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | ||
540 | 40, | ||
541 | (s,cf,p,v) => { LinkConstraintSolverIterations = cf.GetFloat(p, v); }, | ||
542 | (s) => { return LinkConstraintSolverIterations; }, | ||
543 | (s,p,l,v) => { LinkConstraintSolverIterations = v; } ), | ||
544 | |||
545 | new ParameterDefn("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", | ||
546 | 0f, | ||
547 | (s,cf,p,v) => { s.PhysicsMetricDumpFrames = cf.GetFloat(p, (int)v); }, | ||
548 | (s) => { return (float)s.PhysicsMetricDumpFrames; }, | ||
549 | (s,p,l,v) => { s.PhysicsMetricDumpFrames = (int)v; } ), | ||
550 | new ParameterDefn("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool", | ||
551 | 0f, | ||
552 | (s,cf,p,v) => { ; }, | ||
553 | (s) => { return 0f; }, | ||
554 | (s,p,l,v) => { BSParam.ResetBroadphasePoolTainted(s, v); } ), | ||
555 | new ParameterDefn("ResetConstraintSolver", "Setting this is any value resets the constraint solver", | ||
556 | 0f, | ||
557 | (s,cf,p,v) => { ; }, | ||
558 | (s) => { return 0f; }, | ||
559 | (s,p,l,v) => { BSParam.ResetConstraintSolverTainted(s, v); } ), | ||
560 | }; | ||
561 | |||
562 | // Convert a boolean to our numeric true and false values | ||
563 | public static float NumericBool(bool b) | ||
564 | { | ||
565 | return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse); | ||
566 | } | ||
567 | |||
568 | // Convert numeric true and false values to a boolean | ||
569 | public static bool BoolNumeric(float b) | ||
570 | { | ||
571 | return (b == ConfigurationParameters.numericTrue ? true : false); | ||
572 | } | ||
573 | |||
574 | private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v) | ||
575 | { | ||
576 | BSScene physScene = pPhysScene; | ||
577 | physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate() | ||
578 | { | ||
579 | physScene.PE.ResetBroadphasePool(physScene.World); | ||
580 | }); | ||
581 | } | ||
582 | |||
583 | private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v) | ||
584 | { | ||
585 | BSScene physScene = pPhysScene; | ||
586 | physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate() | ||
587 | { | ||
588 | physScene.PE.ResetConstraintSolver(physScene.World); | ||
589 | }); | ||
590 | } | ||
591 | |||
592 | // Search through the parameter definitions and return the matching | ||
593 | // ParameterDefn structure. | ||
594 | // Case does not matter as names are compared after converting to lower case. | ||
595 | // Returns 'false' if the parameter is not found. | ||
596 | internal static bool TryGetParameter(string paramName, out ParameterDefn defn) | ||
597 | { | ||
598 | bool ret = false; | ||
599 | ParameterDefn foundDefn = new ParameterDefn(); | ||
600 | string pName = paramName.ToLower(); | ||
601 | |||
602 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
603 | { | ||
604 | if (pName == parm.name.ToLower()) | ||
605 | { | ||
606 | foundDefn = parm; | ||
607 | ret = true; | ||
608 | break; | ||
609 | } | ||
610 | } | ||
611 | defn = foundDefn; | ||
612 | return ret; | ||
613 | } | ||
614 | |||
615 | // Pass through the settable parameters and set the default values | ||
616 | internal static void SetParameterDefaultValues(BSScene physicsScene) | ||
617 | { | ||
618 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
619 | { | ||
620 | parm.setter(physicsScene, parm.name, PhysParameterEntry.APPLY_TO_NONE, parm.defaultValue); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | // Get user set values out of the ini file. | ||
625 | internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg) | ||
626 | { | ||
627 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
628 | { | ||
629 | parm.userParam(physicsScene, cfg, parm.name, parm.defaultValue); | ||
630 | } | ||
631 | } | ||
632 | |||
633 | internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1]; | ||
634 | |||
635 | // This creates an array in the correct format for returning the list of | ||
636 | // parameters. This is used by the 'list' option of the 'physics' command. | ||
637 | internal static void BuildParameterTable() | ||
638 | { | ||
639 | if (SettableParameters.Length < ParameterDefinitions.Length) | ||
640 | { | ||
641 | List<PhysParameterEntry> entries = new List<PhysParameterEntry>(); | ||
642 | for (int ii = 0; ii < ParameterDefinitions.Length; ii++) | ||
643 | { | ||
644 | ParameterDefn pd = ParameterDefinitions[ii]; | ||
645 | entries.Add(new PhysParameterEntry(pd.name, pd.desc)); | ||
646 | } | ||
647 | |||
648 | // make the list in alphabetical order for estetic reasons | ||
649 | entries.Sort(delegate(PhysParameterEntry ppe1, PhysParameterEntry ppe2) | ||
650 | { | ||
651 | return ppe1.name.CompareTo(ppe2.name); | ||
652 | }); | ||
653 | |||
654 | SettableParameters = entries.ToArray(); | ||
655 | } | ||
656 | } | ||
657 | |||
658 | |||
659 | } | ||
660 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index f6a890e..027c786 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -45,6 +45,26 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
45 | * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. | 45 | * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. |
46 | * The last two (and certainly the last one) should be referenced only in taint-time. | 46 | * The last two (and certainly the last one) should be referenced only in taint-time. |
47 | */ | 47 | */ |
48 | |||
49 | /* | ||
50 | * As of 20121221, the following are the call sequences (going down) for different script physical functions: | ||
51 | * llApplyImpulse llApplyRotImpulse llSetTorque llSetForce | ||
52 | * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce | ||
53 | * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse | ||
54 | * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v | ||
55 | * BS.ApplyCentralForce BS.ApplyTorque | ||
56 | */ | ||
57 | |||
58 | // Flags used to denote which properties updates when making UpdateProperties calls to linksets, etc. | ||
59 | public enum UpdatedProperties : uint | ||
60 | { | ||
61 | Position = 1 << 0, | ||
62 | Orientation = 1 << 1, | ||
63 | Velocity = 1 << 2, | ||
64 | Acceleration = 1 << 3, | ||
65 | RotationalVelocity = 1 << 4, | ||
66 | EntPropUpdates = Position | Orientation | Velocity | Acceleration | RotationalVelocity, | ||
67 | } | ||
48 | public abstract class BSPhysObject : PhysicsActor | 68 | public abstract class BSPhysObject : PhysicsActor |
49 | { | 69 | { |
50 | protected BSPhysObject() | 70 | protected BSPhysObject() |
@@ -57,26 +77,45 @@ public abstract class BSPhysObject : PhysicsActor | |||
57 | PhysObjectName = name; | 77 | PhysObjectName = name; |
58 | TypeName = typeName; | 78 | TypeName = typeName; |
59 | 79 | ||
80 | // We don't have any physical representation yet. | ||
81 | PhysBody = new BulletBody(localID); | ||
82 | PhysShape = new BulletShape(); | ||
83 | |||
84 | // A linkset of just me | ||
60 | Linkset = BSLinkset.Factory(PhysicsScene, this); | 85 | Linkset = BSLinkset.Factory(PhysicsScene, this); |
86 | PositionDisplacement = OMV.Vector3.Zero; | ||
87 | |||
61 | LastAssetBuildFailed = false; | 88 | LastAssetBuildFailed = false; |
62 | 89 | ||
90 | // Default material type | ||
91 | Material = MaterialAttributes.Material.Wood; | ||
92 | |||
63 | CollisionCollection = new CollisionEventUpdate(); | 93 | CollisionCollection = new CollisionEventUpdate(); |
94 | CollisionsLastTick = CollisionCollection; | ||
64 | SubscribedEventsMs = 0; | 95 | SubscribedEventsMs = 0; |
65 | CollidingStep = 0; | 96 | CollidingStep = 0; |
66 | CollidingGroundStep = 0; | 97 | CollidingGroundStep = 0; |
67 | } | 98 | } |
68 | 99 | ||
100 | // Tell the object to clean up. | ||
101 | public virtual void Destroy() | ||
102 | { | ||
103 | UnRegisterAllPreStepActions(); | ||
104 | } | ||
105 | |||
69 | public BSScene PhysicsScene { get; protected set; } | 106 | public BSScene PhysicsScene { get; protected set; } |
70 | // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor | 107 | // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor |
71 | public string PhysObjectName { get; protected set; } | 108 | public string PhysObjectName { get; protected set; } |
72 | public string TypeName { get; protected set; } | 109 | public string TypeName { get; protected set; } |
73 | 110 | ||
74 | public BSLinkset Linkset { get; set; } | 111 | public BSLinkset Linkset { get; set; } |
112 | public BSLinksetInfo LinksetInfo { get; set; } | ||
75 | 113 | ||
76 | // Return the object mass without calculating it or having side effects | 114 | // Return the object mass without calculating it or having side effects |
77 | public abstract float RawMass { get; } | 115 | public abstract float RawMass { get; } |
78 | // Set the raw mass but also update physical mass properties (inertia, ...) | 116 | // Set the raw mass but also update physical mass properties (inertia, ...) |
79 | public abstract void UpdatePhysicalMassProperties(float mass); | 117 | // 'inWorld' true if the object has already been added to the dynamic world. |
118 | public abstract void UpdatePhysicalMassProperties(float mass, bool inWorld); | ||
80 | 119 | ||
81 | // The last value calculated for the prim's inertia | 120 | // The last value calculated for the prim's inertia |
82 | public OMV.Vector3 Inertia { get; set; } | 121 | public OMV.Vector3 Inertia { get; set; } |
@@ -105,9 +144,22 @@ public abstract class BSPhysObject : PhysicsActor | |||
105 | public EntityProperties CurrentEntityProperties { get; set; } | 144 | public EntityProperties CurrentEntityProperties { get; set; } |
106 | public EntityProperties LastEntityProperties { get; set; } | 145 | public EntityProperties LastEntityProperties { get; set; } |
107 | 146 | ||
108 | public abstract OMV.Vector3 Scale { get; set; } | 147 | public virtual OMV.Vector3 Scale { get; set; } |
109 | public abstract bool IsSolid { get; } | 148 | public abstract bool IsSolid { get; } |
110 | public abstract bool IsStatic { get; } | 149 | public abstract bool IsStatic { get; } |
150 | public abstract bool IsSelected { get; } | ||
151 | |||
152 | // It can be confusing for an actor to know if it should move or update an object | ||
153 | // depeneding on the setting of 'selected', 'physical, ... | ||
154 | // This flag is the true test -- if true, the object is being acted on in the physical world | ||
155 | public abstract bool IsPhysicallyActive { get; } | ||
156 | |||
157 | // Materialness | ||
158 | public MaterialAttributes.Material Material { get; private set; } | ||
159 | public override void SetMaterial(int material) | ||
160 | { | ||
161 | Material = (MaterialAttributes.Material)material; | ||
162 | } | ||
111 | 163 | ||
112 | // Stop all physical motion. | 164 | // Stop all physical motion. |
113 | public abstract void ZeroMotion(bool inTaintTime); | 165 | public abstract void ZeroMotion(bool inTaintTime); |
@@ -119,15 +171,41 @@ public abstract class BSPhysObject : PhysicsActor | |||
119 | // Update the physical location and motion of the object. Called with data from Bullet. | 171 | // Update the physical location and motion of the object. Called with data from Bullet. |
120 | public abstract void UpdateProperties(EntityProperties entprop); | 172 | public abstract void UpdateProperties(EntityProperties entprop); |
121 | 173 | ||
122 | // Tell the object to clean up. | ||
123 | public abstract void Destroy(); | ||
124 | |||
125 | public abstract OMV.Vector3 RawPosition { get; set; } | 174 | public abstract OMV.Vector3 RawPosition { get; set; } |
126 | public abstract OMV.Vector3 ForcePosition { get; set; } | 175 | public abstract OMV.Vector3 ForcePosition { get; set; } |
127 | 176 | ||
177 | // Position is what the simulator thinks the positions of the prim is. | ||
178 | // Because Bullet needs the zero coordinate to be the center of mass of the linkset, | ||
179 | // sometimes it is necessary to displace the position the physics engine thinks | ||
180 | // the position is. PositionDisplacement must be added and removed from the | ||
181 | // position as the simulator position is stored and fetched from the physics | ||
182 | // engine. | ||
183 | public virtual OMV.Vector3 PositionDisplacement { get; set; } | ||
184 | |||
128 | public abstract OMV.Quaternion RawOrientation { get; set; } | 185 | public abstract OMV.Quaternion RawOrientation { get; set; } |
129 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 186 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
130 | 187 | ||
188 | // The system is telling us the velocity it wants to move at. | ||
189 | // Velocity in world coordinates. | ||
190 | // protected OMV.Vector3 m_targetVelocity; // use the definition in PhysicsActor | ||
191 | public override OMV.Vector3 TargetVelocity | ||
192 | { | ||
193 | get { return m_targetVelocity; } | ||
194 | set | ||
195 | { | ||
196 | m_targetVelocity = value; | ||
197 | Velocity = value; | ||
198 | } | ||
199 | } | ||
200 | public virtual float TargetSpeed | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | OMV.Vector3 characterOrientedVelocity = TargetVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation)); | ||
205 | return characterOrientedVelocity.X; | ||
206 | } | ||
207 | } | ||
208 | public abstract OMV.Vector3 RawVelocity { get; set; } | ||
131 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 209 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
132 | 210 | ||
133 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } | 211 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } |
@@ -136,6 +214,15 @@ public abstract class BSPhysObject : PhysicsActor | |||
136 | 214 | ||
137 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | 215 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } |
138 | 216 | ||
217 | public virtual float ForwardSpeed | ||
218 | { | ||
219 | get | ||
220 | { | ||
221 | OMV.Vector3 characterOrientedVelocity = RawVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation)); | ||
222 | return characterOrientedVelocity.X; | ||
223 | } | ||
224 | } | ||
225 | |||
139 | #region Collisions | 226 | #region Collisions |
140 | 227 | ||
141 | // Requested number of milliseconds between collision events. Zero means disabled. | 228 | // Requested number of milliseconds between collision events. Zero means disabled. |
@@ -146,26 +233,65 @@ public abstract class BSPhysObject : PhysicsActor | |||
146 | protected long CollidingStep { get; set; } | 233 | protected long CollidingStep { get; set; } |
147 | // The simulation step that last had a collision with the ground | 234 | // The simulation step that last had a collision with the ground |
148 | protected long CollidingGroundStep { get; set; } | 235 | protected long CollidingGroundStep { get; set; } |
236 | // The simulation step that last collided with an object | ||
237 | protected long CollidingObjectStep { get; set; } | ||
149 | // The collision flags we think are set in Bullet | 238 | // The collision flags we think are set in Bullet |
150 | protected CollisionFlags CurrentCollisionFlags { get; set; } | 239 | protected CollisionFlags CurrentCollisionFlags { get; set; } |
151 | 240 | ||
241 | public override bool IsColliding { | ||
242 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
243 | set { | ||
244 | if (value) | ||
245 | CollidingStep = PhysicsScene.SimulationStep; | ||
246 | else | ||
247 | CollidingStep = 0; | ||
248 | } | ||
249 | } | ||
250 | public override bool CollidingGround { | ||
251 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
252 | set | ||
253 | { | ||
254 | if (value) | ||
255 | CollidingGroundStep = PhysicsScene.SimulationStep; | ||
256 | else | ||
257 | CollidingGroundStep = 0; | ||
258 | } | ||
259 | } | ||
260 | public override bool CollidingObj { | ||
261 | get { return (CollidingObjectStep == PhysicsScene.SimulationStep); } | ||
262 | set { | ||
263 | if (value) | ||
264 | CollidingObjectStep = PhysicsScene.SimulationStep; | ||
265 | else | ||
266 | CollidingObjectStep = 0; | ||
267 | } | ||
268 | } | ||
269 | |||
152 | // The collisions that have been collected this tick | 270 | // The collisions that have been collected this tick |
153 | protected CollisionEventUpdate CollisionCollection; | 271 | protected CollisionEventUpdate CollisionCollection; |
272 | // Remember collisions from last tick for fancy collision based actions | ||
273 | // (like a BSCharacter walking up stairs). | ||
274 | protected CollisionEventUpdate CollisionsLastTick; | ||
154 | 275 | ||
155 | // The simulation step is telling this object about a collision. | 276 | // The simulation step is telling this object about a collision. |
156 | // Return 'true' if a collision was processed and should be sent up. | 277 | // Return 'true' if a collision was processed and should be sent up. |
278 | // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. | ||
157 | // Called at taint time from within the Step() function | 279 | // Called at taint time from within the Step() function |
158 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, | 280 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, |
159 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 281 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
160 | { | 282 | { |
161 | bool ret = false; | 283 | bool ret = false; |
162 | 284 | ||
163 | // The following lines make IsColliding() and IsCollidingGround() work | 285 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work |
164 | CollidingStep = PhysicsScene.SimulationStep; | 286 | CollidingStep = PhysicsScene.SimulationStep; |
165 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) | 287 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) |
166 | { | 288 | { |
167 | CollidingGroundStep = PhysicsScene.SimulationStep; | 289 | CollidingGroundStep = PhysicsScene.SimulationStep; |
168 | } | 290 | } |
291 | else | ||
292 | { | ||
293 | CollidingObjectStep = PhysicsScene.SimulationStep; | ||
294 | } | ||
169 | 295 | ||
170 | // prims in the same linkset cannot collide with each other | 296 | // prims in the same linkset cannot collide with each other |
171 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) | 297 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) |
@@ -191,8 +317,9 @@ public abstract class BSPhysObject : PhysicsActor | |||
191 | public virtual bool SendCollisions() | 317 | public virtual bool SendCollisions() |
192 | { | 318 | { |
193 | bool ret = true; | 319 | bool ret = true; |
320 | |||
194 | // If the 'no collision' call, force it to happen right now so quick collision_end | 321 | // If the 'no collision' call, force it to happen right now so quick collision_end |
195 | bool force = CollisionCollection.Count == 0; | 322 | bool force = (CollisionCollection.Count == 0 && CollisionsLastTick.Count != 0); |
196 | 323 | ||
197 | // throttle the collisions to the number of milliseconds specified in the subscription | 324 | // throttle the collisions to the number of milliseconds specified in the subscription |
198 | if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) | 325 | if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) |
@@ -207,11 +334,16 @@ public abstract class BSPhysObject : PhysicsActor | |||
207 | ret = false; | 334 | ret = false; |
208 | } | 335 | } |
209 | 336 | ||
210 | // DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); | 337 | DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); |
211 | base.SendCollisionUpdate(CollisionCollection); | 338 | base.SendCollisionUpdate(CollisionCollection); |
212 | 339 | ||
213 | // The collisionCollection structure is passed around in the simulator. | 340 | // Remember the collisions from this tick for some collision specific processing. |
341 | CollisionsLastTick = CollisionCollection; | ||
342 | |||
343 | // The CollisionCollection instance is passed around in the simulator. | ||
214 | // Make sure we don't have a handle to that one and that a new one is used for next time. | 344 | // Make sure we don't have a handle to that one and that a new one is used for next time. |
345 | // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here, | ||
346 | // a race condition is created for the other users of this instance. | ||
215 | CollisionCollection = new CollisionEventUpdate(); | 347 | CollisionCollection = new CollisionEventUpdate(); |
216 | } | 348 | } |
217 | return ret; | 349 | return ret; |
@@ -229,7 +361,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
229 | 361 | ||
230 | PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() | 362 | PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() |
231 | { | 363 | { |
232 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 364 | if (PhysBody.HasPhysicalBody) |
365 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
233 | }); | 366 | }); |
234 | } | 367 | } |
235 | else | 368 | else |
@@ -243,7 +376,9 @@ public abstract class BSPhysObject : PhysicsActor | |||
243 | SubscribedEventsMs = 0; | 376 | SubscribedEventsMs = 0; |
244 | PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() | 377 | PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() |
245 | { | 378 | { |
246 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 379 | // Make sure there is a body there because sometimes destruction happens in an un-ideal order. |
380 | if (PhysBody.HasPhysicalBody) | ||
381 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
247 | }); | 382 | }); |
248 | } | 383 | } |
249 | // Return 'true' if the simulator wants collision events | 384 | // Return 'true' if the simulator wants collision events |
@@ -253,11 +388,66 @@ public abstract class BSPhysObject : PhysicsActor | |||
253 | 388 | ||
254 | #endregion // Collisions | 389 | #endregion // Collisions |
255 | 390 | ||
391 | #region Per Simulation Step actions | ||
392 | // There are some actions that must be performed for a physical object before each simulation step. | ||
393 | // These actions are optional so, rather than scanning all the physical objects and asking them | ||
394 | // if they have anything to do, a physical object registers for an event call before the step is performed. | ||
395 | // This bookkeeping makes it easy to add, remove and clean up after all these registrations. | ||
396 | private Dictionary<string, BSScene.PreStepAction> RegisteredActions = new Dictionary<string, BSScene.PreStepAction>(); | ||
397 | protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) | ||
398 | { | ||
399 | string identifier = op + "-" + id.ToString(); | ||
400 | |||
401 | lock (RegisteredActions) | ||
402 | { | ||
403 | // Clean out any existing action | ||
404 | UnRegisterPreStepAction(op, id); | ||
405 | |||
406 | RegisteredActions[identifier] = actn; | ||
407 | } | ||
408 | PhysicsScene.BeforeStep += actn; | ||
409 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); | ||
410 | } | ||
411 | |||
412 | // Unregister a pre step action. Safe to call if the action has not been registered. | ||
413 | protected void UnRegisterPreStepAction(string op, uint id) | ||
414 | { | ||
415 | string identifier = op + "-" + id.ToString(); | ||
416 | bool removed = false; | ||
417 | lock (RegisteredActions) | ||
418 | { | ||
419 | if (RegisteredActions.ContainsKey(identifier)) | ||
420 | { | ||
421 | PhysicsScene.BeforeStep -= RegisteredActions[identifier]; | ||
422 | RegisteredActions.Remove(identifier); | ||
423 | removed = true; | ||
424 | } | ||
425 | } | ||
426 | DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed); | ||
427 | } | ||
428 | |||
429 | protected void UnRegisterAllPreStepActions() | ||
430 | { | ||
431 | lock (RegisteredActions) | ||
432 | { | ||
433 | foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions) | ||
434 | { | ||
435 | PhysicsScene.BeforeStep -= kvp.Value; | ||
436 | } | ||
437 | RegisteredActions.Clear(); | ||
438 | } | ||
439 | DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); | ||
440 | } | ||
441 | |||
442 | |||
443 | #endregion // Per Simulation Step actions | ||
444 | |||
256 | // High performance detailed logging routine used by the physical objects. | 445 | // High performance detailed logging routine used by the physical objects. |
257 | protected void DetailLog(string msg, params Object[] args) | 446 | protected void DetailLog(string msg, params Object[] args) |
258 | { | 447 | { |
259 | if (PhysicsScene.PhysicsLogging.Enabled) | 448 | if (PhysicsScene.PhysicsLogging.Enabled) |
260 | PhysicsScene.DetailLog(msg, args); | 449 | PhysicsScene.DetailLog(msg, args); |
261 | } | 450 | } |
451 | |||
262 | } | 452 | } |
263 | } | 453 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs index 20f5180..9442854 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs | |||
@@ -59,13 +59,7 @@ public class BSPlugin : IPhysicsPlugin | |||
59 | { | 59 | { |
60 | if (_mScene == null) | 60 | if (_mScene == null) |
61 | { | 61 | { |
62 | if (Util.IsWindows()) | 62 | _mScene = new BSScene(GetName(), sceneIdentifier); |
63 | Util.LoadArchSpecificWindowsDll("BulletSim.dll"); | ||
64 | // If not Windows, loading is performed by the | ||
65 | // Mono loader as specified in | ||
66 | // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config". | ||
67 | |||
68 | _mScene = new BSScene(sceneIdentifier); | ||
69 | } | 63 | } |
70 | return (_mScene); | 64 | return (_mScene); |
71 | } | 65 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 2b3fa25..e6b8507 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -45,13 +45,15 @@ public sealed class BSPrim : BSPhysObject | |||
45 | private static readonly string LogHeader = "[BULLETS PRIM]"; | 45 | private static readonly string LogHeader = "[BULLETS PRIM]"; |
46 | 46 | ||
47 | // _size is what the user passed. Scale is what we pass to the physics engine with the mesh. | 47 | // _size is what the user passed. Scale is what we pass to the physics engine with the mesh. |
48 | // Often Scale is unity because the meshmerizer will apply _size when creating the mesh. | ||
49 | private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user | 48 | private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user |
50 | 49 | ||
51 | private bool _grabbed; | 50 | private bool _grabbed; |
52 | private bool _isSelected; | 51 | private bool _isSelected; |
53 | private bool _isVolumeDetect; | 52 | private bool _isVolumeDetect; |
53 | |||
54 | // _position is what the simulator thinks the positions of the prim is. | ||
54 | private OMV.Vector3 _position; | 55 | private OMV.Vector3 _position; |
56 | |||
55 | private float _mass; // the mass of this object | 57 | private float _mass; // the mass of this object |
56 | private float _density; | 58 | private float _density; |
57 | private OMV.Vector3 _force; | 59 | private OMV.Vector3 _force; |
@@ -67,9 +69,6 @@ public sealed class BSPrim : BSPhysObject | |||
67 | private float _restitution; | 69 | private float _restitution; |
68 | private bool _setAlwaysRun; | 70 | private bool _setAlwaysRun; |
69 | private bool _throttleUpdates; | 71 | private bool _throttleUpdates; |
70 | private bool _isColliding; | ||
71 | private bool _collidingGround; | ||
72 | private bool _collidingObj; | ||
73 | private bool _floatOnWater; | 72 | private bool _floatOnWater; |
74 | private OMV.Vector3 _rotationalVelocity; | 73 | private OMV.Vector3 _rotationalVelocity; |
75 | private bool _kinematic; | 74 | private bool _kinematic; |
@@ -77,13 +76,14 @@ public sealed class BSPrim : BSPhysObject | |||
77 | 76 | ||
78 | private BSDynamics _vehicle; | 77 | private BSDynamics _vehicle; |
79 | 78 | ||
79 | private BSVMotor _targetMotor; | ||
80 | private OMV.Vector3 _PIDTarget; | 80 | private OMV.Vector3 _PIDTarget; |
81 | private bool _usePID; | ||
82 | private float _PIDTau; | 81 | private float _PIDTau; |
83 | private bool _useHoverPID; | 82 | |
83 | private BSFMotor _hoverMotor; | ||
84 | private float _PIDHoverHeight; | 84 | private float _PIDHoverHeight; |
85 | private PIDHoverType _PIDHoverType; | 85 | private PIDHoverType _PIDHoverType; |
86 | private float _PIDHoverTao; | 86 | private float _PIDHoverTau; |
87 | 87 | ||
88 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 88 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
89 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 89 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -93,23 +93,27 @@ public sealed class BSPrim : BSPhysObject | |||
93 | _physicsActorType = (int)ActorTypes.Prim; | 93 | _physicsActorType = (int)ActorTypes.Prim; |
94 | _position = pos; | 94 | _position = pos; |
95 | _size = size; | 95 | _size = size; |
96 | Scale = size; // the scale will be set by CreateGeom depending on object type | 96 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). |
97 | _orientation = rotation; | 97 | _orientation = rotation; |
98 | _buoyancy = 1f; | 98 | _buoyancy = 0f; |
99 | _velocity = OMV.Vector3.Zero; | 99 | _velocity = OMV.Vector3.Zero; |
100 | _rotationalVelocity = OMV.Vector3.Zero; | 100 | _rotationalVelocity = OMV.Vector3.Zero; |
101 | BaseShape = pbs; | 101 | BaseShape = pbs; |
102 | _isPhysical = pisPhysical; | 102 | _isPhysical = pisPhysical; |
103 | _isVolumeDetect = false; | 103 | _isVolumeDetect = false; |
104 | _friction = PhysicsScene.Params.defaultFriction; // TODO: compute based on object material | 104 | |
105 | _density = PhysicsScene.Params.defaultDensity; // TODO: compute based on object material | 105 | // Someday set default attributes based on the material but, for now, we don't know the prim material yet. |
106 | // MaterialAttributes primMat = BSMaterials.GetAttributes(Material, pisPhysical); | ||
107 | _density = PhysicsScene.Params.defaultDensity; | ||
108 | _friction = PhysicsScene.Params.defaultFriction; | ||
106 | _restitution = PhysicsScene.Params.defaultRestitution; | 109 | _restitution = PhysicsScene.Params.defaultRestitution; |
110 | |||
107 | _vehicle = new BSDynamics(PhysicsScene, this); // add vehicleness | 111 | _vehicle = new BSDynamics(PhysicsScene, this); // add vehicleness |
112 | |||
108 | _mass = CalculateMass(); | 113 | _mass = CalculateMass(); |
109 | 114 | ||
110 | // No body or shape yet | 115 | // Cause linkset variables to be initialized (like mass) |
111 | PhysBody = new BulletBody(LocalID, IntPtr.Zero); | 116 | Linkset.Refresh(this); |
112 | PhysShape = new BulletShape(IntPtr.Zero); | ||
113 | 117 | ||
114 | DetailLog("{0},BSPrim.constructor,call", LocalID); | 118 | DetailLog("{0},BSPrim.constructor,call", LocalID); |
115 | // do the actual object creation at taint time | 119 | // do the actual object creation at taint time |
@@ -117,7 +121,7 @@ public sealed class BSPrim : BSPhysObject | |||
117 | { | 121 | { |
118 | CreateGeomAndObject(true); | 122 | CreateGeomAndObject(true); |
119 | 123 | ||
120 | CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(PhysBody.ptr); | 124 | CurrentCollisionFlags = PhysicsScene.PE.GetCollisionFlags(PhysBody); |
121 | }); | 125 | }); |
122 | } | 126 | } |
123 | 127 | ||
@@ -125,10 +129,11 @@ public sealed class BSPrim : BSPhysObject | |||
125 | public override void Destroy() | 129 | public override void Destroy() |
126 | { | 130 | { |
127 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); | 131 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); |
132 | base.Destroy(); | ||
128 | 133 | ||
129 | // Undo any links between me and any other object | 134 | // Undo any links between me and any other object |
130 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 135 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG DEBUG |
131 | int childrenBefore = Linkset.NumberOfChildren; | 136 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG DEBUG |
132 | 137 | ||
133 | Linkset = Linkset.RemoveMeFromLinkset(this); | 138 | Linkset = Linkset.RemoveMeFromLinkset(this); |
134 | 139 | ||
@@ -143,7 +148,9 @@ public sealed class BSPrim : BSPhysObject | |||
143 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); | 148 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); |
144 | // If there are physical body and shape, release my use of same. | 149 | // If there are physical body and shape, release my use of same. |
145 | PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); | 150 | PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); |
151 | PhysBody.Clear(); | ||
146 | PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); | 152 | PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); |
153 | PhysShape.Clear(); | ||
147 | }); | 154 | }); |
148 | } | 155 | } |
149 | 156 | ||
@@ -157,16 +164,15 @@ public sealed class BSPrim : BSPhysObject | |||
157 | // We presume the scale and size are the same. If scale must be changed for | 164 | // We presume the scale and size are the same. If scale must be changed for |
158 | // the physical shape, that is done when the geometry is built. | 165 | // the physical shape, that is done when the geometry is built. |
159 | _size = value; | 166 | _size = value; |
167 | Scale = _size; | ||
160 | ForceBodyShapeRebuild(false); | 168 | ForceBodyShapeRebuild(false); |
161 | } | 169 | } |
162 | } | 170 | } |
163 | // Scale is what we set in the physics engine. It is different than 'size' in that | ||
164 | // 'size' can be encorporated into the mesh. In that case, the scale is <1,1,1>. | ||
165 | public override OMV.Vector3 Scale { get; set; } | ||
166 | 171 | ||
167 | public override PrimitiveBaseShape Shape { | 172 | public override PrimitiveBaseShape Shape { |
168 | set { | 173 | set { |
169 | BaseShape = value; | 174 | BaseShape = value; |
175 | LastAssetBuildFailed = false; | ||
170 | ForceBodyShapeRebuild(false); | 176 | ForceBodyShapeRebuild(false); |
171 | } | 177 | } |
172 | } | 178 | } |
@@ -176,7 +182,6 @@ public sealed class BSPrim : BSPhysObject | |||
176 | 182 | ||
177 | public override bool ForceBodyShapeRebuild(bool inTaintTime) | 183 | public override bool ForceBodyShapeRebuild(bool inTaintTime) |
178 | { | 184 | { |
179 | LastAssetBuildFailed = false; | ||
180 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ForceBodyShapeRebuild", delegate() | 185 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ForceBodyShapeRebuild", delegate() |
181 | { | 186 | { |
182 | _mass = CalculateMass(); // changing the shape changes the mass | 187 | _mass = CalculateMass(); // changing the shape changes the mass |
@@ -189,15 +194,23 @@ public sealed class BSPrim : BSPhysObject | |||
189 | } | 194 | } |
190 | } | 195 | } |
191 | public override bool Selected { | 196 | public override bool Selected { |
192 | set { | 197 | set |
193 | _isSelected = value; | 198 | { |
194 | PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() | 199 | if (value != _isSelected) |
195 | { | 200 | { |
196 | DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); | 201 | _isSelected = value; |
197 | SetObjectDynamic(false); | 202 | PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() |
198 | }); | 203 | { |
204 | DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); | ||
205 | SetObjectDynamic(false); | ||
206 | }); | ||
207 | } | ||
199 | } | 208 | } |
200 | } | 209 | } |
210 | public override bool IsSelected | ||
211 | { | ||
212 | get { return _isSelected; } | ||
213 | } | ||
201 | public override void CrossingFailure() { return; } | 214 | public override void CrossingFailure() { return; } |
202 | 215 | ||
203 | // link me to the specified parent | 216 | // link me to the specified parent |
@@ -244,7 +257,8 @@ public sealed class BSPrim : BSPhysObject | |||
244 | // Zero some other properties in the physics engine | 257 | // Zero some other properties in the physics engine |
245 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() | 258 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() |
246 | { | 259 | { |
247 | BulletSimAPI.ClearAllForces2(PhysBody.ptr); | 260 | if (PhysBody.HasPhysicalBody) |
261 | PhysicsScene.PE.ClearAllForces(PhysBody); | ||
248 | }); | 262 | }); |
249 | } | 263 | } |
250 | public override void ZeroAngularMotion(bool inTaintTime) | 264 | public override void ZeroAngularMotion(bool inTaintTime) |
@@ -253,8 +267,12 @@ public sealed class BSPrim : BSPhysObject | |||
253 | // Zero some other properties in the physics engine | 267 | // Zero some other properties in the physics engine |
254 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() | 268 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() |
255 | { | 269 | { |
256 | BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 270 | // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); |
257 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 271 | if (PhysBody.HasPhysicalBody) |
272 | { | ||
273 | PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | ||
274 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | ||
275 | } | ||
258 | }); | 276 | }); |
259 | } | 277 | } |
260 | 278 | ||
@@ -271,41 +289,70 @@ public sealed class BSPrim : BSPhysObject | |||
271 | } | 289 | } |
272 | public override OMV.Vector3 Position { | 290 | public override OMV.Vector3 Position { |
273 | get { | 291 | get { |
292 | /* NOTE: this refetch is not necessary. The simulator knows about linkset children | ||
293 | * and does not fetch this position info for children. Thus this is commented out. | ||
274 | // child prims move around based on their parent. Need to get the latest location | 294 | // child prims move around based on their parent. Need to get the latest location |
275 | if (!Linkset.IsRoot(this)) | 295 | if (!Linkset.IsRoot(this)) |
276 | _position = Linkset.Position(this); | 296 | _position = Linkset.PositionGet(this); |
297 | */ | ||
277 | 298 | ||
278 | // don't do the GetObjectPosition for root elements because this function is called a zillion times. | 299 | // don't do the GetObjectPosition for root elements because this function is called a zillion times. |
279 | // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); | 300 | // _position = PhysicsScene.PE.GetObjectPosition2(PhysicsScene.World, BSBody) - PositionDisplacement; |
280 | return _position; | 301 | return _position; |
281 | } | 302 | } |
282 | set { | 303 | set { |
283 | // If the position must be forced into the physics engine, use ForcePosition. | 304 | // If the position must be forced into the physics engine, use ForcePosition. |
305 | // All positions are given in world positions. | ||
284 | if (_position == value) | 306 | if (_position == value) |
285 | { | 307 | { |
308 | DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation); | ||
286 | return; | 309 | return; |
287 | } | 310 | } |
288 | _position = value; | 311 | _position = value; |
289 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? | ||
290 | PositionSanityCheck(false); | 312 | PositionSanityCheck(false); |
313 | |||
291 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 314 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() |
292 | { | 315 | { |
293 | // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 316 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
294 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 317 | ForcePosition = _position; |
295 | ActivateIfPhysical(false); | 318 | |
319 | // A linkset might need to know if a component information changed. | ||
320 | Linkset.UpdateProperties(UpdatedProperties.Position, this); | ||
321 | |||
296 | }); | 322 | }); |
297 | } | 323 | } |
298 | } | 324 | } |
299 | public override OMV.Vector3 ForcePosition { | 325 | public override OMV.Vector3 ForcePosition { |
300 | get { | 326 | get { |
301 | _position = BulletSimAPI.GetPosition2(PhysBody.ptr); | 327 | _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement; |
302 | return _position; | 328 | return _position; |
303 | } | 329 | } |
304 | set { | 330 | set { |
305 | _position = value; | 331 | _position = value; |
306 | // PositionSanityCheck(); // Don't do this! Causes a loop and caller should know better. | 332 | if (PhysBody.HasPhysicalBody) |
307 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 333 | { |
308 | ActivateIfPhysical(false); | 334 | PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); |
335 | ActivateIfPhysical(false); | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | // Override to have position displacement immediately update the physical position. | ||
340 | // A feeble attempt to keep the sim and physical positions in sync | ||
341 | // Must be called at taint time. | ||
342 | public override OMV.Vector3 PositionDisplacement | ||
343 | { | ||
344 | get | ||
345 | { | ||
346 | return base.PositionDisplacement; | ||
347 | } | ||
348 | set | ||
349 | { | ||
350 | base.PositionDisplacement = value; | ||
351 | PhysicsScene.TaintedObject(PhysicsScene.InTaintTime, "BSPrim.setPosition", delegate() | ||
352 | { | ||
353 | if (PhysBody.HasPhysicalBody) | ||
354 | PhysicsScene.PE.SetTranslation(PhysBody, _position + base.PositionDisplacement, _orientation); | ||
355 | }); | ||
309 | } | 356 | } |
310 | } | 357 | } |
311 | 358 | ||
@@ -316,51 +363,56 @@ public sealed class BSPrim : BSPhysObject | |||
316 | { | 363 | { |
317 | bool ret = false; | 364 | bool ret = false; |
318 | 365 | ||
366 | if (!PhysicsScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) | ||
367 | { | ||
368 | // The physical object is out of the known/simulated area. | ||
369 | // Upper levels of code will handle the transition to other areas so, for | ||
370 | // the time, we just ignore the position. | ||
371 | return ret; | ||
372 | } | ||
373 | |||
319 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); | 374 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); |
320 | OMV.Vector3 upForce = OMV.Vector3.Zero; | 375 | OMV.Vector3 upForce = OMV.Vector3.Zero; |
321 | if (Position.Z < terrainHeight) | 376 | if (RawPosition.Z < terrainHeight) |
322 | { | 377 | { |
323 | DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 378 | DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); |
324 | float targetHeight = terrainHeight + (Size.Z / 2f); | 379 | float targetHeight = terrainHeight + (Size.Z / 2f); |
325 | // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec. | 380 | // If the object is below ground it just has to be moved up because pushing will |
326 | upForce.Z = (terrainHeight - Position.Z) * 1f; | 381 | // not get it through the terrain |
382 | _position.Z = targetHeight; | ||
383 | if (inTaintTime) | ||
384 | ForcePosition = _position; | ||
327 | ret = true; | 385 | ret = true; |
328 | } | 386 | } |
329 | 387 | ||
330 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | 388 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) |
331 | { | 389 | { |
332 | float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position); | 390 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); |
333 | // TODO: a floating motor so object will bob in the water | 391 | // TODO: a floating motor so object will bob in the water |
334 | if (Math.Abs(Position.Z - waterHeight) > 0.1f) | 392 | if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) |
335 | { | 393 | { |
336 | // Upforce proportional to the distance away from the water. Correct the error in 1 sec. | 394 | // Upforce proportional to the distance away from the water. Correct the error in 1 sec. |
337 | upForce.Z = (waterHeight - Position.Z) * 1f; | 395 | upForce.Z = (waterHeight - RawPosition.Z) * 1f; |
396 | |||
397 | // Apply upforce and overcome gravity. | ||
398 | OMV.Vector3 correctionForce = upForce - PhysicsScene.DefaultGravity; | ||
399 | DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce); | ||
400 | AddForce(correctionForce, false, inTaintTime); | ||
338 | ret = true; | 401 | ret = true; |
339 | } | 402 | } |
340 | } | 403 | } |
341 | 404 | ||
342 | // TODO: check for out of bounds | ||
343 | |||
344 | // The above code computes a force to apply to correct any out-of-bounds problems. Apply same. | ||
345 | if (ret) | ||
346 | { | ||
347 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.PositionSanityCheck:belowTerrain", delegate() | ||
348 | { | ||
349 | // Apply upforce and overcome gravity. | ||
350 | ForceVelocity = ForceVelocity + upForce - PhysicsScene.DefaultGravity; | ||
351 | }); | ||
352 | } | ||
353 | return ret; | 405 | return ret; |
354 | } | 406 | } |
355 | 407 | ||
356 | // Return the effective mass of the object. | 408 | // Return the effective mass of the object. |
357 | // If there are multiple items in the linkset, add them together for the root | 409 | // The definition of this call is to return the mass of the prim. |
410 | // If the simulator cares about the mass of the linkset, it will sum it itself. | ||
358 | public override float Mass | 411 | public override float Mass |
359 | { | 412 | { |
360 | get | 413 | get |
361 | { | 414 | { |
362 | return Linkset.LinksetMass; | 415 | return _mass; |
363 | // return _mass; | ||
364 | } | 416 | } |
365 | } | 417 | } |
366 | 418 | ||
@@ -370,25 +422,64 @@ public sealed class BSPrim : BSPhysObject | |||
370 | } | 422 | } |
371 | // Set the physical mass to the passed mass. | 423 | // Set the physical mass to the passed mass. |
372 | // Note that this does not change _mass! | 424 | // Note that this does not change _mass! |
373 | public override void UpdatePhysicalMassProperties(float physMass) | 425 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
374 | { | 426 | { |
375 | if (IsStatic) | 427 | if (PhysBody.HasPhysicalBody) |
376 | { | 428 | { |
377 | Inertia = OMV.Vector3.Zero; | 429 | if (IsStatic) |
378 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); | 430 | { |
379 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 431 | PhysicsScene.PE.SetGravity(PhysBody, PhysicsScene.DefaultGravity); |
380 | } | 432 | Inertia = OMV.Vector3.Zero; |
381 | else | 433 | PhysicsScene.PE.SetMassProps(PhysBody, 0f, Inertia); |
382 | { | 434 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); |
383 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 435 | } |
384 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | 436 | else |
385 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 437 | { |
386 | // center of mass is at the zero of the object | 438 | OMV.Vector3 grav = ComputeGravity(Buoyancy); |
387 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | 439 | |
388 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); | 440 | if (inWorld) |
441 | { | ||
442 | // Changing interesting properties doesn't change proxy and collision cache | ||
443 | // information. The Bullet solution is to re-add the object to the world | ||
444 | // after parameters are changed. | ||
445 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); | ||
446 | } | ||
447 | |||
448 | // The computation of mass props requires gravity to be set on the object. | ||
449 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
450 | |||
451 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); | ||
452 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); | ||
453 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); | ||
454 | |||
455 | // center of mass is at the zero of the object | ||
456 | // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation); | ||
457 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); | ||
458 | |||
459 | if (inWorld) | ||
460 | { | ||
461 | AddObjectToPhysicalWorld(); | ||
462 | } | ||
463 | |||
464 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
465 | // adding the object resets the object's gravity to world gravity | ||
466 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
467 | |||
468 | } | ||
389 | } | 469 | } |
390 | } | 470 | } |
391 | 471 | ||
472 | // Return what gravity should be set to this very moment | ||
473 | public OMV.Vector3 ComputeGravity(float buoyancy) | ||
474 | { | ||
475 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | ||
476 | |||
477 | if (!IsStatic) | ||
478 | ret *= (1f - buoyancy); | ||
479 | |||
480 | return ret; | ||
481 | } | ||
482 | |||
392 | // Is this used? | 483 | // Is this used? |
393 | public override OMV.Vector3 CenterOfMass | 484 | public override OMV.Vector3 CenterOfMass |
394 | { | 485 | { |
@@ -405,11 +496,32 @@ public sealed class BSPrim : BSPhysObject | |||
405 | get { return _force; } | 496 | get { return _force; } |
406 | set { | 497 | set { |
407 | _force = value; | 498 | _force = value; |
408 | PhysicsScene.TaintedObject("BSPrim.setForce", delegate() | 499 | if (_force != OMV.Vector3.Zero) |
409 | { | 500 | { |
410 | // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); | 501 | // If the force is non-zero, it must be reapplied each tick because |
411 | BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); | 502 | // Bullet clears the forces applied last frame. |
412 | }); | 503 | RegisterPreStepAction("BSPrim.setForce", LocalID, |
504 | delegate(float timeStep) | ||
505 | { | ||
506 | if (!IsPhysicallyActive) | ||
507 | { | ||
508 | UnRegisterPreStepAction("BSPrim.setForce", LocalID); | ||
509 | return; | ||
510 | } | ||
511 | |||
512 | DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); | ||
513 | if (PhysBody.HasPhysicalBody) | ||
514 | { | ||
515 | PhysicsScene.PE.ApplyCentralForce(PhysBody, _force); | ||
516 | ActivateIfPhysical(false); | ||
517 | } | ||
518 | } | ||
519 | ); | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | UnRegisterPreStepAction("BSPrim.setForce", LocalID); | ||
524 | } | ||
413 | } | 525 | } |
414 | } | 526 | } |
415 | 527 | ||
@@ -420,15 +532,18 @@ public sealed class BSPrim : BSPhysObject | |||
420 | set { | 532 | set { |
421 | Vehicle type = (Vehicle)value; | 533 | Vehicle type = (Vehicle)value; |
422 | 534 | ||
423 | // Tell the scene about the vehicle so it will get processing each frame. | ||
424 | PhysicsScene.VehicleInSceneTypeChanged(this, type); | ||
425 | |||
426 | PhysicsScene.TaintedObject("setVehicleType", delegate() | 535 | PhysicsScene.TaintedObject("setVehicleType", delegate() |
427 | { | 536 | { |
428 | // Done at taint time so we're sure the physics engine is not using the variables | 537 | // Done at taint time so we're sure the physics engine is not using the variables |
429 | // Vehicle code changes the parameters for this vehicle type. | 538 | // Vehicle code changes the parameters for this vehicle type. |
430 | _vehicle.ProcessTypeChange(type); | 539 | _vehicle.ProcessTypeChange(type); |
431 | ActivateIfPhysical(false); | 540 | ActivateIfPhysical(false); |
541 | |||
542 | // If an active vehicle, register the vehicle code to be called before each step | ||
543 | if (_vehicle.Type == Vehicle.TYPE_NONE) | ||
544 | UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); | ||
545 | else | ||
546 | RegisterPreStepAction("BSPrim.Vehicle", LocalID, _vehicle.Step); | ||
432 | }); | 547 | }); |
433 | } | 548 | } |
434 | } | 549 | } |
@@ -464,23 +579,6 @@ public sealed class BSPrim : BSPhysObject | |||
464 | }); | 579 | }); |
465 | } | 580 | } |
466 | 581 | ||
467 | // Called each simulation step to advance vehicle characteristics. | ||
468 | // Called from Scene when doing simulation step so we're in taint processing time. | ||
469 | public override void StepVehicle(float timeStep) | ||
470 | { | ||
471 | if (IsPhysical && _vehicle.IsActive) | ||
472 | { | ||
473 | _vehicle.Step(timeStep); | ||
474 | /* // TEST TEST DEBUG DEBUG -- trying to reduce the extra action of Bullet simulation step | ||
475 | PhysicsScene.PostTaintObject("BSPrim.StepVehicles", LocalID, delegate() | ||
476 | { | ||
477 | // This resets the interpolation values and recomputes the tensor variables | ||
478 | BulletSimAPI.SetCenterOfMassByPosRot2(BSBody.ptr, ForcePosition, ForceOrientation); | ||
479 | }); | ||
480 | */ | ||
481 | } | ||
482 | } | ||
483 | |||
484 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | 582 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more |
485 | public override void SetVolumeDetect(int param) { | 583 | public override void SetVolumeDetect(int param) { |
486 | bool newValue = (param != 0); | 584 | bool newValue = (param != 0); |
@@ -495,6 +593,11 @@ public sealed class BSPrim : BSPhysObject | |||
495 | } | 593 | } |
496 | return; | 594 | return; |
497 | } | 595 | } |
596 | public override OMV.Vector3 RawVelocity | ||
597 | { | ||
598 | get { return _velocity; } | ||
599 | set { _velocity = value; } | ||
600 | } | ||
498 | public override OMV.Vector3 Velocity { | 601 | public override OMV.Vector3 Velocity { |
499 | get { return _velocity; } | 602 | get { return _velocity; } |
500 | set { | 603 | set { |
@@ -502,22 +605,50 @@ public sealed class BSPrim : BSPhysObject | |||
502 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() | 605 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() |
503 | { | 606 | { |
504 | // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); | 607 | // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); |
505 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | 608 | ForceVelocity = _velocity; |
506 | }); | 609 | }); |
507 | } | 610 | } |
508 | } | 611 | } |
509 | public override OMV.Vector3 ForceVelocity { | 612 | public override OMV.Vector3 ForceVelocity { |
510 | get { return _velocity; } | 613 | get { return _velocity; } |
511 | set { | 614 | set { |
615 | PhysicsScene.AssertInTaintTime("BSPrim.ForceVelocity"); | ||
616 | |||
512 | _velocity = value; | 617 | _velocity = value; |
513 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | 618 | if (PhysBody.HasPhysicalBody) |
619 | { | ||
620 | DetailLog("{0},BSPrim.ForceVelocity,taint,vel={1}", LocalID, _velocity); | ||
621 | PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); | ||
622 | ActivateIfPhysical(false); | ||
623 | } | ||
514 | } | 624 | } |
515 | } | 625 | } |
516 | public override OMV.Vector3 Torque { | 626 | public override OMV.Vector3 Torque { |
517 | get { return _torque; } | 627 | get { return _torque; } |
518 | set { | 628 | set { |
519 | _torque = value; | 629 | _torque = value; |
520 | AddAngularForce(_torque, false, false); | 630 | if (_torque != OMV.Vector3.Zero) |
631 | { | ||
632 | // If the torque is non-zero, it must be reapplied each tick because | ||
633 | // Bullet clears the forces applied last frame. | ||
634 | RegisterPreStepAction("BSPrim.setTorque", LocalID, | ||
635 | delegate(float timeStep) | ||
636 | { | ||
637 | if (!IsPhysicallyActive) | ||
638 | { | ||
639 | UnRegisterPreStepAction("BSPrim.setTorque", LocalID); | ||
640 | return; | ||
641 | } | ||
642 | |||
643 | if (PhysBody.HasPhysicalBody) | ||
644 | AddAngularForce(_torque, false, true); | ||
645 | } | ||
646 | ); | ||
647 | } | ||
648 | else | ||
649 | { | ||
650 | UnRegisterPreStepAction("BSPrim.setTorque", LocalID); | ||
651 | } | ||
521 | // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); | 652 | // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); |
522 | } | 653 | } |
523 | } | 654 | } |
@@ -537,23 +668,28 @@ public sealed class BSPrim : BSPhysObject | |||
537 | } | 668 | } |
538 | public override OMV.Quaternion Orientation { | 669 | public override OMV.Quaternion Orientation { |
539 | get { | 670 | get { |
671 | /* NOTE: this refetch is not necessary. The simulator knows about linkset children | ||
672 | * and does not fetch this position info for children. Thus this is commented out. | ||
540 | // Children move around because tied to parent. Get a fresh value. | 673 | // Children move around because tied to parent. Get a fresh value. |
541 | if (!Linkset.IsRoot(this)) | 674 | if (!Linkset.IsRoot(this)) |
542 | { | 675 | { |
543 | _orientation = Linkset.Orientation(this); | 676 | _orientation = Linkset.OrientationGet(this); |
544 | } | 677 | } |
678 | */ | ||
545 | return _orientation; | 679 | return _orientation; |
546 | } | 680 | } |
547 | set { | 681 | set { |
548 | if (_orientation == value) | 682 | if (_orientation == value) |
549 | return; | 683 | return; |
550 | _orientation = value; | 684 | _orientation = value; |
551 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? | 685 | |
552 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 686 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() |
553 | { | 687 | { |
554 | // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); | 688 | ForceOrientation = _orientation; |
555 | // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 689 | |
556 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 690 | // A linkset might need to know if a component information changed. |
691 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); | ||
692 | |||
557 | }); | 693 | }); |
558 | } | 694 | } |
559 | } | 695 | } |
@@ -562,13 +698,14 @@ public sealed class BSPrim : BSPhysObject | |||
562 | { | 698 | { |
563 | get | 699 | get |
564 | { | 700 | { |
565 | _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); | 701 | _orientation = PhysicsScene.PE.GetOrientation(PhysBody); |
566 | return _orientation; | 702 | return _orientation; |
567 | } | 703 | } |
568 | set | 704 | set |
569 | { | 705 | { |
570 | _orientation = value; | 706 | _orientation = value; |
571 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 707 | if (PhysBody.HasPhysicalBody) |
708 | PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); | ||
572 | } | 709 | } |
573 | } | 710 | } |
574 | public override int PhysicsActorType { | 711 | public override int PhysicsActorType { |
@@ -583,7 +720,7 @@ public sealed class BSPrim : BSPhysObject | |||
583 | _isPhysical = value; | 720 | _isPhysical = value; |
584 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | 721 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() |
585 | { | 722 | { |
586 | // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 723 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); |
587 | SetObjectDynamic(true); | 724 | SetObjectDynamic(true); |
588 | // whether phys-to-static or static-to-phys, the object is not moving. | 725 | // whether phys-to-static or static-to-phys, the object is not moving. |
589 | ZeroMotion(true); | 726 | ZeroMotion(true); |
@@ -604,6 +741,12 @@ public sealed class BSPrim : BSPhysObject | |||
604 | get { return !IsPhantom && !_isVolumeDetect; } | 741 | get { return !IsPhantom && !_isVolumeDetect; } |
605 | } | 742 | } |
606 | 743 | ||
744 | // The object is moving and is actively being dynamic in the physical world | ||
745 | public override bool IsPhysicallyActive | ||
746 | { | ||
747 | get { return !_isSelected && IsPhysical; } | ||
748 | } | ||
749 | |||
607 | // Make gravity work if the object is physical and not selected | 750 | // Make gravity work if the object is physical and not selected |
608 | // Called at taint-time!! | 751 | // Called at taint-time!! |
609 | private void SetObjectDynamic(bool forceRebuild) | 752 | private void SetObjectDynamic(bool forceRebuild) |
@@ -624,7 +767,7 @@ public sealed class BSPrim : BSPhysObject | |||
624 | 767 | ||
625 | // Mangling all the physical properties requires the object not be in the physical world. | 768 | // Mangling all the physical properties requires the object not be in the physical world. |
626 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 769 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
627 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 770 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); |
628 | 771 | ||
629 | // Set up the object physicalness (does gravity and collisions move this object) | 772 | // Set up the object physicalness (does gravity and collisions move this object) |
630 | MakeDynamic(IsStatic); | 773 | MakeDynamic(IsStatic); |
@@ -638,16 +781,10 @@ public sealed class BSPrim : BSPhysObject | |||
638 | // Make solid or not (do things bounce off or pass through this object). | 781 | // Make solid or not (do things bounce off or pass through this object). |
639 | MakeSolid(IsSolid); | 782 | MakeSolid(IsSolid); |
640 | 783 | ||
641 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 784 | AddObjectToPhysicalWorld(); |
642 | 785 | ||
643 | // Rebuild its shape | 786 | // Rebuild its shape |
644 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 787 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); |
645 | |||
646 | // Collision filter can be set only when the object is in the world | ||
647 | if (PhysBody.collisionFilter != 0 || PhysBody.collisionMask != 0) | ||
648 | { | ||
649 | BulletSimAPI.SetCollisionFilterMask2(PhysBody.ptr, (uint)PhysBody.collisionFilter, (uint)PhysBody.collisionMask); | ||
650 | } | ||
651 | 788 | ||
652 | // Recompute any linkset parameters. | 789 | // Recompute any linkset parameters. |
653 | // When going from non-physical to physical, this re-enables the constraints that | 790 | // When going from non-physical to physical, this re-enables the constraints that |
@@ -655,8 +792,8 @@ public sealed class BSPrim : BSPhysObject | |||
655 | // For compound based linksets, this enables and disables interactions of the children. | 792 | // For compound based linksets, this enables and disables interactions of the children. |
656 | Linkset.Refresh(this); | 793 | Linkset.Refresh(this); |
657 | 794 | ||
658 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", | 795 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}", |
659 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); | 796 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape); |
660 | } | 797 | } |
661 | 798 | ||
662 | // "Making dynamic" means changing to and from static. | 799 | // "Making dynamic" means changing to and from static. |
@@ -669,74 +806,80 @@ public sealed class BSPrim : BSPhysObject | |||
669 | if (makeStatic) | 806 | if (makeStatic) |
670 | { | 807 | { |
671 | // Become a Bullet 'static' object type | 808 | // Become a Bullet 'static' object type |
672 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 809 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
673 | // Stop all movement | 810 | // Stop all movement |
674 | ZeroMotion(true); | 811 | ZeroMotion(true); |
675 | // Center of mass is at the center of the object | 812 | |
676 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); | 813 | // Set various physical properties so other object interact properly |
814 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | ||
815 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | ||
816 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | ||
817 | |||
677 | // Mass is zero which disables a bunch of physics stuff in Bullet | 818 | // Mass is zero which disables a bunch of physics stuff in Bullet |
678 | UpdatePhysicalMassProperties(0f); | 819 | UpdatePhysicalMassProperties(0f, false); |
679 | // Set collision detection parameters | 820 | // Set collision detection parameters |
680 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 821 | if (BSParam.CcdMotionThreshold > 0f) |
681 | { | 822 | { |
682 | BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | 823 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
683 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | 824 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
684 | } | 825 | } |
685 | // There can be special things needed for implementing linksets | 826 | |
686 | Linkset.MakeStatic(this); | ||
687 | // The activation state is 'disabled' so Bullet will not try to act on it. | 827 | // The activation state is 'disabled' so Bullet will not try to act on it. |
688 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); | 828 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION); |
689 | // Start it out sleeping and physical actions could wake it up. | 829 | // Start it out sleeping and physical actions could wake it up. |
690 | // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); | 830 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING); |
831 | |||
832 | // This collides like a static object | ||
833 | PhysBody.collisionType = CollisionType.Static; | ||
691 | 834 | ||
692 | PhysBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; | 835 | // There can be special things needed for implementing linksets |
693 | PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; | 836 | Linkset.MakeStatic(this); |
694 | } | 837 | } |
695 | else | 838 | else |
696 | { | 839 | { |
697 | // Not a Bullet static object | 840 | // Not a Bullet static object |
698 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 841 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
699 | 842 | ||
700 | // Set various physical properties so internal dynamic properties will get computed correctly as they are set | 843 | // Set various physical properties so other object interact properly |
701 | BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); | 844 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); |
702 | BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); | 845 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); |
846 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | ||
703 | 847 | ||
704 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 848 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
705 | // Since this can be called multiple times, only zero forces when becoming physical | 849 | // Since this can be called multiple times, only zero forces when becoming physical |
706 | // BulletSimAPI.ClearAllForces2(BSBody.ptr); | 850 | // PhysicsScene.PE.ClearAllForces(BSBody); |
707 | 851 | ||
708 | // For good measure, make sure the transform is set through to the motion state | 852 | // For good measure, make sure the transform is set through to the motion state |
709 | BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); | 853 | PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); |
710 | 854 | ||
711 | // Center of mass is at the center of the object | 855 | // Center of mass is at the center of the object |
712 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); | 856 | // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation); |
713 | 857 | ||
714 | // A dynamic object has mass | 858 | // A dynamic object has mass |
715 | UpdatePhysicalMassProperties(RawMass); | 859 | UpdatePhysicalMassProperties(RawMass, false); |
716 | 860 | ||
717 | // Set collision detection parameters | 861 | // Set collision detection parameters |
718 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 862 | if (BSParam.CcdMotionThreshold > 0f) |
719 | { | 863 | { |
720 | BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | 864 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
721 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | 865 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
722 | } | 866 | } |
723 | 867 | ||
724 | // Various values for simulation limits | 868 | // Various values for simulation limits |
725 | BulletSimAPI.SetDamping2(PhysBody.ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping); | 869 | PhysicsScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping); |
726 | BulletSimAPI.SetDeactivationTime2(PhysBody.ptr, PhysicsScene.Params.deactivationTime); | 870 | PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime); |
727 | BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | 871 | PhysicsScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); |
728 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | 872 | PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); |
729 | 873 | ||
730 | // There might be special things needed for implementing linksets. | 874 | // This collides like an object. |
731 | Linkset.MakeDynamic(this); | 875 | PhysBody.collisionType = CollisionType.Dynamic; |
732 | 876 | ||
733 | // Force activation of the object so Bullet will act on it. | 877 | // Force activation of the object so Bullet will act on it. |
734 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. | 878 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. |
735 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); | 879 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); |
736 | // BulletSimAPI.Activate2(BSBody.ptr, true); | ||
737 | 880 | ||
738 | PhysBody.collisionFilter = CollisionFilterGroups.ObjectFilter; | 881 | // There might be special things needed for implementing linksets. |
739 | PhysBody.collisionMask = CollisionFilterGroups.ObjectMask; | 882 | Linkset.MakeDynamic(this); |
740 | } | 883 | } |
741 | } | 884 | } |
742 | 885 | ||
@@ -746,7 +889,7 @@ public sealed class BSPrim : BSPhysObject | |||
746 | // the functions after this one set up the state of a possibly newly created collision body. | 889 | // the functions after this one set up the state of a possibly newly created collision body. |
747 | private void MakeSolid(bool makeSolid) | 890 | private void MakeSolid(bool makeSolid) |
748 | { | 891 | { |
749 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(PhysBody.ptr); | 892 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(PhysBody); |
750 | if (makeSolid) | 893 | if (makeSolid) |
751 | { | 894 | { |
752 | // Verify the previous code created the correct shape for this type of thing. | 895 | // Verify the previous code created the correct shape for this type of thing. |
@@ -754,7 +897,7 @@ public sealed class BSPrim : BSPhysObject | |||
754 | { | 897 | { |
755 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); | 898 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); |
756 | } | 899 | } |
757 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 900 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
758 | } | 901 | } |
759 | else | 902 | else |
760 | { | 903 | { |
@@ -762,9 +905,10 @@ public sealed class BSPrim : BSPhysObject | |||
762 | { | 905 | { |
763 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); | 906 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); |
764 | } | 907 | } |
765 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 908 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
766 | PhysBody.collisionFilter = CollisionFilterGroups.VolumeDetectFilter; | 909 | |
767 | PhysBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; | 910 | // Change collision info from a static object to a ghosty collision object |
911 | PhysBody.collisionType = CollisionType.VolumeDetect; | ||
768 | } | 912 | } |
769 | } | 913 | } |
770 | 914 | ||
@@ -773,8 +917,8 @@ public sealed class BSPrim : BSPhysObject | |||
773 | // Called in taint-time!! | 917 | // Called in taint-time!! |
774 | private void ActivateIfPhysical(bool forceIt) | 918 | private void ActivateIfPhysical(bool forceIt) |
775 | { | 919 | { |
776 | if (IsPhysical) | 920 | if (IsPhysical && PhysBody.HasPhysicalBody) |
777 | BulletSimAPI.Activate2(PhysBody.ptr, forceIt); | 921 | PhysicsScene.PE.Activate(PhysBody, forceIt); |
778 | } | 922 | } |
779 | 923 | ||
780 | // Turn on or off the flag controlling whether collision events are returned to the simulator. | 924 | // Turn on or off the flag controlling whether collision events are returned to the simulator. |
@@ -782,11 +926,27 @@ public sealed class BSPrim : BSPhysObject | |||
782 | { | 926 | { |
783 | if (wantsCollisionEvents) | 927 | if (wantsCollisionEvents) |
784 | { | 928 | { |
785 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 929 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
786 | } | 930 | } |
787 | else | 931 | else |
788 | { | 932 | { |
789 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 933 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
934 | } | ||
935 | } | ||
936 | |||
937 | // Add me to the physical world. | ||
938 | // Object MUST NOT already be in the world. | ||
939 | // This routine exists because some assorted properties get mangled by adding to the world. | ||
940 | internal void AddObjectToPhysicalWorld() | ||
941 | { | ||
942 | if (PhysBody.HasPhysicalBody) | ||
943 | { | ||
944 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | ||
945 | } | ||
946 | else | ||
947 | { | ||
948 | m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID); | ||
949 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType); | ||
790 | } | 950 | } |
791 | } | 951 | } |
792 | 952 | ||
@@ -805,18 +965,6 @@ public sealed class BSPrim : BSPhysObject | |||
805 | get { return _throttleUpdates; } | 965 | get { return _throttleUpdates; } |
806 | set { _throttleUpdates = value; } | 966 | set { _throttleUpdates = value; } |
807 | } | 967 | } |
808 | public override bool IsColliding { | ||
809 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
810 | set { _isColliding = value; } | ||
811 | } | ||
812 | public override bool CollidingGround { | ||
813 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
814 | set { _collidingGround = value; } | ||
815 | } | ||
816 | public override bool CollidingObj { | ||
817 | get { return _collidingObj; } | ||
818 | set { _collidingObj = value; } | ||
819 | } | ||
820 | public bool IsPhantom { | 968 | public bool IsPhantom { |
821 | get { | 969 | get { |
822 | // SceneObjectPart removes phantom objects from the physics scene | 970 | // SceneObjectPart removes phantom objects from the physics scene |
@@ -831,32 +979,23 @@ public sealed class BSPrim : BSPhysObject | |||
831 | PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() | 979 | PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() |
832 | { | 980 | { |
833 | if (_floatOnWater) | 981 | if (_floatOnWater) |
834 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | 982 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
835 | else | 983 | else |
836 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | 984 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
837 | }); | 985 | }); |
838 | } | 986 | } |
839 | } | 987 | } |
840 | public override OMV.Vector3 RotationalVelocity { | 988 | public override OMV.Vector3 RotationalVelocity { |
841 | get { | 989 | get { |
842 | /* | ||
843 | OMV.Vector3 pv = OMV.Vector3.Zero; | ||
844 | // if close to zero, report zero | ||
845 | // This is copied from ODE but I'm not sure why it returns zero but doesn't | ||
846 | // zero the property in the physics engine. | ||
847 | if (_rotationalVelocity.ApproxEquals(pv, 0.2f)) | ||
848 | return pv; | ||
849 | */ | ||
850 | |||
851 | return _rotationalVelocity; | 990 | return _rotationalVelocity; |
852 | } | 991 | } |
853 | set { | 992 | set { |
854 | _rotationalVelocity = value; | 993 | _rotationalVelocity = value; |
994 | Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); | ||
855 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 995 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
856 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 996 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
857 | { | 997 | { |
858 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | 998 | ForceRotationalVelocity = _rotationalVelocity; |
859 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); | ||
860 | }); | 999 | }); |
861 | } | 1000 | } |
862 | } | 1001 | } |
@@ -866,7 +1005,13 @@ public sealed class BSPrim : BSPhysObject | |||
866 | } | 1005 | } |
867 | set { | 1006 | set { |
868 | _rotationalVelocity = value; | 1007 | _rotationalVelocity = value; |
869 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); | 1008 | if (PhysBody.HasPhysicalBody) |
1009 | { | ||
1010 | DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
1011 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | ||
1012 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | ||
1013 | ActivateIfPhysical(false); | ||
1014 | } | ||
870 | } | 1015 | } |
871 | } | 1016 | } |
872 | public override bool Kinematic { | 1017 | public override bool Kinematic { |
@@ -890,9 +1035,10 @@ public sealed class BSPrim : BSPhysObject | |||
890 | set { | 1035 | set { |
891 | _buoyancy = value; | 1036 | _buoyancy = value; |
892 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 1037 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
893 | // Buoyancy is faked by changing the gravity applied to the object | 1038 | // Force the recalculation of the various inertia,etc variables in the object |
894 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 1039 | DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2}", LocalID, _buoyancy, _mass); |
895 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | 1040 | UpdatePhysicalMassProperties(_mass, true); |
1041 | ActivateIfPhysical(false); | ||
896 | } | 1042 | } |
897 | } | 1043 | } |
898 | 1044 | ||
@@ -900,17 +1046,112 @@ public sealed class BSPrim : BSPhysObject | |||
900 | public override OMV.Vector3 PIDTarget { | 1046 | public override OMV.Vector3 PIDTarget { |
901 | set { _PIDTarget = value; } | 1047 | set { _PIDTarget = value; } |
902 | } | 1048 | } |
903 | public override bool PIDActive { | ||
904 | set { _usePID = value; } | ||
905 | } | ||
906 | public override float PIDTau { | 1049 | public override float PIDTau { |
907 | set { _PIDTau = value; } | 1050 | set { _PIDTau = value; } |
908 | } | 1051 | } |
1052 | public override bool PIDActive { | ||
1053 | set { | ||
1054 | if (value) | ||
1055 | { | ||
1056 | // We're taking over after this. | ||
1057 | ZeroMotion(true); | ||
1058 | |||
1059 | _targetMotor = new BSVMotor("BSPrim.PIDTarget", | ||
1060 | _PIDTau, // timeScale | ||
1061 | BSMotor.Infinite, // decay time scale | ||
1062 | BSMotor.InfiniteVector, // friction timescale | ||
1063 | 1f // efficiency | ||
1064 | ); | ||
1065 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1066 | _targetMotor.SetTarget(_PIDTarget); | ||
1067 | _targetMotor.SetCurrent(RawPosition); | ||
1068 | /* | ||
1069 | _targetMotor = new BSPIDVMotor("BSPrim.PIDTarget"); | ||
1070 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1071 | |||
1072 | _targetMotor.SetTarget(_PIDTarget); | ||
1073 | _targetMotor.SetCurrent(RawPosition); | ||
1074 | _targetMotor.TimeScale = _PIDTau; | ||
1075 | _targetMotor.Efficiency = 1f; | ||
1076 | */ | ||
1077 | |||
1078 | RegisterPreStepAction("BSPrim.PIDTarget", LocalID, delegate(float timeStep) | ||
1079 | { | ||
1080 | if (!IsPhysicallyActive) | ||
1081 | { | ||
1082 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | ||
1083 | return; | ||
1084 | } | ||
1085 | |||
1086 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | ||
1087 | |||
1088 | // 'movePosition' is where we'd like the prim to be at this moment. | ||
1089 | OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); | ||
1090 | |||
1091 | // If we are very close to our target, turn off the movement motor. | ||
1092 | if (_targetMotor.ErrorIsZero()) | ||
1093 | { | ||
1094 | DetailLog("{0},BSPrim.PIDTarget,zeroMovement,movePos={1},pos={2},mass={3}", | ||
1095 | LocalID, movePosition, RawPosition, Mass); | ||
1096 | ForcePosition = _targetMotor.TargetValue; | ||
1097 | _targetMotor.Enabled = false; | ||
1098 | } | ||
1099 | else | ||
1100 | { | ||
1101 | ForcePosition = movePosition; | ||
1102 | } | ||
1103 | DetailLog("{0},BSPrim.PIDTarget,move,fromPos={1},movePos={2}", LocalID, origPosition, movePosition); | ||
1104 | }); | ||
1105 | } | ||
1106 | else | ||
1107 | { | ||
1108 | // Stop any targetting | ||
1109 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | ||
1110 | } | ||
1111 | } | ||
1112 | } | ||
909 | 1113 | ||
910 | // Used for llSetHoverHeight and maybe vehicle height | 1114 | // Used for llSetHoverHeight and maybe vehicle height |
911 | // Hover Height will override MoveTo target's Z | 1115 | // Hover Height will override MoveTo target's Z |
912 | public override bool PIDHoverActive { | 1116 | public override bool PIDHoverActive { |
913 | set { _useHoverPID = value; } | 1117 | set { |
1118 | if (value) | ||
1119 | { | ||
1120 | // Turning the target on | ||
1121 | _hoverMotor = new BSFMotor("BSPrim.Hover", | ||
1122 | _PIDHoverTau, // timeScale | ||
1123 | BSMotor.Infinite, // decay time scale | ||
1124 | BSMotor.Infinite, // friction timescale | ||
1125 | 1f // efficiency | ||
1126 | ); | ||
1127 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1128 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1129 | _hoverMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1130 | |||
1131 | RegisterPreStepAction("BSPrim.Hover", LocalID, delegate(float timeStep) | ||
1132 | { | ||
1133 | if (!IsPhysicallyActive) | ||
1134 | return; | ||
1135 | |||
1136 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1137 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1138 | float targetHeight = _hoverMotor.Step(timeStep); | ||
1139 | |||
1140 | // 'targetHeight' is where we'd like the Z of the prim to be at this moment. | ||
1141 | // Compute the amount of force to push us there. | ||
1142 | float moveForce = (targetHeight - RawPosition.Z) * Mass; | ||
1143 | // Undo anything the object thinks it's doing at the moment | ||
1144 | moveForce = -RawVelocity.Z * Mass; | ||
1145 | |||
1146 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, new OMV.Vector3(0f, 0f, moveForce)); | ||
1147 | DetailLog("{0},BSPrim.Hover,move,targHt={1},moveForce={2},mass={3}", LocalID, targetHeight, moveForce, Mass); | ||
1148 | }); | ||
1149 | } | ||
1150 | else | ||
1151 | { | ||
1152 | UnRegisterPreStepAction("BSPrim.Hover", LocalID); | ||
1153 | } | ||
1154 | } | ||
914 | } | 1155 | } |
915 | public override float PIDHoverHeight { | 1156 | public override float PIDHoverHeight { |
916 | set { _PIDHoverHeight = value; } | 1157 | set { _PIDHoverHeight = value; } |
@@ -919,8 +1160,35 @@ public sealed class BSPrim : BSPhysObject | |||
919 | set { _PIDHoverType = value; } | 1160 | set { _PIDHoverType = value; } |
920 | } | 1161 | } |
921 | public override float PIDHoverTau { | 1162 | public override float PIDHoverTau { |
922 | set { _PIDHoverTao = value; } | 1163 | set { _PIDHoverTau = value; } |
923 | } | 1164 | } |
1165 | // Based on current position, determine what we should be hovering at now. | ||
1166 | // Must recompute often. What if we walked offa cliff> | ||
1167 | private float ComputeCurrentPIDHoverHeight() | ||
1168 | { | ||
1169 | float ret = _PIDHoverHeight; | ||
1170 | float groundHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); | ||
1171 | |||
1172 | switch (_PIDHoverType) | ||
1173 | { | ||
1174 | case PIDHoverType.Ground: | ||
1175 | ret = groundHeight + _PIDHoverHeight; | ||
1176 | break; | ||
1177 | case PIDHoverType.GroundAndWater: | ||
1178 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition); | ||
1179 | if (groundHeight > waterHeight) | ||
1180 | { | ||
1181 | ret = groundHeight + _PIDHoverHeight; | ||
1182 | } | ||
1183 | else | ||
1184 | { | ||
1185 | ret = waterHeight + _PIDHoverHeight; | ||
1186 | } | ||
1187 | break; | ||
1188 | } | ||
1189 | return ret; | ||
1190 | } | ||
1191 | |||
924 | 1192 | ||
925 | // For RotLookAt | 1193 | // For RotLookAt |
926 | public override OMV.Quaternion APIDTarget { set { return; } } | 1194 | public override OMV.Quaternion APIDTarget { set { return; } } |
@@ -928,54 +1196,73 @@ public sealed class BSPrim : BSPhysObject | |||
928 | public override float APIDStrength { set { return; } } | 1196 | public override float APIDStrength { set { return; } } |
929 | public override float APIDDamping { set { return; } } | 1197 | public override float APIDDamping { set { return; } } |
930 | 1198 | ||
931 | private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>(); | ||
932 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 1199 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
933 | AddForce(force, pushforce, false); | 1200 | // Per documentation, max force is limited. |
1201 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | ||
1202 | |||
1203 | // Since this force is being applied in only one step, make this a force per second. | ||
1204 | addForce /= PhysicsScene.LastTimeStep; | ||
1205 | AddForce(addForce, pushforce, false /* inTaintTime */); | ||
934 | } | 1206 | } |
1207 | |||
935 | // Applying a force just adds this to the total force on the object. | 1208 | // Applying a force just adds this to the total force on the object. |
1209 | // This added force will only last the next simulation tick. | ||
936 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 1210 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
937 | // for an object, doesn't matter if force is a pushforce or not | 1211 | // for an object, doesn't matter if force is a pushforce or not |
938 | if (force.IsFinite()) | 1212 | if (IsPhysicallyActive) |
939 | { | ||
940 | // _force += force; | ||
941 | lock (m_accumulatedForces) | ||
942 | m_accumulatedForces.Add(new OMV.Vector3(force)); | ||
943 | } | ||
944 | else | ||
945 | { | 1213 | { |
946 | m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); | 1214 | if (force.IsFinite()) |
947 | return; | ||
948 | } | ||
949 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | ||
950 | { | ||
951 | OMV.Vector3 fSum = OMV.Vector3.Zero; | ||
952 | lock (m_accumulatedForces) | ||
953 | { | 1215 | { |
954 | // Sum the accumulated additional forces for one big force to apply once. | 1216 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
955 | foreach (OMV.Vector3 v in m_accumulatedForces) | 1217 | |
1218 | OMV.Vector3 addForce = force; | ||
1219 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | ||
956 | { | 1220 | { |
957 | fSum += v; | 1221 | // Bullet adds this central force to the total force for this tick |
958 | } | 1222 | DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); |
959 | m_accumulatedForces.Clear(); | 1223 | if (PhysBody.HasPhysicalBody) |
1224 | { | ||
1225 | PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); | ||
1226 | ActivateIfPhysical(false); | ||
1227 | } | ||
1228 | }); | ||
960 | } | 1229 | } |
961 | DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum); | 1230 | else |
962 | if (fSum != OMV.Vector3.Zero) | 1231 | { |
963 | BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); | 1232 | m_log.WarnFormat("{0}: AddForce: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); |
964 | }); | 1233 | return; |
1234 | } | ||
1235 | } | ||
965 | } | 1236 | } |
966 | 1237 | ||
967 | // An impulse force is scaled by the mass of the object. | 1238 | public void AddForceImpulse(OMV.Vector3 impulse, bool pushforce, bool inTaintTime) { |
968 | public void ApplyForceImpulse(OMV.Vector3 impulse, bool inTaintTime) | 1239 | // for an object, doesn't matter if force is a pushforce or not |
969 | { | 1240 | if (!IsPhysicallyActive) |
970 | OMV.Vector3 applyImpulse = impulse; | ||
971 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate() | ||
972 | { | 1241 | { |
973 | DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse); | 1242 | if (impulse.IsFinite()) |
974 | BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); | 1243 | { |
975 | }); | 1244 | OMV.Vector3 addImpulse = Util.ClampV(impulse, BSParam.MaxAddForceMagnitude); |
1245 | // DetailLog("{0},BSPrim.addForceImpulse,call,impulse={1}", LocalID, impulse); | ||
1246 | |||
1247 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddImpulse", delegate() | ||
1248 | { | ||
1249 | // Bullet adds this impulse immediately to the velocity | ||
1250 | DetailLog("{0},BSPrim.addForceImpulse,taint,impulseforce={1}", LocalID, addImpulse); | ||
1251 | if (PhysBody.HasPhysicalBody) | ||
1252 | { | ||
1253 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, addImpulse); | ||
1254 | ActivateIfPhysical(false); | ||
1255 | } | ||
1256 | }); | ||
1257 | } | ||
1258 | else | ||
1259 | { | ||
1260 | m_log.WarnFormat("{0}: AddForceImpulse: Got a NaN impulse applied to a prim. LocalID={1}", LogHeader, LocalID); | ||
1261 | return; | ||
1262 | } | ||
1263 | } | ||
976 | } | 1264 | } |
977 | 1265 | ||
978 | private List<OMV.Vector3> m_accumulatedAngularForces = new List<OMV.Vector3>(); | ||
979 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 1266 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
980 | AddAngularForce(force, pushforce, false); | 1267 | AddAngularForce(force, pushforce, false); |
981 | } | 1268 | } |
@@ -983,42 +1270,37 @@ public sealed class BSPrim : BSPhysObject | |||
983 | { | 1270 | { |
984 | if (force.IsFinite()) | 1271 | if (force.IsFinite()) |
985 | { | 1272 | { |
986 | // _force += force; | 1273 | OMV.Vector3 angForce = force; |
987 | lock (m_accumulatedAngularForces) | 1274 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate() |
988 | m_accumulatedAngularForces.Add(new OMV.Vector3(force)); | 1275 | { |
1276 | if (PhysBody.HasPhysicalBody) | ||
1277 | { | ||
1278 | PhysicsScene.PE.ApplyTorque(PhysBody, angForce); | ||
1279 | ActivateIfPhysical(false); | ||
1280 | } | ||
1281 | }); | ||
989 | } | 1282 | } |
990 | else | 1283 | else |
991 | { | 1284 | { |
992 | m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); | 1285 | m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); |
993 | return; | 1286 | return; |
994 | } | 1287 | } |
995 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate() | ||
996 | { | ||
997 | OMV.Vector3 fSum = OMV.Vector3.Zero; | ||
998 | lock (m_accumulatedAngularForces) | ||
999 | { | ||
1000 | // Sum the accumulated additional forces for one big force to apply once. | ||
1001 | foreach (OMV.Vector3 v in m_accumulatedAngularForces) | ||
1002 | { | ||
1003 | fSum += v; | ||
1004 | } | ||
1005 | m_accumulatedAngularForces.Clear(); | ||
1006 | } | ||
1007 | DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum); | ||
1008 | if (fSum != OMV.Vector3.Zero) | ||
1009 | { | ||
1010 | BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); | ||
1011 | _torque = fSum; | ||
1012 | } | ||
1013 | }); | ||
1014 | } | 1288 | } |
1289 | |||
1015 | // A torque impulse. | 1290 | // A torque impulse. |
1291 | // ApplyTorqueImpulse adds torque directly to the angularVelocity. | ||
1292 | // AddAngularForce accumulates the force and applied it to the angular velocity all at once. | ||
1293 | // Computed as: angularVelocity += impulse * inertia; | ||
1016 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) | 1294 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) |
1017 | { | 1295 | { |
1018 | OMV.Vector3 applyImpulse = impulse; | 1296 | OMV.Vector3 applyImpulse = impulse; |
1019 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() | 1297 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() |
1020 | { | 1298 | { |
1021 | BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); | 1299 | if (PhysBody.HasPhysicalBody) |
1300 | { | ||
1301 | PhysicsScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse); | ||
1302 | ActivateIfPhysical(false); | ||
1303 | } | ||
1022 | }); | 1304 | }); |
1023 | } | 1305 | } |
1024 | 1306 | ||
@@ -1313,11 +1595,7 @@ public sealed class BSPrim : BSPhysObject | |||
1313 | } | 1595 | } |
1314 | */ | 1596 | */ |
1315 | 1597 | ||
1316 | if (returnMass <= 0) | 1598 | returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); |
1317 | returnMass = 0.0001f; | ||
1318 | |||
1319 | if (returnMass > PhysicsScene.MaximumObjectMass) | ||
1320 | returnMass = PhysicsScene.MaximumObjectMass; | ||
1321 | 1599 | ||
1322 | return returnMass; | 1600 | return returnMass; |
1323 | }// end CalculateMass | 1601 | }// end CalculateMass |
@@ -1326,7 +1604,7 @@ public sealed class BSPrim : BSPhysObject | |||
1326 | // Rebuild the geometry and object. | 1604 | // Rebuild the geometry and object. |
1327 | // This is called when the shape changes so we need to recreate the mesh/hull. | 1605 | // This is called when the shape changes so we need to recreate the mesh/hull. |
1328 | // Called at taint-time!!! | 1606 | // Called at taint-time!!! |
1329 | private void CreateGeomAndObject(bool forceRebuild) | 1607 | public void CreateGeomAndObject(bool forceRebuild) |
1330 | { | 1608 | { |
1331 | // If this prim is part of a linkset, we must remove and restore the physical | 1609 | // If this prim is part of a linkset, we must remove and restore the physical |
1332 | // links if the body is rebuilt. | 1610 | // links if the body is rebuilt. |
@@ -1336,12 +1614,11 @@ public sealed class BSPrim : BSPhysObject | |||
1336 | // Create the correct physical representation for this type of object. | 1614 | // Create the correct physical representation for this type of object. |
1337 | // Updates PhysBody and PhysShape with the new information. | 1615 | // Updates PhysBody and PhysShape with the new information. |
1338 | // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. | 1616 | // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. |
1339 | // Returns 'true' if either the body or the shape was changed. | ||
1340 | PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody) | 1617 | PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody) |
1341 | { | 1618 | { |
1342 | // Called if the current prim body is about to be destroyed. | 1619 | // Called if the current prim body is about to be destroyed. |
1343 | // Remove all the physical dependencies on the old body. | 1620 | // Remove all the physical dependencies on the old body. |
1344 | // (Maybe someday make the changing of BSShape an event handled by BSLinkset.) | 1621 | // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) |
1345 | needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); | 1622 | needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); |
1346 | needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this); | 1623 | needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this); |
1347 | }); | 1624 | }); |
@@ -1364,72 +1641,20 @@ public sealed class BSPrim : BSPhysObject | |||
1364 | 1641 | ||
1365 | // The physics engine says that properties have updated. Update same and inform | 1642 | // The physics engine says that properties have updated. Update same and inform |
1366 | // the world that things have changed. | 1643 | // the world that things have changed. |
1367 | // TODO: do we really need to check for changed? Maybe just copy values and call RequestPhysicsterseUpdate() | ||
1368 | enum UpdatedProperties { | ||
1369 | Position = 1 << 0, | ||
1370 | Rotation = 1 << 1, | ||
1371 | Velocity = 1 << 2, | ||
1372 | Acceleration = 1 << 3, | ||
1373 | RotationalVel = 1 << 4 | ||
1374 | } | ||
1375 | |||
1376 | const float ROTATION_TOLERANCE = 0.01f; | ||
1377 | const float VELOCITY_TOLERANCE = 0.001f; | ||
1378 | const float POSITION_TOLERANCE = 0.05f; | ||
1379 | const float ACCELERATION_TOLERANCE = 0.01f; | ||
1380 | const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f; | ||
1381 | |||
1382 | public override void UpdateProperties(EntityProperties entprop) | 1644 | public override void UpdateProperties(EntityProperties entprop) |
1383 | { | 1645 | { |
1384 | /* | 1646 | // Updates only for individual prims and for the root object of a linkset. |
1385 | UpdatedProperties changed = 0; | 1647 | if (Linkset.IsRoot(this)) |
1386 | // assign to the local variables so the normal set action does not happen | ||
1387 | // if (_position != entprop.Position) | ||
1388 | if (!_position.ApproxEquals(entprop.Position, POSITION_TOLERANCE)) | ||
1389 | { | ||
1390 | _position = entprop.Position; | ||
1391 | changed |= UpdatedProperties.Position; | ||
1392 | } | ||
1393 | // if (_orientation != entprop.Rotation) | ||
1394 | if (!_orientation.ApproxEquals(entprop.Rotation, ROTATION_TOLERANCE)) | ||
1395 | { | ||
1396 | _orientation = entprop.Rotation; | ||
1397 | changed |= UpdatedProperties.Rotation; | ||
1398 | } | ||
1399 | // if (_velocity != entprop.Velocity) | ||
1400 | if (!_velocity.ApproxEquals(entprop.Velocity, VELOCITY_TOLERANCE)) | ||
1401 | { | ||
1402 | _velocity = entprop.Velocity; | ||
1403 | changed |= UpdatedProperties.Velocity; | ||
1404 | } | ||
1405 | // if (_acceleration != entprop.Acceleration) | ||
1406 | if (!_acceleration.ApproxEquals(entprop.Acceleration, ACCELERATION_TOLERANCE)) | ||
1407 | { | ||
1408 | _acceleration = entprop.Acceleration; | ||
1409 | changed |= UpdatedProperties.Acceleration; | ||
1410 | } | ||
1411 | // if (_rotationalVelocity != entprop.RotationalVelocity) | ||
1412 | if (!_rotationalVelocity.ApproxEquals(entprop.RotationalVelocity, ROTATIONAL_VELOCITY_TOLERANCE)) | ||
1413 | { | ||
1414 | _rotationalVelocity = entprop.RotationalVelocity; | ||
1415 | changed |= UpdatedProperties.RotationalVel; | ||
1416 | } | ||
1417 | if (changed != 0) | ||
1418 | { | 1648 | { |
1419 | // Only update the position of single objects and linkset roots | 1649 | // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet |
1420 | if (Linkset.IsRoot(this)) | 1650 | // TODO: handle physics introduced by Bullet with computed vehicle physics. |
1651 | if (_vehicle.IsActive) | ||
1421 | { | 1652 | { |
1422 | base.RequestPhysicsterseUpdate(); | 1653 | // entprop.RotationalVelocity = OMV.Vector3.Zero; |
1423 | } | 1654 | } |
1424 | } | ||
1425 | */ | ||
1426 | |||
1427 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. | ||
1428 | 1655 | ||
1429 | // Updates only for individual prims and for the root object of a linkset. | 1656 | // Assign directly to the local variables so the normal set actions do not happen |
1430 | if (Linkset.IsRoot(this)) | 1657 | entprop.Position -= PositionDisplacement; |
1431 | { | ||
1432 | // Assign directly to the local variables so the normal set action does not happen | ||
1433 | _position = entprop.Position; | 1658 | _position = entprop.Position; |
1434 | _orientation = entprop.Rotation; | 1659 | _orientation = entprop.Rotation; |
1435 | _velocity = entprop.Velocity; | 1660 | _velocity = entprop.Velocity; |
@@ -1437,21 +1662,19 @@ public sealed class BSPrim : BSPhysObject | |||
1437 | _rotationalVelocity = entprop.RotationalVelocity; | 1662 | _rotationalVelocity = entprop.RotationalVelocity; |
1438 | 1663 | ||
1439 | // The sanity check can change the velocity and/or position. | 1664 | // The sanity check can change the velocity and/or position. |
1440 | if (PositionSanityCheck(true)) | 1665 | if (IsPhysical && PositionSanityCheck(true)) |
1441 | { | 1666 | { |
1442 | entprop.Position = _position; | 1667 | entprop.Position = _position; |
1443 | entprop.Velocity = _velocity; | 1668 | entprop.Velocity = _velocity; |
1444 | } | 1669 | } |
1445 | 1670 | ||
1446 | // remember the current and last set values | 1671 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG |
1447 | LastEntityProperties = CurrentEntityProperties; | ||
1448 | CurrentEntityProperties = entprop; | ||
1449 | |||
1450 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; | ||
1451 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", | 1672 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", |
1452 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); | 1673 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); |
1453 | 1674 | ||
1454 | // BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, BSBody.ptr); // DEBUG DEBUG DEBUG | 1675 | // remember the current and last set values |
1676 | LastEntityProperties = CurrentEntityProperties; | ||
1677 | CurrentEntityProperties = entprop; | ||
1455 | 1678 | ||
1456 | base.RequestPhysicsterseUpdate(); | 1679 | base.RequestPhysicsterseUpdate(); |
1457 | } | 1680 | } |
@@ -1466,7 +1689,7 @@ public sealed class BSPrim : BSPhysObject | |||
1466 | */ | 1689 | */ |
1467 | 1690 | ||
1468 | // The linkset implimentation might want to know about this. | 1691 | // The linkset implimentation might want to know about this. |
1469 | Linkset.UpdateProperties(this); | 1692 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
1470 | } | 1693 | } |
1471 | } | 1694 | } |
1472 | } | 1695 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 27a78d1..8075b73 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | ||
29 | using System.Runtime.InteropServices; | 30 | using System.Runtime.InteropServices; |
30 | using System.Text; | 31 | using System.Text; |
31 | using System.Threading; | 32 | using System.Threading; |
@@ -38,40 +39,22 @@ using Nini.Config; | |||
38 | using log4net; | 39 | using log4net; |
39 | using OpenMetaverse; | 40 | using OpenMetaverse; |
40 | 41 | ||
41 | // TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) | ||
42 | // Test sculpties (verified that they don't work) | ||
43 | // Compute physics FPS reasonably | ||
44 | // Based on material, set density and friction | ||
45 | // Don't use constraints in linksets of non-physical objects. Means having to move children manually. | ||
46 | // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? | ||
47 | // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) | ||
48 | // At the moment, physical and phantom causes object to drop through the terrain | ||
49 | // Physical phantom objects and related typing (collision options ) | ||
50 | // Check out llVolumeDetect. Must do something for that. | ||
51 | // Use collision masks for collision with terrain and phantom objects | ||
52 | // More efficient memory usage when passing hull information from BSPrim to BulletSim | ||
53 | // Should prim.link() and prim.delink() membership checking happen at taint time? | ||
54 | // Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once. | ||
55 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect | ||
56 | // Implement LockAngularMotion | ||
57 | // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) | ||
58 | // Remove mesh and Hull stuff. Use mesh passed to bullet and use convexdecom from bullet. | ||
59 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? | ||
60 | // Check terrain size. 128 or 127? | ||
61 | // Raycast | ||
62 | // | ||
63 | namespace OpenSim.Region.Physics.BulletSPlugin | 42 | namespace OpenSim.Region.Physics.BulletSPlugin |
64 | { | 43 | { |
65 | public sealed class BSScene : PhysicsScene, IPhysicsParameters | 44 | public sealed class BSScene : PhysicsScene, IPhysicsParameters |
66 | { | 45 | { |
67 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 46 | internal static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
68 | private static readonly string LogHeader = "[BULLETS SCENE]"; | 47 | internal static readonly string LogHeader = "[BULLETS SCENE]"; |
69 | 48 | ||
70 | // The name of the region we're working for. | 49 | // The name of the region we're working for. |
71 | public string RegionName { get; private set; } | 50 | public string RegionName { get; private set; } |
72 | 51 | ||
73 | public string BulletSimVersion = "?"; | 52 | public string BulletSimVersion = "?"; |
74 | 53 | ||
54 | // The handle to the underlying managed or unmanaged version of Bullet being used. | ||
55 | public string BulletEngineName { get; private set; } | ||
56 | public BSAPITemplate PE; | ||
57 | |||
75 | public Dictionary<uint, BSPhysObject> PhysObjects; | 58 | public Dictionary<uint, BSPhysObject> PhysObjects; |
76 | public BSShapeCollection Shapes; | 59 | public BSShapeCollection Shapes; |
77 | 60 | ||
@@ -82,32 +65,29 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
82 | // every tick so OpenSim will update its animation. | 65 | // every tick so OpenSim will update its animation. |
83 | private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>(); | 66 | private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>(); |
84 | 67 | ||
85 | // List of all the objects that have vehicle properties and should be called | ||
86 | // to update each physics step. | ||
87 | private List<BSPhysObject> m_vehicles = new List<BSPhysObject>(); | ||
88 | |||
89 | // let my minuions use my logger | 68 | // let my minuions use my logger |
90 | public ILog Logger { get { return m_log; } } | 69 | public ILog Logger { get { return m_log; } } |
91 | 70 | ||
92 | public IMesher mesher; | 71 | public IMesher mesher; |
93 | // Level of Detail values kept as float because that's what the Meshmerizer wants | ||
94 | public float MeshLOD { get; private set; } | ||
95 | public float MeshMegaPrimLOD { get; private set; } | ||
96 | public float MeshMegaPrimThreshold { get; private set; } | ||
97 | public float SculptLOD { get; private set; } | ||
98 | |||
99 | public uint WorldID { get; private set; } | 72 | public uint WorldID { get; private set; } |
100 | public BulletSim World { get; private set; } | 73 | public BulletWorld World { get; private set; } |
101 | 74 | ||
102 | // All the constraints that have been allocated in this instance. | 75 | // All the constraints that have been allocated in this instance. |
103 | public BSConstraintCollection Constraints { get; private set; } | 76 | public BSConstraintCollection Constraints { get; private set; } |
104 | 77 | ||
105 | // Simulation parameters | 78 | // Simulation parameters |
106 | private int m_maxSubSteps; | 79 | internal int m_maxSubSteps; |
107 | private float m_fixedTimeStep; | 80 | internal float m_fixedTimeStep; |
108 | private long m_simulationStep = 0; | 81 | internal long m_simulationStep = 0; |
82 | internal float NominalFrameRate { get; set; } | ||
109 | public long SimulationStep { get { return m_simulationStep; } } | 83 | public long SimulationStep { get { return m_simulationStep; } } |
110 | private int m_taintsToProcessPerStep; | 84 | internal float LastTimeStep { get; private set; } |
85 | |||
86 | // Physical objects can register for prestep or poststep events | ||
87 | public delegate void PreStepAction(float timeStep); | ||
88 | public delegate void PostStepAction(float timeStep); | ||
89 | public event PreStepAction BeforeStep; | ||
90 | public event PreStepAction AfterStep; | ||
111 | 91 | ||
112 | // A value of the time now so all the collision and update routines do not have to get their own | 92 | // A value of the time now so all the collision and update routines do not have to get their own |
113 | // Set to 'now' just before all the prims and actors are called for collisions and updates | 93 | // Set to 'now' just before all the prims and actors are called for collisions and updates |
@@ -121,31 +101,22 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
121 | public bool InTaintTime { get; private set; } | 101 | public bool InTaintTime { get; private set; } |
122 | 102 | ||
123 | // Pinned memory used to pass step information between managed and unmanaged | 103 | // Pinned memory used to pass step information between managed and unmanaged |
124 | private int m_maxCollisionsPerFrame; | 104 | internal int m_maxCollisionsPerFrame; |
125 | private CollisionDesc[] m_collisionArray; | 105 | internal CollisionDesc[] m_collisionArray; |
126 | private GCHandle m_collisionArrayPinnedHandle; | ||
127 | 106 | ||
128 | private int m_maxUpdatesPerFrame; | 107 | internal int m_maxUpdatesPerFrame; |
129 | private EntityProperties[] m_updateArray; | 108 | internal EntityProperties[] m_updateArray; |
130 | private GCHandle m_updateArrayPinnedHandle; | ||
131 | |||
132 | public bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed | ||
133 | public bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes | ||
134 | public bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | ||
135 | |||
136 | public float PID_D { get; private set; } // derivative | ||
137 | public float PID_P { get; private set; } // proportional | ||
138 | 109 | ||
139 | public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero | 110 | public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero |
140 | public const uint GROUNDPLANE_ID = 1; | 111 | public const uint GROUNDPLANE_ID = 1; |
141 | public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here | 112 | public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here |
142 | 113 | ||
143 | private float m_waterLevel; | 114 | public float SimpleWaterLevel { get; set; } |
144 | public BSTerrainManager TerrainManager { get; private set; } | 115 | public BSTerrainManager TerrainManager { get; private set; } |
145 | 116 | ||
146 | public ConfigurationParameters Params | 117 | public ConfigurationParameters Params |
147 | { | 118 | { |
148 | get { return m_params[0]; } | 119 | get { return UnmanagedParams[0]; } |
149 | } | 120 | } |
150 | public Vector3 DefaultGravity | 121 | public Vector3 DefaultGravity |
151 | { | 122 | { |
@@ -157,8 +128,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
157 | get { return Params.gravity; } | 128 | get { return Params.gravity; } |
158 | } | 129 | } |
159 | 130 | ||
160 | public float MaximumObjectMass { get; private set; } | ||
161 | |||
162 | // When functions in the unmanaged code must be called, it is only | 131 | // When functions in the unmanaged code must be called, it is only |
163 | // done at a known time just before the simulation step. The taint | 132 | // done at a known time just before the simulation step. The taint |
164 | // system saves all these function calls and executes them in | 133 | // system saves all these function calls and executes them in |
@@ -181,13 +150,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
181 | 150 | ||
182 | // A pointer to an instance if this structure is passed to the C++ code | 151 | // A pointer to an instance if this structure is passed to the C++ code |
183 | // Used to pass basic configuration values to the unmanaged code. | 152 | // Used to pass basic configuration values to the unmanaged code. |
184 | ConfigurationParameters[] m_params; | 153 | internal ConfigurationParameters[] UnmanagedParams; |
185 | GCHandle m_paramsHandle; | ||
186 | |||
187 | // Handle to the callback used by the unmanaged code to call into the managed code. | ||
188 | // Used for debug logging. | ||
189 | // Need to store the handle in a persistant variable so it won't be freed. | ||
190 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; | ||
191 | 154 | ||
192 | // Sometimes you just have to log everything. | 155 | // Sometimes you just have to log everything. |
193 | public Logging.LogWriter PhysicsLogging; | 156 | public Logging.LogWriter PhysicsLogging; |
@@ -195,15 +158,24 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
195 | private string m_physicsLoggingDir; | 158 | private string m_physicsLoggingDir; |
196 | private string m_physicsLoggingPrefix; | 159 | private string m_physicsLoggingPrefix; |
197 | private int m_physicsLoggingFileMinutes; | 160 | private int m_physicsLoggingFileMinutes; |
161 | private bool m_physicsLoggingDoFlush; | ||
162 | private bool m_physicsPhysicalDumpEnabled; | ||
163 | public float PhysicsMetricDumpFrames { get; set; } | ||
198 | // 'true' of the vehicle code is to log lots of details | 164 | // 'true' of the vehicle code is to log lots of details |
199 | public bool VehicleLoggingEnabled { get; private set; } | 165 | public bool VehicleLoggingEnabled { get; private set; } |
166 | public bool VehiclePhysicalLoggingEnabled { get; private set; } | ||
200 | 167 | ||
201 | #region Construction and Initialization | 168 | #region Construction and Initialization |
202 | public BSScene(string identifier) | 169 | public BSScene(string engineType, string identifier) |
203 | { | 170 | { |
204 | m_initialized = false; | 171 | m_initialized = false; |
205 | // we are passed the name of the region we're working for. | 172 | |
173 | // The name of the region we're working for is passed to us. Keep for identification. | ||
206 | RegionName = identifier; | 174 | RegionName = identifier; |
175 | |||
176 | // Set identifying variables in the PhysicsScene interface. | ||
177 | EngineType = engineType; | ||
178 | Name = EngineType + "/" + RegionName; | ||
207 | } | 179 | } |
208 | 180 | ||
209 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | 181 | public override void Initialise(IMesher meshmerizer, IConfigSource config) |
@@ -216,17 +188,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
216 | Shapes = new BSShapeCollection(this); | 188 | Shapes = new BSShapeCollection(this); |
217 | 189 | ||
218 | // Allocate pinned memory to pass parameters. | 190 | // Allocate pinned memory to pass parameters. |
219 | m_params = new ConfigurationParameters[1]; | 191 | UnmanagedParams = new ConfigurationParameters[1]; |
220 | m_paramsHandle = GCHandle.Alloc(m_params, GCHandleType.Pinned); | ||
221 | 192 | ||
222 | // Set default values for physics parameters plus any overrides from the ini file | 193 | // Set default values for physics parameters plus any overrides from the ini file |
223 | GetInitialParameterValues(config); | 194 | GetInitialParameterValues(config); |
224 | 195 | ||
225 | // allocate more pinned memory close to the above in an attempt to get the memory all together | 196 | // Get the connection to the physics engine (could be native or one of many DLLs) |
226 | m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; | 197 | PE = SelectUnderlyingBulletEngine(BulletEngineName); |
227 | m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned); | ||
228 | m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; | ||
229 | m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned); | ||
230 | 198 | ||
231 | // Enable very detailed logging. | 199 | // Enable very detailed logging. |
232 | // By creating an empty logger when not logging, the log message invocation code | 200 | // By creating an empty logger when not logging, the log message invocation code |
@@ -234,28 +202,16 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
234 | if (m_physicsLoggingEnabled) | 202 | if (m_physicsLoggingEnabled) |
235 | { | 203 | { |
236 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); | 204 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); |
205 | PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output error messages. | ||
237 | } | 206 | } |
238 | else | 207 | else |
239 | { | 208 | { |
240 | PhysicsLogging = new Logging.LogWriter(); | 209 | PhysicsLogging = new Logging.LogWriter(); |
241 | } | 210 | } |
242 | 211 | ||
243 | // If Debug logging level, enable logging from the unmanaged code | 212 | // Allocate memory for returning of the updates and collisions from the physics engine |
244 | m_DebugLogCallbackHandle = null; | 213 | m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; |
245 | if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) | 214 | m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; |
246 | { | ||
247 | m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); | ||
248 | if (PhysicsLogging.Enabled) | ||
249 | // The handle is saved in a variable to make sure it doesn't get freed after this call | ||
250 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog); | ||
251 | else | ||
252 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); | ||
253 | } | ||
254 | |||
255 | // Get the version of the DLL | ||
256 | // TODO: this doesn't work yet. Something wrong with marshaling the returned string. | ||
257 | // BulletSimVersion = BulletSimAPI.GetVersion(); | ||
258 | // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); | ||
259 | 215 | ||
260 | // The bounding box for the simulated world. The origin is 0,0,0 unless we're | 216 | // The bounding box for the simulated world. The origin is 0,0,0 unless we're |
261 | // a child in a mega-region. | 217 | // a child in a mega-region. |
@@ -263,18 +219,14 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
263 | // area. It tracks active objects no matter where they are. | 219 | // area. It tracks active objects no matter where they are. |
264 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 220 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
265 | 221 | ||
266 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); | 222 | World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray); |
267 | World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(), | ||
268 | m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), | ||
269 | m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(), | ||
270 | m_DebugLogCallbackHandle)); | ||
271 | 223 | ||
272 | Constraints = new BSConstraintCollection(World); | 224 | Constraints = new BSConstraintCollection(World); |
273 | 225 | ||
274 | TerrainManager = new BSTerrainManager(this); | 226 | TerrainManager = new BSTerrainManager(this); |
275 | TerrainManager.CreateInitialGroundPlaneAndTerrain(); | 227 | TerrainManager.CreateInitialGroundPlaneAndTerrain(); |
276 | 228 | ||
277 | m_log.WarnFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)Params.linksetImplementation); | 229 | m_log.WarnFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation); |
278 | 230 | ||
279 | InTaintTime = false; | 231 | InTaintTime = false; |
280 | m_initialized = true; | 232 | m_initialized = true; |
@@ -285,9 +237,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
285 | private void GetInitialParameterValues(IConfigSource config) | 237 | private void GetInitialParameterValues(IConfigSource config) |
286 | { | 238 | { |
287 | ConfigurationParameters parms = new ConfigurationParameters(); | 239 | ConfigurationParameters parms = new ConfigurationParameters(); |
288 | m_params[0] = parms; | 240 | UnmanagedParams[0] = parms; |
289 | 241 | ||
290 | SetParameterDefaultValues(); | 242 | BSParam.SetParameterDefaultValues(this); |
291 | 243 | ||
292 | if (config != null) | 244 | if (config != null) |
293 | { | 245 | { |
@@ -295,19 +247,34 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
295 | IConfig pConfig = config.Configs["BulletSim"]; | 247 | IConfig pConfig = config.Configs["BulletSim"]; |
296 | if (pConfig != null) | 248 | if (pConfig != null) |
297 | { | 249 | { |
298 | SetParameterConfigurationValues(pConfig); | 250 | BSParam.SetParameterConfigurationValues(this, pConfig); |
251 | |||
252 | // There are two Bullet implementations to choose from | ||
253 | BulletEngineName = pConfig.GetString("BulletEngine", "BulletUnmanaged"); | ||
299 | 254 | ||
300 | // Very detailed logging for physics debugging | 255 | // Very detailed logging for physics debugging |
256 | // TODO: the boolean values can be moved to the normal parameter processing. | ||
301 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); | 257 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); |
302 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); | 258 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); |
303 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-"); | 259 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-"); |
304 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); | 260 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); |
261 | m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false); | ||
262 | m_physicsPhysicalDumpEnabled = pConfig.GetBoolean("PhysicsPhysicalDumpEnabled", false); | ||
305 | // Very detailed logging for vehicle debugging | 263 | // Very detailed logging for vehicle debugging |
306 | VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); | 264 | VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); |
265 | VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false); | ||
307 | 266 | ||
308 | // Do any replacements in the parameters | 267 | // Do any replacements in the parameters |
309 | m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); | 268 | m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); |
310 | } | 269 | } |
270 | |||
271 | // The material characteristics. | ||
272 | BSMaterials.InitializeFromDefaults(Params); | ||
273 | if (pConfig != null) | ||
274 | { | ||
275 | // Let the user add new and interesting material property values. | ||
276 | BSMaterials.InitializefromParameters(pConfig); | ||
277 | } | ||
311 | } | 278 | } |
312 | } | 279 | } |
313 | 280 | ||
@@ -326,16 +293,41 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
326 | return ret; | 293 | return ret; |
327 | } | 294 | } |
328 | 295 | ||
329 | // Called directly from unmanaged code so don't do much | 296 | // Select the connection to the actual Bullet implementation. |
330 | private void BulletLogger(string msg) | 297 | // The main engine selection is the engineName up to the first hypen. |
298 | // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name | ||
299 | // is passed to the engine to do its special selection, etc. | ||
300 | private BSAPITemplate SelectUnderlyingBulletEngine(string engineName) | ||
331 | { | 301 | { |
332 | m_log.Debug("[BULLETS UNMANAGED]:" + msg); | 302 | // For the moment, do a simple switch statement. |
333 | } | 303 | // Someday do fancyness with looking up the interfaces in the assembly. |
304 | BSAPITemplate ret = null; | ||
334 | 305 | ||
335 | // Called directly from unmanaged code so don't do much | 306 | string selectionName = engineName.ToLower(); |
336 | private void BulletLoggerPhysLog(string msg) | 307 | int hyphenIndex = engineName.IndexOf("-"); |
337 | { | 308 | if (hyphenIndex > 0) |
338 | DetailLog("[BULLETS UNMANAGED]:" + msg); | 309 | selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1); |
310 | |||
311 | switch (selectionName) | ||
312 | { | ||
313 | case "bulletunmanaged": | ||
314 | ret = new BSAPIUnman(engineName, this); | ||
315 | break; | ||
316 | case "bulletxna": | ||
317 | ret = new BSAPIXNA(engineName, this); | ||
318 | break; | ||
319 | } | ||
320 | |||
321 | if (ret == null) | ||
322 | { | ||
323 | m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader); | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion); | ||
328 | } | ||
329 | |||
330 | return ret; | ||
339 | } | 331 | } |
340 | 332 | ||
341 | public override void Dispose() | 333 | public override void Dispose() |
@@ -345,8 +337,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
345 | // make sure no stepping happens while we're deleting stuff | 337 | // make sure no stepping happens while we're deleting stuff |
346 | m_initialized = false; | 338 | m_initialized = false; |
347 | 339 | ||
348 | TerrainManager.ReleaseGroundPlaneAndTerrain(); | ||
349 | |||
350 | foreach (KeyValuePair<uint, BSPhysObject> kvp in PhysObjects) | 340 | foreach (KeyValuePair<uint, BSPhysObject> kvp in PhysObjects) |
351 | { | 341 | { |
352 | kvp.Value.Destroy(); | 342 | kvp.Value.Destroy(); |
@@ -366,8 +356,15 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
366 | Shapes = null; | 356 | Shapes = null; |
367 | } | 357 | } |
368 | 358 | ||
359 | if (TerrainManager != null) | ||
360 | { | ||
361 | TerrainManager.ReleaseGroundPlaneAndTerrain(); | ||
362 | TerrainManager.Dispose(); | ||
363 | TerrainManager = null; | ||
364 | } | ||
365 | |||
369 | // Anything left in the unmanaged code should be cleaned out | 366 | // Anything left in the unmanaged code should be cleaned out |
370 | BulletSimAPI.Shutdown2(World.ptr); | 367 | PE.Shutdown(World); |
371 | 368 | ||
372 | // Not logging any more | 369 | // Not logging any more |
373 | PhysicsLogging.Close(); | 370 | PhysicsLogging.Close(); |
@@ -389,12 +386,14 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
389 | if (!m_initialized) return null; | 386 | if (!m_initialized) return null; |
390 | 387 | ||
391 | BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying); | 388 | BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying); |
392 | lock (PhysObjects) PhysObjects.Add(localID, actor); | 389 | lock (PhysObjects) |
390 | PhysObjects.Add(localID, actor); | ||
393 | 391 | ||
394 | // TODO: Remove kludge someday. | 392 | // TODO: Remove kludge someday. |
395 | // We must generate a collision for avatars whether they collide or not. | 393 | // We must generate a collision for avatars whether they collide or not. |
396 | // This is required by OpenSim to update avatar animations, etc. | 394 | // This is required by OpenSim to update avatar animations, etc. |
397 | lock (m_avatars) m_avatars.Add(actor); | 395 | lock (m_avatars) |
396 | m_avatars.Add(actor); | ||
398 | 397 | ||
399 | return actor; | 398 | return actor; |
400 | } | 399 | } |
@@ -410,9 +409,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
410 | { | 409 | { |
411 | try | 410 | try |
412 | { | 411 | { |
413 | lock (PhysObjects) PhysObjects.Remove(actor.LocalID); | 412 | lock (PhysObjects) |
413 | PhysObjects.Remove(bsactor.LocalID); | ||
414 | // Remove kludge someday | 414 | // Remove kludge someday |
415 | lock (m_avatars) m_avatars.Remove(bsactor); | 415 | lock (m_avatars) |
416 | m_avatars.Remove(bsactor); | ||
416 | } | 417 | } |
417 | catch (Exception e) | 418 | catch (Exception e) |
418 | { | 419 | { |
@@ -421,6 +422,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
421 | bsactor.Destroy(); | 422 | bsactor.Destroy(); |
422 | // bsactor.dispose(); | 423 | // bsactor.dispose(); |
423 | } | 424 | } |
425 | else | ||
426 | { | ||
427 | m_log.ErrorFormat("{0}: Requested to remove avatar that is not a BSCharacter. ID={1}, type={2}", | ||
428 | LogHeader, actor.LocalID, actor.GetType().Name); | ||
429 | } | ||
424 | } | 430 | } |
425 | 431 | ||
426 | public override void RemovePrim(PhysicsActor prim) | 432 | public override void RemovePrim(PhysicsActor prim) |
@@ -474,41 +480,56 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
474 | // Simulate one timestep | 480 | // Simulate one timestep |
475 | public override float Simulate(float timeStep) | 481 | public override float Simulate(float timeStep) |
476 | { | 482 | { |
483 | // prevent simulation until we've been initialized | ||
484 | if (!m_initialized) return 5.0f; | ||
485 | |||
486 | LastTimeStep = timeStep; | ||
487 | |||
477 | int updatedEntityCount = 0; | 488 | int updatedEntityCount = 0; |
478 | IntPtr updatedEntitiesPtr; | ||
479 | int collidersCount = 0; | 489 | int collidersCount = 0; |
480 | IntPtr collidersPtr; | ||
481 | 490 | ||
482 | int beforeTime = 0; | 491 | int beforeTime = 0; |
483 | int simTime = 0; | 492 | int simTime = 0; |
484 | 493 | ||
485 | // prevent simulation until we've been initialized | ||
486 | if (!m_initialized) return 5.0f; | ||
487 | |||
488 | // update the prim states while we know the physics engine is not busy | 494 | // update the prim states while we know the physics engine is not busy |
489 | int numTaints = _taintOperations.Count; | 495 | int numTaints = _taintOperations.Count; |
496 | |||
497 | InTaintTime = true; // Only used for debugging so locking is not necessary. | ||
498 | |||
499 | ProcessTaints(); | ||
500 | |||
501 | // Some of the physical objects requre individual, pre-step calls | ||
502 | // (vehicles and avatar movement, in particular) | ||
503 | TriggerPreStepEvent(timeStep); | ||
504 | |||
505 | // the prestep actions might have added taints | ||
506 | numTaints += _taintOperations.Count; | ||
490 | ProcessTaints(); | 507 | ProcessTaints(); |
491 | 508 | ||
492 | // Some of the prims operate with special vehicle properties | 509 | InTaintTime = false; // Only used for debugging so locking is not necessary. |
493 | ProcessVehicles(timeStep); | 510 | |
494 | ProcessTaints(); // the vehicles might have added taints | 511 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. |
512 | // Only enable this in a limited test world with few objects. | ||
513 | if (m_physicsPhysicalDumpEnabled) | ||
514 | PE.DumpAllInfo(World); | ||
495 | 515 | ||
496 | // step the physical world one interval | 516 | // step the physical world one interval |
497 | m_simulationStep++; | 517 | m_simulationStep++; |
498 | int numSubSteps = 0; | 518 | int numSubSteps = 0; |
499 | |||
500 | try | 519 | try |
501 | { | 520 | { |
502 | if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG | 521 | if (PhysicsLogging.Enabled) |
503 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); | 522 | beforeTime = Util.EnvironmentTickCount(); |
504 | 523 | ||
505 | numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, | 524 | numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); |
506 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); | ||
507 | 525 | ||
508 | if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); | 526 | if (PhysicsLogging.Enabled) |
509 | DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}", | 527 | { |
510 | DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, updatedEntityCount, collidersCount); | 528 | simTime = Util.EnvironmentTickCountSubtract(beforeTime); |
511 | if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG | 529 | DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", |
530 | DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, | ||
531 | updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); | ||
532 | } | ||
512 | } | 533 | } |
513 | catch (Exception e) | 534 | catch (Exception e) |
514 | { | 535 | { |
@@ -520,9 +541,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
520 | collidersCount = 0; | 541 | collidersCount = 0; |
521 | } | 542 | } |
522 | 543 | ||
523 | // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in | 544 | if ((m_simulationStep % PhysicsMetricDumpFrames) == 0) |
545 | PE.DumpPhysicsStatistics(World); | ||
524 | 546 | ||
525 | // Get a value for 'now' so all the collision and update routines don't have to get their own | 547 | // Get a value for 'now' so all the collision and update routines don't have to get their own. |
526 | SimulationNowTime = Util.EnvironmentTickCount(); | 548 | SimulationNowTime = Util.EnvironmentTickCount(); |
527 | 549 | ||
528 | // If there were collisions, process them by sending the event to the prim. | 550 | // If there were collisions, process them by sending the event to the prim. |
@@ -562,12 +584,16 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
562 | 584 | ||
563 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. | 585 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. |
564 | // Not done above because it is inside an iteration of ObjectWithCollisions. | 586 | // Not done above because it is inside an iteration of ObjectWithCollisions. |
587 | // This complex collision processing is required to create an empty collision | ||
588 | // event call after all real collisions have happened on an object. This enables | ||
589 | // the simulator to generate the 'collision end' event. | ||
565 | if (ObjectsWithNoMoreCollisions.Count > 0) | 590 | if (ObjectsWithNoMoreCollisions.Count > 0) |
566 | { | 591 | { |
567 | foreach (BSPhysObject po in ObjectsWithNoMoreCollisions) | 592 | foreach (BSPhysObject po in ObjectsWithNoMoreCollisions) |
568 | ObjectsWithCollisions.Remove(po); | 593 | ObjectsWithCollisions.Remove(po); |
569 | ObjectsWithNoMoreCollisions.Clear(); | 594 | ObjectsWithNoMoreCollisions.Clear(); |
570 | } | 595 | } |
596 | // Done with collisions. | ||
571 | 597 | ||
572 | // If any of the objects had updated properties, tell the object it has been changed by the physics engine | 598 | // If any of the objects had updated properties, tell the object it has been changed by the physics engine |
573 | if (updatedEntityCount > 0) | 599 | if (updatedEntityCount > 0) |
@@ -583,17 +609,17 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
583 | } | 609 | } |
584 | } | 610 | } |
585 | 611 | ||
586 | ProcessPostStepTaints(); | 612 | TriggerPostStepEvent(timeStep); |
587 | 613 | ||
588 | // This causes the unmanaged code to output ALL the values found in ALL the objects in the world. | 614 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. |
589 | // Only enable this in a limited test world with few objects. | 615 | // Only enable this in a limited test world with few objects. |
590 | // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG | 616 | if (m_physicsPhysicalDumpEnabled) |
617 | PE.DumpAllInfo(World); | ||
591 | 618 | ||
592 | // The physics engine returns the number of milliseconds it simulated this call. | 619 | // The physics engine returns the number of milliseconds it simulated this call. |
593 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. | 620 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. |
594 | // We multiply by 55 to give a recognizable running rate (55 or less). | 621 | // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55). |
595 | return numSubSteps * m_fixedTimeStep * 1000 * 55; | 622 | return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; |
596 | // return timeStep * 1000 * 55; | ||
597 | } | 623 | } |
598 | 624 | ||
599 | // Something has collided | 625 | // Something has collided |
@@ -639,12 +665,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
639 | 665 | ||
640 | public override void SetWaterLevel(float baseheight) | 666 | public override void SetWaterLevel(float baseheight) |
641 | { | 667 | { |
642 | m_waterLevel = baseheight; | 668 | SimpleWaterLevel = baseheight; |
643 | } | ||
644 | // Someday.... | ||
645 | public float GetWaterLevelAtXYZ(Vector3 loc) | ||
646 | { | ||
647 | return m_waterLevel; | ||
648 | } | 669 | } |
649 | 670 | ||
650 | public override void DeleteTerrain() | 671 | public override void DeleteTerrain() |
@@ -681,6 +702,15 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
681 | public override bool IsThreaded { get { return false; } } | 702 | public override bool IsThreaded { get { return false; } } |
682 | 703 | ||
683 | #region Taints | 704 | #region Taints |
705 | // The simulation execution order is: | ||
706 | // Simulate() | ||
707 | // DoOneTimeTaints | ||
708 | // TriggerPreStepEvent | ||
709 | // DoOneTimeTaints | ||
710 | // Step() | ||
711 | // ProcessAndForwardCollisions | ||
712 | // ProcessAndForwardPropertyUpdates | ||
713 | // TriggerPostStepEvent | ||
684 | 714 | ||
685 | // Calls to the PhysicsActors can't directly call into the physics engine | 715 | // Calls to the PhysicsActors can't directly call into the physics engine |
686 | // because it might be busy. We delay changes to a known time. | 716 | // because it might be busy. We delay changes to a known time. |
@@ -707,58 +737,35 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
707 | TaintedObject(ident, callback); | 737 | TaintedObject(ident, callback); |
708 | } | 738 | } |
709 | 739 | ||
740 | private void TriggerPreStepEvent(float timeStep) | ||
741 | { | ||
742 | PreStepAction actions = BeforeStep; | ||
743 | if (actions != null) | ||
744 | actions(timeStep); | ||
745 | |||
746 | } | ||
747 | |||
748 | private void TriggerPostStepEvent(float timeStep) | ||
749 | { | ||
750 | PreStepAction actions = AfterStep; | ||
751 | if (actions != null) | ||
752 | actions(timeStep); | ||
753 | |||
754 | } | ||
755 | |||
710 | // When someone tries to change a property on a BSPrim or BSCharacter, the object queues | 756 | // When someone tries to change a property on a BSPrim or BSCharacter, the object queues |
711 | // a callback into itself to do the actual property change. That callback is called | 757 | // a callback into itself to do the actual property change. That callback is called |
712 | // here just before the physics engine is called to step the simulation. | 758 | // here just before the physics engine is called to step the simulation. |
713 | public void ProcessTaints() | 759 | public void ProcessTaints() |
714 | { | 760 | { |
715 | InTaintTime = true; // Only used for debugging so locking is not necessary. | ||
716 | ProcessRegularTaints(); | 761 | ProcessRegularTaints(); |
717 | ProcessPostTaintTaints(); | 762 | ProcessPostTaintTaints(); |
718 | InTaintTime = false; | ||
719 | } | 763 | } |
720 | 764 | ||
721 | private void ProcessRegularTaints() | 765 | private void ProcessRegularTaints() |
722 | { | 766 | { |
723 | if (_taintOperations.Count > 0) // save allocating new list if there is nothing to process | 767 | if (_taintOperations.Count > 0) // save allocating new list if there is nothing to process |
724 | { | 768 | { |
725 | /* | ||
726 | // Code to limit the number of taints processed per step. Meant to limit step time. | ||
727 | // Unsure if a good idea as code assumes that taints are done before the step. | ||
728 | int taintCount = m_taintsToProcessPerStep; | ||
729 | TaintCallbackEntry oneCallback = new TaintCallbackEntry(); | ||
730 | while (_taintOperations.Count > 0 && taintCount-- > 0) | ||
731 | { | ||
732 | bool gotOne = false; | ||
733 | lock (_taintLock) | ||
734 | { | ||
735 | if (_taintOperations.Count > 0) | ||
736 | { | ||
737 | oneCallback = _taintOperations[0]; | ||
738 | _taintOperations.RemoveAt(0); | ||
739 | gotOne = true; | ||
740 | } | ||
741 | } | ||
742 | if (gotOne) | ||
743 | { | ||
744 | try | ||
745 | { | ||
746 | DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", DetailLogZero, oneCallback.ident); | ||
747 | oneCallback.callback(); | ||
748 | } | ||
749 | catch (Exception e) | ||
750 | { | ||
751 | DetailLog("{0},BSScene.ProcessTaints,doTaintException,id={1}", DetailLogZero, oneCallback.ident); // DEBUG DEBUG DEBUG | ||
752 | m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, oneCallback.ident, e); | ||
753 | } | ||
754 | } | ||
755 | } | ||
756 | if (_taintOperations.Count > 0) | ||
757 | { | ||
758 | DetailLog("{0},BSScene.ProcessTaints,leftTaintsOnList,numNotProcessed={1}", DetailLogZero, _taintOperations.Count); | ||
759 | } | ||
760 | */ | ||
761 | |||
762 | // swizzle a new list into the list location so we can process what's there | 769 | // swizzle a new list into the list location so we can process what's there |
763 | List<TaintCallbackEntry> oldList; | 770 | List<TaintCallbackEntry> oldList; |
764 | lock (_taintLock) | 771 | lock (_taintLock) |
@@ -797,6 +804,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
797 | return; | 804 | return; |
798 | } | 805 | } |
799 | 806 | ||
807 | // Taints that happen after the normal taint processing but before the simulation step. | ||
800 | private void ProcessPostTaintTaints() | 808 | private void ProcessPostTaintTaints() |
801 | { | 809 | { |
802 | if (_postTaintOperations.Count > 0) | 810 | if (_postTaintOperations.Count > 0) |
@@ -824,45 +832,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
824 | } | 832 | } |
825 | } | 833 | } |
826 | 834 | ||
827 | public void PostStepTaintObject(String ident, TaintCallback callback) | ||
828 | { | ||
829 | if (!m_initialized) return; | ||
830 | |||
831 | lock (_taintLock) | ||
832 | { | ||
833 | _postStepOperations.Add(new TaintCallbackEntry(ident, callback)); | ||
834 | } | ||
835 | |||
836 | return; | ||
837 | } | ||
838 | |||
839 | private void ProcessPostStepTaints() | ||
840 | { | ||
841 | if (_postStepOperations.Count > 0) | ||
842 | { | ||
843 | List<TaintCallbackEntry> oldList; | ||
844 | lock (_taintLock) | ||
845 | { | ||
846 | oldList = _postStepOperations; | ||
847 | _postStepOperations = new List<TaintCallbackEntry>(); | ||
848 | } | ||
849 | |||
850 | foreach (TaintCallbackEntry tcbe in oldList) | ||
851 | { | ||
852 | try | ||
853 | { | ||
854 | DetailLog("{0},BSScene.ProcessPostStepTaints,doTaint,id={1}", DetailLogZero, tcbe.ident); // DEBUG DEBUG DEBUG | ||
855 | tcbe.callback(); | ||
856 | } | ||
857 | catch (Exception e) | ||
858 | { | ||
859 | m_log.ErrorFormat("{0}: ProcessPostStepTaints: {1}: Exception: {2}", LogHeader, tcbe.ident, e); | ||
860 | } | ||
861 | } | ||
862 | oldList.Clear(); | ||
863 | } | ||
864 | } | ||
865 | |||
866 | // Only used for debugging. Does not change state of anything so locking is not necessary. | 835 | // Only used for debugging. Does not change state of anything so locking is not necessary. |
867 | public bool AssertInTaintTime(string whereFrom) | 836 | public bool AssertInTaintTime(string whereFrom) |
868 | { | 837 | { |
@@ -870,517 +839,19 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
870 | { | 839 | { |
871 | DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom); | 840 | DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom); |
872 | m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom); | 841 | m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom); |
873 | Util.PrintCallStack(); // Prints the stack into the DEBUG log file. | 842 | Util.PrintCallStack(DetailLog); |
874 | } | 843 | } |
875 | return InTaintTime; | 844 | return InTaintTime; |
876 | } | 845 | } |
877 | 846 | ||
878 | #endregion // Taints | 847 | #endregion // Taints |
879 | 848 | ||
880 | #region Vehicles | ||
881 | |||
882 | public void VehicleInSceneTypeChanged(BSPrim vehic, Vehicle newType) | ||
883 | { | ||
884 | RemoveVehiclePrim(vehic); | ||
885 | if (newType != Vehicle.TYPE_NONE) | ||
886 | { | ||
887 | // make it so the scene will call us each tick to do vehicle things | ||
888 | AddVehiclePrim(vehic); | ||
889 | } | ||
890 | } | ||
891 | |||
892 | // Make so the scene will call this prim for vehicle actions each tick. | ||
893 | // Safe to call if prim is already in the vehicle list. | ||
894 | public void AddVehiclePrim(BSPrim vehicle) | ||
895 | { | ||
896 | lock (m_vehicles) | ||
897 | { | ||
898 | if (!m_vehicles.Contains(vehicle)) | ||
899 | { | ||
900 | m_vehicles.Add(vehicle); | ||
901 | } | ||
902 | } | ||
903 | } | ||
904 | |||
905 | // Remove a prim from our list of vehicles. | ||
906 | // Safe to call if the prim is not in the vehicle list. | ||
907 | public void RemoveVehiclePrim(BSPrim vehicle) | ||
908 | { | ||
909 | lock (m_vehicles) | ||
910 | { | ||
911 | if (m_vehicles.Contains(vehicle)) | ||
912 | { | ||
913 | m_vehicles.Remove(vehicle); | ||
914 | } | ||
915 | } | ||
916 | } | ||
917 | |||
918 | // Some prims have extra vehicle actions | ||
919 | // Called at taint time! | ||
920 | private void ProcessVehicles(float timeStep) | ||
921 | { | ||
922 | foreach (BSPhysObject pobj in m_vehicles) | ||
923 | { | ||
924 | pobj.StepVehicle(timeStep); | ||
925 | } | ||
926 | } | ||
927 | #endregion Vehicles | ||
928 | |||
929 | #region INI and command line parameter processing | ||
930 | |||
931 | delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); | ||
932 | delegate float ParamGet(BSScene scene); | ||
933 | delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); | ||
934 | delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val); | ||
935 | |||
936 | private struct ParameterDefn | ||
937 | { | ||
938 | public string name; // string name of the parameter | ||
939 | public string desc; // a short description of what the parameter means | ||
940 | public float defaultValue; // default value if not specified anywhere else | ||
941 | public ParamUser userParam; // get the value from the configuration file | ||
942 | public ParamGet getter; // return the current value stored for this parameter | ||
943 | public ParamSet setter; // set the current value for this parameter | ||
944 | public SetOnObject onObject; // set the value on an object in the physical domain | ||
945 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) | ||
946 | { | ||
947 | name = n; | ||
948 | desc = d; | ||
949 | defaultValue = v; | ||
950 | userParam = u; | ||
951 | getter = g; | ||
952 | setter = s; | ||
953 | onObject = null; | ||
954 | } | ||
955 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o) | ||
956 | { | ||
957 | name = n; | ||
958 | desc = d; | ||
959 | defaultValue = v; | ||
960 | userParam = u; | ||
961 | getter = g; | ||
962 | setter = s; | ||
963 | onObject = o; | ||
964 | } | ||
965 | } | ||
966 | |||
967 | // List of all of the externally visible parameters. | ||
968 | // For each parameter, this table maps a text name to getter and setters. | ||
969 | // To add a new externally referencable/settable parameter, add the paramter storage | ||
970 | // location somewhere in the program and make an entry in this table with the | ||
971 | // getters and setters. | ||
972 | // It is easiest to find an existing definition and copy it. | ||
973 | // Parameter values are floats. Booleans are converted to a floating value. | ||
974 | // | ||
975 | // A ParameterDefn() takes the following parameters: | ||
976 | // -- the text name of the parameter. This is used for console input and ini file. | ||
977 | // -- a short text description of the parameter. This shows up in the console listing. | ||
978 | // -- a delegate for fetching the parameter from the ini file. | ||
979 | // Should handle fetching the right type from the ini file and converting it. | ||
980 | // -- a delegate for getting the value as a float | ||
981 | // -- a delegate for setting the value from a float | ||
982 | // | ||
983 | // The single letter parameters for the delegates are: | ||
984 | // s = BSScene | ||
985 | // o = BSPhysObject | ||
986 | // p = string parameter name | ||
987 | // l = localID of referenced object | ||
988 | // v = float value | ||
989 | // cf = parameter configuration class (for fetching values from ini file) | ||
990 | private ParameterDefn[] ParameterDefinitions = | ||
991 | { | ||
992 | new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties", | ||
993 | ConfigurationParameters.numericTrue, | ||
994 | (s,cf,p,v) => { s.ShouldMeshSculptedPrim = cf.GetBoolean(p, s.BoolNumeric(v)); }, | ||
995 | (s) => { return s.NumericBool(s.ShouldMeshSculptedPrim); }, | ||
996 | (s,p,l,v) => { s.ShouldMeshSculptedPrim = s.BoolNumeric(v); } ), | ||
997 | new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects", | ||
998 | ConfigurationParameters.numericFalse, | ||
999 | (s,cf,p,v) => { s.ShouldForceSimplePrimMeshing = cf.GetBoolean(p, s.BoolNumeric(v)); }, | ||
1000 | (s) => { return s.NumericBool(s.ShouldForceSimplePrimMeshing); }, | ||
1001 | (s,p,l,v) => { s.ShouldForceSimplePrimMeshing = s.BoolNumeric(v); } ), | ||
1002 | new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects", | ||
1003 | ConfigurationParameters.numericTrue, | ||
1004 | (s,cf,p,v) => { s.ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, s.BoolNumeric(v)); }, | ||
1005 | (s) => { return s.NumericBool(s.ShouldUseHullsForPhysicalObjects); }, | ||
1006 | (s,p,l,v) => { s.ShouldUseHullsForPhysicalObjects = s.BoolNumeric(v); } ), | ||
1007 | |||
1008 | new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | ||
1009 | 8f, | ||
1010 | (s,cf,p,v) => { s.MeshLOD = (float)cf.GetInt(p, (int)v); }, | ||
1011 | (s) => { return s.MeshLOD; }, | ||
1012 | (s,p,l,v) => { s.MeshLOD = v; } ), | ||
1013 | new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters", | ||
1014 | 16f, | ||
1015 | (s,cf,p,v) => { s.MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); }, | ||
1016 | (s) => { return s.MeshMegaPrimLOD; }, | ||
1017 | (s,p,l,v) => { s.MeshMegaPrimLOD = v; } ), | ||
1018 | new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD", | ||
1019 | 10f, | ||
1020 | (s,cf,p,v) => { s.MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); }, | ||
1021 | (s) => { return s.MeshMegaPrimThreshold; }, | ||
1022 | (s,p,l,v) => { s.MeshMegaPrimThreshold = v; } ), | ||
1023 | new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | ||
1024 | 32f, | ||
1025 | (s,cf,p,v) => { s.SculptLOD = (float)cf.GetInt(p, (int)v); }, | ||
1026 | (s) => { return s.SculptLOD; }, | ||
1027 | (s,p,l,v) => { s.SculptLOD = v; } ), | ||
1028 | |||
1029 | new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps", | ||
1030 | 10f, | ||
1031 | (s,cf,p,v) => { s.m_maxSubSteps = cf.GetInt(p, (int)v); }, | ||
1032 | (s) => { return (float)s.m_maxSubSteps; }, | ||
1033 | (s,p,l,v) => { s.m_maxSubSteps = (int)v; } ), | ||
1034 | new ParameterDefn("FixedTimeStep", "In simulation step, seconds of one substep (1/60)", | ||
1035 | 1f / 60f, | ||
1036 | (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); }, | ||
1037 | (s) => { return (float)s.m_fixedTimeStep; }, | ||
1038 | (s,p,l,v) => { s.m_fixedTimeStep = v; } ), | ||
1039 | new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame", | ||
1040 | 2048f, | ||
1041 | (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); }, | ||
1042 | (s) => { return (float)s.m_maxCollisionsPerFrame; }, | ||
1043 | (s,p,l,v) => { s.m_maxCollisionsPerFrame = (int)v; } ), | ||
1044 | new ParameterDefn("MaxUpdatesPerFrame", "Max updates returned at end of each frame", | ||
1045 | 8000f, | ||
1046 | (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); }, | ||
1047 | (s) => { return (float)s.m_maxUpdatesPerFrame; }, | ||
1048 | (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ), | ||
1049 | new ParameterDefn("MaxTaintsToProcessPerStep", "Number of update taints to process before each simulation step", | ||
1050 | 500f, | ||
1051 | (s,cf,p,v) => { s.m_taintsToProcessPerStep = cf.GetInt(p, (int)v); }, | ||
1052 | (s) => { return (float)s.m_taintsToProcessPerStep; }, | ||
1053 | (s,p,l,v) => { s.m_taintsToProcessPerStep = (int)v; } ), | ||
1054 | new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)", | ||
1055 | 10000.01f, | ||
1056 | (s,cf,p,v) => { s.MaximumObjectMass = cf.GetFloat(p, v); }, | ||
1057 | (s) => { return (float)s.MaximumObjectMass; }, | ||
1058 | (s,p,l,v) => { s.MaximumObjectMass = v; } ), | ||
1059 | |||
1060 | new ParameterDefn("PID_D", "Derivitive factor for motion smoothing", | ||
1061 | 2200f, | ||
1062 | (s,cf,p,v) => { s.PID_D = cf.GetFloat(p, v); }, | ||
1063 | (s) => { return (float)s.PID_D; }, | ||
1064 | (s,p,l,v) => { s.PID_D = v; } ), | ||
1065 | new ParameterDefn("PID_P", "Parameteric factor for motion smoothing", | ||
1066 | 900f, | ||
1067 | (s,cf,p,v) => { s.PID_P = cf.GetFloat(p, v); }, | ||
1068 | (s) => { return (float)s.PID_P; }, | ||
1069 | (s,p,l,v) => { s.PID_P = v; } ), | ||
1070 | |||
1071 | new ParameterDefn("DefaultFriction", "Friction factor used on new objects", | ||
1072 | 0.5f, | ||
1073 | (s,cf,p,v) => { s.m_params[0].defaultFriction = cf.GetFloat(p, v); }, | ||
1074 | (s) => { return s.m_params[0].defaultFriction; }, | ||
1075 | (s,p,l,v) => { s.m_params[0].defaultFriction = v; } ), | ||
1076 | new ParameterDefn("DefaultDensity", "Density for new objects" , | ||
1077 | 10.000006836f, // Aluminum g/cm3 | ||
1078 | (s,cf,p,v) => { s.m_params[0].defaultDensity = cf.GetFloat(p, v); }, | ||
1079 | (s) => { return s.m_params[0].defaultDensity; }, | ||
1080 | (s,p,l,v) => { s.m_params[0].defaultDensity = v; } ), | ||
1081 | new ParameterDefn("DefaultRestitution", "Bouncyness of an object" , | ||
1082 | 0f, | ||
1083 | (s,cf,p,v) => { s.m_params[0].defaultRestitution = cf.GetFloat(p, v); }, | ||
1084 | (s) => { return s.m_params[0].defaultRestitution; }, | ||
1085 | (s,p,l,v) => { s.m_params[0].defaultRestitution = v; } ), | ||
1086 | new ParameterDefn("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)", | ||
1087 | 0f, | ||
1088 | (s,cf,p,v) => { s.m_params[0].collisionMargin = cf.GetFloat(p, v); }, | ||
1089 | (s) => { return s.m_params[0].collisionMargin; }, | ||
1090 | (s,p,l,v) => { s.m_params[0].collisionMargin = v; } ), | ||
1091 | new ParameterDefn("Gravity", "Vertical force of gravity (negative means down)", | ||
1092 | -9.80665f, | ||
1093 | (s,cf,p,v) => { s.m_params[0].gravity = cf.GetFloat(p, v); }, | ||
1094 | (s) => { return s.m_params[0].gravity; }, | ||
1095 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].gravity, p, PhysParameterEntry.APPLY_TO_NONE, v); }, | ||
1096 | (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ), | ||
1097 | |||
1098 | |||
1099 | new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", | ||
1100 | 0f, | ||
1101 | (s,cf,p,v) => { s.m_params[0].linearDamping = cf.GetFloat(p, v); }, | ||
1102 | (s) => { return s.m_params[0].linearDamping; }, | ||
1103 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearDamping, p, l, v); }, | ||
1104 | (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, v, s.m_params[0].angularDamping); } ), | ||
1105 | new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", | ||
1106 | 0f, | ||
1107 | (s,cf,p,v) => { s.m_params[0].angularDamping = cf.GetFloat(p, v); }, | ||
1108 | (s) => { return s.m_params[0].angularDamping; }, | ||
1109 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularDamping, p, l, v); }, | ||
1110 | (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, s.m_params[0].linearDamping, v); } ), | ||
1111 | new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", | ||
1112 | 0.2f, | ||
1113 | (s,cf,p,v) => { s.m_params[0].deactivationTime = cf.GetFloat(p, v); }, | ||
1114 | (s) => { return s.m_params[0].deactivationTime; }, | ||
1115 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].deactivationTime, p, l, v); }, | ||
1116 | (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.PhysBody.ptr, v); } ), | ||
1117 | new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", | ||
1118 | 0.8f, | ||
1119 | (s,cf,p,v) => { s.m_params[0].linearSleepingThreshold = cf.GetFloat(p, v); }, | ||
1120 | (s) => { return s.m_params[0].linearSleepingThreshold; }, | ||
1121 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearSleepingThreshold, p, l, v); }, | ||
1122 | (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), | ||
1123 | new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", | ||
1124 | 1.0f, | ||
1125 | (s,cf,p,v) => { s.m_params[0].angularSleepingThreshold = cf.GetFloat(p, v); }, | ||
1126 | (s) => { return s.m_params[0].angularSleepingThreshold; }, | ||
1127 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularSleepingThreshold, p, l, v); }, | ||
1128 | (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), | ||
1129 | new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , | ||
1130 | 0f, // set to zero to disable | ||
1131 | (s,cf,p,v) => { s.m_params[0].ccdMotionThreshold = cf.GetFloat(p, v); }, | ||
1132 | (s) => { return s.m_params[0].ccdMotionThreshold; }, | ||
1133 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdMotionThreshold, p, l, v); }, | ||
1134 | (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.PhysBody.ptr, v); } ), | ||
1135 | new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , | ||
1136 | 0f, | ||
1137 | (s,cf,p,v) => { s.m_params[0].ccdSweptSphereRadius = cf.GetFloat(p, v); }, | ||
1138 | (s) => { return s.m_params[0].ccdSweptSphereRadius; }, | ||
1139 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdSweptSphereRadius, p, l, v); }, | ||
1140 | (s,o,v) => { BulletSimAPI.SetCcdSweptSphereRadius2(o.PhysBody.ptr, v); } ), | ||
1141 | new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , | ||
1142 | 0.1f, | ||
1143 | (s,cf,p,v) => { s.m_params[0].contactProcessingThreshold = cf.GetFloat(p, v); }, | ||
1144 | (s) => { return s.m_params[0].contactProcessingThreshold; }, | ||
1145 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].contactProcessingThreshold, p, l, v); }, | ||
1146 | (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ), | ||
1147 | |||
1148 | new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", | ||
1149 | (float)BSTerrainPhys.TerrainImplementation.Mesh, | ||
1150 | (s,cf,p,v) => { s.m_params[0].terrainImplementation = cf.GetFloat(p,v); }, | ||
1151 | (s) => { return s.m_params[0].terrainImplementation; }, | ||
1152 | (s,p,l,v) => { s.m_params[0].terrainImplementation = v; } ), | ||
1153 | new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" , | ||
1154 | 0.5f, | ||
1155 | (s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); }, | ||
1156 | (s) => { return s.m_params[0].terrainFriction; }, | ||
1157 | (s,p,l,v) => { s.m_params[0].terrainFriction = v; /* TODO: set on real terrain */} ), | ||
1158 | new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" , | ||
1159 | 0.8f, | ||
1160 | (s,cf,p,v) => { s.m_params[0].terrainHitFraction = cf.GetFloat(p, v); }, | ||
1161 | (s) => { return s.m_params[0].terrainHitFraction; }, | ||
1162 | (s,p,l,v) => { s.m_params[0].terrainHitFraction = v; /* TODO: set on real terrain */ } ), | ||
1163 | new ParameterDefn("TerrainRestitution", "Bouncyness" , | ||
1164 | 0f, | ||
1165 | (s,cf,p,v) => { s.m_params[0].terrainRestitution = cf.GetFloat(p, v); }, | ||
1166 | (s) => { return s.m_params[0].terrainRestitution; }, | ||
1167 | (s,p,l,v) => { s.m_params[0].terrainRestitution = v; /* TODO: set on real terrain */ } ), | ||
1168 | new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", | ||
1169 | 0.2f, | ||
1170 | (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, | ||
1171 | (s) => { return s.m_params[0].avatarFriction; }, | ||
1172 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarFriction, p, l, v); } ), | ||
1173 | new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | ||
1174 | 10f, | ||
1175 | (s,cf,p,v) => { s.m_params[0].avatarStandingFriction = cf.GetFloat(p, v); }, | ||
1176 | (s) => { return s.m_params[0].avatarStandingFriction; }, | ||
1177 | (s,p,l,v) => { s.m_params[0].avatarStandingFriction = v; } ), | ||
1178 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | ||
1179 | 60f, | ||
1180 | (s,cf,p,v) => { s.m_params[0].avatarDensity = cf.GetFloat(p, v); }, | ||
1181 | (s) => { return s.m_params[0].avatarDensity; }, | ||
1182 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarDensity, p, l, v); } ), | ||
1183 | new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | ||
1184 | 0f, | ||
1185 | (s,cf,p,v) => { s.m_params[0].avatarRestitution = cf.GetFloat(p, v); }, | ||
1186 | (s) => { return s.m_params[0].avatarRestitution; }, | ||
1187 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarRestitution, p, l, v); } ), | ||
1188 | new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", | ||
1189 | 0.6f, | ||
1190 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleWidth = cf.GetFloat(p, v); }, | ||
1191 | (s) => { return s.m_params[0].avatarCapsuleWidth; }, | ||
1192 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarCapsuleWidth, p, l, v); } ), | ||
1193 | new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", | ||
1194 | 0.45f, | ||
1195 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleDepth = cf.GetFloat(p, v); }, | ||
1196 | (s) => { return s.m_params[0].avatarCapsuleDepth; }, | ||
1197 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarCapsuleDepth, p, l, v); } ), | ||
1198 | new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", | ||
1199 | 1.5f, | ||
1200 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleHeight = cf.GetFloat(p, v); }, | ||
1201 | (s) => { return s.m_params[0].avatarCapsuleHeight; }, | ||
1202 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarCapsuleHeight, p, l, v); } ), | ||
1203 | new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | ||
1204 | 0.1f, | ||
1205 | (s,cf,p,v) => { s.m_params[0].avatarContactProcessingThreshold = cf.GetFloat(p, v); }, | ||
1206 | (s) => { return s.m_params[0].avatarContactProcessingThreshold; }, | ||
1207 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarContactProcessingThreshold, p, l, v); } ), | ||
1208 | |||
1209 | |||
1210 | new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", | ||
1211 | 0f, | ||
1212 | (s,cf,p,v) => { s.m_params[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); }, | ||
1213 | (s) => { return s.m_params[0].maxPersistantManifoldPoolSize; }, | ||
1214 | (s,p,l,v) => { s.m_params[0].maxPersistantManifoldPoolSize = v; } ), | ||
1215 | new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", | ||
1216 | 0f, | ||
1217 | (s,cf,p,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); }, | ||
1218 | (s) => { return s.m_params[0].maxCollisionAlgorithmPoolSize; }, | ||
1219 | (s,p,l,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = v; } ), | ||
1220 | new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", | ||
1221 | ConfigurationParameters.numericFalse, | ||
1222 | (s,cf,p,v) => { s.m_params[0].shouldDisableContactPoolDynamicAllocation = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1223 | (s) => { return s.m_params[0].shouldDisableContactPoolDynamicAllocation; }, | ||
1224 | (s,p,l,v) => { s.m_params[0].shouldDisableContactPoolDynamicAllocation = v; } ), | ||
1225 | new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", | ||
1226 | ConfigurationParameters.numericFalse, | ||
1227 | (s,cf,p,v) => { s.m_params[0].shouldForceUpdateAllAabbs = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1228 | (s) => { return s.m_params[0].shouldForceUpdateAllAabbs; }, | ||
1229 | (s,p,l,v) => { s.m_params[0].shouldForceUpdateAllAabbs = v; } ), | ||
1230 | new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction", | ||
1231 | ConfigurationParameters.numericTrue, | ||
1232 | (s,cf,p,v) => { s.m_params[0].shouldRandomizeSolverOrder = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1233 | (s) => { return s.m_params[0].shouldRandomizeSolverOrder; }, | ||
1234 | (s,p,l,v) => { s.m_params[0].shouldRandomizeSolverOrder = v; } ), | ||
1235 | new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", | ||
1236 | ConfigurationParameters.numericTrue, | ||
1237 | (s,cf,p,v) => { s.m_params[0].shouldSplitSimulationIslands = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1238 | (s) => { return s.m_params[0].shouldSplitSimulationIslands; }, | ||
1239 | (s,p,l,v) => { s.m_params[0].shouldSplitSimulationIslands = v; } ), | ||
1240 | new ParameterDefn("ShouldEnableFrictionCaching", "Enable friction computation caching", | ||
1241 | ConfigurationParameters.numericFalse, | ||
1242 | (s,cf,p,v) => { s.m_params[0].shouldEnableFrictionCaching = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1243 | (s) => { return s.m_params[0].shouldEnableFrictionCaching; }, | ||
1244 | (s,p,l,v) => { s.m_params[0].shouldEnableFrictionCaching = v; } ), | ||
1245 | new ParameterDefn("NumberOfSolverIterations", "Number of internal iterations (0 means default)", | ||
1246 | 0f, // zero says use Bullet default | ||
1247 | (s,cf,p,v) => { s.m_params[0].numberOfSolverIterations = cf.GetFloat(p, v); }, | ||
1248 | (s) => { return s.m_params[0].numberOfSolverIterations; }, | ||
1249 | (s,p,l,v) => { s.m_params[0].numberOfSolverIterations = v; } ), | ||
1250 | |||
1251 | new ParameterDefn("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | ||
1252 | (float)BSLinkset.LinksetImplementation.Compound, | ||
1253 | (s,cf,p,v) => { s.m_params[0].linksetImplementation = cf.GetFloat(p,v); }, | ||
1254 | (s) => { return s.m_params[0].linksetImplementation; }, | ||
1255 | (s,p,l,v) => { s.m_params[0].linksetImplementation = v; } ), | ||
1256 | new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", | ||
1257 | ConfigurationParameters.numericFalse, | ||
1258 | (s,cf,p,v) => { s.m_params[0].linkConstraintUseFrameOffset = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1259 | (s) => { return s.m_params[0].linkConstraintUseFrameOffset; }, | ||
1260 | (s,p,l,v) => { s.m_params[0].linkConstraintUseFrameOffset = v; } ), | ||
1261 | new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", | ||
1262 | ConfigurationParameters.numericTrue, | ||
1263 | (s,cf,p,v) => { s.m_params[0].linkConstraintEnableTransMotor = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | ||
1264 | (s) => { return s.m_params[0].linkConstraintEnableTransMotor; }, | ||
1265 | (s,p,l,v) => { s.m_params[0].linkConstraintEnableTransMotor = v; } ), | ||
1266 | new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints", | ||
1267 | 5.0f, | ||
1268 | (s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxVel = cf.GetFloat(p, v); }, | ||
1269 | (s) => { return s.m_params[0].linkConstraintTransMotorMaxVel; }, | ||
1270 | (s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxVel = v; } ), | ||
1271 | new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints", | ||
1272 | 0.1f, | ||
1273 | (s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = cf.GetFloat(p, v); }, | ||
1274 | (s) => { return s.m_params[0].linkConstraintTransMotorMaxForce; }, | ||
1275 | (s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = v; } ), | ||
1276 | new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", | ||
1277 | 0.1f, | ||
1278 | (s,cf,p,v) => { s.m_params[0].linkConstraintCFM = cf.GetFloat(p, v); }, | ||
1279 | (s) => { return s.m_params[0].linkConstraintCFM; }, | ||
1280 | (s,p,l,v) => { s.m_params[0].linkConstraintCFM = v; } ), | ||
1281 | new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", | ||
1282 | 0.1f, | ||
1283 | (s,cf,p,v) => { s.m_params[0].linkConstraintERP = cf.GetFloat(p, v); }, | ||
1284 | (s) => { return s.m_params[0].linkConstraintERP; }, | ||
1285 | (s,p,l,v) => { s.m_params[0].linkConstraintERP = v; } ), | ||
1286 | new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | ||
1287 | 40, | ||
1288 | (s,cf,p,v) => { s.m_params[0].linkConstraintSolverIterations = cf.GetFloat(p, v); }, | ||
1289 | (s) => { return s.m_params[0].linkConstraintSolverIterations; }, | ||
1290 | (s,p,l,v) => { s.m_params[0].linkConstraintSolverIterations = v; } ), | ||
1291 | |||
1292 | new ParameterDefn("LogPhysicsStatisticsFrames", "Frames between outputting detailed phys stats. (0 is off)", | ||
1293 | 0f, | ||
1294 | (s,cf,p,v) => { s.m_params[0].physicsLoggingFrames = cf.GetInt(p, (int)v); }, | ||
1295 | (s) => { return (float)s.m_params[0].physicsLoggingFrames; }, | ||
1296 | (s,p,l,v) => { s.m_params[0].physicsLoggingFrames = (int)v; } ), | ||
1297 | }; | ||
1298 | |||
1299 | // Convert a boolean to our numeric true and false values | ||
1300 | public float NumericBool(bool b) | ||
1301 | { | ||
1302 | return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse); | ||
1303 | } | ||
1304 | |||
1305 | // Convert numeric true and false values to a boolean | ||
1306 | public bool BoolNumeric(float b) | ||
1307 | { | ||
1308 | return (b == ConfigurationParameters.numericTrue ? true : false); | ||
1309 | } | ||
1310 | |||
1311 | // Search through the parameter definitions and return the matching | ||
1312 | // ParameterDefn structure. | ||
1313 | // Case does not matter as names are compared after converting to lower case. | ||
1314 | // Returns 'false' if the parameter is not found. | ||
1315 | private bool TryGetParameter(string paramName, out ParameterDefn defn) | ||
1316 | { | ||
1317 | bool ret = false; | ||
1318 | ParameterDefn foundDefn = new ParameterDefn(); | ||
1319 | string pName = paramName.ToLower(); | ||
1320 | |||
1321 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
1322 | { | ||
1323 | if (pName == parm.name.ToLower()) | ||
1324 | { | ||
1325 | foundDefn = parm; | ||
1326 | ret = true; | ||
1327 | break; | ||
1328 | } | ||
1329 | } | ||
1330 | defn = foundDefn; | ||
1331 | return ret; | ||
1332 | } | ||
1333 | |||
1334 | // Pass through the settable parameters and set the default values | ||
1335 | private void SetParameterDefaultValues() | ||
1336 | { | ||
1337 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
1338 | { | ||
1339 | parm.setter(this, parm.name, PhysParameterEntry.APPLY_TO_NONE, parm.defaultValue); | ||
1340 | } | ||
1341 | } | ||
1342 | |||
1343 | // Get user set values out of the ini file. | ||
1344 | private void SetParameterConfigurationValues(IConfig cfg) | ||
1345 | { | ||
1346 | foreach (ParameterDefn parm in ParameterDefinitions) | ||
1347 | { | ||
1348 | parm.userParam(this, cfg, parm.name, parm.defaultValue); | ||
1349 | } | ||
1350 | } | ||
1351 | |||
1352 | private PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1]; | ||
1353 | |||
1354 | // This creates an array in the correct format for returning the list of | ||
1355 | // parameters. This is used by the 'list' option of the 'physics' command. | ||
1356 | private void BuildParameterTable() | ||
1357 | { | ||
1358 | if (SettableParameters.Length < ParameterDefinitions.Length) | ||
1359 | { | ||
1360 | List<PhysParameterEntry> entries = new List<PhysParameterEntry>(); | ||
1361 | for (int ii = 0; ii < ParameterDefinitions.Length; ii++) | ||
1362 | { | ||
1363 | ParameterDefn pd = ParameterDefinitions[ii]; | ||
1364 | entries.Add(new PhysParameterEntry(pd.name, pd.desc)); | ||
1365 | } | ||
1366 | |||
1367 | // make the list in alphabetical order for estetic reasons | ||
1368 | entries.Sort(delegate(PhysParameterEntry ppe1, PhysParameterEntry ppe2) | ||
1369 | { | ||
1370 | return ppe1.name.CompareTo(ppe2.name); | ||
1371 | }); | ||
1372 | |||
1373 | SettableParameters = entries.ToArray(); | ||
1374 | } | ||
1375 | } | ||
1376 | |||
1377 | |||
1378 | #region IPhysicsParameters | 849 | #region IPhysicsParameters |
1379 | // Get the list of parameters this physics engine supports | 850 | // Get the list of parameters this physics engine supports |
1380 | public PhysParameterEntry[] GetParameterList() | 851 | public PhysParameterEntry[] GetParameterList() |
1381 | { | 852 | { |
1382 | BuildParameterTable(); | 853 | BSParam.BuildParameterTable(); |
1383 | return SettableParameters; | 854 | return BSParam.SettableParameters; |
1384 | } | 855 | } |
1385 | 856 | ||
1386 | // Set parameter on a specific or all instances. | 857 | // Set parameter on a specific or all instances. |
@@ -1392,8 +863,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
1392 | public bool SetPhysicsParameter(string parm, float val, uint localID) | 863 | public bool SetPhysicsParameter(string parm, float val, uint localID) |
1393 | { | 864 | { |
1394 | bool ret = false; | 865 | bool ret = false; |
1395 | ParameterDefn theParam; | 866 | BSParam.ParameterDefn theParam; |
1396 | if (TryGetParameter(parm, out theParam)) | 867 | if (BSParam.TryGetParameter(parm, out theParam)) |
1397 | { | 868 | { |
1398 | theParam.setter(this, parm, localID, val); | 869 | theParam.setter(this, parm, localID, val); |
1399 | ret = true; | 870 | ret = true; |
@@ -1405,19 +876,20 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
1405 | // If the local ID is APPLY_TO_NONE, just change the default value | 876 | // If the local ID is APPLY_TO_NONE, just change the default value |
1406 | // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs | 877 | // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs |
1407 | // If the localID is a specific object, apply the parameter change to only that object | 878 | // If the localID is a specific object, apply the parameter change to only that object |
1408 | private void UpdateParameterObject(ref float defaultLoc, string parm, uint localID, float val) | 879 | internal delegate void AssignVal(float x); |
880 | internal void UpdateParameterObject(AssignVal setDefault, string parm, uint localID, float val) | ||
1409 | { | 881 | { |
1410 | List<uint> objectIDs = new List<uint>(); | 882 | List<uint> objectIDs = new List<uint>(); |
1411 | switch (localID) | 883 | switch (localID) |
1412 | { | 884 | { |
1413 | case PhysParameterEntry.APPLY_TO_NONE: | 885 | case PhysParameterEntry.APPLY_TO_NONE: |
1414 | defaultLoc = val; // setting only the default value | 886 | setDefault(val); // setting only the default value |
1415 | // This will cause a call into the physical world if some operation is specified (SetOnObject). | 887 | // This will cause a call into the physical world if some operation is specified (SetOnObject). |
1416 | objectIDs.Add(TERRAIN_ID); | 888 | objectIDs.Add(TERRAIN_ID); |
1417 | TaintedUpdateParameter(parm, objectIDs, val); | 889 | TaintedUpdateParameter(parm, objectIDs, val); |
1418 | break; | 890 | break; |
1419 | case PhysParameterEntry.APPLY_TO_ALL: | 891 | case PhysParameterEntry.APPLY_TO_ALL: |
1420 | defaultLoc = val; // setting ALL also sets the default value | 892 | setDefault(val); // setting ALL also sets the default value |
1421 | lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys); | 893 | lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys); |
1422 | TaintedUpdateParameter(parm, objectIDs, val); | 894 | TaintedUpdateParameter(parm, objectIDs, val); |
1423 | break; | 895 | break; |
@@ -1436,8 +908,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
1436 | List<uint> xlIDs = lIDs; | 908 | List<uint> xlIDs = lIDs; |
1437 | string xparm = parm; | 909 | string xparm = parm; |
1438 | TaintedObject("BSScene.UpdateParameterSet", delegate() { | 910 | TaintedObject("BSScene.UpdateParameterSet", delegate() { |
1439 | ParameterDefn thisParam; | 911 | BSParam.ParameterDefn thisParam; |
1440 | if (TryGetParameter(xparm, out thisParam)) | 912 | if (BSParam.TryGetParameter(xparm, out thisParam)) |
1441 | { | 913 | { |
1442 | if (thisParam.onObject != null) | 914 | if (thisParam.onObject != null) |
1443 | { | 915 | { |
@@ -1458,8 +930,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
1458 | { | 930 | { |
1459 | float val = 0f; | 931 | float val = 0f; |
1460 | bool ret = false; | 932 | bool ret = false; |
1461 | ParameterDefn theParam; | 933 | BSParam.ParameterDefn theParam; |
1462 | if (TryGetParameter(parm, out theParam)) | 934 | if (BSParam.TryGetParameter(parm, out theParam)) |
1463 | { | 935 | { |
1464 | val = theParam.getter(this); | 936 | val = theParam.getter(this); |
1465 | ret = true; | 937 | ret = true; |
@@ -1470,24 +942,12 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
1470 | 942 | ||
1471 | #endregion IPhysicsParameters | 943 | #endregion IPhysicsParameters |
1472 | 944 | ||
1473 | #endregion Runtime settable parameters | ||
1474 | |||
1475 | // Debugging routine for dumping detailed physical information for vehicle prims | ||
1476 | private void DumpVehicles() | ||
1477 | { | ||
1478 | foreach (BSPrim prim in m_vehicles) | ||
1479 | { | ||
1480 | BulletSimAPI.DumpRigidBody2(World.ptr, prim.PhysBody.ptr); | ||
1481 | BulletSimAPI.DumpCollisionShape2(World.ptr, prim.PhysShape.ptr); | ||
1482 | } | ||
1483 | } | ||
1484 | |||
1485 | // Invoke the detailed logger and output something if it's enabled. | 945 | // Invoke the detailed logger and output something if it's enabled. |
1486 | public void DetailLog(string msg, params Object[] args) | 946 | public void DetailLog(string msg, params Object[] args) |
1487 | { | 947 | { |
1488 | PhysicsLogging.Write(msg, args); | 948 | PhysicsLogging.Write(msg, args); |
1489 | // Add the Flush() if debugging crashes. Gets all the messages written out. | 949 | // Add the Flush() if debugging crashes. Gets all the messages written out. |
1490 | // PhysicsLogging.Flush(); | 950 | if (m_physicsLoggingDoFlush) PhysicsLogging.Flush(); |
1491 | } | 951 | } |
1492 | // Used to fill in the LocalID when there isn't one. It's the correct number of characters. | 952 | // Used to fill in the LocalID when there isn't one. It's the correct number of characters. |
1493 | public const string DetailLogZero = "0000000000"; | 953 | public const string DetailLogZero = "0000000000"; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 892c34b..473ef10 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -45,7 +45,7 @@ public sealed class BSShapeCollection : IDisposable | |||
45 | // Description of a Mesh | 45 | // Description of a Mesh |
46 | private struct MeshDesc | 46 | private struct MeshDesc |
47 | { | 47 | { |
48 | public IntPtr ptr; | 48 | public BulletShape shape; |
49 | public int referenceCount; | 49 | public int referenceCount; |
50 | public DateTime lastReferenced; | 50 | public DateTime lastReferenced; |
51 | public UInt64 shapeKey; | 51 | public UInt64 shapeKey; |
@@ -55,7 +55,7 @@ public sealed class BSShapeCollection : IDisposable | |||
55 | // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. | 55 | // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. |
56 | private struct HullDesc | 56 | private struct HullDesc |
57 | { | 57 | { |
58 | public IntPtr ptr; | 58 | public BulletShape shape; |
59 | public int referenceCount; | 59 | public int referenceCount; |
60 | public DateTime lastReferenced; | 60 | public DateTime lastReferenced; |
61 | public UInt64 shapeKey; | 61 | public UInt64 shapeKey; |
@@ -65,9 +65,16 @@ public sealed class BSShapeCollection : IDisposable | |||
65 | private Dictionary<System.UInt64, MeshDesc> Meshes = new Dictionary<System.UInt64, MeshDesc>(); | 65 | private Dictionary<System.UInt64, MeshDesc> Meshes = new Dictionary<System.UInt64, MeshDesc>(); |
66 | private Dictionary<System.UInt64, HullDesc> Hulls = new Dictionary<System.UInt64, HullDesc>(); | 66 | private Dictionary<System.UInt64, HullDesc> Hulls = new Dictionary<System.UInt64, HullDesc>(); |
67 | 67 | ||
68 | private bool DDetail = false; | ||
69 | |||
68 | public BSShapeCollection(BSScene physScene) | 70 | public BSShapeCollection(BSScene physScene) |
69 | { | 71 | { |
70 | PhysicsScene = physScene; | 72 | PhysicsScene = physScene; |
73 | // Set the next to 'true' for very detailed shape update detailed logging (detailed details?) | ||
74 | // While detailed debugging is still active, this is better than commenting out all the | ||
75 | // DetailLog statements. When debugging slows down, this and the protected logging | ||
76 | // statements can be commented/removed. | ||
77 | DDetail = true; | ||
71 | } | 78 | } |
72 | 79 | ||
73 | public void Dispose() | 80 | public void Dispose() |
@@ -91,7 +98,7 @@ public sealed class BSShapeCollection : IDisposable | |||
91 | // higher level dependencies on the shape or body. Mostly used for LinkSets to | 98 | // higher level dependencies on the shape or body. Mostly used for LinkSets to |
92 | // remove the physical constraints before the body is destroyed. | 99 | // remove the physical constraints before the body is destroyed. |
93 | // Called at taint-time!! | 100 | // Called at taint-time!! |
94 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim, | 101 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim, |
95 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) | 102 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) |
96 | { | 103 | { |
97 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); | 104 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); |
@@ -119,6 +126,11 @@ public sealed class BSShapeCollection : IDisposable | |||
119 | return ret; | 126 | return ret; |
120 | } | 127 | } |
121 | 128 | ||
129 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim) | ||
130 | { | ||
131 | return GetBodyAndShape(forceRebuild, sim, prim, null, null); | ||
132 | } | ||
133 | |||
122 | // Track another user of a body. | 134 | // Track another user of a body. |
123 | // We presume the caller has allocated the body. | 135 | // We presume the caller has allocated the body. |
124 | // Bodies only have one user so the body is just put into the world if not already there. | 136 | // Bodies only have one user so the body is just put into the world if not already there. |
@@ -126,13 +138,13 @@ public sealed class BSShapeCollection : IDisposable | |||
126 | { | 138 | { |
127 | lock (m_collectionActivityLock) | 139 | lock (m_collectionActivityLock) |
128 | { | 140 | { |
129 | DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); | 141 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); |
130 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() | 142 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() |
131 | { | 143 | { |
132 | if (!BulletSimAPI.IsInWorld2(body.ptr)) | 144 | if (!PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) |
133 | { | 145 | { |
134 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); | 146 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); |
135 | DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); | 147 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); |
136 | } | 148 | } |
137 | }); | 149 | }); |
138 | } | 150 | } |
@@ -142,27 +154,27 @@ public sealed class BSShapeCollection : IDisposable | |||
142 | // Called when releasing use of a BSBody. BSShape is handled separately. | 154 | // Called when releasing use of a BSBody. BSShape is handled separately. |
143 | public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) | 155 | public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) |
144 | { | 156 | { |
145 | if (body.ptr == IntPtr.Zero) | 157 | if (!body.HasPhysicalBody) |
146 | return; | 158 | return; |
147 | 159 | ||
148 | lock (m_collectionActivityLock) | 160 | lock (m_collectionActivityLock) |
149 | { | 161 | { |
150 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() | 162 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() |
151 | { | 163 | { |
152 | DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}", | 164 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}", |
153 | body.ID, body, inTaintTime); | 165 | body.ID, body, inTaintTime); |
154 | // If the caller needs to know the old body is going away, pass the event up. | 166 | // If the caller needs to know the old body is going away, pass the event up. |
155 | if (bodyCallback != null) bodyCallback(body); | 167 | if (bodyCallback != null) bodyCallback(body); |
156 | 168 | ||
157 | if (BulletSimAPI.IsInWorld2(body.ptr)) | 169 | if (PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) |
158 | { | 170 | { |
159 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); | 171 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); |
160 | DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); | 172 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); |
161 | } | 173 | } |
162 | 174 | ||
163 | // Zero any reference to the shape so it is not freed when the body is deleted. | 175 | // Zero any reference to the shape so it is not freed when the body is deleted. |
164 | BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); | 176 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null); |
165 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); | 177 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); |
166 | }); | 178 | }); |
167 | } | 179 | } |
168 | } | 180 | } |
@@ -184,17 +196,17 @@ public sealed class BSShapeCollection : IDisposable | |||
184 | { | 196 | { |
185 | // There is an existing instance of this mesh. | 197 | // There is an existing instance of this mesh. |
186 | meshDesc.referenceCount++; | 198 | meshDesc.referenceCount++; |
187 | DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", | 199 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", |
188 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | 200 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); |
189 | } | 201 | } |
190 | else | 202 | else |
191 | { | 203 | { |
192 | // This is a new reference to a mesh | 204 | // This is a new reference to a mesh |
193 | meshDesc.ptr = shape.ptr; | 205 | meshDesc.shape = shape.Clone(); |
194 | meshDesc.shapeKey = shape.shapeKey; | 206 | meshDesc.shapeKey = shape.shapeKey; |
195 | // We keep a reference to the underlying IMesh data so a hull can be built | 207 | // We keep a reference to the underlying IMesh data so a hull can be built |
196 | meshDesc.referenceCount = 1; | 208 | meshDesc.referenceCount = 1; |
197 | DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", | 209 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", |
198 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | 210 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); |
199 | ret = true; | 211 | ret = true; |
200 | } | 212 | } |
@@ -207,16 +219,16 @@ public sealed class BSShapeCollection : IDisposable | |||
207 | { | 219 | { |
208 | // There is an existing instance of this hull. | 220 | // There is an existing instance of this hull. |
209 | hullDesc.referenceCount++; | 221 | hullDesc.referenceCount++; |
210 | DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", | 222 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", |
211 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | 223 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); |
212 | } | 224 | } |
213 | else | 225 | else |
214 | { | 226 | { |
215 | // This is a new reference to a hull | 227 | // This is a new reference to a hull |
216 | hullDesc.ptr = shape.ptr; | 228 | hullDesc.shape = shape.Clone(); |
217 | hullDesc.shapeKey = shape.shapeKey; | 229 | hullDesc.shapeKey = shape.shapeKey; |
218 | hullDesc.referenceCount = 1; | 230 | hullDesc.referenceCount = 1; |
219 | DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", | 231 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", |
220 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | 232 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); |
221 | ret = true; | 233 | ret = true; |
222 | 234 | ||
@@ -236,20 +248,20 @@ public sealed class BSShapeCollection : IDisposable | |||
236 | // Release the usage of a shape. | 248 | // Release the usage of a shape. |
237 | public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) | 249 | public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) |
238 | { | 250 | { |
239 | if (shape.ptr == IntPtr.Zero) | 251 | if (!shape.HasPhysicalShape) |
240 | return; | 252 | return; |
241 | 253 | ||
242 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() | 254 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() |
243 | { | 255 | { |
244 | if (shape.ptr != IntPtr.Zero) | 256 | if (shape.HasPhysicalShape) |
245 | { | 257 | { |
246 | if (shape.isNativeShape) | 258 | if (shape.isNativeShape) |
247 | { | 259 | { |
248 | // Native shapes are not tracked and are released immediately | 260 | // Native shapes are not tracked and are released immediately |
249 | DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", | 261 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", |
250 | BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); | 262 | BSScene.DetailLogZero, shape.AddrString, inTaintTime); |
251 | if (shapeCallback != null) shapeCallback(shape); | 263 | if (shapeCallback != null) shapeCallback(shape); |
252 | BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); | 264 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); |
253 | } | 265 | } |
254 | else | 266 | else |
255 | { | 267 | { |
@@ -286,7 +298,7 @@ public sealed class BSShapeCollection : IDisposable | |||
286 | if (shapeCallback != null) shapeCallback(shape); | 298 | if (shapeCallback != null) shapeCallback(shape); |
287 | meshDesc.lastReferenced = System.DateTime.Now; | 299 | meshDesc.lastReferenced = System.DateTime.Now; |
288 | Meshes[shape.shapeKey] = meshDesc; | 300 | Meshes[shape.shapeKey] = meshDesc; |
289 | DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", | 301 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", |
290 | BSScene.DetailLogZero, shape, meshDesc.referenceCount); | 302 | BSScene.DetailLogZero, shape, meshDesc.referenceCount); |
291 | 303 | ||
292 | } | 304 | } |
@@ -307,7 +319,7 @@ public sealed class BSShapeCollection : IDisposable | |||
307 | 319 | ||
308 | hullDesc.lastReferenced = System.DateTime.Now; | 320 | hullDesc.lastReferenced = System.DateTime.Now; |
309 | Hulls[shape.shapeKey] = hullDesc; | 321 | Hulls[shape.shapeKey] = hullDesc; |
310 | DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", | 322 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", |
311 | BSScene.DetailLogZero, shape, hullDesc.referenceCount); | 323 | BSScene.DetailLogZero, shape, hullDesc.referenceCount); |
312 | } | 324 | } |
313 | } | 325 | } |
@@ -320,57 +332,56 @@ public sealed class BSShapeCollection : IDisposable | |||
320 | // Called at taint-time. | 332 | // Called at taint-time. |
321 | private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) | 333 | private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) |
322 | { | 334 | { |
323 | if (!BulletSimAPI.IsCompound2(shape.ptr)) | 335 | if (!PhysicsScene.PE.IsCompound(shape)) |
324 | { | 336 | { |
325 | // Failed the sanity check!! | 337 | // Failed the sanity check!! |
326 | PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", | 338 | PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", |
327 | LogHeader, shape.type, shape.ptr.ToString("X")); | 339 | LogHeader, shape.type, shape.AddrString); |
328 | DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", | 340 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", |
329 | BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); | 341 | BSScene.DetailLogZero, shape.type, shape.AddrString); |
330 | return; | 342 | return; |
331 | } | 343 | } |
332 | 344 | ||
333 | int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); | 345 | int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape); |
334 | DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); | 346 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); |
335 | 347 | ||
336 | for (int ii = numChildren - 1; ii >= 0; ii--) | 348 | for (int ii = numChildren - 1; ii >= 0; ii--) |
337 | { | 349 | { |
338 | IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); | 350 | BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii); |
339 | DereferenceAnonCollisionShape(childShape); | 351 | DereferenceAnonCollisionShape(childShape); |
340 | } | 352 | } |
341 | BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); | 353 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); |
342 | } | 354 | } |
343 | 355 | ||
344 | // Sometimes we have a pointer to a collision shape but don't know what type it is. | 356 | // Sometimes we have a pointer to a collision shape but don't know what type it is. |
345 | // Figure out type and call the correct dereference routine. | 357 | // Figure out type and call the correct dereference routine. |
346 | // Called at taint-time. | 358 | // Called at taint-time. |
347 | private void DereferenceAnonCollisionShape(IntPtr cShape) | 359 | private void DereferenceAnonCollisionShape(BulletShape shapeInfo) |
348 | { | 360 | { |
349 | MeshDesc meshDesc; | 361 | MeshDesc meshDesc; |
350 | HullDesc hullDesc; | 362 | HullDesc hullDesc; |
351 | 363 | ||
352 | BulletShape shapeInfo = new BulletShape(cShape); | 364 | if (TryGetMeshByPtr(shapeInfo, out meshDesc)) |
353 | if (TryGetMeshByPtr(cShape, out meshDesc)) | ||
354 | { | 365 | { |
355 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; | 366 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; |
356 | shapeInfo.shapeKey = meshDesc.shapeKey; | 367 | shapeInfo.shapeKey = meshDesc.shapeKey; |
357 | } | 368 | } |
358 | else | 369 | else |
359 | { | 370 | { |
360 | if (TryGetHullByPtr(cShape, out hullDesc)) | 371 | if (TryGetHullByPtr(shapeInfo, out hullDesc)) |
361 | { | 372 | { |
362 | shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; | 373 | shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; |
363 | shapeInfo.shapeKey = hullDesc.shapeKey; | 374 | shapeInfo.shapeKey = hullDesc.shapeKey; |
364 | } | 375 | } |
365 | else | 376 | else |
366 | { | 377 | { |
367 | if (BulletSimAPI.IsCompound2(cShape)) | 378 | if (PhysicsScene.PE.IsCompound(shapeInfo)) |
368 | { | 379 | { |
369 | shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; | 380 | shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; |
370 | } | 381 | } |
371 | else | 382 | else |
372 | { | 383 | { |
373 | if (BulletSimAPI.IsNativeShape2(cShape)) | 384 | if (PhysicsScene.PE.IsNativeShape(shapeInfo)) |
374 | { | 385 | { |
375 | shapeInfo.isNativeShape = true; | 386 | shapeInfo.isNativeShape = true; |
376 | shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) | 387 | shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) |
@@ -379,7 +390,7 @@ public sealed class BSShapeCollection : IDisposable | |||
379 | } | 390 | } |
380 | } | 391 | } |
381 | 392 | ||
382 | DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); | 393 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); |
383 | 394 | ||
384 | if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN) | 395 | if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN) |
385 | { | 396 | { |
@@ -388,7 +399,7 @@ public sealed class BSShapeCollection : IDisposable | |||
388 | else | 399 | else |
389 | { | 400 | { |
390 | PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", | 401 | PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", |
391 | LogHeader, PhysicsScene.RegionName, cShape.ToString("X")); | 402 | LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString); |
392 | } | 403 | } |
393 | } | 404 | } |
394 | 405 | ||
@@ -408,19 +419,18 @@ public sealed class BSShapeCollection : IDisposable | |||
408 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE) | 419 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE) |
409 | { | 420 | { |
410 | // an avatar capsule is close to a native shape (it is not shared) | 421 | // an avatar capsule is close to a native shape (it is not shared) |
411 | ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE, | 422 | GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE, shapeCallback); |
412 | FixedShapeKey.KEY_CAPSULE, shapeCallback); | 423 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape); |
413 | DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape); | ||
414 | ret = true; | 424 | ret = true; |
415 | haveShape = true; | 425 | haveShape = true; |
416 | } | 426 | } |
417 | 427 | ||
418 | // Compound shapes are handled special as they are rebuilt from scratch. | 428 | // Compound shapes are handled special as they are rebuilt from scratch. |
419 | // This isn't too great a hardship since most of the child shapes will already been created. | 429 | // This isn't too great a hardship since most of the child shapes will have already been created. |
420 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) | 430 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) |
421 | { | 431 | { |
422 | ret = GetReferenceToCompoundShape(prim, shapeCallback); | 432 | ret = GetReferenceToCompoundShape(prim, shapeCallback); |
423 | DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape); | 433 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape); |
424 | haveShape = true; | 434 | haveShape = true; |
425 | } | 435 | } |
426 | 436 | ||
@@ -432,8 +442,9 @@ public sealed class BSShapeCollection : IDisposable | |||
432 | return ret; | 442 | return ret; |
433 | } | 443 | } |
434 | 444 | ||
435 | // Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'. | 445 | // Create a mesh, hull or native shape. |
436 | private bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 446 | // Return 'true' if the prim's shape was changed. |
447 | public bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) | ||
437 | { | 448 | { |
438 | bool ret = false; | 449 | bool ret = false; |
439 | bool haveShape = false; | 450 | bool haveShape = false; |
@@ -443,8 +454,9 @@ public sealed class BSShapeCollection : IDisposable | |||
443 | // If the prim attributes are simple, this could be a simple Bullet native shape | 454 | // If the prim attributes are simple, this could be a simple Bullet native shape |
444 | if (!haveShape | 455 | if (!haveShape |
445 | && pbs != null | 456 | && pbs != null |
457 | && !pbs.SculptEntry | ||
446 | && nativeShapePossible | 458 | && nativeShapePossible |
447 | && ((pbs.SculptEntry && !PhysicsScene.ShouldMeshSculptedPrim) | 459 | && ((pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim) |
448 | || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | 460 | || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 |
449 | && pbs.ProfileHollow == 0 | 461 | && pbs.ProfileHollow == 0 |
450 | && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 | 462 | && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 |
@@ -453,35 +465,43 @@ public sealed class BSShapeCollection : IDisposable | |||
453 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 | 465 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 |
454 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) | 466 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) |
455 | { | 467 | { |
456 | // It doesn't look like Bullet scales spheres so make sure the scales are all equal | 468 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. |
469 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; | ||
470 | if (prim.PhysShape.HasPhysicalShape) | ||
471 | scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape); | ||
472 | |||
473 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", | ||
474 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); | ||
475 | |||
476 | // It doesn't look like Bullet scales native spheres so make sure the scales are all equal | ||
457 | if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) | 477 | if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) |
458 | && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z) | 478 | && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z) |
459 | { | 479 | { |
460 | haveShape = true; | 480 | haveShape = true; |
461 | if (forceRebuild | 481 | if (forceRebuild |
462 | || prim.Scale != prim.Size | 482 | || prim.Scale != scaleOfExistingShape |
463 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE | 483 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE |
464 | ) | 484 | ) |
465 | { | 485 | { |
466 | ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_SPHERE, | 486 | ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_SPHERE, |
467 | FixedShapeKey.KEY_SPHERE, shapeCallback); | 487 | FixedShapeKey.KEY_SPHERE, shapeCallback); |
468 | DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},shape={2}", | ||
469 | prim.LocalID, forceRebuild, prim.PhysShape); | ||
470 | } | 488 | } |
489 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},rebuilt={2},shape={3}", | ||
490 | prim.LocalID, forceRebuild, ret, prim.PhysShape); | ||
471 | } | 491 | } |
472 | if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) | 492 | if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) |
473 | { | 493 | { |
474 | haveShape = true; | 494 | haveShape = true; |
475 | if (forceRebuild | 495 | if (forceRebuild |
476 | || prim.Scale != prim.Size | 496 | || prim.Scale != scaleOfExistingShape |
477 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX | 497 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX |
478 | ) | 498 | ) |
479 | { | 499 | { |
480 | ret = GetReferenceToNativeShape( prim, BSPhysicsShapeType.SHAPE_BOX, | 500 | ret = GetReferenceToNativeShape( prim, BSPhysicsShapeType.SHAPE_BOX, |
481 | FixedShapeKey.KEY_BOX, shapeCallback); | 501 | FixedShapeKey.KEY_BOX, shapeCallback); |
482 | DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},shape={2}", | ||
483 | prim.LocalID, forceRebuild, prim.PhysShape); | ||
484 | } | 502 | } |
503 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},rebuilt={2},shape={3}", | ||
504 | prim.LocalID, forceRebuild, ret, prim.PhysShape); | ||
485 | } | 505 | } |
486 | } | 506 | } |
487 | 507 | ||
@@ -494,23 +514,24 @@ public sealed class BSShapeCollection : IDisposable | |||
494 | return ret; | 514 | return ret; |
495 | } | 515 | } |
496 | 516 | ||
517 | // return 'true' if the prim's shape was changed. | ||
497 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 518 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
498 | { | 519 | { |
499 | 520 | ||
500 | bool ret = false; | 521 | bool ret = false; |
501 | // Note that if it's a native shape, the check for physical/non-physical is not | 522 | // Note that if it's a native shape, the check for physical/non-physical is not |
502 | // made. Native shapes work in either case. | 523 | // made. Native shapes work in either case. |
503 | if (prim.IsPhysical && PhysicsScene.ShouldUseHullsForPhysicalObjects) | 524 | if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects) |
504 | { | 525 | { |
505 | // Update prim.BSShape to reference a hull of this shape. | 526 | // Update prim.BSShape to reference a hull of this shape. |
506 | ret = GetReferenceToHull(prim,shapeCallback); | 527 | ret = GetReferenceToHull(prim,shapeCallback); |
507 | DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", | 528 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", |
508 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | 529 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); |
509 | } | 530 | } |
510 | else | 531 | else |
511 | { | 532 | { |
512 | ret = GetReferenceToMesh(prim, shapeCallback); | 533 | ret = GetReferenceToMesh(prim, shapeCallback); |
513 | DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", | 534 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", |
514 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | 535 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); |
515 | } | 536 | } |
516 | return ret; | 537 | return ret; |
@@ -528,9 +549,10 @@ public sealed class BSShapeCollection : IDisposable | |||
528 | BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey); | 549 | BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey); |
529 | 550 | ||
530 | // Don't need to do a 'ReferenceShape()' here because native shapes are not shared. | 551 | // Don't need to do a 'ReferenceShape()' here because native shapes are not shared. |
531 | DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}", | 552 | if (DDetail) DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}", |
532 | prim.LocalID, newShape, prim.Scale); | 553 | prim.LocalID, newShape, prim.Scale); |
533 | 554 | ||
555 | // native shapes are scaled by Bullet | ||
534 | prim.PhysShape = newShape; | 556 | prim.PhysShape = newShape; |
535 | return true; | 557 | return true; |
536 | } | 558 | } |
@@ -550,20 +572,17 @@ public sealed class BSShapeCollection : IDisposable | |||
550 | 572 | ||
551 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) | 573 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) |
552 | { | 574 | { |
553 | // The proper scale has been calculated in the prim. | 575 | |
554 | newShape = new BulletShape( | 576 | newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale); |
555 | BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale) | 577 | if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); |
556 | , shapeType); | ||
557 | DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); | ||
558 | } | 578 | } |
559 | else | 579 | else |
560 | { | 580 | { |
561 | // Native shapes are scaled in Bullet so set the scaling to the size | 581 | // Native shapes are scaled in Bullet so set the scaling to the size |
562 | prim.Scale = prim.Size; | 582 | newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData); |
563 | nativeShapeData.Scale = prim.Scale; | 583 | |
564 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); | ||
565 | } | 584 | } |
566 | if (newShape.ptr == IntPtr.Zero) | 585 | if (!newShape.HasPhysicalShape) |
567 | { | 586 | { |
568 | PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", | 587 | PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", |
569 | LogHeader, prim.LocalID, shapeType); | 588 | LogHeader, prim.LocalID, shapeType); |
@@ -580,7 +599,7 @@ public sealed class BSShapeCollection : IDisposable | |||
580 | // Called at taint-time! | 599 | // Called at taint-time! |
581 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 600 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
582 | { | 601 | { |
583 | BulletShape newShape = new BulletShape(IntPtr.Zero); | 602 | BulletShape newShape = new BulletShape(); |
584 | 603 | ||
585 | float lod; | 604 | float lod; |
586 | System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | 605 | System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); |
@@ -589,7 +608,7 @@ public sealed class BSShapeCollection : IDisposable | |||
589 | if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH) | 608 | if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH) |
590 | return false; | 609 | return false; |
591 | 610 | ||
592 | DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}", | 611 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}", |
593 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); | 612 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); |
594 | 613 | ||
595 | // Since we're recreating new, get rid of the reference to the previous shape | 614 | // Since we're recreating new, get rid of the reference to the previous shape |
@@ -601,8 +620,6 @@ public sealed class BSShapeCollection : IDisposable | |||
601 | 620 | ||
602 | ReferenceShape(newShape); | 621 | ReferenceShape(newShape); |
603 | 622 | ||
604 | // meshes are already scaled by the meshmerizer | ||
605 | prim.Scale = new OMV.Vector3(1f, 1f, 1f); | ||
606 | prim.PhysShape = newShape; | 623 | prim.PhysShape = newShape; |
607 | 624 | ||
608 | return true; // 'true' means a new shape has been added to this prim | 625 | return true; // 'true' means a new shape has been added to this prim |
@@ -610,18 +627,18 @@ public sealed class BSShapeCollection : IDisposable | |||
610 | 627 | ||
611 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 628 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
612 | { | 629 | { |
630 | BulletShape newShape = new BulletShape(); | ||
613 | IMesh meshData = null; | 631 | IMesh meshData = null; |
614 | IntPtr meshPtr = IntPtr.Zero; | 632 | |
615 | MeshDesc meshDesc; | 633 | MeshDesc meshDesc; |
616 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) | 634 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) |
617 | { | 635 | { |
618 | // If the mesh has already been built just use it. | 636 | // If the mesh has already been built just use it. |
619 | meshPtr = meshDesc.ptr; | 637 | newShape = meshDesc.shape.Clone(); |
620 | } | 638 | } |
621 | else | 639 | else |
622 | { | 640 | { |
623 | // Pass false for physicalness as this creates some sort of bounding box which we don't need | 641 | meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); |
624 | meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, false); | ||
625 | 642 | ||
626 | if (meshData != null) | 643 | if (meshData != null) |
627 | { | 644 | { |
@@ -640,11 +657,10 @@ public sealed class BSShapeCollection : IDisposable | |||
640 | // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", | 657 | // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", |
641 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); | 658 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); |
642 | 659 | ||
643 | meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | 660 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, |
644 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); | 661 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); |
645 | } | 662 | } |
646 | } | 663 | } |
647 | BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH); | ||
648 | newShape.shapeKey = newMeshKey; | 664 | newShape.shapeKey = newMeshKey; |
649 | 665 | ||
650 | return newShape; | 666 | return newShape; |
@@ -663,7 +679,7 @@ public sealed class BSShapeCollection : IDisposable | |||
663 | if (newHullKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_HULL) | 679 | if (newHullKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_HULL) |
664 | return false; | 680 | return false; |
665 | 681 | ||
666 | DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}", | 682 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}", |
667 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X")); | 683 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X")); |
668 | 684 | ||
669 | // Remove usage of the previous shape. | 685 | // Remove usage of the previous shape. |
@@ -674,8 +690,6 @@ public sealed class BSShapeCollection : IDisposable | |||
674 | 690 | ||
675 | ReferenceShape(newShape); | 691 | ReferenceShape(newShape); |
676 | 692 | ||
677 | // hulls are already scaled by the meshmerizer | ||
678 | prim.Scale = new OMV.Vector3(1f, 1f, 1f); | ||
679 | prim.PhysShape = newShape; | 693 | prim.PhysShape = newShape; |
680 | return true; // 'true' means a new shape has been added to this prim | 694 | return true; // 'true' means a new shape has been added to this prim |
681 | } | 695 | } |
@@ -684,18 +698,20 @@ public sealed class BSShapeCollection : IDisposable | |||
684 | private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 698 | private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
685 | { | 699 | { |
686 | 700 | ||
701 | BulletShape newShape = new BulletShape(); | ||
687 | IntPtr hullPtr = IntPtr.Zero; | 702 | IntPtr hullPtr = IntPtr.Zero; |
703 | |||
688 | HullDesc hullDesc; | 704 | HullDesc hullDesc; |
689 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) | 705 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) |
690 | { | 706 | { |
691 | // If the hull shape already is created, just use it. | 707 | // If the hull shape already is created, just use it. |
692 | hullPtr = hullDesc.ptr; | 708 | newShape = hullDesc.shape.Clone(); |
693 | } | 709 | } |
694 | else | 710 | else |
695 | { | 711 | { |
696 | // Build a new hull in the physical world | 712 | // Build a new hull in the physical world |
697 | // Pass false for physicalness as this creates some sort of bounding box which we don't need | 713 | // Pass true for physicalness as this creates some sort of bounding box which we don't need |
698 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, false); | 714 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); |
699 | if (meshData != null) | 715 | if (meshData != null) |
700 | { | 716 | { |
701 | 717 | ||
@@ -777,14 +793,13 @@ public sealed class BSShapeCollection : IDisposable | |||
777 | } | 793 | } |
778 | } | 794 | } |
779 | // create the hull data structure in Bullet | 795 | // create the hull data structure in Bullet |
780 | hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); | 796 | newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls); |
781 | } | 797 | } |
782 | } | 798 | } |
783 | 799 | ||
784 | BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); | ||
785 | newShape.shapeKey = newHullKey; | 800 | newShape.shapeKey = newHullKey; |
786 | 801 | ||
787 | return newShape; // 'true' means a new shape has been added to this prim | 802 | return newShape; |
788 | } | 803 | } |
789 | 804 | ||
790 | // Callback from convex hull creater with a newly created hull. | 805 | // Callback from convex hull creater with a newly created hull. |
@@ -803,13 +818,13 @@ public sealed class BSShapeCollection : IDisposable | |||
803 | // Don't need to do this as the shape is freed when the new root shape is created below. | 818 | // Don't need to do this as the shape is freed when the new root shape is created below. |
804 | // DereferenceShape(prim.PhysShape, true, shapeCallback); | 819 | // DereferenceShape(prim.PhysShape, true, shapeCallback); |
805 | 820 | ||
806 | BulletShape cShape = new BulletShape( | 821 | |
807 | BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND); | 822 | BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false); |
808 | 823 | ||
809 | // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. | 824 | // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. |
810 | CreateGeomMeshOrHull(prim, shapeCallback); | 825 | CreateGeomMeshOrHull(prim, shapeCallback); |
811 | BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); | 826 | PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity); |
812 | DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", | 827 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", |
813 | prim.LocalID, cShape, prim.PhysShape); | 828 | prim.LocalID, cShape, prim.PhysShape); |
814 | 829 | ||
815 | prim.PhysShape = cShape; | 830 | prim.PhysShape = cShape; |
@@ -822,14 +837,14 @@ public sealed class BSShapeCollection : IDisposable | |||
822 | private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod) | 837 | private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod) |
823 | { | 838 | { |
824 | // level of detail based on size and type of the object | 839 | // level of detail based on size and type of the object |
825 | float lod = PhysicsScene.MeshLOD; | 840 | float lod = BSParam.MeshLOD; |
826 | if (pbs.SculptEntry) | 841 | if (pbs.SculptEntry) |
827 | lod = PhysicsScene.SculptLOD; | 842 | lod = BSParam.SculptLOD; |
828 | 843 | ||
829 | // Mega prims usually get more detail because one can interact with shape approximations at this size. | 844 | // Mega prims usually get more detail because one can interact with shape approximations at this size. |
830 | float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z)); | 845 | float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z)); |
831 | if (maxAxis > PhysicsScene.MeshMegaPrimThreshold) | 846 | if (maxAxis > BSParam.MeshMegaPrimThreshold) |
832 | lod = PhysicsScene.MeshMegaPrimLOD; | 847 | lod = BSParam.MeshMegaPrimLOD; |
833 | 848 | ||
834 | retLod = lod; | 849 | retLod = lod; |
835 | return pbs.GetMeshKey(size, lod); | 850 | return pbs.GetMeshKey(size, lod); |
@@ -851,7 +866,7 @@ public sealed class BSShapeCollection : IDisposable | |||
851 | private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) | 866 | private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) |
852 | { | 867 | { |
853 | // If the shape was successfully created, nothing more to do | 868 | // If the shape was successfully created, nothing more to do |
854 | if (newShape.ptr != IntPtr.Zero) | 869 | if (newShape.HasPhysicalShape) |
855 | return newShape; | 870 | return newShape; |
856 | 871 | ||
857 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | 872 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset |
@@ -859,8 +874,7 @@ public sealed class BSShapeCollection : IDisposable | |||
859 | { | 874 | { |
860 | prim.LastAssetBuildFailed = true; | 875 | prim.LastAssetBuildFailed = true; |
861 | BSPhysObject xprim = prim; | 876 | BSPhysObject xprim = prim; |
862 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lID={1},lastFailed={2}", | 877 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed); |
863 | LogHeader, prim.LocalID, prim.LastAssetBuildFailed); | ||
864 | Util.FireAndForget(delegate | 878 | Util.FireAndForget(delegate |
865 | { | 879 | { |
866 | RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; | 880 | RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; |
@@ -869,19 +883,34 @@ public sealed class BSShapeCollection : IDisposable | |||
869 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. | 883 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. |
870 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) | 884 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) |
871 | { | 885 | { |
872 | if (!yprim.BaseShape.SculptEntry) | 886 | bool assetFound = false; // DEBUG DEBUG |
873 | return; | 887 | string mismatchIDs = String.Empty; // DEBUG DEBUG |
874 | if (yprim.BaseShape.SculptTexture.ToString() != asset.ID) | 888 | if (yprim.BaseShape.SculptEntry) |
875 | return; | 889 | { |
876 | 890 | if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) | |
877 | yprim.BaseShape.SculptData = asset.Data; | 891 | { |
878 | // This will cause the prim to see that the filler shape is not the right | 892 | yprim.BaseShape.SculptData = asset.Data; |
879 | // one and try again to build the object. | 893 | // This will cause the prim to see that the filler shape is not the right |
880 | // No race condition with the normal shape setting since the rebuild is at taint time. | 894 | // one and try again to build the object. |
881 | yprim.ForceBodyShapeRebuild(false); | 895 | // No race condition with the normal shape setting since the rebuild is at taint time. |
896 | yprim.ForceBodyShapeRebuild(false /* inTaintTime */); | ||
897 | assetFound = true; | ||
898 | } | ||
899 | else | ||
900 | { | ||
901 | mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID; | ||
902 | } | ||
903 | } | ||
904 | DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}", | ||
905 | yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs ); | ||
882 | 906 | ||
883 | }); | 907 | }); |
884 | } | 908 | } |
909 | else | ||
910 | { | ||
911 | PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}", | ||
912 | LogHeader, PhysicsScene.Name); | ||
913 | } | ||
885 | }); | 914 | }); |
886 | } | 915 | } |
887 | else | 916 | else |
@@ -893,9 +922,9 @@ public sealed class BSShapeCollection : IDisposable | |||
893 | } | 922 | } |
894 | } | 923 | } |
895 | 924 | ||
896 | // While we figure out the real problem, stick a simple native shape on the object. | 925 | // While we wait for the mesh defining asset to be loaded, stick in a simple box for the object. |
897 | BulletShape fillinShape = | 926 | BulletShape fillinShape = BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); |
898 | BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | 927 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,boxTempShape", prim.LocalID); |
899 | 928 | ||
900 | return fillinShape; | 929 | return fillinShape; |
901 | } | 930 | } |
@@ -904,19 +933,19 @@ public sealed class BSShapeCollection : IDisposable | |||
904 | // Updates prim.BSBody with the information about the new body if one is created. | 933 | // Updates prim.BSBody with the information about the new body if one is created. |
905 | // Returns 'true' if an object was actually created. | 934 | // Returns 'true' if an object was actually created. |
906 | // Called at taint-time. | 935 | // Called at taint-time. |
907 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletSim sim, BulletShape shape, | 936 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BulletShape shape, |
908 | BodyDestructionCallback bodyCallback) | 937 | BodyDestructionCallback bodyCallback) |
909 | { | 938 | { |
910 | bool ret = false; | 939 | bool ret = false; |
911 | 940 | ||
912 | // the mesh, hull or native shape must have already been created in Bullet | 941 | // the mesh, hull or native shape must have already been created in Bullet |
913 | bool mustRebuild = (prim.PhysBody.ptr == IntPtr.Zero); | 942 | bool mustRebuild = !prim.PhysBody.HasPhysicalBody; |
914 | 943 | ||
915 | // If there is an existing body, verify it's of an acceptable type. | 944 | // If there is an existing body, verify it's of an acceptable type. |
916 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. | 945 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. |
917 | if (!mustRebuild) | 946 | if (!mustRebuild) |
918 | { | 947 | { |
919 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr); | 948 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody); |
920 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY | 949 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY |
921 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) | 950 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) |
922 | { | 951 | { |
@@ -931,20 +960,16 @@ public sealed class BSShapeCollection : IDisposable | |||
931 | DereferenceBody(prim.PhysBody, true, bodyCallback); | 960 | DereferenceBody(prim.PhysBody, true, bodyCallback); |
932 | 961 | ||
933 | BulletBody aBody; | 962 | BulletBody aBody; |
934 | IntPtr bodyPtr = IntPtr.Zero; | ||
935 | if (prim.IsSolid) | 963 | if (prim.IsSolid) |
936 | { | 964 | { |
937 | bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, | 965 | aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
938 | prim.LocalID, prim.RawPosition, prim.RawOrientation); | 966 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody); |
939 | DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | ||
940 | } | 967 | } |
941 | else | 968 | else |
942 | { | 969 | { |
943 | bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, | 970 | aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
944 | prim.LocalID, prim.RawPosition, prim.RawOrientation); | 971 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); |
945 | DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | ||
946 | } | 972 | } |
947 | aBody = new BulletBody(prim.LocalID, bodyPtr); | ||
948 | 973 | ||
949 | ReferenceBody(aBody, true); | 974 | ReferenceBody(aBody, true); |
950 | 975 | ||
@@ -956,13 +981,13 @@ public sealed class BSShapeCollection : IDisposable | |||
956 | return ret; | 981 | return ret; |
957 | } | 982 | } |
958 | 983 | ||
959 | private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc) | 984 | private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc) |
960 | { | 985 | { |
961 | bool ret = false; | 986 | bool ret = false; |
962 | MeshDesc foundDesc = new MeshDesc(); | 987 | MeshDesc foundDesc = new MeshDesc(); |
963 | foreach (MeshDesc md in Meshes.Values) | 988 | foreach (MeshDesc md in Meshes.Values) |
964 | { | 989 | { |
965 | if (md.ptr == addr) | 990 | if (md.shape.ReferenceSame(shape)) |
966 | { | 991 | { |
967 | foundDesc = md; | 992 | foundDesc = md; |
968 | ret = true; | 993 | ret = true; |
@@ -974,13 +999,13 @@ public sealed class BSShapeCollection : IDisposable | |||
974 | return ret; | 999 | return ret; |
975 | } | 1000 | } |
976 | 1001 | ||
977 | private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc) | 1002 | private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc) |
978 | { | 1003 | { |
979 | bool ret = false; | 1004 | bool ret = false; |
980 | HullDesc foundDesc = new HullDesc(); | 1005 | HullDesc foundDesc = new HullDesc(); |
981 | foreach (HullDesc hd in Hulls.Values) | 1006 | foreach (HullDesc hd in Hulls.Values) |
982 | { | 1007 | { |
983 | if (hd.ptr == addr) | 1008 | if (hd.shape.ReferenceSame(shape)) |
984 | { | 1009 | { |
985 | foundDesc = hd; | 1010 | foundDesc = hd; |
986 | ret = true; | 1011 | ret = true; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 96cd55e..ee18379 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | |||
@@ -27,24 +27,19 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
31 | using System.Text; | 30 | using System.Text; |
32 | 31 | ||
32 | using OMV = OpenMetaverse; | ||
33 | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | 34 | namespace OpenSim.Region.Physics.BulletSPlugin |
34 | { | 35 | { |
35 | public abstract class BSShape | 36 | public abstract class BSShape |
36 | { | 37 | { |
37 | public IntPtr ptr { get; set; } | ||
38 | public BSPhysicsShapeType type { get; set; } | ||
39 | public System.UInt64 key { get; set; } | ||
40 | public int referenceCount { get; set; } | 38 | public int referenceCount { get; set; } |
41 | public DateTime lastReferenced { get; set; } | 39 | public DateTime lastReferenced { get; set; } |
42 | 40 | ||
43 | public BSShape() | 41 | public BSShape() |
44 | { | 42 | { |
45 | ptr = IntPtr.Zero; | ||
46 | type = BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
47 | key = 0; | ||
48 | referenceCount = 0; | 43 | referenceCount = 0; |
49 | lastReferenced = DateTime.Now; | 44 | lastReferenced = DateTime.Now; |
50 | } | 45 | } |
@@ -63,7 +58,7 @@ public abstract class BSShape | |||
63 | } | 58 | } |
64 | 59 | ||
65 | // Compound shapes are handled special as they are rebuilt from scratch. | 60 | // Compound shapes are handled special as they are rebuilt from scratch. |
66 | // This isn't too great a hardship since most of the child shapes will already been created. | 61 | // This isn't too great a hardship since most of the child shapes will have already been created. |
67 | if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) | 62 | if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) |
68 | { | 63 | { |
69 | // Getting a reference to a compound shape gets you the compound shape with the root prim shape added | 64 | // Getting a reference to a compound shape gets you the compound shape with the root prim shape added |
@@ -71,6 +66,14 @@ public abstract class BSShape | |||
71 | physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret); | 66 | physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret); |
72 | } | 67 | } |
73 | 68 | ||
69 | // Avatars have their own unique shape | ||
70 | if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_AVATAR) | ||
71 | { | ||
72 | // Getting a reference to a compound shape gets you the compound shape with the root prim shape added | ||
73 | ret = BSShapeAvatar.GetReference(prim); | ||
74 | physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,avatarShape,shape={1}", prim.LocalID, ret); | ||
75 | } | ||
76 | |||
74 | if (ret == null) | 77 | if (ret == null) |
75 | ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim); | 78 | ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim); |
76 | 79 | ||
@@ -91,15 +94,17 @@ public abstract class BSShape | |||
91 | // All shapes have a static call to get a reference to the physical shape | 94 | // All shapes have a static call to get a reference to the physical shape |
92 | // protected abstract static BSShape GetReference(); | 95 | // protected abstract static BSShape GetReference(); |
93 | 96 | ||
97 | // Returns a string for debugging that uniquily identifies the memory used by this instance | ||
98 | public virtual string AddrString | ||
99 | { | ||
100 | get { return "unknown"; } | ||
101 | } | ||
102 | |||
94 | public override string ToString() | 103 | public override string ToString() |
95 | { | 104 | { |
96 | StringBuilder buff = new StringBuilder(); | 105 | StringBuilder buff = new StringBuilder(); |
97 | buff.Append("<p="); | 106 | buff.Append("<p="); |
98 | buff.Append(ptr.ToString("X")); | 107 | buff.Append(AddrString); |
99 | buff.Append(",s="); | ||
100 | buff.Append(type.ToString()); | ||
101 | buff.Append(",k="); | ||
102 | buff.Append(key.ToString("X")); | ||
103 | buff.Append(",c="); | 108 | buff.Append(",c="); |
104 | buff.Append(referenceCount.ToString()); | 109 | buff.Append(referenceCount.ToString()); |
105 | buff.Append(">"); | 110 | buff.Append(">"); |
@@ -126,7 +131,8 @@ public class BSShapeNative : BSShape | |||
126 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) | 131 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) |
127 | { | 132 | { |
128 | // Native shapes are not shared and are always built anew. | 133 | // Native shapes are not shared and are always built anew. |
129 | return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); | 134 | //return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); |
135 | return null; | ||
130 | } | 136 | } |
131 | 137 | ||
132 | private BSShapeNative(BSScene physicsScene, BSPhysObject prim, | 138 | private BSShapeNative(BSScene physicsScene, BSPhysObject prim, |
@@ -141,14 +147,15 @@ public class BSShapeNative : BSShape | |||
141 | nativeShapeData.HullKey = (ulong)shapeKey; | 147 | nativeShapeData.HullKey = (ulong)shapeKey; |
142 | 148 | ||
143 | 149 | ||
150 | /* | ||
144 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) | 151 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) |
145 | { | 152 | { |
146 | ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); | 153 | ptr = PhysicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale); |
147 | physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); | 154 | physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); |
148 | } | 155 | } |
149 | else | 156 | else |
150 | { | 157 | { |
151 | ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData); | 158 | ptr = PhysicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData); |
152 | } | 159 | } |
153 | if (ptr == IntPtr.Zero) | 160 | if (ptr == IntPtr.Zero) |
154 | { | 161 | { |
@@ -157,15 +164,18 @@ public class BSShapeNative : BSShape | |||
157 | } | 164 | } |
158 | type = shapeType; | 165 | type = shapeType; |
159 | key = (UInt64)shapeKey; | 166 | key = (UInt64)shapeKey; |
167 | */ | ||
160 | } | 168 | } |
161 | // Make this reference to the physical shape go away since native shapes are not shared. | 169 | // Make this reference to the physical shape go away since native shapes are not shared. |
162 | public override void Dereference(BSScene physicsScene) | 170 | public override void Dereference(BSScene physicsScene) |
163 | { | 171 | { |
172 | /* | ||
164 | // Native shapes are not tracked and are released immediately | 173 | // Native shapes are not tracked and are released immediately |
165 | physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); | 174 | physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); |
166 | BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr); | 175 | PhysicsScene.PE.DeleteCollisionShape(physicsScene.World, this); |
167 | ptr = IntPtr.Zero; | 176 | ptr = IntPtr.Zero; |
168 | // Garbage collection will free up this instance. | 177 | // Garbage collection will free up this instance. |
178 | */ | ||
169 | } | 179 | } |
170 | } | 180 | } |
171 | 181 | ||
@@ -205,4 +215,143 @@ public class BSShapeCompound : BSShape | |||
205 | } | 215 | } |
206 | public override void Dereference(BSScene physicsScene) { } | 216 | public override void Dereference(BSScene physicsScene) { } |
207 | } | 217 | } |
218 | |||
219 | public class BSShapeAvatar : BSShape | ||
220 | { | ||
221 | private static string LogHeader = "[BULLETSIM SHAPE AVATAR]"; | ||
222 | public BSShapeAvatar() : base() | ||
223 | { | ||
224 | } | ||
225 | public static BSShape GetReference(BSPhysObject prim) | ||
226 | { | ||
227 | return new BSShapeNull(); | ||
228 | } | ||
229 | public override void Dereference(BSScene physicsScene) { } | ||
230 | |||
231 | // From the front: | ||
232 | // A---A | ||
233 | // / \ | ||
234 | // B-------B | ||
235 | // / \ +Z | ||
236 | // C-----------C | | ||
237 | // \ / -Y --+-- +Y | ||
238 | // \ / | | ||
239 | // \ / -Z | ||
240 | // D-----D | ||
241 | // \ / | ||
242 | // E-E | ||
243 | |||
244 | // From the top A and E are just lines. | ||
245 | // B, C and D are hexagons: | ||
246 | // | ||
247 | // C1--C2 +X | ||
248 | // / \ | | ||
249 | // C0 C3 -Y --+-- +Y | ||
250 | // \ / | | ||
251 | // C5--C4 -X | ||
252 | |||
253 | // Zero goes directly through the middle so the offsets are from that middle axis | ||
254 | // and up and down from a middle horizon (A and E are the same distance from the zero). | ||
255 | // The height, width and depth is one. All scaling is done by the simulator. | ||
256 | |||
257 | // Z component -- how far the level is from the middle zero | ||
258 | private const float Aup = 0.5f; | ||
259 | private const float Bup = 0.4f; | ||
260 | private const float Cup = 0.3f; | ||
261 | private const float Dup = -0.4f; | ||
262 | private const float Eup = -0.5f; | ||
263 | |||
264 | // Y component -- distance from center to x0 and x3 | ||
265 | private const float Awid = 0.25f; | ||
266 | private const float Bwid = 0.3f; | ||
267 | private const float Cwid = 0.5f; | ||
268 | private const float Dwid = 0.3f; | ||
269 | private const float Ewid = 0.2f; | ||
270 | |||
271 | // Y component -- distance from center to x1, x2, x4 and x5 | ||
272 | private const float Afwid = 0.0f; | ||
273 | private const float Bfwid = 0.2f; | ||
274 | private const float Cfwid = 0.4f; | ||
275 | private const float Dfwid = 0.2f; | ||
276 | private const float Efwid = 0.0f; | ||
277 | |||
278 | // X component -- distance from zero to the front or back of a level | ||
279 | private const float Adep = 0f; | ||
280 | private const float Bdep = 0.3f; | ||
281 | private const float Cdep = 0.5f; | ||
282 | private const float Ddep = 0.2f; | ||
283 | private const float Edep = 0f; | ||
284 | |||
285 | private OMV.Vector3[] avatarVertices = { | ||
286 | new OMV.Vector3( 0.0f, -Awid, Aup), // A0 | ||
287 | new OMV.Vector3( 0.0f, +Awid, Aup), // A3 | ||
288 | |||
289 | new OMV.Vector3( 0.0f, -Bwid, Bup), // B0 | ||
290 | new OMV.Vector3(+Bdep, -Bfwid, Bup), // B1 | ||
291 | new OMV.Vector3(+Bdep, +Bfwid, Bup), // B2 | ||
292 | new OMV.Vector3( 0.0f, +Bwid, Bup), // B3 | ||
293 | new OMV.Vector3(-Bdep, +Bfwid, Bup), // B4 | ||
294 | new OMV.Vector3(-Bdep, -Bfwid, Bup), // B5 | ||
295 | |||
296 | new OMV.Vector3( 0.0f, -Cwid, Cup), // C0 | ||
297 | new OMV.Vector3(+Cdep, -Cfwid, Cup), // C1 | ||
298 | new OMV.Vector3(+Cdep, +Cfwid, Cup), // C2 | ||
299 | new OMV.Vector3( 0.0f, +Cwid, Cup), // C3 | ||
300 | new OMV.Vector3(-Cdep, +Cfwid, Cup), // C4 | ||
301 | new OMV.Vector3(-Cdep, -Cfwid, Cup), // C5 | ||
302 | |||
303 | new OMV.Vector3( 0.0f, -Dwid, Dup), // D0 | ||
304 | new OMV.Vector3(+Ddep, -Dfwid, Dup), // D1 | ||
305 | new OMV.Vector3(+Ddep, +Dfwid, Dup), // D2 | ||
306 | new OMV.Vector3( 0.0f, +Dwid, Dup), // D3 | ||
307 | new OMV.Vector3(-Ddep, +Dfwid, Dup), // D4 | ||
308 | new OMV.Vector3(-Ddep, -Dfwid, Dup), // D5 | ||
309 | |||
310 | new OMV.Vector3( 0.0f, -Ewid, Eup), // E0 | ||
311 | new OMV.Vector3( 0.0f, +Ewid, Eup), // E3 | ||
312 | }; | ||
313 | |||
314 | // Offsets of the vertices in the vertices array | ||
315 | private enum Ind : int | ||
316 | { | ||
317 | A0, A3, | ||
318 | B0, B1, B2, B3, B4, B5, | ||
319 | C0, C1, C2, C3, C4, C5, | ||
320 | D0, D1, D2, D3, D4, D5, | ||
321 | E0, E3 | ||
322 | } | ||
323 | |||
324 | // Comments specify trianges and quads in clockwise direction | ||
325 | private Ind[] avatarIndices = { | ||
326 | Ind.A0, Ind.B0, Ind.B1, // A0,B0,B1 | ||
327 | Ind.A0, Ind.B1, Ind.B2, Ind.B2, Ind.A3, Ind.A0, // A0,B1,B2,A3 | ||
328 | Ind.A3, Ind.B2, Ind.B3, // A3,B2,B3 | ||
329 | Ind.A3, Ind.B3, Ind.B4, // A3,B3,B4 | ||
330 | Ind.A3, Ind.B4, Ind.B5, Ind.B5, Ind.A0, Ind.A3, // A3,B4,B5,A0 | ||
331 | Ind.A0, Ind.B5, Ind.B0, // A0,B5,B0 | ||
332 | |||
333 | Ind.B0, Ind.C0, Ind.C1, Ind.C1, Ind.B1, Ind.B0, // B0,C0,C1,B1 | ||
334 | Ind.B1, Ind.C1, Ind.C2, Ind.C2, Ind.B2, Ind.B1, // B1,C1,C2,B2 | ||
335 | Ind.B2, Ind.C2, Ind.C3, Ind.C3, Ind.B3, Ind.B2, // B2,C2,C3,B3 | ||
336 | Ind.B3, Ind.C3, Ind.C4, Ind.C4, Ind.B4, Ind.B3, // B3,C3,C4,B4 | ||
337 | Ind.B4, Ind.C4, Ind.C5, Ind.C5, Ind.B5, Ind.B4, // B4,C4,C5,B5 | ||
338 | Ind.B5, Ind.C5, Ind.C0, Ind.C0, Ind.B0, Ind.B5, // B5,C5,C0,B0 | ||
339 | |||
340 | Ind.C0, Ind.D0, Ind.D1, Ind.D1, Ind.C1, Ind.C0, // C0,D0,D1,C1 | ||
341 | Ind.C1, Ind.D1, Ind.D2, Ind.D2, Ind.C2, Ind.C1, // C1,D1,D2,C2 | ||
342 | Ind.C2, Ind.D2, Ind.D3, Ind.D3, Ind.C3, Ind.C2, // C2,D2,D3,C3 | ||
343 | Ind.C3, Ind.D3, Ind.D4, Ind.D4, Ind.C4, Ind.C3, // C3,D3,D4,C4 | ||
344 | Ind.C4, Ind.D4, Ind.D5, Ind.D5, Ind.C5, Ind.C4, // C4,D4,D5,C5 | ||
345 | Ind.C5, Ind.D5, Ind.D0, Ind.D0, Ind.C0, Ind.C5, // C5,D5,D0,C0 | ||
346 | |||
347 | Ind.E0, Ind.D0, Ind.D1, // E0,D0,D1 | ||
348 | Ind.E0, Ind.D1, Ind.D2, Ind.D2, Ind.E3, Ind.E0, // E0,D1,D2,E3 | ||
349 | Ind.E3, Ind.D2, Ind.D3, // E3,D2,D3 | ||
350 | Ind.E3, Ind.D3, Ind.D4, // E3,D3,D4 | ||
351 | Ind.E3, Ind.D4, Ind.D5, Ind.D5, Ind.E0, Ind.E3, // E3,D4,D5,E0 | ||
352 | Ind.E0, Ind.D5, Ind.D0, // E0,D5,D0 | ||
353 | |||
354 | }; | ||
355 | |||
356 | } | ||
208 | } | 357 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 3ca756c..e4fecc3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |||
@@ -44,7 +44,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
44 | { | 44 | { |
45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; | 45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; |
46 | 46 | ||
47 | BulletHeightMapInfo m_mapInfo = null; | 47 | BulletHMapInfo m_mapInfo = null; |
48 | 48 | ||
49 | // Constructor to build a default, flat heightmap terrain. | 49 | // Constructor to build a default, flat heightmap terrain. |
50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) | 50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) |
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
58 | { | 58 | { |
59 | initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; | 59 | initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; |
60 | } | 60 | } |
61 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 61 | m_mapInfo = new BulletHMapInfo(id, initialMap); |
62 | m_mapInfo.minCoords = minTerrainCoords; | 62 | m_mapInfo.minCoords = minTerrainCoords; |
63 | m_mapInfo.maxCoords = maxTerrainCoords; | 63 | m_mapInfo.maxCoords = maxTerrainCoords; |
64 | m_mapInfo.terrainRegionBase = TerrainBase; | 64 | m_mapInfo.terrainRegionBase = TerrainBase; |
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
72 | Vector3 minCoords, Vector3 maxCoords) | 72 | Vector3 minCoords, Vector3 maxCoords) |
73 | : base(physicsScene, regionBase, id) | 73 | : base(physicsScene, regionBase, id) |
74 | { | 74 | { |
75 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 75 | m_mapInfo = new BulletHMapInfo(id, initialMap); |
76 | m_mapInfo.minCoords = minCoords; | 76 | m_mapInfo.minCoords = minCoords; |
77 | m_mapInfo.maxCoords = maxCoords; | 77 | m_mapInfo.maxCoords = maxCoords; |
78 | m_mapInfo.minZ = minCoords.Z; | 78 | m_mapInfo.minZ = minCoords.Z; |
@@ -91,13 +91,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
91 | // Using the information in m_mapInfo, create the physical representation of the heightmap. | 91 | // Using the information in m_mapInfo, create the physical representation of the heightmap. |
92 | private void BuildHeightmapTerrain() | 92 | private void BuildHeightmapTerrain() |
93 | { | 93 | { |
94 | m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID, | ||
95 | m_mapInfo.minCoords, m_mapInfo.maxCoords, | ||
96 | m_mapInfo.heightMap, BSTerrainManager.TERRAIN_COLLISION_MARGIN); | ||
97 | |||
98 | // Create the terrain shape from the mapInfo | 94 | // Create the terrain shape from the mapInfo |
99 | m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr), | 95 | m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID, |
100 | BSPhysicsShapeType.SHAPE_TERRAIN); | 96 | new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, |
97 | m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); | ||
98 | |||
101 | 99 | ||
102 | // The terrain object initial position is at the center of the object | 100 | // The terrain object initial position is at the center of the object |
103 | Vector3 centerPos; | 101 | Vector3 centerPos; |
@@ -105,28 +103,26 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
105 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); | 103 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); |
106 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); | 104 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); |
107 | 105 | ||
108 | m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, | 106 | m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, |
109 | BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, | 107 | m_mapInfo.ID, centerPos, Quaternion.Identity); |
110 | m_mapInfo.ID, centerPos, Quaternion.Identity)); | ||
111 | 108 | ||
112 | // Set current terrain attributes | 109 | // Set current terrain attributes |
113 | BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainFriction); | 110 | PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); |
114 | BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | 111 | PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); |
115 | BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainRestitution); | 112 | PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); |
116 | BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 113 | PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); |
117 | 114 | ||
118 | // Return the new terrain to the world of physical objects | 115 | // Return the new terrain to the world of physical objects |
119 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 116 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody); |
120 | 117 | ||
121 | // redo its bounding box now that it is in the world | 118 | // redo its bounding box now that it is in the world |
122 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 119 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); |
123 | 120 | ||
124 | BulletSimAPI.SetCollisionFilterMask2(m_mapInfo.terrainBody.ptr, | 121 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; |
125 | (uint)CollisionFilterGroups.TerrainFilter, | 122 | m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene); |
126 | (uint)CollisionFilterGroups.TerrainMask); | ||
127 | 123 | ||
128 | // Make it so the terrain will not move or be considered for movement. | 124 | // Make it so the terrain will not move or be considered for movement. |
129 | BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | 125 | PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); |
130 | 126 | ||
131 | return; | 127 | return; |
132 | } | 128 | } |
@@ -136,19 +132,18 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
136 | { | 132 | { |
137 | if (m_mapInfo != null) | 133 | if (m_mapInfo != null) |
138 | { | 134 | { |
139 | if (m_mapInfo.terrainBody.ptr != IntPtr.Zero) | 135 | if (m_mapInfo.terrainBody.HasPhysicalBody) |
140 | { | 136 | { |
141 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 137 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); |
142 | // Frees both the body and the shape. | 138 | // Frees both the body and the shape. |
143 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 139 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); |
144 | BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); | ||
145 | } | 140 | } |
146 | } | 141 | } |
147 | m_mapInfo = null; | 142 | m_mapInfo = null; |
148 | } | 143 | } |
149 | 144 | ||
150 | // The passed position is relative to the base of the region. | 145 | // The passed position is relative to the base of the region. |
151 | public override float GetHeightAtXYZ(Vector3 pos) | 146 | public override float GetTerrainHeightAtXYZ(Vector3 pos) |
152 | { | 147 | { |
153 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | 148 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; |
154 | 149 | ||
@@ -166,5 +161,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
166 | } | 161 | } |
167 | return ret; | 162 | return ret; |
168 | } | 163 | } |
164 | |||
165 | // The passed position is relative to the base of the region. | ||
166 | public override float GetWaterLevelAtXYZ(Vector3 pos) | ||
167 | { | ||
168 | return PhysicsScene.SimpleWaterLevel; | ||
169 | } | ||
169 | } | 170 | } |
170 | } | 171 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 23fcfd3..2e9db39 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |||
@@ -62,11 +62,12 @@ public abstract class BSTerrainPhys : IDisposable | |||
62 | ID = id; | 62 | ID = id; |
63 | } | 63 | } |
64 | public abstract void Dispose(); | 64 | public abstract void Dispose(); |
65 | public abstract float GetHeightAtXYZ(Vector3 pos); | 65 | public abstract float GetTerrainHeightAtXYZ(Vector3 pos); |
66 | public abstract float GetWaterLevelAtXYZ(Vector3 pos); | ||
66 | } | 67 | } |
67 | 68 | ||
68 | // ========================================================================================== | 69 | // ========================================================================================== |
69 | public sealed class BSTerrainManager | 70 | public sealed class BSTerrainManager : IDisposable |
70 | { | 71 | { |
71 | static string LogHeader = "[BULLETSIM TERRAIN MANAGER]"; | 72 | static string LogHeader = "[BULLETSIM TERRAIN MANAGER]"; |
72 | 73 | ||
@@ -75,13 +76,12 @@ public sealed class BSTerrainManager | |||
75 | public const float HEIGHT_INITIALIZATION = 24.987f; | 76 | public const float HEIGHT_INITIALIZATION = 24.987f; |
76 | public const float HEIGHT_INITIAL_LASTHEIGHT = 24.876f; | 77 | public const float HEIGHT_INITIAL_LASTHEIGHT = 24.876f; |
77 | public const float HEIGHT_GETHEIGHT_RET = 24.765f; | 78 | public const float HEIGHT_GETHEIGHT_RET = 24.765f; |
79 | public const float WATER_HEIGHT_GETHEIGHT_RET = 19.998f; | ||
78 | 80 | ||
79 | // If the min and max height are equal, we reduce the min by this | 81 | // If the min and max height are equal, we reduce the min by this |
80 | // amount to make sure that a bounding box is built for the terrain. | 82 | // amount to make sure that a bounding box is built for the terrain. |
81 | public const float HEIGHT_EQUAL_FUDGE = 0.2f; | 83 | public const float HEIGHT_EQUAL_FUDGE = 0.2f; |
82 | 84 | ||
83 | public const float TERRAIN_COLLISION_MARGIN = 0.0f; | ||
84 | |||
85 | // Until the whole simulator is changed to pass us the region size, we rely on constants. | 85 | // Until the whole simulator is changed to pass us the region size, we rely on constants. |
86 | public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 86 | public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
87 | 87 | ||
@@ -122,25 +122,28 @@ public sealed class BSTerrainManager | |||
122 | MegaRegionParentPhysicsScene = null; | 122 | MegaRegionParentPhysicsScene = null; |
123 | } | 123 | } |
124 | 124 | ||
125 | public void Dispose() | ||
126 | { | ||
127 | ReleaseGroundPlaneAndTerrain(); | ||
128 | } | ||
129 | |||
125 | // Create the initial instance of terrain and the underlying ground plane. | 130 | // Create the initial instance of terrain and the underlying ground plane. |
126 | // This is called from the initialization routine so we presume it is | 131 | // This is called from the initialization routine so we presume it is |
127 | // safe to call Bullet in real time. We hope no one is moving prims around yet. | 132 | // safe to call Bullet in real time. We hope no one is moving prims around yet. |
128 | public void CreateInitialGroundPlaneAndTerrain() | 133 | public void CreateInitialGroundPlaneAndTerrain() |
129 | { | 134 | { |
130 | // The ground plane is here to catch things that are trying to drop to negative infinity | 135 | // The ground plane is here to catch things that are trying to drop to negative infinity |
131 | BulletShape groundPlaneShape = new BulletShape( | 136 | BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin); |
132 | BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, TERRAIN_COLLISION_MARGIN), | 137 | m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, |
133 | BSPhysicsShapeType.SHAPE_GROUNDPLANE); | 138 | BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity); |
134 | m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, | 139 | |
135 | BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, | 140 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane); |
136 | Vector3.Zero, Quaternion.Identity)); | 141 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane); |
137 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr); | ||
138 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr); | ||
139 | // Ground plane does not move | 142 | // Ground plane does not move |
140 | BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); | 143 | PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION); |
141 | // Everything collides with the ground plane. | 144 | // Everything collides with the ground plane. |
142 | BulletSimAPI.SetCollisionFilterMask2(m_groundPlane.ptr, | 145 | m_groundPlane.collisionType = CollisionType.Groundplane; |
143 | (uint)CollisionFilterGroups.GroundPlaneFilter, (uint)CollisionFilterGroups.GroundPlaneMask); | 146 | m_groundPlane.ApplyCollisionMask(PhysicsScene); |
144 | 147 | ||
145 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. | 148 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. |
146 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); | 149 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); |
@@ -150,13 +153,13 @@ public sealed class BSTerrainManager | |||
150 | // Release all the terrain structures we might have allocated | 153 | // Release all the terrain structures we might have allocated |
151 | public void ReleaseGroundPlaneAndTerrain() | 154 | public void ReleaseGroundPlaneAndTerrain() |
152 | { | 155 | { |
153 | if (m_groundPlane.ptr != IntPtr.Zero) | 156 | if (m_groundPlane.HasPhysicalBody) |
154 | { | 157 | { |
155 | if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr)) | 158 | if (PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_groundPlane)) |
156 | { | 159 | { |
157 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr); | 160 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane); |
158 | } | 161 | } |
159 | m_groundPlane.ptr = IntPtr.Zero; | 162 | m_groundPlane.Clear(); |
160 | } | 163 | } |
161 | 164 | ||
162 | ReleaseTerrain(); | 165 | ReleaseTerrain(); |
@@ -165,17 +168,22 @@ public sealed class BSTerrainManager | |||
165 | // Release all the terrain we have allocated | 168 | // Release all the terrain we have allocated |
166 | public void ReleaseTerrain() | 169 | public void ReleaseTerrain() |
167 | { | 170 | { |
168 | foreach (KeyValuePair<Vector3, BSTerrainPhys> kvp in m_terrains) | 171 | lock (m_terrains) |
169 | { | 172 | { |
170 | kvp.Value.Dispose(); | 173 | foreach (KeyValuePair<Vector3, BSTerrainPhys> kvp in m_terrains) |
174 | { | ||
175 | kvp.Value.Dispose(); | ||
176 | } | ||
177 | m_terrains.Clear(); | ||
171 | } | 178 | } |
172 | m_terrains.Clear(); | ||
173 | } | 179 | } |
174 | 180 | ||
175 | // The simulator wants to set a new heightmap for the terrain. | 181 | // The simulator wants to set a new heightmap for the terrain. |
176 | public void SetTerrain(float[] heightMap) { | 182 | public void SetTerrain(float[] heightMap) { |
177 | float[] localHeightMap = heightMap; | 183 | float[] localHeightMap = heightMap; |
178 | PhysicsScene.TaintedObject("TerrainManager.SetTerrain", delegate() | 184 | // If there are multiple requests for changes to the same terrain between ticks, |
185 | // only do that last one. | ||
186 | PhysicsScene.PostTaintObject("TerrainManager.SetTerrain-"+ m_worldOffset.ToString(), 0, delegate() | ||
179 | { | 187 | { |
180 | if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null) | 188 | if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null) |
181 | { | 189 | { |
@@ -211,6 +219,7 @@ public sealed class BSTerrainManager | |||
211 | // terrain shape is created and added to the body. | 219 | // terrain shape is created and added to the body. |
212 | // This call is most often used to update the heightMap and parameters of the terrain. | 220 | // This call is most often used to update the heightMap and parameters of the terrain. |
213 | // (The above does suggest that some simplification/refactoring is in order.) | 221 | // (The above does suggest that some simplification/refactoring is in order.) |
222 | // Called during taint-time. | ||
214 | private void UpdateTerrain(uint id, float[] heightMap, | 223 | private void UpdateTerrain(uint id, float[] heightMap, |
215 | Vector3 minCoords, Vector3 maxCoords, bool inTaintTime) | 224 | Vector3 minCoords, Vector3 maxCoords, bool inTaintTime) |
216 | { | 225 | { |
@@ -220,7 +229,7 @@ public sealed class BSTerrainManager | |||
220 | // Find high and low points of passed heightmap. | 229 | // Find high and low points of passed heightmap. |
221 | // The min and max passed in is usually the area objects can be in (maximum | 230 | // The min and max passed in is usually the area objects can be in (maximum |
222 | // object height, for instance). The terrain wants the bounding box for the | 231 | // object height, for instance). The terrain wants the bounding box for the |
223 | // terrain so we replace passed min and max Z with the actual terrain min/max Z. | 232 | // terrain so replace passed min and max Z with the actual terrain min/max Z. |
224 | float minZ = float.MaxValue; | 233 | float minZ = float.MaxValue; |
225 | float maxZ = float.MinValue; | 234 | float maxZ = float.MinValue; |
226 | foreach (float height in heightMap) | 235 | foreach (float height in heightMap) |
@@ -238,15 +247,15 @@ public sealed class BSTerrainManager | |||
238 | 247 | ||
239 | Vector3 terrainRegionBase = new Vector3(minCoords.X, minCoords.Y, 0f); | 248 | Vector3 terrainRegionBase = new Vector3(minCoords.X, minCoords.Y, 0f); |
240 | 249 | ||
241 | BSTerrainPhys terrainPhys; | 250 | lock (m_terrains) |
242 | if (m_terrains.TryGetValue(terrainRegionBase, out terrainPhys)) | ||
243 | { | 251 | { |
244 | // There is already a terrain in this spot. Free the old and build the new. | 252 | BSTerrainPhys terrainPhys; |
245 | DetailLog("{0},UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}", | 253 | if (m_terrains.TryGetValue(terrainRegionBase, out terrainPhys)) |
246 | BSScene.DetailLogZero, id, terrainRegionBase, minCoords, minCoords); | ||
247 | |||
248 | PhysicsScene.TaintedObject(inTaintTime, "BSScene.UpdateTerrain:UpdateExisting", delegate() | ||
249 | { | 254 | { |
255 | // There is already a terrain in this spot. Free the old and build the new. | ||
256 | DetailLog("{0},UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}", | ||
257 | BSScene.DetailLogZero, id, terrainRegionBase, minCoords, minCoords); | ||
258 | |||
250 | // Remove old terrain from the collection | 259 | // Remove old terrain from the collection |
251 | m_terrains.Remove(terrainRegionBase); | 260 | m_terrains.Remove(terrainRegionBase); |
252 | // Release any physical memory it may be using. | 261 | // Release any physical memory it may be using. |
@@ -271,35 +280,24 @@ public sealed class BSTerrainManager | |||
271 | // I hate doing this, but just bail | 280 | // I hate doing this, but just bail |
272 | return; | 281 | return; |
273 | } | 282 | } |
274 | }); | 283 | } |
275 | } | 284 | else |
276 | else | 285 | { |
277 | { | 286 | // We don't know about this terrain so either we are creating a new terrain or |
278 | // We don't know about this terrain so either we are creating a new terrain or | 287 | // our mega-prim child is giving us a new terrain to add to the phys world |
279 | // our mega-prim child is giving us a new terrain to add to the phys world | ||
280 | |||
281 | // if this is a child terrain, calculate a unique terrain id | ||
282 | uint newTerrainID = id; | ||
283 | if (newTerrainID >= BSScene.CHILDTERRAIN_ID) | ||
284 | newTerrainID = ++m_terrainCount; | ||
285 | |||
286 | float[] heightMapX = heightMap; | ||
287 | Vector3 minCoordsX = minCoords; | ||
288 | Vector3 maxCoordsX = maxCoords; | ||
289 | 288 | ||
290 | DetailLog("{0},UpdateTerrain:NewTerrain,call,id={1}, minC={2}, maxC={3}", | 289 | // if this is a child terrain, calculate a unique terrain id |
291 | BSScene.DetailLogZero, newTerrainID, minCoords, minCoords); | 290 | uint newTerrainID = id; |
291 | if (newTerrainID >= BSScene.CHILDTERRAIN_ID) | ||
292 | newTerrainID = ++m_terrainCount; | ||
292 | 293 | ||
293 | // Code that must happen at taint-time | 294 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,newID={1},minCoord={2},maxCoord={3}", |
294 | PhysicsScene.TaintedObject(inTaintTime, "BSScene.UpdateTerrain:NewTerrain", delegate() | 295 | BSScene.DetailLogZero, newTerrainID, minCoords, minCoords); |
295 | { | ||
296 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}", | ||
297 | BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y); | ||
298 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); | 296 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); |
299 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 297 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
300 | 298 | ||
301 | m_terrainModified = true; | 299 | m_terrainModified = true; |
302 | }); | 300 | } |
303 | } | 301 | } |
304 | } | 302 | } |
305 | 303 | ||
@@ -308,9 +306,9 @@ public sealed class BSTerrainManager | |||
308 | { | 306 | { |
309 | PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", | 307 | PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", |
310 | LogHeader, PhysicsScene.RegionName, terrainRegionBase, | 308 | LogHeader, PhysicsScene.RegionName, terrainRegionBase, |
311 | (BSTerrainPhys.TerrainImplementation)PhysicsScene.Params.terrainImplementation); | 309 | (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation); |
312 | BSTerrainPhys newTerrainPhys = null; | 310 | BSTerrainPhys newTerrainPhys = null; |
313 | switch ((int)PhysicsScene.Params.terrainImplementation) | 311 | switch ((int)BSParam.TerrainImplementation) |
314 | { | 312 | { |
315 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: | 313 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: |
316 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, | 314 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, |
@@ -323,14 +321,21 @@ public sealed class BSTerrainManager | |||
323 | default: | 321 | default: |
324 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}", | 322 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}", |
325 | LogHeader, | 323 | LogHeader, |
326 | (int)PhysicsScene.Params.terrainImplementation, | 324 | (int)BSParam.TerrainImplementation, |
327 | PhysicsScene.Params.terrainImplementation, | 325 | BSParam.TerrainImplementation, |
328 | PhysicsScene.RegionName, terrainRegionBase); | 326 | PhysicsScene.RegionName, terrainRegionBase); |
329 | break; | 327 | break; |
330 | } | 328 | } |
331 | return newTerrainPhys; | 329 | return newTerrainPhys; |
332 | } | 330 | } |
333 | 331 | ||
332 | // Return 'true' of this position is somewhere in known physical terrain space | ||
333 | public bool IsWithinKnownTerrain(Vector3 pos) | ||
334 | { | ||
335 | Vector3 terrainBaseXYZ; | ||
336 | BSTerrainPhys physTerrain; | ||
337 | return GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ); | ||
338 | } | ||
334 | 339 | ||
335 | // Given an X and Y, find the height of the terrain. | 340 | // Given an X and Y, find the height of the terrain. |
336 | // Since we could be handling multiple terrains for a mega-region, | 341 | // Since we could be handling multiple terrains for a mega-region, |
@@ -341,40 +346,74 @@ public sealed class BSTerrainManager | |||
341 | private float lastHeightTX = 999999f; | 346 | private float lastHeightTX = 999999f; |
342 | private float lastHeightTY = 999999f; | 347 | private float lastHeightTY = 999999f; |
343 | private float lastHeight = HEIGHT_INITIAL_LASTHEIGHT; | 348 | private float lastHeight = HEIGHT_INITIAL_LASTHEIGHT; |
344 | public float GetTerrainHeightAtXYZ(Vector3 loc) | 349 | public float GetTerrainHeightAtXYZ(Vector3 pos) |
345 | { | 350 | { |
346 | float tX = loc.X; | 351 | float tX = pos.X; |
347 | float tY = loc.Y; | 352 | float tY = pos.Y; |
348 | // You'd be surprized at the number of times this routine is called | 353 | // You'd be surprized at the number of times this routine is called |
349 | // with the same parameters as last time. | 354 | // with the same parameters as last time. |
350 | if (!m_terrainModified && lastHeightTX == tX && lastHeightTY == tY) | 355 | if (!m_terrainModified && (lastHeightTX == tX) && (lastHeightTY == tY)) |
351 | return lastHeight; | 356 | return lastHeight; |
357 | m_terrainModified = false; | ||
352 | 358 | ||
353 | lastHeightTX = tX; | 359 | lastHeightTX = tX; |
354 | lastHeightTY = tY; | 360 | lastHeightTY = tY; |
355 | float ret = HEIGHT_GETHEIGHT_RET; | 361 | float ret = HEIGHT_GETHEIGHT_RET; |
356 | 362 | ||
357 | int offsetX = ((int)(tX / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X; | 363 | Vector3 terrainBaseXYZ; |
358 | int offsetY = ((int)(tY / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y; | ||
359 | Vector3 terrainBaseXYZ = new Vector3(offsetX, offsetY, 0f); | ||
360 | |||
361 | BSTerrainPhys physTerrain; | 364 | BSTerrainPhys physTerrain; |
362 | if (m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain)) | 365 | if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ)) |
363 | { | 366 | { |
364 | ret = physTerrain.GetHeightAtXYZ(loc - terrainBaseXYZ); | 367 | ret = physTerrain.GetTerrainHeightAtXYZ(pos - terrainBaseXYZ); |
365 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,loc={1},base={2},height={3}", | ||
366 | BSScene.DetailLogZero, loc, terrainBaseXYZ, ret); | ||
367 | } | 368 | } |
368 | else | 369 | else |
369 | { | 370 | { |
370 | PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}", | 371 | PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}", |
371 | LogHeader, PhysicsScene.RegionName, tX, tY); | 372 | LogHeader, PhysicsScene.RegionName, tX, tY); |
373 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}", | ||
374 | BSScene.DetailLogZero, pos, terrainBaseXYZ); | ||
372 | } | 375 | } |
373 | m_terrainModified = false; | 376 | |
374 | lastHeight = ret; | 377 | lastHeight = ret; |
375 | return ret; | 378 | return ret; |
376 | } | 379 | } |
377 | 380 | ||
381 | public float GetWaterLevelAtXYZ(Vector3 pos) | ||
382 | { | ||
383 | float ret = WATER_HEIGHT_GETHEIGHT_RET; | ||
384 | |||
385 | Vector3 terrainBaseXYZ; | ||
386 | BSTerrainPhys physTerrain; | ||
387 | if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ)) | ||
388 | { | ||
389 | ret = physTerrain.GetWaterLevelAtXYZ(pos); | ||
390 | } | ||
391 | else | ||
392 | { | ||
393 | PhysicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: pos={1}, terrainBase={2}, height={3}", | ||
394 | LogHeader, PhysicsScene.RegionName, pos, terrainBaseXYZ, ret); | ||
395 | } | ||
396 | return ret; | ||
397 | } | ||
398 | |||
399 | // Given an address, return 'true' of there is a description of that terrain and output | ||
400 | // the descriptor class and the 'base' fo the addresses therein. | ||
401 | private bool GetTerrainPhysicalAtXYZ(Vector3 pos, out BSTerrainPhys outPhysTerrain, out Vector3 outTerrainBase) | ||
402 | { | ||
403 | int offsetX = ((int)(pos.X / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X; | ||
404 | int offsetY = ((int)(pos.Y / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y; | ||
405 | Vector3 terrainBaseXYZ = new Vector3(offsetX, offsetY, 0f); | ||
406 | |||
407 | BSTerrainPhys physTerrain = null; | ||
408 | lock (m_terrains) | ||
409 | { | ||
410 | m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain); | ||
411 | } | ||
412 | outTerrainBase = terrainBaseXYZ; | ||
413 | outPhysTerrain = physTerrain; | ||
414 | return (physTerrain != null); | ||
415 | } | ||
416 | |||
378 | // Although no one seems to check this, I do support combining. | 417 | // Although no one seems to check this, I do support combining. |
379 | public bool SupportsCombining() | 418 | public bool SupportsCombining() |
380 | { | 419 | { |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index dca7150..8244f02 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -88,11 +88,11 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
88 | // Something is very messed up and a crash is in our future. | 88 | // Something is very messed up and a crash is in our future. |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}", | ||
92 | ID, indicesCount, indices.Length, verticesCount, vertices.Length); | ||
91 | 93 | ||
92 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | 94 | m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount, vertices); |
93 | indicesCount, indices, verticesCount, vertices), | 95 | if (!m_terrainShape.HasPhysicalShape) |
94 | BSPhysicsShapeType.SHAPE_MESH); | ||
95 | if (m_terrainShape.ptr == IntPtr.Zero) | ||
96 | { | 96 | { |
97 | // DISASTER!! | 97 | // DISASTER!! |
98 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape", ID); | 98 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape", ID); |
@@ -104,8 +104,8 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
104 | Vector3 pos = regionBase; | 104 | Vector3 pos = regionBase; |
105 | Quaternion rot = Quaternion.Identity; | 105 | Quaternion rot = Quaternion.Identity; |
106 | 106 | ||
107 | m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot)); | 107 | m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot); |
108 | if (m_terrainBody.ptr == IntPtr.Zero) | 108 | if (!m_terrainBody.HasPhysicalBody) |
109 | { | 109 | { |
110 | // DISASTER!! | 110 | // DISASTER!! |
111 | physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); | 111 | physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); |
@@ -114,39 +114,40 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
114 | } | 114 | } |
115 | 115 | ||
116 | // Set current terrain attributes | 116 | // Set current terrain attributes |
117 | BulletSimAPI.SetFriction2(m_terrainBody.ptr, PhysicsScene.Params.terrainFriction); | 117 | PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction); |
118 | BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | 118 | PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction); |
119 | BulletSimAPI.SetRestitution2(m_terrainBody.ptr, PhysicsScene.Params.terrainRestitution); | 119 | PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution); |
120 | BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 120 | PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); |
121 | 121 | ||
122 | // Static objects are not very massive. | 122 | // Static objects are not very massive. |
123 | BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); | 123 | PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero); |
124 | 124 | ||
125 | // Return the new terrain to the world of physical objects | 125 | // Put the new terrain to the world of physical objects |
126 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 126 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody); |
127 | 127 | ||
128 | // redo its bounding box now that it is in the world | 128 | // Redo its bounding box now that it is in the world |
129 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 129 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody); |
130 | 130 | ||
131 | BulletSimAPI.SetCollisionFilterMask2(m_terrainBody.ptr, | 131 | m_terrainBody.collisionType = CollisionType.Terrain; |
132 | (uint)CollisionFilterGroups.TerrainFilter, | 132 | m_terrainBody.ApplyCollisionMask(PhysicsScene); |
133 | (uint)CollisionFilterGroups.TerrainMask); | ||
134 | 133 | ||
135 | // Make it so the terrain will not move or be considered for movement. | 134 | // Make it so the terrain will not move or be considered for movement. |
136 | BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | 135 | PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION); |
137 | } | 136 | } |
138 | 137 | ||
139 | public override void Dispose() | 138 | public override void Dispose() |
140 | { | 139 | { |
141 | if (m_terrainBody.ptr != IntPtr.Zero) | 140 | if (m_terrainBody.HasPhysicalBody) |
142 | { | 141 | { |
143 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 142 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_terrainBody); |
144 | // Frees both the body and the shape. | 143 | // Frees both the body and the shape. |
145 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 144 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody); |
145 | m_terrainBody.Clear(); | ||
146 | m_terrainShape.Clear(); | ||
146 | } | 147 | } |
147 | } | 148 | } |
148 | 149 | ||
149 | public override float GetHeightAtXYZ(Vector3 pos) | 150 | public override float GetTerrainHeightAtXYZ(Vector3 pos) |
150 | { | 151 | { |
151 | // For the moment use the saved heightmap to get the terrain height. | 152 | // For the moment use the saved heightmap to get the terrain height. |
152 | // TODO: raycast downward to find the true terrain below the position. | 153 | // TODO: raycast downward to find the true terrain below the position. |
@@ -167,6 +168,12 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
167 | return ret; | 168 | return ret; |
168 | } | 169 | } |
169 | 170 | ||
171 | // The passed position is relative to the base of the region. | ||
172 | public override float GetWaterLevelAtXYZ(Vector3 pos) | ||
173 | { | ||
174 | return PhysicsScene.SimpleWaterLevel; | ||
175 | } | ||
176 | |||
170 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). | 177 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). |
171 | // Return 'true' if successfully created. | 178 | // Return 'true' if successfully created. |
172 | public static bool ConvertHeightmapToMesh( | 179 | public static bool ConvertHeightmapToMesh( |
@@ -188,6 +195,11 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
188 | // Simple mesh creation which assumes magnification == 1. | 195 | // Simple mesh creation which assumes magnification == 1. |
189 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. | 196 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. |
190 | 197 | ||
198 | // Create an array of vertices that is sizeX+1 by sizeY+1 (note the loop | ||
199 | // from zero to <= sizeX). The triangle indices are then generated as two triangles | ||
200 | // per heightmap point. There are sizeX by sizeY of these squares. The extra row and | ||
201 | // column of vertices are used to complete the triangles of the last row and column | ||
202 | // of the heightmap. | ||
191 | try | 203 | try |
192 | { | 204 | { |
193 | // One vertice per heightmap value plus the vertices off the top and bottom edge. | 205 | // One vertice per heightmap value plus the vertices off the top and bottom edge. |
@@ -200,16 +212,18 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
200 | float magY = (float)sizeY / extentY; | 212 | float magY = (float)sizeY / extentY; |
201 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}", | 213 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}", |
202 | BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY); | 214 | BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY); |
215 | float minHeight = float.MaxValue; | ||
203 | // Note that sizeX+1 vertices are created since there is land between this and the next region. | 216 | // Note that sizeX+1 vertices are created since there is land between this and the next region. |
204 | for (int yy = 0; yy <= sizeY; yy++) | 217 | for (int yy = 0; yy <= sizeY; yy++) |
205 | { | 218 | { |
206 | for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we got through sizeX + 1 times | 219 | for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we go around sizeX + 1 times |
207 | { | 220 | { |
208 | int offset = yy * sizeX + xx; | 221 | int offset = yy * sizeX + xx; |
209 | // Extend the height from the height from the last row or column | 222 | // Extend the height with the height from the last row or column |
210 | if (yy == sizeY) offset -= sizeX; | 223 | if (yy == sizeY) offset -= sizeX; |
211 | if (xx == sizeX) offset -= 1; | 224 | if (xx == sizeX) offset -= 1; |
212 | float height = heightMap[offset]; | 225 | float height = heightMap[offset]; |
226 | minHeight = Math.Min(minHeight, height); | ||
213 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; | 227 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; |
214 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; | 228 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; |
215 | vertices[verticesCount + 2] = height + extentBase.Z; | 229 | vertices[verticesCount + 2] = height + extentBase.Z; |
@@ -217,14 +231,12 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
217 | } | 231 | } |
218 | } | 232 | } |
219 | verticesCount = verticesCount / 3; | 233 | verticesCount = verticesCount / 3; |
220 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeVerts,verCount={1}", | ||
221 | BSScene.DetailLogZero, verticesCount); | ||
222 | 234 | ||
223 | for (int yy = 0; yy < sizeY; yy++) | 235 | for (int yy = 0; yy < sizeY; yy++) |
224 | { | 236 | { |
225 | for (int xx = 0; xx < sizeX; xx++) | 237 | for (int xx = 0; xx < sizeX; xx++) |
226 | { | 238 | { |
227 | int offset = yy * sizeX + xx; | 239 | int offset = yy * (sizeX + 1) + xx; |
228 | // Each vertices is presumed to be the upper left corner of a box of two triangles | 240 | // Each vertices is presumed to be the upper left corner of a box of two triangles |
229 | indices[indicesCount + 0] = offset; | 241 | indices[indicesCount + 0] = offset; |
230 | indices[indicesCount + 1] = offset + 1; | 242 | indices[indicesCount + 1] = offset + 1; |
@@ -235,8 +247,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
235 | indicesCount += 6; | 247 | indicesCount += 6; |
236 | } | 248 | } |
237 | } | 249 | } |
238 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeIndices,indCount={1}", // DEEBUG DEBUG DEBUG | 250 | |
239 | LogHeader, indicesCount); // DEBUG | ||
240 | ret = true; | 251 | ret = true; |
241 | } | 252 | } |
242 | catch (Exception e) | 253 | catch (Exception e) |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs deleted file mode 100644 index e60a760..0000000 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ /dev/null | |||
@@ -1,1015 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Runtime.InteropServices; | ||
29 | using System.Security; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin { | ||
34 | |||
35 | // Classes to allow some type checking for the API | ||
36 | // These hold pointers to allocated objects in the unmanaged space. | ||
37 | |||
38 | // The physics engine controller class created at initialization | ||
39 | public struct BulletSim | ||
40 | { | ||
41 | public BulletSim(uint worldId, BSScene bss, IntPtr xx) | ||
42 | { | ||
43 | ptr = xx; | ||
44 | worldID = worldId; | ||
45 | physicsScene = bss; | ||
46 | } | ||
47 | public IntPtr ptr; | ||
48 | public uint worldID; | ||
49 | // The scene is only in here so very low level routines have a handle to print debug/error messages | ||
50 | public BSScene physicsScene; | ||
51 | } | ||
52 | |||
53 | // An allocated Bullet btRigidBody | ||
54 | public struct BulletBody | ||
55 | { | ||
56 | public BulletBody(uint id, IntPtr xx) | ||
57 | { | ||
58 | ID = id; | ||
59 | ptr = xx; | ||
60 | collisionFilter = 0; | ||
61 | collisionMask = 0; | ||
62 | } | ||
63 | public IntPtr ptr; | ||
64 | public uint ID; | ||
65 | public CollisionFilterGroups collisionFilter; | ||
66 | public CollisionFilterGroups collisionMask; | ||
67 | public override string ToString() | ||
68 | { | ||
69 | StringBuilder buff = new StringBuilder(); | ||
70 | buff.Append("<id="); | ||
71 | buff.Append(ID.ToString()); | ||
72 | buff.Append(",p="); | ||
73 | buff.Append(ptr.ToString("X")); | ||
74 | if (collisionFilter != 0 || collisionMask != 0) | ||
75 | { | ||
76 | buff.Append(",f="); | ||
77 | buff.Append(collisionFilter.ToString("X")); | ||
78 | buff.Append(",m="); | ||
79 | buff.Append(collisionMask.ToString("X")); | ||
80 | } | ||
81 | buff.Append(">"); | ||
82 | return buff.ToString(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public struct BulletShape | ||
87 | { | ||
88 | public BulletShape(IntPtr xx) | ||
89 | { | ||
90 | ptr = xx; | ||
91 | type=BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
92 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | ||
93 | isNativeShape = false; | ||
94 | } | ||
95 | public BulletShape(IntPtr xx, BSPhysicsShapeType typ) | ||
96 | { | ||
97 | ptr = xx; | ||
98 | type = typ; | ||
99 | shapeKey = 0; | ||
100 | isNativeShape = false; | ||
101 | } | ||
102 | public IntPtr ptr; | ||
103 | public BSPhysicsShapeType type; | ||
104 | public System.UInt64 shapeKey; | ||
105 | public bool isNativeShape; | ||
106 | public override string ToString() | ||
107 | { | ||
108 | StringBuilder buff = new StringBuilder(); | ||
109 | buff.Append("<p="); | ||
110 | buff.Append(ptr.ToString("X")); | ||
111 | buff.Append(",s="); | ||
112 | buff.Append(type.ToString()); | ||
113 | buff.Append(",k="); | ||
114 | buff.Append(shapeKey.ToString("X")); | ||
115 | buff.Append(",n="); | ||
116 | buff.Append(isNativeShape.ToString()); | ||
117 | buff.Append(">"); | ||
118 | return buff.ToString(); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | // Constraint type values as defined by Bullet | ||
123 | public enum ConstraintType : int | ||
124 | { | ||
125 | POINT2POINT_CONSTRAINT_TYPE = 3, | ||
126 | HINGE_CONSTRAINT_TYPE, | ||
127 | CONETWIST_CONSTRAINT_TYPE, | ||
128 | D6_CONSTRAINT_TYPE, | ||
129 | SLIDER_CONSTRAINT_TYPE, | ||
130 | CONTACT_CONSTRAINT_TYPE, | ||
131 | D6_SPRING_CONSTRAINT_TYPE, | ||
132 | MAX_CONSTRAINT_TYPE | ||
133 | } | ||
134 | |||
135 | // An allocated Bullet btConstraint | ||
136 | public struct BulletConstraint | ||
137 | { | ||
138 | public BulletConstraint(IntPtr xx) | ||
139 | { | ||
140 | ptr = xx; | ||
141 | } | ||
142 | public IntPtr ptr; | ||
143 | } | ||
144 | |||
145 | // An allocated HeightMapThing which holds various heightmap info. | ||
146 | // Made a class rather than a struct so there would be only one | ||
147 | // instance of this and C# will pass around pointers rather | ||
148 | // than making copies. | ||
149 | public class BulletHeightMapInfo | ||
150 | { | ||
151 | public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { | ||
152 | ID = id; | ||
153 | Ptr = xx; | ||
154 | heightMap = hm; | ||
155 | terrainRegionBase = Vector3.Zero; | ||
156 | minCoords = new Vector3(100f, 100f, 25f); | ||
157 | maxCoords = new Vector3(101f, 101f, 26f); | ||
158 | minZ = maxZ = 0f; | ||
159 | sizeX = sizeY = 256f; | ||
160 | } | ||
161 | public uint ID; | ||
162 | public IntPtr Ptr; | ||
163 | public float[] heightMap; | ||
164 | public Vector3 terrainRegionBase; | ||
165 | public Vector3 minCoords; | ||
166 | public Vector3 maxCoords; | ||
167 | public float sizeX, sizeY; | ||
168 | public float minZ, maxZ; | ||
169 | public BulletShape terrainShape; | ||
170 | public BulletBody terrainBody; | ||
171 | } | ||
172 | |||
173 | // =============================================================================== | ||
174 | [StructLayout(LayoutKind.Sequential)] | ||
175 | public struct ConvexHull | ||
176 | { | ||
177 | Vector3 Offset; | ||
178 | int VertexCount; | ||
179 | Vector3[] Vertices; | ||
180 | } | ||
181 | public enum BSPhysicsShapeType | ||
182 | { | ||
183 | SHAPE_UNKNOWN = 0, | ||
184 | SHAPE_CAPSULE = 1, | ||
185 | SHAPE_BOX = 2, | ||
186 | SHAPE_CONE = 3, | ||
187 | SHAPE_CYLINDER = 4, | ||
188 | SHAPE_SPHERE = 5, | ||
189 | SHAPE_MESH = 6, | ||
190 | SHAPE_HULL = 7, | ||
191 | // following defined by BulletSim | ||
192 | SHAPE_GROUNDPLANE = 20, | ||
193 | SHAPE_TERRAIN = 21, | ||
194 | SHAPE_COMPOUND = 22, | ||
195 | SHAPE_HEIGHTMAP = 23, | ||
196 | }; | ||
197 | |||
198 | // The native shapes have predefined shape hash keys | ||
199 | public enum FixedShapeKey : ulong | ||
200 | { | ||
201 | KEY_NONE = 0, | ||
202 | KEY_BOX = 1, | ||
203 | KEY_SPHERE = 2, | ||
204 | KEY_CONE = 3, | ||
205 | KEY_CYLINDER = 4, | ||
206 | KEY_CAPSULE = 5, | ||
207 | } | ||
208 | |||
209 | [StructLayout(LayoutKind.Sequential)] | ||
210 | public struct ShapeData | ||
211 | { | ||
212 | public uint ID; | ||
213 | public BSPhysicsShapeType Type; | ||
214 | public Vector3 Position; | ||
215 | public Quaternion Rotation; | ||
216 | public Vector3 Velocity; | ||
217 | public Vector3 Scale; | ||
218 | public float Mass; | ||
219 | public float Buoyancy; | ||
220 | public System.UInt64 HullKey; | ||
221 | public System.UInt64 MeshKey; | ||
222 | public float Friction; | ||
223 | public float Restitution; | ||
224 | public float Collidable; // true of things bump into this | ||
225 | public float Static; // true if a static object. Otherwise gravity, etc. | ||
226 | public float Solid; // true if object cannot be passed through | ||
227 | public Vector3 Size; | ||
228 | |||
229 | // note that bools are passed as floats since bool size changes by language and architecture | ||
230 | public const float numericTrue = 1f; | ||
231 | public const float numericFalse = 0f; | ||
232 | } | ||
233 | [StructLayout(LayoutKind.Sequential)] | ||
234 | public struct SweepHit | ||
235 | { | ||
236 | public uint ID; | ||
237 | public float Fraction; | ||
238 | public Vector3 Normal; | ||
239 | public Vector3 Point; | ||
240 | } | ||
241 | [StructLayout(LayoutKind.Sequential)] | ||
242 | public struct RaycastHit | ||
243 | { | ||
244 | public uint ID; | ||
245 | public float Fraction; | ||
246 | public Vector3 Normal; | ||
247 | } | ||
248 | [StructLayout(LayoutKind.Sequential)] | ||
249 | public struct CollisionDesc | ||
250 | { | ||
251 | public uint aID; | ||
252 | public uint bID; | ||
253 | public Vector3 point; | ||
254 | public Vector3 normal; | ||
255 | } | ||
256 | [StructLayout(LayoutKind.Sequential)] | ||
257 | public struct EntityProperties | ||
258 | { | ||
259 | public uint ID; | ||
260 | public Vector3 Position; | ||
261 | public Quaternion Rotation; | ||
262 | public Vector3 Velocity; | ||
263 | public Vector3 Acceleration; | ||
264 | public Vector3 RotationalVelocity; | ||
265 | } | ||
266 | |||
267 | // Format of this structure must match the definition in the C++ code | ||
268 | [StructLayout(LayoutKind.Sequential)] | ||
269 | public struct ConfigurationParameters | ||
270 | { | ||
271 | public float defaultFriction; | ||
272 | public float defaultDensity; | ||
273 | public float defaultRestitution; | ||
274 | public float collisionMargin; | ||
275 | public float gravity; | ||
276 | |||
277 | public float linearDamping; | ||
278 | public float angularDamping; | ||
279 | public float deactivationTime; | ||
280 | public float linearSleepingThreshold; | ||
281 | public float angularSleepingThreshold; | ||
282 | public float ccdMotionThreshold; | ||
283 | public float ccdSweptSphereRadius; | ||
284 | public float contactProcessingThreshold; | ||
285 | |||
286 | public float terrainImplementation; | ||
287 | public float terrainFriction; | ||
288 | public float terrainHitFraction; | ||
289 | public float terrainRestitution; | ||
290 | public float avatarFriction; | ||
291 | public float avatarStandingFriction; | ||
292 | public float avatarDensity; | ||
293 | public float avatarRestitution; | ||
294 | public float avatarCapsuleWidth; | ||
295 | public float avatarCapsuleDepth; | ||
296 | public float avatarCapsuleHeight; | ||
297 | public float avatarContactProcessingThreshold; | ||
298 | |||
299 | public float maxPersistantManifoldPoolSize; | ||
300 | public float maxCollisionAlgorithmPoolSize; | ||
301 | public float shouldDisableContactPoolDynamicAllocation; | ||
302 | public float shouldForceUpdateAllAabbs; | ||
303 | public float shouldRandomizeSolverOrder; | ||
304 | public float shouldSplitSimulationIslands; | ||
305 | public float shouldEnableFrictionCaching; | ||
306 | public float numberOfSolverIterations; | ||
307 | |||
308 | public float linksetImplementation; | ||
309 | public float linkConstraintUseFrameOffset; | ||
310 | public float linkConstraintEnableTransMotor; | ||
311 | public float linkConstraintTransMotorMaxVel; | ||
312 | public float linkConstraintTransMotorMaxForce; | ||
313 | public float linkConstraintERP; | ||
314 | public float linkConstraintCFM; | ||
315 | public float linkConstraintSolverIterations; | ||
316 | |||
317 | public float physicsLoggingFrames; | ||
318 | |||
319 | public const float numericTrue = 1f; | ||
320 | public const float numericFalse = 0f; | ||
321 | } | ||
322 | |||
323 | |||
324 | // The states a bullet collision object can have | ||
325 | public enum ActivationState : uint | ||
326 | { | ||
327 | ACTIVE_TAG = 1, | ||
328 | ISLAND_SLEEPING, | ||
329 | WANTS_DEACTIVATION, | ||
330 | DISABLE_DEACTIVATION, | ||
331 | DISABLE_SIMULATION, | ||
332 | } | ||
333 | |||
334 | public enum CollisionObjectTypes : int | ||
335 | { | ||
336 | CO_COLLISION_OBJECT = 1 << 0, | ||
337 | CO_RIGID_BODY = 1 << 1, | ||
338 | CO_GHOST_OBJECT = 1 << 2, | ||
339 | CO_SOFT_BODY = 1 << 3, | ||
340 | CO_HF_FLUID = 1 << 4, | ||
341 | CO_USER_TYPE = 1 << 5, | ||
342 | } | ||
343 | |||
344 | // Values used by Bullet and BulletSim to control object properties. | ||
345 | // Bullet's "CollisionFlags" has more to do with operations on the | ||
346 | // object (if collisions happen, if gravity effects it, ...). | ||
347 | public enum CollisionFlags : uint | ||
348 | { | ||
349 | CF_STATIC_OBJECT = 1 << 0, | ||
350 | CF_KINEMATIC_OBJECT = 1 << 1, | ||
351 | CF_NO_CONTACT_RESPONSE = 1 << 2, | ||
352 | CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3, | ||
353 | CF_CHARACTER_OBJECT = 1 << 4, | ||
354 | CF_DISABLE_VISUALIZE_OBJECT = 1 << 5, | ||
355 | CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, | ||
356 | // Following used by BulletSim to control collisions | ||
357 | BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, | ||
358 | BS_FLOATS_ON_WATER = 1 << 11, | ||
359 | BS_NONE = 0, | ||
360 | BS_ALL = 0xFFFFFFFF, | ||
361 | |||
362 | // These are the collision flags switched depending on physical state. | ||
363 | // The other flags are used for other things and should not be fooled with. | ||
364 | BS_ACTIVE = CF_STATIC_OBJECT | ||
365 | | CF_KINEMATIC_OBJECT | ||
366 | | CF_NO_CONTACT_RESPONSE | ||
367 | }; | ||
368 | |||
369 | // Values for collisions groups and masks | ||
370 | public enum CollisionFilterGroups : uint | ||
371 | { | ||
372 | // Don't use the bit definitions!! Define the use in a | ||
373 | // filter/mask definition below. This way collision interactions | ||
374 | // are more easily debugged. | ||
375 | BNoneFilter = 0, | ||
376 | BDefaultFilter = 1 << 0, | ||
377 | BStaticFilter = 1 << 1, | ||
378 | BKinematicFilter = 1 << 2, | ||
379 | BDebrisFilter = 1 << 3, | ||
380 | BSensorTrigger = 1 << 4, | ||
381 | BCharacterFilter = 1 << 5, | ||
382 | BAllFilter = 0xFFFFFFFF, | ||
383 | // Filter groups defined by BulletSim | ||
384 | BGroundPlaneFilter = 1 << 10, | ||
385 | BTerrainFilter = 1 << 11, | ||
386 | BRaycastFilter = 1 << 12, | ||
387 | BSolidFilter = 1 << 13, | ||
388 | BLinksetFilter = 1 << 14, | ||
389 | |||
390 | // The collsion filters and masked are defined in one place -- don't want them scattered | ||
391 | AvatarFilter = BCharacterFilter, | ||
392 | AvatarMask = BAllFilter, | ||
393 | ObjectFilter = BSolidFilter, | ||
394 | ObjectMask = BAllFilter, | ||
395 | StaticObjectFilter = BStaticFilter, | ||
396 | StaticObjectMask = BAllFilter & ~BStaticFilter, // static objects don't collide with each other | ||
397 | LinksetFilter = BLinksetFilter, | ||
398 | LinksetMask = BAllFilter & ~BLinksetFilter, // linkset objects don't collide with each other | ||
399 | VolumeDetectFilter = BSensorTrigger, | ||
400 | VolumeDetectMask = ~BSensorTrigger, | ||
401 | TerrainFilter = BTerrainFilter, | ||
402 | TerrainMask = BAllFilter & ~BStaticFilter, // static objects on the ground don't collide | ||
403 | GroundPlaneFilter = BGroundPlaneFilter, | ||
404 | GroundPlaneMask = BAllFilter | ||
405 | |||
406 | }; | ||
407 | |||
408 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | ||
409 | // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2. | ||
410 | public enum ConstraintParams : int | ||
411 | { | ||
412 | BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730 | ||
413 | BT_CONSTRAINT_STOP_ERP, | ||
414 | BT_CONSTRAINT_CFM, | ||
415 | BT_CONSTRAINT_STOP_CFM, | ||
416 | }; | ||
417 | public enum ConstraintParamAxis : int | ||
418 | { | ||
419 | AXIS_LINEAR_X = 0, | ||
420 | AXIS_LINEAR_Y, | ||
421 | AXIS_LINEAR_Z, | ||
422 | AXIS_ANGULAR_X, | ||
423 | AXIS_ANGULAR_Y, | ||
424 | AXIS_ANGULAR_Z, | ||
425 | AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls | ||
426 | AXIS_ANGULAR_ALL, | ||
427 | AXIS_ALL | ||
428 | }; | ||
429 | |||
430 | // =============================================================================== | ||
431 | static class BulletSimAPI { | ||
432 | |||
433 | // Link back to the managed code for outputting log messages | ||
434 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
435 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | ||
436 | |||
437 | // =============================================================================== | ||
438 | // Initialization and simulation | ||
439 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
440 | public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, | ||
441 | int maxCollisions, IntPtr collisionArray, | ||
442 | int maxUpdates, IntPtr updateArray, | ||
443 | DebugLogCallback logRoutine); | ||
444 | |||
445 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
446 | public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); | ||
447 | |||
448 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
449 | public static extern void SetHeightMap2(IntPtr world, float[] heightmap); | ||
450 | |||
451 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
452 | public static extern void Shutdown2(IntPtr sim); | ||
453 | |||
454 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
455 | public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
456 | out int updatedEntityCount, | ||
457 | out IntPtr updatedEntitiesPtr, | ||
458 | out int collidersCount, | ||
459 | out IntPtr collidersPtr); | ||
460 | |||
461 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
462 | public static extern bool PushUpdate2(IntPtr obj); | ||
463 | |||
464 | // ===================================================================================== | ||
465 | // Mesh, hull, shape and body creation helper routines | ||
466 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
467 | public static extern IntPtr CreateMeshShape2(IntPtr world, | ||
468 | int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
469 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | ||
470 | |||
471 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
472 | public static extern IntPtr CreateHullShape2(IntPtr world, | ||
473 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); | ||
474 | |||
475 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
476 | public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); | ||
477 | |||
478 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
479 | public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); | ||
480 | |||
481 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
482 | public static extern bool IsNativeShape2(IntPtr shape); | ||
483 | |||
484 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
485 | public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); | ||
486 | |||
487 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
488 | public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); | ||
489 | |||
490 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
491 | public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); | ||
492 | |||
493 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
494 | public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); | ||
495 | |||
496 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
497 | public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); | ||
498 | |||
499 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
500 | public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); | ||
501 | |||
502 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
503 | public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); | ||
504 | |||
505 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
506 | public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); | ||
507 | |||
508 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
509 | public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); | ||
510 | |||
511 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
512 | public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); | ||
513 | |||
514 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
515 | public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); | ||
516 | |||
517 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
518 | public static extern int GetBodyType2(IntPtr obj); | ||
519 | |||
520 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
521 | public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
522 | |||
523 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
524 | public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
525 | |||
526 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
527 | public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); | ||
528 | |||
529 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
530 | public static extern IntPtr AllocateBodyInfo2(IntPtr obj); | ||
531 | |||
532 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
533 | public static extern void ReleaseBodyInfo2(IntPtr obj); | ||
534 | |||
535 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
536 | public static extern void DestroyObject2(IntPtr sim, IntPtr obj); | ||
537 | |||
538 | // ===================================================================================== | ||
539 | // Terrain creation and helper routines | ||
540 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
541 | public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, | ||
542 | [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); | ||
543 | |||
544 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
545 | public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, | ||
546 | [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); | ||
547 | |||
548 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
549 | public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); | ||
550 | |||
551 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
552 | public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); | ||
553 | |||
554 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
555 | public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); | ||
556 | |||
557 | // ===================================================================================== | ||
558 | // Constraint creation and helper routines | ||
559 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
560 | public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
561 | Vector3 frame1loc, Quaternion frame1rot, | ||
562 | Vector3 frame2loc, Quaternion frame2rot, | ||
563 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
564 | |||
565 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
566 | public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
567 | Vector3 joinPoint, | ||
568 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
569 | |||
570 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
571 | public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, | ||
572 | Vector3 pivotinA, Vector3 pivotinB, | ||
573 | Vector3 axisInA, Vector3 axisInB, | ||
574 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | ||
575 | |||
576 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
577 | public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); | ||
578 | |||
579 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
580 | public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); | ||
581 | |||
582 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
583 | public static extern bool SetFrames2(IntPtr constrain, | ||
584 | Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); | ||
585 | |||
586 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
587 | public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); | ||
588 | |||
589 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
590 | public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); | ||
591 | |||
592 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
593 | public static extern bool UseFrameOffset2(IntPtr constrain, float enable); | ||
594 | |||
595 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
596 | public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); | ||
597 | |||
598 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
599 | public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); | ||
600 | |||
601 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
602 | public static extern bool CalculateTransforms2(IntPtr constrain); | ||
603 | |||
604 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
605 | public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); | ||
606 | |||
607 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
608 | public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); | ||
609 | |||
610 | // ===================================================================================== | ||
611 | // btCollisionWorld entries | ||
612 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
613 | public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); | ||
614 | |||
615 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
616 | public static extern void UpdateAabbs2(IntPtr world); | ||
617 | |||
618 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
619 | public static extern bool GetForceUpdateAllAabbs2(IntPtr world); | ||
620 | |||
621 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
622 | public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); | ||
623 | |||
624 | // ===================================================================================== | ||
625 | // btDynamicsWorld entries | ||
626 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
627 | public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); | ||
628 | |||
629 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
630 | public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); | ||
631 | |||
632 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
633 | public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); | ||
634 | |||
635 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
636 | public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); | ||
637 | // ===================================================================================== | ||
638 | // btCollisionObject entries | ||
639 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
640 | public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); | ||
641 | |||
642 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
643 | public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); | ||
644 | |||
645 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
646 | public static extern bool HasAnisotripicFriction2(IntPtr constrain); | ||
647 | |||
648 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
649 | public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); | ||
650 | |||
651 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
652 | public static extern float GetContactProcessingThreshold2(IntPtr obj); | ||
653 | |||
654 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
655 | public static extern bool IsStaticObject2(IntPtr obj); | ||
656 | |||
657 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
658 | public static extern bool IsKinematicObject2(IntPtr obj); | ||
659 | |||
660 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
661 | public static extern bool IsStaticOrKinematicObject2(IntPtr obj); | ||
662 | |||
663 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
664 | public static extern bool HasContactResponse2(IntPtr obj); | ||
665 | |||
666 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
667 | public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); | ||
668 | |||
669 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
670 | public static extern IntPtr GetCollisionShape2(IntPtr obj); | ||
671 | |||
672 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
673 | public static extern int GetActivationState2(IntPtr obj); | ||
674 | |||
675 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
676 | public static extern void SetActivationState2(IntPtr obj, int state); | ||
677 | |||
678 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
679 | public static extern void SetDeactivationTime2(IntPtr obj, float dtime); | ||
680 | |||
681 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
682 | public static extern float GetDeactivationTime2(IntPtr obj); | ||
683 | |||
684 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
685 | public static extern void ForceActivationState2(IntPtr obj, ActivationState state); | ||
686 | |||
687 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
688 | public static extern void Activate2(IntPtr obj, bool forceActivation); | ||
689 | |||
690 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
691 | public static extern bool IsActive2(IntPtr obj); | ||
692 | |||
693 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
694 | public static extern void SetRestitution2(IntPtr obj, float val); | ||
695 | |||
696 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
697 | public static extern float GetRestitution2(IntPtr obj); | ||
698 | |||
699 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
700 | public static extern void SetFriction2(IntPtr obj, float val); | ||
701 | |||
702 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
703 | public static extern float GetFriction2(IntPtr obj); | ||
704 | |||
705 | /* Haven't defined the type 'Transform' | ||
706 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
707 | public static extern Transform GetWorldTransform2(IntPtr obj); | ||
708 | |||
709 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
710 | public static extern void setWorldTransform2(IntPtr obj, Transform trans); | ||
711 | */ | ||
712 | |||
713 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
714 | public static extern Vector3 GetPosition2(IntPtr obj); | ||
715 | |||
716 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
717 | public static extern Quaternion GetOrientation2(IntPtr obj); | ||
718 | |||
719 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
720 | public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); | ||
721 | |||
722 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
723 | public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); | ||
724 | |||
725 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
726 | public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); | ||
727 | |||
728 | /* | ||
729 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
730 | public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); | ||
731 | |||
732 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
733 | public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); | ||
734 | */ | ||
735 | |||
736 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
737 | public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); | ||
738 | |||
739 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
740 | public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); | ||
741 | |||
742 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
743 | public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); | ||
744 | |||
745 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
746 | public static extern float GetHitFraction2(IntPtr obj); | ||
747 | |||
748 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
749 | public static extern void SetHitFraction2(IntPtr obj, float val); | ||
750 | |||
751 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
752 | public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); | ||
753 | |||
754 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
755 | public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
756 | |||
757 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
758 | public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
759 | |||
760 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
761 | public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); | ||
762 | |||
763 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
764 | public static extern float GetCcdMotionThreshold2(IntPtr obj); | ||
765 | |||
766 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
767 | public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); | ||
768 | |||
769 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
770 | public static extern float GetCcdSweptSphereRadius2(IntPtr obj); | ||
771 | |||
772 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
773 | public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); | ||
774 | |||
775 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
776 | public static extern IntPtr GetUserPointer2(IntPtr obj); | ||
777 | |||
778 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
779 | public static extern void SetUserPointer2(IntPtr obj, IntPtr val); | ||
780 | |||
781 | // ===================================================================================== | ||
782 | // btRigidBody entries | ||
783 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
784 | public static extern void ApplyGravity2(IntPtr obj); | ||
785 | |||
786 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
787 | public static extern void SetGravity2(IntPtr obj, Vector3 val); | ||
788 | |||
789 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
790 | public static extern Vector3 GetGravity2(IntPtr obj); | ||
791 | |||
792 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
793 | public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); | ||
794 | |||
795 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
796 | public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); | ||
797 | |||
798 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
799 | public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); | ||
800 | |||
801 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
802 | public static extern float GetLinearDamping2(IntPtr obj); | ||
803 | |||
804 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
805 | public static extern float GetAngularDamping2(IntPtr obj); | ||
806 | |||
807 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
808 | public static extern float GetLinearSleepingThreshold2(IntPtr obj); | ||
809 | |||
810 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
811 | public static extern float GetAngularSleepingThreshold2(IntPtr obj); | ||
812 | |||
813 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
814 | public static extern void ApplyDamping2(IntPtr obj, float timeStep); | ||
815 | |||
816 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
817 | public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); | ||
818 | |||
819 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
820 | public static extern Vector3 GetLinearFactor2(IntPtr obj); | ||
821 | |||
822 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
823 | public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); | ||
824 | |||
825 | /* | ||
826 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
827 | public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); | ||
828 | */ | ||
829 | |||
830 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
831 | public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); | ||
832 | |||
833 | // Add a force to the object as if its mass is one. | ||
834 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
835 | public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); | ||
836 | |||
837 | // Set the force being applied to the object as if its mass is one. | ||
838 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
839 | public static extern void SetObjectForce2(IntPtr obj, Vector3 force); | ||
840 | |||
841 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
842 | public static extern Vector3 GetTotalForce2(IntPtr obj); | ||
843 | |||
844 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
845 | public static extern Vector3 GetTotalTorque2(IntPtr obj); | ||
846 | |||
847 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
848 | public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); | ||
849 | |||
850 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
851 | public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); | ||
852 | |||
853 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
854 | public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); | ||
855 | |||
856 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
857 | public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); | ||
858 | |||
859 | // Apply force at the given point. Will add torque to the object. | ||
860 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
861 | public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); | ||
862 | |||
863 | // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. | ||
864 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
865 | public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); | ||
866 | |||
867 | // Apply impulse to the object's torque. Force is scaled by object's mass. | ||
868 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
869 | public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); | ||
870 | |||
871 | // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. | ||
872 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
873 | public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); | ||
874 | |||
875 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
876 | public static extern void ClearForces2(IntPtr obj); | ||
877 | |||
878 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
879 | public static extern void ClearAllForces2(IntPtr obj); | ||
880 | |||
881 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
882 | public static extern void UpdateInertiaTensor2(IntPtr obj); | ||
883 | |||
884 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
885 | public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); | ||
886 | |||
887 | /* | ||
888 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
889 | public static extern Transform GetCenterOfMassTransform2(IntPtr obj); | ||
890 | */ | ||
891 | |||
892 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
893 | public static extern Vector3 GetLinearVelocity2(IntPtr obj); | ||
894 | |||
895 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
896 | public static extern Vector3 GetAngularVelocity2(IntPtr obj); | ||
897 | |||
898 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
899 | public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); | ||
900 | |||
901 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
902 | public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); | ||
903 | |||
904 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
905 | public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); | ||
906 | |||
907 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
908 | public static extern void Translate2(IntPtr obj, Vector3 trans); | ||
909 | |||
910 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
911 | public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); | ||
912 | |||
913 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
914 | public static extern bool WantsSleeping2(IntPtr obj); | ||
915 | |||
916 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
917 | public static extern void SetAngularFactor2(IntPtr obj, float factor); | ||
918 | |||
919 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
920 | public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); | ||
921 | |||
922 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
923 | public static extern Vector3 GetAngularFactor2(IntPtr obj); | ||
924 | |||
925 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
926 | public static extern bool IsInWorld2(IntPtr obj); | ||
927 | |||
928 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
929 | public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); | ||
930 | |||
931 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
932 | public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); | ||
933 | |||
934 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
935 | public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); | ||
936 | |||
937 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
938 | public static extern int GetNumConstraintRefs2(IntPtr obj); | ||
939 | |||
940 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
941 | public static extern void SetCollisionFilterMask2(IntPtr body, uint filter, uint mask); | ||
942 | |||
943 | // ===================================================================================== | ||
944 | // btCollisionShape entries | ||
945 | |||
946 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
947 | public static extern float GetAngularMotionDisc2(IntPtr shape); | ||
948 | |||
949 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
950 | public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); | ||
951 | |||
952 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
953 | public static extern bool IsPolyhedral2(IntPtr shape); | ||
954 | |||
955 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
956 | public static extern bool IsConvex2d2(IntPtr shape); | ||
957 | |||
958 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
959 | public static extern bool IsConvex2(IntPtr shape); | ||
960 | |||
961 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
962 | public static extern bool IsNonMoving2(IntPtr shape); | ||
963 | |||
964 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
965 | public static extern bool IsConcave2(IntPtr shape); | ||
966 | |||
967 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
968 | public static extern bool IsCompound2(IntPtr shape); | ||
969 | |||
970 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
971 | public static extern bool IsSoftBody2(IntPtr shape); | ||
972 | |||
973 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
974 | public static extern bool IsInfinite2(IntPtr shape); | ||
975 | |||
976 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
977 | public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); | ||
978 | |||
979 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
980 | public static extern Vector3 GetLocalScaling2(IntPtr shape); | ||
981 | |||
982 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
983 | public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); | ||
984 | |||
985 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
986 | public static extern int GetShapeType2(IntPtr shape); | ||
987 | |||
988 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
989 | public static extern void SetMargin2(IntPtr shape, float val); | ||
990 | |||
991 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
992 | public static extern float GetMargin2(IntPtr shape); | ||
993 | |||
994 | // ===================================================================================== | ||
995 | // Debugging | ||
996 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
997 | public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); | ||
998 | |||
999 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1000 | public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); | ||
1001 | |||
1002 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1003 | public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); | ||
1004 | |||
1005 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1006 | public static extern void DumpAllInfo2(IntPtr sim); | ||
1007 | |||
1008 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1009 | public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); | ||
1010 | |||
1011 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1012 | public static extern void DumpPhysicsStatistics2(IntPtr sim); | ||
1013 | |||
1014 | } | ||
1015 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs new file mode 100755 index 0000000..c7a2f7e --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | |||
@@ -0,0 +1,265 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OMV = OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
33 | { | ||
34 | // Classes to allow some type checking for the API | ||
35 | // These hold pointers to allocated objects in the unmanaged space. | ||
36 | // These classes are subclassed by the various physical implementations of | ||
37 | // objects. In particular, there is a version for physical instances in | ||
38 | // unmanaged memory ("unman") and one for in managed memory ("XNA"). | ||
39 | |||
40 | // Currently, the instances of these classes are a reference to a | ||
41 | // physical representation and this has no releationship to other | ||
42 | // instances. Someday, refarb the usage of these classes so each instance | ||
43 | // refers to a particular physical instance and this class controls reference | ||
44 | // counts and such. This should be done along with adding BSShapes. | ||
45 | |||
46 | public class BulletWorld | ||
47 | { | ||
48 | public BulletWorld(uint worldId, BSScene bss) | ||
49 | { | ||
50 | worldID = worldId; | ||
51 | physicsScene = bss; | ||
52 | } | ||
53 | public uint worldID; | ||
54 | // The scene is only in here so very low level routines have a handle to print debug/error messages | ||
55 | public BSScene physicsScene; | ||
56 | } | ||
57 | |||
58 | // An allocated Bullet btRigidBody | ||
59 | public class BulletBody | ||
60 | { | ||
61 | public BulletBody(uint id) | ||
62 | { | ||
63 | ID = id; | ||
64 | collisionType = CollisionType.Static; | ||
65 | } | ||
66 | public uint ID; | ||
67 | public CollisionType collisionType; | ||
68 | |||
69 | public virtual void Clear() { } | ||
70 | public virtual bool HasPhysicalBody { get { return false; } } | ||
71 | |||
72 | // Apply the specificed collision mask into the physical world | ||
73 | public virtual bool ApplyCollisionMask(BSScene physicsScene) | ||
74 | { | ||
75 | // Should assert the body has been added to the physical world. | ||
76 | // (The collision masks are stored in the collision proxy cache which only exists for | ||
77 | // a collision body that is in the world.) | ||
78 | return physicsScene.PE.SetCollisionGroupMask(this, | ||
79 | BulletSimData.CollisionTypeMasks[collisionType].group, | ||
80 | BulletSimData.CollisionTypeMasks[collisionType].mask); | ||
81 | } | ||
82 | |||
83 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
84 | public virtual string AddrString | ||
85 | { | ||
86 | get { return "unknown"; } | ||
87 | } | ||
88 | |||
89 | public override string ToString() | ||
90 | { | ||
91 | StringBuilder buff = new StringBuilder(); | ||
92 | buff.Append("<id="); | ||
93 | buff.Append(ID.ToString()); | ||
94 | buff.Append(",p="); | ||
95 | buff.Append(AddrString); | ||
96 | buff.Append(",c="); | ||
97 | buff.Append(collisionType); | ||
98 | buff.Append(">"); | ||
99 | return buff.ToString(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public class BulletShape | ||
104 | { | ||
105 | public BulletShape() | ||
106 | { | ||
107 | type = BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
108 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | ||
109 | isNativeShape = false; | ||
110 | } | ||
111 | public BSPhysicsShapeType type; | ||
112 | public System.UInt64 shapeKey; | ||
113 | public bool isNativeShape; | ||
114 | |||
115 | public virtual void Clear() { } | ||
116 | public virtual bool HasPhysicalShape { get { return false; } } | ||
117 | |||
118 | // Make another reference to this physical object. | ||
119 | public virtual BulletShape Clone() { return new BulletShape(); } | ||
120 | |||
121 | // Return 'true' if this and other refer to the same physical object | ||
122 | public virtual bool ReferenceSame(BulletShape xx) { return false; } | ||
123 | |||
124 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
125 | public virtual string AddrString | ||
126 | { | ||
127 | get { return "unknown"; } | ||
128 | } | ||
129 | |||
130 | public override string ToString() | ||
131 | { | ||
132 | StringBuilder buff = new StringBuilder(); | ||
133 | buff.Append("<p="); | ||
134 | buff.Append(AddrString); | ||
135 | buff.Append(",s="); | ||
136 | buff.Append(type.ToString()); | ||
137 | buff.Append(",k="); | ||
138 | buff.Append(shapeKey.ToString("X")); | ||
139 | buff.Append(",n="); | ||
140 | buff.Append(isNativeShape.ToString()); | ||
141 | buff.Append(">"); | ||
142 | return buff.ToString(); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | // An allocated Bullet btConstraint | ||
147 | public class BulletConstraint | ||
148 | { | ||
149 | public BulletConstraint() | ||
150 | { | ||
151 | } | ||
152 | public virtual void Clear() { } | ||
153 | public virtual bool HasPhysicalConstraint { get { return false; } } | ||
154 | |||
155 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
156 | public virtual string AddrString | ||
157 | { | ||
158 | get { return "unknown"; } | ||
159 | } | ||
160 | } | ||
161 | |||
162 | // An allocated HeightMapThing which holds various heightmap info. | ||
163 | // Made a class rather than a struct so there would be only one | ||
164 | // instance of this and C# will pass around pointers rather | ||
165 | // than making copies. | ||
166 | public class BulletHMapInfo | ||
167 | { | ||
168 | public BulletHMapInfo(uint id, float[] hm) { | ||
169 | ID = id; | ||
170 | heightMap = hm; | ||
171 | terrainRegionBase = OMV.Vector3.Zero; | ||
172 | minCoords = new OMV.Vector3(100f, 100f, 25f); | ||
173 | maxCoords = new OMV.Vector3(101f, 101f, 26f); | ||
174 | minZ = maxZ = 0f; | ||
175 | sizeX = sizeY = 256f; | ||
176 | } | ||
177 | public uint ID; | ||
178 | public float[] heightMap; | ||
179 | public OMV.Vector3 terrainRegionBase; | ||
180 | public OMV.Vector3 minCoords; | ||
181 | public OMV.Vector3 maxCoords; | ||
182 | public float sizeX, sizeY; | ||
183 | public float minZ, maxZ; | ||
184 | public BulletShape terrainShape; | ||
185 | public BulletBody terrainBody; | ||
186 | } | ||
187 | |||
188 | // The general class of collsion object. | ||
189 | public enum CollisionType | ||
190 | { | ||
191 | Avatar, | ||
192 | Groundplane, | ||
193 | Terrain, | ||
194 | Static, | ||
195 | Dynamic, | ||
196 | VolumeDetect, | ||
197 | // Linkset, // A linkset should be either Static or Dynamic | ||
198 | LinksetChild, | ||
199 | Unknown | ||
200 | }; | ||
201 | |||
202 | // Hold specification of group and mask collision flags for a CollisionType | ||
203 | public struct CollisionTypeFilterGroup | ||
204 | { | ||
205 | public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) | ||
206 | { | ||
207 | type = t; | ||
208 | group = g; | ||
209 | mask = m; | ||
210 | } | ||
211 | public CollisionType type; | ||
212 | public uint group; | ||
213 | public uint mask; | ||
214 | }; | ||
215 | |||
216 | public static class BulletSimData | ||
217 | { | ||
218 | |||
219 | // Map of collisionTypes to flags for collision groups and masks. | ||
220 | // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code | ||
221 | // but, instead, use references to this dictionary. Finding and debugging | ||
222 | // collision flag problems will be made easier. | ||
223 | public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks | ||
224 | = new Dictionary<CollisionType, CollisionTypeFilterGroup>() | ||
225 | { | ||
226 | { CollisionType.Avatar, | ||
227 | new CollisionTypeFilterGroup(CollisionType.Avatar, | ||
228 | (uint)CollisionFilterGroups.BCharacterGroup, | ||
229 | (uint)CollisionFilterGroups.BAllGroup) | ||
230 | }, | ||
231 | { CollisionType.Groundplane, | ||
232 | new CollisionTypeFilterGroup(CollisionType.Groundplane, | ||
233 | (uint)CollisionFilterGroups.BGroundPlaneGroup, | ||
234 | (uint)CollisionFilterGroups.BAllGroup) | ||
235 | }, | ||
236 | { CollisionType.Terrain, | ||
237 | new CollisionTypeFilterGroup(CollisionType.Terrain, | ||
238 | (uint)CollisionFilterGroups.BTerrainGroup, | ||
239 | (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) | ||
240 | }, | ||
241 | { CollisionType.Static, | ||
242 | new CollisionTypeFilterGroup(CollisionType.Static, | ||
243 | (uint)CollisionFilterGroups.BStaticGroup, | ||
244 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
245 | }, | ||
246 | { CollisionType.Dynamic, | ||
247 | new CollisionTypeFilterGroup(CollisionType.Dynamic, | ||
248 | (uint)CollisionFilterGroups.BSolidGroup, | ||
249 | (uint)(CollisionFilterGroups.BAllGroup)) | ||
250 | }, | ||
251 | { CollisionType.VolumeDetect, | ||
252 | new CollisionTypeFilterGroup(CollisionType.VolumeDetect, | ||
253 | (uint)CollisionFilterGroups.BSensorTrigger, | ||
254 | (uint)(~CollisionFilterGroups.BSensorTrigger)) | ||
255 | }, | ||
256 | { CollisionType.LinksetChild, | ||
257 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, | ||
258 | (uint)CollisionFilterGroups.BLinksetChildGroup, | ||
259 | (uint)(CollisionFilterGroups.BNoneGroup)) | ||
260 | // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
261 | }, | ||
262 | }; | ||
263 | |||
264 | } | ||
265 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt new file mode 100755 index 0000000..41bab26 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | |||
@@ -0,0 +1,322 @@ | |||
1 | CURRENT PRIORITIES | ||
2 | ================================================= | ||
3 | Child movement in linkset (don't rebuild linkset) | ||
4 | Vehicle angular vertical attraction | ||
5 | vehicle angular banking | ||
6 | Center-of-gravity | ||
7 | Vehicle angular deflection | ||
8 | Preferred orientation angular correction fix | ||
9 | when should angular and linear motor targets be zeroed? when selected? | ||
10 | Need a vehicle.clear()? Or an 'else' in prestep if not physical. | ||
11 | Teravus llMoveToTarget script debug | ||
12 | Mixing of hover, buoyancy/gravity, moveToTarget, into one force | ||
13 | Nebadon vehicles turning funny in arena | ||
14 | limitMotorUp calibration (more down?) | ||
15 | llRotLookAt | ||
16 | llLookAt | ||
17 | Avatars walking up stairs (HALF DONE) | ||
18 | Avatar movement | ||
19 | flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle (DONE) | ||
20 | walking up stairs is not calibrated correctly (stairs out of Kepler cabin) | ||
21 | avatar capsule rotation completed (NOT DONE - Bullet's capsule shape is not the solution) | ||
22 | Enable vehicle border crossings (at least as poorly as ODE) | ||
23 | Terrain skirts | ||
24 | Avatar created in previous region and not new region when crossing border | ||
25 | Vehicle recreated in new sim at small Z value (offset from root value?) (DONE) | ||
26 | Vehicle script tuning/debugging | ||
27 | Avanti speed script | ||
28 | Weapon shooter script | ||
29 | Add material densities to the material types | ||
30 | |||
31 | CRASHES | ||
32 | ================================================= | ||
33 | Crazyness during 20130115 office hours was PositionAdjustUnderground for both char and prim | ||
34 | m1:logs/20130115.0934/physics-BulletSim-20130115083613.log | ||
35 | Creation of Neb's terrain made the terrain "disappear". Everything started to fall | ||
36 | and then get restored to be above terrain. | ||
37 | 20121129.1411: editting/moving phys object across region boundries causes crash | ||
38 | getPos-> btRigidBody::upcast -> getBodyType -> BOOM | ||
39 | 20121128.1600: mesh object not rezzing (no physics mesh). | ||
40 | Causes many errors. Doesn't stop after first error with box shape. | ||
41 | Eventually crashes when deleting the object. | ||
42 | 20121206.1434: rez Sam-pan into OSGrid BulletSim11 region | ||
43 | Immediate simulator crash. Mono does not output any stacktrace and | ||
44 | log just stops after reporting taint-time linking of the linkset. | ||
45 | |||
46 | VEHICLES TODO LIST: | ||
47 | ================================================= | ||
48 | Border crossing with linked vehicle causes crash | ||
49 | Vehicles (Move smoothly) | ||
50 | Some vehicles should not be able to turn if no speed or off ground. | ||
51 | Cannot edit/move a vehicle being ridden: it jumps back to the origional position. | ||
52 | Neb car jiggling left and right | ||
53 | Happens on terrain and any other mesh object. Flat cubes are much smoother. | ||
54 | This has been reduced but not eliminated. | ||
55 | Implement referenceFrame for all the motion routines. | ||
56 | For limitMotorUp, use raycast down to find if vehicle is in the air. | ||
57 | Angular motion around Z moves the vehicle in world Z and not vehicle Z in ODE. | ||
58 | Verify that angular motion specified around Z moves in the vehicle coordinates. | ||
59 | Verify llGetVel() is returning a smooth and good value for vehicle movement. | ||
60 | llGetVel() should return the root's velocity if requested in a child prim. | ||
61 | Implement function efficiency for lineaar and angular motion. | ||
62 | After getting off a vehicle, the root prim is phantom (can be walked through) | ||
63 | Need to force a position update for the root prim after compound shape destruction | ||
64 | Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint) | ||
65 | Remove vehicle angular velocity zeroing in BSPrim.UpdateProperties(). | ||
66 | A kludge that isn't fixing the real problem of Bullet adding extra motion. | ||
67 | Incorporate inter-relationship of angular corrections. For instance, angularDeflection | ||
68 | and angularMotorUp will compute same X or Y correction. When added together | ||
69 | creates over-correction and over-shoot and wabbling. | ||
70 | |||
71 | GENERAL TODO LIST: | ||
72 | ================================================= | ||
73 | llMoveToTarget objects are not effected by gravity until target is removed. | ||
74 | Implement llSetPhysicalMaterial. | ||
75 | extend it with Center-of-mass, rolling friction, density | ||
76 | Implement llSetForceAndTorque. | ||
77 | Change BSPrim.moveToTarget to used forces rather than changing position | ||
78 | Changing position allows one to move through walls | ||
79 | Implement an avatar mesh shape. The Bullet capsule is way too limited. | ||
80 | Consider just hand creating a vertex/index array in a new BSShapeAvatar. | ||
81 | Verify/fix phantom, volume-detect objects do not fall to infinity. Should stop at terrain. | ||
82 | Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. | ||
83 | Duplicating a physical prim causes old prim to jump away | ||
84 | Dup a phys prim and the original become unselected and thus interacts w/ selected prim. | ||
85 | Scenes with hundred of thousands of static objects take a lot of physics CPU time. | ||
86 | BSPrim.Force should set a continious force on the prim. The force should be | ||
87 | applied each tick. Some limits? | ||
88 | Gun sending shooter flying. | ||
89 | Collision margin (gap between physical objects lying on each other) | ||
90 | Boundry checking (crashes related to crossing boundry) | ||
91 | Add check for border edge position for avatars and objects. | ||
92 | Verify the events are created for border crossings. | ||
93 | Avatar rotation (check out changes to ScenePresence for physical rotation) | ||
94 | Avatar running (what does phys engine need to do?) | ||
95 | Small physical objects do not interact correctly | ||
96 | Create chain of .5x.5x.1 torui and make all but top physical so to hang. | ||
97 | The chain will fall apart and pairs will dance around on ground | ||
98 | Chains of 1x1x.2 will stay connected but will dance. | ||
99 | Chains above 2x2x.4 are more stable and get stablier as torui get larger. | ||
100 | Add PID motor for avatar movement (slow to stop, ...) | ||
101 | setForce should set a constant force. Different than AddImpulse. | ||
102 | Implement raycast. | ||
103 | Implement ShapeCollection.Dispose() | ||
104 | Implement water as a plain so raycasting and collisions can happen with same. | ||
105 | Add collision penetration return | ||
106 | Add field passed back by BulletSim.dll and fill with info in ManifoldConstact.GetDistance() | ||
107 | Add osGetPhysicsEngineName() so scripters can tell whether BulletSim or ODE | ||
108 | Also osGetPhysicsEngineVerion() maybe. | ||
109 | Linkset.Position and Linkset.Orientation requre rewrite to properly return | ||
110 | child position. LinksetConstraint acts like it's at taint time!! | ||
111 | Implement LockAngularMotion -- implements llSetStatus(ROTATE_AXIS_*, T/F) | ||
112 | Should the different PID factors have non-equal contributions for different | ||
113 | values of Efficiency? | ||
114 | Selecting and deselecting physical objects causes CPU processing time to jump | ||
115 | http://www.youtube.com/watch?v=Hjg57fWg8yI&hd=1 | ||
116 | put thousand physical objects, select and deselect same. CPU time will be large. | ||
117 | Re-implement buoyancy as a separate force on the object rather than diddling gravity. | ||
118 | Register a pre-step event to add the force. | ||
119 | More efficient memory usage when passing hull information from BSPrim to BulletSim | ||
120 | Avatar movement motor check for zero or small movement. Somehow suppress small movements | ||
121 | when avatar has stopped and is just standing. Simple test for near zero has | ||
122 | the problem of preventing starting up (increase from zero) especially when falling. | ||
123 | Physical and phantom will drop through the terrain | ||
124 | |||
125 | |||
126 | LINKSETS | ||
127 | ====================================================== | ||
128 | Editing a child of a linkset causes the child to go phantom | ||
129 | Move a child prim once when it is physical and can never move it again without it going phantom | ||
130 | Offset the center of the linkset to be the geometric center of all the prims | ||
131 | Not quite the same as the center-of-gravity | ||
132 | Linksets should allow collisions to individual children | ||
133 | Add LocalID to children shapes in LinksetCompound and create events for individuals | ||
134 | LinksetCompound: when one of the children changes orientation (like tires | ||
135 | turning on a vehicle, the whole compound object is rebuilt. Optimize this | ||
136 | so orientation/position of individual children can change without a rebuild. | ||
137 | Verify/think through scripts in children of linksets. What do they reference | ||
138 | and return when getting position, velocity, ... | ||
139 | Confirm constraint linksets still work after making all the changes for compound linksets. | ||
140 | Use PostTaint callback to do rebuilds for constraint linksets to reduce rebuilding | ||
141 | Add 'changed' flag or similar to reduce the number of times a linkset is rebuilt. | ||
142 | For compound linksets, add ability to remove or reposition individual child shapes. | ||
143 | Speed up creation of large physical linksets | ||
144 | For instance, sitting in Neb's car (130 prims) takes several seconds to become physical. | ||
145 | REALLY bad for very large physical linksets (freezes the sim for many seconds). | ||
146 | Eliminate collisions between objects in a linkset. (LinksetConstraint) | ||
147 | Have UserPointer point to struct with localID and linksetID? | ||
148 | Objects in original linkset still collide with each other? | ||
149 | |||
150 | MORE | ||
151 | ====================================================== | ||
152 | Create tests for different interface components | ||
153 | Have test objects/scripts measure themselves and turn color if correct/bad | ||
154 | Test functions in SL and calibrate correctness there | ||
155 | Create auto rezzer and tracker to run through the tests | ||
156 | Use the HACD convex hull routine in Bullet rather than the C# version. | ||
157 | Do we need to do convex hulls all the time? Can complex meshes be left meshes? | ||
158 | There is some problem with meshes and collisions | ||
159 | Hulls are not as detailed as meshes. Hulled vehicles insides are different shape. | ||
160 | Debounce avatar contact so legs don't keep folding up when standing. | ||
161 | Implement LSL physics controls. Like STATUS_ROTATE_X. | ||
162 | Add border extensions to terrain to help region crossings and objects leaving region. | ||
163 | Use a different capsule shape for avatar when sitting | ||
164 | LL uses a pyrimidal shape scaled by the avatar's bounding box | ||
165 | http://wiki.secondlife.com/wiki/File:Avmeshforms.png | ||
166 | Performance test with lots of avatars. Can BulletSim support a thousand? | ||
167 | Optimize collisions in C++: only send up to the object subscribed to collisions. | ||
168 | Use collision subscription and remove the collsion(A,B) and collision(B,A) | ||
169 | Check whether SimMotionState needs large if statement (see TODO). | ||
170 | Implement 'top colliders' info. | ||
171 | Avatar jump | ||
172 | Performance measurement and changes to make quicker. | ||
173 | Implement detailed physics stats (GetStats()). | ||
174 | Measure performance improvement from hulls | ||
175 | Test not using ghost objects for volume detect implementation. | ||
176 | Performance of closures and delegates for taint processing | ||
177 | Are there faster ways? | ||
178 | Is any slowdown introduced by the existing implementation significant? | ||
179 | Is there are more efficient method of implementing pre and post step actions? | ||
180 | See http://www.codeproject.com/Articles/29922/Weak-Events-in-C | ||
181 | Physics Arena central pyramid: why is one side permiable? | ||
182 | In SL, perfect spheres don't seem to have rolling friction. Add special case. | ||
183 | Enforce physical parameter min/max: | ||
184 | Gravity: [-1, 28] | ||
185 | Friction: [0, 255] | ||
186 | Density: [1, 22587] | ||
187 | Restitution [0, 1] | ||
188 | http://wiki.secondlife.com/wiki/Physics_Material_Settings_test | ||
189 | Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/31796/1.html | ||
190 | Keep avatar scaling correct. http://pennycow.blogspot.fr/2011/07/matter-of-scale.html | ||
191 | |||
192 | INTERNAL IMPROVEMENT/CLEANUP | ||
193 | ================================================= | ||
194 | Can the 'inTaintTime' flag be cleaned up and used? For instance, a call to | ||
195 | BSScene.TaintedObject() could immediately execute the callback if already in taint time. | ||
196 | Create the physical wrapper classes (BulletBody, BulletShape) by methods on | ||
197 | BSAPITemplate and make their actual implementation Bullet engine specific. | ||
198 | For the short term, just call the existing functions in ShapeCollection. | ||
199 | Consider moving prim/character body and shape destruction in destroy() | ||
200 | to postTimeTime rather than protecting all the potential sets that | ||
201 | might have been queued up. | ||
202 | Remove unused fields from ShapeData (not used in API2) | ||
203 | Remove unused fields from pinned memory shared parameter block | ||
204 | Create parameter variables in BSScene to replace same. | ||
205 | Breakout code for mesh/hull/compound/native into separate BSShape* classes | ||
206 | Standardize access to building and reference code. | ||
207 | The skeleton classes are in the sources but are not complete or linked in. | ||
208 | Make BSBody and BSShape real classes to centralize creation/changin/destruction | ||
209 | Convert state and parameter calls from BulletSimAPI direct calls to | ||
210 | calls on BSBody and BSShape | ||
211 | Generalize Dynamics and PID with standardized motors. | ||
212 | Generalize Linkset and vehicles into PropertyManagers | ||
213 | Methods for Refresh, RemoveBodyDependencies, RestoreBodyDependencies | ||
214 | Potentially add events for shape destruction, etc. | ||
215 | Better mechanism for resetting linkset set and vehicle parameters when body rebuilt. | ||
216 | BSPrim.CreateGeomAndObject is kludgy with the callbacks, etc. | ||
217 | Implement linkset by setting position of children when root updated. (LinksetManual) | ||
218 | Linkset implementation using manual prim movement. | ||
219 | LinkablePrim class? Would that simplify/centralize the linkset logic? | ||
220 | BSScene.UpdateParameterSet() is broken. How to set params on objects? | ||
221 | Add floating motor for BS_FLOATS_ON_WATER so prim and avatar will | ||
222 | bob at the water level. BSPrim.PositionSanityCheck() | ||
223 | Should taints check for existance or activeness of target? | ||
224 | When destroying linksets/etc, taints can be generated for objects that are | ||
225 | actually gone when the taint happens. Crashes don't happen because the taint closure | ||
226 | keeps the object from being freed, but that is just an accident. | ||
227 | Possibly have an 'active' flag that is checked by the taint processor? | ||
228 | Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones) | ||
229 | Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'? | ||
230 | There are TOO MANY interfaces from BulletSim core to Bullet itself | ||
231 | Think of something to eliminate one or more of the layers | ||
232 | |||
233 | THREADING | ||
234 | ================================================= | ||
235 | Do taint action immediately if not actually executing Bullet. | ||
236 | Add lock around Bullet execution and just do taint actions if simulation is not happening. | ||
237 | |||
238 | DONE DONE DONE DONE | ||
239 | ================================================= | ||
240 | Cleanup code in BSDynamics by using motors. (Resolution: started) | ||
241 | Consider implementing terrain with a mesh rather than heightmap. (Resolution: done) | ||
242 | Would have better and adjustable resolution. | ||
243 | Build terrain mesh so heighmap is height of the center of the square meter. | ||
244 | Resolution: NOT DONE: SL and ODE define meter square as being at one corner with one diagional. | ||
245 | Terrain as mesh. (Resolution: done) | ||
246 | How are static linksets seen by the physics engine? | ||
247 | Resolution: they are not linked in physics. When moved, all the children are repositioned. | ||
248 | Convert BSCharacter to use all API2 (Resolution: done) | ||
249 | Avatar pushing difficult (too heavy?) | ||
250 | Use asset service passed to BulletSim to get sculptie bodies, etc. (Resolution: done) | ||
251 | Remove old code in DLL (all non-API2 stuff). (Resolution: done) | ||
252 | Measurements of mega-physical prim performance (with graph) (Resolution: done, email) | ||
253 | Debug Bullet internal stats output (why is timing all wrong?) | ||
254 | Resolution: Bullet stats logging only works with a single instance of Bullet (one region). | ||
255 | Implement meshes or just verify that they work. (Resolution: they do!) | ||
256 | Do prim hash codes work for sculpties and meshes? (Resolution: yes) | ||
257 | Linkset implementation using compound shapes. (Resolution: implemented LinksetCompound) | ||
258 | Compound shapes will need the LocalID in the shapes and collision | ||
259 | processing to get it from there. | ||
260 | Light cycle not banking (Resolution: It doesn't. Banking is roll adding yaw.) | ||
261 | Package Bullet source mods for Bullet internal stats output | ||
262 | (Resolution: move code into WorldData.h rather than relying on patches) | ||
263 | Single prim vehicles don't seem to properly vehiclize. | ||
264 | (Resolution: mass was not getting set properly for single prim linksets) | ||
265 | Add material type linkage and input all the material property definitions. | ||
266 | Skeleton classes and table are in the sources but are not filled or used. | ||
267 | (Resolution: | ||
268 | Neb vehicle taking > 25ms of physics time!! | ||
269 | (Resolution: compound linksets were being rebuild WAY too often) | ||
270 | Avatar height off after unsitting (floats off ground) | ||
271 | Editting appearance then moving restores. | ||
272 | Must not be initializing height when recreating capsule after unsit. | ||
273 | (Resolution: confusion of scale vs size for native objects removed) | ||
274 | Light cycle falling over when driving (Resolution: implemented angularMotorUp) | ||
275 | Should vehicle angular/linear movement friction happen after all the components | ||
276 | or does it only apply to the basic movement? | ||
277 | (Resolution: friction added before returning newly computed motor value. | ||
278 | What is expected by some vehicles (turning up friction to moderate speed)) | ||
279 | Tune terrain/object friction to be closer to SL. | ||
280 | (Resolution: added material type with friction and resolution) | ||
281 | Smooth avatar movement with motor (DONE) | ||
282 | Should motor update be all at taint-time? (Yes, DONE) | ||
283 | Fix avatar slowly sliding when standing (zero motion when stopped) (DONE) | ||
284 | (Resolution: added BSVMotor for avatar starting and stopping) | ||
285 | llApplyImpulse() | ||
286 | Compare mass/movement in OS and SL. Calibrate actions. (DONE) | ||
287 | (Resolution: tested on SL and OS. AddForce scales the force for timestep) | ||
288 | llSetBuoyancy() (DONE) | ||
289 | (Resolution: Bullet resets object gravity when added to world. Moved set gravity) | ||
290 | Avatar density is WAY off. Compare and calibrate with what's in SL. (DONE) | ||
291 | (Resolution: set default density to 3.5 (from 60) which is closer to SL) | ||
292 | Redo BulletSimAPI to allow native C# implementation of Bullet option (DONE) | ||
293 | (Resolution: added BSAPITemplate and then interfaces for C++ Bullet and C# BulletXNA | ||
294 | Meshes rendering as bounding boxes (DONE) | ||
295 | (Resolution: Added test for mesh/sculpties in native shapes so it didn't think it was a box) | ||
296 | llMoveToTarget (Resolution: added simple motor to update the position.) | ||
297 | Angular motor direction is global coordinates rather than local coordinates (DONE) | ||
298 | Add vehicle collisions so IsColliding is properly reported. (DONE) | ||
299 | Needed for banking, limitMotorUp, movementLimiting, ... | ||
300 | (Resolution: added CollisionFlags.BS_VEHICLE_COLLISION and code to use it) | ||
301 | VehicleAddForce is not scaled by the simulation step but it is only | ||
302 | applied for one step. Should it be scaled? (DONE) | ||
303 | (Resolution: use force for timed things, Impulse for immediate, non-timed things) | ||
304 | Complete implemention of preStepActions (DONE) | ||
305 | Replace vehicle step call with prestep event. | ||
306 | Is there a need for postStepActions? postStepTaints? | ||
307 | Disable activity of passive linkset children. (DONE) | ||
308 | Since the linkset is a compound object, the old prims are left lying | ||
309 | around and need to be phantomized so they don't collide, ... | ||
310 | Remove HeightmapInfo from terrain specification (DONE) | ||
311 | Since C++ code does not need terrain height, this structure et al are not needed. | ||
312 | Surfboard go wonky when turning (DONE) | ||
313 | Angular motor direction is global coordinates rather than local coordinates? | ||
314 | (Resolution: made angular motor direction correct coordinate system) | ||
315 | Mantis 6040 script http://opensimulator.org/mantis/view.php?id=6040 (DONE) | ||
316 | Msg Kayaker on OSGrid when working | ||
317 | (Resolution: LINEAR_DIRECTION is in vehicle coords. Test script does the | ||
318 | same in SL as in OS/BulletSim) | ||
319 | Boats float low in the water (DONE) | ||
320 | Boats floating at proper level (DONE) | ||
321 | When is force introduced by SetForce removed? The prestep action could go forever. (DONE) | ||
322 | (Resolution: setForce registers a prestep action which keeps applying the force) \ No newline at end of file | ||
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs index 8de70ef..ba24aa7 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs | |||
@@ -2190,7 +2190,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2190 | convex = false; | 2190 | convex = false; |
2191 | try | 2191 | try |
2192 | { | 2192 | { |
2193 | _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, (int)LevelOfDetail.High, true,convex,false); | 2193 | _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, (int)LevelOfDetail.High, true,false,convex,false); |
2194 | } | 2194 | } |
2195 | catch | 2195 | catch |
2196 | { | 2196 | { |
@@ -2557,7 +2557,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2557 | 2557 | ||
2558 | try | 2558 | try |
2559 | { | 2559 | { |
2560 | mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, (int)LevelOfDetail.High, true, convex,false); | 2560 | mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, (int)LevelOfDetail.High, true, false,convex,false); |
2561 | } | 2561 | } |
2562 | catch | 2562 | catch |
2563 | { | 2563 | { |
diff --git a/OpenSim/Region/Physics/Manager/IMesher.cs b/OpenSim/Region/Physics/Manager/IMesher.cs index ecc2918..df980ab 100644 --- a/OpenSim/Region/Physics/Manager/IMesher.cs +++ b/OpenSim/Region/Physics/Manager/IMesher.cs | |||
@@ -37,7 +37,7 @@ namespace OpenSim.Region.Physics.Manager | |||
37 | { | 37 | { |
38 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod); | 38 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod); |
39 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical); | 39 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical); |
40 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde); | 40 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde); |
41 | IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex); | 41 | IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex); |
42 | void ReleaseMesh(IMesh mesh); | 42 | void ReleaseMesh(IMesh mesh); |
43 | void ExpireReleaseMeshs(); | 43 | void ExpireReleaseMeshs(); |
diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 9338130..e2789d6 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs | |||
@@ -349,17 +349,20 @@ namespace OpenSim.Region.Physics.Manager | |||
349 | } | 349 | } |
350 | 350 | ||
351 | /// <summary> | 351 | /// <summary> |
352 | /// Velocity of this actor. | 352 | /// The desired velocity of this actor. |
353 | /// </summary> | 353 | /// </summary> |
354 | /// <remarks> | 354 | /// <remarks> |
355 | /// Setting this provides a target velocity for physics scene updates. | 355 | /// Setting this provides a target velocity for physics scene updates. |
356 | /// Getting this returns the velocity calculated by physics scene updates, using factors such as target velocity, | 356 | /// Getting this returns the last set target. Fetch Velocity to get the current velocity. |
357 | /// time to accelerate and collisions. | ||
358 | /// </remarks> | 357 | /// </remarks> |
358 | protected Vector3 m_targetVelocity; | ||
359 | public virtual Vector3 TargetVelocity | 359 | public virtual Vector3 TargetVelocity |
360 | { | 360 | { |
361 | get { return Velocity; } | 361 | get { return m_targetVelocity; } |
362 | set { Velocity = value; } | 362 | set { |
363 | m_targetVelocity = value; | ||
364 | Velocity = m_targetVelocity; | ||
365 | } | ||
363 | } | 366 | } |
364 | 367 | ||
365 | public abstract Vector3 Velocity { get; set; } | 368 | public abstract Vector3 Velocity { get; set; } |
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs index 8587a2b..8ccfda5 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs | |||
@@ -30,7 +30,7 @@ using System.Collections.Generic; | |||
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using log4net; | 33 | using log4net; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | 35 | ||
36 | namespace OpenSim.Region.Physics.Manager | 36 | namespace OpenSim.Region.Physics.Manager |
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index d24ab2a..f82b597 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs | |||
@@ -97,13 +97,20 @@ namespace OpenSim.Region.Physics.Manager | |||
97 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 97 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
98 | 98 | ||
99 | /// <summary> | 99 | /// <summary> |
100 | /// Name of this scene. Useful in debug messages to distinguish one OdeScene instance from another. | 100 | /// A unique identifying string for this instance of the physics engine. |
101 | /// Useful in debug messages to distinguish one OdeScene instance from another. | ||
102 | /// Usually set to include the region name that the physics engine is acting for. | ||
101 | /// </summary> | 103 | /// </summary> |
102 | public string Name { get; protected set; } | 104 | public string Name { get; protected set; } |
103 | 105 | ||
106 | /// <summary> | ||
107 | /// A string identifying the family of this physics engine. Most common values returned | ||
108 | /// are "OpenDynamicsEngine" and "BulletSim" but others are possible. | ||
109 | /// </summary> | ||
110 | public string EngineType { get; protected set; } | ||
111 | |||
104 | // The only thing that should register for this event is the SceneGraph | 112 | // The only thing that should register for this event is the SceneGraph |
105 | // Anything else could cause problems. | 113 | // Anything else could cause problems. |
106 | |||
107 | public event physicsCrash OnPhysicsCrash; | 114 | public event physicsCrash OnPhysicsCrash; |
108 | 115 | ||
109 | public static PhysicsScene Null | 116 | public static PhysicsScene Null |
diff --git a/OpenSim/Region/Physics/Manager/ZeroMesher.cs b/OpenSim/Region/Physics/Manager/ZeroMesher.cs index 16846e6..80ecf66 100644 --- a/OpenSim/Region/Physics/Manager/ZeroMesher.cs +++ b/OpenSim/Region/Physics/Manager/ZeroMesher.cs | |||
@@ -64,16 +64,21 @@ namespace OpenSim.Region.Physics.Manager | |||
64 | { | 64 | { |
65 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) | 65 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) |
66 | { | 66 | { |
67 | return CreateMesh(primName, primShape, size, lod, false); | 67 | return CreateMesh(primName, primShape, size, lod, false, false); |
68 | } | 68 | } |
69 | 69 | ||
70 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex,bool forOde) | 70 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex,bool forOde) |
71 | { | 71 | { |
72 | return CreateMesh(primName, primShape, size, lod, false); | 72 | return CreateMesh(primName, primShape, size, lod, false); |
73 | } | 73 | } |
74 | 74 | ||
75 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) | 75 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) |
76 | { | 76 | { |
77 | return CreateMesh(primName, primShape, size, lod, false, false); | ||
78 | } | ||
79 | |||
80 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache) | ||
81 | { | ||
77 | // Remove the reference to the encoded JPEG2000 data so it can be GCed | 82 | // Remove the reference to the encoded JPEG2000 data so it can be GCed |
78 | primShape.SculptData = OpenMetaverse.Utils.EmptyBytes; | 83 | primShape.SculptData = OpenMetaverse.Utils.EmptyBytes; |
79 | 84 | ||
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index f629c4d..d181b78 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -321,6 +321,9 @@ namespace OpenSim.Region.Physics.Meshing | |||
321 | 321 | ||
322 | if (primShape.SculptData.Length <= 0) | 322 | if (primShape.SculptData.Length <= 0) |
323 | { | 323 | { |
324 | // XXX: At the moment we can not log here since ODEPrim, for instance, ends up triggering this | ||
325 | // method twice - once before it has loaded sculpt data from the asset service and once afterwards. | ||
326 | // The first time will always call with unloaded SculptData if this needs to be uploaded. | ||
324 | // m_log.ErrorFormat("[MESH]: asset data for {0} is zero length", primName); | 327 | // m_log.ErrorFormat("[MESH]: asset data for {0} is zero length", primName); |
325 | return false; | 328 | return false; |
326 | } | 329 | } |
@@ -699,16 +702,21 @@ namespace OpenSim.Region.Physics.Meshing | |||
699 | 702 | ||
700 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) | 703 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) |
701 | { | 704 | { |
702 | return CreateMesh(primName, primShape, size, lod, false); | 705 | return CreateMesh(primName, primShape, size, lod, false, true); |
703 | } | 706 | } |
704 | 707 | ||
705 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde) | 708 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde) |
706 | { | 709 | { |
707 | return CreateMesh(primName, primShape, size, lod, false); | 710 | return CreateMesh(primName, primShape, size, lod, false); |
708 | } | 711 | } |
709 | 712 | ||
710 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) | 713 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) |
711 | { | 714 | { |
715 | return CreateMesh(primName, primShape, size, lod, isPhysical, true); | ||
716 | } | ||
717 | |||
718 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache) | ||
719 | { | ||
712 | #if SPAM | 720 | #if SPAM |
713 | m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); | 721 | m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); |
714 | #endif | 722 | #endif |
@@ -718,9 +726,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
718 | 726 | ||
719 | // If this mesh has been created already, return it instead of creating another copy | 727 | // If this mesh has been created already, return it instead of creating another copy |
720 | // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory | 728 | // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory |
721 | key = primShape.GetMeshKey(size, lod); | 729 | if (shouldCache) |
722 | if (m_uniqueMeshes.TryGetValue(key, out mesh)) | 730 | { |
723 | return mesh; | 731 | key = primShape.GetMeshKey(size, lod); |
732 | if (m_uniqueMeshes.TryGetValue(key, out mesh)) | ||
733 | return mesh; | ||
734 | } | ||
724 | 735 | ||
725 | if (size.X < 0.01f) size.X = 0.01f; | 736 | if (size.X < 0.01f) size.X = 0.01f; |
726 | if (size.Y < 0.01f) size.Y = 0.01f; | 737 | if (size.Y < 0.01f) size.Y = 0.01f; |
@@ -743,7 +754,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
743 | // trim the vertex and triangle lists to free up memory | 754 | // trim the vertex and triangle lists to free up memory |
744 | mesh.TrimExcess(); | 755 | mesh.TrimExcess(); |
745 | 756 | ||
746 | m_uniqueMeshes.Add(key, mesh); | 757 | if (shouldCache) |
758 | { | ||
759 | m_uniqueMeshes.Add(key, mesh); | ||
760 | } | ||
747 | } | 761 | } |
748 | 762 | ||
749 | return mesh; | 763 | return mesh; |
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index a59f63f..d09aa62 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -3367,6 +3367,11 @@ Console.WriteLine(" JointCreateFixed"); | |||
3367 | _pbs.SculptData = new byte[asset.Data.Length]; | 3367 | _pbs.SculptData = new byte[asset.Data.Length]; |
3368 | asset.Data.CopyTo(_pbs.SculptData, 0); | 3368 | asset.Data.CopyTo(_pbs.SculptData, 0); |
3369 | // m_assetFailed = false; | 3369 | // m_assetFailed = false; |
3370 | |||
3371 | // m_log.DebugFormat( | ||
3372 | // "[ODE PRIM]: Received mesh/sculpt data asset {0} with {1} bytes for {2} at {3} in {4}", | ||
3373 | // _pbs.SculptTexture, _pbs.SculptData.Length, Name, _position, _parent_scene.Name); | ||
3374 | |||
3370 | m_taintshape = true; | 3375 | m_taintshape = true; |
3371 | _parent_scene.AddPhysicsActorTaint(this); | 3376 | _parent_scene.AddPhysicsActorTaint(this); |
3372 | } | 3377 | } |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 478dd95..07663b3 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -72,7 +72,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
72 | // http://opensimulator.org/mantis/view.php?id=2750). | 72 | // http://opensimulator.org/mantis/view.php?id=2750). |
73 | d.InitODE(); | 73 | d.InitODE(); |
74 | 74 | ||
75 | m_scene = new OdeScene(sceneIdentifier); | 75 | m_scene = new OdeScene(GetName(), sceneIdentifier); |
76 | } | 76 | } |
77 | 77 | ||
78 | return m_scene; | 78 | return m_scene; |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index d53bd90..02a0b15 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs | |||
@@ -526,11 +526,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
526 | /// These settings need to be tweaked 'exactly' right or weird stuff happens. | 526 | /// These settings need to be tweaked 'exactly' right or weird stuff happens. |
527 | /// </summary> | 527 | /// </summary> |
528 | /// <param value="name">Name of the scene. Useful in debug messages.</param> | 528 | /// <param value="name">Name of the scene. Useful in debug messages.</param> |
529 | public OdeScene(string name) | 529 | public OdeScene(string engineType, string name) |
530 | { | 530 | { |
531 | m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); | 531 | m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); |
532 | 532 | ||
533 | Name = name; | 533 | Name = name; |
534 | EngineType = engineType; | ||
534 | 535 | ||
535 | nearCallback = near; | 536 | nearCallback = near; |
536 | triCallback = TriCallback; | 537 | triCallback = TriCallback; |
diff --git a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs index cbc6b95..16404c6 100644 --- a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs +++ b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs | |||
@@ -32,13 +32,14 @@ using OpenMetaverse; | |||
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
34 | using OpenSim.Region.Physics.OdePlugin; | 34 | using OpenSim.Region.Physics.OdePlugin; |
35 | using OpenSim.Tests.Common; | ||
35 | using log4net; | 36 | using log4net; |
36 | using System.Reflection; | 37 | using System.Reflection; |
37 | 38 | ||
38 | namespace OpenSim.Region.Physics.OdePlugin.Tests | 39 | namespace OpenSim.Region.Physics.OdePlugin.Tests |
39 | { | 40 | { |
40 | [TestFixture] | 41 | [TestFixture] |
41 | public class ODETestClass | 42 | public class ODETestClass : OpenSimTestCase |
42 | { | 43 | { |
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 45 | ||
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs index e6b42e6..ed086dd 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
49 | 49 | ||
50 | public PhysicsScene GetScene(string sceneIdentifier) | 50 | public PhysicsScene GetScene(string sceneIdentifier) |
51 | { | 51 | { |
52 | return new POSScene(sceneIdentifier); | 52 | return new POSScene(GetName(), sceneIdentifier); |
53 | } | 53 | } |
54 | 54 | ||
55 | public string GetName() | 55 | public string GetName() |
diff --git a/OpenSim/Region/Physics/POSPlugin/POSScene.cs b/OpenSim/Region/Physics/POSPlugin/POSScene.cs index 2f24a50..d30d482 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSScene.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSScene.cs | |||
@@ -43,8 +43,10 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
43 | 43 | ||
44 | //protected internal string sceneIdentifier; | 44 | //protected internal string sceneIdentifier; |
45 | 45 | ||
46 | public POSScene(String _sceneIdentifier) | 46 | public POSScene(string engineType, String _sceneIdentifier) |
47 | { | 47 | { |
48 | EngineType = engineType; | ||
49 | Name = EngineType + "/" + _sceneIdentifier; | ||
48 | //sceneIdentifier = _sceneIdentifier; | 50 | //sceneIdentifier = _sceneIdentifier; |
49 | } | 51 | } |
50 | 52 | ||
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs index 6e1a105..00cbfbd 100644 --- a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs | |||
@@ -1031,12 +1031,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
1031 | 1031 | ||
1032 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) | 1032 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) |
1033 | { | 1033 | { |
1034 | return CreateMesh(primName, primShape, size, lod, false,false,false); | 1034 | return CreateMesh(primName, primShape, size, lod, false,false,false,false); |
1035 | } | 1035 | } |
1036 | 1036 | ||
1037 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) | 1037 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) |
1038 | { | 1038 | { |
1039 | return CreateMesh(primName, primShape, size, lod, false,false,false); | 1039 | return CreateMesh(primName, primShape, size, lod, false,false,false,false); |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) | 1042 | public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) |
@@ -1080,7 +1080,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
1080 | 1080 | ||
1081 | private static Vector3 m_MeshUnitSize = new Vector3(1.0f, 1.0f, 1.0f); | 1081 | private static Vector3 m_MeshUnitSize = new Vector3(1.0f, 1.0f, 1.0f); |
1082 | 1082 | ||
1083 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde) | 1083 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde) |
1084 | { | 1084 | { |
1085 | #if SPAM | 1085 | #if SPAM |
1086 | m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); | 1086 | m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs index 5030cec..0df71eb 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs | |||
@@ -448,7 +448,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
448 | else | 448 | else |
449 | { | 449 | { |
450 | repData.meshState = MeshState.needMesh; | 450 | repData.meshState = MeshState.needMesh; |
451 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true); | 451 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, false, convex, true); |
452 | if (mesh == null) | 452 | if (mesh == null) |
453 | { | 453 | { |
454 | repData.meshState = MeshState.MeshFailed; | 454 | repData.meshState = MeshState.MeshFailed; |
@@ -513,7 +513,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
513 | clod = (int)LevelOfDetail.Low; | 513 | clod = (int)LevelOfDetail.Low; |
514 | } | 514 | } |
515 | 515 | ||
516 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true); | 516 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, false, convex, true); |
517 | 517 | ||
518 | if (mesh == null) | 518 | if (mesh == null) |
519 | { | 519 | { |
@@ -929,4 +929,4 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
929 | repData.actor.Name); | 929 | repData.actor.Name); |
930 | } | 930 | } |
931 | } | 931 | } |
932 | } \ No newline at end of file | 932 | } |
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs index 2027ca6..d2323f5 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs | |||
@@ -26,9 +26,11 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Threading; | ||
29 | using OpenMetaverse; | 30 | using OpenMetaverse; |
30 | using OpenSim.Framework; | 31 | using OpenSim.Framework; |
31 | using OpenSim.Region.Framework.Scenes; | 32 | using OpenSim.Region.Framework.Scenes; |
33 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | 34 | ||
33 | namespace OpenSim.Region.ScriptEngine.Interfaces | 35 | namespace OpenSim.Region.ScriptEngine.Interfaces |
34 | { | 36 | { |
@@ -38,11 +40,12 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
38 | /// Initialize the API | 40 | /// Initialize the API |
39 | /// </summary> | 41 | /// </summary> |
40 | /// <remarks> | 42 | /// <remarks> |
41 | /// Each API has an identifier, which is used to load the | 43 | /// Each API has an identifier, which is used to load the proper runtime assembly at load time. |
42 | /// proper runtime assembly at load time. | 44 | /// <param name='scriptEngine'>/param> |
43 | /// <param name='engine'>/param> | 45 | /// <param name='host'>/param> |
44 | /// <param name='part'></param> | 46 | /// <param name='item'>/param> |
45 | /// <param name='item'></param> | 47 | /// <param name='coopSleepHandle'>/param> |
46 | void Initialize(IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item); | 48 | void Initialize( |
49 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle); | ||
47 | } | 50 | } |
48 | } \ No newline at end of file | 51 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index b04f6b6..f68612c 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs | |||
@@ -28,9 +28,11 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Threading; | ||
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
32 | using log4net; | 33 | using log4net; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Region.ScriptEngine.Shared; | 36 | using OpenSim.Region.ScriptEngine.Shared; |
35 | using OpenSim.Region.ScriptEngine.Interfaces; | 37 | using OpenSim.Region.ScriptEngine.Interfaces; |
36 | 38 | ||
@@ -59,6 +61,18 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
59 | public interface IScriptInstance | 61 | public interface IScriptInstance |
60 | { | 62 | { |
61 | /// <summary> | 63 | /// <summary> |
64 | /// Debug level for this script instance. | ||
65 | /// </summary> | ||
66 | /// <remarks> | ||
67 | /// Level == 0, no extra data is logged. | ||
68 | /// Level >= 1, state changes are logged. | ||
69 | /// Level >= 2, event firing is logged. | ||
70 | /// <value> | ||
71 | /// The debug level. | ||
72 | /// </value> | ||
73 | int DebugLevel { get; set; } | ||
74 | |||
75 | /// <summary> | ||
62 | /// Is the script currently running? | 76 | /// Is the script currently running? |
63 | /// </summary> | 77 | /// </summary> |
64 | bool Running { get; set; } | 78 | bool Running { get; set; } |
@@ -93,6 +107,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
93 | /// </summary> | 107 | /// </summary> |
94 | long MeasurementPeriodExecutionTime { get; } | 108 | long MeasurementPeriodExecutionTime { get; } |
95 | 109 | ||
110 | /// <summary> | ||
111 | /// Scene part in which this script instance is contained. | ||
112 | /// </summary> | ||
113 | SceneObjectPart Part { get; } | ||
114 | |||
96 | IScriptEngine Engine { get; } | 115 | IScriptEngine Engine { get; } |
97 | UUID AppDomain { get; set; } | 116 | UUID AppDomain { get; set; } |
98 | string PrimName { get; } | 117 | string PrimName { get; } |
@@ -112,8 +131,24 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
112 | 131 | ||
113 | uint LocalID { get; } | 132 | uint LocalID { get; } |
114 | UUID AssetID { get; } | 133 | UUID AssetID { get; } |
134 | |||
135 | /// <summary> | ||
136 | /// Inventory item containing the script used. | ||
137 | /// </summary> | ||
138 | TaskInventoryItem ScriptTask { get; } | ||
139 | |||
115 | Queue EventQueue { get; } | 140 | Queue EventQueue { get; } |
116 | 141 | ||
142 | /// <summary> | ||
143 | /// Number of events queued for processing. | ||
144 | /// </summary> | ||
145 | long EventsQueued { get; } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Number of events processed by this script instance. | ||
149 | /// </summary> | ||
150 | long EventsProcessed { get; } | ||
151 | |||
117 | void ClearQueue(); | 152 | void ClearQueue(); |
118 | int StartParam { get; set; } | 153 | int StartParam { get; set; } |
119 | 154 | ||
@@ -125,7 +160,13 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
125 | /// <summary> | 160 | /// <summary> |
126 | /// Stop the script instance. | 161 | /// Stop the script instance. |
127 | /// </summary> | 162 | /// </summary> |
163 | /// <remarks> | ||
164 | /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise | ||
165 | /// there is a danger that it will self-abort and not complete the reset. | ||
166 | /// </remarks> | ||
128 | /// <param name="timeout"></param> | 167 | /// <param name="timeout"></param> |
168 | /// How many milliseconds we will wait for an existing script event to finish before | ||
169 | /// forcibly aborting that event. | ||
129 | /// <returns>true if the script was successfully stopped, false otherwise</returns> | 170 | /// <returns>true if the script was successfully stopped, false otherwise</returns> |
130 | bool Stop(int timeout); | 171 | bool Stop(int timeout); |
131 | 172 | ||
@@ -147,8 +188,31 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
147 | object EventProcessor(); | 188 | object EventProcessor(); |
148 | 189 | ||
149 | int EventTime(); | 190 | int EventTime(); |
150 | void ResetScript(); | 191 | |
192 | /// <summary> | ||
193 | /// Reset the script. | ||
194 | /// </summary> | ||
195 | /// <remarks> | ||
196 | /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise | ||
197 | /// there is a danger that it will self-abort and not complete the reset. Such a thread must call | ||
198 | /// ApiResetScript() instead. | ||
199 | /// </remarks> | ||
200 | /// <param name='timeout'> | ||
201 | /// How many milliseconds we will wait for an existing script event to finish before | ||
202 | /// forcibly aborting that event prior to script reset. | ||
203 | /// </param> | ||
204 | void ResetScript(int timeout); | ||
205 | |||
206 | /// <summary> | ||
207 | /// Reset the script. | ||
208 | /// </summary> | ||
209 | /// <remarks> | ||
210 | /// This must not be called by any thread other than the one executing the scripts current event. This is | ||
211 | /// because there is no wait or abort logic if another thread is in the middle of processing a script event. | ||
212 | /// Such an external thread should use ResetScript() instead. | ||
213 | /// </remarks> | ||
151 | void ApiResetScript(); | 214 | void ApiResetScript(); |
215 | |||
152 | Dictionary<string, object> GetVars(); | 216 | Dictionary<string, object> GetVars(); |
153 | void SetVars(Dictionary<string, object> vars); | 217 | void SetVars(Dictionary<string, object> vars); |
154 | DetectParams GetDetectParams(int idx); | 218 | DetectParams GetDetectParams(int idx); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs index b5fa6de..d03955b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Threading; | ||
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using System.Collections; | 31 | using System.Collections; |
31 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
@@ -62,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
62 | internal TaskInventoryItem m_item; | 63 | internal TaskInventoryItem m_item; |
63 | internal bool m_CMFunctionsEnabled = false; | 64 | internal bool m_CMFunctionsEnabled = false; |
64 | 65 | ||
65 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 66 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle) |
66 | { | 67 | { |
67 | m_ScriptEngine = ScriptEngine; | 68 | m_ScriptEngine = ScriptEngine; |
68 | m_host = host; | 69 | m_host = host; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 0562c7f..9df04df 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -87,10 +87,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
87 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi | 87 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi |
88 | { | 88 | { |
89 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 89 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
90 | |||
90 | protected IScriptEngine m_ScriptEngine; | 91 | protected IScriptEngine m_ScriptEngine; |
91 | protected SceneObjectPart m_host; | 92 | protected SceneObjectPart m_host; |
92 | 93 | ||
93 | /// <summary> | 94 | /// <summary> |
95 | /// Used for script sleeps when we are using co-operative script termination. | ||
96 | /// </summary> | ||
97 | /// <remarks>null if co-operative script termination is not active</remarks> | ||
98 | EventWaitHandle m_coopSleepHandle; | ||
99 | |||
100 | /// <summary> | ||
94 | /// The item that hosts this script | 101 | /// The item that hosts this script |
95 | /// </summary> | 102 | /// </summary> |
96 | protected TaskInventoryItem m_item; | 103 | protected TaskInventoryItem m_item; |
@@ -100,6 +107,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
100 | protected float m_ScriptDelayFactor = 1.0f; | 107 | protected float m_ScriptDelayFactor = 1.0f; |
101 | protected float m_ScriptDistanceFactor = 1.0f; | 108 | protected float m_ScriptDistanceFactor = 1.0f; |
102 | protected float m_MinTimerInterval = 0.5f; | 109 | protected float m_MinTimerInterval = 0.5f; |
110 | protected float m_recoilScaleFactor = 0.0f; | ||
103 | 111 | ||
104 | protected DateTime m_timer = DateTime.Now; | 112 | protected DateTime m_timer = DateTime.Now; |
105 | protected bool m_waitingForScriptAnswer = false; | 113 | protected bool m_waitingForScriptAnswer = false; |
@@ -141,33 +149,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
141 | {"TURNRIGHT", "Turning Right"} | 149 | {"TURNRIGHT", "Turning Right"} |
142 | }; | 150 | }; |
143 | 151 | ||
144 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 152 | public void Initialize( |
153 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle) | ||
145 | { | 154 | { |
146 | /* | ||
147 | m_ShoutSayTimer = new Timer(1000); | ||
148 | m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed; | ||
149 | m_ShoutSayTimer.AutoReset = true; | ||
150 | m_ShoutSayTimer.Start(); | ||
151 | */ | ||
152 | m_lastSayShoutCheck = DateTime.UtcNow; | 155 | m_lastSayShoutCheck = DateTime.UtcNow; |
153 | 156 | ||
154 | m_ScriptEngine = ScriptEngine; | 157 | m_ScriptEngine = scriptEngine; |
155 | m_host = host; | 158 | m_host = host; |
156 | m_item = item; | 159 | m_item = item; |
157 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | 160 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); |
161 | m_coopSleepHandle = coopSleepHandle; | ||
158 | 162 | ||
159 | LoadLimits(); // read script limits from config. | 163 | LoadConfig(); |
160 | 164 | ||
161 | m_TransferModule = | 165 | m_TransferModule = |
162 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); | 166 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); |
163 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); | 167 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); |
164 | m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>(); | 168 | m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>(); |
165 | 169 | ||
166 | AsyncCommands = new AsyncCommandManager(ScriptEngine); | 170 | AsyncCommands = new AsyncCommandManager(m_ScriptEngine); |
167 | } | 171 | } |
168 | 172 | ||
169 | /* load configuration items that affect script, object and run-time behavior. */ | 173 | /// <summary> |
170 | private void LoadLimits() | 174 | /// Load configuration items that affect script, object and run-time behavior. */ |
175 | /// </summary> | ||
176 | private void LoadConfig() | ||
171 | { | 177 | { |
172 | m_ScriptDelayFactor = | 178 | m_ScriptDelayFactor = |
173 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 179 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); |
@@ -181,12 +187,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
181 | m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); | 187 | m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); |
182 | if (m_notecardLineReadCharsMax > 65535) | 188 | if (m_notecardLineReadCharsMax > 65535) |
183 | m_notecardLineReadCharsMax = 65535; | 189 | m_notecardLineReadCharsMax = 65535; |
190 | |||
184 | // load limits for particular subsystems. | 191 | // load limits for particular subsystems. |
185 | IConfig SMTPConfig; | 192 | IConfig SMTPConfig; |
186 | if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) { | 193 | if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) { |
187 | // there's an smtp config, so load in the snooze time. | 194 | // there's an smtp config, so load in the snooze time. |
188 | EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); | 195 | EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); |
189 | } | 196 | } |
197 | |||
198 | // Rezzing an object with a velocity can create recoil. This feature seems to have been | ||
199 | // removed from recent versions of SL. The code computes recoil (vel*mass) and scales | ||
200 | // it by this factor. May be zero to turn off recoil all together. | ||
201 | m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); | ||
190 | } | 202 | } |
191 | 203 | ||
192 | public override Object InitializeLifetimeService() | 204 | public override Object InitializeLifetimeService() |
@@ -207,7 +219,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
207 | delay = (int)((float)delay * m_ScriptDelayFactor); | 219 | delay = (int)((float)delay * m_ScriptDelayFactor); |
208 | if (delay == 0) | 220 | if (delay == 0) |
209 | return; | 221 | return; |
210 | System.Threading.Thread.Sleep(delay); | 222 | |
223 | Sleep(delay); | ||
224 | } | ||
225 | |||
226 | protected virtual void Sleep(int delay) | ||
227 | { | ||
228 | if (m_coopSleepHandle == null) | ||
229 | System.Threading.Thread.Sleep(delay); | ||
230 | else if (m_coopSleepHandle.WaitOne(delay)) | ||
231 | throw new ScriptCoopStopException(); | ||
211 | } | 232 | } |
212 | 233 | ||
213 | public Scene World | 234 | public Scene World |
@@ -1483,19 +1504,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1483 | return 0; | 1504 | return 0; |
1484 | 1505 | ||
1485 | case ScriptBaseClass.STATUS_ROTATE_X: | 1506 | case ScriptBaseClass.STATUS_ROTATE_X: |
1486 | if (m_host.GetAxisRotation(2) == 2) | 1507 | // if (m_host.GetAxisRotation(2) != 0) |
1508 | if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0) | ||
1487 | return 1; | 1509 | return 1; |
1488 | else | 1510 | else |
1489 | return 0; | 1511 | return 0; |
1490 | 1512 | ||
1491 | case ScriptBaseClass.STATUS_ROTATE_Y: | 1513 | case ScriptBaseClass.STATUS_ROTATE_Y: |
1492 | if (m_host.GetAxisRotation(4) == 4) | 1514 | if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0) |
1493 | return 1; | 1515 | return 1; |
1494 | else | 1516 | else |
1495 | return 0; | 1517 | return 0; |
1496 | 1518 | ||
1497 | case ScriptBaseClass.STATUS_ROTATE_Z: | 1519 | case ScriptBaseClass.STATUS_ROTATE_Z: |
1498 | if (m_host.GetAxisRotation(8) == 8) | 1520 | if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0) |
1499 | return 1; | 1521 | return 1; |
1500 | else | 1522 | else |
1501 | return 0; | 1523 | return 0; |
@@ -3139,11 +3161,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3139 | 3161 | ||
3140 | PhysicsActor pa = new_group.RootPart.PhysActor; | 3162 | PhysicsActor pa = new_group.RootPart.PhysActor; |
3141 | 3163 | ||
3164 | //Recoil. | ||
3142 | if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) | 3165 | if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) |
3143 | { | 3166 | { |
3144 | float groupmass = new_group.GetMass(); | 3167 | float groupmass = new_group.GetMass(); |
3145 | vel *= -groupmass; | 3168 | Vector3 recoil = -vel * groupmass * m_recoilScaleFactor; |
3146 | llApplyImpulse(vel, 0); | 3169 | if (recoil != Vector3.Zero) |
3170 | { | ||
3171 | llApplyImpulse(recoil, 0); | ||
3172 | } | ||
3147 | } | 3173 | } |
3148 | // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) | 3174 | // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) |
3149 | return; | 3175 | return; |
@@ -3218,7 +3244,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3218 | { | 3244 | { |
3219 | // m_log.Info("llSleep snoozing " + sec + "s."); | 3245 | // m_log.Info("llSleep snoozing " + sec + "s."); |
3220 | m_host.AddScriptLPS(1); | 3246 | m_host.AddScriptLPS(1); |
3221 | Thread.Sleep((int)(sec * 1000)); | 3247 | |
3248 | Sleep((int)(sec * 1000)); | ||
3222 | } | 3249 | } |
3223 | 3250 | ||
3224 | public LSL_Float llGetMass() | 3251 | public LSL_Float llGetMass() |
@@ -3320,7 +3347,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3320 | /// <summary> | 3347 | /// <summary> |
3321 | /// Attach the object containing this script to the avatar that owns it. | 3348 | /// Attach the object containing this script to the avatar that owns it. |
3322 | /// </summary> | 3349 | /// </summary> |
3323 | /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param> | 3350 | /// <param name='attachmentPoint'> |
3351 | /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>) | ||
3352 | /// </param> | ||
3324 | /// <returns>true if the attach suceeded, false if it did not</returns> | 3353 | /// <returns>true if the attach suceeded, false if it did not</returns> |
3325 | public bool AttachToAvatar(int attachmentPoint) | 3354 | public bool AttachToAvatar(int attachmentPoint) |
3326 | { | 3355 | { |
@@ -3678,7 +3707,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3678 | if (animID == UUID.Zero) | 3707 | if (animID == UUID.Zero) |
3679 | presence.Animator.RemoveAnimation(anim); | 3708 | presence.Animator.RemoveAnimation(anim); |
3680 | else | 3709 | else |
3681 | presence.Animator.RemoveAnimation(animID); | 3710 | presence.Animator.RemoveAnimation(animID, true); |
3682 | } | 3711 | } |
3683 | } | 3712 | } |
3684 | } | 3713 | } |
@@ -3751,21 +3780,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3751 | } | 3780 | } |
3752 | else | 3781 | else |
3753 | { | 3782 | { |
3754 | bool sitting = false; | 3783 | if (m_host.ParentGroup.GetSittingAvatars().Contains(agentID)) |
3755 | if (m_host.SitTargetAvatar == agentID) | ||
3756 | { | ||
3757 | sitting = true; | ||
3758 | } | ||
3759 | else | ||
3760 | { | ||
3761 | foreach (SceneObjectPart p in m_host.ParentGroup.Parts) | ||
3762 | { | ||
3763 | if (p.SitTargetAvatar == agentID) | ||
3764 | sitting = true; | ||
3765 | } | ||
3766 | } | ||
3767 | |||
3768 | if (sitting) | ||
3769 | { | 3784 | { |
3770 | // When agent is sitting, certain permissions are implicit if requested from sitting agent | 3785 | // When agent is sitting, certain permissions are implicit if requested from sitting agent |
3771 | implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | 3786 | implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | |
@@ -3807,7 +3822,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3807 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | 3822 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); |
3808 | if (npcModule != null && npcModule.IsNPC(agentID, World)) | 3823 | if (npcModule != null && npcModule.IsNPC(agentID, World)) |
3809 | { | 3824 | { |
3810 | if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID) | 3825 | if (npcModule.CheckPermissions(agentID, m_host.OwnerID)) |
3811 | { | 3826 | { |
3812 | lock (m_host.TaskInventory) | 3827 | lock (m_host.TaskInventory) |
3813 | { | 3828 | { |
@@ -4182,62 +4197,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4182 | public LSL_String llGetLinkName(int linknum) | 4197 | public LSL_String llGetLinkName(int linknum) |
4183 | { | 4198 | { |
4184 | m_host.AddScriptLPS(1); | 4199 | m_host.AddScriptLPS(1); |
4185 | // simplest case, this prims link number | ||
4186 | if (linknum == m_host.LinkNum || linknum == ScriptBaseClass.LINK_THIS) | ||
4187 | return m_host.Name; | ||
4188 | |||
4189 | // parse for sitting avatare-names | ||
4190 | List<String> nametable = new List<String>(); | ||
4191 | World.ForEachRootScenePresence(delegate(ScenePresence presence) | ||
4192 | { | ||
4193 | SceneObjectPart sitPart = presence.ParentPart; | ||
4194 | if (sitPart != null && m_host.ParentGroup.ContainsPart(sitPart.LocalId)) | ||
4195 | nametable.Add(presence.ControllingClient.Name); | ||
4196 | }); | ||
4197 | 4200 | ||
4198 | int totalprims = m_host.ParentGroup.PrimCount + nametable.Count; | 4201 | if (linknum < 0) |
4199 | if (totalprims > m_host.ParentGroup.PrimCount) | ||
4200 | { | 4202 | { |
4201 | // sitting Avatar-Name with negativ linknum / SinglePrim | 4203 | if (linknum == ScriptBaseClass.LINK_THIS) |
4202 | if (linknum < 0 && m_host.ParentGroup.PrimCount == 1 && nametable.Count == 1) | ||
4203 | return nametable[0]; | ||
4204 | // Prim-Name / SinglePrim Sitting Avatar | ||
4205 | if (linknum == 1 && m_host.ParentGroup.PrimCount == 1 && nametable.Count == 1) | ||
4206 | return m_host.Name; | 4204 | return m_host.Name; |
4207 | // LinkNumber > of Real PrimSet = AvatarName | 4205 | else |
4208 | if (linknum > m_host.ParentGroup.PrimCount && linknum <= totalprims) | 4206 | return ScriptBaseClass.NULL_KEY; |
4209 | return nametable[totalprims - linknum]; | ||
4210 | } | 4207 | } |
4211 | 4208 | ||
4212 | // Single prim | 4209 | int actualPrimCount = m_host.ParentGroup.PrimCount; |
4213 | if (m_host.LinkNum == 0) | 4210 | List<UUID> sittingAvatarIds = m_host.ParentGroup.GetSittingAvatars(); |
4211 | int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count; | ||
4212 | |||
4213 | // Special case for a single prim. In this case the linknum is zero. However, this will not match a single | ||
4214 | // prim that has any avatars sat upon it (in which case the root prim is link 1). | ||
4215 | if (linknum == 0) | ||
4214 | { | 4216 | { |
4215 | if (linknum == 0 || linknum == ScriptBaseClass.LINK_ROOT) | 4217 | if (actualPrimCount == 1 && sittingAvatarIds.Count == 0) |
4216 | return m_host.Name; | 4218 | return m_host.Name; |
4217 | else | ||
4218 | return UUID.Zero.ToString(); | ||
4219 | } | ||
4220 | 4219 | ||
4221 | // Link set | 4220 | return ScriptBaseClass.NULL_KEY; |
4222 | SceneObjectPart part = null; | 4221 | } |
4223 | if (m_host.LinkNum == 1) // this is the Root prim | 4222 | // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but |
4223 | // here we must match 1 (ScriptBaseClass.LINK_ROOT). | ||
4224 | else if (linknum == 1 && actualPrimCount == 1) | ||
4224 | { | 4225 | { |
4225 | if (linknum < 0) | 4226 | if (sittingAvatarIds.Count > 0) |
4226 | part = m_host.ParentGroup.GetLinkNumPart(2); | 4227 | return m_host.ParentGroup.RootPart.Name; |
4227 | else | 4228 | else |
4228 | part = m_host.ParentGroup.GetLinkNumPart(linknum); | 4229 | return ScriptBaseClass.NULL_KEY; |
4229 | } | 4230 | } |
4230 | else // this is a child prim | 4231 | else if (linknum <= adjustedPrimCount) |
4231 | { | 4232 | { |
4232 | if (linknum < 2) | 4233 | if (linknum <= actualPrimCount) |
4233 | part = m_host.ParentGroup.GetLinkNumPart(1); | 4234 | { |
4235 | return m_host.ParentGroup.GetLinkNumPart(linknum).Name; | ||
4236 | } | ||
4234 | else | 4237 | else |
4235 | part = m_host.ParentGroup.GetLinkNumPart(linknum); | 4238 | { |
4239 | ScenePresence sp = World.GetScenePresence(sittingAvatarIds[linknum - actualPrimCount - 1]); | ||
4240 | if (sp != null) | ||
4241 | return sp.Name; | ||
4242 | else | ||
4243 | return ScriptBaseClass.NULL_KEY; | ||
4244 | } | ||
4236 | } | 4245 | } |
4237 | if (part != null) | ||
4238 | return part.Name; | ||
4239 | else | 4246 | else |
4240 | return UUID.Zero.ToString(); | 4247 | { |
4248 | return ScriptBaseClass.NULL_KEY; | ||
4249 | } | ||
4241 | } | 4250 | } |
4242 | 4251 | ||
4243 | public LSL_Integer llGetInventoryNumber(int type) | 4252 | public LSL_Integer llGetInventoryNumber(int type) |
@@ -5850,9 +5859,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5850 | } | 5859 | } |
5851 | 5860 | ||
5852 | /// <summary> | 5861 | /// <summary> |
5853 | /// Insert the list identified by <src> into the | 5862 | /// Insert the list identified by <paramref name="src"/> into the |
5854 | /// list designated by <dest> such that the first | 5863 | /// list designated by <paramref name="dest"/> such that the first |
5855 | /// new element has the index specified by <index> | 5864 | /// new element has the index specified by <paramref name="index"/> |
5856 | /// </summary> | 5865 | /// </summary> |
5857 | 5866 | ||
5858 | public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index) | 5867 | public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index) |
@@ -6218,13 +6227,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6218 | if (parcelOwned && land.LandData.OwnerID == id || | 6227 | if (parcelOwned && land.LandData.OwnerID == id || |
6219 | parcel && land.LandData.GlobalID == id) | 6228 | parcel && land.LandData.GlobalID == id) |
6220 | { | 6229 | { |
6221 | result.Add(ssp.UUID.ToString()); | 6230 | result.Add(new LSL_Key(ssp.UUID.ToString())); |
6222 | } | 6231 | } |
6223 | } | 6232 | } |
6224 | } | 6233 | } |
6225 | else | 6234 | else |
6226 | { | 6235 | { |
6227 | result.Add(ssp.UUID.ToString()); | 6236 | result.Add(new LSL_Key(ssp.UUID.ToString())); |
6228 | } | 6237 | } |
6229 | } | 6238 | } |
6230 | // Maximum of 100 results | 6239 | // Maximum of 100 results |
@@ -6685,6 +6694,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6685 | ps.BurstSpeedMax = 1.0f; | 6694 | ps.BurstSpeedMax = 1.0f; |
6686 | ps.BurstRate = 0.1f; | 6695 | ps.BurstRate = 0.1f; |
6687 | ps.PartMaxAge = 10.0f; | 6696 | ps.PartMaxAge = 10.0f; |
6697 | ps.BurstPartCount = 1; | ||
6688 | return ps; | 6698 | return ps; |
6689 | } | 6699 | } |
6690 | 6700 | ||
@@ -6706,10 +6716,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6706 | SetParticleSystem(m_host, rules); | 6716 | SetParticleSystem(m_host, rules); |
6707 | } | 6717 | } |
6708 | 6718 | ||
6709 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules) | 6719 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules) |
6710 | { | 6720 | { |
6711 | |||
6712 | |||
6713 | if (rules.Length == 0) | 6721 | if (rules.Length == 0) |
6714 | { | 6722 | { |
6715 | part.RemoveParticleSystem(); | 6723 | part.RemoveParticleSystem(); |
@@ -7369,6 +7377,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7369 | public void llCloseRemoteDataChannel(string channel) | 7377 | public void llCloseRemoteDataChannel(string channel) |
7370 | { | 7378 | { |
7371 | m_host.AddScriptLPS(1); | 7379 | m_host.AddScriptLPS(1); |
7380 | |||
7381 | IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); | ||
7382 | if (xmlRpcRouter != null) | ||
7383 | { | ||
7384 | xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID); | ||
7385 | } | ||
7386 | |||
7372 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); | 7387 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); |
7373 | if (xmlrpcMod != null) | 7388 | if (xmlrpcMod != null) |
7374 | xmlrpcMod.CloseXMLRPCChannel((UUID)channel); | 7389 | xmlrpcMod.CloseXMLRPCChannel((UUID)channel); |
@@ -11515,6 +11530,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11515 | case ScriptBaseClass.OBJECT_PHYSICS_COST: | 11530 | case ScriptBaseClass.OBJECT_PHYSICS_COST: |
11516 | ret.Add(new LSL_Float(0)); | 11531 | ret.Add(new LSL_Float(0)); |
11517 | break; | 11532 | break; |
11533 | case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding | ||
11534 | ret.Add(new LSL_Float(0)); | ||
11535 | break; | ||
11536 | case ScriptBaseClass.OBJECT_ROOT: | ||
11537 | SceneObjectPart p = av.ParentPart; | ||
11538 | if (p != null) | ||
11539 | { | ||
11540 | ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString())); | ||
11541 | } | ||
11542 | else | ||
11543 | { | ||
11544 | ret.Add(new LSL_String(id)); | ||
11545 | } | ||
11546 | break; | ||
11547 | case ScriptBaseClass.OBJECT_ATTACHED_POINT: | ||
11548 | ret.Add(new LSL_Integer(0)); | ||
11549 | break; | ||
11550 | case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding | ||
11551 | ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR)); | ||
11552 | break; | ||
11553 | case ScriptBaseClass.OBJECT_PHYSICS: | ||
11554 | ret.Add(new LSL_Integer(0)); | ||
11555 | break; | ||
11556 | case ScriptBaseClass.OBJECT_PHANTOM: | ||
11557 | ret.Add(new LSL_Integer(0)); | ||
11558 | break; | ||
11559 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: | ||
11560 | ret.Add(new LSL_Integer(0)); | ||
11561 | break; | ||
11518 | default: | 11562 | default: |
11519 | // Invalid or unhandled constant. | 11563 | // Invalid or unhandled constant. |
11520 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); | 11564 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); |
@@ -11606,6 +11650,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11606 | // The value returned in SL for normal prims is prim count | 11650 | // The value returned in SL for normal prims is prim count |
11607 | ret.Add(new LSL_Float(obj.PhysicsCost)); | 11651 | ret.Add(new LSL_Float(obj.PhysicsCost)); |
11608 | break; | 11652 | break; |
11653 | case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding | ||
11654 | ret.Add(new LSL_Float(0)); | ||
11655 | break; | ||
11656 | case ScriptBaseClass.OBJECT_ROOT: | ||
11657 | ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString())); | ||
11658 | break; | ||
11659 | case ScriptBaseClass.OBJECT_ATTACHED_POINT: | ||
11660 | ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint)); | ||
11661 | break; | ||
11662 | case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: | ||
11663 | byte pcode = obj.Shape.PCode; | ||
11664 | if (obj.ParentGroup.AttachmentPoint != 0 | ||
11665 | || pcode == (byte)PCode.Grass | ||
11666 | || pcode == (byte)PCode.Tree | ||
11667 | || pcode == (byte)PCode.NewTree) | ||
11668 | { | ||
11669 | ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER)); | ||
11670 | } | ||
11671 | else | ||
11672 | { | ||
11673 | ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET)); | ||
11674 | } | ||
11675 | break; | ||
11676 | case ScriptBaseClass.OBJECT_PHYSICS: | ||
11677 | if (obj.ParentGroup.AttachmentPoint != 0) | ||
11678 | { | ||
11679 | ret.Add(new LSL_Integer(0)); // Always false if attached | ||
11680 | } | ||
11681 | else | ||
11682 | { | ||
11683 | ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0)); | ||
11684 | } | ||
11685 | break; | ||
11686 | case ScriptBaseClass.OBJECT_PHANTOM: | ||
11687 | if (obj.ParentGroup.AttachmentPoint != 0) | ||
11688 | { | ||
11689 | ret.Add(new LSL_Integer(0)); // Always false if attached | ||
11690 | } | ||
11691 | else | ||
11692 | { | ||
11693 | ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0)); | ||
11694 | } | ||
11695 | break; | ||
11696 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: | ||
11697 | ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0)); | ||
11698 | break; | ||
11609 | default: | 11699 | default: |
11610 | // Invalid or unhandled constant. | 11700 | // Invalid or unhandled constant. |
11611 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); | 11701 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); |
@@ -13257,7 +13347,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
13257 | /// Get a notecard line. | 13347 | /// Get a notecard line. |
13258 | /// </summary> | 13348 | /// </summary> |
13259 | /// <param name="assetID"></param> | 13349 | /// <param name="assetID"></param> |
13260 | /// <param name="line">Lines start at index 0</param> | 13350 | /// <param name="lineNumber">Lines start at index 0</param> |
13261 | /// <returns></returns> | 13351 | /// <returns></returns> |
13262 | public static string GetLine(UUID assetID, int lineNumber) | 13352 | public static string GetLine(UUID assetID, int lineNumber) |
13263 | { | 13353 | { |
@@ -13286,9 +13376,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
13286 | /// Get a notecard line. | 13376 | /// Get a notecard line. |
13287 | /// </summary> | 13377 | /// </summary> |
13288 | /// <param name="assetID"></param> | 13378 | /// <param name="assetID"></param> |
13289 | /// <param name="line">Lines start at index 0</param> | 13379 | /// <param name="lineNumber">Lines start at index 0</param> |
13290 | /// <param name="maxLength">Maximum length of the returned line. Longer lines will be truncated</para> | 13380 | /// <param name="maxLength"> |
13291 | /// <returns></returns> | 13381 | /// Maximum length of the returned line. |
13382 | /// </param> | ||
13383 | /// <returns> | ||
13384 | /// If the line length is longer than <paramref name="maxLength"/>, | ||
13385 | /// the return string will be truncated. | ||
13386 | /// </returns> | ||
13292 | public static string GetLine(UUID assetID, int lineNumber, int maxLength) | 13387 | public static string GetLine(UUID assetID, int lineNumber, int maxLength) |
13293 | { | 13388 | { |
13294 | string line = GetLine(assetID, lineNumber); | 13389 | string line = GetLine(assetID, lineNumber); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs index ceb4660..a08ccc8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs | |||
@@ -30,6 +30,7 @@ using System.Reflection; | |||
30 | using System.Collections; | 30 | using System.Collections; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
33 | using System.Threading; | ||
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using Nini.Config; | 35 | using Nini.Config; |
35 | using OpenSim; | 36 | using OpenSim; |
@@ -61,9 +62,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
61 | internal bool m_LSFunctionsEnabled = false; | 62 | internal bool m_LSFunctionsEnabled = false; |
62 | internal IScriptModuleComms m_comms = null; | 63 | internal IScriptModuleComms m_comms = null; |
63 | 64 | ||
64 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 65 | public void Initialize( |
66 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle) | ||
65 | { | 67 | { |
66 | m_ScriptEngine = ScriptEngine; | 68 | m_ScriptEngine = scriptEngine; |
67 | m_host = host; | 69 | m_host = host; |
68 | 70 | ||
69 | if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) | 71 | if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) |
@@ -92,10 +94,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
92 | get { return m_ScriptEngine.World; } | 94 | get { return m_ScriptEngine.World; } |
93 | } | 95 | } |
94 | 96 | ||
95 | // | 97 | /// <summary> |
96 | //Dumps an error message on the debug console. | 98 | /// Dumps an error message on the debug console. |
97 | // | 99 | /// </summary> |
98 | |||
99 | internal void LSShoutError(string message) | 100 | internal void LSShoutError(string message) |
100 | { | 101 | { |
101 | if (message.Length > 1023) | 102 | if (message.Length > 1023) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 8f34833..981499e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | |||
@@ -30,6 +30,7 @@ using System.Reflection; | |||
30 | using System.Collections; | 30 | using System.Collections; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
33 | using System.Threading; | ||
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using Nini.Config; | 35 | using Nini.Config; |
35 | using OpenSim; | 36 | using OpenSim; |
@@ -61,9 +62,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
61 | internal bool m_MODFunctionsEnabled = false; | 62 | internal bool m_MODFunctionsEnabled = false; |
62 | internal IScriptModuleComms m_comms = null; | 63 | internal IScriptModuleComms m_comms = null; |
63 | 64 | ||
64 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 65 | public void Initialize( |
66 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle) | ||
65 | { | 67 | { |
66 | m_ScriptEngine = ScriptEngine; | 68 | m_ScriptEngine = scriptEngine; |
67 | m_host = host; | 69 | m_host = host; |
68 | m_item = item; | 70 | m_item = item; |
69 | 71 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 7c2f8ed..10ec34d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -143,9 +143,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
143 | 143 | ||
144 | protected IUrlModule m_UrlModule = null; | 144 | protected IUrlModule m_UrlModule = null; |
145 | 145 | ||
146 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 146 | public void Initialize( |
147 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle) | ||
147 | { | 148 | { |
148 | m_ScriptEngine = ScriptEngine; | 149 | m_ScriptEngine = scriptEngine; |
149 | m_host = host; | 150 | m_host = host; |
150 | m_item = item; | 151 | m_item = item; |
151 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | 152 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); |
@@ -254,11 +255,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
254 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); | 255 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); |
255 | } | 256 | } |
256 | 257 | ||
258 | // Returns of the function is allowed. Throws a script exception if not allowed. | ||
257 | public void CheckThreatLevel(ThreatLevel level, string function) | 259 | public void CheckThreatLevel(ThreatLevel level, string function) |
258 | { | 260 | { |
259 | if (!m_OSFunctionsEnabled) | 261 | if (!m_OSFunctionsEnabled) |
260 | OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws | 262 | OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws |
261 | 263 | ||
264 | string reasonWhyNot = CheckThreatLevelTest(level, function); | ||
265 | if (!String.IsNullOrEmpty(reasonWhyNot)) | ||
266 | { | ||
267 | OSSLError(reasonWhyNot); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | // Check to see if function is allowed. Returns an empty string if function permitted | ||
272 | // or a string explaining why this function can't be used. | ||
273 | private string CheckThreatLevelTest(ThreatLevel level, string function) | ||
274 | { | ||
262 | if (!m_FunctionPerms.ContainsKey(function)) | 275 | if (!m_FunctionPerms.ContainsKey(function)) |
263 | { | 276 | { |
264 | FunctionPerms perms = new FunctionPerms(); | 277 | FunctionPerms perms = new FunctionPerms(); |
@@ -338,10 +351,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
338 | { | 351 | { |
339 | // Allow / disallow by threat level | 352 | // Allow / disallow by threat level |
340 | if (level > m_MaxThreatLevel) | 353 | if (level > m_MaxThreatLevel) |
341 | OSSLError( | 354 | return |
342 | String.Format( | 355 | String.Format( |
343 | "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.", | 356 | "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.", |
344 | function, m_MaxThreatLevel, level)); | 357 | function, m_MaxThreatLevel, level); |
345 | } | 358 | } |
346 | else | 359 | else |
347 | { | 360 | { |
@@ -351,7 +364,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
351 | if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID)) | 364 | if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID)) |
352 | { | 365 | { |
353 | // prim owner is in the list of allowed owners | 366 | // prim owner is in the list of allowed owners |
354 | return; | 367 | return String.Empty; |
355 | } | 368 | } |
356 | 369 | ||
357 | UUID ownerID = m_item.OwnerID; | 370 | UUID ownerID = m_item.OwnerID; |
@@ -363,7 +376,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
363 | 376 | ||
364 | if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero) | 377 | if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero) |
365 | { | 378 | { |
366 | return; | 379 | return String.Empty; |
367 | } | 380 | } |
368 | } | 381 | } |
369 | 382 | ||
@@ -374,7 +387,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
374 | 387 | ||
375 | if (land.LandData.OwnerID == ownerID) | 388 | if (land.LandData.OwnerID == ownerID) |
376 | { | 389 | { |
377 | return; | 390 | return String.Empty; |
378 | } | 391 | } |
379 | } | 392 | } |
380 | 393 | ||
@@ -384,7 +397,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
384 | //Only Estate Managers may use the function | 397 | //Only Estate Managers may use the function |
385 | if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) | 398 | if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) |
386 | { | 399 | { |
387 | return; | 400 | return String.Empty; |
388 | } | 401 | } |
389 | } | 402 | } |
390 | 403 | ||
@@ -393,25 +406,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
393 | { | 406 | { |
394 | if (World.RegionInfo.EstateSettings.EstateOwner == ownerID) | 407 | if (World.RegionInfo.EstateSettings.EstateOwner == ownerID) |
395 | { | 408 | { |
396 | return; | 409 | return String.Empty; |
397 | } | 410 | } |
398 | } | 411 | } |
399 | 412 | ||
400 | if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) | 413 | if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) |
401 | OSSLError( | 414 | return( |
402 | String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", | 415 | String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", |
403 | function)); | 416 | function)); |
404 | 417 | ||
405 | if (m_item.CreatorID != ownerID) | 418 | if (m_item.CreatorID != ownerID) |
406 | { | 419 | { |
407 | if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0) | 420 | if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0) |
408 | OSSLError( | 421 | return String.Format("{0} permission denied. Script permissions error.", function); |
409 | String.Format("{0} permission denied. Script permissions error.", | ||
410 | function)); | ||
411 | 422 | ||
412 | } | 423 | } |
413 | } | 424 | } |
414 | } | 425 | } |
426 | return String.Empty; | ||
415 | } | 427 | } |
416 | 428 | ||
417 | internal void OSSLDeprecated(string function, string replacement) | 429 | internal void OSSLDeprecated(string function, string replacement) |
@@ -983,7 +995,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
983 | if (animID == UUID.Zero) | 995 | if (animID == UUID.Zero) |
984 | target.Animator.RemoveAnimation(animation); | 996 | target.Animator.RemoveAnimation(animation); |
985 | else | 997 | else |
986 | target.Animator.RemoveAnimation(animID); | 998 | target.Animator.RemoveAnimation(animID, true); |
987 | } | 999 | } |
988 | } | 1000 | } |
989 | } | 1001 | } |
@@ -1214,12 +1226,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1214 | sunHour += 24.0; | 1226 | sunHour += 24.0; |
1215 | 1227 | ||
1216 | World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; | 1228 | World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; |
1217 | World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 | 1229 | World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 |
1218 | World.RegionInfo.RegionSettings.FixedSun = sunFixed; | 1230 | World.RegionInfo.RegionSettings.FixedSun = sunFixed; |
1219 | World.RegionInfo.RegionSettings.Save(); | 1231 | World.RegionInfo.RegionSettings.Save(); |
1220 | 1232 | ||
1221 | World.EventManager.TriggerEstateToolsSunUpdate( | 1233 | World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle); |
1222 | World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour); | ||
1223 | } | 1234 | } |
1224 | 1235 | ||
1225 | /// <summary> | 1236 | /// <summary> |
@@ -1244,8 +1255,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1244 | World.RegionInfo.EstateSettings.FixedSun = sunFixed; | 1255 | World.RegionInfo.EstateSettings.FixedSun = sunFixed; |
1245 | World.RegionInfo.EstateSettings.Save(); | 1256 | World.RegionInfo.EstateSettings.Save(); |
1246 | 1257 | ||
1247 | World.EventManager.TriggerEstateToolsSunUpdate( | 1258 | World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle); |
1248 | World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour); | ||
1249 | } | 1259 | } |
1250 | 1260 | ||
1251 | /// <summary> | 1261 | /// <summary> |
@@ -1569,6 +1579,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1569 | } | 1579 | } |
1570 | } | 1580 | } |
1571 | 1581 | ||
1582 | public string osGetPhysicsEngineType() | ||
1583 | { | ||
1584 | // High because it can be used to target attacks to known weaknesses | ||
1585 | // This would allow a new class of griefer scripts that don't even | ||
1586 | // require their user to know what they are doing (see script | ||
1587 | // kiddie) | ||
1588 | // Because it would be nice if scripts didn't blow up if the information | ||
1589 | // about the physics engine, this function returns an empty string if | ||
1590 | // the user does not have permission to see it. This as opposed to | ||
1591 | // throwing an exception. | ||
1592 | m_host.AddScriptLPS(1); | ||
1593 | string ret = String.Empty; | ||
1594 | if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType"))) | ||
1595 | { | ||
1596 | if (m_ScriptEngine.World.PhysicsScene != null) | ||
1597 | { | ||
1598 | ret = m_ScriptEngine.World.PhysicsScene.EngineType; | ||
1599 | // An old physics engine might have an uninitialized engine type | ||
1600 | if (ret == null) | ||
1601 | ret = "unknown"; | ||
1602 | } | ||
1603 | } | ||
1604 | |||
1605 | return ret; | ||
1606 | } | ||
1607 | |||
1572 | public string osGetSimulatorVersion() | 1608 | public string osGetSimulatorVersion() |
1573 | { | 1609 | { |
1574 | // High because it can be used to target attacks to known weaknesses | 1610 | // High because it can be used to target attacks to known weaknesses |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 4dd795d..d3ef378 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -42,6 +42,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
42 | { | 42 | { |
43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 44 | ||
45 | /// <summary> | ||
46 | /// Used by one-off and repeated sensors | ||
47 | /// </summary> | ||
48 | public class SensorInfo | ||
49 | { | ||
50 | public uint localID; | ||
51 | public UUID itemID; | ||
52 | public double interval; | ||
53 | public DateTime next; | ||
54 | |||
55 | public string name; | ||
56 | public UUID keyID; | ||
57 | public int type; | ||
58 | public double range; | ||
59 | public double arc; | ||
60 | public SceneObjectPart host; | ||
61 | |||
62 | public SensorInfo Clone() | ||
63 | { | ||
64 | return (SensorInfo)this.MemberwiseClone(); | ||
65 | } | ||
66 | } | ||
67 | |||
45 | public AsyncCommandManager m_CmdManager; | 68 | public AsyncCommandManager m_CmdManager; |
46 | 69 | ||
47 | /// <summary> | 70 | /// <summary> |
@@ -78,24 +101,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
78 | private int maximumToReturn = 16; | 101 | private int maximumToReturn = 16; |
79 | 102 | ||
80 | // | 103 | // |
81 | // SenseRepeater and Sensors | ||
82 | // | ||
83 | private class SenseRepeatClass | ||
84 | { | ||
85 | public uint localID; | ||
86 | public UUID itemID; | ||
87 | public double interval; | ||
88 | public DateTime next; | ||
89 | |||
90 | public string name; | ||
91 | public UUID keyID; | ||
92 | public int type; | ||
93 | public double range; | ||
94 | public double arc; | ||
95 | public SceneObjectPart host; | ||
96 | } | ||
97 | |||
98 | // | ||
99 | // Sensed entity | 104 | // Sensed entity |
100 | // | 105 | // |
101 | private class SensedEntity : IComparable | 106 | private class SensedEntity : IComparable |
@@ -127,7 +132,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
127 | /// | 132 | /// |
128 | /// Always lock SenseRepeatListLock when updating this list. | 133 | /// Always lock SenseRepeatListLock when updating this list. |
129 | /// </remarks> | 134 | /// </remarks> |
130 | private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>(); | 135 | private List<SensorInfo> SenseRepeaters = new List<SensorInfo>(); |
131 | private object SenseRepeatListLock = new object(); | 136 | private object SenseRepeatListLock = new object(); |
132 | 137 | ||
133 | public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, | 138 | public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, |
@@ -141,7 +146,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
141 | return; | 146 | return; |
142 | 147 | ||
143 | // Add to timer | 148 | // Add to timer |
144 | SenseRepeatClass ts = new SenseRepeatClass(); | 149 | SensorInfo ts = new SensorInfo(); |
145 | ts.localID = m_localID; | 150 | ts.localID = m_localID; |
146 | ts.itemID = m_itemID; | 151 | ts.itemID = m_itemID; |
147 | ts.interval = sec; | 152 | ts.interval = sec; |
@@ -160,11 +165,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
160 | AddSenseRepeater(ts); | 165 | AddSenseRepeater(ts); |
161 | } | 166 | } |
162 | 167 | ||
163 | private void AddSenseRepeater(SenseRepeatClass senseRepeater) | 168 | private void AddSenseRepeater(SensorInfo senseRepeater) |
164 | { | 169 | { |
165 | lock (SenseRepeatListLock) | 170 | lock (SenseRepeatListLock) |
166 | { | 171 | { |
167 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(SenseRepeaters); | 172 | List<SensorInfo> newSenseRepeaters = new List<SensorInfo>(SenseRepeaters); |
168 | newSenseRepeaters.Add(senseRepeater); | 173 | newSenseRepeaters.Add(senseRepeater); |
169 | SenseRepeaters = newSenseRepeaters; | 174 | SenseRepeaters = newSenseRepeaters; |
170 | } | 175 | } |
@@ -175,8 +180,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
175 | // Remove from timer | 180 | // Remove from timer |
176 | lock (SenseRepeatListLock) | 181 | lock (SenseRepeatListLock) |
177 | { | 182 | { |
178 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(); | 183 | List<SensorInfo> newSenseRepeaters = new List<SensorInfo>(); |
179 | foreach (SenseRepeatClass ts in SenseRepeaters) | 184 | foreach (SensorInfo ts in SenseRepeaters) |
180 | { | 185 | { |
181 | if (ts.localID != m_localID || ts.itemID != m_itemID) | 186 | if (ts.localID != m_localID || ts.itemID != m_itemID) |
182 | { | 187 | { |
@@ -191,7 +196,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
191 | public void CheckSenseRepeaterEvents() | 196 | public void CheckSenseRepeaterEvents() |
192 | { | 197 | { |
193 | // Go through all timers | 198 | // Go through all timers |
194 | foreach (SenseRepeatClass ts in SenseRepeaters) | 199 | foreach (SensorInfo ts in SenseRepeaters) |
195 | { | 200 | { |
196 | // Time has passed? | 201 | // Time has passed? |
197 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) | 202 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) |
@@ -208,7 +213,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
208 | double range, double arc, SceneObjectPart host) | 213 | double range, double arc, SceneObjectPart host) |
209 | { | 214 | { |
210 | // Add to timer | 215 | // Add to timer |
211 | SenseRepeatClass ts = new SenseRepeatClass(); | 216 | SensorInfo ts = new SensorInfo(); |
212 | ts.localID = m_localID; | 217 | ts.localID = m_localID; |
213 | ts.itemID = m_itemID; | 218 | ts.itemID = m_itemID; |
214 | ts.interval = 0; | 219 | ts.interval = 0; |
@@ -224,7 +229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
224 | SensorSweep(ts); | 229 | SensorSweep(ts); |
225 | } | 230 | } |
226 | 231 | ||
227 | private void SensorSweep(SenseRepeatClass ts) | 232 | private void SensorSweep(SensorInfo ts) |
228 | { | 233 | { |
229 | if (ts.host == null) | 234 | if (ts.host == null) |
230 | { | 235 | { |
@@ -300,7 +305,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
300 | } | 305 | } |
301 | } | 306 | } |
302 | 307 | ||
303 | private List<SensedEntity> doObjectSensor(SenseRepeatClass ts) | 308 | private List<SensedEntity> doObjectSensor(SensorInfo ts) |
304 | { | 309 | { |
305 | List<EntityBase> Entities; | 310 | List<EntityBase> Entities; |
306 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); | 311 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); |
@@ -451,7 +456,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
451 | return sensedEntities; | 456 | return sensedEntities; |
452 | } | 457 | } |
453 | 458 | ||
454 | private List<SensedEntity> doAgentSensor(SenseRepeatClass ts) | 459 | private List<SensedEntity> doAgentSensor(SensorInfo ts) |
455 | { | 460 | { |
456 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); | 461 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); |
457 | 462 | ||
@@ -630,7 +635,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
630 | { | 635 | { |
631 | List<Object> data = new List<Object>(); | 636 | List<Object> data = new List<Object>(); |
632 | 637 | ||
633 | foreach (SenseRepeatClass ts in SenseRepeaters) | 638 | foreach (SensorInfo ts in SenseRepeaters) |
634 | { | 639 | { |
635 | if (ts.itemID == itemID) | 640 | if (ts.itemID == itemID) |
636 | { | 641 | { |
@@ -660,7 +665,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
660 | 665 | ||
661 | while (idx < data.Length) | 666 | while (idx < data.Length) |
662 | { | 667 | { |
663 | SenseRepeatClass ts = new SenseRepeatClass(); | 668 | SensorInfo ts = new SensorInfo(); |
664 | 669 | ||
665 | ts.localID = localID; | 670 | ts.localID = localID; |
666 | ts.itemID = itemID; | 671 | ts.itemID = itemID; |
@@ -681,5 +686,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
681 | idx += 6; | 686 | idx += 6; |
682 | } | 687 | } |
683 | } | 688 | } |
689 | |||
690 | public List<SensorInfo> GetSensorInfo() | ||
691 | { | ||
692 | List<SensorInfo> retList = new List<SensorInfo>(); | ||
693 | |||
694 | lock (SenseRepeatListLock) | ||
695 | { | ||
696 | foreach (SensorInfo i in SenseRepeaters) | ||
697 | retList.Add(i.Clone()); | ||
698 | } | ||
699 | |||
700 | return retList; | ||
701 | } | ||
684 | } | 702 | } |
685 | } | 703 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs index 9ee6946..68aacd2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs | |||
@@ -35,6 +35,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
35 | { | 35 | { |
36 | public class Timer | 36 | public class Timer |
37 | { | 37 | { |
38 | public class TimerInfo | ||
39 | { | ||
40 | public uint localID; | ||
41 | public UUID itemID; | ||
42 | //public double interval; | ||
43 | public long interval; | ||
44 | //public DateTime next; | ||
45 | public long next; | ||
46 | |||
47 | public TimerInfo Clone() | ||
48 | { | ||
49 | return (TimerInfo)this.MemberwiseClone(); | ||
50 | } | ||
51 | } | ||
52 | |||
38 | public AsyncCommandManager m_CmdManager; | 53 | public AsyncCommandManager m_CmdManager; |
39 | 54 | ||
40 | public int TimersCount | 55 | public int TimersCount |
@@ -59,17 +74,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
59 | return localID.ToString() + itemID.ToString(); | 74 | return localID.ToString() + itemID.ToString(); |
60 | } | 75 | } |
61 | 76 | ||
62 | private class TimerClass | 77 | private Dictionary<string,TimerInfo> Timers = new Dictionary<string,TimerInfo>(); |
63 | { | ||
64 | public uint localID; | ||
65 | public UUID itemID; | ||
66 | //public double interval; | ||
67 | public long interval; | ||
68 | //public DateTime next; | ||
69 | public long next; | ||
70 | } | ||
71 | |||
72 | private Dictionary<string,TimerClass> Timers = new Dictionary<string,TimerClass>(); | ||
73 | private object TimerListLock = new object(); | 78 | private object TimerListLock = new object(); |
74 | 79 | ||
75 | public void SetTimerEvent(uint m_localID, UUID m_itemID, double sec) | 80 | public void SetTimerEvent(uint m_localID, UUID m_itemID, double sec) |
@@ -81,7 +86,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
81 | } | 86 | } |
82 | 87 | ||
83 | // Add to timer | 88 | // Add to timer |
84 | TimerClass ts = new TimerClass(); | 89 | TimerInfo ts = new TimerInfo(); |
85 | ts.localID = m_localID; | 90 | ts.localID = m_localID; |
86 | ts.itemID = m_itemID; | 91 | ts.itemID = m_itemID; |
87 | ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait | 92 | ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait |
@@ -118,14 +123,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
118 | if (Timers.Count == 0) | 123 | if (Timers.Count == 0) |
119 | return; | 124 | return; |
120 | 125 | ||
121 | Dictionary<string, TimerClass>.ValueCollection tvals; | 126 | Dictionary<string, TimerInfo>.ValueCollection tvals; |
122 | lock (TimerListLock) | 127 | lock (TimerListLock) |
123 | { | 128 | { |
124 | // Go through all timers | 129 | // Go through all timers |
125 | tvals = Timers.Values; | 130 | tvals = Timers.Values; |
126 | } | 131 | } |
127 | 132 | ||
128 | foreach (TimerClass ts in tvals) | 133 | foreach (TimerInfo ts in tvals) |
129 | { | 134 | { |
130 | // Time has passed? | 135 | // Time has passed? |
131 | if (ts.next < DateTime.Now.Ticks) | 136 | if (ts.next < DateTime.Now.Ticks) |
@@ -149,8 +154,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
149 | 154 | ||
150 | lock (TimerListLock) | 155 | lock (TimerListLock) |
151 | { | 156 | { |
152 | Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values; | 157 | Dictionary<string, TimerInfo>.ValueCollection tvals = Timers.Values; |
153 | foreach (TimerClass ts in tvals) | 158 | foreach (TimerInfo ts in tvals) |
154 | { | 159 | { |
155 | if (ts.itemID == itemID) | 160 | if (ts.itemID == itemID) |
156 | { | 161 | { |
@@ -169,7 +174,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
169 | 174 | ||
170 | while (idx < data.Length) | 175 | while (idx < data.Length) |
171 | { | 176 | { |
172 | TimerClass ts = new TimerClass(); | 177 | TimerInfo ts = new TimerInfo(); |
173 | 178 | ||
174 | ts.localID = localID; | 179 | ts.localID = localID; |
175 | ts.itemID = itemID; | 180 | ts.itemID = itemID; |
@@ -183,5 +188,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
183 | } | 188 | } |
184 | } | 189 | } |
185 | } | 190 | } |
191 | |||
192 | public List<TimerInfo> GetTimersInfo() | ||
193 | { | ||
194 | List<TimerInfo> retList = new List<TimerInfo>(); | ||
195 | |||
196 | lock (TimerListLock) | ||
197 | { | ||
198 | foreach (TimerInfo i in Timers.Values) | ||
199 | retList.Add(i.Clone()); | ||
200 | } | ||
201 | |||
202 | return retList; | ||
203 | } | ||
186 | } | 204 | } |
187 | } | 205 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index c447d1f..7eb347e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -259,6 +259,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
259 | 259 | ||
260 | string osGetScriptEngineName(); | 260 | string osGetScriptEngineName(); |
261 | string osGetSimulatorVersion(); | 261 | string osGetSimulatorVersion(); |
262 | string osGetPhysicsEngineType(); | ||
262 | Object osParseJSONNew(string JSON); | 263 | Object osParseJSONNew(string JSON); |
263 | Hashtable osParseJSON(string JSON); | 264 | Hashtable osParseJSON(string JSON); |
264 | 265 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 0dd5a57..da3b31f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -557,6 +557,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
557 | public const int OBJECT_SERVER_COST = 14; | 557 | public const int OBJECT_SERVER_COST = 14; |
558 | public const int OBJECT_STREAMING_COST = 15; | 558 | public const int OBJECT_STREAMING_COST = 15; |
559 | public const int OBJECT_PHYSICS_COST = 16; | 559 | public const int OBJECT_PHYSICS_COST = 16; |
560 | public const int OBJECT_CHARACTER_TIME = 17; | ||
561 | public const int OBJECT_ROOT = 18; | ||
562 | public const int OBJECT_ATTACHED_POINT = 19; | ||
563 | public const int OBJECT_PATHFINDING_TYPE = 20; | ||
564 | public const int OBJECT_PHYSICS = 21; | ||
565 | public const int OBJECT_PHANTOM = 22; | ||
566 | public const int OBJECT_TEMP_ON_REZ = 23; | ||
567 | |||
568 | // Pathfinding types | ||
569 | public const int OPT_OTHER = -1; | ||
570 | public const int OPT_LEGACY_LINKSET = 0; | ||
571 | public const int OPT_AVATAR = 1; | ||
572 | public const int OPT_CHARACTER = 2; | ||
573 | public const int OPT_WALKABLE = 3; | ||
574 | public const int OPT_STATIC_OBSTACLE = 4; | ||
575 | public const int OPT_MATERIAL_VOLUME = 5; | ||
576 | public const int OPT_EXCLUSION_VOLUME = 6; | ||
560 | 577 | ||
561 | // for llGetAgentList | 578 | // for llGetAgentList |
562 | public const int AGENT_LIST_PARCEL = 1; | 579 | public const int AGENT_LIST_PARCEL = 1; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index afa9ae0..c9902e4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -420,6 +420,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
420 | return m_OSSL_Functions.osGetScriptEngineName(); | 420 | return m_OSSL_Functions.osGetScriptEngineName(); |
421 | } | 421 | } |
422 | 422 | ||
423 | public string osGetPhysicsEngineType() | ||
424 | { | ||
425 | return m_OSSL_Functions.osGetPhysicsEngineType(); | ||
426 | } | ||
427 | |||
423 | public string osGetSimulatorVersion() | 428 | public string osGetSimulatorVersion() |
424 | { | 429 | { |
425 | return m_OSSL_Functions.osGetSimulatorVersion(); | 430 | return m_OSSL_Functions.osGetSimulatorVersion(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index 7763619..77e087c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | |||
@@ -39,7 +39,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
39 | /// The generated C# code is compared against the expected C# code. | 39 | /// The generated C# code is compared against the expected C# code. |
40 | /// </summary> | 40 | /// </summary> |
41 | [TestFixture] | 41 | [TestFixture] |
42 | public class CSCodeGeneratorTest | 42 | public class CSCodeGeneratorTest : OpenSimTestCase |
43 | { | 43 | { |
44 | [Test] | 44 | [Test] |
45 | public void TestDefaultState() | 45 | public void TestDefaultState() |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 1fa6954..05a8756 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs | |||
@@ -41,7 +41,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
41 | /// the LSL source. | 41 | /// the LSL source. |
42 | /// </summary> | 42 | /// </summary> |
43 | [TestFixture] | 43 | [TestFixture] |
44 | public class CompilerTest | 44 | public class CompilerTest : OpenSimTestCase |
45 | { | 45 | { |
46 | private string m_testDir; | 46 | private string m_testDir; |
47 | private CSharpCodeProvider m_CSCodeProvider; | 47 | private CSharpCodeProvider m_CSCodeProvider; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs index 22804f5..e44a106 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs | |||
@@ -82,6 +82,24 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | /// <summary> | ||
86 | /// Used to signal when the script is stopping in co-operation with the script engine | ||
87 | /// (instead of through Thread.Abort()). | ||
88 | /// </summary> | ||
89 | [Serializable] | ||
90 | public class ScriptCoopStopException : Exception | ||
91 | { | ||
92 | public ScriptCoopStopException() | ||
93 | { | ||
94 | } | ||
95 | |||
96 | protected ScriptCoopStopException( | ||
97 | SerializationInfo info, | ||
98 | StreamingContext context) | ||
99 | { | ||
100 | } | ||
101 | } | ||
102 | |||
85 | public class DetectParams | 103 | public class DetectParams |
86 | { | 104 | { |
87 | public const int AGENT = 1; | 105 | public const int AGENT = 1; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 771db0c..a869a6a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -94,6 +94,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
94 | private UUID m_CurrentStateHash; | 94 | private UUID m_CurrentStateHash; |
95 | private UUID m_RegionID; | 95 | private UUID m_RegionID; |
96 | 96 | ||
97 | public int DebugLevel { get; set; } | ||
98 | |||
97 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; } | 99 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; } |
98 | 100 | ||
99 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); | 101 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); |
@@ -156,6 +158,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
156 | 158 | ||
157 | public UUID AppDomain { get; set; } | 159 | public UUID AppDomain { get; set; } |
158 | 160 | ||
161 | public SceneObjectPart Part { get; private set; } | ||
162 | |||
159 | public string PrimName { get; private set; } | 163 | public string PrimName { get; private set; } |
160 | 164 | ||
161 | public string ScriptName { get; private set; } | 165 | public string ScriptName { get; private set; } |
@@ -174,6 +178,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
174 | 178 | ||
175 | public Queue EventQueue { get; private set; } | 179 | public Queue EventQueue { get; private set; } |
176 | 180 | ||
181 | public long EventsQueued | ||
182 | { | ||
183 | get | ||
184 | { | ||
185 | lock (EventQueue) | ||
186 | return EventQueue.Count; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | public long EventsProcessed { get; private set; } | ||
191 | |||
177 | public int StartParam { get; set; } | 192 | public int StartParam { get; set; } |
178 | 193 | ||
179 | public TaskInventoryItem ScriptTask { get; private set; } | 194 | public TaskInventoryItem ScriptTask { get; private set; } |
@@ -186,54 +201,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
186 | 201 | ||
187 | public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; | 202 | public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; |
188 | 203 | ||
204 | private bool m_coopTermination; | ||
205 | |||
206 | private EventWaitHandle m_coopSleepHandle; | ||
207 | |||
189 | public void ClearQueue() | 208 | public void ClearQueue() |
190 | { | 209 | { |
191 | m_TimerQueued = false; | 210 | m_TimerQueued = false; |
192 | EventQueue.Clear(); | 211 | EventQueue.Clear(); |
193 | } | 212 | } |
194 | 213 | ||
195 | public ScriptInstance(IScriptEngine engine, SceneObjectPart part, | 214 | public ScriptInstance( |
196 | UUID itemID, UUID assetID, string assembly, | 215 | IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item, |
197 | AppDomain dom, string primName, string scriptName, | 216 | int startParam, bool postOnRez, |
198 | int startParam, bool postOnRez, StateSource stateSource, | 217 | int maxScriptQueue) |
199 | int maxScriptQueue) | ||
200 | { | 218 | { |
201 | State = "default"; | 219 | State = "default"; |
202 | EventQueue = new Queue(32); | 220 | EventQueue = new Queue(32); |
203 | 221 | ||
204 | Engine = engine; | 222 | Engine = engine; |
205 | LocalID = part.LocalId; | 223 | Part = part; |
206 | ObjectID = part.UUID; | 224 | ScriptTask = item; |
207 | RootLocalID = part.ParentGroup.LocalId; | 225 | |
208 | RootObjectID = part.ParentGroup.UUID; | 226 | // This is currently only here to allow regression tests to get away without specifying any inventory |
209 | ItemID = itemID; | 227 | // item when they are testing script logic that doesn't require an item. |
210 | AssetID = assetID; | 228 | if (ScriptTask != null) |
211 | PrimName = primName; | 229 | { |
212 | ScriptName = scriptName; | 230 | ScriptName = ScriptTask.Name; |
213 | m_Assembly = assembly; | 231 | ItemID = ScriptTask.ItemID; |
232 | AssetID = ScriptTask.AssetID; | ||
233 | } | ||
234 | |||
235 | PrimName = part.ParentGroup.Name; | ||
214 | StartParam = startParam; | 236 | StartParam = startParam; |
215 | m_MaxScriptQueue = maxScriptQueue; | 237 | m_MaxScriptQueue = maxScriptQueue; |
216 | m_stateSource = stateSource; | ||
217 | m_postOnRez = postOnRez; | 238 | m_postOnRez = postOnRez; |
218 | m_AttachedAvatar = part.ParentGroup.AttachedAvatar; | 239 | m_AttachedAvatar = part.ParentGroup.AttachedAvatar; |
219 | m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; | 240 | m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; |
220 | 241 | ||
221 | if (part != null) | 242 | if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op") |
222 | { | 243 | { |
223 | part.TaskInventory.LockItemsForRead(true); | 244 | m_coopTermination = true; |
224 | if (part.TaskInventory.ContainsKey(ItemID)) | 245 | m_coopSleepHandle = new AutoResetEvent(false); |
225 | { | ||
226 | ScriptTask = part.TaskInventory[ItemID]; | ||
227 | } | ||
228 | part.TaskInventory.LockItemsForRead(false); | ||
229 | } | 246 | } |
247 | } | ||
248 | |||
249 | /// <summary> | ||
250 | /// Load the script from an assembly into an AppDomain. | ||
251 | /// </summary> | ||
252 | /// <param name='dom'></param> | ||
253 | /// <param name='assembly'></param> | ||
254 | /// <param name='stateSource'></param> | ||
255 | public void Load(AppDomain dom, string assembly, StateSource stateSource) | ||
256 | { | ||
257 | m_Assembly = assembly; | ||
258 | m_stateSource = stateSource; | ||
230 | 259 | ||
231 | ApiManager am = new ApiManager(); | 260 | ApiManager am = new ApiManager(); |
232 | 261 | ||
233 | foreach (string api in am.GetApis()) | 262 | foreach (string api in am.GetApis()) |
234 | { | 263 | { |
235 | m_Apis[api] = am.CreateApi(api); | 264 | m_Apis[api] = am.CreateApi(api); |
236 | m_Apis[api].Initialize(engine, part, ScriptTask); | 265 | m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle); |
237 | } | 266 | } |
238 | 267 | ||
239 | try | 268 | try |
@@ -267,7 +296,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
267 | 296 | ||
268 | // // m_log.Debug("[Script] Script instance created"); | 297 | // // m_log.Debug("[Script] Script instance created"); |
269 | 298 | ||
270 | part.SetScriptEvents(ItemID, | 299 | Part.SetScriptEvents(ItemID, |
271 | (int)m_Script.GetStateEventFlags(State)); | 300 | (int)m_Script.GetStateEventFlags(State)); |
272 | } | 301 | } |
273 | catch (Exception e) | 302 | catch (Exception e) |
@@ -309,7 +338,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
309 | 338 | ||
310 | // m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName); | 339 | // m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName); |
311 | 340 | ||
312 | part.SetScriptEvents(ItemID, | 341 | Part.SetScriptEvents(ItemID, |
313 | (int)m_Script.GetStateEventFlags(State)); | 342 | (int)m_Script.GetStateEventFlags(State)); |
314 | 343 | ||
315 | if (!Running) | 344 | if (!Running) |
@@ -521,9 +550,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
521 | } | 550 | } |
522 | 551 | ||
523 | // Wait for the current event to complete. | 552 | // Wait for the current event to complete. |
524 | if (!m_InSelfDelete && workItem.Wait(new TimeSpan((long)timeout * 100000))) | 553 | if (!m_InSelfDelete) |
525 | { | 554 | { |
526 | return true; | 555 | if (!m_coopTermination) |
556 | { | ||
557 | // If we're not co-operative terminating then try and wait for the event to complete before stopping | ||
558 | if (workItem.Wait(new TimeSpan((long)timeout * 100000))) | ||
559 | return true; | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | m_log.DebugFormat( | ||
564 | "[SCRIPT INSTANCE]: Co-operatively stopping script {0} {1} in {2} {3}", | ||
565 | ScriptName, ItemID, PrimName, ObjectID); | ||
566 | |||
567 | // This will terminate the event on next handle check by the script. | ||
568 | m_coopSleepHandle.Set(); | ||
569 | |||
570 | // For now, we will wait forever since the event should always cleanly terminate once LSL loop | ||
571 | // checking is implemented. May want to allow a shorter timeout option later. | ||
572 | if (workItem.Wait(TimeSpan.MaxValue)) | ||
573 | { | ||
574 | m_log.DebugFormat( | ||
575 | "[SCRIPT INSTANCE]: Co-operatively stopped script {0} {1} in {2} {3}", | ||
576 | ScriptName, ItemID, PrimName, ObjectID); | ||
577 | |||
578 | return true; | ||
579 | } | ||
580 | } | ||
527 | } | 581 | } |
528 | 582 | ||
529 | lock (EventQueue) | 583 | lock (EventQueue) |
@@ -536,11 +590,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
536 | 590 | ||
537 | // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then | 591 | // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then |
538 | // forcibly abort the work item (this aborts the underlying thread). | 592 | // forcibly abort the work item (this aborts the underlying thread). |
593 | // Co-operative termination should never reach this point. | ||
539 | if (!m_InSelfDelete) | 594 | if (!m_InSelfDelete) |
540 | { | 595 | { |
541 | // m_log.ErrorFormat( | 596 | m_log.DebugFormat( |
542 | // "[SCRIPT INSTANCE]: Aborting script {0} {1} in prim {2} {3} {4} {5}", | 597 | "[SCRIPT INSTANCE]: Aborting unstopped script {0} {1} in prim {2}, localID {3}, timeout was {4} ms", |
543 | // ScriptName, ItemID, PrimName, ObjectID, m_InSelfDelete, DateTime.Now.Ticks); | 598 | ScriptName, ItemID, PrimName, LocalID, timeout); |
544 | 599 | ||
545 | workItem.Abort(); | 600 | workItem.Abort(); |
546 | } | 601 | } |
@@ -696,19 +751,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
696 | { | 751 | { |
697 | 752 | ||
698 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); | 753 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); |
754 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); | ||
755 | |||
756 | if (DebugLevel >= 2) | ||
757 | m_log.DebugFormat( | ||
758 | "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | ||
759 | data.EventName, | ||
760 | ScriptName, | ||
761 | part.Name, | ||
762 | part.LocalId, | ||
763 | part.ParentGroup.Name, | ||
764 | part.ParentGroup.UUID, | ||
765 | part.AbsolutePosition, | ||
766 | part.ParentGroup.Scene.Name); | ||
699 | 767 | ||
700 | m_DetectParams = data.DetectParams; | 768 | m_DetectParams = data.DetectParams; |
701 | 769 | ||
702 | if (data.EventName == "state") // Hardcoded state change | 770 | if (data.EventName == "state") // Hardcoded state change |
703 | { | 771 | { |
704 | // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", | ||
705 | // PrimName, ScriptName, data.Params[0].ToString()); | ||
706 | State = data.Params[0].ToString(); | 772 | State = data.Params[0].ToString(); |
773 | |||
774 | if (DebugLevel >= 1) | ||
775 | m_log.DebugFormat( | ||
776 | "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | ||
777 | State, | ||
778 | ScriptName, | ||
779 | part.Name, | ||
780 | part.LocalId, | ||
781 | part.ParentGroup.Name, | ||
782 | part.ParentGroup.UUID, | ||
783 | part.AbsolutePosition, | ||
784 | part.ParentGroup.Scene.Name); | ||
785 | |||
707 | AsyncCommandManager.RemoveScript(Engine, | 786 | AsyncCommandManager.RemoveScript(Engine, |
708 | LocalID, ItemID); | 787 | LocalID, ItemID); |
709 | 788 | ||
710 | SceneObjectPart part = Engine.World.GetSceneObjectPart( | ||
711 | LocalID); | ||
712 | if (part != null) | 789 | if (part != null) |
713 | { | 790 | { |
714 | part.SetScriptEvents(ItemID, | 791 | part.SetScriptEvents(ItemID, |
@@ -720,8 +797,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
720 | if (Engine.World.PipeEventsForScript(LocalID) || | 797 | if (Engine.World.PipeEventsForScript(LocalID) || |
721 | data.EventName == "control") // Don't freeze avies! | 798 | data.EventName == "control") // Don't freeze avies! |
722 | { | 799 | { |
723 | SceneObjectPart part = Engine.World.GetSceneObjectPart( | ||
724 | LocalID); | ||
725 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", | 800 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", |
726 | // PrimName, ScriptName, data.EventName, State); | 801 | // PrimName, ScriptName, data.EventName, State); |
727 | 802 | ||
@@ -763,7 +838,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
763 | m_InEvent = false; | 838 | m_InEvent = false; |
764 | m_CurrentEvent = String.Empty; | 839 | m_CurrentEvent = String.Empty; |
765 | 840 | ||
766 | if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) | 841 | if ((!(e is TargetInvocationException) |
842 | || (!(e.InnerException is SelfDeleteException) | ||
843 | && !(e.InnerException is ScriptDeleteException) | ||
844 | && !(e.InnerException is ScriptCoopStopException))) | ||
845 | && !(e is ThreadAbortException)) | ||
767 | { | 846 | { |
768 | try | 847 | try |
769 | { | 848 | { |
@@ -776,6 +855,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
776 | ChatTypeEnum.DebugChannel, 2147483647, | 855 | ChatTypeEnum.DebugChannel, 2147483647, |
777 | part.AbsolutePosition, | 856 | part.AbsolutePosition, |
778 | part.Name, part.UUID, false); | 857 | part.Name, part.UUID, false); |
858 | |||
859 | |||
860 | m_log.DebugFormat( | ||
861 | "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", | ||
862 | ScriptName, | ||
863 | PrimName, | ||
864 | part.UUID, | ||
865 | part.AbsolutePosition, | ||
866 | part.ParentGroup.Scene.Name, | ||
867 | text.Replace("\n", "\\n"), | ||
868 | e.InnerException); | ||
779 | } | 869 | } |
780 | catch (Exception) | 870 | catch (Exception) |
781 | { | 871 | { |
@@ -802,6 +892,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
802 | if (part != null) | 892 | if (part != null) |
803 | part.Inventory.RemoveInventoryItem(ItemID); | 893 | part.Inventory.RemoveInventoryItem(ItemID); |
804 | } | 894 | } |
895 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) | ||
896 | { | ||
897 | m_log.DebugFormat( | ||
898 | "[SCRIPT INSTANCE]: Script {0}.{1} in event {2}, state {3} stopped co-operatively.", | ||
899 | PrimName, ScriptName, data.EventName, State); | ||
900 | } | ||
805 | } | 901 | } |
806 | } | 902 | } |
807 | } | 903 | } |
@@ -810,6 +906,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
810 | // script engine to run the next event. | 906 | // script engine to run the next event. |
811 | lock (EventQueue) | 907 | lock (EventQueue) |
812 | { | 908 | { |
909 | EventsProcessed++; | ||
910 | |||
813 | if (EventQueue.Count > 0 && Running && !ShuttingDown) | 911 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
814 | { | 912 | { |
815 | m_CurrentWorkItem = Engine.QueueEventHandler(this); | 913 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
@@ -834,7 +932,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
834 | return (DateTime.Now - m_EventStart).Seconds; | 932 | return (DateTime.Now - m_EventStart).Seconds; |
835 | } | 933 | } |
836 | 934 | ||
837 | public void ResetScript() | 935 | public void ResetScript(int timeout) |
838 | { | 936 | { |
839 | if (m_Script == null) | 937 | if (m_Script == null) |
840 | return; | 938 | return; |
@@ -844,7 +942,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
844 | RemoveState(); | 942 | RemoveState(); |
845 | ReleaseControls(); | 943 | ReleaseControls(); |
846 | 944 | ||
847 | Stop(0); | 945 | Stop(timeout); |
848 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); | 946 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
849 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; | 947 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
850 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | 948 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; |
@@ -1015,7 +1113,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1015 | "({0}): {1}", scriptLine - 1, | 1113 | "({0}): {1}", scriptLine - 1, |
1016 | e.InnerException.Message); | 1114 | e.InnerException.Message); |
1017 | 1115 | ||
1018 | System.Console.WriteLine(e.ToString()+"\n"); | ||
1019 | return message; | 1116 | return message; |
1020 | } | 1117 | } |
1021 | } | 1118 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs new file mode 100644 index 0000000..8c3e9e0 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Threading; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.CoreModules.Scripting.WorldComm; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.ScriptEngine.XEngine; | ||
39 | using OpenSim.Tests.Common; | ||
40 | using OpenSim.Tests.Common.Mock; | ||
41 | |||
42 | namespace OpenSim.Region.ScriptEngine.Shared.Instance.Tests | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Test that co-operative script thread termination is working correctly. | ||
46 | /// </summary> | ||
47 | [TestFixture] | ||
48 | public class CoopTerminationTests : OpenSimTestCase | ||
49 | { | ||
50 | private TestScene m_scene; | ||
51 | private OpenSim.Region.ScriptEngine.XEngine.XEngine m_xEngine; | ||
52 | |||
53 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
54 | private AutoResetEvent m_stoppedEvent = new AutoResetEvent(false); | ||
55 | |||
56 | private OSChatMessage m_osChatMessageReceived; | ||
57 | |||
58 | [TestFixtureSetUp] | ||
59 | public void Init() | ||
60 | { | ||
61 | //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin"); | ||
62 | // Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); | ||
63 | m_xEngine = new OpenSim.Region.ScriptEngine.XEngine.XEngine(); | ||
64 | |||
65 | IniConfigSource configSource = new IniConfigSource(); | ||
66 | |||
67 | IConfig startupConfig = configSource.AddConfig("Startup"); | ||
68 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
69 | |||
70 | IConfig xEngineConfig = configSource.AddConfig("XEngine"); | ||
71 | xEngineConfig.Set("Enabled", "true"); | ||
72 | xEngineConfig.Set("StartDelay", "0"); | ||
73 | |||
74 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
75 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
76 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
77 | |||
78 | xEngineConfig.Set("ScriptStopStrategy", "co-op"); | ||
79 | |||
80 | m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource); | ||
81 | SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine); | ||
82 | m_scene.StartScripts(); | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Test co-operative termination on derez of an object containing a script with a long-running event. | ||
87 | /// </summary> | ||
88 | /// <remarks> | ||
89 | /// TODO: Actually compiling the script is incidental to this test. Really want a way to compile test scripts | ||
90 | /// within the build itself. | ||
91 | /// </remarks> | ||
92 | [Test] | ||
93 | public void TestStopOnLongSleep() | ||
94 | { | ||
95 | TestHelpers.InMethod(); | ||
96 | // TestHelpers.EnableLogging(); | ||
97 | |||
98 | UUID userId = TestHelpers.ParseTail(0x1); | ||
99 | // UUID objectId = TestHelpers.ParseTail(0x100); | ||
100 | // UUID itemId = TestHelpers.ParseTail(0x3); | ||
101 | string itemName = "TestStopOnObjectDerezLongSleep() Item"; | ||
102 | |||
103 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStopOnObjectDerezLongSleep", 0x100); | ||
104 | m_scene.AddNewSceneObject(so, true); | ||
105 | |||
106 | InventoryItemBase itemTemplate = new InventoryItemBase(); | ||
107 | // itemTemplate.ID = itemId; | ||
108 | itemTemplate.Name = itemName; | ||
109 | itemTemplate.Folder = so.UUID; | ||
110 | itemTemplate.InvType = (int)InventoryType.LSL; | ||
111 | |||
112 | m_scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
113 | |||
114 | SceneObjectPart partWhereRezzed = m_scene.RezNewScript(userId, itemTemplate, | ||
115 | @"default | ||
116 | { | ||
117 | state_entry() | ||
118 | { | ||
119 | llSay(0, ""Thin Lizzy""); | ||
120 | llSleep(60); | ||
121 | } | ||
122 | }"); | ||
123 | |||
124 | TaskInventoryItem rezzedItem = partWhereRezzed.Inventory.GetInventoryItem(itemName); | ||
125 | |||
126 | // Wait for the script to start the event before we try stopping it. | ||
127 | m_chatEvent.WaitOne(60000); | ||
128 | |||
129 | Console.WriteLine("Script started with message [{0}]", m_osChatMessageReceived.Message); | ||
130 | |||
131 | // FIXME: This is a very poor way of trying to avoid a low-probability race condition where the script | ||
132 | // executes llSay() but has not started the sleep before we try to stop it. | ||
133 | Thread.Sleep(1000); | ||
134 | |||
135 | // We need a way of carrying on if StopScript() fail, since it won't return if the script isn't actually | ||
136 | // stopped. This kind of multi-threading is far from ideal in a regression test. | ||
137 | new Thread(() => { m_xEngine.StopScript(rezzedItem.ItemID); m_stoppedEvent.Set(); }).Start(); | ||
138 | |||
139 | if (!m_stoppedEvent.WaitOne(30000)) | ||
140 | Assert.Fail("Script did not co-operatively stop."); | ||
141 | |||
142 | bool running; | ||
143 | TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName); | ||
144 | Assert.That( | ||
145 | SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True); | ||
146 | Assert.That(running, Is.False); | ||
147 | } | ||
148 | |||
149 | private void OnChatFromWorld(object sender, OSChatMessage oscm) | ||
150 | { | ||
151 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
152 | |||
153 | m_osChatMessageReceived = oscm; | ||
154 | m_chatEvent.Set(); | ||
155 | } | ||
156 | } | ||
157 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index c9c4753..2e61fb8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -633,19 +633,44 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
633 | 633 | ||
634 | public LSL_Types.Vector3 GetVector3Item(int itemIndex) | 634 | public LSL_Types.Vector3 GetVector3Item(int itemIndex) |
635 | { | 635 | { |
636 | if(m_data[itemIndex] is LSL_Types.Vector3) | 636 | if (m_data[itemIndex] is LSL_Types.Vector3) |
637 | { | ||
637 | return (LSL_Types.Vector3)m_data[itemIndex]; | 638 | return (LSL_Types.Vector3)m_data[itemIndex]; |
639 | } | ||
640 | else if(m_data[itemIndex] is OpenMetaverse.Vector3) | ||
641 | { | ||
642 | return new LSL_Types.Vector3( | ||
643 | (OpenMetaverse.Vector3)m_data[itemIndex]); | ||
644 | } | ||
638 | else | 645 | else |
646 | { | ||
639 | throw new InvalidCastException(string.Format( | 647 | throw new InvalidCastException(string.Format( |
640 | "{0} expected but {1} given", | 648 | "{0} expected but {1} given", |
641 | typeof(LSL_Types.Vector3).Name, | 649 | typeof(LSL_Types.Vector3).Name, |
642 | m_data[itemIndex] != null ? | 650 | m_data[itemIndex] != null ? |
643 | m_data[itemIndex].GetType().Name : "null")); | 651 | m_data[itemIndex].GetType().Name : "null")); |
652 | } | ||
644 | } | 653 | } |
645 | 654 | ||
646 | public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) | 655 | public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) |
647 | { | 656 | { |
648 | return (LSL_Types.Quaternion)m_data[itemIndex]; | 657 | if (m_data[itemIndex] is LSL_Types.Quaternion) |
658 | { | ||
659 | return (LSL_Types.Quaternion)m_data[itemIndex]; | ||
660 | } | ||
661 | else if(m_data[itemIndex] is OpenMetaverse.Quaternion) | ||
662 | { | ||
663 | return new LSL_Types.Quaternion( | ||
664 | (OpenMetaverse.Quaternion)m_data[itemIndex]); | ||
665 | } | ||
666 | else | ||
667 | { | ||
668 | throw new InvalidCastException(string.Format( | ||
669 | "{0} expected but {1} given", | ||
670 | typeof(LSL_Types.Quaternion).Name, | ||
671 | m_data[itemIndex] != null ? | ||
672 | m_data[itemIndex].GetType().Name : "null")); | ||
673 | } | ||
649 | } | 674 | } |
650 | 675 | ||
651 | public LSL_Types.key GetKeyItem(int itemIndex) | 676 | public LSL_Types.key GetKeyItem(int itemIndex) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs index c73e22f..6dd6c17 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs | |||
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC; | |||
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
44 | using OpenSim.Services.Interfaces; | 45 | using OpenSim.Services.Interfaces; |
45 | using OpenSim.Tests.Common; | 46 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | 47 | using OpenSim.Tests.Common.Mock; |
@@ -51,14 +52,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
51 | /// Tests for inventory functions in LSL | 52 | /// Tests for inventory functions in LSL |
52 | /// </summary> | 53 | /// </summary> |
53 | [TestFixture] | 54 | [TestFixture] |
54 | public class LSL_ApiInventoryTests | 55 | public class LSL_ApiInventoryTests : OpenSimTestCase |
55 | { | 56 | { |
56 | protected Scene m_scene; | 57 | protected Scene m_scene; |
57 | protected XEngine.XEngine m_engine; | 58 | protected XEngine.XEngine m_engine; |
58 | 59 | ||
59 | [SetUp] | 60 | [SetUp] |
60 | public void SetUp() | 61 | public override void SetUp() |
61 | { | 62 | { |
63 | base.SetUp(); | ||
64 | |||
62 | IConfigSource initConfigSource = new IniConfigSource(); | 65 | IConfigSource initConfigSource = new IniConfigSource(); |
63 | IConfig config = initConfigSource.AddConfig("XEngine"); | 66 | IConfig config = initConfigSource.AddConfig("XEngine"); |
64 | config.Set("Enabled", "true"); | 67 | config.Set("Enabled", "true"); |
@@ -91,7 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
91 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); | 94 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); |
92 | 95 | ||
93 | LSL_Api api = new LSL_Api(); | 96 | LSL_Api api = new LSL_Api(); |
94 | api.Initialize(m_engine, so1.RootPart, null); | 97 | api.Initialize(m_engine, so1.RootPart, null, null); |
95 | 98 | ||
96 | // Create a second object | 99 | // Create a second object |
97 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); | 100 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); |
@@ -124,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
124 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); | 127 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); |
125 | m_scene.AddSceneObject(so1); | 128 | m_scene.AddSceneObject(so1); |
126 | LSL_Api api = new LSL_Api(); | 129 | LSL_Api api = new LSL_Api(); |
127 | api.Initialize(m_engine, so1.RootPart, null); | 130 | api.Initialize(m_engine, so1.RootPart, null, null); |
128 | 131 | ||
129 | // Create an object embedded inside the first | 132 | // Create an object embedded inside the first |
130 | UUID itemId = TestHelpers.ParseTail(0x20); | 133 | UUID itemId = TestHelpers.ParseTail(0x20); |
@@ -134,7 +137,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
134 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); | 137 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); |
135 | m_scene.AddSceneObject(so2); | 138 | m_scene.AddSceneObject(so2); |
136 | LSL_Api api2 = new LSL_Api(); | 139 | LSL_Api api2 = new LSL_Api(); |
137 | api2.Initialize(m_engine, so2.RootPart, null); | 140 | api2.Initialize(m_engine, so2.RootPart, null, null); |
138 | 141 | ||
139 | // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** | 142 | // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** |
140 | api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); | 143 | api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs index 2565ae7..5b57bbe 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs | |||
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC; | |||
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
44 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | 45 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
45 | using OpenSim.Services.Interfaces; | 46 | using OpenSim.Services.Interfaces; |
46 | using OpenSim.Tests.Common; | 47 | using OpenSim.Tests.Common; |
@@ -56,14 +57,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
56 | /// OpenSim.Region.Framework.Scenes.Tests.SceneObjectLinkingTests. | 57 | /// OpenSim.Region.Framework.Scenes.Tests.SceneObjectLinkingTests. |
57 | /// </remarks> | 58 | /// </remarks> |
58 | [TestFixture] | 59 | [TestFixture] |
59 | public class LSL_ApiLinkingTests | 60 | public class LSL_ApiLinkingTests : OpenSimTestCase |
60 | { | 61 | { |
61 | protected Scene m_scene; | 62 | protected Scene m_scene; |
62 | protected XEngine.XEngine m_engine; | 63 | protected XEngine.XEngine m_engine; |
63 | 64 | ||
64 | [SetUp] | 65 | [SetUp] |
65 | public void SetUp() | 66 | public override void SetUp() |
66 | { | 67 | { |
68 | base.SetUp(); | ||
69 | |||
67 | IConfigSource initConfigSource = new IniConfigSource(); | 70 | IConfigSource initConfigSource = new IniConfigSource(); |
68 | IConfig config = initConfigSource.AddConfig("XEngine"); | 71 | IConfig config = initConfigSource.AddConfig("XEngine"); |
69 | config.Set("Enabled", "true"); | 72 | config.Set("Enabled", "true"); |
@@ -102,7 +105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
102 | m_scene.AddSceneObject(grp2); | 105 | m_scene.AddSceneObject(grp2); |
103 | 106 | ||
104 | LSL_Api apiGrp1 = new LSL_Api(); | 107 | LSL_Api apiGrp1 = new LSL_Api(); |
105 | apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item); | 108 | apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item, null); |
106 | 109 | ||
107 | apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE); | 110 | apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE); |
108 | 111 | ||
@@ -129,7 +132,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
129 | grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; | 132 | grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; |
130 | 133 | ||
131 | LSL_Api apiGrp1 = new LSL_Api(); | 134 | LSL_Api apiGrp1 = new LSL_Api(); |
132 | apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item); | 135 | apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item, null); |
133 | 136 | ||
134 | apiGrp1.llBreakLink(2); | 137 | apiGrp1.llBreakLink(2); |
135 | 138 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs index dd23be8..60de5cb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs | |||
@@ -34,6 +34,7 @@ using OpenSim.Region.ScriptEngine.Shared; | |||
34 | using OpenSim.Region.Framework.Scenes; | 34 | using OpenSim.Region.Framework.Scenes; |
35 | using Nini.Config; | 35 | using Nini.Config; |
36 | using OpenSim.Region.ScriptEngine.Shared.Api; | 36 | using OpenSim.Region.ScriptEngine.Shared.Api; |
37 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
37 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | 38 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
38 | using OpenMetaverse; | 39 | using OpenMetaverse; |
39 | using OpenSim.Tests.Common.Mock; | 40 | using OpenSim.Tests.Common.Mock; |
@@ -46,13 +47,15 @@ using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | |||
46 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | 47 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
47 | { | 48 | { |
48 | [TestFixture] | 49 | [TestFixture] |
49 | public class LSL_ApiListTests | 50 | public class LSL_ApiListTests : OpenSimTestCase |
50 | { | 51 | { |
51 | private LSL_Api m_lslApi; | 52 | private LSL_Api m_lslApi; |
52 | 53 | ||
53 | [SetUp] | 54 | [SetUp] |
54 | public void SetUp() | 55 | public override void SetUp() |
55 | { | 56 | { |
57 | base.SetUp(); | ||
58 | |||
56 | IConfigSource initConfigSource = new IniConfigSource(); | 59 | IConfigSource initConfigSource = new IniConfigSource(); |
57 | IConfig config = initConfigSource.AddConfig("XEngine"); | 60 | IConfig config = initConfigSource.AddConfig("XEngine"); |
58 | config.Set("Enabled", "true"); | 61 | config.Set("Enabled", "true"); |
@@ -65,7 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
65 | engine.AddRegion(scene); | 68 | engine.AddRegion(scene); |
66 | 69 | ||
67 | m_lslApi = new LSL_Api(); | 70 | m_lslApi = new LSL_Api(); |
68 | m_lslApi.Initialize(engine, part, null); | 71 | m_lslApi.Initialize(engine, part, null, null); |
69 | } | 72 | } |
70 | 73 | ||
71 | [Test] | 74 | [Test] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index c41d1e7..e97ae06 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs | |||
@@ -33,6 +33,7 @@ using OpenSim.Region.ScriptEngine.Shared; | |||
33 | using OpenSim.Region.Framework.Scenes; | 33 | using OpenSim.Region.Framework.Scenes; |
34 | using Nini.Config; | 34 | using Nini.Config; |
35 | using OpenSim.Region.ScriptEngine.Shared.Api; | 35 | using OpenSim.Region.ScriptEngine.Shared.Api; |
36 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
36 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | 37 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
37 | using OpenMetaverse; | 38 | using OpenMetaverse; |
38 | using System; | 39 | using System; |
@@ -66,7 +67,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
66 | engine.AddRegion(scene); | 67 | engine.AddRegion(scene); |
67 | 68 | ||
68 | m_lslApi = new LSL_Api(); | 69 | m_lslApi = new LSL_Api(); |
69 | m_lslApi.Initialize(engine, part, null); | 70 | m_lslApi.Initialize(engine, part, null, null); |
70 | } | 71 | } |
71 | 72 | ||
72 | [Test] | 73 | [Test] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs index 3ed2562..c8c7f82 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs | |||
@@ -33,7 +33,7 @@ using OpenSim.Region.ScriptEngine.Shared; | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | 33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
34 | { | 34 | { |
35 | [TestFixture] | 35 | [TestFixture] |
36 | public class LSL_TypesTestLSLFloat | 36 | public class LSL_TypesTestLSLFloat : OpenSimTestCase |
37 | { | 37 | { |
38 | // Used for testing equality of two floats. | 38 | // Used for testing equality of two floats. |
39 | private double _lowPrecisionTolerance = 0.000001; | 39 | private double _lowPrecisionTolerance = 0.000001; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs index 8d1169a..c664108 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs | |||
@@ -33,7 +33,7 @@ using OpenSim.Region.ScriptEngine.Shared; | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | 33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
34 | { | 34 | { |
35 | [TestFixture] | 35 | [TestFixture] |
36 | public class LSL_TypesTestLSLInteger | 36 | public class LSL_TypesTestLSLInteger : OpenSimTestCase |
37 | { | 37 | { |
38 | private Dictionary<double, int> m_doubleIntSet; | 38 | private Dictionary<double, int> m_doubleIntSet; |
39 | private Dictionary<string, int> m_stringIntSet; | 39 | private Dictionary<string, int> m_stringIntSet; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs index c4ca1a8..8550f2d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs | |||
@@ -33,7 +33,7 @@ using OpenSim.Region.ScriptEngine.Shared; | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | 33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
34 | { | 34 | { |
35 | [TestFixture] | 35 | [TestFixture] |
36 | public class LSL_TypesTestLSLString | 36 | public class LSL_TypesTestLSLString : OpenSimTestCase |
37 | { | 37 | { |
38 | private Dictionary<double, string> m_doubleStringSet; | 38 | private Dictionary<double, string> m_doubleStringSet; |
39 | 39 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs index b81225f..71b88bc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs | |||
@@ -36,7 +36,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
36 | /// Tests the LSL_Types.list class. | 36 | /// Tests the LSL_Types.list class. |
37 | /// </summary> | 37 | /// </summary> |
38 | [TestFixture] | 38 | [TestFixture] |
39 | public class LSL_TypesTestList | 39 | public class LSL_TypesTestList : OpenSimTestCase |
40 | { | 40 | { |
41 | /// <summary> | 41 | /// <summary> |
42 | /// Tests concatenating a string to a list. | 42 | /// Tests concatenating a string to a list. |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs index ebf8001..0c838af 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs | |||
@@ -36,7 +36,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
36 | /// Tests for Vector3 | 36 | /// Tests for Vector3 |
37 | /// </summary> | 37 | /// </summary> |
38 | [TestFixture] | 38 | [TestFixture] |
39 | public class LSL_TypesTestVector3 | 39 | public class LSL_TypesTestVector3 : OpenSimTestCase |
40 | { | 40 | { |
41 | [Test] | 41 | [Test] |
42 | public void TestDotProduct() | 42 | public void TestDotProduct() |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs index c401794..c88bad5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | |||
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC; | |||
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
44 | using OpenSim.Services.Interfaces; | 45 | using OpenSim.Services.Interfaces; |
45 | using OpenSim.Tests.Common; | 46 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | 47 | using OpenSim.Tests.Common.Mock; |
@@ -51,14 +52,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
51 | /// Tests for OSSL_Api | 52 | /// Tests for OSSL_Api |
52 | /// </summary> | 53 | /// </summary> |
53 | [TestFixture] | 54 | [TestFixture] |
54 | public class OSSL_ApiAppearanceTest | 55 | public class OSSL_ApiAppearanceTest : OpenSimTestCase |
55 | { | 56 | { |
56 | protected Scene m_scene; | 57 | protected Scene m_scene; |
57 | protected XEngine.XEngine m_engine; | 58 | protected XEngine.XEngine m_engine; |
58 | 59 | ||
59 | [SetUp] | 60 | [SetUp] |
60 | public void SetUp() | 61 | public override void SetUp() |
61 | { | 62 | { |
63 | base.SetUp(); | ||
64 | |||
62 | IConfigSource initConfigSource = new IniConfigSource(); | 65 | IConfigSource initConfigSource = new IniConfigSource(); |
63 | IConfig config = initConfigSource.AddConfig("XEngine"); | 66 | IConfig config = initConfigSource.AddConfig("XEngine"); |
64 | config.Set("Enabled", "true"); | 67 | config.Set("Enabled", "true"); |
@@ -91,7 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
91 | m_scene.AddSceneObject(so); | 94 | m_scene.AddSceneObject(so); |
92 | 95 | ||
93 | OSSL_Api osslApi = new OSSL_Api(); | 96 | OSSL_Api osslApi = new OSSL_Api(); |
94 | osslApi.Initialize(m_engine, part, null); | 97 | osslApi.Initialize(m_engine, part, null, null); |
95 | 98 | ||
96 | string notecardName = "appearanceNc"; | 99 | string notecardName = "appearanceNc"; |
97 | 100 | ||
@@ -132,7 +135,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
132 | m_scene.AddSceneObject(so); | 135 | m_scene.AddSceneObject(so); |
133 | 136 | ||
134 | OSSL_Api osslApi = new OSSL_Api(); | 137 | OSSL_Api osslApi = new OSSL_Api(); |
135 | osslApi.Initialize(m_engine, part, null); | 138 | osslApi.Initialize(m_engine, part, null, null); |
136 | 139 | ||
137 | string notecardName = "appearanceNc"; | 140 | string notecardName = "appearanceNc"; |
138 | 141 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs index 5ed1f3d..b2803a1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs | |||
@@ -41,6 +41,7 @@ using OpenSim.Region.CoreModules.Framework.InventoryAccess; | |||
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
44 | using OpenSim.Services.Interfaces; | 45 | using OpenSim.Services.Interfaces; |
45 | using OpenSim.Tests.Common; | 46 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | 47 | using OpenSim.Tests.Common.Mock; |
@@ -98,9 +99,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
98 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); | 99 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); |
99 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); | 100 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); |
100 | 101 | ||
101 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 102 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
102 | OSSL_Api osslApi = new OSSL_Api(); | 103 | OSSL_Api osslApi = new OSSL_Api(); |
103 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 104 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
104 | 105 | ||
105 | // SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID); | 106 | // SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID); |
106 | 107 | ||
@@ -144,9 +145,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
144 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); | 145 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); |
145 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); | 146 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); |
146 | 147 | ||
147 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 148 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
148 | OSSL_Api osslApi = new OSSL_Api(); | 149 | OSSL_Api osslApi = new OSSL_Api(); |
149 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 150 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
150 | 151 | ||
151 | // Create an object embedded inside the first | 152 | // Create an object embedded inside the first |
152 | TaskInventoryHelpers.AddNotecard( | 153 | TaskInventoryHelpers.AddNotecard( |
@@ -192,12 +193,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
192 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); | 193 | SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); |
193 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); | 194 | TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); |
194 | 195 | ||
195 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 196 | new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
196 | OSSL_Api osslApi = new OSSL_Api(); | 197 | OSSL_Api osslApi = new OSSL_Api(); |
197 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); | 198 | osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null); |
198 | 199 | ||
199 | // Create an object embedded inside the first | 200 | // Create an object embedded inside the first |
200 | TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID); | 201 | TaskInventoryHelpers.AddSceneObject( |
202 | m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID); | ||
201 | 203 | ||
202 | ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2); | 204 | ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2); |
203 | 205 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index b49bcc2..1f8a6e5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | |||
@@ -42,6 +42,7 @@ using OpenSim.Region.OptionalModules.World.NPC; | |||
42 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
43 | using OpenSim.Region.ScriptEngine.Shared; | 43 | using OpenSim.Region.ScriptEngine.Shared; |
44 | using OpenSim.Region.ScriptEngine.Shared.Api; | 44 | using OpenSim.Region.ScriptEngine.Shared.Api; |
45 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
45 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | 46 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
46 | using OpenSim.Services.Interfaces; | 47 | using OpenSim.Services.Interfaces; |
47 | using OpenSim.Tests.Common; | 48 | using OpenSim.Tests.Common; |
@@ -99,7 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
99 | m_scene.AddSceneObject(so); | 100 | m_scene.AddSceneObject(so); |
100 | 101 | ||
101 | OSSL_Api osslApi = new OSSL_Api(); | 102 | OSSL_Api osslApi = new OSSL_Api(); |
102 | osslApi.Initialize(m_engine, part, null); | 103 | osslApi.Initialize(m_engine, part, null, null); |
103 | 104 | ||
104 | string notecardName = "appearanceNc"; | 105 | string notecardName = "appearanceNc"; |
105 | osslApi.osOwnerSaveAppearance(notecardName); | 106 | osslApi.osOwnerSaveAppearance(notecardName); |
@@ -125,14 +126,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
125 | m_scene.AddSceneObject(so); | 126 | m_scene.AddSceneObject(so); |
126 | 127 | ||
127 | OSSL_Api osslApi = new OSSL_Api(); | 128 | OSSL_Api osslApi = new OSSL_Api(); |
128 | osslApi.Initialize(m_engine, so.RootPart, null); | 129 | osslApi.Initialize(m_engine, so.RootPart, null, null); |
129 | 130 | ||
130 | string npcRaw; | ||
131 | bool gotExpectedException = false; | 131 | bool gotExpectedException = false; |
132 | try | 132 | try |
133 | { | 133 | { |
134 | npcRaw | 134 | osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); |
135 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); | ||
136 | } | 135 | } |
137 | catch (ScriptException) | 136 | catch (ScriptException) |
138 | { | 137 | { |
@@ -162,7 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
162 | m_scene.AddSceneObject(so); | 161 | m_scene.AddSceneObject(so); |
163 | 162 | ||
164 | OSSL_Api osslApi = new OSSL_Api(); | 163 | OSSL_Api osslApi = new OSSL_Api(); |
165 | osslApi.Initialize(m_engine, part, null); | 164 | osslApi.Initialize(m_engine, part, null, null); |
166 | 165 | ||
167 | string notecardName = "appearanceNc"; | 166 | string notecardName = "appearanceNc"; |
168 | osslApi.osOwnerSaveAppearance(notecardName); | 167 | osslApi.osOwnerSaveAppearance(notecardName); |
@@ -196,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
196 | m_scene.AddSceneObject(so); | 195 | m_scene.AddSceneObject(so); |
197 | 196 | ||
198 | OSSL_Api osslApi = new OSSL_Api(); | 197 | OSSL_Api osslApi = new OSSL_Api(); |
199 | osslApi.Initialize(m_engine, part, null); | 198 | osslApi.Initialize(m_engine, part, null, null); |
200 | 199 | ||
201 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); | 200 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); |
202 | 201 | ||
@@ -234,7 +233,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
234 | m_scene.AddSceneObject(so); | 233 | m_scene.AddSceneObject(so); |
235 | 234 | ||
236 | OSSL_Api osslApi = new OSSL_Api(); | 235 | OSSL_Api osslApi = new OSSL_Api(); |
237 | osslApi.Initialize(m_engine, part, null); | 236 | osslApi.Initialize(m_engine, part, null, null); |
238 | 237 | ||
239 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); | 238 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); |
240 | 239 | ||
@@ -286,10 +285,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
286 | m_scene.AddSceneObject(otherSo); | 285 | m_scene.AddSceneObject(otherSo); |
287 | 286 | ||
288 | OSSL_Api osslApi = new OSSL_Api(); | 287 | OSSL_Api osslApi = new OSSL_Api(); |
289 | osslApi.Initialize(m_engine, part, null); | 288 | osslApi.Initialize(m_engine, part, null, null); |
290 | 289 | ||
291 | OSSL_Api otherOsslApi = new OSSL_Api(); | 290 | OSSL_Api otherOsslApi = new OSSL_Api(); |
292 | otherOsslApi.Initialize(m_engine, otherPart, null); | 291 | otherOsslApi.Initialize(m_engine, otherPart, null, null); |
293 | 292 | ||
294 | string notecardName = "appearanceNc"; | 293 | string notecardName = "appearanceNc"; |
295 | osslApi.osOwnerSaveAppearance(notecardName); | 294 | osslApi.osOwnerSaveAppearance(notecardName); |
@@ -333,7 +332,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
333 | m_scene.AddSceneObject(so); | 332 | m_scene.AddSceneObject(so); |
334 | 333 | ||
335 | OSSL_Api osslApi = new OSSL_Api(); | 334 | OSSL_Api osslApi = new OSSL_Api(); |
336 | osslApi.Initialize(m_engine, part, null); | 335 | osslApi.Initialize(m_engine, part, null, null); |
337 | 336 | ||
338 | string notecardName = "appearanceNc"; | 337 | string notecardName = "appearanceNc"; |
339 | osslApi.osOwnerSaveAppearance(notecardName); | 338 | osslApi.osOwnerSaveAppearance(notecardName); |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs new file mode 100644 index 0000000..efb854d --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Framework.Console; | ||
32 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
33 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
34 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.XEngine | ||
37 | { | ||
38 | public class ScriptEngineConsoleCommands | ||
39 | { | ||
40 | IScriptEngine m_engine; | ||
41 | |||
42 | public ScriptEngineConsoleCommands(IScriptEngine engine) | ||
43 | { | ||
44 | m_engine = engine; | ||
45 | } | ||
46 | |||
47 | public void RegisterCommands() | ||
48 | { | ||
49 | MainConsole.Instance.Commands.AddCommand( | ||
50 | "Scripts", false, "show script sensors", "show script sensors", "Show script sensors information", | ||
51 | HandleShowSensors); | ||
52 | |||
53 | MainConsole.Instance.Commands.AddCommand( | ||
54 | "Scripts", false, "show script timers", "show script timers", "Show script sensors information", | ||
55 | HandleShowTimers); | ||
56 | } | ||
57 | |||
58 | private bool IsSceneSelected() | ||
59 | { | ||
60 | return MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World; | ||
61 | } | ||
62 | |||
63 | private void HandleShowSensors(string module, string[] cmdparams) | ||
64 | { | ||
65 | if (!IsSceneSelected()) | ||
66 | return; | ||
67 | |||
68 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine); | ||
69 | |||
70 | if (sr == null) | ||
71 | { | ||
72 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo(); | ||
77 | |||
78 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
79 | cdt.AddColumn("Part name", 40); | ||
80 | cdt.AddColumn("Script item ID", 36); | ||
81 | cdt.AddColumn("Type", 4); | ||
82 | cdt.AddColumn("Interval", 8); | ||
83 | cdt.AddColumn("Range", 8); | ||
84 | cdt.AddColumn("Arc", 8); | ||
85 | |||
86 | foreach (SensorRepeat.SensorInfo s in sensorInfo) | ||
87 | { | ||
88 | cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc); | ||
89 | } | ||
90 | |||
91 | MainConsole.Instance.Output(cdt.ToString()); | ||
92 | MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count); | ||
93 | } | ||
94 | |||
95 | private void HandleShowTimers(string module, string[] cmdparams) | ||
96 | { | ||
97 | if (!IsSceneSelected()) | ||
98 | return; | ||
99 | |||
100 | Timer timerPlugin = AsyncCommandManager.GetTimerPlugin(m_engine); | ||
101 | |||
102 | if (timerPlugin == null) | ||
103 | { | ||
104 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | List<Timer.TimerInfo> timersInfo = timerPlugin.GetTimersInfo(); | ||
109 | |||
110 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
111 | cdt.AddColumn("Part local ID", 13); | ||
112 | cdt.AddColumn("Script item ID", 36); | ||
113 | cdt.AddColumn("Interval", 10); | ||
114 | cdt.AddColumn("Next", 8); | ||
115 | |||
116 | foreach (Timer.TimerInfo t in timersInfo) | ||
117 | { | ||
118 | // Convert from 100 ns ticks back to seconds | ||
119 | cdt.AddRow(t.localID, t.itemID, (double)t.interval / 10000000, t.next); | ||
120 | } | ||
121 | |||
122 | MainConsole.Instance.Output(cdt.ToString()); | ||
123 | MainConsole.Instance.OutputFormat("Total: {0}", timersInfo.Count); | ||
124 | } | ||
125 | } | ||
126 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs index f331658..5abfe9a 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs | |||
@@ -44,7 +44,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests | |||
44 | /// XEngine tests. | 44 | /// XEngine tests. |
45 | /// </summary> | 45 | /// </summary> |
46 | [TestFixture] | 46 | [TestFixture] |
47 | public class XEngineTest | 47 | public class XEngineTest : OpenSimTestCase |
48 | { | 48 | { |
49 | private TestScene m_scene; | 49 | private TestScene m_scene; |
50 | private XEngine m_xEngine; | 50 | private XEngine m_xEngine; |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 9f05666..816d8ba 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using System.Diagnostics; //for [DebuggerNonUserCode] | 31 | using System.Diagnostics; //for [DebuggerNonUserCode] |
32 | using System.Globalization; | 32 | using System.Globalization; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Linq; | ||
34 | using System.Reflection; | 35 | using System.Reflection; |
35 | using System.Security; | 36 | using System.Security; |
36 | using System.Security.Policy; | 37 | using System.Security.Policy; |
@@ -107,6 +108,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
107 | private IXmlRpcRouter m_XmlRpcRouter; | 108 | private IXmlRpcRouter m_XmlRpcRouter; |
108 | private int m_EventLimit; | 109 | private int m_EventLimit; |
109 | private bool m_KillTimedOutScripts; | 110 | private bool m_KillTimedOutScripts; |
111 | |||
112 | /// <summary> | ||
113 | /// Number of milliseconds we will wait for a script event to complete on script stop before we forcibly abort | ||
114 | /// its thread. | ||
115 | /// </summary> | ||
116 | /// <remarks> | ||
117 | /// It appears that if a script thread is aborted whilst it is holding ReaderWriterLockSlim (possibly the write | ||
118 | /// lock) then the lock is not properly released. This causes mono 2.6, 2.10 and possibly | ||
119 | /// later to crash, sometimes with symptoms such as a leap to 100% script usage and a vm thead dump showing | ||
120 | /// all threads waiting on release of ReaderWriterLockSlim write thread which none of the threads listed | ||
121 | /// actually hold. | ||
122 | /// | ||
123 | /// Pausing for event completion reduces the risk of this happening. However, it may be that aborting threads | ||
124 | /// is not a mono issue per se but rather a risky activity in itself in an AppDomain that is not immediately | ||
125 | /// shutting down. | ||
126 | /// </remarks> | ||
127 | private int m_WaitForEventCompletionOnScriptStop = 1000; | ||
128 | |||
110 | private string m_ScriptEnginesPath = null; | 129 | private string m_ScriptEnginesPath = null; |
111 | 130 | ||
112 | private ExpiringCache<UUID, bool> m_runFlags = new ExpiringCache<UUID, bool>(); | 131 | private ExpiringCache<UUID, bool> m_runFlags = new ExpiringCache<UUID, bool>(); |
@@ -218,6 +237,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
218 | } | 237 | } |
219 | } | 238 | } |
220 | 239 | ||
240 | private ScriptEngineConsoleCommands m_consoleCommands; | ||
241 | |||
221 | public string ScriptEngineName | 242 | public string ScriptEngineName |
222 | { | 243 | { |
223 | get { return "XEngine"; } | 244 | get { return "XEngine"; } |
@@ -316,6 +337,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
316 | m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); | 337 | m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); |
317 | m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); | 338 | m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); |
318 | m_SaveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000; | 339 | m_SaveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000; |
340 | m_WaitForEventCompletionOnScriptStop | ||
341 | = m_ScriptConfig.GetInt("WaitForEventCompletionOnScriptStop", m_WaitForEventCompletionOnScriptStop); | ||
342 | |||
319 | m_ScriptEnginesPath = m_ScriptConfig.GetString("ScriptEnginesPath", "ScriptEngines"); | 343 | m_ScriptEnginesPath = m_ScriptConfig.GetString("ScriptEnginesPath", "ScriptEngines"); |
320 | 344 | ||
321 | m_Prio = ThreadPriority.BelowNormal; | 345 | m_Prio = ThreadPriority.BelowNormal; |
@@ -364,48 +388,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
364 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; | 388 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; |
365 | } | 389 | } |
366 | 390 | ||
391 | m_consoleCommands = new ScriptEngineConsoleCommands(this); | ||
392 | m_consoleCommands.RegisterCommands(); | ||
393 | |||
367 | MainConsole.Instance.Commands.AddCommand( | 394 | MainConsole.Instance.Commands.AddCommand( |
368 | "Scripts", false, "xengine status", "xengine status", "Show status information", | 395 | "Scripts", false, "xengine status", "xengine status", "Show status information", |
369 | "Show status information on the script engine.", | 396 | "Show status information on the script engine.", |
370 | HandleShowStatus); | 397 | HandleShowStatus); |
371 | 398 | ||
372 | MainConsole.Instance.Commands.AddCommand( | 399 | MainConsole.Instance.Commands.AddCommand( |
373 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>]", "Show script information", | 400 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>+]", "Show script information", |
374 | "Show information on all scripts known to the script engine." | 401 | "Show information on all scripts known to the script engine.\n" |
375 | + "If a <script-item-uuid> is given then only information on that script will be shown.", | 402 | + "If one or more <script-item-uuid>s are given then only information on that script will be shown.", |
376 | HandleShowScripts); | 403 | HandleShowScripts); |
377 | 404 | ||
378 | MainConsole.Instance.Commands.AddCommand( | 405 | MainConsole.Instance.Commands.AddCommand( |
379 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>]", "Show script information", | 406 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>+]", "Show script information", |
380 | "Synonym for scripts show command", HandleShowScripts); | 407 | "Synonym for scripts show command", HandleShowScripts); |
381 | 408 | ||
382 | MainConsole.Instance.Commands.AddCommand( | 409 | MainConsole.Instance.Commands.AddCommand( |
383 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>]", "Suspends all running scripts", | 410 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>+]", "Suspends all running scripts", |
384 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" | 411 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" |
385 | + " script that is currently processing an event.\n" | 412 | + " script that is currently processing an event.\n" |
386 | + "Suspended scripts will continue to accumulate events but won't process them.\n" | 413 | + "Suspended scripts will continue to accumulate events but won't process them.\n" |
387 | + "If a <script-item-uuid> is given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", | 414 | + "If one or more <script-item-uuid>s are given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", |
388 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); | 415 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); |
389 | 416 | ||
390 | MainConsole.Instance.Commands.AddCommand( | 417 | MainConsole.Instance.Commands.AddCommand( |
391 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>]", "Resumes all suspended scripts", | 418 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>+]", "Resumes all suspended scripts", |
392 | "Resumes all currently suspended scripts.\n" | 419 | "Resumes all currently suspended scripts.\n" |
393 | + "Resumed scripts will process all events accumulated whilst suspended." | 420 | + "Resumed scripts will process all events accumulated whilst suspended.\n" |
394 | + "If a <script-item-uuid> is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", | 421 | + "If one or more <script-item-uuid>s are given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", |
395 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); | 422 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); |
396 | 423 | ||
397 | MainConsole.Instance.Commands.AddCommand( | 424 | MainConsole.Instance.Commands.AddCommand( |
398 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>]", "Stops all running scripts", | 425 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>+]", "Stops all running scripts", |
399 | "Stops all running scripts." | 426 | "Stops all running scripts.\n" |
400 | + "If a <script-item-uuid> is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", | 427 | + "If one or more <script-item-uuid>s are given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", |
401 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); | 428 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); |
402 | 429 | ||
403 | MainConsole.Instance.Commands.AddCommand( | 430 | MainConsole.Instance.Commands.AddCommand( |
404 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>]", "Starts all stopped scripts", | 431 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>+]", "Starts all stopped scripts", |
405 | "Starts all stopped scripts." | 432 | "Starts all stopped scripts.\n" |
406 | + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", | 433 | + "If one or more <script-item-uuid>s are given then only that script will be started. Otherwise, all suitable scripts are started.", |
407 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); | 434 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); |
408 | 435 | ||
436 | MainConsole.Instance.Commands.AddCommand( | ||
437 | "Scripts", false, "debug scripts log", "debug scripts log <item-id> <log-level>", "Extra debug logging for a script", | ||
438 | "Activates or deactivates extra debug logging for the given script.\n" | ||
439 | + "Level == 0, deactivate extra debug logging.\n" | ||
440 | + "Level >= 1, log state changes.\n" | ||
441 | + "Level >= 2, log event invocations.\n", | ||
442 | HandleDebugScriptLogCommand); | ||
443 | |||
409 | // MainConsole.Instance.Commands.AddCommand( | 444 | // MainConsole.Instance.Commands.AddCommand( |
410 | // "Debug", false, "debug xengine", "debug xengine [<level>]", | 445 | // "Debug", false, "debug xengine", "debug xengine [<level>]", |
411 | // "Turn on detailed xengine debugging.", | 446 | // "Turn on detailed xengine debugging.", |
@@ -414,6 +449,41 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
414 | // HandleDebugLevelCommand); | 449 | // HandleDebugLevelCommand); |
415 | } | 450 | } |
416 | 451 | ||
452 | private void HandleDebugScriptLogCommand(string module, string[] args) | ||
453 | { | ||
454 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) | ||
455 | return; | ||
456 | |||
457 | if (args.Length != 5) | ||
458 | { | ||
459 | MainConsole.Instance.Output("Usage: debug script log <item-id> <log-level>"); | ||
460 | return; | ||
461 | } | ||
462 | |||
463 | UUID itemId; | ||
464 | |||
465 | if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, args[3], out itemId)) | ||
466 | return; | ||
467 | |||
468 | int newLevel; | ||
469 | |||
470 | if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out newLevel)) | ||
471 | return; | ||
472 | |||
473 | IScriptInstance si; | ||
474 | |||
475 | lock (m_Scripts) | ||
476 | { | ||
477 | // XXX: We can't give the user feedback on a bad item id because this may apply to a different script | ||
478 | // engine | ||
479 | if (!m_Scripts.TryGetValue(itemId, out si)) | ||
480 | return; | ||
481 | } | ||
482 | |||
483 | si.DebugLevel = newLevel; | ||
484 | MainConsole.Instance.OutputFormat("Set debug level of {0} {1} to {2}", si.ScriptName, si.ItemID, newLevel); | ||
485 | } | ||
486 | |||
417 | /// <summary> | 487 | /// <summary> |
418 | /// Change debug level | 488 | /// Change debug level |
419 | /// </summary> | 489 | /// </summary> |
@@ -445,9 +515,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
445 | /// </summary> | 515 | /// </summary> |
446 | /// <param name="cmdparams"></param> | 516 | /// <param name="cmdparams"></param> |
447 | /// <param name="instance"></param> | 517 | /// <param name="instance"></param> |
448 | /// <returns>true if we're okay to proceed, false if not.</returns> | 518 | /// <param name="comparer">Basis on which to sort output. Can be null if no sort needs to take place</param> |
449 | private void HandleScriptsAction(string[] cmdparams, Action<IScriptInstance> action) | 519 | private void HandleScriptsAction(string[] cmdparams, Action<IScriptInstance> action) |
450 | { | 520 | { |
521 | HandleScriptsAction<object>(cmdparams, action, null); | ||
522 | } | ||
523 | |||
524 | /// <summary> | ||
525 | /// Parse the raw item id into a script instance from the command params if it's present. | ||
526 | /// </summary> | ||
527 | /// <param name="cmdparams"></param> | ||
528 | /// <param name="instance"></param> | ||
529 | /// <param name="keySelector">Basis on which to sort output. Can be null if no sort needs to take place</param> | ||
530 | private void HandleScriptsAction<TKey>( | ||
531 | string[] cmdparams, Action<IScriptInstance> action, Func<IScriptInstance, TKey> keySelector) | ||
532 | { | ||
451 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) | 533 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) |
452 | return; | 534 | return; |
453 | 535 | ||
@@ -458,35 +540,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
458 | 540 | ||
459 | if (cmdparams.Length == 2) | 541 | if (cmdparams.Length == 2) |
460 | { | 542 | { |
461 | foreach (IScriptInstance instance in m_Scripts.Values) | 543 | IEnumerable<IScriptInstance> scripts = m_Scripts.Values; |
544 | |||
545 | if (keySelector != null) | ||
546 | scripts = scripts.OrderBy<IScriptInstance, TKey>(keySelector); | ||
547 | |||
548 | foreach (IScriptInstance instance in scripts) | ||
462 | action(instance); | 549 | action(instance); |
463 | 550 | ||
464 | return; | 551 | return; |
465 | } | 552 | } |
466 | 553 | ||
467 | rawItemId = cmdparams[2]; | 554 | for (int i = 2; i < cmdparams.Length; i++) |
468 | |||
469 | if (!UUID.TryParse(rawItemId, out itemId)) | ||
470 | { | ||
471 | MainConsole.Instance.OutputFormat("Error - {0} is not a valid UUID", rawItemId); | ||
472 | return; | ||
473 | } | ||
474 | |||
475 | if (itemId != UUID.Zero) | ||
476 | { | 555 | { |
477 | IScriptInstance instance = GetInstance(itemId); | 556 | rawItemId = cmdparams[i]; |
478 | if (instance == null) | 557 | |
558 | if (!UUID.TryParse(rawItemId, out itemId)) | ||
479 | { | 559 | { |
480 | // Commented out for now since this will cause false reports on simulators with more than | 560 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid UUID", rawItemId); |
481 | // one scene where the current command line set region is 'root' (which causes commands to | 561 | continue; |
482 | // go to both regions... (sigh) | ||
483 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
484 | return; | ||
485 | } | 562 | } |
486 | else | 563 | |
564 | if (itemId != UUID.Zero) | ||
487 | { | 565 | { |
488 | action(instance); | 566 | IScriptInstance instance = GetInstance(itemId); |
489 | return; | 567 | if (instance == null) |
568 | { | ||
569 | // Commented out for now since this will cause false reports on simulators with more than | ||
570 | // one scene where the current command line set region is 'root' (which causes commands to | ||
571 | // go to both regions... (sigh) | ||
572 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
573 | continue; | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | action(instance); | ||
578 | } | ||
490 | } | 579 | } |
491 | } | 580 | } |
492 | } | 581 | } |
@@ -505,9 +594,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
505 | StringBuilder sb = new StringBuilder(); | 594 | StringBuilder sb = new StringBuilder(); |
506 | sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); | 595 | sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); |
507 | 596 | ||
597 | long scriptsLoaded, eventsQueued = 0, eventsProcessed = 0; | ||
598 | |||
508 | lock (m_Scripts) | 599 | lock (m_Scripts) |
509 | sb.AppendFormat("Scripts loaded : {0}\n", m_Scripts.Count); | 600 | { |
601 | scriptsLoaded = m_Scripts.Count; | ||
510 | 602 | ||
603 | foreach (IScriptInstance si in m_Scripts.Values) | ||
604 | { | ||
605 | eventsQueued += si.EventsQueued; | ||
606 | eventsProcessed += si.EventsProcessed; | ||
607 | } | ||
608 | } | ||
609 | |||
610 | sb.AppendFormat("Scripts loaded : {0}\n", scriptsLoaded); | ||
511 | sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); | 611 | sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); |
512 | sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); | 612 | sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); |
513 | sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); | 613 | sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); |
@@ -516,6 +616,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
516 | sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); | 616 | sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); |
517 | sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); | 617 | sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); |
518 | // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); | 618 | // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); |
619 | sb.AppendFormat("Events queued : {0}\n", eventsQueued); | ||
620 | sb.AppendFormat("Events processed : {0}\n", eventsProcessed); | ||
519 | 621 | ||
520 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); | 622 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); |
521 | sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); | 623 | sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); |
@@ -546,7 +648,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
546 | } | 648 | } |
547 | } | 649 | } |
548 | 650 | ||
549 | HandleScriptsAction(cmdparams, HandleShowScript); | 651 | HandleScriptsAction<long>(cmdparams, HandleShowScript, si => si.EventsProcessed); |
550 | } | 652 | } |
551 | 653 | ||
552 | private void HandleShowScript(IScriptInstance instance) | 654 | private void HandleShowScript(IScriptInstance instance) |
@@ -576,11 +678,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
576 | 678 | ||
577 | sb.AppendFormat("Script name : {0}\n", instance.ScriptName); | 679 | sb.AppendFormat("Script name : {0}\n", instance.ScriptName); |
578 | sb.AppendFormat("Status : {0}\n", status); | 680 | sb.AppendFormat("Status : {0}\n", status); |
579 | 681 | sb.AppendFormat("Queued events : {0}\n", instance.EventsQueued); | |
580 | lock (eq) | 682 | sb.AppendFormat("Processed events : {0}\n", instance.EventsProcessed); |
581 | sb.AppendFormat("Queued events : {0}\n", eq.Count); | ||
582 | |||
583 | sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); | 683 | sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); |
684 | sb.AppendFormat("Asset UUID : {0}\n", instance.AssetID); | ||
584 | sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); | 685 | sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); |
585 | sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); | 686 | sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); |
586 | sb.AppendFormat("Position : {0}\n", sop.AbsolutePosition); | 687 | sb.AppendFormat("Position : {0}\n", sop.AbsolutePosition); |
@@ -1089,8 +1190,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1089 | 1190 | ||
1090 | string assembly = ""; | 1191 | string assembly = ""; |
1091 | 1192 | ||
1092 | CultureInfo USCulture = new CultureInfo("en-US"); | 1193 | Culture.SetCurrentCulture(); |
1093 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
1094 | 1194 | ||
1095 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; | 1195 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; |
1096 | 1196 | ||
@@ -1256,12 +1356,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1256 | m_DomainScripts[appDomain].Add(itemID); | 1356 | m_DomainScripts[appDomain].Add(itemID); |
1257 | 1357 | ||
1258 | instance = new ScriptInstance(this, part, | 1358 | instance = new ScriptInstance(this, part, |
1259 | itemID, assetID, assembly, | 1359 | item, |
1260 | m_AppDomains[appDomain], | 1360 | startParam, postOnRez, |
1261 | part.ParentGroup.RootPart.Name, | 1361 | m_MaxScriptQueue); |
1262 | item.Name, startParam, postOnRez, | ||
1263 | stateSource, m_MaxScriptQueue); | ||
1264 | 1362 | ||
1363 | instance.Load(m_AppDomains[appDomain], assembly, stateSource); | ||
1265 | // m_log.DebugFormat( | 1364 | // m_log.DebugFormat( |
1266 | // "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", | 1365 | // "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", |
1267 | // part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, | 1366 | // part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, |
@@ -1347,9 +1446,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1347 | lockScriptsForWrite(false); | 1446 | lockScriptsForWrite(false); |
1348 | instance.ClearQueue(); | 1447 | instance.ClearQueue(); |
1349 | 1448 | ||
1350 | // Give the script some time to finish processing its last event. Simply aborting the script thread can | 1449 | instance.Stop(m_WaitForEventCompletionOnScriptStop); |
1351 | // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. | ||
1352 | instance.Stop(1000); | ||
1353 | 1450 | ||
1354 | // bool objectRemoved = false; | 1451 | // bool objectRemoved = false; |
1355 | 1452 | ||
@@ -1477,7 +1574,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1477 | m_MaxScriptQueue = maxScriptQueue; | 1574 | m_MaxScriptQueue = maxScriptQueue; |
1478 | 1575 | ||
1479 | STPStartInfo startInfo = new STPStartInfo(); | 1576 | STPStartInfo startInfo = new STPStartInfo(); |
1480 | startInfo.IdleTimeout = idleTimeout*1000; // convert to seconds as stated in .ini | 1577 | startInfo.ThreadPoolName = "XEngine"; |
1578 | startInfo.IdleTimeout = idleTimeout * 1000; // convert to seconds as stated in .ini | ||
1481 | startInfo.MaxWorkerThreads = maxThreads; | 1579 | startInfo.MaxWorkerThreads = maxThreads; |
1482 | startInfo.MinWorkerThreads = minThreads; | 1580 | startInfo.MinWorkerThreads = minThreads; |
1483 | startInfo.ThreadPriority = threadPriority;; | 1581 | startInfo.ThreadPriority = threadPriority;; |
@@ -1504,8 +1602,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1504 | /// <returns></returns> | 1602 | /// <returns></returns> |
1505 | private object ProcessEventHandler(object parms) | 1603 | private object ProcessEventHandler(object parms) |
1506 | { | 1604 | { |
1507 | CultureInfo USCulture = new CultureInfo("en-US"); | 1605 | Culture.SetCurrentCulture(); |
1508 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
1509 | 1606 | ||
1510 | IScriptInstance instance = (ScriptInstance) parms; | 1607 | IScriptInstance instance = (ScriptInstance) parms; |
1511 | 1608 | ||
@@ -1693,7 +1790,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1693 | { | 1790 | { |
1694 | IScriptInstance instance = GetInstance(itemID); | 1791 | IScriptInstance instance = GetInstance(itemID); |
1695 | if (instance != null) | 1792 | if (instance != null) |
1696 | instance.ResetScript(); | 1793 | instance.ResetScript(m_WaitForEventCompletionOnScriptStop); |
1697 | } | 1794 | } |
1698 | 1795 | ||
1699 | public void StartScript(UUID itemID) | 1796 | public void StartScript(UUID itemID) |
@@ -1708,14 +1805,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1708 | public void StopScript(UUID itemID) | 1805 | public void StopScript(UUID itemID) |
1709 | { | 1806 | { |
1710 | IScriptInstance instance = GetInstance(itemID); | 1807 | IScriptInstance instance = GetInstance(itemID); |
1808 | |||
1711 | if (instance != null) | 1809 | if (instance != null) |
1712 | { | 1810 | { |
1713 | // Give the script some time to finish processing its last event. Simply aborting the script thread can | 1811 | instance.Stop(m_WaitForEventCompletionOnScriptStop); |
1714 | // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. | ||
1715 | instance.Stop(1000); | ||
1716 | } | 1812 | } |
1717 | else | 1813 | else |
1718 | { | 1814 | { |
1815 | // m_log.DebugFormat("[XENGINE]: Could not find script with ID {0} to stop in {1}", itemID, World.Name); | ||
1719 | m_runFlags.AddOrUpdate(itemID, false, 240); | 1816 | m_runFlags.AddOrUpdate(itemID, false, 240); |
1720 | } | 1817 | } |
1721 | } | 1818 | } |
diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index b08233c..64cb577 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs | |||
@@ -94,8 +94,6 @@ namespace OpenSim.Region.UserStatistics | |||
94 | if (!enabled) | 94 | if (!enabled) |
95 | return; | 95 | return; |
96 | 96 | ||
97 | AddEventHandlers(); | ||
98 | |||
99 | if (Util.IsWindows()) | 97 | if (Util.IsWindows()) |
100 | Util.LoadArchSpecificWindowsDll("sqlite3.dll"); | 98 | Util.LoadArchSpecificWindowsDll("sqlite3.dll"); |
101 | 99 | ||
@@ -143,10 +141,14 @@ namespace OpenSim.Region.UserStatistics | |||
143 | lock (m_scenes) | 141 | lock (m_scenes) |
144 | { | 142 | { |
145 | m_scenes.Add(scene); | 143 | m_scenes.Add(scene); |
146 | if (m_simstatsCounters.ContainsKey(scene.RegionInfo.RegionID)) | 144 | updateLogMod = m_scenes.Count * 2; |
147 | m_simstatsCounters.Remove(scene.RegionInfo.RegionID); | ||
148 | 145 | ||
149 | m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID)); | 146 | m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID)); |
147 | |||
148 | scene.EventManager.OnRegisterCaps += OnRegisterCaps; | ||
149 | scene.EventManager.OnDeregisterCaps += OnDeRegisterCaps; | ||
150 | scene.EventManager.OnClientClosed += OnClientClosed; | ||
151 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
150 | scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket; | 152 | scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket; |
151 | } | 153 | } |
152 | } | 154 | } |
@@ -157,6 +159,15 @@ namespace OpenSim.Region.UserStatistics | |||
157 | 159 | ||
158 | public void RemoveRegion(Scene scene) | 160 | public void RemoveRegion(Scene scene) |
159 | { | 161 | { |
162 | if (!enabled) | ||
163 | return; | ||
164 | |||
165 | lock (m_scenes) | ||
166 | { | ||
167 | m_scenes.Remove(scene); | ||
168 | updateLogMod = m_scenes.Count * 2; | ||
169 | m_simstatsCounters.Remove(scene.RegionInfo.RegionID); | ||
170 | } | ||
160 | } | 171 | } |
161 | 172 | ||
162 | public virtual void Close() | 173 | public virtual void Close() |
@@ -187,9 +198,7 @@ namespace OpenSim.Region.UserStatistics | |||
187 | private void ReceiveClassicSimStatsPacket(SimStats stats) | 198 | private void ReceiveClassicSimStatsPacket(SimStats stats) |
188 | { | 199 | { |
189 | if (!enabled) | 200 | if (!enabled) |
190 | { | ||
191 | return; | 201 | return; |
192 | } | ||
193 | 202 | ||
194 | try | 203 | try |
195 | { | 204 | { |
@@ -198,17 +207,25 @@ namespace OpenSim.Region.UserStatistics | |||
198 | if (concurrencyCounter > 0 || System.Environment.TickCount - lastHit > 30000) | 207 | if (concurrencyCounter > 0 || System.Environment.TickCount - lastHit > 30000) |
199 | return; | 208 | return; |
200 | 209 | ||
201 | if ((updateLogCounter++ % updateLogMod) == 0) | 210 | // We will conduct this under lock so that fields such as updateLogCounter do not potentially get |
211 | // confused if a scene is removed. | ||
212 | // XXX: Possibly the scope of this lock could be reduced though it's not critical. | ||
213 | lock (m_scenes) | ||
202 | { | 214 | { |
203 | m_loglines = readLogLines(10); | 215 | if (updateLogMod != 0 && updateLogCounter++ % updateLogMod == 0) |
204 | if (updateLogCounter > 10000) updateLogCounter = 1; | 216 | { |
205 | } | 217 | m_loglines = readLogLines(10); |
206 | 218 | ||
207 | USimStatsData ss = m_simstatsCounters[stats.RegionUUID]; | 219 | if (updateLogCounter > 10000) |
220 | updateLogCounter = 1; | ||
221 | } | ||
208 | 222 | ||
209 | if ((++ss.StatsCounter % updateStatsMod) == 0) | 223 | USimStatsData ss = m_simstatsCounters[stats.RegionUUID]; |
210 | { | 224 | |
211 | ss.ConsumeSimStats(stats); | 225 | if ((++ss.StatsCounter % updateStatsMod) == 0) |
226 | { | ||
227 | ss.ConsumeSimStats(stats); | ||
228 | } | ||
212 | } | 229 | } |
213 | } | 230 | } |
214 | catch (KeyNotFoundException) | 231 | catch (KeyNotFoundException) |