diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | 144 |
1 files changed, 120 insertions, 24 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs index d65d407..7179a6d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | |||
@@ -37,19 +37,28 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
37 | { | 37 | { |
38 | public class BSPrimLinkable : BSPrimDisplaced | 38 | public class BSPrimLinkable : BSPrimDisplaced |
39 | { | 39 | { |
40 | // The purpose of this subclass is to add linkset functionality to the prim. This overrides | ||
41 | // operations necessary for keeping the linkset created and, additionally, this | ||
42 | // calls the linkset implementation for its creation and management. | ||
43 | |||
44 | // This adds the overrides for link() and delink() so the prim is linkable. | ||
45 | |||
40 | public BSLinkset Linkset { get; set; } | 46 | public BSLinkset Linkset { get; set; } |
41 | // The index of this child prim. | 47 | // The index of this child prim. |
42 | public int LinksetChildIndex { get; set; } | 48 | public int LinksetChildIndex { get; set; } |
43 | 49 | ||
44 | public BSLinksetInfo LinksetInfo { get; set; } | 50 | public BSLinkset.LinksetImplementation LinksetType { get; set; } |
45 | 51 | ||
46 | public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 52 | public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
47 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 53 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
48 | : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) | 54 | : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) |
49 | { | 55 | { |
50 | Linkset = BSLinkset.Factory(PhysicsScene, this); | 56 | // Default linkset implementation for this prim |
57 | LinksetType = (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation; | ||
58 | |||
59 | Linkset = BSLinkset.Factory(PhysScene, this); | ||
51 | 60 | ||
52 | PhysicsScene.TaintedObject("BSPrimLinksetCompound.Refresh", delegate() | 61 | PhysScene.TaintedObject("BSPrimLinksetCompound.Refresh", delegate() |
53 | { | 62 | { |
54 | Linkset.Refresh(this); | 63 | Linkset.Refresh(this); |
55 | }); | 64 | }); |
@@ -61,16 +70,13 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
61 | base.Destroy(); | 70 | base.Destroy(); |
62 | } | 71 | } |
63 | 72 | ||
64 | public override BSPhysicsShapeType PreferredPhysicalShape | ||
65 | { get { return Linkset.PreferredPhysicalShape(this); } } | ||
66 | |||
67 | public override void link(Manager.PhysicsActor obj) | 73 | public override void link(Manager.PhysicsActor obj) |
68 | { | 74 | { |
69 | BSPrimLinkable parent = obj as BSPrimLinkable; | 75 | BSPrimLinkable parent = obj as BSPrimLinkable; |
70 | if (parent != null) | 76 | if (parent != null) |
71 | { | 77 | { |
72 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 78 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
73 | int childrenBefore = Linkset.NumberOfChildren; | 79 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
74 | 80 | ||
75 | Linkset = parent.Linkset.AddMeToLinkset(this); | 81 | Linkset = parent.Linkset.AddMeToLinkset(this); |
76 | 82 | ||
@@ -85,8 +91,8 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
85 | // TODO: decide if this parent checking needs to happen at taint time | 91 | // TODO: decide if this parent checking needs to happen at taint time |
86 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 92 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
87 | 93 | ||
88 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 94 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
89 | int childrenBefore = Linkset.NumberOfChildren; | 95 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
90 | 96 | ||
91 | Linkset = Linkset.RemoveMeFromLinkset(this); | 97 | Linkset = Linkset.RemoveMeFromLinkset(this); |
92 | 98 | ||
@@ -102,7 +108,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
102 | set | 108 | set |
103 | { | 109 | { |
104 | base.Position = value; | 110 | base.Position = value; |
105 | PhysicsScene.TaintedObject("BSPrimLinkset.setPosition", delegate() | 111 | PhysScene.TaintedObject("BSPrimLinkset.setPosition", delegate() |
106 | { | 112 | { |
107 | Linkset.UpdateProperties(UpdatedProperties.Position, this); | 113 | Linkset.UpdateProperties(UpdatedProperties.Position, this); |
108 | }); | 114 | }); |
@@ -116,7 +122,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
116 | set | 122 | set |
117 | { | 123 | { |
118 | base.Orientation = value; | 124 | base.Orientation = value; |
119 | PhysicsScene.TaintedObject("BSPrimLinkset.setOrientation", delegate() | 125 | PhysScene.TaintedObject("BSPrimLinkset.setOrientation", delegate() |
120 | { | 126 | { |
121 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); | 127 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); |
122 | }); | 128 | }); |
@@ -128,6 +134,17 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
128 | get { return Linkset.LinksetMass; } | 134 | get { return Linkset.LinksetMass; } |
129 | } | 135 | } |
130 | 136 | ||
137 | public override OMV.Vector3 CenterOfMass | ||
138 | { | ||
139 | get { return Linkset.CenterOfMass; } | ||
140 | } | ||
141 | |||
142 | public override OMV.Vector3 GeometricCenter | ||
143 | { | ||
144 | get { return Linkset.GeometricCenter; } | ||
145 | } | ||
146 | |||
147 | // Refresh the linkset structure and parameters when the prim's physical parameters are changed. | ||
131 | public override void UpdatePhysicalParameters() | 148 | public override void UpdatePhysicalParameters() |
132 | { | 149 | { |
133 | base.UpdatePhysicalParameters(); | 150 | base.UpdatePhysicalParameters(); |
@@ -139,22 +156,28 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
139 | Linkset.Refresh(this); | 156 | Linkset.Refresh(this); |
140 | } | 157 | } |
141 | 158 | ||
159 | // When the prim is made dynamic or static, the linkset needs to change. | ||
142 | protected override void MakeDynamic(bool makeStatic) | 160 | protected override void MakeDynamic(bool makeStatic) |
143 | { | 161 | { |
144 | base.MakeDynamic(makeStatic); | 162 | base.MakeDynamic(makeStatic); |
145 | if (makeStatic) | 163 | if (Linkset != null) // null can happen during initialization |
146 | Linkset.MakeStatic(this); | 164 | { |
147 | else | 165 | if (makeStatic) |
148 | Linkset.MakeDynamic(this); | 166 | Linkset.MakeStatic(this); |
167 | else | ||
168 | Linkset.MakeDynamic(this); | ||
169 | } | ||
149 | } | 170 | } |
150 | 171 | ||
151 | // Body is being taken apart. Remove physical dependencies and schedule a rebuild. | 172 | // Body is being taken apart. Remove physical dependencies and schedule a rebuild. |
152 | protected override void RemoveBodyDependencies() | 173 | protected override void RemoveDependencies() |
153 | { | 174 | { |
154 | Linkset.RemoveBodyDependencies(this); | 175 | Linkset.RemoveDependencies(this); |
155 | base.RemoveBodyDependencies(); | 176 | base.RemoveDependencies(); |
156 | } | 177 | } |
157 | 178 | ||
179 | // Called after a simulation step for the changes in physical object properties. | ||
180 | // Do any filtering/modification needed for linksets. | ||
158 | public override void UpdateProperties(EntityProperties entprop) | 181 | public override void UpdateProperties(EntityProperties entprop) |
159 | { | 182 | { |
160 | if (Linkset.IsRoot(this)) | 183 | if (Linkset.IsRoot(this)) |
@@ -163,20 +186,93 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
163 | // TODO: this will have to change when linksets are articulated. | 186 | // TODO: this will have to change when linksets are articulated. |
164 | base.UpdateProperties(entprop); | 187 | base.UpdateProperties(entprop); |
165 | } | 188 | } |
189 | /* | ||
190 | else | ||
191 | { | ||
192 | // For debugging, report the movement of children | ||
193 | DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
194 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | ||
195 | entprop.Acceleration, entprop.RotationalVelocity); | ||
196 | } | ||
197 | */ | ||
166 | // The linkset might like to know about changing locations | 198 | // The linkset might like to know about changing locations |
167 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); | 199 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
168 | } | 200 | } |
169 | 201 | ||
202 | // Called after a simulation step to post a collision with this object. | ||
203 | // This returns 'true' if the collision has been queued and the SendCollisions call must | ||
204 | // be made at the end of the simulation step. | ||
170 | public override bool Collide(uint collidingWith, BSPhysObject collidee, | 205 | public override bool Collide(uint collidingWith, BSPhysObject collidee, |
171 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 206 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
172 | { | 207 | { |
173 | // prims in the same linkset cannot collide with each other | 208 | bool ret = false; |
174 | BSPrimLinkable convCollidee = collidee as BSPrimLinkable; | 209 | // Ask the linkset if it wants to handle the collision |
175 | if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID)) | 210 | if (!Linkset.HandleCollide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth)) |
211 | { | ||
212 | // The linkset didn't handle it so pass the collision through normal processing | ||
213 | ret = base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth); | ||
214 | } | ||
215 | return ret; | ||
216 | } | ||
217 | |||
218 | // A linkset reports any collision on any part of the linkset. | ||
219 | public long SomeCollisionSimulationStep = 0; | ||
220 | public override bool HasSomeCollision | ||
221 | { | ||
222 | get | ||
223 | { | ||
224 | return (SomeCollisionSimulationStep == PhysScene.SimulationStep) || base.IsColliding; | ||
225 | } | ||
226 | set | ||
227 | { | ||
228 | if (value) | ||
229 | SomeCollisionSimulationStep = PhysScene.SimulationStep; | ||
230 | else | ||
231 | SomeCollisionSimulationStep = 0; | ||
232 | |||
233 | base.HasSomeCollision = value; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | // Convert the existing linkset of this prim into a new type. | ||
238 | public bool ConvertLinkset(BSLinkset.LinksetImplementation newType) | ||
239 | { | ||
240 | bool ret = false; | ||
241 | if (LinksetType != newType) | ||
176 | { | 242 | { |
177 | return false; | 243 | // Set the implementation type first so the call to BSLinkset.Factory gets the new type. |
244 | this.LinksetType = newType; | ||
245 | |||
246 | BSLinkset oldLinkset = this.Linkset; | ||
247 | BSLinkset newLinkset = BSLinkset.Factory(PhysScene, this); | ||
248 | |||
249 | this.Linkset = newLinkset; | ||
250 | |||
251 | // Pick up any physical dependencies this linkset might have in the physics engine. | ||
252 | oldLinkset.RemoveDependencies(this); | ||
253 | |||
254 | // Create a list of the children (mainly because can't interate through a list that's changing) | ||
255 | List<BSPrimLinkable> children = new List<BSPrimLinkable>(); | ||
256 | oldLinkset.ForEachMember((child) => | ||
257 | { | ||
258 | if (!oldLinkset.IsRoot(child)) | ||
259 | children.Add(child); | ||
260 | return false; // 'false' says to continue to next member | ||
261 | }); | ||
262 | |||
263 | // Remove the children from the old linkset and add to the new (will be a new instance from the factory) | ||
264 | foreach (BSPrimLinkable child in children) | ||
265 | { | ||
266 | oldLinkset.RemoveMeFromLinkset(child); | ||
267 | newLinkset.AddMeToLinkset(child); | ||
268 | child.Linkset = newLinkset; | ||
269 | } | ||
270 | |||
271 | // Force the shape and linkset to get reconstructed | ||
272 | newLinkset.Refresh(this); | ||
273 | this.ForceBodyShapeRebuild(true /* inTaintTime */); | ||
178 | } | 274 | } |
179 | return base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth); | 275 | return ret; |
180 | } | 276 | } |
181 | } | 277 | } |
182 | } | 278 | } |