Add routines in Util.cs for conversion of region handles to region

locations and for the conversion of region world location to region
'region' location. These routines will replace all the arithmatic
scattered throughout OpenSimulator.
master-beforevarregion
Robert Adams 2014-01-04 10:39:05 -08:00
parent dd96fef940
commit d9848943a9
2 changed files with 47 additions and 1 deletions

View File

@ -38,7 +38,10 @@ namespace OpenSim.Framework
// This could be a parameters but, really, a region of greater than this is pretty unmanageable
public const uint MaximumRegionSize = 8192;
public const byte TerrainPatchSize = 16;
// Since terrain is stored in 16x16 heights, regions must be a multiple of this number and that is the minimum
public const int MinRegionSize = 16;
public const int TerrainPatchSize = 16;
public const string DefaultTexture = "89556747-24cb-43ed-920b-47caed15465f";
public enum EstateAccessCodex : uint

View File

@ -333,6 +333,49 @@ namespace OpenSim.Framework
return Utils.UIntsToLong(X, Y);
}
// Regions are identified with a 'handle' made up of its region coordinates packed into a ulong.
// Several places rely on the ability to extract a region's location from its handle.
// Note the location is in 'world coordinates' (see below).
// Region handles are based on the lowest coordinate of the region so trim the passed x,y to be the regions 0,0.
public static ulong RegionWorldLocToHandle(uint X, uint Y)
{
return Utils.UIntsToLong(X, Y);
}
public static ulong RegionLocToHandle(uint X, uint Y)
{
return Utils.UIntsToLong(Util.RegionToWorldLoc(X), Util.RegionToWorldLoc(Y));
}
public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y)
{
X = (uint)(handle >> 32);
Y = (uint)(handle & (ulong)uint.MaxValue);
}
public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y)
{
uint worldX, worldY;
RegionHandleToWorldLoc(handle, out worldX, out worldY);
X = WorldToRegionLoc(worldX);
Y = WorldToRegionLoc(worldY);
}
// A region location can be 'world coordinates' (meters from zero) or 'region coordinates'
// (number of regions from zero). This measurement of regions relies on the legacy 256 region size.
// These routines exist to make what is being converted explicit so the next person knows what was meant.
// Convert a region's 'world coordinate' to its 'region coordinate'.
public static uint WorldToRegionLoc(uint worldCoord)
{
return worldCoord / Constants.RegionSize;
}
// Convert a region's 'region coordinate' to its 'world coordinate'.
public static uint RegionToWorldLoc(uint regionCoord)
{
return regionCoord * Constants.RegionSize;
}
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T>
{