diff options
author | UbitUmarov | 2016-09-03 07:51:53 +0100 |
---|---|---|
committer | UbitUmarov | 2016-09-03 07:51:53 +0100 |
commit | 9aec227767cf726216514d0494f11b5d8bf5b807 (patch) | |
tree | 8f308f4c1eefa19954fc30a560ac780f8a8e916a /OpenSim/Region/PhysicsModules/ubOde | |
parent | merge issue (diff) | |
parent | tests making sure evering thing is coerently wrong.. (diff) | |
download | opensim-SC-9aec227767cf726216514d0494f11b5d8bf5b807.zip opensim-SC-9aec227767cf726216514d0494f11b5d8bf5b807.tar.gz opensim-SC-9aec227767cf726216514d0494f11b5d8bf5b807.tar.bz2 opensim-SC-9aec227767cf726216514d0494f11b5d8bf5b807.tar.xz |
Merge branch 'master' into httptests
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde')
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs | 52 | ||||
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs | 179 | ||||
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs | 15 | ||||
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs | 283 |
4 files changed, 274 insertions, 255 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs index c9489d2..3a5a936 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs | |||
@@ -122,8 +122,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
122 | private float m_buoyancy = 0f; | 122 | private float m_buoyancy = 0f; |
123 | 123 | ||
124 | private bool m_freemove = false; | 124 | private bool m_freemove = false; |
125 | // private CollisionLocker ode; | 125 | |
126 | |||
127 | // private string m_name = String.Empty; | 126 | // private string m_name = String.Empty; |
128 | // other filter control | 127 | // other filter control |
129 | int m_colliderfilter = 0; | 128 | int m_colliderfilter = 0; |
@@ -1571,11 +1570,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1571 | { | 1570 | { |
1572 | if (CollisionEventsThisFrame != null) | 1571 | if (CollisionEventsThisFrame != null) |
1573 | { | 1572 | { |
1574 | lock (CollisionEventsThisFrame) | 1573 | CollisionEventsThisFrame.Clear(); |
1575 | { | 1574 | CollisionEventsThisFrame = null; |
1576 | CollisionEventsThisFrame.Clear(); | ||
1577 | CollisionEventsThisFrame = null; | ||
1578 | } | ||
1579 | } | 1575 | } |
1580 | m_eventsubscription = 0; | 1576 | m_eventsubscription = 0; |
1581 | _parent_scene.RemoveCollisionEventReporting(this); | 1577 | _parent_scene.RemoveCollisionEventReporting(this); |
@@ -1585,11 +1581,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1585 | { | 1581 | { |
1586 | if (CollisionEventsThisFrame == null) | 1582 | if (CollisionEventsThisFrame == null) |
1587 | CollisionEventsThisFrame = new CollisionEventUpdate(); | 1583 | CollisionEventsThisFrame = new CollisionEventUpdate(); |
1588 | lock (CollisionEventsThisFrame) | 1584 | CollisionEventsThisFrame.AddCollider(CollidedWith, contact); |
1589 | { | 1585 | _parent_scene.AddCollisionEventReporting(this); |
1590 | CollisionEventsThisFrame.AddCollider(CollidedWith, contact); | ||
1591 | _parent_scene.AddCollisionEventReporting(this); | ||
1592 | } | ||
1593 | } | 1586 | } |
1594 | 1587 | ||
1595 | public void SendCollisions(int timestep) | 1588 | public void SendCollisions(int timestep) |
@@ -1600,28 +1593,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1600 | if (CollisionEventsThisFrame == null) | 1593 | if (CollisionEventsThisFrame == null) |
1601 | return; | 1594 | return; |
1602 | 1595 | ||
1603 | lock (CollisionEventsThisFrame) | 1596 | if (m_cureventsubscription < m_eventsubscription) |
1604 | { | 1597 | return; |
1605 | if (m_cureventsubscription < m_eventsubscription) | ||
1606 | return; | ||
1607 | 1598 | ||
1608 | int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; | 1599 | int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; |
1609 | 1600 | ||
1610 | if (!SentEmptyCollisionsEvent || ncolisions > 0) | 1601 | if (!SentEmptyCollisionsEvent || ncolisions > 0) |
1611 | { | 1602 | { |
1612 | base.SendCollisionUpdate(CollisionEventsThisFrame); | 1603 | base.SendCollisionUpdate(CollisionEventsThisFrame); |
1613 | m_cureventsubscription = 0; | 1604 | m_cureventsubscription = 0; |
1614 | 1605 | ||
1615 | if (ncolisions == 0) | 1606 | if (ncolisions == 0) |
1616 | { | 1607 | { |
1617 | SentEmptyCollisionsEvent = true; | 1608 | SentEmptyCollisionsEvent = true; |
1618 | // _parent_scene.RemoveCollisionEventReporting(this); | 1609 | // _parent_scene.RemoveCollisionEventReporting(this); |
1619 | } | 1610 | } |
1620 | else | 1611 | else |
1621 | { | 1612 | { |
1622 | SentEmptyCollisionsEvent = false; | 1613 | SentEmptyCollisionsEvent = false; |
1623 | CollisionEventsThisFrame.Clear(); | 1614 | CollisionEventsThisFrame.Clear(); |
1624 | } | ||
1625 | } | 1615 | } |
1626 | } | 1616 | } |
1627 | } | 1617 | } |
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs index d8a2272..fa32441 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs | |||
@@ -648,6 +648,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
648 | break; | 648 | break; |
649 | 649 | ||
650 | } | 650 | } |
651 | // disable mouse steering | ||
652 | m_flags &= ~(VehicleFlag.MOUSELOOK_STEER | | ||
653 | VehicleFlag.MOUSELOOK_BANK | | ||
654 | VehicleFlag.CAMERA_DECOUPLED); | ||
651 | 655 | ||
652 | m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); | 656 | m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); |
653 | m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; | 657 | m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; |
@@ -794,6 +798,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
794 | 798 | ||
795 | float ldampZ = 0; | 799 | float ldampZ = 0; |
796 | 800 | ||
801 | bool mousemode = false; | ||
802 | bool mousemodebank = false; | ||
803 | |||
804 | float bankingEfficiency; | ||
805 | float verticalAttractionTimescale = m_verticalAttractionTimescale; | ||
806 | |||
807 | if((m_flags & (VehicleFlag.MOUSELOOK_STEER | VehicleFlag.MOUSELOOK_BANK)) != 0 ) | ||
808 | { | ||
809 | mousemode = true; | ||
810 | mousemodebank = (m_flags & VehicleFlag.MOUSELOOK_BANK) != 0; | ||
811 | if(mousemodebank) | ||
812 | { | ||
813 | bankingEfficiency = m_bankingEfficiency; | ||
814 | if(verticalAttractionTimescale < 149.9) | ||
815 | verticalAttractionTimescale *= 2.0f; // reduce current instability | ||
816 | } | ||
817 | else | ||
818 | bankingEfficiency = 0; | ||
819 | } | ||
820 | else | ||
821 | bankingEfficiency = m_bankingEfficiency; | ||
822 | |||
797 | // linear motor | 823 | // linear motor |
798 | if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) | 824 | if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) |
799 | { | 825 | { |
@@ -930,12 +956,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
930 | } | 956 | } |
931 | 957 | ||
932 | // vertical atractor | 958 | // vertical atractor |
933 | if (m_verticalAttractionTimescale < 300) | 959 | if (verticalAttractionTimescale < 300) |
934 | { | 960 | { |
935 | float roll; | 961 | float roll; |
936 | float pitch; | 962 | float pitch; |
937 | 963 | ||
938 | float ftmp = m_invtimestep / m_verticalAttractionTimescale / m_verticalAttractionTimescale; | 964 | float ftmp = m_invtimestep / verticalAttractionTimescale / verticalAttractionTimescale; |
939 | 965 | ||
940 | float ftmp2; | 966 | float ftmp2; |
941 | ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep; | 967 | ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep; |
@@ -967,7 +993,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
967 | torque.Y += effpitch * ftmp; | 993 | torque.Y += effpitch * ftmp; |
968 | } | 994 | } |
969 | 995 | ||
970 | if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) | 996 | if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) |
971 | { | 997 | { |
972 | 998 | ||
973 | float broll = effroll; | 999 | float broll = effroll; |
@@ -1018,58 +1044,129 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1018 | m_amdampZ = 1 / m_angularFrictionTimescale.Z; | 1044 | m_amdampZ = 1 / m_angularFrictionTimescale.Z; |
1019 | } | 1045 | } |
1020 | 1046 | ||
1021 | // angular motor | 1047 | if(mousemode) |
1022 | if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) | ||
1023 | { | 1048 | { |
1024 | tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error | 1049 | CameraData cam = rootPrim.TryGetCameraData(); |
1025 | tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep | 1050 | if(cam.Valid && cam.MouseLook) |
1026 | torque.X += tmpV.X * m_ampwr; | 1051 | { |
1027 | torque.Y += tmpV.Y * m_ampwr; | 1052 | Vector3 dirv = cam.CameraAtAxis * irotq; |
1028 | torque.Z += tmpV.Z; | ||
1029 | 1053 | ||
1030 | m_amEfect *= m_amDecay; | 1054 | float invamts = 1.0f/m_angularMotorTimescale; |
1031 | } | 1055 | float tmp; |
1032 | else | ||
1033 | m_amEfect = 0; | ||
1034 | 1056 | ||
1035 | // angular deflection | 1057 | // get out of x == 0 plane |
1036 | if (m_angularDeflectionEfficiency > 0) | 1058 | if(Math.Abs(dirv.X) < 0.001f) |
1037 | { | 1059 | dirv.X = 0.001f; |
1038 | Vector3 dirv; | 1060 | |
1039 | 1061 | if (Math.Abs(dirv.Z) > 0.01) | |
1040 | if (curLocalVel.X > 0.01f) | 1062 | { |
1041 | dirv = curLocalVel; | 1063 | tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y; |
1042 | else if (curLocalVel.X < -0.01f) | 1064 | if(tmp < -4f) |
1043 | // use oposite | 1065 | tmp = -4f; |
1044 | dirv = -curLocalVel; | 1066 | else if(tmp > 4f) |
1067 | tmp = 4f; | ||
1068 | torque.Y += (tmp - curLocalAngVel.Y) * invamts; | ||
1069 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1070 | } | ||
1071 | else | ||
1072 | torque.Y -= curLocalAngVel.Y * m_invtimestep; | ||
1073 | |||
1074 | if (Math.Abs(dirv.Y) > 0.01) | ||
1075 | { | ||
1076 | if(mousemodebank) | ||
1077 | { | ||
1078 | tmp = -(float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X; | ||
1079 | if(tmp < -4f) | ||
1080 | tmp = -4f; | ||
1081 | else if(tmp > 4f) | ||
1082 | tmp = 4f; | ||
1083 | torque.X += (tmp - curLocalAngVel.X) * invamts; | ||
1084 | } | ||
1085 | else | ||
1086 | { | ||
1087 | tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z; | ||
1088 | tmp *= invamts; | ||
1089 | if(tmp < -4f) | ||
1090 | tmp = -4f; | ||
1091 | else if(tmp > 4f) | ||
1092 | tmp = 4f; | ||
1093 | torque.Z += (tmp - curLocalAngVel.Z) * invamts; | ||
1094 | } | ||
1095 | torque.X -= curLocalAngVel.X * m_amdampX; | ||
1096 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1097 | } | ||
1098 | else | ||
1099 | { | ||
1100 | if(mousemodebank) | ||
1101 | torque.X -= curLocalAngVel.X * m_invtimestep; | ||
1102 | else | ||
1103 | torque.Z -= curLocalAngVel.Z * m_invtimestep; | ||
1104 | } | ||
1105 | } | ||
1045 | else | 1106 | else |
1046 | { | 1107 | { |
1047 | // make it fall into small positive x case | 1108 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) |
1048 | dirv.X = 0.01f; | 1109 | { |
1049 | dirv.Y = curLocalVel.Y; | 1110 | torque.X -= curLocalAngVel.X * 10f; |
1050 | dirv.Z = curLocalVel.Z; | 1111 | torque.Y -= curLocalAngVel.Y * 10f; |
1112 | torque.Z -= curLocalAngVel.Z * 10f; | ||
1113 | } | ||
1051 | } | 1114 | } |
1115 | } | ||
1116 | else | ||
1117 | { | ||
1118 | // angular motor | ||
1119 | if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) | ||
1120 | { | ||
1121 | tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error | ||
1122 | tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep | ||
1123 | torque.X += tmpV.X * m_ampwr; | ||
1124 | torque.Y += tmpV.Y * m_ampwr; | ||
1125 | torque.Z += tmpV.Z; | ||
1052 | 1126 | ||
1053 | float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; | 1127 | m_amEfect *= m_amDecay; |
1128 | } | ||
1129 | else | ||
1130 | m_amEfect = 0; | ||
1054 | 1131 | ||
1055 | if (Math.Abs(dirv.Z) > 0.01) | 1132 | // angular deflection |
1133 | if (m_angularDeflectionEfficiency > 0) | ||
1056 | { | 1134 | { |
1057 | torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; | 1135 | Vector3 dirv; |
1136 | |||
1137 | if (curLocalVel.X > 0.01f) | ||
1138 | dirv = curLocalVel; | ||
1139 | else if (curLocalVel.X < -0.01f) | ||
1140 | // use oposite | ||
1141 | dirv = -curLocalVel; | ||
1142 | else | ||
1143 | { | ||
1144 | // make it fall into small positive x case | ||
1145 | dirv.X = 0.01f; | ||
1146 | dirv.Y = curLocalVel.Y; | ||
1147 | dirv.Z = curLocalVel.Z; | ||
1148 | } | ||
1149 | |||
1150 | float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; | ||
1151 | |||
1152 | if (Math.Abs(dirv.Z) > 0.01) | ||
1153 | { | ||
1154 | torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; | ||
1155 | } | ||
1156 | |||
1157 | if (Math.Abs(dirv.Y) > 0.01) | ||
1158 | { | ||
1159 | torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; | ||
1160 | } | ||
1058 | } | 1161 | } |
1059 | 1162 | ||
1060 | if (Math.Abs(dirv.Y) > 0.01) | 1163 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) |
1061 | { | 1164 | { |
1062 | torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; | 1165 | torque.X -= curLocalAngVel.X * m_amdampX; |
1166 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1167 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1063 | } | 1168 | } |
1064 | } | 1169 | } |
1065 | |||
1066 | // angular friction | ||
1067 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) | ||
1068 | { | ||
1069 | torque.X -= curLocalAngVel.X * m_amdampX; | ||
1070 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1071 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1072 | } | ||
1073 | 1170 | ||
1074 | force *= dmass.mass; | 1171 | force *= dmass.mass; |
1075 | 1172 | ||
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs index 6f2cbbe..4adf87e 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs | |||
@@ -306,7 +306,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
306 | public override uint LocalID | 306 | public override uint LocalID |
307 | { | 307 | { |
308 | get { return m_localID; } | 308 | get { return m_localID; } |
309 | set { m_localID = value; } | 309 | set |
310 | { | ||
311 | uint oldid = m_localID; | ||
312 | m_localID = value; | ||
313 | _parent_scene.changePrimID(this, oldid); | ||
314 | } | ||
310 | } | 315 | } |
311 | 316 | ||
312 | public override PhysicsActor ParentActor | 317 | public override PhysicsActor ParentActor |
@@ -1066,8 +1071,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1066 | public OdePrim(String primName, ODEScene parent_scene, Vector3 pos, Vector3 size, | 1071 | public OdePrim(String primName, ODEScene parent_scene, Vector3 pos, Vector3 size, |
1067 | Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID) | 1072 | Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID) |
1068 | { | 1073 | { |
1074 | _parent_scene = parent_scene; | ||
1075 | |||
1069 | Name = primName; | 1076 | Name = primName; |
1070 | LocalID = plocalID; | 1077 | m_localID = plocalID; |
1071 | 1078 | ||
1072 | m_vehicle = null; | 1079 | m_vehicle = null; |
1073 | 1080 | ||
@@ -1113,7 +1120,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1113 | 1120 | ||
1114 | _pbs = pbs; | 1121 | _pbs = pbs; |
1115 | 1122 | ||
1116 | _parent_scene = parent_scene; | ||
1117 | m_targetSpace = IntPtr.Zero; | 1123 | m_targetSpace = IntPtr.Zero; |
1118 | 1124 | ||
1119 | if (pos.Z < 0) | 1125 | if (pos.Z < 0) |
@@ -1159,6 +1165,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1159 | m_OBBOffset = repData.OBBOffset; | 1165 | m_OBBOffset = repData.OBBOffset; |
1160 | 1166 | ||
1161 | UpdatePrimBodyData(); | 1167 | UpdatePrimBodyData(); |
1168 | |||
1169 | AddChange(changes.Add, null); | ||
1162 | } | 1170 | } |
1163 | 1171 | ||
1164 | private void resetCollisionAccounting() | 1172 | private void resetCollisionAccounting() |
@@ -2441,6 +2449,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2441 | 2449 | ||
2442 | private void changeadd() | 2450 | private void changeadd() |
2443 | { | 2451 | { |
2452 | _parent_scene.addToPrims(this); | ||
2444 | } | 2453 | } |
2445 | 2454 | ||
2446 | private void changeAngularLock(byte newLocks) | 2455 | private void changeAngularLock(byte newLocks) |
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs index 6c5b405..e6aa7ef 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | using System; | 31 | using System; |
32 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
33 | using System.Linq; | ||
33 | using System.Reflection; | 34 | using System.Reflection; |
34 | using System.Runtime.InteropServices; | 35 | using System.Runtime.InteropServices; |
35 | using System.Threading; | 36 | using System.Threading; |
@@ -170,7 +171,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
170 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 171 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
171 | 172 | ||
172 | public bool m_OSOdeLib = false; | 173 | public bool m_OSOdeLib = false; |
173 | public bool m_suportCombine = false; // mega suport not tested | ||
174 | public Scene m_frameWorkScene = null; | 174 | public Scene m_frameWorkScene = null; |
175 | 175 | ||
176 | // private int threadid = 0; | 176 | // private int threadid = 0; |
@@ -258,9 +258,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
258 | 258 | ||
259 | public ContactData[] m_materialContactsData = new ContactData[8]; | 259 | public ContactData[] m_materialContactsData = new ContactData[8]; |
260 | 260 | ||
261 | private Dictionary<Vector3, IntPtr> RegionTerrain = new Dictionary<Vector3, IntPtr>(); | 261 | private IntPtr TerrainGeom; |
262 | private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); | 262 | private float[] TerrainHeightFieldHeight; |
263 | private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); | 263 | private GCHandle TerrainHeightFieldHeightsHandler = new GCHandle(); |
264 | 264 | ||
265 | private int m_physicsiterations = 15; | 265 | private int m_physicsiterations = 15; |
266 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 266 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
@@ -302,9 +302,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
302 | public int physics_logging_interval = 0; | 302 | public int physics_logging_interval = 0; |
303 | public bool physics_logging_append_existing_logfile = false; | 303 | public bool physics_logging_append_existing_logfile = false; |
304 | 304 | ||
305 | private Vector3 m_worldOffset = Vector3.Zero; | ||
306 | public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); | 305 | public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); |
307 | private PhysicsScene m_parentScene = null; | ||
308 | 306 | ||
309 | private ODERayCastRequestManager m_rayCastManager; | 307 | private ODERayCastRequestManager m_rayCastManager; |
310 | public ODEMeshWorker m_meshWorker; | 308 | public ODEMeshWorker m_meshWorker; |
@@ -379,8 +377,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
379 | WorldExtents.Y = m_frameWorkScene.RegionInfo.RegionSizeY; | 377 | WorldExtents.Y = m_frameWorkScene.RegionInfo.RegionSizeY; |
380 | m_regionHeight = (uint)WorldExtents.Y; | 378 | m_regionHeight = (uint)WorldExtents.Y; |
381 | 379 | ||
382 | m_suportCombine = false; | ||
383 | |||
384 | lock (OdeLock) | 380 | lock (OdeLock) |
385 | { | 381 | { |
386 | // Create the world and the first space | 382 | // Create the world and the first space |
@@ -803,14 +799,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
803 | return; | 799 | return; |
804 | } | 800 | } |
805 | 801 | ||
806 | // update actors collision score | ||
807 | if (p1.CollisionScore >= float.MaxValue - count) | ||
808 | p1.CollisionScore = 0; | ||
809 | p1.CollisionScore += count; | ||
810 | |||
811 | if (p2.CollisionScore >= float.MaxValue - count) | ||
812 | p2.CollisionScore = 0; | ||
813 | p2.CollisionScore += count; | ||
814 | 802 | ||
815 | // get first contact | 803 | // get first contact |
816 | d.ContactGeom curContact = new d.ContactGeom(); | 804 | d.ContactGeom curContact = new d.ContactGeom(); |
@@ -1056,6 +1044,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1056 | { | 1044 | { |
1057 | uint obj2LocalID = 0; | 1045 | uint obj2LocalID = 0; |
1058 | 1046 | ||
1047 | // update actors collision score | ||
1048 | if (p1.CollisionScore < float.MaxValue) | ||
1049 | p1.CollisionScore += 1.0f; | ||
1050 | if (p2.CollisionScore < float.MaxValue) | ||
1051 | p2.CollisionScore += 1.0f; | ||
1052 | |||
1059 | bool p1events = p1.SubscribedEvents(); | 1053 | bool p1events = p1.SubscribedEvents(); |
1060 | bool p2events = p2.SubscribedEvents(); | 1054 | bool p2events = p2.SubscribedEvents(); |
1061 | 1055 | ||
@@ -1328,8 +1322,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1328 | { | 1322 | { |
1329 | 1323 | ||
1330 | newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID); | 1324 | newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID); |
1331 | lock (_prims) | ||
1332 | _prims[newPrim.LocalID] = newPrim; | ||
1333 | } | 1325 | } |
1334 | return newPrim; | 1326 | return newPrim; |
1335 | } | 1327 | } |
@@ -1350,7 +1342,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1350 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | 1342 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, |
1351 | Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid) | 1343 | Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid) |
1352 | { | 1344 | { |
1353 | |||
1354 | return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid); | 1345 | return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid); |
1355 | } | 1346 | } |
1356 | 1347 | ||
@@ -1396,6 +1387,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1396 | 1387 | ||
1397 | } | 1388 | } |
1398 | 1389 | ||
1390 | public void addToPrims(OdePrim prim) | ||
1391 | { | ||
1392 | lock (_prims) | ||
1393 | _prims[prim.LocalID] = prim; | ||
1394 | } | ||
1395 | |||
1399 | public OdePrim getPrim(uint id) | 1396 | public OdePrim getPrim(uint id) |
1400 | { | 1397 | { |
1401 | lock (_prims) | 1398 | lock (_prims) |
@@ -1413,6 +1410,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1413 | return _prims.ContainsKey(prm.LocalID); | 1410 | return _prims.ContainsKey(prm.LocalID); |
1414 | } | 1411 | } |
1415 | 1412 | ||
1413 | public void changePrimID(OdePrim prim,uint oldID) | ||
1414 | { | ||
1415 | lock (_prims) | ||
1416 | { | ||
1417 | if(_prims.ContainsKey(oldID)) | ||
1418 | _prims.Remove(oldID); | ||
1419 | _prims[prim.LocalID] = prim; | ||
1420 | } | ||
1421 | } | ||
1422 | |||
1416 | public bool haveActor(PhysicsActor actor) | 1423 | public bool haveActor(PhysicsActor actor) |
1417 | { | 1424 | { |
1418 | if (actor is OdePrim) | 1425 | if (actor is OdePrim) |
@@ -1922,30 +1929,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1922 | 1929 | ||
1923 | public float GetTerrainHeightAtXY(float x, float y) | 1930 | public float GetTerrainHeightAtXY(float x, float y) |
1924 | { | 1931 | { |
1925 | 1932 | if (TerrainGeom == IntPtr.Zero) | |
1926 | int offsetX = 0; | ||
1927 | int offsetY = 0; | ||
1928 | |||
1929 | if (m_suportCombine) | ||
1930 | { | ||
1931 | offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
1932 | offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
1933 | } | ||
1934 | |||
1935 | // get region map | ||
1936 | IntPtr heightFieldGeom = IntPtr.Zero; | ||
1937 | if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom)) | ||
1938 | return 0f; | 1933 | return 0f; |
1939 | 1934 | ||
1940 | if (heightFieldGeom == IntPtr.Zero) | 1935 | if (TerrainHeightFieldHeight == null || TerrainHeightFieldHeight.Length == 0) |
1941 | return 0f; | ||
1942 | |||
1943 | if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom)) | ||
1944 | return 0f; | 1936 | return 0f; |
1945 | 1937 | ||
1946 | // TerrainHeightField for ODE as offset 1m | 1938 | // TerrainHeightField for ODE as offset 1m |
1947 | x += 1f - offsetX; | 1939 | x += 1f; |
1948 | y += 1f - offsetY; | 1940 | y += 1f; |
1949 | 1941 | ||
1950 | // make position fit into array | 1942 | // make position fit into array |
1951 | if (x < 0) | 1943 | if (x < 0) |
@@ -2024,7 +2016,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2024 | iy *= regsize; | 2016 | iy *= regsize; |
2025 | iy += ix; // all indexes have iy + ix | 2017 | iy += ix; // all indexes have iy + ix |
2026 | 2018 | ||
2027 | float[] heights = TerrainHeightFieldHeights[heightFieldGeom]; | 2019 | float[] heights = TerrainHeightFieldHeight; |
2028 | /* | 2020 | /* |
2029 | if ((dx + dy) <= 1.0f) | 2021 | if ((dx + dy) <= 1.0f) |
2030 | { | 2022 | { |
@@ -2061,31 +2053,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2061 | 2053 | ||
2062 | public Vector3 GetTerrainNormalAtXY(float x, float y) | 2054 | public Vector3 GetTerrainNormalAtXY(float x, float y) |
2063 | { | 2055 | { |
2064 | int offsetX = 0; | ||
2065 | int offsetY = 0; | ||
2066 | |||
2067 | if (m_suportCombine) | ||
2068 | { | ||
2069 | offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
2070 | offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; | ||
2071 | } | ||
2072 | |||
2073 | // get region map | ||
2074 | IntPtr heightFieldGeom = IntPtr.Zero; | ||
2075 | Vector3 norm = new Vector3(0, 0, 1); | 2056 | Vector3 norm = new Vector3(0, 0, 1); |
2076 | 2057 | ||
2077 | if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom)) | 2058 | if (TerrainGeom == IntPtr.Zero) |
2078 | return norm; ; | ||
2079 | |||
2080 | if (heightFieldGeom == IntPtr.Zero) | ||
2081 | return norm; | 2059 | return norm; |
2082 | 2060 | ||
2083 | if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom)) | 2061 | if (TerrainHeightFieldHeight == null || TerrainHeightFieldHeight.Length == 0) |
2084 | return norm; | 2062 | return norm; |
2085 | 2063 | ||
2086 | // TerrainHeightField for ODE as offset 1m | 2064 | // TerrainHeightField for ODE as offset 1m |
2087 | x += 1f - offsetX; | 2065 | x += 1f; |
2088 | y += 1f - offsetY; | 2066 | y += 1f; |
2089 | 2067 | ||
2090 | // make position fit into array | 2068 | // make position fit into array |
2091 | if (x < 0) | 2069 | if (x < 0) |
@@ -2172,7 +2150,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2172 | iy *= regsize; | 2150 | iy *= regsize; |
2173 | iy += ix; // all indexes have iy + ix | 2151 | iy += ix; // all indexes have iy + ix |
2174 | 2152 | ||
2175 | float[] heights = TerrainHeightFieldHeights[heightFieldGeom]; | 2153 | float[] heights = TerrainHeightFieldHeight; |
2176 | 2154 | ||
2177 | if (firstTri) | 2155 | if (firstTri) |
2178 | { | 2156 | { |
@@ -2199,34 +2177,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2199 | 2177 | ||
2200 | public override void SetTerrain(float[] heightMap) | 2178 | public override void SetTerrain(float[] heightMap) |
2201 | { | 2179 | { |
2202 | if (m_worldOffset != Vector3.Zero && m_parentScene != null) | ||
2203 | { | ||
2204 | if (m_parentScene is ODEScene) | ||
2205 | { | ||
2206 | ((ODEScene)m_parentScene).SetTerrain(heightMap, m_worldOffset); | ||
2207 | } | ||
2208 | } | ||
2209 | else | ||
2210 | { | ||
2211 | SetTerrain(heightMap, m_worldOffset); | ||
2212 | } | ||
2213 | } | ||
2214 | |||
2215 | public override void CombineTerrain(float[] heightMap, Vector3 pOffset) | ||
2216 | { | ||
2217 | if(m_suportCombine) | ||
2218 | SetTerrain(heightMap, pOffset); | ||
2219 | } | ||
2220 | |||
2221 | public void SetTerrain(float[] heightMap, Vector3 pOffset) | ||
2222 | { | ||
2223 | if (m_OSOdeLib) | 2180 | if (m_OSOdeLib) |
2224 | OSSetTerrain(heightMap, pOffset); | 2181 | OSSetTerrain(heightMap); |
2225 | else | 2182 | else |
2226 | OriSetTerrain(heightMap, pOffset); | 2183 | OriSetTerrain(heightMap); |
2227 | } | 2184 | } |
2228 | 2185 | ||
2229 | public void OriSetTerrain(float[] heightMap, Vector3 pOffset) | 2186 | public void OriSetTerrain(float[] heightMap) |
2230 | { | 2187 | { |
2231 | // assumes 1m size grid and constante size square regions | 2188 | // assumes 1m size grid and constante size square regions |
2232 | // needs to know about sims around in future | 2189 | // needs to know about sims around in future |
@@ -2291,45 +2248,40 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2291 | { | 2248 | { |
2292 | d.AllocateODEDataForThread(~0U); | 2249 | d.AllocateODEDataForThread(~0U); |
2293 | 2250 | ||
2294 | IntPtr GroundGeom = IntPtr.Zero; | 2251 | if (TerrainGeom != IntPtr.Zero) |
2295 | if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) | ||
2296 | { | 2252 | { |
2297 | RegionTerrain.Remove(pOffset); | 2253 | actor_name_map.Remove(TerrainGeom); |
2298 | if (GroundGeom != IntPtr.Zero) | 2254 | d.GeomDestroy(TerrainGeom); |
2299 | { | ||
2300 | actor_name_map.Remove(GroundGeom); | ||
2301 | d.GeomDestroy(GroundGeom); | ||
2302 | 2255 | ||
2303 | if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) | ||
2304 | { | ||
2305 | TerrainHeightFieldHeightsHandlers[GroundGeom].Free(); | ||
2306 | TerrainHeightFieldHeightsHandlers.Remove(GroundGeom); | ||
2307 | TerrainHeightFieldHeights.Remove(GroundGeom); | ||
2308 | } | ||
2309 | } | ||
2310 | } | 2256 | } |
2257 | |||
2258 | if (TerrainHeightFieldHeightsHandler.IsAllocated) | ||
2259 | TerrainHeightFieldHeightsHandler.Free(); | ||
2260 | |||
2311 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 2261 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
2312 | 2262 | ||
2313 | GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); | 2263 | GC.Collect(1); |
2264 | |||
2265 | TerrainHeightFieldHeightsHandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); | ||
2314 | 2266 | ||
2315 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, | 2267 | d.GeomHeightfieldDataBuildSingle(HeightmapData, TerrainHeightFieldHeightsHandler.AddrOfPinnedObject(), 0, |
2316 | heightmapHeight, heightmapWidth , | 2268 | heightmapHeight, heightmapWidth , |
2317 | (int)heightmapHeightSamples, (int)heightmapWidthSamples, scale, | 2269 | (int)heightmapHeightSamples, (int)heightmapWidthSamples, scale, |
2318 | offset, thickness, wrap); | 2270 | offset, thickness, wrap); |
2319 | 2271 | ||
2320 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); | 2272 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); |
2321 | 2273 | ||
2322 | GroundGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1); | 2274 | TerrainGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1); |
2323 | 2275 | ||
2324 | if (GroundGeom != IntPtr.Zero) | 2276 | if (TerrainGeom != IntPtr.Zero) |
2325 | { | 2277 | { |
2326 | d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); | 2278 | d.GeomSetCategoryBits(TerrainGeom, (uint)(CollisionCategories.Land)); |
2327 | d.GeomSetCollideBits(GroundGeom, 0); | 2279 | d.GeomSetCollideBits(TerrainGeom, 0); |
2328 | 2280 | ||
2329 | PhysicsActor pa = new NullPhysicsActor(); | 2281 | PhysicsActor pa = new NullPhysicsActor(); |
2330 | pa.Name = "Terrain"; | 2282 | pa.Name = "Terrain"; |
2331 | pa.PhysicsActorType = (int)ActorTypes.Ground; | 2283 | pa.PhysicsActorType = (int)ActorTypes.Ground; |
2332 | actor_name_map[GroundGeom] = pa; | 2284 | actor_name_map[TerrainGeom] = pa; |
2333 | 2285 | ||
2334 | // geom_name_map[GroundGeom] = "Terrain"; | 2286 | // geom_name_map[GroundGeom] = "Terrain"; |
2335 | 2287 | ||
@@ -2339,16 +2291,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2339 | q.Z = 0.5f; | 2291 | q.Z = 0.5f; |
2340 | q.W = 0.5f; | 2292 | q.W = 0.5f; |
2341 | 2293 | ||
2342 | d.GeomSetQuaternion(GroundGeom, ref q); | 2294 | d.GeomSetQuaternion(TerrainGeom, ref q); |
2343 | d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0.0f); | 2295 | d.GeomSetPosition(TerrainGeom, m_regionWidth * 0.5f, m_regionHeight * 0.5f, 0.0f); |
2344 | RegionTerrain.Add(pOffset, GroundGeom); | 2296 | TerrainHeightFieldHeight = _heightmap; |
2345 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); | ||
2346 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); | ||
2347 | } | 2297 | } |
2298 | else | ||
2299 | TerrainHeightFieldHeightsHandler.Free(); | ||
2348 | } | 2300 | } |
2349 | } | 2301 | } |
2350 | 2302 | ||
2351 | public void OSSetTerrain(float[] heightMap, Vector3 pOffset) | 2303 | public void OSSetTerrain(float[] heightMap) |
2352 | { | 2304 | { |
2353 | // assumes 1m size grid and constante size square regions | 2305 | // assumes 1m size grid and constante size square regions |
2354 | // needs to know about sims around in future | 2306 | // needs to know about sims around in future |
@@ -2402,26 +2354,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2402 | } | 2354 | } |
2403 | yt += heightmapWidthSamples; | 2355 | yt += heightmapWidthSamples; |
2404 | } | 2356 | } |
2357 | |||
2405 | lock (OdeLock) | 2358 | lock (OdeLock) |
2406 | { | 2359 | { |
2407 | IntPtr GroundGeom = IntPtr.Zero; | 2360 | if (TerrainGeom != IntPtr.Zero) |
2408 | if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) | ||
2409 | { | 2361 | { |
2410 | RegionTerrain.Remove(pOffset); | 2362 | actor_name_map.Remove(TerrainGeom); |
2411 | if (GroundGeom != IntPtr.Zero) | 2363 | d.GeomDestroy(TerrainGeom); |
2412 | { | ||
2413 | actor_name_map.Remove(GroundGeom); | ||
2414 | d.GeomDestroy(GroundGeom); | ||
2415 | |||
2416 | if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) | ||
2417 | { | ||
2418 | if (TerrainHeightFieldHeightsHandlers[GroundGeom].IsAllocated) | ||
2419 | TerrainHeightFieldHeightsHandlers[GroundGeom].Free(); | ||
2420 | TerrainHeightFieldHeightsHandlers.Remove(GroundGeom); | ||
2421 | TerrainHeightFieldHeights.Remove(GroundGeom); | ||
2422 | } | ||
2423 | } | ||
2424 | } | 2364 | } |
2365 | |||
2366 | if (TerrainHeightFieldHeightsHandler.IsAllocated) | ||
2367 | TerrainHeightFieldHeightsHandler.Free(); | ||
2368 | |||
2369 | TerrainHeightFieldHeight = null; | ||
2370 | |||
2425 | IntPtr HeightmapData = d.GeomOSTerrainDataCreate(); | 2371 | IntPtr HeightmapData = d.GeomOSTerrainDataCreate(); |
2426 | 2372 | ||
2427 | const int wrap = 0; | 2373 | const int wrap = 0; |
@@ -2429,32 +2375,31 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2429 | if (thickness < 0) | 2375 | if (thickness < 0) |
2430 | thickness = 1; | 2376 | thickness = 1; |
2431 | 2377 | ||
2432 | GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); | 2378 | TerrainHeightFieldHeightsHandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); |
2433 | 2379 | ||
2434 | d.GeomOSTerrainDataBuild(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, 1.0f, | 2380 | d.GeomOSTerrainDataBuild(HeightmapData, TerrainHeightFieldHeightsHandler.AddrOfPinnedObject(), 0, 1.0f, |
2435 | (int)heightmapWidthSamples, (int)heightmapHeightSamples, | 2381 | (int)heightmapWidthSamples, (int)heightmapHeightSamples, |
2436 | thickness, wrap); | 2382 | thickness, wrap); |
2437 | 2383 | ||
2438 | // d.GeomOSTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); | 2384 | // d.GeomOSTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); |
2439 | GroundGeom = d.CreateOSTerrain(GroundSpace, HeightmapData, 1); | 2385 | TerrainGeom = d.CreateOSTerrain(GroundSpace, HeightmapData, 1); |
2440 | if (GroundGeom != IntPtr.Zero) | 2386 | if (TerrainGeom != IntPtr.Zero) |
2441 | { | 2387 | { |
2442 | d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); | 2388 | d.GeomSetCategoryBits(TerrainGeom, (uint)(CollisionCategories.Land)); |
2443 | d.GeomSetCollideBits(GroundGeom, 0); | 2389 | d.GeomSetCollideBits(TerrainGeom, 0); |
2444 | |||
2445 | 2390 | ||
2446 | PhysicsActor pa = new NullPhysicsActor(); | 2391 | PhysicsActor pa = new NullPhysicsActor(); |
2447 | pa.Name = "Terrain"; | 2392 | pa.Name = "Terrain"; |
2448 | pa.PhysicsActorType = (int)ActorTypes.Ground; | 2393 | pa.PhysicsActorType = (int)ActorTypes.Ground; |
2449 | actor_name_map[GroundGeom] = pa; | 2394 | actor_name_map[TerrainGeom] = pa; |
2450 | 2395 | ||
2451 | // geom_name_map[GroundGeom] = "Terrain"; | 2396 | // geom_name_map[GroundGeom] = "Terrain"; |
2452 | 2397 | ||
2453 | d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0.0f); | 2398 | d.GeomSetPosition(TerrainGeom, m_regionWidth * 0.5f, m_regionHeight * 0.5f, 0.0f); |
2454 | RegionTerrain.Add(pOffset, GroundGeom); | 2399 | TerrainHeightFieldHeight = _heightmap; |
2455 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); | 2400 | } |
2456 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); | 2401 | else |
2457 | } | 2402 | TerrainHeightFieldHeightsHandler.Free(); |
2458 | } | 2403 | } |
2459 | } | 2404 | } |
2460 | 2405 | ||
@@ -2467,11 +2412,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2467 | return waterlevel; | 2412 | return waterlevel; |
2468 | } | 2413 | } |
2469 | 2414 | ||
2470 | public override bool SupportsCombining() | ||
2471 | { | ||
2472 | return m_suportCombine; | ||
2473 | } | ||
2474 | |||
2475 | public override void SetWaterLevel(float baseheight) | 2415 | public override void SetWaterLevel(float baseheight) |
2476 | { | 2416 | { |
2477 | waterlevel = baseheight; | 2417 | waterlevel = baseheight; |
@@ -2518,26 +2458,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2518 | foreach (OdeCharacter ch in chtorem) | 2458 | foreach (OdeCharacter ch in chtorem) |
2519 | ch.DoAChange(changes.Remove, null); | 2459 | ch.DoAChange(changes.Remove, null); |
2520 | 2460 | ||
2461 | if (TerrainGeom != IntPtr.Zero) | ||
2462 | d.GeomDestroy(TerrainGeom); | ||
2463 | TerrainGeom = IntPtr.Zero; | ||
2521 | 2464 | ||
2522 | foreach (IntPtr GroundGeom in RegionTerrain.Values) | 2465 | if (TerrainHeightFieldHeightsHandler.IsAllocated) |
2523 | { | 2466 | TerrainHeightFieldHeightsHandler.Free(); |
2524 | if (GroundGeom != IntPtr.Zero) | ||
2525 | d.GeomDestroy(GroundGeom); | ||
2526 | } | ||
2527 | 2467 | ||
2528 | RegionTerrain.Clear(); | 2468 | TerrainHeightFieldHeight = null; |
2529 | |||
2530 | if (TerrainHeightFieldHeightsHandlers.Count > 0) | ||
2531 | { | ||
2532 | foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values) | ||
2533 | { | ||
2534 | if (gch.IsAllocated) | ||
2535 | gch.Free(); | ||
2536 | } | ||
2537 | } | ||
2538 | |||
2539 | TerrainHeightFieldHeightsHandlers.Clear(); | ||
2540 | TerrainHeightFieldHeights.Clear(); | ||
2541 | 2469 | ||
2542 | if (ContactgeomsArray != IntPtr.Zero) | 2470 | if (ContactgeomsArray != IntPtr.Zero) |
2543 | { | 2471 | { |
@@ -2556,27 +2484,22 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
2556 | } | 2484 | } |
2557 | } | 2485 | } |
2558 | 2486 | ||
2487 | private int compareByCollisionsDesc(OdePrim A, OdePrim B) | ||
2488 | { | ||
2489 | return -A.CollisionScore.CompareTo(B.CollisionScore); | ||
2490 | } | ||
2491 | |||
2559 | public override Dictionary<uint, float> GetTopColliders() | 2492 | public override Dictionary<uint, float> GetTopColliders() |
2560 | { | 2493 | { |
2561 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | 2494 | Dictionary<uint, float> topColliders; |
2562 | int cnt = 0; | 2495 | List<OdePrim> orderedPrims; |
2563 | lock (_prims) | 2496 | lock (_activeprims) |
2564 | { | 2497 | orderedPrims = new List<OdePrim>(_activeprims); |
2565 | foreach (OdePrim prm in _prims.Values) | 2498 | |
2566 | { | 2499 | orderedPrims.Sort(compareByCollisionsDesc); |
2567 | if (prm.CollisionScore > 0) | 2500 | topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); |
2568 | { | 2501 | |
2569 | returncolliders.Add(prm.LocalID, prm.CollisionScore); | 2502 | return topColliders; |
2570 | cnt++; | ||
2571 | prm.CollisionScore = 0f; | ||
2572 | if (cnt > 25) | ||
2573 | { | ||
2574 | break; | ||
2575 | } | ||
2576 | } | ||
2577 | } | ||
2578 | } | ||
2579 | return returncolliders; | ||
2580 | } | 2503 | } |
2581 | 2504 | ||
2582 | public override bool SupportsRayCast() | 2505 | public override bool SupportsRayCast() |