diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 52635b2..c7377b8 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -333,6 +333,49 @@ namespace OpenSim.Framework | |||
333 | return Utils.UIntsToLong(X, Y); | 333 | return Utils.UIntsToLong(X, Y); |
334 | } | 334 | } |
335 | 335 | ||
336 | // Regions are identified with a 'handle' made up of its region coordinates packed into a ulong. | ||
337 | // Several places rely on the ability to extract a region's location from its handle. | ||
338 | // Note the location is in 'world coordinates' (see below). | ||
339 | // Region handles are based on the lowest coordinate of the region so trim the passed x,y to be the regions 0,0. | ||
340 | public static ulong RegionWorldLocToHandle(uint X, uint Y) | ||
341 | { | ||
342 | return Utils.UIntsToLong(X, Y); | ||
343 | } | ||
344 | |||
345 | public static ulong RegionLocToHandle(uint X, uint Y) | ||
346 | { | ||
347 | return Utils.UIntsToLong(Util.RegionToWorldLoc(X), Util.RegionToWorldLoc(Y)); | ||
348 | } | ||
349 | |||
350 | public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) | ||
351 | { | ||
352 | X = (uint)(handle >> 32); | ||
353 | Y = (uint)(handle & (ulong)uint.MaxValue); | ||
354 | } | ||
355 | |||
356 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) | ||
357 | { | ||
358 | uint worldX, worldY; | ||
359 | RegionHandleToWorldLoc(handle, out worldX, out worldY); | ||
360 | X = WorldToRegionLoc(worldX); | ||
361 | Y = WorldToRegionLoc(worldY); | ||
362 | } | ||
363 | |||
364 | // A region location can be 'world coordinates' (meters from zero) or 'region coordinates' | ||
365 | // (number of regions from zero). This measurement of regions relies on the legacy 256 region size. | ||
366 | // These routines exist to make what is being converted explicit so the next person knows what was meant. | ||
367 | // Convert a region's 'world coordinate' to its 'region coordinate'. | ||
368 | public static uint WorldToRegionLoc(uint worldCoord) | ||
369 | { | ||
370 | return worldCoord / Constants.RegionSize; | ||
371 | } | ||
372 | |||
373 | // Convert a region's 'region coordinate' to its 'world coordinate'. | ||
374 | public static uint RegionToWorldLoc(uint regionCoord) | ||
375 | { | ||
376 | return regionCoord * Constants.RegionSize; | ||
377 | } | ||
378 | |||
336 | public static T Clamp<T>(T x, T min, T max) | 379 | public static T Clamp<T>(T x, T min, T max) |
337 | where T : IComparable<T> | 380 | where T : IComparable<T> |
338 | { | 381 | { |
@@ -988,7 +1031,7 @@ namespace OpenSim.Framework | |||
988 | else if (typeof(T) == typeof(Int32)) | 1031 | else if (typeof(T) == typeof(Int32)) |
989 | val = cnf.GetInt(varname, (int)val); | 1032 | val = cnf.GetInt(varname, (int)val); |
990 | else if (typeof(T) == typeof(float)) | 1033 | else if (typeof(T) == typeof(float)) |
991 | val = cnf.GetFloat(varname, (int)val); | 1034 | val = cnf.GetFloat(varname, (float)val); |
992 | else | 1035 | else |
993 | m_log.ErrorFormat("[UTIL]: Unhandled type {0}", typeof(T)); | 1036 | m_log.ErrorFormat("[UTIL]: Unhandled type {0}", typeof(T)); |
994 | } | 1037 | } |
@@ -1703,6 +1746,30 @@ namespace OpenSim.Framework | |||
1703 | } | 1746 | } |
1704 | 1747 | ||
1705 | /// <summary> | 1748 | /// <summary> |
1749 | /// Pretty format the hashtable contents to a single line. | ||
1750 | /// </summary> | ||
1751 | /// <remarks> | ||
1752 | /// Used for debugging output. | ||
1753 | /// </remarks> | ||
1754 | /// <param name='ht'></param> | ||
1755 | public static string PrettyFormatToSingleLine(Hashtable ht) | ||
1756 | { | ||
1757 | StringBuilder sb = new StringBuilder(); | ||
1758 | |||
1759 | int i = 0; | ||
1760 | |||
1761 | foreach (string key in ht.Keys) | ||
1762 | { | ||
1763 | sb.AppendFormat("{0}:{1}", key, ht[key]); | ||
1764 | |||
1765 | if (++i < ht.Count) | ||
1766 | sb.AppendFormat(", "); | ||
1767 | } | ||
1768 | |||
1769 | return sb.ToString(); | ||
1770 | } | ||
1771 | |||
1772 | /// <summary> | ||
1706 | /// Used to trigger an early library load on Windows systems. | 1773 | /// Used to trigger an early library load on Windows systems. |
1707 | /// </summary> | 1774 | /// </summary> |
1708 | /// <remarks> | 1775 | /// <remarks> |