diff options
author | Sean Dague | 2008-07-17 19:58:47 +0000 |
---|---|---|
committer | Sean Dague | 2008-07-17 19:58:47 +0000 |
commit | 366e09b543412d8497350986e4c6dc182c515f59 (patch) | |
tree | 7c4cb1146818a31a53e639759ecd9c021ec927f0 | |
parent | if no texture, make it plywood (diff) | |
download | opensim-SC_OLD-366e09b543412d8497350986e4c6dc182c515f59.zip opensim-SC_OLD-366e09b543412d8497350986e4c6dc182c515f59.tar.gz opensim-SC_OLD-366e09b543412d8497350986e4c6dc182c515f59.tar.bz2 opensim-SC_OLD-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.
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateRegionData.cs | 28 | ||||
-rw-r--r-- | OpenSim/Data/NHibernate/Terrain.cs | 101 |
2 files changed, 129 insertions, 0 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs index 3ba3556..38c9b9f 100644 --- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs +++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs | |||
@@ -141,6 +141,34 @@ namespace OpenSim.Data.NHibernate | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | private void SaveOrUpdate(Terrain t) | ||
145 | { | ||
146 | try | ||
147 | { | ||
148 | ICriteria criteria = session.CreateCriteria(typeof(Terrain)); | ||
149 | criteria.Add(Expression.Eq("RegionID", t.RegionID)); | ||
150 | if (criteria.List().Count < 1) | ||
151 | { | ||
152 | session.Save(t); | ||
153 | } | ||
154 | else if (criteria.List().Count == 1) | ||
155 | { | ||
156 | Terrain old = (Terrain)criteria.List()[0]; | ||
157 | session.Evict(old); | ||
158 | session.Update(t); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | m_log.Error("Not unique"); | ||
163 | } | ||
164 | } | ||
165 | catch (Exception e) | ||
166 | { | ||
167 | m_log.Error("[NHIBERNATE] issue saving asset", e); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | |||
144 | /// <summary> | 172 | /// <summary> |
145 | /// Adds an object into region storage | 173 | /// Adds an object into region storage |
146 | /// </summary> | 174 | /// </summary> |
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using OpenSim.Framework; | ||
31 | using libsecondlife; | ||
32 | |||
33 | namespace 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 | ||