diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLSimulationData.cs | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index b03a904..4bd8617 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs | |||
@@ -48,6 +48,7 @@ namespace OpenSim.Data.MySQL | |||
48 | public class MySQLSimulationData : ISimulationDataStore | 48 | public class MySQLSimulationData : ISimulationDataStore |
49 | { | 49 | { |
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
51 | private static string LogHeader = "[REGION DB MYSQL]"; | ||
51 | 52 | ||
52 | private string m_connectionString; | 53 | private string m_connectionString; |
53 | private object m_dbLock = new object(); | 54 | private object m_dbLock = new object(); |
@@ -91,7 +92,7 @@ namespace OpenSim.Data.MySQL | |||
91 | } | 92 | } |
92 | catch (Exception e) | 93 | catch (Exception e) |
93 | { | 94 | { |
94 | m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message); | 95 | m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e); |
95 | throw; | 96 | throw; |
96 | } | 97 | } |
97 | 98 | ||
@@ -572,10 +573,14 @@ namespace OpenSim.Data.MySQL | |||
572 | } | 573 | } |
573 | } | 574 | } |
574 | 575 | ||
576 | // Legacy entry point for when terrain was always a 256x256 hieghtmap | ||
575 | public void StoreTerrain(double[,] ter, UUID regionID) | 577 | public void StoreTerrain(double[,] ter, UUID regionID) |
576 | { | 578 | { |
577 | m_log.Info("[REGION DB]: Storing terrain"); | 579 | StoreTerrain(new HeightmapTerrainData(ter), regionID); |
580 | } | ||
578 | 581 | ||
582 | public void StoreTerrain(TerrainData terrData, UUID regionID) | ||
583 | { | ||
579 | lock (m_dbLock) | 584 | lock (m_dbLock) |
580 | { | 585 | { |
581 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 586 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
@@ -589,11 +594,18 @@ namespace OpenSim.Data.MySQL | |||
589 | 594 | ||
590 | ExecuteNonQuery(cmd); | 595 | ExecuteNonQuery(cmd); |
591 | 596 | ||
592 | cmd.CommandText = "insert into terrain (RegionUUID, " + | 597 | int terrainDBRevision; |
593 | "Revision, Heightfield) values (?RegionUUID, " + | 598 | Array terrainDBblob; |
594 | "1, ?Heightfield)"; | 599 | terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); |
595 | 600 | ||
596 | cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); | 601 | m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}", |
602 | LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision); | ||
603 | |||
604 | cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)" | ||
605 | + "values (?RegionUUID, ?Revision, ?Heightfield)"; | ||
606 | |||
607 | cmd.Parameters.AddWithValue("Revision", terrainDBRevision); | ||
608 | cmd.Parameters.AddWithValue("Heightfield", terrainDBblob); | ||
597 | 609 | ||
598 | ExecuteNonQuery(cmd); | 610 | ExecuteNonQuery(cmd); |
599 | } | 611 | } |
@@ -1525,30 +1537,6 @@ namespace OpenSim.Data.MySQL | |||
1525 | } | 1537 | } |
1526 | 1538 | ||
1527 | /// <summary> | 1539 | /// <summary> |
1528 | /// | ||
1529 | /// </summary> | ||
1530 | /// <param name="val"></param> | ||
1531 | /// <returns></returns> | ||
1532 | private static Array SerializeTerrain(double[,] val) | ||
1533 | { | ||
1534 | MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double)); | ||
1535 | BinaryWriter bw = new BinaryWriter(str); | ||
1536 | |||
1537 | // TODO: COMPATIBILITY - Add byte-order conversions | ||
1538 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1539 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1540 | { | ||
1541 | double height = val[x, y]; | ||
1542 | if (height == 0.0) | ||
1543 | height = double.Epsilon; | ||
1544 | |||
1545 | bw.Write(height); | ||
1546 | } | ||
1547 | |||
1548 | return str.ToArray(); | ||
1549 | } | ||
1550 | |||
1551 | /// <summary> | ||
1552 | /// Fill the prim command with prim values | 1540 | /// Fill the prim command with prim values |
1553 | /// </summary> | 1541 | /// </summary> |
1554 | /// <param name="row"></param> | 1542 | /// <param name="row"></param> |