diff options
author | UbitUmarov | 2016-07-31 23:19:51 +0100 |
---|---|---|
committer | UbitUmarov | 2016-07-31 23:19:51 +0100 |
commit | a9befe1c62a621c7e9b88a95a2e9e9df08df1a07 (patch) | |
tree | aa88ad0018c1e9d69212ed9dce5b448d3bfb1f50 /OpenSim/Framework/Util.cs | |
parent | Merge branch 'master' into httptests (diff) | |
parent | on 0.8 grids compatibility code just do a BIG range request. It whould be do... (diff) | |
download | opensim-SC-a9befe1c62a621c7e9b88a95a2e9e9df08df1a07.zip opensim-SC-a9befe1c62a621c7e9b88a95a2e9e9df08df1a07.tar.gz opensim-SC-a9befe1c62a621c7e9b88a95a2e9e9df08df1a07.tar.bz2 opensim-SC-a9befe1c62a621c7e9b88a95a2e9e9df08df1a07.tar.xz |
Merge branch 'master' into httptests
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 1b3a4c3..5250d30 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -368,47 +368,49 @@ namespace OpenSim.Framework | |||
368 | return Utils.UIntsToLong(X, Y); | 368 | return Utils.UIntsToLong(X, Y); |
369 | } | 369 | } |
370 | 370 | ||
371 | // Regions are identified with a 'handle' made up of its region coordinates packed into a ulong. | 371 | // Regions are identified with a 'handle' made up of its world coordinates packed into a ulong. |
372 | // Several places rely on the ability to extract a region's location from its handle. | 372 | // Region handles are based on the coordinate of the region corner with lower X and Y |
373 | // Note the location is in 'world coordinates' (see below). | 373 | // var regions need more work than this to get that right corner from a generic world position |
374 | // Region handles are based on the lowest coordinate of the region so trim the passed x,y to be the regions 0,0. | 374 | // this corner must be on a grid point |
375 | public static ulong RegionWorldLocToHandle(uint X, uint Y) | 375 | public static ulong RegionWorldLocToHandle(uint X, uint Y) |
376 | { | 376 | { |
377 | return Utils.UIntsToLong(X, Y); | 377 | ulong handle = X & 0xffffff00; // make sure it matchs grid coord points. |
378 | handle <<= 32; // to higher half | ||
379 | handle |= (Y & 0xffffff00); | ||
380 | return handle; | ||
378 | } | 381 | } |
379 | 382 | ||
380 | public static ulong RegionLocToHandle(uint X, uint Y) | 383 | public static ulong RegionGridLocToHandle(uint X, uint Y) |
381 | { | 384 | { |
382 | return Utils.UIntsToLong(Util.RegionToWorldLoc(X), Util.RegionToWorldLoc(Y)); | 385 | ulong handle = X << 40; // shift to higher half and mult by 256) |
386 | handle |= (Y << 8); // mult by 256) | ||
387 | return handle; | ||
383 | } | 388 | } |
384 | 389 | ||
385 | public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) | 390 | public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) |
386 | { | 391 | { |
387 | X = (uint)(handle >> 32); | 392 | X = (uint)(handle >> 32); |
388 | Y = (uint)(handle & (ulong)uint.MaxValue); | 393 | Y = (uint)(handle & 0xfffffffful); |
389 | } | 394 | } |
390 | 395 | ||
391 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) | 396 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) |
392 | { | 397 | { |
393 | uint worldX, worldY; | 398 | X = (uint)(handle >> 40) & 0x00ffffffu; // bring from higher half, divide by 256 and clean |
394 | RegionHandleToWorldLoc(handle, out worldX, out worldY); | 399 | Y = (uint)(handle >> 8) & 0x00ffffffu; // divide by 256 and clean |
395 | X = WorldToRegionLoc(worldX); | 400 | // if you trust the uint cast then the clean can be removed. |
396 | Y = WorldToRegionLoc(worldY); | ||
397 | } | 401 | } |
398 | 402 | ||
399 | // A region location can be 'world coordinates' (meters from zero) or 'region coordinates' | 403 | // A region location can be 'world coordinates' (meters) or 'region grid coordinates' |
400 | // (number of regions from zero). This measurement of regions relies on the legacy 256 region size. | 404 | // grid coordinates have a fixed step of 256m as defined by viewers |
401 | // These routines exist to make what is being converted explicit so the next person knows what was meant. | ||
402 | // Convert a region's 'world coordinate' to its 'region coordinate'. | ||
403 | public static uint WorldToRegionLoc(uint worldCoord) | 405 | public static uint WorldToRegionLoc(uint worldCoord) |
404 | { | 406 | { |
405 | return worldCoord / Constants.RegionSize; | 407 | return worldCoord >> 8; |
406 | } | 408 | } |
407 | 409 | ||
408 | // Convert a region's 'region coordinate' to its 'world coordinate'. | 410 | // Convert a region's 'region grid coordinate' to its 'world coordinate'. |
409 | public static uint RegionToWorldLoc(uint regionCoord) | 411 | public static uint RegionToWorldLoc(uint regionCoord) |
410 | { | 412 | { |
411 | return regionCoord * Constants.RegionSize; | 413 | return regionCoord << 8; |
412 | } | 414 | } |
413 | 415 | ||
414 | public static T Clamp<T>(T x, T min, T max) | 416 | public static T Clamp<T>(T x, T min, T max) |
@@ -1303,7 +1305,7 @@ namespace OpenSim.Framework | |||
1303 | } | 1305 | } |
1304 | catch (Exception e) | 1306 | catch (Exception e) |
1305 | { | 1307 | { |
1306 | m_log.WarnFormat("[UTILS]: Exception copying configuration file {0} to {1}: {2}", exampleConfigFile, configFile, e.Message); | 1308 | m_log.WarnFormat("[UTILS]: Exception copying configuration file {0} to {1}: {2}", configFile, exampleConfigFile, e.Message); |
1307 | return false; | 1309 | return false; |
1308 | } | 1310 | } |
1309 | } | 1311 | } |