From 18a5cfd10fa6fa2d3b94f1be7edb656f9688ee27 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 17 Jul 2008 20:58:24 +0000 Subject: terrain is close to working, but I still end up at the bottom of the sea right now. --- OpenSim/Data/NHibernate/NHibernateRegionData.cs | 9 +++---- .../Resources/MySQLDialect/002_RegionStore.sql | 2 +- OpenSim/Data/NHibernate/Terrain.cs | 31 +++++++++++++++------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs index 2167002..9d6409e 100644 --- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs +++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs @@ -298,13 +298,10 @@ namespace OpenSim.Data.NHibernate Terrain t = session.Load(typeof(Terrain), regionID) as Terrain; return t.Doubles; } - catch (Exception e) + catch (NHibernate.ObjectNotFoundException e) { - m_log.Error("[NHIBERNATE] issue loading terrain", e); - - double[,] terret = new double[256,256]; - terret.Initialize(); - return terret; + m_log.Info("No terrain yet"); + return null; } } diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql index 4e9c974..fc11e95 100644 --- a/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql +++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/002_RegionStore.sql @@ -2,7 +2,7 @@ BEGIN; CREATE TABLE `Terrain` ( `RegionID` char(36) not null, - `Map` blob, + `Map` longblob, PRIMARY KEY (`RegionID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/OpenSim/Data/NHibernate/Terrain.cs b/OpenSim/Data/NHibernate/Terrain.cs index 4c184da..a95e45a 100644 --- a/OpenSim/Data/NHibernate/Terrain.cs +++ b/OpenSim/Data/NHibernate/Terrain.cs @@ -27,13 +27,17 @@ using System; using System.IO; +using System.Reflection; using OpenSim.Framework; +using log4net; using libsecondlife; namespace OpenSim.Data.NHibernate { public class Terrain { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private double[,] map; private LLUUID regionID; @@ -70,29 +74,36 @@ namespace OpenSim.Data.NHibernate private static double[,] parseTerrain(byte[] data) { - double[,] terret = new double[Constants.RegionSize,Constants.RegionSize]; + double[,] terret = new double[256,256]; terret.Initialize(); MemoryStream str = new MemoryStream(data); BinaryReader br = new BinaryReader(str); - for (int x = 0; x < Constants.RegionSize; x++) - { - for (int y = 0; y < Constants.RegionSize; y++) + try { + for (int x = 0; x < 256; x++) { - 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; } 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); // TODO: COMPATIBILITY - Add byte-order conversions - for (int x = 0; x < Constants.RegionSize; x++) - for (int y = 0; y < Constants.RegionSize; y++) + for (int x = 0; x < 256; x++) + { + for (int y = 0; y < 256; y++) { double height = val[x, y]; if (height <= 0.0) @@ -100,8 +111,8 @@ namespace OpenSim.Data.NHibernate bw.Write(height); } - - return (byte[])str.ToArray(); + } + return str.ToArray(); } } } \ No newline at end of file -- cgit v1.1