diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 87 |
1 files changed, 58 insertions, 29 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 0e257b6..beaea1f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -73,7 +73,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
73 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 73 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
74 | private static readonly string LogHeader = "[BULLETS SCENE]"; | 74 | private static readonly string LogHeader = "[BULLETS SCENE]"; |
75 | 75 | ||
76 | public void DebugLog(string mm, params Object[] xx) { if (shouldDebugLog) m_log.DebugFormat(mm, xx); } | 76 | public void DebugLog(string mm, params Object[] xx) { if (ShouldDebugLog) m_log.DebugFormat(mm, xx); } |
77 | 77 | ||
78 | public string BulletSimVersion = "?"; | 78 | public string BulletSimVersion = "?"; |
79 | 79 | ||
@@ -162,14 +162,24 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
162 | } | 162 | } |
163 | 163 | ||
164 | public delegate void TaintCallback(); | 164 | public delegate void TaintCallback(); |
165 | private List<TaintCallback> _taintedObjects; | 165 | private struct TaintCallbackEntry |
166 | { | ||
167 | public String ident; | ||
168 | public TaintCallback callback; | ||
169 | public TaintCallbackEntry(string i, TaintCallback c) | ||
170 | { | ||
171 | ident = i; | ||
172 | callback = c; | ||
173 | } | ||
174 | } | ||
175 | private List<TaintCallbackEntry> _taintedObjects; | ||
166 | private Object _taintLock = new Object(); | 176 | private Object _taintLock = new Object(); |
167 | 177 | ||
168 | // A pointer to an instance if this structure is passed to the C++ code | 178 | // A pointer to an instance if this structure is passed to the C++ code |
169 | ConfigurationParameters[] m_params; | 179 | ConfigurationParameters[] m_params; |
170 | GCHandle m_paramsHandle; | 180 | GCHandle m_paramsHandle; |
171 | 181 | ||
172 | public bool shouldDebugLog { get; private set; } | 182 | public bool ShouldDebugLog { get; private set; } |
173 | 183 | ||
174 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; | 184 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; |
175 | 185 | ||
@@ -232,7 +242,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
232 | BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); | 242 | BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); |
233 | } | 243 | } |
234 | 244 | ||
235 | _taintedObjects = new List<TaintCallback>(); | 245 | _taintedObjects = new List<TaintCallbackEntry>(); |
236 | 246 | ||
237 | mesher = meshmerizer; | 247 | mesher = meshmerizer; |
238 | // The bounding box for the simulated world | 248 | // The bounding box for the simulated world |
@@ -245,7 +255,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
245 | 255 | ||
246 | // Initialization to support the transition to a new API which puts most of the logic | 256 | // Initialization to support the transition to a new API which puts most of the logic |
247 | // into the C# code so it is easier to modify and add to. | 257 | // into the C# code so it is easier to modify and add to. |
248 | m_worldSim = new BulletSim(m_worldID, BulletSimAPI.GetSimHandle2(m_worldID)); | 258 | m_worldSim = new BulletSim(m_worldID, this, BulletSimAPI.GetSimHandle2(m_worldID)); |
249 | m_constraintCollection = new BSConstraintCollection(World); | 259 | m_constraintCollection = new BSConstraintCollection(World); |
250 | 260 | ||
251 | m_initialized = true; | 261 | m_initialized = true; |
@@ -352,6 +362,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
352 | BSPrim bsprim = prim as BSPrim; | 362 | BSPrim bsprim = prim as BSPrim; |
353 | if (bsprim != null) | 363 | if (bsprim != null) |
354 | { | 364 | { |
365 | DetailLog("{0},RemovePrim,call", bsprim.LocalID); | ||
355 | // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); | 366 | // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); |
356 | try | 367 | try |
357 | { | 368 | { |
@@ -377,6 +388,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
377 | 388 | ||
378 | if (!m_initialized) return null; | 389 | if (!m_initialized) return null; |
379 | 390 | ||
391 | DetailLog("{0},AddPrimShape,call", localID); | ||
392 | |||
380 | BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical); | 393 | BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical); |
381 | lock (m_prims) m_prims.Add(localID, prim); | 394 | lock (m_prims) m_prims.Add(localID, prim); |
382 | return prim; | 395 | return prim; |
@@ -416,12 +429,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
416 | { | 429 | { |
417 | numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep, | 430 | numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep, |
418 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); | 431 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); |
419 | DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", "0000000000", numSubSteps, updatedEntityCount, collidersCount); | 432 | DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); |
420 | } | 433 | } |
421 | catch (Exception e) | 434 | catch (Exception e) |
422 | { | 435 | { |
423 | m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e); | 436 | m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e); |
424 | DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", "0000000000", numSubSteps, updatedEntityCount, collidersCount); | 437 | DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); |
425 | // updatedEntityCount = 0; | 438 | // updatedEntityCount = 0; |
426 | collidersCount = 0; | 439 | collidersCount = 0; |
427 | } | 440 | } |
@@ -535,7 +548,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
535 | 548 | ||
536 | public override void SetTerrain(float[] heightMap) { | 549 | public override void SetTerrain(float[] heightMap) { |
537 | m_heightMap = heightMap; | 550 | m_heightMap = heightMap; |
538 | this.TaintedObject(delegate() | 551 | this.TaintedObject("BSScene.SetTerrain", delegate() |
539 | { | 552 | { |
540 | BulletSimAPI.SetHeightmap(m_worldID, m_heightMap); | 553 | BulletSimAPI.SetHeightmap(m_worldID, m_heightMap); |
541 | }); | 554 | }); |
@@ -727,12 +740,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
727 | // Calls to the PhysicsActors can't directly call into the physics engine | 740 | // Calls to the PhysicsActors can't directly call into the physics engine |
728 | // because it might be busy. We delay changes to a known time. | 741 | // because it might be busy. We delay changes to a known time. |
729 | // We rely on C#'s closure to save and restore the context for the delegate. | 742 | // We rely on C#'s closure to save and restore the context for the delegate. |
730 | public void TaintedObject(TaintCallback callback) | 743 | public void TaintedObject(String ident, TaintCallback callback) |
731 | { | 744 | { |
732 | if (!m_initialized) return; | 745 | if (!m_initialized) return; |
733 | 746 | ||
734 | lock (_taintLock) | 747 | lock (_taintLock) |
735 | _taintedObjects.Add(callback); | 748 | _taintedObjects.Add(new TaintCallbackEntry(ident, callback)); |
736 | return; | 749 | return; |
737 | } | 750 | } |
738 | 751 | ||
@@ -744,22 +757,22 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
744 | if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process | 757 | if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process |
745 | { | 758 | { |
746 | // swizzle a new list into the list location so we can process what's there | 759 | // swizzle a new list into the list location so we can process what's there |
747 | List<TaintCallback> oldList; | 760 | List<TaintCallbackEntry> oldList; |
748 | lock (_taintLock) | 761 | lock (_taintLock) |
749 | { | 762 | { |
750 | oldList = _taintedObjects; | 763 | oldList = _taintedObjects; |
751 | _taintedObjects = new List<TaintCallback>(); | 764 | _taintedObjects = new List<TaintCallbackEntry>(); |
752 | } | 765 | } |
753 | 766 | ||
754 | foreach (TaintCallback callback in oldList) | 767 | foreach (TaintCallbackEntry tcbe in oldList) |
755 | { | 768 | { |
756 | try | 769 | try |
757 | { | 770 | { |
758 | callback(); | 771 | tcbe.callback(); |
759 | } | 772 | } |
760 | catch (Exception e) | 773 | catch (Exception e) |
761 | { | 774 | { |
762 | m_log.ErrorFormat("{0}: ProcessTaints: Exception: {1}", LogHeader, e); | 775 | m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, tcbe.ident, e); |
763 | } | 776 | } |
764 | } | 777 | } |
765 | oldList.Clear(); | 778 | oldList.Clear(); |
@@ -767,6 +780,20 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
767 | } | 780 | } |
768 | 781 | ||
769 | #region Vehicles | 782 | #region Vehicles |
783 | |||
784 | public void VehicleInSceneTypeChanged(BSPrim vehic, Vehicle newType) | ||
785 | { | ||
786 | if (newType == Vehicle.TYPE_NONE) | ||
787 | { | ||
788 | RemoveVehiclePrim(vehic); | ||
789 | } | ||
790 | else | ||
791 | { | ||
792 | // make it so the scene will call us each tick to do vehicle things | ||
793 | AddVehiclePrim(vehic); | ||
794 | } | ||
795 | } | ||
796 | |||
770 | // Make so the scene will call this prim for vehicle actions each tick. | 797 | // Make so the scene will call this prim for vehicle actions each tick. |
771 | // Safe to call if prim is already in the vehicle list. | 798 | // Safe to call if prim is already in the vehicle list. |
772 | public void AddVehiclePrim(BSPrim vehicle) | 799 | public void AddVehiclePrim(BSPrim vehicle) |
@@ -812,12 +839,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
812 | 839 | ||
813 | private struct ParameterDefn | 840 | private struct ParameterDefn |
814 | { | 841 | { |
815 | public string name; | 842 | public string name; // string name of the parameter |
816 | public string desc; | 843 | public string desc; // a short description of what the parameter means |
817 | public float defaultValue; | 844 | public float defaultValue; // default value if not specified anywhere else |
818 | public ParamUser userParam; | 845 | public ParamUser userParam; // get the value from the configuration file |
819 | public ParamGet getter; | 846 | public ParamGet getter; // return the current value stored for this parameter |
820 | public ParamSet setter; | 847 | public ParamSet setter; // set the current value for this parameter |
821 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) | 848 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) |
822 | { | 849 | { |
823 | name = n; | 850 | name = n; |
@@ -834,7 +861,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
834 | // To add a new externally referencable/settable parameter, add the paramter storage | 861 | // To add a new externally referencable/settable parameter, add the paramter storage |
835 | // location somewhere in the program and make an entry in this table with the | 862 | // location somewhere in the program and make an entry in this table with the |
836 | // getters and setters. | 863 | // getters and setters. |
837 | // To add a new variable, it is easiest to find an existing definition and copy it. | 864 | // It is easiest to find an existing definition and copy it. |
838 | // Parameter values are floats. Booleans are converted to a floating value. | 865 | // Parameter values are floats. Booleans are converted to a floating value. |
839 | // | 866 | // |
840 | // A ParameterDefn() takes the following parameters: | 867 | // A ParameterDefn() takes the following parameters: |
@@ -870,7 +897,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
870 | (s) => { return (float)s.m_meshLOD; }, | 897 | (s) => { return (float)s.m_meshLOD; }, |
871 | (s,p,l,v) => { s.m_meshLOD = (int)v; } ), | 898 | (s,p,l,v) => { s.m_meshLOD = (int)v; } ), |
872 | new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | 899 | new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", |
873 | 32, | 900 | 32f, |
874 | (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); }, | 901 | (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); }, |
875 | (s) => { return (float)s.m_sculptLOD; }, | 902 | (s) => { return (float)s.m_sculptLOD; }, |
876 | (s,p,l,v) => { s.m_sculptLOD = (int)v; } ), | 903 | (s,p,l,v) => { s.m_sculptLOD = (int)v; } ), |
@@ -1106,9 +1133,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1106 | (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ), | 1133 | (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ), |
1107 | new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements", | 1134 | new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements", |
1108 | ConfigurationParameters.numericFalse, | 1135 | ConfigurationParameters.numericFalse, |
1109 | (s,cf,p,v) => { s.shouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, | 1136 | (s,cf,p,v) => { s.ShouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, |
1110 | (s) => { return s.NumericBool(s.shouldDebugLog); }, | 1137 | (s) => { return s.NumericBool(s.ShouldDebugLog); }, |
1111 | (s,p,l,v) => { s.shouldDebugLog = s.BoolNumeric(v); } ), | 1138 | (s,p,l,v) => { s.ShouldDebugLog = s.BoolNumeric(v); } ), |
1112 | 1139 | ||
1113 | }; | 1140 | }; |
1114 | 1141 | ||
@@ -1248,7 +1275,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1248 | List<uint> objectIDs = lIDs; | 1275 | List<uint> objectIDs = lIDs; |
1249 | string xparm = parm.ToLower(); | 1276 | string xparm = parm.ToLower(); |
1250 | float xval = val; | 1277 | float xval = val; |
1251 | TaintedObject(delegate() { | 1278 | TaintedObject("BSScene.UpdateParameterSet", delegate() { |
1252 | foreach (uint lID in objectIDs) | 1279 | foreach (uint lID in objectIDs) |
1253 | { | 1280 | { |
1254 | BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval); | 1281 | BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval); |
@@ -1268,7 +1295,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1268 | uint xlocalID = localID; | 1295 | uint xlocalID = localID; |
1269 | string xparm = parm.ToLower(); | 1296 | string xparm = parm.ToLower(); |
1270 | float xval = val; | 1297 | float xval = val; |
1271 | TaintedObject(delegate() { | 1298 | TaintedObject("BSScene.TaintedUpdateParameter", delegate() { |
1272 | BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval); | 1299 | BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval); |
1273 | }); | 1300 | }); |
1274 | } | 1301 | } |
@@ -1294,10 +1321,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1294 | #endregion Runtime settable parameters | 1321 | #endregion Runtime settable parameters |
1295 | 1322 | ||
1296 | // Invoke the detailed logger and output something if it's enabled. | 1323 | // Invoke the detailed logger and output something if it's enabled. |
1297 | private void DetailLog(string msg, params Object[] args) | 1324 | public void DetailLog(string msg, params Object[] args) |
1298 | { | 1325 | { |
1299 | PhysicsLogging.Write(msg, args); | 1326 | PhysicsLogging.Write(msg, args); |
1300 | } | 1327 | } |
1328 | // used to fill in the LocalID when there isn't one | ||
1329 | public const string DetailLogZero = "0000000000"; | ||
1301 | 1330 | ||
1302 | } | 1331 | } |
1303 | } | 1332 | } |