mirror of
https://github.com/opensim/opensim.git
synced 2026-07-13 19:14:51 +08:00
varregion: elimination of Constants.RegionSize from all over OpenSimulator.
Routines in Util to compute region world coordinates from region coordinates as well as the conversion to and from region handles. These routines have replaced a lot of math scattered throughout the simulator. Should be no functional changes.
This commit is contained in:
@@ -408,8 +408,8 @@ namespace OpenSim.Framework
|
||||
}
|
||||
ClearTaint();
|
||||
|
||||
m_log.InfoFormat("{0} Read compressed 2d heightmap. Heightmap size=<{1},{2}>. Region size={<{3},{4}>. CompFact={5}", LogHeader,
|
||||
hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor);
|
||||
m_log.InfoFormat("{0} Read compressed 2d heightmap. Heightmap size=<{1},{2}>. Region size=<{3},{4}>. CompFact={5}",
|
||||
LogHeader, hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,15 +160,19 @@ namespace OpenSim.Framework
|
||||
public virtual ulong HomeRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Utils.UIntsToLong(
|
||||
m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize);
|
||||
{
|
||||
return Util.RegionWorldLocToHandle(Util.RegionToWorldLoc(m_homeRegionX), Util.RegionToWorldLoc(m_homeRegionY));
|
||||
// return Utils.UIntsToLong( m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
m_homeRegionX = (uint) (value >> 40);
|
||||
m_homeRegionY = (((uint) (value)) >> 8);
|
||||
uint regionWorldLocX, regionWorldLocY;
|
||||
Util.RegionHandleToWorldLoc(value, out regionWorldLocX, out regionWorldLocY);
|
||||
m_homeRegionX = Util.WorldToRegionLoc(regionWorldLocX);
|
||||
m_homeRegionY = Util.WorldToRegionLoc(regionWorldLocY);
|
||||
// m_homeRegionX = (uint) (value >> 40);
|
||||
// m_homeRegionY = (((uint) (value)) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +333,43 @@ 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).
|
||||
public static ulong RegionWorldLocToHandle(uint X, uint Y)
|
||||
{
|
||||
return Utils.UIntsToLong(X, 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>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user