diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/OdePlugin.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 336 |
1 files changed, 174 insertions, 162 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 8bb822e..f2c9b57 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Runtime.InteropServices; | ||
31 | using Axiom.Math; | 32 | using Axiom.Math; |
32 | using Ode.NET; | 33 | using Ode.NET; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
@@ -99,17 +100,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
99 | private d.Contact TerrainContact; | 100 | private d.Contact TerrainContact; |
100 | private d.Contact AvatarMovementprimContact; | 101 | private d.Contact AvatarMovementprimContact; |
101 | private d.Contact AvatarMovementTerrainContact; | 102 | private d.Contact AvatarMovementTerrainContact; |
102 | 103 | ||
103 | private int m_physicsiterations = 10; | 104 | private int m_physicsiterations = 10; |
104 | private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 105 | private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
105 | private PhysicsActor PANull = new NullPhysicsActor(); | 106 | private PhysicsActor PANull = new NullPhysicsActor(); |
106 | private float step_time = 0.0f; | 107 | private float step_time = 0.0f; |
107 | public IntPtr world; | 108 | public IntPtr world; |
108 | 109 | ||
109 | public IntPtr space; | 110 | public IntPtr space; |
110 | // split static geometry collision handling into spaces of 30 meters | 111 | // split static geometry collision handling into spaces of 30 meters |
111 | public IntPtr[,] staticPrimspace = new IntPtr[(int)(300/metersInSpace),(int)(300/metersInSpace)]; | 112 | public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)]; |
112 | 113 | ||
113 | public static Object OdeLock = new Object(); | 114 | public static Object OdeLock = new Object(); |
114 | 115 | ||
115 | public IMesher mesher; | 116 | public IMesher mesher; |
@@ -126,7 +127,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
126 | contact.surface.soft_erp = 0.005f; | 127 | contact.surface.soft_erp = 0.005f; |
127 | contact.surface.soft_cfm = 0.00003f; | 128 | contact.surface.soft_cfm = 0.00003f; |
128 | */ | 129 | */ |
129 | 130 | ||
130 | contact.surface.mu = 250.0f; | 131 | contact.surface.mu = 250.0f; |
131 | contact.surface.bounce = 0.2f; | 132 | contact.surface.bounce = 0.2f; |
132 | 133 | ||
@@ -151,7 +152,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
151 | contactgroup = d.JointGroupCreate(0); | 152 | contactgroup = d.JointGroupCreate(0); |
152 | //contactgroup | 153 | //contactgroup |
153 | 154 | ||
154 | 155 | ||
155 | d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f); | 156 | d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f); |
156 | d.WorldSetAutoDisableFlag(world, false); | 157 | d.WorldSetAutoDisableFlag(world, false); |
157 | d.WorldSetContactSurfaceLayer(world, 0.001f); | 158 | d.WorldSetContactSurfaceLayer(world, 0.001f); |
@@ -165,10 +166,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
165 | { | 166 | { |
166 | for (int j = 0; j < staticPrimspace.GetLength(1); j++) | 167 | for (int j = 0; j < staticPrimspace.GetLength(1); j++) |
167 | { | 168 | { |
168 | staticPrimspace[i,j] = IntPtr.Zero; | 169 | staticPrimspace[i, j] = IntPtr.Zero; |
169 | } | 170 | } |
170 | } | 171 | } |
171 | |||
172 | } | 172 | } |
173 | 173 | ||
174 | public override void Initialise(IMesher meshmerizer) | 174 | public override void Initialise(IMesher meshmerizer) |
@@ -184,25 +184,25 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
184 | private void near(IntPtr space, IntPtr g1, IntPtr g2) | 184 | private void near(IntPtr space, IntPtr g1, IntPtr g2) |
185 | { | 185 | { |
186 | // no lock here! It's invoked from within Simulate(), which is thread-locked | 186 | // no lock here! It's invoked from within Simulate(), which is thread-locked |
187 | if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2) ) | 187 | if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2)) |
188 | { | 188 | { |
189 | // Separating static prim geometry spaces. | 189 | // Separating static prim geometry spaces. |
190 | // We'll be calling near recursivly if one | 190 | // We'll be calling near recursivly if one |
191 | // of them is a space to find all of the | 191 | // of them is a space to find all of the |
192 | // contact points in the space | 192 | // contact points in the space |
193 | 193 | ||
194 | d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); | 194 | d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); |
195 | //Colliding a space or a geom with a space or a geom. | 195 | //Colliding a space or a geom with a space or a geom. |
196 | 196 | ||
197 | //Collide all geoms in each space.. | 197 | //Collide all geoms in each space.. |
198 | //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback); | 198 | //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback); |
199 | //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback); | 199 | //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback); |
200 | } | 200 | } |
201 | else | 201 | else |
202 | { | 202 | { |
203 | // Colliding Geom To Geom | 203 | // Colliding Geom To Geom |
204 | // This portion of the function 'was' blatantly ripped off from BoxStack.cs | 204 | // This portion of the function 'was' blatantly ripped off from BoxStack.cs |
205 | 205 | ||
206 | IntPtr b1 = d.GeomGetBody(g1); | 206 | IntPtr b1 = d.GeomGetBody(g1); |
207 | IntPtr b2 = d.GeomGetBody(g2); | 207 | IntPtr b2 = d.GeomGetBody(g2); |
208 | 208 | ||
@@ -213,7 +213,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
213 | return; | 213 | return; |
214 | 214 | ||
215 | d.GeomClassID id = d.GeomGetClass(g1); | 215 | d.GeomClassID id = d.GeomGetClass(g1); |
216 | 216 | ||
217 | String name1 = null; | 217 | String name1 = null; |
218 | String name2 = null; | 218 | String name2 = null; |
219 | 219 | ||
@@ -228,21 +228,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
228 | 228 | ||
229 | if (id == d.GeomClassID.TriMeshClass) | 229 | if (id == d.GeomClassID.TriMeshClass) |
230 | { | 230 | { |
231 | // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); | 231 | // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); |
232 | //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); | 232 | //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); |
233 | } | 233 | } |
234 | 234 | ||
235 | int count = 0; | 235 | int count = 0; |
236 | try | 236 | try |
237 | { | 237 | { |
238 | count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); | 238 | count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); |
239 | } | 239 | } |
240 | catch (System.Runtime.InteropServices.SEHException) | 240 | catch (SEHException) |
241 | { | 241 | { |
242 | MainLog.Instance.Error("PHYSICS", "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); | 242 | MainLog.Instance.Error("PHYSICS", |
243 | "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); | ||
243 | base.TriggerPhysicsBasedRestart(); | 244 | base.TriggerPhysicsBasedRestart(); |
244 | } | 245 | } |
245 | 246 | ||
246 | for (int i = 0; i < count; i++) | 247 | for (int i = 0; i < count; i++) |
247 | { | 248 | { |
248 | IntPtr joint; | 249 | IntPtr joint; |
@@ -263,17 +264,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
263 | // We only need to test p2 for 'jump crouch purposes' | 264 | // We only need to test p2 for 'jump crouch purposes' |
264 | p2.IsColliding = true; | 265 | p2.IsColliding = true; |
265 | 266 | ||
266 | |||
267 | 267 | ||
268 | switch(p1.PhysicsActorType) { | 268 | switch (p1.PhysicsActorType) |
269 | case (int)ActorTypes.Agent: | 269 | { |
270 | case (int) ActorTypes.Agent: | ||
270 | p2.CollidingObj = true; | 271 | p2.CollidingObj = true; |
271 | break; | 272 | break; |
272 | case (int)ActorTypes.Prim: | 273 | case (int) ActorTypes.Prim: |
273 | if (p2.Velocity.X >0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0) | 274 | if (p2.Velocity.X > 0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0) |
274 | p2.CollidingObj = true; | 275 | p2.CollidingObj = true; |
275 | break; | 276 | break; |
276 | case (int)ActorTypes.Unknown: | 277 | case (int) ActorTypes.Unknown: |
277 | p2.CollidingGround = true; | 278 | p2.CollidingGround = true; |
278 | break; | 279 | break; |
279 | default: | 280 | default: |
@@ -282,7 +283,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
282 | } | 283 | } |
283 | 284 | ||
284 | // we don't want prim or avatar to explode | 285 | // we don't want prim or avatar to explode |
286 | |||
285 | #region InterPenetration Handling - Unintended physics explosions | 287 | #region InterPenetration Handling - Unintended physics explosions |
288 | |||
286 | if (contacts[i].depth >= 0.08f) | 289 | if (contacts[i].depth >= 0.08f) |
287 | { | 290 | { |
288 | if (contacts[i].depth >= 1.00f) | 291 | if (contacts[i].depth >= 1.00f) |
@@ -290,30 +293,31 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
290 | //MainLog.Instance.Debug("PHYSICS",contacts[i].depth.ToString()); | 293 | //MainLog.Instance.Debug("PHYSICS",contacts[i].depth.ToString()); |
291 | } | 294 | } |
292 | // If you interpenetrate a prim with an agent | 295 | // If you interpenetrate a prim with an agent |
293 | if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Prim) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Prim)) | 296 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent && |
297 | p1.PhysicsActorType == (int) ActorTypes.Prim) || | ||
298 | (p1.PhysicsActorType == (int) ActorTypes.Agent && | ||
299 | p2.PhysicsActorType == (int) ActorTypes.Prim)) | ||
294 | { | 300 | { |
295 | 301 | if (p2.PhysicsActorType == (int) ActorTypes.Agent) | |
296 | if (p2.PhysicsActorType == (int)ActorTypes.Agent) | ||
297 | { | 302 | { |
298 | p2.CollidingObj = true; | 303 | p2.CollidingObj = true; |
299 | //contacts[i].depth = 0.003f; | 304 | //contacts[i].depth = 0.003f; |
300 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); | 305 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); |
301 | OdeCharacter character = (OdeCharacter)p2; | 306 | OdeCharacter character = (OdeCharacter) p2; |
302 | character.SetPidStatus(true); | 307 | character.SetPidStatus(true); |
303 | //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); | 308 | //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); |
304 | |||
305 | } | 309 | } |
306 | else | 310 | else |
307 | { | 311 | { |
308 | contacts[i].depth = 0.0000000f; | 312 | contacts[i].depth = 0.0000000f; |
309 | } | 313 | } |
310 | if (p1.PhysicsActorType == (int)ActorTypes.Agent) | 314 | if (p1.PhysicsActorType == (int) ActorTypes.Agent) |
311 | { | 315 | { |
312 | p1.CollidingObj = true; | 316 | p1.CollidingObj = true; |
313 | //contacts[i].depth = 0.003f; | 317 | //contacts[i].depth = 0.003f; |
314 | p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f); | 318 | p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f); |
315 | //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2)); | 319 | //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2)); |
316 | OdeCharacter character = (OdeCharacter)p2; | 320 | OdeCharacter character = (OdeCharacter) p2; |
317 | character.SetPidStatus(true); | 321 | character.SetPidStatus(true); |
318 | } | 322 | } |
319 | else | 323 | else |
@@ -322,39 +326,45 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
322 | } | 326 | } |
323 | } | 327 | } |
324 | // If you interpenetrate a prim with another prim | 328 | // If you interpenetrate a prim with another prim |
325 | if (p1.PhysicsActorType == (int)ActorTypes.Prim && p2.PhysicsActorType == (int)ActorTypes.Prim) | 329 | if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim) |
326 | { | 330 | { |
327 | // Don't collide, one or both prim will explode. | 331 | // Don't collide, one or both prim will explode. |
328 | contacts[i].depth = -1f; | 332 | contacts[i].depth = -1f; |
329 | } | 333 | } |
330 | if (contacts[i].depth >= 1.00f) | 334 | if (contacts[i].depth >= 1.00f) |
331 | { | 335 | { |
332 | if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Unknown) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Unknown)) | 336 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent && |
337 | p1.PhysicsActorType == (int) ActorTypes.Unknown) || | ||
338 | (p1.PhysicsActorType == (int) ActorTypes.Agent && | ||
339 | p2.PhysicsActorType == (int) ActorTypes.Unknown)) | ||
333 | { | 340 | { |
334 | 341 | if (p2.PhysicsActorType == (int) ActorTypes.Agent) | |
335 | if (p2.PhysicsActorType == (int)ActorTypes.Agent) | ||
336 | { | 342 | { |
337 | OdeCharacter character = (OdeCharacter)p2; | 343 | OdeCharacter character = (OdeCharacter) p2; |
338 | 344 | ||
339 | //p2.CollidingObj = true; | 345 | //p2.CollidingObj = true; |
340 | contacts[i].depth = 0.003f; | 346 | contacts[i].depth = 0.003f; |
341 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); | 347 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); |
342 | contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); | 348 | contacts[i].pos = |
349 | new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), | ||
350 | contacts[i].pos.Y + (p1.Size.Y/2), | ||
351 | contacts[i].pos.Z + (p1.Size.Z/2)); | ||
343 | character.SetPidStatus(true); | 352 | character.SetPidStatus(true); |
344 | |||
345 | } | 353 | } |
346 | else | 354 | else |
347 | { | 355 | { |
348 | |||
349 | } | 356 | } |
350 | if (p1.PhysicsActorType == (int)ActorTypes.Agent) | 357 | if (p1.PhysicsActorType == (int) ActorTypes.Agent) |
351 | { | 358 | { |
352 | OdeCharacter character = (OdeCharacter)p2; | 359 | OdeCharacter character = (OdeCharacter) p2; |
353 | 360 | ||
354 | //p2.CollidingObj = true; | 361 | //p2.CollidingObj = true; |
355 | contacts[i].depth = 0.003f; | 362 | contacts[i].depth = 0.003f; |
356 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); | 363 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); |
357 | contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); | 364 | contacts[i].pos = |
365 | new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), | ||
366 | contacts[i].pos.Y + (p1.Size.Y/2), | ||
367 | contacts[i].pos.Z + (p1.Size.Z/2)); | ||
358 | character.SetPidStatus(true); | 368 | character.SetPidStatus(true); |
359 | } | 369 | } |
360 | else | 370 | else |
@@ -364,18 +374,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
364 | } | 374 | } |
365 | } | 375 | } |
366 | } | 376 | } |
377 | |||
367 | #endregion | 378 | #endregion |
368 | 379 | ||
369 | if (contacts[i].depth >= 0f) | 380 | if (contacts[i].depth >= 0f) |
370 | { | 381 | { |
371 | if (name1 == "Terrain" || name2 == "Terrain") | 382 | if (name1 == "Terrain" || name2 == "Terrain") |
372 | { | 383 | { |
373 | 384 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && | |
374 | if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) | 385 | (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) |
375 | { | 386 | { |
376 | AvatarMovementTerrainContact.geom = contacts[i]; | 387 | AvatarMovementTerrainContact.geom = contacts[i]; |
377 | joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); | 388 | joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); |
378 | |||
379 | } | 389 | } |
380 | else | 390 | else |
381 | { | 391 | { |
@@ -385,11 +395,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
385 | } | 395 | } |
386 | else | 396 | else |
387 | { | 397 | { |
388 | if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) | 398 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && |
399 | (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) | ||
389 | { | 400 | { |
390 | AvatarMovementprimContact.geom = contacts[i]; | 401 | AvatarMovementprimContact.geom = contacts[i]; |
391 | joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); | 402 | joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); |
392 | |||
393 | } | 403 | } |
394 | else | 404 | else |
395 | { | 405 | { |
@@ -399,7 +409,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
399 | } | 409 | } |
400 | d.JointAttach(joint, b1, b2); | 410 | d.JointAttach(joint, b1, b2); |
401 | } | 411 | } |
402 | 412 | ||
403 | if (count > 3) | 413 | if (count > 3) |
404 | { | 414 | { |
405 | p2.ThrottleUpdates = true; | 415 | p2.ThrottleUpdates = true; |
@@ -421,7 +431,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
421 | } | 431 | } |
422 | // If the sim is running slow this frame, | 432 | // If the sim is running slow this frame, |
423 | // don't process collision for prim! | 433 | // don't process collision for prim! |
424 | if (timeStep < (m_SkipFramesAtms / 3)) | 434 | if (timeStep < (m_SkipFramesAtms/3)) |
425 | { | 435 | { |
426 | foreach (OdePrim chr in _activeprims) | 436 | foreach (OdePrim chr in _activeprims) |
427 | { | 437 | { |
@@ -432,16 +442,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
432 | //foreach (OdePrim ch2 in _prims) | 442 | //foreach (OdePrim ch2 in _prims) |
433 | /// should be a separate space -- lots of avatars will be N**2 slow | 443 | /// should be a separate space -- lots of avatars will be N**2 slow |
434 | //{ | 444 | //{ |
435 | //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) | 445 | //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) |
436 | //{ | 446 | //{ |
437 | // Only test prim that are 0.03 meters away in one direction. | 447 | // Only test prim that are 0.03 meters away in one direction. |
438 | // This should be Optimized! | 448 | // This should be Optimized! |
439 | 449 | ||
440 | //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) | 450 | //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) |
441 | //{ | 451 | //{ |
442 | //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); | 452 | //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); |
443 | //} | 453 | //} |
444 | //} | 454 | //} |
445 | //} | 455 | //} |
446 | } | 456 | } |
447 | } | 457 | } |
@@ -456,7 +466,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
456 | if (d.BodyIsEnabled(chr.Body)) | 466 | if (d.BodyIsEnabled(chr.Body)) |
457 | { | 467 | { |
458 | d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); | 468 | d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); |
459 | |||
460 | } | 469 | } |
461 | } | 470 | } |
462 | } | 471 | } |
@@ -492,7 +501,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
492 | 501 | ||
493 | p.setPrimForRemoval(); | 502 | p.setPrimForRemoval(); |
494 | AddPhysicsActorTaint(prim); | 503 | AddPhysicsActorTaint(prim); |
495 | |||
496 | } | 504 | } |
497 | } | 505 | } |
498 | } | 506 | } |
@@ -519,13 +527,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
519 | } | 527 | } |
520 | else | 528 | else |
521 | { | 529 | { |
522 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); | 530 | MainLog.Instance.Verbose("Physics", |
531 | "Invalid Scene passed to 'removeprim from scene':" + | ||
532 | ((OdePrim) prim).m_targetSpace.ToString()); | ||
523 | } | 533 | } |
524 | } | 534 | } |
525 | } | 535 | } |
526 | 536 | ||
527 | 537 | ||
528 | |||
529 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore | 538 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore |
530 | if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) | 539 | if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) |
531 | { | 540 | { |
@@ -541,17 +550,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
541 | } | 550 | } |
542 | else | 551 | else |
543 | { | 552 | { |
544 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); | 553 | MainLog.Instance.Verbose("Physics", |
554 | "Invalid Scene passed to 'removeprim from scene':" + | ||
555 | ((OdePrim) prim).m_targetSpace.ToString()); | ||
545 | } | 556 | } |
546 | } | 557 | } |
547 | } | 558 | } |
548 | } | 559 | } |
549 | 560 | ||
550 | d.GeomDestroy(prim.prim_geom); | 561 | d.GeomDestroy(prim.prim_geom); |
551 | 562 | ||
552 | _prims.Remove(prim); | 563 | _prims.Remove(prim); |
553 | } | 564 | } |
554 | |||
555 | } | 565 | } |
556 | 566 | ||
557 | public void resetSpaceArrayItemToZero(IntPtr space) | 567 | public void resetSpaceArrayItemToZero(IntPtr space) |
@@ -566,7 +576,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
566 | } | 576 | } |
567 | } | 577 | } |
568 | 578 | ||
569 | public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY) | 579 | public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY) |
570 | { | 580 | { |
571 | staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; | 581 | staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; |
572 | } | 582 | } |
@@ -582,16 +592,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
582 | // never be called if the prim is physical(active) | 592 | // never be called if the prim is physical(active) |
583 | if (currentspace != space) | 593 | if (currentspace != space) |
584 | { | 594 | { |
585 | if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr)0) | 595 | if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr) 0) |
586 | { | 596 | { |
587 | if (d.GeomIsSpace(currentspace)) | 597 | if (d.GeomIsSpace(currentspace)) |
588 | { | 598 | { |
589 | |||
590 | d.SpaceRemove(currentspace, geom); | 599 | d.SpaceRemove(currentspace, geom); |
591 | } | 600 | } |
592 | else | 601 | else |
593 | { | 602 | { |
594 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); | 603 | MainLog.Instance.Verbose("Physics", |
604 | "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + | ||
605 | " Geom:" + geom.ToString()); | ||
595 | } | 606 | } |
596 | } | 607 | } |
597 | else | 608 | else |
@@ -599,7 +610,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
599 | IntPtr sGeomIsIn = d.GeomGetSpace(geom); | 610 | IntPtr sGeomIsIn = d.GeomGetSpace(geom); |
600 | if (!(sGeomIsIn.Equals(null))) | 611 | if (!(sGeomIsIn.Equals(null))) |
601 | { | 612 | { |
602 | if (sGeomIsIn != (IntPtr)0) | 613 | if (sGeomIsIn != (IntPtr) 0) |
603 | { | 614 | { |
604 | if (d.GeomIsSpace(currentspace)) | 615 | if (d.GeomIsSpace(currentspace)) |
605 | { | 616 | { |
@@ -607,7 +618,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
607 | } | 618 | } |
608 | else | 619 | else |
609 | { | 620 | { |
610 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); | 621 | MainLog.Instance.Verbose("Physics", |
622 | "Invalid Scene passed to 'recalculatespace':" + | ||
623 | sGeomIsIn.ToString() + " Geom:" + geom.ToString()); | ||
611 | } | 624 | } |
612 | } | 625 | } |
613 | } | 626 | } |
@@ -617,7 +630,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
617 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore | 630 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore |
618 | if (d.SpaceGetNumGeoms(currentspace) == 0) | 631 | if (d.SpaceGetNumGeoms(currentspace) == 0) |
619 | { | 632 | { |
620 | if (currentspace != (IntPtr)0) | 633 | if (currentspace != (IntPtr) 0) |
621 | { | 634 | { |
622 | if (d.GeomIsSpace(currentspace)) | 635 | if (d.GeomIsSpace(currentspace)) |
623 | { | 636 | { |
@@ -628,9 +641,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
628 | } | 641 | } |
629 | else | 642 | else |
630 | { | 643 | { |
631 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); | 644 | MainLog.Instance.Verbose("Physics", |
645 | "Invalid Scene passed to 'recalculatespace':" + | ||
646 | currentspace.ToString() + " Geom:" + geom.ToString()); | ||
632 | } | 647 | } |
633 | |||
634 | } | 648 | } |
635 | } | 649 | } |
636 | } | 650 | } |
@@ -639,15 +653,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
639 | // this is a physical object that got disabled. ;.; | 653 | // this is a physical object that got disabled. ;.; |
640 | if (d.SpaceQuery(currentspace, geom)) | 654 | if (d.SpaceQuery(currentspace, geom)) |
641 | { | 655 | { |
642 | if (currentspace != (IntPtr)0) | 656 | if (currentspace != (IntPtr) 0) |
643 | if (d.GeomIsSpace(currentspace)) | 657 | if (d.GeomIsSpace(currentspace)) |
644 | { | 658 | { |
645 | d.SpaceRemove(currentspace, geom); | 659 | d.SpaceRemove(currentspace, geom); |
646 | } | 660 | } |
647 | else | 661 | else |
648 | { | 662 | { |
649 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); | 663 | MainLog.Instance.Verbose("Physics", |
650 | 664 | "Invalid Scene passed to 'recalculatespace':" + | |
665 | currentspace.ToString() + " Geom:" + geom.ToString()); | ||
651 | } | 666 | } |
652 | } | 667 | } |
653 | else | 668 | else |
@@ -655,7 +670,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
655 | IntPtr sGeomIsIn = d.GeomGetSpace(geom); | 670 | IntPtr sGeomIsIn = d.GeomGetSpace(geom); |
656 | if (!(sGeomIsIn.Equals(null))) | 671 | if (!(sGeomIsIn.Equals(null))) |
657 | { | 672 | { |
658 | if (sGeomIsIn != (IntPtr)0) | 673 | if (sGeomIsIn != (IntPtr) 0) |
659 | { | 674 | { |
660 | if (d.GeomIsSpace(sGeomIsIn)) | 675 | if (d.GeomIsSpace(sGeomIsIn)) |
661 | { | 676 | { |
@@ -663,14 +678,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
663 | } | 678 | } |
664 | else | 679 | else |
665 | { | 680 | { |
666 | MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); | 681 | MainLog.Instance.Verbose("Physics", |
682 | "Invalid Scene passed to 'recalculatespace':" + | ||
683 | sGeomIsIn.ToString() + " Geom:" + geom.ToString()); | ||
667 | } | 684 | } |
668 | } | 685 | } |
669 | } | 686 | } |
670 | } | 687 | } |
671 | } | 688 | } |
672 | 689 | ||
673 | 690 | ||
674 | // The routines in the Position and Size sections do the 'inserting' into the space, | 691 | // The routines in the Position and Size sections do the 'inserting' into the space, |
675 | // so all we have to do is make sure that the space that we're putting the prim into | 692 | // so all we have to do is make sure that the space that we're putting the prim into |
676 | // is in the 'main' space. | 693 | // is in the 'main' space. |
@@ -679,17 +696,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
679 | 696 | ||
680 | if (newspace == IntPtr.Zero) | 697 | if (newspace == IntPtr.Zero) |
681 | { | 698 | { |
682 | newspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); | 699 | newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); |
683 | d.HashSpaceSetLevels(newspace, -4, 66); | 700 | d.HashSpaceSetLevels(newspace, -4, 66); |
684 | } | 701 | } |
685 | 702 | ||
686 | return newspace; | 703 | return newspace; |
687 | } | 704 | } |
688 | 705 | ||
689 | public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) { | 706 | public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) |
707 | { | ||
690 | // creating a new space for prim and inserting it into main space. | 708 | // creating a new space for prim and inserting it into main space. |
691 | staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); | 709 | staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); |
692 | d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX,iprimspaceArrItemY]); | 710 | d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); |
693 | return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; | 711 | return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; |
694 | } | 712 | } |
695 | 713 | ||
@@ -697,7 +715,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
697 | { | 715 | { |
698 | int[] xyspace = calculateSpaceArrayItemFromPos(pos); | 716 | int[] xyspace = calculateSpaceArrayItemFromPos(pos); |
699 | //MainLog.Instance.Verbose("Physics", "Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); | 717 | //MainLog.Instance.Verbose("Physics", "Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); |
700 | IntPtr locationbasedspace = staticPrimspace[xyspace[0],xyspace[1]]; | 718 | IntPtr locationbasedspace = staticPrimspace[xyspace[0], xyspace[1]]; |
701 | 719 | ||
702 | //locationbasedspace = space; | 720 | //locationbasedspace = space; |
703 | return locationbasedspace; | 721 | return locationbasedspace; |
@@ -706,17 +724,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
706 | public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) | 724 | public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) |
707 | { | 725 | { |
708 | int[] returnint = new int[2]; | 726 | int[] returnint = new int[2]; |
709 | 727 | ||
710 | returnint[0] = (int)(pos.X / metersInSpace); | 728 | returnint[0] = (int) (pos.X/metersInSpace); |
711 | 729 | ||
712 | if (returnint[0] > ((int)(259f / metersInSpace))) | 730 | if (returnint[0] > ((int) (259f/metersInSpace))) |
713 | returnint[0] = ((int)(259f / metersInSpace)); | 731 | returnint[0] = ((int) (259f/metersInSpace)); |
714 | if (returnint[0] < 0) | 732 | if (returnint[0] < 0) |
715 | returnint[0] = 0; | 733 | returnint[0] = 0; |
716 | 734 | ||
717 | returnint[1] = (int)(pos.Y / metersInSpace); | 735 | returnint[1] = (int) (pos.Y/metersInSpace); |
718 | if (returnint[0] > ((int)(259f / metersInSpace))) | 736 | if (returnint[0] > ((int) (259f/metersInSpace))) |
719 | returnint[0] = ((int)(259f / metersInSpace)); | 737 | returnint[0] = ((int) (259f/metersInSpace)); |
720 | if (returnint[0] < 0) | 738 | if (returnint[0] < 0) |
721 | returnint[0] = 0; | 739 | returnint[0] = 0; |
722 | 740 | ||
@@ -726,7 +744,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
726 | private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, | 744 | private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, |
727 | IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) | 745 | IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) |
728 | { | 746 | { |
729 | |||
730 | PhysicsVector pos = new PhysicsVector(); | 747 | PhysicsVector pos = new PhysicsVector(); |
731 | pos.X = position.X; | 748 | pos.X = position.X; |
732 | pos.Y = position.Y; | 749 | pos.Y = position.Y; |
@@ -741,21 +758,21 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
741 | rot.y = rotation.y; | 758 | rot.y = rotation.y; |
742 | rot.z = rotation.z; | 759 | rot.z = rotation.z; |
743 | 760 | ||
744 | 761 | ||
745 | int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos); | 762 | int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos); |
746 | IntPtr targetspace = calculateSpaceForGeom(pos); | 763 | IntPtr targetspace = calculateSpaceForGeom(pos); |
747 | 764 | ||
748 | if (targetspace == IntPtr.Zero) | 765 | if (targetspace == IntPtr.Zero) |
749 | targetspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); | 766 | targetspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); |
750 | 767 | ||
751 | OdePrim newPrim; | 768 | OdePrim newPrim; |
752 | lock (OdeLock) | 769 | lock (OdeLock) |
753 | { | 770 | { |
754 | newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); | 771 | newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); |
755 | 772 | ||
756 | _prims.Add(newPrim); | 773 | _prims.Add(newPrim); |
757 | } | 774 | } |
758 | 775 | ||
759 | return newPrim; | 776 | return newPrim; |
760 | } | 777 | } |
761 | 778 | ||
@@ -763,16 +780,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
763 | { | 780 | { |
764 | // adds active prim.. (ones that should be iterated over in collisions_optimized | 781 | // adds active prim.. (ones that should be iterated over in collisions_optimized |
765 | 782 | ||
766 | _activeprims.Add(activatePrim); | 783 | _activeprims.Add(activatePrim); |
767 | |||
768 | } | 784 | } |
785 | |||
769 | public void remActivePrim(OdePrim deactivatePrim) | 786 | public void remActivePrim(OdePrim deactivatePrim) |
770 | { | 787 | { |
771 | 788 | _activeprims.Remove(deactivatePrim); | |
772 | _activeprims.Remove(deactivatePrim); | ||
773 | |||
774 | |||
775 | } | 789 | } |
790 | |||
776 | public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) | 791 | public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) |
777 | { | 792 | { |
778 | /* String name1 = null; | 793 | /* String name1 = null; |
@@ -818,7 +833,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
818 | return 1; | 833 | return 1; |
819 | } | 834 | } |
820 | 835 | ||
821 | 836 | ||
822 | public bool needsMeshing(PrimitiveBaseShape pbs) | 837 | public bool needsMeshing(PrimitiveBaseShape pbs) |
823 | { | 838 | { |
824 | if (pbs.ProfileHollow != 0) | 839 | if (pbs.ProfileHollow != 0) |
@@ -833,7 +848,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
833 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 848 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
834 | PhysicsVector size, Quaternion rotation) //To be removed | 849 | PhysicsVector size, Quaternion rotation) //To be removed |
835 | { | 850 | { |
836 | return this.AddPrimShape(primName, pbs, position, size, rotation, false); | 851 | return AddPrimShape(primName, pbs, position, size, rotation, false); |
837 | } | 852 | } |
838 | 853 | ||
839 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 854 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
@@ -848,12 +863,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
848 | /// support simple box & hollow box now; later, more shapes | 863 | /// support simple box & hollow box now; later, more shapes |
849 | if (needsMeshing(pbs)) | 864 | if (needsMeshing(pbs)) |
850 | { | 865 | { |
851 | mesh = mesher.CreateMesh(primName, pbs, size); | 866 | mesh = mesher.CreateMesh(primName, pbs, size); |
852 | } | 867 | } |
853 | 868 | ||
854 | break; | 869 | break; |
855 | } | 870 | } |
856 | 871 | ||
857 | result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); | 872 | result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); |
858 | 873 | ||
859 | 874 | ||
@@ -864,10 +879,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
864 | { | 879 | { |
865 | if (prim is OdePrim) | 880 | if (prim is OdePrim) |
866 | { | 881 | { |
867 | OdePrim taintedprim = ((OdePrim)prim); | 882 | OdePrim taintedprim = ((OdePrim) prim); |
868 | if (!(_taintedPrim.Contains(taintedprim))) | 883 | if (!(_taintedPrim.Contains(taintedprim))) |
869 | _taintedPrim.Add(taintedprim); | 884 | _taintedPrim.Add(taintedprim); |
870 | |||
871 | } | 885 | } |
872 | } | 886 | } |
873 | 887 | ||
@@ -877,19 +891,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
877 | 891 | ||
878 | step_time += timeStep; | 892 | step_time += timeStep; |
879 | 893 | ||
880 | 894 | ||
881 | // If We're loaded down by something else, | 895 | // If We're loaded down by something else, |
882 | // or debugging with the Visual Studio project on pause | 896 | // or debugging with the Visual Studio project on pause |
883 | // skip a few frames to catch up gracefully. | 897 | // skip a few frames to catch up gracefully. |
884 | // without shooting the physicsactors all over the place | 898 | // without shooting the physicsactors all over the place |
885 | |||
886 | 899 | ||
887 | 900 | ||
888 | if (step_time >= m_SkipFramesAtms) | 901 | if (step_time >= m_SkipFramesAtms) |
889 | { | 902 | { |
890 | // Instead of trying to catch up, it'll do one physics frame only | 903 | // Instead of trying to catch up, it'll do one physics frame only |
891 | step_time = ODE_STEPSIZE; | 904 | step_time = ODE_STEPSIZE; |
892 | this.m_physicsiterations = 5; | 905 | m_physicsiterations = 5; |
893 | } | 906 | } |
894 | else | 907 | else |
895 | { | 908 | { |
@@ -897,35 +910,36 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
897 | } | 910 | } |
898 | lock (OdeLock) | 911 | lock (OdeLock) |
899 | { | 912 | { |
900 | // Process 10 frames if the sim is running normal.. | 913 | // Process 10 frames if the sim is running normal.. |
901 | // process 5 frames if the sim is running slow | 914 | // process 5 frames if the sim is running slow |
902 | try{ | 915 | try |
916 | { | ||
903 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); | 917 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); |
904 | } | 918 | } |
905 | catch (System.StackOverflowException) | 919 | catch (StackOverflowException) |
906 | { | 920 | { |
907 | MainLog.Instance.Error("PHYSICS", "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); | 921 | MainLog.Instance.Error("PHYSICS", |
922 | "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); | ||
908 | base.TriggerPhysicsBasedRestart(); | 923 | base.TriggerPhysicsBasedRestart(); |
909 | } | 924 | } |
910 | 925 | ||
911 | int i = 0; | 926 | int i = 0; |
912 | 927 | ||
913 | 928 | ||
914 | // Figure out the Frames Per Second we're going at. | 929 | // Figure out the Frames Per Second we're going at. |
915 | 930 | ||
916 | fps = (((step_time / ODE_STEPSIZE * m_physicsiterations)*2)* 10); | 931 | fps = (((step_time/ODE_STEPSIZE*m_physicsiterations)*2)*10); |
917 | 932 | ||
918 | 933 | ||
919 | while (step_time > 0.0f) | 934 | while (step_time > 0.0f) |
920 | { | 935 | { |
921 | |||
922 | foreach (OdeCharacter actor in _characters) | 936 | foreach (OdeCharacter actor in _characters) |
923 | { | 937 | { |
924 | actor.Move(timeStep); | 938 | actor.Move(timeStep); |
925 | actor.collidelock = true; | 939 | actor.collidelock = true; |
926 | } | 940 | } |
927 | 941 | ||
928 | 942 | ||
929 | collision_optimized(timeStep); | 943 | collision_optimized(timeStep); |
930 | d.WorldQuickStep(world, ODE_STEPSIZE); | 944 | d.WorldQuickStep(world, ODE_STEPSIZE); |
931 | d.JointGroupEmpty(contactgroup); | 945 | d.JointGroupEmpty(contactgroup); |
@@ -933,7 +947,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
933 | { | 947 | { |
934 | actor.collidelock = false; | 948 | actor.collidelock = false; |
935 | } | 949 | } |
936 | 950 | ||
937 | step_time -= ODE_STEPSIZE; | 951 | step_time -= ODE_STEPSIZE; |
938 | i++; | 952 | i++; |
939 | } | 953 | } |
@@ -941,7 +955,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
941 | foreach (OdeCharacter actor in _characters) | 955 | foreach (OdeCharacter actor in _characters) |
942 | { | 956 | { |
943 | actor.UpdatePositionAndVelocity(); | 957 | actor.UpdatePositionAndVelocity(); |
944 | |||
945 | } | 958 | } |
946 | bool processedtaints = false; | 959 | bool processedtaints = false; |
947 | foreach (OdePrim prim in _taintedPrim) | 960 | foreach (OdePrim prim in _taintedPrim) |
@@ -963,7 +976,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
963 | if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag)) | 976 | if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag)) |
964 | { | 977 | { |
965 | actor.UpdatePositionAndVelocity(); | 978 | actor.UpdatePositionAndVelocity(); |
966 | |||
967 | } | 979 | } |
968 | } | 980 | } |
969 | } | 981 | } |
@@ -984,25 +996,25 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
984 | public float[] ResizeTerrain512(float[] heightMap) | 996 | public float[] ResizeTerrain512(float[] heightMap) |
985 | { | 997 | { |
986 | float[] returnarr = new float[262144]; | 998 | float[] returnarr = new float[262144]; |
987 | float[,] resultarr = new float[m_regionWidth, m_regionHeight]; | 999 | float[,] resultarr = new float[m_regionWidth,m_regionHeight]; |
988 | 1000 | ||
989 | // Filling out the array into it's multi-dimentional components | 1001 | // Filling out the array into it's multi-dimentional components |
990 | for (int y = 0; y < m_regionHeight; y++) | 1002 | for (int y = 0; y < m_regionHeight; y++) |
991 | { | 1003 | { |
992 | for (int x = 0; x < m_regionWidth; x++) | 1004 | for (int x = 0; x < m_regionWidth; x++) |
993 | { | 1005 | { |
994 | resultarr[y,x] = heightMap[y * m_regionWidth + x]; | 1006 | resultarr[y, x] = heightMap[y*m_regionWidth + x]; |
995 | } | 1007 | } |
996 | } | 1008 | } |
997 | 1009 | ||
998 | // Resize using interpolation | 1010 | // Resize using interpolation |
999 | 1011 | ||
1000 | // This particular way is quick but it only works on a multiple of the original | 1012 | // This particular way is quick but it only works on a multiple of the original |
1001 | 1013 | ||
1002 | // The idea behind this method can be described with the following diagrams | 1014 | // The idea behind this method can be described with the following diagrams |
1003 | // second pass and third pass happen in the same loop really.. just separated | 1015 | // second pass and third pass happen in the same loop really.. just separated |
1004 | // them to show what this does. | 1016 | // them to show what this does. |
1005 | 1017 | ||
1006 | // First Pass | 1018 | // First Pass |
1007 | // ResultArr: | 1019 | // ResultArr: |
1008 | // 1,1,1,1,1,1 | 1020 | // 1,1,1,1,1,1 |
@@ -1054,12 +1066,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1054 | // 4th # | 1066 | // 4th # |
1055 | // on single loop. | 1067 | // on single loop. |
1056 | 1068 | ||
1057 | float[,] resultarr2 = new float[512, 512]; | 1069 | float[,] resultarr2 = new float[512,512]; |
1058 | for (int y = 0; y < m_regionHeight; y++) | 1070 | for (int y = 0; y < m_regionHeight; y++) |
1059 | { | 1071 | { |
1060 | for (int x = 0; x < m_regionWidth; x++) | 1072 | for (int x = 0; x < m_regionWidth; x++) |
1061 | { | 1073 | { |
1062 | resultarr2[y*2,x*2] = resultarr[y,x]; | 1074 | resultarr2[y*2, x*2] = resultarr[y, x]; |
1063 | 1075 | ||
1064 | if (y < m_regionHeight) | 1076 | if (y < m_regionHeight) |
1065 | { | 1077 | { |
@@ -1067,16 +1079,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1067 | { | 1079 | { |
1068 | if (x + 1 < m_regionWidth) | 1080 | if (x + 1 < m_regionWidth) |
1069 | { | 1081 | { |
1070 | resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4); | 1082 | resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] + |
1083 | resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); | ||
1071 | } | 1084 | } |
1072 | else | 1085 | else |
1073 | { | 1086 | { |
1074 | resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x]) / 2); | 1087 | resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2); |
1075 | } | 1088 | } |
1076 | } | 1089 | } |
1077 | else | 1090 | else |
1078 | { | 1091 | { |
1079 | resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; | 1092 | resultarr2[(y*2) + 1, x*2] = resultarr[y, x]; |
1080 | } | 1093 | } |
1081 | } | 1094 | } |
1082 | if (x < m_regionWidth) | 1095 | if (x < m_regionWidth) |
@@ -1085,31 +1098,32 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1085 | { | 1098 | { |
1086 | if (y + 1 < m_regionHeight) | 1099 | if (y + 1 < m_regionHeight) |
1087 | { | 1100 | { |
1088 | resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); | 1101 | resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + |
1102 | resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); | ||
1089 | } | 1103 | } |
1090 | else | 1104 | else |
1091 | { | 1105 | { |
1092 | resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1]) / 2); | 1106 | resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2); |
1093 | } | 1107 | } |
1094 | } | 1108 | } |
1095 | else | 1109 | else |
1096 | { | 1110 | { |
1097 | resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; | 1111 | resultarr2[y*2, (x*2) + 1] = resultarr[y, x]; |
1098 | } | 1112 | } |
1099 | } | 1113 | } |
1100 | if (x < m_regionWidth && y < m_regionHeight) | 1114 | if (x < m_regionWidth && y < m_regionHeight) |
1101 | { | 1115 | { |
1102 | if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight)) | 1116 | if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight)) |
1103 | { | 1117 | { |
1104 | resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); | 1118 | resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + |
1119 | resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); | ||
1105 | } | 1120 | } |
1106 | else | 1121 | else |
1107 | { | 1122 | { |
1108 | resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x]; | 1123 | resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x]; |
1109 | } | 1124 | } |
1110 | } | 1125 | } |
1111 | } | 1126 | } |
1112 | |||
1113 | } | 1127 | } |
1114 | //Flatten out the array | 1128 | //Flatten out the array |
1115 | int i = 0; | 1129 | int i = 0; |
@@ -1119,7 +1133,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1119 | { | 1133 | { |
1120 | if (resultarr2[y, x] <= 0) | 1134 | if (resultarr2[y, x] <= 0) |
1121 | returnarr[i] = 0.0000001f; | 1135 | returnarr[i] = 0.0000001f; |
1122 | else | 1136 | else |
1123 | returnarr[i] = resultarr2[y, x]; | 1137 | returnarr[i] = resultarr2[y, x]; |
1124 | 1138 | ||
1125 | i++; | 1139 | i++; |
@@ -1127,8 +1141,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1127 | } | 1141 | } |
1128 | 1142 | ||
1129 | return returnarr; | 1143 | return returnarr; |
1130 | |||
1131 | } | 1144 | } |
1145 | |||
1132 | public override void SetTerrain(float[] heightMap) | 1146 | public override void SetTerrain(float[] heightMap) |
1133 | { | 1147 | { |
1134 | // this._heightmap[i] = (double)heightMap[i]; | 1148 | // this._heightmap[i] = (double)heightMap[i]; |
@@ -1137,8 +1151,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1137 | 1151 | ||
1138 | const uint heightmapWidth = m_regionWidth + 2; | 1152 | const uint heightmapWidth = m_regionWidth + 2; |
1139 | const uint heightmapHeight = m_regionHeight + 2; | 1153 | const uint heightmapHeight = m_regionHeight + 2; |
1140 | const uint heightmapWidthSamples = 2 * m_regionWidth + 2; | 1154 | const uint heightmapWidthSamples = 2*m_regionWidth + 2; |
1141 | const uint heightmapHeightSamples = 2 * m_regionHeight + 2; | 1155 | const uint heightmapHeightSamples = 2*m_regionHeight + 2; |
1142 | const float scale = 1.0f; | 1156 | const float scale = 1.0f; |
1143 | const float offset = 0.0f; | 1157 | const float offset = 0.0f; |
1144 | const float thickness = 2.0f; | 1158 | const float thickness = 2.0f; |
@@ -1166,7 +1180,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1166 | } | 1180 | } |
1167 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 1181 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
1168 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, | 1182 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, |
1169 | (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, offset, thickness, wrap); | 1183 | (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, |
1184 | offset, thickness, wrap); | ||
1170 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); | 1185 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); |
1171 | LandGeom = d.CreateHeightfield(space, HeightmapData, 1); | 1186 | LandGeom = d.CreateHeightfield(space, HeightmapData, 1); |
1172 | geom_name_map[LandGeom] = "Terrain"; | 1187 | geom_name_map[LandGeom] = "Terrain"; |
@@ -1193,7 +1208,4 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1193 | { | 1208 | { |
1194 | } | 1209 | } |
1195 | } | 1210 | } |
1196 | 1211 | } \ No newline at end of file | |
1197 | |||
1198 | |||
1199 | } | ||