aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
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
parentvarregion: any conversions of use of Constants.RegionSize converted into (diff)
downloadopensim-SC-df14b40e88e658a2adb50d45c941fb016a2952eb.zip
opensim-SC-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.gz
opensim-SC-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.bz2
opensim-SC-df14b40e88e658a2adb50d45c941fb016a2952eb.tar.xz
varregion: update LandManagementModule and LandObject for variable sized regions.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs63
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs176
2 files changed, 133 insertions, 106 deletions
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index 9279066..4aee6a5 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -64,6 +64,12 @@ namespace OpenSim.Region.CoreModules.World.Land
64 public class LandManagementModule : INonSharedRegionModule 64 public class LandManagementModule : INonSharedRegionModule
65 { 65 {
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 private static readonly string LogHeader = "[LAND MANAGEMENT MODULE]";
68
69 /// <summary>
70 /// Minimum land unit size in region co-ordinates.
71 /// </summary>
72 public const int landUnit = 4;
67 73
68 private static readonly string remoteParcelRequestPath = "0009/"; 74 private static readonly string remoteParcelRequestPath = "0009/";
69 75
@@ -74,15 +80,10 @@ namespace OpenSim.Region.CoreModules.World.Land
74 protected IPrimCountModule m_primCountModule; 80 protected IPrimCountModule m_primCountModule;
75 protected IDialogModule m_Dialog; 81 protected IDialogModule m_Dialog;
76 82
77 // Minimum for parcels to work is 64m even if we don't actually use them.
78 #pragma warning disable 0429
79 private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
80 #pragma warning restore 0429
81
82 /// <value> 83 /// <value>
83 /// Local land ids at specified region co-ordinates (region size / 4) 84 /// Local land ids at specified region co-ordinates (region size / 4)
84 /// </value> 85 /// </value>
85 private readonly int[,] m_landIDList = new int[landArrayMax, landArrayMax]; 86 private int[,] m_landIDList;
86 87
87 /// <value> 88 /// <value>
88 /// Land objects keyed by local id 89 /// Land objects keyed by local id
@@ -123,7 +124,7 @@ namespace OpenSim.Region.CoreModules.World.Land
123 public void AddRegion(Scene scene) 124 public void AddRegion(Scene scene)
124 { 125 {
125 m_scene = scene; 126 m_scene = scene;
126 m_landIDList.Initialize(); 127 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
127 landChannel = new LandChannel(scene, this); 128 landChannel = new LandChannel(scene, this);
128 129
129 parcelInfoCache = new Cache(); 130 parcelInfoCache = new Cache();
@@ -235,7 +236,7 @@ namespace OpenSim.Region.CoreModules.World.Land
235 public void UpdateLandObject(int local_id, LandData data) 236 public void UpdateLandObject(int local_id, LandData data)
236 { 237 {
237 LandData newData = data.Copy(); 238 LandData newData = data.Copy();
238 newData.LocalID = local_id; 239 newData.LocalID = local_id;
239 240
240 ILandObject land; 241 ILandObject land;
241 lock (m_landList) 242 lock (m_landList)
@@ -264,7 +265,7 @@ namespace OpenSim.Region.CoreModules.World.Land
264 { 265 {
265 m_landList.Clear(); 266 m_landList.Clear();
266 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; 267 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
267 m_landIDList.Initialize(); 268 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
268 } 269 }
269 } 270 }
270 271
@@ -274,11 +275,11 @@ namespace OpenSim.Region.CoreModules.World.Land
274 /// <returns>The parcel created.</returns> 275 /// <returns>The parcel created.</returns>
275 protected ILandObject CreateDefaultParcel() 276 protected ILandObject CreateDefaultParcel()
276 { 277 {
277 m_log.DebugFormat( 278 m_log.DebugFormat("{0} Creating default parcel for region {1}", LogHeader, m_scene.RegionInfo.RegionName);
278 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
279 279
280 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene); 280 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
281 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize)); 281 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0,
282 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
282 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; 283 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
283 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); 284 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
284 285
@@ -569,9 +570,9 @@ namespace OpenSim.Region.CoreModules.World.Land
569 new_land.LandData.LocalID = newLandLocalID; 570 new_land.LandData.LocalID = newLandLocalID;
570 571
571 bool[,] landBitmap = new_land.GetLandBitmap(); 572 bool[,] landBitmap = new_land.GetLandBitmap();
572 for (int x = 0; x < landArrayMax; x++) 573 for (int x = 0; x < landBitmap.GetLength(0); x++)
573 { 574 {
574 for (int y = 0; y < landArrayMax; y++) 575 for (int y = 0; y < landBitmap.GetLength(1); y++)
575 { 576 {
576 if (landBitmap[x, y]) 577 if (landBitmap[x, y])
577 { 578 {
@@ -601,9 +602,9 @@ namespace OpenSim.Region.CoreModules.World.Land
601 ILandObject land; 602 ILandObject land;
602 lock (m_landList) 603 lock (m_landList)
603 { 604 {
604 for (int x = 0; x < 64; x++) 605 for (int x = 0; x < m_landIDList.GetLength(0); x++)
605 { 606 {
606 for (int y = 0; y < 64; y++) 607 for (int y = 0; y < m_landIDList.GetLength(1); y++)
607 { 608 {
608 if (m_landIDList[x, y] == local_id) 609 if (m_landIDList[x, y] == local_id)
609 { 610 {
@@ -656,9 +657,9 @@ namespace OpenSim.Region.CoreModules.World.Land
656 bool[,] landBitmapSlave = slave.GetLandBitmap(); 657 bool[,] landBitmapSlave = slave.GetLandBitmap();
657 lock (m_landList) 658 lock (m_landList)
658 { 659 {
659 for (int x = 0; x < 64; x++) 660 for (int x = 0; x < landBitmapSlave.GetLength(0); x++)
660 { 661 {
661 for (int y = 0; y < 64; y++) 662 for (int y = 0; y < landBitmapSlave.GetLength(1); y++)
662 { 663 {
663 if (landBitmapSlave[x, y]) 664 if (landBitmapSlave[x, y])
664 { 665 {
@@ -695,20 +696,23 @@ namespace OpenSim.Region.CoreModules.World.Land
695 int x; 696 int x;
696 int y; 697 int y;
697 698
698 if (x_float > Constants.RegionSize || x_float < 0 || y_float > Constants.RegionSize || y_float < 0) 699 if (x_float >= m_scene.RegionInfo.RegionSizeX || x_float < 0 || y_float >= m_scene.RegionInfo.RegionSizeX || y_float < 0)
699 return null; 700 return null;
700 701
701 try 702 try
702 { 703 {
703 x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / 4.0)); 704 x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / (float)landUnit));
704 y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / 4.0)); 705 y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / (float)landUnit));
705 } 706 }
706 catch (OverflowException) 707 catch (OverflowException)
707 { 708 {
708 return null; 709 return null;
709 } 710 }
710 711
711 if (x >= 64 || y >= 64 || x < 0 || y < 0) 712 if (x >= (m_scene.RegionInfo.RegionSizeX / landUnit)
713 || y >= (m_scene.RegionInfo.RegionSizeY / landUnit)
714 || x < 0
715 || y < 0)
712 { 716 {
713 return null; 717 return null;
714 } 718 }
@@ -740,20 +744,20 @@ namespace OpenSim.Region.CoreModules.World.Land
740 int avx = (int)x; 744 int avx = (int)x;
741 if (avx < 0) 745 if (avx < 0)
742 avx = 0; 746 avx = 0;
743 else if (avx >= (int)Constants.RegionSize) 747 else if (avx >= m_scene.RegionInfo.RegionSizeX)
744 avx = (int)Constants.RegionSize - 1; 748 avx = (int)Constants.RegionSize - 1;
745 749
746 int avy = (int)y; 750 int avy = (int)y;
747 if (avy < 0) 751 if (avy < 0)
748 avy = 0; 752 avy = 0;
749 else if (avy >= (int)Constants.RegionSize) 753 else if (avy >= m_scene.RegionInfo.RegionSizeY)
750 avy = (int)Constants.RegionSize - 1; 754 avy = (int)Constants.RegionSize - 1;
751 755
752 lock (m_landIDList) 756 lock (m_landIDList)
753 { 757 {
754 try 758 try
755 { 759 {
756 return m_landList[m_landIDList[avx / 4, avy / 4]]; 760 return m_landList[m_landIDList[avx / landUnit, avy / landUnit]];
757 } 761 }
758 catch (IndexOutOfRangeException) 762 catch (IndexOutOfRangeException)
759 { 763 {
@@ -764,7 +768,7 @@ namespace OpenSim.Region.CoreModules.World.Land
764 768
765 public ILandObject GetLandObject(int x, int y) 769 public ILandObject GetLandObject(int x, int y)
766 { 770 {
767 if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0) 771 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
768 { 772 {
769 // These exceptions here will cause a lot of complaints from the users specifically because 773 // These exceptions here will cause a lot of complaints from the users specifically because
770 // they happen every time at border crossings 774 // they happen every time at border crossings
@@ -1057,9 +1061,10 @@ namespace OpenSim.Region.CoreModules.World.Land
1057 int byteArrayCount = 0; 1061 int byteArrayCount = 0;
1058 int sequenceID = 0; 1062 int sequenceID = 0;
1059 1063
1060 for (int y = 0; y < Constants.RegionSize; y += 4) 1064 // Layer data is in landUnit (4m) chunks
1065 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y += landUnit)
1061 { 1066 {
1062 for (int x = 0; x < Constants.RegionSize; x += 4) 1067 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x += landUnit)
1063 { 1068 {
1064 byte tempByte = 0; //This represents the byte for the current 4x4 1069 byte tempByte = 0; //This represents the byte for the current 4x4
1065 1070
@@ -1769,7 +1774,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1769 { 1774 {
1770 // most likely still cached from building the extLandData entry 1775 // most likely still cached from building the extLandData entry
1771 uint x = 0, y = 0; 1776 uint x = 0, y = 0;
1772 Utils.LongToUInts(data.RegionHandle, out x, out y); 1777 Util.RegionHandleToWorldLoc(data.RegionHandle, out x, out y);
1773 info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); 1778 info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
1774 } 1779 }
1775 // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark. 1780 // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
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