diff options
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs index 3df2ddc..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,23 +110,33 @@ 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) |
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 | } | ||
124 | |||
125 | return ret; | ||
126 | } | ||
110 | 127 | ||
111 | if (this.TryGetConstraint(body1, body2, out constrain)) | 128 | // The constraint MUST exist in the collection |
129 | public bool RemoveAndDestroyConstraint(BSConstraint constrain) | ||
130 | { | ||
131 | lock (m_constraints) | ||
112 | { | 132 | { |
113 | m_world.scene.DetailLog("{0},BSConstraintCollection.RemoveAndDestroyConstraint,taint,body1={1},body2={2}", BSScene.DetailLogZero, body1.ID, body2.ID); | ||
114 | // remove the constraint from our collection | 133 | // remove the constraint from our collection |
115 | m_constraints.Remove(constrain); | 134 | m_constraints.Remove(constrain); |
116 | // tell the engine that all its structures need to be freed | ||
117 | constrain.Dispose(); | ||
118 | // we destroyed something | ||
119 | ret = true; | ||
120 | } | 135 | } |
121 | 136 | // tell the engine that all its structures need to be freed | |
122 | return ret; | 137 | constrain.Dispose(); |
138 | // we destroyed something | ||
139 | return true; | ||
123 | } | 140 | } |
124 | 141 | ||
125 | // Remove all constraints that reference the passed body. | 142 | // Remove all constraints that reference the passed body. |
@@ -130,16 +147,15 @@ public class BSConstraintCollection : IDisposable | |||
130 | 147 | ||
131 | List<BSConstraint> toRemove = new List<BSConstraint>(); | 148 | List<BSConstraint> toRemove = new List<BSConstraint>(); |
132 | uint lookingID = body1.ID; | 149 | uint lookingID = body1.ID; |
133 | ForEachConstraint(delegate(BSConstraint constrain) | 150 | lock (m_constraints) |
134 | { | 151 | { |
135 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) | 152 | foreach (BSConstraint constrain in m_constraints) |
136 | { | 153 | { |
137 | toRemove.Add(constrain); | 154 | if (constrain.Body1.ID == lookingID || constrain.Body2.ID == lookingID) |
155 | { | ||
156 | toRemove.Add(constrain); | ||
157 | } | ||
138 | } | 158 | } |
139 | return false; | ||
140 | }); | ||
141 | lock (m_constraints) | ||
142 | { | ||
143 | foreach (BSConstraint constrain in toRemove) | 159 | foreach (BSConstraint constrain in toRemove) |
144 | { | 160 | { |
145 | m_constraints.Remove(constrain); | 161 | m_constraints.Remove(constrain); |
@@ -151,28 +167,16 @@ public class BSConstraintCollection : IDisposable | |||
151 | 167 | ||
152 | public bool RecalculateAllConstraints() | 168 | public bool RecalculateAllConstraints() |
153 | { | 169 | { |
154 | ForEachConstraint(delegate(BSConstraint constrain) | 170 | bool ret = false; |
155 | { | ||
156 | constrain.CalculateTransforms(); | ||
157 | return false; | ||
158 | }); | ||
159 | return true; | ||
160 | } | ||
161 | |||
162 | // Lock the constraint list and loop through it. | ||
163 | // The constraint action returns 'true' if it wants the loop aborted. | ||
164 | private void ForEachConstraint(ConstraintAction action) | ||
165 | { | ||
166 | lock (m_constraints) | 171 | lock (m_constraints) |
167 | { | 172 | { |
168 | foreach (BSConstraint constrain in m_constraints) | 173 | foreach (BSConstraint constrain in m_constraints) |
169 | { | 174 | { |
170 | if (action(constrain)) | 175 | constrain.CalculateTransforms(); |
171 | break; | 176 | ret = true; |
172 | } | 177 | } |
173 | } | 178 | } |
179 | return ret; | ||
174 | } | 180 | } |
175 | |||
176 | |||
177 | } | 181 | } |
178 | } | 182 | } |