diff options
Merge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs index c88e645..22ea367 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | |||
@@ -56,29 +56,25 @@ public class BSConstraintCollection : IDisposable | |||
56 | 56 | ||
57 | public void Clear() | 57 | public void Clear() |
58 | { | 58 | { |
59 | foreach (BSConstraint cons in m_constraints) | 59 | lock (m_constraints) |
60 | { | 60 | { |
61 | cons.Dispose(); | 61 | foreach (BSConstraint cons in m_constraints) |
62 | { | ||
63 | cons.Dispose(); | ||
64 | } | ||
65 | m_constraints.Clear(); | ||
62 | } | 66 | } |
63 | m_constraints.Clear(); | ||
64 | } | ||
65 | |||
66 | public BSConstraint CreateConstraint(BulletSim world, BulletBody obj1, BulletBody obj2, | ||
67 | Vector3 frame1, Quaternion frame1rot, | ||
68 | Vector3 frame2, Quaternion frame2rot) | ||
69 | { | ||
70 | BSConstraint constrain = new BSConstraint(world, obj1, obj2, frame1, frame1rot, frame2, frame2rot); | ||
71 | |||
72 | this.AddConstraint(constrain); | ||
73 | return constrain; | ||
74 | } | 67 | } |
75 | 68 | ||
76 | public bool AddConstraint(BSConstraint cons) | 69 | public bool AddConstraint(BSConstraint cons) |
77 | { | 70 | { |
78 | // There is only one constraint between any bodies. Remove any old just to make sure. | 71 | lock (m_constraints) |
79 | RemoveAndDestroyConstraint(cons.Body1, cons.Body2); | 72 | { |
73 | // There is only one constraint between any bodies. Remove any old just to make sure. | ||
74 | RemoveAndDestroyConstraint(cons.Body1, cons.Body2); | ||
80 | 75 | ||
81 | m_constraints.Add(cons); | 76 | m_constraints.Add(cons); |
77 | } | ||
82 | 78 | ||
83 | return true; | 79 | return true; |
84 | } | 80 | } |
@@ -92,16 +88,19 @@ public class BSConstraintCollection : IDisposable | |||
92 | 88 | ||
93 | uint lookingID1 = body1.ID; | 89 | uint lookingID1 = body1.ID; |
94 | uint lookingID2 = body2.ID; | 90 | uint lookingID2 = body2.ID; |
95 | ForEachConstraint(delegate(BSConstraint constrain) | 91 | lock (m_constraints) |
96 | { | 92 | { |
97 | if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) | 93 | foreach (BSConstraint constrain in m_constraints) |
98 | || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1)) | ||
99 | { | 94 | { |
100 | foundConstraint = constrain; | 95 | if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) |
101 | found = true; | 96 | || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1)) |
97 | { | ||
98 | foundConstraint = constrain; | ||
99 | found = true; | ||
100 | break; | ||
101 | } | ||
102 | } | 102 | } |
103 | return found; | 103 | } |
104 | }); | ||
105 | returnConstraint = foundConstraint; | 104 | returnConstraint = foundConstraint; |
106 | return found; | 105 | return found; |
107 | } | 106 | } |
@@ -111,22 +110,33 @@ public class BSConstraintCollection : IDisposable | |||
111 | // Return 'true' if a constraint was found and destroyed. | 110 | // Return 'true' if a constraint was found and destroyed. |
112 | public bool RemoveAndDestroyConstraint(BulletBody body1, BulletBody body2) | 111 | public bool RemoveAndDestroyConstraint(BulletBody body1, BulletBody body2) |
113 | { | 112 | { |
114 | // return BulletSimAPI.RemoveConstraint(m_world.ID, obj1.ID, obj2.ID); | ||
115 | |||
116 | bool ret = false; | 113 | bool ret = false; |
117 | BSConstraint constrain; | 114 | lock (m_constraints) |
115 | { | ||
116 | BSConstraint constrain; | ||
117 | if (this.TryGetConstraint(body1, body2, out constrain)) | ||
118 | { | ||
119 | // remove the constraint from our collection | ||
120 | RemoveAndDestroyConstraint(constrain); | ||
121 | ret = true; | ||
122 | } | ||
123 | } | ||
118 | 124 | ||
119 | if (this.TryGetConstraint(body1, body2, out constrain)) | 125 | return ret; |
126 | } | ||
127 | |||
128 | // The constraint MUST exist in the collection | ||
129 | public bool RemoveAndDestroyConstraint(BSConstraint constrain) | ||
130 | { | ||
131 | lock (m_constraints) | ||
120 | { | 132 | { |
121 | // remove the constraint from our collection | 133 | // remove the constraint from our collection |
122 | m_constraints.Remove(constrain); | 134 | m_constraints.Remove(constrain); |
123 | // tell the engine that all its structures need to be freed | ||
124 | constrain.Dispose(); | ||
125 | // we destroyed something | ||
126 | ret = true; | ||
127 | } | 135 | } |
128 | 136 | // tell the engine that all its structures need to be freed | |
129 | return ret; | 137 | constrain.Dispose(); |
138 | // we destroyed something | ||
139 | return true; | ||
130 | } | 140 | } |
131 | 141 | ||
132 | // Remove all constraints that reference the passed body. | 142 | // Remove all constraints that reference the passed body. |
@@ -137,16 +147,15 @@ public class BSConstraintCollection : IDisposable | |||
137 | 147 | ||
138 | List<BSConstraint> toRemove = new List<BSConstraint>(); | 148 | List<BSConstraint> toRemove = new List<BSConstraint>(); |
139 | uint lookingID = body1.ID; | 149 | uint lookingID = body1.ID; |
140 | ForEachConstraint(delegate(BSConstraint constrain) | 150 | lock (m_constraints) |
141 | { | 151 | { |
142 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) | 152 | foreach (BSConstraint constrain in m_constraints) |
143 | { | 153 | { |
144 | toRemove.Add(constrain); | 154 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) |
155 | { | ||
156 | toRemove.Add(constrain); | ||
157 | } | ||
145 | } | 158 | } |
146 | return false; | ||
147 | }); | ||
148 | lock (m_constraints) | ||
149 | { | ||
150 | foreach (BSConstraint constrain in toRemove) | 159 | foreach (BSConstraint constrain in toRemove) |
151 | { | 160 | { |
152 | m_constraints.Remove(constrain); | 161 | m_constraints.Remove(constrain); |
@@ -158,27 +167,16 @@ public class BSConstraintCollection : IDisposable | |||
158 | 167 | ||
159 | public bool RecalculateAllConstraints() | 168 | public bool RecalculateAllConstraints() |
160 | { | 169 | { |
161 | foreach (BSConstraint constrain in m_constraints) | 170 | bool ret = false; |
162 | { | ||
163 | constrain.CalculateTransforms(); | ||
164 | } | ||
165 | return true; | ||
166 | } | ||
167 | |||
168 | // Lock the constraint list and loop through it. | ||
169 | // The constraint action returns 'true' if it wants the loop aborted. | ||
170 | private void ForEachConstraint(ConstraintAction action) | ||
171 | { | ||
172 | lock (m_constraints) | 171 | lock (m_constraints) |
173 | { | 172 | { |
174 | foreach (BSConstraint constrain in m_constraints) | 173 | foreach (BSConstraint constrain in m_constraints) |
175 | { | 174 | { |
176 | if (action(constrain)) | 175 | constrain.CalculateTransforms(); |
177 | break; | 176 | ret = true; |
178 | } | 177 | } |
179 | } | 178 | } |
179 | return ret; | ||
180 | } | 180 | } |
181 | |||
182 | |||
183 | } | 181 | } |
184 | } | 182 | } |