diff options
Diffstat (limited to 'OpenSim/Region/PhysicsModules/Ode/OdeScene.cs')
-rw-r--r-- | OpenSim/Region/PhysicsModules/Ode/OdeScene.cs | 980 |
1 files changed, 202 insertions, 778 deletions
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs index 8cc7f28..d15568e 100644 --- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs +++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs | |||
@@ -31,31 +31,24 @@ | |||
31 | // or application thread stack may just blowup | 31 | // or application thread stack may just blowup |
32 | // see RayCast(ODERayCastRequest req) | 32 | // see RayCast(ODERayCastRequest req) |
33 | 33 | ||
34 | //#define USE_DRAWSTUFF | ||
35 | //#define SPAM | ||
36 | |||
37 | using System; | 34 | using System; |
38 | using System.Collections.Generic; | 35 | using System.Collections.Generic; |
39 | using System.Diagnostics; | 36 | using System.Diagnostics; |
40 | using System.IO; | 37 | using System.IO; |
41 | using System.Linq; | 38 | using System.Linq; |
42 | using System.Reflection; | 39 | using System.Reflection; |
40 | using System.Runtime.ExceptionServices; | ||
43 | using System.Runtime.InteropServices; | 41 | using System.Runtime.InteropServices; |
44 | using System.Threading; | 42 | using System.Threading; |
45 | using log4net; | 43 | using log4net; |
46 | using Nini.Config; | 44 | using Nini.Config; |
47 | using Mono.Addins; | 45 | using Mono.Addins; |
48 | using Ode.NET; | ||
49 | using OpenMetaverse; | 46 | using OpenMetaverse; |
50 | #if USE_DRAWSTUFF | ||
51 | using Drawstuff.NET; | ||
52 | #endif | ||
53 | using OpenSim.Framework; | 47 | using OpenSim.Framework; |
54 | using OpenSim.Region.PhysicsModules.SharedBase; | 48 | using OpenSim.Region.PhysicsModules.SharedBase; |
55 | using OpenSim.Region.Framework.Scenes; | 49 | using OpenSim.Region.Framework.Scenes; |
56 | using OpenSim.Region.Framework.Interfaces; | 50 | using OpenSim.Region.Framework.Interfaces; |
57 | 51 | ||
58 | |||
59 | namespace OpenSim.Region.PhysicsModule.ODE | 52 | namespace OpenSim.Region.PhysicsModule.ODE |
60 | { | 53 | { |
61 | public enum StatusIndicators : int | 54 | public enum StatusIndicators : int |
@@ -65,16 +58,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
65 | End = 2 | 58 | End = 2 |
66 | } | 59 | } |
67 | 60 | ||
68 | // public struct sCollisionData | ||
69 | // { | ||
70 | // public uint ColliderLocalId; | ||
71 | // public uint CollidedWithLocalId; | ||
72 | // public int NumberOfCollisions; | ||
73 | // public int CollisionType; | ||
74 | // public int StatusIndicator; | ||
75 | // public int lastframe; | ||
76 | // } | ||
77 | |||
78 | [Flags] | 61 | [Flags] |
79 | public enum CollisionCategories : int | 62 | public enum CollisionCategories : int |
80 | { | 63 | { |
@@ -111,11 +94,9 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
111 | Rubber = 6 | 94 | Rubber = 6 |
112 | } | 95 | } |
113 | 96 | ||
114 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")] | 97 | public class OdeScene : PhysicsScene |
115 | public class OdeScene : PhysicsScene, INonSharedRegionModule | ||
116 | { | 98 | { |
117 | private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString()); | 99 | private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString()); |
118 | private bool m_Enabled = false; | ||
119 | 100 | ||
120 | // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); | 101 | // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); |
121 | 102 | ||
@@ -144,6 +125,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
144 | /// .../opensim/bin/libode-x86_64.so(_Z12dCollideCCTLP6dxGeomS0_iP12dContactGeomi+0x92) [0x7f03b44bcf82] | 125 | /// .../opensim/bin/libode-x86_64.so(_Z12dCollideCCTLP6dxGeomS0_iP12dContactGeomi+0x92) [0x7f03b44bcf82] |
145 | /// </remarks> | 126 | /// </remarks> |
146 | internal static Object UniversalColliderSyncObject = new Object(); | 127 | internal static Object UniversalColliderSyncObject = new Object(); |
128 | internal static Object SimulationLock = new Object(); | ||
147 | 129 | ||
148 | /// <summary> | 130 | /// <summary> |
149 | /// Is stats collecting enabled for this ODE scene? | 131 | /// Is stats collecting enabled for this ODE scene? |
@@ -276,8 +258,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
276 | 258 | ||
277 | private Random fluidRandomizer = new Random(Environment.TickCount); | 259 | private Random fluidRandomizer = new Random(Environment.TickCount); |
278 | 260 | ||
279 | public bool m_suportCombine = true; | ||
280 | |||
281 | private uint m_regionWidth = Constants.RegionSize; | 261 | private uint m_regionWidth = Constants.RegionSize; |
282 | private uint m_regionHeight = Constants.RegionSize; | 262 | private uint m_regionHeight = Constants.RegionSize; |
283 | 263 | ||
@@ -293,11 +273,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
293 | 273 | ||
294 | private float contactsurfacelayer = 0.001f; | 274 | private float contactsurfacelayer = 0.001f; |
295 | 275 | ||
296 | private int worldHashspaceLow = -4; | 276 | private int HashspaceLow = -5; |
297 | private int worldHashspaceHigh = 128; | 277 | private int HashspaceHigh = 12; |
298 | |||
299 | private int smallHashspaceLow = -4; | ||
300 | private int smallHashspaceHigh = 66; | ||
301 | 278 | ||
302 | private float waterlevel = 0f; | 279 | private float waterlevel = 0f; |
303 | private int framecount = 0; | 280 | private int framecount = 0; |
@@ -335,7 +312,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
335 | public bool IsAvCapsuleTilted { get; private set; } | 312 | public bool IsAvCapsuleTilted { get; private set; } |
336 | 313 | ||
337 | private float avDensity = 80f; | 314 | private float avDensity = 80f; |
338 | // private float avHeightFudgeFactor = 0.52f; | ||
339 | private float avMovementDivisorWalk = 1.3f; | 315 | private float avMovementDivisorWalk = 1.3f; |
340 | private float avMovementDivisorRun = 0.8f; | 316 | private float avMovementDivisorRun = 0.8f; |
341 | private float minimumGroundFlightOffset = 3f; | 317 | private float minimumGroundFlightOffset = 3f; |
@@ -356,13 +332,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
356 | public float bodyPIDD = 35f; | 332 | public float bodyPIDD = 35f; |
357 | public float bodyPIDG = 25; | 333 | public float bodyPIDG = 25; |
358 | 334 | ||
359 | public int geomCrossingFailuresBeforeOutofbounds = 5; | ||
360 | |||
361 | public float bodyMotorJointMaxforceTensor = 2; | ||
362 | |||
363 | public int bodyFramesAutoDisable = 20; | 335 | public int bodyFramesAutoDisable = 20; |
364 | 336 | ||
365 | private float[] _watermap; | ||
366 | private bool m_filterCollisions = true; | 337 | private bool m_filterCollisions = true; |
367 | 338 | ||
368 | private d.NearCallback nearCallback; | 339 | private d.NearCallback nearCallback; |
@@ -473,31 +444,21 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
473 | private d.Contact WaterContact; | 444 | private d.Contact WaterContact; |
474 | private d.Contact[,] m_materialContacts; | 445 | private d.Contact[,] m_materialContacts; |
475 | 446 | ||
476 | //Ckrinke: Comment out until used. We declare it, initialize it, but do not use it | ||
477 | //Ckrinke private int m_randomizeWater = 200; | ||
478 | private int m_physicsiterations = 10; | 447 | private int m_physicsiterations = 10; |
479 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 448 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
480 | private readonly PhysicsActor PANull = new NullPhysicsActor(); | 449 | private readonly PhysicsActor PANull = new NullPhysicsActor(); |
481 | // private float step_time = 0.0f; | 450 | private float step_time = 0.0f; |
482 | //Ckrinke: Comment out until used. We declare it, initialize it, but do not use it | ||
483 | //Ckrinke private int ms = 0; | ||
484 | public IntPtr world; | 451 | public IntPtr world; |
485 | //private bool returncollisions = false; | ||
486 | // private uint obj1LocalID = 0; | ||
487 | private uint obj2LocalID = 0; | 452 | private uint obj2LocalID = 0; |
488 | //private int ctype = 0; | ||
489 | private OdeCharacter cc1; | 453 | private OdeCharacter cc1; |
490 | private OdePrim cp1; | 454 | private OdePrim cp1; |
491 | private OdeCharacter cc2; | 455 | private OdeCharacter cc2; |
492 | private OdePrim cp2; | 456 | private OdePrim cp2; |
493 | private int p1ExpectedPoints = 0; | 457 | private int p1ExpectedPoints = 0; |
494 | private int p2ExpectedPoints = 0; | 458 | private int p2ExpectedPoints = 0; |
495 | //private int cStartStop = 0; | ||
496 | //private string cDictKey = ""; | ||
497 | 459 | ||
498 | public IntPtr space; | 460 | public IntPtr space; |
499 | 461 | ||
500 | //private IntPtr tmpSpace; | ||
501 | // split static geometry collision handling into spaces of 30 meters | 462 | // split static geometry collision handling into spaces of 30 meters |
502 | public IntPtr[,] staticPrimspace; | 463 | public IntPtr[,] staticPrimspace; |
503 | 464 | ||
@@ -535,88 +496,37 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
535 | 496 | ||
536 | private ODERayCastRequestManager m_rayCastManager; | 497 | private ODERayCastRequestManager m_rayCastManager; |
537 | 498 | ||
499 | public Scene m_frameWorkScene = null; | ||
538 | 500 | ||
539 | #region INonSharedRegionModule | 501 | public OdeScene(Scene pscene, IConfigSource psourceconfig, string pname, string pversion) |
540 | public string Name | ||
541 | { | ||
542 | get { return "OpenDynamicsEngine"; } | ||
543 | } | ||
544 | |||
545 | public Type ReplaceableInterface | ||
546 | { | ||
547 | get { return null; } | ||
548 | } | ||
549 | |||
550 | public void Initialise(IConfigSource source) | ||
551 | { | ||
552 | // TODO: Move this out of Startup | ||
553 | IConfig config = source.Configs["Startup"]; | ||
554 | if (config != null) | ||
555 | { | ||
556 | string physics = config.GetString("physics", string.Empty); | ||
557 | if (physics == Name) | ||
558 | { | ||
559 | m_Enabled = true; | ||
560 | m_config = source; | ||
561 | |||
562 | // We do this so that OpenSimulator on Windows loads the correct native ODE library depending on whether | ||
563 | // it's running as a 32-bit process or a 64-bit one. By invoking LoadLibary here, later DLLImports | ||
564 | // will find it already loaded later on. | ||
565 | // | ||
566 | // This isn't necessary for other platforms (e.g. Mac OSX and Linux) since the DLL used can be | ||
567 | // controlled in Ode.NET.dll.config | ||
568 | if (Util.IsWindows()) | ||
569 | Util.LoadArchSpecificWindowsDll("ode.dll"); | ||
570 | |||
571 | // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to | ||
572 | // http://opensimulator.org/mantis/view.php?id=2750). | ||
573 | d.InitODE(); | ||
574 | |||
575 | } | ||
576 | } | ||
577 | |||
578 | } | ||
579 | |||
580 | public void Close() | ||
581 | { | ||
582 | } | ||
583 | |||
584 | public void AddRegion(Scene scene) | ||
585 | { | 502 | { |
586 | if (!m_Enabled) | 503 | m_config = psourceconfig; |
587 | return; | 504 | m_frameWorkScene = pscene; |
588 | 505 | ||
589 | EngineType = Name; | 506 | EngineType = pname; |
590 | PhysicsSceneName = EngineType + "/" + scene.RegionInfo.RegionName; | 507 | PhysicsSceneName = EngineType + "/" + pscene.RegionInfo.RegionName; |
508 | EngineName = pname + " " + pversion; | ||
591 | 509 | ||
592 | scene.RegisterModuleInterface<PhysicsScene>(this); | 510 | pscene.RegisterModuleInterface<PhysicsScene>(this); |
593 | Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ); | 511 | Vector3 extent = new Vector3(pscene.RegionInfo.RegionSizeX, pscene.RegionInfo.RegionSizeY, pscene.RegionInfo.RegionSizeZ); |
594 | Initialise(extent); | 512 | Initialise(extent); |
595 | InitialiseFromConfig(m_config); | 513 | InitialiseFromConfig(m_config); |
596 | 514 | ||
597 | // This may not be that good since terrain may not be avaiable at this point | 515 | // This may not be that good since terrain may not be avaiable at this point |
598 | base.Initialise(scene.PhysicsRequestAsset, | 516 | base.Initialise(pscene.PhysicsRequestAsset, |
599 | (scene.Heightmap != null ? scene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), | 517 | (pscene.Heightmap != null ? pscene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), |
600 | (float)scene.RegionInfo.RegionSettings.WaterHeight); | 518 | (float)pscene.RegionInfo.RegionSettings.WaterHeight); |
601 | 519 | ||
602 | } | 520 | } |
603 | 521 | ||
604 | public void RemoveRegion(Scene scene) | 522 | public void RegionLoaded() |
605 | { | 523 | { |
606 | if (!m_Enabled) | 524 | mesher = m_frameWorkScene.RequestModuleInterface<IMesher>(); |
607 | return; | ||
608 | } | ||
609 | |||
610 | public void RegionLoaded(Scene scene) | ||
611 | { | ||
612 | if (!m_Enabled) | ||
613 | return; | ||
614 | |||
615 | mesher = scene.RequestModuleInterface<IMesher>(); | ||
616 | if (mesher == null) | 525 | if (mesher == null) |
617 | m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName); | 526 | m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName); |
527 | |||
528 | m_frameWorkScene.PhysicsEnabled = true; | ||
618 | } | 529 | } |
619 | #endregion | ||
620 | 530 | ||
621 | /// <summary> | 531 | /// <summary> |
622 | /// Initiailizes the scene | 532 | /// Initiailizes the scene |
@@ -625,16 +535,12 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
625 | /// </summary> | 535 | /// </summary> |
626 | private void Initialise(Vector3 regionExtent) | 536 | private void Initialise(Vector3 regionExtent) |
627 | { | 537 | { |
628 | WorldExtents.X = regionExtent.X; | 538 | WorldExtents.X = regionExtent.X; |
629 | m_regionWidth = (uint)regionExtent.X; | 539 | m_regionWidth = (uint)regionExtent.X; |
630 | WorldExtents.Y = regionExtent.Y; | 540 | WorldExtents.Y = regionExtent.Y; |
631 | m_regionHeight = (uint)regionExtent.Y; | 541 | m_regionHeight = (uint)regionExtent.Y; |
632 | 542 | ||
633 | m_suportCombine = false; | ||
634 | |||
635 | nearCallback = near; | 543 | nearCallback = near; |
636 | triCallback = TriCallback; | ||
637 | triArrayCallback = TriArrayCallback; | ||
638 | m_rayCastManager = new ODERayCastRequestManager(this); | 544 | m_rayCastManager = new ODERayCastRequestManager(this); |
639 | 545 | ||
640 | // Create the world and the first space | 546 | // Create the world and the first space |
@@ -644,33 +550,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
644 | contactgroup = d.JointGroupCreate(0); | 550 | contactgroup = d.JointGroupCreate(0); |
645 | 551 | ||
646 | d.WorldSetAutoDisableFlag(world, false); | 552 | d.WorldSetAutoDisableFlag(world, false); |
647 | |||
648 | #if USE_DRAWSTUFF | ||
649 | Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization)); | ||
650 | viewthread.Start(); | ||
651 | #endif | ||
652 | |||
653 | // _watermap = new float[258 * 258]; | ||
654 | |||
655 | // Zero out the prim spaces array (we split our space into smaller spaces so | ||
656 | // we can hit test less. | ||
657 | } | 553 | } |
658 | 554 | ||
659 | #if USE_DRAWSTUFF | ||
660 | public void startvisualization(object o) | ||
661 | { | ||
662 | ds.Functions fn; | ||
663 | fn.version = ds.VERSION; | ||
664 | fn.start = new ds.CallbackFunction(start); | ||
665 | fn.step = new ds.CallbackFunction(step); | ||
666 | fn.command = new ds.CallbackFunction(command); | ||
667 | fn.stop = null; | ||
668 | fn.path_to_textures = "./textures"; | ||
669 | string[] args = new string[0]; | ||
670 | ds.SimulationLoop(args.Length, args, 352, 288, ref fn); | ||
671 | } | ||
672 | #endif | ||
673 | |||
674 | // Initialize from configs | 555 | // Initialize from configs |
675 | private void InitialiseFromConfig(IConfigSource config) | 556 | private void InitialiseFromConfig(IConfigSource config) |
676 | { | 557 | { |
@@ -679,18 +560,9 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
679 | m_config = config; | 560 | m_config = config; |
680 | // Defaults | 561 | // Defaults |
681 | 562 | ||
682 | if (Environment.OSVersion.Platform == PlatformID.Unix) | 563 | avPIDD = 2200.0f; |
683 | { | 564 | avPIDP = 900.0f; |
684 | avPIDD = 3200.0f; | 565 | avStandupTensor = 550000f; |
685 | avPIDP = 1400.0f; | ||
686 | avStandupTensor = 2000000f; | ||
687 | } | ||
688 | else | ||
689 | { | ||
690 | avPIDD = 2200.0f; | ||
691 | avPIDP = 900.0f; | ||
692 | avStandupTensor = 550000f; | ||
693 | } | ||
694 | 566 | ||
695 | int contactsPerCollision = 80; | 567 | int contactsPerCollision = 80; |
696 | 568 | ||
@@ -714,12 +586,10 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
714 | avatarTerminalVelocity, AvatarTerminalVelocity); | 586 | avatarTerminalVelocity, AvatarTerminalVelocity); |
715 | } | 587 | } |
716 | 588 | ||
717 | worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4); | 589 | HashspaceLow = physicsconfig.GetInt("world_hashspace_level_low", -5); |
718 | worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128); | 590 | HashspaceHigh = physicsconfig.GetInt("world_hashspace_level_high", 12); |
719 | 591 | ||
720 | metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f); | 592 | metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f); |
721 | smallHashspaceLow = physicsconfig.GetInt("small_hashspace_size_low", -4); | ||
722 | smallHashspaceHigh = physicsconfig.GetInt("small_hashspace_size_high", 66); | ||
723 | 593 | ||
724 | contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", 0.001f); | 594 | contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", 0.001f); |
725 | 595 | ||
@@ -738,7 +608,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
738 | mAvatarObjectContactBounce = physicsconfig.GetFloat("m_avatarobjectcontact_bounce", 0.1f); | 608 | mAvatarObjectContactBounce = physicsconfig.GetFloat("m_avatarobjectcontact_bounce", 0.1f); |
739 | 609 | ||
740 | ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); | 610 | ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); |
741 | m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", 10); | 611 | m_physicsiterations = physicsconfig.GetInt("world_solver_iterations", 10); |
742 | 612 | ||
743 | avDensity = physicsconfig.GetFloat("av_density", 80f); | 613 | avDensity = physicsconfig.GetFloat("av_density", 80f); |
744 | // avHeightFudgeFactor = physicsconfig.GetFloat("av_height_fudge_factor", 0.52f); | 614 | // avHeightFudgeFactor = physicsconfig.GetFloat("av_height_fudge_factor", 0.52f); |
@@ -754,7 +624,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
754 | 624 | ||
755 | geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 5); | 625 | geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 5); |
756 | geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); | 626 | geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); |
757 | geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); | ||
758 | 627 | ||
759 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); | 628 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); |
760 | bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); | 629 | bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); |
@@ -767,29 +636,16 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
767 | meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f); | 636 | meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f); |
768 | MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f); | 637 | MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f); |
769 | m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false); | 638 | m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false); |
770 | |||
771 | |||
772 | 639 | ||
773 | if (Environment.OSVersion.Platform == PlatformID.Unix) | 640 | avPIDD = physicsconfig.GetFloat("av_pid_derivative", 2200.0f); |
774 | { | 641 | avPIDP = physicsconfig.GetFloat("av_pid_proportional", 900.0f); |
775 | avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", 2200.0f); | 642 | avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor", 550000f); |
776 | avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", 900.0f); | ||
777 | avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_linux", 550000f); | ||
778 | bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_linux", 5f); | ||
779 | } | ||
780 | else | ||
781 | { | ||
782 | avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", 2200.0f); | ||
783 | avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", 900.0f); | ||
784 | avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_win", 550000f); | ||
785 | bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_win", 5f); | ||
786 | } | ||
787 | 643 | ||
788 | physics_logging = physicsconfig.GetBoolean("physics_logging", false); | 644 | physics_logging = physicsconfig.GetBoolean("physics_logging", false); |
789 | physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0); | 645 | physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0); |
790 | physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false); | 646 | physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false); |
791 | 647 | ||
792 | m_NINJA_physics_joints_enabled = physicsconfig.GetBoolean("use_NINJA_physics_joints", false); | 648 | // m_NINJA_physics_joints_enabled = physicsconfig.GetBoolean("use_NINJA_physics_joints", false); |
793 | minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", 3f); | 649 | minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", 3f); |
794 | maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", 10000.01f); | 650 | maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", 10000.01f); |
795 | } | 651 | } |
@@ -812,17 +668,15 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
812 | if (spaceGridMaxY > 24) | 668 | if (spaceGridMaxY > 24) |
813 | { | 669 | { |
814 | spaceGridMaxY = 24; | 670 | spaceGridMaxY = 24; |
815 | spacesPerMeterY = spaceGridMaxY / WorldExtents.Y ; | 671 | spacesPerMeterY = spaceGridMaxY / WorldExtents.Y; |
816 | } | 672 | } |
817 | 673 | ||
818 | staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY]; | 674 | staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY]; |
819 | 675 | ||
820 | // make this index limits | 676 | // make this index limits |
821 | spaceGridMaxX--; | 677 | spaceGridMaxX--; |
822 | spaceGridMaxY--; | 678 | spaceGridMaxY--; |
823 | 679 | ||
824 | |||
825 | |||
826 | // Centeral contact friction and bounce | 680 | // Centeral contact friction and bounce |
827 | // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why | 681 | // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why |
828 | // an avatar falls through in Z but not in X or Y when walking on a prim. | 682 | // an avatar falls through in Z but not in X or Y when walking on a prim. |
@@ -984,7 +838,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
984 | m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f; | 838 | m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f; |
985 | m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f; | 839 | m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f; |
986 | 840 | ||
987 | d.HashSpaceSetLevels(space, worldHashspaceLow, worldHashspaceHigh); | 841 | d.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh); |
988 | 842 | ||
989 | // Set the gravity,, don't disable things automatically (we set it explicitly on some things) | 843 | // Set the gravity,, don't disable things automatically (we set it explicitly on some things) |
990 | 844 | ||
@@ -997,9 +851,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
997 | d.WorldSetLinearDampingThreshold(world, 256f); | 851 | d.WorldSetLinearDampingThreshold(world, 256f); |
998 | d.WorldSetMaxAngularSpeed(world, 256f); | 852 | d.WorldSetMaxAngularSpeed(world, 256f); |
999 | 853 | ||
1000 | // Set how many steps we go without running collision testing | ||
1001 | // This is in addition to the step size. | ||
1002 | // Essentially Steps * m_physicsiterations | ||
1003 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); | 854 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); |
1004 | //d.WorldSetContactMaxCorrectingVel(world, 1000.0f); | 855 | //d.WorldSetContactMaxCorrectingVel(world, 1000.0f); |
1005 | 856 | ||
@@ -1014,22 +865,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1014 | _worldInitialized = true; | 865 | _worldInitialized = true; |
1015 | } | 866 | } |
1016 | 867 | ||
1017 | // internal void waitForSpaceUnlock(IntPtr space) | ||
1018 | // { | ||
1019 | // //if (space != IntPtr.Zero) | ||
1020 | // //while (d.SpaceLockQuery(space)) { } // Wait and do nothing | ||
1021 | // } | ||
1022 | |||
1023 | // /// <summary> | ||
1024 | // /// Debug space message for printing the space that a prim/avatar is in. | ||
1025 | // /// </summary> | ||
1026 | // /// <param name="pos"></param> | ||
1027 | // /// <returns>Returns which split up space the given position is in.</returns> | ||
1028 | // public string whichspaceamIin(Vector3 pos) | ||
1029 | // { | ||
1030 | // return calculateSpaceForGeom(pos).ToString(); | ||
1031 | // } | ||
1032 | |||
1033 | #region Collision Detection | 868 | #region Collision Detection |
1034 | 869 | ||
1035 | /// <summary> | 870 | /// <summary> |
@@ -1042,7 +877,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1042 | /// <param name='contactsArray'></param> | 877 | /// <param name='contactsArray'></param> |
1043 | /// <param name='contactGeomSize'></param> | 878 | /// <param name='contactGeomSize'></param> |
1044 | private int CollideGeoms( | 879 | private int CollideGeoms( |
1045 | IntPtr geom1, IntPtr geom2, int maxContacts, Ode.NET.d.ContactGeom[] contactsArray, int contactGeomSize) | 880 | IntPtr geom1, IntPtr geom2, int maxContacts, d.ContactGeom[] contactsArray, int contactGeomSize) |
1046 | { | 881 | { |
1047 | int count; | 882 | int count; |
1048 | 883 | ||
@@ -1113,7 +948,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1113 | { | 948 | { |
1114 | if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) | 949 | if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) |
1115 | return; | 950 | return; |
1116 | 951 | ||
1117 | // Separating static prim geometry spaces. | 952 | // Separating static prim geometry spaces. |
1118 | // We'll be calling near recursivly if one | 953 | // We'll be calling near recursivly if one |
1119 | // of them is a space to find all of the | 954 | // of them is a space to find all of the |
@@ -1155,12 +990,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1155 | name2 = "null"; | 990 | name2 = "null"; |
1156 | } | 991 | } |
1157 | 992 | ||
1158 | //if (id == d.GeomClassId.TriMeshClass) | ||
1159 | //{ | ||
1160 | // m_log.InfoFormat("near: A collision was detected between {1} and {2}", 0, name1, name2); | ||
1161 | //m_log.Debug("near: A collision was detected between {1} and {2}", 0, name1, name2); | ||
1162 | //} | ||
1163 | |||
1164 | // Figure out how many contact points we have | 993 | // Figure out how many contact points we have |
1165 | int count = 0; | 994 | int count = 0; |
1166 | 995 | ||
@@ -1175,7 +1004,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1175 | if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) | 1004 | if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) |
1176 | return; | 1005 | return; |
1177 | 1006 | ||
1178 | count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); | 1007 | count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.unmanagedSizeOf); |
1179 | 1008 | ||
1180 | // All code after this is only relevant if we have any collisions | 1009 | // All code after this is only relevant if we have any collisions |
1181 | if (count <= 0) | 1010 | if (count <= 0) |
@@ -1198,10 +1027,10 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1198 | 1027 | ||
1199 | PhysicsActor p1; | 1028 | PhysicsActor p1; |
1200 | PhysicsActor p2; | 1029 | PhysicsActor p2; |
1201 | 1030 | ||
1202 | p1ExpectedPoints = 0; | 1031 | p1ExpectedPoints = 0; |
1203 | p2ExpectedPoints = 0; | 1032 | p2ExpectedPoints = 0; |
1204 | 1033 | ||
1205 | if (!actor_name_map.TryGetValue(g1, out p1)) | 1034 | if (!actor_name_map.TryGetValue(g1, out p1)) |
1206 | { | 1035 | { |
1207 | p1 = PANull; | 1036 | p1 = PANull; |
@@ -1238,7 +1067,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1238 | IntPtr joint; | 1067 | IntPtr joint; |
1239 | // If we're colliding with terrain, use 'TerrainContact' instead of contact. | 1068 | // If we're colliding with terrain, use 'TerrainContact' instead of contact. |
1240 | // allows us to have different settings | 1069 | // allows us to have different settings |
1241 | 1070 | ||
1242 | // We only need to test p2 for 'jump crouch purposes' | 1071 | // We only need to test p2 for 'jump crouch purposes' |
1243 | if (p2 is OdeCharacter && p1.PhysicsActorType == (int)ActorTypes.Prim) | 1072 | if (p2 is OdeCharacter && p1.PhysicsActorType == (int)ActorTypes.Prim) |
1244 | { | 1073 | { |
@@ -1252,7 +1081,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1252 | { | 1081 | { |
1253 | p2.IsColliding = true; | 1082 | p2.IsColliding = true; |
1254 | } | 1083 | } |
1255 | 1084 | ||
1256 | //if ((framecount % m_returncollisions) == 0) | 1085 | //if ((framecount % m_returncollisions) == 0) |
1257 | 1086 | ||
1258 | switch (p1.PhysicsActorType) | 1087 | switch (p1.PhysicsActorType) |
@@ -1279,110 +1108,9 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1279 | // we don't want prim or avatar to explode | 1108 | // we don't want prim or avatar to explode |
1280 | 1109 | ||
1281 | #region InterPenetration Handling - Unintended physics explosions | 1110 | #region InterPenetration Handling - Unintended physics explosions |
1282 | # region disabled code1 | ||
1283 | 1111 | ||
1284 | if (curContact.depth >= 0.08f) | 1112 | if (curContact.depth >= 0.08f) |
1285 | { | 1113 | { |
1286 | //This is disabled at the moment only because it needs more tweaking | ||
1287 | //It will eventually be uncommented | ||
1288 | /* | ||
1289 | if (contact.depth >= 1.00f) | ||
1290 | { | ||
1291 | //m_log.Debug("[PHYSICS]: " + contact.depth.ToString()); | ||
1292 | } | ||
1293 | |||
1294 | //If you interpenetrate a prim with an agent | ||
1295 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent && | ||
1296 | p1.PhysicsActorType == (int) ActorTypes.Prim) || | ||
1297 | (p1.PhysicsActorType == (int) ActorTypes.Agent && | ||
1298 | p2.PhysicsActorType == (int) ActorTypes.Prim)) | ||
1299 | { | ||
1300 | |||
1301 | //contact.depth = contact.depth * 4.15f; | ||
1302 | /* | ||
1303 | if (p2.PhysicsActorType == (int) ActorTypes.Agent) | ||
1304 | { | ||
1305 | p2.CollidingObj = true; | ||
1306 | contact.depth = 0.003f; | ||
1307 | p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); | ||
1308 | OdeCharacter character = (OdeCharacter) p2; | ||
1309 | character.SetPidStatus(true); | ||
1310 | contact.pos = new d.Vector3(contact.pos.X + (p1.Size.X / 2), contact.pos.Y + (p1.Size.Y / 2), contact.pos.Z + (p1.Size.Z / 2)); | ||
1311 | |||
1312 | } | ||
1313 | else | ||
1314 | { | ||
1315 | |||
1316 | //contact.depth = 0.0000000f; | ||
1317 | } | ||
1318 | if (p1.PhysicsActorType == (int) ActorTypes.Agent) | ||
1319 | { | ||
1320 | |||
1321 | p1.CollidingObj = true; | ||
1322 | contact.depth = 0.003f; | ||
1323 | p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f); | ||
1324 | contact.pos = new d.Vector3(contact.pos.X + (p2.Size.X / 2), contact.pos.Y + (p2.Size.Y / 2), contact.pos.Z + (p2.Size.Z / 2)); | ||
1325 | OdeCharacter character = (OdeCharacter)p1; | ||
1326 | character.SetPidStatus(true); | ||
1327 | } | ||
1328 | else | ||
1329 | { | ||
1330 | |||
1331 | //contact.depth = 0.0000000f; | ||
1332 | } | ||
1333 | |||
1334 | |||
1335 | |||
1336 | } | ||
1337 | */ | ||
1338 | // If you interpenetrate a prim with another prim | ||
1339 | /* | ||
1340 | if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim) | ||
1341 | { | ||
1342 | #region disabledcode2 | ||
1343 | //OdePrim op1 = (OdePrim)p1; | ||
1344 | //OdePrim op2 = (OdePrim)p2; | ||
1345 | //op1.m_collisionscore++; | ||
1346 | //op2.m_collisionscore++; | ||
1347 | |||
1348 | //if (op1.m_collisionscore > 8000 || op2.m_collisionscore > 8000) | ||
1349 | //{ | ||
1350 | //op1.m_taintdisable = true; | ||
1351 | //AddPhysicsActorTaint(p1); | ||
1352 | //op2.m_taintdisable = true; | ||
1353 | //AddPhysicsActorTaint(p2); | ||
1354 | //} | ||
1355 | |||
1356 | //if (contact.depth >= 0.25f) | ||
1357 | //{ | ||
1358 | // Don't collide, one or both prim will expld. | ||
1359 | |||
1360 | //op1.m_interpenetrationcount++; | ||
1361 | //op2.m_interpenetrationcount++; | ||
1362 | //interpenetrations_before_disable = 200; | ||
1363 | //if (op1.m_interpenetrationcount >= interpenetrations_before_disable) | ||
1364 | //{ | ||
1365 | //op1.m_taintdisable = true; | ||
1366 | //AddPhysicsActorTaint(p1); | ||
1367 | //} | ||
1368 | //if (op2.m_interpenetrationcount >= interpenetrations_before_disable) | ||
1369 | //{ | ||
1370 | // op2.m_taintdisable = true; | ||
1371 | //AddPhysicsActorTaint(p2); | ||
1372 | //} | ||
1373 | |||
1374 | //contact.depth = contact.depth / 8f; | ||
1375 | //contact.normal = new d.Vector3(0, 0, 1); | ||
1376 | //} | ||
1377 | //if (op1.m_disabled || op2.m_disabled) | ||
1378 | //{ | ||
1379 | //Manually disabled objects stay disabled | ||
1380 | //contact.depth = 0f; | ||
1381 | //} | ||
1382 | #endregion | ||
1383 | } | ||
1384 | */ | ||
1385 | #endregion | ||
1386 | if (curContact.depth >= 1.00f) | 1114 | if (curContact.depth >= 1.00f) |
1387 | { | 1115 | { |
1388 | //m_log.Info("[P]: " + contact.depth.ToString()); | 1116 | //m_log.Info("[P]: " + contact.depth.ToString()); |
@@ -1432,7 +1160,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1432 | 1160 | ||
1433 | // Logic for collision handling | 1161 | // Logic for collision handling |
1434 | // Note, that if *all* contacts are skipped (VolumeDetect) | 1162 | // Note, that if *all* contacts are skipped (VolumeDetect) |
1435 | // The prim still detects (and forwards) collision events but | 1163 | // The prim still detects (and forwards) collision events but |
1436 | // appears to be phantom for the world | 1164 | // appears to be phantom for the world |
1437 | Boolean skipThisContact = false; | 1165 | Boolean skipThisContact = false; |
1438 | 1166 | ||
@@ -1507,10 +1235,10 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1507 | material = ((OdePrim) p2).m_material; | 1235 | material = ((OdePrim) p2).m_material; |
1508 | p2ExpectedPoints = ((OdePrim)p2).ExpectedCollisionContacts; | 1236 | p2ExpectedPoints = ((OdePrim)p2).ExpectedCollisionContacts; |
1509 | } | 1237 | } |
1510 | 1238 | ||
1511 | // Unnessesary because p1 is defined above | 1239 | // Unnessesary because p1 is defined above |
1512 | //if (p1 is OdePrim) | 1240 | //if (p1 is OdePrim) |
1513 | // { | 1241 | // { |
1514 | // p1ExpectedPoints = ((OdePrim)p1).ExpectedCollisionContacts; | 1242 | // p1ExpectedPoints = ((OdePrim)p1).ExpectedCollisionContacts; |
1515 | // } | 1243 | // } |
1516 | //m_log.DebugFormat("Material: {0}", material); | 1244 | //m_log.DebugFormat("Material: {0}", material); |
@@ -1622,7 +1350,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1622 | material = ((OdePrim)p2).m_material; | 1350 | material = ((OdePrim)p2).m_material; |
1623 | p2ExpectedPoints = ((OdePrim)p2).ExpectedCollisionContacts; | 1351 | p2ExpectedPoints = ((OdePrim)p2).ExpectedCollisionContacts; |
1624 | } | 1352 | } |
1625 | 1353 | ||
1626 | //m_log.DebugFormat("Material: {0}", material); | 1354 | //m_log.DebugFormat("Material: {0}", material); |
1627 | m_materialContacts[material, 0].geom = curContact; | 1355 | m_materialContacts[material, 0].geom = curContact; |
1628 | 1356 | ||
@@ -1642,7 +1370,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1642 | } | 1370 | } |
1643 | 1371 | ||
1644 | collision_accounting_events(p1, p2, maxDepthContact); | 1372 | collision_accounting_events(p1, p2, maxDepthContact); |
1645 | 1373 | ||
1646 | if (count > ((p1ExpectedPoints + p2ExpectedPoints) * 0.25) + (geomContactPointsStartthrottle)) | 1374 | if (count > ((p1ExpectedPoints + p2ExpectedPoints) * 0.25) + (geomContactPointsStartthrottle)) |
1647 | { | 1375 | { |
1648 | // If there are more then 3 contact points, it's likely | 1376 | // If there are more then 3 contact points, it's likely |
@@ -1678,31 +1406,13 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1678 | { | 1406 | { |
1679 | if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) | 1407 | if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) |
1680 | { | 1408 | { |
1681 | //contactGeom.depth *= .00005f; | 1409 | result = true; |
1682 | //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); | 1410 | break; |
1683 | // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); | ||
1684 | result = true; | ||
1685 | break; | ||
1686 | } | 1411 | } |
1687 | // else | ||
1688 | // { | ||
1689 | // //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); | ||
1690 | // } | ||
1691 | } | 1412 | } |
1692 | // else | 1413 | } |
1693 | // { | ||
1694 | // //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); | ||
1695 | // //int i = 0; | ||
1696 | // } | ||
1697 | } | ||
1698 | else if (at == ActorTypes.Prim) | 1414 | else if (at == ActorTypes.Prim) |
1699 | { | 1415 | { |
1700 | //d.AABB aabb1 = new d.AABB(); | ||
1701 | //d.AABB aabb2 = new d.AABB(); | ||
1702 | |||
1703 | //d.GeomGetAABB(contactGeom.g2, out aabb2); | ||
1704 | //d.GeomGetAABB(contactGeom.g1, out aabb1); | ||
1705 | //aabb1. | ||
1706 | if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f))) | 1416 | if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f))) |
1707 | { | 1417 | { |
1708 | if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) | 1418 | if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) |
@@ -1729,9 +1439,28 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1729 | obj2LocalID = 0; | 1439 | obj2LocalID = 0; |
1730 | //ctype = 0; | 1440 | //ctype = 0; |
1731 | //cStartStop = 0; | 1441 | //cStartStop = 0; |
1732 | if (!p2.SubscribedEvents() && !p1.SubscribedEvents()) | 1442 | // if (!p2.SubscribedEvents() && !p1.SubscribedEvents()) |
1443 | // return; | ||
1444 | bool p1events = p1.SubscribedEvents(); | ||
1445 | bool p2events = p2.SubscribedEvents(); | ||
1446 | |||
1447 | if (p1.IsVolumeDtc) | ||
1448 | p2events = false; | ||
1449 | if (p2.IsVolumeDtc) | ||
1450 | p1events = false; | ||
1451 | |||
1452 | if (!p2events && !p1events) | ||
1733 | return; | 1453 | return; |
1734 | 1454 | ||
1455 | Vector3 vel = Vector3.Zero; | ||
1456 | if (p2 != null && p2.IsPhysical) | ||
1457 | vel = p2.Velocity; | ||
1458 | |||
1459 | if (p1 != null && p1.IsPhysical) | ||
1460 | vel -= p1.Velocity; | ||
1461 | |||
1462 | contact.RelativeSpeed = Vector3.Dot(vel, contact.SurfaceNormal); | ||
1463 | |||
1735 | switch ((ActorTypes)p2.PhysicsActorType) | 1464 | switch ((ActorTypes)p2.PhysicsActorType) |
1736 | { | 1465 | { |
1737 | case ActorTypes.Agent: | 1466 | case ActorTypes.Agent: |
@@ -1744,14 +1473,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1744 | cc1 = (OdeCharacter)p1; | 1473 | cc1 = (OdeCharacter)p1; |
1745 | obj2LocalID = cc1.LocalID; | 1474 | obj2LocalID = cc1.LocalID; |
1746 | cc1.AddCollisionEvent(cc2.LocalID, contact); | 1475 | cc1.AddCollisionEvent(cc2.LocalID, contact); |
1747 | //ctype = (int)CollisionCategories.Character; | ||
1748 | |||
1749 | //if (cc1.CollidingObj) | ||
1750 | //cStartStop = (int)StatusIndicators.Generic; | ||
1751 | //else | ||
1752 | //cStartStop = (int)StatusIndicators.Start; | ||
1753 | |||
1754 | //returncollisions = true; | ||
1755 | break; | 1476 | break; |
1756 | 1477 | ||
1757 | case ActorTypes.Prim: | 1478 | case ActorTypes.Prim: |
@@ -1761,21 +1482,11 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1761 | obj2LocalID = cp1.LocalID; | 1482 | obj2LocalID = cp1.LocalID; |
1762 | cp1.AddCollisionEvent(cc2.LocalID, contact); | 1483 | cp1.AddCollisionEvent(cc2.LocalID, contact); |
1763 | } | 1484 | } |
1764 | //ctype = (int)CollisionCategories.Geom; | ||
1765 | |||
1766 | //if (cp1.CollidingObj) | ||
1767 | //cStartStop = (int)StatusIndicators.Generic; | ||
1768 | //else | ||
1769 | //cStartStop = (int)StatusIndicators.Start; | ||
1770 | |||
1771 | //returncollisions = true; | ||
1772 | break; | 1485 | break; |
1773 | 1486 | ||
1774 | case ActorTypes.Ground: | 1487 | case ActorTypes.Ground: |
1775 | case ActorTypes.Unknown: | 1488 | case ActorTypes.Unknown: |
1776 | obj2LocalID = 0; | 1489 | obj2LocalID = 0; |
1777 | //ctype = (int)CollisionCategories.Land; | ||
1778 | //returncollisions = true; | ||
1779 | break; | 1490 | break; |
1780 | } | 1491 | } |
1781 | 1492 | ||
@@ -1797,13 +1508,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1797 | cc1 = (OdeCharacter) p1; | 1508 | cc1 = (OdeCharacter) p1; |
1798 | obj2LocalID = cc1.LocalID; | 1509 | obj2LocalID = cc1.LocalID; |
1799 | cc1.AddCollisionEvent(cp2.LocalID, contact); | 1510 | cc1.AddCollisionEvent(cp2.LocalID, contact); |
1800 | //ctype = (int)CollisionCategories.Character; | ||
1801 | |||
1802 | //if (cc1.CollidingObj) | ||
1803 | //cStartStop = (int)StatusIndicators.Generic; | ||
1804 | //else | ||
1805 | //cStartStop = (int)StatusIndicators.Start; | ||
1806 | //returncollisions = true; | ||
1807 | } | 1511 | } |
1808 | break; | 1512 | break; |
1809 | case ActorTypes.Prim: | 1513 | case ActorTypes.Prim: |
@@ -1813,23 +1517,12 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1813 | cp1 = (OdePrim) p1; | 1517 | cp1 = (OdePrim) p1; |
1814 | obj2LocalID = cp1.LocalID; | 1518 | obj2LocalID = cp1.LocalID; |
1815 | cp1.AddCollisionEvent(cp2.LocalID, contact); | 1519 | cp1.AddCollisionEvent(cp2.LocalID, contact); |
1816 | //ctype = (int)CollisionCategories.Geom; | ||
1817 | |||
1818 | //if (cp1.CollidingObj) | ||
1819 | //cStartStop = (int)StatusIndicators.Generic; | ||
1820 | //else | ||
1821 | //cStartStop = (int)StatusIndicators.Start; | ||
1822 | |||
1823 | //returncollisions = true; | ||
1824 | } | 1520 | } |
1825 | break; | 1521 | break; |
1826 | 1522 | ||
1827 | case ActorTypes.Ground: | 1523 | case ActorTypes.Ground: |
1828 | case ActorTypes.Unknown: | 1524 | case ActorTypes.Unknown: |
1829 | obj2LocalID = 0; | 1525 | obj2LocalID = 0; |
1830 | //ctype = (int)CollisionCategories.Land; | ||
1831 | |||
1832 | //returncollisions = true; | ||
1833 | break; | 1526 | break; |
1834 | } | 1527 | } |
1835 | 1528 | ||
@@ -1837,80 +1530,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1837 | } | 1530 | } |
1838 | break; | 1531 | break; |
1839 | } | 1532 | } |
1840 | //if (returncollisions) | ||
1841 | //{ | ||
1842 | |||
1843 | //lock (m_storedCollisions) | ||
1844 | //{ | ||
1845 | //cDictKey = obj1LocalID.ToString() + obj2LocalID.ToString() + cStartStop.ToString() + ctype.ToString(); | ||
1846 | //if (m_storedCollisions.ContainsKey(cDictKey)) | ||
1847 | //{ | ||
1848 | //sCollisionData objd = m_storedCollisions[cDictKey]; | ||
1849 | //objd.NumberOfCollisions += 1; | ||
1850 | //objd.lastframe = framecount; | ||
1851 | //m_storedCollisions[cDictKey] = objd; | ||
1852 | //} | ||
1853 | //else | ||
1854 | //{ | ||
1855 | //sCollisionData objd = new sCollisionData(); | ||
1856 | //objd.ColliderLocalId = obj1LocalID; | ||
1857 | //objd.CollidedWithLocalId = obj2LocalID; | ||
1858 | //objd.CollisionType = ctype; | ||
1859 | //objd.NumberOfCollisions = 1; | ||
1860 | //objd.lastframe = framecount; | ||
1861 | //objd.StatusIndicator = cStartStop; | ||
1862 | //m_storedCollisions.Add(cDictKey, objd); | ||
1863 | //} | ||
1864 | //} | ||
1865 | // } | ||
1866 | } | ||
1867 | |||
1868 | private int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) | ||
1869 | { | ||
1870 | /* String name1 = null; | ||
1871 | String name2 = null; | ||
1872 | |||
1873 | if (!geom_name_map.TryGetValue(trimesh, out name1)) | ||
1874 | { | ||
1875 | name1 = "null"; | ||
1876 | } | ||
1877 | if (!geom_name_map.TryGetValue(refObject, out name2)) | ||
1878 | { | ||
1879 | name2 = "null"; | ||
1880 | } | ||
1881 | |||
1882 | m_log.InfoFormat("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2); | ||
1883 | */ | ||
1884 | return 1; | ||
1885 | } | ||
1886 | |||
1887 | private int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) | ||
1888 | { | ||
1889 | // String name1 = null; | ||
1890 | // String name2 = null; | ||
1891 | // | ||
1892 | // if (!geom_name_map.TryGetValue(trimesh, out name1)) | ||
1893 | // { | ||
1894 | // name1 = "null"; | ||
1895 | // } | ||
1896 | // | ||
1897 | // if (!geom_name_map.TryGetValue(refObject, out name2)) | ||
1898 | // { | ||
1899 | // name2 = "null"; | ||
1900 | // } | ||
1901 | |||
1902 | // m_log.InfoFormat("TriCallback: A collision was detected between {1} and {2}. Index was {3}", 0, name1, name2, triangleIndex); | ||
1903 | |||
1904 | d.Vector3 v0 = new d.Vector3(); | ||
1905 | d.Vector3 v1 = new d.Vector3(); | ||
1906 | d.Vector3 v2 = new d.Vector3(); | ||
1907 | |||
1908 | d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2); | ||
1909 | // m_log.DebugFormat("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z); | ||
1910 | |||
1911 | return 1; | ||
1912 | } | 1533 | } |
1913 | |||
1914 | /// <summary> | 1534 | /// <summary> |
1915 | /// This is our collision testing routine in ODE | 1535 | /// This is our collision testing routine in ODE |
1916 | /// </summary> | 1536 | /// </summary> |
@@ -1924,11 +1544,11 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1924 | // since we don't know if we're colliding yet | 1544 | // since we don't know if we're colliding yet |
1925 | if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) | 1545 | if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) |
1926 | continue; | 1546 | continue; |
1927 | 1547 | ||
1928 | chr.IsColliding = false; | 1548 | chr.IsColliding = false; |
1929 | chr.CollidingGround = false; | 1549 | chr.CollidingGround = false; |
1930 | chr.CollidingObj = false; | 1550 | chr.CollidingObj = false; |
1931 | 1551 | ||
1932 | // Test the avatar's geometry for collision with the space | 1552 | // Test the avatar's geometry for collision with the space |
1933 | // This will return near and the space that they are the closest to | 1553 | // This will return near and the space that they are the closest to |
1934 | // And we'll run this again against the avatar and the space segment | 1554 | // And we'll run this again against the avatar and the space segment |
@@ -1942,7 +1562,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
1942 | { | 1562 | { |
1943 | m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", PhysicsSceneName); | 1563 | m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", PhysicsSceneName); |
1944 | } | 1564 | } |
1945 | 1565 | ||
1946 | //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); | 1566 | //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); |
1947 | //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) | 1567 | //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) |
1948 | //{ | 1568 | //{ |
@@ -2003,15 +1623,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2003 | 1623 | ||
2004 | #endregion | 1624 | #endregion |
2005 | 1625 | ||
2006 | public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) | ||
2007 | { | ||
2008 | if (!m_suportCombine) | ||
2009 | return; | ||
2010 | m_worldOffset = offset; | ||
2011 | WorldExtents = new Vector2(extents.X, extents.Y); | ||
2012 | m_parentScene = pScene; | ||
2013 | } | ||
2014 | |||
2015 | // Recovered for use by fly height. Kitto Flora | 1626 | // Recovered for use by fly height. Kitto Flora |
2016 | internal float GetTerrainHeightAtXY(float x, float y) | 1627 | internal float GetTerrainHeightAtXY(float x, float y) |
2017 | { | 1628 | { |
@@ -2019,12 +1630,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2019 | int offsetX = 0; | 1630 | int offsetX = 0; |
2020 | int offsetY = 0; | 1631 | int offsetY = 0; |
2021 | 1632 | ||
2022 | if (m_suportCombine) | ||
2023 | { | ||
2024 | offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
2025 | offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
2026 | } | ||
2027 | |||
2028 | if(RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom)) | 1633 | if(RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom)) |
2029 | { | 1634 | { |
2030 | if (heightFieldGeom != IntPtr.Zero) | 1635 | if (heightFieldGeom != IntPtr.Zero) |
@@ -2042,14 +1647,15 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2042 | x = x - offsetX + 1f; | 1647 | x = x - offsetX + 1f; |
2043 | y = y - offsetY + 1f; | 1648 | y = y - offsetY + 1f; |
2044 | 1649 | ||
2045 | index = (int)((int)x * ((int)m_regionHeight +3) + (int)y); | 1650 | // map is rotated |
1651 | index = (int)x * ((int)m_regionHeight + 3) + (int)y; | ||
2046 | 1652 | ||
2047 | if (index < TerrainHeightFieldHeights[heightFieldGeom].Length) | 1653 | if (index < TerrainHeightFieldHeights[heightFieldGeom].Length) |
2048 | { | 1654 | { |
2049 | //m_log.DebugFormat("x{0} y{1} = {2}", x, y, (float)TerrainHeightFieldHeights[heightFieldGeom][index]); | 1655 | //m_log.DebugFormat("x{0} y{1} = {2}", x, y, (float)TerrainHeightFieldHeights[heightFieldGeom][index]); |
2050 | return (float)TerrainHeightFieldHeights[heightFieldGeom][index]; | 1656 | return (float)TerrainHeightFieldHeights[heightFieldGeom][index]; |
2051 | } | 1657 | } |
2052 | 1658 | ||
2053 | else | 1659 | else |
2054 | return 0f; | 1660 | return 0f; |
2055 | } | 1661 | } |
@@ -2069,7 +1675,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2069 | { | 1675 | { |
2070 | return 0f; | 1676 | return 0f; |
2071 | } | 1677 | } |
2072 | } | 1678 | } |
2073 | // End recovered. Kitto Flora | 1679 | // End recovered. Kitto Flora |
2074 | 1680 | ||
2075 | /// <summary> | 1681 | /// <summary> |
@@ -2079,7 +1685,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2079 | internal void AddCollisionEventReporting(PhysicsActor obj) | 1685 | internal void AddCollisionEventReporting(PhysicsActor obj) |
2080 | { | 1686 | { |
2081 | // m_log.DebugFormat("[PHYSICS]: Adding {0} {1} to collision event reporting", obj.SOPName, obj.LocalID); | 1687 | // m_log.DebugFormat("[PHYSICS]: Adding {0} {1} to collision event reporting", obj.SOPName, obj.LocalID); |
2082 | 1688 | ||
2083 | lock (m_collisionEventActorsChanges) | 1689 | lock (m_collisionEventActorsChanges) |
2084 | m_collisionEventActorsChanges[obj.LocalID] = obj; | 1690 | m_collisionEventActorsChanges[obj.LocalID] = obj; |
2085 | } | 1691 | } |
@@ -2099,7 +1705,9 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2099 | #region Add/Remove Entities | 1705 | #region Add/Remove Entities |
2100 | 1706 | ||
2101 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) | 1707 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) |
2102 | { | 1708 | { |
1709 | d.AllocateODEDataForThread(0); | ||
1710 | |||
2103 | OdeCharacter newAv | 1711 | OdeCharacter newAv |
2104 | = new OdeCharacter( | 1712 | = new OdeCharacter( |
2105 | avName, this, position, velocity, size, avPIDD, avPIDP, | 1713 | avName, this, position, velocity, size, avPIDD, avPIDP, |
@@ -2119,7 +1727,12 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2119 | // "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2}", | 1727 | // "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2}", |
2120 | // actor.Name, actor.LocalID, Name); | 1728 | // actor.Name, actor.LocalID, Name); |
2121 | 1729 | ||
2122 | ((OdeCharacter) actor).Destroy(); | 1730 | lock (OdeLock) |
1731 | { | ||
1732 | d.AllocateODEDataForThread(0); | ||
1733 | |||
1734 | ((OdeCharacter) actor).Destroy(); | ||
1735 | } | ||
2123 | } | 1736 | } |
2124 | 1737 | ||
2125 | internal void AddCharacter(OdeCharacter chr) | 1738 | internal void AddCharacter(OdeCharacter chr) |
@@ -2169,9 +1782,11 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2169 | Vector3 siz = size; | 1782 | Vector3 siz = size; |
2170 | Quaternion rot = rotation; | 1783 | Quaternion rot = rotation; |
2171 | 1784 | ||
1785 | |||
2172 | OdePrim newPrim; | 1786 | OdePrim newPrim; |
2173 | lock (OdeLock) | 1787 | lock (OdeLock) |
2174 | { | 1788 | { |
1789 | d.AllocateODEDataForThread(0); | ||
2175 | newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical); | 1790 | newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical); |
2176 | 1791 | ||
2177 | lock (_prims) | 1792 | lock (_prims) |
@@ -2456,7 +2071,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2456 | 2071 | ||
2457 | lock (externalJointRequestsLock) | 2072 | lock (externalJointRequestsLock) |
2458 | { | 2073 | { |
2459 | if (!requestedJointsToBeCreated.Contains(joint)) // forbid same creation request from entering twice | 2074 | if (!requestedJointsToBeCreated.Contains(joint)) // forbid same creation request from entering twice |
2460 | { | 2075 | { |
2461 | requestedJointsToBeCreated.Add(joint); | 2076 | requestedJointsToBeCreated.Add(joint); |
2462 | } | 2077 | } |
@@ -2620,59 +2235,13 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2620 | 2235 | ||
2621 | 2236 | ||
2622 | } | 2237 | } |
2623 | // we don't want to remove the main space | ||
2624 | |||
2625 | // If the geometry is in the targetspace, remove it from the target space | ||
2626 | //m_log.Warn(prim.m_targetSpace); | ||
2627 | |||
2628 | //if (prim.m_targetSpace != IntPtr.Zero) | ||
2629 | //{ | ||
2630 | //if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom)) | ||
2631 | //{ | ||
2632 | |||
2633 | //if (d.GeomIsSpace(prim.m_targetSpace)) | ||
2634 | //{ | ||
2635 | //waitForSpaceUnlock(prim.m_targetSpace); | ||
2636 | //d.SpaceRemove(prim.m_targetSpace, prim.prim_geom); | ||
2637 | prim.m_targetSpace = IntPtr.Zero; | 2238 | prim.m_targetSpace = IntPtr.Zero; |
2638 | //} | ||
2639 | //else | ||
2640 | //{ | ||
2641 | // m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | ||
2642 | //((OdePrim)prim).m_targetSpace.ToString()); | ||
2643 | //} | ||
2644 | |||
2645 | //} | ||
2646 | //} | ||
2647 | //m_log.Warn(prim.prim_geom); | ||
2648 | |||
2649 | if (!prim.RemoveGeom()) | 2239 | if (!prim.RemoveGeom()) |
2650 | m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene"); | 2240 | m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene"); |
2651 | 2241 | ||
2652 | lock (_prims) | 2242 | lock (_prims) |
2653 | _prims.Remove(prim); | 2243 | _prims.Remove(prim); |
2654 | 2244 | ||
2655 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore | ||
2656 | //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) | ||
2657 | //{ | ||
2658 | //if (prim.m_targetSpace != null) | ||
2659 | //{ | ||
2660 | //if (d.GeomIsSpace(prim.m_targetSpace)) | ||
2661 | //{ | ||
2662 | //waitForSpaceUnlock(prim.m_targetSpace); | ||
2663 | //d.SpaceRemove(space, prim.m_targetSpace); | ||
2664 | // free up memory used by the space. | ||
2665 | //d.SpaceDestroy(prim.m_targetSpace); | ||
2666 | //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position); | ||
2667 | //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]); | ||
2668 | //} | ||
2669 | //else | ||
2670 | //{ | ||
2671 | //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | ||
2672 | //((OdePrim) prim).m_targetSpace.ToString()); | ||
2673 | //} | ||
2674 | //} | ||
2675 | //} | ||
2676 | 2245 | ||
2677 | if (SupportsNINJAJoints) | 2246 | if (SupportsNINJAJoints) |
2678 | RemoveAllJointsConnectedToActorThreadLocked(prim); | 2247 | RemoveAllJointsConnectedToActorThreadLocked(prim); |
@@ -2768,12 +2337,9 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2768 | { | 2337 | { |
2769 | if (d.GeomIsSpace(currentspace)) | 2338 | if (d.GeomIsSpace(currentspace)) |
2770 | { | 2339 | { |
2771 | // waitForSpaceUnlock(currentspace); | ||
2772 | // waitForSpaceUnlock(space); | ||
2773 | d.SpaceRemove(space, currentspace); | 2340 | d.SpaceRemove(space, currentspace); |
2774 | // free up memory used by the space. | 2341 | // free up memory used by the space. |
2775 | 2342 | ||
2776 | //d.SpaceDestroy(currentspace); | ||
2777 | resetSpaceArrayItemToZero(currentspace); | 2343 | resetSpaceArrayItemToZero(currentspace); |
2778 | } | 2344 | } |
2779 | else | 2345 | else |
@@ -2831,7 +2397,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2831 | if (newspace == IntPtr.Zero) | 2397 | if (newspace == IntPtr.Zero) |
2832 | { | 2398 | { |
2833 | newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); | 2399 | newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); |
2834 | d.HashSpaceSetLevels(newspace, smallHashspaceLow, smallHashspaceHigh); | 2400 | d.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh); |
2835 | } | 2401 | } |
2836 | 2402 | ||
2837 | return newspace; | 2403 | return newspace; |
@@ -2851,7 +2417,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2851 | // waitForSpaceUnlock(space); | 2417 | // waitForSpaceUnlock(space); |
2852 | d.SpaceSetSublevel(space, 1); | 2418 | d.SpaceSetSublevel(space, 1); |
2853 | d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); | 2419 | d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); |
2854 | 2420 | ||
2855 | return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; | 2421 | return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; |
2856 | } | 2422 | } |
2857 | 2423 | ||
@@ -2948,7 +2514,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
2948 | iPropertiesNotSupportedDefault++; | 2514 | iPropertiesNotSupportedDefault++; |
2949 | 2515 | ||
2950 | if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0)) | 2516 | if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0)) |
2951 | iPropertiesNotSupportedDefault++; | 2517 | iPropertiesNotSupportedDefault++; |
2952 | 2518 | ||
2953 | if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0) | 2519 | if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0) |
2954 | iPropertiesNotSupportedDefault++; | 2520 | iPropertiesNotSupportedDefault++; |
@@ -3021,7 +2587,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3021 | #if SPAM | 2587 | #if SPAM |
3022 | m_log.Debug("Mesh"); | 2588 | m_log.Debug("Mesh"); |
3023 | #endif | 2589 | #endif |
3024 | return true; | 2590 | return true; |
3025 | } | 2591 | } |
3026 | 2592 | ||
3027 | /// <summary> | 2593 | /// <summary> |
@@ -3052,6 +2618,49 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3052 | } | 2618 | } |
3053 | } | 2619 | } |
3054 | 2620 | ||
2621 | // does all pending changes generated during region load process | ||
2622 | public override void ProcessPreSimulation() | ||
2623 | { | ||
2624 | lock (OdeLock) | ||
2625 | { | ||
2626 | if (world == IntPtr.Zero) | ||
2627 | { | ||
2628 | _taintedPrims.Clear();; | ||
2629 | return; | ||
2630 | } | ||
2631 | |||
2632 | int donechanges = 0; | ||
2633 | if (_taintedPrims.Count > 0) | ||
2634 | { | ||
2635 | |||
2636 | m_log.InfoFormat("[Ode] start processing pending actor operations"); | ||
2637 | int tstart = Util.EnvironmentTickCount(); | ||
2638 | |||
2639 | d.AllocateODEDataForThread(0); | ||
2640 | |||
2641 | lock (_taintedPrims) | ||
2642 | { | ||
2643 | foreach (OdePrim prim in _taintedPrims) | ||
2644 | { | ||
2645 | if (prim.m_taintremove) | ||
2646 | RemovePrimThreadLocked(prim); | ||
2647 | else | ||
2648 | prim.ProcessTaints(); | ||
2649 | |||
2650 | prim.m_collisionscore = 0; | ||
2651 | donechanges++; | ||
2652 | } | ||
2653 | _taintedPrims.Clear(); | ||
2654 | } | ||
2655 | |||
2656 | int time = Util.EnvironmentTickCountSubtract(tstart); | ||
2657 | m_log.InfoFormat("[Ode] finished {0} operations in {1}ms", donechanges, time); | ||
2658 | } | ||
2659 | m_log.InfoFormat("[Ode] {0} prim actors loaded",_prims.Count); | ||
2660 | } | ||
2661 | } | ||
2662 | |||
2663 | |||
3055 | /// <summary> | 2664 | /// <summary> |
3056 | /// This is our main simulate loop | 2665 | /// This is our main simulate loop |
3057 | /// </summary> | 2666 | /// </summary> |
@@ -3065,7 +2674,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3065 | /// <returns>The number of frames simulated over that period.</returns> | 2674 | /// <returns>The number of frames simulated over that period.</returns> |
3066 | public override float Simulate(float timeStep) | 2675 | public override float Simulate(float timeStep) |
3067 | { | 2676 | { |
3068 | if (!_worldInitialized) return 11f; | 2677 | if (!_worldInitialized) |
2678 | return 1.0f; | ||
3069 | 2679 | ||
3070 | int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0; | 2680 | int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0; |
3071 | int tempTick = 0, tempTick2 = 0; | 2681 | int tempTick = 0, tempTick2 = 0; |
@@ -3077,26 +2687,12 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3077 | 2687 | ||
3078 | float fps = 0; | 2688 | float fps = 0; |
3079 | 2689 | ||
3080 | float timeLeft = timeStep; | 2690 | step_time += timeStep; |
3081 | 2691 | ||
3082 | //m_log.Info(timeStep.ToString()); | 2692 | float HalfOdeStep = ODE_STEPSIZE * 0.5f; |
3083 | // step_time += timeSte | 2693 | if (step_time < HalfOdeStep) |
3084 | // | 2694 | return 0; |
3085 | // // If We're loaded down by something else, | 2695 | |
3086 | // // or debugging with the Visual Studio project on pause | ||
3087 | // // skip a few frames to catch up gracefully. | ||
3088 | // // without shooting the physicsactors all over the place | ||
3089 | // | ||
3090 | // if (step_time >= m_SkipFramesAtms) | ||
3091 | // { | ||
3092 | // // Instead of trying to catch up, it'll do 5 physics frames only | ||
3093 | // step_time = ODE_STEPSIZE; | ||
3094 | // m_physicsiterations = 5; | ||
3095 | // } | ||
3096 | // else | ||
3097 | // { | ||
3098 | // m_physicsiterations = 10; | ||
3099 | // } | ||
3100 | 2696 | ||
3101 | // We change _collisionEventPrimChanges to avoid locking _collisionEventPrim itself and causing potential | 2697 | // We change _collisionEventPrimChanges to avoid locking _collisionEventPrim itself and causing potential |
3102 | // deadlock if the collision event tries to lock something else later on which is already locked by a | 2698 | // deadlock if the collision event tries to lock something else later on which is already locked by a |
@@ -3120,29 +2716,12 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3120 | CreateRequestedJoints(); // this must be outside of the lock (OdeLock) to avoid deadlocks | 2716 | CreateRequestedJoints(); // this must be outside of the lock (OdeLock) to avoid deadlocks |
3121 | } | 2717 | } |
3122 | 2718 | ||
2719 | |||
3123 | lock (OdeLock) | 2720 | lock (OdeLock) |
3124 | { | 2721 | { |
3125 | // Process 10 frames if the sim is running normal.. | 2722 | d.AllocateODEDataForThread(~0U); |
3126 | // process 5 frames if the sim is running slow | ||
3127 | //try | ||
3128 | //{ | ||
3129 | //d.WorldSetQuickStepNumIterations(world, m_physicsiterations); | ||
3130 | //} | ||
3131 | //catch (StackOverflowException) | ||
3132 | //{ | ||
3133 | // m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); | ||
3134 | // ode.drelease(world); | ||
3135 | //base.TriggerPhysicsBasedRestart(); | ||
3136 | //} | ||
3137 | 2723 | ||
3138 | // Figure out the Frames Per Second we're going at. | 2724 | while (step_time > HalfOdeStep) |
3139 | //(step_time == 0.004f, there's 250 of those per second. Times the step time/step size | ||
3140 | |||
3141 | fps = (timeStep / ODE_STEPSIZE) * 1000; | ||
3142 | // HACK: Using a time dilation of 1.0 to debug rubberbanding issues | ||
3143 | //m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f); | ||
3144 | |||
3145 | while (timeLeft > 0.0f) | ||
3146 | { | 2725 | { |
3147 | try | 2726 | try |
3148 | { | 2727 | { |
@@ -3241,10 +2820,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3241 | tempTick = tempTick2; | 2820 | tempTick = tempTick2; |
3242 | } | 2821 | } |
3243 | 2822 | ||
3244 | //if ((framecount % m_randomizeWater) == 0) | ||
3245 | // randomizeWater(waterlevel); | ||
3246 | |||
3247 | //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); | ||
3248 | m_rayCastManager.ProcessQueuedRequests(); | 2823 | m_rayCastManager.ProcessQueuedRequests(); |
3249 | 2824 | ||
3250 | if (CollectStats) | 2825 | if (CollectStats) |
@@ -3265,7 +2840,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3265 | 2840 | ||
3266 | foreach (PhysicsActor obj in m_collisionEventActors.Values) | 2841 | foreach (PhysicsActor obj in m_collisionEventActors.Values) |
3267 | { | 2842 | { |
3268 | // m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID); | 2843 | // m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID); |
3269 | 2844 | ||
3270 | switch ((ActorTypes)obj.PhysicsActorType) | 2845 | switch ((ActorTypes)obj.PhysicsActorType) |
3271 | { | 2846 | { |
@@ -3295,7 +2870,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3295 | tempTick = tempTick2; | 2870 | tempTick = tempTick2; |
3296 | } | 2871 | } |
3297 | 2872 | ||
3298 | d.WorldQuickStep(world, ODE_STEPSIZE); | 2873 | lock(SimulationLock) |
2874 | d.WorldQuickStep(world, ODE_STEPSIZE); | ||
3299 | 2875 | ||
3300 | if (CollectStats) | 2876 | if (CollectStats) |
3301 | m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick); | 2877 | m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick); |
@@ -3307,7 +2883,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3307 | m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e); | 2883 | m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e); |
3308 | } | 2884 | } |
3309 | 2885 | ||
3310 | timeLeft -= ODE_STEPSIZE; | 2886 | step_time -= ODE_STEPSIZE; |
2887 | fps += ODE_STEPSIZE; | ||
3311 | } | 2888 | } |
3312 | 2889 | ||
3313 | if (CollectStats) | 2890 | if (CollectStats) |
@@ -3403,6 +2980,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3403 | m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick); | 2980 | m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick); |
3404 | } | 2981 | } |
3405 | 2982 | ||
2983 | fps *= 1.0f/timeStep; | ||
3406 | return fps; | 2984 | return fps; |
3407 | } | 2985 | } |
3408 | 2986 | ||
@@ -3531,7 +3109,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3531 | // as the axis for the hinge. | 3109 | // as the axis for the hinge. |
3532 | 3110 | ||
3533 | // Therefore, we must get the joint's coordinate frame based on the | 3111 | // Therefore, we must get the joint's coordinate frame based on the |
3534 | // joint.Rotation field, which originates from the orientation of the | 3112 | // joint.Rotation field, which originates from the orientation of the |
3535 | // joint's proxy object in the scene. | 3113 | // joint's proxy object in the scene. |
3536 | 3114 | ||
3537 | // The joint's coordinate frame is defined as the transformation matrix | 3115 | // The joint's coordinate frame is defined as the transformation matrix |
@@ -3659,7 +3237,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3659 | int startTime = Util.EnvironmentTickCount(); | 3237 | int startTime = Util.EnvironmentTickCount(); |
3660 | m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", PhysicsSceneName, pOffset); | 3238 | m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", PhysicsSceneName, pOffset); |
3661 | 3239 | ||
3662 | 3240 | ||
3663 | float[] _heightmap; | 3241 | float[] _heightmap; |
3664 | 3242 | ||
3665 | // ok im lasy this are just a aliases | 3243 | // ok im lasy this are just a aliases |
@@ -3675,7 +3253,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3675 | 3253 | ||
3676 | _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples]; | 3254 | _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples]; |
3677 | 3255 | ||
3678 | |||
3679 | const float scale = 1.0f; | 3256 | const float scale = 1.0f; |
3680 | const float offset = 0.0f; | 3257 | const float offset = 0.0f; |
3681 | const float thickness = 10f; | 3258 | const float thickness = 10f; |
@@ -3722,6 +3299,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3722 | 3299 | ||
3723 | lock (OdeLock) | 3300 | lock (OdeLock) |
3724 | { | 3301 | { |
3302 | d.AllocateODEDataForThread(~0U); | ||
3303 | |||
3725 | IntPtr GroundGeom = IntPtr.Zero; | 3304 | IntPtr GroundGeom = IntPtr.Zero; |
3726 | if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) | 3305 | if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) |
3727 | { | 3306 | { |
@@ -3740,7 +3319,8 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3740 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 3319 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
3741 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, | 3320 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, |
3742 | heightmapWidth, heightmapHeight, | 3321 | heightmapWidth, heightmapHeight, |
3743 | (int)heightmapWidthSamples, (int)heightmapHeightSamples, | 3322 | (int)heightmapWidthSamples, |
3323 | (int)heightmapHeightSamples, | ||
3744 | scale, offset, thickness, wrap); | 3324 | scale, offset, thickness, wrap); |
3745 | 3325 | ||
3746 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); | 3326 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); |
@@ -3765,7 +3345,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3765 | 3345 | ||
3766 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); | 3346 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); |
3767 | d.GeomSetRotation(GroundGeom, ref R); | 3347 | d.GeomSetRotation(GroundGeom, ref R); |
3768 | d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0f); | 3348 | d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f); |
3769 | IntPtr testGround = IntPtr.Zero; | 3349 | IntPtr testGround = IntPtr.Zero; |
3770 | if (RegionTerrain.TryGetValue(pOffset, out testGround)) | 3350 | if (RegionTerrain.TryGetValue(pOffset, out testGround)) |
3771 | { | 3351 | { |
@@ -3788,82 +3368,30 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3788 | return waterlevel; | 3368 | return waterlevel; |
3789 | } | 3369 | } |
3790 | 3370 | ||
3791 | public override bool SupportsCombining() | ||
3792 | { | ||
3793 | return m_suportCombine; | ||
3794 | } | ||
3795 | |||
3796 | public override void SetWaterLevel(float baseheight) | 3371 | public override void SetWaterLevel(float baseheight) |
3797 | { | 3372 | { |
3798 | waterlevel = baseheight; | 3373 | waterlevel = baseheight; |
3799 | // randomizeWater(waterlevel); | ||
3800 | } | 3374 | } |
3801 | 3375 | ||
3802 | /* | 3376 | [HandleProcessCorruptedStateExceptions] |
3803 | private void randomizeWater(float baseheight) | 3377 | public override void Dispose() |
3804 | { | 3378 | { |
3805 | uint heightmapWidth = m_regionWidth + 2; | 3379 | lock(SimulationLock) |
3806 | uint heightmapHeight = m_regionHeight + 2; | 3380 | lock(OdeLock) |
3807 | uint heightmapWidthSamples = m_regionWidth + 2; | ||
3808 | uint heightmapHeightSamples = m_regionHeight + 2; | ||
3809 | float scale = 1.0f; | ||
3810 | float offset = 0.0f; | ||
3811 | float thickness = 2.9f; | ||
3812 | int wrap = 0; | ||
3813 | |||
3814 | for (int i = 0; i < (258 * 258); i++) | ||
3815 | { | ||
3816 | _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f); | ||
3817 | // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f)); | ||
3818 | } | ||
3819 | |||
3820 | lock (OdeLock) | ||
3821 | { | 3381 | { |
3822 | if (WaterGeom != IntPtr.Zero) | 3382 | if(world == IntPtr.Zero) |
3823 | { | 3383 | return; |
3824 | d.SpaceRemove(space, WaterGeom); | ||
3825 | } | ||
3826 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | ||
3827 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight, | ||
3828 | (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale, | ||
3829 | offset, thickness, wrap); | ||
3830 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); | ||
3831 | WaterGeom = d.CreateHeightfield(space, HeightmapData, 1); | ||
3832 | if (WaterGeom != IntPtr.Zero) | ||
3833 | { | ||
3834 | d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water)); | ||
3835 | d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space)); | ||
3836 | } | ||
3837 | |||
3838 | geom_name_map[WaterGeom] = "Water"; | ||
3839 | |||
3840 | d.Matrix3 R = new d.Matrix3(); | ||
3841 | |||
3842 | Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f); | ||
3843 | Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f); | ||
3844 | //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); | ||
3845 | 3384 | ||
3846 | q1 = q1 * q2; | 3385 | _worldInitialized = false; |
3847 | //q1 = q1 * q3; | ||
3848 | Vector3 v3; | ||
3849 | float angle; | ||
3850 | q1.GetAxisAngle(out v3, out angle); | ||
3851 | 3386 | ||
3852 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); | 3387 | d.AllocateODEDataForThread(~0U); |
3853 | d.GeomSetRotation(WaterGeom, ref R); | ||
3854 | d.GeomSetPosition(WaterGeom, 128, 128, 0); | ||
3855 | } | ||
3856 | } | ||
3857 | */ | ||
3858 | public override void Dispose() | ||
3859 | { | ||
3860 | _worldInitialized = false; | ||
3861 | 3388 | ||
3862 | m_rayCastManager.Dispose(); | 3389 | if (m_rayCastManager != null) |
3863 | m_rayCastManager = null; | 3390 | { |
3391 | m_rayCastManager.Dispose(); | ||
3392 | m_rayCastManager = null; | ||
3393 | } | ||
3864 | 3394 | ||
3865 | lock (OdeLock) | ||
3866 | { | ||
3867 | lock (_prims) | 3395 | lock (_prims) |
3868 | { | 3396 | { |
3869 | foreach (OdePrim prm in _prims) | 3397 | foreach (OdePrim prm in _prims) |
@@ -3876,10 +3404,33 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3876 | //{ | 3404 | //{ |
3877 | //RemoveAvatar(act); | 3405 | //RemoveAvatar(act); |
3878 | //} | 3406 | //} |
3879 | d.WorldDestroy(world); | 3407 | IntPtr GroundGeom = IntPtr.Zero; |
3880 | //d.CloseODE(); | 3408 | if (RegionTerrain.TryGetValue(m_worldOffset, out GroundGeom)) |
3409 | { | ||
3410 | RegionTerrain.Remove(m_worldOffset); | ||
3411 | if (GroundGeom != IntPtr.Zero) | ||
3412 | { | ||
3413 | if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) | ||
3414 | TerrainHeightFieldHeights.Remove(GroundGeom); | ||
3415 | d.GeomDestroy(GroundGeom); | ||
3416 | } | ||
3417 | } | ||
3418 | |||
3419 | try | ||
3420 | { | ||
3421 | d.WorldDestroy(world); | ||
3422 | world = IntPtr.Zero; | ||
3423 | } | ||
3424 | catch (AccessViolationException e) | ||
3425 | { | ||
3426 | m_log.ErrorFormat("[ODE SCENE]: exception {0}", e.Message); | ||
3427 | } | ||
3881 | } | 3428 | } |
3429 | } | ||
3882 | 3430 | ||
3431 | private int compareByCollisionsDesc(OdePrim A, OdePrim B) | ||
3432 | { | ||
3433 | return -A.CollisionScore.CompareTo(B.CollisionScore); | ||
3883 | } | 3434 | } |
3884 | 3435 | ||
3885 | public override Dictionary<uint, float> GetTopColliders() | 3436 | public override Dictionary<uint, float> GetTopColliders() |
@@ -3889,7 +3440,7 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3889 | lock (_prims) | 3440 | lock (_prims) |
3890 | { | 3441 | { |
3891 | List<OdePrim> orderedPrims = new List<OdePrim>(_prims); | 3442 | List<OdePrim> orderedPrims = new List<OdePrim>(_prims); |
3892 | orderedPrims.OrderByDescending(p => p.CollisionScore); | 3443 | orderedPrims.Sort(compareByCollisionsDesc); |
3893 | topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); | 3444 | topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); |
3894 | 3445 | ||
3895 | foreach (OdePrim p in _prims) | 3446 | foreach (OdePrim p in _prims) |
@@ -3940,133 +3491,6 @@ namespace OpenSim.Region.PhysicsModule.ODE | |||
3940 | return new List<ContactResult>(ourResults); | 3491 | return new List<ContactResult>(ourResults); |
3941 | } | 3492 | } |
3942 | 3493 | ||
3943 | #if USE_DRAWSTUFF | ||
3944 | // Keyboard callback | ||
3945 | public void command(int cmd) | ||
3946 | { | ||
3947 | IntPtr geom; | ||
3948 | d.Mass mass; | ||
3949 | d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f); | ||
3950 | |||
3951 | |||
3952 | |||
3953 | Char ch = Char.ToLower((Char)cmd); | ||
3954 | switch ((Char)ch) | ||
3955 | { | ||
3956 | case 'w': | ||
3957 | try | ||
3958 | { | ||
3959 | Vector3 rotate = (new Vector3(1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD)); | ||
3960 | |||
3961 | xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z; | ||
3962 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3963 | } | ||
3964 | catch (ArgumentException) | ||
3965 | { hpr.X = 0; } | ||
3966 | break; | ||
3967 | |||
3968 | case 'a': | ||
3969 | hpr.X++; | ||
3970 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3971 | break; | ||
3972 | |||
3973 | case 's': | ||
3974 | try | ||
3975 | { | ||
3976 | Vector3 rotate2 = (new Vector3(-1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD)); | ||
3977 | |||
3978 | xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z; | ||
3979 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3980 | } | ||
3981 | catch (ArgumentException) | ||
3982 | { hpr.X = 0; } | ||
3983 | break; | ||
3984 | case 'd': | ||
3985 | hpr.X--; | ||
3986 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3987 | break; | ||
3988 | case 'r': | ||
3989 | xyz.Z++; | ||
3990 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3991 | break; | ||
3992 | case 'f': | ||
3993 | xyz.Z--; | ||
3994 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3995 | break; | ||
3996 | case 'e': | ||
3997 | xyz.Y++; | ||
3998 | ds.SetViewpoint(ref xyz, ref hpr); | ||
3999 | break; | ||
4000 | case 'q': | ||
4001 | xyz.Y--; | ||
4002 | ds.SetViewpoint(ref xyz, ref hpr); | ||
4003 | break; | ||
4004 | } | ||
4005 | } | ||
4006 | |||
4007 | public void step(int pause) | ||
4008 | { | ||
4009 | |||
4010 | ds.SetColor(1.0f, 1.0f, 0.0f); | ||
4011 | ds.SetTexture(ds.Texture.Wood); | ||
4012 | lock (_prims) | ||
4013 | { | ||
4014 | foreach (OdePrim prm in _prims) | ||
4015 | { | ||
4016 | //IntPtr body = d.GeomGetBody(prm.prim_geom); | ||
4017 | if (prm.prim_geom != IntPtr.Zero) | ||
4018 | { | ||
4019 | d.Vector3 pos; | ||
4020 | d.GeomCopyPosition(prm.prim_geom, out pos); | ||
4021 | //d.BodyCopyPosition(body, out pos); | ||
4022 | |||
4023 | d.Matrix3 R; | ||
4024 | d.GeomCopyRotation(prm.prim_geom, out R); | ||
4025 | //d.BodyCopyRotation(body, out R); | ||
4026 | |||
4027 | |||
4028 | d.Vector3 sides = new d.Vector3(); | ||
4029 | sides.X = prm.Size.X; | ||
4030 | sides.Y = prm.Size.Y; | ||
4031 | sides.Z = prm.Size.Z; | ||
4032 | |||
4033 | ds.DrawBox(ref pos, ref R, ref sides); | ||
4034 | } | ||
4035 | } | ||
4036 | } | ||
4037 | ds.SetColor(1.0f, 0.0f, 0.0f); | ||
4038 | |||
4039 | foreach (OdeCharacter chr in _characters) | ||
4040 | { | ||
4041 | if (chr.Shell != IntPtr.Zero) | ||
4042 | { | ||
4043 | IntPtr body = d.GeomGetBody(chr.Shell); | ||
4044 | |||
4045 | d.Vector3 pos; | ||
4046 | d.GeomCopyPosition(chr.Shell, out pos); | ||
4047 | //d.BodyCopyPosition(body, out pos); | ||
4048 | |||
4049 | d.Matrix3 R; | ||
4050 | d.GeomCopyRotation(chr.Shell, out R); | ||
4051 | //d.BodyCopyRotation(body, out R); | ||
4052 | |||
4053 | ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f); | ||
4054 | d.Vector3 sides = new d.Vector3(); | ||
4055 | sides.X = 0.5f; | ||
4056 | sides.Y = 0.5f; | ||
4057 | sides.Z = 0.5f; | ||
4058 | |||
4059 | ds.DrawBox(ref pos, ref R, ref sides); | ||
4060 | } | ||
4061 | } | ||
4062 | } | ||
4063 | |||
4064 | public void start(int unused) | ||
4065 | { | ||
4066 | ds.SetViewpoint(ref xyz, ref hpr); | ||
4067 | } | ||
4068 | #endif | ||
4069 | |||
4070 | public override Dictionary<string, float> GetStats() | 3494 | public override Dictionary<string, float> GetStats() |
4071 | { | 3495 | { |
4072 | if (!CollectStats) | 3496 | if (!CollectStats) |