aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
diff options
context:
space:
mode:
authorUbitUmarov2019-01-29 13:49:29 +0000
committerUbitUmarov2019-01-29 13:49:29 +0000
commit6bc8e2413f2780fe4ce071a589a9d16efeaf2265 (patch)
treebf3d1cf99b49391cf869854f57a0cba384a45565 /OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
parentmantis 8457: ok ok shutup the warning (diff)
downloadopensim-SC-6bc8e2413f2780fe4ce071a589a9d16efeaf2265.zip
opensim-SC-6bc8e2413f2780fe4ce071a589a9d16efeaf2265.tar.gz
opensim-SC-6bc8e2413f2780fe4ce071a589a9d16efeaf2265.tar.bz2
opensim-SC-6bc8e2413f2780fe4ce071a589a9d16efeaf2265.tar.xz
ubode replace a locklessqueue by .net concurrentqueue
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs136
1 files changed, 50 insertions, 86 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
index 9703eb5..97dcb69 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
@@ -26,9 +26,10 @@
26 */ 26 */
27 27
28// Revision 2011/12/13 by Ubit Umarov 28// Revision 2011/12/13 by Ubit Umarov
29//#define SPAM 29
30 30
31using System; 31using System;
32using System.Collections.Concurrent;
32using System.Collections.Generic; 33using System.Collections.Generic;
33using System.Linq; 34using System.Linq;
34using System.Reflection; 35using System.Reflection;
@@ -158,7 +159,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
158 public struct ODEchangeitem 159 public struct ODEchangeitem
159 { 160 {
160 public PhysicsActor actor; 161 public PhysicsActor actor;
161 public OdeCharacter character;
162 public changes what; 162 public changes what;
163 public Object arg; 163 public Object arg;
164 } 164 }
@@ -230,7 +230,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
230 private HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); 230 private HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
231 private HashSet<OdePrim> _activegroups = new HashSet<OdePrim>(); 231 private HashSet<OdePrim> _activegroups = new HashSet<OdePrim>();
232 232
233 public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>(); 233 public ConcurrentQueue<ODEchangeitem> ChangesQueue = new ConcurrentQueue<ODEchangeitem>();
234 234
235 /// <summary> 235 /// <summary>
236 /// A list of actors that should receive collision events. 236 /// A list of actors that should receive collision events.
@@ -621,8 +621,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
621 return; 621 return;
622 } 622 }
623 623
624
625
626 // Figure out how many contact points we have 624 // Figure out how many contact points we have
627 int count = 0; 625 int count = 0;
628 try 626 try
@@ -1180,12 +1178,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1180 //m_log.Debug("[PHYSICS]:ODELOCK"); 1178 //m_log.Debug("[PHYSICS]:ODELOCK");
1181 if (world == IntPtr.Zero) 1179 if (world == IntPtr.Zero)
1182 return; 1180 return;
1183 lock (SimulationLock) 1181 ((OdeCharacter) actor).Destroy();
1184 lock (OdeLock)
1185 {
1186 SafeNativeMethods.AllocateODEDataForThread(0);
1187 ((OdeCharacter) actor).Destroy();
1188 }
1189 } 1182 }
1190 1183
1191 public void addActivePrim(OdePrim activatePrim) 1184 public void addActivePrim(OdePrim activatePrim)
@@ -1224,7 +1217,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1224 return AddPrim(primName, position, size, rotation, pbs, isPhysical, isPhantom, 0 , localid); 1217 return AddPrim(primName, position, size, rotation, pbs, isPhysical, isPhantom, 0 , localid);
1225 } 1218 }
1226 1219
1227
1228 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 1220 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1229 Vector3 size, Quaternion rotation, bool isPhysical, uint localid) 1221 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
1230 { 1222 {
@@ -1244,6 +1236,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1244 _activeprims.Remove(deactivatePrim); 1236 _activeprims.Remove(deactivatePrim);
1245 } 1237 }
1246 } 1238 }
1239
1247 public void remActiveGroup(OdePrim deactivatePrim) 1240 public void remActiveGroup(OdePrim deactivatePrim)
1248 { 1241 {
1249 lock (_activegroups) 1242 lock (_activegroups)
@@ -1258,25 +1251,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1258 // removed in the next physics simulate pass. 1251 // removed in the next physics simulate pass.
1259 if (prim is OdePrim) 1252 if (prim is OdePrim)
1260 { 1253 {
1261// lock (OdeLock) 1254 OdePrim p = (OdePrim)prim;
1262 { 1255 p.setPrimForRemoval();
1263
1264 OdePrim p = (OdePrim)prim;
1265 p.setPrimForRemoval();
1266 }
1267 } 1256 }
1268 } 1257 }
1269 1258
1270 public void RemovePrimThreadLocked(OdePrim prim) 1259 public void RemovePrimThreadLocked(OdePrim prim)
1271 { 1260 {
1272 //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); 1261 //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
1273 lock (prim) 1262 lock (_prims)
1274 { 1263 _prims.Remove(prim.LocalID);
1275// RemoveCollisionEventReporting(prim);
1276 lock (_prims)
1277 _prims.Remove(prim.LocalID);
1278 }
1279
1280 } 1264 }
1281 1265
1282 public void addToPrims(OdePrim prim) 1266 public void addToPrims(OdePrim prim)
@@ -1405,12 +1389,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1405 /// to use in place of old taint mechanism so changes do have a time sequence 1389 /// to use in place of old taint mechanism so changes do have a time sequence
1406 /// </summary> 1390 /// </summary>
1407 1391
1408 public void AddChange(PhysicsActor actor, changes what, Object arg) 1392 public void AddChange(PhysicsActor _actor, changes _what, Object _arg)
1409 { 1393 {
1410 ODEchangeitem item = new ODEchangeitem(); 1394 if (world == IntPtr.Zero)
1411 item.actor = actor; 1395 return;
1412 item.what = what; 1396
1413 item.arg = arg; 1397 ODEchangeitem item = new ODEchangeitem
1398 {
1399 actor = _actor,
1400 what = _what,
1401 arg = _arg
1402 };
1414 ChangesQueue.Enqueue(item); 1403 ChangesQueue.Enqueue(item);
1415 } 1404 }
1416 1405
@@ -1430,22 +1419,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1430 lock (OdeLock) 1419 lock (OdeLock)
1431 { 1420 {
1432 if (world == IntPtr.Zero) 1421 if (world == IntPtr.Zero)
1433 {
1434 ChangesQueue.Clear();
1435 return; 1422 return;
1436 }
1437
1438 SafeNativeMethods.AllocateODEDataForThread(~0U);
1439 1423
1440 ODEchangeitem item; 1424 ODEchangeitem item;
1441 1425
1442 int donechanges = 0; 1426 int donechanges = 0;
1443 if (ChangesQueue.Count > 0) 1427 if (!ChangesQueue.IsEmpty)
1444 { 1428 {
1445 m_log.InfoFormat("[ubOde] start processing pending actor operations"); 1429 m_log.InfoFormat("[ubOde] start processing pending actor operations");
1446 int tstart = Util.EnvironmentTickCount(); 1430 int tstart = Util.EnvironmentTickCount();
1447 1431
1448 while (ChangesQueue.Dequeue(out item)) 1432 SafeNativeMethods.AllocateODEDataForThread(~0U);
1433
1434 while (ChangesQueue.TryDequeue(out item))
1449 { 1435 {
1450 if (item.actor != null) 1436 if (item.actor != null)
1451 { 1437 {
@@ -1511,13 +1497,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1511 1497
1512 lock (OdeLock) 1498 lock (OdeLock)
1513 { 1499 {
1514 if (world == IntPtr.Zero)
1515 {
1516 ChangesQueue.Clear();
1517 return 0;
1518 }
1519
1520 ODEchangeitem item;
1521 1500
1522// d.WorldSetQuickStepNumIterations(world, curphysiteractions); 1501// d.WorldSetQuickStepNumIterations(world, curphysiteractions);
1523 1502
@@ -1539,17 +1518,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1539*/ 1518*/
1540 SafeNativeMethods.AllocateODEDataForThread(~0U); 1519 SafeNativeMethods.AllocateODEDataForThread(~0U);
1541 1520
1542 if (ChangesQueue.Count > 0) 1521 if (!ChangesQueue.IsEmpty)
1543 { 1522 {
1544 while (ChangesQueue.Dequeue(out item)) 1523 ODEchangeitem item;
1524
1525 while (ChangesQueue.TryDequeue(out item))
1545 { 1526 {
1546 if (item.actor != null) 1527 if (item.actor != null)
1547 { 1528 {
1548 try 1529 try
1549 { 1530 {
1550 lock (SimulationLock) 1531 lock (SimulationLock)
1551 { 1532 {
1552 if (item.actor is OdeCharacter) 1533 if (item.actor is OdeCharacter)
1553 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg); 1534 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1554 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg)) 1535 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1555 RemovePrimThreadLocked((OdePrim)item.actor); 1536 RemovePrimThreadLocked((OdePrim)item.actor);
@@ -1575,31 +1556,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1575 // clear pointer/counter to contacts to pass into joints 1556 // clear pointer/counter to contacts to pass into joints
1576 m_global_contactcount = 0; 1557 m_global_contactcount = 0;
1577 1558
1559 // tmpTime = Util.GetTimeStampMS();
1578 1560
1579// tmpTime = Util.GetTimeStampMS(); 1561 lock (SimulationLock)
1580
1581 // Move characters
1582 lock (_characters)
1583 { 1562 {
1584 List<OdeCharacter> defects = new List<OdeCharacter>(); 1563 // Move characters
1585 foreach (OdeCharacter actor in _characters) 1564 lock (_characters)
1586 { 1565 {
1587 if (actor != null) 1566 foreach (OdeCharacter actor in _characters)
1588 actor.Move(defects);
1589 }
1590 if (defects.Count != 0)
1591 {
1592 foreach (OdeCharacter defect in defects)
1593 { 1567 {
1594 RemoveCharacter(defect); 1568 actor.Move();
1595 } 1569 }
1596 defects.Clear();
1597 } 1570 }
1598 }
1599 1571
1600 // Move other active objects 1572 // Move other active objects
1601 lock (SimulationLock)
1602 {
1603 lock (_activegroups) 1573 lock (_activegroups)
1604 { 1574 {
1605 foreach (OdePrim aprim in _activegroups) 1575 foreach (OdePrim aprim in _activegroups)
@@ -1629,9 +1599,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1629 List<OdePrim> sleepers = new List<OdePrim>(); 1599 List<OdePrim> sleepers = new List<OdePrim>();
1630 foreach (PhysicsActor obj in _collisionEventPrim) 1600 foreach (PhysicsActor obj in _collisionEventPrim)
1631 { 1601 {
1632 if (obj == null)
1633 continue;
1634
1635 switch ((ActorTypes)obj.PhysicsActorType) 1602 switch ((ActorTypes)obj.PhysicsActorType)
1636 { 1603 {
1637 case ActorTypes.Agent: 1604 case ActorTypes.Agent:
@@ -1644,10 +1611,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1644 if (!pobj.m_outbounds) 1611 if (!pobj.m_outbounds)
1645 { 1612 {
1646 pobj.SendCollisions((int)(odetimestepMS)); 1613 pobj.SendCollisions((int)(odetimestepMS));
1647 if(pobj.Body != IntPtr.Zero && !pobj.m_isSelected && 1614 lock(SimulationLock)
1648 !pobj.m_disabled && !pobj.m_building && 1615 {
1649 !SafeNativeMethods.BodyIsEnabled(pobj.Body)) 1616 if(pobj.Body != IntPtr.Zero && !pobj.m_isSelected &&
1650 sleepers.Add(pobj); 1617 !pobj.m_disabled && !pobj.m_building &&
1618 !SafeNativeMethods.BodyIsEnabled(pobj.Body))
1619 sleepers.Add(pobj);
1620 }
1651 } 1621 }
1652 break; 1622 break;
1653 } 1623 }
@@ -1656,17 +1626,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1656 foreach(OdePrim prm in sleepers) 1626 foreach(OdePrim prm in sleepers)
1657 prm.SleeperAddCollisionEvents(); 1627 prm.SleeperAddCollisionEvents();
1658 sleepers.Clear(); 1628 sleepers.Clear();
1659 // collisonRepo += Util.GetTimeStampMS() - tmpTime; 1629 // collisonRepo += Util.GetTimeStampMS() - tmpTime;
1660 1630
1661 1631
1662 // do a ode simulation step 1632 // do a ode simulation step
1663 // tmpTime = Util.GetTimeStampMS(); 1633 // tmpTime = Util.GetTimeStampMS();
1664 lock (SimulationLock) 1634 lock (SimulationLock)
1665 { 1635 {
1666 SafeNativeMethods.WorldQuickStep(world, ODE_STEPSIZE); 1636 SafeNativeMethods.WorldQuickStep(world, ODE_STEPSIZE);
1667 SafeNativeMethods.JointGroupEmpty(contactgroup); 1637 SafeNativeMethods.JointGroupEmpty(contactgroup);
1668 } 1638 }
1669 // qstepTIme += Util.GetTimeStampMS() - tmpTime; 1639 // qstepTIme += Util.GetTimeStampMS() - tmpTime;
1670 1640
1671 // update managed ideia of physical data and do updates to core 1641 // update managed ideia of physical data and do updates to core
1672 /* 1642 /*
@@ -1709,7 +1679,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1709// ode.dunlock(world); 1679// ode.dunlock(world);
1710 } 1680 }
1711 1681
1712
1713 step_time -= ODE_STEPSIZE; 1682 step_time -= ODE_STEPSIZE;
1714 nodeframes++; 1683 nodeframes++;
1715 1684
@@ -1727,7 +1696,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1727 { 1696 {
1728 RemoveCharacter(chr); 1697 RemoveCharacter(chr);
1729 } 1698 }
1730
1731 _badCharacter.Clear(); 1699 _badCharacter.Clear();
1732 } 1700 }
1733 } 1701 }
@@ -1815,8 +1783,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1815 mesher.ExpireReleaseMeshs(); 1783 mesher.ExpireReleaseMeshs();
1816 m_lastMeshExpire = now; 1784 m_lastMeshExpire = now;
1817 } 1785 }
1818
1819
1820 } 1786 }
1821 1787
1822 return fps; 1788 return fps;
@@ -2005,6 +1971,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2005 1971
2006 private void InitTerrain() 1972 private void InitTerrain()
2007 { 1973 {
1974 lock(SimulationLock)
2008 lock (OdeLock) 1975 lock (OdeLock)
2009 { 1976 {
2010 SafeNativeMethods.AllocateODEDataForThread(~0U); 1977 SafeNativeMethods.AllocateODEDataForThread(~0U);
@@ -2110,6 +2077,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2110 yt += heightmapWidthSamples; 2077 yt += heightmapWidthSamples;
2111 } 2078 }
2112 2079
2080 lock(SimulationLock)
2113 lock (OdeLock) 2081 lock (OdeLock)
2114 { 2082 {
2115 SafeNativeMethods.GeomOSTerrainDataSetBounds(HeightmapData, minH, maxH); 2083 SafeNativeMethods.GeomOSTerrainDataSetBounds(HeightmapData, minH, maxH);
@@ -2133,9 +2101,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2133 2101
2134 public override void Dispose() 2102 public override void Dispose()
2135 { 2103 {
2104 lock(SimulationLock)
2136 lock (OdeLock) 2105 lock (OdeLock)
2137 { 2106 {
2138
2139 if (world == IntPtr.Zero) 2107 if (world == IntPtr.Zero)
2140 return; 2108 return;
2141 2109
@@ -2152,7 +2120,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2152 2120
2153 lock (_prims) 2121 lock (_prims)
2154 { 2122 {
2155 ChangesQueue.Clear();
2156 foreach (OdePrim prm in _prims.Values) 2123 foreach (OdePrim prm in _prims.Values)
2157 { 2124 {
2158 prm.DoAChange(changes.Remove, null); 2125 prm.DoAChange(changes.Remove, null);
@@ -2168,7 +2135,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2168 _characters.CopyTo(chtorem); 2135 _characters.CopyTo(chtorem);
2169 } 2136 }
2170 2137
2171 ChangesQueue.Clear();
2172 foreach (OdeCharacter ch in chtorem) 2138 foreach (OdeCharacter ch in chtorem)
2173 ch.DoAChange(changes.Remove, null); 2139 ch.DoAChange(changes.Remove, null);
2174 2140
@@ -2257,7 +2223,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2257 } 2223 }
2258 } 2224 }
2259 2225
2260
2261 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count) 2226 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
2262 { 2227 {
2263 List<ContactResult> ourresults = new List<ContactResult>(); 2228 List<ContactResult> ourresults = new List<ContactResult>();
@@ -2498,6 +2463,5 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2498 }); 2463 });
2499 return 1; 2464 return 1;
2500 } 2465 }
2501
2502 } 2466 }
2503} 2467}