diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 858 |
1 files changed, 430 insertions, 428 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index a31c578..db0c99e 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -39,33 +39,27 @@ using log4net; | |||
39 | using OpenMetaverse; | 39 | using OpenMetaverse; |
40 | 40 | ||
41 | // TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) | 41 | // TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) |
42 | // Debug linkset | 42 | // Test sculpties (verified that they don't work) |
43 | // Test with multiple regions in one simulator | ||
44 | // Adjust character capsule size when height is adjusted (ScenePresence.SetHeight) | ||
45 | // Test sculpties | ||
46 | // Compute physics FPS reasonably | 43 | // Compute physics FPS reasonably |
47 | // Based on material, set density and friction | 44 | // Based on material, set density and friction |
48 | // More efficient memory usage when passing hull information from BSPrim to BulletSim | 45 | // Don't use constraints in linksets of non-physical objects. Means having to move children manually. |
49 | // Move all logic out of the C++ code and into the C# code for easier future modifications. | ||
50 | // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? | 46 | // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? |
51 | // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) | 47 | // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) |
52 | // At the moment, physical and phantom causes object to drop through the terrain | 48 | // At the moment, physical and phantom causes object to drop through the terrain |
53 | // Physical phantom objects and related typing (collision options ) | 49 | // Physical phantom objects and related typing (collision options ) |
54 | // Use collision masks for collision with terrain and phantom objects | ||
55 | // Check out llVolumeDetect. Must do something for that. | 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 | ||
56 | // Should prim.link() and prim.delink() membership checking happen at taint time? | 53 | // Should prim.link() and prim.delink() membership checking happen at taint time? |
57 | // changing the position and orientation of a linked prim must rebuild the constraint with the root. | 54 | // Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once. |
58 | // Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once | ||
59 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect | 55 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect |
60 | // Implement the genCollisions feature in BulletSim::SetObjectProperties (don't pass up unneeded collisions) | ||
61 | // Implement LockAngularMotion | 56 | // Implement LockAngularMotion |
62 | // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) | 57 | // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) |
63 | // Does NeedsMeshing() really need to exclude all the different shapes? | ||
64 | // Remove mesh and Hull stuff. Use mesh passed to bullet and use convexdecom from bullet. | 58 | // Remove mesh and Hull stuff. Use mesh passed to bullet and use convexdecom from bullet. |
65 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? | 59 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? |
66 | // Check terrain size. 128 or 127? | 60 | // Check terrain size. 128 or 127? |
67 | // Raycast | 61 | // Raycast |
68 | // | 62 | // |
69 | namespace OpenSim.Region.Physics.BulletSPlugin | 63 | namespace OpenSim.Region.Physics.BulletSPlugin |
70 | { | 64 | { |
71 | public class BSScene : PhysicsScene, IPhysicsParameters | 65 | public class BSScene : PhysicsScene, IPhysicsParameters |
@@ -73,62 +67,56 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
73 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 67 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
74 | private static readonly string LogHeader = "[BULLETS SCENE]"; | 68 | private static readonly string LogHeader = "[BULLETS SCENE]"; |
75 | 69 | ||
76 | public void DebugLog(string mm, params Object[] xx) { if (ShouldDebugLog) m_log.DebugFormat(mm, xx); } | 70 | // The name of the region we're working for. |
71 | public string RegionName { get; private set; } | ||
77 | 72 | ||
78 | public string BulletSimVersion = "?"; | 73 | public string BulletSimVersion = "?"; |
79 | 74 | ||
80 | private Dictionary<uint, BSCharacter> m_avatars = new Dictionary<uint, BSCharacter>(); | 75 | public Dictionary<uint, BSPhysObject> PhysObjects; |
81 | private Dictionary<uint, BSPrim> m_prims = new Dictionary<uint, BSPrim>(); | 76 | public BSShapeCollection Shapes; |
82 | private HashSet<BSCharacter> m_avatarsWithCollisions = new HashSet<BSCharacter>(); | ||
83 | private HashSet<BSPrim> m_primsWithCollisions = new HashSet<BSPrim>(); | ||
84 | private List<BSPrim> m_vehicles = new List<BSPrim>(); | ||
85 | private float[] m_heightMap; | ||
86 | private float m_waterLevel; | ||
87 | private uint m_worldID; | ||
88 | public uint WorldID { get { return m_worldID; } } | ||
89 | 77 | ||
90 | // let my minuions use my logger | 78 | // Keeping track of the objects with collisions so we can report begin and end of a collision |
91 | public ILog Logger { get { return m_log; } } | 79 | public HashSet<BSPhysObject> ObjectsWithCollisions = new HashSet<BSPhysObject>(); |
80 | public HashSet<BSPhysObject> ObjectsWithNoMoreCollisions = new HashSet<BSPhysObject>(); | ||
81 | // Keep track of all the avatars so we can send them a collision event | ||
82 | // every tick so OpenSim will update its animation. | ||
83 | private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>(); | ||
92 | 84 | ||
93 | private bool m_initialized = false; | 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>(); | ||
94 | 88 | ||
95 | private int m_detailedStatsStep = 0; | 89 | // let my minuions use my logger |
90 | public ILog Logger { get { return m_log; } } | ||
96 | 91 | ||
97 | public IMesher mesher; | 92 | public IMesher mesher; |
98 | private float m_meshLOD; | 93 | // Level of Detail values kept as float because that's what the Meshmerizer wants |
99 | public float MeshLOD | 94 | public float MeshLOD { get; private set; } |
100 | { | 95 | public float MeshMegaPrimLOD { get; private set; } |
101 | get { return m_meshLOD; } | 96 | public float MeshMegaPrimThreshold { get; private set; } |
102 | } | 97 | public float SculptLOD { get; private set; } |
103 | private float m_sculptLOD; | ||
104 | public float SculptLOD | ||
105 | { | ||
106 | get { return m_sculptLOD; } | ||
107 | } | ||
108 | 98 | ||
109 | private BulletSim m_worldSim; | 99 | public uint WorldID { get; private set; } |
110 | public BulletSim World | 100 | public BulletSim World { get; private set; } |
111 | { | ||
112 | get { return m_worldSim; } | ||
113 | } | ||
114 | private BSConstraintCollection m_constraintCollection; | ||
115 | public BSConstraintCollection Constraints | ||
116 | { | ||
117 | get { return m_constraintCollection; } | ||
118 | } | ||
119 | 101 | ||
102 | // All the constraints that have been allocated in this instance. | ||
103 | public BSConstraintCollection Constraints { get; private set; } | ||
104 | |||
105 | // Simulation parameters | ||
120 | private int m_maxSubSteps; | 106 | private int m_maxSubSteps; |
121 | private float m_fixedTimeStep; | 107 | private float m_fixedTimeStep; |
122 | private long m_simulationStep = 0; | 108 | private long m_simulationStep = 0; |
123 | public long SimulationStep { get { return m_simulationStep; } } | 109 | public long SimulationStep { get { return m_simulationStep; } } |
124 | 110 | private int m_taintsToProcessPerStep; | |
125 | public float LastSimulatedTimestep { get; private set; } | ||
126 | 111 | ||
127 | // A value of the time now so all the collision and update routines do not have to get their own | 112 | // A value of the time now so all the collision and update routines do not have to get their own |
128 | // Set to 'now' just before all the prims and actors are called for collisions and updates | 113 | // Set to 'now' just before all the prims and actors are called for collisions and updates |
129 | private int m_simulationNowTime; | 114 | public int SimulationNowTime { get; private set; } |
130 | public int SimulationNowTime { get { return m_simulationNowTime; } } | 115 | |
116 | // True if initialized and ready to do simulation steps | ||
117 | private bool m_initialized = false; | ||
131 | 118 | ||
119 | // Pinned memory used to pass step information between managed and unmanaged | ||
132 | private int m_maxCollisionsPerFrame; | 120 | private int m_maxCollisionsPerFrame; |
133 | private CollisionDesc[] m_collisionArray; | 121 | private CollisionDesc[] m_collisionArray; |
134 | private GCHandle m_collisionArrayPinnedHandle; | 122 | private GCHandle m_collisionArrayPinnedHandle; |
@@ -137,14 +125,19 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
137 | private EntityProperties[] m_updateArray; | 125 | private EntityProperties[] m_updateArray; |
138 | private GCHandle m_updateArrayPinnedHandle; | 126 | private GCHandle m_updateArrayPinnedHandle; |
139 | 127 | ||
140 | private bool _meshSculptedPrim = true; // cause scuplted prims to get meshed | 128 | public bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed |
141 | private bool _forceSimplePrimMeshing = false; // if a cube or sphere, let Bullet do internal shapes | 129 | public bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes |
130 | public bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | ||
142 | 131 | ||
143 | public float PID_D { get; private set; } // derivative | 132 | public float PID_D { get; private set; } // derivative |
144 | public float PID_P { get; private set; } // proportional | 133 | public float PID_P { get; private set; } // proportional |
145 | 134 | ||
146 | public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero | 135 | public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero |
147 | public const uint GROUNDPLANE_ID = 1; | 136 | public const uint GROUNDPLANE_ID = 1; |
137 | public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here | ||
138 | |||
139 | private float m_waterLevel; | ||
140 | public BSTerrainManager TerrainManager { get; private set; } | ||
148 | 141 | ||
149 | public ConfigurationParameters Params | 142 | public ConfigurationParameters Params |
150 | { | 143 | { |
@@ -154,13 +147,18 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
154 | { | 147 | { |
155 | get { return new Vector3(0f, 0f, Params.gravity); } | 148 | get { return new Vector3(0f, 0f, Params.gravity); } |
156 | } | 149 | } |
157 | 150 | // Just the Z value of the gravity | |
158 | private float m_maximumObjectMass; | 151 | public float DefaultGravityZ |
159 | public float MaximumObjectMass | ||
160 | { | 152 | { |
161 | get { return m_maximumObjectMass; } | 153 | get { return Params.gravity; } |
162 | } | 154 | } |
163 | 155 | ||
156 | public float MaximumObjectMass { get; private set; } | ||
157 | |||
158 | // When functions in the unmanaged code must be called, it is only | ||
159 | // done at a known time just before the simulation step. The taint | ||
160 | // system saves all these function calls and executes them in | ||
161 | // order before the simulation. | ||
164 | public delegate void TaintCallback(); | 162 | public delegate void TaintCallback(); |
165 | private struct TaintCallbackEntry | 163 | private struct TaintCallbackEntry |
166 | { | 164 | { |
@@ -172,15 +170,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
172 | callback = c; | 170 | callback = c; |
173 | } | 171 | } |
174 | } | 172 | } |
173 | private Object _taintLock = new Object(); // lock for using the next object | ||
175 | private List<TaintCallbackEntry> _taintedObjects; | 174 | private List<TaintCallbackEntry> _taintedObjects; |
176 | private Object _taintLock = new Object(); | ||
177 | 175 | ||
178 | // A pointer to an instance if this structure is passed to the C++ code | 176 | // A pointer to an instance if this structure is passed to the C++ code |
177 | // Used to pass basic configuration values to the unmanaged code. | ||
179 | ConfigurationParameters[] m_params; | 178 | ConfigurationParameters[] m_params; |
180 | GCHandle m_paramsHandle; | 179 | GCHandle m_paramsHandle; |
181 | 180 | ||
182 | public bool ShouldDebugLog { get; private set; } | 181 | // Handle to the callback used by the unmanaged code to call into the managed code. |
183 | 182 | // Used for debug logging. | |
183 | // Need to store the handle in a persistant variable so it won't be freed. | ||
184 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; | 184 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; |
185 | 185 | ||
186 | // Sometimes you just have to log everything. | 186 | // Sometimes you just have to log everything. |
@@ -189,17 +189,24 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
189 | private string m_physicsLoggingDir; | 189 | private string m_physicsLoggingDir; |
190 | private string m_physicsLoggingPrefix; | 190 | private string m_physicsLoggingPrefix; |
191 | private int m_physicsLoggingFileMinutes; | 191 | private int m_physicsLoggingFileMinutes; |
192 | // 'true' of the vehicle code is to log lots of details | ||
193 | public bool VehicleLoggingEnabled { get; private set; } | ||
192 | 194 | ||
193 | private bool m_vehicleLoggingEnabled; | 195 | #region Construction and Initialization |
194 | public bool VehicleLoggingEnabled { get { return m_vehicleLoggingEnabled; } } | ||
195 | |||
196 | public BSScene(string identifier) | 196 | public BSScene(string identifier) |
197 | { | 197 | { |
198 | m_initialized = false; | 198 | m_initialized = false; |
199 | // we are passed the name of the region we're working for. | ||
200 | RegionName = identifier; | ||
199 | } | 201 | } |
200 | 202 | ||
201 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | 203 | public override void Initialise(IMesher meshmerizer, IConfigSource config) |
202 | { | 204 | { |
205 | mesher = meshmerizer; | ||
206 | _taintedObjects = new List<TaintCallbackEntry>(); | ||
207 | PhysObjects = new Dictionary<uint, BSPhysObject>(); | ||
208 | Shapes = new BSShapeCollection(this); | ||
209 | |||
203 | // Allocate pinned memory to pass parameters. | 210 | // Allocate pinned memory to pass parameters. |
204 | m_params = new ConfigurationParameters[1]; | 211 | m_params = new ConfigurationParameters[1]; |
205 | m_paramsHandle = GCHandle.Alloc(m_params, GCHandleType.Pinned); | 212 | m_paramsHandle = GCHandle.Alloc(m_params, GCHandleType.Pinned); |
@@ -215,7 +222,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
215 | 222 | ||
216 | // Enable very detailed logging. | 223 | // Enable very detailed logging. |
217 | // By creating an empty logger when not logging, the log message invocation code | 224 | // By creating an empty logger when not logging, the log message invocation code |
218 | // can be left in and every call doesn't have to check for null. | 225 | // can be left in and every call doesn't have to check for null. |
219 | if (m_physicsLoggingEnabled) | 226 | if (m_physicsLoggingEnabled) |
220 | { | 227 | { |
221 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); | 228 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); |
@@ -225,38 +232,39 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
225 | PhysicsLogging = new Logging.LogWriter(); | 232 | PhysicsLogging = new Logging.LogWriter(); |
226 | } | 233 | } |
227 | 234 | ||
228 | // Get the version of the DLL | 235 | // If Debug logging level, enable logging from the unmanaged code |
229 | // TODO: this doesn't work yet. Something wrong with marshaling the returned string. | 236 | m_DebugLogCallbackHandle = null; |
230 | // BulletSimVersion = BulletSimAPI.GetVersion(); | ||
231 | // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); | ||
232 | |||
233 | // if Debug, enable logging from the unmanaged code | ||
234 | if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) | 237 | if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) |
235 | { | 238 | { |
236 | m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); | 239 | m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); |
237 | if (PhysicsLogging.Enabled) | 240 | if (PhysicsLogging.Enabled) |
241 | // The handle is saved in a variable to make sure it doesn't get freed after this call | ||
238 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog); | 242 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog); |
239 | else | 243 | else |
240 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); | 244 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); |
241 | // the handle is saved in a variable to make sure it doesn't get freed after this call | ||
242 | BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); | ||
243 | } | 245 | } |
244 | 246 | ||
245 | _taintedObjects = new List<TaintCallbackEntry>(); | 247 | // Get the version of the DLL |
248 | // TODO: this doesn't work yet. Something wrong with marshaling the returned string. | ||
249 | // BulletSimVersion = BulletSimAPI.GetVersion(); | ||
250 | // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); | ||
246 | 251 | ||
247 | mesher = meshmerizer; | 252 | // The bounding box for the simulated world. The origin is 0,0,0 unless we're |
248 | // The bounding box for the simulated world | 253 | // a child in a mega-region. |
249 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, 8192f); | 254 | // Bullet actually doesn't care about the extents of the simulated |
255 | // area. It tracks active objects no matter where they are. | ||
256 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | ||
250 | 257 | ||
251 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); | 258 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); |
252 | m_worldID = BulletSimAPI.Initialize(worldExtent, m_paramsHandle.AddrOfPinnedObject(), | 259 | World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(), |
253 | m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), | 260 | m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), |
254 | m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject()); | 261 | m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(), |
262 | m_DebugLogCallbackHandle)); | ||
263 | |||
264 | Constraints = new BSConstraintCollection(World); | ||
255 | 265 | ||
256 | // Initialization to support the transition to a new API which puts most of the logic | 266 | TerrainManager = new BSTerrainManager(this); |
257 | // into the C# code so it is easier to modify and add to. | 267 | TerrainManager.CreateInitialGroundPlaneAndTerrain(); |
258 | m_worldSim = new BulletSim(m_worldID, this, BulletSimAPI.GetSimHandle2(m_worldID)); | ||
259 | m_constraintCollection = new BSConstraintCollection(World); | ||
260 | 268 | ||
261 | m_initialized = true; | 269 | m_initialized = true; |
262 | } | 270 | } |
@@ -281,10 +289,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
281 | // Very detailed logging for physics debugging | 289 | // Very detailed logging for physics debugging |
282 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); | 290 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); |
283 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); | 291 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); |
284 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-"); | 292 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-"); |
285 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); | 293 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); |
286 | // Very detailed logging for vehicle debugging | 294 | // Very detailed logging for vehicle debugging |
287 | m_vehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); | 295 | VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); |
296 | |||
297 | // Do any replacements in the parameters | ||
298 | m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); | ||
288 | } | 299 | } |
289 | } | 300 | } |
290 | } | 301 | } |
@@ -309,13 +320,51 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
309 | { | 320 | { |
310 | m_log.Debug("[BULLETS UNMANAGED]:" + msg); | 321 | m_log.Debug("[BULLETS UNMANAGED]:" + msg); |
311 | } | 322 | } |
312 | 323 | ||
313 | // Called directly from unmanaged code so don't do much | 324 | // Called directly from unmanaged code so don't do much |
314 | private void BulletLoggerPhysLog(string msg) | 325 | private void BulletLoggerPhysLog(string msg) |
315 | { | 326 | { |
316 | PhysicsLogging.Write("[BULLETS UNMANAGED]:" + msg); | 327 | DetailLog("[BULLETS UNMANAGED]:" + msg); |
317 | } | 328 | } |
318 | 329 | ||
330 | public override void Dispose() | ||
331 | { | ||
332 | // m_log.DebugFormat("{0}: Dispose()", LogHeader); | ||
333 | |||
334 | // make sure no stepping happens while we're deleting stuff | ||
335 | m_initialized = false; | ||
336 | |||
337 | TerrainManager.ReleaseGroundPlaneAndTerrain(); | ||
338 | |||
339 | foreach (KeyValuePair<uint, BSPhysObject> kvp in PhysObjects) | ||
340 | { | ||
341 | kvp.Value.Destroy(); | ||
342 | } | ||
343 | PhysObjects.Clear(); | ||
344 | |||
345 | // Now that the prims are all cleaned up, there should be no constraints left | ||
346 | if (Constraints != null) | ||
347 | { | ||
348 | Constraints.Dispose(); | ||
349 | Constraints = null; | ||
350 | } | ||
351 | |||
352 | if (Shapes != null) | ||
353 | { | ||
354 | Shapes.Dispose(); | ||
355 | Shapes = null; | ||
356 | } | ||
357 | |||
358 | // Anything left in the unmanaged code should be cleaned out | ||
359 | BulletSimAPI.Shutdown2(World.ptr); | ||
360 | |||
361 | // Not logging any more | ||
362 | PhysicsLogging.Close(); | ||
363 | } | ||
364 | #endregion // Construction and Initialization | ||
365 | |||
366 | #region Prim and Avatar addition and removal | ||
367 | |||
319 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) | 368 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) |
320 | { | 369 | { |
321 | m_log.ErrorFormat("{0}: CALL TO AddAvatar in BSScene. NOT IMPLEMENTED", LogHeader); | 370 | m_log.ErrorFormat("{0}: CALL TO AddAvatar in BSScene. NOT IMPLEMENTED", LogHeader); |
@@ -329,7 +378,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
329 | if (!m_initialized) return null; | 378 | if (!m_initialized) return null; |
330 | 379 | ||
331 | BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying); | 380 | BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying); |
332 | lock (m_avatars) m_avatars.Add(localID, actor); | 381 | lock (PhysObjects) PhysObjects.Add(localID, actor); |
382 | |||
383 | // TODO: Remove kludge someday. | ||
384 | // We must generate a collision for avatars whether they collide or not. | ||
385 | // This is required by OpenSim to update avatar animations, etc. | ||
386 | lock (m_avatars) m_avatars.Add(actor); | ||
387 | |||
333 | return actor; | 388 | return actor; |
334 | } | 389 | } |
335 | 390 | ||
@@ -344,7 +399,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
344 | { | 399 | { |
345 | try | 400 | try |
346 | { | 401 | { |
347 | lock (m_avatars) m_avatars.Remove(actor.LocalID); | 402 | lock (PhysObjects) PhysObjects.Remove(actor.LocalID); |
403 | // Remove kludge someday | ||
404 | lock (m_avatars) m_avatars.Remove(bsactor); | ||
348 | } | 405 | } |
349 | catch (Exception e) | 406 | catch (Exception e) |
350 | { | 407 | { |
@@ -362,11 +419,11 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
362 | BSPrim bsprim = prim as BSPrim; | 419 | BSPrim bsprim = prim as BSPrim; |
363 | if (bsprim != null) | 420 | if (bsprim != null) |
364 | { | 421 | { |
365 | // DetailLog("{0},RemovePrim,call", bsprim.LocalID); | 422 | DetailLog("{0},RemovePrim,call", bsprim.LocalID); |
366 | // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); | 423 | // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); |
367 | try | 424 | try |
368 | { | 425 | { |
369 | lock (m_prims) m_prims.Remove(bsprim.LocalID); | 426 | lock (PhysObjects) PhysObjects.Remove(bsprim.LocalID); |
370 | } | 427 | } |
371 | catch (Exception e) | 428 | catch (Exception e) |
372 | { | 429 | { |
@@ -388,18 +445,21 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
388 | 445 | ||
389 | if (!m_initialized) return null; | 446 | if (!m_initialized) return null; |
390 | 447 | ||
391 | // DetailLog("{0},AddPrimShape,call", localID); | 448 | DetailLog("{0},AddPrimShape,call", localID); |
392 | 449 | ||
393 | BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical); | 450 | BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical); |
394 | lock (m_prims) m_prims.Add(localID, prim); | 451 | lock (PhysObjects) PhysObjects.Add(localID, prim); |
395 | return prim; | 452 | return prim; |
396 | } | 453 | } |
397 | 454 | ||
398 | // This is a call from the simulator saying that some physical property has been updated. | 455 | // This is a call from the simulator saying that some physical property has been updated. |
399 | // The BulletSim driver senses the changing of relevant properties so this taint | 456 | // The BulletSim driver senses the changing of relevant properties so this taint |
400 | // information call is not needed. | 457 | // information call is not needed. |
401 | public override void AddPhysicsActorTaint(PhysicsActor prim) { } | 458 | public override void AddPhysicsActorTaint(PhysicsActor prim) { } |
402 | 459 | ||
460 | #endregion // Prim and Avatar addition and removal | ||
461 | |||
462 | #region Simulation | ||
403 | // Simulate one timestep | 463 | // Simulate one timestep |
404 | public override float Simulate(float timeStep) | 464 | public override float Simulate(float timeStep) |
405 | { | 465 | { |
@@ -408,34 +468,46 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
408 | int collidersCount = 0; | 468 | int collidersCount = 0; |
409 | IntPtr collidersPtr; | 469 | IntPtr collidersPtr; |
410 | 470 | ||
411 | LastSimulatedTimestep = timeStep; | 471 | int beforeTime = 0; |
472 | int simTime = 0; | ||
412 | 473 | ||
413 | // prevent simulation until we've been initialized | 474 | // prevent simulation until we've been initialized |
414 | if (!m_initialized) return 10.0f; | 475 | if (!m_initialized) return 5.0f; |
415 | |||
416 | int simulateStartTime = Util.EnvironmentTickCount(); | ||
417 | 476 | ||
418 | // update the prim states while we know the physics engine is not busy | 477 | // update the prim states while we know the physics engine is not busy |
478 | int numTaints = _taintedObjects.Count; | ||
419 | ProcessTaints(); | 479 | ProcessTaints(); |
420 | 480 | ||
421 | // Some of the prims operate with special vehicle properties | 481 | // Some of the prims operate with special vehicle properties |
422 | ProcessVehicles(timeStep); | 482 | ProcessVehicles(timeStep); |
483 | numTaints += _taintedObjects.Count; | ||
423 | ProcessTaints(); // the vehicles might have added taints | 484 | ProcessTaints(); // the vehicles might have added taints |
424 | 485 | ||
425 | // step the physical world one interval | 486 | // step the physical world one interval |
426 | m_simulationStep++; | 487 | m_simulationStep++; |
427 | int numSubSteps = 0; | 488 | int numSubSteps = 0; |
489 | |||
490 | // DEBUG | ||
491 | // DetailLog("{0},BSScene.Simulate,beforeStep,ntaimts={1},step={2}", DetailLogZero, numTaints, m_simulationStep); | ||
492 | |||
428 | try | 493 | try |
429 | { | 494 | { |
430 | numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep, | 495 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); |
496 | |||
497 | numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, | ||
431 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); | 498 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); |
432 | // DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); | 499 | |
500 | if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); | ||
501 | DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}", | ||
502 | DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, updatedEntityCount, collidersCount); | ||
433 | } | 503 | } |
434 | catch (Exception e) | 504 | catch (Exception e) |
435 | { | 505 | { |
436 | m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e); | 506 | m_log.WarnFormat("{0},PhysicsStep Exception: nTaints={1}, substeps={2}, updates={3}, colliders={4}, e={5}", |
437 | // DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); | 507 | LogHeader, numTaints, numSubSteps, updatedEntityCount, collidersCount, e); |
438 | // updatedEntityCount = 0; | 508 | DetailLog("{0},PhysicsStepException,call, nTaints={1}, substeps={2}, updates={3}, colliders={4}", |
509 | DetailLogZero, numTaints, numSubSteps, updatedEntityCount, collidersCount); | ||
510 | updatedEntityCount = 0; | ||
439 | collidersCount = 0; | 511 | collidersCount = 0; |
440 | } | 512 | } |
441 | 513 | ||
@@ -443,7 +515,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
443 | // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in | 515 | // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in |
444 | 516 | ||
445 | // Get a value for 'now' so all the collision and update routines don't have to get their own | 517 | // Get a value for 'now' so all the collision and update routines don't have to get their own |
446 | m_simulationNowTime = Util.EnvironmentTickCount(); | 518 | SimulationNowTime = Util.EnvironmentTickCount(); |
447 | 519 | ||
448 | // If there were collisions, process them by sending the event to the prim. | 520 | // If there were collisions, process them by sending the event to the prim. |
449 | // Collisions must be processed before updates. | 521 | // Collisions must be processed before updates. |
@@ -462,19 +534,32 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
462 | 534 | ||
463 | // The above SendCollision's batch up the collisions on the objects. | 535 | // The above SendCollision's batch up the collisions on the objects. |
464 | // Now push the collisions into the simulator. | 536 | // Now push the collisions into the simulator. |
465 | foreach (BSPrim bsp in m_primsWithCollisions) | 537 | if (ObjectsWithCollisions.Count > 0) |
466 | bsp.SendCollisions(); | 538 | { |
467 | m_primsWithCollisions.Clear(); | 539 | foreach (BSPhysObject bsp in ObjectsWithCollisions) |
468 | 540 | if (!bsp.SendCollisions()) | |
469 | // This is a kludge to get avatar movement updated. | 541 | { |
470 | // Don't send collisions only if there were collisions -- send everytime. | 542 | // If the object is done colliding, see that it's removed from the colliding list |
471 | // ODE sends collisions even if there are none and this is used to update | 543 | ObjectsWithNoMoreCollisions.Add(bsp); |
472 | // avatar animations and stuff. | 544 | } |
473 | // foreach (BSCharacter bsc in m_avatarsWithCollisions) | 545 | } |
474 | // bsc.SendCollisions(); | 546 | |
475 | foreach (KeyValuePair<uint, BSCharacter> kvp in m_avatars) | 547 | // This is a kludge to get avatar movement updates. |
476 | kvp.Value.SendCollisions(); | 548 | // The simulator expects collisions for avatars even if there are have been no collisions. |
477 | m_avatarsWithCollisions.Clear(); | 549 | // The event updates avatar animations and stuff. |
550 | // If you fix avatar animation updates, remove this overhead and let normal collision processing happen. | ||
551 | foreach (BSPhysObject bsp in m_avatars) | ||
552 | if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice | ||
553 | bsp.SendCollisions(); | ||
554 | |||
555 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. | ||
556 | // Not done above because it is inside an iteration of ObjectWithCollisions. | ||
557 | if (ObjectsWithNoMoreCollisions.Count > 0) | ||
558 | { | ||
559 | foreach (BSPhysObject po in ObjectsWithNoMoreCollisions) | ||
560 | ObjectsWithCollisions.Remove(po); | ||
561 | ObjectsWithNoMoreCollisions.Clear(); | ||
562 | } | ||
478 | 563 | ||
479 | // If any of the objects had updated properties, tell the object it has been changed by the physics engine | 564 | // If any of the objects had updated properties, tell the object it has been changed by the physics engine |
480 | if (updatedEntityCount > 0) | 565 | if (updatedEntityCount > 0) |
@@ -482,145 +567,102 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
482 | for (int ii = 0; ii < updatedEntityCount; ii++) | 567 | for (int ii = 0; ii < updatedEntityCount; ii++) |
483 | { | 568 | { |
484 | EntityProperties entprop = m_updateArray[ii]; | 569 | EntityProperties entprop = m_updateArray[ii]; |
485 | BSPrim prim; | 570 | BSPhysObject pobj; |
486 | if (m_prims.TryGetValue(entprop.ID, out prim)) | 571 | if (PhysObjects.TryGetValue(entprop.ID, out pobj)) |
487 | { | 572 | { |
488 | prim.UpdateProperties(entprop); | 573 | pobj.UpdateProperties(entprop); |
489 | continue; | ||
490 | } | ||
491 | BSCharacter actor; | ||
492 | if (m_avatars.TryGetValue(entprop.ID, out actor)) | ||
493 | { | ||
494 | actor.UpdateProperties(entprop); | ||
495 | continue; | ||
496 | } | 574 | } |
497 | } | 575 | } |
498 | } | 576 | } |
499 | 577 | ||
500 | // If enabled, call into the physics engine to dump statistics | 578 | // This causes the unmanaged code to output ALL the values found in ALL the objects in the world. |
501 | if (m_detailedStatsStep > 0) | 579 | // Only enable this in a limited test world with few objects. |
502 | { | 580 | // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG |
503 | if ((m_simulationStep % m_detailedStatsStep) == 0) | ||
504 | { | ||
505 | BulletSimAPI.DumpBulletStatistics(); | ||
506 | } | ||
507 | } | ||
508 | 581 | ||
509 | // this is a waste since the outside routine also calcuates the physics simulation | 582 | // The physics engine returns the number of milliseconds it simulated this call. |
510 | // period. TODO: There should be a way of computing physics frames from simulator computation. | 583 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. |
511 | // long simulateTotalTime = Util.EnvironmentTickCountSubtract(simulateStartTime); | 584 | // We multiply by 55 to give a recognizable running rate (55 or less). |
512 | // return (timeStep * (float)simulateTotalTime); | 585 | return numSubSteps * m_fixedTimeStep * 1000 * 55; |
513 | 586 | // return timeStep * 1000 * 55; | |
514 | // TODO: FIX THIS: fps calculation possibly wrong. | ||
515 | // This calculation says 1/timeStep is the ideal frame rate. Any time added to | ||
516 | // that by the physics simulation gives a slower frame rate. | ||
517 | long totalSimulationTime = Util.EnvironmentTickCountSubtract(simulateStartTime); | ||
518 | if (totalSimulationTime >= timeStep) | ||
519 | return 0; | ||
520 | return 1f / (timeStep + totalSimulationTime); | ||
521 | } | 587 | } |
522 | 588 | ||
523 | // Something has collided | 589 | // Something has collided |
524 | private void SendCollision(uint localID, uint collidingWith, Vector3 collidePoint, Vector3 collideNormal, float penitration) | 590 | private void SendCollision(uint localID, uint collidingWith, Vector3 collidePoint, Vector3 collideNormal, float penetration) |
525 | { | 591 | { |
526 | if (localID == TERRAIN_ID || localID == GROUNDPLANE_ID) | 592 | if (localID <= TerrainManager.HighestTerrainID) |
527 | { | 593 | { |
528 | return; // don't send collisions to the terrain | 594 | return; // don't send collisions to the terrain |
529 | } | 595 | } |
530 | 596 | ||
531 | ActorTypes type = ActorTypes.Prim; | 597 | BSPhysObject collider; |
532 | if (collidingWith == TERRAIN_ID || collidingWith == GROUNDPLANE_ID) | 598 | if (!PhysObjects.TryGetValue(localID, out collider)) |
533 | type = ActorTypes.Ground; | 599 | { |
534 | else if (m_avatars.ContainsKey(collidingWith)) | 600 | // If the object that is colliding cannot be found, just ignore the collision. |
535 | type = ActorTypes.Agent; | 601 | DetailLog("{0},BSScene.SendCollision,colliderNotInObjectList,id={1},with={2}", DetailLogZero, localID, collidingWith); |
536 | |||
537 | BSPrim prim; | ||
538 | if (m_prims.TryGetValue(localID, out prim)) { | ||
539 | prim.Collide(collidingWith, type, collidePoint, collideNormal, penitration); | ||
540 | m_primsWithCollisions.Add(prim); | ||
541 | return; | 602 | return; |
542 | } | 603 | } |
543 | BSCharacter actor; | 604 | |
544 | if (m_avatars.TryGetValue(localID, out actor)) { | 605 | // The terrain is not in the physical object list so 'collidee' can be null when Collide() is called. |
545 | actor.Collide(collidingWith, type, collidePoint, collideNormal, penitration); | 606 | BSPhysObject collidee = null; |
546 | m_avatarsWithCollisions.Add(actor); | 607 | PhysObjects.TryGetValue(collidingWith, out collidee); |
547 | return; | 608 | |
609 | // DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith); | ||
610 | |||
611 | if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) | ||
612 | { | ||
613 | // If a collision was posted, remember to send it to the simulator | ||
614 | ObjectsWithCollisions.Add(collider); | ||
548 | } | 615 | } |
616 | |||
549 | return; | 617 | return; |
550 | } | 618 | } |
551 | 619 | ||
552 | public override void GetResults() { } | 620 | #endregion // Simulation |
553 | 621 | ||
554 | public override void SetTerrain(float[] heightMap) { | 622 | public override void GetResults() { } |
555 | m_heightMap = heightMap; | ||
556 | this.TaintedObject("BSScene.SetTerrain", delegate() | ||
557 | { | ||
558 | BulletSimAPI.SetHeightmap(m_worldID, m_heightMap); | ||
559 | }); | ||
560 | } | ||
561 | 623 | ||
562 | // Someday we will have complex terrain with caves and tunnels | 624 | #region Terrain |
563 | // For the moment, it's flat and convex | ||
564 | public float GetTerrainHeightAtXYZ(Vector3 loc) | ||
565 | { | ||
566 | return GetTerrainHeightAtXY(loc.X, loc.Y); | ||
567 | } | ||
568 | 625 | ||
569 | public float GetTerrainHeightAtXY(float tX, float tY) | 626 | public override void SetTerrain(float[] heightMap) { |
570 | { | 627 | TerrainManager.SetTerrain(heightMap); |
571 | if (tX < 0 || tX >= Constants.RegionSize || tY < 0 || tY >= Constants.RegionSize) | ||
572 | return 30; | ||
573 | return m_heightMap[((int)tX) * Constants.RegionSize + ((int)tY)]; | ||
574 | } | 628 | } |
575 | 629 | ||
576 | public override void SetWaterLevel(float baseheight) | 630 | public override void SetWaterLevel(float baseheight) |
577 | { | 631 | { |
578 | m_waterLevel = baseheight; | 632 | m_waterLevel = baseheight; |
579 | // TODO: pass to physics engine so things will float? | ||
580 | } | 633 | } |
581 | public float GetWaterLevel() | 634 | // Someday.... |
635 | public float GetWaterLevelAtXYZ(Vector3 loc) | ||
582 | { | 636 | { |
583 | return m_waterLevel; | 637 | return m_waterLevel; |
584 | } | 638 | } |
585 | 639 | ||
586 | public override void DeleteTerrain() | 640 | public override void DeleteTerrain() |
587 | { | 641 | { |
588 | // m_log.DebugFormat("{0}: DeleteTerrain()", LogHeader); | 642 | // m_log.DebugFormat("{0}: DeleteTerrain()", LogHeader); |
589 | } | 643 | } |
590 | 644 | ||
591 | public override void Dispose() | 645 | // Although no one seems to check this, I do support combining. |
646 | public override bool SupportsCombining() | ||
592 | { | 647 | { |
593 | // m_log.DebugFormat("{0}: Dispose()", LogHeader); | 648 | return TerrainManager.SupportsCombining(); |
594 | 649 | } | |
595 | // make sure no stepping happens while we're deleting stuff | 650 | // This call says I am a child to region zero in a mega-region. 'pScene' is that |
596 | m_initialized = false; | 651 | // of region zero, 'offset' is my offset from regions zero's origin, and |
597 | 652 | // 'extents' is the largest XY that is handled in my region. | |
598 | foreach (KeyValuePair<uint, BSCharacter> kvp in m_avatars) | 653 | public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) |
599 | { | 654 | { |
600 | kvp.Value.Destroy(); | 655 | TerrainManager.Combine(pScene, offset, extents); |
601 | } | 656 | } |
602 | m_avatars.Clear(); | ||
603 | |||
604 | foreach (KeyValuePair<uint, BSPrim> kvp in m_prims) | ||
605 | { | ||
606 | kvp.Value.Destroy(); | ||
607 | } | ||
608 | m_prims.Clear(); | ||
609 | |||
610 | // Now that the prims are all cleaned up, there should be no constraints left | ||
611 | if (m_constraintCollection != null) | ||
612 | { | ||
613 | m_constraintCollection.Dispose(); | ||
614 | m_constraintCollection = null; | ||
615 | } | ||
616 | |||
617 | // Anything left in the unmanaged code should be cleaned out | ||
618 | BulletSimAPI.Shutdown(WorldID); | ||
619 | 657 | ||
620 | // Not logging any more | 658 | // Unhook all the combining that I know about. |
621 | PhysicsLogging.Close(); | 659 | public override void UnCombine(PhysicsScene pScene) |
660 | { | ||
661 | TerrainManager.UnCombine(pScene); | ||
622 | } | 662 | } |
623 | 663 | ||
664 | #endregion // Terrain | ||
665 | |||
624 | public override Dictionary<uint, float> GetTopColliders() | 666 | public override Dictionary<uint, float> GetTopColliders() |
625 | { | 667 | { |
626 | return new Dictionary<uint, float>(); | 668 | return new Dictionary<uint, float>(); |
@@ -628,121 +670,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
628 | 670 | ||
629 | public override bool IsThreaded { get { return false; } } | 671 | public override bool IsThreaded { get { return false; } } |
630 | 672 | ||
631 | /// <summary> | ||
632 | /// Routine to figure out if we need to mesh this prim with our mesher | ||
633 | /// </summary> | ||
634 | /// <param name="pbs"></param> | ||
635 | /// <returns>true if the prim needs meshing</returns> | ||
636 | public bool NeedsMeshing(PrimitiveBaseShape pbs) | ||
637 | { | ||
638 | // most of this is redundant now as the mesher will return null if it cant mesh a prim | ||
639 | // but we still need to check for sculptie meshing being enabled so this is the most | ||
640 | // convenient place to do it for now... | ||
641 | |||
642 | // int iPropertiesNotSupportedDefault = 0; | ||
643 | |||
644 | if (pbs.SculptEntry && !_meshSculptedPrim) | ||
645 | { | ||
646 | // Render sculpties as boxes | ||
647 | return false; | ||
648 | } | ||
649 | |||
650 | // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since Bullet | ||
651 | // can use an internal representation for the prim | ||
652 | if (!_forceSimplePrimMeshing) | ||
653 | { | ||
654 | if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) | ||
655 | || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 | ||
656 | && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z)) | ||
657 | { | ||
658 | |||
659 | if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | ||
660 | && pbs.ProfileHollow == 0 | ||
661 | && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 | ||
662 | && pbs.PathBegin == 0 && pbs.PathEnd == 0 | ||
663 | && pbs.PathTaperX == 0 && pbs.PathTaperY == 0 | ||
664 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 | ||
665 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) | ||
666 | { | ||
667 | return false; | ||
668 | } | ||
669 | } | ||
670 | } | ||
671 | |||
672 | /* TODO: verify that the mesher will now do all these shapes | ||
673 | if (pbs.ProfileHollow != 0) | ||
674 | iPropertiesNotSupportedDefault++; | ||
675 | |||
676 | if ((pbs.PathBegin != 0) || pbs.PathEnd != 0) | ||
677 | iPropertiesNotSupportedDefault++; | ||
678 | |||
679 | if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0)) | ||
680 | iPropertiesNotSupportedDefault++; | ||
681 | |||
682 | if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0) | ||
683 | iPropertiesNotSupportedDefault++; | ||
684 | |||
685 | if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100)) | ||
686 | iPropertiesNotSupportedDefault++; | ||
687 | |||
688 | if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0)) | ||
689 | iPropertiesNotSupportedDefault++; | ||
690 | |||
691 | if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight) | ||
692 | iPropertiesNotSupportedDefault++; | ||
693 | |||
694 | if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X)) | ||
695 | iPropertiesNotSupportedDefault++; | ||
696 | |||
697 | if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte) Extrusion.Curve1) | ||
698 | iPropertiesNotSupportedDefault++; | ||
699 | |||
700 | // test for torus | ||
701 | if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square) | ||
702 | { | ||
703 | if (pbs.PathCurve == (byte)Extrusion.Curve1) | ||
704 | { | ||
705 | iPropertiesNotSupportedDefault++; | ||
706 | } | ||
707 | } | ||
708 | else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) | ||
709 | { | ||
710 | if (pbs.PathCurve == (byte)Extrusion.Straight) | ||
711 | { | ||
712 | iPropertiesNotSupportedDefault++; | ||
713 | } | ||
714 | // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits | ||
715 | else if (pbs.PathCurve == (byte)Extrusion.Curve1) | ||
716 | { | ||
717 | iPropertiesNotSupportedDefault++; | ||
718 | } | ||
719 | } | ||
720 | else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) | ||
721 | { | ||
722 | if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2) | ||
723 | { | ||
724 | iPropertiesNotSupportedDefault++; | ||
725 | } | ||
726 | } | ||
727 | else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) | ||
728 | { | ||
729 | if (pbs.PathCurve == (byte)Extrusion.Straight) | ||
730 | { | ||
731 | iPropertiesNotSupportedDefault++; | ||
732 | } | ||
733 | else if (pbs.PathCurve == (byte)Extrusion.Curve1) | ||
734 | { | ||
735 | iPropertiesNotSupportedDefault++; | ||
736 | } | ||
737 | } | ||
738 | if (iPropertiesNotSupportedDefault == 0) | ||
739 | { | ||
740 | return false; | ||
741 | } | ||
742 | */ | ||
743 | return true; | ||
744 | } | ||
745 | |||
746 | // Calls to the PhysicsActors can't directly call into the physics engine | 673 | // Calls to the PhysicsActors can't directly call into the physics engine |
747 | // because it might be busy. We delay changes to a known time. | 674 | // because it might be busy. We delay changes to a known time. |
748 | // We rely on C#'s closure to save and restore the context for the delegate. | 675 | // We rely on C#'s closure to save and restore the context for the delegate. |
@@ -751,7 +678,10 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
751 | if (!m_initialized) return; | 678 | if (!m_initialized) return; |
752 | 679 | ||
753 | lock (_taintLock) | 680 | lock (_taintLock) |
681 | { | ||
754 | _taintedObjects.Add(new TaintCallbackEntry(ident, callback)); | 682 | _taintedObjects.Add(new TaintCallbackEntry(ident, callback)); |
683 | } | ||
684 | |||
755 | return; | 685 | return; |
756 | } | 686 | } |
757 | 687 | ||
@@ -762,6 +692,35 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
762 | { | 692 | { |
763 | if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process | 693 | if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process |
764 | { | 694 | { |
695 | int taintCount = m_taintsToProcessPerStep; | ||
696 | TaintCallbackEntry oneCallback = new TaintCallbackEntry(); | ||
697 | while (_taintedObjects.Count > 0 && taintCount-- > 0) | ||
698 | { | ||
699 | bool gotOne = false; | ||
700 | lock (_taintLock) | ||
701 | { | ||
702 | if (_taintedObjects.Count > 0) | ||
703 | { | ||
704 | oneCallback = _taintedObjects[0]; | ||
705 | _taintedObjects.RemoveAt(0); | ||
706 | gotOne = true; | ||
707 | } | ||
708 | } | ||
709 | if (gotOne) | ||
710 | { | ||
711 | try | ||
712 | { | ||
713 | DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", DetailLogZero, oneCallback.ident); | ||
714 | oneCallback.callback(); | ||
715 | } | ||
716 | catch (Exception e) | ||
717 | { | ||
718 | DetailLog("{0},BSScene.ProcessTaints,doTaintException,id={1}", DetailLogZero, oneCallback.ident); // DEBUG DEBUG DEBUG | ||
719 | m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, oneCallback.ident, e); | ||
720 | } | ||
721 | } | ||
722 | } | ||
723 | /* | ||
765 | // swizzle a new list into the list location so we can process what's there | 724 | // swizzle a new list into the list location so we can process what's there |
766 | List<TaintCallbackEntry> oldList; | 725 | List<TaintCallbackEntry> oldList; |
767 | lock (_taintLock) | 726 | lock (_taintLock) |
@@ -774,6 +733,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
774 | { | 733 | { |
775 | try | 734 | try |
776 | { | 735 | { |
736 | DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", DetailLogZero, tcbe.ident); // DEBUG DEBUG DEBUG | ||
777 | tcbe.callback(); | 737 | tcbe.callback(); |
778 | } | 738 | } |
779 | catch (Exception e) | 739 | catch (Exception e) |
@@ -782,6 +742,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
782 | } | 742 | } |
783 | } | 743 | } |
784 | oldList.Clear(); | 744 | oldList.Clear(); |
745 | */ | ||
785 | } | 746 | } |
786 | } | 747 | } |
787 | 748 | ||
@@ -789,13 +750,10 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
789 | 750 | ||
790 | public void VehicleInSceneTypeChanged(BSPrim vehic, Vehicle newType) | 751 | public void VehicleInSceneTypeChanged(BSPrim vehic, Vehicle newType) |
791 | { | 752 | { |
792 | if (newType == Vehicle.TYPE_NONE) | 753 | RemoveVehiclePrim(vehic); |
793 | { | 754 | if (newType != Vehicle.TYPE_NONE) |
794 | RemoveVehiclePrim(vehic); | ||
795 | } | ||
796 | else | ||
797 | { | 755 | { |
798 | // make it so the scene will call us each tick to do vehicle things | 756 | // make it so the scene will call us each tick to do vehicle things |
799 | AddVehiclePrim(vehic); | 757 | AddVehiclePrim(vehic); |
800 | } | 758 | } |
801 | } | 759 | } |
@@ -827,21 +785,22 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
827 | } | 785 | } |
828 | 786 | ||
829 | // Some prims have extra vehicle actions | 787 | // Some prims have extra vehicle actions |
830 | // no locking because only called when physics engine is not busy | 788 | // Called at taint time! |
831 | private void ProcessVehicles(float timeStep) | 789 | private void ProcessVehicles(float timeStep) |
832 | { | 790 | { |
833 | foreach (BSPrim prim in m_vehicles) | 791 | foreach (BSPhysObject pobj in m_vehicles) |
834 | { | 792 | { |
835 | prim.StepVehicle(timeStep); | 793 | pobj.StepVehicle(timeStep); |
836 | } | 794 | } |
837 | } | 795 | } |
838 | #endregion Vehicles | 796 | #endregion Vehicles |
839 | 797 | ||
840 | #region Parameters | 798 | #region INI and command line parameter processing |
841 | 799 | ||
842 | delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); | 800 | delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); |
843 | delegate float ParamGet(BSScene scene); | 801 | delegate float ParamGet(BSScene scene); |
844 | delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); | 802 | delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); |
803 | delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val); | ||
845 | 804 | ||
846 | private struct ParameterDefn | 805 | private struct ParameterDefn |
847 | { | 806 | { |
@@ -851,6 +810,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
851 | public ParamUser userParam; // get the value from the configuration file | 810 | public ParamUser userParam; // get the value from the configuration file |
852 | public ParamGet getter; // return the current value stored for this parameter | 811 | public ParamGet getter; // return the current value stored for this parameter |
853 | public ParamSet setter; // set the current value for this parameter | 812 | public ParamSet setter; // set the current value for this parameter |
813 | public SetOnObject onObject; // set the value on an object in the physical domain | ||
854 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) | 814 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) |
855 | { | 815 | { |
856 | name = n; | 816 | name = n; |
@@ -859,6 +819,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
859 | userParam = u; | 819 | userParam = u; |
860 | getter = g; | 820 | getter = g; |
861 | setter = s; | 821 | setter = s; |
822 | onObject = null; | ||
823 | } | ||
824 | public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o) | ||
825 | { | ||
826 | name = n; | ||
827 | desc = d; | ||
828 | defaultValue = v; | ||
829 | userParam = u; | ||
830 | getter = g; | ||
831 | setter = s; | ||
832 | onObject = o; | ||
862 | } | 833 | } |
863 | } | 834 | } |
864 | 835 | ||
@@ -869,7 +840,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
869 | // getters and setters. | 840 | // getters and setters. |
870 | // It is easiest to find an existing definition and copy it. | 841 | // It is easiest to find an existing definition and copy it. |
871 | // Parameter values are floats. Booleans are converted to a floating value. | 842 | // Parameter values are floats. Booleans are converted to a floating value. |
872 | // | 843 | // |
873 | // A ParameterDefn() takes the following parameters: | 844 | // A ParameterDefn() takes the following parameters: |
874 | // -- the text name of the parameter. This is used for console input and ini file. | 845 | // -- the text name of the parameter. This is used for console input and ini file. |
875 | // -- a short text description of the parameter. This shows up in the console listing. | 846 | // -- a short text description of the parameter. This shows up in the console listing. |
@@ -880,6 +851,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
880 | // | 851 | // |
881 | // The single letter parameters for the delegates are: | 852 | // The single letter parameters for the delegates are: |
882 | // s = BSScene | 853 | // s = BSScene |
854 | // o = BSPhysObject | ||
883 | // p = string parameter name | 855 | // p = string parameter name |
884 | // l = localID of referenced object | 856 | // l = localID of referenced object |
885 | // v = float value | 857 | // v = float value |
@@ -888,25 +860,40 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
888 | { | 860 | { |
889 | new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties", | 861 | new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties", |
890 | ConfigurationParameters.numericTrue, | 862 | ConfigurationParameters.numericTrue, |
891 | (s,cf,p,v) => { s._meshSculptedPrim = cf.GetBoolean(p, s.BoolNumeric(v)); }, | 863 | (s,cf,p,v) => { s.ShouldMeshSculptedPrim = cf.GetBoolean(p, s.BoolNumeric(v)); }, |
892 | (s) => { return s.NumericBool(s._meshSculptedPrim); }, | 864 | (s) => { return s.NumericBool(s.ShouldMeshSculptedPrim); }, |
893 | (s,p,l,v) => { s._meshSculptedPrim = s.BoolNumeric(v); } ), | 865 | (s,p,l,v) => { s.ShouldMeshSculptedPrim = s.BoolNumeric(v); } ), |
894 | new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects", | 866 | new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects", |
895 | ConfigurationParameters.numericFalse, | 867 | ConfigurationParameters.numericFalse, |
896 | (s,cf,p,v) => { s._forceSimplePrimMeshing = cf.GetBoolean(p, s.BoolNumeric(v)); }, | 868 | (s,cf,p,v) => { s.ShouldForceSimplePrimMeshing = cf.GetBoolean(p, s.BoolNumeric(v)); }, |
897 | (s) => { return s.NumericBool(s._forceSimplePrimMeshing); }, | 869 | (s) => { return s.NumericBool(s.ShouldForceSimplePrimMeshing); }, |
898 | (s,p,l,v) => { s._forceSimplePrimMeshing = s.BoolNumeric(v); } ), | 870 | (s,p,l,v) => { s.ShouldForceSimplePrimMeshing = s.BoolNumeric(v); } ), |
871 | new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects", | ||
872 | ConfigurationParameters.numericTrue, | ||
873 | (s,cf,p,v) => { s.ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, s.BoolNumeric(v)); }, | ||
874 | (s) => { return s.NumericBool(s.ShouldUseHullsForPhysicalObjects); }, | ||
875 | (s,p,l,v) => { s.ShouldUseHullsForPhysicalObjects = s.BoolNumeric(v); } ), | ||
899 | 876 | ||
900 | new ParameterDefn("MeshLOD", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | 877 | new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", |
901 | 8f, | 878 | 8f, |
902 | (s,cf,p,v) => { s.m_meshLOD = cf.GetInt(p, (int)v); }, | 879 | (s,cf,p,v) => { s.MeshLOD = (float)cf.GetInt(p, (int)v); }, |
903 | (s) => { return (float)s.m_meshLOD; }, | 880 | (s) => { return s.MeshLOD; }, |
904 | (s,p,l,v) => { s.m_meshLOD = (int)v; } ), | 881 | (s,p,l,v) => { s.MeshLOD = v; } ), |
905 | new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | 882 | new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters", |
883 | 16f, | ||
884 | (s,cf,p,v) => { s.MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); }, | ||
885 | (s) => { return s.MeshMegaPrimLOD; }, | ||
886 | (s,p,l,v) => { s.MeshMegaPrimLOD = v; } ), | ||
887 | new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD", | ||
888 | 10f, | ||
889 | (s,cf,p,v) => { s.MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); }, | ||
890 | (s) => { return s.MeshMegaPrimThreshold; }, | ||
891 | (s,p,l,v) => { s.MeshMegaPrimThreshold = v; } ), | ||
892 | new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", | ||
906 | 32f, | 893 | 32f, |
907 | (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); }, | 894 | (s,cf,p,v) => { s.SculptLOD = (float)cf.GetInt(p, (int)v); }, |
908 | (s) => { return (float)s.m_sculptLOD; }, | 895 | (s) => { return s.SculptLOD; }, |
909 | (s,p,l,v) => { s.m_sculptLOD = (int)v; } ), | 896 | (s,p,l,v) => { s.SculptLOD = v; } ), |
910 | 897 | ||
911 | new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps", | 898 | new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps", |
912 | 10f, | 899 | 10f, |
@@ -928,11 +915,16 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
928 | (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); }, | 915 | (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); }, |
929 | (s) => { return (float)s.m_maxUpdatesPerFrame; }, | 916 | (s) => { return (float)s.m_maxUpdatesPerFrame; }, |
930 | (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ), | 917 | (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ), |
918 | new ParameterDefn("MaxTaintsToProcessPerStep", "Number of update taints to process before each simulation step", | ||
919 | 100f, | ||
920 | (s,cf,p,v) => { s.m_taintsToProcessPerStep = cf.GetInt(p, (int)v); }, | ||
921 | (s) => { return (float)s.m_taintsToProcessPerStep; }, | ||
922 | (s,p,l,v) => { s.m_taintsToProcessPerStep = (int)v; } ), | ||
931 | new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)", | 923 | new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)", |
932 | 10000.01f, | 924 | 10000.01f, |
933 | (s,cf,p,v) => { s.m_maximumObjectMass = cf.GetFloat(p, v); }, | 925 | (s,cf,p,v) => { s.MaximumObjectMass = cf.GetFloat(p, v); }, |
934 | (s) => { return (float)s.m_maximumObjectMass; }, | 926 | (s) => { return (float)s.MaximumObjectMass; }, |
935 | (s,p,l,v) => { s.m_maximumObjectMass = v; } ), | 927 | (s,p,l,v) => { s.MaximumObjectMass = v; } ), |
936 | 928 | ||
937 | new ParameterDefn("PID_D", "Derivitive factor for motion smoothing", | 929 | new ParameterDefn("PID_D", "Derivitive factor for motion smoothing", |
938 | 2200f, | 930 | 2200f, |
@@ -969,104 +961,118 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
969 | -9.80665f, | 961 | -9.80665f, |
970 | (s,cf,p,v) => { s.m_params[0].gravity = cf.GetFloat(p, v); }, | 962 | (s,cf,p,v) => { s.m_params[0].gravity = cf.GetFloat(p, v); }, |
971 | (s) => { return s.m_params[0].gravity; }, | 963 | (s) => { return s.m_params[0].gravity; }, |
972 | (s,p,l,v) => { s.m_params[0].gravity = v; s.TaintedUpdateParameter(p,l,v); } ), | 964 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].gravity, p, PhysParameterEntry.APPLY_TO_NONE, v); }, |
965 | (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ), | ||
973 | 966 | ||
974 | 967 | ||
975 | new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", | 968 | new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", |
976 | 0f, | 969 | 0f, |
977 | (s,cf,p,v) => { s.m_params[0].linearDamping = cf.GetFloat(p, v); }, | 970 | (s,cf,p,v) => { s.m_params[0].linearDamping = cf.GetFloat(p, v); }, |
978 | (s) => { return s.m_params[0].linearDamping; }, | 971 | (s) => { return s.m_params[0].linearDamping; }, |
979 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].linearDamping, p, l, v); } ), | 972 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearDamping, p, l, v); }, |
973 | (s,o,v) => { BulletSimAPI.SetDamping2(o.BSBody.ptr, v, v); } ), | ||
980 | new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", | 974 | new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", |
981 | 0f, | 975 | 0f, |
982 | (s,cf,p,v) => { s.m_params[0].angularDamping = cf.GetFloat(p, v); }, | 976 | (s,cf,p,v) => { s.m_params[0].angularDamping = cf.GetFloat(p, v); }, |
983 | (s) => { return s.m_params[0].angularDamping; }, | 977 | (s) => { return s.m_params[0].angularDamping; }, |
984 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].angularDamping, p, l, v); } ), | 978 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularDamping, p, l, v); }, |
979 | (s,o,v) => { BulletSimAPI.SetDamping2(o.BSBody.ptr, v, v); } ), | ||
985 | new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", | 980 | new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", |
986 | 0.2f, | 981 | 0.2f, |
987 | (s,cf,p,v) => { s.m_params[0].deactivationTime = cf.GetFloat(p, v); }, | 982 | (s,cf,p,v) => { s.m_params[0].deactivationTime = cf.GetFloat(p, v); }, |
988 | (s) => { return s.m_params[0].deactivationTime; }, | 983 | (s) => { return s.m_params[0].deactivationTime; }, |
989 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].deactivationTime, p, l, v); } ), | 984 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].deactivationTime, p, l, v); }, |
985 | (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.BSBody.ptr, v); } ), | ||
990 | new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", | 986 | new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", |
991 | 0.8f, | 987 | 0.8f, |
992 | (s,cf,p,v) => { s.m_params[0].linearSleepingThreshold = cf.GetFloat(p, v); }, | 988 | (s,cf,p,v) => { s.m_params[0].linearSleepingThreshold = cf.GetFloat(p, v); }, |
993 | (s) => { return s.m_params[0].linearSleepingThreshold; }, | 989 | (s) => { return s.m_params[0].linearSleepingThreshold; }, |
994 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].linearSleepingThreshold, p, l, v); } ), | 990 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearSleepingThreshold, p, l, v); }, |
991 | (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.BSBody.ptr, v, v); } ), | ||
995 | new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", | 992 | new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", |
996 | 1.0f, | 993 | 1.0f, |
997 | (s,cf,p,v) => { s.m_params[0].angularSleepingThreshold = cf.GetFloat(p, v); }, | 994 | (s,cf,p,v) => { s.m_params[0].angularSleepingThreshold = cf.GetFloat(p, v); }, |
998 | (s) => { return s.m_params[0].angularSleepingThreshold; }, | 995 | (s) => { return s.m_params[0].angularSleepingThreshold; }, |
999 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].angularSleepingThreshold, p, l, v); } ), | 996 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularSleepingThreshold, p, l, v); }, |
997 | (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.BSBody.ptr, v, v); } ), | ||
1000 | new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , | 998 | new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , |
1001 | 0f, // set to zero to disable | 999 | 0f, // set to zero to disable |
1002 | (s,cf,p,v) => { s.m_params[0].ccdMotionThreshold = cf.GetFloat(p, v); }, | 1000 | (s,cf,p,v) => { s.m_params[0].ccdMotionThreshold = cf.GetFloat(p, v); }, |
1003 | (s) => { return s.m_params[0].ccdMotionThreshold; }, | 1001 | (s) => { return s.m_params[0].ccdMotionThreshold; }, |
1004 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].ccdMotionThreshold, p, l, v); } ), | 1002 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdMotionThreshold, p, l, v); }, |
1003 | (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.BSBody.ptr, v); } ), | ||
1005 | new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , | 1004 | new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , |
1006 | 0f, | 1005 | 0f, |
1007 | (s,cf,p,v) => { s.m_params[0].ccdSweptSphereRadius = cf.GetFloat(p, v); }, | 1006 | (s,cf,p,v) => { s.m_params[0].ccdSweptSphereRadius = cf.GetFloat(p, v); }, |
1008 | (s) => { return s.m_params[0].ccdSweptSphereRadius; }, | 1007 | (s) => { return s.m_params[0].ccdSweptSphereRadius; }, |
1009 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].ccdSweptSphereRadius, p, l, v); } ), | 1008 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdSweptSphereRadius, p, l, v); }, |
1009 | (s,o,v) => { BulletSimAPI.SetCcdSweepSphereRadius2(o.BSBody.ptr, v); } ), | ||
1010 | new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , | 1010 | new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , |
1011 | 0.1f, | 1011 | 0.1f, |
1012 | (s,cf,p,v) => { s.m_params[0].contactProcessingThreshold = cf.GetFloat(p, v); }, | 1012 | (s,cf,p,v) => { s.m_params[0].contactProcessingThreshold = cf.GetFloat(p, v); }, |
1013 | (s) => { return s.m_params[0].contactProcessingThreshold; }, | 1013 | (s) => { return s.m_params[0].contactProcessingThreshold; }, |
1014 | (s,p,l,v) => { s.UpdateParameterPrims(ref s.m_params[0].contactProcessingThreshold, p, l, v); } ), | 1014 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].contactProcessingThreshold, p, l, v); }, |
1015 | (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.BSBody.ptr, v); } ), | ||
1015 | 1016 | ||
1016 | new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" , | 1017 | new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" , |
1017 | 0.5f, | 1018 | 0.5f, |
1018 | (s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); }, | 1019 | (s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); }, |
1019 | (s) => { return s.m_params[0].terrainFriction; }, | 1020 | (s) => { return s.m_params[0].terrainFriction; }, |
1020 | (s,p,l,v) => { s.m_params[0].terrainFriction = v; s.TaintedUpdateParameter(p,l,v); } ), | 1021 | (s,p,l,v) => { s.m_params[0].terrainFriction = v; /* TODO: set on real terrain */} ), |
1021 | new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" , | 1022 | new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" , |
1022 | 0.8f, | 1023 | 0.8f, |
1023 | (s,cf,p,v) => { s.m_params[0].terrainHitFraction = cf.GetFloat(p, v); }, | 1024 | (s,cf,p,v) => { s.m_params[0].terrainHitFraction = cf.GetFloat(p, v); }, |
1024 | (s) => { return s.m_params[0].terrainHitFraction; }, | 1025 | (s) => { return s.m_params[0].terrainHitFraction; }, |
1025 | (s,p,l,v) => { s.m_params[0].terrainHitFraction = v; s.TaintedUpdateParameter(p,l,v); } ), | 1026 | (s,p,l,v) => { s.m_params[0].terrainHitFraction = v; /* TODO: set on real terrain */ } ), |
1026 | new ParameterDefn("TerrainRestitution", "Bouncyness" , | 1027 | new ParameterDefn("TerrainRestitution", "Bouncyness" , |
1027 | 0f, | 1028 | 0f, |
1028 | (s,cf,p,v) => { s.m_params[0].terrainRestitution = cf.GetFloat(p, v); }, | 1029 | (s,cf,p,v) => { s.m_params[0].terrainRestitution = cf.GetFloat(p, v); }, |
1029 | (s) => { return s.m_params[0].terrainRestitution; }, | 1030 | (s) => { return s.m_params[0].terrainRestitution; }, |
1030 | (s,p,l,v) => { s.m_params[0].terrainRestitution = v; s.TaintedUpdateParameter(p,l,v); } ), | 1031 | (s,p,l,v) => { s.m_params[0].terrainRestitution = v; /* TODO: set on real terrain */ } ), |
1031 | new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", | 1032 | new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", |
1032 | 0.5f, | 1033 | 0.2f, |
1033 | (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, | 1034 | (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, |
1034 | (s) => { return s.m_params[0].avatarFriction; }, | 1035 | (s) => { return s.m_params[0].avatarFriction; }, |
1035 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarFriction, p, l, v); } ), | 1036 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarFriction, p, l, v); } ), |
1037 | new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | ||
1038 | 10f, | ||
1039 | (s,cf,p,v) => { s.m_params[0].avatarStandingFriction = cf.GetFloat(p, v); }, | ||
1040 | (s) => { return s.m_params[0].avatarStandingFriction; }, | ||
1041 | (s,p,l,v) => { s.m_params[0].avatarStandingFriction = v; } ), | ||
1036 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | 1042 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", |
1037 | 60f, | 1043 | 60f, |
1038 | (s,cf,p,v) => { s.m_params[0].avatarDensity = cf.GetFloat(p, v); }, | 1044 | (s,cf,p,v) => { s.m_params[0].avatarDensity = cf.GetFloat(p, v); }, |
1039 | (s) => { return s.m_params[0].avatarDensity; }, | 1045 | (s) => { return s.m_params[0].avatarDensity; }, |
1040 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarDensity, p, l, v); } ), | 1046 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarDensity, p, l, v); } ), |
1041 | new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | 1047 | new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", |
1042 | 0f, | 1048 | 0f, |
1043 | (s,cf,p,v) => { s.m_params[0].avatarRestitution = cf.GetFloat(p, v); }, | 1049 | (s,cf,p,v) => { s.m_params[0].avatarRestitution = cf.GetFloat(p, v); }, |
1044 | (s) => { return s.m_params[0].avatarRestitution; }, | 1050 | (s) => { return s.m_params[0].avatarRestitution; }, |
1045 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarRestitution, p, l, v); } ), | 1051 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarRestitution, p, l, v); } ), |
1046 | new ParameterDefn("AvatarCapsuleRadius", "Radius of space around an avatar", | 1052 | new ParameterDefn("AvatarCapsuleRadius", "Radius of space around an avatar", |
1047 | 0.37f, | 1053 | 0.37f, |
1048 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleRadius = cf.GetFloat(p, v); }, | 1054 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleRadius = cf.GetFloat(p, v); }, |
1049 | (s) => { return s.m_params[0].avatarCapsuleRadius; }, | 1055 | (s) => { return s.m_params[0].avatarCapsuleRadius; }, |
1050 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarCapsuleRadius, p, l, v); } ), | 1056 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarCapsuleRadius, p, l, v); } ), |
1051 | new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", | 1057 | new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", |
1052 | 1.5f, | 1058 | 1.5f, |
1053 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleHeight = cf.GetFloat(p, v); }, | 1059 | (s,cf,p,v) => { s.m_params[0].avatarCapsuleHeight = cf.GetFloat(p, v); }, |
1054 | (s) => { return s.m_params[0].avatarCapsuleHeight; }, | 1060 | (s) => { return s.m_params[0].avatarCapsuleHeight; }, |
1055 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarCapsuleHeight, p, l, v); } ), | 1061 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarCapsuleHeight, p, l, v); } ), |
1056 | new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | 1062 | new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", |
1057 | 0.1f, | 1063 | 0.1f, |
1058 | (s,cf,p,v) => { s.m_params[0].avatarContactProcessingThreshold = cf.GetFloat(p, v); }, | 1064 | (s,cf,p,v) => { s.m_params[0].avatarContactProcessingThreshold = cf.GetFloat(p, v); }, |
1059 | (s) => { return s.m_params[0].avatarContactProcessingThreshold; }, | 1065 | (s) => { return s.m_params[0].avatarContactProcessingThreshold; }, |
1060 | (s,p,l,v) => { s.UpdateParameterAvatars(ref s.m_params[0].avatarContactProcessingThreshold, p, l, v); } ), | 1066 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarContactProcessingThreshold, p, l, v); } ), |
1061 | 1067 | ||
1062 | 1068 | ||
1063 | new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", | 1069 | new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", |
1064 | 0f, // zero to disable | 1070 | 0f, |
1065 | (s,cf,p,v) => { s.m_params[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); }, | 1071 | (s,cf,p,v) => { s.m_params[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); }, |
1066 | (s) => { return s.m_params[0].maxPersistantManifoldPoolSize; }, | 1072 | (s) => { return s.m_params[0].maxPersistantManifoldPoolSize; }, |
1067 | (s,p,l,v) => { s.m_params[0].maxPersistantManifoldPoolSize = v; } ), | 1073 | (s,p,l,v) => { s.m_params[0].maxPersistantManifoldPoolSize = v; } ), |
1068 | new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", | 1074 | new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)", |
1069 | 0f, // zero to disable | 1075 | 0f, |
1070 | (s,cf,p,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); }, | 1076 | (s,cf,p,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); }, |
1071 | (s) => { return s.m_params[0].maxCollisionAlgorithmPoolSize; }, | 1077 | (s) => { return s.m_params[0].maxCollisionAlgorithmPoolSize; }, |
1072 | (s,p,l,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = v; } ), | 1078 | (s,p,l,v) => { s.m_params[0].maxCollisionAlgorithmPoolSize = v; } ), |
@@ -1081,12 +1087,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1081 | (s) => { return s.m_params[0].shouldForceUpdateAllAabbs; }, | 1087 | (s) => { return s.m_params[0].shouldForceUpdateAllAabbs; }, |
1082 | (s,p,l,v) => { s.m_params[0].shouldForceUpdateAllAabbs = v; } ), | 1088 | (s,p,l,v) => { s.m_params[0].shouldForceUpdateAllAabbs = v; } ), |
1083 | new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction", | 1089 | new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction", |
1084 | ConfigurationParameters.numericFalse, | 1090 | ConfigurationParameters.numericTrue, |
1085 | (s,cf,p,v) => { s.m_params[0].shouldRandomizeSolverOrder = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | 1091 | (s,cf,p,v) => { s.m_params[0].shouldRandomizeSolverOrder = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, |
1086 | (s) => { return s.m_params[0].shouldRandomizeSolverOrder; }, | 1092 | (s) => { return s.m_params[0].shouldRandomizeSolverOrder; }, |
1087 | (s,p,l,v) => { s.m_params[0].shouldRandomizeSolverOrder = v; } ), | 1093 | (s,p,l,v) => { s.m_params[0].shouldRandomizeSolverOrder = v; } ), |
1088 | new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", | 1094 | new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", |
1089 | ConfigurationParameters.numericFalse, | 1095 | ConfigurationParameters.numericTrue, |
1090 | (s,cf,p,v) => { s.m_params[0].shouldSplitSimulationIslands = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, | 1096 | (s,cf,p,v) => { s.m_params[0].shouldSplitSimulationIslands = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, |
1091 | (s) => { return s.m_params[0].shouldSplitSimulationIslands; }, | 1097 | (s) => { return s.m_params[0].shouldSplitSimulationIslands; }, |
1092 | (s,p,l,v) => { s.m_params[0].shouldSplitSimulationIslands = v; } ), | 1098 | (s,p,l,v) => { s.m_params[0].shouldSplitSimulationIslands = v; } ), |
@@ -1121,28 +1127,27 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1121 | (s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = cf.GetFloat(p, v); }, | 1127 | (s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = cf.GetFloat(p, v); }, |
1122 | (s) => { return s.m_params[0].linkConstraintTransMotorMaxForce; }, | 1128 | (s) => { return s.m_params[0].linkConstraintTransMotorMaxForce; }, |
1123 | (s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = v; } ), | 1129 | (s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = v; } ), |
1124 | new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=none, 1=all. Default=0", | 1130 | new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", |
1125 | 0.0f, | 1131 | 0.001f, |
1126 | (s,cf,p,v) => { s.m_params[0].linkConstraintCFM = cf.GetFloat(p, v); }, | 1132 | (s,cf,p,v) => { s.m_params[0].linkConstraintCFM = cf.GetFloat(p, v); }, |
1127 | (s) => { return s.m_params[0].linkConstraintCFM; }, | 1133 | (s) => { return s.m_params[0].linkConstraintCFM; }, |
1128 | (s,p,l,v) => { s.m_params[0].linkConstraintCFM = v; } ), | 1134 | (s,p,l,v) => { s.m_params[0].linkConstraintCFM = v; } ), |
1129 | new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", | 1135 | new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", |
1130 | 0.2f, | 1136 | 0.8f, |
1131 | (s,cf,p,v) => { s.m_params[0].linkConstraintERP = cf.GetFloat(p, v); }, | 1137 | (s,cf,p,v) => { s.m_params[0].linkConstraintERP = cf.GetFloat(p, v); }, |
1132 | (s) => { return s.m_params[0].linkConstraintERP; }, | 1138 | (s) => { return s.m_params[0].linkConstraintERP; }, |
1133 | (s,p,l,v) => { s.m_params[0].linkConstraintERP = v; } ), | 1139 | (s,p,l,v) => { s.m_params[0].linkConstraintERP = v; } ), |
1140 | new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | ||
1141 | 40, | ||
1142 | (s,cf,p,v) => { s.m_params[0].linkConstraintSolverIterations = cf.GetFloat(p, v); }, | ||
1143 | (s) => { return s.m_params[0].linkConstraintSolverIterations; }, | ||
1144 | (s,p,l,v) => { s.m_params[0].linkConstraintSolverIterations = v; } ), | ||
1134 | 1145 | ||
1135 | new ParameterDefn("DetailedStats", "Frames between outputting detailed phys stats. (0 is off)", | 1146 | new ParameterDefn("LogPhysicsStatisticsFrames", "Frames between outputting detailed phys stats. (0 is off)", |
1136 | 0f, | 1147 | 0f, |
1137 | (s,cf,p,v) => { s.m_detailedStatsStep = cf.GetInt(p, (int)v); }, | 1148 | (s,cf,p,v) => { s.m_params[0].physicsLoggingFrames = cf.GetInt(p, (int)v); }, |
1138 | (s) => { return (float)s.m_detailedStatsStep; }, | 1149 | (s) => { return (float)s.m_params[0].physicsLoggingFrames; }, |
1139 | (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ), | 1150 | (s,p,l,v) => { s.m_params[0].physicsLoggingFrames = (int)v; } ), |
1140 | new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements", | ||
1141 | ConfigurationParameters.numericFalse, | ||
1142 | (s,cf,p,v) => { s.ShouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, | ||
1143 | (s) => { return s.NumericBool(s.ShouldDebugLog); }, | ||
1144 | (s,p,l,v) => { s.ShouldDebugLog = s.BoolNumeric(v); } ), | ||
1145 | |||
1146 | }; | 1151 | }; |
1147 | 1152 | ||
1148 | // Convert a boolean to our numeric true and false values | 1153 | // Convert a boolean to our numeric true and false values |
@@ -1200,11 +1205,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1200 | 1205 | ||
1201 | private PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1]; | 1206 | private PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1]; |
1202 | 1207 | ||
1208 | // This creates an array in the correct format for returning the list of | ||
1209 | // parameters. This is used by the 'list' option of the 'physics' command. | ||
1203 | private void BuildParameterTable() | 1210 | private void BuildParameterTable() |
1204 | { | 1211 | { |
1205 | if (SettableParameters.Length < ParameterDefinitions.Length) | 1212 | if (SettableParameters.Length < ParameterDefinitions.Length) |
1206 | { | 1213 | { |
1207 | |||
1208 | List<PhysParameterEntry> entries = new List<PhysParameterEntry>(); | 1214 | List<PhysParameterEntry> entries = new List<PhysParameterEntry>(); |
1209 | for (int ii = 0; ii < ParameterDefinitions.Length; ii++) | 1215 | for (int ii = 0; ii < ParameterDefinitions.Length; ii++) |
1210 | { | 1216 | { |
@@ -1249,60 +1255,54 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1249 | return ret; | 1255 | return ret; |
1250 | } | 1256 | } |
1251 | 1257 | ||
1252 | // check to see if we are updating a parameter for a particular or all of the prims | ||
1253 | protected void UpdateParameterPrims(ref float loc, string parm, uint localID, float val) | ||
1254 | { | ||
1255 | List<uint> operateOn; | ||
1256 | lock (m_prims) operateOn = new List<uint>(m_prims.Keys); | ||
1257 | UpdateParameterSet(operateOn, ref loc, parm, localID, val); | ||
1258 | } | ||
1259 | |||
1260 | // check to see if we are updating a parameter for a particular or all of the avatars | ||
1261 | protected void UpdateParameterAvatars(ref float loc, string parm, uint localID, float val) | ||
1262 | { | ||
1263 | List<uint> operateOn; | ||
1264 | lock (m_avatars) operateOn = new List<uint>(m_avatars.Keys); | ||
1265 | UpdateParameterSet(operateOn, ref loc, parm, localID, val); | ||
1266 | } | ||
1267 | |||
1268 | // update all the localIDs specified | 1258 | // update all the localIDs specified |
1269 | // If the local ID is APPLY_TO_NONE, just change the default value | 1259 | // If the local ID is APPLY_TO_NONE, just change the default value |
1270 | // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs | 1260 | // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs |
1271 | // If the localID is a specific object, apply the parameter change to only that object | 1261 | // If the localID is a specific object, apply the parameter change to only that object |
1272 | protected void UpdateParameterSet(List<uint> lIDs, ref float defaultLoc, string parm, uint localID, float val) | 1262 | protected void UpdateParameterObject(ref float defaultLoc, string parm, uint localID, float val) |
1273 | { | 1263 | { |
1264 | List<uint> objectIDs = new List<uint>(); | ||
1274 | switch (localID) | 1265 | switch (localID) |
1275 | { | 1266 | { |
1276 | case PhysParameterEntry.APPLY_TO_NONE: | 1267 | case PhysParameterEntry.APPLY_TO_NONE: |
1277 | defaultLoc = val; // setting only the default value | 1268 | defaultLoc = val; // setting only the default value |
1269 | // This will cause a call into the physical world if some operation is specified (SetOnObject). | ||
1270 | objectIDs.Add(TERRAIN_ID); | ||
1271 | TaintedUpdateParameter(parm, objectIDs, val); | ||
1278 | break; | 1272 | break; |
1279 | case PhysParameterEntry.APPLY_TO_ALL: | 1273 | case PhysParameterEntry.APPLY_TO_ALL: |
1280 | defaultLoc = val; // setting ALL also sets the default value | 1274 | defaultLoc = val; // setting ALL also sets the default value |
1281 | List<uint> objectIDs = lIDs; | 1275 | lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys); |
1282 | string xparm = parm.ToLower(); | 1276 | TaintedUpdateParameter(parm, objectIDs, val); |
1283 | float xval = val; | ||
1284 | TaintedObject("BSScene.UpdateParameterSet", delegate() { | ||
1285 | foreach (uint lID in objectIDs) | ||
1286 | { | ||
1287 | BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval); | ||
1288 | } | ||
1289 | }); | ||
1290 | break; | 1277 | break; |
1291 | default: | 1278 | default: |
1292 | // setting only one localID | 1279 | // setting only one localID |
1293 | TaintedUpdateParameter(parm, localID, val); | 1280 | objectIDs.Add(localID); |
1281 | TaintedUpdateParameter(parm, objectIDs, val); | ||
1294 | break; | 1282 | break; |
1295 | } | 1283 | } |
1296 | } | 1284 | } |
1297 | 1285 | ||
1298 | // schedule the actual updating of the paramter to when the phys engine is not busy | 1286 | // schedule the actual updating of the paramter to when the phys engine is not busy |
1299 | protected void TaintedUpdateParameter(string parm, uint localID, float val) | 1287 | protected void TaintedUpdateParameter(string parm, List<uint> lIDs, float val) |
1300 | { | 1288 | { |
1301 | uint xlocalID = localID; | ||
1302 | string xparm = parm.ToLower(); | ||
1303 | float xval = val; | 1289 | float xval = val; |
1304 | TaintedObject("BSScene.TaintedUpdateParameter", delegate() { | 1290 | List<uint> xlIDs = lIDs; |
1305 | BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval); | 1291 | string xparm = parm; |
1292 | TaintedObject("BSScene.UpdateParameterSet", delegate() { | ||
1293 | ParameterDefn thisParam; | ||
1294 | if (TryGetParameter(xparm, out thisParam)) | ||
1295 | { | ||
1296 | if (thisParam.onObject != null) | ||
1297 | { | ||
1298 | foreach (uint lID in xlIDs) | ||
1299 | { | ||
1300 | BSPhysObject theObject = null; | ||
1301 | PhysObjects.TryGetValue(lID, out theObject); | ||
1302 | thisParam.onObject(this, theObject, xval); | ||
1303 | } | ||
1304 | } | ||
1305 | } | ||
1306 | }); | 1306 | }); |
1307 | } | 1307 | } |
1308 | 1308 | ||
@@ -1330,8 +1330,10 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1330 | public void DetailLog(string msg, params Object[] args) | 1330 | public void DetailLog(string msg, params Object[] args) |
1331 | { | 1331 | { |
1332 | PhysicsLogging.Write(msg, args); | 1332 | PhysicsLogging.Write(msg, args); |
1333 | // Add the Flush() if debugging crashes to get all the messages written out. | ||
1334 | // PhysicsLogging.Flush(); | ||
1333 | } | 1335 | } |
1334 | // used to fill in the LocalID when there isn't one | 1336 | // Used to fill in the LocalID when there isn't one. It's the correct number of characters. |
1335 | public const string DetailLogZero = "0000000000"; | 1337 | public const string DetailLogZero = "0000000000"; |
1336 | 1338 | ||
1337 | } | 1339 | } |