aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs272
1 files changed, 257 insertions, 15 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
index 6db9515..5eb525b 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
@@ -27,6 +27,7 @@
27using System; 27using System;
28using System.Reflection; 28using System.Reflection;
29using System.Threading; 29using System.Threading;
30using System.Runtime.InteropServices;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
@@ -159,15 +160,147 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
159 } 160 }
160 } 161 }
161 162
163 // dont care about endianess
164 [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)]
165 public class fastRegionHandle
166 {
167 [FieldOffset(0)] public ulong handle;
168 [FieldOffset(0)] public uint y;
169 [FieldOffset(4)] public uint x;
170
171 public fastRegionHandle(ulong h)
172 {
173 handle = h;
174 }
175
176 public fastRegionHandle(uint px, uint py)
177 {
178 y = py & 0xffffff00;
179 x = px & 0xffffff00;
180 }
181 // actually do care
182 public ulong toHandle()
183 {
184 if(BitConverter.IsLittleEndian)
185 return handle;
186 return (ulong) x << 32 | (ulong)y ;
187 }
188
189 public static bool operator ==(fastRegionHandle value1, fastRegionHandle value2)
190 {
191 return value1.handle == value2.handle;
192 }
193 public static bool operator !=(fastRegionHandle value1, fastRegionHandle value2)
194 {
195 return value1.handle != value2.handle;
196 }
197 public override int GetHashCode()
198 {
199 return handle.GetHashCode();
200 }
201 public override bool Equals(Object obj)
202 {
203 if(obj == null)
204 return false;
205 fastRegionHandle p = obj as fastRegionHandle;
206 return p.handle == handle;
207 }
208 }
209
210/*
211 [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)]
212 public class regionHandle
213 {
214 [FieldOffset(0)] private ulong handle;
215 [FieldOffset(0)] public uint a;
216 [FieldOffset(4)] public uint b;
217
218 public regionHandle(ulong h)
219 {
220 handle = h;
221 }
222
223 public regionHandle(uint px, uint py)
224 {
225 if(BitConverter.IsLittleEndian)
226 {
227 a = py & 0xffffff00;
228 b = px & 0xffffff00;
229 }
230 else
231 {
232 a = px & 0xffffff00;
233 b = py & 0xffffff00;
234 }
235 }
236
237 public uint x
238 {
239 get
240 {
241 if(BitConverter.IsLittleEndian)
242 return b;
243 return a;
244 }
245 set
246 {
247 if(BitConverter.IsLittleEndian)
248 b = value & 0xffffff00;
249 else
250 a = value & 0xffffff00;
251 }
252 }
253
254 public uint y
255 {
256 get
257 {
258 if(BitConverter.IsLittleEndian)
259 return a;
260 return b;
261 }
262 set
263 {
264 if(BitConverter.IsLittleEndian)
265 a = value;
266 else
267 b = value;
268 }
269 }
270
271 public static bool operator ==(regionHandle value1, regionHandle value2)
272 {
273 return value1.handle == value2.handle;
274 }
275 public static bool operator !=(regionHandle value1, regionHandle value2)
276 {
277 return value1.handle != value2.handle;
278 }
279 public override int GetHashCode()
280 {
281 return handle.GetHashCode();
282 }
283 public override bool Equals(Object obj)
284 {
285 if(obj == null)
286 return false;
287 regionHandle p = obj as regionHandle;
288 return p.handle == handle;
289 }
290 }
291*/
292
162 public class RegionInfoForScope 293 public class RegionInfoForScope
163 { 294 {
164 public const ulong HANDLEMASH = 0xffffff00ffffff00ul; 295 public const ulong HANDLEMASK = 0xffffff00ffffff00ul;
165 public const ulong HANDLECOORDMASH = 0xffffff00ul; 296 public const ulong HANDLECOORDMASK = 0xffffff00ul;
166 297
167 private Dictionary<ulong, GridRegion> storage; 298 private Dictionary<ulong, GridRegion> storage;
168 private Dictionary<ulong, DateTime> expires; 299 private Dictionary<ulong, DateTime> expires;
169 private Dictionary<string, ulong> byname; 300 private Dictionary<string, ulong> byname;
170 private Dictionary<UUID, ulong> byuuid; 301 private Dictionary<UUID, ulong> byuuid;
302 // includes handles to the inside of large regions
303 private Dictionary<ulong, ulong> innerHandles = new Dictionary<ulong, ulong>();
171 304
172 public RegionInfoForScope() 305 public RegionInfoForScope()
173 { 306 {
@@ -184,16 +317,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
184 byname = new Dictionary<string, ulong>(); 317 byname = new Dictionary<string, ulong>();
185 byuuid = new Dictionary<UUID, ulong>(); 318 byuuid = new Dictionary<UUID, ulong>();
186 319
187 ulong handle = region.RegionHandle & HANDLEMASH; 320 ulong handle = region.RegionHandle & HANDLEMASK;
188 storage[handle] = region; 321 storage[handle] = region;
189 expires[handle] = expire; 322 expires[handle] = expire;
190 byname[region.RegionName] = handle; 323 byname[region.RegionName] = handle;
191 byuuid[region.RegionID] = handle; 324 byuuid[region.RegionID] = handle;
325 addToInner(region);
192 } 326 }
193 327
194 public void Add(GridRegion region, DateTime expire) 328 public void Add(GridRegion region, DateTime expire)
195 { 329 {
196 ulong handle = region.RegionHandle & HANDLEMASH; 330 ulong handle = region.RegionHandle & HANDLEMASK;
197 331
198 if(storage != null && storage.ContainsKey(handle)) 332 if(storage != null && storage.ContainsKey(handle))
199 return; 333 return;
@@ -211,6 +345,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
211 expires[handle] = expire; 345 expires[handle] = expire;
212 byname[region.RegionName] = handle; 346 byname[region.RegionName] = handle;
213 byuuid[region.RegionID] = handle; 347 byuuid[region.RegionID] = handle;
348
349 addToInner(region);
214 } 350 }
215 351
216 public void AddUpdate(GridRegion region, DateTime expire) 352 public void AddUpdate(GridRegion region, DateTime expire)
@@ -224,18 +360,32 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
224 if(byuuid == null) 360 if(byuuid == null)
225 byuuid = new Dictionary<UUID, ulong>(); 361 byuuid = new Dictionary<UUID, ulong>();
226 362
227 ulong handle = region.RegionHandle & HANDLEMASH; 363 ulong handle = region.RegionHandle & HANDLEMASK;
228 364
229 storage[handle] = region;
230 if(expires.ContainsKey(handle)) 365 if(expires.ContainsKey(handle))
231 { 366 {
232 if(expires[handle] < expire) 367 if(expires[handle] < expire)
233 expires[handle] = expire; 368 expires[handle] = expire;
369 if(storage.ContainsKey(handle))
370 {
371 GridRegion oldr = storage[handle];
372 if (oldr.RegionSizeX != region.RegionSizeX
373 || oldr.RegionSizeY != region.RegionSizeY)
374 {
375 removeFromInner(oldr);
376 addToInner(region);
377 }
378 }
234 } 379 }
235 else 380 else
236 expires[handle] = expire; 381 {
382 expires[handle] = expire;
383 addToInner(region);
384 }
385 storage[handle] = region;
237 byname[region.RegionName] = handle; 386 byname[region.RegionName] = handle;
238 byuuid[region.RegionID] = handle; 387 byuuid[region.RegionID] = handle;
388
239 } 389 }
240 390
241 public void Remove(GridRegion region) 391 public void Remove(GridRegion region)
@@ -248,9 +398,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
248 if(byuuid != null) 398 if(byuuid != null)
249 byuuid.Remove(region.RegionID); 399 byuuid.Remove(region.RegionID);
250 400
251 ulong handle = region.RegionHandle & HANDLEMASH; 401 ulong handle = region.RegionHandle & HANDLEMASK;
252 if(storage != null) 402 if(storage != null)
253 storage.Remove(handle); 403 storage.Remove(handle);
404 removeFromInner(region);
254 if(expires != null) 405 if(expires != null)
255 { 406 {
256 expires.Remove(handle); 407 expires.Remove(handle);
@@ -261,7 +412,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
261 412
262 public void Remove(ulong handle) 413 public void Remove(ulong handle)
263 { 414 {
264 handle &= HANDLEMASH; 415 handle &= HANDLEMASK;
265 416
266 if(storage != null) 417 if(storage != null)
267 { 418 {
@@ -272,6 +423,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
272 byname.Remove(r.RegionName); 423 byname.Remove(r.RegionName);
273 if(byuuid != null) 424 if(byuuid != null)
274 byuuid.Remove(r.RegionID); 425 byuuid.Remove(r.RegionID);
426 removeFromInner(r);
275 } 427 }
276 storage.Remove(handle); 428 storage.Remove(handle);
277 } 429 }
@@ -297,6 +449,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
297 byuuid = null; 449 byuuid = null;
298 storage = null; 450 storage = null;
299 expires = null; 451 expires = null;
452 innerHandles.Clear();
300 } 453 }
301 454
302 public bool Contains(GridRegion region) 455 public bool Contains(GridRegion region)
@@ -306,7 +459,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
306 if(region == null) 459 if(region == null)
307 return false; 460 return false;
308 461
309 ulong handle = region.RegionHandle & HANDLEMASH; 462 ulong handle = region.RegionHandle & HANDLEMASK;
310 return storage.ContainsKey(handle); 463 return storage.ContainsKey(handle);
311 } 464 }
312 465
@@ -315,7 +468,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
315 if(storage == null) 468 if(storage == null)
316 return false; 469 return false;
317 470
318 handle &= HANDLEMASH; 471 handle &= HANDLEMASK;
319 return storage.ContainsKey(handle); 472 return storage.ContainsKey(handle);
320 } 473 }
321 474
@@ -324,10 +477,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
324 if(storage == null) 477 if(storage == null)
325 return null; 478 return null;
326 479
327 handle &= HANDLEMASH; 480 handle &= HANDLEMASK;
328 if(storage.ContainsKey(handle)) 481 if(storage.ContainsKey(handle))
329 return storage[handle]; 482 return storage[handle];
483
484 if(!innerHandles.ContainsKey(handle))
485 return null;
330 486
487 ulong rhandle = innerHandles[handle];
488 if(storage.ContainsKey(rhandle))
489 return storage[rhandle];
490
331 return null; 491 return null;
332 } 492 }
333 493
@@ -359,13 +519,40 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
359 return null; 519 return null;
360 520
361 // look for a handle first this should find normal size regions 521 // look for a handle first this should find normal size regions
362 ulong handle = (ulong)x & HANDLECOORDMASH; 522 ulong handle = (ulong)x & HANDLECOORDMASK;
363 handle <<= 32; 523 handle <<= 32;
364 handle |= ((ulong)y & HANDLECOORDMASH); 524 handle |= ((ulong)y & HANDLECOORDMASK);
365 525
366 if(storage.ContainsKey(handle)) 526 if(storage.ContainsKey(handle))
367 return storage[handle]; 527 return storage[handle];
368 528
529 if(!innerHandles.ContainsKey(handle))
530 return null;
531
532 ulong rhandle = innerHandles[handle];
533 if(!storage.ContainsKey(rhandle))
534 return null;
535
536 GridRegion r = storage[rhandle];
537 if(r == null)
538 return null;
539
540 // extra check, possible redundant
541
542 int test = r.RegionLocX;
543 if(x < test)
544 return null;
545 test += r.RegionSizeX;
546 if(x >= test)
547 return null;
548 test = r.RegionLocY;
549 if (y < test)
550 return null;
551 test += r.RegionSizeY;
552 if (y < test)
553 return r;
554
555/*
369 // next do the harder work 556 // next do the harder work
370 foreach(KeyValuePair<ulong, GridRegion> kvp in storage) 557 foreach(KeyValuePair<ulong, GridRegion> kvp in storage)
371 { 558 {
@@ -386,6 +573,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
386 if (y < test) 573 if (y < test)
387 return r; 574 return r;
388 } 575 }
576*/
389 return null; 577 return null;
390 } 578 }
391 579
@@ -421,6 +609,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
421 byname.Remove(r.RegionName); 609 byname.Remove(r.RegionName);
422 if(byuuid != null) 610 if(byuuid != null)
423 byuuid.Remove(r.RegionID); 611 byuuid.Remove(r.RegionID);
612 removeFromInner(r);
424 } 613 }
425 storage.Remove(h); 614 storage.Remove(h);
426 } 615 }
@@ -447,6 +636,59 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
447 else 636 else
448 return byname.Count; 637 return byname.Count;
449 } 638 }
639
640 private void addToInner(GridRegion region)
641 {
642 int rsx = region.RegionSizeX;
643 int rsy = region.RegionSizeY;
644
645 if(rsx < 512 && rsy < 512)
646 return;
647
648 rsx >>= 8;
649 rsy >>= 8;
650
651 ulong handle = region.RegionHandle & HANDLEMASK;
652 fastRegionHandle fh = new fastRegionHandle(handle);
653 uint startY = fh.y;
654 for(int i = 0; i < rsx; i++)
655 {
656 for(int j = 0; j < rsy ; j++)
657 {
658 innerHandles[fh.toHandle()] = handle;
659 fh.y += 256;
660 }
661
662 fh.y = startY;
663 fh.x += 256;
664 }
665 }
666
667 private void removeFromInner(GridRegion region)
668 {
669 int rsx = region.RegionSizeX;
670 int rsy = region.RegionSizeY;
671
672 if(rsx < 512 && rsy < 512)
673 return;
674
675 rsx >>= 8;
676 rsy >>= 8;
677 ulong handle = region.RegionHandle & HANDLEMASK;
678 fastRegionHandle fh = new fastRegionHandle(handle);
679 uint startY = fh.y;
680 for(int i = 0; i < rsx; i++)
681 {
682 for(int j = 0; j < rsy ; j++)
683 {
684 innerHandles.Remove(fh.toHandle());
685 fh.y += 256;
686 }
687
688 fh.y = startY;
689 fh.x += 256;
690 }
691 }
450 } 692 }
451 693
452 public class RegionsExpiringCache 694 public class RegionsExpiringCache