aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorUbitUmarov2015-12-14 11:57:24 +0000
committerUbitUmarov2015-12-14 11:57:24 +0000
commit2a354f6c286b4b70e2768d9b267f53c3d391a10b (patch)
tree7a162221d865ed9e10c0d9049cd82d705bb4c6d6 /OpenSim
parenttaint prim count when join or subdivide parcels (diff)
downloadopensim-SC_OLD-2a354f6c286b4b70e2768d9b267f53c3d391a10b.zip
opensim-SC_OLD-2a354f6c286b4b70e2768d9b267f53c3d391a10b.tar.gz
opensim-SC_OLD-2a354f6c286b4b70e2768d9b267f53c3d391a10b.tar.bz2
opensim-SC_OLD-2a354f6c286b4b70e2768d9b267f53c3d391a10b.tar.xz
calculate land startpoint, endpoint and center estimate when it is updated, it not every time they are needed
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/ILandObject.cs15
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs82
-rwxr-xr-xOpenSim/Region/Framework/Scenes/Scene.cs47
3 files changed, 65 insertions, 79 deletions
diff --git a/OpenSim/Framework/ILandObject.cs b/OpenSim/Framework/ILandObject.cs
index ef7a9e6..7a50c2a 100644
--- a/OpenSim/Framework/ILandObject.cs
+++ b/OpenSim/Framework/ILandObject.cs
@@ -50,16 +50,19 @@ namespace OpenSim.Framework
50 IPrimCounts PrimCounts { get; set; } 50 IPrimCounts PrimCounts { get; set; }
51 51
52 /// <summary> 52 /// <summary>
53 /// The start point for the land object. This is the western-most point as one scans land working from 53 /// The start point for the land object. This is the northern-most point as one scans land working from
54 /// north to south. 54 /// west to east.
55 /// </summary> 55 /// </summary>
56 Vector3 StartPoint { get; } 56 Vector2 StartPoint { get; }
57 57
58 /// <summary> 58 /// <summary>
59 /// The end point for the land object. This is the eastern-most point as one scans land working from 59 /// The end point for the land object. This is the southern-most point as one scans land working from
60 /// south to north. 60 /// west to east.
61 /// </summary> 61 /// </summary>
62 Vector3 EndPoint { get; } 62 Vector2 EndPoint { get; }
63
64 // a estimation of a parcel center.
65 Vector2 CenterPoint { get; }
63 66
64 bool ContainsPoint(int x, int y); 67 bool ContainsPoint(int x, int y);
65 68
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index 28652d7..e1cd283 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -90,43 +90,32 @@ namespace OpenSim.Region.CoreModules.World.Land
90 get { return m_scene.RegionInfo.RegionID; } 90 get { return m_scene.RegionInfo.RegionID; }
91 } 91 }
92 92
93 public Vector3 StartPoint 93 private Vector2 m_startPoint = Vector2.Zero;
94 private Vector2 m_endPoint = Vector2.Zero;
95 private Vector2 m_centerPoint = Vector2.Zero;
96
97 public Vector2 StartPoint
94 { 98 {
95 get 99 get
96 { 100 {
97 for (int y = 0; y < LandBitmap.GetLength(1); y++) 101 return m_startPoint;
98 {
99 for (int x = 0; x < LandBitmap.GetLength(0); x++)
100 {
101 if (LandBitmap[x, y])
102 return new Vector3(x * landUnit, y * landUnit, 0);
103 }
104 }
105
106 m_log.ErrorFormat("{0} StartPoint. No start point found. bitmapSize=<{1},{2}>",
107 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
108 return new Vector3(-1, -1, -1);
109 } 102 }
110 } 103 }
111 104
112 public Vector3 EndPoint 105 public Vector2 EndPoint
113 { 106 {
114 get 107 get
115 { 108 {
116 for (int y = LandBitmap.GetLength(1) - 1; y >= 0; y--) 109 return m_endPoint;
117 { 110 }
118 for (int x = LandBitmap.GetLength(0) - 1; x >= 0; x--) 111 }
119 {
120 if (LandBitmap[x, y])
121 {
122 return new Vector3(x * landUnit + landUnit, y * landUnit + landUnit, 0);
123 }
124 }
125 }
126 112
127 m_log.ErrorFormat("{0} EndPoint. No end point found. bitmapSize=<{1},{2}>", 113 //estimate a center point of a parcel
128 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1)); 114 public Vector2 CenterPoint
129 return new Vector3(-1, -1, -1); 115 {
116 get
117 {
118 return m_centerPoint;
130 } 119 }
131 } 120 }
132 121
@@ -789,6 +778,14 @@ namespace OpenSim.Region.CoreModules.World.Land
789 int max_y = Int32.MinValue; 778 int max_y = Int32.MinValue;
790 int tempArea = 0; 779 int tempArea = 0;
791 int x, y; 780 int x, y;
781
782 int lastX = 0;
783 int lastY = 0;
784 float avgx = 0f;
785 float avgy = 0f;
786
787 bool needStart = true;
788
792 for (x = 0; x < LandBitmap.GetLength(0); x++) 789 for (x = 0; x < LandBitmap.GetLength(0); x++)
793 { 790 {
794 for (y = 0; y < LandBitmap.GetLength(1); y++) 791 for (y = 0; y < LandBitmap.GetLength(1); y++)
@@ -803,10 +800,37 @@ namespace OpenSim.Region.CoreModules.World.Land
803 max_x = x; 800 max_x = x;
804 if (max_y < y) 801 if (max_y < y)
805 max_y = y; 802 max_y = y;
806 tempArea += landUnit * landUnit; //16sqm peice of land 803
804 if(needStart)
805 {
806 avgx = x;
807 avgy = y;
808 m_startPoint.X = x * landUnit;
809 m_startPoint.Y = y * landUnit;
810 needStart = false;
811 }
812 else
813 {
814 avgx = (avgx * tempArea + x) / (tempArea + 1);
815 avgy = (avgy * tempArea + y) / (tempArea + 1);
816 }
817
818 tempArea++;
819
820 lastX = x;
821 lastY = y;
807 } 822 }
808 } 823 }
809 } 824 }
825
826 int halfunit = landUnit/2;
827
828 m_centerPoint.X = avgx * landUnit + halfunit;
829 m_centerPoint.Y = avgy * landUnit + halfunit;
830
831 m_endPoint.X = lastX * landUnit + landUnit;
832 m_endPoint.Y = lastY * landUnit + landUnit;
833
810 int tx = min_x * landUnit; 834 int tx = min_x * landUnit;
811 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1)) 835 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
812 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1); 836 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
@@ -847,7 +871,7 @@ namespace OpenSim.Region.CoreModules.World.Land
847 = new Vector3( 871 = new Vector3(
848 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0); 872 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0);
849 873
850 LandData.Area = tempArea; 874 LandData.Area = tempArea * landUnit * landUnit;
851 } 875 }
852 876
853 #endregion 877 #endregion
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 4d2cdd9..1857fd8 100755
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -5827,7 +5827,7 @@ Environment.Exit(1);
5827 5827
5828 private Vector3 GetParcelCenterAtGround(ILandObject parcel) 5828 private Vector3 GetParcelCenterAtGround(ILandObject parcel)
5829 { 5829 {
5830 Vector2 center = GetParcelCenter(parcel); 5830 Vector2 center = parcel.CenterPoint;
5831 return GetPositionAtGround(center.X, center.Y); 5831 return GetPositionAtGround(center.X, center.Y);
5832 } 5832 }
5833 5833
@@ -5880,53 +5880,12 @@ Environment.Exit(1);
5880 5880
5881 private Vector2 GetParcelSafeCorner(ILandObject parcel) 5881 private Vector2 GetParcelSafeCorner(ILandObject parcel)
5882 { 5882 {
5883 Vector3 start = parcel.StartPoint; 5883 return parcel.StartPoint;
5884 float x = start.X + 2.0f;
5885 float y = start.Y + 2.0f;
5886 return new Vector2(x, y);
5887 } 5884 }
5888 5885
5889 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y) 5886 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y)
5890 { 5887 {
5891 return Vector2.Distance(new Vector2(x, y), GetParcelCenter(parcel)); 5888 return Vector2.Distance(new Vector2(x, y), parcel.CenterPoint);
5892 }
5893
5894 //calculate the average center point of a parcel
5895 private Vector2 GetParcelCenter(ILandObject parcel)
5896 {
5897 int count = 0;
5898 int avgx = 0;
5899 int avgy = 0;
5900 Vector3 start = parcel.StartPoint;
5901 Vector3 end = parcel.EndPoint;
5902 int startX = (int) start.X;
5903 int startY = (int) start.Y;
5904 int endX = (int) end.X;
5905 int endY = (int) end.Y;
5906
5907 for (int x = startX; x < endX; x += 4)
5908 {
5909 for (int y = startY; y < endY; y += 4)
5910 {
5911 //Just keep a running average as we check if all the points are inside or not
5912 if (parcel.ContainsPoint(x, y))
5913 {
5914 if (count == 0)
5915 {
5916 avgx = x;
5917 avgy = y;
5918 }
5919 else
5920 {
5921 avgx = (avgx * count + x) / (count + 1);
5922 avgy = (avgy * count + y) / (count + 1);
5923 }
5924 count += 1;
5925 }
5926 }
5927 }
5928
5929 return new Vector2(avgx, avgy);
5930 } 5889 }
5931 5890
5932 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar) 5891 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)