aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs290
1 files changed, 145 insertions, 145 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
index 36da77c..fb9e21e 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
@@ -1,146 +1,146 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.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 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds) 37 public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds)
38 { 38 {
39 SetDiff(); 39 SetDiff();
40 40
41 Channel water = new Channel(w, h); 41 Channel water = new Channel(w, h);
42 Channel sediment = new Channel(w, h); 42 Channel sediment = new Channel(w, h);
43 Channel terrain = this; 43 Channel terrain = this;
44 Channel waterFlow = new Channel(w, h); 44 Channel waterFlow = new Channel(w, h);
45 45
46 NeighbourSystem type = NeighbourSystem.Moore; 46 NeighbourSystem type = NeighbourSystem.Moore;
47 int NEIGHBOUR_ME = 4; 47 int NEIGHBOUR_ME = 4;
48 48
49 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 49 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
50 50
51 for (int i = 0; i < rounds; i++) 51 for (int i = 0; i < rounds; i++)
52 { 52 {
53 water += rain; 53 water += rain;
54 54
55 sediment = terrain * water; 55 sediment = terrain * water;
56 terrain -= sediment; 56 terrain -= sediment;
57 57
58 for (int x = 1; x < w - 1; x++) 58 for (int x = 1; x < w - 1; x++)
59 { 59 {
60 for (int y = 1; y < h - 1; y++) 60 for (int y = 1; y < h - 1; y++)
61 { 61 {
62 double[] heights = new double[NEIGHBOUR_MAX]; 62 double[] heights = new double[NEIGHBOUR_MAX];
63 double[] diffs = new double[NEIGHBOUR_MAX]; 63 double[] diffs = new double[NEIGHBOUR_MAX];
64 64
65 double heightCenter = map[x, y]; 65 double heightCenter = map[x, y];
66 66
67 for (int j = 0; j < NEIGHBOUR_MAX; j++) 67 for (int j = 0; j < NEIGHBOUR_MAX; j++)
68 { 68 {
69 if (j != NEIGHBOUR_ME) 69 if (j != NEIGHBOUR_ME)
70 { 70 {
71 int[] coords = Neighbours(type, j); 71 int[] coords = Neighbours(type, j);
72 coords[0] += x; 72 coords[0] += x;
73 coords[1] += y; 73 coords[1] += y;
74 74
75 heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + sediment.map[coords[0], coords[1]]; 75 heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + sediment.map[coords[0], coords[1]];
76 diffs[j] = heightCenter - heights[j]; 76 diffs[j] = heightCenter - heights[j];
77 } 77 }
78 } 78 }
79 79
80 double totalHeight = 0; 80 double totalHeight = 0;
81 double totalHeightDiff = 0; 81 double totalHeightDiff = 0;
82 int totalCellsCounted = 1; 82 int totalCellsCounted = 1;
83 83
84 for (int j = 0; j < NEIGHBOUR_MAX; j++) 84 for (int j = 0; j < NEIGHBOUR_MAX; j++)
85 { 85 {
86 if (j != NEIGHBOUR_ME) 86 if (j != NEIGHBOUR_ME)
87 { 87 {
88 if (diffs[j] > 0) 88 if (diffs[j] > 0)
89 { 89 {
90 totalHeight += heights[j]; 90 totalHeight += heights[j];
91 totalHeightDiff += diffs[j]; 91 totalHeightDiff += diffs[j];
92 totalCellsCounted++; 92 totalCellsCounted++;
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 if (totalCellsCounted == 1) 97 if (totalCellsCounted == 1)
98 continue; 98 continue;
99 99
100 double averageHeight = totalHeight / totalCellsCounted; 100 double averageHeight = totalHeight / totalCellsCounted;
101 double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight); 101 double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight);
102 102
103 // TODO: Check this. 103 // TODO: Check this.
104 waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount; 104 waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount;
105 105
106 double totalInverseDiff = waterAmount / totalHeightDiff; 106 double totalInverseDiff = waterAmount / totalHeightDiff;
107 107
108 for (int j = 0; j < NEIGHBOUR_MAX; j++) 108 for (int j = 0; j < NEIGHBOUR_MAX; j++)
109 { 109 {
110 if (j != NEIGHBOUR_ME) 110 if (j != NEIGHBOUR_ME)
111 { 111 {
112 int[] coords = Neighbours(type, j); 112 int[] coords = Neighbours(type, j);
113 coords[0] += x; 113 coords[0] += x;
114 coords[1] += y; 114 coords[1] += y;
115 115
116 if (diffs[j] > 0) 116 if (diffs[j] > 0)
117 { 117 {
118 waterFlow.SetWrap(coords[0], coords[1], waterFlow.map[coords[0], coords[1]] + diffs[j] * totalInverseDiff); 118 waterFlow.SetWrap(coords[0], coords[1], waterFlow.map[coords[0], coords[1]] + diffs[j] * totalInverseDiff);
119 } 119 }
120 } 120 }
121 } 121 }
122 } 122 }
123 } 123 }
124 124
125 water += waterFlow; 125 water += waterFlow;
126 waterFlow.Fill(0); 126 waterFlow.Fill(0);
127 127
128 water *= evaporation; 128 water *= evaporation;
129 129
130 for (int x = 0; x < w; x++) 130 for (int x = 0; x < w; x++)
131 { 131 {
132 for (int y = 0; y < h; y++) 132 for (int y = 0; y < h; y++)
133 { 133 {
134 double deposition = sediment.map[x, y] - water.map[x, y] * solubility; 134 double deposition = sediment.map[x, y] - water.map[x, y] * solubility;
135 if (deposition > 0) 135 if (deposition > 0)
136 { 136 {
137 sediment.map[x, y] -= deposition; 137 sediment.map[x, y] -= deposition;
138 terrain.map[x, y] += deposition; 138 terrain.map[x, y] += deposition;
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 } 143 }
144 } 144 }
145 } 145 }
146} \ No newline at end of file 146} \ No newline at end of file