diff options
author | Adam Frisby | 2008-03-14 13:37:39 +0000 |
---|---|---|
committer | Adam Frisby | 2008-03-14 13:37:39 +0000 |
commit | 53e8d91c06b3fc5cf61ba767930fa733a6efb232 (patch) | |
tree | 28db1d0e7e96c737da680bef72de527e2dacfb8f /OpenSim/Region/Environment | |
parent | * Added proper handling of llSetStatus(STATUS_PHYSICS,BOOL) (diff) | |
download | opensim-SC_OLD-53e8d91c06b3fc5cf61ba767930fa733a6efb232.zip opensim-SC_OLD-53e8d91c06b3fc5cf61ba767930fa733a6efb232.tar.gz opensim-SC_OLD-53e8d91c06b3fc5cf61ba767930fa733a6efb232.tar.bz2 opensim-SC_OLD-53e8d91c06b3fc5cf61ba767930fa733a6efb232.tar.xz |
* Fixed 'flatten area' brush, so it now has a 'force' instead of instantly flattening the selected area.
* Noise, and Noise-Area brushes now use Perlin noise, more closely simulating the method LL uses officially.
* TerrainModule has been cleaned up slightly.
* TerrainUtil class has several new functions related to seeded noise generation.
* Extracted ITerrainEffect, ITerrainFloodEffect, ITerrainLoader, ITerrainPaintableEffect, TerrainChannel to seperate files.
Diffstat (limited to '')
10 files changed, 336 insertions, 213 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs index 4551f53..007d37e 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs | |||
@@ -58,12 +58,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes | |||
58 | 58 | ||
59 | avg = sum / steps; | 59 | avg = sum / steps; |
60 | 60 | ||
61 | double str = 0.1 * strength; // == 0.2 in the default client | ||
62 | |||
61 | for (x = 0; x < map.Width; x++) | 63 | for (x = 0; x < map.Width; x++) |
62 | { | 64 | { |
63 | for (y = 0; y < map.Height; y++) | 65 | for (y = 0; y < map.Height; y++) |
64 | { | 66 | { |
65 | if (fillArea[x, y] == true) | 67 | if (fillArea[x, y] == true) |
66 | map[x, y] = avg; | 68 | map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); |
67 | } | 69 | } |
68 | } | 70 | } |
69 | } | 71 | } |
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs index 6063b2f..95ad57d 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs | |||
@@ -31,65 +31,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes | |||
31 | { | 31 | { |
32 | public class NoiseArea : ITerrainFloodEffect | 32 | public class NoiseArea : ITerrainFloodEffect |
33 | { | 33 | { |
34 | private double Noise(int x, int y) | ||
35 | { | ||
36 | // TODO: Seed | ||
37 | int n = x + y * 57; | ||
38 | n = (n<<13) ^ n; | ||
39 | return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); | ||
40 | } | ||
41 | |||
42 | private double SmoothedNoise1(int x, int y) | ||
43 | { | ||
44 | double corners = (Noise(x - 1, y - 1) + Noise(x + 1, y - 1) + Noise(x - 1, y + 1) + Noise(x + 1, y + 1)) / 16; | ||
45 | double sides = (Noise(x - 1, y) + Noise(x + 1, y) + Noise(x, y - 1) + Noise(x, y + 1)) / 8; | ||
46 | double center = Noise(x, y) / 4; | ||
47 | return corners + sides + center; | ||
48 | } | ||
49 | |||
50 | private double Interpolate(double x, double y, double z) | ||
51 | { | ||
52 | return (x * (1.0 - z)) + (y * z); | ||
53 | } | ||
54 | |||
55 | private double InterpolatedNoise(double x, double y) | ||
56 | { | ||
57 | int integer_X = (int)(x); | ||
58 | double fractional_X = x - integer_X; | ||
59 | |||
60 | int integer_Y = (int)y; | ||
61 | double fractional_Y = y - integer_Y; | ||
62 | |||
63 | double v1 = SmoothedNoise1(integer_X, integer_Y); | ||
64 | double v2 = SmoothedNoise1(integer_X + 1, integer_Y); | ||
65 | double v3 = SmoothedNoise1(integer_X, integer_Y + 1); | ||
66 | double v4 = SmoothedNoise1(integer_X + 1, integer_Y + 1); | ||
67 | |||
68 | double i1 = Interpolate(v1, v2, fractional_X); | ||
69 | double i2 = Interpolate(v3, v4, fractional_X); | ||
70 | |||
71 | return Interpolate(i1, i2, fractional_Y); | ||
72 | } | ||
73 | |||
74 | private double PerlinNoise2D(double x, double y) | ||
75 | { | ||
76 | int octaves = 1; | ||
77 | double persistence = 0.0005; | ||
78 | |||
79 | double frequency = 0.0; | ||
80 | double amplitude = 0.0; | ||
81 | double total = 0.0; | ||
82 | |||
83 | for (int i = 0; i < octaves; i++) | ||
84 | { | ||
85 | frequency = System.Math.Pow(2, i); | ||
86 | amplitude = System.Math.Pow(persistence, i); | ||
87 | |||
88 | total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; | ||
89 | } | ||
90 | return total; | ||
91 | } | ||
92 | |||
93 | #region ITerrainFloodEffect Members | 34 | #region ITerrainFloodEffect Members |
94 | 35 | ||
95 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | 36 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) |
@@ -101,11 +42,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes | |||
101 | { | 42 | { |
102 | if (fillArea[x, y] == true) | 43 | if (fillArea[x, y] == true) |
103 | { | 44 | { |
104 | lock (OpenSim.Framework.Util.RandomClass) | 45 | double noise = TerrainUtil.PerlinNoise2D((double)x / (double)Framework.Constants.RegionSize, (double)y / (double)Framework.Constants.RegionSize, 8, 1.0); |
105 | { | 46 | |
106 | double noise = PerlinNoise2D(x, y);//OpenSim.Framework.Util.RandomClass.NextDouble(); | 47 | map[x, y] += noise * strength; |
107 | map[x, y] += (noise /*- 0.5*/) * strength; | ||
108 | } | ||
109 | } | 48 | } |
110 | } | 49 | } |
111 | } | 50 | } |
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs new file mode 100644 index 0000000..e7fcf68 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using OpenSim.Region.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.Terrain | ||
31 | { | ||
32 | public interface ITerrainEffect | ||
33 | { | ||
34 | void RunEffect(ITerrainChannel map, double strength); | ||
35 | } | ||
36 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs new file mode 100644 index 0000000..aabd19b --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using OpenSim.Region.Environment.Interfaces; | ||
29 | using System; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.Terrain | ||
32 | { | ||
33 | public interface ITerrainFloodEffect | ||
34 | { | ||
35 | void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); | ||
36 | } | ||
37 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs new file mode 100644 index 0000000..b67c8f2 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using OpenSim.Region.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.Terrain | ||
31 | { | ||
32 | public interface ITerrainLoader | ||
33 | { | ||
34 | ITerrainChannel LoadFile(string filename); | ||
35 | void SaveFile(string filename, ITerrainChannel map); | ||
36 | } | ||
37 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs new file mode 100644 index 0000000..cf1ea4e --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using OpenSim.Region.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.Terrain | ||
31 | { | ||
32 | public interface ITerrainPaintableEffect | ||
33 | { | ||
34 | void PaintEffect(ITerrainChannel map, double x, double y, double strength, double duration); | ||
35 | } | ||
36 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs index 4a03a17..9754a99 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs | |||
@@ -57,15 +57,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes | |||
57 | z *= z; | 57 | z *= z; |
58 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 58 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
59 | 59 | ||
60 | double noise; | 60 | double noise = TerrainUtil.PerlinNoise2D((double)x / (double)Framework.Constants.RegionSize, (double)y / (double)Framework.Constants.RegionSize, 8, 1.0); |
61 | |||
62 | lock (Util.RandomClass) | ||
63 | { | ||
64 | noise = Util.RandomClass.NextDouble(); | ||
65 | } | ||
66 | 61 | ||
67 | if (z > 0.0) | 62 | if (z > 0.0) |
68 | map[x, y] += (noise - 0.5) * z * duration; | 63 | map[x, y] += noise * z * duration; |
69 | } | 64 | } |
70 | } | 65 | } |
71 | } | 66 | } |
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs new file mode 100644 index 0000000..59937d1 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs | |||
@@ -0,0 +1,119 @@ | |||
1 | | ||
2 | using OpenSim.Framework; | ||
3 | using OpenSim.Region.Environment.Interfaces; | ||
4 | |||
5 | namespace OpenSim.Region.Environment.Modules.Terrain | ||
6 | { | ||
7 | |||
8 | /// <summary> | ||
9 | /// A new version of the old Channel class, simplified | ||
10 | /// </summary> | ||
11 | public class TerrainChannel : ITerrainChannel | ||
12 | { | ||
13 | private double[,] map; | ||
14 | private bool[,] taint; | ||
15 | |||
16 | public int Width | ||
17 | { | ||
18 | get { return map.GetLength(0); } | ||
19 | } | ||
20 | |||
21 | public int Height | ||
22 | { | ||
23 | get { return map.GetLength(1); } | ||
24 | } | ||
25 | |||
26 | public TerrainChannel Copy() | ||
27 | { | ||
28 | TerrainChannel copy = new TerrainChannel(false); | ||
29 | copy.map = (double[,])this.map.Clone(); | ||
30 | |||
31 | return copy; | ||
32 | } | ||
33 | |||
34 | public float[] GetFloatsSerialised() | ||
35 | { | ||
36 | float[] heights = new float[Width * Height]; | ||
37 | int i; | ||
38 | |||
39 | for (i = 0; i < Width * Height; i++) | ||
40 | { | ||
41 | heights[i] = (float)map[i % Width, i / Width]; | ||
42 | } | ||
43 | |||
44 | return heights; | ||
45 | } | ||
46 | |||
47 | public double[,] GetDoubles() | ||
48 | { | ||
49 | return map; | ||
50 | } | ||
51 | |||
52 | public double this[int x, int y] | ||
53 | { | ||
54 | get | ||
55 | { | ||
56 | return map[x, y]; | ||
57 | } | ||
58 | set | ||
59 | { | ||
60 | if (map[x, y] != value) | ||
61 | { | ||
62 | taint[x / 16, y / 16] = true; | ||
63 | map[x, y] = value; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public bool Tainted(int x, int y) | ||
69 | { | ||
70 | if (taint[x / 16, y / 16] != false) | ||
71 | { | ||
72 | taint[x / 16, y / 16] = false; | ||
73 | return true; | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | return false; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | public TerrainChannel() | ||
82 | { | ||
83 | map = new double[Constants.RegionSize, Constants.RegionSize]; | ||
84 | taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; | ||
85 | |||
86 | int x, y; | ||
87 | for (x = 0; x < Constants.RegionSize; x++) | ||
88 | { | ||
89 | for (y = 0; y < Constants.RegionSize; y++) | ||
90 | { | ||
91 | map[x, y] = 60.0 - // 60 = Sphere Radius | ||
92 | ((x - (Constants.RegionSize / 2)) * (x - (Constants.RegionSize / 2)) + | ||
93 | (y - (Constants.RegionSize / 2)) * (y - (Constants.RegionSize / 2))); | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public TerrainChannel(double[,] import) | ||
99 | { | ||
100 | map = import; | ||
101 | taint = new bool[import.GetLength(0), import.GetLength(1)]; | ||
102 | } | ||
103 | |||
104 | public TerrainChannel(bool createMap) | ||
105 | { | ||
106 | if (createMap) | ||
107 | { | ||
108 | map = new double[Constants.RegionSize, Constants.RegionSize]; | ||
109 | taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public TerrainChannel(int w, int h) | ||
114 | { | ||
115 | map = new double[w, h]; | ||
116 | taint = new bool[w / 16, h / 16]; | ||
117 | } | ||
118 | } | ||
119 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs index 83c6658..5931552 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs | |||
@@ -36,151 +36,18 @@ using OpenSim.Region.Environment.Scenes; | |||
36 | 36 | ||
37 | namespace OpenSim.Region.Environment.Modules.Terrain | 37 | namespace OpenSim.Region.Environment.Modules.Terrain |
38 | { | 38 | { |
39 | public interface ITerrainPaintableEffect | 39 | public class TerrainModule : IRegionModule |
40 | { | ||
41 | void PaintEffect(ITerrainChannel map, double x, double y, double strength, double duration); | ||
42 | } | ||
43 | |||
44 | public interface ITerrainFloodEffect | ||
45 | { | ||
46 | void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); | ||
47 | } | ||
48 | |||
49 | public interface ITerrainEffect | ||
50 | { | ||
51 | void RunEffect(ITerrainChannel map, double strength); | ||
52 | } | ||
53 | |||
54 | public interface ITerrainLoader | ||
55 | { | ||
56 | ITerrainChannel LoadFile(string filename); | ||
57 | void SaveFile(string filename, ITerrainChannel map); | ||
58 | } | ||
59 | |||
60 | /// <summary> | ||
61 | /// A new version of the old Channel class, simplified | ||
62 | /// </summary> | ||
63 | public class TerrainChannel : ITerrainChannel | ||
64 | { | 40 | { |
65 | private double[,] map; | 41 | public enum StandardTerrainEffects : byte |
66 | private bool[,] taint; | ||
67 | |||
68 | public int Width | ||
69 | { | ||
70 | get { return map.GetLength(0); } | ||
71 | } | ||
72 | |||
73 | public int Height | ||
74 | { | ||
75 | get { return map.GetLength(1); } | ||
76 | } | ||
77 | |||
78 | public TerrainChannel Copy() | ||
79 | { | ||
80 | TerrainChannel copy = new TerrainChannel(false); | ||
81 | copy.map = (double[,])this.map.Clone(); | ||
82 | |||
83 | return copy; | ||
84 | } | ||
85 | |||
86 | public float[] GetFloatsSerialised() | ||
87 | { | ||
88 | float[] heights = new float[Width * Height]; | ||
89 | int i; | ||
90 | |||
91 | for (i = 0; i < Width * Height; i++) | ||
92 | { | ||
93 | heights[i] = (float)map[i % Width, i / Width]; | ||
94 | } | ||
95 | |||
96 | return heights; | ||
97 | } | ||
98 | |||
99 | public double[,] GetDoubles() | ||
100 | { | ||
101 | return map; | ||
102 | } | ||
103 | |||
104 | public double this[int x, int y] | ||
105 | { | ||
106 | get | ||
107 | { | ||
108 | return map[x, y]; | ||
109 | } | ||
110 | set | ||
111 | { | ||
112 | if (map[x, y] != value) | ||
113 | { | ||
114 | taint[x / 16, y / 16] = true; | ||
115 | map[x, y] = value; | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public bool Tainted(int x, int y) | ||
121 | { | 42 | { |
122 | if (taint[x / 16, y / 16] != false) | 43 | Flatten = 0, |
123 | { | 44 | Raise = 1, |
124 | taint[x / 16, y / 16] = false; | 45 | Lower = 2, |
125 | return true; | 46 | Smooth = 3, |
126 | } | 47 | Noise = 4, |
127 | else | 48 | Revert = 5 |
128 | { | ||
129 | return false; | ||
130 | } | ||
131 | } | 49 | } |
132 | 50 | ||
133 | public TerrainChannel() | ||
134 | { | ||
135 | map = new double[Constants.RegionSize, Constants.RegionSize]; | ||
136 | taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; | ||
137 | |||
138 | int x, y; | ||
139 | for (x = 0; x < Constants.RegionSize; x++) | ||
140 | { | ||
141 | for (y = 0; y < Constants.RegionSize; y++) | ||
142 | { | ||
143 | map[x, y] = 60.0 - // 60 = Sphere Radius | ||
144 | ((x - (Constants.RegionSize / 2)) * (x - (Constants.RegionSize / 2)) + | ||
145 | (y - (Constants.RegionSize / 2)) * (y - (Constants.RegionSize / 2))); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | public TerrainChannel(double[,] import) | ||
151 | { | ||
152 | map = import; | ||
153 | taint = new bool[import.GetLength(0), import.GetLength(1)]; | ||
154 | } | ||
155 | |||
156 | public TerrainChannel(bool createMap) | ||
157 | { | ||
158 | if (createMap) | ||
159 | { | ||
160 | map = new double[Constants.RegionSize, Constants.RegionSize]; | ||
161 | taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | public TerrainChannel(int w, int h) | ||
166 | { | ||
167 | map = new double[w, h]; | ||
168 | taint = new bool[w / 16, h / 16]; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | public enum StandardTerrainEffects : byte | ||
173 | { | ||
174 | Flatten = 0, | ||
175 | Raise = 1, | ||
176 | Lower = 2, | ||
177 | Smooth = 3, | ||
178 | Noise = 4, | ||
179 | Revert = 5 | ||
180 | } | ||
181 | |||
182 | public class TerrainModule : IRegionModule | ||
183 | { | ||
184 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
185 | 52 | ||
186 | private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = | 53 | private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = |
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs index 23ab321..55265d9 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs | |||
@@ -47,5 +47,60 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
47 | double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); | 47 | double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); |
48 | return hi; | 48 | return hi; |
49 | } | 49 | } |
50 | |||
51 | private static double Noise(double x, double y) | ||
52 | { | ||
53 | int n = (int)x + (int)(y * 749); | ||
54 | n = (n << 13) ^ n; | ||
55 | return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); | ||
56 | } | ||
57 | |||
58 | private static double SmoothedNoise1(double x, double y) | ||
59 | { | ||
60 | double corners = (Noise(x - 1, y - 1) + Noise(x + 1, y - 1) + Noise(x - 1, y + 1) + Noise(x + 1, y + 1)) / 16; | ||
61 | double sides = (Noise(x - 1, y) + Noise(x + 1, y) + Noise(x, y - 1) + Noise(x, y + 1)) / 8; | ||
62 | double center = Noise(x, y) / 4; | ||
63 | return corners + sides + center; | ||
64 | } | ||
65 | |||
66 | private static double Interpolate(double x, double y, double z) | ||
67 | { | ||
68 | return (x * (1.0 - z)) + (y * z); | ||
69 | } | ||
70 | |||
71 | private static double InterpolatedNoise(double x, double y) | ||
72 | { | ||
73 | int integer_X = (int)(x); | ||
74 | double fractional_X = x - integer_X; | ||
75 | |||
76 | int integer_Y = (int)y; | ||
77 | double fractional_Y = y - integer_Y; | ||
78 | |||
79 | double v1 = SmoothedNoise1(integer_X, integer_Y); | ||
80 | double v2 = SmoothedNoise1(integer_X + 1, integer_Y); | ||
81 | double v3 = SmoothedNoise1(integer_X, integer_Y + 1); | ||
82 | double v4 = SmoothedNoise1(integer_X + 1, integer_Y + 1); | ||
83 | |||
84 | double i1 = Interpolate(v1, v2, fractional_X); | ||
85 | double i2 = Interpolate(v3, v4, fractional_X); | ||
86 | |||
87 | return Interpolate(i1, i2, fractional_Y); | ||
88 | } | ||
89 | |||
90 | public static double PerlinNoise2D(double x, double y, int octaves, double persistence) | ||
91 | { | ||
92 | double frequency = 0.0; | ||
93 | double amplitude = 0.0; | ||
94 | double total = 0.0; | ||
95 | |||
96 | for (int i = 0; i < octaves; i++) | ||
97 | { | ||
98 | frequency = System.Math.Pow(2, i); | ||
99 | amplitude = System.Math.Pow(persistence, i); | ||
100 | |||
101 | total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; | ||
102 | } | ||
103 | return total; | ||
104 | } | ||
50 | } | 105 | } |
51 | } | 106 | } |