diff options
author | Dan Lake | 2012-02-01 16:25:35 -0800 |
---|---|---|
committer | Dan Lake | 2012-02-01 16:25:35 -0800 |
commit | c10193c72b1f029a958f04d2f5d7ee384e693aaa (patch) | |
tree | 052ec7e973c15b158310511197affad14eb9c64f /OpenSim/Region/Physics/OdePlugin | |
parent | Trigger event when prims are scheduled for an update. This gives modules earl... (diff) | |
parent | Small optimization to last commit (diff) | |
download | opensim-SC_OLD-c10193c72b1f029a958f04d2f5d7ee384e693aaa.zip opensim-SC_OLD-c10193c72b1f029a958f04d2f5d7ee384e693aaa.tar.gz opensim-SC_OLD-c10193c72b1f029a958f04d2f5d7ee384e693aaa.tar.bz2 opensim-SC_OLD-c10193c72b1f029a958f04d2f5d7ee384e693aaa.tar.xz |
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 40 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 32 |
2 files changed, 59 insertions, 13 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 68999fc..7c1c046 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | |||
@@ -134,9 +134,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
134 | | CollisionCategories.Body | 134 | | CollisionCategories.Body |
135 | | CollisionCategories.Character | 135 | | CollisionCategories.Character |
136 | | CollisionCategories.Land); | 136 | | CollisionCategories.Land); |
137 | internal IntPtr Body = IntPtr.Zero; | 137 | /// <summary> |
138 | /// Body for dynamics simulation | ||
139 | /// </summary> | ||
140 | internal IntPtr Body { get; private set; } | ||
141 | |||
138 | private OdeScene _parent_scene; | 142 | private OdeScene _parent_scene; |
139 | internal IntPtr Shell = IntPtr.Zero; | 143 | |
144 | /// <summary> | ||
145 | /// Collision geometry | ||
146 | /// </summary> | ||
147 | internal IntPtr Shell { get; private set; } | ||
148 | |||
140 | private IntPtr Amotor = IntPtr.Zero; | 149 | private IntPtr Amotor = IntPtr.Zero; |
141 | private d.Mass ShellMass; | 150 | private d.Mass ShellMass; |
142 | 151 | ||
@@ -1018,6 +1027,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1018 | /// <param name="tensor"></param> | 1027 | /// <param name="tensor"></param> |
1019 | private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) | 1028 | private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) |
1020 | { | 1029 | { |
1030 | if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero)) | ||
1031 | { | ||
1032 | m_log.ErrorFormat( | ||
1033 | "[ODE CHARACTER]: Creating ODE structures for {0} even though some already exist. Shell = {1}, Body = {2}, Amotor = {3}", | ||
1034 | Name, Shell, Body, Amotor); | ||
1035 | } | ||
1036 | |||
1021 | int dAMotorEuler = 1; | 1037 | int dAMotorEuler = 1; |
1022 | // _parent_scene.waitForSpaceUnlock(_parent_scene.space); | 1038 | // _parent_scene.waitForSpaceUnlock(_parent_scene.space); |
1023 | if (CAPSULE_LENGTH <= 0) | 1039 | if (CAPSULE_LENGTH <= 0) |
@@ -1032,6 +1048,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1032 | CAPSULE_RADIUS = 0.01f; | 1048 | CAPSULE_RADIUS = 0.01f; |
1033 | } | 1049 | } |
1034 | 1050 | ||
1051 | // lock (OdeScene.UniversalColliderSyncObject) | ||
1035 | Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); | 1052 | Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); |
1036 | 1053 | ||
1037 | d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); | 1054 | d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); |
@@ -1135,6 +1152,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1135 | /// </summary> | 1152 | /// </summary> |
1136 | internal void DestroyOdeStructures() | 1153 | internal void DestroyOdeStructures() |
1137 | { | 1154 | { |
1155 | // Create avatar capsule and related ODE data | ||
1156 | if (Shell == IntPtr.Zero || Body == IntPtr.Zero || Amotor == IntPtr.Zero) | ||
1157 | { | ||
1158 | m_log.ErrorFormat( | ||
1159 | "[ODE CHARACTER]: Destroying ODE structures for {0} even though some are already null. Shell = {1}, Body = {2}, Amotor = {3}", | ||
1160 | Name, Shell, Body, Amotor); | ||
1161 | } | ||
1162 | |||
1138 | // destroy avatar capsule and related ODE data | 1163 | // destroy avatar capsule and related ODE data |
1139 | if (Amotor != IntPtr.Zero) | 1164 | if (Amotor != IntPtr.Zero) |
1140 | { | 1165 | { |
@@ -1155,7 +1180,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1155 | 1180 | ||
1156 | if (Shell != IntPtr.Zero) | 1181 | if (Shell != IntPtr.Zero) |
1157 | { | 1182 | { |
1183 | // lock (OdeScene.UniversalColliderSyncObject) | ||
1158 | d.GeomDestroy(Shell); | 1184 | d.GeomDestroy(Shell); |
1185 | |||
1159 | _parent_scene.geom_name_map.Remove(Shell); | 1186 | _parent_scene.geom_name_map.Remove(Shell); |
1160 | _parent_scene.actor_name_map.Remove(Shell); | 1187 | _parent_scene.actor_name_map.Remove(Shell); |
1161 | 1188 | ||
@@ -1260,15 +1287,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1260 | { | 1287 | { |
1261 | if (m_tainted_isPhysical) | 1288 | if (m_tainted_isPhysical) |
1262 | { | 1289 | { |
1263 | // Create avatar capsule and related ODE data | ||
1264 | if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero)) | ||
1265 | { | ||
1266 | m_log.Warn("[ODE CHARACTER]: re-creating the following avatar ODE data for " + Name + ", even though it already exists - " | ||
1267 | + (Shell!=IntPtr.Zero ? "Shell ":"") | ||
1268 | + (Body!=IntPtr.Zero ? "Body ":"") | ||
1269 | + (Amotor!=IntPtr.Zero ? "Amotor ":"")); | ||
1270 | } | ||
1271 | |||
1272 | CreateOdeStructures(_position.X, _position.Y, _position.Z, m_tensor); | 1290 | CreateOdeStructures(_position.X, _position.Y, _position.Z, m_tensor); |
1273 | _parent_scene.AddCharacter(this); | 1291 | _parent_scene.AddCharacter(this); |
1274 | } | 1292 | } |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 228eca9..4530c09 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs | |||
@@ -105,6 +105,32 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
105 | private readonly ILog m_log; | 105 | private readonly ILog m_log; |
106 | // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); | 106 | // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); |
107 | 107 | ||
108 | /// <summary> | ||
109 | /// Provide a sync object so that only one thread calls d.Collide() at a time across all OdeScene instances. | ||
110 | /// </summary> | ||
111 | /// <remarks> | ||
112 | /// With ODE as of r1755 (though also tested on r1860), only one thread can call d.Collide() at a | ||
113 | /// time, even where physics objects are in entirely different ODE worlds. This is because generating contacts | ||
114 | /// uses a static cache at the ODE level. | ||
115 | /// | ||
116 | /// Without locking, simulators running multiple regions will eventually crash with a native stack trace similar | ||
117 | /// to | ||
118 | /// | ||
119 | /// mono() [0x489171] | ||
120 | /// mono() [0x4d154f] | ||
121 | /// /lib/x86_64-linux-gnu/libpthread.so.0(+0xfc60) [0x7f6ded592c60] | ||
122 | /// .../opensim/bin/libode-x86_64.so(_ZN6Opcode11OBBCollider8_CollideEPKNS_14AABBNoLeafNodeE+0xd7a) [0x7f6dd822628a] | ||
123 | /// | ||
124 | /// ODE provides an experimental option to cache in thread local storage but compiling ODE with this option | ||
125 | /// causes OpenSimulator to immediately crash with a native stack trace similar to | ||
126 | /// | ||
127 | /// mono() [0x489171] | ||
128 | /// mono() [0x4d154f] | ||
129 | /// /lib/x86_64-linux-gnu/libpthread.so.0(+0xfc60) [0x7f03c9849c60] | ||
130 | /// .../opensim/bin/libode-x86_64.so(_Z12dCollideCCTLP6dxGeomS0_iP12dContactGeomi+0x92) [0x7f03b44bcf82] | ||
131 | /// </remarks> | ||
132 | internal static Object UniversalColliderSyncObject = new Object(); | ||
133 | |||
108 | private Random fluidRandomizer = new Random(Environment.TickCount); | 134 | private Random fluidRandomizer = new Random(Environment.TickCount); |
109 | 135 | ||
110 | private const uint m_regionWidth = Constants.RegionSize; | 136 | private const uint m_regionWidth = Constants.RegionSize; |
@@ -799,7 +825,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
799 | if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) | 825 | if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) |
800 | return; | 826 | return; |
801 | 827 | ||
802 | count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); | 828 | lock (OdeScene.UniversalColliderSyncObject) |
829 | count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); | ||
830 | |||
803 | if (count > contacts.Length) | 831 | if (count > contacts.Length) |
804 | m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); | 832 | m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); |
805 | } | 833 | } |
@@ -1525,7 +1553,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1525 | chr.CollidingGround = false; | 1553 | chr.CollidingGround = false; |
1526 | chr.CollidingObj = false; | 1554 | chr.CollidingObj = false; |
1527 | 1555 | ||
1528 | // test the avatar's geometry for collision with the space | 1556 | // Test the avatar's geometry for collision with the space |
1529 | // This will return near and the space that they are the closest to | 1557 | // This will return near and the space that they are the closest to |
1530 | // And we'll run this again against the avatar and the space segment | 1558 | // And we'll run this again against the avatar and the space segment |
1531 | // This will return with a bunch of possible objects in the space segment | 1559 | // This will return with a bunch of possible objects in the space segment |