diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLSimulationData.cs | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index b03a904..42f2ebb 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 | } |
@@ -601,9 +613,16 @@ namespace OpenSim.Data.MySQL | |||
601 | } | 613 | } |
602 | } | 614 | } |
603 | 615 | ||
616 | // Legacy region loading | ||
604 | public double[,] LoadTerrain(UUID regionID) | 617 | public double[,] LoadTerrain(UUID regionID) |
605 | { | 618 | { |
606 | double[,] terrain = null; | 619 | TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); |
620 | return terrData.GetDoubles(); | ||
621 | } | ||
622 | |||
623 | public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) | ||
624 | { | ||
625 | TerrainData terrData = null; | ||
607 | 626 | ||
608 | lock (m_dbLock) | 627 | lock (m_dbLock) |
609 | { | 628 | { |
@@ -623,32 +642,15 @@ namespace OpenSim.Data.MySQL | |||
623 | while (reader.Read()) | 642 | while (reader.Read()) |
624 | { | 643 | { |
625 | int rev = Convert.ToInt32(reader["Revision"]); | 644 | int rev = Convert.ToInt32(reader["Revision"]); |
626 | 645 | byte[] blob = (byte[])reader["Heightfield"]; | |
627 | terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; | 646 | terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); |
628 | terrain.Initialize(); | ||
629 | |||
630 | using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"])) | ||
631 | { | ||
632 | using (BinaryReader br = new BinaryReader(mstr)) | ||
633 | { | ||
634 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
635 | { | ||
636 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
637 | { | ||
638 | terrain[x, y] = br.ReadDouble(); | ||
639 | } | ||
640 | } | ||
641 | } | ||
642 | |||
643 | m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev); | ||
644 | } | ||
645 | } | 647 | } |
646 | } | 648 | } |
647 | } | 649 | } |
648 | } | 650 | } |
649 | } | 651 | } |
650 | 652 | ||
651 | return terrain; | 653 | return terrData; |
652 | } | 654 | } |
653 | 655 | ||
654 | public void RemoveLandObject(UUID globalID) | 656 | public void RemoveLandObject(UUID globalID) |
@@ -1525,30 +1527,6 @@ namespace OpenSim.Data.MySQL | |||
1525 | } | 1527 | } |
1526 | 1528 | ||
1527 | /// <summary> | 1529 | /// <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 | 1530 | /// Fill the prim command with prim values |
1553 | /// </summary> | 1531 | /// </summary> |
1554 | /// <param name="row"></param> | 1532 | /// <param name="row"></param> |