From 4663999c243e7ac6f05f3bb6b76fefb2ff285134 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Thu, 17 Jul 2008 20:58:20 +0000
Subject: first pass at Terrain implementation
---
OpenSim/Data/NHibernate/NHibernateRegionData.cs | 35 ++++++++++++++--------
.../Resources/MySQLDialect/002_RegionStore.sql | 9 ++++++
.../Data/NHibernate/Resources/RegionStore.hbm.xml | 7 ++++-
OpenSim/Data/NHibernate/Terrain.cs | 6 ++++
4 files changed, 44 insertions(+), 13 deletions(-)
create mode 100644 OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql
(limited to 'OpenSim/Data/NHibernate')
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
index 38c9b9f..fb0a545 100644
--- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
@@ -120,13 +120,14 @@ namespace OpenSim.Data.NHibernate
{
ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart));
criteria.Add(Expression.Eq("UUID", p.UUID));
- if (criteria.List().Count < 1)
+ ArrayList l = (ArrayList)criteria.List();
+ if (l.Count < 1)
{
session.Save(p);
}
- else if (criteria.List().Count == 1)
+ else if (l.Count == 1)
{
- SceneObjectPart old = (SceneObjectPart)criteria.List()[0];
+ SceneObjectPart old = (SceneObjectPart)l[0];
session.Evict(old);
session.Update(p);
}
@@ -147,13 +148,14 @@ namespace OpenSim.Data.NHibernate
{
ICriteria criteria = session.CreateCriteria(typeof(Terrain));
criteria.Add(Expression.Eq("RegionID", t.RegionID));
- if (criteria.List().Count < 1)
+ ArrayList l = (ArrayList)criteria.List();
+ if (l.Count < 1)
{
session.Save(t);
}
- else if (criteria.List().Count == 1)
+ else if (l.Count == 1)
{
- Terrain old = (Terrain)criteria.List()[0];
+ Terrain old = (Terrain)l[0];
session.Evict(old);
session.Update(t);
}
@@ -278,7 +280,8 @@ namespace OpenSim.Data.NHibernate
/// region UUID
public void StoreTerrain(double[,] ter, LLUUID regionID)
{
-
+ Terrain t = new Terrain(regionID, ter);
+ SaveOrUpdate(t);
}
///
@@ -288,11 +291,19 @@ namespace OpenSim.Data.NHibernate
/// Heightfield data
public double[,] LoadTerrain(LLUUID regionID)
{
- double[,] terret = new double[256,256];
- terret.Initialize();
-
-
- return terret;
+ try
+ {
+ Terrain t = session.Load(typeof(Terrain), regionID) as Terrain;
+ return t.Doubles;
+ }
+ catch (Exception e)
+ {
+ m_log.Error("[NHIBERNATE] issue loading terrain", e);
+
+ double[,] terret = new double[256,256];
+ terret.Initialize();
+ return terret;
+ }
}
///
diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql
new file mode 100644
index 0000000..4e9c974
--- /dev/null
+++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql
@@ -0,0 +1,9 @@
+BEGIN;
+
+CREATE TABLE `Terrain` (
+ `RegionID` char(36) not null,
+ `Map` blob,
+ PRIMARY KEY (`RegionID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+COMMIT;
\ No newline at end of file
diff --git a/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml b/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml
index 40d3864..9fc8065 100644
--- a/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml
+++ b/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml
@@ -103,6 +103,11 @@
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenSim/Data/NHibernate/Terrain.cs b/OpenSim/Data/NHibernate/Terrain.cs
index f125ae3..4c184da 100644
--- a/OpenSim/Data/NHibernate/Terrain.cs
+++ b/OpenSim/Data/NHibernate/Terrain.cs
@@ -62,6 +62,12 @@ namespace OpenSim.Data.NHibernate
set { map = parseTerrain(value); }
}
+ public double[,] Doubles
+ {
+ get {return map;}
+ set {map = value;}
+ }
+
private static double[,] parseTerrain(byte[] data)
{
double[,] terret = new double[Constants.RegionSize,Constants.RegionSize];
--
cgit v1.1