aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/OdeScene.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs133
1 files changed, 81 insertions, 52 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index e8689a6..355d30b 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -193,9 +193,30 @@ namespace OpenSim.Region.Physics.OdePlugin
193 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); 193 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
194 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>(); 194 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
195 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); 195 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
196 private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>(); 196
197 /// <summary>
198 /// Used to lock on manipulation of _taintedPrimL and _taintedPrimH
199 /// </summary>
197 private readonly Object _taintedPrimLock = new Object(); 200 private readonly Object _taintedPrimLock = new Object();
201
202 /// <summary>
203 /// List of tainted prims.
204 /// </summary>
205 /// <remarks>
206 /// A tainted prim is one that has taints to process before performing any other operations. The list is
207 /// cleared after processing.
208 /// </remarks>
198 private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>(); 209 private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>();
210
211 /// <summary>
212 /// HashSet of tainted prims.
213 /// </summary>
214 /// <remarks>
215 /// A tainted prim is one that has taints to process before performing any other operations. The hashset is
216 /// cleared after processing.
217 /// </remarks>
218 private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>();
219
199 private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>(); 220 private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>();
200 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>(); 221 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>();
201 222
@@ -257,6 +278,9 @@ namespace OpenSim.Region.Physics.OdePlugin
257 // split static geometry collision handling into spaces of 30 meters 278 // split static geometry collision handling into spaces of 30 meters
258 public IntPtr[,] staticPrimspace; 279 public IntPtr[,] staticPrimspace;
259 280
281 /// <summary>
282 /// Used to lock the entire physics scene. Locked during the main part of Simulate()
283 /// </summary>
260 public Object OdeLock; 284 public Object OdeLock;
261 285
262 public IMesher mesher; 286 public IMesher mesher;
@@ -643,15 +667,15 @@ namespace OpenSim.Region.Physics.OdePlugin
643 //while (d.SpaceLockQuery(space)) { } // Wait and do nothing 667 //while (d.SpaceLockQuery(space)) { } // Wait and do nothing
644 } 668 }
645 669
646 /// <summary> 670// /// <summary>
647 /// Debug space message for printing the space that a prim/avatar is in. 671// /// Debug space message for printing the space that a prim/avatar is in.
648 /// </summary> 672// /// </summary>
649 /// <param name="pos"></param> 673// /// <param name="pos"></param>
650 /// <returns>Returns which split up space the given position is in.</returns> 674// /// <returns>Returns which split up space the given position is in.</returns>
651 public string whichspaceamIin(Vector3 pos) 675// public string whichspaceamIin(Vector3 pos)
652 { 676// {
653 return calculateSpaceForGeom(pos).ToString(); 677// return calculateSpaceForGeom(pos).ToString();
654 } 678// }
655 679
656 #region Collision Detection 680 #region Collision Detection
657 681
@@ -1402,7 +1426,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1402 // } 1426 // }
1403 } 1427 }
1404 1428
1405 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) 1429 private int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
1406 { 1430 {
1407 /* String name1 = null; 1431 /* String name1 = null;
1408 String name2 = null; 1432 String name2 = null;
@@ -1421,7 +1445,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1421 return 1; 1445 return 1;
1422 } 1446 }
1423 1447
1424 public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) 1448 private int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
1425 { 1449 {
1426// String name1 = null; 1450// String name1 = null;
1427// String name2 = null; 1451// String name2 = null;
@@ -1552,7 +1576,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1552 } 1576 }
1553 1577
1554 // Recovered for use by fly height. Kitto Flora 1578 // Recovered for use by fly height. Kitto Flora
1555 public float GetTerrainHeightAtXY(float x, float y) 1579 internal float GetTerrainHeightAtXY(float x, float y)
1556 { 1580 {
1557 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; 1581 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1558 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; 1582 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
@@ -1610,7 +1634,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1610 /// Add actor to the list that should receive collision events in the simulate loop. 1634 /// Add actor to the list that should receive collision events in the simulate loop.
1611 /// </summary> 1635 /// </summary>
1612 /// <param name="obj"></param> 1636 /// <param name="obj"></param>
1613 public void AddCollisionEventReporting(PhysicsActor obj) 1637 internal void AddCollisionEventReporting(PhysicsActor obj)
1614 { 1638 {
1615 lock (_collisionEventPrim) 1639 lock (_collisionEventPrim)
1616 { 1640 {
@@ -1623,7 +1647,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1623 /// Remove actor from the list that should receive collision events in the simulate loop. 1647 /// Remove actor from the list that should receive collision events in the simulate loop.
1624 /// </summary> 1648 /// </summary>
1625 /// <param name="obj"></param> 1649 /// <param name="obj"></param>
1626 public void RemoveCollisionEventReporting(PhysicsActor obj) 1650 internal void RemoveCollisionEventReporting(PhysicsActor obj)
1627 { 1651 {
1628 lock (_collisionEventPrim) 1652 lock (_collisionEventPrim)
1629 { 1653 {
@@ -1647,7 +1671,13 @@ namespace OpenSim.Region.Physics.OdePlugin
1647 return newAv; 1671 return newAv;
1648 } 1672 }
1649 1673
1650 public void AddCharacter(OdeCharacter chr) 1674 public override void RemoveAvatar(PhysicsActor actor)
1675 {
1676 //m_log.Debug("[PHYSICS]:ODELOCK");
1677 ((OdeCharacter) actor).Destroy();
1678 }
1679
1680 internal void AddCharacter(OdeCharacter chr)
1651 { 1681 {
1652 lock (_characters) 1682 lock (_characters)
1653 { 1683 {
@@ -1660,7 +1690,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1660 } 1690 }
1661 } 1691 }
1662 1692
1663 public void RemoveCharacter(OdeCharacter chr) 1693 internal void RemoveCharacter(OdeCharacter chr)
1664 { 1694 {
1665 lock (_characters) 1695 lock (_characters)
1666 { 1696 {
@@ -1671,7 +1701,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1671 } 1701 }
1672 } 1702 }
1673 1703
1674 public void BadCharacter(OdeCharacter chr) 1704 internal void BadCharacter(OdeCharacter chr)
1675 { 1705 {
1676 lock (_badCharacter) 1706 lock (_badCharacter)
1677 { 1707 {
@@ -1680,12 +1710,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1680 } 1710 }
1681 } 1711 }
1682 1712
1683 public override void RemoveAvatar(PhysicsActor actor)
1684 {
1685 //m_log.Debug("[PHYSICS]:ODELOCK");
1686 ((OdeCharacter) actor).Destroy();
1687 }
1688
1689 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, 1713 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1690 PrimitiveBaseShape pbs, bool isphysical, uint localID) 1714 PrimitiveBaseShape pbs, bool isphysical, uint localID)
1691 { 1715 {
@@ -1705,13 +1729,17 @@ namespace OpenSim.Region.Physics.OdePlugin
1705 return newPrim; 1729 return newPrim;
1706 } 1730 }
1707 1731
1708 public void addActivePrim(OdePrim activatePrim) 1732 /// <summary>
1733 /// Make this prim subject to physics.
1734 /// </summary>
1735 /// <param name="prim"></param>
1736 internal void ActivatePrim(OdePrim prim)
1709 { 1737 {
1710 // adds active prim.. (ones that should be iterated over in collisions_optimized 1738 // adds active prim.. (ones that should be iterated over in collisions_optimized
1711 lock (_activeprims) 1739 lock (_activeprims)
1712 { 1740 {
1713 if (!_activeprims.Contains(activatePrim)) 1741 if (!_activeprims.Contains(prim))
1714 _activeprims.Add(activatePrim); 1742 _activeprims.Add(prim);
1715 //else 1743 //else
1716 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); 1744 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
1717 } 1745 }
@@ -2084,12 +2112,14 @@ namespace OpenSim.Region.Physics.OdePlugin
2084 return new Vector3(axis.X, axis.Y, axis.Z); 2112 return new Vector3(axis.X, axis.Y, axis.Z);
2085 } 2113 }
2086 2114
2087 public void remActivePrim(OdePrim deactivatePrim) 2115 /// <summary>
2116 /// Stop this prim being subject to physics
2117 /// </summary>
2118 /// <param name="prim"></param>
2119 internal void DeactivatePrim(OdePrim prim)
2088 { 2120 {
2089 lock (_activeprims) 2121 lock (_activeprims)
2090 { 2122 _activeprims.Remove(prim);
2091 _activeprims.Remove(deactivatePrim);
2092 }
2093 } 2123 }
2094 2124
2095 public override void RemovePrim(PhysicsActor prim) 2125 public override void RemovePrim(PhysicsActor prim)
@@ -2121,7 +2151,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2121 /// that the space was using. 2151 /// that the space was using.
2122 /// </summary> 2152 /// </summary>
2123 /// <param name="prim"></param> 2153 /// <param name="prim"></param>
2124 public void RemovePrimThreadLocked(OdePrim prim) 2154 internal void RemovePrimThreadLocked(OdePrim prim)
2125 { 2155 {
2126//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); 2156//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
2127 lock (prim) 2157 lock (prim)
@@ -2217,7 +2247,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2217 /// Takes a space pointer and zeros out the array we're using to hold the spaces 2247 /// Takes a space pointer and zeros out the array we're using to hold the spaces
2218 /// </summary> 2248 /// </summary>
2219 /// <param name="pSpace"></param> 2249 /// <param name="pSpace"></param>
2220 public void resetSpaceArrayItemToZero(IntPtr pSpace) 2250 private void resetSpaceArrayItemToZero(IntPtr pSpace)
2221 { 2251 {
2222 for (int x = 0; x < staticPrimspace.GetLength(0); x++) 2252 for (int x = 0; x < staticPrimspace.GetLength(0); x++)
2223 { 2253 {
@@ -2229,10 +2259,10 @@ namespace OpenSim.Region.Physics.OdePlugin
2229 } 2259 }
2230 } 2260 }
2231 2261
2232 public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY) 2262// private void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY)
2233 { 2263// {
2234 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; 2264// staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
2235 } 2265// }
2236 2266
2237 /// <summary> 2267 /// <summary>
2238 /// Called when a static prim moves. Allocates a space for the prim based on its position 2268 /// Called when a static prim moves. Allocates a space for the prim based on its position
@@ -2241,7 +2271,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2241 /// <param name="pos">the position that the geom moved to</param> 2271 /// <param name="pos">the position that the geom moved to</param>
2242 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param> 2272 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
2243 /// <returns>a pointer to the new space it's in</returns> 2273 /// <returns>a pointer to the new space it's in</returns>
2244 public IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace) 2274 internal IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace)
2245 { 2275 {
2246 // Called from setting the Position and Size of an ODEPrim so 2276 // Called from setting the Position and Size of an ODEPrim so
2247 // it's already in locked space. 2277 // it's already in locked space.
@@ -2372,7 +2402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2372 /// <param name="iprimspaceArrItemX"></param> 2402 /// <param name="iprimspaceArrItemX"></param>
2373 /// <param name="iprimspaceArrItemY"></param> 2403 /// <param name="iprimspaceArrItemY"></param>
2374 /// <returns>A pointer to the created space</returns> 2404 /// <returns>A pointer to the created space</returns>
2375 public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) 2405 internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
2376 { 2406 {
2377 // creating a new space for prim and inserting it into main space. 2407 // creating a new space for prim and inserting it into main space.
2378 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); 2408 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero);
@@ -2388,7 +2418,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2388 /// </summary> 2418 /// </summary>
2389 /// <param name="pos"></param> 2419 /// <param name="pos"></param>
2390 /// <returns>a pointer to the space. This could be a new space or reused space.</returns> 2420 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
2391 public IntPtr calculateSpaceForGeom(Vector3 pos) 2421 internal IntPtr calculateSpaceForGeom(Vector3 pos)
2392 { 2422 {
2393 int[] xyspace = calculateSpaceArrayItemFromPos(pos); 2423 int[] xyspace = calculateSpaceArrayItemFromPos(pos);
2394 //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); 2424 //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString());
@@ -2400,7 +2430,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2400 /// </summary> 2430 /// </summary>
2401 /// <param name="pos"></param> 2431 /// <param name="pos"></param>
2402 /// <returns>an array item based on the position</returns> 2432 /// <returns>an array item based on the position</returns>
2403 public int[] calculateSpaceArrayItemFromPos(Vector3 pos) 2433 internal int[] calculateSpaceArrayItemFromPos(Vector3 pos)
2404 { 2434 {
2405 int[] returnint = new int[2]; 2435 int[] returnint = new int[2];
2406 2436
@@ -2427,7 +2457,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2427 /// </summary> 2457 /// </summary>
2428 /// <param name="pbs"></param> 2458 /// <param name="pbs"></param>
2429 /// <returns></returns> 2459 /// <returns></returns>
2430 public bool needsMeshing(PrimitiveBaseShape pbs) 2460 internal bool needsMeshing(PrimitiveBaseShape pbs)
2431 { 2461 {
2432 // most of this is redundant now as the mesher will return null if it cant mesh a prim 2462 // most of this is redundant now as the mesher will return null if it cant mesh a prim
2433 // but we still need to check for sculptie meshing being enabled so this is the most 2463 // but we still need to check for sculptie meshing being enabled so this is the most
@@ -2705,7 +2735,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
2705 else 2735 else
2706 { 2736 {
2707// Console.WriteLine("Simulate calls ProcessTaints for {0}", prim.Name); 2737// Console.WriteLine("Simulate calls ProcessTaints for {0}", prim.Name);
2708 prim.ProcessTaints(timeStep); 2738 prim.ProcessTaints();
2709 } 2739 }
2710 2740
2711 processedtaints = true; 2741 processedtaints = true;
@@ -2910,7 +2940,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
2910 /// <remarks> 2940 /// <remarks>
2911 /// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else. 2941 /// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else.
2912 /// </remarks> 2942 /// </remarks>
2913 protected void SimulatePendingNINJAJoints() 2943 private void SimulatePendingNINJAJoints()
2914 { 2944 {
2915 // Create pending joints, if possible 2945 // Create pending joints, if possible
2916 2946
@@ -3101,7 +3131,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3101 /// Called as part of the Simulate() loop if NINJA physics is active. Must only be called from there. 3131 /// Called as part of the Simulate() loop if NINJA physics is active. Must only be called from there.
3102 /// </remarks> 3132 /// </remarks>
3103 /// <param name="actor"></param> 3133 /// <param name="actor"></param>
3104 protected void SimulateActorPendingJoints(OdePrim actor) 3134 private void SimulateActorPendingJoints(OdePrim actor)
3105 { 3135 {
3106 // If an actor moved, move its joint proxy objects as well. 3136 // If an actor moved, move its joint proxy objects as well.
3107 // There seems to be an event PhysicsActor.OnPositionUpdate that could be used 3137 // There seems to be an event PhysicsActor.OnPositionUpdate that could be used
@@ -3138,7 +3168,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3138 } 3168 }
3139 3169
3140 #region ODE Specific Terrain Fixes 3170 #region ODE Specific Terrain Fixes
3141 public float[] ResizeTerrain512NearestNeighbour(float[] heightMap) 3171 private float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
3142 { 3172 {
3143 float[] returnarr = new float[262144]; 3173 float[] returnarr = new float[262144];
3144 float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y]; 3174 float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y];
@@ -3251,7 +3281,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3251 return returnarr; 3281 return returnarr;
3252 } 3282 }
3253 3283
3254 public float[] ResizeTerrain512Interpolation(float[] heightMap) 3284 private float[] ResizeTerrain512Interpolation(float[] heightMap)
3255 { 3285 {
3256 float[] returnarr = new float[262144]; 3286 float[] returnarr = new float[262144];
3257 float[,] resultarr = new float[512,512]; 3287 float[,] resultarr = new float[512,512];
@@ -3419,7 +3449,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3419 } 3449 }
3420 } 3450 }
3421 3451
3422 public void SetTerrain(float[] heightMap, Vector3 pOffset) 3452 private void SetTerrain(float[] heightMap, Vector3 pOffset)
3423 { 3453 {
3424 // this._heightmap[i] = (double)heightMap[i]; 3454 // this._heightmap[i] = (double)heightMap[i];
3425 // dbm (danx0r) -- creating a buffer zone of one extra sample all around 3455 // dbm (danx0r) -- creating a buffer zone of one extra sample all around
@@ -3548,7 +3578,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3548 { 3578 {
3549 } 3579 }
3550 3580
3551 public float GetWaterLevel() 3581 internal float GetWaterLevel()
3552 { 3582 {
3553 return waterlevel; 3583 return waterlevel;
3554 } 3584 }
@@ -3623,7 +3653,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3623 randomizeWater(waterlevel); 3653 randomizeWater(waterlevel);
3624 } 3654 }
3625 3655
3626 public void randomizeWater(float baseheight) 3656 private void randomizeWater(float baseheight)
3627 { 3657 {
3628 const uint heightmapWidth = m_regionWidth + 2; 3658 const uint heightmapWidth = m_regionWidth + 2;
3629 const uint heightmapHeight = m_regionHeight + 2; 3659 const uint heightmapHeight = m_regionHeight + 2;
@@ -3675,9 +3705,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3675 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3705 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3676 d.GeomSetRotation(WaterGeom, ref R); 3706 d.GeomSetRotation(WaterGeom, ref R);
3677 d.GeomSetPosition(WaterGeom, 128, 128, 0); 3707 d.GeomSetPosition(WaterGeom, 128, 128, 0);
3678
3679 } 3708 }
3680
3681 } 3709 }
3682 3710
3683 public override void Dispose() 3711 public override void Dispose()
@@ -3724,6 +3752,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
3724 } 3752 }
3725 } 3753 }
3726 } 3754 }
3755
3727 return returncolliders; 3756 return returncolliders;
3728 } 3757 }
3729 3758