aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/Terrain.cs
diff options
context:
space:
mode:
authorSean Dague2008-07-17 19:58:47 +0000
committerSean Dague2008-07-17 19:58:47 +0000
commit366e09b543412d8497350986e4c6dc182c515f59 (patch)
tree7c4cb1146818a31a53e639759ecd9c021ec927f0 /OpenSim/Data/NHibernate/Terrain.cs
parentif no texture, make it plywood (diff)
downloadopensim-SC-366e09b543412d8497350986e4c6dc182c515f59.zip
opensim-SC-366e09b543412d8497350986e4c6dc182c515f59.tar.gz
opensim-SC-366e09b543412d8497350986e4c6dc182c515f59.tar.bz2
opensim-SC-366e09b543412d8497350986e4c6dc182c515f59.tar.xz
add a Terrain object for the purpose of mapping. This may make sense
to stick up in framework later, but for now we'll just keep it close to the data.
Diffstat (limited to 'OpenSim/Data/NHibernate/Terrain.cs')
-rw-r--r--OpenSim/Data/NHibernate/Terrain.cs101
1 files changed, 101 insertions, 0 deletions
diff --git a/OpenSim/Data/NHibernate/Terrain.cs b/OpenSim/Data/NHibernate/Terrain.cs
new file mode 100644
index 0000000..f125ae3
--- /dev/null
+++ b/OpenSim/Data/NHibernate/Terrain.cs
@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using OpenSim.Framework;
31using libsecondlife;
32
33namespace OpenSim.Data.NHibernate
34{
35 public class Terrain
36 {
37 private double[,] map;
38 private LLUUID regionID;
39
40 public Terrain(LLUUID Region, double[,] array)
41 {
42 map = array;
43 regionID = Region;
44 }
45
46 public Terrain()
47 {
48 map = new double[Constants.RegionSize, Constants.RegionSize];
49 map.Initialize();
50 regionID = LLUUID.Zero;
51 }
52
53 public LLUUID RegionID
54 {
55 get { return regionID; }
56 set { regionID = value; }
57 }
58
59 public byte[] Map
60 {
61 get { return serializeTerrain(map); }
62 set { map = parseTerrain(value); }
63 }
64
65 private static double[,] parseTerrain(byte[] data)
66 {
67 double[,] terret = new double[Constants.RegionSize,Constants.RegionSize];
68 terret.Initialize();
69
70 MemoryStream str = new MemoryStream(data);
71 BinaryReader br = new BinaryReader(str);
72 for (int x = 0; x < Constants.RegionSize; x++)
73 {
74 for (int y = 0; y < Constants.RegionSize; y++)
75 {
76 terret[x, y] = br.ReadDouble();
77 }
78 }
79 return terret;
80 }
81
82 private static byte[] serializeTerrain(double[,] val)
83 {
84 MemoryStream str = new MemoryStream((int)(Constants.RegionSize * Constants.RegionSize * sizeof (double)));
85 BinaryWriter bw = new BinaryWriter(str);
86
87 // TODO: COMPATIBILITY - Add byte-order conversions
88 for (int x = 0; x < Constants.RegionSize; x++)
89 for (int y = 0; y < Constants.RegionSize; y++)
90 {
91 double height = val[x, y];
92 if (height <= 0.0)
93 height = double.Epsilon;
94
95 bw.Write(height);
96 }
97
98 return (byte[])str.ToArray();
99 }
100 }
101} \ No newline at end of file