diff options
Diffstat (limited to 'OpenSim/Data/MSSQL')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLSimulationData.cs | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs index 8adddc9..dbfd16c 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 |
@@ -569,15 +570,19 @@ ELSE | |||
569 | return terrain; | 570 | return terrain; |
570 | } | 571 | } |
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); | ||
577 | } | ||
578 | |||
572 | /// <summary> | 579 | /// <summary> |
573 | /// Stores the terrain map to DB. | 580 | /// Stores the terrain map to DB. |
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 = (int)DBTerrainRevision.Legacy256; | ||
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,21 @@ 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)) | 603 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
595 | { | 604 | { |
596 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); | 605 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); |
597 | cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); | 606 | cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision)); |
598 | cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); | 607 | cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob)); |
599 | conn.Open(); | 608 | conn.Open(); |
600 | cmd.ExecuteNonQuery(); | 609 | cmd.ExecuteNonQuery(); |
601 | } | 610 | } |
602 | 611 | ||
603 | _Log.Info("[REGION DB]: Stored terrain revision r " + revision); | 612 | _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision); |
604 | } | 613 | } |
605 | 614 | ||
606 | /// <summary> | 615 | /// <summary> |
@@ -1345,30 +1354,6 @@ VALUES | |||
1345 | #region Private Methods | 1354 | #region Private Methods |
1346 | 1355 | ||
1347 | /// <summary> | 1356 | /// <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. | 1357 | /// Stores new regionsettings. |
1373 | /// </summary> | 1358 | /// </summary> |
1374 | /// <param name="regionSettings">The region settings.</param> | 1359 | /// <param name="regionSettings">The region settings.</param> |