diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | 94 |
1 files changed, 45 insertions, 49 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs index 862b744..22ea367 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | |||
@@ -56,21 +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 | } | 67 | } |
65 | 68 | ||
66 | public bool AddConstraint(BSConstraint cons) | 69 | public bool AddConstraint(BSConstraint cons) |
67 | { | 70 | { |
68 | // There is only one constraint between any bodies. Remove any old just to make sure. | 71 | lock (m_constraints) |
69 | RemoveAndDestroyConstraint(cons.Body1, cons.Body2); | 72 | { |
70 | 73 | // There is only one constraint between any bodies. Remove any old just to make sure. | |
71 | m_world.scene.DetailLog("{0},BSConstraintCollection.AddConstraint,call,body1={1},body2={2}", BSScene.DetailLogZero, cons.Body1.ID, cons.Body2.ID); | 74 | RemoveAndDestroyConstraint(cons.Body1, cons.Body2); |
72 | 75 | ||
73 | m_constraints.Add(cons); | 76 | m_constraints.Add(cons); |
77 | } | ||
74 | 78 | ||
75 | return true; | 79 | return true; |
76 | } | 80 | } |
@@ -84,16 +88,19 @@ public class BSConstraintCollection : IDisposable | |||
84 | 88 | ||
85 | uint lookingID1 = body1.ID; | 89 | uint lookingID1 = body1.ID; |
86 | uint lookingID2 = body2.ID; | 90 | uint lookingID2 = body2.ID; |
87 | ForEachConstraint(delegate(BSConstraint constrain) | 91 | lock (m_constraints) |
88 | { | 92 | { |
89 | if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) | 93 | foreach (BSConstraint constrain in m_constraints) |
90 | || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1)) | ||
91 | { | 94 | { |
92 | foundConstraint = constrain; | 95 | if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) |
93 | found = true; | 96 | || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1)) |
97 | { | ||
98 | foundConstraint = constrain; | ||
99 | found = true; | ||
100 | break; | ||
101 | } | ||
94 | } | 102 | } |
95 | return found; | 103 | } |
96 | }); | ||
97 | returnConstraint = foundConstraint; | 104 | returnConstraint = foundConstraint; |
98 | return found; | 105 | return found; |
99 | } | 106 | } |
@@ -103,17 +110,16 @@ public class BSConstraintCollection : IDisposable | |||
103 | // Return 'true' if a constraint was found and destroyed. | 110 | // Return 'true' if a constraint was found and destroyed. |
104 | public bool RemoveAndDestroyConstraint(BulletBody body1, BulletBody body2) | 111 | public bool RemoveAndDestroyConstraint(BulletBody body1, BulletBody body2) |
105 | { | 112 | { |
106 | // return BulletSimAPI.RemoveConstraint(m_world.ID, obj1.ID, obj2.ID); | ||
107 | |||
108 | bool ret = false; | 113 | bool ret = false; |
109 | BSConstraint constrain; | 114 | lock (m_constraints) |
110 | |||
111 | if (this.TryGetConstraint(body1, body2, out constrain)) | ||
112 | { | 115 | { |
113 | m_world.scene.DetailLog("{0},BSConstraintCollection.RemoveAndDestroyConstraint,taint,body1={1},body2={2}", BSScene.DetailLogZero, body1.ID, body2.ID); | 116 | BSConstraint constrain; |
114 | // remove the constraint from our collection | 117 | if (this.TryGetConstraint(body1, body2, out constrain)) |
115 | RemoveAndDestroyConstraint(constrain); | 118 | { |
116 | ret = true; | 119 | // remove the constraint from our collection |
120 | RemoveAndDestroyConstraint(constrain); | ||
121 | ret = true; | ||
122 | } | ||
117 | } | 123 | } |
118 | 124 | ||
119 | return ret; | 125 | return ret; |
@@ -122,8 +128,11 @@ public class BSConstraintCollection : IDisposable | |||
122 | // The constraint MUST exist in the collection | 128 | // The constraint MUST exist in the collection |
123 | public bool RemoveAndDestroyConstraint(BSConstraint constrain) | 129 | public bool RemoveAndDestroyConstraint(BSConstraint constrain) |
124 | { | 130 | { |
125 | // remove the constraint from our collection | 131 | lock (m_constraints) |
126 | m_constraints.Remove(constrain); | 132 | { |
133 | // remove the constraint from our collection | ||
134 | m_constraints.Remove(constrain); | ||
135 | } | ||
127 | // tell the engine that all its structures need to be freed | 136 | // tell the engine that all its structures need to be freed |
128 | constrain.Dispose(); | 137 | constrain.Dispose(); |
129 | // we destroyed something | 138 | // we destroyed something |
@@ -138,16 +147,15 @@ public class BSConstraintCollection : IDisposable | |||
138 | 147 | ||
139 | List<BSConstraint> toRemove = new List<BSConstraint>(); | 148 | List<BSConstraint> toRemove = new List<BSConstraint>(); |
140 | uint lookingID = body1.ID; | 149 | uint lookingID = body1.ID; |
141 | ForEachConstraint(delegate(BSConstraint constrain) | 150 | lock (m_constraints) |
142 | { | 151 | { |
143 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) | 152 | foreach (BSConstraint constrain in m_constraints) |
144 | { | 153 | { |
145 | toRemove.Add(constrain); | 154 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) |
155 | { | ||
156 | toRemove.Add(constrain); | ||
157 | } | ||
146 | } | 158 | } |
147 | return false; | ||
148 | }); | ||
149 | lock (m_constraints) | ||
150 | { | ||
151 | foreach (BSConstraint constrain in toRemove) | 159 | foreach (BSConstraint constrain in toRemove) |
152 | { | 160 | { |
153 | m_constraints.Remove(constrain); | 161 | m_constraints.Remove(constrain); |
@@ -159,28 +167,16 @@ public class BSConstraintCollection : IDisposable | |||
159 | 167 | ||
160 | public bool RecalculateAllConstraints() | 168 | public bool RecalculateAllConstraints() |
161 | { | 169 | { |
162 | ForEachConstraint(delegate(BSConstraint constrain) | 170 | bool ret = false; |
163 | { | ||
164 | constrain.CalculateTransforms(); | ||
165 | return false; | ||
166 | }); | ||
167 | return true; | ||
168 | } | ||
169 | |||
170 | // Lock the constraint list and loop through it. | ||
171 | // The constraint action returns 'true' if it wants the loop aborted. | ||
172 | private void ForEachConstraint(ConstraintAction action) | ||
173 | { | ||
174 | lock (m_constraints) | 171 | lock (m_constraints) |
175 | { | 172 | { |
176 | foreach (BSConstraint constrain in m_constraints) | 173 | foreach (BSConstraint constrain in m_constraints) |
177 | { | 174 | { |
178 | if (action(constrain)) | 175 | constrain.CalculateTransforms(); |
179 | break; | 176 | ret = true; |
180 | } | 177 | } |
181 | } | 178 | } |
179 | return ret; | ||
182 | } | 180 | } |
183 | |||
184 | |||
185 | } | 181 | } |
186 | } | 182 | } |