aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Land/LandObject.cs
diff options
context:
space:
mode:
authorRobert Adams2015-03-29 16:45:00 -0700
committerRobert Adams2015-03-29 16:45:00 -0700
commitdf14b40e88e658a2adb50d45c941fb016a2952eb (patch)
tree4d9b7f8a62b0999af7c1971c232809ade765fc8b /OpenSim/Region/CoreModules/World/Land/LandObject.cs
parentvarregion: any conversions of use of Constants.RegionSize converted into (diff)
downloadopensim-SC_OLD-df14b40e88e658a2adb50d45c941fb016a2952eb.zip
opensim-SC_OLD-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.gz
opensim-SC_OLD-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.bz2
opensim-SC_OLD-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.xz
varregion: update LandManagementModule and LandObject for variable sized regions.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Land/LandObject.cs')
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs176
1 files changed, 99 insertions, 77 deletions
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index a3cd4a5..5858d6c 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -45,15 +45,13 @@ namespace OpenSim.Region.CoreModules.World.Land
45 #region Member Variables 45 #region Member Variables
46 46
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 #pragma warning disable 0429 48 private static readonly string LogHeader = "[LAND OBJECT]";
49 private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64; 49
50 #pragma warning restore 0429 50 private readonly int landUnit = 4;
51 private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax];
52 51
53 private int m_lastSeqId = 0; 52 private int m_lastSeqId = 0;
54 private int m_expiryCounter = 0; 53 private int m_expiryCounter = 0;
55 54
56 protected LandData m_landData = new LandData();
57 protected Scene m_scene; 55 protected Scene m_scene;
58 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>(); 56 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
59 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>(); 57 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
@@ -61,6 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Land
61 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>(); 59 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>();
62 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds 60 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds
63 61
62 private bool[,] m_landBitmap;
64 public bool[,] LandBitmap 63 public bool[,] LandBitmap
65 { 64 {
66 get { return m_landBitmap; } 65 get { return m_landBitmap; }
@@ -76,6 +75,7 @@ namespace OpenSim.Region.CoreModules.World.Land
76 return free; 75 return free;
77 } 76 }
78 77
78 protected LandData m_landData;
79 public LandData LandData 79 public LandData LandData
80 { 80 {
81 get { return m_landData; } 81 get { return m_landData; }
@@ -94,12 +94,12 @@ namespace OpenSim.Region.CoreModules.World.Land
94 { 94 {
95 get 95 get
96 { 96 {
97 for (int y = 0; y < landArrayMax; y++) 97 for (int y = 0; y < LandBitmap.GetLength(1); y++)
98 { 98 {
99 for (int x = 0; x < landArrayMax; x++) 99 for (int x = 0; x < LandBitmap.GetLength(0); x++)
100 { 100 {
101 if (LandBitmap[x, y]) 101 if (LandBitmap[x, y])
102 return new Vector3(x * 4, y * 4, 0); 102 return new Vector3(x * landUnit, y * landUnit, 0);
103 } 103 }
104 } 104 }
105 105
@@ -111,13 +111,13 @@ namespace OpenSim.Region.CoreModules.World.Land
111 { 111 {
112 get 112 get
113 { 113 {
114 for (int y = landArrayMax - 1; y >= 0; y--) 114 for (int y = LandBitmap.GetLength(1) - 1; y >= 0; y--)
115 { 115 {
116 for (int x = landArrayMax - 1; x >= 0; x--) 116 for (int x = LandBitmap.GetLength(0) - 1; x >= 0; x--)
117 { 117 {
118 if (LandBitmap[x, y]) 118 if (LandBitmap[x, y])
119 { 119 {
120 return new Vector3(x * 4 + 4, y * 4 + 4, 0); 120 return new Vector3(x * landUnit + landUnit, y * landUnit + landUnit, 0);
121 } 121 }
122 } 122 }
123 } 123 }
@@ -128,9 +128,21 @@ namespace OpenSim.Region.CoreModules.World.Land
128 128
129 #region Constructors 129 #region Constructors
130 130
131 public LandObject(LandData landData, Scene scene)
132 {
133 LandData = landData.Copy();
134 m_scene = scene;
135 }
136
131 public LandObject(UUID owner_id, bool is_group_owned, Scene scene) 137 public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
132 { 138 {
133 m_scene = scene; 139 m_scene = scene;
140 if (m_scene == null)
141 LandBitmap = new bool[Constants.RegionSize / landUnit, Constants.RegionSize / landUnit];
142 else
143 LandBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
144
145 LandData = new LandData();
134 LandData.OwnerID = owner_id; 146 LandData.OwnerID = owner_id;
135 if (is_group_owned) 147 if (is_group_owned)
136 LandData.GroupID = owner_id; 148 LandData.GroupID = owner_id;
@@ -155,9 +167,9 @@ namespace OpenSim.Region.CoreModules.World.Land
155 /// <returns>Returns true if the piece of land contains the specified point</returns> 167 /// <returns>Returns true if the piece of land contains the specified point</returns>
156 public bool ContainsPoint(int x, int y) 168 public bool ContainsPoint(int x, int y)
157 { 169 {
158 if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize) 170 if (x >= 0 && y >= 0 && x < m_scene.RegionInfo.RegionSizeX && y < m_scene.RegionInfo.RegionSizeY)
159 { 171 {
160 return (LandBitmap[x / 4, y / 4] == true); 172 return LandBitmap[x / landUnit, y / landUnit];
161 } 173 }
162 else 174 else
163 { 175 {
@@ -197,10 +209,10 @@ namespace OpenSim.Region.CoreModules.World.Land
197 else 209 else
198 { 210 {
199 // Normal Calculations 211 // Normal Calculations
200 int parcelMax = (int)((long)LandData.Area 212 int parcelMax = (int)( (long)LandData.Area
201 * (long)m_scene.RegionInfo.ObjectCapacity 213 * (long)m_scene.RegionInfo.ObjectCapacity
202 * (long)m_scene.RegionInfo.RegionSettings.ObjectBonus 214 * (long)m_scene.RegionInfo.RegionSettings.ObjectBonus
203 / 65536L); 215 / (long)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY) );
204 //m_log.DebugFormat("Area: {0}, Capacity {1}, Bonus {2}, Parcel {3}", LandData.Area, m_scene.RegionInfo.ObjectCapacity, m_scene.RegionInfo.RegionSettings.ObjectBonus, parcelMax); 216 //m_log.DebugFormat("Area: {0}, Capacity {1}, Bonus {2}, Parcel {3}", LandData.Area, m_scene.RegionInfo.ObjectCapacity, m_scene.RegionInfo.RegionSettings.ObjectBonus, parcelMax);
205 return parcelMax; 217 return parcelMax;
206 } 218 }
@@ -231,8 +243,9 @@ namespace OpenSim.Region.CoreModules.World.Land
231 else 243 else
232 { 244 {
233 //Normal Calculations 245 //Normal Calculations
234 int simMax = (int)((long)LandData.SimwideArea 246 int simMax = (int)( (long)LandData.SimwideArea
235 * (long)m_scene.RegionInfo.ObjectCapacity / 65536L); 247 * (long)m_scene.RegionInfo.ObjectCapacity
248 / (long)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY) );
236 // m_log.DebugFormat("Simwide Area: {0}, Capacity {1}, SimMax {2}", LandData.SimwideArea, m_scene.RegionInfo.ObjectCapacity, simMax); 249 // m_log.DebugFormat("Simwide Area: {0}, Capacity {1}, SimMax {2}", LandData.SimwideArea, m_scene.RegionInfo.ObjectCapacity, simMax);
237 return simMax; 250 return simMax;
238 } 251 }
@@ -597,8 +610,8 @@ namespace OpenSim.Region.CoreModules.World.Land
597 try 610 try
598 { 611 {
599 over = 612 over =
600 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)), 613 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)m_scene.RegionInfo.RegionSizeX - 1)),
601 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1))); 614 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)m_scene.RegionInfo.RegionSizeY - 1)));
602 } 615 }
603 catch (Exception) 616 catch (Exception)
604 { 617 {
@@ -752,9 +765,9 @@ namespace OpenSim.Region.CoreModules.World.Land
752 int max_y = Int32.MinValue; 765 int max_y = Int32.MinValue;
753 int tempArea = 0; 766 int tempArea = 0;
754 int x, y; 767 int x, y;
755 for (x = 0; x < 64; x++) 768 for (x = 0; x < LandBitmap.GetLength(0); x++)
756 { 769 {
757 for (y = 0; y < 64; y++) 770 for (y = 0; y < LandBitmap.GetLength(1); y++)
758 { 771 {
759 if (LandBitmap[x, y] == true) 772 if (LandBitmap[x, y] == true)
760 { 773 {
@@ -766,23 +779,25 @@ namespace OpenSim.Region.CoreModules.World.Land
766 max_x = x; 779 max_x = x;
767 if (max_y < y) 780 if (max_y < y)
768 max_y = y; 781 max_y = y;
769 tempArea += 16; //16sqm peice of land 782 tempArea += landUnit * landUnit; //16sqm peice of land
770 } 783 }
771 } 784 }
772 } 785 }
786 int tx = min_x * landUnit;
787 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
788 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
773 789
774 int tx = min_x * 4;
775 int htx; 790 int htx;
776 if (tx == ((int)Constants.RegionSize)) 791 if (tx >= ((int)m_scene.RegionInfo.RegionSizeX))
777 htx = tx - 1; 792 htx = (int)m_scene.RegionInfo.RegionSizeX - 1;
778 else 793 else
779 htx = tx; 794 htx = tx;
780 795
781 int ty = min_y * 4; 796 int ty = min_y * landUnit;
782 int hty; 797 int hty;
783 798
784 if (ty == ((int)Constants.RegionSize)) 799 if (ty >= ((int)m_scene.RegionInfo.RegionSizeY))
785 hty = ty - 1; 800 hty = (int)m_scene.RegionInfo.RegionSizeY - 1;
786 else 801 else
787 hty = ty; 802 hty = ty;
788 803
@@ -791,17 +806,17 @@ namespace OpenSim.Region.CoreModules.World.Land
791 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0); 806 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0);
792 807
793 max_x++; 808 max_x++;
794 tx = max_x * 4; 809 tx = max_x * landUnit;
795 if (tx == ((int)Constants.RegionSize)) 810 if (tx >= ((int)m_scene.RegionInfo.RegionSizeX))
796 htx = tx - 1; 811 htx = (int)m_scene.RegionInfo.RegionSizeX - 1;
797 else 812 else
798 htx = tx; 813 htx = tx;
799 814
800 max_y++; 815 max_y++;
801 ty = max_y * 4; 816 ty = max_y * 4;
802 817
803 if (ty == ((int)Constants.RegionSize)) 818 if (ty >= ((int)m_scene.RegionInfo.RegionSizeY))
804 hty = ty - 1; 819 hty = (int)m_scene.RegionInfo.RegionSizeY - 1;
805 else 820 else
806 hty = ty; 821 hty = ty;
807 822
@@ -819,20 +834,11 @@ namespace OpenSim.Region.CoreModules.World.Land
819 /// <summary> 834 /// <summary>
820 /// Sets the land's bitmap manually 835 /// Sets the land's bitmap manually
821 /// </summary> 836 /// </summary>
822 /// <param name="bitmap">64x64 block representing where this land is on a map</param> 837 /// <param name="bitmap">block representing where this land is on a map mapped in a 4x4 meter grid</param>
823 public void SetLandBitmap(bool[,] bitmap) 838 public void SetLandBitmap(bool[,] bitmap)
824 { 839 {
825 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2) 840 LandBitmap = bitmap;
826 { 841 ForceUpdateLandInfo();
827 //Throw an exception - The bitmap is not 64x64
828 //throw new Exception("Error: Invalid Parcel Bitmap");
829 }
830 else
831 {
832 //Valid: Lets set it
833 LandBitmap = bitmap;
834 ForceUpdateLandInfo();
835 }
836 } 842 }
837 843
838 /// <summary> 844 /// <summary>
@@ -846,14 +852,16 @@ namespace OpenSim.Region.CoreModules.World.Land
846 852
847 public bool[,] BasicFullRegionLandBitmap() 853 public bool[,] BasicFullRegionLandBitmap()
848 { 854 {
849 return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize); 855 return GetSquareLandBitmap(0, 0, (int)m_scene.RegionInfo.RegionSizeX, (int) m_scene.RegionInfo.RegionSizeY);
850 } 856 }
851 857
852 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y) 858 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
853 { 859 {
854 bool[,] tempBitmap = new bool[64,64]; 860 // Empty bitmap for the whole region
861 bool[,] tempBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
855 tempBitmap.Initialize(); 862 tempBitmap.Initialize();
856 863
864 // Fill the bitmap square area specified by state and end
857 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true); 865 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
858 return tempBitmap; 866 return tempBitmap;
859 } 867 }
@@ -871,19 +879,13 @@ namespace OpenSim.Region.CoreModules.World.Land
871 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y, 879 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
872 bool set_value) 880 bool set_value)
873 { 881 {
874 if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
875 {
876 //Throw an exception - The bitmap is not 64x64
877 //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
878 }
879
880 int x, y; 882 int x, y;
881 for (y = 0; y < 64; y++) 883 for (y = 0; y < land_bitmap.GetLength(1); y++)
882 { 884 {
883 for (x = 0; x < 64; x++) 885 for (x = 0; x < land_bitmap.GetLength(0); x++)
884 { 886 {
885 if (x >= start_x / 4 && x < end_x / 4 887 if (x >= start_x / landUnit && x < end_x / landUnit
886 && y >= start_y / 4 && y < end_y / 4) 888 && y >= start_y / landUnit && y < end_y / landUnit)
887 { 889 {
888 land_bitmap[x, y] = set_value; 890 land_bitmap[x, y] = set_value;
889 } 891 }
@@ -900,21 +902,21 @@ namespace OpenSim.Region.CoreModules.World.Land
900 /// <returns></returns> 902 /// <returns></returns>
901 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add) 903 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
902 { 904 {
903 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2) 905 if (bitmap_base.GetLength(0) != bitmap_add.GetLength(0)
904 { 906 || bitmap_base.GetLength(1) != bitmap_add.GetLength(1)
905 //Throw an exception - The bitmap is not 64x64 907 || bitmap_add.Rank != 2
906 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps"); 908 || bitmap_base.Rank != 2)
907 }
908 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
909 { 909 {
910 //Throw an exception - The bitmap is not 64x64 910 throw new Exception(
911 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps"); 911 String.Format("{0} MergeLandBitmaps. merging maps not same size. baseSizeXY=<{1},{2}>, addSizeXY=<{3},{4}>",
912 LogHeader, bitmap_base.GetLength(0), bitmap_base.GetLength(1), bitmap_add.GetLength(0), bitmap_add.GetLength(1))
913 );
912 } 914 }
913 915
914 int x, y; 916 int x, y;
915 for (y = 0; y < 64; y++) 917 for (y = 0; y < bitmap_base.GetLength(1); y++)
916 { 918 {
917 for (x = 0; x < 64; x++) 919 for (x = 0; x < bitmap_add.GetLength(0); x++)
918 { 920 {
919 if (bitmap_add[x, y]) 921 if (bitmap_add[x, y])
920 { 922 {
@@ -931,14 +933,14 @@ namespace OpenSim.Region.CoreModules.World.Land
931 /// <returns></returns> 933 /// <returns></returns>
932 private byte[] ConvertLandBitmapToBytes() 934 private byte[] ConvertLandBitmapToBytes()
933 { 935 {
934 byte[] tempConvertArr = new byte[512]; 936 byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
935 int tempByte = 0; 937 int tempByte = 0;
936 int x, y, i, byteNum = 0; 938 int i, byteNum = 0;
937 int mask = 1; 939 int mask = 1;
938 i = 0; 940 i = 0;
939 for (y = 0; y < 64; y++) 941 for (int y = 0; y < LandBitmap.GetLength(1); y++)
940 { 942 {
941 for (x = 0; x < 64; x++) 943 for (int x = 0; x < LandBitmap.GetLength(0); x++)
942 { 944 {
943 if (LandBitmap[x, y]) 945 if (LandBitmap[x, y])
944 tempByte |= mask; 946 tempByte |= mask;
@@ -971,25 +973,45 @@ namespace OpenSim.Region.CoreModules.World.Land
971 973
972 private bool[,] ConvertBytesToLandBitmap() 974 private bool[,] ConvertBytesToLandBitmap()
973 { 975 {
974 bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax]; 976 bool[,] tempConvertMap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
975 tempConvertMap.Initialize(); 977 tempConvertMap.Initialize();
976 byte tempByte = 0; 978 byte tempByte = 0;
977 int x = 0, y = 0, i = 0, bitNum = 0; 979 // Math.Min overcomes an old bug that might have made it into the database. Only use the bytes that fit into convertMap.
978 for (i = 0; i < 512; i++) 980 int bitmapLen = Math.Min(LandData.Bitmap.Length, tempConvertMap.GetLength(0) * tempConvertMap.GetLength(1) / 8);
981 int xLen = (int)(m_scene.RegionInfo.RegionSizeX / landUnit);
982
983 if (bitmapLen == 512)
984 {
985 // Legacy bitmap being passed in. Use the legacy region size
986 // and only set the lower area of the larger region.
987 xLen = (int)(Constants.RegionSize / landUnit);
988 }
989 // m_log.DebugFormat("{0} ConvertBytesToLandBitmap: bitmapLen={1}, xLen={2}", LogHeader, bitmapLen, xLen);
990
991 int x = 0, y = 0;
992 for (int i = 0; i < bitmapLen; i++)
979 { 993 {
980 tempByte = LandData.Bitmap[i]; 994 tempByte = LandData.Bitmap[i];
981 for (bitNum = 0; bitNum < 8; bitNum++) 995 for (int bitNum = 0; bitNum < 8; bitNum++)
982 { 996 {
983 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1); 997 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
984 tempConvertMap[x, y] = bit; 998 try
999 {
1000 tempConvertMap[x, y] = bit;
1001 }
1002 catch (Exception)
1003 {
1004 m_log.DebugFormat("{0} ConvertBytestoLandBitmap: i={1}, x={2}, y={3}", LogHeader, i, x, y);
1005 }
985 x++; 1006 x++;
986 if (x > 63) 1007 if (x >= xLen)
987 { 1008 {
988 x = 0; 1009 x = 0;
989 y++; 1010 y++;
990 } 1011 }
991 } 1012 }
992 } 1013 }
1014
993 return tempConvertMap; 1015 return tempConvertMap;
994 } 1016 }
995 1017