first pass at Terrain implementation

0.6.0-stable
Sean Dague 2008-07-17 20:58:20 +00:00
parent 366e09b543
commit 4663999c24
4 changed files with 44 additions and 13 deletions

View File

@ -120,13 +120,14 @@ namespace OpenSim.Data.NHibernate
{ {
ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart)); ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart));
criteria.Add(Expression.Eq("UUID", p.UUID)); criteria.Add(Expression.Eq("UUID", p.UUID));
if (criteria.List().Count < 1) ArrayList l = (ArrayList)criteria.List();
if (l.Count < 1)
{ {
session.Save(p); 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.Evict(old);
session.Update(p); session.Update(p);
} }
@ -147,13 +148,14 @@ namespace OpenSim.Data.NHibernate
{ {
ICriteria criteria = session.CreateCriteria(typeof(Terrain)); ICriteria criteria = session.CreateCriteria(typeof(Terrain));
criteria.Add(Expression.Eq("RegionID", t.RegionID)); criteria.Add(Expression.Eq("RegionID", t.RegionID));
if (criteria.List().Count < 1) ArrayList l = (ArrayList)criteria.List();
if (l.Count < 1)
{ {
session.Save(t); 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.Evict(old);
session.Update(t); session.Update(t);
} }
@ -278,7 +280,8 @@ namespace OpenSim.Data.NHibernate
/// <param name="regionID">region UUID</param> /// <param name="regionID">region UUID</param>
public void StoreTerrain(double[,] ter, LLUUID regionID) public void StoreTerrain(double[,] ter, LLUUID regionID)
{ {
Terrain t = new Terrain(regionID, ter);
SaveOrUpdate(t);
} }
/// <summary> /// <summary>
@ -288,11 +291,19 @@ namespace OpenSim.Data.NHibernate
/// <returns>Heightfield data</returns> /// <returns>Heightfield data</returns>
public double[,] LoadTerrain(LLUUID regionID) public double[,] LoadTerrain(LLUUID regionID)
{ {
double[,] terret = new double[256,256]; try
terret.Initialize(); {
Terrain t = session.Load(typeof(Terrain), regionID) as Terrain;
return t.Doubles;
return terret; }
catch (Exception e)
{
m_log.Error("[NHIBERNATE] issue loading terrain", e);
double[,] terret = new double[256,256];
terret.Initialize();
return terret;
}
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,9 @@
BEGIN;
CREATE TABLE `Terrain` (
`RegionID` char(36) not null,
`Map` blob,
PRIMARY KEY (`RegionID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
COMMIT;

View File

@ -103,6 +103,11 @@
<property name="ExtraParams" type="System.Byte[]" /> <property name="ExtraParams" type="System.Byte[]" />
<property name="State" type="System.Byte" /> <property name="State" type="System.Byte" />
</component> </component>
</class>
<class name="OpenSim.Data.NHibernate.Terrain, OpenSim.Data.NHibernate" table="Terrain" lazy="false">
<id name="RegionID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="Map" type="System.Byte[]" />
</class> </class>
</hibernate-mapping> </hibernate-mapping>

View File

@ -62,6 +62,12 @@ namespace OpenSim.Data.NHibernate
set { map = parseTerrain(value); } set { map = parseTerrain(value); }
} }
public double[,] Doubles
{
get {return map;}
set {map = value;}
}
private static double[,] parseTerrain(byte[] data) private static double[,] parseTerrain(byte[] data)
{ {
double[,] terret = new double[Constants.RegionSize,Constants.RegionSize]; double[,] terret = new double[Constants.RegionSize,Constants.RegionSize];