diff options
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs | 312 |
1 files changed, 156 insertions, 156 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs index e2df885..4f7d20c 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs | |||
@@ -1,157 +1,157 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Framework; | 28 | using OpenSim.Framework; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain |
32 | { | 32 | { |
33 | /// <summary> | 33 | /// <summary> |
34 | /// A new version of the old Channel class, simplified | 34 | /// A new version of the old Channel class, simplified |
35 | /// </summary> | 35 | /// </summary> |
36 | public class TerrainChannel : ITerrainChannel | 36 | public class TerrainChannel : ITerrainChannel |
37 | { | 37 | { |
38 | private readonly bool[,] taint; | 38 | private readonly bool[,] taint; |
39 | private double[,] map; | 39 | private double[,] map; |
40 | 40 | ||
41 | public TerrainChannel() | 41 | public TerrainChannel() |
42 | { | 42 | { |
43 | map = new double[Constants.RegionSize,Constants.RegionSize]; | 43 | map = new double[Constants.RegionSize,Constants.RegionSize]; |
44 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; | 44 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; |
45 | 45 | ||
46 | int x; | 46 | int x; |
47 | for (x = 0; x < Constants.RegionSize; x++) | 47 | for (x = 0; x < Constants.RegionSize; x++) |
48 | { | 48 | { |
49 | int y; | 49 | int y; |
50 | for (y = 0; y < Constants.RegionSize; y++) | 50 | for (y = 0; y < Constants.RegionSize; y++) |
51 | { | 51 | { |
52 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; | 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; | 53 | double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; |
54 | if (map[x, y] < spherFac) | 54 | if (map[x, y] < spherFac) |
55 | { | 55 | { |
56 | map[x, y] = spherFac; | 56 | map[x, y] = spherFac; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | public TerrainChannel(double[,] import) | 62 | public TerrainChannel(double[,] import) |
63 | { | 63 | { |
64 | map = import; | 64 | map = import; |
65 | taint = new bool[import.GetLength(0),import.GetLength(1)]; | 65 | taint = new bool[import.GetLength(0),import.GetLength(1)]; |
66 | } | 66 | } |
67 | 67 | ||
68 | public TerrainChannel(bool createMap) | 68 | public TerrainChannel(bool createMap) |
69 | { | 69 | { |
70 | if (createMap) | 70 | if (createMap) |
71 | { | 71 | { |
72 | map = new double[Constants.RegionSize,Constants.RegionSize]; | 72 | map = new double[Constants.RegionSize,Constants.RegionSize]; |
73 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; | 73 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | public TerrainChannel(int w, int h) | 77 | public TerrainChannel(int w, int h) |
78 | { | 78 | { |
79 | map = new double[w,h]; | 79 | map = new double[w,h]; |
80 | taint = new bool[w / 16,h / 16]; | 80 | taint = new bool[w / 16,h / 16]; |
81 | } | 81 | } |
82 | 82 | ||
83 | #region ITerrainChannel Members | 83 | #region ITerrainChannel Members |
84 | 84 | ||
85 | public int Width | 85 | public int Width |
86 | { | 86 | { |
87 | get { return map.GetLength(0); } | 87 | get { return map.GetLength(0); } |
88 | } | 88 | } |
89 | 89 | ||
90 | public int Height | 90 | public int Height |
91 | { | 91 | { |
92 | get { return map.GetLength(1); } | 92 | get { return map.GetLength(1); } |
93 | } | 93 | } |
94 | 94 | ||
95 | public ITerrainChannel MakeCopy() | 95 | public ITerrainChannel MakeCopy() |
96 | { | 96 | { |
97 | TerrainChannel copy = new TerrainChannel(false); | 97 | TerrainChannel copy = new TerrainChannel(false); |
98 | copy.map = (double[,]) map.Clone(); | 98 | copy.map = (double[,]) map.Clone(); |
99 | 99 | ||
100 | return copy; | 100 | return copy; |
101 | } | 101 | } |
102 | 102 | ||
103 | public float[] GetFloatsSerialised() | 103 | public float[] GetFloatsSerialised() |
104 | { | 104 | { |
105 | float[] heights = new float[Width * Height]; | 105 | float[] heights = new float[Width * Height]; |
106 | int i; | 106 | int i; |
107 | 107 | ||
108 | for (i = 0; i < Width * Height; i++) | 108 | for (i = 0; i < Width * Height; i++) |
109 | { | 109 | { |
110 | heights[i] = (float) map[i % Width, i / Width]; | 110 | heights[i] = (float) map[i % Width, i / Width]; |
111 | } | 111 | } |
112 | 112 | ||
113 | return heights; | 113 | return heights; |
114 | } | 114 | } |
115 | 115 | ||
116 | public double[,] GetDoubles() | 116 | public double[,] GetDoubles() |
117 | { | 117 | { |
118 | return map; | 118 | return map; |
119 | } | 119 | } |
120 | 120 | ||
121 | public double this[int x, int y] | 121 | public double this[int x, int y] |
122 | { | 122 | { |
123 | get { return map[x, y]; } | 123 | get { return map[x, y]; } |
124 | set | 124 | set |
125 | { | 125 | { |
126 | if (map[x, y] != value) | 126 | if (map[x, y] != value) |
127 | { | 127 | { |
128 | taint[x / 16, y / 16] = true; | 128 | taint[x / 16, y / 16] = true; |
129 | map[x, y] = value; | 129 | map[x, y] = value; |
130 | } | 130 | } |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | public bool Tainted(int x, int y) | 134 | public bool Tainted(int x, int y) |
135 | { | 135 | { |
136 | if (taint[x / 16, y / 16]) | 136 | if (taint[x / 16, y / 16]) |
137 | { | 137 | { |
138 | taint[x / 16, y / 16] = false; | 138 | taint[x / 16, y / 16] = false; |
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | else | 141 | else |
142 | { | 142 | { |
143 | return false; | 143 | return false; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | #endregion | 147 | #endregion |
148 | 148 | ||
149 | public TerrainChannel Copy() | 149 | public TerrainChannel Copy() |
150 | { | 150 | { |
151 | TerrainChannel copy = new TerrainChannel(false); | 151 | TerrainChannel copy = new TerrainChannel(false); |
152 | copy.map = (double[,]) map.Clone(); | 152 | copy.map = (double[,]) map.Clone(); |
153 | 153 | ||
154 | return copy; | 154 | return copy; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | } \ No newline at end of file | 157 | } \ No newline at end of file |