aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-05 17:38:27 -0700
committerJohn Hurliman2009-10-05 17:38:27 -0700
commit7ddb6fbced5f2a98aa0201e354987ebc32adf7d2 (patch)
tree903b87112e7f851218e7b3d41c681f1b8f512af2 /OpenSim/Region
parentBeginning work on the new LLUDP implementation (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-7ddb6fbced5f2a98aa0201e354987ebc32adf7d2.zip
opensim-SC_OLD-7ddb6fbced5f2a98aa0201e354987ebc32adf7d2.tar.gz
opensim-SC_OLD-7ddb6fbced5f2a98aa0201e354987ebc32adf7d2.tar.bz2
opensim-SC_OLD-7ddb6fbced5f2a98aa0201e354987ebc32adf7d2.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim into htb-throttle
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs42
-rw-r--r--OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs12
-rw-r--r--OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs2
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs5
-rw-r--r--OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs14
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs14
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs13
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs12
-rw-r--r--OpenSim/Region/Physics/Manager/IMesher.cs2
-rw-r--r--OpenSim/Region/Physics/Meshing/Mesh.cs166
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs12
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs13
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs7
15 files changed, 206 insertions, 112 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
index 5219df7..343f537 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs
@@ -88,7 +88,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
88 J2KImage imgrequest; 88 J2KImage imgrequest;
89 89
90 // Do a linear search for this texture download 90 // Do a linear search for this texture download
91 lock (m_priorityQueue) 91 lock (m_syncRoot)
92 m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest); 92 m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest);
93 93
94 if (imgrequest != null) 94 if (imgrequest != null)
@@ -99,7 +99,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
99 99
100 try 100 try
101 { 101 {
102 lock (m_priorityQueue) 102 lock (m_syncRoot)
103 m_priorityQueue.Delete(imgrequest.PriorityQueueHandle); 103 m_priorityQueue.Delete(imgrequest.PriorityQueueHandle);
104 } 104 }
105 catch (Exception) { } 105 catch (Exception) { }
@@ -167,8 +167,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
167 J2KImage imagereq; 167 J2KImage imagereq;
168 int numCollected = 0; 168 int numCollected = 0;
169 169
170 lock (m_syncRoot) 170 //lock (m_syncRoot)
171 { 171 //{
172 m_lastloopprocessed = DateTime.Now.Ticks; 172 m_lastloopprocessed = DateTime.Now.Ticks;
173 173
174 // This can happen during Close() 174 // This can happen during Close()
@@ -191,7 +191,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
191 if (numCollected == count) 191 if (numCollected == count)
192 break; 192 break;
193 } 193 }
194 } 194 //}
195 195
196 return m_priorityQueue.Count > 0; 196 return m_priorityQueue.Count > 0;
197 } 197 }
@@ -211,16 +211,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
211 { 211 {
212 J2KImage image = null; 212 J2KImage image = null;
213 213
214 if (m_priorityQueue.Count > 0) 214 lock (m_syncRoot)
215 { 215 {
216 try 216
217 if (m_priorityQueue.Count > 0)
217 { 218 {
218 lock (m_priorityQueue) 219 try
220 {
219 image = m_priorityQueue.FindMax(); 221 image = m_priorityQueue.FindMax();
222 }
223 catch (Exception) { }
220 } 224 }
221 catch (Exception) { }
222 } 225 }
223
224 return image; 226 return image;
225 } 227 }
226 228
@@ -228,23 +230,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP
228 { 230 {
229 image.PriorityQueueHandle = null; 231 image.PriorityQueueHandle = null;
230 232
231 lock (m_priorityQueue) 233 lock (m_syncRoot)
232 m_priorityQueue.Add(ref image.PriorityQueueHandle, image); 234 try
235 {
236 m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
237 }
238 catch (Exception) { }
233 } 239 }
234 240
235 void RemoveImageFromQueue(J2KImage image) 241 void RemoveImageFromQueue(J2KImage image)
236 { 242 {
237 try 243 lock (m_syncRoot)
238 { 244 try
239 lock (m_priorityQueue) 245 {
240 m_priorityQueue.Delete(image.PriorityQueueHandle); 246 m_priorityQueue.Delete(image.PriorityQueueHandle);
241 } 247 }
242 catch (Exception) { } 248 catch (Exception) { }
243 } 249 }
244 250
245 void UpdateImageInQueue(J2KImage image) 251 void UpdateImageInQueue(J2KImage image)
246 { 252 {
247 lock (m_priorityQueue) 253 lock (m_syncRoot)
248 { 254 {
249 try { m_priorityQueue.Replace(image.PriorityQueueHandle, image); } 255 try { m_priorityQueue.Replace(image.PriorityQueueHandle, image); }
250 catch (Exception) 256 catch (Exception)
diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
index 5a5ad7e..66ca7c2 100644
--- a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
@@ -178,7 +178,7 @@ namespace OpenSim.Region.CoreModules.Asset
178 { 178 {
179 if (maximalSize <= 0 || maximalCount <= 0) 179 if (maximalSize <= 0 || maximalCount <= 0)
180 { 180 {
181 Log.Info("[ASSET CACHE]: Cenome asset cache is not enabled."); 181 //Log.Debug("[ASSET CACHE]: Cenome asset cache is not enabled.");
182 m_enabled = false; 182 m_enabled = false;
183 return; 183 return;
184 } 184 }
@@ -194,7 +194,7 @@ namespace OpenSim.Region.CoreModules.Asset
194 CnmSynchronizedCache<string, AssetBase>.Synchronized(new CnmMemoryCache<string, AssetBase>( 194 CnmSynchronizedCache<string, AssetBase>.Synchronized(new CnmMemoryCache<string, AssetBase>(
195 maximalSize, maximalCount, expirationTime)); 195 maximalSize, maximalCount, expirationTime));
196 m_enabled = true; 196 m_enabled = true;
197 Log.InfoFormat( 197 Log.DebugFormat(
198 "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})", 198 "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})",
199 maximalSize, 199 maximalSize,
200 maximalCount, 200 maximalCount,
@@ -263,7 +263,7 @@ namespace OpenSim.Region.CoreModules.Asset
263 263
264 if (m_getCount == m_debugEpoch) 264 if (m_getCount == m_debugEpoch)
265 { 265 {
266 Log.InfoFormat( 266 Log.DebugFormat(
267 "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes", 267 "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes",
268 m_cachedCount, 268 m_cachedCount,
269 m_getCount, 269 m_getCount,
@@ -333,7 +333,7 @@ namespace OpenSim.Region.CoreModules.Asset
333 return; 333 return;
334 334
335 string name = moduleConfig.GetString("AssetCaching"); 335 string name = moduleConfig.GetString("AssetCaching");
336 Log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name); 336 //Log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);
337 337
338 if (name != Name) 338 if (name != Name)
339 return; 339 return;
@@ -343,14 +343,14 @@ namespace OpenSim.Region.CoreModules.Asset
343 int maxCount = DefaultMaxCount; 343 int maxCount = DefaultMaxCount;
344 TimeSpan expirationTime = DefaultExpirationTime; 344 TimeSpan expirationTime = DefaultExpirationTime;
345 345
346 IConfig assetConfig = source.Configs[ "AssetCache" ]; 346 IConfig assetConfig = source.Configs["AssetCache"];
347 if (assetConfig != null) 347 if (assetConfig != null)
348 { 348 {
349 // Get optional configurations 349 // Get optional configurations
350 maxSize = assetConfig.GetLong("MaxSize", DefaultMaxSize); 350 maxSize = assetConfig.GetLong("MaxSize", DefaultMaxSize);
351 maxCount = assetConfig.GetInt("MaxCount", DefaultMaxCount); 351 maxCount = assetConfig.GetInt("MaxCount", DefaultMaxCount);
352 expirationTime = 352 expirationTime =
353 TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int) DefaultExpirationTime.TotalMinutes)); 353 TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int)DefaultExpirationTime.TotalMinutes));
354 354
355 // Debugging purposes only 355 // Debugging purposes only
356 m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0); 356 m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
diff --git a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
index 2de40d2..0a7e736 100644
--- a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
@@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules.Asset
66 if (moduleConfig != null) 66 if (moduleConfig != null)
67 { 67 {
68 string name = moduleConfig.GetString("AssetCaching"); 68 string name = moduleConfig.GetString("AssetCaching");
69 m_log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name); 69 //m_log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);
70 70
71 if (name == Name) 71 if (name == Name)
72 { 72 {
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index c0bb70c..b81ab41 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -636,11 +636,8 @@ namespace Flotsam.RegionModules.AssetCache
636 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); 636 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk");
637 637
638 } 638 }
639
640
641 } 639 }
642 640
643 #endregion 641 #endregion
644
645 } 642 }
646} 643} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
index 8d8e0fe..4869f5d 100644
--- a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Region.CoreModules.Asset
68 if (moduleConfig != null) 68 if (moduleConfig != null)
69 { 69 {
70 string name = moduleConfig.GetString("AssetCaching"); 70 string name = moduleConfig.GetString("AssetCaching");
71 m_log.DebugFormat("[ASSET CACHE] name = {0} (this module's name: {1}). Sync? ", name, Name, m_Cache.IsSynchronized); 71 //m_log.DebugFormat("[ASSET CACHE] name = {0} (this module's name: {1}). Sync? ", name, Name, m_Cache.IsSynchronized);
72 72
73 if (name == Name) 73 if (name == Name)
74 { 74 {
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 3ca4882..1c72488 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -206,6 +206,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
206 206
207 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 207 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
208 { 208 {
209 GridRegion region = null;
210
211 // First see if it's a neighbour, even if it isn't on this sim.
212 // Neighbour data is cached in memory, so this is fast
213 foreach (RegionCache rcache in m_LocalCache.Values)
214 {
215 region = rcache.GetRegionByPosition(x, y);
216 if (region != null)
217 {
218 return region;
219 }
220 }
221
222 // Then try on this sim (may be a lookup in DB if this is using MySql).
209 return m_GridService.GetRegionByPosition(scopeID, x, y); 223 return m_GridService.GetRegionByPosition(scopeID, x, y);
210 } 224 }
211 225
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
index 2b336bb..44e850b 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
@@ -29,10 +29,12 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31 31
32using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces; 34using OpenSim.Services.Interfaces;
34using GridRegion = OpenSim.Services.Interfaces.GridRegion; 35using GridRegion = OpenSim.Services.Interfaces.GridRegion;
35 36
37using OpenMetaverse;
36using log4net; 38using log4net;
37 39
38namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid 40namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
@@ -75,5 +77,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
75 { 77 {
76 return new List<GridRegion>(m_neighbours.Values); 78 return new List<GridRegion>(m_neighbours.Values);
77 } 79 }
80
81 public GridRegion GetRegionByPosition(int x, int y)
82 {
83 uint xsnap = (uint)(x / Constants.RegionSize) * Constants.RegionSize;
84 uint ysnap = (uint)(y / Constants.RegionSize) * Constants.RegionSize;
85 ulong handle = Utils.UIntsToLong(xsnap, ysnap);
86
87 if (m_neighbours.ContainsKey(handle))
88 return m_neighbours[handle];
89
90 return null;
91 }
78 } 92 }
79} 93}
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index 9622555..901144a 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -397,10 +397,15 @@ namespace OpenSim.Region.CoreModules.World.Permissions
397 // with the powers requested (powers = 0 for no powers check) 397 // with the powers requested (powers = 0 for no powers check)
398 protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers) 398 protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
399 { 399 {
400 IClientAPI client = m_scene.GetScenePresence(userID).ControllingClient; 400 ScenePresence sp = m_scene.GetScenePresence(userID);
401 401 if (sp != null)
402 return ((groupID == client.ActiveGroupId) && (client.ActiveGroupPowers != 0) && 402 {
403 ((powers == 0) || ((client.ActiveGroupPowers & powers) == powers))); 403 IClientAPI client = sp.ControllingClient;
404
405 return ((groupID == client.ActiveGroupId) && (client.ActiveGroupPowers != 0) &&
406 ((powers == 0) || ((client.ActiveGroupPowers & powers) == powers)));
407 }
408 return false;
404 } 409 }
405 410
406 /// <summary> 411 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
index 631d801..00fe5df 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
@@ -425,7 +425,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
425 425
426 foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID)) 426 foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID))
427 { 427 {
428 if (m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid)) 428 if (!m_agentsDroppedSession.ContainsKey(im.imSessionID) || m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid))
429 { 429 {
430 // Don't deliver messages to people who have dropped this session 430 // Don't deliver messages to people who have dropped this session
431 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID); 431 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
index 2e89a24..b209199 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
@@ -148,9 +148,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
148 UUID[] CurrentKeys = new UUID[m_clientRequestIDInfo.Count]; 148 UUID[] CurrentKeys = new UUID[m_clientRequestIDInfo.Count];
149 foreach (UUID key in CurrentKeys) 149 foreach (UUID key in CurrentKeys)
150 { 150 {
151 if (DateTime.Now - m_clientRequestIDInfo[key].LastUsedTMStamp > cacheTimeout) 151 if (m_clientRequestIDInfo.ContainsKey(key))
152 { 152 {
153 m_clientRequestIDInfo.Remove(key); 153 if (DateTime.Now - m_clientRequestIDInfo[key].LastUsedTMStamp > cacheTimeout)
154 {
155 m_clientRequestIDInfo.Remove(key);
156 }
154 } 157 }
155 } 158 }
156 } 159 }
@@ -476,7 +479,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
476 479
477 foreach (string key in binBucketOSD.Keys) 480 foreach (string key in binBucketOSD.Keys)
478 { 481 {
479 m_log.WarnFormat("{0}: {1}", key, binBucketOSD[key].ToString()); 482 if (binBucketOSD.ContainsKey(key))
483 {
484 m_log.WarnFormat("{0}: {1}", key, binBucketOSD[key].ToString());
485 }
480 } 486 }
481 } 487 }
482 488
diff --git a/OpenSim/Region/Physics/Manager/IMesher.cs b/OpenSim/Region/Physics/Manager/IMesher.cs
index e26c623..ac14292 100644
--- a/OpenSim/Region/Physics/Manager/IMesher.cs
+++ b/OpenSim/Region/Physics/Manager/IMesher.cs
@@ -47,6 +47,8 @@ namespace OpenSim.Region.Physics.Manager
47 int[] getIndexListAsInt(); 47 int[] getIndexListAsInt();
48 int[] getIndexListAsIntLocked(); 48 int[] getIndexListAsIntLocked();
49 float[] getVertexListAsFloatLocked(); 49 float[] getVertexListAsFloatLocked();
50 void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount);
51 void getVertexListAsPtrToFloatArray( out IntPtr vertexList, out int vertexStride, out int vertexCount );
50 void releaseSourceMeshData(); 52 void releaseSourceMeshData();
51 void releasePinned(); 53 void releasePinned();
52 void Append(IMesh newMesh); 54 void Append(IMesh newMesh);
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs
index aae8871..ff1f816 100644
--- a/OpenSim/Region/Physics/Meshing/Mesh.cs
+++ b/OpenSim/Region/Physics/Meshing/Mesh.cs
@@ -36,23 +36,27 @@ namespace OpenSim.Region.Physics.Meshing
36{ 36{
37 public class Mesh : IMesh 37 public class Mesh : IMesh
38 { 38 {
39 private Dictionary<Vertex, int> vertices; 39 private Dictionary<Vertex, int> m_vertices;
40 private List<Triangle> triangles; 40 private List<Triangle> m_triangles;
41 GCHandle pinnedVirtexes; 41 GCHandle m_pinnedVertexes;
42 GCHandle pinnedIndex; 42 GCHandle m_pinnedIndex;
43 public float[] normals; 43 IntPtr m_verticesPtr = IntPtr.Zero;
44 int m_vertexCount = 0;
45 IntPtr m_indicesPtr = IntPtr.Zero;
46 int m_indexCount = 0;
47 public float[] m_normals;
44 48
45 public Mesh() 49 public Mesh()
46 { 50 {
47 vertices = new Dictionary<Vertex, int>(); 51 m_vertices = new Dictionary<Vertex, int>();
48 triangles = new List<Triangle>(); 52 m_triangles = new List<Triangle>();
49 } 53 }
50 54
51 public Mesh Clone() 55 public Mesh Clone()
52 { 56 {
53 Mesh result = new Mesh(); 57 Mesh result = new Mesh();
54 58
55 foreach (Triangle t in triangles) 59 foreach (Triangle t in m_triangles)
56 { 60 {
57 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone())); 61 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone()));
58 } 62 }
@@ -62,27 +66,27 @@ namespace OpenSim.Region.Physics.Meshing
62 66
63 public void Add(Triangle triangle) 67 public void Add(Triangle triangle)
64 { 68 {
65 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated) 69 if (m_pinnedIndex.IsAllocated || m_pinnedVertexes.IsAllocated || m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
66 throw new NotSupportedException("Attempt to Add to a pinned Mesh"); 70 throw new NotSupportedException("Attempt to Add to a pinned Mesh");
67 // If a vertex of the triangle is not yet in the vertices list, 71 // If a vertex of the triangle is not yet in the vertices list,
68 // add it and set its index to the current index count 72 // add it and set its index to the current index count
69 if (!vertices.ContainsKey(triangle.v1)) 73 if( !m_vertices.ContainsKey(triangle.v1) )
70 vertices[triangle.v1] = vertices.Count; 74 m_vertices[triangle.v1] = m_vertices.Count;
71 if (!vertices.ContainsKey(triangle.v2)) 75 if (!m_vertices.ContainsKey(triangle.v2))
72 vertices[triangle.v2] = vertices.Count; 76 m_vertices[triangle.v2] = m_vertices.Count;
73 if (!vertices.ContainsKey(triangle.v3)) 77 if (!m_vertices.ContainsKey(triangle.v3))
74 vertices[triangle.v3] = vertices.Count; 78 m_vertices[triangle.v3] = m_vertices.Count;
75 triangles.Add(triangle); 79 m_triangles.Add(triangle);
76 } 80 }
77 81
78 public void CalcNormals() 82 public void CalcNormals()
79 { 83 {
80 int iTriangles = triangles.Count; 84 int iTriangles = m_triangles.Count;
81 85
82 this.normals = new float[iTriangles * 3]; 86 this.m_normals = new float[iTriangles * 3];
83 87
84 int i = 0; 88 int i = 0;
85 foreach (Triangle t in triangles) 89 foreach (Triangle t in m_triangles)
86 { 90 {
87 float ux, uy, uz; 91 float ux, uy, uz;
88 float vx, vy, vz; 92 float vx, vy, vz;
@@ -129,9 +133,9 @@ namespace OpenSim.Region.Physics.Meshing
129 //ny /= l; 133 //ny /= l;
130 //nz /= l; 134 //nz /= l;
131 135
132 normals[i] = nx * lReciprocal; 136 m_normals[i] = nx * lReciprocal;
133 normals[i + 1] = ny * lReciprocal; 137 m_normals[i + 1] = ny * lReciprocal;
134 normals[i + 2] = nz * lReciprocal; 138 m_normals[i + 2] = nz * lReciprocal;
135 139
136 i += 3; 140 i += 3;
137 } 141 }
@@ -140,45 +144,70 @@ namespace OpenSim.Region.Physics.Meshing
140 public List<PhysicsVector> getVertexList() 144 public List<PhysicsVector> getVertexList()
141 { 145 {
142 List<PhysicsVector> result = new List<PhysicsVector>(); 146 List<PhysicsVector> result = new List<PhysicsVector>();
143 foreach (Vertex v in vertices.Keys) 147 foreach (Vertex v in m_vertices.Keys)
144 { 148 {
145 result.Add(v); 149 result.Add(v);
146 } 150 }
147 return result; 151 return result;
148 } 152 }
149 153
150 public float[] getVertexListAsFloatLocked() 154 private float[] getVertexListAsFloat()
151 { 155 {
152 if (pinnedVirtexes.IsAllocated) 156 if(m_vertices == null)
153 return (float[])(pinnedVirtexes.Target); 157 throw new NotSupportedException();
154 float[] result; 158 float[] result = new float[m_vertices.Count * 3];
155 159 foreach (KeyValuePair<Vertex, int> kvp in m_vertices)
156 //m_log.WarnFormat("vertices.Count = {0}", vertices.Count);
157 result = new float[vertices.Count * 3];
158 foreach (KeyValuePair<Vertex, int> kvp in vertices)
159 { 160 {
160 Vertex v = kvp.Key; 161 Vertex v = kvp.Key;
161 int i = kvp.Value; 162 int i = kvp.Value;
162 //m_log.WarnFormat("kvp.Value = {0}", i);
163 result[3 * i + 0] = v.X; 163 result[3 * i + 0] = v.X;
164 result[3 * i + 1] = v.Y; 164 result[3 * i + 1] = v.Y;
165 result[3 * i + 2] = v.Z; 165 result[3 * i + 2] = v.Z;
166 } 166 }
167 pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
168 return result; 167 return result;
169 } 168 }
170 169
171 public int[] getIndexListAsInt() 170 public float[] getVertexListAsFloatLocked()
172 { 171 {
173 int[] result; 172 if( m_pinnedVertexes.IsAllocated )
173 return (float[])(m_pinnedVertexes.Target);
174 174
175 result = new int[triangles.Count * 3]; 175 float[] result = getVertexListAsFloat();
176 for (int i = 0; i < triangles.Count; i++) 176 m_pinnedVertexes = GCHandle.Alloc(result, GCHandleType.Pinned);
177
178 return result;
179 }
180
181 public void getVertexListAsPtrToFloatArray(out IntPtr vertices, out int vertexStride, out int vertexCount)
182 {
183 // A vertex is 3 floats
184 vertexStride = 3 * sizeof(float);
185
186 // If there isn't an unmanaged array allocated yet, do it now
187 if (m_verticesPtr == IntPtr.Zero)
177 { 188 {
178 Triangle t = triangles[i]; 189 float[] vertexList = getVertexListAsFloat();
179 result[3 * i + 0] = vertices[t.v1]; 190 // Each vertex is 3 elements (floats)
180 result[3 * i + 1] = vertices[t.v2]; 191 m_vertexCount = vertexList.Length / 3;
181 result[3 * i + 2] = vertices[t.v3]; 192 int byteCount = m_vertexCount * vertexStride;
193 m_verticesPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(byteCount);
194 System.Runtime.InteropServices.Marshal.Copy(vertexList, 0, m_verticesPtr, m_vertexCount * 3);
195 }
196 vertices = m_verticesPtr;
197 vertexCount = m_vertexCount;
198 }
199
200 public int[] getIndexListAsInt()
201 {
202 if (m_triangles == null)
203 throw new NotSupportedException();
204 int[] result = new int[m_triangles.Count * 3];
205 for (int i = 0; i < m_triangles.Count; i++)
206 {
207 Triangle t = m_triangles[i];
208 result[3 * i + 0] = m_vertices[t.v1];
209 result[3 * i + 1] = m_vertices[t.v2];
210 result[3 * i + 2] = m_vertices[t.v3];
182 } 211 }
183 return result; 212 return result;
184 } 213 }
@@ -189,19 +218,48 @@ namespace OpenSim.Region.Physics.Meshing
189 /// <returns></returns> 218 /// <returns></returns>
190 public int[] getIndexListAsIntLocked() 219 public int[] getIndexListAsIntLocked()
191 { 220 {
192 if (pinnedIndex.IsAllocated) 221 if (m_pinnedIndex.IsAllocated)
193 return (int[])(pinnedIndex.Target); 222 return (int[])(m_pinnedIndex.Target);
194 223
195 int[] result = getIndexListAsInt(); 224 int[] result = getIndexListAsInt();
196 pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); 225 m_pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned);
197 226
198 return result; 227 return result;
199 } 228 }
200 229
230 public void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount)
231 {
232 // If there isn't an unmanaged array allocated yet, do it now
233 if (m_indicesPtr == IntPtr.Zero)
234 {
235 int[] indexList = getIndexListAsInt();
236 m_indexCount = indexList.Length;
237 int byteCount = m_indexCount * sizeof(int);
238 m_indicesPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(byteCount);
239 System.Runtime.InteropServices.Marshal.Copy(indexList, 0, m_indicesPtr, m_indexCount);
240 }
241 // A triangle is 3 ints (indices)
242 triStride = 3 * sizeof(int);
243 indices = m_indicesPtr;
244 indexCount = m_indexCount;
245 }
246
201 public void releasePinned() 247 public void releasePinned()
202 { 248 {
203 pinnedVirtexes.Free(); 249 if (m_pinnedVertexes.IsAllocated)
204 pinnedIndex.Free(); 250 m_pinnedVertexes.Free();
251 if (m_pinnedIndex.IsAllocated)
252 m_pinnedIndex.Free();
253 if (m_verticesPtr != IntPtr.Zero)
254 {
255 System.Runtime.InteropServices.Marshal.FreeHGlobal(m_verticesPtr);
256 m_verticesPtr = IntPtr.Zero;
257 }
258 if (m_indicesPtr != IntPtr.Zero)
259 {
260 System.Runtime.InteropServices.Marshal.FreeHGlobal(m_indicesPtr);
261 m_indicesPtr = IntPtr.Zero;
262 }
205 } 263 }
206 264
207 /// <summary> 265 /// <summary>
@@ -209,29 +267,29 @@ namespace OpenSim.Region.Physics.Meshing
209 /// </summary> 267 /// </summary>
210 public void releaseSourceMeshData() 268 public void releaseSourceMeshData()
211 { 269 {
212 triangles = null; 270 m_triangles = null;
213 vertices = null; 271 m_vertices = null;
214 } 272 }
215 273
216 public void Append(IMesh newMesh) 274 public void Append(IMesh newMesh)
217 { 275 {
218 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated) 276 if (m_pinnedIndex.IsAllocated || m_pinnedVertexes.IsAllocated || m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
219 throw new NotSupportedException("Attempt to Append to a pinned Mesh"); 277 throw new NotSupportedException("Attempt to Append to a pinned Mesh");
220 278
221 if (!(newMesh is Mesh)) 279 if (!(newMesh is Mesh))
222 return; 280 return;
223 281
224 foreach (Triangle t in ((Mesh)newMesh).triangles) 282 foreach (Triangle t in ((Mesh)newMesh).m_triangles)
225 Add(t); 283 Add(t);
226 } 284 }
227 285
228 // Do a linear transformation of mesh. 286 // Do a linear transformation of mesh.
229 public void TransformLinear(float[,] matrix, float[] offset) 287 public void TransformLinear(float[,] matrix, float[] offset)
230 { 288 {
231 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated) 289 if (m_pinnedIndex.IsAllocated || m_pinnedVertexes.IsAllocated || m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
232 throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh"); 290 throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh");
233 291
234 foreach (Vertex v in vertices.Keys) 292 foreach (Vertex v in m_vertices.Keys)
235 { 293 {
236 if (v == null) 294 if (v == null)
237 continue; 295 continue;
@@ -252,7 +310,7 @@ namespace OpenSim.Region.Physics.Meshing
252 String fileName = name + "_" + title + ".raw"; 310 String fileName = name + "_" + title + ".raw";
253 String completePath = Path.Combine(path, fileName); 311 String completePath = Path.Combine(path, fileName);
254 StreamWriter sw = new StreamWriter(completePath); 312 StreamWriter sw = new StreamWriter(completePath);
255 foreach (Triangle t in triangles) 313 foreach (Triangle t in m_triangles)
256 { 314 {
257 String s = t.ToStringRaw(); 315 String s = t.ToStringRaw();
258 sw.WriteLine(s); 316 sw.WriteLine(s);
@@ -262,7 +320,7 @@ namespace OpenSim.Region.Physics.Meshing
262 320
263 public void TrimExcess() 321 public void TrimExcess()
264 { 322 {
265 triangles.TrimExcess(); 323 m_triangles.TrimExcess();
266 } 324 }
267 } 325 }
268} 326}
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 0e29ccc..1ea08e2 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -498,12 +498,9 @@ namespace OpenSim.Region.Physics.Meshing
498 // If this mesh has been created already, return it instead of creating another copy 498 // If this mesh has been created already, return it instead of creating another copy
499 // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory 499 // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory
500 500
501 if (! primShape.SculptEntry) 501 key = GetMeshKey(primShape, size, lod);
502 { 502 if (m_uniqueMeshes.TryGetValue(key, out mesh))
503 key = GetMeshKey(primShape, size, lod); 503 return mesh;
504 if (m_uniqueMeshes.TryGetValue(key, out mesh))
505 return mesh;
506 }
507 504
508 if (size.X < 0.01f) size.X = 0.01f; 505 if (size.X < 0.01f) size.X = 0.01f;
509 if (size.Y < 0.01f) size.Y = 0.01f; 506 if (size.Y < 0.01f) size.Y = 0.01f;
@@ -525,10 +522,9 @@ namespace OpenSim.Region.Physics.Meshing
525 522
526 // trim the vertex and triangle lists to free up memory 523 // trim the vertex and triangle lists to free up memory
527 mesh.TrimExcess(); 524 mesh.TrimExcess();
528 }
529 525
530 if (!primShape.SculptEntry)
531 m_uniqueMeshes.Add(key, mesh); 526 m_uniqueMeshes.Add(key, mesh);
527 }
532 528
533 return mesh; 529 return mesh;
534 } 530 }
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 032b5df..c041243 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -813,18 +813,17 @@ namespace OpenSim.Region.Physics.OdePlugin
813 } 813 }
814 } 814 }
815 815
816 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 816 IntPtr vertices, indices;
817 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 817 int vertexCount, indexCount;
818 int vertexStride, triStride;
819 mesh.getVertexListAsPtrToFloatArray( out vertices, out vertexStride, out vertexCount ); // Note, that vertices are fixed in unmanaged heap
820 mesh.getIndexListAsPtrToIntArray( out indices, out triStride, out indexCount ); // Also fixed, needs release after usage
818 821
819 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory 822 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
820 823
821 int VertexCount = vertexList.GetLength(0)/3;
822 int IndexCount = indexList.GetLength(0);
823
824 _triMeshData = d.GeomTriMeshDataCreate(); 824 _triMeshData = d.GeomTriMeshDataCreate();
825 825
826 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount, 826 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
827 3*sizeof (int));
828 d.GeomTriMeshDataPreprocess(_triMeshData); 827 d.GeomTriMeshDataPreprocess(_triMeshData);
829 828
830 _parent_scene.waitForSpaceUnlock(m_targetSpace); 829 _parent_scene.waitForSpaceUnlock(m_targetSpace);
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0769c90..f5ab1de 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -3476,7 +3476,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3476 public override void UnCombine(PhysicsScene pScene) 3476 public override void UnCombine(PhysicsScene pScene)
3477 { 3477 {
3478 IntPtr localGround = IntPtr.Zero; 3478 IntPtr localGround = IntPtr.Zero;
3479 float[] localHeightfield; 3479 //float[] localHeightfield;
3480 bool proceed = false; 3480 bool proceed = false;
3481 List<IntPtr> geomDestroyList = new List<IntPtr>(); 3481 List<IntPtr> geomDestroyList = new List<IntPtr>();
3482 3482
@@ -3771,16 +3771,13 @@ namespace OpenSim.Region.Physics.OdePlugin
3771 sides.Z = 0.5f; 3771 sides.Z = 0.5f;
3772 3772
3773 ds.DrawBox(ref pos, ref R, ref sides); 3773 ds.DrawBox(ref pos, ref R, ref sides);
3774
3775
3776 } 3774 }
3777 } 3775 }
3778 } 3776 }
3779 } 3777 }
3780 3778
3781 public void start(int unused) 3779 public void start(int unused)
3782 { 3780 {
3783
3784 ds.SetViewpoint(ref xyz, ref hpr); 3781 ds.SetViewpoint(ref xyz, ref hpr);
3785 } 3782 }
3786#endif 3783#endif