diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLSimulationData.cs | 103 |
1 files changed, 45 insertions, 58 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs index f41f60c..9f5991b 100644 --- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs +++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs | |||
@@ -49,6 +49,7 @@ namespace OpenSim.Data.MSSQL | |||
49 | 49 | ||
50 | // private static FileSystemDataStore Instance = new FileSystemDataStore(); | 50 | // private static FileSystemDataStore Instance = new FileSystemDataStore(); |
51 | private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
52 | private static string LogHeader = "[REGION DB MSSQL]"; | ||
52 | 53 | ||
53 | /// <summary> | 54 | /// <summary> |
54 | /// The database manager | 55 | /// The database manager |
@@ -530,43 +531,49 @@ ELSE | |||
530 | /// <returns></returns> | 531 | /// <returns></returns> |
531 | public double[,] LoadTerrain(UUID regionID) | 532 | public double[,] LoadTerrain(UUID regionID) |
532 | { | 533 | { |
533 | double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; | 534 | TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); |
534 | 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; | ||
535 | 541 | ||
536 | 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"; |
537 | 543 | ||
538 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 544 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
539 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
540 | { | 545 | { |
541 | // MySqlParameter param = new MySqlParameter(); | 546 | 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 | { | 547 | { |
546 | int rev; | 548 | // MySqlParameter param = new MySqlParameter(); |
547 | if (reader.Read()) | 549 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); |
550 | conn.Open(); | ||
551 | using (SqlDataReader reader = cmd.ExecuteReader()) | ||
548 | { | 552 | { |
549 | MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); | 553 | int rev; |
550 | BinaryReader br = new BinaryReader(str); | 554 | if (reader.Read()) |
551 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
552 | { | 555 | { |
553 | for (int y = 0; y < (int)Constants.RegionSize; y++) | 556 | rev = (int)reader["Revision"]; |
554 | { | 557 | byte[] blob = (byte[])reader["Heightfield"]; |
555 | terrain[x, y] = br.ReadDouble(); | 558 | terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); |
556 | } | ||
557 | } | 559 | } |
558 | rev = (int)reader["Revision"]; | 560 | else |
559 | } | 561 | { |
560 | else | 562 | _Log.Info("[REGION DB]: No terrain found for region"); |
561 | { | 563 | return null; |
562 | _Log.Info("[REGION DB]: No terrain found for region"); | 564 | } |
563 | return null; | 565 | _Log.Info("[REGION DB]: Loaded terrain revision r" + rev); |
564 | } | 566 | } |
565 | _Log.Info("[REGION DB]: Loaded terrain revision r" + rev); | ||
566 | } | 567 | } |
567 | } | 568 | } |
568 | 569 | ||
569 | return terrain; | 570 | return terrData; |
571 | } | ||
572 | |||
573 | // Legacy entry point for when terrain was always a 256x256 hieghtmap | ||
574 | public void StoreTerrain(double[,] ter, UUID regionID) | ||
575 | { | ||
576 | StoreTerrain(new HeightmapTerrainData(ter), regionID); | ||
570 | } | 577 | } |
571 | 578 | ||
572 | /// <summary> | 579 | /// <summary> |
@@ -574,10 +581,8 @@ ELSE | |||
574 | /// </summary> | 581 | /// </summary> |
575 | /// <param name="terrain">terrain map data.</param> | 582 | /// <param name="terrain">terrain map data.</param> |
576 | /// <param name="regionID">regionID.</param> | 583 | /// <param name="regionID">regionID.</param> |
577 | public void StoreTerrain(double[,] terrain, UUID regionID) | 584 | public void StoreTerrain(TerrainData terrData, UUID regionID) |
578 | { | 585 | { |
579 | int revision = Util.UnixTimeSinceEpoch(); | ||
580 | |||
581 | //Delete old terrain map | 586 | //Delete old terrain map |
582 | string sql = "delete from terrain where RegionUUID=@RegionUUID"; | 587 | string sql = "delete from terrain where RegionUUID=@RegionUUID"; |
583 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 588 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
@@ -590,17 +595,23 @@ ELSE | |||
590 | 595 | ||
591 | sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; | 596 | sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; |
592 | 597 | ||
598 | int terrainDBRevision; | ||
599 | Array terrainDBblob; | ||
600 | terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); | ||
601 | |||
593 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 602 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
594 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
595 | { | 603 | { |
596 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); | 604 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
597 | cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); | 605 | { |
598 | cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); | 606 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); |
599 | conn.Open(); | 607 | cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision)); |
600 | cmd.ExecuteNonQuery(); | 608 | cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob)); |
609 | conn.Open(); | ||
610 | cmd.ExecuteNonQuery(); | ||
611 | } | ||
601 | } | 612 | } |
602 | 613 | ||
603 | _Log.Info("[REGION DB]: Stored terrain revision r " + revision); | 614 | _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision); |
604 | } | 615 | } |
605 | 616 | ||
606 | /// <summary> | 617 | /// <summary> |
@@ -1345,30 +1356,6 @@ VALUES | |||
1345 | #region Private Methods | 1356 | #region Private Methods |
1346 | 1357 | ||
1347 | /// <summary> | 1358 | /// <summary> |
1348 | /// Serializes the terrain data for storage in DB. | ||
1349 | /// </summary> | ||
1350 | /// <param name="val">terrain data</param> | ||
1351 | /// <returns></returns> | ||
1352 | private static Array serializeTerrain(double[,] val) | ||
1353 | { | ||
1354 | MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double)); | ||
1355 | BinaryWriter bw = new BinaryWriter(str); | ||
1356 | |||
1357 | // TODO: COMPATIBILITY - Add byte-order conversions | ||
1358 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1359 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1360 | { | ||
1361 | double height = val[x, y]; | ||
1362 | if (height == 0.0) | ||
1363 | height = double.Epsilon; | ||
1364 | |||
1365 | bw.Write(height); | ||
1366 | } | ||
1367 | |||
1368 | return str.ToArray(); | ||
1369 | } | ||
1370 | |||
1371 | /// <summary> | ||
1372 | /// Stores new regionsettings. | 1359 | /// Stores new regionsettings. |
1373 | /// </summary> | 1360 | /// </summary> |
1374 | /// <param name="regionSettings">The region settings.</param> | 1361 | /// <param name="regionSettings">The region settings.</param> |