aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/PGSQL/PGSQLSimulationData.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/PGSQL/PGSQLSimulationData.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 'OpenSim/Data/PGSQL/PGSQLSimulationData.cs')
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs72
1 files changed, 43 insertions, 29 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index 3243635..cd02e05 100644
--- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Data.PGSQL
46 public class PGSQLSimulationData : ISimulationDataStore 46 public class PGSQLSimulationData : ISimulationDataStore
47 { 47 {
48 private const string _migrationStore = "RegionStore"; 48 private const string _migrationStore = "RegionStore";
49 private const string LogHeader = "[REGION DB PGSQL]";
49 50
50 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 51 // private static FileSystemDataStore Instance = new FileSystemDataStore();
51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 52 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -523,8 +524,17 @@ namespace OpenSim.Data.PGSQL
523 /// <returns></returns> 524 /// <returns></returns>
524 public double[,] LoadTerrain(UUID regionID) 525 public double[,] LoadTerrain(UUID regionID)
525 { 526 {
526 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 527 double[,] ret = null;
527 terrain.Initialize(); 528 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
529 if (terrData != null)
530 ret = terrData.GetDoubles();
531 return ret;
532 }
533
534 // Returns 'null' if region not found
535 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
536 {
537 TerrainData terrData = null;
528 538
529 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain 539 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain
530 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; "; 540 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; ";
@@ -540,16 +550,9 @@ namespace OpenSim.Data.PGSQL
540 int rev; 550 int rev;
541 if (reader.Read()) 551 if (reader.Read())
542 { 552 {
543 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 553 rev = Convert.ToInt32(reader["Revision"]);
544 BinaryReader br = new BinaryReader(str); 554 byte[] blob = (byte[])reader["Heightfield"];
545 for (int x = 0; x < (int)Constants.RegionSize; x++) 555 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
546 {
547 for (int y = 0; y < (int)Constants.RegionSize; y++)
548 {
549 terrain[x, y] = br.ReadDouble();
550 }
551 }
552 rev = (int)reader["Revision"];
553 } 556 }
554 else 557 else
555 { 558 {
@@ -560,7 +563,13 @@ namespace OpenSim.Data.PGSQL
560 } 563 }
561 } 564 }
562 565
563 return terrain; 566 return terrData;
567 }
568
569 // Legacy entry point for when terrain was always a 256x256 heightmap
570 public void StoreTerrain(double[,] terrain, UUID regionID)
571 {
572 StoreTerrain(new HeightmapTerrainData(terrain), regionID);
564 } 573 }
565 574
566 /// <summary> 575 /// <summary>
@@ -568,35 +577,38 @@ namespace OpenSim.Data.PGSQL
568 /// </summary> 577 /// </summary>
569 /// <param name="terrain">terrain map data.</param> 578 /// <param name="terrain">terrain map data.</param>
570 /// <param name="regionID">regionID.</param> 579 /// <param name="regionID">regionID.</param>
571 public void StoreTerrain(double[,] terrain, UUID regionID) 580 public void StoreTerrain(TerrainData terrData, UUID regionID)
572 { 581 {
573 int revision = Util.UnixTimeSinceEpoch();
574
575 //Delete old terrain map 582 //Delete old terrain map
576 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID"; 583 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID";
577 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 584 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
578 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
579 { 585 {
580 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 586 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
581 conn.Open(); 587 {
582 cmd.ExecuteNonQuery(); 588 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
589 conn.Open();
590 cmd.ExecuteNonQuery();
591 }
583 } 592 }
584 593 int terrainDBRevision;
585 _Log.Info("[REGION DB]: Deleted terrain revision r " + revision); 594 Array terrainDBblob;
595 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
586 596
587 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)"; 597 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)";
588 598
589 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 599 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
590 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
591 { 600 {
592 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 601 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
593 cmd.Parameters.Add(_Database.CreateParameter("Revision", revision)); 602 {
594 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", serializeTerrain(terrain))); 603 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
595 conn.Open(); 604 cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision));
596 cmd.ExecuteNonQuery(); 605 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob));
606 conn.Open();
607 cmd.ExecuteNonQuery();
608 }
597 } 609 }
598 610
599 _Log.Info("[REGION DB]: Stored terrain revision r " + revision); 611 _Log.Info("[REGION DB]: Stored terrain revision r " + terrainDBRevision);
600 } 612 }
601 613
602 /// <summary> 614 /// <summary>
@@ -1349,6 +1361,7 @@ namespace OpenSim.Data.PGSQL
1349 1361
1350 #region Private Methods 1362 #region Private Methods
1351 1363
1364 /*
1352 /// <summary> 1365 /// <summary>
1353 /// Serializes the terrain data for storage in DB. 1366 /// Serializes the terrain data for storage in DB.
1354 /// </summary> 1367 /// </summary>
@@ -1372,6 +1385,7 @@ namespace OpenSim.Data.PGSQL
1372 1385
1373 return str.ToArray(); 1386 return str.ToArray();
1374 } 1387 }
1388 */
1375 1389
1376 /// <summary> 1390 /// <summary>
1377 /// Stores new regionsettings. 1391 /// Stores new regionsettings.