diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Constants.cs | 11 | ||||
-rw-r--r-- | OpenSim/Framework/RegionInfo.cs | 219 | ||||
-rw-r--r-- | OpenSim/Framework/TerrainData.cs | 418 | ||||
-rw-r--r-- | OpenSim/Framework/UserProfileData.cs | 14 | ||||
-rw-r--r-- | OpenSim/Framework/Util.cs | 38 |
5 files changed, 653 insertions, 47 deletions
diff --git a/OpenSim/Framework/Constants.cs b/OpenSim/Framework/Constants.cs index a2eb5ee..d80808c 100644 --- a/OpenSim/Framework/Constants.cs +++ b/OpenSim/Framework/Constants.cs | |||
@@ -30,9 +30,18 @@ namespace OpenSim.Framework | |||
30 | { | 30 | { |
31 | public class Constants | 31 | public class Constants |
32 | { | 32 | { |
33 | // 'RegionSize' is the legacy region size. | ||
34 | // DO NOT USE THIS FOR ANY NEW CODE. Use Scene.RegionSize[XYZ] as a region might not | ||
35 | // be the legacy region size. | ||
33 | public const uint RegionSize = 256; | 36 | public const uint RegionSize = 256; |
34 | public const uint RegionHeight = 4096; | 37 | public const uint RegionHeight = 4096; |
35 | public const byte TerrainPatchSize = 16; | 38 | // This could be a parameters but, really, a region of greater than this is pretty unmanageable |
39 | public const uint MaximumRegionSize = 8192; | ||
40 | |||
41 | // Since terrain is stored in 16x16 heights, regions must be a multiple of this number and that is the minimum | ||
42 | public const int MinRegionSize = 16; | ||
43 | public const int TerrainPatchSize = 16; | ||
44 | |||
36 | public const string DefaultTexture = "89556747-24cb-43ed-920b-47caed15465f"; | 45 | public const string DefaultTexture = "89556747-24cb-43ed-920b-47caed15465f"; |
37 | 46 | ||
38 | public enum EstateAccessCodex : uint | 47 | public enum EstateAccessCodex : uint |
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs index 24b9c89..63b3d89 100644 --- a/OpenSim/Framework/RegionInfo.cs +++ b/OpenSim/Framework/RegionInfo.cs | |||
@@ -99,6 +99,7 @@ namespace OpenSim.Framework | |||
99 | public class RegionInfo | 99 | public class RegionInfo |
100 | { | 100 | { |
101 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 101 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
102 | private static readonly string LogHeader = "[REGION INFO]"; | ||
102 | 103 | ||
103 | public bool commFailTF = false; | 104 | public bool commFailTF = false; |
104 | public ConfigurationMember configMember; | 105 | public ConfigurationMember configMember; |
@@ -137,16 +138,20 @@ namespace OpenSim.Framework | |||
137 | public bool m_allow_alternate_ports; | 138 | public bool m_allow_alternate_ports; |
138 | protected string m_externalHostName; | 139 | protected string m_externalHostName; |
139 | protected IPEndPoint m_internalEndPoint; | 140 | protected IPEndPoint m_internalEndPoint; |
140 | protected uint? m_regionLocX; | ||
141 | protected uint? m_regionLocY; | ||
142 | protected uint m_remotingPort; | 141 | protected uint m_remotingPort; |
143 | public UUID RegionID = UUID.Zero; | 142 | public UUID RegionID = UUID.Zero; |
144 | public string RemotingAddress; | 143 | public string RemotingAddress; |
145 | public UUID ScopeID = UUID.Zero; | 144 | public UUID ScopeID = UUID.Zero; |
146 | private UUID m_maptileStaticUUID = UUID.Zero; | 145 | private UUID m_maptileStaticUUID = UUID.Zero; |
147 | 146 | ||
148 | private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>(); | 147 | public uint RegionWorldLocX = 0; |
148 | public uint RegionWorldLocY = 0; | ||
149 | public uint RegionWorldLocZ = 0; | ||
150 | public uint RegionSizeX = Constants.RegionSize; | ||
151 | public uint RegionSizeY = Constants.RegionSize; | ||
152 | public uint RegionSizeZ = Constants.RegionHeight; | ||
149 | 153 | ||
154 | private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>(); | ||
150 | 155 | ||
151 | // Apparently, we're applying the same estatesettings regardless of whether it's local or remote. | 156 | // Apparently, we're applying the same estatesettings regardless of whether it's local or remote. |
152 | 157 | ||
@@ -229,11 +234,8 @@ namespace OpenSim.Framework | |||
229 | m_serverURI = string.Empty; | 234 | m_serverURI = string.Empty; |
230 | } | 235 | } |
231 | 236 | ||
232 | public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) | 237 | public RegionInfo(uint legacyRegionLocX, uint legacyRegionLocY, IPEndPoint internalEndPoint, string externalUri) |
233 | { | 238 | { |
234 | m_regionLocX = regionLocX; | ||
235 | m_regionLocY = regionLocY; | ||
236 | |||
237 | m_internalEndPoint = internalEndPoint; | 239 | m_internalEndPoint = internalEndPoint; |
238 | m_externalHostName = externalUri; | 240 | m_externalHostName = externalUri; |
239 | m_serverURI = string.Empty; | 241 | m_serverURI = string.Empty; |
@@ -447,25 +449,66 @@ namespace OpenSim.Framework | |||
447 | 449 | ||
448 | /// <summary> | 450 | /// <summary> |
449 | /// The x co-ordinate of this region in map tiles (e.g. 1000). | 451 | /// The x co-ordinate of this region in map tiles (e.g. 1000). |
452 | /// Coordinate is scaled as world coordinates divided by the legacy region size | ||
453 | /// and is thus is the number of legacy regions. | ||
454 | /// </summary> | ||
455 | public uint LegacyRegionLocX | ||
456 | { | ||
457 | get { return RegionWorldLocX / Constants.RegionSize; } | ||
458 | set { RegionWorldLocX = value * Constants.RegionSize; } | ||
459 | } | ||
460 | |||
461 | /// <summary> | ||
462 | /// The y co-ordinate of this region in map tiles (e.g. 1000). | ||
463 | /// Coordinate is scaled as world coordinates divided by the legacy region size | ||
464 | /// and is thus is the number of legacy regions. | ||
465 | /// </summary> | ||
466 | public uint LegacyRegionLocY | ||
467 | { | ||
468 | get { return RegionWorldLocY / Constants.RegionSize; } | ||
469 | set { RegionWorldLocY = value * Constants.RegionSize; } | ||
470 | } | ||
471 | |||
472 | /// <summary> | ||
473 | /// The x co-ordinate of this region in map tiles (e.g. 1000). | ||
474 | /// Coordinate is scaled as world coordinates divided by the legacy region size | ||
475 | /// and is thus is the number of legacy regions. | ||
476 | /// DO NOT USE FOR NEW CODE! This entrypoint exists for downward compatability with external modules. | ||
450 | /// </summary> | 477 | /// </summary> |
451 | public uint RegionLocX | 478 | public uint RegionLocX |
452 | { | 479 | { |
453 | get { return m_regionLocX.Value; } | 480 | get { return LegacyRegionLocX; } |
454 | set { m_regionLocX = value; } | 481 | set { LegacyRegionLocX = value; } |
455 | } | 482 | } |
456 | 483 | ||
457 | /// <summary> | 484 | /// <summary> |
458 | /// The y co-ordinate of this region in map tiles (e.g. 1000). | 485 | /// The y co-ordinate of this region in map tiles (e.g. 1000). |
486 | /// Coordinate is scaled as world coordinates divided by the legacy region size | ||
487 | /// and is thus is the number of legacy regions. | ||
488 | /// DO NOT USE FOR NEW CODE! This entrypoint exists for downward compatability with external modules. | ||
459 | /// </summary> | 489 | /// </summary> |
460 | public uint RegionLocY | 490 | public uint RegionLocY |
461 | { | 491 | { |
462 | get { return m_regionLocY.Value; } | 492 | get { return LegacyRegionLocY; } |
463 | set { m_regionLocY = value; } | 493 | set { LegacyRegionLocY = value; } |
494 | } | ||
495 | |||
496 | public void SetDefaultRegionSize() | ||
497 | { | ||
498 | RegionWorldLocX = 0; | ||
499 | RegionWorldLocY = 0; | ||
500 | RegionWorldLocZ = 0; | ||
501 | RegionSizeX = Constants.RegionSize; | ||
502 | RegionSizeY = Constants.RegionSize; | ||
503 | RegionSizeZ = Constants.RegionHeight; | ||
464 | } | 504 | } |
465 | 505 | ||
506 | // A unique region handle is created from the region's world coordinates. | ||
507 | // This cannot be changed because some code expects to receive the region handle and then | ||
508 | // compute the region coordinates from it. | ||
466 | public ulong RegionHandle | 509 | public ulong RegionHandle |
467 | { | 510 | { |
468 | get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); } | 511 | get { return Util.UIntsToLong(RegionWorldLocX, RegionWorldLocY); } |
469 | } | 512 | } |
470 | 513 | ||
471 | public void SetEndPoint(string ipaddr, int port) | 514 | public void SetEndPoint(string ipaddr, int port) |
@@ -572,8 +615,25 @@ namespace OpenSim.Framework | |||
572 | 615 | ||
573 | string[] locationElements = location.Split(new char[] {','}); | 616 | string[] locationElements = location.Split(new char[] {','}); |
574 | 617 | ||
575 | m_regionLocX = Convert.ToUInt32(locationElements[0]); | 618 | LegacyRegionLocX = Convert.ToUInt32(locationElements[0]); |
576 | m_regionLocY = Convert.ToUInt32(locationElements[1]); | 619 | LegacyRegionLocY = Convert.ToUInt32(locationElements[1]); |
620 | |||
621 | // Region size | ||
622 | // Default to legacy region size if not specified. | ||
623 | allKeys.Remove("SizeX"); | ||
624 | string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString()); | ||
625 | config.Set("SizeX", configSizeX); | ||
626 | RegionSizeX = Convert.ToUInt32(configSizeX); | ||
627 | allKeys.Remove("SizeY"); | ||
628 | string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString()); | ||
629 | config.Set("SizeY", configSizeX); | ||
630 | RegionSizeY = Convert.ToUInt32(configSizeY); | ||
631 | allKeys.Remove("SizeZ"); | ||
632 | string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString()); | ||
633 | config.Set("SizeZ", configSizeX); | ||
634 | RegionSizeZ = Convert.ToUInt32(configSizeZ); | ||
635 | |||
636 | DoRegionSizeSanityChecks(); | ||
577 | 637 | ||
578 | // InternalAddress | 638 | // InternalAddress |
579 | // | 639 | // |
@@ -693,6 +753,57 @@ namespace OpenSim.Framework | |||
693 | } | 753 | } |
694 | } | 754 | } |
695 | 755 | ||
756 | // Make sure user specified region sizes are sane. | ||
757 | // Must be multiples of legacy region size (256). | ||
758 | private void DoRegionSizeSanityChecks() | ||
759 | { | ||
760 | if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize) | ||
761 | { | ||
762 | // Doing non-legacy region sizes. | ||
763 | // Enforce region size to be multiples of the legacy region size (256) | ||
764 | uint partial = RegionSizeX % Constants.RegionSize; | ||
765 | if (partial != 0) | ||
766 | { | ||
767 | RegionSizeX -= partial; | ||
768 | if (RegionSizeX == 0) | ||
769 | RegionSizeX = Constants.RegionSize; | ||
770 | m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeX={3} instead of specified {4}", | ||
771 | LogHeader, Constants.RegionSize, m_regionName, RegionSizeX, RegionSizeX + partial); | ||
772 | } | ||
773 | partial = RegionSizeY % Constants.RegionSize; | ||
774 | if (partial != 0) | ||
775 | { | ||
776 | RegionSizeY -= partial; | ||
777 | if (RegionSizeY == 0) | ||
778 | RegionSizeY = Constants.RegionSize; | ||
779 | m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeY={3} instead of specified {4}", | ||
780 | LogHeader, Constants.RegionSize, m_regionName, RegionSizeY, RegionSizeY + partial); | ||
781 | } | ||
782 | |||
783 | // Because of things in the viewer, regions MUST be square. | ||
784 | // Remove this check when viewers have been updated. | ||
785 | if (RegionSizeX != RegionSizeY) | ||
786 | { | ||
787 | uint minSize = Math.Min(RegionSizeX, RegionSizeY); | ||
788 | RegionSizeX = minSize; | ||
789 | RegionSizeY = minSize; | ||
790 | m_log.ErrorFormat("{0} Regions must be square until viewers are updated. Forcing region {1} size to <{2},{3}>", | ||
791 | LogHeader, m_regionName, RegionSizeX, RegionSizeY); | ||
792 | } | ||
793 | |||
794 | // There is a practical limit to region size. | ||
795 | if (RegionSizeX > Constants.MaximumRegionSize || RegionSizeY > Constants.MaximumRegionSize) | ||
796 | { | ||
797 | RegionSizeX = Util.Clamp<uint>(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize); | ||
798 | RegionSizeY = Util.Clamp<uint>(RegionSizeY, Constants.RegionSize, Constants.MaximumRegionSize); | ||
799 | m_log.ErrorFormat("{0} Region dimensions must be less than {1}. Clamping {2}'s size to <{3},{4}>", | ||
800 | LogHeader, Constants.MaximumRegionSize, m_regionName, RegionSizeX, RegionSizeY); | ||
801 | } | ||
802 | |||
803 | m_log.InfoFormat("{0} Region {1} size set to <{2},{3}>", LogHeader, m_regionName, RegionSizeX, RegionSizeY); | ||
804 | } | ||
805 | } | ||
806 | |||
696 | private void WriteNiniConfig(IConfigSource source) | 807 | private void WriteNiniConfig(IConfigSource source) |
697 | { | 808 | { |
698 | IConfig config = source.Configs[RegionName]; | 809 | IConfig config = source.Configs[RegionName]; |
@@ -704,9 +815,16 @@ namespace OpenSim.Framework | |||
704 | 815 | ||
705 | config.Set("RegionUUID", RegionID.ToString()); | 816 | config.Set("RegionUUID", RegionID.ToString()); |
706 | 817 | ||
707 | string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY); | 818 | string location = String.Format("{0},{1}", LegacyRegionLocX, LegacyRegionLocY); |
708 | config.Set("Location", location); | 819 | config.Set("Location", location); |
709 | 820 | ||
821 | if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize) | ||
822 | { | ||
823 | config.Set("SizeX", RegionSizeX); | ||
824 | config.Set("SizeY", RegionSizeY); | ||
825 | config.Set("SizeZ", RegionSizeZ); | ||
826 | } | ||
827 | |||
710 | config.Set("InternalAddress", m_internalEndPoint.Address.ToString()); | 828 | config.Set("InternalAddress", m_internalEndPoint.Address.ToString()); |
711 | config.Set("InternalPort", m_internalEndPoint.Port); | 829 | config.Set("InternalPort", m_internalEndPoint.Port); |
712 | 830 | ||
@@ -789,10 +907,18 @@ namespace OpenSim.Framework | |||
789 | RegionID.ToString(), true); | 907 | RegionID.ToString(), true); |
790 | configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, | 908 | configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, |
791 | "Region Name", RegionName, true); | 909 | "Region Name", RegionName, true); |
910 | |||
792 | configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | 911 | configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, |
793 | "Grid Location (X Axis)", m_regionLocX.ToString(), true); | 912 | "Grid Location (X Axis)", LegacyRegionLocX.ToString(), true); |
794 | configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | 913 | configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, |
795 | "Grid Location (Y Axis)", m_regionLocY.ToString(), true); | 914 | "Grid Location (Y Axis)", LegacyRegionLocY.ToString(), true); |
915 | configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
916 | "Size of region in X dimension", RegionSizeX.ToString(), true); | ||
917 | configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
918 | "Size of region in Y dimension", RegionSizeY.ToString(), true); | ||
919 | configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
920 | "Size of region in Z dimension", RegionSizeZ.ToString(), true); | ||
921 | |||
796 | //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); | 922 | //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); |
797 | configMember.addConfigurationOption("internal_ip_address", | 923 | configMember.addConfigurationOption("internal_ip_address", |
798 | ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, | 924 | ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, |
@@ -855,10 +981,18 @@ namespace OpenSim.Framework | |||
855 | UUID.Random().ToString(), true); | 981 | UUID.Random().ToString(), true); |
856 | configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, | 982 | configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, |
857 | "Region Name", "OpenSim Test", false); | 983 | "Region Name", "OpenSim Test", false); |
984 | |||
858 | configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | 985 | configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, |
859 | "Grid Location (X Axis)", "1000", false); | 986 | "Grid Location (X Axis)", "1000", false); |
860 | configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | 987 | configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, |
861 | "Grid Location (Y Axis)", "1000", false); | 988 | "Grid Location (Y Axis)", "1000", false); |
989 | configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
990 | "Size of region in X dimension", Constants.RegionSize.ToString(), false); | ||
991 | configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
992 | "Size of region in Y dimension", Constants.RegionSize.ToString(), false); | ||
993 | configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||
994 | "Size of region in Z dimension", Constants.RegionHeight.ToString(), false); | ||
995 | |||
862 | //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); | 996 | //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); |
863 | configMember.addConfigurationOption("internal_ip_address", | 997 | configMember.addConfigurationOption("internal_ip_address", |
864 | ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, | 998 | ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, |
@@ -916,10 +1050,19 @@ namespace OpenSim.Framework | |||
916 | RegionName = (string) configuration_result; | 1050 | RegionName = (string) configuration_result; |
917 | break; | 1051 | break; |
918 | case "sim_location_x": | 1052 | case "sim_location_x": |
919 | m_regionLocX = (uint) configuration_result; | 1053 | LegacyRegionLocX = (uint) configuration_result; |
920 | break; | 1054 | break; |
921 | case "sim_location_y": | 1055 | case "sim_location_y": |
922 | m_regionLocY = (uint) configuration_result; | 1056 | LegacyRegionLocY = (uint) configuration_result; |
1057 | break; | ||
1058 | case "sim_size_x": | ||
1059 | RegionSizeX = (uint) configuration_result; | ||
1060 | break; | ||
1061 | case "sim_size_y": | ||
1062 | RegionSizeY = (uint) configuration_result; | ||
1063 | break; | ||
1064 | case "sim_size_z": | ||
1065 | RegionSizeZ = (uint) configuration_result; | ||
923 | break; | 1066 | break; |
924 | case "internal_ip_address": | 1067 | case "internal_ip_address": |
925 | IPAddress address = (IPAddress) configuration_result; | 1068 | IPAddress address = (IPAddress) configuration_result; |
@@ -1000,8 +1143,13 @@ namespace OpenSim.Framework | |||
1000 | args["external_host_name"] = OSD.FromString(ExternalHostName); | 1143 | args["external_host_name"] = OSD.FromString(ExternalHostName); |
1001 | args["http_port"] = OSD.FromString(HttpPort.ToString()); | 1144 | args["http_port"] = OSD.FromString(HttpPort.ToString()); |
1002 | args["server_uri"] = OSD.FromString(ServerURI); | 1145 | args["server_uri"] = OSD.FromString(ServerURI); |
1003 | args["region_xloc"] = OSD.FromString(RegionLocX.ToString()); | 1146 | |
1004 | args["region_yloc"] = OSD.FromString(RegionLocY.ToString()); | 1147 | args["region_xloc"] = OSD.FromString(LegacyRegionLocX.ToString()); |
1148 | args["region_yloc"] = OSD.FromString(LegacyRegionLocY.ToString()); | ||
1149 | args["region_size_x"] = OSD.FromString(RegionSizeX.ToString()); | ||
1150 | args["region_size_y"] = OSD.FromString(RegionSizeY.ToString()); | ||
1151 | args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString()); | ||
1152 | |||
1005 | args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString()); | 1153 | args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString()); |
1006 | args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString()); | 1154 | args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString()); |
1007 | if ((RemotingAddress != null) && !RemotingAddress.Equals("")) | 1155 | if ((RemotingAddress != null) && !RemotingAddress.Equals("")) |
@@ -1032,14 +1180,21 @@ namespace OpenSim.Framework | |||
1032 | { | 1180 | { |
1033 | uint locx; | 1181 | uint locx; |
1034 | UInt32.TryParse(args["region_xloc"].AsString(), out locx); | 1182 | UInt32.TryParse(args["region_xloc"].AsString(), out locx); |
1035 | RegionLocX = locx; | 1183 | LegacyRegionLocX = locx; |
1036 | } | 1184 | } |
1037 | if (args["region_yloc"] != null) | 1185 | if (args["region_yloc"] != null) |
1038 | { | 1186 | { |
1039 | uint locy; | 1187 | uint locy; |
1040 | UInt32.TryParse(args["region_yloc"].AsString(), out locy); | 1188 | UInt32.TryParse(args["region_yloc"].AsString(), out locy); |
1041 | RegionLocY = locy; | 1189 | LegacyRegionLocY = locy; |
1042 | } | 1190 | } |
1191 | if (args.ContainsKey("region_size_x")) | ||
1192 | RegionSizeX = (uint)args["region_size_x"].AsInteger(); | ||
1193 | if (args.ContainsKey("region_size_y")) | ||
1194 | RegionSizeY = (uint)args["region_size_y"].AsInteger(); | ||
1195 | if (args.ContainsKey("region_size_z")) | ||
1196 | RegionSizeZ = (uint)args["region_size_z"].AsInteger(); | ||
1197 | |||
1043 | IPAddress ip_addr = null; | 1198 | IPAddress ip_addr = null; |
1044 | if (args["internal_ep_address"] != null) | 1199 | if (args["internal_ep_address"] != null) |
1045 | { | 1200 | { |
@@ -1076,23 +1231,5 @@ namespace OpenSim.Framework | |||
1076 | regionInfo.ServerURI = serverURI; | 1231 | regionInfo.ServerURI = serverURI; |
1077 | return regionInfo; | 1232 | return regionInfo; |
1078 | } | 1233 | } |
1079 | |||
1080 | public Dictionary<string, object> ToKeyValuePairs() | ||
1081 | { | ||
1082 | Dictionary<string, object> kvp = new Dictionary<string, object>(); | ||
1083 | kvp["uuid"] = RegionID.ToString(); | ||
1084 | kvp["locX"] = RegionLocX.ToString(); | ||
1085 | kvp["locY"] = RegionLocY.ToString(); | ||
1086 | kvp["external_ip_address"] = ExternalEndPoint.Address.ToString(); | ||
1087 | kvp["external_port"] = ExternalEndPoint.Port.ToString(); | ||
1088 | kvp["external_host_name"] = ExternalHostName; | ||
1089 | kvp["http_port"] = HttpPort.ToString(); | ||
1090 | kvp["internal_ip_address"] = InternalEndPoint.Address.ToString(); | ||
1091 | kvp["internal_port"] = InternalEndPoint.Port.ToString(); | ||
1092 | kvp["alternate_ports"] = m_allow_alternate_ports.ToString(); | ||
1093 | kvp["server_uri"] = ServerURI; | ||
1094 | |||
1095 | return kvp; | ||
1096 | } | ||
1097 | } | 1234 | } |
1098 | } | 1235 | } |
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs new file mode 100644 index 0000000..1c52a69 --- /dev/null +++ b/OpenSim/Framework/TerrainData.cs | |||
@@ -0,0 +1,418 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | |||
33 | using OpenMetaverse; | ||
34 | |||
35 | using log4net; | ||
36 | |||
37 | namespace OpenSim.Framework | ||
38 | { | ||
39 | public abstract class TerrainData | ||
40 | { | ||
41 | // Terrain always is a square | ||
42 | public int SizeX { get; protected set; } | ||
43 | public int SizeY { get; protected set; } | ||
44 | public int SizeZ { get; protected set; } | ||
45 | |||
46 | // A height used when the user doesn't specify anything | ||
47 | public const float DefaultTerrainHeight = 21f; | ||
48 | |||
49 | public abstract float this[int x, int y] { get; set; } | ||
50 | // Someday terrain will have caves | ||
51 | public abstract float this[int x, int y, int z] { get; set; } | ||
52 | |||
53 | public bool IsTainted { get; protected set; } | ||
54 | public abstract bool IsTaintedAt(int xx, int yy); | ||
55 | public abstract void ClearTaint(); | ||
56 | |||
57 | public abstract void ClearLand(); | ||
58 | public abstract void ClearLand(float height); | ||
59 | |||
60 | // Return a representation of this terrain for storing as a blob in the database. | ||
61 | // Returns 'true' to say blob was stored in the 'out' locations. | ||
62 | public abstract bool GetDatabaseBlob(out int DBFormatRevisionCode, out Array blob); | ||
63 | |||
64 | // Given a revision code and a blob from the database, create and return the right type of TerrainData. | ||
65 | // The sizes passed are the expected size of the region. The database info will be used to | ||
66 | // initialize the heightmap of that sized region with as much data is in the blob. | ||
67 | // Return created TerrainData or 'null' if unsuccessful. | ||
68 | public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) | ||
69 | { | ||
70 | // For the moment, there is only one implementation class | ||
71 | return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); | ||
72 | } | ||
73 | |||
74 | // return a special compressed representation of the heightmap in shorts | ||
75 | public abstract short[] GetCompressedMap(); | ||
76 | public abstract float CompressionFactor { get; } | ||
77 | |||
78 | public abstract double[,] GetDoubles(); | ||
79 | public abstract TerrainData Clone(); | ||
80 | } | ||
81 | |||
82 | // The terrain is stored in the database as a blob with a 'revision' field. | ||
83 | // Some implementations of terrain storage would fill the revision field with | ||
84 | // the time the terrain was stored. When real revisions were added and this | ||
85 | // feature removed, that left some old entries with the time in the revision | ||
86 | // field. | ||
87 | // Thus, if revision is greater than 'RevisionHigh' then terrain db entry is | ||
88 | // left over and it is presumed to be 'Legacy256'. | ||
89 | // Numbers are arbitrary and are chosen to to reduce possible mis-interpretation. | ||
90 | // If a revision does not match any of these, it is assumed to be Legacy256. | ||
91 | public enum DBTerrainRevision | ||
92 | { | ||
93 | // Terrain is 'double[256,256]' | ||
94 | Legacy256 = 11, | ||
95 | // Terrain is 'int32, int32, float[,]' where the ints are X and Y dimensions | ||
96 | // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. | ||
97 | Variable2D = 22, | ||
98 | // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions | ||
99 | // and third int is the 'compression factor'. The heights are compressed as | ||
100 | // "short compressedHeight = (short)(height * compressionFactor);" | ||
101 | // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. | ||
102 | Compressed2D = 27, | ||
103 | // A revision that is not listed above or any revision greater than this value is 'Legacy256'. | ||
104 | RevisionHigh = 1234 | ||
105 | } | ||
106 | |||
107 | // Version of terrain that is a heightmap. | ||
108 | // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge | ||
109 | // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. | ||
110 | // The heighmap is kept as an array of short integers. The integer values are converted to | ||
111 | // and from floats by TerrainCompressionFactor. Shorts are used to limit storage used. | ||
112 | public class HeightmapTerrainData : TerrainData | ||
113 | { | ||
114 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
115 | private static string LogHeader = "[HEIGHTMAP TERRAIN DATA]"; | ||
116 | |||
117 | // TerrainData.this[x, y] | ||
118 | public override float this[int x, int y] | ||
119 | { | ||
120 | get { return FromCompressedHeight(m_heightmap[x, y]); } | ||
121 | set { | ||
122 | short newVal = ToCompressedHeight(value); | ||
123 | if (m_heightmap[x, y] != newVal) | ||
124 | { | ||
125 | m_heightmap[x, y] = newVal; | ||
126 | m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true; | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | |||
131 | // TerrainData.this[x, y, z] | ||
132 | public override float this[int x, int y, int z] | ||
133 | { | ||
134 | get { return this[x, y]; } | ||
135 | set { this[x, y] = value; } | ||
136 | } | ||
137 | |||
138 | // TerrainData.ClearTaint | ||
139 | public override void ClearTaint() | ||
140 | { | ||
141 | IsTainted = false; | ||
142 | for (int ii = 0; ii < m_taint.GetLength(0); ii++) | ||
143 | for (int jj = 0; jj < m_taint.GetLength(1); jj++) | ||
144 | m_taint[ii, jj] = false; | ||
145 | } | ||
146 | |||
147 | // TerrainData.ClearLand | ||
148 | public override void ClearLand() | ||
149 | { | ||
150 | ClearLand(DefaultTerrainHeight); | ||
151 | } | ||
152 | // TerrainData.ClearLand(float) | ||
153 | public override void ClearLand(float pHeight) | ||
154 | { | ||
155 | short flatHeight = ToCompressedHeight(pHeight); | ||
156 | for (int xx = 0; xx < SizeX; xx++) | ||
157 | for (int yy = 0; yy < SizeY; yy++) | ||
158 | m_heightmap[xx, yy] = flatHeight; | ||
159 | } | ||
160 | |||
161 | public override bool IsTaintedAt(int xx, int yy) | ||
162 | { | ||
163 | return m_taint[xx / Constants.TerrainPatchSize, yy / Constants.TerrainPatchSize]; | ||
164 | } | ||
165 | |||
166 | // TerrainData.GetDatabaseBlob | ||
167 | // The user wants something to store in the database. | ||
168 | public override bool GetDatabaseBlob(out int DBRevisionCode, out Array blob) | ||
169 | { | ||
170 | bool ret = false; | ||
171 | if (SizeX == Constants.RegionSize && SizeY == Constants.RegionSize) | ||
172 | { | ||
173 | DBRevisionCode = (int)DBTerrainRevision.Legacy256; | ||
174 | blob = ToLegacyTerrainSerialization(); | ||
175 | ret = true; | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | DBRevisionCode = (int)DBTerrainRevision.Compressed2D; | ||
180 | blob = ToCompressedTerrainSerialization(); | ||
181 | ret = true; | ||
182 | } | ||
183 | return ret; | ||
184 | } | ||
185 | |||
186 | // TerrainData.CompressionFactor | ||
187 | private float m_compressionFactor = 100.0f; | ||
188 | public override float CompressionFactor { get { return m_compressionFactor; } } | ||
189 | |||
190 | // TerrainData.GetCompressedMap | ||
191 | public override short[] GetCompressedMap() | ||
192 | { | ||
193 | short[] newMap = new short[SizeX * SizeY]; | ||
194 | |||
195 | int ind = 0; | ||
196 | for (int xx = 0; xx < SizeX; xx++) | ||
197 | for (int yy = 0; yy < SizeY; yy++) | ||
198 | newMap[ind++] = m_heightmap[xx, yy]; | ||
199 | |||
200 | return newMap; | ||
201 | |||
202 | } | ||
203 | // TerrainData.Clone | ||
204 | public override TerrainData Clone() | ||
205 | { | ||
206 | HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ); | ||
207 | ret.m_heightmap = (short[,])this.m_heightmap.Clone(); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | // TerrainData.GetDoubles | ||
212 | public override double[,] GetDoubles() | ||
213 | { | ||
214 | double[,] ret = new double[SizeX, SizeY]; | ||
215 | for (int xx = 0; xx < SizeX; xx++) | ||
216 | for (int yy = 0; yy < SizeY; yy++) | ||
217 | ret[xx, yy] = FromCompressedHeight(m_heightmap[xx, yy]); | ||
218 | |||
219 | return ret; | ||
220 | } | ||
221 | |||
222 | |||
223 | // ============================================================= | ||
224 | |||
225 | private short[,] m_heightmap; | ||
226 | // Remember subregions of the heightmap that has changed. | ||
227 | private bool[,] m_taint; | ||
228 | |||
229 | // To save space (especially for large regions), keep the height as a short integer | ||
230 | // that is coded as the float height times the compression factor (usually '100' | ||
231 | // to make for two decimal points). | ||
232 | public short ToCompressedHeight(double pHeight) | ||
233 | { | ||
234 | return (short)(pHeight * CompressionFactor); | ||
235 | } | ||
236 | |||
237 | public float FromCompressedHeight(short pHeight) | ||
238 | { | ||
239 | return ((float)pHeight) / CompressionFactor; | ||
240 | } | ||
241 | |||
242 | // To keep with the legacy theme, create an instance of this class based on the | ||
243 | // way terrain used to be passed around. | ||
244 | public HeightmapTerrainData(double[,] pTerrain) | ||
245 | { | ||
246 | SizeX = pTerrain.GetLength(0); | ||
247 | SizeY = pTerrain.GetLength(1); | ||
248 | SizeZ = (int)Constants.RegionHeight; | ||
249 | m_compressionFactor = 100.0f; | ||
250 | |||
251 | m_heightmap = new short[SizeX, SizeY]; | ||
252 | for (int ii = 0; ii < SizeX; ii++) | ||
253 | { | ||
254 | for (int jj = 0; jj < SizeY; jj++) | ||
255 | { | ||
256 | m_heightmap[ii, jj] = ToCompressedHeight(pTerrain[ii, jj]); | ||
257 | |||
258 | } | ||
259 | } | ||
260 | // m_log.DebugFormat("{0} new by doubles. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); | ||
261 | |||
262 | m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; | ||
263 | ClearTaint(); | ||
264 | } | ||
265 | |||
266 | // Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that | ||
267 | public HeightmapTerrainData(int pX, int pY, int pZ) | ||
268 | { | ||
269 | SizeX = pX; | ||
270 | SizeY = pY; | ||
271 | SizeZ = pZ; | ||
272 | m_compressionFactor = 100.0f; | ||
273 | m_heightmap = new short[SizeX, SizeY]; | ||
274 | m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; | ||
275 | // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); | ||
276 | ClearTaint(); | ||
277 | } | ||
278 | |||
279 | public HeightmapTerrainData(short[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) | ||
280 | { | ||
281 | m_compressionFactor = pCompressionFactor; | ||
282 | int ind = 0; | ||
283 | for (int xx = 0; xx < SizeX; xx++) | ||
284 | for (int yy = 0; yy < SizeY; yy++) | ||
285 | m_heightmap[xx, yy] = cmap[ind++]; | ||
286 | // m_log.DebugFormat("{0} new by compressed map. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); | ||
287 | } | ||
288 | |||
289 | // Create a heighmap from a database blob | ||
290 | public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) : this(pSizeX, pSizeY, pSizeZ) | ||
291 | { | ||
292 | switch ((DBTerrainRevision)pFormatCode) | ||
293 | { | ||
294 | case DBTerrainRevision.Compressed2D: | ||
295 | FromCompressedTerrainSerialization(pBlob); | ||
296 | m_log.DebugFormat("{0} HeightmapTerrainData create from Compressed2D serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY); | ||
297 | break; | ||
298 | default: | ||
299 | FromLegacyTerrainSerialization(pBlob); | ||
300 | m_log.DebugFormat("{0} HeightmapTerrainData create from legacy serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY); | ||
301 | break; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | // Just create an array of doubles. Presumes the caller implicitly knows the size. | ||
306 | public Array ToLegacyTerrainSerialization() | ||
307 | { | ||
308 | Array ret = null; | ||
309 | |||
310 | using (MemoryStream str = new MemoryStream((int)Constants.RegionSize * (int)Constants.RegionSize * sizeof(double))) | ||
311 | { | ||
312 | using (BinaryWriter bw = new BinaryWriter(str)) | ||
313 | { | ||
314 | for (int xx = 0; xx < Constants.RegionSize; xx++) | ||
315 | { | ||
316 | for (int yy = 0; yy < Constants.RegionSize; yy++) | ||
317 | { | ||
318 | double height = this[xx, yy]; | ||
319 | if (height == 0.0) | ||
320 | height = double.Epsilon; | ||
321 | bw.Write(height); | ||
322 | } | ||
323 | } | ||
324 | } | ||
325 | ret = str.ToArray(); | ||
326 | } | ||
327 | return ret; | ||
328 | } | ||
329 | |||
330 | // Just create an array of doubles. Presumes the caller implicitly knows the size. | ||
331 | public void FromLegacyTerrainSerialization(byte[] pBlob) | ||
332 | { | ||
333 | // In case database info doesn't match real terrain size, initialize the whole terrain. | ||
334 | ClearLand(); | ||
335 | |||
336 | using (MemoryStream mstr = new MemoryStream(pBlob)) | ||
337 | { | ||
338 | using (BinaryReader br = new BinaryReader(mstr)) | ||
339 | { | ||
340 | for (int xx = 0; xx < (int)Constants.RegionSize; xx++) | ||
341 | { | ||
342 | for (int yy = 0; yy < (int)Constants.RegionSize; yy++) | ||
343 | { | ||
344 | float val = (float)br.ReadDouble(); | ||
345 | if (xx < SizeX && yy < SizeY) | ||
346 | m_heightmap[xx, yy] = ToCompressedHeight(val); | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | ClearTaint(); | ||
351 | } | ||
352 | } | ||
353 | |||
354 | // See the reader below. | ||
355 | public Array ToCompressedTerrainSerialization() | ||
356 | { | ||
357 | Array ret = null; | ||
358 | using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(Int16)))) | ||
359 | { | ||
360 | using (BinaryWriter bw = new BinaryWriter(str)) | ||
361 | { | ||
362 | bw.Write((Int32)DBTerrainRevision.Compressed2D); | ||
363 | bw.Write((Int32)SizeX); | ||
364 | bw.Write((Int32)SizeY); | ||
365 | bw.Write((Int32)CompressionFactor); | ||
366 | for (int yy = 0; yy < SizeY; yy++) | ||
367 | for (int xx = 0; xx < SizeX; xx++) | ||
368 | { | ||
369 | bw.Write((Int16)m_heightmap[xx, yy]); | ||
370 | } | ||
371 | } | ||
372 | ret = str.ToArray(); | ||
373 | } | ||
374 | return ret; | ||
375 | } | ||
376 | |||
377 | // Initialize heightmap from blob consisting of: | ||
378 | // int32, int32, int32, int32, int16[] | ||
379 | // where the first int32 is format code, next two int32s are the X and y of heightmap data and | ||
380 | // the forth int is the compression factor for the following int16s | ||
381 | // This is just sets heightmap info. The actual size of the region was set on this instance's | ||
382 | // creation and any heights not initialized by theis blob are set to the default height. | ||
383 | public void FromCompressedTerrainSerialization(byte[] pBlob) | ||
384 | { | ||
385 | Int32 hmFormatCode, hmSizeX, hmSizeY, hmCompressionFactor; | ||
386 | |||
387 | using (MemoryStream mstr = new MemoryStream(pBlob)) | ||
388 | { | ||
389 | using (BinaryReader br = new BinaryReader(mstr)) | ||
390 | { | ||
391 | hmFormatCode = br.ReadInt32(); | ||
392 | hmSizeX = br.ReadInt32(); | ||
393 | hmSizeY = br.ReadInt32(); | ||
394 | hmCompressionFactor = br.ReadInt32(); | ||
395 | |||
396 | m_compressionFactor = hmCompressionFactor; | ||
397 | |||
398 | // In case database info doesn't match real terrain size, initialize the whole terrain. | ||
399 | ClearLand(); | ||
400 | |||
401 | for (int yy = 0; yy < hmSizeY; yy++) | ||
402 | { | ||
403 | for (int xx = 0; xx < hmSizeX; xx++) | ||
404 | { | ||
405 | Int16 val = br.ReadInt16(); | ||
406 | if (xx < SizeX && yy < SizeY) | ||
407 | m_heightmap[xx, yy] = val; | ||
408 | } | ||
409 | } | ||
410 | } | ||
411 | ClearTaint(); | ||
412 | |||
413 | m_log.InfoFormat("{0} Read compressed 2d heightmap. Heightmap size=<{1},{2}>. Region size=<{3},{4}>. CompFact={5}", | ||
414 | LogHeader, hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor); | ||
415 | } | ||
416 | } | ||
417 | } | ||
418 | } | ||
diff --git a/OpenSim/Framework/UserProfileData.cs b/OpenSim/Framework/UserProfileData.cs index 9bac739..266ccf0 100644 --- a/OpenSim/Framework/UserProfileData.cs +++ b/OpenSim/Framework/UserProfileData.cs | |||
@@ -160,15 +160,19 @@ namespace OpenSim.Framework | |||
160 | public virtual ulong HomeRegion | 160 | public virtual ulong HomeRegion |
161 | { | 161 | { |
162 | get | 162 | get |
163 | { | 163 | { |
164 | return Utils.UIntsToLong( | 164 | return Util.RegionWorldLocToHandle(Util.RegionToWorldLoc(m_homeRegionX), Util.RegionToWorldLoc(m_homeRegionY)); |
165 | m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize); | 165 | // return Utils.UIntsToLong( m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize); |
166 | } | 166 | } |
167 | 167 | ||
168 | set | 168 | set |
169 | { | 169 | { |
170 | m_homeRegionX = (uint) (value >> 40); | 170 | uint regionWorldLocX, regionWorldLocY; |
171 | m_homeRegionY = (((uint) (value)) >> 8); | 171 | Util.RegionHandleToWorldLoc(value, out regionWorldLocX, out regionWorldLocY); |
172 | m_homeRegionX = Util.WorldToRegionLoc(regionWorldLocX); | ||
173 | m_homeRegionY = Util.WorldToRegionLoc(regionWorldLocY); | ||
174 | // m_homeRegionX = (uint) (value >> 40); | ||
175 | // m_homeRegionY = (((uint) (value)) >> 8); | ||
172 | } | 176 | } |
173 | } | 177 | } |
174 | 178 | ||
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index e8dfec1..2276951 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -333,6 +333,44 @@ 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 void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) | ||
346 | { | ||
347 | X = (uint)(handle >> 32); | ||
348 | Y = (uint)(handle & (ulong)uint.MaxValue); | ||
349 | } | ||
350 | |||
351 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) | ||
352 | { | ||
353 | uint worldX, worldY; | ||
354 | RegionHandleToWorldLoc(handle, out worldX, out worldY); | ||
355 | X = WorldToRegionLoc(worldX); | ||
356 | Y = WorldToRegionLoc(worldY); | ||
357 | } | ||
358 | |||
359 | // A region location can be 'world coordinates' (meters from zero) or 'region coordinates' | ||
360 | // (number of regions from zero). This measurement of regions relies on the legacy 256 region size. | ||
361 | // These routines exist to make what is being converted explicit so the next person knows what was meant. | ||
362 | // Convert a region's 'world coordinate' to its 'region coordinate'. | ||
363 | public static uint WorldToRegionLoc(uint worldCoord) | ||
364 | { | ||
365 | return worldCoord / Constants.RegionSize; | ||
366 | } | ||
367 | |||
368 | // Convert a region's 'region coordinate' to its 'world coordinate'. | ||
369 | public static uint RegionToWorldLoc(uint regionCoord) | ||
370 | { | ||
371 | return regionCoord * Constants.RegionSize; | ||
372 | } | ||
373 | |||
336 | public static T Clamp<T>(T x, T min, T max) | 374 | public static T Clamp<T>(T x, T min, T max) |
337 | where T : IComparable<T> | 375 | where T : IComparable<T> |
338 | { | 376 | { |