terrain is close to working, but I still end up at the bottom of the sea

right now.
0.6.0-stable
Sean Dague 2008-07-17 20:58:24 +00:00
parent 50eab18590
commit 18a5cfd10f
3 changed files with 25 additions and 17 deletions

View File

@ -298,13 +298,10 @@ namespace OpenSim.Data.NHibernate
Terrain t = session.Load(typeof(Terrain), regionID) as Terrain; Terrain t = session.Load(typeof(Terrain), regionID) as Terrain;
return t.Doubles; return t.Doubles;
} }
catch (Exception e) catch (NHibernate.ObjectNotFoundException e)
{ {
m_log.Error("[NHIBERNATE] issue loading terrain", e); m_log.Info("No terrain yet");
return null;
double[,] terret = new double[256,256];
terret.Initialize();
return terret;
} }
} }

View File

@ -2,7 +2,7 @@ BEGIN;
CREATE TABLE `Terrain` ( CREATE TABLE `Terrain` (
`RegionID` char(36) not null, `RegionID` char(36) not null,
`Map` blob, `Map` longblob,
PRIMARY KEY (`RegionID`) PRIMARY KEY (`RegionID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -27,13 +27,17 @@
using System; using System;
using System.IO; using System.IO;
using System.Reflection;
using OpenSim.Framework; using OpenSim.Framework;
using log4net;
using libsecondlife; using libsecondlife;
namespace OpenSim.Data.NHibernate namespace OpenSim.Data.NHibernate
{ {
public class Terrain public class Terrain
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private double[,] map; private double[,] map;
private LLUUID regionID; private LLUUID regionID;
@ -70,29 +74,36 @@ namespace OpenSim.Data.NHibernate
private static double[,] parseTerrain(byte[] data) private static double[,] parseTerrain(byte[] data)
{ {
double[,] terret = new double[Constants.RegionSize,Constants.RegionSize]; double[,] terret = new double[256,256];
terret.Initialize(); terret.Initialize();
MemoryStream str = new MemoryStream(data); MemoryStream str = new MemoryStream(data);
BinaryReader br = new BinaryReader(str); BinaryReader br = new BinaryReader(str);
for (int x = 0; x < Constants.RegionSize; x++) try {
{ for (int x = 0; x < 256; x++)
for (int y = 0; y < Constants.RegionSize; y++)
{ {
terret[x, y] = br.ReadDouble(); for (int y = 0; y < 256; y++)
{
terret[x, y] = br.ReadDouble();
}
} }
} }
catch (Exception e)
{
m_log.Error("Issue parsing Map", e);
}
return terret; return terret;
} }
private static byte[] serializeTerrain(double[,] val) private static byte[] serializeTerrain(double[,] val)
{ {
MemoryStream str = new MemoryStream((int)(Constants.RegionSize * Constants.RegionSize * sizeof (double))); MemoryStream str = new MemoryStream((int)(65536 * sizeof (double)));
BinaryWriter bw = new BinaryWriter(str); BinaryWriter bw = new BinaryWriter(str);
// TODO: COMPATIBILITY - Add byte-order conversions // TODO: COMPATIBILITY - Add byte-order conversions
for (int x = 0; x < Constants.RegionSize; x++) for (int x = 0; x < 256; x++)
for (int y = 0; y < Constants.RegionSize; y++) {
for (int y = 0; y < 256; y++)
{ {
double height = val[x, y]; double height = val[x, y];
if (height <= 0.0) if (height <= 0.0)
@ -100,8 +111,8 @@ namespace OpenSim.Data.NHibernate
bw.Write(height); bw.Write(height);
} }
}
return (byte[])str.ToArray(); return str.ToArray();
} }
} }
} }