aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSParam.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSParam.cs634
1 files changed, 634 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
new file mode 100755
index 0000000..3e80aa4
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -0,0 +1,634 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31using OpenSim.Region.Physics.Manager;
32
33using OpenMetaverse;
34using Nini.Config;
35
36namespace OpenSim.Region.Physics.BulletSPlugin
37{
38public static class BSParam
39{
40 // Level of Detail values kept as float because that's what the Meshmerizer wants
41 public static float MeshLOD { get; private set; }
42 public static float MeshMegaPrimLOD { get; private set; }
43 public static float MeshMegaPrimThreshold { get; private set; }
44 public static float SculptLOD { get; private set; }
45
46 public static float MinimumObjectMass { get; private set; }
47 public static float MaximumObjectMass { get; private set; }
48
49 public static float LinearDamping { get; private set; }
50 public static float AngularDamping { get; private set; }
51 public static float DeactivationTime { get; private set; }
52 public static float LinearSleepingThreshold { get; private set; }
53 public static float AngularSleepingThreshold { get; private set; }
54 public static float CcdMotionThreshold { get; private set; }
55 public static float CcdSweptSphereRadius { get; private set; }
56 public static float ContactProcessingThreshold { get; private set; }
57
58 public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed
59 public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
60 public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
61
62 public static float TerrainImplementation { get; private set; }
63 public static float TerrainFriction { get; private set; }
64 public static float TerrainHitFraction { get; private set; }
65 public static float TerrainRestitution { get; private set; }
66 public static float TerrainCollisionMargin { get; private set; }
67
68 // Avatar parameters
69 public static float AvatarFriction { get; private set; }
70 public static float AvatarStandingFriction { get; private set; }
71 public static float AvatarAlwaysRunFactor { get; private set; }
72 public static float AvatarDensity { get; private set; }
73 public static float AvatarRestitution { get; private set; }
74 public static float AvatarCapsuleWidth { get; private set; }
75 public static float AvatarCapsuleDepth { get; private set; }
76 public static float AvatarCapsuleHeight { get; private set; }
77 public static float AvatarContactProcessingThreshold { get; private set; }
78 public static float AvatarStepHeight { get; private set; }
79 public static float AvatarStepApproachFactor { get; private set; }
80 public static float AvatarStepForceFactor { get; private set; }
81
82 public static float VehicleAngularDamping { get; private set; }
83 public static float VehicleDebuggingEnabled { get; private set; }
84
85 public static float LinksetImplementation { get; private set; }
86 public static float LinkConstraintUseFrameOffset { get; private set; }
87 public static float LinkConstraintEnableTransMotor { get; private set; }
88 public static float LinkConstraintTransMotorMaxVel { get; private set; }
89 public static float LinkConstraintTransMotorMaxForce { get; private set; }
90 public static float LinkConstraintERP { get; private set; }
91 public static float LinkConstraintCFM { get; private set; }
92 public static float LinkConstraintSolverIterations { get; private set; }
93
94 public static float PID_D { get; private set; } // derivative
95 public static float PID_P { get; private set; } // proportional
96
97 // Various constants that come from that other virtual world that shall not be named.
98 public const float MinGravityZ = -1f;
99 public const float MaxGravityZ = 28f;
100 public const float MinFriction = 0f;
101 public const float MaxFriction = 255f;
102 public const float MinDensity = 0.01f;
103 public const float MaxDensity = 22587f;
104 public const float MinRestitution = 0f;
105 public const float MaxRestitution = 1f;
106 public const float MaxAddForceMagnitude = 20f;
107
108 // ===========================================================================
109 public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val);
110 public delegate float ParamGet(BSScene scene);
111 public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val);
112 public delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val);
113
114 public struct ParameterDefn
115 {
116 public string name; // string name of the parameter
117 public string desc; // a short description of what the parameter means
118 public float defaultValue; // default value if not specified anywhere else
119 public ParamUser userParam; // get the value from the configuration file
120 public ParamGet getter; // return the current value stored for this parameter
121 public ParamSet setter; // set the current value for this parameter
122 public SetOnObject onObject; // set the value on an object in the physical domain
123 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s)
124 {
125 name = n;
126 desc = d;
127 defaultValue = v;
128 userParam = u;
129 getter = g;
130 setter = s;
131 onObject = null;
132 }
133 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o)
134 {
135 name = n;
136 desc = d;
137 defaultValue = v;
138 userParam = u;
139 getter = g;
140 setter = s;
141 onObject = o;
142 }
143 }
144
145 // List of all of the externally visible parameters.
146 // For each parameter, this table maps a text name to getter and setters.
147 // To add a new externally referencable/settable parameter, add the paramter storage
148 // location somewhere in the program and make an entry in this table with the
149 // getters and setters.
150 // It is easiest to find an existing definition and copy it.
151 // Parameter values are floats. Booleans are converted to a floating value.
152 //
153 // A ParameterDefn() takes the following parameters:
154 // -- the text name of the parameter. This is used for console input and ini file.
155 // -- a short text description of the parameter. This shows up in the console listing.
156 // -- a default value (float)
157 // -- a delegate for fetching the parameter from the ini file.
158 // Should handle fetching the right type from the ini file and converting it.
159 // -- a delegate for getting the value as a float
160 // -- a delegate for setting the value from a float
161 // -- an optional delegate to update the value in the world. Most often used to
162 // push the new value to an in-world object.
163 //
164 // The single letter parameters for the delegates are:
165 // s = BSScene
166 // o = BSPhysObject
167 // p = string parameter name
168 // l = localID of referenced object
169 // v = value (float)
170 // cf = parameter configuration class (for fetching values from ini file)
171 private static ParameterDefn[] ParameterDefinitions =
172 {
173 new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties",
174 ConfigurationParameters.numericTrue,
175 (s,cf,p,v) => { ShouldMeshSculptedPrim = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
176 (s) => { return BSParam.NumericBool(ShouldMeshSculptedPrim); },
177 (s,p,l,v) => { ShouldMeshSculptedPrim = BSParam.BoolNumeric(v); } ),
178 new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects",
179 ConfigurationParameters.numericFalse,
180 (s,cf,p,v) => { ShouldForceSimplePrimMeshing = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
181 (s) => { return BSParam.NumericBool(ShouldForceSimplePrimMeshing); },
182 (s,p,l,v) => { ShouldForceSimplePrimMeshing = BSParam.BoolNumeric(v); } ),
183 new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects",
184 ConfigurationParameters.numericTrue,
185 (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
186 (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); },
187 (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ),
188
189 new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)",
190 8f,
191 (s,cf,p,v) => { MeshLOD = (float)cf.GetInt(p, (int)v); },
192 (s) => { return MeshLOD; },
193 (s,p,l,v) => { MeshLOD = v; } ),
194 new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters",
195 16f,
196 (s,cf,p,v) => { MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); },
197 (s) => { return MeshMegaPrimLOD; },
198 (s,p,l,v) => { MeshMegaPrimLOD = v; } ),
199 new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD",
200 10f,
201 (s,cf,p,v) => { MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); },
202 (s) => { return MeshMegaPrimThreshold; },
203 (s,p,l,v) => { MeshMegaPrimThreshold = v; } ),
204 new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)",
205 32f,
206 (s,cf,p,v) => { SculptLOD = (float)cf.GetInt(p, (int)v); },
207 (s) => { return SculptLOD; },
208 (s,p,l,v) => { SculptLOD = v; } ),
209
210 new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps",
211 10f,
212 (s,cf,p,v) => { s.m_maxSubSteps = cf.GetInt(p, (int)v); },
213 (s) => { return (float)s.m_maxSubSteps; },
214 (s,p,l,v) => { s.m_maxSubSteps = (int)v; } ),
215 new ParameterDefn("FixedTimeStep", "In simulation step, seconds of one substep (1/60)",
216 1f / 60f,
217 (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); },
218 (s) => { return (float)s.m_fixedTimeStep; },
219 (s,p,l,v) => { s.m_fixedTimeStep = v; } ),
220 new ParameterDefn("NominalFrameRate", "The base frame rate we claim",
221 55f,
222 (s,cf,p,v) => { s.NominalFrameRate = cf.GetInt(p, (int)v); },
223 (s) => { return (float)s.NominalFrameRate; },
224 (s,p,l,v) => { s.NominalFrameRate = (int)v; } ),
225 new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame",
226 2048f,
227 (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); },
228 (s) => { return (float)s.m_maxCollisionsPerFrame; },
229 (s,p,l,v) => { s.m_maxCollisionsPerFrame = (int)v; } ),
230 new ParameterDefn("MaxUpdatesPerFrame", "Max updates returned at end of each frame",
231 8000f,
232 (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); },
233 (s) => { return (float)s.m_maxUpdatesPerFrame; },
234 (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ),
235 new ParameterDefn("MaxTaintsToProcessPerStep", "Number of update taints to process before each simulation step",
236 500f,
237 (s,cf,p,v) => { s.m_taintsToProcessPerStep = cf.GetInt(p, (int)v); },
238 (s) => { return (float)s.m_taintsToProcessPerStep; },
239 (s,p,l,v) => { s.m_taintsToProcessPerStep = (int)v; } ),
240 new ParameterDefn("MinObjectMass", "Minimum object mass (0.0001)",
241 0.0001f,
242 (s,cf,p,v) => { MinimumObjectMass = cf.GetFloat(p, v); },
243 (s) => { return (float)MinimumObjectMass; },
244 (s,p,l,v) => { MinimumObjectMass = v; } ),
245 new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)",
246 10000.01f,
247 (s,cf,p,v) => { MaximumObjectMass = cf.GetFloat(p, v); },
248 (s) => { return (float)MaximumObjectMass; },
249 (s,p,l,v) => { MaximumObjectMass = v; } ),
250
251 new ParameterDefn("PID_D", "Derivitive factor for motion smoothing",
252 2200f,
253 (s,cf,p,v) => { PID_D = cf.GetFloat(p, v); },
254 (s) => { return (float)PID_D; },
255 (s,p,l,v) => { PID_D = v; } ),
256 new ParameterDefn("PID_P", "Parameteric factor for motion smoothing",
257 900f,
258 (s,cf,p,v) => { PID_P = cf.GetFloat(p, v); },
259 (s) => { return (float)PID_P; },
260 (s,p,l,v) => { PID_P = v; } ),
261
262 new ParameterDefn("DefaultFriction", "Friction factor used on new objects",
263 0.2f,
264 (s,cf,p,v) => { s.UnmanagedParams[0].defaultFriction = cf.GetFloat(p, v); },
265 (s) => { return s.UnmanagedParams[0].defaultFriction; },
266 (s,p,l,v) => { s.UnmanagedParams[0].defaultFriction = v; } ),
267 new ParameterDefn("DefaultDensity", "Density for new objects" ,
268 10.000006836f, // Aluminum g/cm3
269 (s,cf,p,v) => { s.UnmanagedParams[0].defaultDensity = cf.GetFloat(p, v); },
270 (s) => { return s.UnmanagedParams[0].defaultDensity; },
271 (s,p,l,v) => { s.UnmanagedParams[0].defaultDensity = v; } ),
272 new ParameterDefn("DefaultRestitution", "Bouncyness of an object" ,
273 0f,
274 (s,cf,p,v) => { s.UnmanagedParams[0].defaultRestitution = cf.GetFloat(p, v); },
275 (s) => { return s.UnmanagedParams[0].defaultRestitution; },
276 (s,p,l,v) => { s.UnmanagedParams[0].defaultRestitution = v; } ),
277 new ParameterDefn("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)",
278 0.04f,
279 (s,cf,p,v) => { s.UnmanagedParams[0].collisionMargin = cf.GetFloat(p, v); },
280 (s) => { return s.UnmanagedParams[0].collisionMargin; },
281 (s,p,l,v) => { s.UnmanagedParams[0].collisionMargin = v; } ),
282 new ParameterDefn("Gravity", "Vertical force of gravity (negative means down)",
283 -9.80665f,
284 (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); },
285 (s) => { return s.UnmanagedParams[0].gravity; },
286 (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); },
287 (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ),
288
289
290 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
291 0f,
292 (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); },
293 (s) => { return LinearDamping; },
294 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); },
295 (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ),
296 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
297 0f,
298 (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); },
299 (s) => { return AngularDamping; },
300 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); },
301 (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ),
302 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
303 0.2f,
304 (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
305 (s) => { return DeactivationTime; },
306 (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); },
307 (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ),
308 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
309 0.8f,
310 (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
311 (s) => { return LinearSleepingThreshold; },
312 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); },
313 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
314 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
315 1.0f,
316 (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); },
317 (s) => { return AngularSleepingThreshold; },
318 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); },
319 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
320 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
321 0.3f, // set to zero to disable
322 (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
323 (s) => { return CcdMotionThreshold; },
324 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); },
325 (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ),
326 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
327 0.2f,
328 (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); },
329 (s) => { return CcdSweptSphereRadius; },
330 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); },
331 (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ),
332 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
333 0.1f,
334 (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); },
335 (s) => { return ContactProcessingThreshold; },
336 (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); },
337 (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ),
338
339 new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
340 (float)BSTerrainPhys.TerrainImplementation.Mesh,
341 (s,cf,p,v) => { TerrainImplementation = cf.GetFloat(p,v); },
342 (s) => { return TerrainImplementation; },
343 (s,p,l,v) => { TerrainImplementation = v; } ),
344 new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" ,
345 0.3f,
346 (s,cf,p,v) => { TerrainFriction = cf.GetFloat(p, v); },
347 (s) => { return TerrainFriction; },
348 (s,p,l,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ),
349 new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" ,
350 0.8f,
351 (s,cf,p,v) => { TerrainHitFraction = cf.GetFloat(p, v); },
352 (s) => { return TerrainHitFraction; },
353 (s,p,l,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ),
354 new ParameterDefn("TerrainRestitution", "Bouncyness" ,
355 0f,
356 (s,cf,p,v) => { TerrainRestitution = cf.GetFloat(p, v); },
357 (s) => { return TerrainRestitution; },
358 (s,p,l,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ),
359 new ParameterDefn("TerrainCollisionMargin", "Margin where collision checking starts" ,
360 0.04f,
361 (s,cf,p,v) => { TerrainCollisionMargin = cf.GetFloat(p, v); },
362 (s) => { return TerrainCollisionMargin; },
363 (s,p,l,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ),
364
365 new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.",
366 0.2f,
367 (s,cf,p,v) => { AvatarFriction = cf.GetFloat(p, v); },
368 (s) => { return AvatarFriction; },
369 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarFriction=x;}, p, l, v); } ),
370 new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.",
371 10.0f,
372 (s,cf,p,v) => { AvatarStandingFriction = cf.GetFloat(p, v); },
373 (s) => { return AvatarStandingFriction; },
374 (s,p,l,v) => { AvatarStandingFriction = v; } ),
375 new ParameterDefn("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run",
376 1.3f,
377 (s,cf,p,v) => { AvatarAlwaysRunFactor = cf.GetFloat(p, v); },
378 (s) => { return AvatarAlwaysRunFactor; },
379 (s,p,l,v) => { AvatarAlwaysRunFactor = v; } ),
380 new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.",
381 3.5f,
382 (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); },
383 (s) => { return AvatarDensity; },
384 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ),
385 new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.",
386 0f,
387 (s,cf,p,v) => { AvatarRestitution = cf.GetFloat(p, v); },
388 (s) => { return AvatarRestitution; },
389 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarRestitution=x;}, p, l, v); } ),
390 new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule",
391 0.6f,
392 (s,cf,p,v) => { AvatarCapsuleWidth = cf.GetFloat(p, v); },
393 (s) => { return AvatarCapsuleWidth; },
394 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleWidth=x;}, p, l, v); } ),
395 new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule",
396 0.45f,
397 (s,cf,p,v) => { AvatarCapsuleDepth = cf.GetFloat(p, v); },
398 (s) => { return AvatarCapsuleDepth; },
399 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleDepth=x;}, p, l, v); } ),
400 new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar",
401 1.5f,
402 (s,cf,p,v) => { AvatarCapsuleHeight = cf.GetFloat(p, v); },
403 (s) => { return AvatarCapsuleHeight; },
404 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleHeight=x;}, p, l, v); } ),
405 new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions",
406 0.1f,
407 (s,cf,p,v) => { AvatarContactProcessingThreshold = cf.GetFloat(p, v); },
408 (s) => { return AvatarContactProcessingThreshold; },
409 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarContactProcessingThreshold=x;}, p, l, v); } ),
410 new ParameterDefn("AvatarStepHeight", "Height of a step obstacle to consider step correction",
411 0.3f,
412 (s,cf,p,v) => { AvatarStepHeight = cf.GetFloat(p, v); },
413 (s) => { return AvatarStepHeight; },
414 (s,p,l,v) => { AvatarStepHeight = v; } ),
415 new ParameterDefn("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)",
416 0.6f,
417 (s,cf,p,v) => { AvatarStepApproachFactor = cf.GetFloat(p, v); },
418 (s) => { return AvatarStepApproachFactor; },
419 (s,p,l,v) => { AvatarStepApproachFactor = v; } ),
420 new ParameterDefn("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step",
421 2.0f,
422 (s,cf,p,v) => { AvatarStepForceFactor = cf.GetFloat(p, v); },
423 (s) => { return AvatarStepForceFactor; },
424 (s,p,l,v) => { AvatarStepForceFactor = v; } ),
425
426 new ParameterDefn("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)",
427 0.95f,
428 (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); },
429 (s) => { return VehicleAngularDamping; },
430 (s,p,l,v) => { VehicleAngularDamping = v; } ),
431 new ParameterDefn("VehicleDebuggingEnable", "Turn on/off vehicle debugging",
432 ConfigurationParameters.numericFalse,
433 (s,cf,p,v) => { VehicleDebuggingEnabled = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
434 (s) => { return VehicleDebuggingEnabled; },
435 (s,p,l,v) => { VehicleDebuggingEnabled = v; } ),
436
437 new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)",
438 0f,
439 (s,cf,p,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); },
440 (s) => { return s.UnmanagedParams[0].maxPersistantManifoldPoolSize; },
441 (s,p,l,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ),
442 new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)",
443 0f,
444 (s,cf,p,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); },
445 (s) => { return s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize; },
446 (s,p,l,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ),
447 new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count",
448 ConfigurationParameters.numericFalse,
449 (s,cf,p,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
450 (s) => { return s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation; },
451 (s,p,l,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = v; } ),
452 new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step",
453 ConfigurationParameters.numericFalse,
454 (s,cf,p,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
455 (s) => { return s.UnmanagedParams[0].shouldForceUpdateAllAabbs; },
456 (s,p,l,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = v; } ),
457 new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction",
458 ConfigurationParameters.numericTrue,
459 (s,cf,p,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
460 (s) => { return s.UnmanagedParams[0].shouldRandomizeSolverOrder; },
461 (s,p,l,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = v; } ),
462 new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands",
463 ConfigurationParameters.numericTrue,
464 (s,cf,p,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
465 (s) => { return s.UnmanagedParams[0].shouldSplitSimulationIslands; },
466 (s,p,l,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = v; } ),
467 new ParameterDefn("ShouldEnableFrictionCaching", "Enable friction computation caching",
468 ConfigurationParameters.numericTrue,
469 (s,cf,p,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
470 (s) => { return s.UnmanagedParams[0].shouldEnableFrictionCaching; },
471 (s,p,l,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = v; } ),
472 new ParameterDefn("NumberOfSolverIterations", "Number of internal iterations (0 means default)",
473 0f, // zero says use Bullet default
474 (s,cf,p,v) => { s.UnmanagedParams[0].numberOfSolverIterations = cf.GetFloat(p, v); },
475 (s) => { return s.UnmanagedParams[0].numberOfSolverIterations; },
476 (s,p,l,v) => { s.UnmanagedParams[0].numberOfSolverIterations = v; } ),
477
478 new ParameterDefn("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)",
479 (float)BSLinkset.LinksetImplementation.Compound,
480 (s,cf,p,v) => { LinksetImplementation = cf.GetFloat(p,v); },
481 (s) => { return LinksetImplementation; },
482 (s,p,l,v) => { LinksetImplementation = v; } ),
483 new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.",
484 ConfigurationParameters.numericFalse,
485 (s,cf,p,v) => { LinkConstraintUseFrameOffset = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
486 (s) => { return LinkConstraintUseFrameOffset; },
487 (s,p,l,v) => { LinkConstraintUseFrameOffset = v; } ),
488 new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints",
489 ConfigurationParameters.numericTrue,
490 (s,cf,p,v) => { LinkConstraintEnableTransMotor = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
491 (s) => { return LinkConstraintEnableTransMotor; },
492 (s,p,l,v) => { LinkConstraintEnableTransMotor = v; } ),
493 new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints",
494 5.0f,
495 (s,cf,p,v) => { LinkConstraintTransMotorMaxVel = cf.GetFloat(p, v); },
496 (s) => { return LinkConstraintTransMotorMaxVel; },
497 (s,p,l,v) => { LinkConstraintTransMotorMaxVel = v; } ),
498 new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints",
499 0.1f,
500 (s,cf,p,v) => { LinkConstraintTransMotorMaxForce = cf.GetFloat(p, v); },
501 (s) => { return LinkConstraintTransMotorMaxForce; },
502 (s,p,l,v) => { LinkConstraintTransMotorMaxForce = v; } ),
503 new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1",
504 0.1f,
505 (s,cf,p,v) => { LinkConstraintCFM = cf.GetFloat(p, v); },
506 (s) => { return LinkConstraintCFM; },
507 (s,p,l,v) => { LinkConstraintCFM = v; } ),
508 new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2",
509 0.1f,
510 (s,cf,p,v) => { LinkConstraintERP = cf.GetFloat(p, v); },
511 (s) => { return LinkConstraintERP; },
512 (s,p,l,v) => { LinkConstraintERP = v; } ),
513 new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)",
514 40,
515 (s,cf,p,v) => { LinkConstraintSolverIterations = cf.GetFloat(p, v); },
516 (s) => { return LinkConstraintSolverIterations; },
517 (s,p,l,v) => { LinkConstraintSolverIterations = v; } ),
518
519 new ParameterDefn("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)",
520 0f,
521 (s,cf,p,v) => { s.PhysicsMetricDumpFrames = cf.GetFloat(p, (int)v); },
522 (s) => { return (float)s.PhysicsMetricDumpFrames; },
523 (s,p,l,v) => { s.PhysicsMetricDumpFrames = (int)v; } ),
524 new ParameterDefn("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool",
525 0f,
526 (s,cf,p,v) => { ; },
527 (s) => { return 0f; },
528 (s,p,l,v) => { BSParam.ResetBroadphasePoolTainted(s, v); } ),
529 new ParameterDefn("ResetConstraintSolver", "Setting this is any value resets the constraint solver",
530 0f,
531 (s,cf,p,v) => { ; },
532 (s) => { return 0f; },
533 (s,p,l,v) => { BSParam.ResetConstraintSolverTainted(s, v); } ),
534 };
535
536 // Convert a boolean to our numeric true and false values
537 public static float NumericBool(bool b)
538 {
539 return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse);
540 }
541
542 // Convert numeric true and false values to a boolean
543 public static bool BoolNumeric(float b)
544 {
545 return (b == ConfigurationParameters.numericTrue ? true : false);
546 }
547
548 private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v)
549 {
550 BSScene physScene = pPhysScene;
551 physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate()
552 {
553 physScene.PE.ResetBroadphasePool(physScene.World);
554 });
555 }
556
557 private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v)
558 {
559 BSScene physScene = pPhysScene;
560 physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate()
561 {
562 physScene.PE.ResetConstraintSolver(physScene.World);
563 });
564 }
565
566 // Search through the parameter definitions and return the matching
567 // ParameterDefn structure.
568 // Case does not matter as names are compared after converting to lower case.
569 // Returns 'false' if the parameter is not found.
570 internal static bool TryGetParameter(string paramName, out ParameterDefn defn)
571 {
572 bool ret = false;
573 ParameterDefn foundDefn = new ParameterDefn();
574 string pName = paramName.ToLower();
575
576 foreach (ParameterDefn parm in ParameterDefinitions)
577 {
578 if (pName == parm.name.ToLower())
579 {
580 foundDefn = parm;
581 ret = true;
582 break;
583 }
584 }
585 defn = foundDefn;
586 return ret;
587 }
588
589 // Pass through the settable parameters and set the default values
590 internal static void SetParameterDefaultValues(BSScene physicsScene)
591 {
592 foreach (ParameterDefn parm in ParameterDefinitions)
593 {
594 parm.setter(physicsScene, parm.name, PhysParameterEntry.APPLY_TO_NONE, parm.defaultValue);
595 }
596 }
597
598 // Get user set values out of the ini file.
599 internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg)
600 {
601 foreach (ParameterDefn parm in ParameterDefinitions)
602 {
603 parm.userParam(physicsScene, cfg, parm.name, parm.defaultValue);
604 }
605 }
606
607 internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1];
608
609 // This creates an array in the correct format for returning the list of
610 // parameters. This is used by the 'list' option of the 'physics' command.
611 internal static void BuildParameterTable()
612 {
613 if (SettableParameters.Length < ParameterDefinitions.Length)
614 {
615 List<PhysParameterEntry> entries = new List<PhysParameterEntry>();
616 for (int ii = 0; ii < ParameterDefinitions.Length; ii++)
617 {
618 ParameterDefn pd = ParameterDefinitions[ii];
619 entries.Add(new PhysParameterEntry(pd.name, pd.desc));
620 }
621
622 // make the list in alphabetical order for estetic reasons
623 entries.Sort(delegate(PhysParameterEntry ppe1, PhysParameterEntry ppe2)
624 {
625 return ppe1.name.CompareTo(ppe2.name);
626 });
627
628 SettableParameters = entries.ToArray();
629 }
630 }
631
632
633}
634}