aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
diff options
context:
space:
mode:
authorRobert Adams2015-03-27 19:32:50 -0700
committerRobert Adams2015-03-27 19:32:50 -0700
commitbedafb8fae9898ef0c5fc6470236ee7244e616a9 (patch)
tree618728d92dad56dd587c243892d966b9ff9ea89b /OpenSim/Data/MSSQL/MSSQLSimulationData.cs
parentvarregion: restore checkAgentAccessToRegion routine in EntityTransferModule. (diff)
downloadopensim-SC-bedafb8fae9898ef0c5fc6470236ee7244e616a9.zip
opensim-SC-bedafb8fae9898ef0c5fc6470236ee7244e616a9.tar.gz
opensim-SC-bedafb8fae9898ef0c5fc6470236ee7244e616a9.tar.bz2
opensim-SC-bedafb8fae9898ef0c5fc6470236ee7244e616a9.tar.xz
varregion: refactor use of 'double heightmap[,]' into references to new class TerrainData
and push the implementation from Scene into the database readers and writers.
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs83
1 files changed, 49 insertions, 34 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index 0d09be6..145b9c0 100644
--- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
@@ -530,43 +530,52 @@ ELSE
530 /// <returns></returns> 530 /// <returns></returns>
531 public double[,] LoadTerrain(UUID regionID) 531 public double[,] LoadTerrain(UUID regionID)
532 { 532 {
533 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 533 double[,] ret = null;
534 terrain.Initialize(); 534 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
535 if (terrData != null)
536 ret = terrData.GetDoubles();
537 return ret;
538 }
539
540 // Returns 'null' if region not found
541 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
542 {
543 TerrainData terrData = null;
535 544
536 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc"; 545 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
537 546
538 using (SqlConnection conn = new SqlConnection(m_connectionString)) 547 using (SqlConnection conn = new SqlConnection(m_connectionString))
539 using (SqlCommand cmd = new SqlCommand(sql, conn))
540 { 548 {
541 // MySqlParameter param = new MySqlParameter(); 549 using (SqlCommand cmd = new SqlCommand(sql, conn))
542 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
543 conn.Open();
544 using (SqlDataReader reader = cmd.ExecuteReader())
545 { 550 {
546 int rev; 551 // MySqlParameter param = new MySqlParameter();
547 if (reader.Read()) 552 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
553 conn.Open();
554 using (SqlDataReader reader = cmd.ExecuteReader())
548 { 555 {
549 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 556 if (reader.Read())
550 BinaryReader br = new BinaryReader(str);
551 for (int x = 0; x < (int)Constants.RegionSize; x++)
552 { 557 {
553 for (int y = 0; y < (int)Constants.RegionSize; y++) 558 int rev = (int)reader["Revision"];
554 { 559 byte[] blob = (byte[])reader["Heightfield"];
555 terrain[x, y] = br.ReadDouble(); 560 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
556 }
557 } 561 }
558 rev = (int)reader["Revision"]; 562 else
559 } 563 {
560 else 564 _Log.Info("[REGION DB]: No terrain found for region");
561 { 565 return null;
562 _Log.Info("[REGION DB]: No terrain found for region"); 566 }
563 return null; 567 _Log.Info("[REGION DB]: Loaded terrain");
564 } 568 }
565 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
566 } 569 }
567 } 570 }
568 571
569 return terrain; 572 return terrData;
573 }
574
575 // Legacy entry point for when terrain was always a 256x256 hieghtmap
576 public void StoreTerrain(double[,] ter, UUID regionID)
577 {
578 StoreTerrain(new HeightmapTerrainData(ter), regionID);
570 } 579 }
571 580
572 /// <summary> 581 /// <summary>
@@ -574,10 +583,8 @@ ELSE
574 /// </summary> 583 /// </summary>
575 /// <param name="terrain">terrain map data.</param> 584 /// <param name="terrain">terrain map data.</param>
576 /// <param name="regionID">regionID.</param> 585 /// <param name="regionID">regionID.</param>
577 public void StoreTerrain(double[,] terrain, UUID regionID) 586 public void StoreTerrain(TerrainData terrData, UUID regionID)
578 { 587 {
579 int revision = Util.UnixTimeSinceEpoch();
580
581 //Delete old terrain map 588 //Delete old terrain map
582 string sql = "delete from terrain where RegionUUID=@RegionUUID"; 589 string sql = "delete from terrain where RegionUUID=@RegionUUID";
583 using (SqlConnection conn = new SqlConnection(m_connectionString)) 590 using (SqlConnection conn = new SqlConnection(m_connectionString))
@@ -590,17 +597,23 @@ ELSE
590 597
591 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; 598 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
592 599
600 int terrainDBRevision;
601 Array terrainDBblob;
602 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
603
593 using (SqlConnection conn = new SqlConnection(m_connectionString)) 604 using (SqlConnection conn = new SqlConnection(m_connectionString))
594 using (SqlCommand cmd = new SqlCommand(sql, conn))
595 { 605 {
596 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); 606 using (SqlCommand cmd = new SqlCommand(sql, conn))
597 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); 607 {
598 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); 608 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
599 conn.Open(); 609 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision));
600 cmd.ExecuteNonQuery(); 610 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob));
611 conn.Open();
612 cmd.ExecuteNonQuery();
613 }
601 } 614 }
602 615
603 _Log.Info("[REGION DB]: Stored terrain revision r " + revision); 616 _Log.Info("[REGION DB]: Stored terrain");
604 } 617 }
605 618
606 /// <summary> 619 /// <summary>
@@ -1344,6 +1357,7 @@ VALUES
1344 1357
1345 #region Private Methods 1358 #region Private Methods
1346 1359
1360 /*
1347 /// <summary> 1361 /// <summary>
1348 /// Serializes the terrain data for storage in DB. 1362 /// Serializes the terrain data for storage in DB.
1349 /// </summary> 1363 /// </summary>
@@ -1367,6 +1381,7 @@ VALUES
1367 1381
1368 return str.ToArray(); 1382 return str.ToArray();
1369 } 1383 }
1384 */
1370 1385
1371 /// <summary> 1386 /// <summary>
1372 /// Stores new regionsettings. 1387 /// Stores new regionsettings.