From 71bd3ce49f1159251ec4339d098d93c2119729f0 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Sat, 17 Sep 2016 16:42:40 +0100
Subject: add load baked terrain methods
---
OpenSim/Data/MySQL/MySQLSimulationData.cs | 35 ++++++++++++++++++++++
OpenSim/Data/Null/NullSimulationData.cs | 9 ++++++
OpenSim/Data/PGSQL/PGSQLSimulationData.cs | 33 ++++++++++++++++++++
OpenSim/Data/SQLite/SQLiteSimulationData.cs | 28 +++++++++++++++++
.../Framework/Interfaces/ISimulationDataStore.cs | 3 +-
.../SimulationService/SimulationDataService.cs | 5 ++++
OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs | 13 ++++++++
7 files changed, 125 insertions(+), 1 deletion(-)
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index 1a57199..ab24b76 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -733,6 +733,41 @@ namespace OpenSim.Data.MySQL
return terrData;
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ TerrainData terrData = null;
+
+ lock (m_dbLock)
+ {
+ using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+ {
+ dbcon.Open();
+
+ using (MySqlCommand cmd = dbcon.CreateCommand())
+ {
+ cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
+ "from bakedterrain where RegionUUID = ?RegionUUID ";
+ cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
+
+ using (IDataReader reader = ExecuteReader(cmd))
+ {
+ while (reader.Read())
+ {
+ int rev = Convert.ToInt32(reader["Revision"]);
+ if ((reader["Heightfield"] != DBNull.Value))
+ {
+ byte[] blob = (byte[])reader["Heightfield"];
+ terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return terrData;
+ }
+
public virtual void RemoveLandObject(UUID globalID)
{
lock (m_dbLock)
diff --git a/OpenSim/Data/Null/NullSimulationData.cs b/OpenSim/Data/Null/NullSimulationData.cs
index 5ea8bfa..7bb6da3 100644
--- a/OpenSim/Data/Null/NullSimulationData.cs
+++ b/OpenSim/Data/Null/NullSimulationData.cs
@@ -175,6 +175,15 @@ namespace OpenSim.Data.Null
return null;
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ if (m_bakedterrains.ContainsKey(regionID))
+ {
+ return m_bakedterrains[regionID];
+ }
+ return null;
+ }
+
public void RemoveLandObject(UUID globalID)
{
}
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index e6161a2..902aae0 100755
--- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -573,6 +573,39 @@ namespace OpenSim.Data.PGSQL
return terrData;
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ TerrainData terrData = null;
+
+ string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from bakedterrain
+ where ""RegionUUID"" = :RegionUUID; ";
+
+ using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
+ {
+ using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
+ {
+ // PGSqlParameter param = new PGSqlParameter();
+ cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
+ conn.Open();
+ using (NpgsqlDataReader reader = cmd.ExecuteReader())
+ {
+ int rev;
+ if (reader.Read())
+ {
+ rev = Convert.ToInt32(reader["Revision"]);
+ if ((reader["Heightfield"] != DBNull.Value))
+ {
+ byte[] blob = (byte[])reader["Heightfield"];
+ terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
+ }
+ }
+ }
+ }
+ }
+
+ return terrData;
+ }
+
// Legacy entry point for when terrain was always a 256x256 heightmap
public void StoreTerrain(double[,] terrain, UUID regionID)
{
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index 76b367a..0d565f7 100644
--- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
@@ -950,6 +950,34 @@ namespace OpenSim.Data.SQLite
return terrData;
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ TerrainData terrData = null;
+
+ lock (ds)
+ {
+ String sql = "select RegionUUID, Revision, Heightfield from backedterrain" +
+ " where RegionUUID=:RegionUUID";
+
+ using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
+ {
+ cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
+
+ using (IDataReader row = cmd.ExecuteReader())
+ {
+ int rev = 0;
+ if (row.Read())
+ {
+ rev = Convert.ToInt32(row["Revision"]);
+ byte[] blob = (byte[])row["Heightfield"];
+ terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
+ }
+ }
+ }
+ }
+ return terrData;
+ }
+
public void RemoveLandObject(UUID globalID)
{
lock (ds)
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
index 4940a28..8536db0 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
@@ -93,7 +93,7 @@ namespace OpenSim.Region.Framework.Interfaces
void StoreTerrain(double[,] terrain, UUID regionID);
///
- /// Load the latest terrain revision from region storage
+ /// Load terrain from region storage
///
/// the region UUID
/// the X dimension of the terrain being filled
@@ -101,6 +101,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the Z dimension of the terrain being filled
/// Heightfield data
TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ);
+ TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ);
// Legacy version kept for downward compabibility
double[,] LoadTerrain(UUID regionID);
diff --git a/OpenSim/Services/SimulationService/SimulationDataService.cs b/OpenSim/Services/SimulationService/SimulationDataService.cs
index 4ec8293..eef958a 100644
--- a/OpenSim/Services/SimulationService/SimulationDataService.cs
+++ b/OpenSim/Services/SimulationService/SimulationDataService.cs
@@ -124,6 +124,11 @@ namespace OpenSim.Services.SimulationService
return m_database.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ);
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ return m_database.LoadBakedTerrain(regionID, pSizeX, pSizeY, pSizeZ);
+ }
+
public void StoreLandObject(ILandObject Parcel)
{
m_database.StoreLandObject(Parcel);
diff --git a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
index 61fee4b..8daa19d 100644
--- a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
@@ -89,6 +89,11 @@ namespace OpenSim.Data.Null
return m_store.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ);
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ return m_store.LoadBakedTerrain(regionID, pSizeX, pSizeY, pSizeZ);
+ }
+
public void StoreLandObject(ILandObject Parcel)
{
m_store.StoreLandObject(Parcel);
@@ -343,6 +348,14 @@ namespace OpenSim.Data.Null
return null;
}
+ public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+ {
+ if (m_bakedterrains.ContainsKey(regionID))
+ return m_bakedterrains[regionID];
+ else
+ return null;
+ }
+
public double[,] LoadTerrain(UUID regionID)
{
if (m_terrains.ContainsKey(regionID))
--
cgit v1.1