aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs283
1 files changed, 103 insertions, 180 deletions
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
31using System; 31using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Linq;
33using System.Reflection; 34using System.Reflection;
34using System.Runtime.InteropServices; 35using System.Runtime.InteropServices;
35using System.Threading; 36using 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()