aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs110
1 files changed, 56 insertions, 54 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
index 01f6bdf..1344715 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
@@ -35,34 +35,70 @@ namespace OpenSim.Region.Environment.Modules.Terrain
35 /// </summary> 35 /// </summary>
36 public class TerrainChannel : ITerrainChannel 36 public class TerrainChannel : ITerrainChannel
37 { 37 {
38 private readonly bool[,] taint;
38 private double[,] map; 39 private double[,] map;
39 private bool[,] taint;
40 40
41 public int Width 41 public TerrainChannel()
42 { 42 {
43 get { return map.GetLength(0); } 43 map = new double[Constants.RegionSize,Constants.RegionSize];
44 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16];
45
46 int x;
47 for (x = 0; x < Constants.RegionSize; x++)
48 {
49 int y;
50 for (y = 0; y < Constants.RegionSize; y++)
51 {
52 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
53 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01;
54 if (map[x, y] < spherFac)
55 {
56 map[x, y] = spherFac;
57 }
58 }
59 }
44 } 60 }
45 61
46 public int Height 62 public TerrainChannel(double[,] import)
47 { 63 {
48 get { return map.GetLength(1); } 64 map = import;
65 taint = new bool[import.GetLength(0),import.GetLength(1)];
49 } 66 }
50 67
51 public TerrainChannel Copy() 68 public TerrainChannel(bool createMap)
52 { 69 {
53 TerrainChannel copy = new TerrainChannel(false); 70 if (createMap)
54 copy.map = (double[,])this.map.Clone(); 71 {
72 map = new double[Constants.RegionSize,Constants.RegionSize];
73 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16];
74 }
75 }
55 76
56 return copy; 77 public TerrainChannel(int w, int h)
78 {
79 map = new double[w,h];
80 taint = new bool[w / 16,h / 16];
81 }
82
83 #region ITerrainChannel Members
84
85 public int Width
86 {
87 get { return map.GetLength(0); }
88 }
89
90 public int Height
91 {
92 get { return map.GetLength(1); }
57 } 93 }
58 94
59 public ITerrainChannel MakeCopy() 95 public ITerrainChannel MakeCopy()
60 { 96 {
61 TerrainChannel copy = new TerrainChannel(false); 97 TerrainChannel copy = new TerrainChannel(false);
62 copy.map = (double[,])this.map.Clone(); 98 copy.map = (double[,]) map.Clone();
63 99
64 return copy; 100 return copy;
65 } 101 }
66 102
67 public float[] GetFloatsSerialised() 103 public float[] GetFloatsSerialised()
68 { 104 {
@@ -71,7 +107,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
71 107
72 for (i = 0; i < Width * Height; i++) 108 for (i = 0; i < Width * Height; i++)
73 { 109 {
74 heights[i] = (float)map[i % Width, i / Width]; 110 heights[i] = (float) map[i % Width, i / Width];
75 } 111 }
76 112
77 return heights; 113 return heights;
@@ -84,10 +120,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
84 120
85 public double this[int x, int y] 121 public double this[int x, int y]
86 { 122 {
87 get 123 get { return map[x, y]; }
88 {
89 return map[x, y];
90 }
91 set 124 set
92 { 125 {
93 if (map[x, y] != value) 126 if (map[x, y] != value)
@@ -100,7 +133,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
100 133
101 public bool Tainted(int x, int y) 134 public bool Tainted(int x, int y)
102 { 135 {
103 if (taint[x / 16, y / 16] != false) 136 if (taint[x / 16, y / 16])
104 { 137 {
105 taint[x / 16, y / 16] = false; 138 taint[x / 16, y / 16] = false;
106 return true; 139 return true;
@@ -111,45 +144,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
111 } 144 }
112 } 145 }
113 146
114 public TerrainChannel() 147 #endregion
115 {
116 map = new double[Constants.RegionSize, Constants.RegionSize];
117 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16];
118 148
119 int x, y; 149 public TerrainChannel Copy()
120 for (x = 0; x < Constants.RegionSize; x++)
121 {
122 for (y = 0; y < Constants.RegionSize; y++)
123 {
124 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
125 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01;
126 if (map[x, y] < spherFac)
127 {
128 map[x, y] = spherFac;
129 }
130 }
131 }
132 }
133
134 public TerrainChannel(double[,] import)
135 {
136 map = import;
137 taint = new bool[import.GetLength(0), import.GetLength(1)];
138 }
139
140 public TerrainChannel(bool createMap)
141 { 150 {
142 if (createMap) 151 TerrainChannel copy = new TerrainChannel(false);
143 { 152 copy.map = (double[,]) map.Clone();
144 map = new double[Constants.RegionSize, Constants.RegionSize];
145 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16];
146 }
147 }
148 153
149 public TerrainChannel(int w, int h) 154 return copy;
150 {
151 map = new double[w, h];
152 taint = new bool[w / 16, h / 16];
153 } 155 }
154 } 156 }
155} 157} \ No newline at end of file