aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs62
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs32
-rw-r--r--OpenSim/Data/Null/NullSimulationData.cs21
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs48
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs29
5 files changed, 97 insertions, 95 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index dbfd16c..9f5991b 100644
--- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
@@ -531,43 +531,43 @@ ELSE
531 /// <returns></returns> 531 /// <returns></returns>
532 public double[,] LoadTerrain(UUID regionID) 532 public double[,] LoadTerrain(UUID regionID)
533 { 533 {
534 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 534 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
535 terrain.Initialize(); 535 return terrData.GetDoubles();
536 }
537
538 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
539 {
540 TerrainData terrData = null;
536 541
537 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc"; 542 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
538 543
539 using (SqlConnection conn = new SqlConnection(m_connectionString)) 544 using (SqlConnection conn = new SqlConnection(m_connectionString))
540 using (SqlCommand cmd = new SqlCommand(sql, conn))
541 { 545 {
542 // MySqlParameter param = new MySqlParameter(); 546 using (SqlCommand cmd = new SqlCommand(sql, conn))
543 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
544 conn.Open();
545 using (SqlDataReader reader = cmd.ExecuteReader())
546 { 547 {
547 int rev; 548 // MySqlParameter param = new MySqlParameter();
548 if (reader.Read()) 549 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
550 conn.Open();
551 using (SqlDataReader reader = cmd.ExecuteReader())
549 { 552 {
550 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 553 int rev;
551 BinaryReader br = new BinaryReader(str); 554 if (reader.Read())
552 for (int x = 0; x < (int)Constants.RegionSize; x++)
553 { 555 {
554 for (int y = 0; y < (int)Constants.RegionSize; y++) 556 rev = (int)reader["Revision"];
555 { 557 byte[] blob = (byte[])reader["Heightfield"];
556 terrain[x, y] = br.ReadDouble(); 558 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
557 }
558 } 559 }
559 rev = (int)reader["Revision"]; 560 else
560 } 561 {
561 else 562 _Log.Info("[REGION DB]: No terrain found for region");
562 { 563 return null;
563 _Log.Info("[REGION DB]: No terrain found for region"); 564 }
564 return null; 565 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
565 } 566 }
566 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
567 } 567 }
568 } 568 }
569 569
570 return terrain; 570 return terrData;
571 } 571 }
572 572
573 // Legacy entry point for when terrain was always a 256x256 hieghtmap 573 // Legacy entry point for when terrain was always a 256x256 hieghtmap
@@ -600,13 +600,15 @@ ELSE
600 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); 600 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
601 601
602 using (SqlConnection conn = new SqlConnection(m_connectionString)) 602 using (SqlConnection conn = new SqlConnection(m_connectionString))
603 using (SqlCommand cmd = new SqlCommand(sql, conn))
604 { 603 {
605 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); 604 using (SqlCommand cmd = new SqlCommand(sql, conn))
606 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision)); 605 {
607 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob)); 606 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
608 conn.Open(); 607 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision));
609 cmd.ExecuteNonQuery(); 608 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob));
609 conn.Open();
610 cmd.ExecuteNonQuery();
611 }
610 } 612 }
611 613
612 _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision); 614 _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision);
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index 4bd8617..42f2ebb 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -613,9 +613,16 @@ namespace OpenSim.Data.MySQL
613 } 613 }
614 } 614 }
615 615
616 // Legacy region loading
616 public double[,] LoadTerrain(UUID regionID) 617 public double[,] LoadTerrain(UUID regionID)
617 { 618 {
618 double[,] terrain = null; 619 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
620 return terrData.GetDoubles();
621 }
622
623 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
624 {
625 TerrainData terrData = null;
619 626
620 lock (m_dbLock) 627 lock (m_dbLock)
621 { 628 {
@@ -635,32 +642,15 @@ namespace OpenSim.Data.MySQL
635 while (reader.Read()) 642 while (reader.Read())
636 { 643 {
637 int rev = Convert.ToInt32(reader["Revision"]); 644 int rev = Convert.ToInt32(reader["Revision"]);
638 645 byte[] blob = (byte[])reader["Heightfield"];
639 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 646 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
640 terrain.Initialize();
641
642 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
643 {
644 using (BinaryReader br = new BinaryReader(mstr))
645 {
646 for (int x = 0; x < (int)Constants.RegionSize; x++)
647 {
648 for (int y = 0; y < (int)Constants.RegionSize; y++)
649 {
650 terrain[x, y] = br.ReadDouble();
651 }
652 }
653 }
654
655 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
656 }
657 } 647 }
658 } 648 }
659 } 649 }
660 } 650 }
661 } 651 }
662 652
663 return terrain; 653 return terrData;
664 } 654 }
665 655
666 public void RemoveLandObject(UUID globalID) 656 public void RemoveLandObject(UUID globalID)
diff --git a/OpenSim/Data/Null/NullSimulationData.cs b/OpenSim/Data/Null/NullSimulationData.cs
index d11ad72..acde1a1 100644
--- a/OpenSim/Data/Null/NullSimulationData.cs
+++ b/OpenSim/Data/Null/NullSimulationData.cs
@@ -132,18 +132,35 @@ namespace OpenSim.Data.Null
132 return new List<SceneObjectGroup>(); 132 return new List<SceneObjectGroup>();
133 } 133 }
134 134
135 Dictionary<UUID, double[,]> m_terrains = new Dictionary<UUID, double[,]>(); 135 Dictionary<UUID, TerrainData> m_terrains = new Dictionary<UUID, TerrainData>();
136 public void StoreTerrain(double[,] ter, UUID regionID) 136 public void StoreTerrain(TerrainData ter, UUID regionID)
137 { 137 {
138 if (m_terrains.ContainsKey(regionID)) 138 if (m_terrains.ContainsKey(regionID))
139 m_terrains.Remove(regionID); 139 m_terrains.Remove(regionID);
140 m_terrains.Add(regionID, ter); 140 m_terrains.Add(regionID, ter);
141 } 141 }
142 142
143 // Legacy. Just don't do this.
144 public void StoreTerrain(double[,] ter, UUID regionID)
145 {
146 TerrainData terrData = new HeightmapTerrainData(ter);
147 StoreTerrain(terrData, regionID);
148 }
149
150 // Legacy. Just don't do this.
143 public double[,] LoadTerrain(UUID regionID) 151 public double[,] LoadTerrain(UUID regionID)
144 { 152 {
145 if (m_terrains.ContainsKey(regionID)) 153 if (m_terrains.ContainsKey(regionID))
146 { 154 {
155 return m_terrains[regionID].GetDoubles();
156 }
157 return null;
158 }
159
160 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
161 {
162 if (m_terrains.ContainsKey(regionID))
163 {
147 return m_terrains[regionID]; 164 return m_terrains[regionID];
148 } 165 }
149 return null; 166 return null;
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index 433ffe9..34eb038 100644
--- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -524,44 +524,44 @@ namespace OpenSim.Data.PGSQL
524 /// <returns></returns> 524 /// <returns></returns>
525 public double[,] LoadTerrain(UUID regionID) 525 public double[,] LoadTerrain(UUID regionID)
526 { 526 {
527 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 527 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
528 terrain.Initialize(); 528 return terrData.GetDoubles();
529 }
530
531 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
532 {
533 TerrainData terrData = null;
529 534
530 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain 535 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain
531 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; "; 536 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; ";
532 537
533 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 538 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
534 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
535 { 539 {
536 // PGSqlParameter param = new PGSqlParameter(); 540 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
537 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
538 conn.Open();
539 using (NpgsqlDataReader reader = cmd.ExecuteReader())
540 { 541 {
541 int rev; 542 // PGSqlParameter param = new PGSqlParameter();
542 if (reader.Read()) 543 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
544 conn.Open();
545 using (NpgsqlDataReader reader = cmd.ExecuteReader())
543 { 546 {
544 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 547 int rev;
545 BinaryReader br = new BinaryReader(str); 548 if (reader.Read())
546 for (int x = 0; x < (int)Constants.RegionSize; x++)
547 { 549 {
548 for (int y = 0; y < (int)Constants.RegionSize; y++) 550 rev = Convert.ToInt32(reader["Revision"]);
549 { 551 byte[] blob = (byte[])reader["Heightfield"];
550 terrain[x, y] = br.ReadDouble(); 552 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
551 }
552 } 553 }
553 rev = (int)reader["Revision"]; 554 else
554 } 555 {
555 else 556 _Log.Info("[REGION DB]: No terrain found for region");
556 { 557 return null;
557 _Log.Info("[REGION DB]: No terrain found for region"); 558 }
558 return null; 559 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
559 } 560 }
560 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
561 } 561 }
562 } 562 }
563 563
564 return terrain; 564 return terrData;
565 } 565 }
566 566
567 // Legacy entry point for when terrain was always a 256x256 heightmap 567 // Legacy entry point for when terrain was always a 256x256 heightmap
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index cce59c1..dac4450 100644
--- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
@@ -870,11 +870,16 @@ namespace OpenSim.Data.SQLite
870 /// <returns>Heightfield data</returns> 870 /// <returns>Heightfield data</returns>
871 public double[,] LoadTerrain(UUID regionID) 871 public double[,] LoadTerrain(UUID regionID)
872 { 872 {
873 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
874 return terrData.GetDoubles();
875 }
876
877 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
878 {
879 TerrainData terrData = null;
880
873 lock (ds) 881 lock (ds)
874 { 882 {
875 double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
876 terret.Initialize();
877
878 String sql = "select RegionUUID, Revision, Heightfield from terrain" + 883 String sql = "select RegionUUID, Revision, Heightfield from terrain" +
879 " where RegionUUID=:RegionUUID order by Revision desc"; 884 " where RegionUUID=:RegionUUID order by Revision desc";
880 885
@@ -887,21 +892,9 @@ namespace OpenSim.Data.SQLite
887 int rev = 0; 892 int rev = 0;
888 if (row.Read()) 893 if (row.Read())
889 { 894 {
890 // TODO: put this into a function
891 using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"]))
892 {
893 using (BinaryReader br = new BinaryReader(str))
894 {
895 for (int x = 0; x < (int)Constants.RegionSize; x++)
896 {
897 for (int y = 0; y < (int)Constants.RegionSize; y++)
898 {
899 terret[x, y] = br.ReadDouble();
900 }
901 }
902 }
903 }
904 rev = Convert.ToInt32(row["Revision"]); 895 rev = Convert.ToInt32(row["Revision"]);
896 byte[] blob = (byte[])row["Heightfield"];
897 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
905 } 898 }
906 else 899 else
907 { 900 {
@@ -912,8 +905,8 @@ namespace OpenSim.Data.SQLite
912 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); 905 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
913 } 906 }
914 } 907 }
915 return terret;
916 } 908 }
909 return terrData;
917 } 910 }
918 911
919 public void RemoveLandObject(UUID globalID) 912 public void RemoveLandObject(UUID globalID)