aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMW2007-07-25 18:19:38 +0000
committerMW2007-07-25 18:19:38 +0000
commit2b42ea0a429c722bd7c5c67d3815c2ddc8399e78 (patch)
tree0a6338ff52efbdaadaa9a307bee618867460cfb6
parent* Terrain now uses the older slower method again until the fast version can b... (diff)
downloadopensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.zip
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.gz
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.bz2
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.xz
Start of the OpenSim library , for now only contains a few textures.
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs1122
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs162
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactions.cs548
-rw-r--r--OpenSim/Framework/Communications/Cache/CachedUserInfo.cs188
-rw-r--r--OpenSim/Framework/Communications/Cache/InventoryFolder.cs218
-rw-r--r--OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs89
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCache.cs386
-rw-r--r--OpenSim/Framework/Communications/CommunicationsManager.cs25
-rw-r--r--OpenSim/Framework/Data/InventoryData.cs2
-rw-r--r--OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs2
-rw-r--r--OpenSim/Framework/UserManager/LoginResponse.cs32
-rw-r--r--OpenSim/Framework/UserManager/UserManagerBase.cs34
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs8
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs148
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs132
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs554
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs296
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs276
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs154
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs288
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs130
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs566
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs112
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs310
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs428
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs146
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs700
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs424
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs290
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs612
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs224
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs282
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs486
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs98
35 files changed, 4839 insertions, 4635 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 3d0fd76..a3480ec 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -1,561 +1,561 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.Reflection; 32using System.Reflection;
33using System.Threading; 33using System.Threading;
34using libsecondlife; 34using libsecondlife;
35using libsecondlife.Packets; 35using libsecondlife.Packets;
36using OpenSim.Framework.Interfaces; 36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Servers; 37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Types; 38using OpenSim.Framework.Types;
39using OpenSim.Framework.Utilities; 39using OpenSim.Framework.Utilities;
40 40
41namespace OpenSim.Framework.Communications.Caches 41namespace OpenSim.Framework.Communications.Caches
42{ 42{
43 public delegate void DownloadComplete(AssetCache.TextureSender sender); 43 public delegate void DownloadComplete(AssetCache.TextureSender sender);
44 44
45 public class AssetCache : IAssetReceiver 45 public class AssetCache : IAssetReceiver
46 { 46 {
47 // Fields 47 // Fields
48 private Thread _assetCacheThread; 48 private Thread _assetCacheThread;
49 private IAssetServer _assetServer; 49 private IAssetServer _assetServer;
50 public List<AssetRequest> AssetRequests; 50 public List<AssetRequest> AssetRequests;
51 public Dictionary<LLUUID, AssetInfo> Assets; 51 public Dictionary<LLUUID, AssetInfo> Assets;
52 public Dictionary<LLUUID, AssetRequest> RequestedAssets; 52 public Dictionary<LLUUID, AssetRequest> RequestedAssets;
53 public Dictionary<LLUUID, AssetRequest> RequestedTextures; 53 public Dictionary<LLUUID, AssetRequest> RequestedTextures;
54 public Dictionary<LLUUID, TextureSender> SendingTextures; 54 public Dictionary<LLUUID, TextureSender> SendingTextures;
55 private LLUUID[] textureList; 55 private LLUUID[] textureList;
56 public List<AssetRequest> TextureRequests; 56 public List<AssetRequest> TextureRequests;
57 public Dictionary<LLUUID, TextureImage> Textures; 57 public Dictionary<LLUUID, TextureImage> Textures;
58 58
59 // Methods 59 // Methods
60 public AssetCache(IAssetServer assetServer) 60 public AssetCache(IAssetServer assetServer)
61 { 61 {
62 this.AssetRequests = new List<AssetRequest>(); 62 this.AssetRequests = new List<AssetRequest>();
63 this.TextureRequests = new List<AssetRequest>(); 63 this.TextureRequests = new List<AssetRequest>();
64 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); 64 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
65 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); 65 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
66 this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); 66 this.SendingTextures = new Dictionary<LLUUID, TextureSender>();
67 this.textureList = new LLUUID[5]; 67 this.textureList = new LLUUID[5];
68 Console.WriteLine("Creating Asset cache"); 68 Console.WriteLine("Creating Asset cache");
69 this._assetServer = assetServer; 69 this._assetServer = assetServer;
70 this._assetServer.SetReceiver(this); 70 this._assetServer.SetReceiver(this);
71 this.Assets = new Dictionary<LLUUID, AssetInfo>(); 71 this.Assets = new Dictionary<LLUUID, AssetInfo>();
72 this.Textures = new Dictionary<LLUUID, TextureImage>(); 72 this.Textures = new Dictionary<LLUUID, TextureImage>();
73 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); 73 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager));
74 this._assetCacheThread.IsBackground = true; 74 this._assetCacheThread.IsBackground = true;
75 this._assetCacheThread.Start(); 75 this._assetCacheThread.Start();
76 } 76 }
77 77
78 public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey) 78 public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey)
79 { 79 {
80 this.AssetRequests = new List<AssetRequest>(); 80 this.AssetRequests = new List<AssetRequest>();
81 this.TextureRequests = new List<AssetRequest>(); 81 this.TextureRequests = new List<AssetRequest>();
82 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); 82 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
83 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); 83 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
84 this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); 84 this.SendingTextures = new Dictionary<LLUUID, TextureSender>();
85 this.textureList = new LLUUID[5]; 85 this.textureList = new LLUUID[5];
86 Console.WriteLine("Creating Asset cache"); 86 Console.WriteLine("Creating Asset cache");
87 this._assetServer = this.LoadAssetDll(assetServerDLLName); 87 this._assetServer = this.LoadAssetDll(assetServerDLLName);
88 this._assetServer.SetServerInfo(assetServerURL, assetServerKey); 88 this._assetServer.SetServerInfo(assetServerURL, assetServerKey);
89 this._assetServer.SetReceiver(this); 89 this._assetServer.SetReceiver(this);
90 this.Assets = new Dictionary<LLUUID, AssetInfo>(); 90 this.Assets = new Dictionary<LLUUID, AssetInfo>();
91 this.Textures = new Dictionary<LLUUID, TextureImage>(); 91 this.Textures = new Dictionary<LLUUID, TextureImage>();
92 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); 92 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager));
93 this._assetCacheThread.IsBackground = true; 93 this._assetCacheThread.IsBackground = true;
94 this._assetCacheThread.Start(); 94 this._assetCacheThread.Start();
95 } 95 }
96 96
97 public void AddAsset(AssetBase asset) 97 public void AddAsset(AssetBase asset)
98 { 98 {
99 if (asset.Type == 0) 99 if (asset.Type == 0)
100 { 100 {
101 if (!this.Textures.ContainsKey(asset.FullID)) 101 if (!this.Textures.ContainsKey(asset.FullID))
102 { 102 {
103 TextureImage image = new TextureImage(asset); 103 TextureImage image = new TextureImage(asset);
104 this.Textures.Add(image.FullID, image); 104 this.Textures.Add(image.FullID, image);
105 this._assetServer.UploadNewAsset(asset); 105 this._assetServer.UploadNewAsset(asset);
106 } 106 }
107 } 107 }
108 else if (!this.Assets.ContainsKey(asset.FullID)) 108 else if (!this.Assets.ContainsKey(asset.FullID))
109 { 109 {
110 AssetInfo info = new AssetInfo(asset); 110 AssetInfo info = new AssetInfo(asset);
111 this.Assets.Add(info.FullID, info); 111 this.Assets.Add(info.FullID, info);
112 this._assetServer.UploadNewAsset(asset); 112 this._assetServer.UploadNewAsset(asset);
113 } 113 }
114 } 114 }
115 115
116 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest) 116 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
117 { 117 {
118 LLUUID assetID = new LLUUID(transferRequest.TransferInfo.Params, 0); 118 LLUUID assetID = new LLUUID(transferRequest.TransferInfo.Params, 0);
119 if (!this.Assets.ContainsKey(assetID)) 119 if (!this.Assets.ContainsKey(assetID))
120 { 120 {
121 if (!this.RequestedAssets.ContainsKey(assetID)) 121 if (!this.RequestedAssets.ContainsKey(assetID))
122 { 122 {
123 AssetRequest request = new AssetRequest(); 123 AssetRequest request = new AssetRequest();
124 request.RequestUser = userInfo; 124 request.RequestUser = userInfo;
125 request.RequestAssetID = assetID; 125 request.RequestAssetID = assetID;
126 request.TransferRequestID = transferRequest.TransferInfo.TransferID; 126 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
127 this.RequestedAssets.Add(assetID, request); 127 this.RequestedAssets.Add(assetID, request);
128 this._assetServer.RequestAsset(assetID, false); 128 this._assetServer.RequestAsset(assetID, false);
129 } 129 }
130 } 130 }
131 else 131 else
132 { 132 {
133 AssetInfo info = this.Assets[assetID]; 133 AssetInfo info = this.Assets[assetID];
134 AssetRequest request2 = new AssetRequest(); 134 AssetRequest request2 = new AssetRequest();
135 request2.RequestUser = userInfo; 135 request2.RequestUser = userInfo;
136 request2.RequestAssetID = assetID; 136 request2.RequestAssetID = assetID;
137 request2.TransferRequestID = transferRequest.TransferInfo.TransferID; 137 request2.TransferRequestID = transferRequest.TransferInfo.TransferID;
138 request2.AssetInf = info; 138 request2.AssetInf = info;
139 if (info.Data.LongLength > 600) 139 if (info.Data.LongLength > 600)
140 { 140 {
141 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); 141 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8);
142 } 142 }
143 else 143 else
144 { 144 {
145 request2.NumPackets = 1; 145 request2.NumPackets = 1;
146 } 146 }
147 this.AssetRequests.Add(request2); 147 this.AssetRequests.Add(request2);
148 } 148 }
149 } 149 }
150 150
151 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID) 151 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID)
152 { 152 {
153 if (!this.Textures.ContainsKey(imageID)) 153 if (!this.Textures.ContainsKey(imageID))
154 { 154 {
155 if (!this.RequestedTextures.ContainsKey(imageID)) 155 if (!this.RequestedTextures.ContainsKey(imageID))
156 { 156 {
157 AssetRequest request = new AssetRequest(); 157 AssetRequest request = new AssetRequest();
158 request.RequestUser = userInfo; 158 request.RequestUser = userInfo;
159 request.RequestAssetID = imageID; 159 request.RequestAssetID = imageID;
160 request.IsTextureRequest = true; 160 request.IsTextureRequest = true;
161 this.RequestedTextures.Add(imageID, request); 161 this.RequestedTextures.Add(imageID, request);
162 this._assetServer.RequestAsset(imageID, true); 162 this._assetServer.RequestAsset(imageID, true);
163 } 163 }
164 } 164 }
165 else 165 else
166 { 166 {
167 TextureImage image = this.Textures[imageID]; 167 TextureImage image = this.Textures[imageID];
168 AssetRequest request2 = new AssetRequest(); 168 AssetRequest request2 = new AssetRequest();
169 request2.RequestUser = userInfo; 169 request2.RequestUser = userInfo;
170 request2.RequestAssetID = imageID; 170 request2.RequestAssetID = imageID;
171 request2.IsTextureRequest = true; 171 request2.IsTextureRequest = true;
172 request2.ImageInfo = image; 172 request2.ImageInfo = image;
173 if (image.Data.LongLength > 600) 173 if (image.Data.LongLength > 600)
174 { 174 {
175 request2.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); 175 request2.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8);
176 } 176 }
177 else 177 else
178 { 178 {
179 request2.NumPackets = 1; 179 request2.NumPackets = 1;
180 } 180 }
181 this.TextureRequests.Add(request2); 181 this.TextureRequests.Add(request2);
182 } 182 }
183 } 183 }
184 184
185 public void AssetNotFound(AssetBase asset) 185 public void AssetNotFound(AssetBase asset)
186 { 186 {
187 } 187 }
188 188
189 public void AssetReceived(AssetBase asset, bool IsTexture) 189 public void AssetReceived(AssetBase asset, bool IsTexture)
190 { 190 {
191 if (asset.FullID != LLUUID.Zero) 191 if (asset.FullID != LLUUID.Zero)
192 { 192 {
193 if (IsTexture) 193 if (IsTexture)
194 { 194 {
195 TextureImage image = new TextureImage(asset); 195 TextureImage image = new TextureImage(asset);
196 this.Textures.Add(image.FullID, image); 196 this.Textures.Add(image.FullID, image);
197 if (this.RequestedTextures.ContainsKey(image.FullID)) 197 if (this.RequestedTextures.ContainsKey(image.FullID))
198 { 198 {
199 AssetRequest request = this.RequestedTextures[image.FullID]; 199 AssetRequest request = this.RequestedTextures[image.FullID];
200 request.ImageInfo = image; 200 request.ImageInfo = image;
201 if (image.Data.LongLength > 600) 201 if (image.Data.LongLength > 600)
202 { 202 {
203 request.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); 203 request.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8);
204 } 204 }
205 else 205 else
206 { 206 {
207 request.NumPackets = 1; 207 request.NumPackets = 1;
208 } 208 }
209 this.RequestedTextures.Remove(image.FullID); 209 this.RequestedTextures.Remove(image.FullID);
210 this.TextureRequests.Add(request); 210 this.TextureRequests.Add(request);
211 } 211 }
212 } 212 }
213 else 213 else
214 { 214 {
215 AssetInfo info = new AssetInfo(asset); 215 AssetInfo info = new AssetInfo(asset);
216 this.Assets.Add(info.FullID, info); 216 this.Assets.Add(info.FullID, info);
217 if (this.RequestedAssets.ContainsKey(info.FullID)) 217 if (this.RequestedAssets.ContainsKey(info.FullID))
218 { 218 {
219 AssetRequest request2 = this.RequestedAssets[info.FullID]; 219 AssetRequest request2 = this.RequestedAssets[info.FullID];
220 request2.AssetInf = info; 220 request2.AssetInf = info;
221 if (info.Data.LongLength > 600) 221 if (info.Data.LongLength > 600)
222 { 222 {
223 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); 223 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8);
224 } 224 }
225 else 225 else
226 { 226 {
227 request2.NumPackets = 1; 227 request2.NumPackets = 1;
228 } 228 }
229 this.RequestedAssets.Remove(info.FullID); 229 this.RequestedAssets.Remove(info.FullID);
230 this.AssetRequests.Add(request2); 230 this.AssetRequests.Add(request2);
231 } 231 }
232 } 232 }
233 } 233 }
234 } 234 }
235 235
236 public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) 236 public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset)
237 { 237 {
238 AssetInfo info = new AssetInfo(); 238 AssetInfo info = new AssetInfo();
239 info.Data = new byte[sourceAsset.Data.Length]; 239 info.Data = new byte[sourceAsset.Data.Length];
240 Array.Copy(sourceAsset.Data, info.Data, sourceAsset.Data.Length); 240 Array.Copy(sourceAsset.Data, info.Data, sourceAsset.Data.Length);
241 info.FullID = LLUUID.Random(); 241 info.FullID = LLUUID.Random();
242 info.Type = sourceAsset.Type; 242 info.Type = sourceAsset.Type;
243 info.InvType = sourceAsset.InvType; 243 info.InvType = sourceAsset.InvType;
244 return info; 244 return info;
245 } 245 }
246 246
247 public TextureImage CloneImage(LLUUID newOwner, TextureImage source) 247 public TextureImage CloneImage(LLUUID newOwner, TextureImage source)
248 { 248 {
249 TextureImage image = new TextureImage(); 249 TextureImage image = new TextureImage();
250 image.Data = new byte[source.Data.Length]; 250 image.Data = new byte[source.Data.Length];
251 Array.Copy(source.Data, image.Data, source.Data.Length); 251 Array.Copy(source.Data, image.Data, source.Data.Length);
252 image.FullID = LLUUID.Random(); 252 image.FullID = LLUUID.Random();
253 image.Name = source.Name; 253 image.Name = source.Name;
254 return image; 254 return image;
255 } 255 }
256 256
257 public AssetBase[] CreateNewInventorySet(LLUUID agentID) 257 public AssetBase[] CreateNewInventorySet(LLUUID agentID)
258 { 258 {
259 AssetBase[] baseArray = new AssetBase[this.textureList.Length]; 259 AssetBase[] baseArray = new AssetBase[this.textureList.Length];
260 for (int i = 0; i < this.textureList.Length; i++) 260 for (int i = 0; i < this.textureList.Length; i++)
261 { 261 {
262 if (this.Textures.ContainsKey(this.textureList[i])) 262 if (this.Textures.ContainsKey(this.textureList[i]))
263 { 263 {
264 baseArray[i] = this.CloneImage(agentID, this.Textures[this.textureList[i]]); 264 baseArray[i] = this.CloneImage(agentID, this.Textures[this.textureList[i]]);
265 TextureImage asset = new TextureImage(baseArray[i]); 265 TextureImage asset = new TextureImage(baseArray[i]);
266 this.Textures.Add(asset.FullID, asset); 266 this.Textures.Add(asset.FullID, asset);
267 this._assetServer.UploadNewAsset(asset); 267 this._assetServer.UploadNewAsset(asset);
268 } 268 }
269 } 269 }
270 return baseArray; 270 return baseArray;
271 } 271 }
272 272
273 public AssetBase GetAsset(LLUUID assetID) 273 public AssetBase GetAsset(LLUUID assetID)
274 { 274 {
275 AssetBase base2 = null; 275 AssetBase base2 = null;
276 if (this.Textures.ContainsKey(assetID)) 276 if (this.Textures.ContainsKey(assetID))
277 { 277 {
278 return this.Textures[assetID]; 278 return this.Textures[assetID];
279 } 279 }
280 if (this.Assets.ContainsKey(assetID)) 280 if (this.Assets.ContainsKey(assetID))
281 { 281 {
282 base2 = this.Assets[assetID]; 282 base2 = this.Assets[assetID];
283 } 283 }
284 return base2; 284 return base2;
285 } 285 }
286 286
287 private IAssetServer LoadAssetDll(string dllName) 287 private IAssetServer LoadAssetDll(string dllName)
288 { 288 {
289 Assembly assembly = Assembly.LoadFrom(dllName); 289 Assembly assembly = Assembly.LoadFrom(dllName);
290 IAssetServer assetServer = null; 290 IAssetServer assetServer = null;
291 foreach (Type type in assembly.GetTypes()) 291 foreach (Type type in assembly.GetTypes())
292 { 292 {
293 if (type.IsPublic && !type.IsAbstract) 293 if (type.IsPublic && !type.IsAbstract)
294 { 294 {
295 if (type.GetInterface("IAssetPlugin", true) != null) 295 if (type.GetInterface("IAssetPlugin", true) != null)
296 { 296 {
297 assetServer = ((IAssetPlugin)Activator.CreateInstance(assembly.GetType(type.ToString()))).GetAssetServer(); 297 assetServer = ((IAssetPlugin)Activator.CreateInstance(assembly.GetType(type.ToString()))).GetAssetServer();
298 break; 298 break;
299 } 299 }
300 } 300 }
301 } 301 }
302 assembly = null; 302 assembly = null;
303 return assetServer; 303 return assetServer;
304 } 304 }
305 305
306 public void LoadDefaultTextureSet() 306 public void LoadDefaultTextureSet()
307 { 307 {
308 this.textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001"); 308 this.textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001");
309 this.textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002"); 309 this.textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002");
310 this.textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003"); 310 this.textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003");
311 this.textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004"); 311 this.textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004");
312 this.textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005"); 312 this.textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005");
313 for (int i = 0; i < this.textureList.Length; i++) 313 for (int i = 0; i < this.textureList.Length; i++)
314 { 314 {
315 this._assetServer.RequestAsset(this.textureList[i], true); 315 this._assetServer.RequestAsset(this.textureList[i], true);
316 } 316 }
317 } 317 }
318 318
319 private void ProcessAssetQueue() 319 private void ProcessAssetQueue()
320 { 320 {
321 if (this.AssetRequests.Count != 0) 321 if (this.AssetRequests.Count != 0)
322 { 322 {
323 int num; 323 int num;
324 if (this.AssetRequests.Count < 5) 324 if (this.AssetRequests.Count < 5)
325 { 325 {
326 num = this.AssetRequests.Count; 326 num = this.AssetRequests.Count;
327 } 327 }
328 else 328 else
329 { 329 {
330 num = 5; 330 num = 5;
331 } 331 }
332 for (int i = 0; i < num; i++) 332 for (int i = 0; i < num; i++)
333 { 333 {
334 AssetRequest request = this.AssetRequests[i]; 334 AssetRequest request = this.AssetRequests[i];
335 TransferInfoPacket newPack = new TransferInfoPacket(); 335 TransferInfoPacket newPack = new TransferInfoPacket();
336 newPack.TransferInfo.ChannelType = 2; 336 newPack.TransferInfo.ChannelType = 2;
337 newPack.TransferInfo.Status = 0; 337 newPack.TransferInfo.Status = 0;
338 newPack.TransferInfo.TargetType = 0; 338 newPack.TransferInfo.TargetType = 0;
339 newPack.TransferInfo.Params = request.RequestAssetID.GetBytes(); 339 newPack.TransferInfo.Params = request.RequestAssetID.GetBytes();
340 newPack.TransferInfo.Size = request.AssetInf.Data.Length; 340 newPack.TransferInfo.Size = request.AssetInf.Data.Length;
341 newPack.TransferInfo.TransferID = request.TransferRequestID; 341 newPack.TransferInfo.TransferID = request.TransferRequestID;
342 request.RequestUser.OutPacket(newPack); 342 request.RequestUser.OutPacket(newPack);
343 if (request.NumPackets == 1) 343 if (request.NumPackets == 1)
344 { 344 {
345 TransferPacketPacket packet2 = new TransferPacketPacket(); 345 TransferPacketPacket packet2 = new TransferPacketPacket();
346 packet2.TransferData.Packet = 0; 346 packet2.TransferData.Packet = 0;
347 packet2.TransferData.ChannelType = 2; 347 packet2.TransferData.ChannelType = 2;
348 packet2.TransferData.TransferID = request.TransferRequestID; 348 packet2.TransferData.TransferID = request.TransferRequestID;
349 packet2.TransferData.Data = request.AssetInf.Data; 349 packet2.TransferData.Data = request.AssetInf.Data;
350 packet2.TransferData.Status = 1; 350 packet2.TransferData.Status = 1;
351 request.RequestUser.OutPacket(packet2); 351 request.RequestUser.OutPacket(packet2);
352 } 352 }
353 else 353 else
354 { 354 {
355 TransferPacketPacket packet3 = new TransferPacketPacket(); 355 TransferPacketPacket packet3 = new TransferPacketPacket();
356 packet3.TransferData.Packet = 0; 356 packet3.TransferData.Packet = 0;
357 packet3.TransferData.ChannelType = 2; 357 packet3.TransferData.ChannelType = 2;
358 packet3.TransferData.TransferID = request.TransferRequestID; 358 packet3.TransferData.TransferID = request.TransferRequestID;
359 byte[] destinationArray = new byte[0x3e8]; 359 byte[] destinationArray = new byte[0x3e8];
360 Array.Copy(request.AssetInf.Data, destinationArray, 0x3e8); 360 Array.Copy(request.AssetInf.Data, destinationArray, 0x3e8);
361 packet3.TransferData.Data = destinationArray; 361 packet3.TransferData.Data = destinationArray;
362 packet3.TransferData.Status = 0; 362 packet3.TransferData.Status = 0;
363 request.RequestUser.OutPacket(packet3); 363 request.RequestUser.OutPacket(packet3);
364 packet3 = new TransferPacketPacket(); 364 packet3 = new TransferPacketPacket();
365 packet3.TransferData.Packet = 1; 365 packet3.TransferData.Packet = 1;
366 packet3.TransferData.ChannelType = 2; 366 packet3.TransferData.ChannelType = 2;
367 packet3.TransferData.TransferID = request.TransferRequestID; 367 packet3.TransferData.TransferID = request.TransferRequestID;
368 byte[] buffer2 = new byte[request.AssetInf.Data.Length - 0x3e8]; 368 byte[] buffer2 = new byte[request.AssetInf.Data.Length - 0x3e8];
369 Array.Copy(request.AssetInf.Data, 0x3e8, buffer2, 0, buffer2.Length); 369 Array.Copy(request.AssetInf.Data, 0x3e8, buffer2, 0, buffer2.Length);
370 packet3.TransferData.Data = buffer2; 370 packet3.TransferData.Data = buffer2;
371 packet3.TransferData.Status = 1; 371 packet3.TransferData.Status = 1;
372 request.RequestUser.OutPacket(packet3); 372 request.RequestUser.OutPacket(packet3);
373 } 373 }
374 } 374 }
375 for (int j = 0; j < num; j++) 375 for (int j = 0; j < num; j++)
376 { 376 {
377 this.AssetRequests.RemoveAt(0); 377 this.AssetRequests.RemoveAt(0);
378 } 378 }
379 } 379 }
380 } 380 }
381 381
382 private void ProcessTextureQueue() 382 private void ProcessTextureQueue()
383 { 383 {
384 if (this.TextureRequests.Count != 0) 384 if (this.TextureRequests.Count != 0)
385 { 385 {
386 int num = this.TextureRequests.Count; 386 int num = this.TextureRequests.Count;
387 for (int i = 0; i < num; i++) 387 for (int i = 0; i < num; i++)
388 { 388 {
389 AssetRequest req = this.TextureRequests[i]; 389 AssetRequest req = this.TextureRequests[i];
390 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) 390 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID))
391 { 391 {
392 TextureSender sender = new TextureSender(req); 392 TextureSender sender = new TextureSender(req);
393 sender.OnComplete += new DownloadComplete(this.TextureSent); 393 sender.OnComplete += new DownloadComplete(this.TextureSent);
394 lock (this.SendingTextures) 394 lock (this.SendingTextures)
395 { 395 {
396 this.SendingTextures.Add(req.ImageInfo.FullID, sender); 396 this.SendingTextures.Add(req.ImageInfo.FullID, sender);
397 } 397 }
398 } 398 }
399 } 399 }
400 this.TextureRequests.Clear(); 400 this.TextureRequests.Clear();
401 } 401 }
402 } 402 }
403 403
404 public void RunAssetManager() 404 public void RunAssetManager()
405 { 405 {
406 Label_0000: 406 Label_0000:
407 try 407 try
408 { 408 {
409 this.ProcessAssetQueue(); 409 this.ProcessAssetQueue();
410 this.ProcessTextureQueue(); 410 this.ProcessTextureQueue();
411 Thread.Sleep(500); 411 Thread.Sleep(500);
412 goto Label_0000; 412 goto Label_0000;
413 } 413 }
414 catch (Exception exception) 414 catch (Exception exception)
415 { 415 {
416 Console.WriteLine(exception.Message); 416 Console.WriteLine(exception.Message);
417 goto Label_0000; 417 goto Label_0000;
418 } 418 }
419 } 419 }
420 420
421 public void TextureSent(TextureSender sender) 421 public void TextureSent(TextureSender sender)
422 { 422 {
423 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID)) 423 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID))
424 { 424 {
425 lock (this.SendingTextures) 425 lock (this.SendingTextures)
426 { 426 {
427 this.SendingTextures.Remove(sender.request.ImageInfo.FullID); 427 this.SendingTextures.Remove(sender.request.ImageInfo.FullID);
428 } 428 }
429 } 429 }
430 } 430 }
431 431
432 // Nested Types 432 // Nested Types
433 public class AssetInfo : AssetBase 433 public class AssetInfo : AssetBase
434 { 434 {
435 // Methods 435 // Methods
436 public AssetInfo() 436 public AssetInfo()
437 { 437 {
438 } 438 }
439 439
440 public AssetInfo(AssetBase aBase) 440 public AssetInfo(AssetBase aBase)
441 { 441 {
442 base.Data = aBase.Data; 442 base.Data = aBase.Data;
443 base.FullID = aBase.FullID; 443 base.FullID = aBase.FullID;
444 base.Type = aBase.Type; 444 base.Type = aBase.Type;
445 base.InvType = aBase.InvType; 445 base.InvType = aBase.InvType;
446 base.Name = aBase.Name; 446 base.Name = aBase.Name;
447 base.Description = aBase.Description; 447 base.Description = aBase.Description;
448 } 448 }
449 } 449 }
450 450
451 public class AssetRequest 451 public class AssetRequest
452 { 452 {
453 // Fields 453 // Fields
454 public AssetCache.AssetInfo AssetInf; 454 public AssetCache.AssetInfo AssetInf;
455 public long DataPointer; 455 public long DataPointer;
456 public AssetCache.TextureImage ImageInfo; 456 public AssetCache.TextureImage ImageInfo;
457 public bool IsTextureRequest; 457 public bool IsTextureRequest;
458 public int NumPackets; 458 public int NumPackets;
459 public int PacketCounter; 459 public int PacketCounter;
460 public LLUUID RequestAssetID; 460 public LLUUID RequestAssetID;
461 public IClientAPI RequestUser; 461 public IClientAPI RequestUser;
462 public LLUUID TransferRequestID; 462 public LLUUID TransferRequestID;
463 } 463 }
464 464
465 public class TextureImage : AssetBase 465 public class TextureImage : AssetBase
466 { 466 {
467 // Methods 467 // Methods
468 public TextureImage() 468 public TextureImage()
469 { 469 {
470 } 470 }
471 471
472 public TextureImage(AssetBase aBase) 472 public TextureImage(AssetBase aBase)
473 { 473 {
474 base.Data = aBase.Data; 474 base.Data = aBase.Data;
475 base.FullID = aBase.FullID; 475 base.FullID = aBase.FullID;
476 base.Type = aBase.Type; 476 base.Type = aBase.Type;
477 base.InvType = aBase.InvType; 477 base.InvType = aBase.InvType;
478 base.Name = aBase.Name; 478 base.Name = aBase.Name;
479 base.Description = aBase.Description; 479 base.Description = aBase.Description;
480 } 480 }
481 } 481 }
482 482
483 public class TextureSender 483 public class TextureSender
484 { 484 {
485 // Fields 485 // Fields
486 private Thread m_thread; 486 private Thread m_thread;
487 public AssetCache.AssetRequest request; 487 public AssetCache.AssetRequest request;
488 488
489 // Events 489 // Events
490 public event DownloadComplete OnComplete; 490 public event DownloadComplete OnComplete;
491 491
492 // Methods 492 // Methods
493 public TextureSender(AssetCache.AssetRequest req) 493 public TextureSender(AssetCache.AssetRequest req)
494 { 494 {
495 this.request = req; 495 this.request = req;
496 this.m_thread = new Thread(new ThreadStart(this.SendTexture)); 496 this.m_thread = new Thread(new ThreadStart(this.SendTexture));
497 this.m_thread.IsBackground = true; 497 this.m_thread.IsBackground = true;
498 this.m_thread.Start(); 498 this.m_thread.Start();
499 } 499 }
500 500
501 public void SendPacket() 501 public void SendPacket()
502 { 502 {
503 AssetCache.AssetRequest request = this.request; 503 AssetCache.AssetRequest request = this.request;
504 if (request.PacketCounter == 0) 504 if (request.PacketCounter == 0)
505 { 505 {
506 if (request.NumPackets == 1) 506 if (request.NumPackets == 1)
507 { 507 {
508 ImageDataPacket newPack = new ImageDataPacket(); 508 ImageDataPacket newPack = new ImageDataPacket();
509 newPack.ImageID.Packets = 1; 509 newPack.ImageID.Packets = 1;
510 newPack.ImageID.ID = request.ImageInfo.FullID; 510 newPack.ImageID.ID = request.ImageInfo.FullID;
511 newPack.ImageID.Size = (uint)request.ImageInfo.Data.Length; 511 newPack.ImageID.Size = (uint)request.ImageInfo.Data.Length;
512 newPack.ImageData.Data = request.ImageInfo.Data; 512 newPack.ImageData.Data = request.ImageInfo.Data;
513 newPack.ImageID.Codec = 2; 513 newPack.ImageID.Codec = 2;
514 request.RequestUser.OutPacket(newPack); 514 request.RequestUser.OutPacket(newPack);
515 request.PacketCounter++; 515 request.PacketCounter++;
516 } 516 }
517 else 517 else
518 { 518 {
519 ImageDataPacket packet2 = new ImageDataPacket(); 519 ImageDataPacket packet2 = new ImageDataPacket();
520 packet2.ImageID.Packets = (ushort)request.NumPackets; 520 packet2.ImageID.Packets = (ushort)request.NumPackets;
521 packet2.ImageID.ID = request.ImageInfo.FullID; 521 packet2.ImageID.ID = request.ImageInfo.FullID;
522 packet2.ImageID.Size = (uint)request.ImageInfo.Data.Length; 522 packet2.ImageID.Size = (uint)request.ImageInfo.Data.Length;
523 packet2.ImageData.Data = new byte[600]; 523 packet2.ImageData.Data = new byte[600];
524 Array.Copy(request.ImageInfo.Data, 0, packet2.ImageData.Data, 0, 600); 524 Array.Copy(request.ImageInfo.Data, 0, packet2.ImageData.Data, 0, 600);
525 packet2.ImageID.Codec = 2; 525 packet2.ImageID.Codec = 2;
526 request.RequestUser.OutPacket(packet2); 526 request.RequestUser.OutPacket(packet2);
527 request.PacketCounter++; 527 request.PacketCounter++;
528 } 528 }
529 } 529 }
530 else 530 else
531 { 531 {
532 ImagePacketPacket packet3 = new ImagePacketPacket(); 532 ImagePacketPacket packet3 = new ImagePacketPacket();
533 packet3.ImageID.Packet = (ushort)request.PacketCounter; 533 packet3.ImageID.Packet = (ushort)request.PacketCounter;
534 packet3.ImageID.ID = request.ImageInfo.FullID; 534 packet3.ImageID.ID = request.ImageInfo.FullID;
535 int length = (request.ImageInfo.Data.Length - 600) - (0x3e8 * (request.PacketCounter - 1)); 535 int length = (request.ImageInfo.Data.Length - 600) - (0x3e8 * (request.PacketCounter - 1));
536 if (length > 0x3e8) 536 if (length > 0x3e8)
537 { 537 {
538 length = 0x3e8; 538 length = 0x3e8;
539 } 539 }
540 packet3.ImageData.Data = new byte[length]; 540 packet3.ImageData.Data = new byte[length];
541 Array.Copy(request.ImageInfo.Data, 600 + (0x3e8 * (request.PacketCounter - 1)), packet3.ImageData.Data, 0, length); 541 Array.Copy(request.ImageInfo.Data, 600 + (0x3e8 * (request.PacketCounter - 1)), packet3.ImageData.Data, 0, length);
542 request.RequestUser.OutPacket(packet3); 542 request.RequestUser.OutPacket(packet3);
543 request.PacketCounter++; 543 request.PacketCounter++;
544 } 544 }
545 } 545 }
546 546
547 public void SendTexture() 547 public void SendTexture()
548 { 548 {
549 while (this.request.PacketCounter != this.request.NumPackets) 549 while (this.request.PacketCounter != this.request.NumPackets)
550 { 550 {
551 this.SendPacket(); 551 this.SendPacket();
552 Thread.Sleep(500); 552 Thread.Sleep(500);
553 } 553 }
554 if (this.OnComplete != null) 554 if (this.OnComplete != null)
555 { 555 {
556 this.OnComplete(this); 556 this.OnComplete(this);
557 } 557 }
558 } 558 }
559 } 559 }
560 } 560 }
561} 561}
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs
index 8b485af..f9f814a 100644
--- a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs
@@ -1,81 +1,81 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Utilities; 36using OpenSim.Framework.Utilities;
37using OpenSim.Framework.Data; 37using OpenSim.Framework.Data;
38 38
39namespace OpenSim.Framework.Communications.Caches 39namespace OpenSim.Framework.Communications.Caches
40{ 40{
41 public class AssetTransactionManager 41 public class AssetTransactionManager
42 { 42 {
43 // Fields 43 // Fields
44 public Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions = new Dictionary<LLUUID, AgentAssetTransactions>(); 44 public Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions = new Dictionary<LLUUID, AgentAssetTransactions>();
45 45
46 // Methods 46 // Methods
47 public AgentAssetTransactions AddUser(LLUUID userID) 47 public AgentAssetTransactions AddUser(LLUUID userID)
48 { 48 {
49 if (!this.AgentTransactions.ContainsKey(userID)) 49 if (!this.AgentTransactions.ContainsKey(userID))
50 { 50 {
51 AgentAssetTransactions transactions = new AgentAssetTransactions(userID); 51 AgentAssetTransactions transactions = new AgentAssetTransactions(userID);
52 this.AgentTransactions.Add(userID, transactions); 52 this.AgentTransactions.Add(userID, transactions);
53 return transactions; 53 return transactions;
54 } 54 }
55 return null; 55 return null;
56 } 56 }
57 57
58 public AgentAssetTransactions GetUserTransActions(LLUUID userID) 58 public AgentAssetTransactions GetUserTransActions(LLUUID userID)
59 { 59 {
60 if (this.AgentTransactions.ContainsKey(userID)) 60 if (this.AgentTransactions.ContainsKey(userID))
61 { 61 {
62 return this.AgentTransactions[userID]; 62 return this.AgentTransactions[userID];
63 } 63 }
64 return null; 64 return null;
65 } 65 }
66 66
67 public void HandleInventoryFromTransaction() 67 public void HandleInventoryFromTransaction()
68 { 68 {
69 } 69 }
70 70
71 public void HandleUDPUploadRequest() 71 public void HandleUDPUploadRequest()
72 { 72 {
73 } 73 }
74 74
75 public void HandleXfer(IClientAPI remoteClient, uint xferID, uint packetID, byte[] data) 75 public void HandleXfer(IClientAPI remoteClient, uint xferID, uint packetID, byte[] data)
76 { 76 {
77 } 77 }
78 } 78 }
79} 79}
80 80
81 81
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
index 6741969..c906b76 100644
--- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
@@ -1,275 +1,275 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using libsecondlife.Packets; 34using libsecondlife.Packets;
35using OpenSim.Framework.Interfaces; 35using OpenSim.Framework.Interfaces;
36using OpenSim.Framework.Types; 36using OpenSim.Framework.Types;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38using OpenSim.Region.Capabilities; 38using OpenSim.Region.Capabilities;
39using OpenSim.Framework.Servers; 39using OpenSim.Framework.Servers;
40 40
41namespace OpenSim.Framework.Communications.Caches 41namespace OpenSim.Framework.Communications.Caches
42{ 42{
43 public class AgentAssetTransactions 43 public class AgentAssetTransactions
44 { 44 {
45 // Fields 45 // Fields
46 public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>(); 46 public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>();
47 public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>(); 47 public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>();
48 public LLUUID UserID; 48 public LLUUID UserID;
49 public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>(); 49 public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>();
50 50
51 // Methods 51 // Methods
52 public AgentAssetTransactions(LLUUID agentID) 52 public AgentAssetTransactions(LLUUID agentID)
53 { 53 {
54 this.UserID = agentID; 54 this.UserID = agentID;
55 } 55 }
56 56
57 public AssetCapsUploader RequestCapsUploader() 57 public AssetCapsUploader RequestCapsUploader()
58 { 58 {
59 AssetCapsUploader uploader = new AssetCapsUploader(); 59 AssetCapsUploader uploader = new AssetCapsUploader();
60 this.CapsUploaders.Add(uploader); 60 this.CapsUploaders.Add(uploader);
61 return uploader; 61 return uploader;
62 } 62 }
63 63
64 public NoteCardCapsUpdate RequestNoteCardUpdater() 64 public NoteCardCapsUpdate RequestNoteCardUpdater()
65 { 65 {
66 NoteCardCapsUpdate update = new NoteCardCapsUpdate(); 66 NoteCardCapsUpdate update = new NoteCardCapsUpdate();
67 this.NotecardUpdaters.Add(update); 67 this.NotecardUpdaters.Add(update);
68 return update; 68 return update;
69 } 69 }
70 70
71 public AssetXferUploader RequestXferUploader(LLUUID transactionID) 71 public AssetXferUploader RequestXferUploader(LLUUID transactionID)
72 { 72 {
73 AssetXferUploader uploader = new AssetXferUploader(); 73 AssetXferUploader uploader = new AssetXferUploader();
74 this.XferUploaders.Add(transactionID, uploader); 74 this.XferUploaders.Add(transactionID, uploader);
75 return uploader; 75 return uploader;
76 } 76 }
77 77
78 // Nested Types 78 // Nested Types
79 public class AssetCapsUploader 79 public class AssetCapsUploader
80 { 80 {
81 // Fields 81 // Fields
82 private BaseHttpServer httpListener; 82 private BaseHttpServer httpListener;
83 private LLUUID inventoryItemID; 83 private LLUUID inventoryItemID;
84 private string m_assetDescription = ""; 84 private string m_assetDescription = "";
85 private string m_assetName = ""; 85 private string m_assetName = "";
86 private LLUUID m_folderID; 86 private LLUUID m_folderID;
87 private LLUUID newAssetID; 87 private LLUUID newAssetID;
88 private bool SaveImages = false; 88 private bool SaveImages = false;
89 private string uploaderPath = ""; 89 private string uploaderPath = "";
90 90
91 // Events 91 // Events
92 public event UpLoadedTexture OnUpLoad; 92 public event UpLoadedTexture OnUpLoad;
93 93
94 // Methods 94 // Methods
95 public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, LLUUID folderID, string path, BaseHttpServer httpServer) 95 public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, LLUUID folderID, string path, BaseHttpServer httpServer)
96 { 96 {
97 this.m_assetName = assetName; 97 this.m_assetName = assetName;
98 this.m_assetDescription = assetDescription; 98 this.m_assetDescription = assetDescription;
99 this.m_folderID = folderID; 99 this.m_folderID = folderID;
100 this.newAssetID = assetID; 100 this.newAssetID = assetID;
101 this.inventoryItemID = inventoryItem; 101 this.inventoryItemID = inventoryItem;
102 this.uploaderPath = path; 102 this.uploaderPath = path;
103 this.httpListener = httpServer; 103 this.httpListener = httpServer;
104 } 104 }
105 105
106 private void SaveImageToFile(string filename, byte[] data) 106 private void SaveImageToFile(string filename, byte[] data)
107 { 107 {
108 FileStream output = File.Create(filename); 108 FileStream output = File.Create(filename);
109 BinaryWriter writer = new BinaryWriter(output); 109 BinaryWriter writer = new BinaryWriter(output);
110 writer.Write(data); 110 writer.Write(data);
111 writer.Close(); 111 writer.Close();
112 output.Close(); 112 output.Close();
113 } 113 }
114 114
115 public string uploaderCaps(byte[] data, string path, string param) 115 public string uploaderCaps(byte[] data, string path, string param)
116 { 116 {
117 LLUUID inventoryItemID = this.inventoryItemID; 117 LLUUID inventoryItemID = this.inventoryItemID;
118 string text = ""; 118 string text = "";
119 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); 119 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete();
120 complete.new_asset = this.newAssetID.ToStringHyphenated(); 120 complete.new_asset = this.newAssetID.ToStringHyphenated();
121 complete.new_inventory_item = inventoryItemID; 121 complete.new_inventory_item = inventoryItemID;
122 complete.state = "complete"; 122 complete.state = "complete";
123 text = LLSDHelpers.SerialiseLLSDReply(complete); 123 text = LLSDHelpers.SerialiseLLSDReply(complete);
124 this.httpListener.RemoveStreamHandler("POST", this.uploaderPath); 124 this.httpListener.RemoveStreamHandler("POST", this.uploaderPath);
125 if (this.SaveImages) 125 if (this.SaveImages)
126 { 126 {
127 this.SaveImageToFile(this.m_assetName + ".jp2", data); 127 this.SaveImageToFile(this.m_assetName + ".jp2", data);
128 } 128 }
129 if (this.OnUpLoad != null) 129 if (this.OnUpLoad != null)
130 { 130 {
131 this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); 131 this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data);
132 } 132 }
133 return text; 133 return text;
134 } 134 }
135 } 135 }
136 136
137 public class AssetXferUploader 137 public class AssetXferUploader
138 { 138 {
139 // Fields 139 // Fields
140 public bool AddToInventory; 140 public bool AddToInventory;
141 public AssetBase Asset; 141 public AssetBase Asset;
142 public LLUUID InventFolder = LLUUID.Zero; 142 public LLUUID InventFolder = LLUUID.Zero;
143 private IClientAPI ourClient; 143 private IClientAPI ourClient;
144 public LLUUID TransactionID = LLUUID.Zero; 144 public LLUUID TransactionID = LLUUID.Zero;
145 public bool UploadComplete; 145 public bool UploadComplete;
146 public uint XferID; 146 public uint XferID;
147 147
148 // Methods 148 // Methods
149 public void HandleXferPacket(uint xferID, uint packetID, byte[] data) 149 public void HandleXferPacket(uint xferID, uint packetID, byte[] data)
150 { 150 {
151 if (this.XferID == xferID) 151 if (this.XferID == xferID)
152 { 152 {
153 if (this.Asset.Data.Length > 1) 153 if (this.Asset.Data.Length > 1)
154 { 154 {
155 byte[] destinationArray = new byte[this.Asset.Data.Length + data.Length]; 155 byte[] destinationArray = new byte[this.Asset.Data.Length + data.Length];
156 Array.Copy(this.Asset.Data, 0, destinationArray, 0, this.Asset.Data.Length); 156 Array.Copy(this.Asset.Data, 0, destinationArray, 0, this.Asset.Data.Length);
157 Array.Copy(data, 0, destinationArray, this.Asset.Data.Length, data.Length); 157 Array.Copy(data, 0, destinationArray, this.Asset.Data.Length, data.Length);
158 this.Asset.Data = destinationArray; 158 this.Asset.Data = destinationArray;
159 } 159 }
160 else 160 else
161 { 161 {
162 byte[] buffer2 = new byte[data.Length - 4]; 162 byte[] buffer2 = new byte[data.Length - 4];
163 Array.Copy(data, 4, buffer2, 0, data.Length - 4); 163 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
164 this.Asset.Data = buffer2; 164 this.Asset.Data = buffer2;
165 } 165 }
166 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket(); 166 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
167 newPack.XferID.ID = xferID; 167 newPack.XferID.ID = xferID;
168 newPack.XferID.Packet = packetID; 168 newPack.XferID.Packet = packetID;
169 this.ourClient.OutPacket(newPack); 169 this.ourClient.OutPacket(newPack);
170 if ((packetID & 0x80000000) != 0) 170 if ((packetID & 0x80000000) != 0)
171 { 171 {
172 this.SendCompleteMessage(); 172 this.SendCompleteMessage();
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) 177 public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data)
178 { 178 {
179 this.ourClient = remoteClient; 179 this.ourClient = remoteClient;
180 this.Asset = new AssetBase(); 180 this.Asset = new AssetBase();
181 this.Asset.FullID = assetID; 181 this.Asset.FullID = assetID;
182 this.Asset.InvType = type; 182 this.Asset.InvType = type;
183 this.Asset.Type = type; 183 this.Asset.Type = type;
184 this.Asset.Data = data; 184 this.Asset.Data = data;
185 this.Asset.Name = "blank"; 185 this.Asset.Name = "blank";
186 this.Asset.Description = "empty"; 186 this.Asset.Description = "empty";
187 this.TransactionID = transaction; 187 this.TransactionID = transaction;
188 if (this.Asset.Data.Length > 2) 188 if (this.Asset.Data.Length > 2)
189 { 189 {
190 this.SendCompleteMessage(); 190 this.SendCompleteMessage();
191 } 191 }
192 else 192 else
193 { 193 {
194 this.ReqestStartXfer(); 194 this.ReqestStartXfer();
195 } 195 }
196 } 196 }
197 197
198 protected void ReqestStartXfer() 198 protected void ReqestStartXfer()
199 { 199 {
200 this.UploadComplete = false; 200 this.UploadComplete = false;
201 this.XferID = Util.GetNextXferID(); 201 this.XferID = Util.GetNextXferID();
202 RequestXferPacket newPack = new RequestXferPacket(); 202 RequestXferPacket newPack = new RequestXferPacket();
203 newPack.XferID.ID = this.XferID; 203 newPack.XferID.ID = this.XferID;
204 newPack.XferID.VFileType = this.Asset.Type; 204 newPack.XferID.VFileType = this.Asset.Type;
205 newPack.XferID.VFileID = this.Asset.FullID; 205 newPack.XferID.VFileID = this.Asset.FullID;
206 newPack.XferID.FilePath = 0; 206 newPack.XferID.FilePath = 0;
207 newPack.XferID.Filename = new byte[0]; 207 newPack.XferID.Filename = new byte[0];
208 this.ourClient.OutPacket(newPack); 208 this.ourClient.OutPacket(newPack);
209 } 209 }
210 210
211 protected void SendCompleteMessage() 211 protected void SendCompleteMessage()
212 { 212 {
213 this.UploadComplete = true; 213 this.UploadComplete = true;
214 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket(); 214 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
215 newPack.AssetBlock.Type = this.Asset.Type; 215 newPack.AssetBlock.Type = this.Asset.Type;
216 newPack.AssetBlock.Success = true; 216 newPack.AssetBlock.Success = true;
217 newPack.AssetBlock.UUID = this.Asset.FullID; 217 newPack.AssetBlock.UUID = this.Asset.FullID;
218 this.ourClient.OutPacket(newPack); 218 this.ourClient.OutPacket(newPack);
219 } 219 }
220 } 220 }
221 221
222 public class NoteCardCapsUpdate 222 public class NoteCardCapsUpdate
223 { 223 {
224 // Fields 224 // Fields
225 private BaseHttpServer httpListener; 225 private BaseHttpServer httpListener;
226 private LLUUID inventoryItemID; 226 private LLUUID inventoryItemID;
227 private string m_assetName = ""; 227 private string m_assetName = "";
228 private LLUUID newAssetID; 228 private LLUUID newAssetID;
229 private bool SaveImages = false; 229 private bool SaveImages = false;
230 private string uploaderPath = ""; 230 private string uploaderPath = "";
231 231
232 // Events 232 // Events
233 public event UpLoadedTexture OnUpLoad; 233 public event UpLoadedTexture OnUpLoad;
234 234
235 // Methods 235 // Methods
236 public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer) 236 public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer)
237 { 237 {
238 this.inventoryItemID = inventoryItem; 238 this.inventoryItemID = inventoryItem;
239 this.uploaderPath = path; 239 this.uploaderPath = path;
240 this.httpListener = httpServer; 240 this.httpListener = httpServer;
241 this.newAssetID = LLUUID.Random(); 241 this.newAssetID = LLUUID.Random();
242 } 242 }
243 243
244 private void SaveImageToFile(string filename, byte[] data) 244 private void SaveImageToFile(string filename, byte[] data)
245 { 245 {
246 FileStream output = File.Create(filename); 246 FileStream output = File.Create(filename);
247 BinaryWriter writer = new BinaryWriter(output); 247 BinaryWriter writer = new BinaryWriter(output);
248 writer.Write(data); 248 writer.Write(data);
249 writer.Close(); 249 writer.Close();
250 output.Close(); 250 output.Close();
251 } 251 }
252 252
253 public string uploaderCaps(byte[] data, string path, string param) 253 public string uploaderCaps(byte[] data, string path, string param)
254 { 254 {
255 LLUUID inventoryItemID = this.inventoryItemID; 255 LLUUID inventoryItemID = this.inventoryItemID;
256 string text = ""; 256 string text = "";
257 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); 257 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete();
258 complete.new_asset = this.newAssetID.ToStringHyphenated(); 258 complete.new_asset = this.newAssetID.ToStringHyphenated();
259 complete.new_inventory_item = inventoryItemID; 259 complete.new_inventory_item = inventoryItemID;
260 complete.state = "complete"; 260 complete.state = "complete";
261 text = LLSDHelpers.SerialiseLLSDReply(complete); 261 text = LLSDHelpers.SerialiseLLSDReply(complete);
262 this.httpListener.RemoveStreamHandler("POST", this.uploaderPath); 262 this.httpListener.RemoveStreamHandler("POST", this.uploaderPath);
263 if (this.SaveImages) 263 if (this.SaveImages)
264 { 264 {
265 this.SaveImageToFile(this.m_assetName + "notecard.txt", data); 265 this.SaveImageToFile(this.m_assetName + "notecard.txt", data);
266 } 266 }
267 if (this.OnUpLoad != null) 267 if (this.OnUpLoad != null)
268 { 268 {
269 this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); 269 this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data);
270 } 270 }
271 return text; 271 return text;
272 } 272 }
273 } 273 }
274 } 274 }
275} \ No newline at end of file 275} \ No newline at end of file
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
index 2660df3..d850305 100644
--- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
+++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
@@ -1,94 +1,94 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Data; 36using OpenSim.Framework.Data;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38 38
39namespace OpenSim.Framework.Communications.Caches 39namespace OpenSim.Framework.Communications.Caches
40{ 40{
41 public class CachedUserInfo 41 public class CachedUserInfo
42 { 42 {
43 // Fields 43 // Fields
44 public InventoryFolder RootFolder; 44 public InventoryFolder RootFolder;
45 public UserProfileData UserProfile; 45 public UserProfileData UserProfile;
46 46
47 // Methods 47 // Methods
48 public void FolderReceive(LLUUID userID, InventoryFolder folderInfo) 48 public void FolderReceive(LLUUID userID, InventoryFolder folderInfo)
49 { 49 {
50 if (userID == this.UserProfile.UUID) 50 if (userID == this.UserProfile.UUID)
51 { 51 {
52 if (this.RootFolder == null) 52 if (this.RootFolder == null)
53 { 53 {
54 if (folderInfo.parentID == LLUUID.Zero) 54 if (folderInfo.parentID == LLUUID.Zero)
55 { 55 {
56 this.RootFolder = folderInfo; 56 this.RootFolder = folderInfo;
57 } 57 }
58 } 58 }
59 else if (this.RootFolder.folderID == folderInfo.parentID) 59 else if (this.RootFolder.folderID == folderInfo.parentID)
60 { 60 {
61 this.RootFolder.SubFolders.Add(folderInfo.folderID, folderInfo); 61 this.RootFolder.SubFolders.Add(folderInfo.folderID, folderInfo);
62 } 62 }
63 else 63 else
64 { 64 {
65 InventoryFolder folder = this.RootFolder.HasSubFolder(folderInfo.parentID); 65 InventoryFolder folder = this.RootFolder.HasSubFolder(folderInfo.parentID);
66 if (folder != null) 66 if (folder != null)
67 { 67 {
68 folder.SubFolders.Add(folderInfo.folderID, folderInfo); 68 folder.SubFolders.Add(folderInfo.folderID, folderInfo);
69 } 69 }
70 } 70 }
71 } 71 }
72 } 72 }
73 73
74 public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo) 74 public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo)
75 { 75 {
76 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) 76 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null))
77 { 77 {
78 if (itemInfo.parentFolderID == this.RootFolder.folderID) 78 if (itemInfo.parentFolderID == this.RootFolder.folderID)
79 { 79 {
80 this.RootFolder.Items.Add(itemInfo.inventoryID, itemInfo); 80 this.RootFolder.Items.Add(itemInfo.inventoryID, itemInfo);
81 } 81 }
82 else 82 else
83 { 83 {
84 InventoryFolder folder = this.RootFolder.HasSubFolder(itemInfo.parentFolderID); 84 InventoryFolder folder = this.RootFolder.HasSubFolder(itemInfo.parentFolderID);
85 if (folder != null) 85 if (folder != null)
86 { 86 {
87 folder.Items.Add(itemInfo.inventoryID, itemInfo); 87 folder.Items.Add(itemInfo.inventoryID, itemInfo);
88 } 88 }
89 } 89 }
90 } 90 }
91 } 91 }
92 } 92 }
93} 93}
94 94
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs b/OpenSim/Framework/Communications/Cache/InventoryFolder.cs
index 8670eb0..300a6e3 100644
--- a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs
+++ b/OpenSim/Framework/Communications/Cache/InventoryFolder.cs
@@ -1,109 +1,109 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Data; 35using OpenSim.Framework.Data;
36using OpenSim.Framework.Types; 36using OpenSim.Framework.Types;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38 38
39namespace OpenSim.Framework.Communications.Caches 39namespace OpenSim.Framework.Communications.Caches
40{ 40{
41 public class InventoryFolder : InventoryFolderBase 41 public class InventoryFolder : InventoryFolderBase
42 { 42 {
43 // Fields 43 // Fields
44 public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>(); 44 public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>();
45 public Dictionary<LLUUID, InventoryFolder> SubFolders = new Dictionary<LLUUID, InventoryFolder>(); 45 public Dictionary<LLUUID, InventoryFolder> SubFolders = new Dictionary<LLUUID, InventoryFolder>();
46 46
47 // Methods 47 // Methods
48 public InventoryFolder CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) 48 public InventoryFolder CreateNewSubFolder(LLUUID folderID, string folderName, ushort type)
49 { 49 {
50 InventoryFolder subFold = new InventoryFolder(); 50 InventoryFolder subFold = new InventoryFolder();
51 subFold.name = folderName; 51 subFold.name = folderName;
52 subFold.folderID = folderID; 52 subFold.folderID = folderID;
53 subFold.type = type; 53 subFold.type = (short) type;
54 subFold.parentID = this.folderID; 54 subFold.parentID = this.folderID;
55 subFold.agentID = this.agentID; 55 subFold.agentID = this.agentID;
56 this.SubFolders.Add(subFold.folderID, subFold); 56 this.SubFolders.Add(subFold.folderID, subFold);
57 return subFold; 57 return subFold;
58 } 58 }
59 59
60 public InventoryItemBase HasItem(LLUUID itemID) 60 public InventoryItemBase HasItem(LLUUID itemID)
61 { 61 {
62 InventoryItemBase base2 = null; 62 InventoryItemBase base2 = null;
63 if (this.Items.ContainsKey(itemID)) 63 if (this.Items.ContainsKey(itemID))
64 { 64 {
65 return this.Items[itemID]; 65 return this.Items[itemID];
66 } 66 }
67 foreach (InventoryFolder folder in this.SubFolders.Values) 67 foreach (InventoryFolder folder in this.SubFolders.Values)
68 { 68 {
69 base2 = folder.HasItem(itemID); 69 base2 = folder.HasItem(itemID);
70 if (base2 != null) 70 if (base2 != null)
71 { 71 {
72 break; 72 break;
73 } 73 }
74 } 74 }
75 return base2; 75 return base2;
76 } 76 }
77 77
78 public InventoryFolder HasSubFolder(LLUUID folderID) 78 public InventoryFolder HasSubFolder(LLUUID folderID)
79 { 79 {
80 InventoryFolder returnFolder = null; 80 InventoryFolder returnFolder = null;
81 if (this.SubFolders.ContainsKey(folderID)) 81 if (this.SubFolders.ContainsKey(folderID))
82 { 82 {
83 returnFolder = this.SubFolders[folderID]; 83 returnFolder = this.SubFolders[folderID];
84 } 84 }
85 else 85 else
86 { 86 {
87 foreach (InventoryFolder folder in this.SubFolders.Values) 87 foreach (InventoryFolder folder in this.SubFolders.Values)
88 { 88 {
89 returnFolder = folder.HasSubFolder(folderID); 89 returnFolder = folder.HasSubFolder(folderID);
90 if (returnFolder != null) 90 if (returnFolder != null)
91 { 91 {
92 break; 92 break;
93 } 93 }
94 } 94 }
95 } 95 }
96 return returnFolder; 96 return returnFolder;
97 } 97 }
98 98
99 public List<InventoryItemBase> RequestListOfItems() 99 public List<InventoryItemBase> RequestListOfItems()
100 { 100 {
101 List<InventoryItemBase> itemList = new List<InventoryItemBase>(); 101 List<InventoryItemBase> itemList = new List<InventoryItemBase>();
102 foreach (InventoryItemBase item in this.Items.Values) 102 foreach (InventoryItemBase item in this.Items.Values)
103 { 103 {
104 itemList.Add(item); 104 itemList.Add(item);
105 } 105 }
106 return itemList; 106 return itemList;
107 } 107 }
108 } 108 }
109} 109}
diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs
new file mode 100644
index 0000000..2608145
--- /dev/null
+++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs
@@ -0,0 +1,89 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using OpenSim.Framework.Data;
6
7namespace OpenSim.Framework.Communications.Caches
8{
9 public class LibraryRootFolder : InventoryFolder
10 {
11 private LLUUID libOwner = new LLUUID("11111111-1111-0000-0000-000100bba000");
12
13 public LibraryRootFolder()
14 {
15 this.agentID = libOwner;
16 this.folderID = new LLUUID("00000112-000f-0000-0000-000100bba000");
17 this.name = "OpenSim Library";
18 this.parentID = LLUUID.Zero;
19 this.type = (short)-1;
20 this.version = (ushort) 1;
21
22 InventoryItemBase item = new InventoryItemBase();
23 item.avatarID = libOwner;
24 item.creatorsID = libOwner;
25 item.inventoryID = LLUUID.Random();
26 item.assetID = new LLUUID("00000000-0000-0000-9999-000000000002");
27 item.inventoryDescription = "Plywood texture";
28 item.inventoryName = "Plywood";
29 item.type =0;
30 item.parentFolderID = this.folderID;
31 item.inventoryCurrentPermissions = 2147483647;
32 item.inventoryNextPermissions = 2147483647;
33 this.Items.Add(item.inventoryID, item);
34
35 item = new InventoryItemBase();
36 item.avatarID = libOwner;
37 item.creatorsID = libOwner;
38 item.inventoryID = LLUUID.Random();
39 item.assetID = new LLUUID("00000000-0000-0000-9999-000000000003");
40 item.inventoryDescription = "Rocks texture";
41 item.inventoryName = "Rocks";
42 item.type = 0;
43 item.parentFolderID = this.folderID;
44 item.inventoryCurrentPermissions = 2147483647;
45 item.inventoryNextPermissions = 2147483647;
46 this.Items.Add(item.inventoryID, item);
47
48 item = new InventoryItemBase();
49 item.avatarID = libOwner;
50 item.creatorsID = libOwner;
51 item.inventoryID = LLUUID.Random();
52 item.assetID = new LLUUID("00000000-0000-0000-9999-000000000001");
53 item.inventoryDescription = "Bricks texture";
54 item.inventoryName = "Bricks";
55 item.type = 0;
56 item.parentFolderID = this.folderID;
57 item.inventoryCurrentPermissions = 2147483647;
58 item.inventoryNextPermissions = 2147483647;
59 this.Items.Add(item.inventoryID, item);
60
61 item = new InventoryItemBase();
62 item.avatarID = libOwner;
63 item.creatorsID = libOwner;
64 item.inventoryID = LLUUID.Random();
65 item.assetID = new LLUUID("00000000-0000-0000-9999-000000000004");
66 item.inventoryDescription = "Granite texture";
67 item.inventoryName = "Granite";
68 item.type = 0;
69 item.parentFolderID = this.folderID;
70 item.inventoryCurrentPermissions = 2147483647;
71 item.inventoryNextPermissions = 2147483647;
72 this.Items.Add(item.inventoryID, item);
73
74 item = new InventoryItemBase();
75 item.avatarID = libOwner;
76 item.creatorsID = libOwner;
77 item.inventoryID = LLUUID.Random();
78 item.assetID = new LLUUID("00000000-0000-0000-9999-000000000005");
79 item.inventoryDescription = "Hardwood texture";
80 item.inventoryName = "Hardwood";
81 item.type = 0;
82 item.parentFolderID = this.folderID;
83 item.inventoryCurrentPermissions = 2147483647;
84 item.inventoryNextPermissions = 2147483647;
85 this.Items.Add(item.inventoryID, item);
86 }
87
88 }
89}
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
index 8210702..7b4f6a5 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
@@ -1,170 +1,216 @@
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*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Utilities; 36using OpenSim.Framework.Utilities;
37using OpenSim.Framework.Data; 37using OpenSim.Framework.Data;
38 38
39namespace OpenSim.Framework.Communications.Caches 39namespace OpenSim.Framework.Communications.Caches
40{ 40{
41 41 public class UserProfileCache
42 public class UserProfileCache 42 {
43 { 43 // Fields
44 // Fields 44 private CommunicationsManager m_parent;
45 private CommunicationsManager m_parent; 45 public Dictionary<LLUUID, CachedUserInfo> UserProfiles = new Dictionary<LLUUID, CachedUserInfo>();
46 public Dictionary<LLUUID, CachedUserInfo> UserProfiles = new Dictionary<LLUUID, CachedUserInfo>(); 46
47 47 public LibraryRootFolder libraryRoot = new LibraryRootFolder();
48 // Methods 48
49 public UserProfileCache(CommunicationsManager parent) 49 // Methods
50 { 50 public UserProfileCache(CommunicationsManager parent)
51 this.m_parent = parent; 51 {
52 } 52 this.m_parent = parent;
53 53 }
54 public void AddNewUser(LLUUID userID) 54
55 { 55 /// <summary>
56 if (!this.UserProfiles.ContainsKey(userID)) 56 /// A new user has moved into a region in this instance
57 { 57 /// so get info from servers
58 CachedUserInfo userInfo = new CachedUserInfo(); 58 /// </summary>
59 userInfo.UserProfile = this.RequestUserProfileForUser(userID); 59 /// <param name="userID"></param>
60 if (userInfo.UserProfile != null) 60 public void AddNewUser(LLUUID userID)
61 { 61 {
62 this.RequestInventoryForUser(userID, userInfo); 62 if (!this.UserProfiles.ContainsKey(userID))
63 this.UserProfiles.Add(userID, userInfo); 63 {
64 } 64 CachedUserInfo userInfo = new CachedUserInfo();
65 else 65 userInfo.UserProfile = this.RequestUserProfileForUser(userID);
66 { 66 if (userInfo.UserProfile != null)
67 Console.WriteLine("UserProfileCache.cs: user profile for user not found"); 67 {
68 } 68 this.RequestInventoryForUser(userID, userInfo);
69 } 69 this.UserProfiles.Add(userID, userInfo);
70 } 70 }
71 71 else
72 public void AddNewUser(string firstName, string lastName) 72 {
73 { 73 Console.WriteLine("UserProfileCache.cs: user profile for user not found");
74 } 74 }
75 75 }
76 public CachedUserInfo GetUserDetails(LLUUID userID) 76 }
77 { 77
78 if (this.UserProfiles.ContainsKey(userID)) 78 /// <summary>
79 { 79 /// A new user has moved into a region in this instance
80 return this.UserProfiles[userID]; 80 /// so get info from servers
81 } 81 /// </summary>
82 return null; 82 /// <param name="firstName"></param>
83 } 83 /// <param name="lastName"></param>
84 84 public void AddNewUser(string firstName, string lastName)
85 public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, string folderName, LLUUID parentID) 85 {
86 { 86 }
87 if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) 87
88 { 88 public CachedUserInfo GetUserDetails(LLUUID userID)
89 CachedUserInfo info = this.UserProfiles[remoteClient.AgentId]; 89 {
90 if (info.RootFolder.folderID == parentID) 90 if (this.UserProfiles.ContainsKey(userID))
91 { 91 {
92 info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); 92 return this.UserProfiles[userID];
93 } 93 }
94 else 94 return null;
95 { 95 }
96 InventoryFolder folder = info.RootFolder.HasSubFolder(parentID); 96
97 if (folder != null) 97 public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, string folderName, LLUUID parentID)
98 { 98 {
99 folder.CreateNewSubFolder(folderID, folderName, folderType); 99 if (this.UserProfiles.ContainsKey(remoteClient.AgentId))
100 } 100 {
101 } 101 CachedUserInfo info = this.UserProfiles[remoteClient.AgentId];
102 } 102 if (info.RootFolder.folderID == parentID)
103 } 103 {
104 104 info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
105 public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder) 105 }
106 { 106 else
107 if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) 107 {
108 { 108 InventoryFolder folder = info.RootFolder.HasSubFolder(parentID);
109 CachedUserInfo info = this.UserProfiles[remoteClient.AgentId]; 109 if (folder != null)
110 if (info.RootFolder.folderID == folderID) 110 {
111 { 111 folder.CreateNewSubFolder(folderID, folderName, folderType);
112 if (fetchItems) 112 }
113 { 113 }
114 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, info.RootFolder.RequestListOfItems()); 114 }
115 } 115 }
116 } 116
117 else 117 public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
118 { 118 {
119 InventoryFolder folder = info.RootFolder.HasSubFolder(folderID); 119 if (folderID == libraryRoot.folderID )
120 if ((folder != null) && fetchItems) 120 {
121 { 121 remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID, libraryRoot.RequestListOfItems());
122 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems()); 122 }
123 } 123 else if (this.UserProfiles.ContainsKey(remoteClient.AgentId))
124 } 124 {
125 } 125 CachedUserInfo info = this.UserProfiles[remoteClient.AgentId];
126 } 126 if (info.RootFolder.folderID == folderID)
127 127 {
128 public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) 128 if (fetchItems)
129 { 129 {
130 if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) 130 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, info.RootFolder.RequestListOfItems());
131 { 131 }
132 InventoryItemBase item = this.UserProfiles[remoteClient.AgentId].RootFolder.HasItem(itemID); 132 }
133 if (item != null) 133 else
134 { 134 {
135 remoteClient.SendInventoryItemDetails(ownerID, item); 135 InventoryFolder folder = info.RootFolder.HasSubFolder(folderID);
136 } 136 if ((folder != null) && fetchItems)
137 } 137 {
138 } 138 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems());
139 139 }
140 private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) 140 }
141 { 141 }
142 InventoryFolder folderInfo = new InventoryFolder(); 142 }
143 folderInfo.agentID = userID; 143
144 folderInfo.folderID = userInfo.UserProfile.rootInventoryFolderID; 144 public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID)
145 folderInfo.name = "My Inventory"; 145 {
146 folderInfo.parentID = LLUUID.Zero; 146 if (ownerID == libraryRoot.agentID)
147 folderInfo.type = 8; 147 {
148 folderInfo.version = 1; 148 //Console.WriteLine("request info for library item");
149 userInfo.FolderReceive(userID, folderInfo); 149 }
150 } 150 else if (this.UserProfiles.ContainsKey(remoteClient.AgentId))
151 151 {
152 private UserProfileData RequestUserProfileForUser(LLUUID userID) 152 InventoryItemBase item = this.UserProfiles[remoteClient.AgentId].RootFolder.HasItem(itemID);
153 { 153 if (item != null)
154 return this.m_parent.UserServer.GetUserProfile(userID); 154 {
155 } 155 remoteClient.SendInventoryItemDetails(ownerID, item);
156 156 }
157 private void UpdateInventoryToServer(LLUUID userID) 157 }
158 { 158 }
159 } 159
160 160 /// <summary>
161 private void UpdateUserProfileToServer(LLUUID userID) 161 /// Request Iventory Info from Inventory server
162 { 162 /// </summary>
163 } 163 /// <param name="userID"></param>
164 164 private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo)
165 public void UserLogOut(LLUUID userID) 165 {
166 { 166 // this.m_parent.InventoryServer.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive);
167 } 167
168 } 168 //for now we manually create the root folder,
169} 169 // but should be requesting all inventory from inventory server.
170 170 InventoryFolder folderInfo = new InventoryFolder();
171 folderInfo.agentID = userID;
172 folderInfo.folderID = userInfo.UserProfile.rootInventoryFolderID;
173 folderInfo.name = "My Inventory";
174 folderInfo.parentID = LLUUID.Zero;
175 folderInfo.type = 8;
176 folderInfo.version = 1;
177 userInfo.FolderReceive(userID, folderInfo);
178 }
179
180 /// <summary>
181 /// Request the user profile from User server
182 /// </summary>
183 /// <param name="userID"></param>
184 private UserProfileData RequestUserProfileForUser(LLUUID userID)
185 {
186 return this.m_parent.UserServer.GetUserProfile(userID);
187 }
188
189 /// <summary>
190 /// Update Inventory data to Inventory server
191 /// </summary>
192 /// <param name="userID"></param>
193 private void UpdateInventoryToServer(LLUUID userID)
194 {
195 }
196
197 /// <summary>
198 /// Make sure UserProfile is updated on user server
199 /// </summary>
200 /// <param name="userID"></param>
201 private void UpdateUserProfileToServer(LLUUID userID)
202 {
203 }
204
205 /// <summary>
206 /// A user has left this instance
207 /// so make sure servers have been updated
208 /// Then remove cached info
209 /// </summary>
210 /// <param name="userID"></param>
211 public void UserLogOut(LLUUID userID)
212 {
213 }
214 }
215}
216
diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs
index e220e17..ac882ba 100644
--- a/OpenSim/Framework/Communications/CommunicationsManager.cs
+++ b/OpenSim/Framework/Communications/CommunicationsManager.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Framework.Communications
44 public IGridServices GridServer; 44 public IGridServices GridServer;
45 public IInventoryServices InventoryServer; 45 public IInventoryServices InventoryServer;
46 public IInterRegionCommunications InterRegion; 46 public IInterRegionCommunications InterRegion;
47 public UserProfileCache UserProfilesCache; 47 public UserProfileCache UserProfiles;
48 public AssetCache AssetCache; 48 public AssetCache AssetCache;
49 49
50 public NetworkServersInfo ServersInfo; 50 public NetworkServersInfo ServersInfo;
@@ -52,21 +52,28 @@ namespace OpenSim.Framework.Communications
52 { 52 {
53 ServersInfo = serversInfo; 53 ServersInfo = serversInfo;
54 this.AssetCache = assetCache; 54 this.AssetCache = assetCache;
55 UserProfilesCache = new UserProfileCache(this); 55 UserProfiles = new UserProfileCache(this);
56 } 56 }
57 57
58 #region Packet Handlers 58 #region Packet Handlers
59 public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client) 59 public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
60 { 60 {
61 UserProfileData profileData = this.UserServer.GetUserProfile(uuid); 61 if (uuid == UserProfiles.libraryRoot.agentID)
62 if (profileData != null)
63 { 62 {
64 LLUUID profileId = profileData.UUID; 63 remote_client.SendNameReply(uuid , "Mr" , "OpenSim");
65 string firstname = profileData.username; 64 }
66 string lastname = profileData.surname; 65 else
66 {
67 UserProfileData profileData = this.UserServer.GetUserProfile(uuid);
68 if (profileData != null)
69 {
70 LLUUID profileId = profileData.UUID;
71 string firstname = profileData.username;
72 string lastname = profileData.surname;
67 73
68 remote_client.SendNameReply(profileId, firstname, lastname); 74 remote_client.SendNameReply(profileId, firstname, lastname);
69 } 75 }
76 }
70 } 77 }
71 78
72 #endregion 79 #endregion
diff --git a/OpenSim/Framework/Data/InventoryData.cs b/OpenSim/Framework/Data/InventoryData.cs
index 87013cf..d7130f4 100644
--- a/OpenSim/Framework/Data/InventoryData.cs
+++ b/OpenSim/Framework/Data/InventoryData.cs
@@ -101,7 +101,7 @@ namespace OpenSim.Framework.Data
101 /// <summary> 101 /// <summary>
102 /// Tyep of Items normally stored in this folder 102 /// Tyep of Items normally stored in this folder
103 /// </summary> 103 /// </summary>
104 public ushort type; 104 public short type;
105 /// <summary> 105 /// <summary>
106 /// 106 ///
107 /// </summary> 107 /// </summary>
diff --git a/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs b/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs
index d407cdb..49e2e6f 100644
--- a/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs
+++ b/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Framework.InventoryServiceBase
50 } 50 }
51 51
52 /// <summary> 52 /// <summary>
53 /// 53 /// Returns the root folder plus any folders in root (so down one level in the Inventory folders tree)
54 /// </summary> 54 /// </summary>
55 /// <param name="userID"></param> 55 /// <param name="userID"></param>
56 /// <returns></returns> 56 /// <returns></returns>
diff --git a/OpenSim/Framework/UserManager/LoginResponse.cs b/OpenSim/Framework/UserManager/LoginResponse.cs
index 4d5ec5f..b5a4184 100644
--- a/OpenSim/Framework/UserManager/LoginResponse.cs
+++ b/OpenSim/Framework/UserManager/LoginResponse.cs
@@ -27,6 +27,8 @@ namespace OpenSim.Framework.UserManagement
27 private ArrayList inventoryRoot; 27 private ArrayList inventoryRoot;
28 private ArrayList initialOutfit; 28 private ArrayList initialOutfit;
29 private ArrayList agentInventory; 29 private ArrayList agentInventory;
30 private ArrayList inventoryLibraryOwner;
31 private ArrayList inventoryLibrary;
30 32
31 private UserInfo userProfile; 33 private UserInfo userProfile;
32 34
@@ -87,6 +89,8 @@ namespace OpenSim.Framework.UserManagement
87 this.inventoryRoot = new ArrayList(); 89 this.inventoryRoot = new ArrayList();
88 this.initialOutfit = new ArrayList(); 90 this.initialOutfit = new ArrayList();
89 this.agentInventory = new ArrayList(); 91 this.agentInventory = new ArrayList();
92 this.inventoryLibrary = new ArrayList();
93 this.inventoryLibraryOwner = new ArrayList();
90 94
91 this.xmlRpcResponse = new XmlRpcResponse(); 95 this.xmlRpcResponse = new XmlRpcResponse();
92 this.defaultXmlRpcResponse = new XmlRpcResponse(); 96 this.defaultXmlRpcResponse = new XmlRpcResponse();
@@ -234,10 +238,10 @@ namespace OpenSim.Framework.UserManagement
234 responseData["ui-config"] = this.uiConfig; 238 responseData["ui-config"] = this.uiConfig;
235 239
236 responseData["inventory-skeleton"] = this.agentInventory; 240 responseData["inventory-skeleton"] = this.agentInventory;
237 responseData["inventory-skel-lib"] = new ArrayList(); // todo 241 responseData["inventory-skel-lib"] = this.inventoryLibrary;
238 responseData["inventory-root"] = this.inventoryRoot; 242 responseData["inventory-root"] = this.inventoryRoot;
239 responseData["gestures"] = new ArrayList(); // todo 243 responseData["gestures"] = new ArrayList(); // todo
240 responseData["inventory-lib-owner"] = new ArrayList(); // todo 244 responseData["inventory-lib-owner"] = this.inventoryLibraryOwner;
241 responseData["initial-outfit"] = this.initialOutfit; 245 responseData["initial-outfit"] = this.initialOutfit;
242 responseData["start_location"] = this.startLocation; 246 responseData["start_location"] = this.startLocation;
243 responseData["seed_capability"] = this.seedCapability; 247 responseData["seed_capability"] = this.seedCapability;
@@ -600,6 +604,30 @@ namespace OpenSim.Framework.UserManagement
600 } 604 }
601 } 605 }
602 606
607 public ArrayList InventoryLibrary
608 {
609 get
610 {
611 return this.inventoryLibrary;
612 }
613 set
614 {
615 this.inventoryLibrary = value;
616 }
617 }
618
619 public ArrayList InventoryLibraryOwner
620 {
621 get
622 {
623 return this.inventoryLibraryOwner;
624 }
625 set
626 {
627 this.inventoryLibraryOwner = value;
628 }
629 }
630
603 public string Home 631 public string Home
604 { 632 {
605 get 633 get
diff --git a/OpenSim/Framework/UserManager/UserManagerBase.cs b/OpenSim/Framework/UserManager/UserManagerBase.cs
index a103f25..1acafeb 100644
--- a/OpenSim/Framework/UserManager/UserManagerBase.cs
+++ b/OpenSim/Framework/UserManager/UserManagerBase.cs
@@ -347,6 +347,38 @@ namespace OpenSim.Framework.UserManagement
347 } 347 }
348 348
349 /// <summary> 349 /// <summary>
350 ///
351 /// </summary>
352 /// <returns></returns>
353 protected virtual ArrayList GetInventoryLibrary()
354 {
355 //return new ArrayList();
356 Hashtable TempHash = new Hashtable();
357 TempHash["name"] = "OpenSim Library";
358 TempHash["parent_id"] = LLUUID.Zero.ToStringHyphenated();
359 TempHash["version"] = "1";
360 TempHash["type_default"] = "-1";
361 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
362 ArrayList temp = new ArrayList();
363 temp.Add(TempHash);
364 return temp;
365 }
366
367 /// <summary>
368 ///
369 /// </summary>
370 /// <returns></returns>
371 protected virtual ArrayList GetLibraryOwner()
372 {
373 //for now create random inventory library owner
374 Hashtable TempHash = new Hashtable();
375 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
376 ArrayList inventoryLibOwner = new ArrayList();
377 inventoryLibOwner.Add(TempHash);
378 return inventoryLibOwner;
379 }
380
381 /// <summary>
350 /// Customises the login response and fills in missing values. 382 /// Customises the login response and fills in missing values.
351 /// </summary> 383 /// </summary>
352 /// <param name="response">The existing response</param> 384 /// <param name="response">The existing response</param>
@@ -446,6 +478,8 @@ namespace OpenSim.Framework.UserManagement
446 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated(); 478 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated();
447 logResponse.InventoryRoot = InventoryRoot; 479 logResponse.InventoryRoot = InventoryRoot;
448 logResponse.InventorySkeleton = AgentInventoryArray; 480 logResponse.InventorySkeleton = AgentInventoryArray;
481 logResponse.InventoryLibrary = this.GetInventoryLibrary();
482 logResponse.InventoryLibraryOwner = this.GetLibraryOwner();
449 logResponse.CircuitCode = (Int32)circode; 483 logResponse.CircuitCode = (Int32)circode;
450 //logResponse.RegionX = 0; //overwritten 484 //logResponse.RegionX = 0; //overwritten
451 //logResponse.RegionY = 0; //overwritten 485 //logResponse.RegionY = 0; //overwritten
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
index 27def3d..11c2030 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
@@ -669,7 +669,7 @@ namespace OpenSim.Region.Environment.Scenes
669 /// <param name="nextOwnerMask"></param> 669 /// <param name="nextOwnerMask"></param>
670 public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transActionID, LLUUID folderID, uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask) 670 public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transActionID, LLUUID folderID, uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask)
671 { 671 {
672 CachedUserInfo userInfo = commsManager.UserProfilesCache.GetUserDetails(remoteClient.AgentId); 672 CachedUserInfo userInfo = commsManager.UserProfiles.GetUserDetails(remoteClient.AgentId);
673 if (userInfo != null) 673 if (userInfo != null)
674 { 674 {
675 AssetBase asset = new AssetBase(); 675 AssetBase asset = new AssetBase();
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 9849145..0e25e54 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -546,7 +546,7 @@ namespace OpenSim.Region.Environment.Scenes
546 m_estateManager.sendRegionHandshake(client); 546 m_estateManager.sendRegionHandshake(client);
547 CreateAndAddScenePresence(client); 547 CreateAndAddScenePresence(client);
548 m_LandManager.sendParcelOverlay(client); 548 m_LandManager.sendParcelOverlay(client);
549 // commsManager.UserProfilesCache.AddNewUser(client.AgentId); 549 //commsManager.UserProfiles.AddNewUser(client.AgentId);
550 } 550 }
551 551
552 protected virtual void SubscribeToClientEvents(IClientAPI client) 552 protected virtual void SubscribeToClientEvents(IClientAPI client)
@@ -591,9 +591,9 @@ namespace OpenSim.Region.Environment.Scenes
591 client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage); 591 client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage);
592 592
593 // client.OnCreateNewInventoryItem += CreateNewInventoryItem; 593 // client.OnCreateNewInventoryItem += CreateNewInventoryItem;
594 // client.OnCreateNewInventoryFolder += commsManager.UserProfilesCache.HandleCreateInventoryFolder; 594 //client.OnCreateNewInventoryFolder += commsManager.UserProfiles.HandleCreateInventoryFolder;
595 // client.OnFetchInventoryDescendents += commsManager.UserProfilesCache.HandleFecthInventoryDescendents; 595 client.OnFetchInventoryDescendents += commsManager.UserProfiles.HandleFecthInventoryDescendents;
596 // client.OnRequestTaskInventory += RequestTaskInventory; 596 client.OnRequestTaskInventory += RequestTaskInventory;
597 } 597 }
598 598
599 protected ScenePresence CreateAndAddScenePresence(IClientAPI client) 599 protected ScenePresence CreateAndAddScenePresence(IClientAPI client)
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
index 1ef09fc..4093f51 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
@@ -1,74 +1,74 @@
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;
32using System.Drawing; 32using System.Drawing;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 class Raster 36 class Raster
37 { 37 {
38 int w; 38 int w;
39 int h; 39 int h;
40 Bitmap bmp; 40 Bitmap bmp;
41 41
42 public Raster(int width, int height) 42 public Raster(int width, int height)
43 { 43 {
44 w = width; 44 w = width;
45 h = height; 45 h = height;
46 bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 46 bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
47 } 47 }
48 48
49 public Channel ToChannel() 49 public Channel ToChannel()
50 { 50 {
51 Channel chan = new Channel(bmp.Width, bmp.Height); 51 Channel chan = new Channel(bmp.Width, bmp.Height);
52 52
53 int x, y; 53 int x, y;
54 for (x = 0; x < bmp.Width; x++) 54 for (x = 0; x < bmp.Width; x++)
55 { 55 {
56 for (y = 0; y < bmp.Height; y++) 56 for (y = 0; y < bmp.Height; y++)
57 { 57 {
58 Color val = bmp.GetPixel(x, y); 58 Color val = bmp.GetPixel(x, y);
59 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; 59 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
60 } 60 }
61 } 61 }
62 62
63 return chan; 63 return chan;
64 } 64 }
65 65
66 public void DrawText(string txt, string font, double size) 66 public void DrawText(string txt, string font, double size)
67 { 67 {
68 Graphics gd = Graphics.FromImage(bmp); 68 Graphics gd = Graphics.FromImage(bmp);
69 //gd.DrawString(txt, 69 //gd.DrawString(txt,
70 70
71 71
72 } 72 }
73 } 73 }
74} 74}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
index 6dfee1f..2e84409 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
@@ -1,66 +1,66 @@
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
33 33
34/* Channel 34/* Channel
35 * A channel is a single heightmap array 35 * A channel is a single heightmap array
36 * */ 36 * */
37 37
38namespace libTerrain 38namespace libTerrain
39{ 39{
40 partial class Channel 40 partial class Channel
41 { 41 {
42 public double[,] map; 42 public double[,] map;
43 public int[,] diff; 43 public int[,] diff;
44 public int w; 44 public int w;
45 public int h; 45 public int h;
46 46
47 public int seed = 1338; // One better than 1337 47 public int seed = 1338; // One better than 1337
48 48
49 public Channel() 49 public Channel()
50 { 50 {
51 w = 256; 51 w = 256;
52 h = 256; 52 h = 256;
53 map = new double[w, h]; 53 map = new double[w, h];
54 diff = new int[(int)(w / 16), (int)(h / 16)]; 54 diff = new int[(int)(w / 16), (int)(h / 16)];
55 } 55 }
56 56
57 public Channel(int width, int height) 57 public Channel(int width, int height)
58 { 58 {
59 w = width; 59 w = width;
60 h = height; 60 h = height;
61 map = new double[w, h]; 61 map = new double[w, h];
62 diff = new int[(int)(w / 16), (int)(h / 16)]; 62 diff = new int[(int)(w / 16), (int)(h / 16)];
63 } 63 }
64 64
65 } 65 }
66} 66}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
index 1750418..b0182dc 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
@@ -1,277 +1,277 @@
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
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 public partial class Channel 36 public partial class Channel
37 { 37 {
38 public int GetWidth() 38 public int GetWidth()
39 { 39 {
40 return w; 40 return w;
41 } 41 }
42 public int GetHeight() 42 public int GetHeight()
43 { 43 {
44 return h; 44 return h;
45 } 45 }
46 46
47 public Channel Copy() 47 public Channel Copy()
48 { 48 {
49 Channel x = new Channel(w, h); 49 Channel x = new Channel(w, h);
50 x.map = (double[,])this.map.Clone(); 50 x.map = (double[,])this.map.Clone();
51 return x; 51 return x;
52 } 52 }
53 53
54 public void SetDiff() 54 public void SetDiff()
55 { 55 {
56 SetDiff(1); 56 SetDiff(1);
57 } 57 }
58 58
59 public void SetDiff(int val) 59 public void SetDiff(int val)
60 { 60 {
61 for (int x = 0; x < w / 16; x++) 61 for (int x = 0; x < w / 16; x++)
62 { 62 {
63 for (int y = 0; y < h / 16; y++) 63 for (int y = 0; y < h / 16; y++)
64 { 64 {
65 diff[x, y] = val; 65 diff[x, y] = val;
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 public void SetDiff(int x, int y) 70 public void SetDiff(int x, int y)
71 { 71 {
72 diff[x / 16, y / 16]++; 72 diff[x / 16, y / 16]++;
73 } 73 }
74 74
75 public void Set(int x, int y, double val) 75 public void Set(int x, int y, double val)
76 { 76 {
77 if (x >= w) 77 if (x >= w)
78 throw new Exception("Bounds error while setting pixel (width)"); 78 throw new Exception("Bounds error while setting pixel (width)");
79 if (y >= h) 79 if (y >= h)
80 throw new Exception("Bounds error while setting pixel (height)"); 80 throw new Exception("Bounds error while setting pixel (height)");
81 if (x < 0) 81 if (x < 0)
82 throw new Exception("Bounds error while setting pixel (width)"); 82 throw new Exception("Bounds error while setting pixel (width)");
83 if (y < 0) 83 if (y < 0)
84 throw new Exception("Bounds error while setting pixel (height)"); 84 throw new Exception("Bounds error while setting pixel (height)");
85 85
86 if (map[x, y] != val) 86 if (map[x, y] != val)
87 { 87 {
88 SetDiff(x, y); 88 SetDiff(x, y);
89 89
90 map[x, y] = val; 90 map[x, y] = val;
91 } 91 }
92 } 92 }
93 93
94 public void SetClip(int x, int y, double val) 94 public void SetClip(int x, int y, double val)
95 { 95 {
96 SetDiff(x, y); 96 SetDiff(x, y);
97 97
98 if (x >= w) 98 if (x >= w)
99 throw new Exception("Bounds error while setting pixel (width)"); 99 throw new Exception("Bounds error while setting pixel (width)");
100 if (y >= h) 100 if (y >= h)
101 throw new Exception("Bounds error while setting pixel (height)"); 101 throw new Exception("Bounds error while setting pixel (height)");
102 if (x < 0) 102 if (x < 0)
103 throw new Exception("Bounds error while setting pixel (width)"); 103 throw new Exception("Bounds error while setting pixel (width)");
104 if (y < 0) 104 if (y < 0)
105 throw new Exception("Bounds error while setting pixel (height)"); 105 throw new Exception("Bounds error while setting pixel (height)");
106 106
107 if (val > 1.0) 107 if (val > 1.0)
108 val = 1.0; 108 val = 1.0;
109 if (val < 0.0) 109 if (val < 0.0)
110 val = 0.0; 110 val = 0.0;
111 111
112 map[x, y] = val; 112 map[x, y] = val;
113 } 113 }
114 114
115 private double GetBilinearInterpolate(double x, double y) 115 private double GetBilinearInterpolate(double x, double y)
116 { 116 {
117 if (x > w - 2.0) 117 if (x > w - 2.0)
118 x = w - 2.0; 118 x = w - 2.0;
119 if (y > h - 2.0) 119 if (y > h - 2.0)
120 y = h - 2.0; 120 y = h - 2.0;
121 if (x < 0.0) 121 if (x < 0.0)
122 x = 0.0; 122 x = 0.0;
123 if (y < 0.0) 123 if (y < 0.0)
124 y = 0.0; 124 y = 0.0;
125 125
126 int stepSize = 1; 126 int stepSize = 1;
127 double h00 = Get((int)x, (int)y); 127 double h00 = Get((int)x, (int)y);
128 double h10 = Get((int)x + stepSize, (int)y); 128 double h10 = Get((int)x + stepSize, (int)y);
129 double h01 = Get((int)x, (int)y + stepSize); 129 double h01 = Get((int)x, (int)y + stepSize);
130 double h11 = Get((int)x + stepSize, (int)y + stepSize); 130 double h11 = Get((int)x + stepSize, (int)y + stepSize);
131 double h1 = h00; 131 double h1 = h00;
132 double h2 = h10; 132 double h2 = h10;
133 double h3 = h01; 133 double h3 = h01;
134 double h4 = h11; 134 double h4 = h11;
135 double a00 = h1; 135 double a00 = h1;
136 double a10 = h2 - h1; 136 double a10 = h2 - h1;
137 double a01 = h3 - h1; 137 double a01 = h3 - h1;
138 double a11 = h1 - h2 - h3 + h4; 138 double a11 = h1 - h2 - h3 + h4;
139 double partialx = x - (int)x; 139 double partialx = x - (int)x;
140 double partialz = y - (int)y; 140 double partialz = y - (int)y;
141 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); 141 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
142 return hi; 142 return hi;
143 } 143 }
144 144
145 public double Get(int x, int y) 145 public double Get(int x, int y)
146 { 146 {
147 if (x >= w) 147 if (x >= w)
148 x = w - 1; 148 x = w - 1;
149 if (y >= h) 149 if (y >= h)
150 y = h - 1; 150 y = h - 1;
151 if (x < 0) 151 if (x < 0)
152 x = 0; 152 x = 0;
153 if (y < 0) 153 if (y < 0)
154 y = 0; 154 y = 0;
155 return map[x, y]; 155 return map[x, y];
156 } 156 }
157 157
158 public void SetWrap(int x, int y, double val) 158 public void SetWrap(int x, int y, double val)
159 { 159 {
160 SetDiff(x, y); 160 SetDiff(x, y);
161 161
162 map[x % w, y % h] = val; 162 map[x % w, y % h] = val;
163 } 163 }
164 164
165 public void SetWrapClip(int x, int y, double val) 165 public void SetWrapClip(int x, int y, double val)
166 { 166 {
167 SetDiff(x, y); 167 SetDiff(x, y);
168 168
169 if (val > 1.0) 169 if (val > 1.0)
170 val = 1.0; 170 val = 1.0;
171 if (val < 0.0) 171 if (val < 0.0)
172 val = 0.0; 172 val = 0.0;
173 173
174 map[x % w, y % h] = val; 174 map[x % w, y % h] = val;
175 } 175 }
176 176
177 public void Fill(double val) 177 public void Fill(double val)
178 { 178 {
179 SetDiff(); 179 SetDiff();
180 180
181 int x, y; 181 int x, y;
182 for (x = 0; x < w; x++) 182 for (x = 0; x < w; x++)
183 { 183 {
184 for (y = 0; y < h; y++) 184 for (y = 0; y < h; y++)
185 { 185 {
186 map[x, y] = val; 186 map[x, y] = val;
187 } 187 }
188 } 188 }
189 } 189 }
190 190
191 public void Fill(double min, double max, double val) 191 public void Fill(double min, double max, double val)
192 { 192 {
193 SetDiff(); 193 SetDiff();
194 194
195 int x, y; 195 int x, y;
196 for (x = 0; x < w; x++) 196 for (x = 0; x < w; x++)
197 { 197 {
198 for (y = 0; y < h; y++) 198 for (y = 0; y < h; y++)
199 { 199 {
200 if (map[x, y] >= min && map[x, y] <= max) 200 if (map[x, y] >= min && map[x, y] <= max)
201 map[x, y] = val; 201 map[x, y] = val;
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 public double FindMax() 206 public double FindMax()
207 { 207 {
208 int x, y; 208 int x, y;
209 double max = double.MinValue; 209 double max = double.MinValue;
210 210
211 for (x = 0; x < w; x++) 211 for (x = 0; x < w; x++)
212 { 212 {
213 for (y = 0; y < h; y++) 213 for (y = 0; y < h; y++)
214 { 214 {
215 if (map[x, y] > max) 215 if (map[x, y] > max)
216 max = map[x, y]; 216 max = map[x, y];
217 } 217 }
218 } 218 }
219 219
220 return max; 220 return max;
221 } 221 }
222 222
223 public double FindMin() 223 public double FindMin()
224 { 224 {
225 int x, y; 225 int x, y;
226 double min = double.MaxValue; 226 double min = double.MaxValue;
227 227
228 for (x = 0; x < w; x++) 228 for (x = 0; x < w; x++)
229 { 229 {
230 for (y = 0; y < h; y++) 230 for (y = 0; y < h; y++)
231 { 231 {
232 if (map[x, y] < min) 232 if (map[x, y] < min)
233 min = map[x, y]; 233 min = map[x, y];
234 } 234 }
235 } 235 }
236 236
237 return min; 237 return min;
238 } 238 }
239 239
240 public double Sum() 240 public double Sum()
241 { 241 {
242 int x, y; 242 int x, y;
243 double sum = 0.0; 243 double sum = 0.0;
244 244
245 for (x = 0; x < w; x++) 245 for (x = 0; x < w; x++)
246 { 246 {
247 for (y = 0; y < h; y++) 247 for (y = 0; y < h; y++)
248 { 248 {
249 sum += map[x, y]; 249 sum += map[x, y];
250 } 250 }
251 } 251 }
252 252
253 return sum; 253 return sum;
254 } 254 }
255 255
256 public double Avg() 256 public double Avg()
257 { 257 {
258 return Sum() / (w * h); 258 return Sum() / (w * h);
259 } 259 }
260 260
261 public bool ContainsNaN() 261 public bool ContainsNaN()
262 { 262 {
263 int x, y; 263 int x, y;
264 for (x = 0; x < w; x++) 264 for (x = 0; x < w; x++)
265 { 265 {
266 for (y = 0; y < h; y++) 266 for (y = 0; y < h; y++)
267 { 267 {
268 double elm = map[x, y]; 268 double elm = map[x, y];
269 269
270 if (Double.IsNaN(elm)) 270 if (Double.IsNaN(elm))
271 return true; 271 return true;
272 } 272 }
273 } 273 }
274 return false; 274 return false;
275 } 275 }
276 } 276 }
277} 277}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
index 48f02e8..713ae23 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
@@ -1,149 +1,149 @@
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
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 /// <summary> 38 /// <summary>
39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. 39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
40 /// </summary> 40 /// </summary>
41 /// <param name="rx">The X coordinate of the terrain mask</param> 41 /// <param name="rx">The X coordinate of the terrain mask</param>
42 /// <param name="ry">The Y coordinate of the terrain mask</param> 42 /// <param name="ry">The Y coordinate of the terrain mask</param>
43 /// <param name="size">The size of the terrain mask</param> 43 /// <param name="size">The size of the terrain mask</param>
44 /// <param name="amount">The scale of the terrain mask</param> 44 /// <param name="amount">The scale of the terrain mask</param>
45 public void Flatten(double rx, double ry, double size, double amount) 45 public void Flatten(double rx, double ry, double size, double amount)
46 { 46 {
47 FlattenSlow(rx, ry, size, amount); 47 FlattenSlow(rx, ry, size, amount);
48 } 48 }
49 49
50 private void FlattenSlow(double rx, double ry, double size, double amount) 50 private void FlattenSlow(double rx, double ry, double size, double amount)
51 { 51 {
52 // Generate the mask 52 // Generate the mask
53 Channel temp = new Channel(w, h); 53 Channel temp = new Channel(w, h);
54 temp.Fill(0); 54 temp.Fill(0);
55 temp.Raise(rx, ry, size, amount); 55 temp.Raise(rx, ry, size, amount);
56 temp.Normalise(); 56 temp.Normalise();
57 double total_mod = temp.Sum(); 57 double total_mod = temp.Sum();
58 58
59 // Establish the average height under the area 59 // Establish the average height under the area
60 Channel newmap = new Channel(w, h); 60 Channel newmap = new Channel(w, h);
61 newmap.map = (double[,])map.Clone(); 61 newmap.map = (double[,])map.Clone();
62 62
63 newmap *= temp; 63 newmap *= temp;
64 64
65 double total_terrain = newmap.Sum(); 65 double total_terrain = newmap.Sum();
66 double avg_height = total_terrain / total_mod; 66 double avg_height = total_terrain / total_mod;
67 67
68 // Create a flat terrain using the average height 68 // Create a flat terrain using the average height
69 Channel flat = new Channel(w, h); 69 Channel flat = new Channel(w, h);
70 flat.Fill(avg_height); 70 flat.Fill(avg_height);
71 71
72 // Blend the current terrain with the average height terrain 72 // Blend the current terrain with the average height terrain
73 // using the "raised" empty terrain as a mask 73 // using the "raised" empty terrain as a mask
74 Blend(flat, temp); 74 Blend(flat, temp);
75 75
76 } 76 }
77 77
78 private void FlattenFast(double rx, double ry, double size, double amount) 78 private void FlattenFast(double rx, double ry, double size, double amount)
79 { 79 {
80 int x, y; 80 int x, y;
81 double avg = 0; 81 double avg = 0;
82 double div = 0; 82 double div = 0;
83 83
84 int minX = Math.Max(0, (int)(rx - (size + 1))); 84 int minX = Math.Max(0, (int)(rx - (size + 1)));
85 int maxX = Math.Min(w, (int)(rx + (size + 1))); 85 int maxX = Math.Min(w, (int)(rx + (size + 1)));
86 int minY = Math.Max(0, (int)(ry - (size + 1))); 86 int minY = Math.Max(0, (int)(ry - (size + 1)));
87 int maxY = Math.Min(h, (int)(ry + (size + 1))); 87 int maxY = Math.Min(h, (int)(ry + (size + 1)));
88 88
89 for (x = minX; x < maxX; x++) 89 for (x = minX; x < maxX; x++)
90 { 90 {
91 for (y = minY; y < maxY; y++) 91 for (y = minY; y < maxY; y++)
92 { 92 {
93 double z = size; 93 double z = size;
94 z *= z; 94 z *= z;
95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
96 96
97 if (z < 0) 97 if (z < 0)
98 z = 0; 98 z = 0;
99 99
100 avg += z * amount; 100 avg += z * amount;
101 div += z; 101 div += z;
102 } 102 }
103 } 103 }
104 104
105 double height = avg / div; 105 double height = avg / div;
106 106
107 for (x = minX; x < maxX; x++) 107 for (x = minX; x < maxX; x++)
108 { 108 {
109 for (y = minY; y < maxY; y++) 109 for (y = minY; y < maxY; y++)
110 { 110 {
111 double z = size; 111 double z = size;
112 z *= z; 112 z *= z;
113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
114 114
115 if (z < 0) 115 if (z < 0)
116 z = 0; 116 z = 0;
117 117
118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z)); 118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z));
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 public void Flatten(Channel mask, double amount) 123 public void Flatten(Channel mask, double amount)
124 { 124 {
125 // Generate the mask 125 // Generate the mask
126 Channel temp = mask * amount; 126 Channel temp = mask * amount;
127 temp.Clip(0, 1); // Cut off out-of-bounds values 127 temp.Clip(0, 1); // Cut off out-of-bounds values
128 128
129 double total_mod = temp.Sum(); 129 double total_mod = temp.Sum();
130 130
131 // Establish the average height under the area 131 // Establish the average height under the area
132 Channel map = new Channel(w, h); 132 Channel map = new Channel(w, h);
133 map.map = (double[,])this.map.Clone(); 133 map.map = (double[,])this.map.Clone();
134 134
135 map *= temp; 135 map *= temp;
136 136
137 double total_terrain = map.Sum(); 137 double total_terrain = map.Sum();
138 double avg_height = total_terrain / total_mod; 138 double avg_height = total_terrain / total_mod;
139 139
140 // Create a flat terrain using the average height 140 // Create a flat terrain using the average height
141 Channel flat = new Channel(w, h); 141 Channel flat = new Channel(w, h);
142 flat.Fill(avg_height); 142 flat.Fill(avg_height);
143 143
144 // Blend the current terrain with the average height terrain 144 // Blend the current terrain with the average height terrain
145 // using the "raised" empty terrain as a mask 145 // using the "raised" empty terrain as a mask
146 Blend(flat, temp); 146 Blend(flat, temp);
147 } 147 }
148 } 148 }
149} \ No newline at end of file 149} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
index 1d04a4f..64d175c 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
@@ -1,139 +1,139 @@
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
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 /// <summary> 38 /// <summary>
39 /// Raises land around the selection 39 /// Raises land around the selection
40 /// </summary> 40 /// </summary>
41 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 41 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
42 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 42 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
43 /// <param name="size">The radius of the dimple</param> 43 /// <param name="size">The radius of the dimple</param>
44 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 44 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
45 public void Raise(double rx, double ry, double size, double amount) 45 public void Raise(double rx, double ry, double size, double amount)
46 { 46 {
47 RaiseSphere(rx, ry, size, amount); 47 RaiseSphere(rx, ry, size, amount);
48 } 48 }
49 49
50 /// <summary> 50 /// <summary>
51 /// Raises land in a sphere around the selection 51 /// Raises land in a sphere around the selection
52 /// </summary> 52 /// </summary>
53 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 53 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
54 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 54 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
55 /// <param name="size">The radius of the sphere dimple</param> 55 /// <param name="size">The radius of the sphere dimple</param>
56 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 56 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
57 public void RaiseSphere(double rx, double ry, double size, double amount) 57 public void RaiseSphere(double rx, double ry, double size, double amount)
58 { 58 {
59 int x, y; 59 int x, y;
60 for (x = 0; x < w; x++) 60 for (x = 0; x < w; x++)
61 { 61 {
62 for (y = 0; y < h; y++) 62 for (y = 0; y < h; y++)
63 { 63 {
64 double z = size; 64 double z = size;
65 z *= z; 65 z *= z;
66 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 66 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
67 67
68 if (z < 0) 68 if (z < 0)
69 z = 0; 69 z = 0;
70 70
71 Set(x, y, map[x, y] + (z * amount)); 71 Set(x, y, map[x, y] + (z * amount));
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 /// <summary> 76 /// <summary>
77 /// Raises land in a cone around the selection 77 /// Raises land in a cone around the selection
78 /// </summary> 78 /// </summary>
79 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 79 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
80 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 80 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
81 /// <param name="size">The radius of the cone</param> 81 /// <param name="size">The radius of the cone</param>
82 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 82 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
83 public void RaiseCone(double rx, double ry, double size, double amount) 83 public void RaiseCone(double rx, double ry, double size, double amount)
84 { 84 {
85 int x, y; 85 int x, y;
86 for (x = 0; x < w; x++) 86 for (x = 0; x < w; x++)
87 { 87 {
88 for (y = 0; y < h; y++) 88 for (y = 0; y < h; y++)
89 { 89 {
90 double z = size; 90 double z = size;
91 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 91 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
92 92
93 if (z < 0) 93 if (z < 0)
94 z = 0; 94 z = 0;
95 95
96 Set(x, y, map[x, y] + (z * amount)); 96 Set(x, y, map[x, y] + (z * amount));
97 } 97 }
98 } 98 }
99 } 99 }
100 100
101 /// <summary> 101 /// <summary>
102 /// Lowers land in a sphere around the selection 102 /// Lowers land in a sphere around the selection
103 /// </summary> 103 /// </summary>
104 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> 104 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
105 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> 105 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
106 /// <param name="size">The radius of the sphere dimple</param> 106 /// <param name="size">The radius of the sphere dimple</param>
107 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> 107 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
108 public void Lower(double rx, double ry, double size, double amount) 108 public void Lower(double rx, double ry, double size, double amount)
109 { 109 {
110 LowerSphere(rx, ry, size, amount); 110 LowerSphere(rx, ry, size, amount);
111 } 111 }
112 112
113 /// <summary> 113 /// <summary>
114 /// Lowers land in a sphere around the selection 114 /// Lowers land in a sphere around the selection
115 /// </summary> 115 /// </summary>
116 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> 116 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
117 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> 117 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
118 /// <param name="size">The radius of the sphere dimple</param> 118 /// <param name="size">The radius of the sphere dimple</param>
119 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> 119 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
120 public void LowerSphere(double rx, double ry, double size, double amount) 120 public void LowerSphere(double rx, double ry, double size, double amount)
121 { 121 {
122 int x, y; 122 int x, y;
123 for (x = 0; x < w; x++) 123 for (x = 0; x < w; x++)
124 { 124 {
125 for (y = 0; y < h; y++) 125 for (y = 0; y < h; y++)
126 { 126 {
127 double z = size; 127 double z = size;
128 z *= z; 128 z *= z;
129 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 129 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
130 130
131 if (z < 0) 131 if (z < 0)
132 z = 0; 132 z = 0;
133 133
134 Set(x, y, map[x, y] - (z * amount)); 134 Set(x, y, map[x, y] - (z * amount));
135 } 135 }
136 } 136 }
137 } 137 }
138 } 138 }
139} \ No newline at end of file 139} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
index c0173c0..cfefb6b 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
@@ -1,77 +1,77 @@
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;
32using System.Drawing; 32using System.Drawing;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 public Channel LoadImage(string filename) 38 public Channel LoadImage(string filename)
39 { 39 {
40 SetDiff(); 40 SetDiff();
41 41
42 Bitmap bit = new Bitmap(filename); 42 Bitmap bit = new Bitmap(filename);
43 Channel chan = new Channel(bit.Width, bit.Height); 43 Channel chan = new Channel(bit.Width, bit.Height);
44 44
45 int x, y; 45 int x, y;
46 for (x = 0; x < bit.Width; x++) 46 for (x = 0; x < bit.Width; x++)
47 { 47 {
48 for (y = 0; y < bit.Height; y++) 48 for (y = 0; y < bit.Height; y++)
49 { 49 {
50 Color val = bit.GetPixel(x, y); 50 Color val = bit.GetPixel(x, y);
51 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; 51 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
52 } 52 }
53 } 53 }
54 54
55 return chan; 55 return chan;
56 } 56 }
57 57
58 public void SaveImage(string filename) 58 public void SaveImage(string filename)
59 { 59 {
60 Channel outmap = this.Copy(); 60 Channel outmap = this.Copy();
61 outmap.Normalise(); 61 outmap.Normalise();
62 62
63 Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 63 Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
64 int x, y; 64 int x, y;
65 for (x = 0; x < w; x++) 65 for (x = 0; x < w; x++)
66 { 66 {
67 for (y = 0; y < h; y++) 67 for (y = 0; y < h; y++)
68 { 68 {
69 int val = Math.Min(255, (int)(outmap.map[x,y] * 255)); 69 int val = Math.Min(255, (int)(outmap.map[x,y] * 255));
70 Color col = Color.FromArgb(val,val,val); 70 Color col = Color.FromArgb(val,val,val);
71 bit.SetPixel(x, y, col); 71 bit.SetPixel(x, y, col);
72 } 72 }
73 } 73 }
74 bit.Save(filename); 74 bit.Save(filename);
75 } 75 }
76 } 76 }
77} 77}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
index 13dd1bc..2d42759 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
@@ -1,145 +1,145 @@
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 /// <summary> 37 /// <summary>
38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256 38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h 39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
40 /// </summary> 40 /// </summary>
41 /// <param name="val"></param> 41 /// <param name="val"></param>
42 /// <param name="w"></param> 42 /// <param name="w"></param>
43 /// <param name="h"></param> 43 /// <param name="h"></param>
44 /// <returns></returns> 44 /// <returns></returns>
45 private int[] RadialEdge256(int val) 45 private int[] RadialEdge256(int val)
46 { 46 {
47 // Four cases: 47 // Four cases:
48 // 1. 000..255 return 0,val 48 // 1. 000..255 return 0,val
49 // 2. 256..511 return val - 256,255 49 // 2. 256..511 return val - 256,255
50 // 3. 512..767 return 255, val - 511 50 // 3. 512..767 return 255, val - 511
51 // 4. 768..1023 return val - 768,0 51 // 4. 768..1023 return val - 768,0
52 52
53 int[] ret = new int[2]; 53 int[] ret = new int[2];
54 54
55 if (val < 256) 55 if (val < 256)
56 { 56 {
57 ret[0] = 0; 57 ret[0] = 0;
58 ret[1] = val; 58 ret[1] = val;
59 return ret; 59 return ret;
60 } 60 }
61 if (val < 512) 61 if (val < 512)
62 { 62 {
63 ret[0] = (val % 256); 63 ret[0] = (val % 256);
64 ret[1] = 255; 64 ret[1] = 255;
65 return ret; 65 return ret;
66 } 66 }
67 if (val < 768) 67 if (val < 768)
68 { 68 {
69 ret[0] = 255; 69 ret[0] = 255;
70 ret[1] = 255 - (val % 256); 70 ret[1] = 255 - (val % 256);
71 return ret; 71 return ret;
72 } 72 }
73 if (val < 1024) 73 if (val < 1024)
74 { 74 {
75 ret[0] = 255 - (val % 256); 75 ret[0] = 255 - (val % 256);
76 ret[1] = 255; 76 ret[1] = 255;
77 return ret; 77 return ret;
78 } 78 }
79 79
80 throw new Exception("Out of bounds parameter (val)"); 80 throw new Exception("Out of bounds parameter (val)");
81 } 81 }
82 82
83 public void Fracture(int number, double scalemin, double scalemax) 83 public void Fracture(int number, double scalemin, double scalemax)
84 { 84 {
85 SetDiff(); 85 SetDiff();
86 86
87 Random rand = new Random(seed); 87 Random rand = new Random(seed);
88 88
89 for (int i = 0; i < number; i++) 89 for (int i = 0; i < number; i++)
90 { 90 {
91 int[] a, b; 91 int[] a, b;
92 92
93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken 93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken
94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken 94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken
95 double z = rand.NextDouble(); 95 double z = rand.NextDouble();
96 double u = rand.NextDouble(); 96 double u = rand.NextDouble();
97 double v = rand.NextDouble(); 97 double v = rand.NextDouble();
98 98
99 for (int x = 0; x < w; x++) 99 for (int x = 0; x < w; x++)
100 { 100 {
101 for (int y = 0; y < h; y++) 101 for (int y = 0; y < h; y++)
102 { 102 {
103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); 103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
104 104
105 if (v >= 0.5) 105 if (v >= 0.5)
106 { 106 {
107 if (u >= 0.5) 107 if (u >= 0.5)
108 { 108 {
109 if (y > miny) 109 if (y > miny)
110 { 110 {
111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
112 } 112 }
113 } 113 }
114 else 114 else
115 { 115 {
116 if (y < miny) 116 if (y < miny)
117 { 117 {
118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
119 } 119 }
120 } 120 }
121 } 121 }
122 else 122 else
123 { 123 {
124 if (u >= 0.5) 124 if (u >= 0.5)
125 { 125 {
126 if (x > miny) 126 if (x > miny)
127 { 127 {
128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
129 } 129 }
130 } 130 }
131 else 131 else
132 { 132 {
133 if (x < miny) 133 if (x < miny)
134 { 134 {
135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
136 } 136 }
137 } 137 }
138 } 138 }
139 } 139 }
140 } 140 }
141 } 141 }
142 Normalise(); 142 Normalise();
143 } 143 }
144 } 144 }
145} \ No newline at end of file 145} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
index 47b7a66..141fe04 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
@@ -1,66 +1,66 @@
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 37
38 public void GradientCube() 38 public void GradientCube()
39 { 39 {
40 SetDiff(); 40 SetDiff();
41 41
42 int x, y; 42 int x, y;
43 for (x = 0; x < w; x++) 43 for (x = 0; x < w; x++)
44 { 44 {
45 for (y = 0; y < h; y++) 45 for (y = 0; y < h; y++)
46 { 46 {
47 map[x, y] = x*y; 47 map[x, y] = x*y;
48 } 48 }
49 } 49 }
50 Normalise(); 50 Normalise();
51 } 51 }
52 52
53 public void GradientStripe() 53 public void GradientStripe()
54 { 54 {
55 int x, y; 55 int x, y;
56 for (x = 0; x < w; x++) 56 for (x = 0; x < w; x++)
57 { 57 {
58 for (y = 0; y < h; y++) 58 for (y = 0; y < h; y++)
59 { 59 {
60 map[x, y] = x; 60 map[x, y] = x;
61 } 61 }
62 } 62 }
63 Normalise(); 63 Normalise();
64 } 64 }
65 } 65 }
66} \ No newline at end of file 66} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
index 5a697b1..aa18e40 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
@@ -1,283 +1,283 @@
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 /// <summary> 37 /// <summary>
38 /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. 38 /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh.
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 /// <param name="number">The number of hills to generate</param> 41 /// <param name="number">The number of hills to generate</param>
42 /// <param name="scale_min">The minimum size of each hill</param> 42 /// <param name="scale_min">The minimum size of each hill</param>
43 /// <param name="scale_range">The maximum size of each hill</param> 43 /// <param name="scale_range">The maximum size of each hill</param>
44 /// <param name="island">Whether to bias hills towards the center of the map</param> 44 /// <param name="island">Whether to bias hills towards the center of the map</param>
45 /// <param name="additive">Whether to add hills together or to pick the largest value</param> 45 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
46 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> 46 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
47 public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 47 public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
48 { 48 {
49 SetDiff(); 49 SetDiff();
50 50
51 Random random = new Random(seed); 51 Random random = new Random(seed);
52 52
53 int x, y; 53 int x, y;
54 int i; 54 int i;
55 55
56 for (i = 0; i < number; i++) 56 for (i = 0; i < number; i++)
57 { 57 {
58 double rx = Math.Min(255.0, random.NextDouble() * w); 58 double rx = Math.Min(255.0, random.NextDouble() * w);
59 double ry = Math.Min(255.0, random.NextDouble() * h); 59 double ry = Math.Min(255.0, random.NextDouble() * h);
60 double rand = random.NextDouble(); 60 double rand = random.NextDouble();
61 61
62 if (island) 62 if (island)
63 { 63 {
64 // Move everything towards the center 64 // Move everything towards the center
65 rx -= w / 2; 65 rx -= w / 2;
66 rx /= 2; 66 rx /= 2;
67 rx += w / 2; 67 rx += w / 2;
68 68
69 ry -= h / 2; 69 ry -= h / 2;
70 ry /= 2; 70 ry /= 2;
71 ry += h / 2; 71 ry += h / 2;
72 } 72 }
73 73
74 for (x = 0; x < w; x++) 74 for (x = 0; x < w; x++)
75 { 75 {
76 for (y = 0; y < h; y++) 76 for (y = 0; y < h; y++)
77 { 77 {
78 if (noisy) 78 if (noisy)
79 rand = random.NextDouble(); 79 rand = random.NextDouble();
80 80
81 double z = (scale_min + (scale_range * rand)); 81 double z = (scale_min + (scale_range * rand));
82 z *= z; 82 z *= z;
83 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 83 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
84 84
85 if (z < 0) 85 if (z < 0)
86 z = 0; 86 z = 0;
87 87
88 if (additive) 88 if (additive)
89 { 89 {
90 map[x, y] += z; 90 map[x, y] += z;
91 } 91 }
92 else 92 else
93 { 93 {
94 map[x, y] = Math.Max(map[x, y], z); 94 map[x, y] = Math.Max(map[x, y], z);
95 } 95 }
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 Normalise(); 100 Normalise();
101 } 101 }
102 102
103 /// <summary> 103 /// <summary>
104 /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. 104 /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh.
105 /// </summary> 105 /// </summary>
106 /// <remarks>3-Clause BSD Licensed</remarks> 106 /// <remarks>3-Clause BSD Licensed</remarks>
107 /// <param name="number">The number of hills to generate</param> 107 /// <param name="number">The number of hills to generate</param>
108 /// <param name="scale_min">The minimum size of each hill</param> 108 /// <param name="scale_min">The minimum size of each hill</param>
109 /// <param name="scale_range">The maximum size of each hill</param> 109 /// <param name="scale_range">The maximum size of each hill</param>
110 /// <param name="island">Whether to bias hills towards the center of the map</param> 110 /// <param name="island">Whether to bias hills towards the center of the map</param>
111 /// <param name="additive">Whether to add hills together or to pick the largest value</param> 111 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
112 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> 112 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
113 public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 113 public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
114 { 114 {
115 SetDiff(); 115 SetDiff();
116 116
117 Random random = new Random(seed); 117 Random random = new Random(seed);
118 118
119 int x, y; 119 int x, y;
120 int i; 120 int i;
121 121
122 for (i = 0; i < number; i++) 122 for (i = 0; i < number; i++)
123 { 123 {
124 double rx = Math.Min(255.0, random.NextDouble() * w); 124 double rx = Math.Min(255.0, random.NextDouble() * w);
125 double ry = Math.Min(255.0, random.NextDouble() * h); 125 double ry = Math.Min(255.0, random.NextDouble() * h);
126 double rand = random.NextDouble(); 126 double rand = random.NextDouble();
127 127
128 if (island) 128 if (island)
129 { 129 {
130 // Move everything towards the center 130 // Move everything towards the center
131 rx -= w / 2; 131 rx -= w / 2;
132 rx /= 2; 132 rx /= 2;
133 rx += w / 2; 133 rx += w / 2;
134 134
135 ry -= h / 2; 135 ry -= h / 2;
136 ry /= 2; 136 ry /= 2;
137 ry += h / 2; 137 ry += h / 2;
138 } 138 }
139 139
140 for (x = 0; x < w; x++) 140 for (x = 0; x < w; x++)
141 { 141 {
142 for (y = 0; y < h; y++) 142 for (y = 0; y < h; y++)
143 { 143 {
144 if (noisy) 144 if (noisy)
145 rand = random.NextDouble(); 145 rand = random.NextDouble();
146 146
147 double z = (scale_min + (scale_range * rand)); 147 double z = (scale_min + (scale_range * rand));
148 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 148 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
149 149
150 if (z < 0) 150 if (z < 0)
151 z = 0; 151 z = 0;
152 152
153 if (additive) 153 if (additive)
154 { 154 {
155 map[x, y] += z; 155 map[x, y] += z;
156 } 156 }
157 else 157 else
158 { 158 {
159 map[x, y] = Math.Max(map[x, y], z); 159 map[x, y] = Math.Max(map[x, y], z);
160 } 160 }
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 Normalise(); 165 Normalise();
166 } 166 }
167 167
168 public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 168 public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
169 { 169 {
170 SetDiff(); 170 SetDiff();
171 171
172 Random random = new Random(seed); 172 Random random = new Random(seed);
173 173
174 int x, y; 174 int x, y;
175 int i; 175 int i;
176 176
177 for (i = 0; i < number; i++) 177 for (i = 0; i < number; i++)
178 { 178 {
179 double rx = Math.Min(255.0, random.NextDouble() * w); 179 double rx = Math.Min(255.0, random.NextDouble() * w);
180 double ry = Math.Min(255.0, random.NextDouble() * h); 180 double ry = Math.Min(255.0, random.NextDouble() * h);
181 double rand = random.NextDouble(); 181 double rand = random.NextDouble();
182 182
183 if (island) 183 if (island)
184 { 184 {
185 // Move everything towards the center 185 // Move everything towards the center
186 rx -= w / 2; 186 rx -= w / 2;
187 rx /= 2; 187 rx /= 2;
188 rx += w / 2; 188 rx += w / 2;
189 189
190 ry -= h / 2; 190 ry -= h / 2;
191 ry /= 2; 191 ry /= 2;
192 ry += h / 2; 192 ry += h / 2;
193 } 193 }
194 194
195 for (x = 0; x < w; x++) 195 for (x = 0; x < w; x++)
196 { 196 {
197 for (y = 0; y < h; y++) 197 for (y = 0; y < h; y++)
198 { 198 {
199 if (noisy) 199 if (noisy)
200 rand = random.NextDouble(); 200 rand = random.NextDouble();
201 201
202 double z = (scale_min + (scale_range * rand)); 202 double z = (scale_min + (scale_range * rand));
203 z -= Math.Abs(x-rx) + Math.Abs(y-ry); 203 z -= Math.Abs(x-rx) + Math.Abs(y-ry);
204 //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 204 //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
205 205
206 if (z < 0) 206 if (z < 0)
207 z = 0; 207 z = 0;
208 208
209 if (additive) 209 if (additive)
210 { 210 {
211 map[x, y] += z; 211 map[x, y] += z;
212 } 212 }
213 else 213 else
214 { 214 {
215 map[x, y] = Math.Max(map[x, y], z); 215 map[x, y] = Math.Max(map[x, y], z);
216 } 216 }
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 Normalise(); 221 Normalise();
222 } 222 }
223 223
224 public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 224 public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
225 { 225 {
226 SetDiff(); 226 SetDiff();
227 227
228 Random random = new Random(seed); 228 Random random = new Random(seed);
229 229
230 int x, y; 230 int x, y;
231 int i; 231 int i;
232 232
233 for (i = 0; i < number; i++) 233 for (i = 0; i < number; i++)
234 { 234 {
235 double rx = Math.Min(255.0, random.NextDouble() * w); 235 double rx = Math.Min(255.0, random.NextDouble() * w);
236 double ry = Math.Min(255.0, random.NextDouble() * h); 236 double ry = Math.Min(255.0, random.NextDouble() * h);
237 double rand = random.NextDouble(); 237 double rand = random.NextDouble();
238 238
239 if (island) 239 if (island)
240 { 240 {
241 // Move everything towards the center 241 // Move everything towards the center
242 rx -= w / 2; 242 rx -= w / 2;
243 rx /= 2; 243 rx /= 2;
244 rx += w / 2; 244 rx += w / 2;
245 245
246 ry -= h / 2; 246 ry -= h / 2;
247 ry /= 2; 247 ry /= 2;
248 ry += h / 2; 248 ry += h / 2;
249 } 249 }
250 250
251 for (x = 0; x < w; x++) 251 for (x = 0; x < w; x++)
252 { 252 {
253 for (y = 0; y < h; y++) 253 for (y = 0; y < h; y++)
254 { 254 {
255 if (noisy) 255 if (noisy)
256 rand = random.NextDouble(); 256 rand = random.NextDouble();
257 257
258 double z = (scale_min + (scale_range * rand)); 258 double z = (scale_min + (scale_range * rand));
259 z *= z * z * z; 259 z *= z * z * z;
260 double dx = Math.Abs(x - rx); 260 double dx = Math.Abs(x - rx);
261 double dy = Math.Abs(y - ry); 261 double dy = Math.Abs(y - ry);
262 z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); 262 z -= (dx * dx * dx * dx) + (dy * dy * dy * dy);
263 263
264 if (z < 0) 264 if (z < 0)
265 z = 0; 265 z = 0;
266 266
267 if (additive) 267 if (additive)
268 { 268 {
269 map[x, y] += z; 269 map[x, y] += z;
270 } 270 }
271 else 271 else
272 { 272 {
273 map[x, y] = Math.Max(map[x, y], z); 273 map[x, y] = Math.Max(map[x, y], z);
274 } 274 }
275 } 275 }
276 } 276 }
277 } 277 }
278 278
279 Normalise(); 279 Normalise();
280 } 280 }
281 281
282 } 282 }
283} 283}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
index 3cefcfe..d40302c 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
@@ -1,56 +1,56 @@
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 /// <summary> 37 /// <summary>
38 /// Fills a channel with 0..1 noise 38 /// Fills a channel with 0..1 noise
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 public void Noise() 41 public void Noise()
42 { 42 {
43 SetDiff(); 43 SetDiff();
44 44
45 Random rand = new Random(seed); 45 Random rand = new Random(seed);
46 int x, y; 46 int x, y;
47 for (x = 0; x < w; x++) 47 for (x = 0; x < w; x++)
48 { 48 {
49 for (y = 0; y < h; y++) 49 for (y = 0; y < h; y++)
50 { 50 {
51 map[x, y] = rand.NextDouble(); 51 map[x, y] = rand.NextDouble();
52 } 52 }
53 } 53 }
54 } 54 }
55 } 55 }
56} 56}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
index 80abfe5..59d877a 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
@@ -1,156 +1,156 @@
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 private double[] CoordinatesToPolar(int x, int y) 37 private double[] CoordinatesToPolar(int x, int y)
38 { 38 {
39 double theta = Math.Atan2(x - (w / 2), y - (h / 2)); 39 double theta = Math.Atan2(x - (w / 2), y - (h / 2));
40 double rx = (double)x - ((double)w / 2); 40 double rx = (double)x - ((double)w / 2);
41 double ry = (double)y - ((double)h / 2); 41 double ry = (double)y - ((double)h / 2);
42 double r = Math.Sqrt((rx * rx) + (ry * ry)); 42 double r = Math.Sqrt((rx * rx) + (ry * ry));
43 43
44 double[] coords = new double[2]; 44 double[] coords = new double[2];
45 coords[0] = r; 45 coords[0] = r;
46 coords[1] = theta; 46 coords[1] = theta;
47 return coords; 47 return coords;
48 } 48 }
49 49
50 public int[] PolarToCoordinates(double r, double theta) { 50 public int[] PolarToCoordinates(double r, double theta) {
51 double nx; 51 double nx;
52 double ny; 52 double ny;
53 53
54 nx = (double)r * Math.Cos(theta); 54 nx = (double)r * Math.Cos(theta);
55 ny = (double)r * Math.Sin(theta); 55 ny = (double)r * Math.Sin(theta);
56 56
57 nx += w / 2; 57 nx += w / 2;
58 ny += h / 2; 58 ny += h / 2;
59 59
60 if (nx >= w) 60 if (nx >= w)
61 nx = w - 1; 61 nx = w - 1;
62 62
63 if (ny >= h) 63 if (ny >= h)
64 ny = h - 1; 64 ny = h - 1;
65 65
66 if (nx < 0) 66 if (nx < 0)
67 nx = 0; 67 nx = 0;
68 68
69 if (ny < 0) 69 if (ny < 0)
70 ny = 0; 70 ny = 0;
71 71
72 int[] coords = new int[2]; 72 int[] coords = new int[2];
73 coords[0] = (int)nx; 73 coords[0] = (int)nx;
74 coords[1] = (int)ny; 74 coords[1] = (int)ny;
75 return coords; 75 return coords;
76 } 76 }
77 77
78 public void Polar() 78 public void Polar()
79 { 79 {
80 SetDiff(); 80 SetDiff();
81 81
82 Channel n = this.Copy(); 82 Channel n = this.Copy();
83 83
84 int x, y; 84 int x, y;
85 for (x = 0; x < w; x++) 85 for (x = 0; x < w; x++)
86 { 86 {
87 for (y = 0; y < h; y++) 87 for (y = 0; y < h; y++)
88 { 88 {
89 double[] coords = CoordinatesToPolar(x,y); 89 double[] coords = CoordinatesToPolar(x,y);
90 90
91 coords[0] += w / 2.0; 91 coords[0] += w / 2.0;
92 coords[1] += h / 2.0; 92 coords[1] += h / 2.0;
93 93
94 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; 94 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h];
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) 99 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle)
100 { 100 {
101 SetDiff(); 101 SetDiff();
102 102
103 int i; 103 int i;
104 double r = offsetRadius; 104 double r = offsetRadius;
105 double theta = offsetAngle; 105 double theta = offsetAngle;
106 for (i = 0; i < steps; i++) 106 for (i = 0; i < steps; i++)
107 { 107 {
108 r += incRadius; 108 r += incRadius;
109 theta += incAngle; 109 theta += incAngle;
110 110
111 int[] coords = PolarToCoordinates(r,theta); 111 int[] coords = PolarToCoordinates(r,theta);
112 Raise(coords[0], coords[1], 20, 1); 112 Raise(coords[0], coords[1], 20, 1);
113 } 113 }
114 } 114 }
115 115
116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) 116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c)
117 { 117 {
118 SetDiff(); 118 SetDiff();
119 119
120 List<Point2D> points = new List<Point2D>(); 120 List<Point2D> points = new List<Point2D>();
121 121
122 int i; 122 int i;
123 double r = offsetRadius; 123 double r = offsetRadius;
124 double theta = offsetAngle; 124 double theta = offsetAngle;
125 for (i = 0; i < steps; i++) 125 for (i = 0; i < steps; i++)
126 { 126 {
127 r += incRadius; 127 r += incRadius;
128 theta += incAngle; 128 theta += incAngle;
129 129
130 int[] coords = PolarToCoordinates(r, theta); 130 int[] coords = PolarToCoordinates(r, theta);
131 points.Add(new Point2D(coords[0],coords[1])); 131 points.Add(new Point2D(coords[0],coords[1]));
132 } 132 }
133 133
134 VoronoiDiagram(points, c); 134 VoronoiDiagram(points, c);
135 } 135 }
136 136
137 public void Spiral(double wid, double hig, double offset) 137 public void Spiral(double wid, double hig, double offset)
138 { 138 {
139 SetDiff(); 139 SetDiff();
140 140
141 int x, y, z; 141 int x, y, z;
142 z = 0; 142 z = 0;
143 for (x = 0; x < w; x++) 143 for (x = 0; x < w; x++)
144 { 144 {
145 for (y = 0; y < h; y++) 145 for (y = 0; y < h; y++)
146 { 146 {
147 z++; 147 z++;
148 double dx = Math.Abs((w / 2) - x); 148 double dx = Math.Abs((w / 2) - x);
149 double dy = Math.Abs((h / 2) - y); 149 double dy = Math.Abs((h / 2) - y);
150 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); 150 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig);
151 } 151 }
152 } 152 }
153 Normalise(); 153 Normalise();
154 } 154 }
155 } 155 }
156} \ No newline at end of file 156} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
index eb8f7ba..3411ccf 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
@@ -1,214 +1,214 @@
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 /// <summary> 37 /// <summary>
38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel 38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 /// <param name="pointsPerBlock">The number of generator points in each block</param> 41 /// <param name="pointsPerBlock">The number of generator points in each block</param>
42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. 42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it.
43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> 43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param>
44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param> 44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param>
45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) 45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c)
46 { 46 {
47 SetDiff(); 47 SetDiff();
48 48
49 List<Point2D> points = new List<Point2D>(); 49 List<Point2D> points = new List<Point2D>();
50 Random generator = new Random(seed); 50 Random generator = new Random(seed);
51 51
52 // Generate the emitter points 52 // Generate the emitter points
53 int x, y, i; 53 int x, y, i;
54 for (x = -blockSize; x < w + blockSize; x += blockSize) 54 for (x = -blockSize; x < w + blockSize; x += blockSize)
55 { 55 {
56 for (y = -blockSize; y < h + blockSize; y += blockSize) 56 for (y = -blockSize; y < h + blockSize; y += blockSize)
57 { 57 {
58 for (i = 0; i < pointsPerBlock; i++) 58 for (i = 0; i < pointsPerBlock; i++)
59 { 59 {
60 double pX = x + (generator.NextDouble() * (double)blockSize); 60 double pX = x + (generator.NextDouble() * (double)blockSize);
61 double pY = y + (generator.NextDouble() * (double)blockSize); 61 double pY = y + (generator.NextDouble() * (double)blockSize);
62 62
63 points.Add(new Point2D(pX, pY)); 63 points.Add(new Point2D(pX, pY));
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 double[] distances = new double[points.Count]; 68 double[] distances = new double[points.Count];
69 69
70 // Calculate the distance each pixel is from an emitter 70 // Calculate the distance each pixel is from an emitter
71 for (x = 0; x < w; x++) 71 for (x = 0; x < w; x++)
72 { 72 {
73 for (y = 0; y < h; y++) 73 for (y = 0; y < h; y++)
74 { 74 {
75 for (i = 0; i < points.Count; i++) 75 for (i = 0; i < points.Count; i++)
76 { 76 {
77 double dx, dy; 77 double dx, dy;
78 dx = Math.Abs((double)x - points[i].x); 78 dx = Math.Abs((double)x - points[i].x);
79 dy = Math.Abs((double)y - points[i].y); 79 dy = Math.Abs((double)y - points[i].y);
80 80
81 distances[i] = (dx * dx + dy * dy); 81 distances[i] = (dx * dx + dy * dy);
82 } 82 }
83 83
84 Array.Sort(distances); 84 Array.Sort(distances);
85 85
86 double f = 0.0; 86 double f = 0.0;
87 87
88 // Multiply the distances with their 'c' counterpart 88 // Multiply the distances with their 'c' counterpart
89 // ordering the distances descending 89 // ordering the distances descending
90 for (i = 0; i < c.Length; i++) 90 for (i = 0; i < c.Length; i++)
91 { 91 {
92 if (i >= points.Count) 92 if (i >= points.Count)
93 break; 93 break;
94 94
95 f += c[i] * distances[i]; 95 f += c[i] * distances[i];
96 } 96 }
97 97
98 map[x, y] = f; 98 map[x, y] = f;
99 } 99 }
100 } 100 }
101 101
102 // Normalise the result 102 // Normalise the result
103 Normalise(); 103 Normalise();
104 } 104 }
105 105
106 public void VoronoiDiagram(List<Point2D> points, double[] c) 106 public void VoronoiDiagram(List<Point2D> points, double[] c)
107 { 107 {
108 SetDiff(); 108 SetDiff();
109 109
110 Random generator = new Random(seed); 110 Random generator = new Random(seed);
111 int x, y, i; 111 int x, y, i;
112 double[] distances = new double[points.Count]; 112 double[] distances = new double[points.Count];
113 113
114 // Calculate the distance each pixel is from an emitter 114 // Calculate the distance each pixel is from an emitter
115 for (x = 0; x < w; x++) 115 for (x = 0; x < w; x++)
116 { 116 {
117 for (y = 0; y < h; y++) 117 for (y = 0; y < h; y++)
118 { 118 {
119 for (i = 0; i < points.Count; i++) 119 for (i = 0; i < points.Count; i++)
120 { 120 {
121 double dx, dy; 121 double dx, dy;
122 dx = Math.Abs((double)x - points[i].x); 122 dx = Math.Abs((double)x - points[i].x);
123 dy = Math.Abs((double)y - points[i].y); 123 dy = Math.Abs((double)y - points[i].y);
124 124
125 distances[i] = (dx * dx + dy * dy); 125 distances[i] = (dx * dx + dy * dy);
126 } 126 }
127 127
128 Array.Sort(distances); 128 Array.Sort(distances);
129 129
130 double f = 0.0; 130 double f = 0.0;
131 131
132 // Multiply the distances with their 'c' counterpart 132 // Multiply the distances with their 'c' counterpart
133 // ordering the distances descending 133 // ordering the distances descending
134 for (i = 0; i < c.Length; i++) 134 for (i = 0; i < c.Length; i++)
135 { 135 {
136 if (i >= points.Count) 136 if (i >= points.Count)
137 break; 137 break;
138 138
139 f += c[i] * distances[i]; 139 f += c[i] * distances[i];
140 } 140 }
141 141
142 map[x, y] = f; 142 map[x, y] = f;
143 } 143 }
144 } 144 }
145 145
146 // Normalise the result 146 // Normalise the result
147 Normalise(); 147 Normalise();
148 } 148 }
149 149
150 public void VoroflatDiagram(int pointsPerBlock, int blockSize) 150 public void VoroflatDiagram(int pointsPerBlock, int blockSize)
151 { 151 {
152 SetDiff(); 152 SetDiff();
153 153
154 List<Point2D> points = new List<Point2D>(); 154 List<Point2D> points = new List<Point2D>();
155 Random generator = new Random(seed); 155 Random generator = new Random(seed);
156 156
157 // Generate the emitter points 157 // Generate the emitter points
158 int x, y, i; 158 int x, y, i;
159 for (x = -blockSize; x < w + blockSize; x += blockSize) 159 for (x = -blockSize; x < w + blockSize; x += blockSize)
160 { 160 {
161 for (y = -blockSize; y < h + blockSize; y += blockSize) 161 for (y = -blockSize; y < h + blockSize; y += blockSize)
162 { 162 {
163 for (i = 0; i < pointsPerBlock; i++) 163 for (i = 0; i < pointsPerBlock; i++)
164 { 164 {
165 double pX = x + (generator.NextDouble() * (double)blockSize); 165 double pX = x + (generator.NextDouble() * (double)blockSize);
166 double pY = y + (generator.NextDouble() * (double)blockSize); 166 double pY = y + (generator.NextDouble() * (double)blockSize);
167 167
168 points.Add(new Point2D(pX, pY)); 168 points.Add(new Point2D(pX, pY));
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 double[] distances = new double[points.Count]; 173 double[] distances = new double[points.Count];
174 174
175 // Calculate the distance each pixel is from an emitter 175 // Calculate the distance each pixel is from an emitter
176 for (x = 0; x < w; x++) 176 for (x = 0; x < w; x++)
177 { 177 {
178 for (y = 0; y < h; y++) 178 for (y = 0; y < h; y++)
179 { 179 {
180 for (i = 0; i < points.Count; i++) 180 for (i = 0; i < points.Count; i++)
181 { 181 {
182 double dx, dy; 182 double dx, dy;
183 dx = Math.Abs((double)x - points[i].x); 183 dx = Math.Abs((double)x - points[i].x);
184 dy = Math.Abs((double)y - points[i].y); 184 dy = Math.Abs((double)y - points[i].y);
185 185
186 distances[i] = (dx * dx + dy * dy); 186 distances[i] = (dx * dx + dy * dy);
187 } 187 }
188 188
189 //Array.Sort(distances); 189 //Array.Sort(distances);
190 190
191 double f = 0.0; 191 double f = 0.0;
192 192
193 double min = double.MaxValue; 193 double min = double.MaxValue;
194 for (int j = 0; j < distances.Length;j++ ) 194 for (int j = 0; j < distances.Length;j++ )
195 { 195 {
196 if (distances[j] < min) 196 if (distances[j] < min)
197 { 197 {
198 min = distances[j]; 198 min = distances[j];
199 f = j; 199 f = j;
200 } 200 }
201 } 201 }
202 202
203 // Multiply the distances with their 'c' counterpart 203 // Multiply the distances with their 'c' counterpart
204 // ordering the distances descending 204 // ordering the distances descending
205 205
206 map[x, y] = f; 206 map[x, y] = f;
207 } 207 }
208 } 208 }
209 209
210 // Normalise the result 210 // Normalise the result
211 Normalise(); 211 Normalise();
212 } 212 }
213 } 213 }
214} 214}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
index ce36daf..ba2fad6 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
@@ -1,74 +1,74 @@
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 /// <summary> 37 /// <summary>
38 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. 38 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go.
39 /// </summary> 39 /// </summary>
40 /// <param name="number">The number of worms which will traverse the map</param> 40 /// <param name="number">The number of worms which will traverse the map</param>
41 /// <param name="rounds">The number of steps each worm will traverse</param> 41 /// <param name="rounds">The number of steps each worm will traverse</param>
42 /// <param name="movement">The maximum distance each worm will move each step</param> 42 /// <param name="movement">The maximum distance each worm will move each step</param>
43 /// <param name="size">The size of the area around the worm modified</param> 43 /// <param name="size">The size of the area around the worm modified</param>
44 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param> 44 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param>
45 public void Worms(int number, int rounds, double movement, double size, bool centerspawn) 45 public void Worms(int number, int rounds, double movement, double size, bool centerspawn)
46 { 46 {
47 SetDiff(); 47 SetDiff();
48 48
49 Random random = new Random(seed); 49 Random random = new Random(seed);
50 int i, j; 50 int i, j;
51 51
52 for (i = 0; i < number; i++) 52 for (i = 0; i < number; i++)
53 { 53 {
54 double rx, ry; 54 double rx, ry;
55 if (centerspawn) 55 if (centerspawn)
56 { 56 {
57 rx = w / 2.0; 57 rx = w / 2.0;
58 ry = h / 2.0; 58 ry = h / 2.0;
59 } 59 }
60 else 60 else
61 { 61 {
62 rx = random.NextDouble() * (w - 1); 62 rx = random.NextDouble() * (w - 1);
63 ry = random.NextDouble() * (h - 1); 63 ry = random.NextDouble() * (h - 1);
64 } 64 }
65 for (j = 0; j < rounds; j++) 65 for (j = 0; j < rounds; j++)
66 { 66 {
67 rx += (random.NextDouble() * movement) - (movement / 2.0); 67 rx += (random.NextDouble() * movement) - (movement / 2.0);
68 ry += (random.NextDouble() * movement) - (movement / 2.0); 68 ry += (random.NextDouble() * movement) - (movement / 2.0);
69 Raise(rx, ry, size, 1.0); 69 Raise(rx, ry, size, 1.0);
70 } 70 }
71 } 71 }
72 } 72 }
73 } 73 }
74} \ No newline at end of file 74} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
index e6b18f4..18e40b5 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
@@ -1,350 +1,350 @@
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 Channel Normalise() 37 public Channel Normalise()
38 { 38 {
39 SetDiff(); 39 SetDiff();
40 40
41 double max = FindMax(); 41 double max = FindMax();
42 double min = FindMin(); 42 double min = FindMin();
43 43
44 int x, y; 44 int x, y;
45 45
46 if (max != min) 46 if (max != min)
47 { 47 {
48 for (x = 0; x < w; x++) 48 for (x = 0; x < w; x++)
49 { 49 {
50 for (y = 0; y < h; y++) 50 for (y = 0; y < h; y++)
51 { 51 {
52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min)); 52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min));
53 } 53 }
54 } 54 }
55 } 55 }
56 else 56 else
57 { 57 {
58 this.Fill(0.5); 58 this.Fill(0.5);
59 } 59 }
60 60
61 return this; 61 return this;
62 } 62 }
63 63
64 public Channel Normalise(double minv, double maxv) 64 public Channel Normalise(double minv, double maxv)
65 { 65 {
66 SetDiff(); 66 SetDiff();
67 67
68 double max = FindMax(); 68 double max = FindMax();
69 double min = FindMin(); 69 double min = FindMin();
70 70
71 int x, y; 71 int x, y;
72 72
73 for (x = 0; x < w; x++) 73 for (x = 0; x < w; x++)
74 { 74 {
75 for (y = 0; y < h; y++) 75 for (y = 0; y < h; y++)
76 { 76 {
77 double val = (map[x, y] - min) * (1.0 / max - min); 77 double val = (map[x, y] - min) * (1.0 / max - min);
78 val *= maxv - minv; 78 val *= maxv - minv;
79 val += minv; 79 val += minv;
80 80
81 map[x, y] = val; 81 map[x, y] = val;
82 } 82 }
83 } 83 }
84 84
85 return this; 85 return this;
86 } 86 }
87 87
88 public Channel Clip() 88 public Channel Clip()
89 { 89 {
90 int x, y; 90 int x, y;
91 91
92 for (x = 0; x < w; x++) 92 for (x = 0; x < w; x++)
93 { 93 {
94 for (y = 0; y < h; y++) 94 for (y = 0; y < h; y++)
95 { 95 {
96 SetClip(x, y, map[x, y]); 96 SetClip(x, y, map[x, y]);
97 } 97 }
98 } 98 }
99 99
100 return this; 100 return this;
101 } 101 }
102 102
103 public Channel Clip(double min, double max) 103 public Channel Clip(double min, double max)
104 { 104 {
105 int x, y; 105 int x, y;
106 for (x = 0; x < w; x++) 106 for (x = 0; x < w; x++)
107 { 107 {
108 for (y = 0; y < h; y++) 108 for (y = 0; y < h; y++)
109 { 109 {
110 double val = map[x, y]; 110 double val = map[x, y];
111 if (val > max) val = max; 111 if (val > max) val = max;
112 if (val < min) val = min; 112 if (val < min) val = min;
113 113
114 Set(x, y, val); 114 Set(x, y, val);
115 } 115 }
116 } 116 }
117 return this; 117 return this;
118 } 118 }
119 119
120 public Channel Crop(int x1, int y1, int x2, int y2) 120 public Channel Crop(int x1, int y1, int x2, int y2)
121 { 121 {
122 int width = x1 - x2 + 1; 122 int width = x1 - x2 + 1;
123 int height = y1 - y2 + 1; 123 int height = y1 - y2 + 1;
124 Channel chan = new Channel(width, height); 124 Channel chan = new Channel(width, height);
125 125
126 int x, y; 126 int x, y;
127 int nx, ny; 127 int nx, ny;
128 128
129 nx = 0; 129 nx = 0;
130 for (x = x1; x < x2; x++) 130 for (x = x1; x < x2; x++)
131 { 131 {
132 ny = 0; 132 ny = 0;
133 for (y = y1; y < y2; y++) 133 for (y = y1; y < y2; y++)
134 { 134 {
135 chan.map[nx, ny] = map[x, y]; 135 chan.map[nx, ny] = map[x, y];
136 136
137 ny++; 137 ny++;
138 } 138 }
139 nx++; 139 nx++;
140 } 140 }
141 141
142 return this; 142 return this;
143 } 143 }
144 144
145 public Channel AddClip(Channel other) 145 public Channel AddClip(Channel other)
146 { 146 {
147 SetDiff(); 147 SetDiff();
148 148
149 int x, y; 149 int x, y;
150 for (x = 0; x < w; x++) 150 for (x = 0; x < w; x++)
151 { 151 {
152 for (y = 0; y < h; y++) 152 for (y = 0; y < h; y++)
153 { 153 {
154 map[x, y] = other.map[x, y]; 154 map[x, y] = other.map[x, y];
155 if (map[x, y] > 1) 155 if (map[x, y] > 1)
156 map[x, y] = 1; 156 map[x, y] = 1;
157 if (map[x, y] < 0) 157 if (map[x, y] < 0)
158 map[x, y] = 0; 158 map[x, y] = 0;
159 } 159 }
160 } 160 }
161 return this; 161 return this;
162 } 162 }
163 163
164 public void Smooth(double amount) 164 public void Smooth(double amount)
165 { 165 {
166 SetDiff(); 166 SetDiff();
167 167
168 double area = amount; 168 double area = amount;
169 double step = amount / 4.0; 169 double step = amount / 4.0;
170 170
171 double[,] manipulate = new double[w, h]; 171 double[,] manipulate = new double[w, h];
172 int x, y; 172 int x, y;
173 double n, l; 173 double n, l;
174 for (x = 0; x < w; x++) 174 for (x = 0; x < w; x++)
175 { 175 {
176 for (y = 0; y < h; y++) 176 for (y = 0; y < h; y++)
177 { 177 {
178 double average = 0.0; 178 double average = 0.0;
179 int avgsteps = 0; 179 int avgsteps = 0;
180 180
181 for (n = 0.0 - area; n < area; n += step) 181 for (n = 0.0 - area; n < area; n += step)
182 { 182 {
183 for (l = 0.0 - area; l < area; l += step) 183 for (l = 0.0 - area; l < area; l += step)
184 { 184 {
185 avgsteps++; 185 avgsteps++;
186 average += GetBilinearInterpolate(x + n, y + l); 186 average += GetBilinearInterpolate(x + n, y + l);
187 } 187 }
188 } 188 }
189 189
190 manipulate[x, y] = average / avgsteps; 190 manipulate[x, y] = average / avgsteps;
191 } 191 }
192 } 192 }
193 map = manipulate; 193 map = manipulate;
194 } 194 }
195 195
196 public void Pertubation(double amount) 196 public void Pertubation(double amount)
197 { 197 {
198 SetDiff(); 198 SetDiff();
199 199
200 // Simple pertubation filter 200 // Simple pertubation filter
201 double[,] manipulated = new double[w, h]; 201 double[,] manipulated = new double[w, h];
202 Random generator = new Random(seed); // Seeds FTW! 202 Random generator = new Random(seed); // Seeds FTW!
203 //double amount = 8.0; 203 //double amount = 8.0;
204 204
205 int x, y; 205 int x, y;
206 for (x = 0; x < w; x++) 206 for (x = 0; x < w; x++)
207 { 207 {
208 for (y = 0; y < h; y++) 208 for (y = 0; y < h; y++)
209 { 209 {
210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
212 double p = GetBilinearInterpolate(offset_x, offset_y); 212 double p = GetBilinearInterpolate(offset_x, offset_y);
213 manipulated[x, y] = p; 213 manipulated[x, y] = p;
214 } 214 }
215 } 215 }
216 map = manipulated; 216 map = manipulated;
217 } 217 }
218 218
219 public void PertubationMask(Channel mask) 219 public void PertubationMask(Channel mask)
220 { 220 {
221 // Simple pertubation filter 221 // Simple pertubation filter
222 double[,] manipulated = new double[w, h]; 222 double[,] manipulated = new double[w, h];
223 Random generator = new Random(seed); // Seeds FTW! 223 Random generator = new Random(seed); // Seeds FTW!
224 //double amount = 8.0; 224 //double amount = 8.0;
225 225
226 double amount; 226 double amount;
227 227
228 int x, y; 228 int x, y;
229 for (x = 0; x < w; x++) 229 for (x = 0; x < w; x++)
230 { 230 {
231 for (y = 0; y < h; y++) 231 for (y = 0; y < h; y++)
232 { 232 {
233 amount = mask.map[x, y]; 233 amount = mask.map[x, y];
234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
236 236
237 if (offset_x > w) 237 if (offset_x > w)
238 offset_x = w - 1; 238 offset_x = w - 1;
239 if (offset_y > h) 239 if (offset_y > h)
240 offset_y = h - 1; 240 offset_y = h - 1;
241 if (offset_y < 0) 241 if (offset_y < 0)
242 offset_y = 0; 242 offset_y = 0;
243 if (offset_x < 0) 243 if (offset_x < 0)
244 offset_x = 0; 244 offset_x = 0;
245 245
246 double p = GetBilinearInterpolate(offset_x, offset_y); 246 double p = GetBilinearInterpolate(offset_x, offset_y);
247 manipulated[x, y] = p; 247 manipulated[x, y] = p;
248 SetDiff(x, y); 248 SetDiff(x, y);
249 } 249 }
250 } 250 }
251 map = manipulated; 251 map = manipulated;
252 } 252 }
253 253
254 public void Distort(Channel mask, double str) 254 public void Distort(Channel mask, double str)
255 { 255 {
256 // Simple pertubation filter 256 // Simple pertubation filter
257 double[,] manipulated = new double[w, h]; 257 double[,] manipulated = new double[w, h];
258 258
259 double amount; 259 double amount;
260 260
261 int x, y; 261 int x, y;
262 for (x = 0; x < w; x++) 262 for (x = 0; x < w; x++)
263 { 263 {
264 for (y = 0; y < h; y++) 264 for (y = 0; y < h; y++)
265 { 265 {
266 amount = mask.map[x, y]; 266 amount = mask.map[x, y];
267 double offset_x = (double)x + (amount * str) - (0.5 * str); 267 double offset_x = (double)x + (amount * str) - (0.5 * str);
268 double offset_y = (double)y + (amount * str) - (0.5 * str); 268 double offset_y = (double)y + (amount * str) - (0.5 * str);
269 269
270 if (offset_x > w) 270 if (offset_x > w)
271 offset_x = w - 1; 271 offset_x = w - 1;
272 if (offset_y > h) 272 if (offset_y > h)
273 offset_y = h - 1; 273 offset_y = h - 1;
274 if (offset_y < 0) 274 if (offset_y < 0)
275 offset_y = 0; 275 offset_y = 0;
276 if (offset_x < 0) 276 if (offset_x < 0)
277 offset_x = 0; 277 offset_x = 0;
278 278
279 double p = GetBilinearInterpolate(offset_x, offset_y); 279 double p = GetBilinearInterpolate(offset_x, offset_y);
280 manipulated[x, y] = p; 280 manipulated[x, y] = p;
281 SetDiff(x, y); 281 SetDiff(x, y);
282 } 282 }
283 } 283 }
284 map = manipulated; 284 map = manipulated;
285 285
286 } 286 }
287 287
288 public void Distort(Channel mask, Channel mask2, double str) 288 public void Distort(Channel mask, Channel mask2, double str)
289 { 289 {
290 // Simple pertubation filter 290 // Simple pertubation filter
291 double[,] manipulated = new double[w, h]; 291 double[,] manipulated = new double[w, h];
292 292
293 double amountX; 293 double amountX;
294 double amountY; 294 double amountY;
295 295
296 int x, y; 296 int x, y;
297 for (x = 0; x < w; x++) 297 for (x = 0; x < w; x++)
298 { 298 {
299 for (y = 0; y < h; y++) 299 for (y = 0; y < h; y++)
300 { 300 {
301 amountX = mask.map[x, y]; 301 amountX = mask.map[x, y];
302 amountY = mask2.map[x, y]; 302 amountY = mask2.map[x, y];
303 double offset_x = (double)x + (amountX * str) - (0.5 * str); 303 double offset_x = (double)x + (amountX * str) - (0.5 * str);
304 double offset_y = (double)y + (amountY * str) - (0.5 * str); 304 double offset_y = (double)y + (amountY * str) - (0.5 * str);
305 305
306 if (offset_x > w) 306 if (offset_x > w)
307 offset_x = w - 1; 307 offset_x = w - 1;
308 if (offset_y > h) 308 if (offset_y > h)
309 offset_y = h - 1; 309 offset_y = h - 1;
310 if (offset_y < 0) 310 if (offset_y < 0)
311 offset_y = 0; 311 offset_y = 0;
312 if (offset_x < 0) 312 if (offset_x < 0)
313 offset_x = 0; 313 offset_x = 0;
314 314
315 double p = GetBilinearInterpolate(offset_x, offset_y); 315 double p = GetBilinearInterpolate(offset_x, offset_y);
316 manipulated[x, y] = p; 316 manipulated[x, y] = p;
317 SetDiff(x, y); 317 SetDiff(x, y);
318 } 318 }
319 } 319 }
320 map = manipulated; 320 map = manipulated;
321 321
322 } 322 }
323 323
324 public Channel Blend(Channel other, double amount) 324 public Channel Blend(Channel other, double amount)
325 { 325 {
326 int x, y; 326 int x, y;
327 for (x = 0; x < w; x++) 327 for (x = 0; x < w; x++)
328 { 328 {
329 for (y = 0; y < h; y++) 329 for (y = 0; y < h; y++)
330 { 330 {
331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount)); 331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount));
332 } 332 }
333 } 333 }
334 return this; 334 return this;
335 } 335 }
336 336
337 public Channel Blend(Channel other, Channel amount) 337 public Channel Blend(Channel other, Channel amount)
338 { 338 {
339 int x, y; 339 int x, y;
340 for (x = 0; x < w; x++) 340 for (x = 0; x < w; x++)
341 { 341 {
342 for (y = 0; y < h; y++) 342 for (y = 0; y < h; y++)
343 { 343 {
344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); 344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y]));
345 } 345 }
346 } 346 }
347 return this; 347 return this;
348 } 348 }
349 } 349 }
350} 350}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
index 589d360..5d2b4d4 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
@@ -1,213 +1,213 @@
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 // Ideas for Aerobic erosion 37 // Ideas for Aerobic erosion
38 // 38 //
39 // Unlike thermal (gravity) and hydraulic (water suspension) 39 // Unlike thermal (gravity) and hydraulic (water suspension)
40 // aerobic erosion should displace mass by moving sediment 40 // aerobic erosion should displace mass by moving sediment
41 // in "hops". The length of the hop being dictated by the 41 // in "hops". The length of the hop being dictated by the
42 // presence of sharp cliffs and wind speed. 42 // presence of sharp cliffs and wind speed.
43 43
44 // The ability to pickup sediment is defined by the total 44 // The ability to pickup sediment is defined by the total
45 // surface area, such that: 45 // surface area, such that:
46 // 0 0 0 46 // 0 0 0
47 // 0 1 0 47 // 0 1 0
48 // 0 0 0 48 // 0 0 0
49 // Would be the best possible value for sediment to be 49 // Would be the best possible value for sediment to be
50 // picked up (total difference = 8) and flatter land 50 // picked up (total difference = 8) and flatter land
51 // will erode less quickly. 51 // will erode less quickly.
52 52
53 // Suspended particles assist the erosion process by hitting 53 // Suspended particles assist the erosion process by hitting
54 // the surface and chiselling additional particles off faster 54 // the surface and chiselling additional particles off faster
55 // than alone. 55 // than alone.
56 56
57 // Particles are deposited when one of two conditions is met 57 // Particles are deposited when one of two conditions is met
58 // First: 58 // First:
59 // When particles hit a wall - such that the 59 // When particles hit a wall - such that the
60 // wind direction points at a difference >= the 60 // wind direction points at a difference >= the
61 // deposition mininum talus. 61 // deposition mininum talus.
62 // Second: 62 // Second:
63 // When wind speed is lowered to below the minimum 63 // When wind speed is lowered to below the minimum
64 // required for transit. An idea for this is to 64 // required for transit. An idea for this is to
65 // use the navier-stokes algorithms for simulating 65 // use the navier-stokes algorithms for simulating
66 // pressure across the terrain. 66 // pressure across the terrain.
67 67
68 /// <summary> 68 /// <summary>
69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point. 69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
70 /// </summary> 70 /// </summary>
71 /// <param name="windspeed">0..1 The speed of the wind</param> 71 /// <param name="windspeed">0..1 The speed of the wind</param>
72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param> 72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param> 73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> 74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> 75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
76 /// <param name="lowest">Drop sediment at the lowest point?</param> 76 /// <param name="lowest">Drop sediment at the lowest point?</param>
77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics) 77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics)
78 { 78 {
79 bool debugImages = false; 79 bool debugImages = false;
80 80
81 Channel wind = new Channel(w, h) ; 81 Channel wind = new Channel(w, h) ;
82 Channel sediment = new Channel(w, h); 82 Channel sediment = new Channel(w, h);
83 int x, y, i, j; 83 int x, y, i, j;
84 84
85 this.Normalise(); 85 this.Normalise();
86 86
87 wind = this.Copy(); 87 wind = this.Copy();
88 wind.Noise(); 88 wind.Noise();
89 89
90 if (debugImages) 90 if (debugImages)
91 wind.SaveImage("testimg/wind_start.png"); 91 wind.SaveImage("testimg/wind_start.png");
92 92
93 if (usingFluidDynamics) 93 if (usingFluidDynamics)
94 { 94 {
95 wind.navierStokes(20, 0.1, 0.0, 0.0); 95 wind.navierStokes(20, 0.1, 0.0, 0.0);
96 } 96 }
97 else 97 else
98 { 98 {
99 wind.Pertubation(30); 99 wind.Pertubation(30);
100 } 100 }
101 101
102 if (debugImages) 102 if (debugImages)
103 wind.SaveImage("testimg/wind_begin.png"); 103 wind.SaveImage("testimg/wind_begin.png");
104 104
105 for (i = 0; i < rounds; i++) 105 for (i = 0; i < rounds; i++)
106 { 106 {
107 // Convert some rocks to sand 107 // Convert some rocks to sand
108 for (x = 1; x < w - 1; x++) 108 for (x = 1; x < w - 1; x++)
109 { 109 {
110 for (y = 1; y < h - 1; y++) 110 for (y = 1; y < h - 1; y++)
111 { 111 {
112 double me = Get(x, y); 112 double me = Get(x, y);
113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower. 113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
114 114
115 for (j = 0; j < 9; j++) 115 for (j = 0; j < 9; j++)
116 { 116 {
117 int[] coords = Neighbours(NeighbourSystem.Moore, j); 117 int[] coords = Neighbours(NeighbourSystem.Moore, j);
118 double target = Get(x + coords[0], y + coords[1]); 118 double target = Get(x + coords[0], y + coords[1]);
119 119
120 surfacearea += Math.Abs(target - me); 120 surfacearea += Math.Abs(target - me);
121 } 121 }
122 122
123 double amount = surfacearea * wind.map[x, y] * carry; 123 double amount = surfacearea * wind.map[x, y] * carry;
124 124
125 if (amount < 0) 125 if (amount < 0)
126 amount = 0; 126 amount = 0;
127 127
128 if (surfacearea > pickupTalusMinimum) 128 if (surfacearea > pickupTalusMinimum)
129 { 129 {
130 Set(x, y, map[x, y] - amount); 130 Set(x, y, map[x, y] - amount);
131 sediment.map[x, y] += amount; 131 sediment.map[x, y] += amount;
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 if (usingFluidDynamics) 136 if (usingFluidDynamics)
137 { 137 {
138 sediment.navierStokes(7, 0.1, 0.0, 0.1); 138 sediment.navierStokes(7, 0.1, 0.0, 0.1);
139 139
140 Channel noiseChan = new Channel(w, h); 140 Channel noiseChan = new Channel(w, h);
141 noiseChan.Noise(); 141 noiseChan.Noise();
142 wind.Blend(noiseChan, 0.01); 142 wind.Blend(noiseChan, 0.01);
143 143
144 wind.navierStokes(10, 0.1, 0.01, 0.01); 144 wind.navierStokes(10, 0.1, 0.01, 0.01);
145 145
146 sediment.Distort(wind, windspeed); 146 sediment.Distort(wind, windspeed);
147 } 147 }
148 else 148 else
149 { 149 {
150 wind.Pertubation(15); // Can do better later 150 wind.Pertubation(15); // Can do better later
151 wind.seed++; 151 wind.seed++;
152 sediment.Pertubation(10); // Sediment is blown around a bit 152 sediment.Pertubation(10); // Sediment is blown around a bit
153 sediment.seed++; 153 sediment.seed++;
154 } 154 }
155 155
156 if (debugImages) 156 if (debugImages)
157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png"); 157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png");
158 158
159 // Convert some sand to rock 159 // Convert some sand to rock
160 for (x = 1; x < w - 1; x++) 160 for (x = 1; x < w - 1; x++)
161 { 161 {
162 for (y = 1; y < h - 1; y++) 162 for (y = 1; y < h - 1; y++)
163 { 163 {
164 double me = Get(x, y); 164 double me = Get(x, y);
165 double surfacearea = 0.01; // Flat land does not get deposition 165 double surfacearea = 0.01; // Flat land does not get deposition
166 double min = double.MaxValue; 166 double min = double.MaxValue;
167 int[] minside = new int[2]; 167 int[] minside = new int[2];
168 168
169 for (j = 0; j < 9; j++) 169 for (j = 0; j < 9; j++)
170 { 170 {
171 int[] coords = Neighbours(NeighbourSystem.Moore, j); 171 int[] coords = Neighbours(NeighbourSystem.Moore, j);
172 double target = Get(x + coords[0], y + coords[1]); 172 double target = Get(x + coords[0], y + coords[1]);
173 173
174 surfacearea += Math.Abs(target - me); 174 surfacearea += Math.Abs(target - me);
175 175
176 if (target < min && lowest) 176 if (target < min && lowest)
177 { 177 {
178 minside = (int[])coords.Clone(); 178 minside = (int[])coords.Clone();
179 min = target; 179 min = target;
180 } 180 }
181 } 181 }
182 182
183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry; 183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry;
184 184
185 if (amount < 0) 185 if (amount < 0)
186 amount = 0; 186 amount = 0;
187 187
188 if (surfacearea > dropTalusMinimum) 188 if (surfacearea > dropTalusMinimum)
189 { 189 {
190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount); 190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount);
191 sediment.map[x, y] -= amount; 191 sediment.map[x, y] -= amount;
192 } 192 }
193 } 193 }
194 } 194 }
195 195
196 if (debugImages) 196 if (debugImages)
197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png"); 197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png");
198 198
199 wind.Normalise(); 199 wind.Normalise();
200 wind *= windspeed; 200 wind *= windspeed;
201 201
202 this.Normalise(); 202 this.Normalise();
203 } 203 }
204 204
205 Channel myself = this; 205 Channel myself = this;
206 myself += sediment; 206 myself += sediment;
207 myself.Normalise(); 207 myself.Normalise();
208 208
209 if (debugImages) 209 if (debugImages)
210 this.SaveImage("testimg/output.png"); 210 this.SaveImage("testimg/output.png");
211 } 211 }
212 } 212 }
213} \ No newline at end of file 213} \ No newline at end of file
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
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
index 8a111ed..1cd213b 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
@@ -1,307 +1,307 @@
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 // Navier Stokes Algorithms ported from 37 // Navier Stokes Algorithms ported from
38 // "Real-Time Fluid Dynamics for Games" by Jos Stam. 38 // "Real-Time Fluid Dynamics for Games" by Jos Stam.
39 // presented at GDC 2003. 39 // presented at GDC 2003.
40 40
41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd) 41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd)
42 42
43 private static int nsIX(int i, int j, int N) 43 private static int nsIX(int i, int j, int N)
44 { 44 {
45 return ((i) + (N + 2) * (j)); 45 return ((i) + (N + 2) * (j));
46 } 46 }
47 47
48 private static void nsSwap(ref double x0, ref double x) 48 private static void nsSwap(ref double x0, ref double x)
49 { 49 {
50 double tmp = x0; 50 double tmp = x0;
51 x0 = x; 51 x0 = x;
52 x = tmp; 52 x = tmp;
53 } 53 }
54 54
55 private static void nsSwap(ref double[] x0, ref double[] x) 55 private static void nsSwap(ref double[] x0, ref double[] x)
56 { 56 {
57 double[] tmp = x0; 57 double[] tmp = x0;
58 x0 = x; 58 x0 = x;
59 x = tmp; 59 x = tmp;
60 } 60 }
61 61
62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) 62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt)
63 { 63 {
64 int i; 64 int i;
65 int size = (N + 2) * (N + 2); 65 int size = (N + 2) * (N + 2);
66 for (i = 0; i < size; i++) 66 for (i = 0; i < size; i++)
67 { 67 {
68 x[i] += dt * s[i]; 68 x[i] += dt * s[i];
69 } 69 }
70 } 70 }
71 71
72 private void nsSetBnd(int N, int b, ref double[] x) 72 private void nsSetBnd(int N, int b, ref double[] x)
73 { 73 {
74 int i; 74 int i;
75 for (i = 0; i <= N; i++) 75 for (i = 0; i <= N; i++)
76 { 76 {
77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; 77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)];
78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; 78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)];
79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; 79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)];
80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; 80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)];
81 } 81 }
82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); 82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]);
83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); 83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]);
84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); 84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]);
85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); 85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]);
86 } 86 }
87 87
88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) 88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c)
89 { 89 {
90 int i, j; 90 int i, j;
91 for (i = 1; i <= N; i++) 91 for (i = 1; i <= N; i++)
92 { 92 {
93 for (j = 1; j <= N; j++) 93 for (j = 1; j <= N; j++)
94 { 94 {
95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a * 95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a *
96 (x[nsIX(i - 1, j, N)] + 96 (x[nsIX(i - 1, j, N)] +
97 x[nsIX(i + 1, j, N)] + 97 x[nsIX(i + 1, j, N)] +
98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) 98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)])
99 ) / c; 99 ) / c;
100 } 100 }
101 } 101 }
102 102
103 nsSetBnd(N, b, ref x); 103 nsSetBnd(N, b, ref x);
104 } 104 }
105 105
106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) 106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt)
107 { 107 {
108 double a = dt * diff * N * N; 108 double a = dt * diff * N * N;
109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a); 109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a);
110 } 110 }
111 111
112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) 112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt)
113 { 113 {
114 int i, j, i0, j0, i1, j1; 114 int i, j, i0, j0, i1, j1;
115 double x, y, s0, t0, s1, t1, dt0; 115 double x, y, s0, t0, s1, t1, dt0;
116 116
117 dt0 = dt * N; 117 dt0 = dt * N;
118 118
119 for (i = 1; i <= N; i++) 119 for (i = 1; i <= N; i++)
120 { 120 {
121 for (j = 1; j <= N; j++) 121 for (j = 1; j <= N; j++)
122 { 122 {
123 x = i - dt0 * u[nsIX(i, j, N)]; 123 x = i - dt0 * u[nsIX(i, j, N)];
124 y = j - dt0 * v[nsIX(i, j, N)]; 124 y = j - dt0 * v[nsIX(i, j, N)];
125 125
126 if (x < 0.5) 126 if (x < 0.5)
127 x = 0.5; 127 x = 0.5;
128 if (x > N + 0.5) 128 if (x > N + 0.5)
129 x = N + 0.5; 129 x = N + 0.5;
130 i0 = (int)x; 130 i0 = (int)x;
131 i1 = i0 + 1; 131 i1 = i0 + 1;
132 132
133 if (y < 0.5) 133 if (y < 0.5)
134 y = 0.5; 134 y = 0.5;
135 if (y > N + 0.5) 135 if (y > N + 0.5)
136 y = N + 0.5; 136 y = N + 0.5;
137 j0 = (int)y; 137 j0 = (int)y;
138 j1 = j0 + 1; 138 j1 = j0 + 1;
139 139
140 s1 = x - i0; 140 s1 = x - i0;
141 s0 = 1 - s1; 141 s0 = 1 - s1;
142 t1 = y - j0; 142 t1 = y - j0;
143 t0 = 1 - t1; 143 t0 = 1 - t1;
144 144
145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) + 145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) +
146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]); 146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]);
147 } 147 }
148 } 148 }
149 149
150 nsSetBnd(N, b, ref d); 150 nsSetBnd(N, b, ref d);
151 } 151 }
152 152
153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div) 153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div)
154 { 154 {
155 int i, j; 155 int i, j;
156 156
157 for (i = 1; i <= N; i++) 157 for (i = 1; i <= N; i++)
158 { 158 {
159 for (j = 1; j <= N; j++) 159 for (j = 1; j <= N; j++)
160 { 160 {
161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N; 161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N;
162 p[nsIX(i, j, N)] = 0; 162 p[nsIX(i, j, N)] = 0;
163 } 163 }
164 } 164 }
165 165
166 nsSetBnd(N, 0, ref div); 166 nsSetBnd(N, 0, ref div);
167 nsSetBnd(N, 0, ref p); 167 nsSetBnd(N, 0, ref p);
168 168
169 nsLinSolve(N, 0, ref p, ref div, 1, 4); 169 nsLinSolve(N, 0, ref p, ref div, 1, 4);
170 170
171 for (i = 1; i <= N; i++) 171 for (i = 1; i <= N; i++)
172 { 172 {
173 for (j = 1; j <= N; j++) 173 for (j = 1; j <= N; j++)
174 { 174 {
175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); 175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]);
176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); 176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]);
177 } 177 }
178 } 178 }
179 179
180 nsSetBnd(N, 1, ref u); 180 nsSetBnd(N, 1, ref u);
181 nsSetBnd(N, 2, ref v); 181 nsSetBnd(N, 2, ref v);
182 } 182 }
183 183
184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt) 184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt)
185 { 185 {
186 nsAddSource(N, ref x, ref x0, dt); 186 nsAddSource(N, ref x, ref x0, dt);
187 nsSwap(ref x0, ref x); 187 nsSwap(ref x0, ref x);
188 nsDiffuse(N, 0, ref x, ref x0, diff, dt); 188 nsDiffuse(N, 0, ref x, ref x0, diff, dt);
189 nsSwap(ref x0, ref x); 189 nsSwap(ref x0, ref x);
190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); 190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt);
191 } 191 }
192 192
193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt) 193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt)
194 { 194 {
195 nsAddSource(N, ref u, ref u0, dt); 195 nsAddSource(N, ref u, ref u0, dt);
196 nsAddSource(N, ref v, ref v0, dt); 196 nsAddSource(N, ref v, ref v0, dt);
197 nsSwap(ref u0, ref u); 197 nsSwap(ref u0, ref u);
198 nsDiffuse(N, 1, ref u, ref u0, visc, dt); 198 nsDiffuse(N, 1, ref u, ref u0, visc, dt);
199 nsSwap(ref v0, ref v); 199 nsSwap(ref v0, ref v);
200 nsDiffuse(N, 2, ref v, ref v0, visc, dt); 200 nsDiffuse(N, 2, ref v, ref v0, visc, dt);
201 nsProject(N, ref u, ref v, ref u0, ref v0); 201 nsProject(N, ref u, ref v, ref u0, ref v0);
202 nsSwap(ref u0, ref u); 202 nsSwap(ref u0, ref u);
203 nsSwap(ref v0, ref v); 203 nsSwap(ref v0, ref v);
204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt); 204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt);
205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt); 205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt);
206 nsProject(N, ref u, ref v, ref u0, ref v0); 206 nsProject(N, ref u, ref v, ref u0, ref v0);
207 } 207 }
208 208
209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles) 209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles)
210 { 210 {
211 int i; 211 int i;
212 int j; 212 int j;
213 213
214 for (i = 1; i <= N; i++) 214 for (i = 1; i <= N; i++)
215 { 215 {
216 for (j = 1; j <= N; j++) 216 for (j = 1; j <= N; j++)
217 { 217 {
218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)]; 218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)];
219 } 219 }
220 } 220 }
221 } 221 }
222 222
223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens) 223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens)
224 { 224 {
225 int i; 225 int i;
226 int j; 226 int j;
227 227
228 for (i = 1; i <= N; i++) 228 for (i = 1; i <= N; i++)
229 { 229 {
230 for (j = 1; j <= N; j++) 230 for (j = 1; j <= N; j++)
231 { 231 {
232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1]; 232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1];
233 } 233 }
234 } 234 }
235 } 235 }
236 236
237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc) 237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc)
238 { 238 {
239 int size = (N * 2) * (N * 2); 239 int size = (N * 2) * (N * 2);
240 240
241 double[] u = new double[size]; // Force, X axis 241 double[] u = new double[size]; // Force, X axis
242 double[] v = new double[size]; // Force, Y axis 242 double[] v = new double[size]; // Force, Y axis
243 double[] u_prev = new double[size]; 243 double[] u_prev = new double[size];
244 double[] v_prev = new double[size]; 244 double[] v_prev = new double[size];
245 double[] dens = new double[size]; 245 double[] dens = new double[size];
246 double[] dens_prev = new double[size]; 246 double[] dens_prev = new double[size];
247 247
248 nsDoublesToBuffer(this.map, N, ref dens); 248 nsDoublesToBuffer(this.map, N, ref dens);
249 nsDoublesToBuffer(this.map, N, ref dens_prev); 249 nsDoublesToBuffer(this.map, N, ref dens_prev);
250 250
251 for (int i = 0; i < rounds; i++) 251 for (int i = 0; i < rounds; i++)
252 { 252 {
253 u_prev = u; 253 u_prev = u;
254 v_prev = v; 254 v_prev = v;
255 dens_prev = dens; 255 dens_prev = dens;
256 256
257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
259 } 259 }
260 260
261 nsBufferToDoubles(ref dens, N, ref this.map); 261 nsBufferToDoubles(ref dens, N, ref this.map);
262 } 262 }
263 263
264 /// <summary> 264 /// <summary>
265 /// Performs computational fluid dynamics on a channel 265 /// Performs computational fluid dynamics on a channel
266 /// </summary> 266 /// </summary>
267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param> 267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param>
268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param> 268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param>
269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param> 269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param>
270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> 270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param>
271 public void navierStokes(int rounds, double dt, double diff, double visc) 271 public void navierStokes(int rounds, double dt, double diff, double visc)
272 { 272 {
273 nsSimulate(this.h, rounds, dt, diff, visc); 273 nsSimulate(this.h, rounds, dt, diff, visc);
274 } 274 }
275 275
276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) 276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret)
277 { 277 {
278 int N = this.h; 278 int N = this.h;
279 279
280 int size = (N * 2) * (N * 2); 280 int size = (N * 2) * (N * 2);
281 281
282 double[] u = new double[size]; // Force, X axis 282 double[] u = new double[size]; // Force, X axis
283 double[] v = new double[size]; // Force, Y axis 283 double[] v = new double[size]; // Force, Y axis
284 double[] u_prev = new double[size]; 284 double[] u_prev = new double[size];
285 double[] v_prev = new double[size]; 285 double[] v_prev = new double[size];
286 double[] dens = new double[size]; 286 double[] dens = new double[size];
287 double[] dens_prev = new double[size]; 287 double[] dens_prev = new double[size];
288 288
289 nsDoublesToBuffer(this.map, N, ref dens); 289 nsDoublesToBuffer(this.map, N, ref dens);
290 nsDoublesToBuffer(this.map, N, ref dens_prev); 290 nsDoublesToBuffer(this.map, N, ref dens_prev);
291 291
292 for (int i = 0; i < rounds; i++) 292 for (int i = 0; i < rounds; i++)
293 { 293 {
294 u_prev = u; 294 u_prev = u;
295 v_prev = v; 295 v_prev = v;
296 dens_prev = dens; 296 dens_prev = dens;
297 297
298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
300 } 300 }
301 301
302 nsBufferToDoubles(ref u, N, ref uret); 302 nsBufferToDoubles(ref u, N, ref uret);
303 nsBufferToDoubles(ref v, N, ref vret); 303 nsBufferToDoubles(ref v, N, ref vret);
304 nsBufferToDoubles(ref dens, N, ref this.map); 304 nsBufferToDoubles(ref dens, N, ref this.map);
305 } 305 }
306 } 306 }
307} \ No newline at end of file 307} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
index 07c7d66..695d501 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
@@ -1,112 +1,112 @@
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 /// <summary> 37 /// <summary>
38 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original. 38 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original.
39 /// </summary> 39 /// </summary>
40 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param> 40 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param>
41 /// <param name="rounds">The number of erosion rounds</param> 41 /// <param name="rounds">The number of erosion rounds</param>
42 /// <param name="c">The amount of rock to carry each round</param> 42 /// <param name="c">The amount of rock to carry each round</param>
43 public Channel ThermalWeathering(double talus, int rounds, double c) 43 public Channel ThermalWeathering(double talus, int rounds, double c)
44 { 44 {
45 SetDiff(); 45 SetDiff();
46 46
47 double[,] lastFrame; 47 double[,] lastFrame;
48 double[,] thisFrame; 48 double[,] thisFrame;
49 49
50 lastFrame = (double[,])map.Clone(); 50 lastFrame = (double[,])map.Clone();
51 thisFrame = (double[,])map.Clone(); 51 thisFrame = (double[,])map.Clone();
52 52
53 NeighbourSystem type = NeighbourSystem.Moore; // Using moore neighbourhood (twice as computationally expensive) 53 NeighbourSystem type = NeighbourSystem.Moore; // Using moore neighbourhood (twice as computationally expensive)
54 int NEIGHBOUR_ME = 4; // I am always 4 in both systems. 54 int NEIGHBOUR_ME = 4; // I am always 4 in both systems.
55 55
56 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 56 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
57 57
58 int frames = rounds; // Number of thermal erosion iterations to run 58 int frames = rounds; // Number of thermal erosion iterations to run
59 int i, j; 59 int i, j;
60 int x, y; 60 int x, y;
61 61
62 for (i = 0; i < frames; i++) 62 for (i = 0; i < frames; i++)
63 { 63 {
64 for (x = 0; x < w; x++) 64 for (x = 0; x < w; x++)
65 { 65 {
66 for (y = 0; y < h; y++) 66 for (y = 0; y < h; y++)
67 { 67 {
68 for (j = 0; j < NEIGHBOUR_MAX; j++) 68 for (j = 0; j < NEIGHBOUR_MAX; j++)
69 { 69 {
70 if (j != NEIGHBOUR_ME) 70 if (j != NEIGHBOUR_ME)
71 { 71 {
72 int[] coords = Neighbours(type, j); 72 int[] coords = Neighbours(type, j);
73 73
74 coords[0] += x; 74 coords[0] += x;
75 coords[1] += y; 75 coords[1] += y;
76 76
77 if (coords[0] > w - 1) 77 if (coords[0] > w - 1)
78 coords[0] = w - 1; 78 coords[0] = w - 1;
79 if (coords[1] > h - 1) 79 if (coords[1] > h - 1)
80 coords[1] = h - 1; 80 coords[1] = h - 1;
81 if (coords[0] < 0) 81 if (coords[0] < 0)
82 coords[0] = 0; 82 coords[0] = 0;
83 if (coords[1] < 0) 83 if (coords[1] < 0)
84 coords[1] = 0; 84 coords[1] = 0;
85 85
86 double heightF = thisFrame[x, y]; 86 double heightF = thisFrame[x, y];
87 double target = thisFrame[coords[0], coords[1]]; 87 double target = thisFrame[coords[0], coords[1]];
88 88
89 if (target > heightF + talus) 89 if (target > heightF + talus)
90 { 90 {
91 double calc = c * ((target - heightF) - talus); 91 double calc = c * ((target - heightF) - talus);
92 heightF += calc; 92 heightF += calc;
93 target -= calc; 93 target -= calc;
94 } 94 }
95 95
96 thisFrame[x, y] = heightF; 96 thisFrame[x, y] = heightF;
97 thisFrame[coords[0], coords[1]] = target; 97 thisFrame[coords[0], coords[1]] = target;
98 98
99 } 99 }
100 } 100 }
101 } 101 }
102 } 102 }
103 lastFrame = (double[,])thisFrame.Clone(); 103 lastFrame = (double[,])thisFrame.Clone();
104 } 104 }
105 105
106 map = thisFrame; 106 map = thisFrame;
107 107
108 Normalise(); // Just to guaruntee a smooth 0..1 value 108 Normalise(); // Just to guaruntee a smooth 0..1 value
109 return this; 109 return this;
110 } 110 }
111 } 111 }
112} 112}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
index 6dc2e30..da03871 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
@@ -1,141 +1,141 @@
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 enum NeighbourSystem 37 enum NeighbourSystem
38 { 38 {
39 Moore, 39 Moore,
40 VonNeumann 40 VonNeumann
41 }; 41 };
42 42
43 private int[] Neighbours(NeighbourSystem type, int index) 43 private int[] Neighbours(NeighbourSystem type, int index)
44 { 44 {
45 int[] coord = new int[2]; 45 int[] coord = new int[2];
46 46
47 index++; 47 index++;
48 48
49 switch (type) 49 switch (type)
50 { 50 {
51 case NeighbourSystem.Moore: 51 case NeighbourSystem.Moore:
52 switch (index) 52 switch (index)
53 { 53 {
54 case 1: 54 case 1:
55 coord[0] = -1; 55 coord[0] = -1;
56 coord[1] = -1; 56 coord[1] = -1;
57 break; 57 break;
58 58
59 case 2: 59 case 2:
60 coord[0] = -0; 60 coord[0] = -0;
61 coord[1] = -1; 61 coord[1] = -1;
62 break; 62 break;
63 63
64 case 3: 64 case 3:
65 coord[0] = +1; 65 coord[0] = +1;
66 coord[1] = -1; 66 coord[1] = -1;
67 break; 67 break;
68 68
69 case 4: 69 case 4:
70 coord[0] = -1; 70 coord[0] = -1;
71 coord[1] = -0; 71 coord[1] = -0;
72 break; 72 break;
73 73
74 case 5: 74 case 5:
75 coord[0] = -0; 75 coord[0] = -0;
76 coord[1] = -0; 76 coord[1] = -0;
77 break; 77 break;
78 78
79 case 6: 79 case 6:
80 coord[0] = +1; 80 coord[0] = +1;
81 coord[1] = -0; 81 coord[1] = -0;
82 break; 82 break;
83 83
84 case 7: 84 case 7:
85 coord[0] = -1; 85 coord[0] = -1;
86 coord[1] = +1; 86 coord[1] = +1;
87 break; 87 break;
88 88
89 case 8: 89 case 8:
90 coord[0] = -0; 90 coord[0] = -0;
91 coord[1] = +1; 91 coord[1] = +1;
92 break; 92 break;
93 93
94 case 9: 94 case 9:
95 coord[0] = +1; 95 coord[0] = +1;
96 coord[1] = +1; 96 coord[1] = +1;
97 break; 97 break;
98 98
99 default: 99 default:
100 break; 100 break;
101 } 101 }
102 break; 102 break;
103 103
104 case NeighbourSystem.VonNeumann: 104 case NeighbourSystem.VonNeumann:
105 switch (index) 105 switch (index)
106 { 106 {
107 case 1: 107 case 1:
108 coord[0] = 0; 108 coord[0] = 0;
109 coord[1] = -1; 109 coord[1] = -1;
110 break; 110 break;
111 111
112 case 2: 112 case 2:
113 coord[0] = -1; 113 coord[0] = -1;
114 coord[1] = 0; 114 coord[1] = 0;
115 break; 115 break;
116 116
117 case 3: 117 case 3:
118 coord[0] = +1; 118 coord[0] = +1;
119 coord[1] = 0; 119 coord[1] = 0;
120 break; 120 break;
121 121
122 case 4: 122 case 4:
123 coord[0] = 0; 123 coord[0] = 0;
124 coord[1] = +1; 124 coord[1] = +1;
125 break; 125 break;
126 126
127 case 5: 127 case 5:
128 coord[0] = -0; 128 coord[0] = -0;
129 coord[1] = -0; 129 coord[1] = -0;
130 break; 130 break;
131 131
132 default: 132 default:
133 break; 133 break;
134 } 134 }
135 break; 135 break;
136 } 136 }
137 137
138 return coord; 138 return coord;
139 } 139 }
140 } 140 }
141} 141}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
index 3199ddc..8184f06 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
@@ -1,243 +1,243 @@
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 /* Operator combination of channel datatypes */ 37 /* Operator combination of channel datatypes */
38 38
39 public static Channel operator +(Channel A, Channel B) 39 public static Channel operator +(Channel A, Channel B)
40 { 40 {
41 if (A.h != B.h) 41 if (A.h != B.h)
42 throw new Exception("Cannot add heightmaps, of different height."); 42 throw new Exception("Cannot add heightmaps, of different height.");
43 if (A.w != B.w) 43 if (A.w != B.w)
44 throw new Exception("Cannot add heightmaps, of different width."); 44 throw new Exception("Cannot add heightmaps, of different width.");
45 45
46 int x, y; 46 int x, y;
47 47
48 for (x = 0; x < A.w; x++) 48 for (x = 0; x < A.w; x++)
49 { 49 {
50 for (y = 0; y < A.h; y++) 50 for (y = 0; y < A.h; y++)
51 { 51 {
52 if (B.map[x, y] != 0) 52 if (B.map[x, y] != 0)
53 A.SetDiff(x, y); 53 A.SetDiff(x, y);
54 54
55 A.map[x, y] += B.map[x, y]; 55 A.map[x, y] += B.map[x, y];
56 } 56 }
57 } 57 }
58 58
59 return A; 59 return A;
60 } 60 }
61 61
62 public static Channel operator *(Channel A, Channel B) 62 public static Channel operator *(Channel A, Channel B)
63 { 63 {
64 if (A.h != B.h) 64 if (A.h != B.h)
65 throw new Exception("Cannot multiply heightmaps, of different height."); 65 throw new Exception("Cannot multiply heightmaps, of different height.");
66 if (A.w != B.w) 66 if (A.w != B.w)
67 throw new Exception("Cannot multiply heightmaps, of different width."); 67 throw new Exception("Cannot multiply heightmaps, of different width.");
68 68
69 int x, y; 69 int x, y;
70 70
71 for (x = 0; x < A.w; x++) 71 for (x = 0; x < A.w; x++)
72 { 72 {
73 for (y = 0; y < A.h; y++) 73 for (y = 0; y < A.h; y++)
74 { 74 {
75 A.map[x, y] *= B.map[x, y]; 75 A.map[x, y] *= B.map[x, y];
76 } 76 }
77 } 77 }
78 78
79 A.SetDiff(); 79 A.SetDiff();
80 80
81 return A; 81 return A;
82 } 82 }
83 83
84 public static Channel operator -(Channel A, Channel B) 84 public static Channel operator -(Channel A, Channel B)
85 { 85 {
86 if (A.h != B.h) 86 if (A.h != B.h)
87 throw new Exception("Cannot subtract heightmaps, of different height."); 87 throw new Exception("Cannot subtract heightmaps, of different height.");
88 if (A.w != B.w) 88 if (A.w != B.w)
89 throw new Exception("Cannot subtract heightmaps, of different width."); 89 throw new Exception("Cannot subtract heightmaps, of different width.");
90 90
91 int x, y; 91 int x, y;
92 92
93 for (x = 0; x < A.w; x++) 93 for (x = 0; x < A.w; x++)
94 { 94 {
95 for (y = 0; y < A.h; y++) 95 for (y = 0; y < A.h; y++)
96 { 96 {
97 if (B.map[x, y] != 0) 97 if (B.map[x, y] != 0)
98 A.SetDiff(x, y); 98 A.SetDiff(x, y);
99 A.map[x, y] -= B.map[x, y]; 99 A.map[x, y] -= B.map[x, y];
100 } 100 }
101 } 101 }
102 102
103 return A; 103 return A;
104 } 104 }
105 105
106 public static Channel operator /(Channel A, Channel B) 106 public static Channel operator /(Channel A, Channel B)
107 { 107 {
108 if (A.h != B.h) 108 if (A.h != B.h)
109 throw new Exception("Cannot divide heightmaps, of different height."); 109 throw new Exception("Cannot divide heightmaps, of different height.");
110 if (A.w != B.w) 110 if (A.w != B.w)
111 throw new Exception("Cannot divide heightmaps, of different width."); 111 throw new Exception("Cannot divide heightmaps, of different width.");
112 112
113 int x, y; 113 int x, y;
114 114
115 for (x = 0; x < A.w; x++) 115 for (x = 0; x < A.w; x++)
116 { 116 {
117 for (y = 0; y < A.h; y++) 117 for (y = 0; y < A.h; y++)
118 { 118 {
119 A.map[x, y] /= B.map[x, y]; 119 A.map[x, y] /= B.map[x, y];
120 } 120 }
121 } 121 }
122 122
123 A.SetDiff(); 123 A.SetDiff();
124 124
125 return A; 125 return A;
126 } 126 }
127 127
128 public static Channel operator ^(Channel A, Channel B) 128 public static Channel operator ^(Channel A, Channel B)
129 { 129 {
130 if (A.h != B.h) 130 if (A.h != B.h)
131 throw new Exception("Cannot divide heightmaps, of different height."); 131 throw new Exception("Cannot divide heightmaps, of different height.");
132 if (A.w != B.w) 132 if (A.w != B.w)
133 throw new Exception("Cannot divide heightmaps, of different width."); 133 throw new Exception("Cannot divide heightmaps, of different width.");
134 134
135 int x, y; 135 int x, y;
136 136
137 for (x = 0; x < A.w; x++) 137 for (x = 0; x < A.w; x++)
138 { 138 {
139 for (y = 0; y < A.h; y++) 139 for (y = 0; y < A.h; y++)
140 { 140 {
141 A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]); 141 A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]);
142 } 142 }
143 } 143 }
144 144
145 A.SetDiff(); 145 A.SetDiff();
146 146
147 return A; 147 return A;
148 } 148 }
149 149
150 150
151 /* Operator combination of channel and double datatypes */ 151 /* Operator combination of channel and double datatypes */
152 152
153 public static Channel operator +(Channel A, double B) 153 public static Channel operator +(Channel A, double B)
154 { 154 {
155 int x, y; 155 int x, y;
156 156
157 for (x = 0; x < A.w; x++) 157 for (x = 0; x < A.w; x++)
158 { 158 {
159 for (y = 0; y < A.h; y++) 159 for (y = 0; y < A.h; y++)
160 { 160 {
161 A.map[x, y] += B; 161 A.map[x, y] += B;
162 } 162 }
163 } 163 }
164 164
165 if (B != 0) 165 if (B != 0)
166 A.SetDiff(); 166 A.SetDiff();
167 167
168 return A; 168 return A;
169 } 169 }
170 170
171 public static Channel operator -(Channel A, double B) 171 public static Channel operator -(Channel A, double B)
172 { 172 {
173 int x, y; 173 int x, y;
174 174
175 for (x = 0; x < A.w; x++) 175 for (x = 0; x < A.w; x++)
176 { 176 {
177 for (y = 0; y < A.h; y++) 177 for (y = 0; y < A.h; y++)
178 { 178 {
179 A.map[x, y] -= B; 179 A.map[x, y] -= B;
180 } 180 }
181 } 181 }
182 182
183 if (B != 0) 183 if (B != 0)
184 A.SetDiff(); 184 A.SetDiff();
185 185
186 return A; 186 return A;
187 } 187 }
188 188
189 public static Channel operator *(Channel A, double B) 189 public static Channel operator *(Channel A, double B)
190 { 190 {
191 int x, y; 191 int x, y;
192 192
193 for (x = 0; x < A.w; x++) 193 for (x = 0; x < A.w; x++)
194 { 194 {
195 for (y = 0; y < A.h; y++) 195 for (y = 0; y < A.h; y++)
196 { 196 {
197 A.map[x, y] *= B; 197 A.map[x, y] *= B;
198 } 198 }
199 } 199 }
200 200
201 if (B != 1) 201 if (B != 1)
202 A.SetDiff(); 202 A.SetDiff();
203 203
204 return A; 204 return A;
205 } 205 }
206 206
207 public static Channel operator /(Channel A, double B) 207 public static Channel operator /(Channel A, double B)
208 { 208 {
209 int x, y; 209 int x, y;
210 210
211 for (x = 0; x < A.w; x++) 211 for (x = 0; x < A.w; x++)
212 { 212 {
213 for (y = 0; y < A.h; y++) 213 for (y = 0; y < A.h; y++)
214 { 214 {
215 A.map[x, y] /= B; 215 A.map[x, y] /= B;
216 } 216 }
217 } 217 }
218 218
219 if (B != 1) 219 if (B != 1)
220 A.SetDiff(); 220 A.SetDiff();
221 221
222 return A; 222 return A;
223 } 223 }
224 224
225 public static Channel operator ^(Channel A, double B) 225 public static Channel operator ^(Channel A, double B)
226 { 226 {
227 int x, y; 227 int x, y;
228 228
229 for (x = 0; x < A.w; x++) 229 for (x = 0; x < A.w; x++)
230 { 230 {
231 for (y = 0; y < A.h; y++) 231 for (y = 0; y < A.h; y++)
232 { 232 {
233 A.map[x, y] = Math.Pow(A.map[x,y],B); 233 A.map[x, y] = Math.Pow(A.map[x,y],B);
234 } 234 }
235 } 235 }
236 236
237 A.SetDiff(); 237 A.SetDiff();
238 238
239 return A; 239 return A;
240 } 240 }
241 241
242 } 242 }
243} 243}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
index 69c1148..785ba0d 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
@@ -1,49 +1,49 @@
1/* 1/*
2Redistribution and use in source and binary forms, with or without 2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are 3modification, are permitted provided that the following conditions are
4met: 4met:
5 5
6 * Redistributions of source code must retain the above copyright 6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer. 7 notice, this list of conditions and the following disclaimer.
8 8
9 * Redistributions in binary form must reproduce the above 9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following 10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided 11 disclaimer in the documentation and/or other materials provided
12 with the distribution. 12 with the distribution.
13 13
14 * Neither the name of libTerrain nor the names of 14 * Neither the name of libTerrain nor the names of
15 its contributors may be used to endorse or promote products 15 its contributors may be used to endorse or promote products
16 derived from this software without specific prior written 16 derived from this software without specific prior written
17 permission. 17 permission.
18 18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/ 30*/
31 31
32using System; 32using System;
33using System.Collections.Generic; 33using System.Collections.Generic;
34using System.Text; 34using System.Text;
35 35
36namespace libTerrain 36namespace libTerrain
37{ 37{
38 public class Point2D 38 public class Point2D
39 { 39 {
40 public double x; 40 public double x;
41 public double y; 41 public double y;
42 42
43 public Point2D(double X, double Y) 43 public Point2D(double X, double Y)
44 { 44 {
45 x = X; 45 x = X;
46 y = Y; 46 y = Y;
47 } 47 }
48 } 48 }
49} 49}