aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs52
1 files changed, 27 insertions, 25 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 1e3e5d8..e35311f 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -52,7 +52,7 @@ public abstract class BSLinkset
52 Manual = 2 // linkset tied together manually (code moves all the pieces) 52 Manual = 2 // linkset tied together manually (code moves all the pieces)
53 } 53 }
54 // Create the correct type of linkset for this child 54 // Create the correct type of linkset for this child
55 public static BSLinkset Factory(BSScene physScene, BSPhysObject parent) 55 public static BSLinkset Factory(BSScene physScene, BSPrimLinkable parent)
56 { 56 {
57 BSLinkset ret = null; 57 BSLinkset ret = null;
58 58
@@ -71,10 +71,14 @@ public abstract class BSLinkset
71 ret = new BSLinksetCompound(physScene, parent); 71 ret = new BSLinksetCompound(physScene, parent);
72 break; 72 break;
73 } 73 }
74 if (ret == null)
75 {
76 physScene.Logger.ErrorFormat("[BULLETSIM LINKSET] Factory could not create linkset. Parent name={1}, ID={2}", parent.Name, parent.LocalID);
77 }
74 return ret; 78 return ret;
75 } 79 }
76 80
77 public BSPhysObject LinksetRoot { get; protected set; } 81 public BSPrimLinkable LinksetRoot { get; protected set; }
78 82
79 public BSScene PhysicsScene { get; private set; } 83 public BSScene PhysicsScene { get; private set; }
80 84
@@ -82,7 +86,7 @@ public abstract class BSLinkset
82 public int LinksetID { get; private set; } 86 public int LinksetID { get; private set; }
83 87
84 // The children under the root in this linkset. 88 // The children under the root in this linkset.
85 protected HashSet<BSPhysObject> m_children; 89 protected HashSet<BSPrimLinkable> m_children;
86 90
87 // We lock the diddling of linkset classes to prevent any badness. 91 // We lock the diddling of linkset classes to prevent any badness.
88 // This locks the modification of the instances of this class. Changes 92 // This locks the modification of the instances of this class. Changes
@@ -91,7 +95,7 @@ public abstract class BSLinkset
91 95
92 // Some linksets have a preferred physical shape. 96 // Some linksets have a preferred physical shape.
93 // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected. 97 // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected.
94 public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor) 98 public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
95 { 99 {
96 return BSPhysicsShapeType.SHAPE_UNKNOWN; 100 return BSPhysicsShapeType.SHAPE_UNKNOWN;
97 } 101 }
@@ -111,7 +115,7 @@ public abstract class BSLinkset
111 get { return ComputeLinksetGeometricCenter(); } 115 get { return ComputeLinksetGeometricCenter(); }
112 } 116 }
113 117
114 protected BSLinkset(BSScene scene, BSPhysObject parent) 118 protected BSLinkset(BSScene scene, BSPrimLinkable parent)
115 { 119 {
116 // A simple linkset of one (no children) 120 // A simple linkset of one (no children)
117 LinksetID = m_nextLinksetID++; 121 LinksetID = m_nextLinksetID++;
@@ -120,7 +124,7 @@ public abstract class BSLinkset
120 m_nextLinksetID = 1; 124 m_nextLinksetID = 1;
121 PhysicsScene = scene; 125 PhysicsScene = scene;
122 LinksetRoot = parent; 126 LinksetRoot = parent;
123 m_children = new HashSet<BSPhysObject>(); 127 m_children = new HashSet<BSPrimLinkable>();
124 LinksetMass = parent.RawMass; 128 LinksetMass = parent.RawMass;
125 Rebuilding = false; 129 Rebuilding = false;
126 } 130 }
@@ -129,7 +133,7 @@ public abstract class BSLinkset
129 // Parent changing should not happen so do some sanity checking. 133 // Parent changing should not happen so do some sanity checking.
130 // We return the parent's linkset so the child can track its membership. 134 // We return the parent's linkset so the child can track its membership.
131 // Called at runtime. 135 // Called at runtime.
132 public BSLinkset AddMeToLinkset(BSPhysObject child) 136 public BSLinkset AddMeToLinkset(BSPrimLinkable child)
133 { 137 {
134 lock (m_linksetActivityLock) 138 lock (m_linksetActivityLock)
135 { 139 {
@@ -145,14 +149,13 @@ public abstract class BSLinkset
145 // Returns a new linkset for the child which is a linkset of one (just the 149 // Returns a new linkset for the child which is a linkset of one (just the
146 // orphened child). 150 // orphened child).
147 // Called at runtime. 151 // Called at runtime.
148 public BSLinkset RemoveMeFromLinkset(BSPhysObject child) 152 public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child)
149 { 153 {
150 lock (m_linksetActivityLock) 154 lock (m_linksetActivityLock)
151 { 155 {
152 if (IsRoot(child)) 156 if (IsRoot(child))
153 { 157 {
154 // Cannot remove the root from a linkset. 158 // Cannot remove the root from a linkset.
155 child.PositionDisplacement = OMV.Vector3.Zero;
156 return this; 159 return this;
157 } 160 }
158 RemoveChildFromLinkset(child); 161 RemoveChildFromLinkset(child);
@@ -160,12 +163,11 @@ public abstract class BSLinkset
160 } 163 }
161 164
162 // The child is down to a linkset of just itself 165 // The child is down to a linkset of just itself
163 child.PositionDisplacement = OMV.Vector3.Zero;
164 return BSLinkset.Factory(PhysicsScene, child); 166 return BSLinkset.Factory(PhysicsScene, child);
165 } 167 }
166 168
167 // Return 'true' if the passed object is the root object of this linkset 169 // Return 'true' if the passed object is the root object of this linkset
168 public bool IsRoot(BSPhysObject requestor) 170 public bool IsRoot(BSPrimLinkable requestor)
169 { 171 {
170 return (requestor.LocalID == LinksetRoot.LocalID); 172 return (requestor.LocalID == LinksetRoot.LocalID);
171 } 173 }
@@ -176,14 +178,14 @@ public abstract class BSLinkset
176 public bool HasAnyChildren { get { return (m_children.Count > 0); } } 178 public bool HasAnyChildren { get { return (m_children.Count > 0); } }
177 179
178 // Return 'true' if this child is in this linkset 180 // Return 'true' if this child is in this linkset
179 public bool HasChild(BSPhysObject child) 181 public bool HasChild(BSPrimLinkable child)
180 { 182 {
181 bool ret = false; 183 bool ret = false;
182 lock (m_linksetActivityLock) 184 lock (m_linksetActivityLock)
183 { 185 {
184 ret = m_children.Contains(child); 186 ret = m_children.Contains(child);
185 /* Safer version but the above should work 187 /* Safer version but the above should work
186 foreach (BSPhysObject bp in m_children) 188 foreach (BSPrimLinkable bp in m_children)
187 { 189 {
188 if (child.LocalID == bp.LocalID) 190 if (child.LocalID == bp.LocalID)
189 { 191 {
@@ -198,14 +200,14 @@ public abstract class BSLinkset
198 200
199 // Perform an action on each member of the linkset including root prim. 201 // Perform an action on each member of the linkset including root prim.
200 // Depends on the action on whether this should be done at taint time. 202 // Depends on the action on whether this should be done at taint time.
201 public delegate bool ForEachMemberAction(BSPhysObject obj); 203 public delegate bool ForEachMemberAction(BSPrimLinkable obj);
202 public virtual bool ForEachMember(ForEachMemberAction action) 204 public virtual bool ForEachMember(ForEachMemberAction action)
203 { 205 {
204 bool ret = false; 206 bool ret = false;
205 lock (m_linksetActivityLock) 207 lock (m_linksetActivityLock)
206 { 208 {
207 action(LinksetRoot); 209 action(LinksetRoot);
208 foreach (BSPhysObject po in m_children) 210 foreach (BSPrimLinkable po in m_children)
209 { 211 {
210 if (action(po)) 212 if (action(po))
211 break; 213 break;
@@ -216,16 +218,16 @@ public abstract class BSLinkset
216 218
217 // I am the root of a linkset and a new child is being added 219 // I am the root of a linkset and a new child is being added
218 // Called while LinkActivity is locked. 220 // Called while LinkActivity is locked.
219 protected abstract void AddChildToLinkset(BSPhysObject child); 221 protected abstract void AddChildToLinkset(BSPrimLinkable child);
220 222
221 // I am the root of a linkset and one of my children is being removed. 223 // I am the root of a linkset and one of my children is being removed.
222 // Safe to call even if the child is not really in my linkset. 224 // Safe to call even if the child is not really in my linkset.
223 protected abstract void RemoveChildFromLinkset(BSPhysObject child); 225 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child);
224 226
225 // When physical properties are changed the linkset needs to recalculate 227 // When physical properties are changed the linkset needs to recalculate
226 // its internal properties. 228 // its internal properties.
227 // May be called at runtime or taint-time. 229 // May be called at runtime or taint-time.
228 public virtual void Refresh(BSPhysObject requestor) 230 public virtual void Refresh(BSPrimLinkable requestor)
229 { 231 {
230 LinksetMass = ComputeLinksetMass(); 232 LinksetMass = ComputeLinksetMass();
231 } 233 }
@@ -240,26 +242,26 @@ public abstract class BSLinkset
240 // has not yet been fully constructed. 242 // has not yet been fully constructed.
241 // Return 'true' if any properties updated on the passed object. 243 // Return 'true' if any properties updated on the passed object.
242 // Called at taint-time! 244 // Called at taint-time!
243 public abstract bool MakeDynamic(BSPhysObject child); 245 public abstract bool MakeDynamic(BSPrimLinkable child);
244 246
245 // The object is going static (non-physical). Do any setup necessary 247 // The object is going static (non-physical). Do any setup necessary
246 // for a static linkset. 248 // for a static linkset.
247 // Return 'true' if any properties updated on the passed object. 249 // Return 'true' if any properties updated on the passed object.
248 // Called at taint-time! 250 // Called at taint-time!
249 public abstract bool MakeStatic(BSPhysObject child); 251 public abstract bool MakeStatic(BSPrimLinkable child);
250 252
251 // Called when a parameter update comes from the physics engine for any object 253 // Called when a parameter update comes from the physics engine for any object
252 // of the linkset is received. 254 // of the linkset is received.
253 // Passed flag is update came from physics engine (true) or the user (false). 255 // Passed flag is update came from physics engine (true) or the user (false).
254 // Called at taint-time!! 256 // Called at taint-time!!
255 public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPhysObject physObject); 257 public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable physObject);
256 258
257 // Routine used when rebuilding the body of the root of the linkset 259 // Routine used when rebuilding the body of the root of the linkset
258 // Destroy all the constraints have have been made to root. 260 // Destroy all the constraints have have been made to root.
259 // This is called when the root body is changing. 261 // This is called when the root body is changing.
260 // Returns 'true' of something was actually removed and would need restoring 262 // Returns 'true' of something was actually removed and would need restoring
261 // Called at taint-time!! 263 // Called at taint-time!!
262 public abstract bool RemoveBodyDependencies(BSPrim child); 264 public abstract bool RemoveBodyDependencies(BSPrimLinkable child);
263 265
264 // ================================================================ 266 // ================================================================
265 protected virtual float ComputeLinksetMass() 267 protected virtual float ComputeLinksetMass()
@@ -269,7 +271,7 @@ public abstract class BSLinkset
269 { 271 {
270 lock (m_linksetActivityLock) 272 lock (m_linksetActivityLock)
271 { 273 {
272 foreach (BSPhysObject bp in m_children) 274 foreach (BSPrimLinkable bp in m_children)
273 { 275 {
274 mass += bp.RawMass; 276 mass += bp.RawMass;
275 } 277 }
@@ -286,7 +288,7 @@ public abstract class BSLinkset
286 com = LinksetRoot.Position * LinksetRoot.RawMass; 288 com = LinksetRoot.Position * LinksetRoot.RawMass;
287 float totalMass = LinksetRoot.RawMass; 289 float totalMass = LinksetRoot.RawMass;
288 290
289 foreach (BSPhysObject bp in m_children) 291 foreach (BSPrimLinkable bp in m_children)
290 { 292 {
291 com += bp.Position * bp.RawMass; 293 com += bp.Position * bp.RawMass;
292 totalMass += bp.RawMass; 294 totalMass += bp.RawMass;
@@ -305,7 +307,7 @@ public abstract class BSLinkset
305 { 307 {
306 com = LinksetRoot.Position; 308 com = LinksetRoot.Position;
307 309
308 foreach (BSPhysObject bp in m_children) 310 foreach (BSPrimLinkable bp in m_children)
309 { 311 {
310 com += bp.Position; 312 com += bp.Position;
311 } 313 }