diff options
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteSimulationData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteSimulationData.cs | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs index 4d6a80a..d28c227 100644 --- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs +++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs | |||
@@ -51,6 +51,7 @@ namespace OpenSim.Data.SQLite | |||
51 | public class SQLiteSimulationData : ISimulationDataStore | 51 | public class SQLiteSimulationData : ISimulationDataStore |
52 | { | 52 | { |
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | private static readonly string LogHeader = "[REGION DB SQLLITE]"; | ||
54 | 55 | ||
55 | private const string primSelect = "select * from prims"; | 56 | private const string primSelect = "select * from prims"; |
56 | private const string shapeSelect = "select * from primshapes"; | 57 | private const string shapeSelect = "select * from primshapes"; |
@@ -819,12 +820,18 @@ namespace OpenSim.Data.SQLite | |||
819 | prim.Inventory.RestoreInventoryItems(inventory); | 820 | prim.Inventory.RestoreInventoryItems(inventory); |
820 | } | 821 | } |
821 | 822 | ||
823 | // Legacy entry point for when terrain was always a 256x256 hieghtmap | ||
824 | public void StoreTerrain(double[,] ter, UUID regionID) | ||
825 | { | ||
826 | StoreTerrain(new HeightmapTerrainData(ter), regionID); | ||
827 | } | ||
828 | |||
822 | /// <summary> | 829 | /// <summary> |
823 | /// Store a terrain revision in region storage | 830 | /// Store a terrain revision in region storage |
824 | /// </summary> | 831 | /// </summary> |
825 | /// <param name="ter">terrain heightfield</param> | 832 | /// <param name="ter">terrain heightfield</param> |
826 | /// <param name="regionID">region UUID</param> | 833 | /// <param name="regionID">region UUID</param> |
827 | public void StoreTerrain(double[,] ter, UUID regionID) | 834 | public void StoreTerrain(TerrainData terrData, UUID regionID) |
828 | { | 835 | { |
829 | lock (ds) | 836 | lock (ds) |
830 | { | 837 | { |
@@ -853,11 +860,17 @@ namespace OpenSim.Data.SQLite | |||
853 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + | 860 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + |
854 | " values(:RegionUUID, :Revision, :Heightfield)"; | 861 | " values(:RegionUUID, :Revision, :Heightfield)"; |
855 | 862 | ||
863 | int terrainDBRevision; | ||
864 | Array terrainDBblob; | ||
865 | terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); | ||
866 | |||
867 | m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision); | ||
868 | |||
856 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) | 869 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) |
857 | { | 870 | { |
858 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | 871 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); |
859 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | 872 | cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision)); |
860 | cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); | 873 | cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob)); |
861 | cmd.ExecuteNonQuery(); | 874 | cmd.ExecuteNonQuery(); |
862 | } | 875 | } |
863 | } | 876 | } |
@@ -870,11 +883,20 @@ namespace OpenSim.Data.SQLite | |||
870 | /// <returns>Heightfield data</returns> | 883 | /// <returns>Heightfield data</returns> |
871 | public double[,] LoadTerrain(UUID regionID) | 884 | public double[,] LoadTerrain(UUID regionID) |
872 | { | 885 | { |
886 | double[,] ret = null; | ||
887 | TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); | ||
888 | if (terrData != null) | ||
889 | ret = terrData.GetDoubles(); | ||
890 | return ret; | ||
891 | } | ||
892 | |||
893 | // Returns 'null' if region not found | ||
894 | public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) | ||
895 | { | ||
896 | TerrainData terrData = null; | ||
897 | |||
873 | lock (ds) | 898 | lock (ds) |
874 | { | 899 | { |
875 | double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; | ||
876 | terret.Initialize(); | ||
877 | |||
878 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + | 900 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + |
879 | " where RegionUUID=:RegionUUID order by Revision desc"; | 901 | " where RegionUUID=:RegionUUID order by Revision desc"; |
880 | 902 | ||
@@ -887,21 +909,9 @@ namespace OpenSim.Data.SQLite | |||
887 | int rev = 0; | 909 | int rev = 0; |
888 | if (row.Read()) | 910 | if (row.Read()) |
889 | { | 911 | { |
890 | // TODO: put this into a function | ||
891 | using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"])) | ||
892 | { | ||
893 | using (BinaryReader br = new BinaryReader(str)) | ||
894 | { | ||
895 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
896 | { | ||
897 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
898 | { | ||
899 | terret[x, y] = br.ReadDouble(); | ||
900 | } | ||
901 | } | ||
902 | } | ||
903 | } | ||
904 | rev = Convert.ToInt32(row["Revision"]); | 912 | rev = Convert.ToInt32(row["Revision"]); |
913 | byte[] blob = (byte[])row["Heightfield"]; | ||
914 | terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); | ||
905 | } | 915 | } |
906 | else | 916 | else |
907 | { | 917 | { |
@@ -912,8 +922,8 @@ namespace OpenSim.Data.SQLite | |||
912 | m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); | 922 | m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); |
913 | } | 923 | } |
914 | } | 924 | } |
915 | return terret; | ||
916 | } | 925 | } |
926 | return terrData; | ||
917 | } | 927 | } |
918 | 928 | ||
919 | public void RemoveLandObject(UUID globalID) | 929 | public void RemoveLandObject(UUID globalID) |
@@ -2016,6 +2026,7 @@ namespace OpenSim.Data.SQLite | |||
2016 | return entry; | 2026 | return entry; |
2017 | } | 2027 | } |
2018 | 2028 | ||
2029 | /* | ||
2019 | /// <summary> | 2030 | /// <summary> |
2020 | /// | 2031 | /// |
2021 | /// </summary> | 2032 | /// </summary> |
@@ -2033,6 +2044,7 @@ namespace OpenSim.Data.SQLite | |||
2033 | 2044 | ||
2034 | return str.ToArray(); | 2045 | return str.ToArray(); |
2035 | } | 2046 | } |
2047 | */ | ||
2036 | 2048 | ||
2037 | // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) | 2049 | // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) |
2038 | // { | 2050 | // { |