aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs62
1 files changed, 32 insertions, 30 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);