aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs4
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs20
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs45
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs50
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs45
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs52
-rw-r--r--OpenSim/Data/Tests/RegionTests.cs8
-rw-r--r--OpenSim/Framework/Constants.cs9
-rw-r--r--OpenSim/Framework/RegionInfo.cs165
-rw-r--r--OpenSim/Framework/TerrainData.cs260
-rw-r--r--OpenSim/Region/Application/OpenSim.cs4
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs2
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs75
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs6
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs48
-rw-r--r--OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs45
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs22
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs1
-rw-r--r--OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs14
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs28
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/SimStatsReporter.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainChannel.cs259
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainCompressor.cs949
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs4
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerIndividualEventForwarder.cs8
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs28
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs13
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs4
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs4
39 files changed, 1764 insertions, 460 deletions
diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
index 1d63d26..74a7a50 100644
--- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
+++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
@@ -184,11 +184,11 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
184 return false; 184 return false;
185 } 185 }
186 else if ( 186 else if (
187 regions[i].RegionLocX == regions[j].RegionLocX && regions[i].RegionLocY == regions[j].RegionLocY) 187 regions[i].LegacyRegionLocX == regions[j].LegacyRegionLocX && regions[i].LegacyRegionLocY == regions[j].LegacyRegionLocY)
188 { 188 {
189 m_log.ErrorFormat( 189 m_log.ErrorFormat(
190 "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same grid location ({2}, {3})", 190 "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same grid location ({2}, {3})",
191 regions[i].RegionName, regions[j].RegionName, regions[i].RegionLocX, regions[i].RegionLocY); 191 regions[i].RegionName, regions[j].RegionName, regions[i].LegacyRegionLocX, regions[i].LegacyRegionLocY);
192 return false; 192 return false;
193 } 193 }
194 else if (regions[i].InternalEndPoint.Port == regions[j].InternalEndPoint.Port) 194 else if (regions[i].InternalEndPoint.Port == regions[j].InternalEndPoint.Port)
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index c78cf3b..7afdd34 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -542,7 +542,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
542 throw new Exception( 542 throw new Exception(
543 String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>", 543 String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
544 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, 544 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
545 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); 545 scene.RegionInfo.LegacyRegionLocX, scene.RegionInfo.LegacyRegionLocY));
546 } 546 }
547 else 547 else
548 { 548 {
@@ -556,8 +556,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController
556 region.RegionID = regionID; 556 region.RegionID = regionID;
557 region.originRegionID = regionID; 557 region.originRegionID = regionID;
558 region.RegionName = (string) requestData["region_name"]; 558 region.RegionName = (string) requestData["region_name"];
559 region.RegionLocX = Convert.ToUInt32(requestData["region_x"]); 559 region.LegacyRegionLocX = Convert.ToUInt32(requestData["region_x"]);
560 region.RegionLocY = Convert.ToUInt32(requestData["region_y"]); 560 region.LegacyRegionLocY = Convert.ToUInt32(requestData["region_y"]);
561 561
562 // check for collisions: region name, region UUID, 562 // check for collisions: region name, region UUID,
563 // region location 563 // region location
@@ -565,14 +565,14 @@ namespace OpenSim.ApplicationPlugins.RemoteController
565 throw new Exception( 565 throw new Exception(
566 String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>", 566 String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
567 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, 567 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
568 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); 568 scene.RegionInfo.LegacyRegionLocX, scene.RegionInfo.LegacyRegionLocY));
569 569
570 if (m_application.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene)) 570 if (m_application.SceneManager.TryGetScene(region.LegacyRegionLocX, region.LegacyRegionLocY, out scene))
571 throw new Exception( 571 throw new Exception(
572 String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>", 572 String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
573 region.RegionLocX, region.RegionLocY, 573 region.LegacyRegionLocX, region.LegacyRegionLocY,
574 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, 574 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
575 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); 575 scene.RegionInfo.LegacyRegionLocX, scene.RegionInfo.LegacyRegionLocY));
576 576
577 region.InternalEndPoint = 577 region.InternalEndPoint =
578 new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0); 578 new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
@@ -586,7 +586,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
586 region.InternalEndPoint.Address, 586 region.InternalEndPoint.Address,
587 region.InternalEndPoint.Port, 587 region.InternalEndPoint.Port,
588 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, 588 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
589 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); 589 scene.RegionInfo.LegacyRegionLocX, scene.RegionInfo.LegacyRegionLocY));
590 590
591 region.ExternalHostName = (string) requestData["external_address"]; 591 region.ExternalHostName = (string) requestData["external_address"];
592 592
@@ -625,8 +625,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController
625 String.Format( 625 String.Format(
626 m_config.GetString("region_file_template", 626 m_config.GetString("region_file_template",
627 "{0}x{1}-{2}.ini"), 627 "{0}x{1}-{2}.ini"),
628 region.RegionLocX.ToString(), 628 region.LegacyRegionLocX.ToString(),
629 region.RegionLocY.ToString(), 629 region.LegacyRegionLocY.ToString(),
630 regionID.ToString(), 630 regionID.ToString(),
631 region.InternalEndPoint.Port.ToString(), 631 region.InternalEndPoint.Port.ToString(),
632 region.RegionName.Replace(" ", "_").Replace(":", "_"). 632 region.RegionName.Replace(" ", "_").Replace(":", "_").
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index f41f60c..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 = 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,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>
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>
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index 69b0beb..433ffe9 100644
--- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Data.PGSQL
46 public class PGSQLSimulationData : ISimulationDataStore 46 public class PGSQLSimulationData : ISimulationDataStore
47 { 47 {
48 private const string _migrationStore = "RegionStore"; 48 private const string _migrationStore = "RegionStore";
49 private const string LogHeader = "[REGION DB PGSQL]";
49 50
50 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 51 // private static FileSystemDataStore Instance = new FileSystemDataStore();
51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 52 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -563,40 +564,54 @@ namespace OpenSim.Data.PGSQL
563 return terrain; 564 return terrain;
564 } 565 }
565 566
567 // Legacy entry point for when terrain was always a 256x256 heightmap
568 public void StoreTerrain(double[,] terrain, UUID regionID)
569 {
570 StoreTerrain(new HeightmapTerrainData(terrain), regionID);
571 }
572
566 /// <summary> 573 /// <summary>
567 /// Stores the terrain map to DB. 574 /// Stores the terrain map to DB.
568 /// </summary> 575 /// </summary>
569 /// <param name="terrain">terrain map data.</param> 576 /// <param name="terrain">terrain map data.</param>
570 /// <param name="regionID">regionID.</param> 577 /// <param name="regionID">regionID.</param>
571 public void StoreTerrain(double[,] terrain, UUID regionID) 578 public void StoreTerrain(TerrainData terrData, UUID regionID)
572 { 579 {
573 int revision = Util.UnixTimeSinceEpoch();
574
575 //Delete old terrain map 580 //Delete old terrain map
576 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID"; 581 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID";
577 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 582 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
578 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
579 { 583 {
580 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 584 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
581 conn.Open(); 585 {
582 cmd.ExecuteNonQuery(); 586 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
587 conn.Open();
588 cmd.ExecuteNonQuery();
589
590 _Log.InfoFormat("{0} Deleted terrain revision id = {1}", LogHeader, regionID);
591 }
583 } 592 }
584 593
585 _Log.Info("[REGION DB]: Deleted terrain revision r " + revision); 594 int terrainDBRevision;
595 Array terrainDBblob;
596 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
586 597
587 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)"; 598 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)";
588 599
589 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 600 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
590 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
591 { 601 {
592 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 602 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
593 cmd.Parameters.Add(_Database.CreateParameter("Revision", revision)); 603 {
594 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", serializeTerrain(terrain))); 604 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
595 conn.Open(); 605 cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision));
596 cmd.ExecuteNonQuery(); 606 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob));
607 conn.Open();
608 cmd.ExecuteNonQuery();
609
610 _Log.InfoFormat("{0} Stored terrain id = {1}, terrainSize = <{2},{3}>",
611 LogHeader, regionID, terrData.SizeX, terrData.SizeY);
612 }
597 } 613 }
598 614
599 _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
600 } 615 }
601 616
602 /// <summary> 617 /// <summary>
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index d938b6b..cce59c1 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,45 +820,44 @@ 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 {
831 int revision = Util.UnixTimeSinceEpoch();
832
833 // This is added to get rid of the infinitely growing
834 // terrain databases which negatively impact on SQLite
835 // over time. Before reenabling this feature there
836 // needs to be a limitter put on the number of
837 // revisions in the database, as this old
838 // implementation is a DOS attack waiting to happen.
839
840 using ( 838 using (
841 SqliteCommand cmd = 839 SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
842 new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision",
843 m_conn))
844 { 840 {
845 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); 841 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
846 cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
847 cmd.ExecuteNonQuery(); 842 cmd.ExecuteNonQuery();
848 } 843 }
849 844
850 // the following is an work around for .NET. The perf 845 // the following is an work around for .NET. The perf
851 // issues associated with it aren't as bad as you think. 846 // issues associated with it aren't as bad as you think.
852 m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
853 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + 847 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
854 " values(:RegionUUID, :Revision, :Heightfield)"; 848 " values(:RegionUUID, :Revision, :Heightfield)";
855 849
850 int terrainDBRevision;
851 Array terrainDBblob;
852 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
853
854 m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision);
855
856 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) 856 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
857 { 857 {
858 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); 858 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
859 cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); 859 cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
860 cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); 860 cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
861 cmd.ExecuteNonQuery(); 861 cmd.ExecuteNonQuery();
862 } 862 }
863 } 863 }
@@ -2016,24 +2016,6 @@ namespace OpenSim.Data.SQLite
2016 return entry; 2016 return entry;
2017 } 2017 }
2018 2018
2019 /// <summary>
2020 ///
2021 /// </summary>
2022 /// <param name="val"></param>
2023 /// <returns></returns>
2024 private static Array serializeTerrain(double[,] val)
2025 {
2026 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
2027 BinaryWriter bw = new BinaryWriter(str);
2028
2029 // TODO: COMPATIBILITY - Add byte-order conversions
2030 for (int x = 0; x < (int)Constants.RegionSize; x++)
2031 for (int y = 0; y < (int)Constants.RegionSize; y++)
2032 bw.Write(val[x, y]);
2033
2034 return str.ToArray();
2035 }
2036
2037 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) 2019 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
2038 // { 2020 // {
2039 // row["RegionUUID"] = regionUUID; 2021 // row["RegionUUID"] = regionUUID;
diff --git a/OpenSim/Data/Tests/RegionTests.cs b/OpenSim/Data/Tests/RegionTests.cs
index dbed8f6..b4989d1 100644
--- a/OpenSim/Data/Tests/RegionTests.cs
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -300,8 +300,8 @@ namespace OpenSim.Data.Tests
300 300
301 RegionInfo regionInfo = new RegionInfo(); 301 RegionInfo regionInfo = new RegionInfo();
302 regionInfo.RegionID = region3; 302 regionInfo.RegionID = region3;
303 regionInfo.RegionLocX = 0; 303 regionInfo.LegacyRegionLocX = 0;
304 regionInfo.RegionLocY = 0; 304 regionInfo.LegacyRegionLocY = 0;
305 305
306 SceneObjectPart sop = new SceneObjectPart(); 306 SceneObjectPart sop = new SceneObjectPart();
307 SceneObjectGroup sog = new SceneObjectGroup(sop); 307 SceneObjectGroup sog = new SceneObjectGroup(sop);
@@ -1066,8 +1066,8 @@ namespace OpenSim.Data.Tests
1066 { 1066 {
1067 RegionInfo regionInfo = new RegionInfo(); 1067 RegionInfo regionInfo = new RegionInfo();
1068 regionInfo.RegionID = regionId; 1068 regionInfo.RegionID = regionId;
1069 regionInfo.RegionLocX = 0; 1069 regionInfo.LegacyRegionLocX = 0;
1070 regionInfo.RegionLocY = 0; 1070 regionInfo.LegacyRegionLocY = 0;
1071 1071
1072 SceneObjectPart sop = new SceneObjectPart(); 1072 SceneObjectPart sop = new SceneObjectPart();
1073 sop.Name = name; 1073 sop.Name = name;
diff --git a/OpenSim/Framework/Constants.cs b/OpenSim/Framework/Constants.cs
index a2eb5ee..d18b32e 100644
--- a/OpenSim/Framework/Constants.cs
+++ b/OpenSim/Framework/Constants.cs
@@ -30,9 +30,16 @@ namespace OpenSim.Framework
30{ 30{
31 public class Constants 31 public class Constants
32 { 32 {
33 // 'RegionSize' captures the legacy region size.
34 // DO NOT USE THIS FOR ANY NEW CODE. Use Scene.RegionSize[XYZ] as a region might not
35 // be the legacy region size.
33 public const uint RegionSize = 256; 36 public const uint RegionSize = 256;
34 public const uint RegionHeight = 4096; 37 public const uint RegionHeight = 4096;
35 public const byte TerrainPatchSize = 16; 38
39 // Since terrain is stored in 16x16 heights, regions must be a multiple of this number and that is the minimum
40 public const int MinRegionSize = 16;
41 public const int TerrainPatchSize = 16;
42
36 public const string DefaultTexture = "89556747-24cb-43ed-920b-47caed15465f"; 43 public const string DefaultTexture = "89556747-24cb-43ed-920b-47caed15465f";
37 44
38 public enum EstateAccessCodex : uint 45 public enum EstateAccessCodex : uint
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs
index 24b9c89..882fe33 100644
--- a/OpenSim/Framework/RegionInfo.cs
+++ b/OpenSim/Framework/RegionInfo.cs
@@ -137,16 +137,20 @@ namespace OpenSim.Framework
137 public bool m_allow_alternate_ports; 137 public bool m_allow_alternate_ports;
138 protected string m_externalHostName; 138 protected string m_externalHostName;
139 protected IPEndPoint m_internalEndPoint; 139 protected IPEndPoint m_internalEndPoint;
140 protected uint? m_regionLocX;
141 protected uint? m_regionLocY;
142 protected uint m_remotingPort; 140 protected uint m_remotingPort;
143 public UUID RegionID = UUID.Zero; 141 public UUID RegionID = UUID.Zero;
144 public string RemotingAddress; 142 public string RemotingAddress;
145 public UUID ScopeID = UUID.Zero; 143 public UUID ScopeID = UUID.Zero;
146 private UUID m_maptileStaticUUID = UUID.Zero; 144 private UUID m_maptileStaticUUID = UUID.Zero;
147 145
148 private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>(); 146 public uint RegionWorldLocX = 0;
147 public uint RegionWorldLocY = 0;
148 public uint RegionWorldLocZ = 0;
149 public uint RegionSizeX = Constants.RegionSize;
150 public uint RegionSizeY = Constants.RegionSize;
151 public uint RegionSizeZ = Constants.RegionHeight;
149 152
153 private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>();
150 154
151 // Apparently, we're applying the same estatesettings regardless of whether it's local or remote. 155 // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
152 156
@@ -229,11 +233,8 @@ namespace OpenSim.Framework
229 m_serverURI = string.Empty; 233 m_serverURI = string.Empty;
230 } 234 }
231 235
232 public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) 236 public RegionInfo(uint legacyRegionLocX, uint legacyRegionLocY, IPEndPoint internalEndPoint, string externalUri)
233 { 237 {
234 m_regionLocX = regionLocX;
235 m_regionLocY = regionLocY;
236
237 m_internalEndPoint = internalEndPoint; 238 m_internalEndPoint = internalEndPoint;
238 m_externalHostName = externalUri; 239 m_externalHostName = externalUri;
239 m_serverURI = string.Empty; 240 m_serverURI = string.Empty;
@@ -447,25 +448,66 @@ namespace OpenSim.Framework
447 448
448 /// <summary> 449 /// <summary>
449 /// The x co-ordinate of this region in map tiles (e.g. 1000). 450 /// The x co-ordinate of this region in map tiles (e.g. 1000).
451 /// Coordinate is scaled as world coordinates divided by the legacy region size
452 /// and is thus is the number of legacy regions.
453 /// </summary>
454 public uint LegacyRegionLocX
455 {
456 get { return RegionWorldLocX / Constants.RegionSize; }
457 set { RegionWorldLocX = value * Constants.RegionSize; }
458 }
459
460 /// <summary>
461 /// The y co-ordinate of this region in map tiles (e.g. 1000).
462 /// Coordinate is scaled as world coordinates divided by the legacy region size
463 /// and is thus is the number of legacy regions.
464 /// </summary>
465 public uint LegacyRegionLocY
466 {
467 get { return RegionWorldLocY / Constants.RegionSize; }
468 set { RegionWorldLocY = value * Constants.RegionSize; }
469 }
470
471 /// <summary>
472 /// The x co-ordinate of this region in map tiles (e.g. 1000).
473 /// Coordinate is scaled as world coordinates divided by the legacy region size
474 /// and is thus is the number of legacy regions.
475 /// DO NOT USE FOR NEW CODE! This entrypoint exists for downward compatability with external modules.
450 /// </summary> 476 /// </summary>
451 public uint RegionLocX 477 public uint RegionLocX
452 { 478 {
453 get { return m_regionLocX.Value; } 479 get { return LegacyRegionLocX; }
454 set { m_regionLocX = value; } 480 set { LegacyRegionLocX = value; }
455 } 481 }
456 482
457 /// <summary> 483 /// <summary>
458 /// The y co-ordinate of this region in map tiles (e.g. 1000). 484 /// The y co-ordinate of this region in map tiles (e.g. 1000).
485 /// Coordinate is scaled as world coordinates divided by the legacy region size
486 /// and is thus is the number of legacy regions.
487 /// DO NOT USE FOR NEW CODE! This entrypoint exists for downward compatability with external modules.
459 /// </summary> 488 /// </summary>
460 public uint RegionLocY 489 public uint RegionLocY
461 { 490 {
462 get { return m_regionLocY.Value; } 491 get { return LegacyRegionLocY; }
463 set { m_regionLocY = value; } 492 set { LegacyRegionLocY = value; }
493 }
494
495 public void SetDefaultRegionSize()
496 {
497 RegionWorldLocX = 0;
498 RegionWorldLocY = 0;
499 RegionWorldLocZ = 0;
500 RegionSizeX = Constants.RegionSize;
501 RegionSizeY = Constants.RegionSize;
502 RegionSizeZ = Constants.RegionHeight;
464 } 503 }
465 504
505 // A unique region handle is created from the region's world coordinates.
506 // This cannot be changed because some code expects to receive the region handle and then
507 // compute the region coordinates from it.
466 public ulong RegionHandle 508 public ulong RegionHandle
467 { 509 {
468 get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); } 510 get { return Util.UIntsToLong(RegionWorldLocX, RegionWorldLocY); }
469 } 511 }
470 512
471 public void SetEndPoint(string ipaddr, int port) 513 public void SetEndPoint(string ipaddr, int port)
@@ -572,8 +614,23 @@ namespace OpenSim.Framework
572 614
573 string[] locationElements = location.Split(new char[] {','}); 615 string[] locationElements = location.Split(new char[] {','});
574 616
575 m_regionLocX = Convert.ToUInt32(locationElements[0]); 617 LegacyRegionLocX = Convert.ToUInt32(locationElements[0]);
576 m_regionLocY = Convert.ToUInt32(locationElements[1]); 618 LegacyRegionLocY = Convert.ToUInt32(locationElements[1]);
619
620 // Region size
621 // Default to legacy region size if not specified.
622 allKeys.Remove("SizeX");
623 string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString());
624 config.Set("SizeX", configSizeX);
625 RegionSizeX = Convert.ToUInt32(configSizeX);
626 allKeys.Remove("SizeY");
627 string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString());
628 config.Set("SizeY", configSizeX);
629 RegionSizeY = Convert.ToUInt32(configSizeY);
630 allKeys.Remove("SizeZ");
631 string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString());
632 config.Set("SizeZ", configSizeX);
633 RegionSizeZ = Convert.ToUInt32(configSizeZ);
577 634
578 // InternalAddress 635 // InternalAddress
579 // 636 //
@@ -704,9 +761,16 @@ namespace OpenSim.Framework
704 761
705 config.Set("RegionUUID", RegionID.ToString()); 762 config.Set("RegionUUID", RegionID.ToString());
706 763
707 string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY); 764 string location = String.Format("{0},{1}", LegacyRegionLocX, LegacyRegionLocY);
708 config.Set("Location", location); 765 config.Set("Location", location);
709 766
767 if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
768 {
769 config.Set("SizeX", RegionSizeX);
770 config.Set("SizeY", RegionSizeY);
771 config.Set("SizeZ", RegionSizeZ);
772 }
773
710 config.Set("InternalAddress", m_internalEndPoint.Address.ToString()); 774 config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
711 config.Set("InternalPort", m_internalEndPoint.Port); 775 config.Set("InternalPort", m_internalEndPoint.Port);
712 776
@@ -789,10 +853,18 @@ namespace OpenSim.Framework
789 RegionID.ToString(), true); 853 RegionID.ToString(), true);
790 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, 854 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
791 "Region Name", RegionName, true); 855 "Region Name", RegionName, true);
856
792 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, 857 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
793 "Grid Location (X Axis)", m_regionLocX.ToString(), true); 858 "Grid Location (X Axis)", LegacyRegionLocX.ToString(), true);
794 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, 859 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
795 "Grid Location (Y Axis)", m_regionLocY.ToString(), true); 860 "Grid Location (Y Axis)", LegacyRegionLocY.ToString(), true);
861 configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
862 "Size of region in X dimension", RegionSizeX.ToString(), true);
863 configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
864 "Size of region in Y dimension", RegionSizeY.ToString(), true);
865 configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
866 "Size of region in Z dimension", RegionSizeZ.ToString(), true);
867
796 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); 868 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
797 configMember.addConfigurationOption("internal_ip_address", 869 configMember.addConfigurationOption("internal_ip_address",
798 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, 870 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
@@ -855,10 +927,18 @@ namespace OpenSim.Framework
855 UUID.Random().ToString(), true); 927 UUID.Random().ToString(), true);
856 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, 928 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
857 "Region Name", "OpenSim Test", false); 929 "Region Name", "OpenSim Test", false);
930
858 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, 931 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
859 "Grid Location (X Axis)", "1000", false); 932 "Grid Location (X Axis)", "1000", false);
860 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, 933 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
861 "Grid Location (Y Axis)", "1000", false); 934 "Grid Location (Y Axis)", "1000", false);
935 configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
936 "Size of region in X dimension", Constants.RegionSize.ToString(), false);
937 configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
938 "Size of region in Y dimension", Constants.RegionSize.ToString(), false);
939 configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
940 "Size of region in Z dimension", Constants.RegionHeight.ToString(), false);
941
862 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); 942 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
863 configMember.addConfigurationOption("internal_ip_address", 943 configMember.addConfigurationOption("internal_ip_address",
864 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, 944 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
@@ -916,10 +996,19 @@ namespace OpenSim.Framework
916 RegionName = (string) configuration_result; 996 RegionName = (string) configuration_result;
917 break; 997 break;
918 case "sim_location_x": 998 case "sim_location_x":
919 m_regionLocX = (uint) configuration_result; 999 LegacyRegionLocX = (uint) configuration_result;
920 break; 1000 break;
921 case "sim_location_y": 1001 case "sim_location_y":
922 m_regionLocY = (uint) configuration_result; 1002 LegacyRegionLocY = (uint) configuration_result;
1003 break;
1004 case "sim_size_x":
1005 RegionSizeX = (uint) configuration_result;
1006 break;
1007 case "sim_size_y":
1008 RegionSizeY = (uint) configuration_result;
1009 break;
1010 case "sim_size_z":
1011 RegionSizeZ = (uint) configuration_result;
923 break; 1012 break;
924 case "internal_ip_address": 1013 case "internal_ip_address":
925 IPAddress address = (IPAddress) configuration_result; 1014 IPAddress address = (IPAddress) configuration_result;
@@ -1000,8 +1089,13 @@ namespace OpenSim.Framework
1000 args["external_host_name"] = OSD.FromString(ExternalHostName); 1089 args["external_host_name"] = OSD.FromString(ExternalHostName);
1001 args["http_port"] = OSD.FromString(HttpPort.ToString()); 1090 args["http_port"] = OSD.FromString(HttpPort.ToString());
1002 args["server_uri"] = OSD.FromString(ServerURI); 1091 args["server_uri"] = OSD.FromString(ServerURI);
1003 args["region_xloc"] = OSD.FromString(RegionLocX.ToString()); 1092
1004 args["region_yloc"] = OSD.FromString(RegionLocY.ToString()); 1093 args["region_xloc"] = OSD.FromString(LegacyRegionLocX.ToString());
1094 args["region_yloc"] = OSD.FromString(LegacyRegionLocY.ToString());
1095 args["region_size_x"] = OSD.FromString(RegionSizeX.ToString());
1096 args["region_size_y"] = OSD.FromString(RegionSizeY.ToString());
1097 args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString());
1098
1005 args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString()); 1099 args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
1006 args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString()); 1100 args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
1007 if ((RemotingAddress != null) && !RemotingAddress.Equals("")) 1101 if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
@@ -1032,14 +1126,21 @@ namespace OpenSim.Framework
1032 { 1126 {
1033 uint locx; 1127 uint locx;
1034 UInt32.TryParse(args["region_xloc"].AsString(), out locx); 1128 UInt32.TryParse(args["region_xloc"].AsString(), out locx);
1035 RegionLocX = locx; 1129 LegacyRegionLocX = locx;
1036 } 1130 }
1037 if (args["region_yloc"] != null) 1131 if (args["region_yloc"] != null)
1038 { 1132 {
1039 uint locy; 1133 uint locy;
1040 UInt32.TryParse(args["region_yloc"].AsString(), out locy); 1134 UInt32.TryParse(args["region_yloc"].AsString(), out locy);
1041 RegionLocY = locy; 1135 LegacyRegionLocY = locy;
1042 } 1136 }
1137 if (args.ContainsKey("region_size_x"))
1138 RegionSizeX = (uint)args["region_size_x"].AsInteger();
1139 if (args.ContainsKey("region_size_y"))
1140 RegionSizeY = (uint)args["region_size_y"].AsInteger();
1141 if (args.ContainsKey("region_size_z"))
1142 RegionSizeZ = (uint)args["region_size_z"].AsInteger();
1143
1043 IPAddress ip_addr = null; 1144 IPAddress ip_addr = null;
1044 if (args["internal_ep_address"] != null) 1145 if (args["internal_ep_address"] != null)
1045 { 1146 {
@@ -1076,23 +1177,5 @@ namespace OpenSim.Framework
1076 regionInfo.ServerURI = serverURI; 1177 regionInfo.ServerURI = serverURI;
1077 return regionInfo; 1178 return regionInfo;
1078 } 1179 }
1079
1080 public Dictionary<string, object> ToKeyValuePairs()
1081 {
1082 Dictionary<string, object> kvp = new Dictionary<string, object>();
1083 kvp["uuid"] = RegionID.ToString();
1084 kvp["locX"] = RegionLocX.ToString();
1085 kvp["locY"] = RegionLocY.ToString();
1086 kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
1087 kvp["external_port"] = ExternalEndPoint.Port.ToString();
1088 kvp["external_host_name"] = ExternalHostName;
1089 kvp["http_port"] = HttpPort.ToString();
1090 kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
1091 kvp["internal_port"] = InternalEndPoint.Port.ToString();
1092 kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
1093 kvp["server_uri"] = ServerURI;
1094
1095 return kvp;
1096 }
1097 } 1180 }
1098} 1181}
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs
new file mode 100644
index 0000000..103359b
--- /dev/null
+++ b/OpenSim/Framework/TerrainData.cs
@@ -0,0 +1,260 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32
33using OpenMetaverse;
34
35using log4net;
36
37namespace OpenSim.Framework
38{
39 public abstract class TerrainData
40 {
41 // Terrain always is a square
42 public int SizeX { get; protected set; }
43 public int SizeY { get; protected set; }
44 public int SizeZ { get; protected set; }
45
46 public abstract float this[int x, int y] { get; set; }
47 // Someday terrain will have caves
48 public abstract float this[int x, int y, int z] { get; set; }
49
50 public bool IsTainted { get; protected set; }
51 public abstract bool IsTaintedAt(int xx, int yy);
52 public abstract void ClearTaint();
53
54 // Return a representation of this terrain for storing as a blob in the database.
55 // Returns 'true' to say blob was stored in the 'out' locations.
56 public abstract bool GetDatabaseBlob(out int DBFormatRevisionCode, out Array blob);
57
58 // return a special compressed representation of the heightmap in shorts
59 public abstract short[] GetCompressedMap();
60 public abstract float CompressionFactor { get; }
61 public abstract void SetCompressedMap(short[] cmap, float pCompressionFactor);
62
63 public abstract TerrainData Clone();
64 }
65
66 // The terrain is stored in the database as a blob with a 'revision' field.
67 // Some implementations of terrain storage would fill the revision field with
68 // the time the terrain was stored. When real revisions were added and this
69 // feature removed, that left some old entries with the time in the revision
70 // field.
71 // Thus, if revision is greater than 'RevisionHigh' then terrain db entry is
72 // left over and it is presumed to be 'Legacy256'.
73 // Numbers are arbitrary and are chosen to to reduce possible mis-interpretation.
74 // If a revision does not match any of these, it is assumed to be Legacy256.
75 public enum DBTerrainRevision
76 {
77 // Terrain is 'double[256,256]'
78 Legacy256 = 11,
79 // Terrain is 'int32, int32, float[,]' where the shorts are X and Y dimensions
80 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
81 Variable2D = 22,
82 // A revision that is not listed above or any revision greater than this value is 'Legacy256'.
83 RevisionHigh = 1234
84 }
85
86 // Version of terrain that is a heightmap.
87 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
88 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
89 // The heighmap is kept as an array of short integers. The integer values are converted to
90 // and from floats by TerrainCompressionFactor. Shorts are used to limit storage used.
91 public class HeightmapTerrainData : TerrainData
92 {
93 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
94 private static string LogHeader = "[TERRAIN DATA]";
95
96 // TerrainData.this[x, y]
97 public override float this[int x, int y]
98 {
99 get { return FromCompressedHeight(m_heightmap[x, y]); }
100 set {
101 short newVal = ToCompressedHeight(value);
102 if (m_heightmap[x, y] != newVal)
103 {
104 m_heightmap[x, y] = newVal;
105 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true;
106 m_log.DebugFormat("{0} set[{1},{2}] to {3} ({4})", LogHeader, x, y, value, newVal);
107 }
108 }
109 }
110
111 // TerrainData.this[x, y, z]
112 public override float this[int x, int y, int z]
113 {
114 get { return this[x, y]; }
115 set { this[x, y] = value; }
116 }
117
118 // TerrainData.ClearTaint
119 public override void ClearTaint()
120 {
121 IsTainted = false;
122 for (int ii = 0; ii < m_taint.GetLength(0); ii++)
123 for (int jj = 0; jj < m_taint.GetLength(1); jj++)
124 m_taint[ii, jj] = false;
125 }
126
127 public override bool IsTaintedAt(int xx, int yy)
128 {
129 return m_taint[xx / Constants.TerrainPatchSize, yy / Constants.TerrainPatchSize];
130 }
131
132 // TerrainData.GetDatabaseBlob
133 // The user wants something to store in the database.
134 public override bool GetDatabaseBlob(out int DBRevisionCode, out Array blob)
135 {
136 DBRevisionCode = (int)DBTerrainRevision.Legacy256;
137 blob = LegacyTerrainSerialization();
138 return false;
139 }
140
141 // TerrainData.CompressionFactor
142 private float m_compressionFactor = 100.0f;
143 public override float CompressionFactor { get { return m_compressionFactor; } }
144
145 // TerrainData.GetCompressedMap
146 public override short[] GetCompressedMap()
147 {
148 short[] newMap = new short[SizeX * SizeY];
149
150 int ind = 0;
151 for (int xx = 0; xx < SizeX; xx++)
152 for (int yy = 0; yy < SizeY; yy++)
153 newMap[ind++] = m_heightmap[xx, yy];
154
155 return newMap;
156
157 }
158 // TerrainData.SetCompressedMap
159 public override void SetCompressedMap(short[] cmap, float pCompressionFactor)
160 {
161 m_compressionFactor = pCompressionFactor;
162
163 int ind = 0;
164 for (int xx = 0; xx < SizeX; xx++)
165 for (int yy = 0; yy < SizeY; yy++)
166 m_heightmap[xx, yy] = cmap[ind++];
167 }
168
169 // TerrainData.Clone
170 public override TerrainData Clone()
171 {
172 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
173 ret.m_heightmap = (short[,])this.m_heightmap.Clone();
174 return ret;
175 }
176
177 // =============================================================
178
179 private short[,] m_heightmap;
180 // Remember subregions of the heightmap that has changed.
181 private bool[,] m_taint;
182
183 // To save space (especially for large regions), keep the height as a short integer
184 // that is coded as the float height times the compression factor (usually '100'
185 // to make for two decimal points).
186 public short ToCompressedHeight(double pHeight)
187 {
188 return (short)(pHeight * CompressionFactor);
189 }
190
191 public float FromCompressedHeight(short pHeight)
192 {
193 return ((float)pHeight) / CompressionFactor;
194 }
195
196 // To keep with the legacy theme, create an instance of this class based on the
197 // way terrain used to be passed around.
198 public HeightmapTerrainData(double[,] pTerrain)
199 {
200 SizeX = pTerrain.GetLength(0);
201 SizeY = pTerrain.GetLength(1);
202 SizeZ = (int)Constants.RegionHeight;
203 m_compressionFactor = 100.0f;
204
205 m_heightmap = new short[SizeX, SizeY];
206 for (int ii = 0; ii < SizeX; ii++)
207 {
208 for (int jj = 0; jj < SizeY; jj++)
209 {
210 m_heightmap[ii, jj] = ToCompressedHeight(pTerrain[ii, jj]);
211
212 }
213 }
214
215 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
216 ClearTaint();
217 }
218
219 // Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that
220 public HeightmapTerrainData(int pX, int pY, int pZ)
221 {
222 SizeX = pX;
223 SizeY = pY;
224 SizeZ = pZ;
225 m_compressionFactor = 100.0f;
226 m_heightmap = new short[SizeX, SizeY];
227 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
228 ClearTaint();
229 }
230
231 public HeightmapTerrainData(short[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ)
232 {
233 SetCompressedMap(cmap, pCompressionFactor);
234 }
235
236
237 // Just create an array of doubles. Presumes the caller implicitly knows the size.
238 public Array LegacyTerrainSerialization()
239 {
240 Array ret = null;
241 using (MemoryStream str = new MemoryStream(SizeX * SizeY * sizeof(double)))
242 {
243 using (BinaryWriter bw = new BinaryWriter(str))
244 {
245 // TODO: COMPATIBILITY - Add byte-order conversions
246 for (int ii = 0; ii < SizeX; ii++)
247 for (int jj = 0; jj < SizeY; jj++)
248 {
249 double height = this[ii, jj];
250 if (height == 0.0)
251 height = double.Epsilon;
252 bw.Write(height);
253 }
254 }
255 ret = str.ToArray();
256 }
257 return ret;
258 }
259 }
260}
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 12250df..e241274 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -781,8 +781,8 @@ namespace OpenSim
781 MainConsole.Instance.Output(String.Format( 781 MainConsole.Instance.Output(String.Format(
782 "Region Name: {0}, Region XLoc: {1}, Region YLoc: {2}, Region Port: {3}, Estate Name: {4}", 782 "Region Name: {0}, Region XLoc: {1}, Region YLoc: {2}, Region Port: {3}, Estate Name: {4}",
783 scene.RegionInfo.RegionName, 783 scene.RegionInfo.RegionName,
784 scene.RegionInfo.RegionLocX, 784 scene.RegionInfo.LegacyRegionLocX,
785 scene.RegionInfo.RegionLocY, 785 scene.RegionInfo.LegacyRegionLocY,
786 scene.RegionInfo.InternalEndPoint.Port, 786 scene.RegionInfo.InternalEndPoint.Port,
787 scene.RegionInfo.EstateSettings.EstateName)); 787 scene.RegionInfo.EstateSettings.EstateName));
788 }); 788 });
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index b032e7f..1e34a1e 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -742,7 +742,7 @@ namespace OpenSim
742 { 742 {
743 m_log.InfoFormat( 743 m_log.InfoFormat(
744 "[OPENSIM]: Got restart signal from SceneManager for region {0} ({1},{2})", 744 "[OPENSIM]: Got restart signal from SceneManager for region {0} ({1},{2})",
745 whichRegion.RegionName, whichRegion.RegionLocX, whichRegion.RegionLocY); 745 whichRegion.RegionName, whichRegion.LegacyRegionLocX, whichRegion.LegacyRegionLocY);
746 746
747 ShutdownClientServer(whichRegion); 747 ShutdownClientServer(whichRegion);
748 IScene scene; 748 IScene scene;
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 03cd2b4..2b8a04f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -34,11 +34,13 @@ using System.Text;
34using System.Threading; 34using System.Threading;
35using System.Timers; 35using System.Timers;
36using System.Xml; 36using System.Xml;
37
37using log4net; 38using log4net;
38using OpenMetaverse; 39using OpenMetaverse;
39using OpenMetaverse.Packets; 40using OpenMetaverse.Packets;
40using OpenMetaverse.Messages.Linden; 41using OpenMetaverse.Messages.Linden;
41using OpenMetaverse.StructuredData; 42using OpenMetaverse.StructuredData;
43
42using OpenSim.Framework; 44using OpenSim.Framework;
43using OpenSim.Framework.Client; 45using OpenSim.Framework.Client;
44using OpenSim.Framework.Monitoring; 46using OpenSim.Framework.Monitoring;
@@ -48,7 +50,6 @@ using OpenSim.Services.Interfaces;
48using Timer = System.Timers.Timer; 50using Timer = System.Timers.Timer;
49using AssetLandmark = OpenSim.Framework.AssetLandmark; 51using AssetLandmark = OpenSim.Framework.AssetLandmark;
50using RegionFlags = OpenMetaverse.RegionFlags; 52using RegionFlags = OpenMetaverse.RegionFlags;
51using Nini.Config;
52 53
53using System.IO; 54using System.IO;
54using PermissionMask = OpenSim.Framework.PermissionMask; 55using PermissionMask = OpenSim.Framework.PermissionMask;
@@ -307,6 +308,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
307 private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f; 308 private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
308 309
309 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 310 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
311 private static string LogHeader = "[LLCLIENTVIEW]";
310 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients 312 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
311 313
312 /// <summary> 314 /// <summary>
@@ -447,7 +449,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
447 449
448// ~LLClientView() 450// ~LLClientView()
449// { 451// {
450// m_log.DebugFormat("[LLCLIENTVIEW]: Destructor called for {0}, circuit code {1}", Name, CircuitCode); 452// m_log.DebugFormat("{0} Destructor called for {1}, circuit code {2}", LogHeader, Name, CircuitCode);
451// } 453// }
452 454
453 /// <summary> 455 /// <summary>
@@ -513,9 +515,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
513 // there is some unidentified connection problem, not where we have issues due to deadlock 515 // there is some unidentified connection problem, not where we have issues due to deadlock
514 if (!IsActive && !force) 516 if (!IsActive && !force)
515 { 517 {
516 m_log.DebugFormat( 518 m_log.DebugFormat( "{0} Not attempting to close inactive client {1} in {2} since force flag is not set",
517 "[CLIENT]: Not attempting to close inactive client {0} in {1} since force flag is not set", 519 LogHeader, Name, m_scene.Name);
518 Name, m_scene.Name);
519 520
520 return; 521 return;
521 } 522 }
@@ -1162,10 +1163,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1162 /// <param name="o"></param> 1163 /// <param name="o"></param>
1163 private void DoSendLayerData(object o) 1164 private void DoSendLayerData(object o)
1164 { 1165 {
1165 float[] map = LLHeightFieldMoronize((float[])o); 1166 float[] map = (float[])o;
1166 1167
1167 try 1168 try
1168 { 1169 {
1170 // Send LayerData in typerwriter pattern
1169 //for (int y = 0; y < 16; y++) 1171 //for (int y = 0; y < 16; y++)
1170 //{ 1172 //{
1171 // for (int x = 0; x < 16; x++) 1173 // for (int x = 0; x < 16; x++)
@@ -1230,7 +1232,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1230 // } 1232 // }
1231 1233
1232 /// <summary> 1234 /// <summary>
1233 /// Sends a specified patch to a client 1235 /// Sends a terrain packet for the point specified.
1236 /// This is a legacy call that has refarbed the terrain into a flat map of floats.
1237 /// We just use the terrain from the region we know about.
1234 /// </summary> 1238 /// </summary>
1235 /// <param name="px">Patch coordinate (x) 0..15</param> 1239 /// <param name="px">Patch coordinate (x) 0..15</param>
1236 /// <param name="py">Patch coordinate (y) 0..15</param> 1240 /// <param name="py">Patch coordinate (y) 0..15</param>
@@ -1239,12 +1243,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1239 { 1243 {
1240 try 1244 try
1241 { 1245 {
1242 int[] patches = new int[] { py * 16 + px }; 1246 // For unknown reasons, after this point, patch numbers are swapped X for y.
1243 float[] heightmap = (map.Length == 65536) ? 1247 // That means, that for <patchNumX, patchNumY, the array location is computed as map[patchNumY * 16 + patchNumX].
1244 map : 1248 // TODO: someday straighten the below implementation to keep the X row order for patch numbers.
1245 LLHeightFieldMoronize(map); 1249 // Since this is passing only one patch, we just swap the patch numbers.
1246 1250 LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(m_scene.Heightmap.GetTerrainData(), px, py);
1247 LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(heightmap, patches);
1248 1251
1249 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a sub optimal editing experience. 1252 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a sub optimal editing experience.
1250 // To alleviate this issue, when the user edits the terrain, we start skipping the queues until they're done editing the terrain. 1253 // To alleviate this issue, when the user edits the terrain, we start skipping the queues until they're done editing the terrain.
@@ -1262,14 +1265,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1262 if (m_justEditedTerrain) 1265 if (m_justEditedTerrain)
1263 { 1266 {
1264 layerpack.Header.Reliable = false; 1267 layerpack.Header.Reliable = false;
1265 OutPacket(layerpack, 1268 OutPacket(layerpack, ThrottleOutPacketType.Unknown );
1266 ThrottleOutPacketType.Unknown );
1267 } 1269 }
1268 else 1270 else
1269 { 1271 {
1270 layerpack.Header.Reliable = true; 1272 layerpack.Header.Reliable = true;
1271 OutPacket(layerpack, 1273 OutPacket(layerpack, ThrottleOutPacketType.Land);
1272 ThrottleOutPacketType.Land);
1273 } 1274 }
1274 } 1275 }
1275 catch (Exception e) 1276 catch (Exception e)
@@ -1279,38 +1280,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1279 } 1280 }
1280 1281
1281 /// <summary> 1282 /// <summary>
1282 /// Munges heightfield into the LLUDP backed in restricted heightfield.
1283 /// </summary>
1284 /// <param name="map">float array in the base; Constants.RegionSize</param>
1285 /// <returns>float array in the base 256</returns>
1286 internal float[] LLHeightFieldMoronize(float[] map)
1287 {
1288 if (map.Length == 65536)
1289 return map;
1290 else
1291 {
1292 float[] returnmap = new float[65536];
1293
1294 if (map.Length < 65535)
1295 {
1296 // rebase the vector stride to 256
1297 for (int i = 0; i < Constants.RegionSize; i++)
1298 Array.Copy(map, i * (int)Constants.RegionSize, returnmap, i * 256, (int)Constants.RegionSize);
1299 }
1300 else
1301 {
1302 for (int i = 0; i < 256; i++)
1303 Array.Copy(map, i * (int)Constants.RegionSize, returnmap, i * 256, 256);
1304 }
1305
1306 //Array.Copy(map,0,returnmap,0,(map.Length < 65536)? map.Length : 65536);
1307
1308 return returnmap;
1309 }
1310
1311 }
1312
1313 /// <summary>
1314 /// Send the wind matrix to the client 1283 /// Send the wind matrix to the client
1315 /// </summary> 1284 /// </summary>
1316 /// <param name="windSpeeds">16x16 array of wind speeds</param> 1285 /// <param name="windSpeeds">16x16 array of wind speeds</param>
@@ -2782,8 +2751,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2782 { 2751 {
2783 if (req.AssetInf.Data == null) 2752 if (req.AssetInf.Data == null)
2784 { 2753 {
2785 m_log.ErrorFormat("Cannot send asset {0} ({1}), asset data is null", 2754 m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset data is null",
2786 req.AssetInf.ID, req.AssetInf.Metadata.ContentType); 2755 LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
2787 return; 2756 return;
2788 } 2757 }
2789 2758
@@ -2910,8 +2879,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2910 { 2879 {
2911 pos = (land.AABBMax + land.AABBMin) * 0.5f; 2880 pos = (land.AABBMax + land.AABBMin) * 0.5f;
2912 } 2881 }
2913 reply.Data.GlobalX = info.RegionLocX + x; 2882 reply.Data.GlobalX = info.LegacyRegionLocX + x;
2914 reply.Data.GlobalY = info.RegionLocY + y; 2883 reply.Data.GlobalY = info.LegacyRegionLocY + y;
2915 reply.Data.GlobalZ = pos.Z; 2884 reply.Data.GlobalZ = pos.Z;
2916 reply.Data.SimName = Utils.StringToBytes(info.RegionName); 2885 reply.Data.SimName = Utils.StringToBytes(info.RegionName);
2917 reply.Data.SnapshotID = land.SnapshotID; 2886 reply.Data.SnapshotID = land.SnapshotID;
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
index 27ace68..db62b31 100644
--- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
@@ -189,8 +189,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
189 string message = c.Message; 189 string message = c.Message;
190 Scene scene = (Scene)c.Scene; 190 Scene scene = (Scene)c.Scene;
191 Vector3 fromPos = c.Position; 191 Vector3 fromPos = c.Position;
192 Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, 192 Vector3 regionPos = new Vector3(scene.RegionInfo.RegionWorldLocX, scene.RegionInfo.RegionWorldLocY, 0);
193 scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
194 193
195 if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; 194 if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel;
196 195
@@ -342,8 +341,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
342 { 341 {
343 Vector3 fromRegionPos = fromPos + regionPos; 342 Vector3 fromRegionPos = fromPos + regionPos;
344 Vector3 toRegionPos = presence.AbsolutePosition + 343 Vector3 toRegionPos = presence.AbsolutePosition +
345 new Vector3(presence.Scene.RegionInfo.RegionLocX * Constants.RegionSize, 344 new Vector3(presence.Scene.RegionInfo.RegionWorldLocX, presence.Scene.RegionInfo.RegionWorldLocY, 0);
346 presence.Scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
347 345
348 int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos); 346 int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos);
349 347
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index 56ff2bd..a982466 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -663,8 +663,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
663 663
664 Vector3 avaPos = p.AbsolutePosition; 664 Vector3 avaPos = p.AbsolutePosition;
665 // Getting the global position for the Avatar 665 // Getting the global position for the Avatar
666 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionLocX*Constants.RegionSize + avaPos.X, 666 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionWorldLocX + avaPos.X,
667 remoteClient.Scene.RegionInfo.RegionLocY*Constants.RegionSize + avaPos.Y, 667 remoteClient.Scene.RegionInfo.RegionWorldLocY + avaPos.Y,
668 avaPos.Z); 668 avaPos.Z);
669 669
670 string landOwnerName = string.Empty; 670 string landOwnerName = string.Empty;
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index aa8a4db..eb1b271 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -494,8 +494,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
494 } 494 }
495 495
496 // Check that these are not the same coordinates 496 // Check that these are not the same coordinates
497 if (finalDestination.RegionLocX == sp.Scene.RegionInfo.RegionLocX && 497 if (finalDestination.RegionLocX == sp.Scene.RegionInfo.LegacyRegionLocX &&
498 finalDestination.RegionLocY == sp.Scene.RegionInfo.RegionLocY) 498 finalDestination.RegionLocY == sp.Scene.RegionInfo.LegacyRegionLocY)
499 { 499 {
500 // Can't do. Viewer crashes 500 // Can't do. Viewer crashes
501 sp.ControllingClient.SendTeleportFailed("Space warp! You would crash. Move to a different region and try again."); 501 sp.ControllingClient.SendTeleportFailed("Space warp! You would crash. Move to a different region and try again.");
@@ -567,8 +567,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
567// destRegionX, destRegionY, finalDestination.RegionID, finalDestination.ServerURI); 567// destRegionX, destRegionY, finalDestination.RegionID, finalDestination.ServerURI);
568 568
569 // Insanely, RegionLoc on RegionInfo is the 256m map co-ord whilst GridRegion.RegionLoc is the raw meters position. 569 // Insanely, RegionLoc on RegionInfo is the 256m map co-ord whilst GridRegion.RegionLoc is the raw meters position.
570 return Math.Abs(sourceRegion.RegionLocX - destRegion.RegionCoordX) <= MaxTransferDistance 570 return Math.Abs(sourceRegion.LegacyRegionLocX - destRegion.RegionCoordX) <= MaxTransferDistance
571 && Math.Abs(sourceRegion.RegionLocY - destRegion.RegionCoordY) <= MaxTransferDistance; 571 && Math.Abs(sourceRegion.LegacyRegionLocY - destRegion.RegionCoordY) <= MaxTransferDistance;
572 } 572 }
573 573
574 /// <summary> 574 /// <summary>
@@ -635,7 +635,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
635 string.Format( 635 string.Format(
636 "Can't teleport to {0} ({1},{2}) from {3} ({4},{5}), destination is more than {6} regions way", 636 "Can't teleport to {0} ({1},{2}) from {3} ({4},{5}), destination is more than {6} regions way",
637 finalDestination.RegionName, finalDestination.RegionCoordX, finalDestination.RegionCoordY, 637 finalDestination.RegionName, finalDestination.RegionCoordX, finalDestination.RegionCoordY,
638 sourceRegion.RegionName, sourceRegion.RegionLocX, sourceRegion.RegionLocY, 638 sourceRegion.RegionName, sourceRegion.LegacyRegionLocX, sourceRegion.LegacyRegionLocY,
639 MaxTransferDistance)); 639 MaxTransferDistance));
640 640
641 return; 641 return;
@@ -1374,8 +1374,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1374// "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name); 1374// "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name);
1375 1375
1376 Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z); 1376 Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
1377 uint neighbourx = scene.RegionInfo.RegionLocX; 1377 uint neighbourx = scene.RegionInfo.LegacyRegionLocX;
1378 uint neighboury = scene.RegionInfo.RegionLocY; 1378 uint neighboury = scene.RegionInfo.LegacyRegionLocY;
1379 const float boundaryDistance = 1.7f; 1379 const float boundaryDistance = 1.7f;
1380 Vector3 northCross = new Vector3(0, boundaryDistance, 0); 1380 Vector3 northCross = new Vector3(0, boundaryDistance, 0);
1381 Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0); 1381 Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
@@ -1408,8 +1408,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1408 neighbourx = b.TriggerRegionX; 1408 neighbourx = b.TriggerRegionX;
1409 1409
1410 Vector3 newposition = pos; 1410 Vector3 newposition = pos;
1411 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; 1411 newposition.X += (scene.RegionInfo.LegacyRegionLocX - neighbourx) * Constants.RegionSize;
1412 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; 1412 newposition.Y += (scene.RegionInfo.LegacyRegionLocY - neighboury) * Constants.RegionSize;
1413 agent.ControllingClient.SendAgentAlertMessage( 1413 agent.ControllingClient.SendAgentAlertMessage(
1414 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); 1414 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1415 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); 1415 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
@@ -1431,8 +1431,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1431 neighbourx = ba.TriggerRegionX; 1431 neighbourx = ba.TriggerRegionX;
1432 1432
1433 Vector3 newposition = pos; 1433 Vector3 newposition = pos;
1434 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; 1434 newposition.X += (scene.RegionInfo.LegacyRegionLocX - neighbourx) * Constants.RegionSize;
1435 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; 1435 newposition.Y += (scene.RegionInfo.LegacyRegionLocY - neighboury) * Constants.RegionSize;
1436 agent.ControllingClient.SendAgentAlertMessage( 1436 agent.ControllingClient.SendAgentAlertMessage(
1437 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); 1437 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1438 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); 1438 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
@@ -1462,8 +1462,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1462 neighboury = ba.TriggerRegionY; 1462 neighboury = ba.TriggerRegionY;
1463 neighbourx = ba.TriggerRegionX; 1463 neighbourx = ba.TriggerRegionX;
1464 Vector3 newposition = pos; 1464 Vector3 newposition = pos;
1465 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; 1465 newposition.X += (scene.RegionInfo.LegacyRegionLocX - neighbourx) * Constants.RegionSize;
1466 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; 1466 newposition.Y += (scene.RegionInfo.LegacyRegionLocY - neighboury) * Constants.RegionSize;
1467 agent.ControllingClient.SendAgentAlertMessage( 1467 agent.ControllingClient.SendAgentAlertMessage(
1468 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); 1468 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1469 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); 1469 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
@@ -1492,8 +1492,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1492 neighboury = b.TriggerRegionY; 1492 neighboury = b.TriggerRegionY;
1493 neighbourx = b.TriggerRegionX; 1493 neighbourx = b.TriggerRegionX;
1494 Vector3 newposition = pos; 1494 Vector3 newposition = pos;
1495 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; 1495 newposition.X += (scene.RegionInfo.LegacyRegionLocX - neighbourx) * Constants.RegionSize;
1496 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; 1496 newposition.Y += (scene.RegionInfo.LegacyRegionLocY - neighboury) * Constants.RegionSize;
1497 agent.ControllingClient.SendAgentAlertMessage( 1497 agent.ControllingClient.SendAgentAlertMessage(
1498 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); 1498 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1499 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); 1499 InformClientToInitiateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
@@ -1901,7 +1901,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1901 1901
1902 if (m_regionInfo != null) 1902 if (m_regionInfo != null)
1903 { 1903 {
1904 neighbours = RequestNeighbours(sp, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY); 1904 neighbours = RequestNeighbours(sp, m_regionInfo.LegacyRegionLocX, m_regionInfo.LegacyRegionLocY);
1905 } 1905 }
1906 else 1906 else
1907 { 1907 {
@@ -2057,8 +2057,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2057 2057
2058 Vector3 CalculateOffset(ScenePresence sp, GridRegion neighbour) 2058 Vector3 CalculateOffset(ScenePresence sp, GridRegion neighbour)
2059 { 2059 {
2060 int rRegionX = (int)sp.Scene.RegionInfo.RegionLocX; 2060 int rRegionX = (int)sp.Scene.RegionInfo.LegacyRegionLocX;
2061 int rRegionY = (int)sp.Scene.RegionInfo.RegionLocY; 2061 int rRegionY = (int)sp.Scene.RegionInfo.LegacyRegionLocY;
2062 int tRegionX = neighbour.RegionLocX / (int)Constants.RegionSize; 2062 int tRegionX = neighbour.RegionLocX / (int)Constants.RegionSize;
2063 int tRegionY = neighbour.RegionLocY / (int)Constants.RegionSize; 2063 int tRegionY = neighbour.RegionLocY / (int)Constants.RegionSize;
2064 int shiftx = (rRegionX - tRegionX) * (int)Constants.RegionSize; 2064 int shiftx = (rRegionX - tRegionX) * (int)Constants.RegionSize;
@@ -2161,10 +2161,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2161 extent.X = ((int)extent.X / (int)Constants.RegionSize); 2161 extent.X = ((int)extent.X / (int)Constants.RegionSize);
2162 extent.Y = ((int)extent.Y / (int)Constants.RegionSize); 2162 extent.Y = ((int)extent.Y / (int)Constants.RegionSize);
2163 2163
2164 swCorner.X = Scene.RegionInfo.RegionLocX - 1; 2164 swCorner.X = Scene.RegionInfo.LegacyRegionLocX - 1;
2165 swCorner.Y = Scene.RegionInfo.RegionLocY - 1; 2165 swCorner.Y = Scene.RegionInfo.LegacyRegionLocY - 1;
2166 neCorner.X = Scene.RegionInfo.RegionLocX + extent.X; 2166 neCorner.X = Scene.RegionInfo.LegacyRegionLocX + extent.X;
2167 neCorner.Y = Scene.RegionInfo.RegionLocY + extent.Y; 2167 neCorner.Y = Scene.RegionInfo.LegacyRegionLocY + extent.Y;
2168 } 2168 }
2169 2169
2170 /// <summary> 2170 /// <summary>
@@ -2301,8 +2301,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2301 return; 2301 return;
2302 } 2302 }
2303 2303
2304 int thisx = (int)scene.RegionInfo.RegionLocX; 2304 int thisx = (int)scene.RegionInfo.LegacyRegionLocX;
2305 int thisy = (int)scene.RegionInfo.RegionLocY; 2305 int thisy = (int)scene.RegionInfo.LegacyRegionLocY;
2306 Vector3 EastCross = new Vector3(0.1f, 0, 0); 2306 Vector3 EastCross = new Vector3(0.1f, 0, 0);
2307 Vector3 WestCross = new Vector3(-0.1f, 0, 0); 2307 Vector3 WestCross = new Vector3(-0.1f, 0, 0);
2308 Vector3 NorthCross = new Vector3(0, 0.1f, 0); 2308 Vector3 NorthCross = new Vector3(0, 0.1f, 0);
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
index d943b20..bf87392 100644
--- a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
@@ -213,8 +213,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
213 if (part != null) 213 if (part != null)
214 { 214 {
215 ObjectRegionName = s.RegionInfo.RegionName; 215 ObjectRegionName = s.RegionInfo.RegionName;
216 uint localX = (s.RegionInfo.RegionLocX * (int)Constants.RegionSize); 216 uint localX = s.RegionInfo.RegionWorldLocX;
217 uint localY = (s.RegionInfo.RegionLocY * (int)Constants.RegionSize); 217 uint localY = s.RegionInfo.RegionWorldLocY;
218 ObjectRegionName = ObjectRegionName + " (" + localX + ", " + localY + ")"; 218 ObjectRegionName = ObjectRegionName + " (" + localX + ", " + localY + ")";
219 return part; 219 return part;
220 } 220 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 26d22b8..c1f2f04 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -224,10 +224,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
224 } 224 }
225 225
226 string reason = string.Empty; 226 string reason = string.Empty;
227 if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, out reason)) 227 if (!m_MapService.AddMapTile((int)scene.RegionInfo.LegacyRegionLocX, (int)scene.RegionInfo.LegacyRegionLocY, jpgData, out reason))
228 { 228 {
229 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}", 229 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}",
230 scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason); 230 scene.RegionInfo.RegionName, scene.RegionInfo.LegacyRegionLocX, scene.RegionInfo.LegacyRegionLocY, reason);
231 } 231 }
232 } 232 }
233 } 233 }
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs
index d8dace2..9aa4243 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs
@@ -71,8 +71,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
71 71
72 public void AddScene(Scene scene) 72 public void AddScene(Scene scene)
73 { 73 {
74 uint x = scene.RegionInfo.RegionLocX; 74 uint x = scene.RegionInfo.LegacyRegionLocX;
75 uint y = scene.RegionInfo.RegionLocY; 75 uint y = scene.RegionInfo.LegacyRegionLocY;
76 76
77 SortedDictionary<uint, Scene> row; 77 SortedDictionary<uint, Scene> row;
78 if (!Regions.TryGetValue(y, out row)) 78 if (!Regions.TryGetValue(y, out row))
@@ -120,8 +120,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
120 { 120 {
121 // We add the region's coordinates to ensure uniqueness even if multiple regions have the same name 121 // We add the region's coordinates to ensure uniqueness even if multiple regions have the same name
122 string path = string.Format("{0}_{1}_{2}", 122 string path = string.Format("{0}_{1}_{2}",
123 scene.RegionInfo.RegionLocX - Rect.X + 1, 123 scene.RegionInfo.LegacyRegionLocX - Rect.X + 1,
124 scene.RegionInfo.RegionLocY - Rect.Y + 1, 124 scene.RegionInfo.LegacyRegionLocY - Rect.Y + 1,
125 scene.RegionInfo.RegionName.Replace(' ', '_')); 125 scene.RegionInfo.RegionName.Replace(' ', '_'));
126 m_regionDirs[scene.RegionInfo.RegionID] = path; 126 m_regionDirs[scene.RegionInfo.RegionID] = path;
127 }); 127 });
diff --git a/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs b/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs
index 3dcc020..25f1e5c 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs
@@ -145,7 +145,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
145 { 145 {
146 foreach (RegionInfo archivedRegion in m_directory2region.Values) 146 foreach (RegionInfo archivedRegion in m_directory2region.Values)
147 { 147 {
148 Point location = new Point((int)rootScene.RegionInfo.RegionLocX, (int)rootScene.RegionInfo.RegionLocY); 148 Point location = new Point((int)rootScene.RegionInfo.LegacyRegionLocX, (int)rootScene.RegionInfo.LegacyRegionLocY);
149 location.Offset(archivedRegion.Location); 149 location.Offset(archivedRegion.Location);
150 150
151 Scene scene; 151 Scene scene;
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
index 173b603..bc172a4 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
@@ -96,9 +96,9 @@ namespace OpenSim.Region.CoreModules.World.Estate
96 int x = (args.Length > 5 ? int.Parse(args[5]) : -1); 96 int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
97 int y = (args.Length > 6 ? int.Parse(args[6]) : -1); 97 int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
98 98
99 if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x) 99 if (x == -1 || m_module.Scene.RegionInfo.LegacyRegionLocX == x)
100 { 100 {
101 if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y) 101 if (y == -1 || m_module.Scene.RegionInfo.LegacyRegionLocY == y)
102 { 102 {
103 int corner = int.Parse(num); 103 int corner = int.Parse(num);
104 UUID texture = UUID.Parse(uuid); 104 UUID texture = UUID.Parse(uuid);
@@ -135,9 +135,9 @@ namespace OpenSim.Region.CoreModules.World.Estate
135 int x = (args.Length > 4 ? int.Parse(args[4]) : -1); 135 int x = (args.Length > 4 ? int.Parse(args[4]) : -1);
136 int y = (args.Length > 5 ? int.Parse(args[5]) : -1); 136 int y = (args.Length > 5 ? int.Parse(args[5]) : -1);
137 137
138 if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x) 138 if (x == -1 || m_module.Scene.RegionInfo.LegacyRegionLocX == x)
139 { 139 {
140 if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y) 140 if (y == -1 || m_module.Scene.RegionInfo.LegacyRegionLocY == y)
141 { 141 {
142 double selectedheight = double.Parse(heightstring); 142 double selectedheight = double.Parse(heightstring);
143 143
@@ -159,9 +159,9 @@ namespace OpenSim.Region.CoreModules.World.Estate
159 int x = (args.Length > 6 ? int.Parse(args[6]) : -1); 159 int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
160 int y = (args.Length > 7 ? int.Parse(args[7]) : -1); 160 int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
161 161
162 if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x) 162 if (x == -1 || m_module.Scene.RegionInfo.LegacyRegionLocX == x)
163 { 163 {
164 if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y) 164 if (y == -1 || m_module.Scene.RegionInfo.LegacyRegionLocY == y)
165 { 165 {
166 int corner = int.Parse(num); 166 int corner = int.Parse(num);
167 float lowValue = float.Parse(min, Culture.NumberFormatInfo); 167 float lowValue = float.Parse(min, Culture.NumberFormatInfo);
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index 1789d6d..51ed83f 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -1717,8 +1717,8 @@ namespace OpenSim.Region.CoreModules.World.Land
1717 // HACK for now 1717 // HACK for now
1718 RegionInfo r = new RegionInfo(); 1718 RegionInfo r = new RegionInfo();
1719 r.RegionName = info.RegionName; 1719 r.RegionName = info.RegionName;
1720 r.RegionLocX = (uint)info.RegionLocX; 1720 r.LegacyRegionLocX = (uint)info.RegionLocX;
1721 r.RegionLocY = (uint)info.RegionLocY; 1721 r.LegacyRegionLocY = (uint)info.RegionLocY;
1722 r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess); 1722 r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess);
1723 remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y); 1723 remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y);
1724 } 1724 }
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index d78ade5..d5c77ec 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -67,7 +67,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
67 { 67 {
68 using (Bitmap bitmap = new Bitmap(filename)) 68 using (Bitmap bitmap = new Bitmap(filename))
69 { 69 {
70 ITerrainChannel retval = new TerrainChannel(true); 70 ITerrainChannel retval = new TerrainChannel(w, h);
71 71
72 for (int x = 0; x < retval.Width; x++) 72 for (int x = 0; x < retval.Width; x++)
73 { 73 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index fd30c46..459af73 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -30,10 +30,14 @@ using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection; 31using System.Reflection;
32using System.Net; 32using System.Net;
33
33using log4net; 34using log4net;
34using Nini.Config; 35using Nini.Config;
36
35using OpenMetaverse; 37using OpenMetaverse;
36using Mono.Addins; 38using Mono.Addins;
39
40using OpenSim.Data;
37using OpenSim.Framework; 41using OpenSim.Framework;
38using OpenSim.Region.CoreModules.Framework.InterfaceCommander; 42using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
39using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; 43using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
@@ -70,6 +74,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
70 #endregion 74 #endregion
71 75
72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 private static readonly string LogHeader = "[TERRAIN MODULE]";
73 78
74 private readonly Commander m_commander = new Commander("terrain"); 79 private readonly Commander m_commander = new Commander("terrain");
75 80
@@ -130,15 +135,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
130 { 135 {
131 if (m_scene.Heightmap == null) 136 if (m_scene.Heightmap == null)
132 { 137 {
133 m_channel = new TerrainChannel(m_InitialTerrain); 138 m_channel = new TerrainChannel(m_InitialTerrain, (int)m_scene.RegionInfo.RegionSizeX,
139 (int)m_scene.RegionInfo.RegionSizeY,
140 (int)m_scene.RegionInfo.RegionSizeZ);
134 m_scene.Heightmap = m_channel; 141 m_scene.Heightmap = m_channel;
135 m_revert = new TerrainChannel();
136 UpdateRevertMap(); 142 UpdateRevertMap();
137 } 143 }
138 else 144 else
139 { 145 {
140 m_channel = m_scene.Heightmap; 146 m_channel = m_scene.Heightmap;
141 m_revert = new TerrainChannel();
142 UpdateRevertMap(); 147 UpdateRevertMap();
143 } 148 }
144 149
@@ -532,6 +537,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
532 /// </summary> 537 /// </summary>
533 public void UpdateRevertMap() 538 public void UpdateRevertMap()
534 { 539 {
540 /*
535 int x; 541 int x;
536 for (x = 0; x < m_channel.Width; x++) 542 for (x = 0; x < m_channel.Width; x++)
537 { 543 {
@@ -541,6 +547,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
541 m_revert[x, y] = m_channel[x, y]; 547 m_revert[x, y] = m_channel[x, y];
542 } 548 }
543 } 549 }
550 */
551 m_revert = m_channel.MakeCopy();
544 } 552 }
545 553
546 /// <summary> 554 /// <summary>
@@ -553,8 +561,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
553 /// <param name="fileStartY">Where to begin our slice</param> 561 /// <param name="fileStartY">Where to begin our slice</param>
554 public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) 562 public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
555 { 563 {
556 int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX; 564 int offsetX = (int) m_scene.RegionInfo.LegacyRegionLocX - fileStartX;
557 int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY; 565 int offsetY = (int) m_scene.RegionInfo.LegacyRegionLocY - fileStartY;
558 566
559 if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) 567 if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
560 { 568 {
@@ -594,14 +602,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain
594 /// <param name="fileStartY">The may y co-ordinate at which to begin the save.</param> 602 /// <param name="fileStartY">The may y co-ordinate at which to begin the save.</param>
595 public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) 603 public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
596 { 604 {
597 int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX; 605 int offsetX = (int)m_scene.RegionInfo.LegacyRegionLocX - fileStartX;
598 int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY; 606 int offsetY = (int)m_scene.RegionInfo.LegacyRegionLocY - fileStartY;
599 607
600 if (offsetX < 0 || offsetX >= fileWidth || offsetY < 0 || offsetY >= fileHeight) 608 if (offsetX < 0 || offsetX >= fileWidth || offsetY < 0 || offsetY >= fileHeight)
601 { 609 {
602 MainConsole.Instance.OutputFormat( 610 MainConsole.Instance.OutputFormat(
603 "ERROR: file width + minimum X tile and file height + minimum Y tile must incorporate the current region at ({0},{1}). File width {2} from {3} and file height {4} from {5} does not.", 611 "ERROR: file width + minimum X tile and file height + minimum Y tile must incorporate the current region at ({0},{1}). File width {2} from {3} and file height {4} from {5} does not.",
604 m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, fileWidth, fileStartX, fileHeight, fileStartY); 612 m_scene.RegionInfo.LegacyRegionLocX, m_scene.RegionInfo.LegacyRegionLocY, fileWidth, fileStartX, fileHeight, fileStartY);
605 613
606 return; 614 return;
607 } 615 }
@@ -705,7 +713,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
705 private void CheckForTerrainUpdates(bool respectEstateSettings) 713 private void CheckForTerrainUpdates(bool respectEstateSettings)
706 { 714 {
707 bool shouldTaint = false; 715 bool shouldTaint = false;
708 float[] serialised = m_channel.GetFloatsSerialised(); 716 float[] terrHeights = m_channel.GetFloatsSerialised();
709 int x; 717 int x;
710 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) 718 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
711 { 719 {
@@ -714,16 +722,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain
714 { 722 {
715 if (m_channel.Tainted(x, y)) 723 if (m_channel.Tainted(x, y))
716 { 724 {
717 // if we should respect the estate settings then 725 // If we should respect the estate settings then
718 // fixup and height deltas that don't respect them 726 // fixup and height deltas that don't respect them.
727 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values.
719 if (respectEstateSettings && LimitChannelChanges(x, y)) 728 if (respectEstateSettings && LimitChannelChanges(x, y))
720 { 729 {
721 // this has been vetoed, so update 730 // Terrain heights were modified. Refetch the terrain info.
722 // what we are going to send to the client 731 terrHeights = m_channel.GetFloatsSerialised();
723 serialised = m_channel.GetFloatsSerialised();
724 } 732 }
725 733
726 SendToClients(serialised, x, y); 734 // m_log.DebugFormat("{0} Patch modified. Sending (x,y) = ({1},{2})", LogHeader, x, y);
735 SendToClients(terrHeights, x, y);
727 shouldTaint = true; 736 shouldTaint = true;
728 } 737 }
729 } 738 }
@@ -792,13 +801,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
792 /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param> 801 /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param>
793 /// <param name="x">The patch corner to send</param> 802 /// <param name="x">The patch corner to send</param>
794 /// <param name="y">The patch corner to send</param> 803 /// <param name="y">The patch corner to send</param>
795 private void SendToClients(float[] serialised, int x, int y) 804 private void SendToClients(float[] heightMap, int x, int y)
796 { 805 {
797 m_scene.ForEachClient( 806 m_scene.ForEachClient(
798 delegate(IClientAPI controller) 807 delegate(IClientAPI controller)
799 { controller.SendLayerData( 808 { controller.SendLayerData( x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, heightMap); }
800 x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised);
801 }
802 ); 809 );
803 } 810 }
804 811
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index cdf1467..8383f4e 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -249,7 +249,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
249 // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is 249 // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is
250 // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks. 250 // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks.
251 251
252 if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048) 252 if (m_scene.RegionInfo.LegacyRegionLocX >= 2048 || m_scene.RegionInfo.LegacyRegionLocY >= 2048)
253 { 253 {
254 ScenePresence avatarPresence = null; 254 ScenePresence avatarPresence = null;
255 255
@@ -278,10 +278,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
278 List<MapBlockData> mapBlocks = new List<MapBlockData>(); ; 278 List<MapBlockData> mapBlocks = new List<MapBlockData>(); ;
279 279
280 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 280 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
281 (int)(m_scene.RegionInfo.RegionLocX - 8) * (int)Constants.RegionSize, 281 (int)(m_scene.RegionInfo.LegacyRegionLocX - 8) * (int)Constants.RegionSize,
282 (int)(m_scene.RegionInfo.RegionLocX + 8) * (int)Constants.RegionSize, 282 (int)(m_scene.RegionInfo.LegacyRegionLocX + 8) * (int)Constants.RegionSize,
283 (int)(m_scene.RegionInfo.RegionLocY - 8) * (int)Constants.RegionSize, 283 (int)(m_scene.RegionInfo.LegacyRegionLocY - 8) * (int)Constants.RegionSize,
284 (int)(m_scene.RegionInfo.RegionLocY + 8) * (int)Constants.RegionSize); 284 (int)(m_scene.RegionInfo.LegacyRegionLocY + 8) * (int)Constants.RegionSize);
285 foreach (GridRegion r in regions) 285 foreach (GridRegion r in regions)
286 { 286 {
287 MapBlockData block = new MapBlockData(); 287 MapBlockData block = new MapBlockData();
@@ -1218,10 +1218,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1218 1218
1219 List<MapBlockData> mapBlocks = new List<MapBlockData>(); 1219 List<MapBlockData> mapBlocks = new List<MapBlockData>();
1220 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1220 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1221 (int)(m_scene.RegionInfo.RegionLocX - 9) * (int)Constants.RegionSize, 1221 (int)(m_scene.RegionInfo.LegacyRegionLocX - 9) * (int)Constants.RegionSize,
1222 (int)(m_scene.RegionInfo.RegionLocX + 9) * (int)Constants.RegionSize, 1222 (int)(m_scene.RegionInfo.LegacyRegionLocX + 9) * (int)Constants.RegionSize,
1223 (int)(m_scene.RegionInfo.RegionLocY - 9) * (int)Constants.RegionSize, 1223 (int)(m_scene.RegionInfo.LegacyRegionLocY - 9) * (int)Constants.RegionSize,
1224 (int)(m_scene.RegionInfo.RegionLocY + 9) * (int)Constants.RegionSize); 1224 (int)(m_scene.RegionInfo.LegacyRegionLocY + 9) * (int)Constants.RegionSize);
1225 List<AssetBase> textures = new List<AssetBase>(); 1225 List<AssetBase> textures = new List<AssetBase>();
1226 List<Image> bitImages = new List<Image>(); 1226 List<Image> bitImages = new List<Image>();
1227 1227
@@ -1262,8 +1262,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1262 1262
1263 for (int i = 0; i < mapBlocks.Count; i++) 1263 for (int i = 0; i < mapBlocks.Count; i++)
1264 { 1264 {
1265 ushort x = (ushort)((mapBlocks[i].X - m_scene.RegionInfo.RegionLocX) + 10); 1265 ushort x = (ushort)((mapBlocks[i].X - m_scene.RegionInfo.LegacyRegionLocX) + 10);
1266 ushort y = (ushort)((mapBlocks[i].Y - m_scene.RegionInfo.RegionLocY) + 10); 1266 ushort y = (ushort)((mapBlocks[i].Y - m_scene.RegionInfo.LegacyRegionLocY) + 10);
1267 g.DrawImage(bitImages[i], (x * 128), 2560 - (y * 128), 128, 128); // y origin is top 1267 g.DrawImage(bitImages[i], (x * 128), 2560 - (y * 128), 128, 128); // y origin is top
1268 } 1268 }
1269 1269
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
index 3787ca0..5ba5b31 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
@@ -135,4 +135,5 @@ namespace OpenSim.Region.Framework.Interfaces
135 135
136 void Shutdown(); 136 void Shutdown();
137 } 137 }
138
138} 139}
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
index e467701..cc8a236 100644
--- a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
+++ b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
@@ -25,13 +25,20 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using OpenSim.Framework;
29
28namespace OpenSim.Region.Framework.Interfaces 30namespace OpenSim.Region.Framework.Interfaces
29{ 31{
30 public interface ITerrainChannel 32 public interface ITerrainChannel
31 { 33 {
32 int Height { get; } 34 int Width { get;} // X dimension
35 int Height { get;} // Y dimension
36 int Altitude { get;} // Z dimension
37
33 double this[int x, int y] { get; set; } 38 double this[int x, int y] { get; set; }
34 int Width { get; } 39
40 // Return the packaged terrain data for passing into lower levels of communication
41 TerrainData GetTerrainData();
35 42
36 /// <summary> 43 /// <summary>
37 /// Squash the entire heightmap into a single dimensioned array 44 /// Squash the entire heightmap into a single dimensioned array
@@ -40,7 +47,10 @@ namespace OpenSim.Region.Framework.Interfaces
40 float[] GetFloatsSerialised(); 47 float[] GetFloatsSerialised();
41 48
42 double[,] GetDoubles(); 49 double[,] GetDoubles();
50
51 // Check if a location has been updated. Clears the taint flag as a side effect.
43 bool Tainted(int x, int y); 52 bool Tainted(int x, int y);
53
44 ITerrainChannel MakeCopy(); 54 ITerrainChannel MakeCopy();
45 string SaveToXmlString(); 55 string SaveToXmlString();
46 void LoadFromXmlString(string data); 56 void LoadFromXmlString(string data);
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 7772f94..e2880e3 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1107,8 +1107,8 @@ namespace OpenSim.Region.Framework.Scenes
1107 if (RegionInfo.RegionHandle != otherRegion.RegionHandle) 1107 if (RegionInfo.RegionHandle != otherRegion.RegionHandle)
1108 { 1108 {
1109 // If these are cast to INT because long + negative values + abs returns invalid data 1109 // If these are cast to INT because long + negative values + abs returns invalid data
1110 int resultX = Math.Abs((int)xcell - (int)RegionInfo.RegionLocX); 1110 int resultX = Math.Abs((int)xcell - (int)RegionInfo.LegacyRegionLocX);
1111 int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY); 1111 int resultY = Math.Abs((int)ycell - (int)RegionInfo.LegacyRegionLocY);
1112 if (resultX <= 1 && resultY <= 1) 1112 if (resultX <= 1 && resultY <= 1)
1113 { 1113 {
1114 // Let the grid service module know, so this can be cached 1114 // Let the grid service module know, so this can be cached
@@ -1183,8 +1183,8 @@ namespace OpenSim.Region.Framework.Scenes
1183 /// </returns> 1183 /// </returns>
1184 public int HaveNeighbor(Cardinals car, ref int[] fix) 1184 public int HaveNeighbor(Cardinals car, ref int[] fix)
1185 { 1185 {
1186 uint neighbourx = RegionInfo.RegionLocX; 1186 uint neighbourx = RegionInfo.LegacyRegionLocX;
1187 uint neighboury = RegionInfo.RegionLocY; 1187 uint neighboury = RegionInfo.LegacyRegionLocY;
1188 1188
1189 int dir = (int)car; 1189 int dir = (int)car;
1190 1190
@@ -1204,8 +1204,8 @@ namespace OpenSim.Region.Framework.Scenes
1204 1204
1205 if (neighbourRegion == null) 1205 if (neighbourRegion == null)
1206 { 1206 {
1207 fix[0] = (int)(RegionInfo.RegionLocX - neighbourx); 1207 fix[0] = (int)(RegionInfo.LegacyRegionLocX - neighbourx);
1208 fix[1] = (int)(RegionInfo.RegionLocY - neighboury); 1208 fix[1] = (int)(RegionInfo.LegacyRegionLocY - neighboury);
1209 return dir * (-1); 1209 return dir * (-1);
1210 } 1210 }
1211 else 1211 else
@@ -1905,13 +1905,13 @@ namespace OpenSim.Region.Framework.Scenes
1905 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain); 1905 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain);
1906 1906
1907 m_log.InfoFormat("[TERRAIN]: No default terrain. Generating a new terrain {0}.", m_InitialTerrain); 1907 m_log.InfoFormat("[TERRAIN]: No default terrain. Generating a new terrain {0}.", m_InitialTerrain);
1908 Heightmap = new TerrainChannel(m_InitialTerrain); 1908 Heightmap = new TerrainChannel(m_InitialTerrain, (int)RegionInfo.RegionSizeX, (int)RegionInfo.RegionSizeY, (int)RegionInfo.RegionSizeZ);
1909 1909
1910 SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1910 SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1911 } 1911 }
1912 else 1912 else
1913 { 1913 {
1914 Heightmap = new TerrainChannel(map); 1914 Heightmap = new TerrainChannel(map, RegionInfo.RegionSizeZ);
1915 } 1915 }
1916 } 1916 }
1917 catch (IOException e) 1917 catch (IOException e)
@@ -4371,8 +4371,8 @@ namespace OpenSim.Region.Framework.Scenes
4371 { 4371 {
4372 uint rRegionX = (uint)(cAgentData.RegionHandle >> 40); 4372 uint rRegionX = (uint)(cAgentData.RegionHandle >> 40);
4373 uint rRegionY = (((uint)(cAgentData.RegionHandle)) >> 8); 4373 uint rRegionY = (((uint)(cAgentData.RegionHandle)) >> 8);
4374 uint tRegionX = RegionInfo.RegionLocX; 4374 uint tRegionX = RegionInfo.LegacyRegionLocX;
4375 uint tRegionY = RegionInfo.RegionLocY; 4375 uint tRegionY = RegionInfo.LegacyRegionLocY;
4376 //Send Data to ScenePresence 4376 //Send Data to ScenePresence
4377 childAgentUpdate.UpdateChildAgent(cAgentData, tRegionX, tRegionY, rRegionX, rRegionY); 4377 childAgentUpdate.UpdateChildAgent(cAgentData, tRegionX, tRegionY, rRegionX, rRegionY);
4378 // Not Implemented: 4378 // Not Implemented:
@@ -4600,13 +4600,13 @@ namespace OpenSim.Region.Framework.Scenes
4600 ScenePresence sp = GetScenePresence(remoteClient.AgentId); 4600 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
4601 if (sp != null) 4601 if (sp != null)
4602 { 4602 {
4603 uint regionX = RegionInfo.RegionLocX; 4603 uint regionX = RegionInfo.LegacyRegionLocX;
4604 uint regionY = RegionInfo.RegionLocY; 4604 uint regionY = RegionInfo.LegacyRegionLocY;
4605 4605
4606 Utils.LongToUInts(regionHandle, out regionX, out regionY); 4606 Utils.LongToUInts(regionHandle, out regionX, out regionY);
4607 4607
4608 int shiftx = (int) regionX - (int) RegionInfo.RegionLocX * (int)Constants.RegionSize; 4608 int shiftx = (int) regionX - (int) RegionInfo.LegacyRegionLocX * (int)Constants.RegionSize;
4609 int shifty = (int) regionY - (int) RegionInfo.RegionLocY * (int)Constants.RegionSize; 4609 int shifty = (int) regionY - (int) RegionInfo.LegacyRegionLocY * (int)Constants.RegionSize;
4610 4610
4611 position.X += shiftx; 4611 position.X += shiftx;
4612 position.Y += shifty; 4612 position.Y += shifty;
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index 28f7896..2677989 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -445,8 +445,8 @@ namespace OpenSim.Region.Framework.Scenes
445 { 445 {
446 foreach (Scene mscene in m_localScenes) 446 foreach (Scene mscene in m_localScenes)
447 { 447 {
448 if (mscene.RegionInfo.RegionLocX == locX && 448 if (mscene.RegionInfo.LegacyRegionLocX == locX &&
449 mscene.RegionInfo.RegionLocY == locY) 449 mscene.RegionInfo.LegacyRegionLocY == locY)
450 { 450 {
451 scene = mscene; 451 scene = mscene;
452 return true; 452 return true;
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 7243db1..297ee5f 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -710,7 +710,7 @@ namespace OpenSim.Region.Framework.Scenes
710 Utils.LongToUInts(handle, out x, out y); 710 Utils.LongToUInts(handle, out x, out y);
711 x = x / Constants.RegionSize; 711 x = x / Constants.RegionSize;
712 y = y / Constants.RegionSize; 712 y = y / Constants.RegionSize;
713 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) 713 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.LegacyRegionLocX, y, Scene.RegionInfo.LegacyRegionLocY))
714 { 714 {
715 old.Add(handle); 715 old.Add(handle);
716 } 716 }
@@ -2094,8 +2094,8 @@ namespace OpenSim.Region.Framework.Scenes
2094// } 2094// }
2095 2095
2096 // Get terrain height for sub-region in a megaregion if necessary 2096 // Get terrain height for sub-region in a megaregion if necessary
2097 int X = (int)((m_scene.RegionInfo.RegionLocX * Constants.RegionSize) + pos.X); 2097 int X = (int)((m_scene.RegionInfo.RegionWorldLocX) + pos.X);
2098 int Y = (int)((m_scene.RegionInfo.RegionLocY * Constants.RegionSize) + pos.Y); 2098 int Y = (int)((m_scene.RegionInfo.RegionWorldLocY) + pos.Y);
2099 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y); 2099 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y);
2100 // If X and Y is NaN, target_region will be null 2100 // If X and Y is NaN, target_region will be null
2101 if (target_region == null) 2101 if (target_region == null)
diff --git a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
index 95f9caf..67998a0 100644
--- a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
+++ b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
@@ -437,7 +437,7 @@ namespace OpenSim.Region.Framework.Scenes
437 437
438 SimStats simStats 438 SimStats simStats
439 = new SimStats( 439 = new SimStats(
440 ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, 440 ReportingRegion.LegacyRegionLocX, ReportingRegion.LegacyRegionLocY, regionFlags, (uint)m_objectCapacity,
441 rb, sb, m_scene.RegionInfo.originRegionID); 441 rb, sb, m_scene.RegionInfo.originRegionID);
442 442
443 handlerSendStatResult = OnSendStatsResult; 443 handlerSendStatResult = OnSendStatsResult;
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index c0ca48e..6d245cb 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
@@ -25,14 +25,19 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using OpenSim.Framework;
29using OpenSim.Region.Framework.Interfaces;
30using System; 28using System;
29using System.IO;
31using System.Text; 30using System.Text;
31using System.Reflection;
32using System.Xml; 32using System.Xml;
33using System.IO;
34using System.Xml.Serialization; 33using System.Xml.Serialization;
35 34
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38
39using log4net;
40
36namespace OpenSim.Region.Framework.Scenes 41namespace OpenSim.Region.Framework.Scenes
37{ 42{
38 /// <summary> 43 /// <summary>
@@ -40,132 +45,115 @@ namespace OpenSim.Region.Framework.Scenes
40 /// </summary> 45 /// </summary>
41 public class TerrainChannel : ITerrainChannel 46 public class TerrainChannel : ITerrainChannel
42 { 47 {
43 private readonly bool[,] taint; 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private double[,] map; 49 private static string LogHeader = "[TERRAIN CHANNEL]";
50
51 protected TerrainData m_terrainData;
45 52
53 public int Width { get { return m_terrainData.SizeX; } } // X dimension
54 // Unfortunately, for historical reasons, in this module 'Width' is X and 'Height' is Y
55 public int Height { get { return m_terrainData.SizeY; } } // Y dimension
56 public int Altitude { get { return m_terrainData.SizeZ; } } // Y dimension
57
58 // Default, not-often-used builder
46 public TerrainChannel() 59 public TerrainChannel()
47 { 60 {
48 map = new double[Constants.RegionSize, Constants.RegionSize]; 61 m_terrainData = new HeightmapTerrainData((int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
49 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; 62 FlatLand();
50 63 // PinHeadIsland();
51 PinHeadIsland();
52 } 64 }
53 65
54 public TerrainChannel(String type) 66 // Create terrain of given size
67 public TerrainChannel(int pX, int pY)
55 { 68 {
56 map = new double[Constants.RegionSize, Constants.RegionSize]; 69 m_terrainData = new HeightmapTerrainData(pX, pY, (int)Constants.RegionHeight);
57 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16]; 70 }
58 71
72 // Create terrain of specified size and initialize with specified terrain.
73 // TODO: join this with the terrain initializers.
74 public TerrainChannel(String type, int pX, int pY, int pZ)
75 {
76 m_terrainData = new HeightmapTerrainData(pX, pY, pZ);
59 if (type.Equals("flat")) 77 if (type.Equals("flat"))
60 FlatLand(); 78 FlatLand();
61 else 79 else
62 PinHeadIsland(); 80 PinHeadIsland();
63 } 81 }
64 82
65 public TerrainChannel(double[,] import) 83 public TerrainChannel(double[,] pM, uint pAltitude)
66 {
67 map = import;
68 taint = new bool[import.GetLength(0),import.GetLength(1)];
69 }
70
71 public TerrainChannel(bool createMap)
72 {
73 if (createMap)
74 {
75 map = new double[Constants.RegionSize,Constants.RegionSize];
76 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16];
77 }
78 }
79
80 public TerrainChannel(int w, int h)
81 { 84 {
82 map = new double[w,h]; 85 m_terrainData = new HeightmapTerrainData(pM);
83 taint = new bool[w / 16,h / 16];
84 } 86 }
85 87
86 #region ITerrainChannel Members 88 #region ITerrainChannel Members
87 89
88 public int Width 90 // ITerrainChannel.MakeCopy()
91 public ITerrainChannel MakeCopy()
89 { 92 {
90 get { return map.GetLength(0); } 93 return this.Copy();
91 } 94 }
92 95
93 public int Height 96 // ITerrainChannel.GetTerrainData()
97 public TerrainData GetTerrainData()
94 { 98 {
95 get { return map.GetLength(1); } 99 return m_terrainData;
96 } 100 }
97 101
98 public ITerrainChannel MakeCopy() 102 // ITerrainChannel.GetFloatsSerialized()
103 // NOTICE that the one dimensional form is ordered by Y!!
104 public float[] GetFloatsSerialised()
99 { 105 {
100 TerrainChannel copy = new TerrainChannel(false); 106 int points = Width * Height;
101 copy.map = (double[,]) map.Clone(); 107 float[] heights = new float[points];
102 108
103 return copy; 109 int idx = 0;
110 for (int ii = 0; ii < Height; ii++)
111 for (int jj = 0; jj < Width; jj++)
112 heights[idx++] = m_terrainData[jj, ii];
113
114 return heights;
104 } 115 }
105 116
106 public float[] GetFloatsSerialised() 117 // ITerrainChannel.GetDoubles()
118 public double[,] GetDoubles()
107 { 119 {
108 // Move the member variables into local variables, calling
109 // member variables 256*256 times gets expensive
110 int w = Width; 120 int w = Width;
111 int h = Height; 121 int l = Height;
112 float[] heights = new float[w * h]; 122 double[,] heights = new double[w, l];
113 123
114 int i, j; // map coordinates
115 int idx = 0; // index into serialized array 124 int idx = 0; // index into serialized array
116 for (i = 0; i < h; i++) 125 for (int ii = 0; ii < w; ii++)
117 { 126 {
118 for (j = 0; j < w; j++) 127 for (int jj = 0; jj < l; jj++)
119 { 128 {
120 heights[idx++] = (float)map[j, i]; 129 heights[ii, jj] = (double)m_terrainData[ii, jj];
130 idx++;
121 } 131 }
122 } 132 }
123 133
124 return heights; 134 return heights;
125 } 135 }
126 136
127 public double[,] GetDoubles() 137 // ITerrainChannel.this[x,y]
128 {
129 return map;
130 }
131
132 public double this[int x, int y] 138 public double this[int x, int y]
133 { 139 {
134 get { return map[x, y]; } 140 get { return (double)m_terrainData[x, y]; }
135 set 141 set
136 { 142 {
137 // Will "fix" terrain hole problems. Although not fantastically.
138 if (Double.IsNaN(value) || Double.IsInfinity(value)) 143 if (Double.IsNaN(value) || Double.IsInfinity(value))
139 return; 144 return;
140 145
141 if (map[x, y] != value) 146 m_terrainData[x, y] = (float)value;
142 {
143 taint[x / 16, y / 16] = true;
144 map[x, y] = value;
145 }
146 } 147 }
147 } 148 }
148 149
150 // ITerrainChannel.Tainted()
149 public bool Tainted(int x, int y) 151 public bool Tainted(int x, int y)
150 { 152 {
151 if (taint[x / 16, y / 16]) 153 return m_terrainData.IsTaintedAt(x, y);
152 {
153 taint[x / 16, y / 16] = false;
154 return true;
155 }
156 return false;
157 }
158
159 #endregion
160
161 public TerrainChannel Copy()
162 {
163 TerrainChannel copy = new TerrainChannel(false);
164 copy.map = (double[,]) map.Clone();
165
166 return copy;
167 } 154 }
168 155
156 // ITerrainChannel.SaveToXmlString()
169 public string SaveToXmlString() 157 public string SaveToXmlString()
170 { 158 {
171 XmlWriterSettings settings = new XmlWriterSettings(); 159 XmlWriterSettings settings = new XmlWriterSettings();
@@ -181,13 +169,7 @@ namespace OpenSim.Region.Framework.Scenes
181 } 169 }
182 } 170 }
183 171
184 private void WriteXml(XmlWriter writer) 172 // ITerrainChannel.LoadFromXmlString()
185 {
186 writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
187 ToXml(writer);
188 writer.WriteEndElement();
189 }
190
191 public void LoadFromXmlString(string data) 173 public void LoadFromXmlString(string data)
192 { 174 {
193 StringReader sr = new StringReader(data); 175 StringReader sr = new StringReader(data);
@@ -199,12 +181,50 @@ namespace OpenSim.Region.Framework.Scenes
199 sr.Close(); 181 sr.Close();
200 } 182 }
201 183
184 #endregion
185
186 public TerrainChannel Copy()
187 {
188 TerrainChannel copy = new TerrainChannel();
189 copy.m_terrainData = m_terrainData.Clone();
190 return copy;
191 }
192
193 private void WriteXml(XmlWriter writer)
194 {
195 if (Width == Constants.RegionSize && Height == Constants.RegionSize)
196 {
197 // Downward compatibility for legacy region terrain maps.
198 // If region is exactly legacy size, return the old format XML.
199 writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
200 ToXml(writer);
201 writer.WriteEndElement();
202 }
203 else
204 {
205 // New format XML that includes width and length.
206 writer.WriteStartElement(String.Empty, "TerrainMap2", String.Empty);
207 ToXml2(writer);
208 writer.WriteEndElement();
209 }
210 }
211
202 private void ReadXml(XmlReader reader) 212 private void ReadXml(XmlReader reader)
203 { 213 {
204 reader.ReadStartElement("TerrainMap"); 214 // Check the first element. If legacy element, use the legacy reader.
205 FromXml(reader); 215 if (reader.IsStartElement("TerrainMap"))
216 {
217 reader.ReadStartElement("TerrainMap");
218 FromXml(reader);
219 }
220 else
221 {
222 reader.ReadStartElement("TerrainMap2");
223 FromXml2(reader);
224 }
206 } 225 }
207 226
227 // Write legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
208 private void ToXml(XmlWriter xmlWriter) 228 private void ToXml(XmlWriter xmlWriter)
209 { 229 {
210 float[] mapData = GetFloatsSerialised(); 230 float[] mapData = GetFloatsSerialised();
@@ -218,12 +238,15 @@ namespace OpenSim.Region.Framework.Scenes
218 serializer.Serialize(xmlWriter, buffer); 238 serializer.Serialize(xmlWriter, buffer);
219 } 239 }
220 240
241 // Read legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
221 private void FromXml(XmlReader xmlReader) 242 private void FromXml(XmlReader xmlReader)
222 { 243 {
223 XmlSerializer serializer = new XmlSerializer(typeof(byte[])); 244 XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
224 byte[] dataArray = (byte[])serializer.Deserialize(xmlReader); 245 byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
225 int index = 0; 246 int index = 0;
226 247
248 m_terrainData = new HeightmapTerrainData(Width, Height, Altitude);
249
227 for (int y = 0; y < Height; y++) 250 for (int y = 0; y < Height; y++)
228 { 251 {
229 for (int x = 0; x < Width; x++) 252 for (int x = 0; x < Width; x++)
@@ -236,35 +259,65 @@ namespace OpenSim.Region.Framework.Scenes
236 } 259 }
237 } 260 }
238 261
262 private class TerrainChannelXMLPackage
263 {
264 public int Version;
265 public int SizeX;
266 public int SizeY;
267 public int SizeZ;
268 public float CompressionFactor;
269 public short[] Map;
270 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, short[] pMap)
271 {
272 Version = 1;
273 SizeX = pX;
274 SizeY = pY;
275 SizeZ = pZ;
276 CompressionFactor = pCompressionFactor;
277 Map = pMap;
278 }
279 }
280
281 // New terrain serialization format that includes the width and length.
282 private void ToXml2(XmlWriter xmlWriter)
283 {
284 TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.CompressionFactor,
285 m_terrainData.GetCompressedMap());
286 XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
287 serializer.Serialize(xmlWriter, package);
288 }
289
290 // New terrain serialization format that includes the width and length.
291 private void FromXml2(XmlReader xmlReader)
292 {
293 XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
294 TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader);
295 m_terrainData = new HeightmapTerrainData(package.Map, package.CompressionFactor, package.SizeX, package.SizeY, package.SizeZ);
296 }
297
298 // Fill the heightmap with the center bump terrain
239 private void PinHeadIsland() 299 private void PinHeadIsland()
240 { 300 {
241 int x; 301 for (int x = 0; x < Width; x++)
242 for (x = 0; x < Constants.RegionSize; x++)
243 { 302 {
244 int y; 303 for (int y = 0; y < Height; y++)
245 for (y = 0; y < Constants.RegionSize; y++)
246 { 304 {
247 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10; 305 m_terrainData[x, y] = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10;
248 double spherFacA = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2.0, Constants.RegionSize / 2.0, 50) * 0.01; 306 float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 50) * 0.01d);
249 double spherFacB = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2.0, Constants.RegionSize / 2.0, 100) * 0.001; 307 float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 100) * 0.001d);
250 if (map[x, y] < spherFacA) 308 if (m_terrainData[x, y]< spherFacA)
251 map[x, y] = spherFacA; 309 m_terrainData[x, y]= spherFacA;
252 if (map[x, y] < spherFacB) 310 if (m_terrainData[x, y]< spherFacB)
253 map[x, y] = spherFacB; 311 m_terrainData[x, y] = spherFacB;
254 } 312 }
255 } 313 }
256 } 314 }
257 315
258 private void FlatLand() 316 private void FlatLand()
259 { 317 {
260 int x; 318 for (int xx = 0; xx < Width; xx++)
261 for (x = 0; x < Constants.RegionSize; x++) 319 for (int yy = 0; yy < Height; yy++)
262 { 320 m_terrainData[xx, yy] = 21;
263 int y;
264 for (y = 0; y < Constants.RegionSize; y++)
265 map[x, y] = 21;
266 }
267 } 321 }
268
269 } 322 }
270} 323}
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
new file mode 100644
index 0000000..e91c959
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -0,0 +1,949 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Freely adapted from the Aurora version of the terrain compressor.
29 * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
30 */
31
32using System;
33using System.Reflection;
34
35using log4net;
36
37using OpenSim.Framework;
38using OpenSim.Region.Framework;
39using OpenSim.Region.Framework.Scenes;
40
41using OpenMetaverse;
42using OpenMetaverse.Packets;
43
44namespace OpenSim.Region.ClientStack.LindenUDP
45{
46 public static class OpenSimTerrainCompressor
47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 private static string LogHeader = "[TERRAIN COMPRESSOR]";
50
51 public const int END_OF_PATCHES = 97;
52
53 private const float OO_SQRT2 = 0.7071067811865475244008443621049f;
54 private const int STRIDE = 264;
55
56 private const int ZERO_CODE = 0x0;
57 private const int ZERO_EOB = 0x2;
58 private const int POSITIVE_VALUE = 0x6;
59 private const int NEGATIVE_VALUE = 0x7;
60
61 private static readonly float[] DequantizeTable16 =
62 new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
63
64 private static readonly float[] DequantizeTable32 =
65 new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
66
67 private static readonly float[] CosineTable16 = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
68 //private static readonly float[] CosineTable32 = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
69 private static readonly int[] CopyMatrix16 = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
70 private static readonly int[] CopyMatrix32 = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
71
72 private static readonly float[] QuantizeTable16 =
73 new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
74
75 static OpenSimTerrainCompressor()
76 {
77 // Initialize the decompression tables
78 BuildDequantizeTable16();
79 SetupCosines16();
80 BuildCopyMatrix16();
81 BuildQuantizeTable16();
82 }
83
84 // Unused: left for historical reference.
85 public static LayerDataPacket CreateLayerDataPacket(TerrainPatch[] patches, byte type, int pRegionSizeX,
86 int pRegionSizeY)
87 {
88 LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}};
89
90 TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
91 {Stride = STRIDE, PatchSize = Constants.TerrainPatchSize};
92
93 // Should be enough to fit even the most poorly packed data
94 byte[] data = new byte[patches.Length*Constants.TerrainPatchSize*Constants.TerrainPatchSize*2];
95 BitPack bitpack = new BitPack(data, 0);
96 bitpack.PackBits(header.Stride, 16);
97 bitpack.PackBits(header.PatchSize, 8);
98 bitpack.PackBits(type, 8);
99
100 foreach (TerrainPatch t in patches)
101 CreatePatch(bitpack, t.Data, t.X, t.Y, pRegionSizeX, pRegionSizeY);
102
103 bitpack.PackBits(END_OF_PATCHES, 8);
104
105 layer.LayerData.Data = new byte[bitpack.BytePos + 1];
106 Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);
107
108 return layer;
109 }
110
111 // Legacy land packet generation gluing old land representation (heights) to compressed representation.
112 // This is an intermediate step in converting terrain into a variable sized heightmap. Some of the
113 // routines (like IClientAPI) only pass the float array of heights around. This entry
114 // converts that legacy representation into the more compact represenation used in
115 // TerrainData. Someday fix the plumbing between here and the scene.
116 public static LayerDataPacket CreateLandPacket(TerrainData terrData, int patchX, int patchY)
117 {
118 int[] xPieces = new int[1];
119 int[] yPieces = new int[1];
120 xPieces[0] = patchX; // patch X dimension
121 yPieces[0] = patchY;
122
123 m_log.DebugFormat("{0} CreateLandPacket. patchX={1}, patchY={2}, sizeX={3}, sizeY={4}",
124 LogHeader, patchX, patchY, terrData.SizeX, terrData.SizeY);
125
126 return CreateLandPacket(terrData, xPieces, yPieces, (int)TerrainPatch.LayerType.Land);
127 }
128
129 /// <summary>
130 /// Creates a LayerData packet for compressed land data given a full
131 /// simulator heightmap and an array of indices of patches to compress
132 /// </summary>
133 /// <param name="heightmap">
134 /// A 256 * 256 array of floating point values
135 /// specifying the height at each meter in the simulator
136 /// </param>
137 /// <param name="x">
138 /// Array of indexes in the 16x16 grid of patches
139 /// for this simulator. For example if 1 and 17 are specified, patches
140 /// x=1,y=0 and x=1,y=1 are sent
141 /// </param>
142 /// <param name="y">
143 /// Array of indexes in the 16x16 grid of patches
144 /// for this simulator. For example if 1 and 17 are specified, patches
145 /// x=1,y=0 and x=1,y=1 are sent
146 /// </param>
147 /// <param name="type"></param>
148 /// <param name="pRegionSizeX"></param>
149 /// <param name="pRegionSizeY"></param>
150 /// <returns></returns>
151 public static LayerDataPacket CreateLandPacket(TerrainData terrData, int[] x, int[] y, byte type)
152 {
153 LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}};
154
155 TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
156 {Stride = STRIDE, PatchSize = Constants.TerrainPatchSize};
157
158 byte[] data = new byte[x.Length * Constants.TerrainPatchSize * Constants.TerrainPatchSize * 2];
159 BitPack bitpack = new BitPack(data, 0);
160 bitpack.PackBits(header.Stride, 16);
161 bitpack.PackBits(header.PatchSize, 8);
162 bitpack.PackBits(type, 8);
163
164 for (int i = 0; i < x.Length; i++)
165 CreatePatchFromHeightmap(bitpack, terrData, x[i], y[i]);
166
167 bitpack.PackBits(END_OF_PATCHES, 8);
168
169 layer.LayerData.Data = new byte[bitpack.BytePos + 1];
170 Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);
171
172 return layer;
173 }
174
175 // Unused: left for historical reference.
176 public static void CreatePatch(BitPack output, float[] patchData, int x, int y, int pRegionSizeX, int pRegionSizeY)
177 {
178 TerrainPatch.Header header = PrescanPatch(patchData);
179 header.QuantWBits = 136;
180 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize)
181 {
182 header.PatchIDs = (y & 0xFFFF);
183 header.PatchIDs += (x << 16);
184 }
185 else
186 {
187 header.PatchIDs = (y & 0x1F);
188 header.PatchIDs += (x << 5);
189 }
190
191 // NOTE: No idea what prequant and postquant should be or what they do
192
193 int wbits;
194 int[] patch = CompressPatch(patchData, header, 10, out wbits);
195 wbits = EncodePatchHeader(output, header, patch, Constants.RegionSize, Constants.RegionSize, wbits);
196 EncodePatch(output, patch, 0, wbits);
197 }
198
199 /// <summary>
200 /// Add a patch of terrain to a BitPacker
201 /// </summary>
202 /// <param name="output">BitPacker to write the patch to</param>
203 /// <param name="heightmap">
204 /// Heightmap of the simulator. Presumed to be an sizeX*sizeY array.
205 /// </param>
206 /// <param name="patchX">
207 /// X offset of the patch to create.
208 /// </param>
209 /// <param name="patchY">
210 /// Y offset of the patch to create.
211 /// </param>
212 /// <param name="pRegionSizeX"></param>
213 /// <param name="pRegionSizeY"></param>
214 public static void CreatePatchFromHeightmap(BitPack output, TerrainData terrData, int patchX, int patchY)
215 {
216 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY);
217 header.QuantWBits = 136;
218
219 // If larger than legacy region size, pack patch X and Y info differently.
220 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
221 {
222 header.PatchIDs = (patchY & 0xFFFF);
223 header.PatchIDs += (patchX << 16);
224 }
225 else
226 {
227 header.PatchIDs = (patchY & 0x1F);
228 header.PatchIDs += (patchX << 5);
229 }
230
231 // NOTE: No idea what prequant and postquant should be or what they do
232 int wbits;
233 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits);
234 wbits = EncodePatchHeader(output, header, patch, (uint)terrData.SizeX, (uint)terrData.SizeY, wbits);
235 EncodePatch(output, patch, 0, wbits);
236 }
237
238 private static TerrainPatch.Header PrescanPatch(float[] patch)
239 {
240 TerrainPatch.Header header = new TerrainPatch.Header();
241 float zmax = -99999999.0f;
242 float zmin = 99999999.0f;
243
244 for (int i = 0; i < Constants.TerrainPatchSize*Constants.TerrainPatchSize; i++)
245 {
246 float val = patch[i];
247 if (val > zmax) zmax = val;
248 if (val < zmin) zmin = val;
249 }
250
251 header.DCOffset = zmin;
252 header.Range = (int) ((zmax - zmin) + 1.0f);
253
254 return header;
255 }
256
257 // Scan the height info we're returning and return a patch packet header for this patch.
258 private static TerrainPatch.Header PrescanPatch(TerrainData terrData, int patchX, int patchY)
259 {
260 TerrainPatch.Header header = new TerrainPatch.Header();
261 float zmax = -99999999.0f;
262 float zmin = 99999999.0f;
263
264 for (int j = patchY*16; j < (patchY + 1)*16; j++)
265 {
266 for (int i = patchX*16; i < (patchX + 1)*16; i++)
267 {
268 // short val = heightmap[j*pRegionSizeX + i];
269 float val = terrData[j, i];
270 if (val > zmax) zmax = val;
271 if (val < zmin) zmin = val;
272 }
273 }
274
275 // Since the the min and max values are the shorts, rescale to be real values.
276 // TODO: all this logic should go into the class wrapping the short values.
277 header.DCOffset = zmin;
278 header.Range = (int)(zmax - zmin + 1.0f);
279
280 return header;
281 }
282
283 public static TerrainPatch.Header DecodePatchHeader(BitPack bitpack)
284 {
285 TerrainPatch.Header header = new TerrainPatch.Header {QuantWBits = bitpack.UnpackBits(8)};
286
287 // Quantized word bits
288 if (header.QuantWBits == END_OF_PATCHES)
289 return header;
290
291 // DC offset
292 header.DCOffset = bitpack.UnpackFloat();
293
294 // Range
295 header.Range = bitpack.UnpackBits(16);
296
297 // Patch IDs (10 bits)
298 header.PatchIDs = bitpack.UnpackBits(10);
299
300 // Word bits
301 header.WordBits = (uint) ((header.QuantWBits & 0x0f) + 2);
302
303 return header;
304 }
305
306 private static int EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, uint pRegionSizeX,
307 uint pRegionSizeY, int wbits)
308 {
309 /*
310 int temp;
311 int wbits = (header.QuantWBits & 0x0f) + 2;
312 uint maxWbits = (uint)wbits + 5;
313 uint minWbits = ((uint)wbits >> 1);
314 int wbitsMaxValue;
315 */
316 // goal is to determ minimum number of bits to use so all data fits
317 /*
318 wbits = (int)minWbits;
319 wbitsMaxValue = (1 << wbits);
320
321 for (int i = 0; i < patch.Length; i++)
322 {
323 temp = patch[i];
324 if (temp != 0)
325 {
326 // Get the absolute value
327 if (temp < 0) temp *= -1;
328
329 no coments..
330
331 for (int j = (int)maxWbits; j > (int)minWbits; j--)
332 {
333 if ((temp & (1 << j)) != 0)
334 {
335 if (j > wbits) wbits = j;
336 break;
337 }
338 }
339
340 while (temp > wbitsMaxValue)
341 {
342 wbits++;
343 if (wbits == maxWbits)
344 goto Done;
345 wbitsMaxValue = 1 << wbits;
346 }
347 }
348 }
349
350 Done:
351
352 // wbits += 1;
353 */
354 // better check
355 if (wbits > 17)
356 wbits = 16;
357 else if (wbits < 3)
358 wbits = 3;
359
360 header.QuantWBits &= 0xf0;
361
362 header.QuantWBits |= (wbits - 2);
363
364 output.PackBits(header.QuantWBits, 8);
365 output.PackFloat(header.DCOffset);
366 output.PackBits(header.Range, 16);
367 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize)
368 output.PackBits(header.PatchIDs, 32);
369 else
370 output.PackBits(header.PatchIDs, 10);
371
372 return wbits;
373 }
374
375 private static void IDCTColumn16(float[] linein, float[] lineout, int column)
376 {
377 for (int n = 0; n < Constants.TerrainPatchSize; n++)
378 {
379 float total = OO_SQRT2*linein[column];
380
381 for (int u = 1; u < Constants.TerrainPatchSize; u++)
382 {
383 int usize = u*Constants.TerrainPatchSize;
384 total += linein[usize + column]*CosineTable16[usize + n];
385 }
386
387 lineout[Constants.TerrainPatchSize*n + column] = total;
388 }
389 }
390
391 private static void IDCTLine16(float[] linein, float[] lineout, int line)
392 {
393 const float oosob = 2.0f/Constants.TerrainPatchSize;
394 int lineSize = line*Constants.TerrainPatchSize;
395
396 for (int n = 0; n < Constants.TerrainPatchSize; n++)
397 {
398 float total = OO_SQRT2*linein[lineSize];
399
400 for (int u = 1; u < Constants.TerrainPatchSize; u++)
401 {
402 total += linein[lineSize + u]*CosineTable16[u*Constants.TerrainPatchSize + n];
403 }
404
405 lineout[lineSize + n] = total*oosob;
406 }
407 }
408
409/*
410 private static void DCTLine16(float[] linein, float[] lineout, int line)
411 {
412 float total = 0.0f;
413 int lineSize = line * Constants.TerrainPatchSize;
414
415 for (int n = 0; n < Constants.TerrainPatchSize; n++)
416 {
417 total += linein[lineSize + n];
418 }
419
420 lineout[lineSize] = OO_SQRT2 * total;
421
422 int uptr = 0;
423 for (int u = 1; u < Constants.TerrainPatchSize; u++)
424 {
425 total = 0.0f;
426 uptr += Constants.TerrainPatchSize;
427
428 for (int n = 0; n < Constants.TerrainPatchSize; n++)
429 {
430 total += linein[lineSize + n] * CosineTable16[uptr + n];
431 }
432
433 lineout[lineSize + u] = total;
434 }
435 }
436*/
437
438 private static void DCTLine16(float[] linein, float[] lineout, int line)
439 {
440 // outputs transpose data (lines exchanged with coluns )
441 // so to save a bit of cpu when doing coluns
442 float total = 0.0f;
443 int lineSize = line*Constants.TerrainPatchSize;
444
445 for (int n = 0; n < Constants.TerrainPatchSize; n++)
446 {
447 total += linein[lineSize + n];
448 }
449
450 lineout[line] = OO_SQRT2*total;
451
452 for (int u = Constants.TerrainPatchSize;
453 u < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
454 u += Constants.TerrainPatchSize)
455 {
456 total = 0.0f;
457 for (int ptrn = lineSize, ptru = u; ptrn < lineSize + Constants.TerrainPatchSize; ptrn++,ptru++)
458 {
459 total += linein[ptrn]*CosineTable16[ptru];
460 }
461
462 lineout[line + u] = total;
463 }
464 }
465
466
467 /*
468 private static void DCTColumn16(float[] linein, int[] lineout, int column)
469 {
470 float total = 0.0f;
471 // const float oosob = 2.0f / Constants.TerrainPatchSize;
472
473 for (int n = 0; n < Constants.TerrainPatchSize; n++)
474 {
475 total += linein[Constants.TerrainPatchSize * n + column];
476 }
477
478 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
479 lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * QuantizeTable16[column]);
480
481 for (int uptr = Constants.TerrainPatchSize; uptr < Constants.TerrainPatchSize * Constants.TerrainPatchSize; uptr += Constants.TerrainPatchSize)
482 {
483 total = 0.0f;
484
485 for (int n = 0; n < Constants.TerrainPatchSize; n++)
486 {
487 total += linein[Constants.TerrainPatchSize * n + column] * CosineTable16[uptr + n];
488 }
489
490 // lineout[CopyMatrix16[Constants.TerrainPatchSize * u + column]] = (int)(total * oosob * QuantizeTable16[Constants.TerrainPatchSize * u + column]);
491 lineout[CopyMatrix16[uptr + column]] = (int)(total * QuantizeTable16[uptr + column]);
492 }
493 }
494 */
495
496 private static void DCTColumn16(float[] linein, int[] lineout, int column)
497 {
498 // input columns are in fact stored in lines now
499
500 float total = 0.0f;
501// const float oosob = 2.0f / Constants.TerrainPatchSize;
502 int inlinesptr = Constants.TerrainPatchSize*column;
503
504 for (int n = 0; n < Constants.TerrainPatchSize; n++)
505 {
506 total += linein[inlinesptr + n];
507 }
508
509 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
510 lineout[CopyMatrix16[column]] = (int) (OO_SQRT2*total*QuantizeTable16[column]);
511
512 for (int uptr = Constants.TerrainPatchSize;
513 uptr < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
514 uptr += Constants.TerrainPatchSize)
515 {
516 total = 0.0f;
517
518 for (int n = inlinesptr, ptru = uptr; n < inlinesptr + Constants.TerrainPatchSize; n++, ptru++)
519 {
520 total += linein[n]*CosineTable16[ptru];
521 }
522
523// lineout[CopyMatrix16[Constants.TerrainPatchSize * u + column]] = (int)(total * oosob * QuantizeTable16[Constants.TerrainPatchSize * u + column]);
524 lineout[CopyMatrix16[uptr + column]] = (int) (total*QuantizeTable16[uptr + column]);
525 }
526 }
527
528 private static int DCTColumn16Wbits(float[] linein, int[] lineout, int column, int wbits, int maxwbits)
529 {
530 // input columns are in fact stored in lines now
531
532 bool dowbits = wbits != maxwbits;
533 int wbitsMaxValue = 1 << wbits;
534
535 float total = 0.0f;
536 // const float oosob = 2.0f / Constants.TerrainPatchSize;
537 int inlinesptr = Constants.TerrainPatchSize*column;
538
539 for (int n = 0; n < Constants.TerrainPatchSize; n++)
540 {
541 total += linein[inlinesptr + n];
542 }
543
544 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
545 int tmp = (int) (OO_SQRT2*total*QuantizeTable16[column]);
546 lineout[CopyMatrix16[column]] = tmp;
547
548 if (dowbits)
549 {
550 if (tmp < 0) tmp *= -1;
551 while (tmp > wbitsMaxValue)
552 {
553 wbits++;
554 wbitsMaxValue = 1 << wbits;
555 if (wbits == maxwbits)
556 {
557 dowbits = false;
558 break;
559 }
560 }
561 }
562
563 for (int uptr = Constants.TerrainPatchSize;
564 uptr < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
565 uptr += Constants.TerrainPatchSize)
566 {
567 total = 0.0f;
568
569 for (int n = inlinesptr, ptru = uptr; n < inlinesptr + Constants.TerrainPatchSize; n++, ptru++)
570 {
571 total += linein[n]*CosineTable16[ptru];
572 }
573
574 tmp = (int) (total*QuantizeTable16[uptr + column]);
575 lineout[CopyMatrix16[uptr + column]] = tmp;
576
577 if (dowbits)
578 {
579 if (tmp < 0) tmp *= -1;
580 while (tmp > wbitsMaxValue)
581 {
582 wbits++;
583 wbitsMaxValue = 1 << wbits;
584 if (wbits == maxwbits)
585 {
586 dowbits = false;
587 break;
588 }
589 }
590 }
591 }
592 return wbits;
593 }
594
595 public static void DecodePatch(int[] patches, BitPack bitpack, TerrainPatch.Header header, int size)
596 {
597 for (int n = 0; n < size*size; n++)
598 {
599 // ?
600 int temp = bitpack.UnpackBits(1);
601 if (temp != 0)
602 {
603 // Value or EOB
604 temp = bitpack.UnpackBits(1);
605 if (temp != 0)
606 {
607 // Value
608 temp = bitpack.UnpackBits(1);
609 if (temp != 0)
610 {
611 // Negative
612 temp = bitpack.UnpackBits((int) header.WordBits);
613 patches[n] = temp*-1;
614 }
615 else
616 {
617 // Positive
618 temp = bitpack.UnpackBits((int) header.WordBits);
619 patches[n] = temp;
620 }
621 }
622 else
623 {
624 // Set the rest to zero
625 // TODO: This might not be necessary
626 for (int o = n; o < size*size; o++)
627 {
628 patches[o] = 0;
629 }
630 break;
631 }
632 }
633 else
634 {
635 patches[n] = 0;
636 }
637 }
638 }
639
640 private static void EncodePatch(BitPack output, int[] patch, int postquant, int wbits)
641 {
642 int maxwbitssize = (1 << wbits) - 1;
643
644 if (postquant > Constants.TerrainPatchSize*Constants.TerrainPatchSize || postquant < 0)
645 {
646 Logger.Log("Postquant is outside the range of allowed values in EncodePatch()", Helpers.LogLevel.Error);
647 return;
648 }
649
650 if (postquant != 0) patch[Constants.TerrainPatchSize*Constants.TerrainPatchSize - postquant] = 0;
651
652 for (int i = 0; i < Constants.TerrainPatchSize*Constants.TerrainPatchSize; i++)
653 {
654 int temp = patch[i];
655
656 if (temp == 0)
657 {
658 bool eob = true;
659
660 for (int j = i; j < Constants.TerrainPatchSize*Constants.TerrainPatchSize - postquant; j++)
661 {
662 if (patch[j] != 0)
663 {
664 eob = false;
665 break;
666 }
667 }
668
669 if (eob)
670 {
671 output.PackBits(ZERO_EOB, 2);
672 return;
673 }
674 output.PackBits(ZERO_CODE, 1);
675 }
676 else
677 {
678 if (temp < 0)
679 {
680 temp *= -1;
681
682 if (temp > maxwbitssize) temp = maxwbitssize;
683
684 output.PackBits(NEGATIVE_VALUE, 3);
685 output.PackBits(temp, wbits);
686 }
687 else
688 {
689 if (temp > maxwbitssize) temp = maxwbitssize;
690
691 output.PackBits(POSITIVE_VALUE, 3);
692 output.PackBits(temp, wbits);
693 }
694 }
695 }
696 }
697
698 public static float[] DecompressPatch(int[] patches, TerrainPatch.Header header, TerrainPatch.GroupHeader group)
699 {
700 float[] block = new float[group.PatchSize*group.PatchSize];
701 float[] output = new float[group.PatchSize*group.PatchSize];
702 int prequant = (header.QuantWBits >> 4) + 2;
703 int quantize = 1 << prequant;
704 float ooq = 1.0f/quantize;
705 float mult = ooq*header.Range;
706 float addval = mult*(1 << (prequant - 1)) + header.DCOffset;
707
708 if (group.PatchSize == Constants.TerrainPatchSize)
709 {
710 for (int n = 0; n < Constants.TerrainPatchSize*Constants.TerrainPatchSize; n++)
711 {
712 block[n] = patches[CopyMatrix16[n]]*DequantizeTable16[n];
713 }
714
715 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
716
717 for (int o = 0; o < Constants.TerrainPatchSize; o++)
718 IDCTColumn16(block, ftemp, o);
719 for (int o = 0; o < Constants.TerrainPatchSize; o++)
720 IDCTLine16(ftemp, block, o);
721 }
722 else
723 {
724 for (int n = 0; n < Constants.TerrainPatchSize*2*Constants.TerrainPatchSize*2; n++)
725 {
726 block[n] = patches[CopyMatrix32[n]]*DequantizeTable32[n];
727 }
728
729 Logger.Log("Implement IDCTPatchLarge", Helpers.LogLevel.Error);
730 }
731
732 for (int j = 0; j < block.Length; j++)
733 {
734 output[j] = block[j]*mult + addval;
735 }
736
737 return output;
738 }
739
740 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits)
741 {
742 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
743 int wordsize = (prequant - 2) & 0x0f;
744 float oozrange = 1.0f/header.Range;
745 float range = (1 << prequant);
746 float premult = oozrange*range;
747 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
748
749 header.QuantWBits = wordsize;
750 header.QuantWBits |= wordsize << 4;
751
752 int k = 0;
753 for (int j = 0; j < Constants.TerrainPatchSize; j++)
754 {
755 for (int i = 0; i < Constants.TerrainPatchSize; i++)
756 block[k++] = patchData[j*Constants.TerrainPatchSize + i]*premult - sub;
757 }
758
759 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
760 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
761
762
763 int maxWbits = prequant + 5;
764 wbits = (prequant >> 1);
765
766 for (int o = 0; o < Constants.TerrainPatchSize; o++)
767 DCTLine16(block, ftemp, o);
768 for (int o = 0; o < Constants.TerrainPatchSize; o++)
769 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
770
771 return itemp;
772 }
773
774 private static int[] CompressPatch(float[,] patchData, TerrainPatch.Header header, int prequant, out int wbits)
775 {
776 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
777 float oozrange = 1.0f/header.Range;
778 float range = (1 << prequant);
779 float premult = oozrange*range;
780 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
781 int wordsize = (prequant - 2) & 0x0f;
782
783 header.QuantWBits = wordsize;
784 header.QuantWBits |= wordsize << 4;
785
786 int k = 0;
787 for (int j = 0; j < Constants.TerrainPatchSize; j++)
788 {
789 for (int i = 0; i < Constants.TerrainPatchSize; i++)
790 block[k++] = patchData[j, i]*premult - sub;
791 }
792
793 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
794 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
795
796 int maxWbits = prequant + 5;
797 wbits = (prequant >> 1);
798
799 for (int o = 0; o < Constants.TerrainPatchSize; o++)
800 DCTLine16(block, ftemp, o);
801 for (int o = 0; o < Constants.TerrainPatchSize; o++)
802 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
803
804 return itemp;
805 }
806
807 private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header,
808 int prequant, out int wbits)
809 {
810 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
811 int wordsize = prequant;
812 float oozrange = 1.0f/header.Range;
813 float range = (1 << prequant);
814 float premult = oozrange*range;
815 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
816
817 header.QuantWBits = wordsize - 2;
818 header.QuantWBits |= (prequant - 2) << 4;
819
820 int k = 0;
821
822 int jPatchLimit = patchY;
823 if (patchY >= (terrData.SizeY / Constants.TerrainPatchSize))
824 {
825 jPatchLimit = (int)(terrData.SizeY - Constants.TerrainPatchSize) / Constants.TerrainPatchSize;
826 }
827 jPatchLimit = (jPatchLimit + 1) * Constants.TerrainPatchSize;
828
829 int iPatchLimit = patchX;
830 if (patchX >= (terrData.SizeX / Constants.TerrainPatchSize))
831 {
832 iPatchLimit = (int)(terrData.SizeX - Constants.TerrainPatchSize) / Constants.TerrainPatchSize;
833 }
834 iPatchLimit = (iPatchLimit + 1) * Constants.TerrainPatchSize;
835
836 for (int j = patchY * Constants.TerrainPatchSize; j < jPatchLimit; j++)
837 {
838 for (int i = patchX * Constants.TerrainPatchSize; i < iPatchLimit; i++)
839 {
840 // block[k++] = (heightmap[j*pRegionSizeX + i])*premult - sub;
841 block[k++] = terrData[j, i] - sub;
842 }
843 }
844
845 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
846 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
847
848 int maxWbits = prequant + 5;
849 wbits = (prequant >> 1);
850
851 for (int o = 0; o < Constants.TerrainPatchSize; o++)
852 DCTLine16(block, ftemp, o);
853 for (int o = 0; o < Constants.TerrainPatchSize; o++)
854 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
855
856 return itemp;
857 }
858
859 #region Initialization
860
861 private static void BuildDequantizeTable16()
862 {
863 for (int j = 0; j < Constants.TerrainPatchSize; j++)
864 {
865 for (int i = 0; i < Constants.TerrainPatchSize; i++)
866 {
867 DequantizeTable16[j*Constants.TerrainPatchSize + i] = 1.0f + 2.0f*(i + j);
868 }
869 }
870 }
871
872 private static void BuildQuantizeTable16()
873 {
874 const float oosob = 2.0f/Constants.TerrainPatchSize;
875 for (int j = 0; j < Constants.TerrainPatchSize; j++)
876 {
877 for (int i = 0; i < Constants.TerrainPatchSize; i++)
878 {
879// QuantizeTable16[j * Constants.TerrainPatchSize + i] = 1.0f / (1.0f + 2.0f * ((float)i + (float)j));
880 QuantizeTable16[j*Constants.TerrainPatchSize + i] = oosob/(1.0f + 2.0f*(i + (float) j));
881 }
882 }
883 }
884
885 private static void SetupCosines16()
886 {
887 const float hposz = (float) Math.PI*0.5f/Constants.TerrainPatchSize;
888
889 for (int u = 0; u < Constants.TerrainPatchSize; u++)
890 {
891 for (int n = 0; n < Constants.TerrainPatchSize; n++)
892 {
893 CosineTable16[u*Constants.TerrainPatchSize + n] = (float) Math.Cos((2.0f*n + 1.0f)*u*hposz);
894 }
895 }
896 }
897
898 private static void BuildCopyMatrix16()
899 {
900 bool diag = false;
901 bool right = true;
902 int i = 0;
903 int j = 0;
904 int count = 0;
905
906 while (i < Constants.TerrainPatchSize && j < Constants.TerrainPatchSize)
907 {
908 CopyMatrix16[j*Constants.TerrainPatchSize + i] = count++;
909
910 if (!diag)
911 {
912 if (right)
913 {
914 if (i < Constants.TerrainPatchSize - 1) i++;
915 else j++;
916
917 right = false;
918 diag = true;
919 }
920 else
921 {
922 if (j < Constants.TerrainPatchSize - 1) j++;
923 else i++;
924
925 right = true;
926 diag = true;
927 }
928 }
929 else
930 {
931 if (right)
932 {
933 i++;
934 j--;
935 if (i == Constants.TerrainPatchSize - 1 || j == 0) diag = false;
936 }
937 else
938 {
939 i--;
940 j++;
941 if (j == Constants.TerrainPatchSize - 1 || i == 0) diag = false;
942 }
943 }
944 }
945 }
946
947 #endregion Initialization
948 }
949} \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
index d4fe5e0..cbc538e 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
@@ -84,8 +84,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
84 84
85 Region = scene.RegionInfo.RegionName; 85 Region = scene.RegionInfo.RegionName;
86 Host = scene.RegionInfo.ExternalHostName; 86 Host = scene.RegionInfo.ExternalHostName;
87 LocX = Convert.ToString(scene.RegionInfo.RegionLocX); 87 LocX = Convert.ToString(scene.RegionInfo.LegacyRegionLocX);
88 LocY = Convert.ToString(scene.RegionInfo.RegionLocY); 88 LocY = Convert.ToString(scene.RegionInfo.LegacyRegionLocY);
89 IDK = Convert.ToString(_idk_++); 89 IDK = Convert.ToString(_idk_++);
90 90
91 showAlert = config.GetBoolean("alert_show", false); 91 showAlert = config.GetBoolean("alert_show", false);
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerIndividualEventForwarder.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerIndividualEventForwarder.cs
index 83732e2..7f616bb 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerIndividualEventForwarder.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerIndividualEventForwarder.cs
@@ -100,8 +100,8 @@ namespace OpenSim.Region.RegionCombinerModule
100 UUID raytargetid, byte bypassraycast, bool rayendisintersection, bool rezselected, bool removeitem, 100 UUID raytargetid, byte bypassraycast, bool rayendisintersection, bool rezselected, bool removeitem,
101 UUID fromtaskid) 101 UUID fromtaskid)
102 { 102 {
103 int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX; 103 int differenceX = (int)m_virtScene.RegionInfo.LegacyRegionLocX - (int)m_rootScene.RegionInfo.LegacyRegionLocX;
104 int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY; 104 int differenceY = (int)m_virtScene.RegionInfo.LegacyRegionLocY - (int)m_rootScene.RegionInfo.LegacyRegionLocY;
105 rayend.X += differenceX * (int)Constants.RegionSize; 105 rayend.X += differenceX * (int)Constants.RegionSize;
106 rayend.Y += differenceY * (int)Constants.RegionSize; 106 rayend.Y += differenceY * (int)Constants.RegionSize;
107 raystart.X += differenceX * (int)Constants.RegionSize; 107 raystart.X += differenceX * (int)Constants.RegionSize;
@@ -126,8 +126,8 @@ namespace OpenSim.Region.RegionCombinerModule
126 PrimitiveBaseShape shape, byte bypassraycast, Vector3 raystart, UUID raytargetid, 126 PrimitiveBaseShape shape, byte bypassraycast, Vector3 raystart, UUID raytargetid,
127 byte rayendisintersection) 127 byte rayendisintersection)
128 { 128 {
129 int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX; 129 int differenceX = (int)m_virtScene.RegionInfo.LegacyRegionLocX - (int)m_rootScene.RegionInfo.LegacyRegionLocX;
130 int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY; 130 int differenceY = (int)m_virtScene.RegionInfo.LegacyRegionLocY - (int)m_rootScene.RegionInfo.LegacyRegionLocY;
131 rayend.X += differenceX * (int)Constants.RegionSize; 131 rayend.X += differenceX * (int)Constants.RegionSize;
132 rayend.Y += differenceY * (int)Constants.RegionSize; 132 rayend.Y += differenceY * (int)Constants.RegionSize;
133 raystart.X += differenceX * (int)Constants.RegionSize; 133 raystart.X += differenceX * (int)Constants.RegionSize;
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
index 7127c73..3f835a4 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
@@ -246,8 +246,8 @@ namespace OpenSim.Region.RegionCombinerModule
246 newConn.RegionScene = scene; 246 newConn.RegionScene = scene;
247 newConn.RegionLandChannel = scene.LandChannel; 247 newConn.RegionLandChannel = scene.LandChannel;
248 newConn.RegionId = scene.RegionInfo.originRegionID; 248 newConn.RegionId = scene.RegionInfo.originRegionID;
249 newConn.X = scene.RegionInfo.RegionLocX; 249 newConn.X = scene.RegionInfo.LegacyRegionLocX;
250 newConn.Y = scene.RegionInfo.RegionLocY; 250 newConn.Y = scene.RegionInfo.LegacyRegionLocY;
251 newConn.XEnd = (int)Constants.RegionSize; 251 newConn.XEnd = (int)Constants.RegionSize;
252 newConn.YEnd = (int)Constants.RegionSize; 252 newConn.YEnd = (int)Constants.RegionSize;
253 253
@@ -502,11 +502,11 @@ namespace OpenSim.Region.RegionCombinerModule
502 502
503 lock (scene.WestBorders) 503 lock (scene.WestBorders)
504 { 504 {
505 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West 505 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.LegacyRegionLocX - rootConn.RegionScene.RegionInfo.LegacyRegionLocX) * (int)Constants.RegionSize); //auto teleport West
506 506
507 // Trigger auto teleport to root region 507 // Trigger auto teleport to root region
508 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX; 508 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.LegacyRegionLocX;
509 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY; 509 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.LegacyRegionLocY;
510 } 510 }
511 511
512 // Reset Terrain.. since terrain loads before we get here, we need to load 512 // Reset Terrain.. since terrain loads before we get here, we need to load
@@ -564,9 +564,9 @@ namespace OpenSim.Region.RegionCombinerModule
564 564
565 lock (scene.SouthBorders) 565 lock (scene.SouthBorders)
566 { 566 {
567 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 567 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.LegacyRegionLocY - rootConn.RegionScene.RegionInfo.LegacyRegionLocY) * (int)Constants.RegionSize); //auto teleport south
568 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX; 568 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.LegacyRegionLocX;
569 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY; 569 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.LegacyRegionLocY;
570 } 570 }
571 571
572 // Reset Terrain.. since terrain normally loads first. 572 // Reset Terrain.. since terrain normally loads first.
@@ -636,9 +636,9 @@ namespace OpenSim.Region.RegionCombinerModule
636 636
637 lock (scene.SouthBorders) 637 lock (scene.SouthBorders)
638 { 638 {
639 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 639 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.LegacyRegionLocY - rootConn.RegionScene.RegionInfo.LegacyRegionLocY) * (int)Constants.RegionSize); //auto teleport south
640 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX; 640 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.LegacyRegionLocX;
641 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY; 641 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.LegacyRegionLocY;
642 } 642 }
643 643
644 lock (rootConn.RegionScene.EastBorders) 644 lock (rootConn.RegionScene.EastBorders)
@@ -657,9 +657,9 @@ namespace OpenSim.Region.RegionCombinerModule
657 657
658 lock (scene.WestBorders) 658 lock (scene.WestBorders)
659 { 659 {
660 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West 660 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.LegacyRegionLocX - rootConn.RegionScene.RegionInfo.LegacyRegionLocX) * (int)Constants.RegionSize); //auto teleport West
661 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX; 661 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.LegacyRegionLocX;
662 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY; 662 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.LegacyRegionLocY;
663 } 663 }
664 664
665 /* 665 /*
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 8650b91..61017b8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -4244,10 +4244,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4244 DataserverPlugin.RegisterRequest(m_host.LocalId, 4244 DataserverPlugin.RegisterRequest(m_host.LocalId,
4245 m_item.ItemID, item.AssetID.ToString()); 4245 m_item.ItemID, item.AssetID.ToString());
4246 4246
4247 Vector3 region = new Vector3( 4247 Vector3 region = new Vector3(World.RegionInfo.RegionWorldLocX, World.RegionInfo.RegionWorldLocY, 0);
4248 World.RegionInfo.RegionLocX * Constants.RegionSize,
4249 World.RegionInfo.RegionLocY * Constants.RegionSize,
4250 0);
4251 4248
4252 World.AssetService.Get(item.AssetID.ToString(), this, 4249 World.AssetService.Get(item.AssetID.ToString(), this,
4253 delegate(string i, object sender, AssetBase a) 4250 delegate(string i, object sender, AssetBase a)
@@ -5481,7 +5478,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5481 public LSL_Vector llGetRegionCorner() 5478 public LSL_Vector llGetRegionCorner()
5482 { 5479 {
5483 m_host.AddScriptLPS(1); 5480 m_host.AddScriptLPS(1);
5484 return new LSL_Vector(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0); 5481 return new LSL_Vector(World.RegionInfo.RegionWorldLocX, World.RegionInfo.RegionWorldLocY, 0);
5485 } 5482 }
5486 5483
5487 /// <summary> 5484 /// <summary>
@@ -5654,8 +5651,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5654 5651
5655 List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID); 5652 List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
5656 5653
5657 uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x; 5654 uint neighborX = World.RegionInfo.LegacyRegionLocX + (uint)dir.x;
5658 uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y; 5655 uint neighborY = World.RegionInfo.LegacyRegionLocY + (uint)dir.y;
5659 5656
5660 foreach (GridRegion sri in neighbors) 5657 foreach (GridRegion sri in neighbors)
5661 { 5658 {
@@ -10740,7 +10737,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10740 httpHeaders["X-SecondLife-Shard"] = shard; 10737 httpHeaders["X-SecondLife-Shard"] = shard;
10741 httpHeaders["X-SecondLife-Object-Name"] = m_host.Name; 10738 httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
10742 httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString(); 10739 httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
10743 httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY); 10740 httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.LegacyRegionLocX, regionInfo.LegacyRegionLocY);
10744 httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z); 10741 httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
10745 httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z); 10742 httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
10746 httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W); 10743 httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W);
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
index b999509..71334ee 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
@@ -201,8 +201,8 @@ namespace OpenSim.Services.Connectors.SimianGrid
201 NameValueCollection requestArgs = new NameValueCollection 201 NameValueCollection requestArgs = new NameValueCollection
202 { 202 {
203 { "RequestMethod", "xAddMapTile" }, 203 { "RequestMethod", "xAddMapTile" },
204 { "X", scene.RegionInfo.RegionLocX.ToString() }, 204 { "X", scene.RegionInfo.LegacyRegionLocX.ToString() },
205 { "Y", scene.RegionInfo.RegionLocY.ToString() }, 205 { "Y", scene.RegionInfo.LegacyRegionLocY.ToString() },
206 { "ContentType", "image/png" }, 206 { "ContentType", "image/png" },
207 { "EncodedData", System.Convert.ToBase64String(pngData) } 207 { "EncodedData", System.Convert.ToBase64String(pngData) }
208 }; 208 };
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 88ac5b3..56171b1 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -246,8 +246,8 @@ namespace OpenSim.Services.Interfaces
246 public GridRegion(RegionInfo ConvertFrom) 246 public GridRegion(RegionInfo ConvertFrom)
247 { 247 {
248 m_regionName = ConvertFrom.RegionName; 248 m_regionName = ConvertFrom.RegionName;
249 m_regionLocX = (int)(ConvertFrom.RegionLocX * Constants.RegionSize); 249 m_regionLocX = (int)(ConvertFrom.RegionWorldLocX);
250 m_regionLocY = (int)(ConvertFrom.RegionLocY * Constants.RegionSize); 250 m_regionLocY = (int)(ConvertFrom.RegionWorldLocY);
251 m_internalEndPoint = ConvertFrom.InternalEndPoint; 251 m_internalEndPoint = ConvertFrom.InternalEndPoint;
252 m_externalHostName = ConvertFrom.ExternalHostName; 252 m_externalHostName = ConvertFrom.ExternalHostName;
253 m_httpPort = ConvertFrom.HttpPort; 253 m_httpPort = ConvertFrom.HttpPort;