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));
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
/// <param name="regionID">region UUID</param>
public void StoreTerrain(double[,] ter, LLUUID regionID)
{
Terrain t = new Terrain(regionID, ter);
SaveOrUpdate(t);
}
/// <summary>
@ -288,12 +291,20 @@ namespace OpenSim.Data.NHibernate
/// <returns>Heightfield data</returns>
public double[,] LoadTerrain(LLUUID regionID)
{
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;
}
}
/// <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="State" type="System.Byte" />
</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>
</hibernate-mapping>

View File

@ -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];