aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs171
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs129
2 files changed, 210 insertions, 90 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 12da6a7..4c041a1 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -28,6 +28,7 @@
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Runtime.InteropServices;
31using Axiom.Math; 32using Axiom.Math;
32using Ode.NET; 33using Ode.NET;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -57,6 +58,7 @@ namespace OpenSim.Region.Physics.OdePlugin
57 public bool m_taintdisable = false; 58 public bool m_taintdisable = false;
58 public bool m_disabled = false; 59 public bool m_disabled = false;
59 public bool m_taintadd = false; 60 public bool m_taintadd = false;
61 public GCHandle gc;
60 private CollisionLocker ode; 62 private CollisionLocker ode;
61 63
62 private bool m_taintforce = false; 64 private bool m_taintforce = false;
@@ -67,6 +69,7 @@ namespace OpenSim.Region.Physics.OdePlugin
67 private OdeScene _parent_scene; 69 private OdeScene _parent_scene;
68 public IntPtr m_targetSpace = (IntPtr) 0; 70 public IntPtr m_targetSpace = (IntPtr) 0;
69 public IntPtr prim_geom; 71 public IntPtr prim_geom;
72 public IntPtr prev_geom;
70 public IntPtr _triMeshData; 73 public IntPtr _triMeshData;
71 74
72 private bool iscolliding = false; 75 private bool iscolliding = false;
@@ -95,6 +98,9 @@ namespace OpenSim.Region.Physics.OdePlugin
95 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 98 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
96 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 99 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
97 { 100 {
101
102
103 gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned);
98 ode = dode; 104 ode = dode;
99 _velocity = new PhysicsVector(); 105 _velocity = new PhysicsVector();
100 _position = pos; 106 _position = pos;
@@ -116,6 +122,9 @@ namespace OpenSim.Region.Physics.OdePlugin
116 _position.Y = 0; 122 _position.Y = 0;
117 } 123 }
118 124
125 prim_geom = (IntPtr)0;
126 prev_geom = (IntPtr)0;
127
119 _size = size; 128 _size = size;
120 m_taintsize = _size; 129 m_taintsize = _size;
121 _acceleration = new PhysicsVector(); 130 _acceleration = new PhysicsVector();
@@ -173,6 +182,13 @@ namespace OpenSim.Region.Physics.OdePlugin
173 set { return; } 182 set { return; }
174 } 183 }
175 184
185 public void SetGeom(IntPtr geom)
186 {
187 prev_geom = prim_geom;
188 prim_geom = geom;
189 m_log.Warn("Setting Geom to: " + prim_geom);
190
191 }
176 192
177 public void enableBody() 193 public void enableBody()
178 { 194 {
@@ -337,9 +353,6 @@ namespace OpenSim.Region.Physics.OdePlugin
337 disableBody(); 353 disableBody();
338 } 354 }
339 355
340
341
342
343 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 356 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
344 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 357 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
345 int VertexCount = vertexList.GetLength(0)/3; 358 int VertexCount = vertexList.GetLength(0)/3;
@@ -356,7 +369,10 @@ namespace OpenSim.Region.Physics.OdePlugin
356 369
357 try 370 try
358 { 371 {
359 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null); 372 if (prim_geom == (IntPtr)0)
373 {
374 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
375 }
360 } 376 }
361 catch (System.AccessViolationException) 377 catch (System.AccessViolationException)
362 { 378 {
@@ -377,10 +393,12 @@ namespace OpenSim.Region.Physics.OdePlugin
377 393
378 public void ProcessTaints(float timestep) 394 public void ProcessTaints(float timestep)
379 { 395 {
380 396
381 397
382 if (m_taintadd) 398 if (m_taintadd)
399 {
383 changeadd(timestep); 400 changeadd(timestep);
401 }
384 402
385 if (m_taintposition != _position) 403 if (m_taintposition != _position)
386 Move(timestep); 404 Move(timestep);
@@ -433,6 +451,11 @@ namespace OpenSim.Region.Physics.OdePlugin
433 } 451 }
434 public void changeadd(float timestep) 452 public void changeadd(float timestep)
435 { 453 {
454 while (ode.lockquery())
455 {
456 }
457 ode.dlock(_parent_scene.world);
458
436 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); 459 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
437 IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position); 460 IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
438 461
@@ -441,6 +464,11 @@ namespace OpenSim.Region.Physics.OdePlugin
441 464
442 m_targetSpace = targetspace; 465 m_targetSpace = targetspace;
443 466
467 if (m_targetSpace != (IntPtr)0)
468 {
469 m_log.Warn("[PHYSICS]: target: " + m_targetSpace.ToString());
470 }
471
444 if (_mesh != null) 472 if (_mesh != null)
445 { 473 {
446 } 474 }
@@ -473,11 +501,12 @@ namespace OpenSim.Region.Physics.OdePlugin
473 _parent_scene.waitForSpaceUnlock(m_targetSpace); 501 _parent_scene.waitForSpaceUnlock(m_targetSpace);
474 try 502 try
475 { 503 {
476 prim_geom = d.CreateSphere(m_targetSpace, _size.X / 2); 504 SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
477 } 505 }
478 catch (System.AccessViolationException) 506 catch (System.AccessViolationException)
479 { 507 {
480 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object"); 508 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
509 ode.dunlock(_parent_scene.world);
481 return; 510 return;
482 } 511 }
483 } 512 }
@@ -486,11 +515,12 @@ namespace OpenSim.Region.Physics.OdePlugin
486 _parent_scene.waitForSpaceUnlock(m_targetSpace); 515 _parent_scene.waitForSpaceUnlock(m_targetSpace);
487 try 516 try
488 { 517 {
489 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 518 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
490 } 519 }
491 catch (System.AccessViolationException) 520 catch (System.AccessViolationException)
492 { 521 {
493 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object"); 522 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
523 ode.dunlock(_parent_scene.world);
494 return; 524 return;
495 } 525 }
496 } 526 }
@@ -500,12 +530,13 @@ namespace OpenSim.Region.Physics.OdePlugin
500 _parent_scene.waitForSpaceUnlock(m_targetSpace); 530 _parent_scene.waitForSpaceUnlock(m_targetSpace);
501 try 531 try
502 { 532 {
503 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 533 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
504 } 534 }
505 catch (System.AccessViolationException) 535 catch (System.AccessViolationException)
506 { 536 {
507 return;
508 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object"); 537 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
538 ode.dunlock(_parent_scene.world);
539 return;
509 } 540 }
510 } 541 }
511 } 542 }
@@ -526,23 +557,26 @@ namespace OpenSim.Region.Physics.OdePlugin
526 _parent_scene.waitForSpaceUnlock(m_targetSpace); 557 _parent_scene.waitForSpaceUnlock(m_targetSpace);
527 try 558 try
528 { 559 {
529 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 560 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
530 } 561 }
531 catch (System.AccessViolationException) 562 catch (System.AccessViolationException)
532 { 563 {
533 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object"); 564 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
565 ode.dunlock(_parent_scene.world);
534 return; 566 return;
535 } 567 }
536 } 568 }
537 } 569 }
538 570 if (prim_geom != (IntPtr) 0)
539 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 571 {
540 d.Quaternion myrot = new d.Quaternion(); 572 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
541 myrot.W = _orientation.w; 573 d.Quaternion myrot = new d.Quaternion();
542 myrot.X = _orientation.x; 574 myrot.W = _orientation.w;
543 myrot.Y = _orientation.y; 575 myrot.X = _orientation.x;
544 myrot.Z = _orientation.z; 576 myrot.Y = _orientation.y;
545 d.GeomSetQuaternion(prim_geom, ref myrot); 577 myrot.Z = _orientation.z;
578 d.GeomSetQuaternion(prim_geom, ref myrot);
579 }
546 580
547 581
548 if (m_isphysical && Body == (IntPtr)0) 582 if (m_isphysical && Body == (IntPtr)0)
@@ -551,7 +585,8 @@ namespace OpenSim.Region.Physics.OdePlugin
551 } 585 }
552 586
553 587
554 } 588 }
589 ode.dunlock(_parent_scene.world);
555 _parent_scene.geom_name_map[prim_geom] = this.m_primName; 590 _parent_scene.geom_name_map[prim_geom] = this.m_primName;
556 _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this; 591 _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this;
557 m_taintadd = false; 592 m_taintadd = false;
@@ -560,32 +595,55 @@ namespace OpenSim.Region.Physics.OdePlugin
560 } 595 }
561 public void Move(float timestep) 596 public void Move(float timestep)
562 { 597 {
598 while (ode.lockquery())
599 {
600 }
601 ode.dlock(_parent_scene.world);
602
603
563 if (m_isphysical) 604 if (m_isphysical)
564 { 605 {
565 // This is a fallback.. May no longer be necessary. 606 // This is a fallback.. May no longer be necessary.
566 if (Body == (IntPtr) 0) 607 if (Body == (IntPtr) 0)
567 enableBody(); 608 enableBody();
568 //Prim auto disable after 20 frames, 609 //Prim auto disable after 20 frames,
569 ///if you move it, re-enable the prim manually. 610 //if you move it, re-enable the prim manually.
570 d.BodyEnable(Body); 611
571 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); 612 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
613 d.BodyEnable(Body);
614
572 } 615 }
573 else 616 else
574 { 617 {
575 string primScenAvatarIn = _parent_scene.whichspaceamIin(_position); 618 string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
576 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); 619 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
577 m_targetSpace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace); 620 _parent_scene.waitForSpaceUnlock(m_targetSpace);
578 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 621
622 IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
623 m_targetSpace = tempspace;
579 624
580 _parent_scene.waitForSpaceUnlock(m_targetSpace); 625 _parent_scene.waitForSpaceUnlock(m_targetSpace);
581 d.SpaceAdd(m_targetSpace, prim_geom); 626 if (prim_geom != (IntPtr) 0)
627 {
628 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
629
630 _parent_scene.waitForSpaceUnlock(m_targetSpace);
631 d.SpaceAdd(m_targetSpace, prim_geom);
632 }
582 } 633 }
634 ode.dunlock(_parent_scene.world);
635
583 resetCollisionAccounting(); 636 resetCollisionAccounting();
584 m_taintposition = _position; 637 m_taintposition = _position;
585 } 638 }
586 639
587 public void rotate(float timestep) 640 public void rotate(float timestep)
588 { 641 {
642 while (ode.lockquery())
643 {
644 }
645 ode.dlock(_parent_scene.world);
646
589 d.Quaternion myrot = new d.Quaternion(); 647 d.Quaternion myrot = new d.Quaternion();
590 myrot.W = _orientation.w; 648 myrot.W = _orientation.w;
591 myrot.X = _orientation.x; 649 myrot.X = _orientation.x;
@@ -596,6 +654,9 @@ namespace OpenSim.Region.Physics.OdePlugin
596 { 654 {
597 d.BodySetQuaternion(Body, ref myrot); 655 d.BodySetQuaternion(Body, ref myrot);
598 } 656 }
657
658 ode.dunlock(_parent_scene.world);
659
599 resetCollisionAccounting(); 660 resetCollisionAccounting();
600 m_taintrot = _orientation; 661 m_taintrot = _orientation;
601 } 662 }
@@ -608,11 +669,17 @@ namespace OpenSim.Region.Physics.OdePlugin
608 } 669 }
609 670
610 public void changedisable(float timestep) 671 public void changedisable(float timestep)
611 { 672 {
673 while (ode.lockquery())
674 {
675 }
676 ode.dlock(_parent_scene.world);
612 m_disabled = true; 677 m_disabled = true;
613 if (Body != (IntPtr) 0) 678 if (Body != (IntPtr) 0)
614 d.BodyDisable(Body); 679 d.BodyDisable(Body);
615 680
681 ode.dunlock(_parent_scene.world);
682
616 m_taintdisable = false; 683 m_taintdisable = false;
617 } 684 }
618 685
@@ -638,6 +705,10 @@ namespace OpenSim.Region.Physics.OdePlugin
638 705
639 public void changesize(float timestamp) 706 public void changesize(float timestamp)
640 { 707 {
708 while (ode.lockquery())
709 {
710 }
711 ode.dlock(_parent_scene.world);
641 //if (!_parent_scene.geom_name_map.ContainsKey(prim_geom)) 712 //if (!_parent_scene.geom_name_map.ContainsKey(prim_geom))
642 //{ 713 //{
643 // m_taintsize = _size; 714 // m_taintsize = _size;
@@ -684,20 +755,20 @@ namespace OpenSim.Region.Physics.OdePlugin
684 if (((_size.X / 2f) > 0f) && ((_size.X / 2f) < 1000)) 755 if (((_size.X / 2f) > 0f) && ((_size.X / 2f) < 1000))
685 { 756 {
686 _parent_scene.waitForSpaceUnlock(m_targetSpace); 757 _parent_scene.waitForSpaceUnlock(m_targetSpace);
687 prim_geom = d.CreateSphere(m_targetSpace, _size.X / 2); 758 SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
688 } 759 }
689 else 760 else
690 { 761 {
691 m_log.Info("[PHYSICS]: Failed to load a sphere bad size"); 762 m_log.Info("[PHYSICS]: Failed to load a sphere bad size");
692 _parent_scene.waitForSpaceUnlock(m_targetSpace); 763 _parent_scene.waitForSpaceUnlock(m_targetSpace);
693 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 764 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
694 } 765 }
695 766
696 } 767 }
697 else 768 else
698 { 769 {
699 _parent_scene.waitForSpaceUnlock(m_targetSpace); 770 _parent_scene.waitForSpaceUnlock(m_targetSpace);
700 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 771 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
701 } 772 }
702 } 773 }
703 //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight) 774 //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
@@ -715,7 +786,7 @@ namespace OpenSim.Region.Physics.OdePlugin
715 else 786 else
716 { 787 {
717 _parent_scene.waitForSpaceUnlock(m_targetSpace); 788 _parent_scene.waitForSpaceUnlock(m_targetSpace);
718 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 789 SetGeom(prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
719 } 790 }
720 //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 791 //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
721 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 792 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
@@ -734,12 +805,12 @@ namespace OpenSim.Region.Physics.OdePlugin
734 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z) 805 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
735 { 806 {
736 _parent_scene.waitForSpaceUnlock(m_targetSpace); 807 _parent_scene.waitForSpaceUnlock(m_targetSpace);
737 prim_geom = d.CreateSphere(m_targetSpace, _size.X / 2); 808 SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
738 } 809 }
739 else 810 else
740 { 811 {
741 _parent_scene.waitForSpaceUnlock(m_targetSpace); 812 _parent_scene.waitForSpaceUnlock(m_targetSpace);
742 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 813 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
743 } 814 }
744 } 815 }
745 //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight) 816 //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
@@ -757,7 +828,7 @@ namespace OpenSim.Region.Physics.OdePlugin
757 else 828 else
758 { 829 {
759 _parent_scene.waitForSpaceUnlock(m_targetSpace); 830 _parent_scene.waitForSpaceUnlock(m_targetSpace);
760 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 831 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
761 } 832 }
762 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 833 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
763 d.Quaternion myrot = new d.Quaternion(); 834 d.Quaternion myrot = new d.Quaternion();
@@ -779,12 +850,21 @@ namespace OpenSim.Region.Physics.OdePlugin
779 } 850 }
780 851
781 _parent_scene.geom_name_map[prim_geom] = oldname; 852 _parent_scene.geom_name_map[prim_geom] = oldname;
853
854 ode.dunlock(_parent_scene.world);
855
782 resetCollisionAccounting(); 856 resetCollisionAccounting();
783 m_taintsize = _size; 857 m_taintsize = _size;
784 } 858 }
785 859
786 public void changeshape(float timestamp) 860 public void changeshape(float timestamp)
787 { 861 {
862 while (ode.lockquery())
863 {
864 }
865 ode.dlock(_parent_scene.world);
866
867
788 string oldname = _parent_scene.geom_name_map[prim_geom]; 868 string oldname = _parent_scene.geom_name_map[prim_geom];
789 869
790 // Cleanup of old prim geometry and Bodies 870 // Cleanup of old prim geometry and Bodies
@@ -809,13 +889,13 @@ namespace OpenSim.Region.Physics.OdePlugin
809 else 889 else
810 { 890 {
811 _parent_scene.waitForSpaceUnlock(m_targetSpace); 891 _parent_scene.waitForSpaceUnlock(m_targetSpace);
812 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 892 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
813 } 893 }
814 } 894 }
815 else 895 else
816 { 896 {
817 _parent_scene.waitForSpaceUnlock(m_targetSpace); 897 _parent_scene.waitForSpaceUnlock(m_targetSpace);
818 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 898 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
819 } 899 }
820 if (IsPhysical && Body == (IntPtr) 0) 900 if (IsPhysical && Body == (IntPtr) 0)
821 { 901 {
@@ -833,12 +913,20 @@ namespace OpenSim.Region.Physics.OdePlugin
833 d.GeomSetQuaternion(prim_geom, ref myrot); 913 d.GeomSetQuaternion(prim_geom, ref myrot);
834 } 914 }
835 _parent_scene.geom_name_map[prim_geom] = oldname; 915 _parent_scene.geom_name_map[prim_geom] = oldname;
916
917 ode.dunlock(_parent_scene.world);
918
836 resetCollisionAccounting(); 919 resetCollisionAccounting();
837 m_taintshape = false; 920 m_taintshape = false;
838 } 921 }
839 922
840 public void changeAddForce(float timestamp) 923 public void changeAddForce(float timestamp)
841 { 924 {
925 while (ode.lockquery())
926 {
927 }
928 ode.dlock(_parent_scene.world);
929
842 System.Threading.Thread.Sleep(2); 930 System.Threading.Thread.Sleep(2);
843 lock (m_forcelist) 931 lock (m_forcelist)
844 { 932 {
@@ -855,6 +943,9 @@ namespace OpenSim.Region.Physics.OdePlugin
855 } 943 }
856 m_forcelist.Clear(); 944 m_forcelist.Clear();
857 } 945 }
946
947 ode.dunlock(_parent_scene.world);
948
858 m_collisionscore = 0; 949 m_collisionscore = 0;
859 m_interpenetrationcount = 0; 950 m_interpenetrationcount = 0;
860 m_taintforce = false; 951 m_taintforce = false;
@@ -862,6 +953,11 @@ namespace OpenSim.Region.Physics.OdePlugin
862 } 953 }
863 private void changevelocity(float timestep) 954 private void changevelocity(float timestep)
864 { 955 {
956 while (ode.lockquery())
957 {
958 }
959 ode.dlock(_parent_scene.world);
960
865 System.Threading.Thread.Sleep(20); 961 System.Threading.Thread.Sleep(20);
866 if (IsPhysical) 962 if (IsPhysical)
867 { 963 {
@@ -870,7 +966,10 @@ namespace OpenSim.Region.Physics.OdePlugin
870 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); 966 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
871 } 967 }
872 } 968 }
873 resetCollisionAccounting(); 969
970 ode.dunlock(_parent_scene.world);
971
972 //resetCollisionAccounting();
874 m_taintVelocity = PhysicsVector.Zero; 973 m_taintVelocity = PhysicsVector.Zero;
875 } 974 }
876 public override bool IsPhysical 975 public override bool IsPhysical
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index f934341..9392192 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -596,7 +596,7 @@ namespace OpenSim.Region.Physics.OdePlugin
596 /// <param name="timeStep"></param> 596 /// <param name="timeStep"></param>
597 private void collision_optimized(float timeStep) 597 private void collision_optimized(float timeStep)
598 { 598 {
599 starttiming(); 599
600 foreach (OdeCharacter chr in _characters) 600 foreach (OdeCharacter chr in _characters)
601 { 601 {
602 // Reset the collision values to false 602 // Reset the collision values to false
@@ -626,7 +626,7 @@ namespace OpenSim.Region.Physics.OdePlugin
626 //forcedZ = true; 626 //forcedZ = true;
627 //} 627 //}
628 } 628 }
629 int avms = stoptiming(); 629
630 630
631 // If the sim is running slow this frame, 631 // If the sim is running slow this frame,
632 // don't process collision for prim! 632 // don't process collision for prim!
@@ -719,8 +719,9 @@ namespace OpenSim.Region.Physics.OdePlugin
719 { 719 {
720 OdePrim p = (OdePrim) prim; 720 OdePrim p = (OdePrim) prim;
721 721
722 p.setPrimForRemoval(); 722 //p.setPrimForRemoval();
723 AddPhysicsActorTaint(prim); 723 //AddPhysicsActorTaint(prim);
724 RemovePrimThreadLocked(p);
724 } 725 }
725 } 726 }
726 } 727 }
@@ -736,10 +737,14 @@ namespace OpenSim.Region.Physics.OdePlugin
736 /// <param name="prim"></param> 737 /// <param name="prim"></param>
737 public void RemovePrimThreadLocked(OdePrim prim) 738 public void RemovePrimThreadLocked(OdePrim prim)
738 { 739 {
739 prim.ResetTaints(); 740 while (ode.lockquery())
740 lock (OdeLock)
741 { 741 {
742 System.Threading.Thread.Sleep(20); 742 }
743 ode.dlock(world);
744 //System.Threading.Thread.Sleep(20);
745 prim.ResetTaints();
746
747
743 if (prim.IsPhysical) 748 if (prim.IsPhysical)
744 { 749 {
745 prim.disableBody(); 750 prim.disableBody();
@@ -748,27 +753,38 @@ namespace OpenSim.Region.Physics.OdePlugin
748 if (prim.m_targetSpace != space && prim.IsPhysical == false) 753 if (prim.m_targetSpace != space && prim.IsPhysical == false)
749 { 754 {
750 // If the geometry is in the targetspace, remove it from the target space 755 // If the geometry is in the targetspace, remove it from the target space
751 if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom)) 756 //m_log.Warn(prim.m_targetSpace);
757 if (prim.prim_geom == (IntPtr)0)
758 prim.prim_geom = prim.prev_geom;
759
760 if (prim.m_targetSpace != (IntPtr)0)
752 { 761 {
753 if (!(prim.m_targetSpace.Equals(null))) 762 if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
754 { 763 {
755 764
756 if (d.GeomIsSpace(prim.m_targetSpace)) 765 if (d.GeomIsSpace(prim.m_targetSpace))
757 { 766 {
758 waitForSpaceUnlock(prim.m_targetSpace); 767 waitForSpaceUnlock(prim.m_targetSpace);
759 d.SpaceRemove(prim.m_targetSpace, prim.prim_geom); 768 d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
769 prim.m_targetSpace = space;
760 } 770 }
761 else 771 else
762 { 772 {
763 m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + 773 m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
764 ((OdePrim) prim).m_targetSpace.ToString()); 774 ((OdePrim)prim).m_targetSpace.ToString());
765 } 775 }
776
766 } 777 }
767 } 778 }
779 m_log.Warn(prim.prim_geom);
768 try 780 try
769 { 781 {
770 782 if (prim.prim_geom != (IntPtr)0)
771 d.GeomDestroy(prim.prim_geom); 783 {
784 d.GeomDestroy(prim.prim_geom);
785 prim.prim_geom = (IntPtr) 0;
786 }
787
772 } 788 }
773 catch (System.AccessViolationException) 789 catch (System.AccessViolationException)
774 { 790 {
@@ -777,30 +793,31 @@ namespace OpenSim.Region.Physics.OdePlugin
777 _prims.Remove(prim); 793 _prims.Remove(prim);
778 794
779 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 795 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
780 if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) 796 //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
781 { 797 //{
782 if (!(prim.m_targetSpace.Equals(null))) 798 //if (!(prim.m_targetSpace.Equals(null)))
783 { 799 //{
784 if (d.GeomIsSpace(prim.m_targetSpace)) 800 //if (d.GeomIsSpace(prim.m_targetSpace))
785 { 801 //{
786 waitForSpaceUnlock(prim.m_targetSpace); 802 //waitForSpaceUnlock(prim.m_targetSpace);
787 d.SpaceRemove(space, prim.m_targetSpace); 803 //d.SpaceRemove(space, prim.m_targetSpace);
788 // free up memory used by the space. 804 // free up memory used by the space.
789 d.SpaceDestroy(prim.m_targetSpace); 805 //d.SpaceDestroy(prim.m_targetSpace);
790 int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position); 806 //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
791 resetSpaceArrayItemToZero(xyspace[0], xyspace[1]); 807 //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
792 } 808 //}
793 else 809 //else
794 { 810 //{
795 m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + 811 //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
796 ((OdePrim) prim).m_targetSpace.ToString()); 812 //((OdePrim) prim).m_targetSpace.ToString());
797 } 813 //}
798 } 814 //}
799 } 815 //}
800 } 816 }
801 817
802 818
803 } 819
820 ode.dunlock(world);
804 } 821 }
805 /// <summary> 822 /// <summary>
806 /// Takes a space pointer and zeros out the array we're using to hold the spaces 823 /// Takes a space pointer and zeros out the array we're using to hold the spaces
@@ -905,9 +922,11 @@ namespace OpenSim.Region.Physics.OdePlugin
905 else 922 else
906 { 923 {
907 // this is a physical object that got disabled. ;.; 924 // this is a physical object that got disabled. ;.;
908 if (d.SpaceQuery(currentspace, geom)) 925 if (currentspace != (IntPtr)0 && geom != (IntPtr)0)
909 { 926 {
910 if (currentspace != (IntPtr) 0) 927 if (d.SpaceQuery(currentspace, geom))
928 {
929
911 if (d.GeomIsSpace(currentspace)) 930 if (d.GeomIsSpace(currentspace))
912 { 931 {
913 waitForSpaceUnlock(currentspace); 932 waitForSpaceUnlock(currentspace);
@@ -918,23 +937,24 @@ namespace OpenSim.Region.Physics.OdePlugin
918 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + 937 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
919 currentspace.ToString() + " Geom:" + geom.ToString()); 938 currentspace.ToString() + " Geom:" + geom.ToString());
920 } 939 }
921 } 940 }
922 else 941 else
923 {
924 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
925 if (!(sGeomIsIn.Equals(null)))
926 { 942 {
927 if (sGeomIsIn != (IntPtr) 0) 943 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
944 if (!(sGeomIsIn.Equals(null)))
928 { 945 {
929 if (d.GeomIsSpace(sGeomIsIn)) 946 if (sGeomIsIn != (IntPtr)0)
930 { 947 {
931 waitForSpaceUnlock(sGeomIsIn); 948 if (d.GeomIsSpace(sGeomIsIn))
932 d.SpaceRemove(sGeomIsIn, geom); 949 {
933 } 950 waitForSpaceUnlock(sGeomIsIn);
934 else 951 d.SpaceRemove(sGeomIsIn, geom);
935 { 952 }
936 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + 953 else
937 sGeomIsIn.ToString() + " Geom:" + geom.ToString()); 954 {
955 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
956 sGeomIsIn.ToString() + " Geom:" + geom.ToString());
957 }
938 } 958 }
939 } 959 }
940 } 960 }
@@ -1041,6 +1061,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1041 1061
1042 _prims.Add(newPrim); 1062 _prims.Add(newPrim);
1043 } 1063 }
1064
1044 1065
1045 return newPrim; 1066 return newPrim;
1046 } 1067 }
@@ -1268,10 +1289,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1268 bool processedtaints = false; 1289 bool processedtaints = false;
1269 foreach (OdePrim prim in _taintedPrim) 1290 foreach (OdePrim prim in _taintedPrim)
1270 { 1291 {
1271 if (prim.m_taintremove) 1292 //if (prim.m_taintremove)
1272 { 1293 //{
1273 RemovePrimThreadLocked(prim); 1294 //RemovePrimThreadLocked(prim);
1274 } 1295 //}
1275 1296
1276 prim.ProcessTaints(timeStep); 1297 prim.ProcessTaints(timeStep);
1277 1298