aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs11
-rw-r--r--OpenSim/Data/IRegionData.cs4
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs103
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs82
-rw-r--r--OpenSim/Data/Null/NullSimulationData.cs21
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs117
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs97
-rw-r--r--OpenSim/Framework/MapBlockData.cs18
-rw-r--r--OpenSim/Framework/MapItemReplyStruct.cs33
-rw-r--r--OpenSim/Framework/TerrainData.cs418
-rw-r--r--OpenSim/Framework/UserProfileData.cs14
-rw-r--r--OpenSim/Region/Application/OpenSim.cs15
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs7
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs11
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs12
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs101
-rw-r--r--OpenSim/Region/ClientStack/RegionApplicationBase.cs6
-rw-r--r--OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs20
-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/Caps/CapabilitiesModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs702
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs5
-rw-r--r--OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs26
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs9
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs6
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs3
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs86
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs85
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs61
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs17
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs318
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs187
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs83
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs36
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs51
-rw-r--r--OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs101
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs436
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs237
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs258
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs28
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs9
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs16
-rw-r--r--OpenSim/Region/Framework/Interfaces/ITerrainModule.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs141
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs30
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs160
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainChannel.cs278
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainCompressor.cs944
-rw-r--r--OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs5
-rw-r--r--OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs4
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs11
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs13
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs4
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs6
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs5
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs6
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs9
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionConnections.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs10
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs3
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs4
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs2
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs10
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs12
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs12
-rw-r--r--OpenSim/Services/Connectors/Land/LandServicesConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs12
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationDataService.cs10
-rw-r--r--OpenSim/Services/GridService/GridService.cs9
-rw-r--r--OpenSim/Services/GridService/HypergridLinker.cs61
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs12
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginResponse.cs28
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs2
-rw-r--r--OpenSim/Tests/Clients/Grid/GridClient.cs8
-rw-r--r--OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs8
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs3
-rw-r--r--OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs29
-rw-r--r--bin/OpenSim.ini.example12
-rw-r--r--bin/OpenSimDefaults.ini9
103 files changed, 3978 insertions, 1881 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 811781c..7067a62 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -1022,7 +1022,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1022 // Set home position 1022 // Set home position
1023 1023
1024 GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 1024 GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
1025 (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); 1025 (int)Util.RegionToWorldLoc(regionXLocation), (int)Util.RegionToWorldLoc(regionYLocation));
1026 if (null == home) 1026 if (null == home)
1027 { 1027 {
1028 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName); 1028 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName);
@@ -1252,7 +1252,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1252 if ((null != regionXLocation) && (null != regionYLocation)) 1252 if ((null != regionXLocation) && (null != regionYLocation))
1253 { 1253 {
1254 GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 1254 GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
1255 (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); 1255 (int)Util.RegionToWorldLoc((uint)regionXLocation), (int)Util.RegionToWorldLoc((uint)regionYLocation));
1256 if (null == home) { 1256 if (null == home) {
1257 m_log.WarnFormat("[RADMIN]: Unable to set home region for updated user account {0} {1}", firstName, lastName); 1257 m_log.WarnFormat("[RADMIN]: Unable to set home region for updated user account {0} {1}", firstName, lastName);
1258 } else { 1258 } else {
@@ -1484,8 +1484,11 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1484 } 1484 }
1485 1485
1486 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>(); 1486 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
1487 Dictionary<string, object> archiveOptions = new Dictionary<string,object>();
1488 if (mergeOar) archiveOptions.Add("merge", null);
1489 if (skipAssets) archiveOptions.Add("skipAssets", null);
1487 if (archiver != null) 1490 if (archiver != null)
1488 archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty); 1491 archiver.DearchiveRegion(filename, Guid.Empty, archiveOptions);
1489 else 1492 else
1490 throw new Exception("Archiver module not present for scene"); 1493 throw new Exception("Archiver module not present for scene");
1491 1494
@@ -2881,7 +2884,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
2881 // Set home position 2884 // Set home position
2882 2885
2883 GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 2886 GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
2884 (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); 2887 (int)Util.RegionToWorldLoc(regionXLocation), (int)Util.RegionToWorldLoc(regionYLocation));
2885 if (null == home) { 2888 if (null == home) {
2886 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]); 2889 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]);
2887 } else { 2890 } else {
diff --git a/OpenSim/Data/IRegionData.cs b/OpenSim/Data/IRegionData.cs
index 463c621..50433ba 100644
--- a/OpenSim/Data/IRegionData.cs
+++ b/OpenSim/Data/IRegionData.cs
@@ -54,12 +54,12 @@ namespace OpenSim.Data
54 /// <summary> 54 /// <summary>
55 /// Return the x-coordinate of this region. 55 /// Return the x-coordinate of this region.
56 /// </summary> 56 /// </summary>
57 public int coordX { get { return posX / (int)Constants.RegionSize; } } 57 public int coordX { get { return (int)Util.WorldToRegionLoc((uint)posX); } }
58 58
59 /// <summary> 59 /// <summary>
60 /// Return the y-coordinate of this region. 60 /// Return the y-coordinate of this region.
61 /// </summary> 61 /// </summary>
62 public int coordY { get { return posY / (int)Constants.RegionSize; } } 62 public int coordY { get { return (int)Util.WorldToRegionLoc((uint)posY); } }
63 63
64 public Dictionary<string, object> Data; 64 public Dictionary<string, object> Data;
65 } 65 }
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index f41f60c..9f5991b 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
@@ -530,43 +531,49 @@ ELSE
530 /// <returns></returns> 531 /// <returns></returns>
531 public double[,] LoadTerrain(UUID regionID) 532 public double[,] LoadTerrain(UUID regionID)
532 { 533 {
533 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 534 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
534 terrain.Initialize(); 535 return terrData.GetDoubles();
536 }
537
538 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
539 {
540 TerrainData terrData = null;
535 541
536 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc"; 542 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
537 543
538 using (SqlConnection conn = new SqlConnection(m_connectionString)) 544 using (SqlConnection conn = new SqlConnection(m_connectionString))
539 using (SqlCommand cmd = new SqlCommand(sql, conn))
540 { 545 {
541 // MySqlParameter param = new MySqlParameter(); 546 using (SqlCommand cmd = new SqlCommand(sql, conn))
542 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
543 conn.Open();
544 using (SqlDataReader reader = cmd.ExecuteReader())
545 { 547 {
546 int rev; 548 // MySqlParameter param = new MySqlParameter();
547 if (reader.Read()) 549 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
550 conn.Open();
551 using (SqlDataReader reader = cmd.ExecuteReader())
548 { 552 {
549 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 553 int rev;
550 BinaryReader br = new BinaryReader(str); 554 if (reader.Read())
551 for (int x = 0; x < (int)Constants.RegionSize; x++)
552 { 555 {
553 for (int y = 0; y < (int)Constants.RegionSize; y++) 556 rev = (int)reader["Revision"];
554 { 557 byte[] blob = (byte[])reader["Heightfield"];
555 terrain[x, y] = br.ReadDouble(); 558 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
556 }
557 } 559 }
558 rev = (int)reader["Revision"]; 560 else
559 } 561 {
560 else 562 _Log.Info("[REGION DB]: No terrain found for region");
561 { 563 return null;
562 _Log.Info("[REGION DB]: No terrain found for region"); 564 }
563 return null; 565 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
564 } 566 }
565 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
566 } 567 }
567 } 568 }
568 569
569 return terrain; 570 return terrData;
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);
570 } 577 }
571 578
572 /// <summary> 579 /// <summary>
@@ -574,10 +581,8 @@ ELSE
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,23 @@ 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))
595 { 603 {
596 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); 604 using (SqlCommand cmd = new SqlCommand(sql, conn))
597 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); 605 {
598 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); 606 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
599 conn.Open(); 607 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision));
600 cmd.ExecuteNonQuery(); 608 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob));
609 conn.Open();
610 cmd.ExecuteNonQuery();
611 }
601 } 612 }
602 613
603 _Log.Info("[REGION DB]: Stored terrain revision r " + revision); 614 _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision);
604 } 615 }
605 616
606 /// <summary> 617 /// <summary>
@@ -1345,30 +1356,6 @@ VALUES
1345 #region Private Methods 1356 #region Private Methods
1346 1357
1347 /// <summary> 1358 /// <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. 1359 /// Stores new regionsettings.
1373 /// </summary> 1360 /// </summary>
1374 /// <param name="regionSettings">The region settings.</param> 1361 /// <param name="regionSettings">The region settings.</param>
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index b03a904..42f2ebb 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Data.MySQL
48 public class MySQLSimulationData : ISimulationDataStore 48 public class MySQLSimulationData : ISimulationDataStore
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[REGION DB MYSQL]";
51 52
52 private string m_connectionString; 53 private string m_connectionString;
53 private object m_dbLock = new object(); 54 private object m_dbLock = new object();
@@ -91,7 +92,7 @@ namespace OpenSim.Data.MySQL
91 } 92 }
92 catch (Exception e) 93 catch (Exception e)
93 { 94 {
94 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message); 95 m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
95 throw; 96 throw;
96 } 97 }
97 98
@@ -572,10 +573,14 @@ namespace OpenSim.Data.MySQL
572 } 573 }
573 } 574 }
574 575
576 // Legacy entry point for when terrain was always a 256x256 hieghtmap
575 public void StoreTerrain(double[,] ter, UUID regionID) 577 public void StoreTerrain(double[,] ter, UUID regionID)
576 { 578 {
577 m_log.Info("[REGION DB]: Storing terrain"); 579 StoreTerrain(new HeightmapTerrainData(ter), regionID);
580 }
578 581
582 public void StoreTerrain(TerrainData terrData, UUID regionID)
583 {
579 lock (m_dbLock) 584 lock (m_dbLock)
580 { 585 {
581 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 586 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
@@ -589,11 +594,18 @@ namespace OpenSim.Data.MySQL
589 594
590 ExecuteNonQuery(cmd); 595 ExecuteNonQuery(cmd);
591 596
592 cmd.CommandText = "insert into terrain (RegionUUID, " + 597 int terrainDBRevision;
593 "Revision, Heightfield) values (?RegionUUID, " + 598 Array terrainDBblob;
594 "1, ?Heightfield)"; 599 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
595 600
596 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); 601 m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}",
602 LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision);
603
604 cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)"
605 + "values (?RegionUUID, ?Revision, ?Heightfield)";
606
607 cmd.Parameters.AddWithValue("Revision", terrainDBRevision);
608 cmd.Parameters.AddWithValue("Heightfield", terrainDBblob);
597 609
598 ExecuteNonQuery(cmd); 610 ExecuteNonQuery(cmd);
599 } 611 }
@@ -601,9 +613,16 @@ namespace OpenSim.Data.MySQL
601 } 613 }
602 } 614 }
603 615
616 // Legacy region loading
604 public double[,] LoadTerrain(UUID regionID) 617 public double[,] LoadTerrain(UUID regionID)
605 { 618 {
606 double[,] terrain = null; 619 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
620 return terrData.GetDoubles();
621 }
622
623 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
624 {
625 TerrainData terrData = null;
607 626
608 lock (m_dbLock) 627 lock (m_dbLock)
609 { 628 {
@@ -623,32 +642,15 @@ namespace OpenSim.Data.MySQL
623 while (reader.Read()) 642 while (reader.Read())
624 { 643 {
625 int rev = Convert.ToInt32(reader["Revision"]); 644 int rev = Convert.ToInt32(reader["Revision"]);
626 645 byte[] blob = (byte[])reader["Heightfield"];
627 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 646 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
628 terrain.Initialize();
629
630 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
631 {
632 using (BinaryReader br = new BinaryReader(mstr))
633 {
634 for (int x = 0; x < (int)Constants.RegionSize; x++)
635 {
636 for (int y = 0; y < (int)Constants.RegionSize; y++)
637 {
638 terrain[x, y] = br.ReadDouble();
639 }
640 }
641 }
642
643 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
644 }
645 } 647 }
646 } 648 }
647 } 649 }
648 } 650 }
649 } 651 }
650 652
651 return terrain; 653 return terrData;
652 } 654 }
653 655
654 public void RemoveLandObject(UUID globalID) 656 public void RemoveLandObject(UUID globalID)
@@ -1525,30 +1527,6 @@ namespace OpenSim.Data.MySQL
1525 } 1527 }
1526 1528
1527 /// <summary> 1529 /// <summary>
1528 ///
1529 /// </summary>
1530 /// <param name="val"></param>
1531 /// <returns></returns>
1532 private static Array SerializeTerrain(double[,] val)
1533 {
1534 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1535 BinaryWriter bw = new BinaryWriter(str);
1536
1537 // TODO: COMPATIBILITY - Add byte-order conversions
1538 for (int x = 0; x < (int)Constants.RegionSize; x++)
1539 for (int y = 0; y < (int)Constants.RegionSize; y++)
1540 {
1541 double height = val[x, y];
1542 if (height == 0.0)
1543 height = double.Epsilon;
1544
1545 bw.Write(height);
1546 }
1547
1548 return str.ToArray();
1549 }
1550
1551 /// <summary>
1552 /// Fill the prim command with prim values 1530 /// Fill the prim command with prim values
1553 /// </summary> 1531 /// </summary>
1554 /// <param name="row"></param> 1532 /// <param name="row"></param>
diff --git a/OpenSim/Data/Null/NullSimulationData.cs b/OpenSim/Data/Null/NullSimulationData.cs
index d11ad72..acde1a1 100644
--- a/OpenSim/Data/Null/NullSimulationData.cs
+++ b/OpenSim/Data/Null/NullSimulationData.cs
@@ -132,18 +132,35 @@ namespace OpenSim.Data.Null
132 return new List<SceneObjectGroup>(); 132 return new List<SceneObjectGroup>();
133 } 133 }
134 134
135 Dictionary<UUID, double[,]> m_terrains = new Dictionary<UUID, double[,]>(); 135 Dictionary<UUID, TerrainData> m_terrains = new Dictionary<UUID, TerrainData>();
136 public void StoreTerrain(double[,] ter, UUID regionID) 136 public void StoreTerrain(TerrainData ter, UUID regionID)
137 { 137 {
138 if (m_terrains.ContainsKey(regionID)) 138 if (m_terrains.ContainsKey(regionID))
139 m_terrains.Remove(regionID); 139 m_terrains.Remove(regionID);
140 m_terrains.Add(regionID, ter); 140 m_terrains.Add(regionID, ter);
141 } 141 }
142 142
143 // Legacy. Just don't do this.
144 public void StoreTerrain(double[,] ter, UUID regionID)
145 {
146 TerrainData terrData = new HeightmapTerrainData(ter);
147 StoreTerrain(terrData, regionID);
148 }
149
150 // Legacy. Just don't do this.
143 public double[,] LoadTerrain(UUID regionID) 151 public double[,] LoadTerrain(UUID regionID)
144 { 152 {
145 if (m_terrains.ContainsKey(regionID)) 153 if (m_terrains.ContainsKey(regionID))
146 { 154 {
155 return m_terrains[regionID].GetDoubles();
156 }
157 return null;
158 }
159
160 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
161 {
162 if (m_terrains.ContainsKey(regionID))
163 {
147 return m_terrains[regionID]; 164 return m_terrains[regionID];
148 } 165 }
149 return null; 166 return null;
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index 354d749..1505f87 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);
@@ -523,44 +524,50 @@ namespace OpenSim.Data.PGSQL
523 /// <returns></returns> 524 /// <returns></returns>
524 public double[,] LoadTerrain(UUID regionID) 525 public double[,] LoadTerrain(UUID regionID)
525 { 526 {
526 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 527 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
527 terrain.Initialize(); 528 return terrData.GetDoubles();
529 }
530
531 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
532 {
533 TerrainData terrData = null;
528 534
529 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain 535 string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain
530 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; "; 536 where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; ";
531 537
532 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 538 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
533 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
534 { 539 {
535 // PGSqlParameter param = new PGSqlParameter(); 540 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
536 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
537 conn.Open();
538 using (NpgsqlDataReader reader = cmd.ExecuteReader())
539 { 541 {
540 int rev; 542 // PGSqlParameter param = new PGSqlParameter();
541 if (reader.Read()) 543 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
544 conn.Open();
545 using (NpgsqlDataReader reader = cmd.ExecuteReader())
542 { 546 {
543 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 547 int rev;
544 BinaryReader br = new BinaryReader(str); 548 if (reader.Read())
545 for (int x = 0; x < (int)Constants.RegionSize; x++)
546 { 549 {
547 for (int y = 0; y < (int)Constants.RegionSize; y++) 550 rev = Convert.ToInt32(reader["Revision"]);
548 { 551 byte[] blob = (byte[])reader["Heightfield"];
549 terrain[x, y] = br.ReadDouble(); 552 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
550 }
551 } 553 }
552 rev = (int)reader["Revision"]; 554 else
553 } 555 {
554 else 556 _Log.Info("[REGION DB]: No terrain found for region");
555 { 557 return null;
556 _Log.Info("[REGION DB]: No terrain found for region"); 558 }
557 return null; 559 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
558 } 560 }
559 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
560 } 561 }
561 } 562 }
562 563
563 return terrain; 564 return terrData;
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);
564 } 571 }
565 572
566 /// <summary> 573 /// <summary>
@@ -568,35 +575,43 @@ namespace OpenSim.Data.PGSQL
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>
@@ -1350,30 +1365,6 @@ namespace OpenSim.Data.PGSQL
1350 #region Private Methods 1365 #region Private Methods
1351 1366
1352 /// <summary> 1367 /// <summary>
1353 /// Serializes the terrain data for storage in DB.
1354 /// </summary>
1355 /// <param name="val">terrain data</param>
1356 /// <returns></returns>
1357 private static Array serializeTerrain(double[,] val)
1358 {
1359 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
1360 BinaryWriter bw = new BinaryWriter(str);
1361
1362 // TODO: COMPATIBILITY - Add byte-order conversions
1363 for (int x = 0; x < (int)Constants.RegionSize; x++)
1364 for (int y = 0; y < (int)Constants.RegionSize; y++)
1365 {
1366 double height = val[x, y];
1367 if (height == 0.0)
1368 height = double.Epsilon;
1369
1370 bw.Write(height);
1371 }
1372
1373 return str.ToArray();
1374 }
1375
1376 /// <summary>
1377 /// Stores new regionsettings. 1368 /// Stores new regionsettings.
1378 /// </summary> 1369 /// </summary>
1379 /// <param name="regionSettings">The region settings.</param> 1370 /// <param name="regionSettings">The region settings.</param>
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index d938b6b..5a34f09 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 }
@@ -870,11 +870,16 @@ namespace OpenSim.Data.SQLite
870 /// <returns>Heightfield data</returns> 870 /// <returns>Heightfield data</returns>
871 public double[,] LoadTerrain(UUID regionID) 871 public double[,] LoadTerrain(UUID regionID)
872 { 872 {
873 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
874 return terrData.GetDoubles();
875 }
876
877 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
878 {
879 TerrainData terrData = null;
880
873 lock (ds) 881 lock (ds)
874 { 882 {
875 double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
876 terret.Initialize();
877
878 String sql = "select RegionUUID, Revision, Heightfield from terrain" + 883 String sql = "select RegionUUID, Revision, Heightfield from terrain" +
879 " where RegionUUID=:RegionUUID order by Revision desc"; 884 " where RegionUUID=:RegionUUID order by Revision desc";
880 885
@@ -887,21 +892,9 @@ namespace OpenSim.Data.SQLite
887 int rev = 0; 892 int rev = 0;
888 if (row.Read()) 893 if (row.Read())
889 { 894 {
890 // TODO: put this into a function
891 using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"]))
892 {
893 using (BinaryReader br = new BinaryReader(str))
894 {
895 for (int x = 0; x < (int)Constants.RegionSize; x++)
896 {
897 for (int y = 0; y < (int)Constants.RegionSize; y++)
898 {
899 terret[x, y] = br.ReadDouble();
900 }
901 }
902 }
903 }
904 rev = Convert.ToInt32(row["Revision"]); 895 rev = Convert.ToInt32(row["Revision"]);
896 byte[] blob = (byte[])row["Heightfield"];
897 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
905 } 898 }
906 else 899 else
907 { 900 {
@@ -912,8 +905,8 @@ namespace OpenSim.Data.SQLite
912 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); 905 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
913 } 906 }
914 } 907 }
915 return terret;
916 } 908 }
909 return terrData;
917 } 910 }
918 911
919 public void RemoveLandObject(UUID globalID) 912 public void RemoveLandObject(UUID globalID)
@@ -2019,40 +2012,6 @@ namespace OpenSim.Data.SQLite
2019 /// <summary> 2012 /// <summary>
2020 /// 2013 ///
2021 /// </summary> 2014 /// </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)
2038 // {
2039 // row["RegionUUID"] = regionUUID;
2040 // row["Revision"] = rev;
2041
2042 // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double));
2043 // BinaryWriter bw = new BinaryWriter(str);
2044
2045 // // TODO: COMPATIBILITY - Add byte-order conversions
2046 // for (int x = 0; x < (int)Constants.RegionSize; x++)
2047 // for (int y = 0; y < (int)Constants.RegionSize; y++)
2048 // bw.Write(val[x, y]);
2049
2050 // row["Heightfield"] = str.ToArray();
2051 // }
2052
2053 /// <summary>
2054 ///
2055 /// </summary>
2056 /// <param name="row"></param> 2015 /// <param name="row"></param>
2057 /// <param name="prim"></param> 2016 /// <param name="prim"></param>
2058 /// <param name="sceneGroupID"></param> 2017 /// <param name="sceneGroupID"></param>
diff --git a/OpenSim/Framework/MapBlockData.cs b/OpenSim/Framework/MapBlockData.cs
index 2298ac5..4bee499 100644
--- a/OpenSim/Framework/MapBlockData.cs
+++ b/OpenSim/Framework/MapBlockData.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenMetaverse.StructuredData;
30 31
31namespace OpenSim.Framework 32namespace OpenSim.Framework
32{ 33{
@@ -40,9 +41,26 @@ namespace OpenSim.Framework
40 public byte WaterHeight; 41 public byte WaterHeight;
41 public ushort X; 42 public ushort X;
42 public ushort Y; 43 public ushort Y;
44 public ushort SizeX;
45 public ushort SizeY;
43 46
44 public MapBlockData() 47 public MapBlockData()
45 { 48 {
46 } 49 }
50
51 public OSDMap ToOSD()
52 {
53 OSDMap map = new OSDMap();
54 map["X"] = X;
55 map["Y"] = Y;
56 map["SizeX"] = SizeX;
57 map["SizeY"] = SizeY;
58 map["Name"] = Name;
59 map["Access"] = Access;
60 map["RegionFlags"] = RegionFlags;
61 map["WaterHeight"] = WaterHeight;
62 map["MapImageID"] = MapImageId;
63 return map;
64 }
47 } 65 }
48} 66}
diff --git a/OpenSim/Framework/MapItemReplyStruct.cs b/OpenSim/Framework/MapItemReplyStruct.cs
index 58011bd..c8693ae 100644
--- a/OpenSim/Framework/MapItemReplyStruct.cs
+++ b/OpenSim/Framework/MapItemReplyStruct.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using OpenMetaverse; 28using OpenMetaverse;
29using OpenMetaverse.StructuredData;
29 30
30namespace OpenSim.Framework 31namespace OpenSim.Framework
31{ 32{
@@ -37,5 +38,37 @@ namespace OpenSim.Framework
37 public int Extra; 38 public int Extra;
38 public int Extra2; 39 public int Extra2;
39 public string name; 40 public string name;
41
42 public mapItemReply(uint pX, uint pY, UUID pId, string pName, int pExt1, int pExt2)
43 {
44 x = pX;
45 y = pY;
46 id = pId;
47 name = pName;
48 Extra = pExt1;
49 Extra2 = pExt2;
50 }
51
52 public OSDMap ToOSD()
53 {
54 OSDMap map = new OSDMap();
55 map["X"] = OSD.FromInteger((int)x);
56 map["Y"] = OSD.FromInteger((int)y);
57 map["ID"] = OSD.FromUUID(id);
58 map["Name"] = OSD.FromString(name);
59 map["Extra"] = OSD.FromInteger(Extra);
60 map["Extra2"] = OSD.FromInteger(Extra2);
61 return map;
62 }
63
64 public void FromOSD(OSDMap map)
65 {
66 x = (uint) map["X"].AsInteger();
67 y = (uint) map["Y"].AsInteger();
68 id = map["ID"].AsUUID();
69 Extra = map["Extra"].AsInteger();
70 Extra2 = map["Extra2"].AsInteger();
71 name = map["Name"].AsString();
72 }
40 } 73 }
41} 74}
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs
new file mode 100644
index 0000000..1c52a69
--- /dev/null
+++ b/OpenSim/Framework/TerrainData.cs
@@ -0,0 +1,418 @@
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 // A height used when the user doesn't specify anything
47 public const float DefaultTerrainHeight = 21f;
48
49 public abstract float this[int x, int y] { get; set; }
50 // Someday terrain will have caves
51 public abstract float this[int x, int y, int z] { get; set; }
52
53 public bool IsTainted { get; protected set; }
54 public abstract bool IsTaintedAt(int xx, int yy);
55 public abstract void ClearTaint();
56
57 public abstract void ClearLand();
58 public abstract void ClearLand(float height);
59
60 // Return a representation of this terrain for storing as a blob in the database.
61 // Returns 'true' to say blob was stored in the 'out' locations.
62 public abstract bool GetDatabaseBlob(out int DBFormatRevisionCode, out Array blob);
63
64 // Given a revision code and a blob from the database, create and return the right type of TerrainData.
65 // The sizes passed are the expected size of the region. The database info will be used to
66 // initialize the heightmap of that sized region with as much data is in the blob.
67 // Return created TerrainData or 'null' if unsuccessful.
68 public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
69 {
70 // For the moment, there is only one implementation class
71 return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
72 }
73
74 // return a special compressed representation of the heightmap in shorts
75 public abstract short[] GetCompressedMap();
76 public abstract float CompressionFactor { get; }
77
78 public abstract double[,] GetDoubles();
79 public abstract TerrainData Clone();
80 }
81
82 // The terrain is stored in the database as a blob with a 'revision' field.
83 // Some implementations of terrain storage would fill the revision field with
84 // the time the terrain was stored. When real revisions were added and this
85 // feature removed, that left some old entries with the time in the revision
86 // field.
87 // Thus, if revision is greater than 'RevisionHigh' then terrain db entry is
88 // left over and it is presumed to be 'Legacy256'.
89 // Numbers are arbitrary and are chosen to to reduce possible mis-interpretation.
90 // If a revision does not match any of these, it is assumed to be Legacy256.
91 public enum DBTerrainRevision
92 {
93 // Terrain is 'double[256,256]'
94 Legacy256 = 11,
95 // Terrain is 'int32, int32, float[,]' where the ints are X and Y dimensions
96 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
97 Variable2D = 22,
98 // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions
99 // and third int is the 'compression factor'. The heights are compressed as
100 // "short compressedHeight = (short)(height * compressionFactor);"
101 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
102 Compressed2D = 27,
103 // A revision that is not listed above or any revision greater than this value is 'Legacy256'.
104 RevisionHigh = 1234
105 }
106
107 // Version of terrain that is a heightmap.
108 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
109 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
110 // The heighmap is kept as an array of short integers. The integer values are converted to
111 // and from floats by TerrainCompressionFactor. Shorts are used to limit storage used.
112 public class HeightmapTerrainData : TerrainData
113 {
114 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
115 private static string LogHeader = "[HEIGHTMAP TERRAIN DATA]";
116
117 // TerrainData.this[x, y]
118 public override float this[int x, int y]
119 {
120 get { return FromCompressedHeight(m_heightmap[x, y]); }
121 set {
122 short newVal = ToCompressedHeight(value);
123 if (m_heightmap[x, y] != newVal)
124 {
125 m_heightmap[x, y] = newVal;
126 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true;
127 }
128 }
129 }
130
131 // TerrainData.this[x, y, z]
132 public override float this[int x, int y, int z]
133 {
134 get { return this[x, y]; }
135 set { this[x, y] = value; }
136 }
137
138 // TerrainData.ClearTaint
139 public override void ClearTaint()
140 {
141 IsTainted = false;
142 for (int ii = 0; ii < m_taint.GetLength(0); ii++)
143 for (int jj = 0; jj < m_taint.GetLength(1); jj++)
144 m_taint[ii, jj] = false;
145 }
146
147 // TerrainData.ClearLand
148 public override void ClearLand()
149 {
150 ClearLand(DefaultTerrainHeight);
151 }
152 // TerrainData.ClearLand(float)
153 public override void ClearLand(float pHeight)
154 {
155 short flatHeight = ToCompressedHeight(pHeight);
156 for (int xx = 0; xx < SizeX; xx++)
157 for (int yy = 0; yy < SizeY; yy++)
158 m_heightmap[xx, yy] = flatHeight;
159 }
160
161 public override bool IsTaintedAt(int xx, int yy)
162 {
163 return m_taint[xx / Constants.TerrainPatchSize, yy / Constants.TerrainPatchSize];
164 }
165
166 // TerrainData.GetDatabaseBlob
167 // The user wants something to store in the database.
168 public override bool GetDatabaseBlob(out int DBRevisionCode, out Array blob)
169 {
170 bool ret = false;
171 if (SizeX == Constants.RegionSize && SizeY == Constants.RegionSize)
172 {
173 DBRevisionCode = (int)DBTerrainRevision.Legacy256;
174 blob = ToLegacyTerrainSerialization();
175 ret = true;
176 }
177 else
178 {
179 DBRevisionCode = (int)DBTerrainRevision.Compressed2D;
180 blob = ToCompressedTerrainSerialization();
181 ret = true;
182 }
183 return ret;
184 }
185
186 // TerrainData.CompressionFactor
187 private float m_compressionFactor = 100.0f;
188 public override float CompressionFactor { get { return m_compressionFactor; } }
189
190 // TerrainData.GetCompressedMap
191 public override short[] GetCompressedMap()
192 {
193 short[] newMap = new short[SizeX * SizeY];
194
195 int ind = 0;
196 for (int xx = 0; xx < SizeX; xx++)
197 for (int yy = 0; yy < SizeY; yy++)
198 newMap[ind++] = m_heightmap[xx, yy];
199
200 return newMap;
201
202 }
203 // TerrainData.Clone
204 public override TerrainData Clone()
205 {
206 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
207 ret.m_heightmap = (short[,])this.m_heightmap.Clone();
208 return ret;
209 }
210
211 // TerrainData.GetDoubles
212 public override double[,] GetDoubles()
213 {
214 double[,] ret = new double[SizeX, SizeY];
215 for (int xx = 0; xx < SizeX; xx++)
216 for (int yy = 0; yy < SizeY; yy++)
217 ret[xx, yy] = FromCompressedHeight(m_heightmap[xx, yy]);
218
219 return ret;
220 }
221
222
223 // =============================================================
224
225 private short[,] m_heightmap;
226 // Remember subregions of the heightmap that has changed.
227 private bool[,] m_taint;
228
229 // To save space (especially for large regions), keep the height as a short integer
230 // that is coded as the float height times the compression factor (usually '100'
231 // to make for two decimal points).
232 public short ToCompressedHeight(double pHeight)
233 {
234 return (short)(pHeight * CompressionFactor);
235 }
236
237 public float FromCompressedHeight(short pHeight)
238 {
239 return ((float)pHeight) / CompressionFactor;
240 }
241
242 // To keep with the legacy theme, create an instance of this class based on the
243 // way terrain used to be passed around.
244 public HeightmapTerrainData(double[,] pTerrain)
245 {
246 SizeX = pTerrain.GetLength(0);
247 SizeY = pTerrain.GetLength(1);
248 SizeZ = (int)Constants.RegionHeight;
249 m_compressionFactor = 100.0f;
250
251 m_heightmap = new short[SizeX, SizeY];
252 for (int ii = 0; ii < SizeX; ii++)
253 {
254 for (int jj = 0; jj < SizeY; jj++)
255 {
256 m_heightmap[ii, jj] = ToCompressedHeight(pTerrain[ii, jj]);
257
258 }
259 }
260 // m_log.DebugFormat("{0} new by doubles. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
261
262 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
263 ClearTaint();
264 }
265
266 // Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that
267 public HeightmapTerrainData(int pX, int pY, int pZ)
268 {
269 SizeX = pX;
270 SizeY = pY;
271 SizeZ = pZ;
272 m_compressionFactor = 100.0f;
273 m_heightmap = new short[SizeX, SizeY];
274 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
275 // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
276 ClearTaint();
277 }
278
279 public HeightmapTerrainData(short[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ)
280 {
281 m_compressionFactor = pCompressionFactor;
282 int ind = 0;
283 for (int xx = 0; xx < SizeX; xx++)
284 for (int yy = 0; yy < SizeY; yy++)
285 m_heightmap[xx, yy] = cmap[ind++];
286 // m_log.DebugFormat("{0} new by compressed map. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
287 }
288
289 // Create a heighmap from a database blob
290 public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) : this(pSizeX, pSizeY, pSizeZ)
291 {
292 switch ((DBTerrainRevision)pFormatCode)
293 {
294 case DBTerrainRevision.Compressed2D:
295 FromCompressedTerrainSerialization(pBlob);
296 m_log.DebugFormat("{0} HeightmapTerrainData create from Compressed2D serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY);
297 break;
298 default:
299 FromLegacyTerrainSerialization(pBlob);
300 m_log.DebugFormat("{0} HeightmapTerrainData create from legacy serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY);
301 break;
302 }
303 }
304
305 // Just create an array of doubles. Presumes the caller implicitly knows the size.
306 public Array ToLegacyTerrainSerialization()
307 {
308 Array ret = null;
309
310 using (MemoryStream str = new MemoryStream((int)Constants.RegionSize * (int)Constants.RegionSize * sizeof(double)))
311 {
312 using (BinaryWriter bw = new BinaryWriter(str))
313 {
314 for (int xx = 0; xx < Constants.RegionSize; xx++)
315 {
316 for (int yy = 0; yy < Constants.RegionSize; yy++)
317 {
318 double height = this[xx, yy];
319 if (height == 0.0)
320 height = double.Epsilon;
321 bw.Write(height);
322 }
323 }
324 }
325 ret = str.ToArray();
326 }
327 return ret;
328 }
329
330 // Just create an array of doubles. Presumes the caller implicitly knows the size.
331 public void FromLegacyTerrainSerialization(byte[] pBlob)
332 {
333 // In case database info doesn't match real terrain size, initialize the whole terrain.
334 ClearLand();
335
336 using (MemoryStream mstr = new MemoryStream(pBlob))
337 {
338 using (BinaryReader br = new BinaryReader(mstr))
339 {
340 for (int xx = 0; xx < (int)Constants.RegionSize; xx++)
341 {
342 for (int yy = 0; yy < (int)Constants.RegionSize; yy++)
343 {
344 float val = (float)br.ReadDouble();
345 if (xx < SizeX && yy < SizeY)
346 m_heightmap[xx, yy] = ToCompressedHeight(val);
347 }
348 }
349 }
350 ClearTaint();
351 }
352 }
353
354 // See the reader below.
355 public Array ToCompressedTerrainSerialization()
356 {
357 Array ret = null;
358 using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(Int16))))
359 {
360 using (BinaryWriter bw = new BinaryWriter(str))
361 {
362 bw.Write((Int32)DBTerrainRevision.Compressed2D);
363 bw.Write((Int32)SizeX);
364 bw.Write((Int32)SizeY);
365 bw.Write((Int32)CompressionFactor);
366 for (int yy = 0; yy < SizeY; yy++)
367 for (int xx = 0; xx < SizeX; xx++)
368 {
369 bw.Write((Int16)m_heightmap[xx, yy]);
370 }
371 }
372 ret = str.ToArray();
373 }
374 return ret;
375 }
376
377 // Initialize heightmap from blob consisting of:
378 // int32, int32, int32, int32, int16[]
379 // where the first int32 is format code, next two int32s are the X and y of heightmap data and
380 // the forth int is the compression factor for the following int16s
381 // This is just sets heightmap info. The actual size of the region was set on this instance's
382 // creation and any heights not initialized by theis blob are set to the default height.
383 public void FromCompressedTerrainSerialization(byte[] pBlob)
384 {
385 Int32 hmFormatCode, hmSizeX, hmSizeY, hmCompressionFactor;
386
387 using (MemoryStream mstr = new MemoryStream(pBlob))
388 {
389 using (BinaryReader br = new BinaryReader(mstr))
390 {
391 hmFormatCode = br.ReadInt32();
392 hmSizeX = br.ReadInt32();
393 hmSizeY = br.ReadInt32();
394 hmCompressionFactor = br.ReadInt32();
395
396 m_compressionFactor = hmCompressionFactor;
397
398 // In case database info doesn't match real terrain size, initialize the whole terrain.
399 ClearLand();
400
401 for (int yy = 0; yy < hmSizeY; yy++)
402 {
403 for (int xx = 0; xx < hmSizeX; xx++)
404 {
405 Int16 val = br.ReadInt16();
406 if (xx < SizeX && yy < SizeY)
407 m_heightmap[xx, yy] = val;
408 }
409 }
410 }
411 ClearTaint();
412
413 m_log.InfoFormat("{0} Read compressed 2d heightmap. Heightmap size=<{1},{2}>. Region size=<{3},{4}>. CompFact={5}",
414 LogHeader, hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor);
415 }
416 }
417 }
418}
diff --git a/OpenSim/Framework/UserProfileData.cs b/OpenSim/Framework/UserProfileData.cs
index 9bac739..266ccf0 100644
--- a/OpenSim/Framework/UserProfileData.cs
+++ b/OpenSim/Framework/UserProfileData.cs
@@ -160,15 +160,19 @@ namespace OpenSim.Framework
160 public virtual ulong HomeRegion 160 public virtual ulong HomeRegion
161 { 161 {
162 get 162 get
163 { 163 {
164 return Utils.UIntsToLong( 164 return Util.RegionWorldLocToHandle(Util.RegionToWorldLoc(m_homeRegionX), Util.RegionToWorldLoc(m_homeRegionY));
165 m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize); 165 // return Utils.UIntsToLong( m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize);
166 } 166 }
167 167
168 set 168 set
169 { 169 {
170 m_homeRegionX = (uint) (value >> 40); 170 uint regionWorldLocX, regionWorldLocY;
171 m_homeRegionY = (((uint) (value)) >> 8); 171 Util.RegionHandleToWorldLoc(value, out regionWorldLocX, out regionWorldLocY);
172 m_homeRegionX = Util.WorldToRegionLoc(regionWorldLocX);
173 m_homeRegionY = Util.WorldToRegionLoc(regionWorldLocY);
174 // m_homeRegionX = (uint) (value >> 40);
175 // m_homeRegionY = (((uint) (value)) >> 8);
172 } 176 }
173 } 177 }
174 178
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 0a6ae98..1e36853 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -266,10 +266,19 @@ namespace OpenSim
266 SavePrimsXml2); 266 SavePrimsXml2);
267 267
268 m_console.Commands.AddCommand("Archiving", false, "load oar", 268 m_console.Commands.AddCommand("Archiving", false, "load oar",
269 "load oar [--merge] [--skip-assets] [<OAR path>]", 269 "load oar [--merge] [--skip-assets]"
270 + " [--forceterrain] [--forceparcels]"
271 + " [--rotation degrees] [--rotationCenter \"<x,y,z>\"]"
272 + " [--displacement \"<x,y,z>\"]"
273 + " [<OAR path>]",
270 "Load a region's data from an OAR archive.", 274 "Load a region's data from an OAR archive.",
271 "--merge will merge the OAR with the existing scene." + Environment.NewLine 275 "--merge will merge the OAR with the existing scene (suppresses terrain and parcel info loading)." + Environment.NewLine
272 + "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine 276 + "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine
277 + "--displacement will add this value to the position of every object loaded" + Environment.NewLine
278 + "--forceterrain forces the loading of terrain from the oar (undoes suppression done by --merge)" + Environment.NewLine
279 + "--forceparcels forces the loading of parcels from the oar (undoes suppression done by --merge)" + Environment.NewLine
280 + "--rotation specified rotation to be applied to the oar. Specified in degrees." + Environment.NewLine
281 + "--rotationcenter Location (relative to original OAR) to apply rotation. Default is <128,128,0>" + Environment.NewLine
273 + "The path can be either a filesystem location or a URI." 282 + "The path can be either a filesystem location or a URI."
274 + " If this is not given then the command looks for an OAR named region.oar in the current directory.", 283 + " If this is not given then the command looks for an OAR named region.oar in the current directory.",
275 LoadOar); 284 LoadOar);
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 308638c..0dc9306 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -690,7 +690,8 @@ namespace OpenSim
690 clientServer = clientNetworkServers; 690 clientServer = clientNetworkServers;
691 scene.LoadWorldMap(); 691 scene.LoadWorldMap();
692 692
693 scene.PhysicsScene = GetPhysicsScene(scene.RegionInfo.RegionName); 693 Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ);
694 scene.PhysicsScene = GetPhysicsScene(scene.RegionInfo.RegionName, regionExtent);
694 scene.PhysicsScene.RequestAssetMethod = scene.PhysicsRequestAsset; 695 scene.PhysicsScene.RequestAssetMethod = scene.PhysicsRequestAsset;
695 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); 696 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
696 scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight); 697 scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight);
@@ -752,10 +753,10 @@ namespace OpenSim
752 753
753 # region Setup methods 754 # region Setup methods
754 755
755 protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier) 756 protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier, Vector3 regionExtent)
756 { 757 {
757 return GetPhysicsScene( 758 return GetPhysicsScene(
758 m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, Config, osSceneIdentifier); 759 m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, Config, osSceneIdentifier, regionExtent);
759 } 760 }
760 761
761 /// <summary> 762 /// <summary>
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
index a05e88c..f98337d 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
@@ -59,6 +59,7 @@ namespace OpenSim.Region.ClientStack.Linden
59 public class EventQueueGetModule : IEventQueue, INonSharedRegionModule 59 public class EventQueueGetModule : IEventQueue, INonSharedRegionModule
60 { 60 {
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62 private static string LogHeader = "[EVENT QUEUE GET MODULE]";
62 63
63 /// <value> 64 /// <value>
64 /// Debug level. 65 /// Debug level.
@@ -714,7 +715,7 @@ namespace OpenSim.Region.ClientStack.Linden
714 public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY) 715 public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY)
715 { 716 {
716 m_log.DebugFormat("{0} EnableSimulator. handle={1}, avatarID={2}, regionSize={3},{4}>", 717 m_log.DebugFormat("{0} EnableSimulator. handle={1}, avatarID={2}, regionSize={3},{4}>",
717 "[EVENT QUEUE GET MODULE]", handle, avatarID, regionSizeX, regionSizeY); 718 LogHeader, handle, avatarID, regionSizeX, regionSizeY);
718 719
719 OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY); 720 OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY);
720 Enqueue(item, avatarID); 721 Enqueue(item, avatarID);
@@ -724,7 +725,7 @@ namespace OpenSim.Region.ClientStack.Linden
724 ulong regionHandle, int regionSizeX, int regionSizeY) 725 ulong regionHandle, int regionSizeX, int regionSizeY)
725 { 726 {
726 m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, avatarID={2}, regionSize={3},{4}>", 727 m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, avatarID={2}, regionSize={3},{4}>",
727 "[EVENT QUEUE GET MODULE]", regionHandle, avatarID, regionSizeX, regionSizeY); 728 LogHeader, regionHandle, avatarID, regionSizeX, regionSizeY);
728 OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath, regionHandle, regionSizeX, regionSizeY); 729 OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath, regionHandle, regionSizeX, regionSizeY);
729 Enqueue(item, avatarID); 730 Enqueue(item, avatarID);
730 } 731 }
@@ -734,8 +735,8 @@ namespace OpenSim.Region.ClientStack.Linden
734 uint locationID, uint flags, string capsURL, 735 uint locationID, uint flags, string capsURL,
735 UUID avatarID, int regionSizeX, int regionSizeY) 736 UUID avatarID, int regionSizeX, int regionSizeY)
736 { 737 {
737 m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, avatarID={2}, regionSize={3},{4}>", 738 m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, avatarID={2}, regionSize=<{3},{4}>",
738 "[EVENT QUEUE GET MODULE]", regionHandle, avatarID, regionSizeX, regionSizeY); 739 LogHeader, regionHandle, avatarID, regionSizeX, regionSizeY);
739 740
740 OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint, 741 OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint,
741 locationID, flags, capsURL, avatarID, regionSizeX, regionSizeY); 742 locationID, flags, capsURL, avatarID, regionSizeX, regionSizeY);
@@ -747,7 +748,7 @@ namespace OpenSim.Region.ClientStack.Linden
747 string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY) 748 string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY)
748 { 749 {
749 m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>", 750 m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>",
750 "[EVENT QUEUE GET MODULE]", handle, avatarID, regionSizeX, regionSizeY); 751 LogHeader, handle, avatarID, regionSizeX, regionSizeY);
751 752
752 OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint, 753 OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint,
753 capsURL, avatarID, sessionID, regionSizeX, regionSizeY); 754 capsURL, avatarID, sessionID, regionSizeX, regionSizeY);
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
index ded228d..384af74 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
@@ -77,8 +77,8 @@ namespace OpenSim.Region.ClientStack.Linden
77 llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle))); 77 llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle)));
78 llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes())); 78 llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes()));
79 llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port)); 79 llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port));
80 llsdSimInfo.Add("RegionSizeX", new OSDInteger(regionSizeX)); 80 llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint) regionSizeX));
81 llsdSimInfo.Add("RegionSizeY", new OSDInteger(regionSizeY)); 81 llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint) regionSizeY));
82 82
83 OSDArray arr = new OSDArray(1); 83 OSDArray arr = new OSDArray(1);
84 arr.Add(llsdSimInfo); 84 arr.Add(llsdSimInfo);
@@ -138,8 +138,8 @@ namespace OpenSim.Region.ClientStack.Linden
138 regionDataMap.Add("SeedCapability", OSD.FromString(capsURL)); 138 regionDataMap.Add("SeedCapability", OSD.FromString(capsURL));
139 regionDataMap.Add("SimIP", OSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes())); 139 regionDataMap.Add("SimIP", OSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes()));
140 regionDataMap.Add("SimPort", OSD.FromInteger(newRegionExternalEndPoint.Port)); 140 regionDataMap.Add("SimPort", OSD.FromInteger(newRegionExternalEndPoint.Port));
141 regionDataMap.Add("RegionSizeX", new OSDInteger(regionSizeX)); 141 regionDataMap.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
142 regionDataMap.Add("RegionSizeY", new OSDInteger(regionSizeY)); 142 regionDataMap.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
143 143
144 OSDArray regionDataArr = new OSDArray(1); 144 OSDArray regionDataArr = new OSDArray(1);
145 regionDataArr.Add(regionDataMap); 145 regionDataArr.Add(regionDataMap);
@@ -166,8 +166,8 @@ namespace OpenSim.Region.ClientStack.Linden
166 info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); 166 info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes()));
167 info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); 167 info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port));
168 info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation 168 info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
169 info.Add("RegionSizeX", new OSDInteger(regionSizeX)); 169 info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
170 info.Add("RegionSizeY", new OSDInteger(regionSizeY)); 170 info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
171 171
172 OSDArray infoArr = new OSDArray(); 172 OSDArray infoArr = new OSDArray();
173 infoArr.Add(info); 173 infoArr.Add(info);
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 3a0ddae..585cdc4 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 }
@@ -1153,7 +1154,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1153 /// <param name="map">heightmap</param> 1154 /// <param name="map">heightmap</param>
1154 public virtual void SendLayerData(float[] map) 1155 public virtual void SendLayerData(float[] map)
1155 { 1156 {
1156 Util.FireAndForget(DoSendLayerData, map); 1157 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData());
1157 } 1158 }
1158 1159
1159 /// <summary> 1160 /// <summary>
@@ -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 TerrainData map = (TerrainData)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++)
@@ -1175,7 +1177,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1175 //} 1177 //}
1176 1178
1177 // Send LayerData in a spiral pattern. Fun! 1179 // Send LayerData in a spiral pattern. Fun!
1178 SendLayerTopRight(map, 0, 0, 15, 15); 1180 SendLayerTopRight(map, 0, 0, map.SizeX/Constants.TerrainPatchSize-1, map.SizeY/Constants.TerrainPatchSize-1);
1179 } 1181 }
1180 catch (Exception e) 1182 catch (Exception e)
1181 { 1183 {
@@ -1183,7 +1185,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1183 } 1185 }
1184 } 1186 }
1185 1187
1186 private void SendLayerTopRight(float[] map, int x1, int y1, int x2, int y2) 1188 private void SendLayerTopRight(TerrainData map, int x1, int y1, int x2, int y2)
1187 { 1189 {
1188 // Row 1190 // Row
1189 for (int i = x1; i <= x2; i++) 1191 for (int i = x1; i <= x2; i++)
@@ -1193,11 +1195,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1193 for (int j = y1 + 1; j <= y2; j++) 1195 for (int j = y1 + 1; j <= y2; j++)
1194 SendLayerData(x2, j, map); 1196 SendLayerData(x2, j, map);
1195 1197
1196 if (x2 - x1 > 0) 1198 if (x2 - x1 > 0 && y2 - y1 > 0)
1197 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2); 1199 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2);
1198 } 1200 }
1199 1201
1200 void SendLayerBottomLeft(float[] map, int x1, int y1, int x2, int y2) 1202 void SendLayerBottomLeft(TerrainData map, int x1, int y1, int x2, int y2)
1201 { 1203 {
1202 // Row in reverse 1204 // Row in reverse
1203 for (int i = x2; i >= x1; i--) 1205 for (int i = x2; i >= x1; i--)
@@ -1207,7 +1209,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1207 for (int j = y2 - 1; j >= y1; j--) 1209 for (int j = y2 - 1; j >= y1; j--)
1208 SendLayerData(x1, j, map); 1210 SendLayerData(x1, j, map);
1209 1211
1210 if (x2 - x1 > 0) 1212 if (x2 - x1 > 0 && y2 - y1 > 0)
1211 SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1); 1213 SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1);
1212 } 1214 }
1213 1215
@@ -1229,22 +1231,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1229 // OutPacket(layerpack, ThrottleOutPacketType.Land); 1231 // OutPacket(layerpack, ThrottleOutPacketType.Land);
1230 // } 1232 // }
1231 1233
1234 // Legacy form of invocation that passes around a bare data array.
1235 // Just ignore what was passed and use the real terrain info that is part of the scene.
1236 public void SendLayerData(int px, int py, float[] map)
1237 {
1238 SendLayerData(px, py, m_scene.Heightmap.GetTerrainData());
1239 }
1240
1232 /// <summary> 1241 /// <summary>
1233 /// Sends a specified patch to a client 1242 /// Sends a terrain packet for the point specified.
1243 /// This is a legacy call that has refarbed the terrain into a flat map of floats.
1244 /// We just use the terrain from the region we know about.
1234 /// </summary> 1245 /// </summary>
1235 /// <param name="px">Patch coordinate (x) 0..15</param> 1246 /// <param name="px">Patch coordinate (x) 0..15</param>
1236 /// <param name="py">Patch coordinate (y) 0..15</param> 1247 /// <param name="py">Patch coordinate (y) 0..15</param>
1237 /// <param name="map">heightmap</param> 1248 /// <param name="map">heightmap</param>
1238 public void SendLayerData(int px, int py, float[] map) 1249 public void SendLayerData(int px, int py, TerrainData terrData)
1239 { 1250 {
1240 try 1251 try
1241 { 1252 {
1242 int[] patches = new int[] { py * 16 + px }; 1253 LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(terrData, px, py);
1243 float[] heightmap = (map.Length == 65536) ?
1244 map :
1245 LLHeightFieldMoronize(map);
1246
1247 LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(heightmap, patches);
1248 1254
1249 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a sub optimal editing experience. 1255 // 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. 1256 // To alleviate this issue, when the user edits the terrain, we start skipping the queues until they're done editing the terrain.
@@ -1262,14 +1268,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1262 if (m_justEditedTerrain) 1268 if (m_justEditedTerrain)
1263 { 1269 {
1264 layerpack.Header.Reliable = false; 1270 layerpack.Header.Reliable = false;
1265 OutPacket(layerpack, 1271 OutPacket(layerpack, ThrottleOutPacketType.Unknown );
1266 ThrottleOutPacketType.Unknown );
1267 } 1272 }
1268 else 1273 else
1269 { 1274 {
1270 layerpack.Header.Reliable = true; 1275 layerpack.Header.Reliable = true;
1271 OutPacket(layerpack, 1276 OutPacket(layerpack, ThrottleOutPacketType.Land);
1272 ThrottleOutPacketType.Land);
1273 } 1277 }
1274 } 1278 }
1275 catch (Exception e) 1279 catch (Exception e)
@@ -1279,38 +1283,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1279 } 1283 }
1280 1284
1281 /// <summary> 1285 /// <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 1286 /// Send the wind matrix to the client
1315 /// </summary> 1287 /// </summary>
1316 /// <param name="windSpeeds">16x16 array of wind speeds</param> 1288 /// <param name="windSpeeds">16x16 array of wind speeds</param>
@@ -2785,8 +2757,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2785 { 2757 {
2786 if (req.AssetInf.Data == null) 2758 if (req.AssetInf.Data == null)
2787 { 2759 {
2788 m_log.ErrorFormat("Cannot send asset {0} ({1}), asset data is null", 2760 m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset data is null",
2789 req.AssetInf.ID, req.AssetInf.Metadata.ContentType); 2761 LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
2790 return; 2762 return;
2791 } 2763 }
2792 2764
@@ -8970,6 +8942,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
8970 TeleportLocationRequest handlerTeleportLocationRequest = OnTeleportLocationRequest; 8942 TeleportLocationRequest handlerTeleportLocationRequest = OnTeleportLocationRequest;
8971 if (handlerTeleportLocationRequest != null) 8943 if (handlerTeleportLocationRequest != null)
8972 { 8944 {
8945 // Adjust teleport location to base of a larger region if requested to teleport to a sub-region
8946 uint locX, locY;
8947 Util.RegionHandleToWorldLoc(tpLocReq.Info.RegionHandle, out locX, out locY);
8948 if ((locX >= m_scene.RegionInfo.WorldLocX)
8949 && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
8950 && (locY >= m_scene.RegionInfo.WorldLocY)
8951 && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)) )
8952 {
8953 tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
8954 tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
8955 tpLocReq.Info.Position.Y += locY - m_scene.RegionInfo.WorldLocY;
8956 }
8957
8973 handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position, 8958 handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
8974 tpLocReq.Info.LookAt, 16); 8959 tpLocReq.Info.LookAt, 16);
8975 } 8960 }
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
index 853b72d..1ce166e 100644
--- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs
+++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
@@ -69,7 +69,7 @@ namespace OpenSim.Region.ClientStack
69 /// The name of the OpenSim scene this physics scene is serving. This will be used in log messages. 69 /// The name of the OpenSim scene this physics scene is serving. This will be used in log messages.
70 /// </param> 70 /// </param>
71 /// <returns></returns> 71 /// <returns></returns>
72 protected abstract PhysicsScene GetPhysicsScene(string osSceneIdentifier); 72 protected abstract PhysicsScene GetPhysicsScene(string osSceneIdentifier, Vector3 regionExtent);
73 73
74 protected abstract ClientStackManager CreateClientStackManager(); 74 protected abstract ClientStackManager CreateClientStackManager();
75 protected abstract Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService, IEstateDataService estateDataService, AgentCircuitManager circuitManager); 75 protected abstract Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService, IEstateDataService estateDataService, AgentCircuitManager circuitManager);
@@ -123,13 +123,13 @@ namespace OpenSim.Region.ClientStack
123 /// </param> 123 /// </param>
124 /// <returns></returns> 124 /// <returns></returns>
125 protected PhysicsScene GetPhysicsScene( 125 protected PhysicsScene GetPhysicsScene(
126 string engine, string meshEngine, IConfigSource config, string osSceneIdentifier) 126 string engine, string meshEngine, IConfigSource config, string osSceneIdentifier, Vector3 regionExtent)
127 { 127 {
128 PhysicsPluginManager physicsPluginManager; 128 PhysicsPluginManager physicsPluginManager;
129 physicsPluginManager = new PhysicsPluginManager(); 129 physicsPluginManager = new PhysicsPluginManager();
130 physicsPluginManager.LoadPluginsFromAssemblies("Physics"); 130 physicsPluginManager.LoadPluginsFromAssemblies("Physics");
131 131
132 return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config, osSceneIdentifier); 132 return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config, osSceneIdentifier, regionExtent);
133 } 133 }
134 } 134 }
135} \ No newline at end of file 135} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs
index d9b0eff..732781a 100644
--- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing;
30using System.IO; 31using System.IO;
31using System.Reflection; 32using System.Reflection;
32using System.Text; 33using System.Text;
@@ -182,6 +183,25 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
182 return DoJ2KDecode(assetID, j2kData, out layers, out components); 183 return DoJ2KDecode(assetID, j2kData, out layers, out components);
183 } 184 }
184 185
186 public Image DecodeToImage(byte[] j2kData)
187 {
188 if (m_useCSJ2K)
189 return J2kImage.FromBytes(j2kData);
190 else
191 {
192 ManagedImage mimage;
193 Image image;
194 if (OpenJPEG.DecodeToImage(j2kData, out mimage, out image))
195 {
196 mimage = null;
197 return image;
198 }
199 else
200 return null;
201 }
202 }
203
204
185 #endregion IJ2KDecoder 205 #endregion IJ2KDecoder
186 206
187 /// <summary> 207 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
index 27ace68..10122e6 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.WorldLocX, scene.RegionInfo.WorldLocY, 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.WorldLocX, presence.Scene.RegionInfo.WorldLocY, 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 bfa30e6..7e50cc6 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -667,8 +667,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
667 667
668 Vector3 avaPos = p.AbsolutePosition; 668 Vector3 avaPos = p.AbsolutePosition;
669 // Getting the global position for the Avatar 669 // Getting the global position for the Avatar
670 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionLocX*Constants.RegionSize + avaPos.X, 670 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X,
671 remoteClient.Scene.RegionInfo.RegionLocY*Constants.RegionSize + avaPos.Y, 671 remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y,
672 avaPos.Z); 672 avaPos.Z);
673 673
674 string landOwnerName = string.Empty; 674 string landOwnerName = string.Empty;
diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
index 6545a99..13cc99a 100644
--- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -269,9 +269,7 @@ namespace OpenSim.Region.CoreModules.Framework
269 foreach (KeyValuePair<ulong, string> kvp in m_childrenSeeds[agentID]) 269 foreach (KeyValuePair<ulong, string> kvp in m_childrenSeeds[agentID])
270 { 270 {
271 uint x, y; 271 uint x, y;
272 Utils.LongToUInts(kvp.Key, out x, out y); 272 Util.RegionHandleToRegionLoc(kvp.Key, out x, out y);
273 x = x / Constants.RegionSize;
274 y = y / Constants.RegionSize;
275 m_log.Info(" >> "+x+", "+y+": "+kvp.Value); 273 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
276 } 274 }
277 } 275 }
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index 5fea0cf..a038f73 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -51,7 +51,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
51 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EntityTransferModule")] 51 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EntityTransferModule")]
52 public class EntityTransferModule : INonSharedRegionModule, IEntityTransferModule 52 public class EntityTransferModule : INonSharedRegionModule, IEntityTransferModule
53 { 53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 private static readonly string LogHeader = "[ENTITY TRANSFER MODULE]"; 55 private static readonly string LogHeader = "[ENTITY TRANSFER MODULE]";
56 56
57 public const int DefaultMaxTransferDistance = 4095; 57 public const int DefaultMaxTransferDistance = 4095;
@@ -121,8 +121,53 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
121 /// </summary> 121 /// </summary>
122 private EntityTransferStateMachine m_entityTransferStateMachine; 122 private EntityTransferStateMachine m_entityTransferStateMachine;
123 123
124 private ExpiringCache<UUID, ExpiringCache<ulong, DateTime>> m_bannedRegions = 124 // For performance, we keed a cached of banned regions so we don't keep going
125 new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>(); 125 // to the grid service.
126 private class BannedRegionCache
127 {
128 private ExpiringCache<UUID, ExpiringCache<ulong, DateTime>> m_bannedRegions =
129 new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>();
130 ExpiringCache<ulong, DateTime> m_idCache;
131 DateTime m_banUntil;
132 public BannedRegionCache()
133 {
134 }
135 // Return 'true' if there is a valid ban entry for this agent in this region
136 public bool IfBanned(ulong pRegionHandle, UUID pAgentID)
137 {
138 bool ret = false;
139 if (m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
140 {
141 if (m_idCache.TryGetValue(pRegionHandle, out m_banUntil))
142 {
143 if (DateTime.Now < m_banUntil)
144 {
145 ret = true;
146 }
147 }
148 }
149 return ret;
150 }
151 // Add this agent in this region as a banned person
152 public void Add(ulong pRegionHandle, UUID pAgentID)
153 {
154 if (!m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
155 {
156 m_idCache = new ExpiringCache<ulong, DateTime>();
157 m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(45));
158 }
159 m_idCache.Add(pRegionHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
160 }
161 // Remove the agent from the region's banned list
162 public void Remove(ulong pRegionHandle, UUID pAgentID)
163 {
164 if (m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
165 {
166 m_idCache.Remove(pRegionHandle);
167 }
168 }
169 }
170 private BannedRegionCache m_bannedRegionCache = new BannedRegionCache();
126 171
127 private IEventQueue m_eqModule; 172 private IEventQueue m_eqModule;
128 private IRegionCombinerModule m_regionCombinerModule; 173 private IRegionCombinerModule m_regionCombinerModule;
@@ -337,6 +382,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
337 "[ENTITY TRANSFER MODULE]: Received teleport cancel request from {0} in {1}", client.Name, Scene.Name); 382 "[ENTITY TRANSFER MODULE]: Received teleport cancel request from {0} in {1}", client.Name, Scene.Name);
338 } 383 }
339 384
385 // Attempt to teleport the ScenePresence to the specified position in the specified region (spec'ed by its handle).
340 public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags) 386 public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags)
341 { 387 {
342 if (sp.Scene.Permissions.IsGridGod(sp.UUID)) 388 if (sp.Scene.Permissions.IsGridGod(sp.UUID))
@@ -434,10 +480,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
434 float posZLimit = 22; 480 float posZLimit = 22;
435 481
436 // TODO: Check other Scene HeightField 482 // TODO: Check other Scene HeightField
437 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize) 483 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
438 {
439 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
440 }
441 484
442 float newPosZ = posZLimit + localAVHeight; 485 float newPosZ = posZLimit + localAVHeight;
443 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 486 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
@@ -480,9 +523,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
480 ScenePresence sp, ulong regionHandle, Vector3 position, 523 ScenePresence sp, ulong regionHandle, Vector3 position,
481 Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination) 524 Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination)
482 { 525 {
483 uint x = 0, y = 0; 526 // Get destination region taking into account that the address could be an offset
484 Utils.LongToUInts(regionHandle, out x, out y); 527 // region inside a varregion.
485 GridRegion reg = Scene.GridService.GetRegionByPosition(sp.Scene.RegionInfo.ScopeID, (int)x, (int)y); 528 GridRegion reg = GetTeleportDestinationRegion(sp.Scene.GridService, sp.Scene.RegionInfo.ScopeID, regionHandle, ref position);
486 529
487 if (reg != null) 530 if (reg != null)
488 { 531 {
@@ -490,9 +533,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
490 533
491 if (finalDestination == null) 534 if (finalDestination == null)
492 { 535 {
493 m_log.WarnFormat( 536 m_log.WarnFormat( "{0} Final destination is having problems. Unable to teleport {1} {2}",
494 "[ENTITY TRANSFER MODULE]: Final destination is having problems. Unable to teleport {0} {1}", 537 LogHeader, sp.Name, sp.UUID);
495 sp.Name, sp.UUID);
496 538
497 sp.ControllingClient.SendTeleportFailed("Problem at destination"); 539 sp.ControllingClient.SendTeleportFailed("Problem at destination");
498 return; 540 return;
@@ -533,11 +575,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
533 575
534 // and set the map-tile to '(Offline)' 576 // and set the map-tile to '(Offline)'
535 uint regX, regY; 577 uint regX, regY;
536 Utils.LongToUInts(regionHandle, out regX, out regY); 578 Util.RegionHandleToRegionLoc(regionHandle, out regX, out regY);
537 579
538 MapBlockData block = new MapBlockData(); 580 MapBlockData block = new MapBlockData();
539 block.X = (ushort)(regX / Constants.RegionSize); 581 block.X = (ushort)regX;
540 block.Y = (ushort)(regY / Constants.RegionSize); 582 block.Y = (ushort)regY;
541 block.Access = 254; // == not there 583 block.Access = 254; // == not there
542 584
543 List<MapBlockData> blocks = new List<MapBlockData>(); 585 List<MapBlockData> blocks = new List<MapBlockData>();
@@ -546,6 +588,31 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
546 } 588 }
547 } 589 }
548 590
591 // The teleport address could be an address in a subregion of a larger varregion.
592 // Find the real base region and adjust the teleport location to account for the
593 // larger region.
594 private GridRegion GetTeleportDestinationRegion(IGridService gridService, UUID scope, ulong regionHandle, ref Vector3 position)
595 {
596 uint x = 0, y = 0;
597 Util.RegionHandleToWorldLoc(regionHandle, out x, out y);
598
599 // Compute the world location we're teleporting to
600 double worldX = (double)x + position.X;
601 double worldY = (double)y + position.Y;
602
603 // Find the region that contains the position
604 GridRegion reg = GetRegionContainingWorldLocation(gridService, scope, worldX, worldY);
605
606 if (reg != null)
607 {
608 // modify the position for the offset into the actual region returned
609 position.X += x - reg.RegionLocX;
610 position.Y += y - reg.RegionLocY;
611 }
612
613 return reg;
614 }
615
549 // Nothing to validate here 616 // Nothing to validate here
550 protected virtual bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason) 617 protected virtual bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason)
551 { 618 {
@@ -1349,6 +1416,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1349 if (uinfo.HomeRegionID == UUID.Zero) 1416 if (uinfo.HomeRegionID == UUID.Zero)
1350 { 1417 {
1351 // can't find the Home region: Tell viewer and abort 1418 // can't find the Home region: Tell viewer and abort
1419 m_log.ErrorFormat("{0} No grid user info found for {1} {2}. Cannot send home.",
1420 LogHeader, client.Name, client.AgentId);
1352 client.SendTeleportFailed("You don't have a home position set."); 1421 client.SendTeleportFailed("You don't have a home position set.");
1353 return false; 1422 return false;
1354 } 1423 }
@@ -1382,7 +1451,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1382 1451
1383 #region Agent Crossings 1452 #region Agent Crossings
1384 1453
1385 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out uint xDest, out uint yDest, out string version, out Vector3 newpos) 1454 // Given a position relative to the current region (which has previously been tested to
1455 // see that it is actually outside the current region), find the new region that the
1456 // point is actually in.
1457 // Returns the coordinates and information of the new region or 'null' of it doesn't exist.
1458 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version, out Vector3 newpos)
1386 { 1459 {
1387 version = String.Empty; 1460 version = String.Empty;
1388 newpos = pos; 1461 newpos = pos;
@@ -1390,131 +1463,54 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1390// m_log.DebugFormat( 1463// m_log.DebugFormat(
1391// "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name); 1464// "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name);
1392 1465
1393 uint neighbourx = scene.RegionInfo.RegionLocX; 1466 // Compute world location of the object's position
1394 uint neighboury = scene.RegionInfo.RegionLocY; 1467 double presenceWorldX = (double)scene.RegionInfo.WorldLocX + pos.X;
1395 const float boundaryDistance = 1.7f; 1468 double presenceWorldY = (double)scene.RegionInfo.WorldLocY + pos.Y;
1396 Vector3 northCross = new Vector3(0, boundaryDistance, 0);
1397 Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
1398 Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
1399 Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);
1400 1469
1401 // distance into new region to place avatar 1470 // Call the grid service to lookup the region containing the new position.
1402 const float enterDistance = 0.5f; 1471 GridRegion neighbourRegion = GetRegionContainingWorldLocation(scene.GridService, scene.RegionInfo.ScopeID,
1472 presenceWorldX, presenceWorldY,
1473 Math.Max(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY));
1403 1474
1404 if (scene.TestBorderCross(pos + westCross, Cardinals.W)) 1475 if (neighbourRegion != null)
1405 { 1476 {
1406 if (scene.TestBorderCross(pos + northCross, Cardinals.N)) 1477 // Compute the entity's position relative to the new region
1407 { 1478 newpos = new Vector3( (float)(presenceWorldX - (double)neighbourRegion.RegionLocX),
1408 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N); 1479 (float)(presenceWorldY - (double)neighbourRegion.RegionLocY),
1409 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize); 1480 pos.Z);
1410 }
1411 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1412 {
1413 neighboury--;
1414 newpos.Y = Constants.RegionSize - enterDistance;
1415 }
1416 1481
1417 neighbourx--; 1482 if (m_bannedRegionCache.IfBanned(neighbourRegion.RegionHandle, agentID))
1418 newpos.X = Constants.RegionSize - enterDistance;
1419 }
1420 else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
1421 {
1422 Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
1423 neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
1424 newpos.X = enterDistance;
1425
1426 if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1427 { 1483 {
1428 neighboury--; 1484 neighbourRegion = null;
1429 newpos.Y = Constants.RegionSize - enterDistance;
1430 } 1485 }
1431 else if (scene.TestBorderCross(pos + northCross, Cardinals.N)) 1486 else
1432 { 1487 {
1433 Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N); 1488 // If not banned, make sure this agent is not in the list.
1434 neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize); 1489 m_bannedRegionCache.Remove(neighbourRegion.RegionHandle, agentID);
1435 newpos.Y = enterDistance;
1436 } 1490 }
1437 }
1438 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1439 {
1440 Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
1441 neighboury--;
1442 newpos.Y = Constants.RegionSize - enterDistance;
1443 }
1444 else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
1445 {
1446 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
1447 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
1448 newpos.Y = enterDistance;
1449 }
1450 1491
1451 /* 1492 // Check to see if we have access to the target region.
1452 1493 string reason;
1453 if (pos.X < boundaryDistance) //West 1494 if (neighbourRegion != null
1454 { 1495 && !scene.SimulationService.QueryAccess(neighbourRegion, agentID, newpos, out version, out reason))
1455 neighbourx--;
1456 newpos.X = Constants.RegionSize - enterDistance;
1457 }
1458 else if (pos.X > Constants.RegionSize - boundaryDistance) // East
1459 {
1460 neighbourx++;
1461 newpos.X = enterDistance;
1462 }
1463
1464 if (pos.Y < boundaryDistance) // South
1465 {
1466 neighboury--;
1467 newpos.Y = Constants.RegionSize - enterDistance;
1468 }
1469 else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
1470 {
1471 neighboury++;
1472 newpos.Y = enterDistance;
1473 }
1474 */
1475
1476 xDest = neighbourx;
1477 yDest = neighboury;
1478
1479 int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);
1480
1481 ulong neighbourHandle = Utils.UIntsToLong((uint)x, (uint)y);
1482
1483 ExpiringCache<ulong, DateTime> r;
1484 DateTime banUntil;
1485
1486 if (m_bannedRegions.TryGetValue(agentID, out r))
1487 {
1488 if (r.TryGetValue(neighbourHandle, out banUntil))
1489 { 1496 {
1490 if (DateTime.Now < banUntil) 1497 // remember banned
1491 return null; 1498 m_bannedRegionCache.Add(neighbourRegion.RegionHandle, agentID);
1492 r.Remove(neighbourHandle); 1499 neighbourRegion = null;
1493 } 1500 }
1494 } 1501 }
1495 else
1496 {
1497 r = null;
1498 }
1499
1500 GridRegion neighbourRegion = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID, (int)x, (int)y);
1501 1502
1502 string reason; 1503 if (neighbourRegion == null)
1503 if (!scene.SimulationService.QueryAccess(neighbourRegion, agentID, newpos, out version, out reason)) 1504 m_log.DebugFormat("{0} GetDestination: region not found. Old region name={1} at <{2},{3}> of size <{4},{5}>. Old pos={6}",
1504 { 1505 LogHeader, scene.RegionInfo.RegionName,
1505 if (r == null) 1506 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
1506 { 1507 scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY,
1507 r = new ExpiringCache<ulong, DateTime>(); 1508 pos);
1508 r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15)); 1509 else
1509 1510 m_log.DebugFormat("{0} GetDestination: new region={1} at <{2},{3}> of size <{4},{5}>, newpos=<{6},{7}>",
1510 m_bannedRegions.Add(agentID, r, TimeSpan.FromSeconds(45)); 1511 LogHeader, neighbourRegion.RegionName,
1511 } 1512 neighbourRegion.RegionLocX, neighbourRegion.RegionLocY, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY,
1512 else 1513 newpos.X, newpos.Y);
1513 {
1514 r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
1515 }
1516 return null;
1517 }
1518 1514
1519 return neighbourRegion; 1515 return neighbourRegion;
1520 } 1516 }
@@ -1526,7 +1522,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1526 Vector3 newpos; 1522 Vector3 newpos;
1527 string version; 1523 string version;
1528 1524
1529 GridRegion neighbourRegion = GetDestination(agent.Scene, agent.UUID, agent.AbsolutePosition, out x, out y, out version, out newpos); 1525 GridRegion neighbourRegion = GetDestination(agent.Scene, agent.UUID, agent.AbsolutePosition, out version, out newpos);
1530 if (neighbourRegion == null) 1526 if (neighbourRegion == null)
1531 { 1527 {
1532 agent.ControllingClient.SendAlertMessage("Cannot region cross into banned parcel"); 1528 agent.ControllingClient.SendAlertMessage("Cannot region cross into banned parcel");
@@ -1568,7 +1564,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1568 1564
1569 agent.Scene.RequestTeleportLocation( 1565 agent.Scene.RequestTeleportLocation(
1570 agent.ControllingClient, 1566 agent.ControllingClient,
1571 Utils.UIntsToLong(regionX * (uint)Constants.RegionSize, regionY * (uint)Constants.RegionSize), 1567 Util.RegionLocToHandle(regionX, regionY),
1572 position, 1568 position,
1573 agent.Lookat, 1569 agent.Lookat,
1574 (uint)Constants.TeleportFlags.ViaLocation); 1570 (uint)Constants.TeleportFlags.ViaLocation);
@@ -1578,11 +1574,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1578 if (im != null) 1574 if (im != null)
1579 { 1575 {
1580 UUID gotoLocation = Util.BuildFakeParcelID( 1576 UUID gotoLocation = Util.BuildFakeParcelID(
1581 Util.UIntsToLong( 1577 Util.RegionLocToHandle(regionX, regionY),
1582 (regionX *
1583 (uint)Constants.RegionSize),
1584 (regionY *
1585 (uint)Constants.RegionSize)),
1586 (uint)(int)position.X, 1578 (uint)(int)position.X,
1587 (uint)(int)position.Y, 1579 (uint)(int)position.Y,
1588 (uint)(int)position.Z); 1580 (uint)(int)position.Z);
@@ -1635,17 +1627,22 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1635 /// Calls an asynchronous method to do so.. so it doesn't lag the sim. 1627 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
1636 /// </summary> 1628 /// </summary>
1637 public ScenePresence CrossAgentToNewRegionAsync( 1629 public ScenePresence CrossAgentToNewRegionAsync(
1638 ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, 1630 ScenePresence agent, Vector3 pos, GridRegion neighbourRegion,
1639 bool isFlying, string version) 1631 bool isFlying, string version)
1640 { 1632 {
1633 m_log.DebugFormat("{0} CrossAgentToNewRegionAsync: new region={1} at <{2},{3}>. newpos={4}",
1634 LogHeader, neighbourRegion.RegionName, neighbourRegion.RegionLocX, neighbourRegion.RegionLocY, pos);
1635
1641 if (!CrossAgentToNewRegionPrep(agent, neighbourRegion)) 1636 if (!CrossAgentToNewRegionPrep(agent, neighbourRegion))
1642 { 1637 {
1638 m_log.DebugFormat("{0} CrossAgentToNewRegionAsync: prep failed. Resetting transfer state", LogHeader);
1643 m_entityTransferStateMachine.ResetFromTransit(agent.UUID); 1639 m_entityTransferStateMachine.ResetFromTransit(agent.UUID);
1644 return agent; 1640 return agent;
1645 } 1641 }
1646 1642
1647 if (!CrossAgentIntoNewRegionMain(agent, pos, neighbourRegion, isFlying)) 1643 if (!CrossAgentIntoNewRegionMain(agent, pos, neighbourRegion, isFlying))
1648 { 1644 {
1645 m_log.DebugFormat("{0} CrossAgentToNewRegionAsync: cross main failed. Resetting transfer state", LogHeader);
1649 m_entityTransferStateMachine.ResetFromTransit(agent.UUID); 1646 m_entityTransferStateMachine.ResetFromTransit(agent.UUID);
1650 return agent; 1647 return agent;
1651 } 1648 }
@@ -2038,15 +2035,195 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2038 } 2035 }
2039 } 2036 }
2040 2037
2038 // Computes the difference between two region bases.
2039 // Returns a vector of world coordinates (meters) from base of first region to the second.
2040 // The first region is the home region of the passed scene presence.
2041 Vector3 CalculateOffset(ScenePresence sp, GridRegion neighbour) 2041 Vector3 CalculateOffset(ScenePresence sp, GridRegion neighbour)
2042 { 2042 {
2043 int rRegionX = (int)sp.Scene.RegionInfo.RegionLocX; 2043 /*
2044 int rRegionY = (int)sp.Scene.RegionInfo.RegionLocY; 2044 int rRegionX = (int)sp.Scene.RegionInfo.LegacyRegionLocX;
2045 int rRegionY = (int)sp.Scene.RegionInfo.LegacyRegionLocY;
2045 int tRegionX = neighbour.RegionLocX / (int)Constants.RegionSize; 2046 int tRegionX = neighbour.RegionLocX / (int)Constants.RegionSize;
2046 int tRegionY = neighbour.RegionLocY / (int)Constants.RegionSize; 2047 int tRegionY = neighbour.RegionLocY / (int)Constants.RegionSize;
2047 int shiftx = (rRegionX - tRegionX) * (int)Constants.RegionSize; 2048 int shiftx = (rRegionX - tRegionX) * (int)Constants.RegionSize;
2048 int shifty = (rRegionY - tRegionY) * (int)Constants.RegionSize; 2049 int shifty = (rRegionY - tRegionY) * (int)Constants.RegionSize;
2049 return new Vector3(shiftx, shifty, 0f); 2050 return new Vector3(shiftx, shifty, 0f);
2051 */
2052 return new Vector3( sp.Scene.RegionInfo.WorldLocX - neighbour.RegionLocX,
2053 sp.Scene.RegionInfo.WorldLocY - neighbour.RegionLocY,
2054 0f);
2055 }
2056
2057 public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID, double px, double py)
2058 {
2059 // Since we don't know how big the regions could be, we have to search a very large area
2060 // to find possible regions.
2061 return GetRegionContainingWorldLocation(pGridService, pScopeID, px, py, Constants.MaximumRegionSize);
2062 }
2063
2064 #region NotFoundLocationCache class
2065 // A collection of not found locations to make future lookups 'not found' lookups quick.
2066 // A simple expiring cache that keeps not found locations for some number of seconds.
2067 // A 'not found' location is presumed to be anywhere in the minimum sized region that
2068 // contains that point. A conservitive estimate.
2069 private class NotFoundLocationCache
2070 {
2071 private struct NotFoundLocation
2072 {
2073 public double minX, maxX, minY, maxY;
2074 public DateTime expireTime;
2075 }
2076 private List<NotFoundLocation> m_notFoundLocations = new List<NotFoundLocation>();
2077 public NotFoundLocationCache()
2078 {
2079 }
2080 // Add an area to the lost of 'not found' places. The area is the snapped region
2081 // area around the added point.
2082 public void Add(double pX, double pY)
2083 {
2084 lock (m_notFoundLocations)
2085 {
2086 if (!LockedContains(pX, pY))
2087 {
2088 NotFoundLocation nfl = new NotFoundLocation();
2089 // A not found location is not found for at least a whole region sized area
2090 nfl.minX = pX - (pX % (double)Constants.RegionSize);
2091 nfl.minY = pY - (pY % (double)Constants.RegionSize);
2092 nfl.maxX = nfl.minX + (double)Constants.RegionSize;
2093 nfl.maxY = nfl.minY + (double)Constants.RegionSize;
2094 nfl.expireTime = DateTime.Now + TimeSpan.FromSeconds(30);
2095 m_notFoundLocations.Add(nfl);
2096 }
2097 }
2098
2099 }
2100 // Test to see of this point is in any of the 'not found' areas.
2101 // Return 'true' if the point is found inside the 'not found' areas.
2102 public bool Contains(double pX, double pY)
2103 {
2104 bool ret = false;
2105 lock (m_notFoundLocations)
2106 ret = LockedContains(pX, pY);
2107 return ret;
2108 }
2109 private bool LockedContains(double pX, double pY)
2110 {
2111 bool ret = false;
2112 this.DoExpiration();
2113 foreach (NotFoundLocation nfl in m_notFoundLocations)
2114 {
2115 if (pX >= nfl.minX && pX < nfl.maxX && pY >= nfl.minY && pY < nfl.maxY)
2116 {
2117 ret = true;
2118 break;
2119 }
2120 }
2121 return ret;
2122 }
2123 private void DoExpiration()
2124 {
2125 List<NotFoundLocation> m_toRemove = null;
2126 DateTime now = DateTime.Now;
2127 foreach (NotFoundLocation nfl in m_notFoundLocations)
2128 {
2129 if (nfl.expireTime < now)
2130 {
2131 if (m_toRemove == null)
2132 m_toRemove = new List<NotFoundLocation>();
2133 m_toRemove.Add(nfl);
2134 }
2135 }
2136 if (m_toRemove != null)
2137 {
2138 foreach (NotFoundLocation nfl in m_toRemove)
2139 m_notFoundLocations.Remove(nfl);
2140 m_toRemove.Clear();
2141 }
2142 }
2143 }
2144 #endregion // NotFoundLocationCache class
2145 private NotFoundLocationCache m_notFoundLocationCache = new NotFoundLocationCache();
2146
2147 // Given a world position (fractional meter coordinate), get the GridRegion info for
2148 // the region containing that point.
2149 // Someday this should be a method on GridService.
2150 // 'pSizeHint' is the size of the source region but since the destination point can be anywhere
2151 // the size of the target region is unknown thus the search area might have to be very large.
2152 // Return 'null' if no such region exists.
2153 public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID,
2154 double px, double py, uint pSizeHint)
2155 {
2156 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: call, XY=<{1},{2}>", LogHeader, px, py);
2157 GridRegion ret = null;
2158 const double fudge = 2.0;
2159
2160 // One problem with this routine is negative results. That is, this can be called lots of times
2161 // for regions that don't exist. m_notFoundLocationCache remembers 'not found' results so they
2162 // will be quick 'not found's next time.
2163 // NotFoundLocationCache is an expiring cache so it will eventually forget about 'not found' and
2164 // thus re-ask the GridService about the location.
2165 if (m_notFoundLocationCache.Contains(px, py))
2166 {
2167 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found via cache. loc=<{1},{2}>", LogHeader, px, py);
2168 return null;
2169 }
2170
2171 // As an optimization, since most regions will be legacy sized regions (256x256), first try to get
2172 // the region at the appropriate legacy region location.
2173 uint possibleX = (uint)Math.Floor(px);
2174 possibleX -= possibleX % Constants.RegionSize;
2175 uint possibleY = (uint)Math.Floor(py);
2176 possibleY -= possibleY % Constants.RegionSize;
2177 ret = pGridService.GetRegionByPosition(pScopeID, (int)possibleX, (int)possibleY);
2178 if (ret != null)
2179 {
2180 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Found region using legacy size. rloc=<{1},{2}>. Rname={3}",
2181 LogHeader, possibleX, possibleY, ret.RegionName);
2182 }
2183
2184 if (ret == null)
2185 {
2186 // If the simple lookup failed, search the larger area for a region that contains this point
2187 double range = (double)pSizeHint + fudge;
2188 while (ret == null && range <= (Constants.MaximumRegionSize + Constants.RegionSize))
2189 {
2190 // Get from the grid service a list of regions that might contain this point.
2191 // The region origin will be in the zero direction so only subtract the range.
2192 List<GridRegion> possibleRegions = pGridService.GetRegionRange(pScopeID,
2193 (int)(px - range), (int)(px),
2194 (int)(py - range), (int)(py));
2195 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegions cnt={1}, range={2}",
2196 LogHeader, possibleRegions.Count, range);
2197 if (possibleRegions != null && possibleRegions.Count > 0)
2198 {
2199 // If we found some regions, check to see if the point is within
2200 foreach (GridRegion gr in possibleRegions)
2201 {
2202 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegion nm={1}, regionLoc=<{2},{3}>, regionSize=<{4},{5}>",
2203 LogHeader, gr.RegionName, gr.RegionLocX, gr.RegionLocY, gr.RegionSizeX, gr.RegionSizeY);
2204 if (px >= (double)gr.RegionLocX && px < (double)(gr.RegionLocX + gr.RegionSizeX)
2205 && py >= (double)gr.RegionLocY && py < (double)(gr.RegionLocY + gr.RegionSizeY))
2206 {
2207 // Found a region that contains the point
2208 ret = gr;
2209 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: found. RegionName={1}", LogHeader, ret.RegionName);
2210 break;
2211 }
2212 }
2213 }
2214 // Larger search area for next time around if not found
2215 range *= 2;
2216 }
2217 }
2218
2219 if (ret == null)
2220 {
2221 // remember this location was not found so we can quickly not find it next time
2222 m_notFoundLocationCache.Add(px, py);
2223 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found. Remembering loc=<{1},{2}>", LogHeader, px, py);
2224 }
2225
2226 return ret;
2050 } 2227 }
2051 2228
2052 private void InformClientOfNeighbourCompleted(IAsyncResult iar) 2229 private void InformClientOfNeighbourCompleted(IAsyncResult iar)
@@ -2168,16 +2345,19 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2168 // view to include everything in the megaregion 2345 // view to include everything in the megaregion
2169 if (m_regionCombinerModule == null || !m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID)) 2346 if (m_regionCombinerModule == null || !m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID))
2170 { 2347 {
2171 int dd = avatar.DrawDistance < Constants.RegionSize ? (int)Constants.RegionSize : (int)avatar.DrawDistance; 2348 // The area to check is as big as the current region.
2349 // We presume all adjacent regions are the same size as this region.
2350 uint dd = Math.Max((uint)avatar.DrawDistance,
2351 Math.Max(Scene.RegionInfo.RegionSizeX, Scene.RegionInfo.RegionSizeY));
2172 2352
2173 int startX = (int)pRegionLocX * (int)Constants.RegionSize - dd + (int)(Constants.RegionSize/2); 2353 uint startX = Util.RegionToWorldLoc(pRegionLocX) - dd + Constants.RegionSize/2;
2174 int startY = (int)pRegionLocY * (int)Constants.RegionSize - dd + (int)(Constants.RegionSize/2); 2354 uint startY = Util.RegionToWorldLoc(pRegionLocY) - dd + Constants.RegionSize/2;
2175 2355
2176 int endX = (int)pRegionLocX * (int)Constants.RegionSize + dd + (int)(Constants.RegionSize/2); 2356 uint endX = Util.RegionToWorldLoc(pRegionLocX) + dd + Constants.RegionSize/2;
2177 int endY = (int)pRegionLocY * (int)Constants.RegionSize + dd + (int)(Constants.RegionSize/2); 2357 uint endY = Util.RegionToWorldLoc(pRegionLocY) + dd + Constants.RegionSize/2;
2178 2358
2179 List<GridRegion> neighbours = 2359 List<GridRegion> neighbours =
2180 avatar.Scene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY); 2360 avatar.Scene.GridService.GetRegionRange(m_regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY);
2181 2361
2182 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; }); 2362 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
2183 return neighbours; 2363 return neighbours;
@@ -2190,10 +2370,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2190 List<GridRegion> neighbours 2370 List<GridRegion> neighbours
2191 = pScene.GridService.GetRegionRange( 2371 = pScene.GridService.GetRegionRange(
2192 m_regionInfo.ScopeID, 2372 m_regionInfo.ScopeID,
2193 (int)swCorner.X * (int)Constants.RegionSize, 2373 (int)Util.RegionToWorldLoc((uint)swCorner.X), (int)Util.RegionToWorldLoc((uint)neCorner.X),
2194 (int)neCorner.X * (int)Constants.RegionSize, 2374 (int)Util.RegionToWorldLoc((uint)swCorner.Y), (int)Util.RegionToWorldLoc((uint)neCorner.Y) );
2195 (int)swCorner.Y * (int)Constants.RegionSize,
2196 (int)neCorner.Y * (int)Constants.RegionSize);
2197 2375
2198 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; }); 2376 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
2199 2377
@@ -2256,10 +2434,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2256 /// Move the given scene object into a new region depending on which region its absolute position has moved 2434 /// Move the given scene object into a new region depending on which region its absolute position has moved
2257 /// into. 2435 /// into.
2258 /// 2436 ///
2259 /// This method locates the new region handle and offsets the prim position for the new region 2437 /// Using the objects new world location, ask the grid service for a the new region and adjust the prim
2438 /// position to be relative to the new region.
2260 /// </summary> 2439 /// </summary>
2261 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
2262 /// <param name="grp">the scene object that we're crossing</param> 2440 /// <param name="grp">the scene object that we're crossing</param>
2441 /// <param name="attemptedPosition">the attempted out of region position of the scene object. This position is
2442 /// relative to the region the object currently is in.</param>
2443 /// <param name="silent">if 'true', the deletion of the client from the region is not broadcast to the clients</param>
2263 public void Cross(SceneObjectGroup grp, Vector3 attemptedPosition, bool silent) 2444 public void Cross(SceneObjectGroup grp, Vector3 attemptedPosition, bool silent)
2264 { 2445 {
2265 if (grp == null) 2446 if (grp == null)
@@ -2285,208 +2466,49 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2285 return; 2466 return;
2286 } 2467 }
2287 2468
2288 int thisx = (int)scene.RegionInfo.RegionLocX; 2469 // Remember the old group position in case the region lookup fails so position can be restored.
2289 int thisy = (int)scene.RegionInfo.RegionLocY; 2470 Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
2290 Vector3 EastCross = new Vector3(0.1f, 0, 0);
2291 Vector3 WestCross = new Vector3(-0.1f, 0, 0);
2292 Vector3 NorthCross = new Vector3(0, 0.1f, 0);
2293 Vector3 SouthCross = new Vector3(0, -0.1f, 0);
2294
2295
2296 // use this if no borders were crossed!
2297 ulong newRegionHandle
2298 = Util.UIntsToLong((uint)((thisx) * Constants.RegionSize),
2299 (uint)((thisy) * Constants.RegionSize));
2300
2301 Vector3 pos = attemptedPosition;
2302
2303 int changeX = 1;
2304 int changeY = 1;
2305
2306 if (scene.TestBorderCross(attemptedPosition + WestCross, Cardinals.W))
2307 {
2308 if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2309 {
2310
2311 Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2312
2313 if (crossedBorderx.BorderLine.Z > 0)
2314 {
2315 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2316 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2317 }
2318 else
2319 pos.X = ((pos.X + Constants.RegionSize));
2320
2321 Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2322 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2323
2324 if (crossedBordery.BorderLine.Z > 0)
2325 {
2326 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2327 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2328 }
2329 else
2330 pos.Y = ((pos.Y + Constants.RegionSize));
2331
2332
2333
2334 newRegionHandle
2335 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2336 (uint)((thisy - changeY) * Constants.RegionSize));
2337 // x - 1
2338 // y - 1
2339 }
2340 else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2341 {
2342 Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2343
2344 if (crossedBorderx.BorderLine.Z > 0)
2345 {
2346 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2347 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2348 }
2349 else
2350 pos.X = ((pos.X + Constants.RegionSize));
2351
2352
2353 Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2354 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2355 2471
2356 if (crossedBordery.BorderLine.Z > 0) 2472 // Compute the absolute position of the object.
2357 { 2473 double objectWorldLocX = (double)scene.RegionInfo.WorldLocX + attemptedPosition.X;
2358 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); 2474 double objectWorldLocY = (double)scene.RegionInfo.WorldLocY + attemptedPosition.Y;
2359 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2360 }
2361 else
2362 pos.Y = ((pos.Y + Constants.RegionSize));
2363 2475
2364 newRegionHandle 2476 // Ask the grid service for the region that contains the passed address
2365 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize), 2477 GridRegion destination = GetRegionContainingWorldLocation(scene.GridService, scene.RegionInfo.ScopeID,
2366 (uint)((thisy + changeY) * Constants.RegionSize)); 2478 objectWorldLocX, objectWorldLocY);
2367 // x - 1
2368 // y + 1
2369 }
2370 else
2371 {
2372 Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2373 2479
2374 if (crossedBorderx.BorderLine.Z > 0) 2480 Vector3 pos = Vector3.Zero;
2375 { 2481 if (destination != null)
2376 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2377 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2378 }
2379 else
2380 pos.X = ((pos.X + Constants.RegionSize));
2381
2382 newRegionHandle
2383 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2384 (uint)(thisy * Constants.RegionSize));
2385 // x - 1
2386 }
2387 }
2388 else if (scene.TestBorderCross(attemptedPosition + EastCross, Cardinals.E))
2389 { 2482 {
2390 if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S)) 2483 // Adjust the object's relative position from the old region (attemptedPosition)
2391 { 2484 // to be relative to the new region (pos).
2392 2485 pos = new Vector3( (float)(objectWorldLocX - (double)destination.RegionLocX),
2393 pos.X = ((pos.X - Constants.RegionSize)); 2486 (float)(objectWorldLocY - (double)destination.RegionLocY),
2394 Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S); 2487 attemptedPosition.Z);
2395 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2396
2397 if (crossedBordery.BorderLine.Z > 0)
2398 {
2399 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2400 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2401 }
2402 else
2403 pos.Y = ((pos.Y + Constants.RegionSize));
2404
2405
2406 newRegionHandle
2407 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2408 (uint)((thisy - changeY) * Constants.RegionSize));
2409 // x + 1
2410 // y - 1
2411 }
2412 else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2413 {
2414 pos.X = ((pos.X - Constants.RegionSize));
2415 pos.Y = ((pos.Y - Constants.RegionSize));
2416 newRegionHandle
2417 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2418 (uint)((thisy + changeY) * Constants.RegionSize));
2419 // x + 1
2420 // y + 1
2421 }
2422 else
2423 {
2424 pos.X = ((pos.X - Constants.RegionSize));
2425 newRegionHandle
2426 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2427 (uint)(thisy * Constants.RegionSize));
2428 // x + 1
2429 }
2430 } 2488 }
2431 else if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2432 {
2433 Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2434 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2435
2436 if (crossedBordery.BorderLine.Z > 0)
2437 {
2438 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2439 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2440 }
2441 else
2442 pos.Y = ((pos.Y + Constants.RegionSize));
2443 2489
2444 newRegionHandle 2490 if (destination == null || !CrossPrimGroupIntoNewRegion(destination, pos, grp, silent))
2445 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize));
2446 // y - 1
2447 }
2448 else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2449 { 2491 {
2492 m_log.InfoFormat("[ENTITY TRANSFER MODULE] cross region transfer failed for object {0}", grp.UUID);
2450 2493
2451 pos.Y = ((pos.Y - Constants.RegionSize)); 2494 // We are going to move the object back to the old position so long as the old position
2452 newRegionHandle 2495 // is in the region
2453 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize)); 2496 oldGroupPosition.X = Util.Clamp<float>(oldGroupPosition.X, 1.0f, (float)(scene.RegionInfo.RegionSizeX - 1));
2454 // y + 1 2497 oldGroupPosition.Y = Util.Clamp<float>(oldGroupPosition.Y, 1.0f, (float)(scene.RegionInfo.RegionSizeY - 1));
2455 } 2498 oldGroupPosition.Z = Util.Clamp<float>(oldGroupPosition.Z, 1.0f, Constants.RegionHeight);
2456 2499
2457 // Offset the positions for the new region across the border 2500 grp.AbsolutePosition = oldGroupPosition;
2458 Vector3 oldGroupPosition = grp.RootPart.GroupPosition; 2501 grp.Velocity = Vector3.Zero;
2502 if (grp.RootPart.PhysActor != null)
2503 grp.RootPart.PhysActor.CrossingFailure();
2459 2504
2460 // If we fail to cross the border, then reset the position of the scene object on that border. 2505 if (grp.RootPart.KeyframeMotion != null)
2461 uint x = 0, y = 0; 2506 grp.RootPart.KeyframeMotion.CrossingFailure();
2462 Utils.LongToUInts(newRegionHandle, out x, out y);
2463 GridRegion destination = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID, (int)x, (int)y);
2464 2507
2465 if (destination != null) 2508 grp.ScheduleGroupForFullUpdate();
2466 {
2467 if (CrossPrimGroupIntoNewRegion(destination, pos, grp, silent))
2468 return; // we did it
2469 } 2509 }
2470
2471 // no one or failed lets go back and tell physics to go on
2472 oldGroupPosition.X = Util.Clamp<float>(oldGroupPosition.X, 0.5f, (float)Constants.RegionSize - 0.5f);
2473 oldGroupPosition.Y = Util.Clamp<float>(oldGroupPosition.Y, 0.5f, (float)Constants.RegionSize - 0.5f);
2474 oldGroupPosition.Z = Util.Clamp<float>(oldGroupPosition.Z, 0.5f, 4096.0f);
2475
2476 grp.AbsolutePosition = oldGroupPosition;
2477 grp.Velocity = Vector3.Zero;
2478
2479 if (grp.RootPart.PhysActor != null)
2480 grp.RootPart.PhysActor.CrossingFailure();
2481
2482 if (grp.RootPart.KeyframeMotion != null)
2483 grp.RootPart.KeyframeMotion.CrossingFailure();
2484
2485 grp.ScheduleGroupForFullUpdate();
2486 } 2510 }
2487 2511
2488
2489
2490 /// <summary> 2512 /// <summary>
2491 /// Move the given scene object into a new region 2513 /// Move the given scene object into a new region
2492 /// </summary> 2514 /// </summary>
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
index fc02916..6a04acf 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
@@ -77,6 +77,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
77 public class EntityTransferStateMachine 77 public class EntityTransferStateMachine
78 { 78 {
79 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 79 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
80 private static readonly string LogHeader = "[ENTITY TRANSFER STATE MACHINE]";
80 81
81 /// <summary> 82 /// <summary>
82 /// If true then on a teleport, the source region waits for a callback from the destination region. If 83 /// If true then on a teleport, the source region waits for a callback from the destination region. If
@@ -100,6 +101,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
100 /// <returns>true if the agent was not already in transit, false if it was</returns> 101 /// <returns>true if the agent was not already in transit, false if it was</returns>
101 internal bool SetInTransit(UUID id) 102 internal bool SetInTransit(UUID id)
102 { 103 {
104 m_log.DebugFormat("{0} SetInTransit. agent={1}, newState=Preparing", LogHeader, id);
103 lock (m_agentsInTransit) 105 lock (m_agentsInTransit)
104 { 106 {
105 if (!m_agentsInTransit.ContainsKey(id)) 107 if (!m_agentsInTransit.ContainsKey(id))
@@ -121,6 +123,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
121 /// <exception cref='Exception'>Illegal transitions will throw an Exception</exception> 123 /// <exception cref='Exception'>Illegal transitions will throw an Exception</exception>
122 internal bool UpdateInTransit(UUID id, AgentTransferState newState) 124 internal bool UpdateInTransit(UUID id, AgentTransferState newState)
123 { 125 {
126 m_log.DebugFormat("{0} UpdateInTransit. agent={1}, newState={2}", LogHeader, id, newState);
127
124 bool transitionOkay = false; 128 bool transitionOkay = false;
125 129
126 // We don't want to throw an exception on cancel since this can come it at any time. 130 // We don't want to throw an exception on cancel since this can come it at any time.
@@ -193,6 +197,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
193 } 197 }
194 else if (failIfNotOkay) 198 else if (failIfNotOkay)
195 { 199 {
200 m_log.DebugFormat("{0} UpdateInTransit. Throwing transition failure = {1}", LogHeader, failureMessage);
196 throw new Exception(failureMessage); 201 throw new Exception(failureMessage);
197 } 202 }
198// else 203// else
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
index d943b20..4e7ad75 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.WorldLocX;
217 uint localY = (s.RegionInfo.RegionLocY * (int)Constants.RegionSize); 217 uint localY = s.RegionInfo.WorldLocY;
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/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 31ef79b..3b38c71 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
48 private static readonly ILog m_log = 48 private static readonly ILog m_log =
49 LogManager.GetLogger( 49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType); 50 MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]";
51 52
52 private IGridService m_GridService; 53 private IGridService m_GridService;
53 private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); 54 private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>();
@@ -56,12 +57,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
56 57
57 public LocalGridServicesConnector() 58 public LocalGridServicesConnector()
58 { 59 {
59 m_log.Debug("[LOCAL GRID SERVICE CONNECTOR]: LocalGridServicesConnector no parms."); 60 m_log.DebugFormat("{0} LocalGridServicesConnector no parms.", LogHeader);
60 } 61 }
61 62
62 public LocalGridServicesConnector(IConfigSource source) 63 public LocalGridServicesConnector(IConfigSource source)
63 { 64 {
64 m_log.Debug("[LOCAL GRID SERVICE CONNECTOR]: LocalGridServicesConnector instantiated directly."); 65 m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader);
65 InitialiseService(source); 66 InitialiseService(source);
66 } 67 }
67 68
@@ -192,6 +193,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
192 return m_GridService.GetRegionByUUID(scopeID, regionID); 193 return m_GridService.GetRegionByUUID(scopeID, regionID);
193 } 194 }
194 195
196 // Get a region given its base coordinates.
197 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
198 // be the base coordinate of the region.
195 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 199 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
196 { 200 {
197 GridRegion region = null; 201 GridRegion region = null;
@@ -206,13 +210,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
206 region = rcache.GetRegionByPosition(x, y); 210 region = rcache.GetRegionByPosition(x, y);
207 if (region != null) 211 if (region != null)
208 { 212 {
209 return region; 213 // m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache. Pos=<{2},{3}>",
214 // LogHeader, region.RegionName, x, y);
215 break;
210 } 216 }
211 } 217 }
212 } 218 }
213 219
214 // Then try on this sim (may be a lookup in DB if this is using MySql). 220 // Then try on this sim (may be a lookup in DB if this is using MySql).
215 return m_GridService.GetRegionByPosition(scopeID, x, y); 221 if (region == null)
222 {
223 region = m_GridService.GetRegionByPosition(scopeID, x, y);
224 if (region == null)
225 m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>",
226 LogHeader, x, y);
227 else
228 m_log.DebugFormat("{0} GetRegionByPosition. Requested region {1} from grid service. Pos=<{2},{3}>",
229 LogHeader, region.RegionName, x, y);
230 }
231 return region;
216 } 232 }
217 233
218 public GridRegion GetRegionByName(UUID scopeID, string regionName) 234 public GridRegion GetRegionByName(UUID scopeID, string regionName)
@@ -268,7 +284,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
268 caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key); 284 caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key);
269 List<GridRegion> regions = kvp.Value.GetNeighbours(); 285 List<GridRegion> regions = kvp.Value.GetNeighbours();
270 foreach (GridRegion r in regions) 286 foreach (GridRegion r in regions)
271 caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); 287 caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
272 } 288 }
273 } 289 }
274 290
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
index 9172536..ae76288 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
@@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
66 return; 66 return;
67 67
68 m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}", 68 m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}",
69 m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX / Constants.RegionSize, otherRegion.RegionLocY / Constants.RegionSize); 69 m_scene.RegionInfo.RegionName, otherRegion.RegionName, Util.WorldToRegionLoc((uint)otherRegion.RegionLocX), Util.WorldToRegionLoc((uint)otherRegion.RegionLocY));
70 70
71 m_neighbours[otherRegion.RegionHandle] = otherRegion; 71 m_neighbours[otherRegion.RegionHandle] = otherRegion;
72 } 72 }
@@ -82,11 +82,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
82 return new List<GridRegion>(m_neighbours.Values); 82 return new List<GridRegion>(m_neighbours.Values);
83 } 83 }
84 84
85 // Get a region given its base coordinates (in meters).
86 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
87 // be the base coordinate of the region.
88 // The snapping is technically unnecessary but is harmless because regions are always
89 // multiples of the legacy region size (256).
85 public GridRegion GetRegionByPosition(int x, int y) 90 public GridRegion GetRegionByPosition(int x, int y)
86 { 91 {
87 uint xsnap = (uint)(x / Constants.RegionSize) * Constants.RegionSize; 92 uint xsnap = (uint)(x / Constants.RegionSize) * Constants.RegionSize;
88 uint ysnap = (uint)(y / Constants.RegionSize) * Constants.RegionSize; 93 uint ysnap = (uint)(y / Constants.RegionSize) * Constants.RegionSize;
89 ulong handle = Utils.UIntsToLong(xsnap, ysnap); 94 ulong handle = Util.RegionWorldLocToHandle(xsnap, ysnap);
90 95
91 if (m_neighbours.ContainsKey(handle)) 96 if (m_neighbours.ContainsKey(handle))
92 return m_neighbours[handle]; 97 return m_neighbours[handle];
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
index 6a57d1f..ae5081c 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
@@ -186,10 +186,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
186 return rinfo; 186 return rinfo;
187 } 187 }
188 188
189 // Get a region given its base world coordinates (in meters).
190 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
191 // be the base coordinate of the region.
192 // The coordinates are world coords (meters), NOT region units.
189 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 193 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
190 { 194 {
191 bool inCache = false; 195 bool inCache = false;
192 GridRegion rinfo = m_RegionInfoCache.Get(scopeID, Util.UIntsToLong((uint)x, (uint)y), out inCache); 196 GridRegion rinfo = m_RegionInfoCache.Get(scopeID, Util.RegionWorldLocToHandle((uint)x, (uint)y), out inCache);
193 if (inCache) 197 if (inCache)
194 return rinfo; 198 return rinfo;
195 199
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
index 4338133..25ae689 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
@@ -34,6 +34,7 @@ using log4net.Config;
34using Nini.Config; 34using Nini.Config;
35using NUnit.Framework; 35using NUnit.Framework;
36using OpenMetaverse; 36using OpenMetaverse;
37
37using OpenSim.Framework; 38using OpenSim.Framework;
38using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; 39using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
39using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
@@ -141,7 +142,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
141 Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null"); 142 Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null");
142 Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match"); 143 Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match");
143 144
144 result = m_LocalConnector.GetRegionByPosition(UUID.Zero, 1000 * (int)Constants.RegionSize, 1000 * (int)Constants.RegionSize); 145 result = m_LocalConnector.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000));
145 Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null"); 146 Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null");
146 Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match"); 147 Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match");
147 148
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 26d22b8..4d7538c 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
57 { 57 {
58 private static readonly ILog m_log = 58 private static readonly ILog m_log =
59 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 59 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
60 private static string LogHeader = "[MAP IMAGE SERVICE MODULE]";
60 61
61 private bool m_enabled = false; 62 private bool m_enabled = false;
62 private IMapImageService m_MapService; 63 private IMapImageService m_MapService;
@@ -192,42 +193,85 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
192 ///</summary> 193 ///</summary>
193 private void UploadMapTile(IScene scene) 194 private void UploadMapTile(IScene scene)
194 { 195 {
195 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: upload maptile for {0}", scene.RegionInfo.RegionName); 196 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
197 string regionName = scene.RegionInfo.RegionName;
196 198
197 // Create a JPG map tile and upload it to the AddMapTile API 199 // Create a JPG map tile and upload it to the AddMapTile API
198 byte[] jpgData = Utils.EmptyBytes;
199 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 200 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
200 if (tileGenerator == null) 201 if (tileGenerator == null)
201 { 202 {
202 m_log.Warn("[MAP IMAGE SERVICE MODULE]: Cannot upload PNG map tile without an ImageGenerator"); 203 m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader);
203 return; 204 return;
204 } 205 }
205 206 using (Bitmap mapTile = tileGenerator.CreateMapTile())
206 using (Image mapTile = tileGenerator.CreateMapTile())
207 { 207 {
208 // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there 208 if (mapTile != null)
209 // is no static map tile. 209 {
210 if (mapTile == null) 210 // mapTile.Save( // DEBUG DEBUG
211 return; 211 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
212 212 // ImageFormat.Jpeg);
213 using (MemoryStream stream = new MemoryStream()) 213 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
214 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
215 {
216 ConvertAndUploadMaptile(mapTile,
217 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
218 scene.RegionInfo.RegionName);
219 }
220 else
221 {
222 // For larger regions (varregion) we must cut the region image into legacy sized
223 // pieces since that is how the maptile system works.
224 // Note the assumption that varregions are always a multiple of legacy size.
225 for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
226 {
227 for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
228 {
229 // Images are addressed from the upper left corner so have to do funny
230 // math to pick out the sub-tile since regions are numbered from
231 // the lower left.
232 Rectangle rect = new Rectangle(
233 (int)xx,
234 mapTile.Height - (int)yy - (int)Constants.RegionSize,
235 (int)Constants.RegionSize, (int)Constants.RegionSize);
236 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
237 {
238 ConvertAndUploadMaptile(subMapTile,
239 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
240 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
241 regionName);
242 }
243 }
244 }
245 }
246 }
247 else
214 { 248 {
215 mapTile.Save(stream, ImageFormat.Jpeg); 249 m_log.WarnFormat("{0} Tile image generation failed", LogHeader);
216 jpgData = stream.ToArray();
217 } 250 }
218 } 251 }
252 }
219 253
220 if (jpgData == Utils.EmptyBytes) 254 private void ConvertAndUploadMaptile(Image tileImage, uint locX, uint locY, string regionName)
255 {
256 byte[] jpgData = Utils.EmptyBytes;
257
258 using (MemoryStream stream = new MemoryStream())
221 { 259 {
222 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed"); 260 tileImage.Save(stream, ImageFormat.Jpeg);
223 return; 261 jpgData = stream.ToArray();
224 } 262 }
225 263 if (jpgData != Utils.EmptyBytes)
226 string reason = string.Empty; 264 {
227 if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, out reason)) 265 string reason = string.Empty;
266 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, out reason))
267 {
268 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
269 regionName, locX, locY, reason);
270 }
271 }
272 else
228 { 273 {
229 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}", 274 m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, regionName);
230 scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason);
231 } 275 }
232 } 276 }
233 } 277 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs
index fd89428..56d9937 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs
@@ -132,7 +132,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour
132 if (s.RegionInfo.RegionHandle == regionHandle) 132 if (s.RegionInfo.RegionHandle == regionHandle)
133 { 133 {
134 m_log.DebugFormat("[LOCAL NEIGHBOUR SERVICE CONNECTOR]: HelloNeighbour from region {0} to neighbour {1} at {2}-{3}", 134 m_log.DebugFormat("[LOCAL NEIGHBOUR SERVICE CONNECTOR]: HelloNeighbour from region {0} to neighbour {1} at {2}-{3}",
135 thisRegion.RegionName, s.Name, x / Constants.RegionSize, y / Constants.RegionSize); 135 thisRegion.RegionName, s.Name, Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y) );
136 136
137 //m_log.Debug("[NEIGHBOUR CONNECTOR]: Found region to SendHelloNeighbour"); 137 //m_log.Debug("[NEIGHBOUR CONNECTOR]: Found region to SendHelloNeighbour");
138 return s.IncomingHelloNeighbour(thisRegion); 138 return s.IncomingHelloNeighbour(thisRegion);
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index d451b9e..f4807ad 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -96,14 +96,40 @@ namespace OpenSim.Region.CoreModules.World.Archiver
96 96
97 /// <value> 97 /// <value>
98 /// Should the archive being loaded be merged with what is already on the region? 98 /// Should the archive being loaded be merged with what is already on the region?
99 /// Merging usually suppresses terrain and parcel loading
99 /// </value> 100 /// </value>
100 protected bool m_merge; 101 protected bool m_merge;
101 102
102 /// <value> 103 /// <value>
104 /// If true, force the loading of terrain from the oar file
105 /// </value>
106 protected bool m_forceTerrain;
107
108 /// <value>
109 /// If true, force the loading of parcels from the oar file
110 /// </value>
111 protected bool m_forceParcels;
112
113 /// <value>
103 /// Should we ignore any assets when reloading the archive? 114 /// Should we ignore any assets when reloading the archive?
104 /// </value> 115 /// </value>
105 protected bool m_skipAssets; 116 protected bool m_skipAssets;
106 117
118 /// <value>
119 /// Displacement added to each object as it is added to the world
120 /// </value>
121 protected Vector3 m_displacement = Vector3.Zero;
122
123 /// <value>
124 /// Rotation to apply to the objects as they are loaded.
125 /// </value>
126 protected float m_rotation = 0f;
127
128 /// <value>
129 /// Center around which to apply the rotation relative to the origional oar position
130 /// </value>
131 protected Vector3 m_rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0f);
132
107 /// <summary> 133 /// <summary>
108 /// Used to cache lookups for valid uuids. 134 /// Used to cache lookups for valid uuids.
109 /// </summary> 135 /// </summary>
@@ -132,7 +158,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
132 private IAssetService m_assetService = null; 158 private IAssetService m_assetService = null;
133 159
134 160
135 public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId) 161 public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string,object>options)
136 { 162 {
137 m_rootScene = scene; 163 m_rootScene = scene;
138 164
@@ -150,9 +176,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
150 } 176 }
151 177
152 m_errorMessage = String.Empty; 178 m_errorMessage = String.Empty;
153 m_merge = merge; 179 m_merge = options.ContainsKey("merge");
154 m_skipAssets = skipAssets; 180 m_forceTerrain = options.ContainsKey("forceTerrain");
181 m_forceParcels = options.ContainsKey("forceParcels");
182 m_skipAssets = options.ContainsKey("skipAssets");
155 m_requestId = requestId; 183 m_requestId = requestId;
184 m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero;
185 m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f;
186 m_rotationCenter = options.ContainsKey("rotationCenter") ? (Vector3)options["rotationCenter"]
187 : new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0f);
156 188
157 // Zero can never be a valid user id 189 // Zero can never be a valid user id
158 m_validUserUuids[UUID.Zero] = false; 190 m_validUserUuids[UUID.Zero] = false;
@@ -161,13 +193,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver
161 m_assetService = m_rootScene.AssetService; 193 m_assetService = m_rootScene.AssetService;
162 } 194 }
163 195
164 public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId) 196 public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object>options)
165 { 197 {
166 m_rootScene = scene; 198 m_rootScene = scene;
167 m_loadPath = null; 199 m_loadPath = null;
168 m_loadStream = loadStream; 200 m_loadStream = loadStream;
169 m_merge = merge; 201 m_skipAssets = options.ContainsKey("skipAssets");
170 m_skipAssets = skipAssets; 202 m_merge = options.ContainsKey("merge");
171 m_requestId = requestId; 203 m_requestId = requestId;
172 204
173 // Zero can never be a valid user id 205 // Zero can never be a valid user id
@@ -243,7 +275,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
243 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) 275 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
244 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); 276 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
245 } 277 }
246 else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH)) 278 else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain))
247 { 279 {
248 LoadTerrain(scene, filePath, data); 280 LoadTerrain(scene, filePath, data);
249 } 281 }
@@ -251,7 +283,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
251 { 283 {
252 LoadRegionSettings(scene, filePath, data, dearchivedScenes); 284 LoadRegionSettings(scene, filePath, data, dearchivedScenes);
253 } 285 }
254 else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH)) 286 else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels))
255 { 287 {
256 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); 288 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data));
257 } 289 }
@@ -422,6 +454,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
422 // Reload serialized prims 454 // Reload serialized prims
423 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); 455 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
424 456
457 float angle = (float)(m_rotation / 180.0 * Math.PI);
458 OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, angle);
459
425 UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject; 460 UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject;
426 461
427 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>(); 462 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>();
@@ -445,6 +480,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
445 480
446 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject); 481 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
447 482
483 // Happily this does not do much to the object since it hasn't been added to the scene yet
484 if (sceneObject.AttachmentPoint == 0)
485 {
486 if (angle != 0f)
487 {
488 sceneObject.RootPart.RotationOffset = rot * sceneObject.GroupRotation;
489 Vector3 offset = sceneObject.AbsolutePosition - m_rotationCenter;
490 offset *= rot;
491 sceneObject.AbsolutePosition = m_rotationCenter + offset;
492 }
493 if (m_displacement != Vector3.Zero)
494 {
495 sceneObject.AbsolutePosition += m_displacement;
496 }
497 }
498
499
448 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero); 500 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero);
449 501
450 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned 502 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
@@ -549,6 +601,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver
549 foreach (string serialisedParcel in serialisedParcels) 601 foreach (string serialisedParcel in serialisedParcels)
550 { 602 {
551 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); 603 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
604
605 if (m_displacement != Vector3.Zero)
606 {
607 Vector3 parcelDisp = new Vector3(m_displacement.X, m_displacement.Y, 0f);
608 parcel.AABBMin += parcelDisp;
609 parcel.AABBMax += parcelDisp;
610 }
552 611
553 // Validate User and Group UUID's 612 // Validate User and Group UUID's
554 613
@@ -809,7 +868,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
809 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); 868 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
810 869
811 MemoryStream ms = new MemoryStream(data); 870 MemoryStream ms = new MemoryStream(data);
812 terrainModule.LoadFromStream(terrainPath, ms); 871 if (m_displacement != Vector3.Zero)
872 {
873 Vector2 terrainDisplacement = new Vector2(m_displacement.X, m_displacement.Y);
874 terrainModule.LoadFromStream(terrainPath, terrainDisplacement, ms);
875 }
876 else
877 {
878 terrainModule.LoadFromStream(terrainPath, ms);
879 }
813 ms.Close(); 880 ms.Close();
814 881
815 m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath); 882 m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs
index 7a844f4..cd95ee9 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequest.cs
@@ -533,7 +533,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
533 if (isMegaregion) 533 if (isMegaregion)
534 size = rcMod.GetSizeOfMegaregion(scene.RegionInfo.RegionID); 534 size = rcMod.GetSizeOfMegaregion(scene.RegionInfo.RegionID);
535 else 535 else
536 size = new Vector2((float)Constants.RegionSize, (float)Constants.RegionSize); 536 size = new Vector2((float)scene.RegionInfo.RegionSizeX, (float)scene.RegionInfo.RegionSizeY);
537 537
538 xtw.WriteElementString("is_megaregion", isMegaregion.ToString()); 538 xtw.WriteElementString("is_megaregion", isMegaregion.ToString());
539 xtw.WriteElementString("size_in_meters", string.Format("{0},{1}", size.X, size.Y)); 539 xtw.WriteElementString("size_in_meters", string.Format("{0},{1}", size.X, size.Y));
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
index 1be6386..2a6f1eb 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
@@ -33,11 +33,14 @@ using log4net;
33using NDesk.Options; 33using NDesk.Options;
34using Nini.Config; 34using Nini.Config;
35using Mono.Addins; 35using Mono.Addins;
36
36using OpenSim.Framework; 37using OpenSim.Framework;
37using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
38using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
40 41
42using OpenMetaverse;
43
41namespace OpenSim.Region.CoreModules.World.Archiver 44namespace OpenSim.Region.CoreModules.World.Archiver
42{ 45{
43 /// <summary> 46 /// <summary>
@@ -101,9 +104,36 @@ namespace OpenSim.Region.CoreModules.World.Archiver
101 { 104 {
102 bool mergeOar = false; 105 bool mergeOar = false;
103 bool skipAssets = false; 106 bool skipAssets = false;
107 bool forceTerrain = false;
108 bool forceParcels = false;
109 Vector3 displacement = new Vector3(0f, 0f, 0f);
110 float rotation = 0f;
111 Vector3 rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0);
104 112
105 OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; }); 113 OptionSet options = new OptionSet();
106 options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; }); 114 options.Add("m|merge", delegate (string v) { mergeOar = (v != null); });
115 options.Add("s|skip-assets", delegate (string v) { skipAssets = (v != null); });
116 options.Add("forceterrain", delegate (string v) { forceTerrain = (v != null); });
117 options.Add("forceparcels", delegate (string v) { forceParcels = (v != null); });
118 options.Add("displacement=", delegate (string v) {
119 try
120 {
121 displacement = v == null ? Vector3.Zero : Vector3.Parse(v);
122 }
123 catch (Exception e)
124 {
125 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing displacement");
126 displacement = new Vector3(0f, 0f, 0f);
127 }
128 });
129 options.Add("rotation=", delegate (string v) {
130 rotation = float.Parse(v);
131 rotation = Util.Clamp<float>(rotation, -359f, 359f);
132 });
133 options.Add("rotationcenter=", delegate (string v) {
134 // RA 20130119: libomv's Vector2.Parse doesn't work. Need to use vector3 for the moment
135 rotationCenter = Vector3.Parse(v);
136 });
107 137
108 // Send a message to the region ready module 138 // Send a message to the region ready module
109 /* bluewall* Disable this for the time being 139 /* bluewall* Disable this for the time being
@@ -122,13 +152,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver
122// foreach (string param in mainParams) 152// foreach (string param in mainParams)
123// m_log.DebugFormat("GOT PARAM [{0}]", param); 153// m_log.DebugFormat("GOT PARAM [{0}]", param);
124 154
155 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
156 if (mergeOar) archiveOptions.Add("merge", null);
157 if (skipAssets) archiveOptions.Add("skipAssets", null);
158 if (forceTerrain) archiveOptions.Add("forceTerrain", null);
159 if (forceParcels) archiveOptions.Add("forceParcels", null);
160 archiveOptions.Add("displacement", displacement);
161 archiveOptions.Add("rotation", rotation);
162 archiveOptions.Add("rotationCenter", rotationCenter);
163
125 if (mainParams.Count > 2) 164 if (mainParams.Count > 2)
126 { 165 {
127 DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty); 166 DearchiveRegion(mainParams[2], Guid.Empty, archiveOptions);
128 } 167 }
129 else 168 else
130 { 169 {
131 DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty); 170 DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, Guid.Empty, archiveOptions);
132 } 171 }
133 } 172 }
134 173
@@ -198,25 +237,27 @@ namespace OpenSim.Region.CoreModules.World.Archiver
198 237
199 public void DearchiveRegion(string loadPath) 238 public void DearchiveRegion(string loadPath)
200 { 239 {
201 DearchiveRegion(loadPath, false, false, Guid.Empty); 240 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
241 DearchiveRegion(loadPath, Guid.Empty, archiveOptions);
202 } 242 }
203 243
204 public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId) 244 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options)
205 { 245 {
206 m_log.InfoFormat( 246 m_log.InfoFormat(
207 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath); 247 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
208 248
209 new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion(); 249 new ArchiveReadRequest(Scene, loadPath, requestId, options).DearchiveRegion();
210 } 250 }
211 251
212 public void DearchiveRegion(Stream loadStream) 252 public void DearchiveRegion(Stream loadStream)
213 { 253 {
214 DearchiveRegion(loadStream, false, false, Guid.Empty); 254 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
255 DearchiveRegion(loadStream, Guid.Empty, archiveOptions);
215 } 256 }
216 257
217 public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId) 258 public void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options)
218 { 259 {
219 new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion(); 260 new ArchiveReadRequest(Scene, loadStream, requestId, options).DearchiveRegion();
220 } 261 }
221 } 262 }
222} 263}
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
index eec1cec..53f41f9 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
@@ -224,8 +224,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
224 224
225 byte[] data = tar.ReadEntry(out filePath, out tarEntryType); 225 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
226 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); 226 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
227 227
228 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); 228 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
229 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);
229 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); 230 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());
230 231
231 Assert.That(arr.ControlFileLoaded, Is.True); 232 Assert.That(arr.ControlFileLoaded, Is.True);
@@ -308,8 +309,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
308 309
309 byte[] data = tar.ReadEntry(out filePath, out tarEntryType); 310 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
310 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); 311 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
311 312
312 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); 313 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
314 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);
313 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); 315 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());
314 316
315 Assert.That(arr.ControlFileLoaded, Is.True); 317 Assert.That(arr.ControlFileLoaded, Is.True);
@@ -752,7 +754,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
752 byte[] archive = archiveWriteStream.ToArray(); 754 byte[] archive = archiveWriteStream.ToArray();
753 MemoryStream archiveReadStream = new MemoryStream(archive); 755 MemoryStream archiveReadStream = new MemoryStream(archive);
754 756
755 m_archiverModule.DearchiveRegion(archiveReadStream, true, false, Guid.Empty); 757 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
758 archiveOptions.Add("merge", null);
759 m_archiverModule.DearchiveRegion(archiveReadStream, Guid.Empty, archiveOptions);
756 760
757 SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name); 761 SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name);
758 Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge"); 762 Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge");
@@ -860,7 +864,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
860 byte[] data = tar.ReadEntry(out filePath, out tarEntryType); 864 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
861 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); 865 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
862 866
863 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); 867 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
868 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);
864 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); 869 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());
865 870
866 Assert.That(arr.ControlFileLoaded, Is.True); 871 Assert.That(arr.ControlFileLoaded, Is.True);
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index 73c4d6c..99db7ff 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -64,6 +64,7 @@ namespace OpenSim.Region.CoreModules.World.Land
64 public class LandManagementModule : INonSharedRegionModule 64 public class LandManagementModule : INonSharedRegionModule
65 { 65 {
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 private static readonly string LogHeader = "[LAND MANAGEMENT MODULE]";
67 68
68 private static readonly string remoteParcelRequestPath = "0009/"; 69 private static readonly string remoteParcelRequestPath = "0009/";
69 70
@@ -74,15 +75,11 @@ namespace OpenSim.Region.CoreModules.World.Land
74 protected IPrimCountModule m_primCountModule; 75 protected IPrimCountModule m_primCountModule;
75 protected IDialogModule m_Dialog; 76 protected IDialogModule m_Dialog;
76 77
77 // Minimum for parcels to work is 64m even if we don't actually use them.
78 #pragma warning disable 0429
79 private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
80 #pragma warning restore 0429
81
82 /// <value> 78 /// <value>
83 /// Local land ids at specified region co-ordinates (region size / 4) 79 /// Local land ids at specified region co-ordinates (region size / 4)
84 /// </value> 80 /// </value>
85 private readonly int[,] m_landIDList = new int[landArrayMax, landArrayMax]; 81 private int[,] m_landIDList;
82 private const int landUnit = 4;
86 83
87 /// <value> 84 /// <value>
88 /// Land objects keyed by local id 85 /// Land objects keyed by local id
@@ -115,6 +112,8 @@ namespace OpenSim.Region.CoreModules.World.Land
115 public void AddRegion(Scene scene) 112 public void AddRegion(Scene scene)
116 { 113 {
117 m_scene = scene; 114 m_scene = scene;
115 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
116
118 m_landIDList.Initialize(); 117 m_landIDList.Initialize();
119 landChannel = new LandChannel(scene, this); 118 landChannel = new LandChannel(scene, this);
120 119
@@ -297,6 +296,7 @@ namespace OpenSim.Region.CoreModules.World.Land
297 { 296 {
298 m_landList.Clear(); 297 m_landList.Clear();
299 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; 298 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
299 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
300 m_landIDList.Initialize(); 300 m_landIDList.Initialize();
301 } 301 }
302 } 302 }
@@ -311,7 +311,8 @@ namespace OpenSim.Region.CoreModules.World.Land
311 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName); 311 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
312 312
313 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene); 313 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
314 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize)); 314 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0,
315 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
315 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; 316 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
316 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); 317 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
317 318
@@ -438,8 +439,8 @@ namespace OpenSim.Region.CoreModules.World.Land
438 439
439 public void SendLandUpdate(ScenePresence avatar, bool force) 440 public void SendLandUpdate(ScenePresence avatar, bool force)
440 { 441 {
441 ILandObject over = GetLandObject((int)Math.Min(((int)Constants.RegionSize - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))), 442 ILandObject over = GetLandObject((int)Math.Min(((int)m_scene.RegionInfo.RegionSizeX - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
442 (int)Math.Min(((int)Constants.RegionSize - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y)))); 443 (int)Math.Min(((int)m_scene.RegionInfo.RegionSizeY - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
443 444
444 if (over != null) 445 if (over != null)
445 { 446 {
@@ -605,17 +606,29 @@ namespace OpenSim.Region.CoreModules.World.Land
605 new_land.LandData.LocalID = newLandLocalID; 606 new_land.LandData.LocalID = newLandLocalID;
606 607
607 bool[,] landBitmap = new_land.GetLandBitmap(); 608 bool[,] landBitmap = new_land.GetLandBitmap();
608 for (int x = 0; x < landArrayMax; x++) 609 // m_log.DebugFormat("{0} AddLandObject. new_land.bitmapSize=({1},{2}). newLocalID={3}",
610 // LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), newLandLocalID);
611
612 if (landBitmap.GetLength(0) != m_landIDList.GetLength(0) || landBitmap.GetLength(1) != m_landIDList.GetLength(1))
609 { 613 {
610 for (int y = 0; y < landArrayMax; y++) 614 // Going to variable sized regions can cause mismatches
615 m_log.ErrorFormat("{0} AddLandObject. Added land bitmap different size than region ID map. bitmapSize=({1},{2}), landIDSize=({3},{4})",
616 LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1) );
617 }
618 else
619 {
620 for (int x = 0; x < landBitmap.GetLength(0); x++)
611 { 621 {
612 if (landBitmap[x, y]) 622 for (int y = 0; y < landBitmap.GetLength(1); y++)
613 { 623 {
614// m_log.DebugFormat( 624 if (landBitmap[x, y])
615// "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}", 625 {
616// new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName); 626 // m_log.DebugFormat(
617 627 // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
618 m_landIDList[x, y] = newLandLocalID; 628 // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
629
630 m_landIDList[x, y] = newLandLocalID;
631 }
619 } 632 }
620 } 633 }
621 } 634 }
@@ -637,9 +650,9 @@ namespace OpenSim.Region.CoreModules.World.Land
637 ILandObject land; 650 ILandObject land;
638 lock (m_landList) 651 lock (m_landList)
639 { 652 {
640 for (int x = 0; x < 64; x++) 653 for (int x = 0; x < m_landIDList.GetLength(0); x++)
641 { 654 {
642 for (int y = 0; y < 64; y++) 655 for (int y = 0; y < m_landIDList.GetLength(1); y++)
643 { 656 {
644 if (m_landIDList[x, y] == local_id) 657 if (m_landIDList[x, y] == local_id)
645 { 658 {
@@ -691,9 +704,9 @@ namespace OpenSim.Region.CoreModules.World.Land
691 bool[,] landBitmapSlave = slave.GetLandBitmap(); 704 bool[,] landBitmapSlave = slave.GetLandBitmap();
692 lock (m_landList) 705 lock (m_landList)
693 { 706 {
694 for (int x = 0; x < 64; x++) 707 for (int x = 0; x < landBitmapSlave.GetLength(0); x++)
695 { 708 {
696 for (int y = 0; y < 64; y++) 709 for (int y = 0; y < landBitmapSlave.GetLength(1); y++)
697 { 710 {
698 if (landBitmapSlave[x, y]) 711 if (landBitmapSlave[x, y])
699 { 712 {
@@ -727,23 +740,28 @@ namespace OpenSim.Region.CoreModules.World.Land
727 /// <returns>Land object at the point supplied</returns> 740 /// <returns>Land object at the point supplied</returns>
728 public ILandObject GetLandObject(float x_float, float y_float) 741 public ILandObject GetLandObject(float x_float, float y_float)
729 { 742 {
743 return GetLandObject((int)x_float, (int)y_float, true /* returnNullIfLandObjectNotFound */);
744 /*
730 int x; 745 int x;
731 int y; 746 int y;
732 747
733 if (x_float >= Constants.RegionSize || x_float < 0 || y_float >= Constants.RegionSize || y_float < 0) 748 if (x_float >= m_scene.RegionInfo.RegionSizeX || x_float < 0 || y_float >= m_scene.RegionInfo.RegionSizeX || y_float < 0)
734 return null; 749 return null;
735 750
736 try 751 try
737 { 752 {
738 x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / 4.0)); 753 x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / (float)landUnit));
739 y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / 4.0)); 754 y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / (float)landUnit));
740 } 755 }
741 catch (OverflowException) 756 catch (OverflowException)
742 { 757 {
743 return null; 758 return null;
744 } 759 }
745 760
746 if (x >= 64 || y >= 64 || x < 0 || y < 0) 761 if (x >= (m_scene.RegionInfo.RegionSizeX / landUnit)
762 || y >= (m_scene.RegionInfo.RegionSizeY / landUnit)
763 || x < 0
764 || y < 0)
747 { 765 {
748 return null; 766 return null;
749 } 767 }
@@ -759,38 +777,122 @@ namespace OpenSim.Region.CoreModules.World.Land
759// m_log.DebugFormat( 777// m_log.DebugFormat(
760// "[LAND MANAGEMENT MODULE]: No land object found at ({0}, {1}) on {2}", 778// "[LAND MANAGEMENT MODULE]: No land object found at ({0}, {1}) on {2}",
761// x, y, m_scene.RegionInfo.RegionName); 779// x, y, m_scene.RegionInfo.RegionName);
762 780
763 if (m_landList.ContainsKey(m_landIDList[x, y])) 781 try
764 return m_landList[m_landIDList[x, y]]; 782 {
783 if (m_landList.ContainsKey(m_landIDList[x, y]))
784 return m_landList[m_landIDList[x, y]];
785 }
786 catch (Exception e)
787 {
788 m_log.DebugFormat("{0} GetLandObject exception. x={1}, y={2}, m_landIDList.len=({3},{4})",
789 LogHeader, x, y, m_landIDList.GetLength(0), m_landIDList.GetLength(1));
790 }
765 791
766 return null; 792 return null;
767 } 793 }
794 */
768 } 795 }
769 796
797 // Public entry.
798 // Throws exception if land object is not found
770 public ILandObject GetLandObject(int x, int y) 799 public ILandObject GetLandObject(int x, int y)
771 { 800 {
772 if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0) 801 return GetLandObject(x, y, false /* returnNullIfLandObjectNotFound */);
802 }
803
804 // Given a region position, return the parcel land object for that location
805 private ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectNotFound)
806 {
807 ILandObject ret = null;
808
809 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
773 { 810 {
774 // These exceptions here will cause a lot of complaints from the users specifically because 811 // These exceptions here will cause a lot of complaints from the users specifically because
775 // they happen every time at border crossings 812 // they happen every time at border crossings
776 throw new Exception("Error: Parcel not found at point " + x + ", " + y); 813 if (returnNullIfLandObjectNotFound)
814 return null;
815 else
816 throw new Exception(
817 String.Format("{0} GetLandObject for non-existant position. Region={1}, pos=<{2},{3}",
818 LogHeader, m_scene.RegionInfo.RegionName, x, y)
819 );
777 } 820 }
778 821
779 lock (m_landIDList) 822 lock (m_landIDList)
780 { 823 {
781 try 824 try
782 { 825 {
783 return m_landList[m_landIDList[x / 4, y / 4]]; 826 int landID = m_landIDList[x / landUnit, y / landUnit];
827 if (landID == 0)
828 {
829 // Zero is the uninitialized value saying there is no parcel for this location.
830 // This sometimes happens when terrain is resized.
831 if (m_landList.Count == 1)
832 {
833 int onlyParcelID = 0;
834 ILandObject onlyLandObject = null;
835 foreach (KeyValuePair<int, ILandObject> kvp in m_landList)
836 {
837 onlyParcelID = kvp.Key;
838 onlyLandObject = kvp.Value;
839 break;
840 }
841
842 // There is only one parcel. Grow it to fill all the unallocated spaces.
843 for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
844 for (int yy = 0; yy < m_landIDList.GetLength(1); yy++)
845 if (m_landIDList[xx, yy] == 0)
846 m_landIDList[xx, yy] = onlyParcelID;
847
848 onlyLandObject.LandBitmap = CreateBitmapForID(onlyParcelID);
849 landID = onlyParcelID;
850 }
851 else
852 {
853 // There are several other parcels so we must create a new one for the unassigned space
854 ILandObject newLand = new LandObject(UUID.Zero, false, m_scene);
855 // Claim all the unclaimed "0" ids
856 newLand.SetLandBitmap(CreateBitmapForID(0));
857 newLand.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
858 newLand.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
859 AddLandObject(newLand);
860 landID = m_lastLandLocalID;
861 }
862 }
863
864 ret = m_landList[landID];
784 } 865 }
785 catch (IndexOutOfRangeException) 866 catch (IndexOutOfRangeException)
786 { 867 {
787// m_log.WarnFormat( 868 m_log.ErrorFormat(
788// "[LAND MANAGEMENT MODULE]: Tried to retrieve land object from out of bounds co-ordinate ({0},{1}) in {2}", 869 "{0} GetLandObject: Tried to retrieve land object from out of bounds co-ordinate ({1},{2}) in {3}. landListSize=({4},{5})",
789// x, y, m_scene.RegionInfo.RegionName); 870 LogHeader, x, y, m_scene.RegionInfo.RegionName, m_landIDList.GetLength(0), m_landIDList.GetLength(1));
790 871 return null;
872 }
873 catch
874 {
875 m_log.ErrorFormat(
876 "{0} GetLandObject: LandID not in landlist. XY=<{1},{2}> in {3}. landID[x,y]={4}",
877 LogHeader, x, y, m_scene.RegionInfo.RegionName, m_landIDList[x/landUnit, y/landUnit]);
791 return null; 878 return null;
792 } 879 }
793 } 880 }
881 return ret;
882 }
883
884 // Create a 'parcel is here' bitmap for the parcel identified by the passed landID
885 private bool[,] CreateBitmapForID(int landID)
886 {
887 bool[,] ret = new bool[m_landIDList.GetLength(0), m_landIDList.GetLength(1)];
888 ret.Initialize();
889
890 for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
891 for (int yy = 0; yy < m_landIDList.GetLength(0); yy++)
892 if (m_landIDList[xx, yy] == landID)
893 ret[xx, yy] = true;
894
895 return ret;
794 } 896 }
795 897
796 #endregion 898 #endregion
@@ -1053,85 +1155,93 @@ namespace OpenSim.Region.CoreModules.World.Land
1053 byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET]; 1155 byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1054 int byteArrayCount = 0; 1156 int byteArrayCount = 0;
1055 int sequenceID = 0; 1157 int sequenceID = 0;
1056 int blockmeters = 4 * (int) Constants.RegionSize/(int)Constants.TerrainPatchSize;
1057
1058 1158
1059 for (int y = 0; y < blockmeters; y++) 1159 // Layer data is in landUnit (4m) chunks
1160 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / landUnit); y++)
1060 { 1161 {
1061 for (int x = 0; x < blockmeters; x++) 1162 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / landUnit); x++)
1062 { 1163 {
1063 byte tempByte = 0; //This represents the byte for the current 4x4 1164 byteArray[byteArrayCount] = BuildLayerByte(GetLandObject(x * landUnit, y * landUnit), x, y, remote_client);
1165 byteArrayCount++;
1166 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
1167 {
1168 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1169 byteArrayCount = 0;
1170 sequenceID++;
1171 byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1172 }
1064 1173
1065 ILandObject currentParcelBlock = GetLandObject(x * 4, y * 4); 1174 }
1175 }
1176 if (byteArrayCount != 0)
1177 {
1178 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1179 }
1180 }
1066 1181
1067 if (currentParcelBlock != null) 1182 private byte BuildLayerByte(ILandObject currentParcelBlock, int x, int y, IClientAPI remote_client)
1068 { 1183 {
1069 if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId) 1184 byte tempByte = 0; //This represents the byte for the current 4x4
1070 {
1071 //Owner Flag
1072 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
1073 }
1074 else if (currentParcelBlock.LandData.SalePrice > 0 &&
1075 (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
1076 currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
1077 {
1078 //Sale Flag
1079 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
1080 }
1081 else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
1082 {
1083 //Public Flag
1084 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
1085 }
1086 else
1087 {
1088 //Other Flag
1089 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
1090 }
1091 1185
1092 //Now for border control 1186 if (currentParcelBlock != null)
1187 {
1188 if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId)
1189 {
1190 //Owner Flag
1191 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
1192 }
1193 else if (currentParcelBlock.LandData.SalePrice > 0 &&
1194 (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
1195 currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
1196 {
1197 //Sale Flag
1198 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
1199 }
1200 else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
1201 {
1202 //Public Flag
1203 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
1204 }
1205 else
1206 {
1207 //Other Flag
1208 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
1209 }
1093 1210
1094 ILandObject westParcel = null; 1211 //Now for border control
1095 ILandObject southParcel = null;
1096 if (x > 0)
1097 {
1098 westParcel = GetLandObject((x - 1) * 4, y * 4);
1099 }
1100 if (y > 0)
1101 {
1102 southParcel = GetLandObject(x * 4, (y - 1) * 4);
1103 }
1104 1212
1105 if (x == 0) 1213 ILandObject westParcel = null;
1106 { 1214 ILandObject southParcel = null;
1107 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST); 1215 if (x > 0)
1108 } 1216 {
1109 else if (westParcel != null && westParcel != currentParcelBlock) 1217 westParcel = GetLandObject((x - 1) * landUnit, y * landUnit);
1110 { 1218 }
1111 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST); 1219 if (y > 0)
1112 } 1220 {
1221 southParcel = GetLandObject(x * landUnit, (y - 1) * landUnit);
1222 }
1113 1223
1114 if (y == 0) 1224 if (x == 0)
1115 { 1225 {
1116 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH); 1226 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
1117 } 1227 }
1118 else if (southParcel != null && southParcel != currentParcelBlock) 1228 else if (westParcel != null && westParcel != currentParcelBlock)
1119 { 1229 {
1120 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH); 1230 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
1121 } 1231 }
1122 1232
1123 byteArray[byteArrayCount] = tempByte; 1233 if (y == 0)
1124 byteArrayCount++; 1234 {
1125 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET) 1235 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
1126 { 1236 }
1127 remote_client.SendLandParcelOverlay(byteArray, sequenceID); 1237 else if (southParcel != null && southParcel != currentParcelBlock)
1128 byteArrayCount = 0; 1238 {
1129 sequenceID++; 1239 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
1130 byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1131 }
1132 }
1133 } 1240 }
1241
1134 } 1242 }
1243
1244 return tempByte;
1135 } 1245 }
1136 1246
1137 public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, 1247 public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
@@ -1679,7 +1789,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1679 { 1789 {
1680 // most likely still cached from building the extLandData entry 1790 // most likely still cached from building the extLandData entry
1681 uint x = 0, y = 0; 1791 uint x = 0, y = 0;
1682 Utils.LongToUInts(data.RegionHandle, out x, out y); 1792 Util.RegionHandleToWorldLoc(data.RegionHandle, out x, out y);
1683 info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); 1793 info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
1684 } 1794 }
1685 // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark. 1795 // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
@@ -2007,4 +2117,4 @@ namespace OpenSim.Region.CoreModules.World.Land
2007 cdl.AddToStringBuilder(report); 2117 cdl.AddToStringBuilder(report);
2008 } 2118 }
2009 } 2119 }
2010} \ No newline at end of file 2120}
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index e54c849..f8f4986 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -45,10 +45,10 @@ namespace OpenSim.Region.CoreModules.World.Land
45 #region Member Variables 45 #region Member Variables
46 46
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 #pragma warning disable 0429 48 private static readonly string LogHeader = "[LAND OBJECT]";
49 private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64; 49
50 #pragma warning restore 0429 50 private bool[,] m_landBitmap;
51 private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax]; 51 private readonly int landUnit = 4;
52 52
53 private int m_lastSeqId = 0; 53 private int m_lastSeqId = 0;
54 54
@@ -93,15 +93,17 @@ namespace OpenSim.Region.CoreModules.World.Land
93 { 93 {
94 get 94 get
95 { 95 {
96 for (int y = 0; y < landArrayMax; y++) 96 for (int y = 0; y < LandBitmap.GetLength(1); y++)
97 { 97 {
98 for (int x = 0; x < landArrayMax; x++) 98 for (int x = 0; x < LandBitmap.GetLength(0); x++)
99 { 99 {
100 if (LandBitmap[x, y]) 100 if (LandBitmap[x, y])
101 return new Vector3(x * 4, y * 4, 0); 101 return new Vector3(x * landUnit, y * landUnit, 0);
102 } 102 }
103 } 103 }
104 104
105 m_log.ErrorFormat("{0} StartPoint. No start point found. bitmapSize=<{1},{2}>",
106 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
105 return new Vector3(-1, -1, -1); 107 return new Vector3(-1, -1, -1);
106 } 108 }
107 } 109 }
@@ -110,17 +112,19 @@ namespace OpenSim.Region.CoreModules.World.Land
110 { 112 {
111 get 113 get
112 { 114 {
113 for (int y = landArrayMax - 1; y >= 0; y--) 115 for (int y = LandBitmap.GetLength(1) - 1; y >= 0; y--)
114 { 116 {
115 for (int x = landArrayMax - 1; x >= 0; x--) 117 for (int x = LandBitmap.GetLength(0) - 1; x >= 0; x--)
116 { 118 {
117 if (LandBitmap[x, y]) 119 if (LandBitmap[x, y])
118 { 120 {
119 return new Vector3(x * 4 + 4, y * 4 + 4, 0); 121 return new Vector3(x * landUnit + landUnit, y * landUnit + landUnit, 0);
120 } 122 }
121 } 123 }
122 } 124 }
123 125
126 m_log.ErrorFormat("{0} EndPoint. No end point found. bitmapSize=<{1},{2}>",
127 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
124 return new Vector3(-1, -1, -1); 128 return new Vector3(-1, -1, -1);
125 } 129 }
126 } 130 }
@@ -130,6 +134,8 @@ namespace OpenSim.Region.CoreModules.World.Land
130 public LandObject(UUID owner_id, bool is_group_owned, Scene scene) 134 public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
131 { 135 {
132 m_scene = scene; 136 m_scene = scene;
137 m_landBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
138
133 LandData.OwnerID = owner_id; 139 LandData.OwnerID = owner_id;
134 if (is_group_owned) 140 if (is_group_owned)
135 LandData.GroupID = owner_id; 141 LandData.GroupID = owner_id;
@@ -152,9 +158,9 @@ namespace OpenSim.Region.CoreModules.World.Land
152 /// <returns>Returns true if the piece of land contains the specified point</returns> 158 /// <returns>Returns true if the piece of land contains the specified point</returns>
153 public bool ContainsPoint(int x, int y) 159 public bool ContainsPoint(int x, int y)
154 { 160 {
155 if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize) 161 if (x >= 0 && y >= 0 && x < m_scene.RegionInfo.RegionSizeX && y < m_scene.RegionInfo.RegionSizeY)
156 { 162 {
157 return (LandBitmap[x / 4, y / 4] == true); 163 return (LandBitmap[x / landUnit, y / landUnit] == true);
158 } 164 }
159 else 165 else
160 { 166 {
@@ -194,7 +200,7 @@ namespace OpenSim.Region.CoreModules.World.Land
194 else 200 else
195 { 201 {
196 // Normal Calculations 202 // Normal Calculations
197 int parcelMax = (int)(((float)LandData.Area / 65536.0f) 203 int parcelMax = (int)(((float)LandData.Area / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
198 * (float)m_scene.RegionInfo.ObjectCapacity 204 * (float)m_scene.RegionInfo.ObjectCapacity
199 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); 205 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
200 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL! 206 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL!
@@ -211,7 +217,7 @@ namespace OpenSim.Region.CoreModules.World.Land
211 else 217 else
212 { 218 {
213 //Normal Calculations 219 //Normal Calculations
214 int simMax = (int)(((float)LandData.SimwideArea / 65536.0f) 220 int simMax = (int)(((float)LandData.SimwideArea / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
215 * (float)m_scene.RegionInfo.ObjectCapacity); 221 * (float)m_scene.RegionInfo.ObjectCapacity);
216 return simMax; 222 return simMax;
217 } 223 }
@@ -224,7 +230,12 @@ namespace OpenSim.Region.CoreModules.World.Land
224 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client) 230 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
225 { 231 {
226 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>(); 232 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
227 uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome)); 233 // uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
234 uint regionFlags = (uint)(RegionFlags.PublicAllowed
235 | RegionFlags.AllowDirectTeleport
236 | RegionFlags.AllowParcelChanges
237 | RegionFlags.AllowVoice );
238
228 if (estateModule != null) 239 if (estateModule != null)
229 regionFlags = estateModule.GetRegionFlags(); 240 regionFlags = estateModule.GetRegionFlags();
230 241
@@ -559,8 +570,8 @@ namespace OpenSim.Region.CoreModules.World.Land
559 try 570 try
560 { 571 {
561 over = 572 over =
562 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)), 573 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)m_scene.RegionInfo.RegionSizeX - 1)),
563 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1))); 574 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)m_scene.RegionInfo.RegionSizeY - 1)));
564 } 575 }
565 catch (Exception) 576 catch (Exception)
566 { 577 {
@@ -707,15 +718,15 @@ namespace OpenSim.Region.CoreModules.World.Land
707 /// </summary> 718 /// </summary>
708 private void UpdateAABBAndAreaValues() 719 private void UpdateAABBAndAreaValues()
709 { 720 {
710 int min_x = 64; 721 int min_x = 10000;
711 int min_y = 64; 722 int min_y = 10000;
712 int max_x = 0; 723 int max_x = 0;
713 int max_y = 0; 724 int max_y = 0;
714 int tempArea = 0; 725 int tempArea = 0;
715 int x, y; 726 int x, y;
716 for (x = 0; x < 64; x++) 727 for (x = 0; x < LandBitmap.GetLength(0); x++)
717 { 728 {
718 for (y = 0; y < 64; y++) 729 for (y = 0; y < LandBitmap.GetLength(1); y++)
719 { 730 {
720 if (LandBitmap[x, y] == true) 731 if (LandBitmap[x, y] == true)
721 { 732 {
@@ -723,31 +734,31 @@ namespace OpenSim.Region.CoreModules.World.Land
723 if (min_y > y) min_y = y; 734 if (min_y > y) min_y = y;
724 if (max_x < x) max_x = x; 735 if (max_x < x) max_x = x;
725 if (max_y < y) max_y = y; 736 if (max_y < y) max_y = y;
726 tempArea += 16; //16sqm peice of land 737 tempArea += landUnit * landUnit; //16sqm peice of land
727 } 738 }
728 } 739 }
729 } 740 }
730 int tx = min_x * 4; 741 int tx = min_x * landUnit;
731 if (tx > ((int)Constants.RegionSize - 1)) 742 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
732 tx = ((int)Constants.RegionSize - 1); 743 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
733 int ty = min_y * 4; 744 int ty = min_y * landUnit;
734 if (ty > ((int)Constants.RegionSize - 1)) 745 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1))
735 ty = ((int)Constants.RegionSize - 1); 746 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1);
736 747
737 LandData.AABBMin = 748 LandData.AABBMin =
738 new Vector3( 749 new Vector3(
739 (float)(min_x * 4), (float)(min_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); 750 (float)(min_x * landUnit), (float)(min_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
740 751
741 tx = max_x * 4; 752 tx = max_x * landUnit;
742 if (tx > ((int)Constants.RegionSize - 1)) 753 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
743 tx = ((int)Constants.RegionSize - 1); 754 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
744 ty = max_y * 4; 755 ty = max_y * landUnit;
745 if (ty > ((int)Constants.RegionSize - 1)) 756 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1))
746 ty = ((int)Constants.RegionSize - 1); 757 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1);
747 758
748 LandData.AABBMax 759 LandData.AABBMax
749 = new Vector3( 760 = new Vector3(
750 (float)(max_x * 4), (float)(max_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); 761 (float)(max_x * landUnit), (float)(max_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
751 762
752 LandData.Area = tempArea; 763 LandData.Area = tempArea;
753 } 764 }
@@ -759,20 +770,12 @@ namespace OpenSim.Region.CoreModules.World.Land
759 /// <summary> 770 /// <summary>
760 /// Sets the land's bitmap manually 771 /// Sets the land's bitmap manually
761 /// </summary> 772 /// </summary>
762 /// <param name="bitmap">64x64 block representing where this land is on a map</param> 773 /// <param name="bitmap">block representing where this land is on a map mapped in a 4x4 meter grid</param>
763 public void SetLandBitmap(bool[,] bitmap) 774 public void SetLandBitmap(bool[,] bitmap)
764 { 775 {
765 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2) 776 LandBitmap = bitmap;
766 { 777 // m_log.DebugFormat("{0} SetLandBitmap. BitmapSize=<{1},{2}>", LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
767 //Throw an exception - The bitmap is not 64x64 778 ForceUpdateLandInfo();
768 //throw new Exception("Error: Invalid Parcel Bitmap");
769 }
770 else
771 {
772 //Valid: Lets set it
773 LandBitmap = bitmap;
774 ForceUpdateLandInfo();
775 }
776 } 779 }
777 780
778 /// <summary> 781 /// <summary>
@@ -786,15 +789,19 @@ namespace OpenSim.Region.CoreModules.World.Land
786 789
787 public bool[,] BasicFullRegionLandBitmap() 790 public bool[,] BasicFullRegionLandBitmap()
788 { 791 {
789 return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize); 792 return GetSquareLandBitmap(0, 0, (int)m_scene.RegionInfo.RegionSizeX, (int) m_scene.RegionInfo.RegionSizeY);
790 } 793 }
791 794
792 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y) 795 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
793 { 796 {
794 bool[,] tempBitmap = new bool[64,64]; 797 // Empty bitmap for the whole region
798 bool[,] tempBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
795 tempBitmap.Initialize(); 799 tempBitmap.Initialize();
796 800
801 // Fill the bitmap square area specified by state and end
797 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true); 802 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
803 // m_log.DebugFormat("{0} GetSquareLandBitmap. tempBitmapSize=<{1},{2}>",
804 // LogHeader, tempBitmap.GetLength(0), tempBitmap.GetLength(1));
798 return tempBitmap; 805 return tempBitmap;
799 } 806 }
800 807
@@ -811,24 +818,20 @@ namespace OpenSim.Region.CoreModules.World.Land
811 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y, 818 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
812 bool set_value) 819 bool set_value)
813 { 820 {
814 if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
815 {
816 //Throw an exception - The bitmap is not 64x64
817 //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
818 }
819
820 int x, y; 821 int x, y;
821 for (y = 0; y < 64; y++) 822 for (y = 0; y < land_bitmap.GetLength(1); y++)
822 { 823 {
823 for (x = 0; x < 64; x++) 824 for (x = 0; x < land_bitmap.GetLength(0); x++)
824 { 825 {
825 if (x >= start_x / 4 && x < end_x / 4 826 if (x >= start_x / landUnit && x < end_x / landUnit
826 && y >= start_y / 4 && y < end_y / 4) 827 && y >= start_y / landUnit && y < end_y / landUnit)
827 { 828 {
828 land_bitmap[x, y] = set_value; 829 land_bitmap[x, y] = set_value;
829 } 830 }
830 } 831 }
831 } 832 }
833 // m_log.DebugFormat("{0} ModifyLandBitmapSquare. startXY=<{1},{2}>, endXY=<{3},{4}>, val={5}, landBitmapSize=<{6},{7}>",
834 // LogHeader, start_x, start_y, end_x, end_y, set_value, land_bitmap.GetLength(0), land_bitmap.GetLength(1));
832 return land_bitmap; 835 return land_bitmap;
833 } 836 }
834 837
@@ -840,21 +843,21 @@ namespace OpenSim.Region.CoreModules.World.Land
840 /// <returns></returns> 843 /// <returns></returns>
841 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add) 844 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
842 { 845 {
843 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2) 846 if (bitmap_base.GetLength(0) != bitmap_add.GetLength(0)
847 || bitmap_base.GetLength(1) != bitmap_add.GetLength(1)
848 || bitmap_add.Rank != 2
849 || bitmap_base.Rank != 2)
844 { 850 {
845 //Throw an exception - The bitmap is not 64x64 851 throw new Exception(
846 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps"); 852 String.Format("{0} MergeLandBitmaps. merging maps not same size. baseSizeXY=<{1},{2}>, addSizeXY=<{3},{4}>",
847 } 853 LogHeader, bitmap_base.GetLength(0), bitmap_base.GetLength(1), bitmap_add.GetLength(0), bitmap_add.GetLength(1))
848 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2) 854 );
849 {
850 //Throw an exception - The bitmap is not 64x64
851 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
852 } 855 }
853 856
854 int x, y; 857 int x, y;
855 for (y = 0; y < 64; y++) 858 for (y = 0; y < bitmap_base.GetLength(1); y++)
856 { 859 {
857 for (x = 0; x < 64; x++) 860 for (x = 0; x < bitmap_add.GetLength(0); x++)
858 { 861 {
859 if (bitmap_add[x, y]) 862 if (bitmap_add[x, y])
860 { 863 {
@@ -871,13 +874,13 @@ namespace OpenSim.Region.CoreModules.World.Land
871 /// <returns></returns> 874 /// <returns></returns>
872 private byte[] ConvertLandBitmapToBytes() 875 private byte[] ConvertLandBitmapToBytes()
873 { 876 {
874 byte[] tempConvertArr = new byte[512]; 877 byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
875 byte tempByte = 0; 878 byte tempByte = 0;
876 int x, y, i, byteNum = 0; 879 int byteNum = 0;
877 i = 0; 880 int i = 0;
878 for (y = 0; y < 64; y++) 881 for (int y = 0; y < LandBitmap.GetLength(1); y++)
879 { 882 {
880 for (x = 0; x < 64; x++) 883 for (int x = 0; x < LandBitmap.GetLength(0); x++)
881 { 884 {
882 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8)); 885 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
883 if (i % 8 == 0) 886 if (i % 8 == 0)
@@ -889,30 +892,52 @@ namespace OpenSim.Region.CoreModules.World.Land
889 } 892 }
890 } 893 }
891 } 894 }
895 // m_log.DebugFormat("{0} ConvertLandBitmapToBytes. BitmapSize=<{1},{2}>",
896 // LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
892 return tempConvertArr; 897 return tempConvertArr;
893 } 898 }
894 899
895 private bool[,] ConvertBytesToLandBitmap() 900 private bool[,] ConvertBytesToLandBitmap()
896 { 901 {
897 bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax]; 902 bool[,] tempConvertMap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
898 tempConvertMap.Initialize(); 903 tempConvertMap.Initialize();
899 byte tempByte = 0; 904 byte tempByte = 0;
900 int x = 0, y = 0, i = 0, bitNum = 0; 905 // Math.Min overcomes an old bug that might have made it into the database. Only use the bytes that fit into convertMap.
901 for (i = 0; i < 512; i++) 906 int bitmapLen = Math.Min(LandData.Bitmap.Length, tempConvertMap.GetLength(0) * tempConvertMap.GetLength(1) / 8);
907 int xLen = (int)(m_scene.RegionInfo.RegionSizeX / landUnit);
908
909 if (bitmapLen == 512)
910 {
911 // Legacy bitmap being passed in. Use the legacy region size
912 // and only set the lower area of the larger region.
913 xLen = (int)(Constants.RegionSize / landUnit);
914 }
915 // m_log.DebugFormat("{0} ConvertBytesToLandBitmap: bitmapLen={1}, xLen={2}", LogHeader, bitmapLen, xLen);
916
917 int x = 0, y = 0;
918 for (int i = 0; i < bitmapLen; i++)
902 { 919 {
903 tempByte = LandData.Bitmap[i]; 920 tempByte = LandData.Bitmap[i];
904 for (bitNum = 0; bitNum < 8; bitNum++) 921 for (int bitNum = 0; bitNum < 8; bitNum++)
905 { 922 {
906 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1); 923 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
907 tempConvertMap[x, y] = bit; 924 try
925 {
926 tempConvertMap[x, y] = bit;
927 }
928 catch (Exception e)
929 {
930 m_log.DebugFormat("{0} ConvertBytestoLandBitmap: i={1}, x={2}, y={3}", LogHeader, i, x, y);
931 }
908 x++; 932 x++;
909 if (x > 63) 933 if (x >= xLen)
910 { 934 {
911 x = 0; 935 x = 0;
912 y++; 936 y++;
913 } 937 }
914 } 938 }
915 } 939 }
940
916 return tempConvertMap; 941 return tempConvertMap;
917 } 942 }
918 943
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
index bc52a43..1dad8ba 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
@@ -102,7 +102,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
102 102
103 terrainRenderer.Initialise(m_scene, m_config); 103 terrainRenderer.Initialise(m_scene, m_config);
104 104
105 mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 105 mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height,
106 System.Drawing.Imaging.PixelFormat.Format24bppRgb);
106 //long t = System.Environment.TickCount; 107 //long t = System.Environment.TickCount;
107 //for (int i = 0; i < 10; ++i) { 108 //for (int i = 0; i < 10; ++i) {
108 terrainRenderer.TerrainToBitmap(mapbmp); 109 terrainRenderer.TerrainToBitmap(mapbmp);
@@ -277,7 +278,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
277 private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) 278 private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp)
278 { 279 {
279 int tc = 0; 280 int tc = 0;
280 double[,] hm = whichScene.Heightmap.GetDoubles(); 281 ITerrainChannel hm = whichScene.Heightmap;
281 tc = Environment.TickCount; 282 tc = Environment.TickCount;
282 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); 283 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
283 EntityBase[] objs = whichScene.GetEntities(); 284 EntityBase[] objs = whichScene.GetEntities();
@@ -287,8 +288,6 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
287 288
288 try 289 try
289 { 290 {
290 //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
291
292 lock (objs) 291 lock (objs)
293 { 292 {
294 foreach (EntityBase obj in objs) 293 foreach (EntityBase obj in objs)
@@ -298,7 +297,6 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
298 { 297 {
299 SceneObjectGroup mapdot = (SceneObjectGroup)obj; 298 SceneObjectGroup mapdot = (SceneObjectGroup)obj;
300 Color mapdotspot = Color.Gray; // Default color when prim color is white 299 Color mapdotspot = Color.Gray; // Default color when prim color is white
301
302 // Loop over prim in group 300 // Loop over prim in group
303 foreach (SceneObjectPart part in mapdot.Parts) 301 foreach (SceneObjectPart part in mapdot.Parts)
304 { 302 {
@@ -363,7 +361,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
363 Vector3 pos = part.GetWorldPosition(); 361 Vector3 pos = part.GetWorldPosition();
364 362
365 // skip prim outside of retion 363 // skip prim outside of retion
366 if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f) 364 if (!m_scene.PositionIsInCurrentRegion(pos))
367 continue; 365 continue;
368 366
369 // skip prim in non-finite position 367 // skip prim in non-finite position
@@ -388,7 +386,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
388 Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); 386 Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
389 Vector3 scale = new Vector3(); 387 Vector3 scale = new Vector3();
390 Vector3 tScale = new Vector3(); 388 Vector3 tScale = new Vector3();
391 Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z); 389 Vector3 axPos = new Vector3(pos.X, pos.Y, pos.Z);
392 390
393 Quaternion llrot = part.GetWorldRotation(); 391 Quaternion llrot = part.GetWorldRotation();
394 Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); 392 Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z);
@@ -406,12 +404,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
406 int mapdrawendY = (int)(pos.Y + scale.Y); 404 int mapdrawendY = (int)(pos.Y + scale.Y);
407 405
408 // If object is beyond the edge of the map, don't draw it to avoid errors 406 // If object is beyond the edge of the map, don't draw it to avoid errors
409 if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1) 407 if (mapdrawstartX < 0
410 || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0 408 || mapdrawstartX > (hm.Width - 1)
411 || mapdrawendY > ((int)Constants.RegionSize - 1)) 409 || mapdrawendX < 0
410 || mapdrawendX > (hm.Width - 1)
411 || mapdrawstartY < 0
412 || mapdrawstartY > (hm.Height - 1)
413 || mapdrawendY < 0
414 || mapdrawendY > (hm.Height - 1))
412 continue; 415 continue;
413 416
414 #region obb face reconstruction part duex 417 #region obb face reconstruction part duex
415 Vector3[] vertexes = new Vector3[8]; 418 Vector3[] vertexes = new Vector3[8];
416 419
417 // float[] distance = new float[6]; 420 // float[] distance = new float[6];
@@ -515,7 +518,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
515 FaceD[2] = vertexes[7]; 518 FaceD[2] = vertexes[7];
516 FaceC[3] = vertexes[7]; 519 FaceC[3] = vertexes[7];
517 FaceD[5] = vertexes[7]; 520 FaceD[5] = vertexes[7];
518 #endregion 521 #endregion
519 522
520 //int wy = 0; 523 //int wy = 0;
521 524
@@ -530,11 +533,11 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
530 for (int i = 0; i < FaceA.Length; i++) 533 for (int i = 0; i < FaceA.Length; i++)
531 { 534 {
532 Point[] working = new Point[5]; 535 Point[] working = new Point[5];
533 working[0] = project(FaceA[i], axPos); 536 working[0] = project(hm, FaceA[i], axPos);
534 working[1] = project(FaceB[i], axPos); 537 working[1] = project(hm, FaceB[i], axPos);
535 working[2] = project(FaceD[i], axPos); 538 working[2] = project(hm, FaceD[i], axPos);
536 working[3] = project(FaceC[i], axPos); 539 working[3] = project(hm, FaceC[i], axPos);
537 working[4] = project(FaceA[i], axPos); 540 working[4] = project(hm, FaceA[i], axPos);
538 541
539 face workingface = new face(); 542 face workingface = new face();
540 workingface.pts = working; 543 workingface.pts = working;
@@ -546,27 +549,25 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
546 z_localIDs.Add(part.LocalId); 549 z_localIDs.Add(part.LocalId);
547 z_sortheights.Add(pos.Z); 550 z_sortheights.Add(pos.Z);
548 551
549 //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) 552 // for (int wx = mapdrawstartX; wx < mapdrawendX; wx++)
550 //{ 553 // {
551 //for (wy = mapdrawstartY; wy < mapdrawendY; wy++) 554 // for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
552 //{ 555 // {
553 //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); 556 // m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy);
554 //try 557 // try
555 //{ 558 // {
556 // Remember, flip the y! 559 // // Remember, flip the y!
557 // mapbmp.SetPixel(wx, (255 - wy), mapdotspot); 560 // mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
558 //} 561 // }
559 //catch (ArgumentException) 562 // catch (ArgumentException)
560 //{ 563 // {
561 // breakYN = true; 564 // breakYN = true;
562 //} 565 // }
563 566 // }
564 //if (breakYN) 567 // if (breakYN)
565 // break; 568 // break;
566 //} 569 // }
567 570 // }
568 //if (breakYN)
569 // break;
570 //} 571 //}
571 } // Object is within 256m Z of terrain 572 } // Object is within 256m Z of terrain
572 } // object is at least a meter wide 573 } // object is at least a meter wide
@@ -609,17 +610,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
609 return mapbmp; 610 return mapbmp;
610 } 611 }
611 612
612 private Point project(Vector3 point3d, Vector3 originpos) 613 private Point project(ITerrainChannel hm, Vector3 point3d, Vector3 originpos)
613 { 614 {
614 Point returnpt = new Point(); 615 Point returnpt = new Point();
615 //originpos = point3d; 616 //originpos = point3d;
616 //int d = (int)(256f / 1.5f); 617 //int d = (int)(256f / 1.5f);
617 618
618 //Vector3 topos = new Vector3(0, 0, 0); 619 //Vector3 topos = new Vector3(0, 0, 0);
619 // float z = -point3d.z - topos.z; 620 // float z = -point3d.z - topos.z;
620 621
621 returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d); 622 returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d);
622 returnpt.Y = (int)(((int)Constants.RegionSize - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d))); 623 returnpt.Y = (int)((hm.Width - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d)));
623 624
624 return returnpt; 625 return returnpt;
625 } 626 }
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
index cb06fd4..708286c 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
@@ -31,6 +31,7 @@ using System.Reflection;
31using log4net; 31using log4net;
32using Nini.Config; 32using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
35 36
36namespace OpenSim.Region.CoreModules.World.LegacyMap 37namespace OpenSim.Region.CoreModules.World.LegacyMap
@@ -39,8 +40,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
39 { 40 {
40 private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); 41 private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95);
41 42
42 private static readonly ILog m_log = 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly string LogHeader = "[SHADED MAPTILE RENDERER]";
44 45
45 private Scene m_scene; 46 private Scene m_scene;
46 //private IConfigSource m_config; // not used currently 47 //private IConfigSource m_config; // not used currently
@@ -53,19 +54,26 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
53 54
54 public void TerrainToBitmap(Bitmap mapbmp) 55 public void TerrainToBitmap(Bitmap mapbmp)
55 { 56 {
57 m_log.DebugFormat("{0} Generating Maptile Step 1: Terrain", LogHeader);
56 int tc = Environment.TickCount; 58 int tc = Environment.TickCount;
57 m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain");
58 59
59 double[,] hm = m_scene.Heightmap.GetDoubles(); 60 ITerrainChannel hm = m_scene.Heightmap;
61
62 if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height)
63 {
64 m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>",
65 LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
66 }
67
60 bool ShadowDebugContinue = true; 68 bool ShadowDebugContinue = true;
61 69
62 bool terraincorruptedwarningsaid = false; 70 bool terraincorruptedwarningsaid = false;
63 71
64 float low = 255; 72 float low = 255;
65 float high = 0; 73 float high = 0;
66 for (int x = 0; x < (int)Constants.RegionSize; x++) 74 for (int x = 0; x < hm.Width; x++)
67 { 75 {
68 for (int y = 0; y < (int)Constants.RegionSize; y++) 76 for (int y = 0; y < hm.Height; y++)
69 { 77 {
70 float hmval = (float)hm[x, y]; 78 float hmval = (float)hm[x, y];
71 if (hmval < low) 79 if (hmval < low)
@@ -77,12 +85,12 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
77 85
78 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; 86 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
79 87
80 for (int x = 0; x < (int)Constants.RegionSize; x++) 88 for (int x = 0; x < hm.Width; x++)
81 { 89 {
82 for (int y = 0; y < (int)Constants.RegionSize; y++) 90 for (int y = 0; y < hm.Height; y++)
83 { 91 {
84 // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left 92 // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left
85 int yr = ((int)Constants.RegionSize - 1) - y; 93 int yr = ((int)hm.Height - 1) - y;
86 94
87 float heightvalue = (float)hm[x, y]; 95 float heightvalue = (float)hm[x, y];
88 96
@@ -109,12 +117,12 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
109 // . 117 // .
110 // 118 //
111 // Shade the terrain for shadows 119 // Shade the terrain for shadows
112 if (x < ((int)Constants.RegionSize - 1) && yr < ((int)Constants.RegionSize - 1)) 120 if (x < (hm.Width - 1) && yr < (hm.Height - 1))
113 { 121 {
114 float hfvalue = (float)hm[x, y]; 122 float hfvalue = (float)hm[x, y];
115 float hfvaluecompare = 0f; 123 float hfvaluecompare = 0f;
116 124
117 if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize)) 125 if ((x + 1 < hm.Width) && (y + 1 < hm.Height))
118 { 126 {
119 hfvaluecompare = (float)hm[x + 1, y + 1]; // light from north-east => look at land height there 127 hfvaluecompare = (float)hm[x + 1, y + 1]; // light from north-east => look at land height there
120 } 128 }
@@ -179,7 +187,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
179 187
180 if (ShadowDebugContinue) 188 if (ShadowDebugContinue)
181 { 189 {
182 if ((x - 1 > 0) && (yr + 1 < (int)Constants.RegionSize)) 190 if ((x - 1 > 0) && (yr + 1 < hm.Height))
183 { 191 {
184 color = mapbmp.GetPixel(x - 1, yr + 1); 192 color = mapbmp.GetPixel(x - 1, yr + 1);
185 int r = color.R; 193 int r = color.R;
@@ -233,7 +241,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
233 terraincorruptedwarningsaid = true; 241 terraincorruptedwarningsaid = true;
234 } 242 }
235 Color black = Color.Black; 243 Color black = Color.Black;
236 mapbmp.SetPixel(x, ((int)Constants.RegionSize - y) - 1, black); 244 mapbmp.SetPixel(x, (hm.Width - y) - 1, black);
237 } 245 }
238 } 246 }
239 } 247 }
@@ -242,4 +250,4 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
242 m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 250 m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
243 } 251 }
244 } 252 }
245} \ No newline at end of file 253}
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
index e895178..9f23141 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
@@ -34,6 +34,8 @@ using Nini.Config;
34using OpenMetaverse; 34using OpenMetaverse;
35using OpenMetaverse.Imaging; 35using OpenMetaverse.Imaging;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Region.Framework;
38using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
38 40
39namespace OpenSim.Region.CoreModules.World.LegacyMap 41namespace OpenSim.Region.CoreModules.World.LegacyMap
@@ -122,8 +124,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
122 { 124 {
123 #region Constants 125 #region Constants
124 126
125 private static readonly ILog m_log = 127 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
126 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 128 private static readonly string LogHeader = "[TEXTURED MAPTILE RENDERER]";
127 129
128 // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank"). 130 // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank").
129 // The color-values were choosen because they "look right" (at least to me) ;-) 131 // The color-values were choosen because they "look right" (at least to me) ;-)
@@ -173,7 +175,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
173 private Bitmap fetchTexture(UUID id) 175 private Bitmap fetchTexture(UUID id)
174 { 176 {
175 AssetBase asset = m_scene.AssetService.Get(id.ToString()); 177 AssetBase asset = m_scene.AssetService.Get(id.ToString());
176 m_log.DebugFormat("[TEXTURED MAP TILE RENDERER]: Fetched texture {0}, found: {1}", id, asset != null); 178 m_log.DebugFormat("{0} Fetched texture {1}, found: {2}", LogHeader, id, asset != null);
177 if (asset == null) return null; 179 if (asset == null) return null;
178 180
179 ManagedImage managedImage; 181 ManagedImage managedImage;
@@ -188,18 +190,15 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
188 } 190 }
189 catch (DllNotFoundException) 191 catch (DllNotFoundException)
190 { 192 {
191 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id); 193 m_log.ErrorFormat("{0} OpenJpeg is not installed correctly on this system. Asset Data is empty for {1}", LogHeader, id);
192
193 } 194 }
194 catch (IndexOutOfRangeException) 195 catch (IndexOutOfRangeException)
195 { 196 {
196 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); 197 m_log.ErrorFormat("{0} OpenJpeg was unable to encode this. Asset Data is empty for {1}", LogHeader, id);
197
198 } 198 }
199 catch (Exception) 199 catch (Exception)
200 { 200 {
201 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); 201 m_log.ErrorFormat("{0} OpenJpeg was unable to encode this. Asset Data is empty for {1}", LogHeader, id);
202
203 } 202 }
204 return null; 203 return null;
205 204
@@ -271,8 +270,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
271 270
272 // the heigthfield might have some jumps in values. Rendered land is smooth, though, 271 // the heigthfield might have some jumps in values. Rendered land is smooth, though,
273 // as a slope is rendered at that place. So average 4 neighbour values to emulate that. 272 // as a slope is rendered at that place. So average 4 neighbour values to emulate that.
274 private float getHeight(double[,] hm, int x, int y) { 273 private float getHeight(ITerrainChannel hm, int x, int y) {
275 if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) 274 if (x < (hm.Width - 1) && y < (hm.Height - 1))
276 return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); 275 return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112);
277 else 276 else
278 return (float)hm[x, y]; 277 return (float)hm[x, y];
@@ -282,7 +281,15 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
282 public void TerrainToBitmap(Bitmap mapbmp) 281 public void TerrainToBitmap(Bitmap mapbmp)
283 { 282 {
284 int tc = Environment.TickCount; 283 int tc = Environment.TickCount;
285 m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain"); 284 m_log.DebugFormat("{0} Generating Maptile Step 1: Terrain", LogHeader);
285
286 ITerrainChannel hm = m_scene.Heightmap;
287
288 if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height)
289 {
290 m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>",
291 LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
292 }
286 293
287 // These textures should be in the AssetCache anyway, as every client conneting to this 294 // These textures should be in the AssetCache anyway, as every client conneting to this
288 // region needs them. Except on start, when the map is recreated (before anyone connected), 295 // region needs them. Except on start, when the map is recreated (before anyone connected),
@@ -310,19 +317,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
310 317
311 float waterHeight = (float)settings.WaterHeight; 318 float waterHeight = (float)settings.WaterHeight;
312 319
313 double[,] hm = m_scene.Heightmap.GetDoubles(); 320 for (int x = 0; x < hm.Width; x++)
314
315 for (int x = 0; x < (int)Constants.RegionSize; x++)
316 { 321 {
317 float columnRatio = x / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation 322 float columnRatio = x / (hm.Width - 1); // 0 - 1, for interpolation
318 for (int y = 0; y < (int)Constants.RegionSize; y++) 323 for (int y = 0; y < hm.Height; y++)
319 { 324 {
320 float rowRatio = y / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation 325 float rowRatio = y / (hm.Height - 1); // 0 - 1, for interpolation
321 326
322 // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left 327 // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left
323 int yr = ((int)Constants.RegionSize - 1) - y; 328 int yr = (hm.Height - 1) - y;
324 329
325 float heightvalue = getHeight(hm, x, y); 330 float heightvalue = getHeight(m_scene.Heightmap, x, y);
326 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) 331 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
327 heightvalue = 0; 332 heightvalue = 0;
328 333
@@ -372,9 +377,9 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
372 } 377 }
373 378
374 // Shade the terrain for shadows 379 // Shade the terrain for shadows
375 if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) 380 if (x < (hm.Width - 1) && y < (hm.Height - 1))
376 { 381 {
377 float hfvaluecompare = getHeight(hm, x + 1, y + 1); // light from north-east => look at land height there 382 float hfvaluecompare = getHeight(m_scene.Heightmap, x + 1, y + 1); // light from north-east => look at land height there
378 if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) 383 if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare))
379 hfvaluecompare = 0f; 384 hfvaluecompare = 0f;
380 385
@@ -420,4 +425,4 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
420 m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 425 m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
421 } 426 }
422 } 427 }
423} \ No newline at end of file 428}
diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
index 0cb574a..b8d4855 100644
--- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
+++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
@@ -151,14 +151,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
151 break; 151 break;
152 152
153 case 2: // Sell a copy 153 case 2: // Sell a copy
154 Vector3 inventoryStoredPosition = new Vector3 154 Vector3 inventoryStoredPosition = new Vector3(
155 (((group.AbsolutePosition.X > (int)Constants.RegionSize) 155 Math.Min(group.AbsolutePosition.X, m_scene.RegionInfo.RegionSizeX - 6),
156 ? 250 156 Math.Min(group.AbsolutePosition.Y, m_scene.RegionInfo.RegionSizeY - 6),
157 : group.AbsolutePosition.X)
158 ,
159 (group.AbsolutePosition.X > (int)Constants.RegionSize)
160 ? 250
161 : group.AbsolutePosition.X,
162 group.AbsolutePosition.Z); 157 group.AbsolutePosition.Z);
163 158
164 Vector3 originalPosition = group.AbsolutePosition; 159 Vector3 originalPosition = group.AbsolutePosition;
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index f8e93e1..45617fc 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -1571,10 +1571,10 @@ namespace OpenSim.Region.CoreModules.World.Permissions
1571 float X = position.X; 1571 float X = position.X;
1572 float Y = position.Y; 1572 float Y = position.Y;
1573 1573
1574 if (X > ((int)Constants.RegionSize - 1)) 1574 if (X > ((int)m_scene.RegionInfo.RegionSizeX - 1))
1575 X = ((int)Constants.RegionSize - 1); 1575 X = ((int)m_scene.RegionInfo.RegionSizeX - 1);
1576 if (Y > ((int)Constants.RegionSize - 1)) 1576 if (Y > ((int)m_scene.RegionInfo.RegionSizeY - 1))
1577 Y = ((int)Constants.RegionSize - 1); 1577 Y = ((int)m_scene.RegionInfo.RegionSizeY - 1);
1578 if (X < 0) 1578 if (X < 0)
1579 X = 0; 1579 X = 0;
1580 if (Y < 0) 1580 if (Y < 0)
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
index 7186dd7..89087b1 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
@@ -42,7 +42,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
42 for (y = 0; y < map.Height; y++) 42 for (y = 0; y < map.Height; y++)
43 { 43 {
44 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; 44 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
45 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; 45 double spherFac = TerrainUtil.SphericalFactor(x, y, map.Width / 2, map.Height / 2, 50) * 0.01;
46 if (map[x, y] < spherFac) 46 if (map[x, y] < spherFac)
47 { 47 {
48 map[x, y] = spherFac; 48 map[x, y] = spherFac;
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/FloodBrushes/NoiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
index 630473e..b6c635c 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
@@ -45,7 +45,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
45 { 45 {
46 if (fillArea[x, y]) 46 if (fillArea[x, y])
47 { 47 {
48 double noise = TerrainUtil.PerlinNoise2D((double) x / Constants.RegionSize, (double) y / Constants.RegionSize, 8, 1.0); 48 double noise = TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0);
49 49
50 map[x, y] += noise * strength; 50 map[x, y] += noise * strength;
51 } 51 }
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
index 989b7d8..e7df3f8 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
53 z *= z; 53 z *= z;
54 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 54 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
55 55
56 double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0); 56 double noise = TerrainUtil.PerlinNoise2D(x / (double) map.Width, y / (double) map.Height, 8, 1.0);
57 57
58 if (z > 0.0) 58 if (z > 0.0)
59 map[x, y] += noise * z * duration; 59 map[x, y] += noise * z * duration;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index fd30c46..7bc5e88 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
@@ -230,11 +235,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
230 try 235 try
231 { 236 {
232 ITerrainChannel channel = loader.Value.LoadFile(filename); 237 ITerrainChannel channel = loader.Value.LoadFile(filename);
233 if (channel.Width != Constants.RegionSize || channel.Height != Constants.RegionSize) 238 if (channel.Width != m_scene.RegionInfo.RegionSizeX || channel.Height != m_scene.RegionInfo.RegionSizeY)
234 { 239 {
235 // TerrainChannel expects a RegionSize x RegionSize map, currently 240 // TerrainChannel expects a RegionSize x RegionSize map, currently
236 throw new ArgumentException(String.Format("wrong size, use a file with size {0} x {1}", 241 throw new ArgumentException(String.Format("wrong size, use a file with size {0} x {1}",
237 Constants.RegionSize, Constants.RegionSize)); 242 m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY));
238 } 243 }
239 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height); 244 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height);
240 m_scene.Heightmap = channel; 245 m_scene.Heightmap = channel;
@@ -309,12 +314,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain
309 LoadFromStream(filename, URIFetch(pathToTerrainHeightmap)); 314 LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
310 } 315 }
311 316
317 public void LoadFromStream(string filename, Stream stream)
318 {
319 Vector2 defaultDisplacement = new Vector2(0f, 0f);
320 LoadFromStream(filename, defaultDisplacement, stream);
321 }
322
312 /// <summary> 323 /// <summary>
313 /// Loads a terrain file from a stream and installs it in the scene. 324 /// Loads a terrain file from a stream and installs it in the scene.
314 /// </summary> 325 /// </summary>
315 /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> 326 /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
316 /// <param name="stream"></param> 327 /// <param name="stream"></param>
317 public void LoadFromStream(string filename, Stream stream) 328 public void LoadFromStream(string filename, Vector2 displacement, Stream stream)
318 { 329 {
319 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) 330 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
320 { 331 {
@@ -325,8 +336,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
325 try 336 try
326 { 337 {
327 ITerrainChannel channel = loader.Value.LoadStream(stream); 338 ITerrainChannel channel = loader.Value.LoadStream(stream);
328 m_scene.Heightmap = channel; 339 MergeTerrainIntoExisting(channel, displacement);
329 m_channel = channel;
330 UpdateRevertMap(); 340 UpdateRevertMap();
331 } 341 }
332 catch (NotImplementedException) 342 catch (NotImplementedException)
@@ -346,6 +356,33 @@ namespace OpenSim.Region.CoreModules.World.Terrain
346 throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); 356 throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
347 } 357 }
348 358
359 private void MergeTerrainIntoExisting(ITerrainChannel channel, Vector2 displacement)
360 {
361 if (displacement == Vector2.Zero)
362 {
363 // If there is no displacement, just use this channel as the new heightmap
364 m_scene.Heightmap = channel;
365 m_channel = channel;
366 }
367 else
368 {
369 // If there is a displacement, we copy the loaded heightmap into the overall region
370 for (int xx = 0; xx < channel.Width; xx++)
371 {
372 for (int yy = 0; yy < channel.Height; yy++)
373 {
374 int dispX = xx + (int)displacement.X;
375 int dispY = yy + (int)displacement.Y;
376 if (dispX >= 0 && dispX < m_channel.Width
377 && dispY >= 0 && dispY < m_channel.Height)
378 {
379 m_channel[dispX, dispY] = channel[xx, yy];
380 }
381 }
382 }
383 }
384 }
385
349 private static Stream URIFetch(Uri uri) 386 private static Stream URIFetch(Uri uri)
350 { 387 {
351 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); 388 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
@@ -532,6 +569,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
532 /// </summary> 569 /// </summary>
533 public void UpdateRevertMap() 570 public void UpdateRevertMap()
534 { 571 {
572 /*
535 int x; 573 int x;
536 for (x = 0; x < m_channel.Width; x++) 574 for (x = 0; x < m_channel.Width; x++)
537 { 575 {
@@ -541,6 +579,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
541 m_revert[x, y] = m_channel[x, y]; 579 m_revert[x, y] = m_channel[x, y];
542 } 580 }
543 } 581 }
582 */
583 m_revert = m_channel.MakeCopy();
544 } 584 }
545 585
546 /// <summary> 586 /// <summary>
@@ -567,8 +607,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
567 { 607 {
568 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, 608 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
569 fileWidth, fileHeight, 609 fileWidth, fileHeight,
570 (int) Constants.RegionSize, 610 (int) m_scene.RegionInfo.RegionSizeX,
571 (int) Constants.RegionSize); 611 (int) m_scene.RegionInfo.RegionSizeY);
572 m_scene.Heightmap = channel; 612 m_scene.Heightmap = channel;
573 m_channel = channel; 613 m_channel = channel;
574 UpdateRevertMap(); 614 UpdateRevertMap();
@@ -615,8 +655,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
615 { 655 {
616 loader.Value.SaveFile(m_channel, filename, offsetX, offsetY, 656 loader.Value.SaveFile(m_channel, filename, offsetX, offsetY,
617 fileWidth, fileHeight, 657 fileWidth, fileHeight,
618 (int)Constants.RegionSize, 658 (int)m_scene.RegionInfo.RegionSizeX,
619 (int)Constants.RegionSize); 659 (int)m_scene.RegionInfo.RegionSizeY);
620 660
621 MainConsole.Instance.OutputFormat( 661 MainConsole.Instance.OutputFormat(
622 "Saved terrain from ({0},{1}) to ({2},{3}) from {4} to {5}", 662 "Saved terrain from ({0},{1}) to ({2},{3}) from {4} to {5}",
@@ -705,7 +745,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
705 private void CheckForTerrainUpdates(bool respectEstateSettings) 745 private void CheckForTerrainUpdates(bool respectEstateSettings)
706 { 746 {
707 bool shouldTaint = false; 747 bool shouldTaint = false;
708 float[] serialised = m_channel.GetFloatsSerialised(); 748 float[] terrHeights = m_channel.GetFloatsSerialised();
709 int x; 749 int x;
710 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) 750 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
711 { 751 {
@@ -714,16 +754,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain
714 { 754 {
715 if (m_channel.Tainted(x, y)) 755 if (m_channel.Tainted(x, y))
716 { 756 {
717 // if we should respect the estate settings then 757 // If we should respect the estate settings then
718 // fixup and height deltas that don't respect them 758 // fixup and height deltas that don't respect them.
759 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values.
719 if (respectEstateSettings && LimitChannelChanges(x, y)) 760 if (respectEstateSettings && LimitChannelChanges(x, y))
720 { 761 {
721 // this has been vetoed, so update 762 // Terrain heights were modified. Refetch the terrain info.
722 // what we are going to send to the client 763 terrHeights = m_channel.GetFloatsSerialised();
723 serialised = m_channel.GetFloatsSerialised();
724 } 764 }
725 765
726 SendToClients(serialised, x, y); 766 // m_log.DebugFormat("{0} Patch modified. Sending (x,y) = ({1},{2})", LogHeader, x, y);
767 SendToClients(terrHeights, x, y);
727 shouldTaint = true; 768 shouldTaint = true;
728 } 769 }
729 } 770 }
@@ -792,13 +833,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> 833 /// <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> 834 /// <param name="x">The patch corner to send</param>
794 /// <param name="y">The patch corner to send</param> 835 /// <param name="y">The patch corner to send</param>
795 private void SendToClients(float[] serialised, int x, int y) 836 private void SendToClients(float[] heightMap, int x, int y)
796 { 837 {
797 m_scene.ForEachClient( 838 m_scene.ForEachClient(
798 delegate(IClientAPI controller) 839 delegate(IClientAPI controller)
799 { controller.SendLayerData( 840 { controller.SendLayerData( x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, heightMap); }
800 x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised);
801 }
802 ); 841 );
803 } 842 }
804 843
@@ -984,28 +1023,28 @@ namespace OpenSim.Region.CoreModules.World.Terrain
984 1023
985 if (direction.ToLower().StartsWith("y")) 1024 if (direction.ToLower().StartsWith("y"))
986 { 1025 {
987 for (int x = 0; x < Constants.RegionSize; x++) 1026 for (int x = 0; x < m_channel.Width; x++)
988 { 1027 {
989 for (int y = 0; y < Constants.RegionSize / 2; y++) 1028 for (int y = 0; y < m_channel.Height / 2; y++)
990 { 1029 {
991 double height = m_channel[x, y]; 1030 double height = m_channel[x, y];
992 double flippedHeight = m_channel[x, (int)Constants.RegionSize - 1 - y]; 1031 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y];
993 m_channel[x, y] = flippedHeight; 1032 m_channel[x, y] = flippedHeight;
994 m_channel[x, (int)Constants.RegionSize - 1 - y] = height; 1033 m_channel[x, (int)m_channel.Height - 1 - y] = height;
995 1034
996 } 1035 }
997 } 1036 }
998 } 1037 }
999 else if (direction.ToLower().StartsWith("x")) 1038 else if (direction.ToLower().StartsWith("x"))
1000 { 1039 {
1001 for (int y = 0; y < Constants.RegionSize; y++) 1040 for (int y = 0; y < m_channel.Height; y++)
1002 { 1041 {
1003 for (int x = 0; x < Constants.RegionSize / 2; x++) 1042 for (int x = 0; x < m_channel.Width / 2; x++)
1004 { 1043 {
1005 double height = m_channel[x, y]; 1044 double height = m_channel[x, y];
1006 double flippedHeight = m_channel[(int)Constants.RegionSize - 1 - x, y]; 1045 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y];
1007 m_channel[x, y] = flippedHeight; 1046 m_channel[x, y] = flippedHeight;
1008 m_channel[(int)Constants.RegionSize - 1 - x, y] = height; 1047 m_channel[(int)m_channel.Width - 1 - x, y] = height;
1009 1048
1010 } 1049 }
1011 } 1050 }
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
index df5ac92..9534ad3 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -32,6 +32,7 @@ using System.Drawing.Imaging;
32using log4net; 32using log4net;
33using OpenMetaverse; 33using OpenMetaverse;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Services.Interfaces; 36using OpenSim.Services.Interfaces;
36 37
37namespace OpenSim.Region.CoreModules.World.Warp3DMap 38namespace OpenSim.Region.CoreModules.World.Warp3DMap
@@ -66,261 +67,271 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
66 #endregion Constants 67 #endregion Constants
67 68
68 private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name); 69 private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
70 private static string LogHeader = "[WARP3D TERRAIN SPLAT]";
69 71
70 /// <summary> 72 /// <summary>
71 /// Builds a composited terrain texture given the region texture 73 /// Builds a composited terrain texture given the region texture
72 /// and heightmap settings 74 /// and heightmap settings
73 /// </summary> 75 /// </summary>
74 /// <param name="heightmap">Terrain heightmap</param> 76 /// <param name="terrain">Terrain heightmap</param>
75 /// <param name="regionInfo">Region information including terrain texture parameters</param> 77 /// <param name="regionInfo">Region information including terrain texture parameters</param>
76 /// <returns>A composited 256x256 RGB texture ready for rendering</returns> 78 /// <returns>A 256x256 square RGB texture ready for rendering</returns>
77 /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting 79 /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting
80 /// Note we create a 256x256 dimension texture even if the actual terrain is larger.
78 /// </remarks> 81 /// </remarks>
79 public static Bitmap Splat(float[] heightmap, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain) 82 public static Bitmap Splat(ITerrainChannel terrain,
83 UUID[] textureIDs, float[] startHeights, float[] heightRanges,
84 Vector3d regionPosition, IAssetService assetService, bool textureTerrain)
80 { 85 {
81 Debug.Assert(heightmap.Length == 256 * 256);
82 Debug.Assert(textureIDs.Length == 4); 86 Debug.Assert(textureIDs.Length == 4);
83 Debug.Assert(startHeights.Length == 4); 87 Debug.Assert(startHeights.Length == 4);
84 Debug.Assert(heightRanges.Length == 4); 88 Debug.Assert(heightRanges.Length == 4);
85 89
86 Bitmap[] detailTexture = new Bitmap[4]; 90 Bitmap[] detailTexture = new Bitmap[4];
87 Bitmap output = null;
88 BitmapData outputData = null;
89 91
90 try 92 if (textureTerrain)
91 { 93 {
92 if (textureTerrain) 94 // Swap empty terrain textureIDs with default IDs
95 for (int i = 0; i < textureIDs.Length; i++)
93 { 96 {
94 // Swap empty terrain textureIDs with default IDs 97 if (textureIDs[i] == UUID.Zero)
95 for (int i = 0; i < textureIDs.Length; i++) 98 textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
96 { 99 }
97 if (textureIDs[i] == UUID.Zero) 100
98 textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i]; 101 #region Texture Fetching
99 } 102
100 103 if (assetService != null)
101 #region Texture Fetching 104 {
102 105 for (int i = 0; i < 4; i++)
103 if (assetService != null)
104 { 106 {
105 for (int i = 0; i < 4; i++) 107 AssetBase asset;
108 UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
109
110 // Try to fetch a cached copy of the decoded/resized version of this texture
111 asset = assetService.GetCached(cacheID.ToString());
112 if (asset != null)
113 {
114 try
115 {
116 using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
117 detailTexture[i] = (Bitmap)Image.FromStream(stream);
118 }
119 catch (Exception ex)
120 {
121 m_log.Warn("Failed to decode cached terrain texture " + cacheID +
122 " (textureID: " + textureIDs[i] + "): " + ex.Message);
123 }
124 }
125
126 if (detailTexture[i] == null)
106 { 127 {
107 AssetBase asset; 128 // Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
108 UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]); 129 asset = assetService.Get(textureIDs[i].ToString());
109
110 // Try to fetch a cached copy of the decoded/resized version of this texture
111 asset = assetService.GetCached(cacheID.ToString());
112 if (asset != null) 130 if (asset != null)
113 { 131 {
114// m_log.DebugFormat( 132// m_log.DebugFormat(
115// "[TERRAIN SPLAT]: Got asset service cached terrain texture {0} {1}", i, asset.ID); 133// "[TERRAIN SPLAT]: Got cached original JPEG2000 terrain texture {0} {1}", i, asset.ID);
116 134
117 try 135 try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
118 {
119 using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
120 detailTexture[i] = (Bitmap)Image.FromStream(stream);
121 }
122 catch (Exception ex) 136 catch (Exception ex)
123 { 137 {
124 m_log.Warn("Failed to decode cached terrain texture " + cacheID + 138 m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
125 " (textureID: " + textureIDs[i] + "): " + ex.Message);
126 } 139 }
127 } 140 }
128
129 if (detailTexture[i] == null)
130 {
131 // Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
132 asset = assetService.Get(textureIDs[i].ToString());
133 if (asset != null)
134 {
135// m_log.DebugFormat(
136// "[TERRAIN SPLAT]: Got cached original JPEG2000 terrain texture {0} {1}", i, asset.ID);
137 141
138 try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); } 142 if (detailTexture[i] != null)
139 catch (Exception ex) 143 {
144 // Make sure this texture is the correct size, otherwise resize
145 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
146 {
147 using (Bitmap origBitmap = detailTexture[i])
140 { 148 {
141 m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message); 149 detailTexture[i] = ImageUtils.ResizeImage(origBitmap, 256, 256);
142 } 150 }
143 } 151 }
144 152
145 if (detailTexture[i] != null) 153 // Save the decoded and resized texture to the cache
146 { 154 byte[] data;
147 // Make sure this texture is the correct size, otherwise resize 155 using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
148 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) 156 {
149 { 157 detailTexture[i].Save(stream, ImageFormat.Png);
150 using (Bitmap origBitmap = detailTexture[i]) 158 data = stream.ToArray();
151 {
152 detailTexture[i] = ImageUtils.ResizeImage(origBitmap, 256, 256);
153 }
154 }
155
156 // Save the decoded and resized texture to the cache
157 byte[] data;
158 using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
159 {
160 detailTexture[i].Save(stream, ImageFormat.Png);
161 data = stream.ToArray();
162 }
163
164 // Cache a PNG copy of this terrain texture
165 AssetBase newAsset = new AssetBase
166 {
167 Data = data,
168 Description = "PNG",
169 Flags = AssetFlags.Collectable,
170 FullID = cacheID,
171 ID = cacheID.ToString(),
172 Local = true,
173 Name = String.Empty,
174 Temporary = true,
175 Type = (sbyte)AssetType.Unknown
176 };
177 newAsset.Metadata.ContentType = "image/png";
178 assetService.Store(newAsset);
179 } 159 }
160
161 // Cache a PNG copy of this terrain texture
162 AssetBase newAsset = new AssetBase
163 {
164 Data = data,
165 Description = "PNG",
166 Flags = AssetFlags.Collectable,
167 FullID = cacheID,
168 ID = cacheID.ToString(),
169 Local = true,
170 Name = String.Empty,
171 Temporary = true,
172 Type = (sbyte)AssetType.Unknown
173 };
174 newAsset.Metadata.ContentType = "image/png";
175 assetService.Store(newAsset);
180 } 176 }
181 } 177 }
182 } 178 }
183
184 #endregion Texture Fetching
185 } 179 }
186 180
187 // Fill in any missing textures with a solid color 181 #endregion Texture Fetching
188 for (int i = 0; i < 4; i++) 182 }
183
184 // Fill in any missing textures with a solid color
185 for (int i = 0; i < 4; i++)
186 {
187 if (detailTexture[i] == null)
189 { 188 {
190 if (detailTexture[i] == null) 189 m_log.DebugFormat("{0} Missing terrain texture for layer {1}. Filling with solid default color",
190 LogHeader, i);
191 // Create a solid color texture for this layer
192 detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
193 using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
191 { 194 {
192// m_log.DebugFormat( 195 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
193// "[TERRAIN SPLAT]: Generating solid colour for missing texture {0}", i); 196 gfx.FillRectangle(brush, 0, 0, 256, 256);
194
195 // Create a solid color texture for this layer
196 detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
197 using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
198 {
199 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
200 gfx.FillRectangle(brush, 0, 0, 256, 256);
201 }
202 } 197 }
203 } 198 }
204 199 else
205 #region Layer Map
206
207 float[] layermap = new float[256 * 256];
208
209 for (int y = 0; y < 256; y++)
210 { 200 {
211 for (int x = 0; x < 256; x++) 201 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
212 { 202 {
213 float height = heightmap[y * 256 + x]; 203 detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256);
214
215 float pctX = (float)x / 255f;
216 float pctY = (float)y / 255f;
217
218 // Use bilinear interpolation between the four corners of start height and
219 // height range to select the current values at this position
220 float startHeight = ImageUtils.Bilinear(
221 startHeights[0],
222 startHeights[2],
223 startHeights[1],
224 startHeights[3],
225 pctX, pctY);
226 startHeight = Utils.Clamp(startHeight, 0f, 255f);
227
228 float heightRange = ImageUtils.Bilinear(
229 heightRanges[0],
230 heightRanges[2],
231 heightRanges[1],
232 heightRanges[3],
233 pctX, pctY);
234 heightRange = Utils.Clamp(heightRange, 0f, 255f);
235
236 // Generate two frequencies of perlin noise based on our global position
237 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
238 Vector3 vec = new Vector3
239 (
240 ((float)regionPosition.X + x) * 0.20319f,
241 ((float)regionPosition.Y + y) * 0.20319f,
242 height * 0.25f
243 );
244
245 float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
246 float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
247 float noise = (lowFreq + highFreq) * 2f;
248
249 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
250 float layer = ((height + noise - startHeight) / heightRange) * 4f;
251 if (Single.IsNaN(layer)) layer = 0f;
252 layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f);
253 } 204 }
254 } 205 }
255 206 }
256 #endregion Layer Map 207
257 208 #region Layer Map
258 #region Texture Compositing 209
259 210 float[,] layermap = new float[256, 256];
260 output = new Bitmap(256, 256, PixelFormat.Format24bppRgb); 211
261 outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); 212 // Scale difference between actual region size and the 256 texture being created
262 213 int xFactor = terrain.Width / 256;
263 unsafe 214 int yFactor = terrain.Height / 256;
215
216 // Create 'layermap' where each value is the fractional layer number to place
217 // at that point. For instance, a value of 1.345 gives the blending of
218 // layer 1 and layer 2 for that point.
219 for (int y = 0; y < 256; y++)
220 {
221 for (int x = 0; x < 256; x++)
264 { 222 {
265 // Get handles to all of the texture data arrays 223 float height = (float)terrain[x * xFactor, y * yFactor];
266 BitmapData[] datas = new BitmapData[] 224
267 { 225 float pctX = (float)x / 255f;
268 detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat), 226 float pctY = (float)y / 255f;
269 detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat), 227
270 detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat), 228 // Use bilinear interpolation between the four corners of start height and
271 detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat) 229 // height range to select the current values at this position
272 }; 230 float startHeight = ImageUtils.Bilinear(
273 231 startHeights[0],
274 int[] comps = new int[] 232 startHeights[2],
275 { 233 startHeights[1],
276 (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, 234 startHeights[3],
277 (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, 235 pctX, pctY);
278 (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, 236 startHeight = Utils.Clamp(startHeight, 0f, 255f);
279 (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3 237
280 }; 238 float heightRange = ImageUtils.Bilinear(
281 239 heightRanges[0],
282 for (int y = 0; y < 256; y++) 240 heightRanges[2],
283 { 241 heightRanges[1],
284 for (int x = 0; x < 256; x++) 242 heightRanges[3],
285 { 243 pctX, pctY);
286 float layer = layermap[y * 256 + x]; 244 heightRange = Utils.Clamp(heightRange, 0f, 255f);
287 245
288 // Select two textures 246 // Generate two frequencies of perlin noise based on our global position
289 int l0 = (int)Math.Floor(layer); 247 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
290 int l1 = Math.Min(l0 + 1, 3); 248 Vector3 vec = new Vector3
291 249 (
292 byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0]; 250 ((float)regionPosition.X + (x * xFactor)) * 0.20319f,
293 byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1]; 251 ((float)regionPosition.Y + (y * yFactor)) * 0.20319f,
294 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; 252 height * 0.25f
295 253 );
296 float aB = *(ptrA + 0); 254
297 float aG = *(ptrA + 1); 255 float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
298 float aR = *(ptrA + 2); 256 float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
299 257 float noise = (lowFreq + highFreq) * 2f;
300 float bB = *(ptrB + 0); 258
301 float bG = *(ptrB + 1); 259 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
302 float bR = *(ptrB + 2); 260 float layer = ((height + noise - startHeight) / heightRange) * 4f;
303 261 if (Single.IsNaN(layer))
304 float layerDiff = layer - l0; 262 layer = 0f;
305 263 layermap[x, y] = Utils.Clamp(layer, 0f, 3f);
306 // Interpolate between the two selected textures
307 *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
308 *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
309 *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
310 }
311 }
312
313 for (int i = 0; i < 4; i++)
314 detailTexture[i].UnlockBits(datas[i]);
315 } 264 }
316 } 265 }
317 finally 266
267 #endregion Layer Map
268
269 #region Texture Compositing
270
271 Bitmap output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
272 BitmapData outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
273
274 // Unsafe work as we lock down the source textures for quicker access and access the
275 // pixel data directly
276 unsafe
318 { 277 {
319 for (int i = 0; i < 4; i++) 278 // Get handles to all of the texture data arrays
320 if (detailTexture[i] != null) 279 BitmapData[] datas = new BitmapData[]
321 detailTexture[i].Dispose(); 280 {
281 detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
282 detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
283 detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
284 detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
285 };
286
287 // Compute size of each pixel data (used to address into the pixel data array)
288 int[] comps = new int[]
289 {
290 (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
291 (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
292 (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
293 (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
294 };
295
296 for (int y = 0; y < 256; y++)
297 {
298 for (int x = 0; x < 256; x++)
299 {
300 float layer = layermap[x, y];
301
302 // Select two textures
303 int l0 = (int)Math.Floor(layer);
304 int l1 = Math.Min(l0 + 1, 3);
305
306 byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
307 byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
308 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
309
310 float aB = *(ptrA + 0);
311 float aG = *(ptrA + 1);
312 float aR = *(ptrA + 2);
313
314 float bB = *(ptrB + 0);
315 float bG = *(ptrB + 1);
316 float bR = *(ptrB + 2);
317
318 float layerDiff = layer - l0;
319
320 // Interpolate between the two selected textures
321 *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
322 *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
323 *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
324 }
325 }
326
327 for (int i = 0; i < detailTexture.Length; i++)
328 detailTexture[i].UnlockBits(datas[i]);
322 } 329 }
323 330
331 for (int i = 0; i < detailTexture.Length; i++)
332 if (detailTexture[i] != null)
333 detailTexture[i].Dispose();
334
324 output.UnlockBits(outputData); 335 output.UnlockBits(outputData);
325 336
326 // We generated the texture upside down, so flip it 337 // We generated the texture upside down, so flip it
@@ -331,6 +342,17 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
331 return output; 342 return output;
332 } 343 }
333 344
345 public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
346 {
347 m_log.DebugFormat("{0} ResizeBitmap. From <{1},{2}> to <{3},{4}>",
348 LogHeader, b.Width, b.Height, nWidth, nHeight);
349 Bitmap result = new Bitmap(nWidth, nHeight);
350 using (Graphics g = Graphics.FromImage(result))
351 g.DrawImage(b, 0, 0, nWidth, nHeight);
352 b.Dispose();
353 return result;
354 }
355
334 public static Bitmap SplatSimple(float[] heightmap) 356 public static Bitmap SplatSimple(float[] heightmap)
335 { 357 {
336 const float BASE_HSV_H = 93f / 360f; 358 const float BASE_HSV_H = 93f / 360f;
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
index ed2b06a..5728731 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
@@ -31,21 +31,25 @@ using System.Drawing;
31using System.Drawing.Imaging; 31using System.Drawing.Imaging;
32using System.IO; 32using System.IO;
33using System.Reflection; 33using System.Reflection;
34
34using CSJ2K; 35using CSJ2K;
35using Nini.Config; 36using Nini.Config;
36using log4net; 37using log4net;
37using Rednettle.Warp3D; 38using Rednettle.Warp3D;
38using Mono.Addins; 39using Mono.Addins;
39using OpenMetaverse; 40
40using OpenMetaverse.Imaging;
41using OpenMetaverse.Rendering;
42using OpenMetaverse.StructuredData;
43using OpenSim.Framework; 41using OpenSim.Framework;
44using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
45using OpenSim.Region.Framework.Scenes; 43using OpenSim.Region.Framework.Scenes;
46using OpenSim.Region.Physics.Manager; 44using OpenSim.Region.Physics.Manager;
47using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
48 46
47using OpenMetaverse;
48using OpenMetaverse.Assets;
49using OpenMetaverse.Imaging;
50using OpenMetaverse.Rendering;
51using OpenMetaverse.StructuredData;
52
49using WarpRenderer = global::Warp3D.Warp3D; 53using WarpRenderer = global::Warp3D.Warp3D;
50 54
51namespace OpenSim.Region.CoreModules.World.Warp3DMap 55namespace OpenSim.Region.CoreModules.World.Warp3DMap
@@ -57,12 +61,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
57 private static readonly Color4 WATER_COLOR = new Color4(29, 72, 96, 216); 61 private static readonly Color4 WATER_COLOR = new Color4(29, 72, 96, 216);
58 62
59 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 63 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
64 private static string LogHeader = "[WARP 3D IMAGE MODULE]";
60 65
61 private Scene m_scene; 66 private Scene m_scene;
62 private IRendering m_primMesher; 67 private IRendering m_primMesher;
63 private IConfigSource m_config;
64 private Dictionary<UUID, Color4> m_colors = new Dictionary<UUID, Color4>(); 68 private Dictionary<UUID, Color4> m_colors = new Dictionary<UUID, Color4>();
65 private bool m_useAntiAliasing = false; // TODO: Make this a config option 69
70 private IConfigSource m_config;
71 private bool m_drawPrimVolume = true; // true if should render the prims on the tile
72 private bool m_textureTerrain = true; // true if to create terrain splatting texture
73 private bool m_texturePrims = true; // true if should texture the rendered prims
74 private float m_texturePrimSize = 48f; // size of prim before we consider texturing it
75 private bool m_renderMeshes = false; // true if to render meshes rather than just bounding boxes
76 private bool m_useAntiAliasing = false; // true if to anti-alias the rendered image
77
66 private bool m_Enabled = false; 78 private bool m_Enabled = false;
67 79
68 #region Region Module interface 80 #region Region Module interface
@@ -71,11 +83,27 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
71 { 83 {
72 m_config = source; 84 m_config = source;
73 85
86 string[] configSections = new string[] { "Map", "Startup" };
87
74 if (Util.GetConfigVarFromSections<string>( 88 if (Util.GetConfigVarFromSections<string>(
75 m_config, "MapImageModule", new string[] { "Startup", "Map" }, "MapImageModule") != "Warp3DImageModule") 89 m_config, "MapImageModule", configSections, "MapImageModule") != "Warp3DImageModule")
76 return; 90 return;
77 91
78 m_Enabled = true; 92 m_Enabled = true;
93
94 m_drawPrimVolume
95 = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, m_drawPrimVolume);
96 m_textureTerrain
97 = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, m_textureTerrain);
98 m_texturePrims
99 = Util.GetConfigVarFromSections<bool>(m_config, "TexturePrims", configSections, m_texturePrims);
100 m_texturePrimSize
101 = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize);
102 m_renderMeshes
103 = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes);
104 m_useAntiAliasing
105 = Util.GetConfigVarFromSections<bool>(m_config, "UseAntiAliasing", configSections, m_useAntiAliasing);
106
79 } 107 }
80 108
81 public void AddRegion(Scene scene) 109 public void AddRegion(Scene scene)
@@ -127,29 +155,28 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
127 155
128 public Bitmap CreateMapTile() 156 public Bitmap CreateMapTile()
129 { 157 {
130 Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); 158 // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f);
131 Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, (int)Constants.RegionSize, (int)Constants.RegionSize, (float)Constants.RegionSize, (float)Constants.RegionSize); 159 // Camera above the middle of the region
160 Vector3 camPos = new Vector3(
161 m_scene.RegionInfo.RegionSizeX/2 - 0.5f,
162 m_scene.RegionInfo.RegionSizeY/2 - 0.5f,
163 221.7025033688163f);
164 // Viewport viewing down onto the region
165 Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f,
166 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY,
167 (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY );
168 // Fill the viewport and return the image
132 return CreateMapTile(viewport, false); 169 return CreateMapTile(viewport, false);
133 } 170 }
134 171
135 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) 172 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures)
136 { 173 {
137 Viewport viewport = new Viewport(camPos, camDir, fov, (float)Constants.RegionSize, 0.1f, width, height); 174 Viewport viewport = new Viewport(camPos, camDir, fov, Constants.RegionSize, 0.1f, width, height);
138 return CreateMapTile(viewport, useTextures); 175 return CreateMapTile(viewport, useTextures);
139 } 176 }
140 177
141 public Bitmap CreateMapTile(Viewport viewport, bool useTextures) 178 public Bitmap CreateMapTile(Viewport viewport, bool useTextures)
142 { 179 {
143 bool drawPrimVolume = true;
144 bool textureTerrain = true;
145
146 string[] configSections = new string[] { "Map", "Startup" };
147
148 drawPrimVolume
149 = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, drawPrimVolume);
150 textureTerrain
151 = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, textureTerrain);
152
153 m_colors.Clear(); 180 m_colors.Clear();
154 181
155 int width = viewport.Width; 182 int width = viewport.Width;
@@ -193,8 +220,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
193 renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 0, 100, 40)); 220 renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 0, 100, 40));
194 221
195 CreateWater(renderer); 222 CreateWater(renderer);
196 CreateTerrain(renderer, textureTerrain); 223 CreateTerrain(renderer, m_textureTerrain);
197 if (drawPrimVolume) 224 if (m_drawPrimVolume)
198 CreateAllPrims(renderer, useTextures); 225 CreateAllPrims(renderer, useTextures);
199 226
200 renderer.Render(); 227 renderer.Render();
@@ -210,6 +237,16 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
210 // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory 237 // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory
211 // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating 238 // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating
212 // this map tile simply takes a lot of memory. 239 // this map tile simply takes a lot of memory.
240 foreach (var o in renderer.Scene.objectData.Values)
241 {
242 warp_Object obj = (warp_Object)o;
243 obj.vertexData = null;
244 obj.triangleData = null;
245 }
246 renderer.Scene.removeAllObjects();
247 renderer = null;
248 viewport = null;
249 m_colors.Clear();
213 GC.Collect(); 250 GC.Collect();
214 m_log.Debug("[WARP 3D IMAGE MODULE]: GC.Collect()"); 251 m_log.Debug("[WARP 3D IMAGE MODULE]: GC.Collect()");
215 252
@@ -236,61 +273,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
236 273
237 #region Rendering Methods 274 #region Rendering Methods
238 275
276 // Add a water plane to the renderer.
239 private void CreateWater(WarpRenderer renderer) 277 private void CreateWater(WarpRenderer renderer)
240 { 278 {
241 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; 279 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
242 280
243 renderer.AddPlane("Water", 256f * 0.5f); 281 renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f);
244 renderer.Scene.sceneobject("Water").setPos(127.5f, waterHeight, 127.5f); 282 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f,
283 waterHeight,
284 m_scene.RegionInfo.RegionSizeY/2 - 0.5f );
245 285
246 renderer.AddMaterial("WaterColor", ConvertColor(WATER_COLOR)); 286 warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR));
247 renderer.Scene.material("WaterColor").setReflectivity(0); // match water color with standard map module thanks lkalif 287 waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif
248 renderer.Scene.material("WaterColor").setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); 288 waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f));
289 renderer.Scene.addMaterial("WaterColor", waterColorMaterial);
249 renderer.SetObjectMaterial("Water", "WaterColor"); 290 renderer.SetObjectMaterial("Water", "WaterColor");
250 } 291 }
251 292
293 // Add a terrain to the renderer.
294 // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for
295 // full resolution. This saves a lot of memory especially for very large regions.
252 private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) 296 private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
253 { 297 {
254 ITerrainChannel terrain = m_scene.Heightmap; 298 ITerrainChannel terrain = m_scene.Heightmap;
255 float[] heightmap = terrain.GetFloatsSerialised(); 299
300 // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding
301 float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f;
256 302
257 warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); 303 warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2);
258 304
259 for (int y = 0; y < 256; y++) 305 // Create all the vertices for the terrain
306 for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
260 { 307 {
261 for (int x = 0; x < 256; x++) 308 for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
262 { 309 {
263 int v = y * 256 + x; 310 warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
264 float height = heightmap[v]; 311 obj.addVertex(new warp_Vertex(pos,
265 312 x / (float)m_scene.RegionInfo.RegionSizeX,
266 warp_Vector pos = ConvertVector(new Vector3(x, y, height)); 313 (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) );
267 obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f));
268 } 314 }
269 } 315 }
270 316
271 for (int y = 0; y < 256; y++) 317 // Now that we have all the vertices, make another pass and create
318 // the normals for each of the surface triangles and
319 // create the list of triangle indices.
320 for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
272 { 321 {
273 for (int x = 0; x < 256; x++) 322 for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
274 { 323 {
275 if (x < 255 && y < 255) 324 float newX = x / diff;
325 float newY = y / diff;
326 if (newX < 255 && newY < 255)
276 { 327 {
277 int v = y * 256 + x; 328 int v = (int)newY * 256 + (int)newX;
278 329
279 // Normal 330 // Normal for a triangle made up of three adjacent vertices
280 Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); 331 Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]);
281 Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); 332 Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]);
282 Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); 333 Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]);
283 warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); 334 warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
284 norm = norm.reverse(); 335 norm = norm.reverse();
285 obj.vertex(v).n = norm; 336 obj.vertex(v).n = norm;
286 337
287 // Triangle 1 338 // Make two triangles for each of the squares in the grid of vertices
288 obj.addTriangle( 339 obj.addTriangle(
289 v, 340 v,
290 v + 1, 341 v + 1,
291 v + 256); 342 v + 256);
292 343
293 // Triangle 2
294 obj.addTriangle( 344 obj.addTriangle(
295 v + 256 + 1, 345 v + 256 + 1,
296 v + 256, 346 v + 256,
@@ -305,7 +355,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
305 float[] startHeights = new float[4]; 355 float[] startHeights = new float[4];
306 float[] heightRanges = new float[4]; 356 float[] heightRanges = new float[4];
307 357
308 RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; 358 OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings;
309 359
310 textureIDs[0] = regionInfo.TerrainTexture1; 360 textureIDs[0] = regionInfo.TerrainTexture1;
311 textureIDs[1] = regionInfo.TerrainTexture2; 361 textureIDs[1] = regionInfo.TerrainTexture2;
@@ -323,14 +373,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
323 heightRanges[3] = (float)regionInfo.Elevation2NE; 373 heightRanges[3] = (float)regionInfo.Elevation2NE;
324 374
325 uint globalX, globalY; 375 uint globalX, globalY;
326 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); 376 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);
327 377
328 warp_Texture texture; 378 warp_Texture texture;
329
330 using ( 379 using (
331 Bitmap image 380 Bitmap image
332 = TerrainSplat.Splat( 381 = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges,
333 heightmap, textureIDs, startHeights, heightRanges,
334 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) 382 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
335 { 383 {
336 texture = new warp_Texture(image); 384 texture = new warp_Texture(image);
@@ -368,8 +416,48 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
368 if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) 416 if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE)
369 return; 417 return;
370 418
419 FacetedMesh renderMesh = null;
371 Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.RotationOffset); 420 Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.RotationOffset);
372 FacetedMesh renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); 421
422 if (m_renderMeshes)
423 {
424 if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero)
425 {
426 // Try fetchinng the asset
427 byte[] sculptAsset = m_scene.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
428 if (sculptAsset != null)
429 {
430 // Is it a mesh?
431 if (omvPrim.Sculpt.Type == SculptType.Mesh)
432 {
433 AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
434 FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out renderMesh);
435 meshAsset = null;
436 }
437 else // It's sculptie
438 {
439 IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>();
440 if (imgDecoder != null)
441 {
442 Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
443 if (sculpt != null)
444 {
445 renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt,
446 DetailLevel.Medium);
447 sculpt.Dispose();
448 }
449 }
450 }
451 }
452 }
453 }
454
455 // If not a mesh or sculptie, try the regular mesher
456 if (renderMesh == null)
457 {
458 renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium);
459 }
460
373 if (renderMesh == null) 461 if (renderMesh == null)
374 return; 462 return;
375 463
@@ -428,7 +516,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
428 516
429 Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); 517 Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i);
430 Color4 faceColor = GetFaceColor(teFace); 518 Color4 faceColor = GetFaceColor(teFace);
431 string materialName = GetOrCreateMaterial(renderer, faceColor); 519 string materialName = String.Empty;
520 if (m_texturePrims && prim.Scale.LengthSquared() > m_texturePrimSize*m_texturePrimSize)
521 materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID);
522 else
523 materialName = GetOrCreateMaterial(renderer, faceColor);
432 524
433 faceObj.transform(m); 525 faceObj.transform(m);
434 faceObj.setPos(primPos); 526 faceObj.setPos(primPos);
@@ -517,10 +609,51 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
517 return name; 609 return name;
518 } 610 }
519 611
612 public string GetOrCreateMaterial(WarpRenderer renderer, Color4 faceColor, UUID textureID)
613 {
614 string materialName = "Color-" + faceColor.ToString() + "-Texture-" + textureID.ToString();
615
616 if (renderer.Scene.material(materialName) == null)
617 {
618 renderer.AddMaterial(materialName, ConvertColor(faceColor));
619 if (faceColor.A < 1f)
620 {
621 renderer.Scene.material(materialName).setTransparency((byte) ((1f - faceColor.A)*255f));
622 }
623 warp_Texture texture = GetTexture(textureID);
624 if (texture != null)
625 renderer.Scene.material(materialName).setTexture(texture);
626 }
627
628 return materialName;
629 }
630
631 private warp_Texture GetTexture(UUID id)
632 {
633 warp_Texture ret = null;
634 byte[] asset = m_scene.AssetService.GetData(id.ToString());
635 if (asset != null)
636 {
637 IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>();
638 Bitmap img = (Bitmap) imgDecoder.DecodeToImage(asset);
639 if (img != null)
640 {
641 return new warp_Texture(img);
642 }
643 }
644 return ret;
645 }
646
520 #endregion Rendering Methods 647 #endregion Rendering Methods
521 648
522 #region Static Helpers 649 #region Static Helpers
523 650
651 // Note: axis change.
652 private static warp_Vector ConvertVector(float x, float y, float z)
653 {
654 return new warp_Vector(x, z, y);
655 }
656
524 private static warp_Vector ConvertVector(Vector3 vector) 657 private static warp_Vector ConvertVector(Vector3 vector)
525 { 658 {
526 return new warp_Vector(vector.X, vector.Z, vector.Y); 659 return new warp_Vector(vector.X, vector.Z, vector.Y);
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
index 708a9a2..1fb1aba 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
@@ -184,8 +184,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
184 data.Name = info.RegionName; 184 data.Name = info.RegionName;
185 data.RegionFlags = 0; // TODO not used? 185 data.RegionFlags = 0; // TODO not used?
186 data.WaterHeight = 0; // not used 186 data.WaterHeight = 0; // not used
187 data.X = (ushort)(info.RegionLocX / Constants.RegionSize); 187 data.X = (ushort)Util.WorldToRegionLoc((uint)info.RegionLocX);
188 data.Y = (ushort)(info.RegionLocY / Constants.RegionSize); 188 data.Y = (ushort)Util.WorldToRegionLoc((uint)info.RegionLocY);
189 blocks.Add(data); 189 blocks.Add(data);
190 } 190 }
191 } 191 }
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index cf2ef29..f57be83 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -59,8 +59,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
59 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WorldMapModule")] 59 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WorldMapModule")]
60 public class WorldMapModule : INonSharedRegionModule, IWorldMapModule 60 public class WorldMapModule : INonSharedRegionModule, IWorldMapModule
61 { 61 {
62 private static readonly ILog m_log = 62 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
63 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 63 private static string LogHeader = "[WORLD MAP]";
64 64
65 private static readonly string DEFAULT_WORLD_MAP_EXPORT_PATH = "exportmap.jpg"; 65 private static readonly string DEFAULT_WORLD_MAP_EXPORT_PATH = "exportmap.jpg";
66 private static readonly UUID STOP_UUID = UUID.Random(); 66 private static readonly UUID STOP_UUID = UUID.Random();
@@ -282,15 +282,15 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
282 { 282 {
283 List<MapBlockData> mapBlocks = new List<MapBlockData>(); ; 283 List<MapBlockData> mapBlocks = new List<MapBlockData>(); ;
284 284
285 // Get regions that are within 8 regions of here
285 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 286 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
286 (int)(m_scene.RegionInfo.RegionLocX - 8) * (int)Constants.RegionSize, 287 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocX - 8),
287 (int)(m_scene.RegionInfo.RegionLocX + 8) * (int)Constants.RegionSize, 288 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocX + 8),
288 (int)(m_scene.RegionInfo.RegionLocY - 8) * (int)Constants.RegionSize, 289 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocY - 8),
289 (int)(m_scene.RegionInfo.RegionLocY + 8) * (int)Constants.RegionSize); 290 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocY + 8) );
290 foreach (GridRegion r in regions) 291 foreach (GridRegion r in regions)
291 { 292 {
292 MapBlockData block = new MapBlockData(); 293 MapBlockData block = MapBlockFromGridRegion(r, 0);
293 MapBlockFromGridRegion(block, r, 0);
294 mapBlocks.Add(block); 294 mapBlocks.Add(block);
295 } 295 }
296 avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0); 296 avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0);
@@ -410,24 +410,23 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
410 } 410 }
411 uint xstart = 0; 411 uint xstart = 0;
412 uint ystart = 0; 412 uint ystart = 0;
413 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out xstart, out ystart); 413 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
414 if (itemtype == 6) // Service 6 right now (MAP_ITEM_AGENTS_LOCATION; green dots) 414 if (itemtype == (int)GridItemType.AgentLocations)
415 { 415 {
416 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) 416 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
417 { 417 {
418 // Local Map Item Request 418 // Just requesting map info about the current, local region
419 int tc = Environment.TickCount; 419 int tc = Environment.TickCount;
420 List<mapItemReply> mapitems = new List<mapItemReply>(); 420 List<mapItemReply> mapitems = new List<mapItemReply>();
421 mapItemReply mapitem = new mapItemReply(); 421 mapItemReply mapitem = new mapItemReply();
422 if (m_scene.GetRootAgentCount() <= 1) 422 if (m_scene.GetRootAgentCount() <= 1)
423 { 423 {
424 mapitem = new mapItemReply(); 424 mapitem = new mapItemReply(
425 mapitem.x = (uint)(xstart + 1); 425 xstart + 1,
426 mapitem.y = (uint)(ystart + 1); 426 ystart + 1,
427 mapitem.id = UUID.Zero; 427 UUID.Zero,
428 mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); 428 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
429 mapitem.Extra = 0; 429 0, 0);
430 mapitem.Extra2 = 0;
431 mapitems.Add(mapitem); 430 mapitems.Add(mapitem);
432 } 431 }
433 else 432 else
@@ -437,13 +436,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
437 // Don't send a green dot for yourself 436 // Don't send a green dot for yourself
438 if (sp.UUID != remoteClient.AgentId) 437 if (sp.UUID != remoteClient.AgentId)
439 { 438 {
440 mapitem = new mapItemReply(); 439 mapitem = new mapItemReply(
441 mapitem.x = (uint)(xstart + sp.AbsolutePosition.X); 440 xstart + (uint)sp.AbsolutePosition.X,
442 mapitem.y = (uint)(ystart + sp.AbsolutePosition.Y); 441 ystart + (uint)sp.AbsolutePosition.Y,
443 mapitem.id = UUID.Zero; 442 UUID.Zero,
444 mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); 443 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
445 mapitem.Extra = 1; 444 1, 0);
446 mapitem.Extra2 = 0;
447 mapitems.Add(mapitem); 445 mapitems.Add(mapitem);
448 } 446 }
449 }); 447 });
@@ -458,7 +456,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
458 RequestMapItems("",remoteClient.AgentId,flags,EstateID,godlike,itemtype,regionhandle); 456 RequestMapItems("",remoteClient.AgentId,flags,EstateID,godlike,itemtype,regionhandle);
459 } 457 }
460 } 458 }
461 else if (itemtype == 7) // Service 7 (MAP_ITEM_LAND_FOR_SALE) 459 else if (itemtype == (int)GridItemType.LandForSale) // Service 7 (MAP_ITEM_LAND_FOR_SALE)
462 { 460 {
463 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) 461 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
464 { 462 {
@@ -488,14 +486,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
488 float x = (min.X+max.X)/2; 486 float x = (min.X+max.X)/2;
489 float y = (min.Y+max.Y)/2; 487 float y = (min.Y+max.Y)/2;
490 488
491 mapitem = new mapItemReply(); 489 mapitem = new mapItemReply(
492 mapitem.x = (uint)(xstart + x); 490 xstart + (uint)x,
493 mapitem.y = (uint)(ystart + y); 491 ystart + (uint)y,
494 // mapitem.z = (uint)m_scene.GetGroundHeight(x,y); 492 parcel.GlobalID,
495 mapitem.id = parcel.GlobalID; 493 parcel.Name,
496 mapitem.name = parcel.Name; 494 parcel.Area,
497 mapitem.Extra = parcel.Area; 495 parcel.SalePrice
498 mapitem.Extra2 = parcel.SalePrice; 496 );
499 mapitems.Add(mapitem); 497 mapitems.Add(mapitem);
500 } 498 }
501 } 499 }
@@ -510,7 +508,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
510 RequestMapItems("",remoteClient.AgentId,flags,EstateID,godlike,itemtype,regionhandle); 508 RequestMapItems("",remoteClient.AgentId,flags,EstateID,godlike,itemtype,regionhandle);
511 } 509 }
512 } 510 }
513 else if (itemtype == 1) // Service 1 (MAP_ITEM_TELEHUB) 511 else if (itemtype == (int)GridItemType.Telehub) // Service 1 (MAP_ITEM_TELEHUB)
514 { 512 {
515 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) 513 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
516 { 514 {
@@ -520,13 +518,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
520 SceneObjectGroup sog = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject); 518 SceneObjectGroup sog = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject);
521 if (sog != null) 519 if (sog != null)
522 { 520 {
523 mapitem = new mapItemReply(); 521 mapitem = new mapItemReply(
524 mapitem.x = (uint)(xstart + sog.AbsolutePosition.X); 522 xstart + (uint)sog.AbsolutePosition.X,
525 mapitem.y = (uint)(ystart + sog.AbsolutePosition.Y); 523 ystart + (uint)sog.AbsolutePosition.Y,
526 mapitem.id = UUID.Zero; 524 UUID.Zero,
527 mapitem.name = sog.Name; 525 sog.Name,
528 mapitem.Extra = 0; // color (not used) 526 0, // color (not used)
529 mapitem.Extra2 = 0; // 0 = telehub / 1 = infohub 527 0 // 0 = telehub / 1 = infohub
528 );
530 mapitems.Add(mapitem); 529 mapitems.Add(mapitem);
531 530
532 remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags); 531 remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags);
@@ -676,19 +675,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
676 { 675 {
677 OSDMap mapitem = (OSDMap)itemarray[i]; 676 OSDMap mapitem = (OSDMap)itemarray[i];
678 mapItemReply mi = new mapItemReply(); 677 mapItemReply mi = new mapItemReply();
679 mi.x = (uint)mapitem["X"].AsInteger(); 678 mi.FromOSD(mapitem);
680 mi.y = (uint)mapitem["Y"].AsInteger();
681 mi.id = mapitem["ID"].AsUUID();
682 mi.Extra = mapitem["Extra"].AsInteger();
683 mi.Extra2 = mapitem["Extra2"].AsInteger();
684 mi.name = mapitem["Name"].AsString();
685 returnitems.Add(mi); 679 returnitems.Add(mi);
686 } 680 }
687 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), mrs.itemtype, mrs.flags); 681 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), mrs.itemtype, mrs.flags);
688 } 682 }
689 683
690 // Service 7 (MAP_ITEM_LAND_FOR_SALE) 684 // Service 7 (MAP_ITEM_LAND_FOR_SALE)
691 uint itemtype = 7; 685 uint itemtype = (uint)GridItemType.LandForSale;
692 686
693 if (response.ContainsKey(itemtype.ToString())) 687 if (response.ContainsKey(itemtype.ToString()))
694 { 688 {
@@ -698,19 +692,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
698 { 692 {
699 OSDMap mapitem = (OSDMap)itemarray[i]; 693 OSDMap mapitem = (OSDMap)itemarray[i];
700 mapItemReply mi = new mapItemReply(); 694 mapItemReply mi = new mapItemReply();
701 mi.x = (uint)mapitem["X"].AsInteger(); 695 mi.FromOSD(mapitem);
702 mi.y = (uint)mapitem["Y"].AsInteger();
703 mi.id = mapitem["ID"].AsUUID();
704 mi.Extra = mapitem["Extra"].AsInteger();
705 mi.Extra2 = mapitem["Extra2"].AsInteger();
706 mi.name = mapitem["Name"].AsString();
707 returnitems.Add(mi); 696 returnitems.Add(mi);
708 } 697 }
709 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags); 698 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags);
710 } 699 }
711 700
712 // Service 1 (MAP_ITEM_TELEHUB) 701 // Service 1 (MAP_ITEM_TELEHUB)
713 itemtype = 1; 702 itemtype = (uint)GridItemType.Telehub;
714 703
715 if (response.ContainsKey(itemtype.ToString())) 704 if (response.ContainsKey(itemtype.ToString()))
716 { 705 {
@@ -720,12 +709,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
720 { 709 {
721 OSDMap mapitem = (OSDMap)itemarray[i]; 710 OSDMap mapitem = (OSDMap)itemarray[i];
722 mapItemReply mi = new mapItemReply(); 711 mapItemReply mi = new mapItemReply();
723 mi.x = (uint)mapitem["X"].AsInteger(); 712 mi.FromOSD(mapitem);
724 mi.y = (uint)mapitem["Y"].AsInteger();
725 mi.id = mapitem["ID"].AsUUID();
726 mi.Extra = mapitem["Extra"].AsInteger();
727 mi.Extra2 = mapitem["Extra2"].AsInteger();
728 mi.name = mapitem["Name"].AsString();
729 returnitems.Add(mi); 713 returnitems.Add(mi);
730 } 714 }
731 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags); 715 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags);
@@ -808,7 +792,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
808 if (httpserver.Length == 0) 792 if (httpserver.Length == 0)
809 { 793 {
810 uint x = 0, y = 0; 794 uint x = 0, y = 0;
811 Utils.LongToUInts(regionhandle, out x, out y); 795 Util.RegionHandleToWorldLoc(regionhandle, out x, out y);
812 GridRegion mreg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); 796 GridRegion mreg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
813 797
814 if (mreg != null) 798 if (mreg != null)
@@ -1007,7 +991,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1007 /// <param name="maxY"></param> 991 /// <param name="maxY"></param>
1008 public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) 992 public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
1009 { 993 {
1010 //m_log.ErrorFormat("[YYY] RequestMapBlocks {0}={1}={2}={3} {4}", minX, minY, maxX, maxY, flag);
1011 if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible 994 if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible
1012 { 995 {
1013 List<MapBlockData> response = new List<MapBlockData>(); 996 List<MapBlockData> response = new List<MapBlockData>();
@@ -1016,22 +999,24 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1016 // on an unloaded square. 999 // on an unloaded square.
1017 // But make sure: Look whether the one we requested is in there 1000 // But make sure: Look whether the one we requested is in there
1018 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1001 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1019 minX * (int)Constants.RegionSize, 1002 (int)Util.RegionToWorldLoc((uint)minX), (int)Util.RegionToWorldLoc((uint)maxX),
1020 maxX * (int)Constants.RegionSize, 1003 (int)Util.RegionToWorldLoc((uint)minY), (int)Util.RegionToWorldLoc((uint)maxY) );
1021 minY * (int)Constants.RegionSize,
1022 maxY * (int)Constants.RegionSize);
1023 1004
1005 m_log.DebugFormat("[WORLD MAP MODULE] RequestMapBlocks min=<{0},{1}>, max=<{2},{3}>, flag={4}, cntFound={5}",
1006 minX, minY, maxX, maxY, flag.ToString("X"), regions.Count);
1024 if (regions != null) 1007 if (regions != null)
1025 { 1008 {
1026 foreach (GridRegion r in regions) 1009 foreach (GridRegion r in regions)
1027 { 1010 {
1028 if ((r.RegionLocX == minX * (int)Constants.RegionSize) && 1011 if (r.RegionLocX == Util.RegionToWorldLoc((uint)minX)
1029 (r.RegionLocY == minY * (int)Constants.RegionSize)) 1012 && r.RegionLocY == Util.RegionToWorldLoc((uint)minY) )
1030 { 1013 {
1031 // found it => add it to response 1014 // found it => add it to response
1032 MapBlockData block = new MapBlockData(); 1015 // Version 2 viewers can handle the larger regions
1033 MapBlockFromGridRegion(block, r, flag); 1016 if ((flag & 2) == 2)
1034 response.Add(block); 1017 response.AddRange(Map2BlockFromGridRegion(r, flag));
1018 else
1019 response.Add(MapBlockFromGridRegion(r, flag));
1035 break; 1020 break;
1036 } 1021 }
1037 } 1022 }
@@ -1043,7 +1028,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1043 MapBlockData block = new MapBlockData(); 1028 MapBlockData block = new MapBlockData();
1044 block.X = (ushort)minX; 1029 block.X = (ushort)minX;
1045 block.Y = (ushort)minY; 1030 block.Y = (ushort)minY;
1046 block.Access = 254; // means 'simulator is offline' 1031 block.Access = (byte)SimAccess.Down; // means 'simulator is offline'
1032 // block.Access = (byte)SimAccess.NonExistant;
1047 response.Add(block); 1033 response.Add(block);
1048 } 1034 }
1049 // The lower 16 bits are an unsigned int16 1035 // The lower 16 bits are an unsigned int16
@@ -1060,41 +1046,112 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1060 { 1046 {
1061 List<MapBlockData> mapBlocks = new List<MapBlockData>(); 1047 List<MapBlockData> mapBlocks = new List<MapBlockData>();
1062 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1048 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1063 (minX - 4) * (int)Constants.RegionSize, 1049 (int)Util.RegionToWorldLoc((uint)(minX - 4)), (int)Util.RegionToWorldLoc((uint)(maxX + 4)),
1064 (maxX + 4) * (int)Constants.RegionSize, 1050 (int)Util.RegionToWorldLoc((uint)(minY - 4)), (int)Util.RegionToWorldLoc((uint)(maxY + 4)) );
1065 (minY - 4) * (int)Constants.RegionSize, 1051 m_log.DebugFormat("{0} GetAndSendBlocks. min=<{1},{2}>, max=<{3},{4}>, cntFound={5}",
1066 (maxY + 4) * (int)Constants.RegionSize); 1052 LogHeader, minX, minY, maxX, maxY, regions.Count);
1067 foreach (GridRegion r in regions) 1053 foreach (GridRegion r in regions)
1068 { 1054 {
1069 MapBlockData block = new MapBlockData(); 1055 // Version 2 viewers can handle the larger regions
1070 MapBlockFromGridRegion(block, r, flag); 1056 if ((flag & 2) == 2)
1071 mapBlocks.Add(block); 1057 mapBlocks.AddRange(Map2BlockFromGridRegion(r, flag));
1058 else
1059 mapBlocks.Add(MapBlockFromGridRegion(r, flag));
1072 } 1060 }
1073 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff); 1061 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
1074 1062
1075 return mapBlocks; 1063 return mapBlocks;
1076 } 1064 }
1077 1065
1078 protected void MapBlockFromGridRegion(MapBlockData block, GridRegion r, uint flag) 1066 // Fill a passed MapBlockData from a GridRegion
1067 protected MapBlockData MapBlockFromGridRegion(GridRegion r, uint flag)
1079 { 1068 {
1069 MapBlockData block = new MapBlockData();
1070
1080 block.Access = r.Access; 1071 block.Access = r.Access;
1081 switch (flag & 0xffff) 1072 switch (flag & 0xffff)
1082 { 1073 {
1083 case 0: 1074 case 0:
1084 block.MapImageId = r.TerrainImage; 1075 block.MapImageId = r.TerrainImage;
1085 break; 1076 break;
1086 case 2: 1077 case 2:
1087 block.MapImageId = r.ParcelImage; 1078 block.MapImageId = r.ParcelImage;
1088 break; 1079 break;
1089 default: 1080 default:
1090 block.MapImageId = UUID.Zero; 1081 block.MapImageId = UUID.Zero;
1091 break; 1082 break;
1092 } 1083 }
1093 block.Name = r.RegionName; 1084 block.Name = r.RegionName;
1094 block.X = (ushort)(r.RegionLocX / Constants.RegionSize); 1085 block.X = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocX);
1095 block.Y = (ushort)(r.RegionLocY / Constants.RegionSize); 1086 block.Y = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocY);
1087 block.SizeX = (ushort) r.RegionSizeX;
1088 block.SizeY = (ushort) r.RegionSizeY;
1089
1090 return block;
1096 } 1091 }
1097 1092
1093 protected List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag)
1094 {
1095 List<MapBlockData> blocks = new List<MapBlockData>();
1096 MapBlockData block = new MapBlockData();
1097 if (r == null)
1098 {
1099 block.Access = (byte)SimAccess.Down;
1100 block.MapImageId = UUID.Zero;
1101 blocks.Add(block);
1102 }
1103 else
1104 {
1105 block.Access = r.Access;
1106 switch (flag & 0xffff)
1107 {
1108 case 0:
1109 block.MapImageId = r.TerrainImage;
1110 break;
1111 case 2:
1112 block.MapImageId = r.ParcelImage;
1113 break;
1114 default:
1115 block.MapImageId = UUID.Zero;
1116 break;
1117 }
1118 block.Name = r.RegionName;
1119 block.X = (ushort)(r.RegionLocX / Constants.RegionSize);
1120 block.Y = (ushort)(r.RegionLocY / Constants.RegionSize);
1121 block.SizeX = (ushort)r.RegionSizeX;
1122 block.SizeY = (ushort)r.RegionSizeY;
1123 blocks.Add(block);
1124 // If these are larger than legacy regions, create fake map entries for the covered
1125 // regions. The map system only does legacy sized regions so we have to fake map
1126 // entries for all the covered regions.
1127 if (r.RegionSizeX > Constants.RegionSize || r.RegionSizeY > Constants.RegionSize)
1128 {
1129 for (int x = 0; x < r.RegionSizeX / Constants.RegionSize; x++)
1130 {
1131 for (int y = 0; y < r.RegionSizeY / Constants.RegionSize; y++)
1132 {
1133 if (x == 0 && y == 0)
1134 continue;
1135 block = new MapBlockData
1136 {
1137 Access = r.Access,
1138 MapImageId = r.TerrainImage,
1139 Name = r.RegionName,
1140 X = (ushort)((r.RegionLocX / Constants.RegionSize) + x),
1141 Y = (ushort)((r.RegionLocY / Constants.RegionSize) + y),
1142 SizeX = (ushort)r.RegionSizeX,
1143 SizeY = (ushort)r.RegionSizeY
1144 };
1145 //Child piece, so ignore it
1146 blocks.Add(block);
1147 }
1148 }
1149 }
1150 }
1151 return blocks;
1152 }
1153
1154
1098 public Hashtable OnHTTPThrottled(Hashtable keysvals) 1155 public Hashtable OnHTTPThrottled(Hashtable keysvals)
1099 { 1156 {
1100 Hashtable reply = new Hashtable(); 1157 Hashtable reply = new Hashtable();
@@ -1223,17 +1280,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1223 1280
1224 List<MapBlockData> mapBlocks = new List<MapBlockData>(); 1281 List<MapBlockData> mapBlocks = new List<MapBlockData>();
1225 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1282 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1226 (int)(m_scene.RegionInfo.RegionLocX - 9) * (int)Constants.RegionSize, 1283 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocX - 9),
1227 (int)(m_scene.RegionInfo.RegionLocX + 9) * (int)Constants.RegionSize, 1284 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocX + 9),
1228 (int)(m_scene.RegionInfo.RegionLocY - 9) * (int)Constants.RegionSize, 1285 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocY - 9),
1229 (int)(m_scene.RegionInfo.RegionLocY + 9) * (int)Constants.RegionSize); 1286 (int)Util.RegionToWorldLoc(m_scene.RegionInfo.RegionLocY + 9));
1230 List<AssetBase> textures = new List<AssetBase>(); 1287 List<AssetBase> textures = new List<AssetBase>();
1231 List<Image> bitImages = new List<Image>(); 1288 List<Image> bitImages = new List<Image>();
1232 1289
1233 foreach (GridRegion r in regions) 1290 foreach (GridRegion r in regions)
1234 { 1291 {
1235 MapBlockData mapBlock = new MapBlockData(); 1292 MapBlockData mapBlock = MapBlockFromGridRegion(r, 0);
1236 MapBlockFromGridRegion(mapBlock, r, 0);
1237 AssetBase texAsset = m_scene.AssetService.Get(mapBlock.MapImageId.ToString()); 1293 AssetBase texAsset = m_scene.AssetService.Get(mapBlock.MapImageId.ToString());
1238 1294
1239 if (texAsset != null) 1295 if (texAsset != null)
@@ -1294,7 +1350,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1294 uint xstart = 0; 1350 uint xstart = 0;
1295 uint ystart = 0; 1351 uint ystart = 0;
1296 1352
1297 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); 1353 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle,out xstart,out ystart);
1354 // m_log.DebugFormat("{0} HandleRemoteMapItemRequest. loc=<{1},{2}>",
1355 // LogHeader, Util.WorldToRegionLoc(xstart), Util.WorldToRegionLoc(ystart));
1298 1356
1299 // Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots) 1357 // Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots)
1300 1358
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 214b07a..709d8fc 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -92,12 +92,11 @@ namespace OpenSim.Region.Framework.Interfaces
92 92
93 void EnableChildAgent(ScenePresence agent, GridRegion region); 93 void EnableChildAgent(ScenePresence agent, GridRegion region);
94 94
95 GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out uint xDest, out uint yDest, out string version, out Vector3 newpos); 95 GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version, out Vector3 newpos);
96 96
97 void Cross(SceneObjectGroup sog, Vector3 position, bool silent); 97 void Cross(SceneObjectGroup sog, Vector3 position, bool silent);
98 98
99 ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version); 99 ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version);
100
101 } 100 }
102 101
103 public interface IUserAgentVerificationModule 102 public interface IUserAgentVerificationModule
diff --git a/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs b/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs
index 46d03b3..1cbd045 100644
--- a/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs
+++ b/OpenSim/Region/Framework/Interfaces/IJ2KDecoder.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -25,6 +25,7 @@
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 System.Drawing;
28using OpenMetaverse; 29using OpenMetaverse;
29using OpenMetaverse.Imaging; 30using OpenMetaverse.Imaging;
30 31
@@ -53,5 +54,12 @@ namespace OpenSim.Region.Framework.Interfaces
53 /// <param name="components">number of components</param> 54 /// <param name="components">number of components</param>
54 /// <returns>true if decode was successful. false otherwise.</returns> 55 /// <returns>true if decode was successful. false otherwise.</returns>
55 bool Decode(UUID assetID, byte[] j2kData, out OpenJPEG.J2KLayerInfo[] layers, out int components); 56 bool Decode(UUID assetID, byte[] j2kData, out OpenJPEG.J2KLayerInfo[] layers, out int components);
57
58 /// <summary>
59 /// Provides a synchronous decode direct to an image object
60 /// </summary>
61 /// <param name="j2kData"></param>
62 /// <returns>decoded image or 'null' of unsuccessful</returns>
63 Image DecodeToImage(byte[] j2kData);
56 } 64 }
57} 65}
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
index 3fafc47..99bc87d 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
@@ -29,6 +29,8 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31 31
32using OpenMetaverse;
33
32namespace OpenSim.Region.Framework.Interfaces 34namespace OpenSim.Region.Framework.Interfaces
33{ 35{
34 /// <summary> 36 /// <summary>
@@ -100,16 +102,11 @@ namespace OpenSim.Region.Framework.Interfaces
100 /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event. 102 /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event.
101 /// 103 ///
102 /// <param name="loadPath"></param> 104 /// <param name="loadPath"></param>
103 /// <param name="merge">
104 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
105 /// settings in the archive will be ignored.
106 /// </param>
107 /// <param name="skipAssets">
108 /// If true, the archive is loaded without loading any assets contained within it. This is useful if the
109 /// assets are already known to be present in the grid's asset service.
110 /// </param>
111 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> 105 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
112 void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId); 106 /// <param name="options">
107 /// Dictionary of options.
108 /// </param>
109 void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options);
113 110
114 /// <summary> 111 /// <summary>
115 /// Dearchive a region from a stream. This replaces the existing scene. 112 /// Dearchive a region from a stream. This replaces the existing scene.
@@ -127,15 +124,10 @@ namespace OpenSim.Region.Framework.Interfaces
127 /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event. 124 /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event.
128 /// 125 ///
129 /// <param name="loadStream"></param> 126 /// <param name="loadStream"></param>
130 /// <param name="merge">
131 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
132 /// settings in the archive will be ignored.
133 /// </param>
134 /// <param name="skipAssets">
135 /// If true, the archive is loaded without loading any assets contained within it. This is useful if the
136 /// assets are already known to be present in the grid's asset service.
137 /// </param
138 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> 127 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
139 void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId); 128 /// <param name="options">
129 /// Dictionary of options.
130 /// </param>
131 void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string,object> options);
140 } 132 }
141} 133}
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
index 085b5ca..8948f04 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
@@ -68,13 +68,22 @@ namespace OpenSim.Region.Framework.Interfaces
68 /// </summary> 68 /// </summary>
69 /// <param name="ter">HeightField data</param> 69 /// <param name="ter">HeightField data</param>
70 /// <param name="regionID">region UUID</param> 70 /// <param name="regionID">region UUID</param>
71 void StoreTerrain(TerrainData terrain, UUID regionID);
72
73 // Legacy version kept for downward compabibility
71 void StoreTerrain(double[,] terrain, UUID regionID); 74 void StoreTerrain(double[,] terrain, UUID regionID);
72 75
73 /// <summary> 76 /// <summary>
74 /// Load the latest terrain revision from region storage 77 /// Load the latest terrain revision from region storage
75 /// </summary> 78 /// </summary>
76 /// <param name="regionID">the region UUID</param> 79 /// <param name="regionID">the region UUID</param>
80 /// <param name="sizeX">the X dimension of the region being filled</param>
81 /// <param name="sizeY">the Y dimension of the region being filled</param>
82 /// <param name="sizeZ">the Z dimension of the region being filled</param>
77 /// <returns>Heightfield data</returns> 83 /// <returns>Heightfield data</returns>
84 TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ);
85
86 // Legacy version kept for downward compabibility
78 double[,] LoadTerrain(UUID regionID); 87 double[,] LoadTerrain(UUID regionID);
79 88
80 void StoreLandObject(ILandObject Parcel); 89 void StoreLandObject(ILandObject Parcel);
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
index 3787ca0..917b5d1 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
@@ -79,13 +79,22 @@ namespace OpenSim.Region.Framework.Interfaces
79 /// </summary> 79 /// </summary>
80 /// <param name="ter">HeightField data</param> 80 /// <param name="ter">HeightField data</param>
81 /// <param name="regionID">region UUID</param> 81 /// <param name="regionID">region UUID</param>
82 void StoreTerrain(TerrainData terrain, UUID regionID);
83
84 // Legacy version kept for downward compabibility
82 void StoreTerrain(double[,] terrain, UUID regionID); 85 void StoreTerrain(double[,] terrain, UUID regionID);
83 86
84 /// <summary> 87 /// <summary>
85 /// Load the latest terrain revision from region storage 88 /// Load the latest terrain revision from region storage
86 /// </summary> 89 /// </summary>
87 /// <param name="regionID">the region UUID</param> 90 /// <param name="regionID">the region UUID</param>
91 /// <param name="pSizeX">the X dimension of the terrain being filled</param>
92 /// <param name="pSizeY">the Y dimension of the terrain being filled</param>
93 /// <param name="pSizeZ">the Z dimension of the terrain being filled</param>
88 /// <returns>Heightfield data</returns> 94 /// <returns>Heightfield data</returns>
95 TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ);
96
97 // Legacy version kept for downward compabibility
89 double[,] LoadTerrain(UUID regionID); 98 double[,] LoadTerrain(UUID regionID);
90 99
91 void StoreLandObject(ILandObject Parcel); 100 void StoreLandObject(ILandObject Parcel);
@@ -135,4 +144,5 @@ namespace OpenSim.Region.Framework.Interfaces
135 144
136 void Shutdown(); 145 void Shutdown();
137 } 146 }
147
138} 148}
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
index e467701..469bd31 100644
--- a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
+++ b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs
@@ -25,13 +25,22 @@
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 float GetHeightAtXYZ(float x, float y, float z);
41
42 // Return the packaged terrain data for passing into lower levels of communication
43 TerrainData GetTerrainData();
35 44
36 /// <summary> 45 /// <summary>
37 /// Squash the entire heightmap into a single dimensioned array 46 /// Squash the entire heightmap into a single dimensioned array
@@ -40,7 +49,10 @@ namespace OpenSim.Region.Framework.Interfaces
40 float[] GetFloatsSerialised(); 49 float[] GetFloatsSerialised();
41 50
42 double[,] GetDoubles(); 51 double[,] GetDoubles();
52
53 // Check if a location has been updated. Clears the taint flag as a side effect.
43 bool Tainted(int x, int y); 54 bool Tainted(int x, int y);
55
44 ITerrainChannel MakeCopy(); 56 ITerrainChannel MakeCopy();
45 string SaveToXmlString(); 57 string SaveToXmlString();
46 void LoadFromXmlString(string data); 58 void LoadFromXmlString(string data);
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
index 5947afb..189a30a 100644
--- a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
@@ -51,6 +51,7 @@ namespace OpenSim.Region.Framework.Interfaces
51 /// </param> 51 /// </param>
52 /// <param name="stream"></param> 52 /// <param name="stream"></param>
53 void LoadFromStream(string filename, Stream stream); 53 void LoadFromStream(string filename, Stream stream);
54 void LoadFromStream(string filename, Vector2 displacement, Stream stream);
54 void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap); 55 void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap);
55 /// <summary> 56 /// <summary>
56 /// Save a terrain to a stream. 57 /// Save a terrain to a stream.
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 9cc5cde..b86f349 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -46,8 +46,8 @@ namespace OpenSim.Region.Framework.Scenes
46{ 46{
47 public partial class Scene 47 public partial class Scene
48 { 48 {
49 private static readonly ILog m_log 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly string LogHeader = "[SCENE INVENTORY]";
51 51
52 /// <summary> 52 /// <summary>
53 /// Allows asynchronous derezzing of objects from the scene into a client's inventory. 53 /// Allows asynchronous derezzing of objects from the scene into a client's inventory.
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index c3110a2..2f666c0 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1033,7 +1033,7 @@ namespace OpenSim.Region.Framework.Scenes
1033 1033
1034 BordersLocked = true; 1034 BordersLocked = true;
1035 Border northBorder = new Border(); 1035 Border northBorder = new Border();
1036 northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (int)Constants.RegionSize); //<--- 1036 northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (float)RegionInfo.RegionSizeY); //<---
1037 northBorder.CrossDirection = Cardinals.N; 1037 northBorder.CrossDirection = Cardinals.N;
1038 NorthBorders.Add(northBorder); 1038 NorthBorders.Add(northBorder);
1039 1039
@@ -1043,7 +1043,7 @@ namespace OpenSim.Region.Framework.Scenes
1043 SouthBorders.Add(southBorder); 1043 SouthBorders.Add(southBorder);
1044 1044
1045 Border eastBorder = new Border(); 1045 Border eastBorder = new Border();
1046 eastBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (int)Constants.RegionSize); //<--- 1046 eastBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (float)RegionInfo.RegionSizeY); //<---
1047 eastBorder.CrossDirection = Cardinals.E; 1047 eastBorder.CrossDirection = Cardinals.E;
1048 EastBorders.Add(eastBorder); 1048 EastBorders.Add(eastBorder);
1049 1049
@@ -1099,8 +1099,9 @@ namespace OpenSim.Region.Framework.Scenes
1099 /// <returns>True after all operations complete, throws exceptions otherwise.</returns> 1099 /// <returns>True after all operations complete, throws exceptions otherwise.</returns>
1100 public override void OtherRegionUp(GridRegion otherRegion) 1100 public override void OtherRegionUp(GridRegion otherRegion)
1101 { 1101 {
1102 uint xcell = (uint)((int)otherRegion.RegionLocX / (int)Constants.RegionSize); 1102 uint xcell = Util.WorldToRegionLoc((uint)otherRegion.RegionLocX);
1103 uint ycell = (uint)((int)otherRegion.RegionLocY / (int)Constants.RegionSize); 1103 uint ycell = Util.WorldToRegionLoc((uint)otherRegion.RegionLocY);
1104
1104 //m_log.InfoFormat("[SCENE]: (on region {0}): Region {1} up in coords {2}-{3}", 1105 //m_log.InfoFormat("[SCENE]: (on region {0}): Region {1} up in coords {2}-{3}",
1105 // RegionInfo.RegionName, otherRegion.RegionName, xcell, ycell); 1106 // RegionInfo.RegionName, otherRegion.RegionName, xcell, ycell);
1106 1107
@@ -1172,46 +1173,6 @@ namespace OpenSim.Region.Framework.Scenes
1172 return found; 1173 return found;
1173 } 1174 }
1174 1175
1175 /// <summary>
1176 /// Checks whether this region has a neighbour in the given direction.
1177 /// </summary>
1178 /// <param name="car"></param>
1179 /// <param name="fix"></param>
1180 /// <returns>
1181 /// An integer which represents a compass point. N == 1, going clockwise until we reach NW == 8.
1182 /// Returns a positive integer if there is a region in that direction, a negative integer if not.
1183 /// </returns>
1184 public int HaveNeighbor(Cardinals car, ref int[] fix)
1185 {
1186 uint neighbourx = RegionInfo.RegionLocX;
1187 uint neighboury = RegionInfo.RegionLocY;
1188
1189 int dir = (int)car;
1190
1191 if (dir > 1 && dir < 5) //Heading East
1192 neighbourx++;
1193 else if (dir > 5) // Heading West
1194 neighbourx--;
1195
1196 if (dir < 3 || dir == 8) // Heading North
1197 neighboury++;
1198 else if (dir > 3 && dir < 7) // Heading Sout
1199 neighboury--;
1200
1201 int x = (int)(neighbourx * Constants.RegionSize);
1202 int y = (int)(neighboury * Constants.RegionSize);
1203 GridRegion neighbourRegion = GridService.GetRegionByPosition(RegionInfo.ScopeID, x, y);
1204
1205 if (neighbourRegion == null)
1206 {
1207 fix[0] = (int)(RegionInfo.RegionLocX - neighbourx);
1208 fix[1] = (int)(RegionInfo.RegionLocY - neighboury);
1209 return dir * (-1);
1210 }
1211 else
1212 return dir;
1213 }
1214
1215 // Alias IncomingHelloNeighbour OtherRegionUp, for now 1176 // Alias IncomingHelloNeighbour OtherRegionUp, for now
1216 public GridRegion IncomingHelloNeighbour(RegionInfo neighbour) 1177 public GridRegion IncomingHelloNeighbour(RegionInfo neighbour)
1217 { 1178 {
@@ -1894,7 +1855,7 @@ namespace OpenSim.Region.Framework.Scenes
1894 { 1855 {
1895 try 1856 try
1896 { 1857 {
1897 double[,] map = SimulationDataService.LoadTerrain(RegionInfo.RegionID); 1858 TerrainData map = SimulationDataService.LoadTerrain(RegionInfo.RegionID, (int)RegionInfo.RegionSizeX, (int)RegionInfo.RegionSizeY, (int)RegionInfo.RegionSizeZ);
1898 if (map == null) 1859 if (map == null)
1899 { 1860 {
1900 // This should be in the Terrain module, but it isn't because 1861 // This should be in the Terrain module, but it isn't because
@@ -1905,7 +1866,7 @@ namespace OpenSim.Region.Framework.Scenes
1905 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain); 1866 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain);
1906 1867
1907 m_log.InfoFormat("[TERRAIN]: No default terrain. Generating a new terrain {0}.", m_InitialTerrain); 1868 m_log.InfoFormat("[TERRAIN]: No default terrain. Generating a new terrain {0}.", m_InitialTerrain);
1908 Heightmap = new TerrainChannel(m_InitialTerrain); 1869 Heightmap = new TerrainChannel(m_InitialTerrain, (int)RegionInfo.RegionSizeX, (int)RegionInfo.RegionSizeY, (int)RegionInfo.RegionSizeZ);
1909 1870
1910 SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1871 SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1911 } 1872 }
@@ -2483,6 +2444,23 @@ namespace OpenSim.Region.Framework.Scenes
2483 EntityTransferModule.Cross(grp, attemptedPosition, silent); 2444 EntityTransferModule.Cross(grp, attemptedPosition, silent);
2484 } 2445 }
2485 2446
2447 // Simple test to see if a position is in the current region.
2448 // Resuming the position is relative to the region so anything outside its bounds.
2449 // Return 'true' if position inside region.
2450 public bool PositionIsInCurrentRegion(Vector3 pos)
2451 {
2452 bool ret = true;
2453 int xx = (int)Math.Floor(pos.X);
2454 int yy = (int)Math.Floor(pos.Y);
2455 if (xx < 0
2456 || xx >= RegionInfo.RegionSizeX
2457 || yy < 0
2458 || yy >= RegionInfo.RegionSizeY)
2459 ret = false;
2460 return ret;
2461
2462 }
2463
2486 public Border GetCrossedBorder(Vector3 position, Cardinals gridline) 2464 public Border GetCrossedBorder(Vector3 position, Cardinals gridline)
2487 { 2465 {
2488 if (BordersLocked) 2466 if (BordersLocked)
@@ -3900,6 +3878,7 @@ namespace OpenSim.Region.Framework.Scenes
3900 { 3878 {
3901 Border crossedBorder = GetCrossedBorder(acd.startpos, Cardinals.E); 3879 Border crossedBorder = GetCrossedBorder(acd.startpos, Cardinals.E);
3902 acd.startpos.X = crossedBorder.BorderLine.Z - 1; 3880 acd.startpos.X = crossedBorder.BorderLine.Z - 1;
3881 m_log.DebugFormat("{0} NewUserConnection Adjusted border E. startpos={1}", LogHeader, acd.startpos);
3903 } 3882 }
3904 3883
3905 if (TestBorderCross(acd.startpos, Cardinals.N)) 3884 if (TestBorderCross(acd.startpos, Cardinals.N))
@@ -4019,12 +3998,12 @@ namespace OpenSim.Region.Framework.Scenes
4019 { 3998 {
4020 if (posX < 0) 3999 if (posX < 0)
4021 posX = 0; 4000 posX = 0;
4022 else if (posX >= 256) 4001 else if (posX >= (float)RegionInfo.RegionSizeX)
4023 posX = 255.999f; 4002 posX = (float)RegionInfo.RegionSizeX - 0.001f;
4024 if (posY < 0) 4003 if (posY < 0)
4025 posY = 0; 4004 posY = 0;
4026 else if (posY >= 256) 4005 else if (posY >= (float)RegionInfo.RegionSizeY)
4027 posY = 255.999f; 4006 posY = (float)RegionInfo.RegionSizeY - 0.001f;
4028 4007
4029 reason = String.Empty; 4008 reason = String.Empty;
4030 if (Permissions.IsGod(agentID)) 4009 if (Permissions.IsGod(agentID))
@@ -4318,7 +4297,7 @@ namespace OpenSim.Region.Framework.Scenes
4318 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 4297 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
4319 4298
4320 // TODO: This check should probably be in QueryAccess(). 4299 // TODO: This check should probably be in QueryAccess().
4321 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4300 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, RegionInfo.RegionSizeX / 2, RegionInfo.RegionSizeY / 2);
4322 if (nearestParcel == null) 4301 if (nearestParcel == null)
4323 { 4302 {
4324 m_log.InfoFormat( 4303 m_log.InfoFormat(
@@ -4613,44 +4592,6 @@ namespace OpenSim.Region.Framework.Scenes
4613 ScenePresence sp = GetScenePresence(remoteClient.AgentId); 4592 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
4614 if (sp != null) 4593 if (sp != null)
4615 { 4594 {
4616 uint regionX = RegionInfo.RegionLocX;
4617 uint regionY = RegionInfo.RegionLocY;
4618
4619 Utils.LongToUInts(regionHandle, out regionX, out regionY);
4620
4621 int shiftx = (int) regionX - (int) RegionInfo.RegionLocX * (int)Constants.RegionSize;
4622 int shifty = (int) regionY - (int) RegionInfo.RegionLocY * (int)Constants.RegionSize;
4623
4624 position.X += shiftx;
4625 position.Y += shifty;
4626
4627 bool result = false;
4628
4629 if (TestBorderCross(position,Cardinals.N))
4630 result = true;
4631
4632 if (TestBorderCross(position, Cardinals.S))
4633 result = true;
4634
4635 if (TestBorderCross(position, Cardinals.E))
4636 result = true;
4637
4638 if (TestBorderCross(position, Cardinals.W))
4639 result = true;
4640
4641 // bordercross if position is outside of region
4642
4643 if (!result)
4644 {
4645 regionHandle = RegionInfo.RegionHandle;
4646 }
4647 else
4648 {
4649 // not in this region, undo the shift!
4650 position.X -= shiftx;
4651 position.Y -= shifty;
4652 }
4653
4654 if (EntityTransferModule != null) 4595 if (EntityTransferModule != null)
4655 { 4596 {
4656 EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags); 4597 EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
@@ -4830,7 +4771,7 @@ namespace OpenSim.Region.Framework.Scenes
4830 else 4771 else
4831 { 4772 {
4832 4773
4833 if (pos.X > 0f && pos.X < Constants.RegionSize && pos.Y > 0f && pos.Y < Constants.RegionSize) 4774 if (pos.X > 0f && pos.X < RegionInfo.RegionSizeX && pos.Y > 0f && pos.Y < RegionInfo.RegionSizeY)
4834 { 4775 {
4835 // The only time parcel != null when an object is inside a region is when 4776 // The only time parcel != null when an object is inside a region is when
4836 // there is nothing behind the landchannel. IE, no land plugin loaded. 4777 // there is nothing behind the landchannel. IE, no land plugin loaded.
@@ -5491,7 +5432,7 @@ namespace OpenSim.Region.Framework.Scenes
5491 { 5432 {
5492 Vector3 unitDirection = Vector3.Normalize(direction); 5433 Vector3 unitDirection = Vector3.Normalize(direction);
5493 //Making distance to search go through some sane limit of distance 5434 //Making distance to search go through some sane limit of distance
5494 for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f) 5435 for (float distance = 0; distance < Math.Max(RegionInfo.RegionSizeX, RegionInfo.RegionSizeY) * 2; distance += .5f)
5495 { 5436 {
5496 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance)); 5437 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
5497 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y)) 5438 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
@@ -5545,9 +5486,9 @@ namespace OpenSim.Region.Framework.Scenes
5545 int count = 0; 5486 int count = 0;
5546 int avgx = 0; 5487 int avgx = 0;
5547 int avgy = 0; 5488 int avgy = 0;
5548 for (int x = 0; x < Constants.RegionSize; x++) 5489 for (int x = 0; x < RegionInfo.RegionSizeX; x++)
5549 { 5490 {
5550 for (int y = 0; y < Constants.RegionSize; y++) 5491 for (int y = 0; y < RegionInfo.RegionSizeY; y++)
5551 { 5492 {
5552 //Just keep a running average as we check if all the points are inside or not 5493 //Just keep a running average as we check if all the points are inside or not
5553 if (parcel.ContainsPoint(x, y)) 5494 if (parcel.ContainsPoint(x, y))
@@ -5571,31 +5512,33 @@ namespace OpenSim.Region.Framework.Scenes
5571 5512
5572 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar) 5513 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
5573 { 5514 {
5574 float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X; 5515 float xdistance = avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2
5575 float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y; 5516 ? avatar.AbsolutePosition.X : RegionInfo.RegionSizeX - avatar.AbsolutePosition.X;
5517 float ydistance = avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2
5518 ? avatar.AbsolutePosition.Y : RegionInfo.RegionSizeY - avatar.AbsolutePosition.Y;
5576 5519
5577 //find out what vertical edge to go to 5520 //find out what vertical edge to go to
5578 if (xdistance < ydistance) 5521 if (xdistance < ydistance)
5579 { 5522 {
5580 if (avatar.AbsolutePosition.X < Constants.RegionSize / 2) 5523 if (avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2)
5581 { 5524 {
5582 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y); 5525 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
5583 } 5526 }
5584 else 5527 else
5585 { 5528 {
5586 return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y); 5529 return GetPositionAtAvatarHeightOrGroundHeight(avatar, RegionInfo.RegionSizeY, avatar.AbsolutePosition.Y);
5587 } 5530 }
5588 } 5531 }
5589 //find out what horizontal edge to go to 5532 //find out what horizontal edge to go to
5590 else 5533 else
5591 { 5534 {
5592 if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2) 5535 if (avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2)
5593 { 5536 {
5594 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f); 5537 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
5595 } 5538 }
5596 else 5539 else
5597 { 5540 {
5598 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize); 5541 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, RegionInfo.RegionSizeY);
5599 } 5542 }
5600 } 5543 }
5601 } 5544 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index c86f412..b059ecf 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -42,8 +42,8 @@ namespace OpenSim.Region.Framework.Scenes
42{ 42{
43 public abstract class SceneBase : IScene 43 public abstract class SceneBase : IScene
44 { 44 {
45 protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 protected static readonly string LogHeader = "[SCENE]"; 46 private static readonly string LogHeader = "[SCENE]";
47 47
48 #region Events 48 #region Events
49 49
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 77889fa..c873e40 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Framework.Scenes
92 { 92 {
93 m_log.DebugFormat( 93 m_log.DebugFormat(
94 "[SCENE COMMUNICATION SERVICE]: Region {0} successfully informed neighbour {1} at {2}-{3} that it is up", 94 "[SCENE COMMUNICATION SERVICE]: Region {0} successfully informed neighbour {1} at {2}-{3} that it is up",
95 m_scene.Name, neighbour.RegionName, x / Constants.RegionSize, y / Constants.RegionSize); 95 m_scene.Name, neighbour.RegionName, Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y));
96 96
97 m_scene.EventManager.TriggerOnRegionUp(neighbour); 97 m_scene.EventManager.TriggerOnRegionUp(neighbour);
98 } 98 }
@@ -100,7 +100,7 @@ namespace OpenSim.Region.Framework.Scenes
100 { 100 {
101 m_log.WarnFormat( 101 m_log.WarnFormat(
102 "[SCENE COMMUNICATION SERVICE]: Region {0} failed to inform neighbour at {1}-{2} that it is up.", 102 "[SCENE COMMUNICATION SERVICE]: Region {0} failed to inform neighbour at {1}-{2} that it is up.",
103 m_scene.Name, x / Constants.RegionSize, y / Constants.RegionSize); 103 m_scene.Name, Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y));
104 } 104 }
105 } 105 }
106 106
@@ -166,7 +166,7 @@ namespace OpenSim.Region.Framework.Scenes
166 // we only want to send one update to each simulator; the simulator will 166 // we only want to send one update to each simulator; the simulator will
167 // hand it off to the regions where a child agent exists, this does assume 167 // hand it off to the regions where a child agent exists, this does assume
168 // that the region position is cached or performance will degrade 168 // that the region position is cached or performance will degrade
169 Utils.LongToUInts(regionHandle, out x, out y); 169 Util.RegionHandleToWorldLoc(regionHandle, out x, out y);
170 GridRegion dest = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); 170 GridRegion dest = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
171 if (dest == null) 171 if (dest == null)
172 continue; 172 continue;
@@ -203,7 +203,7 @@ namespace OpenSim.Region.Framework.Scenes
203 203
204 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); 204 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID);
205 uint x = 0, y = 0; 205 uint x = 0, y = 0;
206 Utils.LongToUInts(regionHandle, out x, out y); 206 Util.RegionHandleToWorldLoc(regionHandle, out x, out y);
207 207
208 GridRegion destination = m_scene.GridService.GetRegionByPosition(m_regionInfo.ScopeID, (int)x, (int)y); 208 GridRegion destination = m_scene.GridService.GetRegionByPosition(m_regionInfo.ScopeID, (int)x, (int)y);
209 209
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 9bd7632..c6b98ca 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -334,7 +334,7 @@ namespace OpenSim.Region.Framework.Scenes
334 { 334 {
335 get 335 get
336 { 336 {
337 Vector3 minScale = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize); 337 Vector3 minScale = new Vector3(Constants.MaximumRegionSize, Constants.MaximumRegionSize, Constants.MaximumRegionSize);
338 Vector3 maxScale = Vector3.Zero; 338 Vector3 maxScale = Vector3.Zero;
339 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 339 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
340 340
@@ -466,8 +466,6 @@ namespace OpenSim.Region.Framework.Scenes
466 && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) 466 && !IsAttachmentCheckFull() && (!Scene.LoadingPrims))
467 { 467 {
468 IEntityTransferModule entityTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 468 IEntityTransferModule entityTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
469 uint x = 0;
470 uint y = 0;
471 string version = String.Empty; 469 string version = String.Empty;
472 Vector3 newpos = Vector3.Zero; 470 Vector3 newpos = Vector3.Zero;
473 OpenSim.Services.Interfaces.GridRegion destination = null; 471 OpenSim.Services.Interfaces.GridRegion destination = null;
@@ -487,7 +485,7 @@ namespace OpenSim.Region.Framework.Scenes
487 485
488 // We set the avatar position as being the object 486 // We set the avatar position as being the object
489 // position to get the region to send to 487 // position to get the region to send to
490 if ((destination = entityTransfer.GetDestination(m_scene, av.UUID, val, out x, out y, out version, out newpos)) == null) 488 if ((destination = entityTransfer.GetDestination(m_scene, av.UUID, val, out version, out newpos)) == null)
491 { 489 {
492 canCross = false; 490 canCross = false;
493 break; 491 break;
@@ -522,14 +520,14 @@ namespace OpenSim.Region.Framework.Scenes
522 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 520 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
523 521
524 // Normalize 522 // Normalize
525 if (val.X >= Constants.RegionSize) 523 if (val.X >= m_scene.RegionInfo.RegionSizeX)
526 val.X -= Constants.RegionSize; 524 val.X -= m_scene.RegionInfo.RegionSizeX;
527 if (val.Y >= Constants.RegionSize) 525 if (val.Y >= m_scene.RegionInfo.RegionSizeY)
528 val.Y -= Constants.RegionSize; 526 val.Y -= m_scene.RegionInfo.RegionSizeY;
529 if (val.X < 0) 527 if (val.X < 0)
530 val.X += Constants.RegionSize; 528 val.X += m_scene.RegionInfo.RegionSizeX;
531 if (val.Y < 0) 529 if (val.Y < 0)
532 val.Y += Constants.RegionSize; 530 val.Y += m_scene.RegionInfo.RegionSizeY;
533 531
534 // If it's deleted, crossing was successful 532 // If it's deleted, crossing was successful
535 if (IsDeleted) 533 if (IsDeleted)
@@ -577,9 +575,9 @@ namespace OpenSim.Region.Framework.Scenes
577 } 575 }
578 } 576 }
579 Vector3 oldp = AbsolutePosition; 577 Vector3 oldp = AbsolutePosition;
580 val.X = Util.Clamp<float>(oldp.X, 0.5f, (float)Constants.RegionSize - 0.5f); 578 val.X = Util.Clamp<float>(oldp.X, 0.5f, (float)m_scene.RegionInfo.RegionSizeX - 0.5f);
581 val.Y = Util.Clamp<float>(oldp.Y, 0.5f, (float)Constants.RegionSize - 0.5f); 579 val.Y = Util.Clamp<float>(oldp.Y, 0.5f, (float)m_scene.RegionInfo.RegionSizeY - 0.5f);
582 val.Z = Util.Clamp<float>(oldp.Z, 0.5f, 4096.0f); 580 val.Z = Util.Clamp<float>(oldp.Z, 0.5f, Constants.RegionHeight);
583 } 581 }
584 } 582 }
585 583
@@ -996,9 +994,9 @@ namespace OpenSim.Region.Framework.Scenes
996 maxX = -256f; 994 maxX = -256f;
997 maxY = -256f; 995 maxY = -256f;
998 maxZ = -256f; 996 maxZ = -256f;
999 minX = 256f; 997 minX = 10000f;
1000 minY = 256f; 998 minY = 10000f;
1001 minZ = 8192f; 999 minZ = 10000f;
1002 1000
1003 SceneObjectPart[] parts = m_parts.GetArray(); 1001 SceneObjectPart[] parts = m_parts.GetArray();
1004 for (int i = 0; i < parts.Length; i++) 1002 for (int i = 0; i < parts.Length; i++)
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 84201cc..715a9b6 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -76,6 +76,7 @@ namespace OpenSim.Region.Framework.Scenes
76 public class ScenePresence : EntityBase, IScenePresence 76 public class ScenePresence : EntityBase, IScenePresence
77 { 77 {
78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
79 private static readonly String LogHeader = "[SCENE PRESENCE]";
79 80
80// ~ScenePresence() 81// ~ScenePresence()
81// { 82// {
@@ -759,9 +760,8 @@ namespace OpenSim.Region.Framework.Scenes
759 foreach (ulong handle in seeds.Keys) 760 foreach (ulong handle in seeds.Keys)
760 { 761 {
761 uint x, y; 762 uint x, y;
762 Utils.LongToUInts(handle, out x, out y); 763 Util.RegionHandleToRegionLoc(handle, out x, out y);
763 x = x / Constants.RegionSize; 764
764 y = y / Constants.RegionSize;
765 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) 765 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY))
766 { 766 {
767 old.Add(handle); 767 old.Add(handle);
@@ -783,9 +783,7 @@ namespace OpenSim.Region.Framework.Scenes
783 foreach (KeyValuePair<ulong, string> kvp in KnownRegions) 783 foreach (KeyValuePair<ulong, string> kvp in KnownRegions)
784 { 784 {
785 uint x, y; 785 uint x, y;
786 Utils.LongToUInts(kvp.Key, out x, out y); 786 Util.RegionHandleToRegionLoc(kvp.Key, out x, out y);
787 x = x / Constants.RegionSize;
788 y = y / Constants.RegionSize;
789 m_log.Info(" >> "+x+", "+y+": "+kvp.Value); 787 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
790 } 788 }
791 } 789 }
@@ -1092,6 +1090,10 @@ namespace OpenSim.Region.Framework.Scenes
1092 // before the inventory is processed in MakeRootAgent. This fixes a race condition 1090 // before the inventory is processed in MakeRootAgent. This fixes a race condition
1093 // related to the handling of attachments 1091 // related to the handling of attachments
1094 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); 1092 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
1093
1094 /* RA 20140111: Commented out these TestBorderCross's.
1095 * Not sure why this code is here. It is not checking all the borders
1096 * and 'in region' sanity checking is done in CheckAndAdjustLandingPoint and below.
1095 if (m_scene.TestBorderCross(pos, Cardinals.E)) 1097 if (m_scene.TestBorderCross(pos, Cardinals.E))
1096 { 1098 {
1097 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 1099 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
@@ -1103,6 +1105,7 @@ namespace OpenSim.Region.Framework.Scenes
1103 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 1105 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
1104 pos.Y = crossedBorder.BorderLine.Z - 1; 1106 pos.Y = crossedBorder.BorderLine.Z - 1;
1105 } 1107 }
1108 */
1106 1109
1107 CheckAndAdjustLandingPoint(ref pos); 1110 CheckAndAdjustLandingPoint(ref pos);
1108 1111
@@ -1123,7 +1126,7 @@ namespace OpenSim.Region.Framework.Scenes
1123 1126
1124 float posZLimit = 0; 1127 float posZLimit = 0;
1125 1128
1126 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1129 if (pos.X < m_scene.RegionInfo.RegionSizeX && pos.Y < m_scene.RegionInfo.RegionSizeY)
1127 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1130 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
1128 1131
1129 float newPosZ = posZLimit + localAVHeight / 2; 1132 float newPosZ = posZLimit + localAVHeight / 2;
@@ -2400,7 +2403,7 @@ namespace OpenSim.Region.Framework.Scenes
2400 if (regionCombinerModule != null) 2403 if (regionCombinerModule != null)
2401 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID); 2404 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID);
2402 else 2405 else
2403 regionSize = new Vector2(Constants.RegionSize); 2406 regionSize = new Vector2(m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
2404 2407
2405 if (pos.X < 0 || pos.X >= regionSize.X 2408 if (pos.X < 0 || pos.X >= regionSize.X
2406 || pos.Y < 0 || pos.Y >= regionSize.Y 2409 || pos.Y < 0 || pos.Y >= regionSize.Y
@@ -2418,8 +2421,8 @@ namespace OpenSim.Region.Framework.Scenes
2418// } 2421// }
2419 2422
2420 // Get terrain height for sub-region in a megaregion if necessary 2423 // Get terrain height for sub-region in a megaregion if necessary
2421 int X = (int)((m_scene.RegionInfo.RegionLocX * Constants.RegionSize) + pos.X); 2424 int X = (int)((m_scene.RegionInfo.WorldLocX) + pos.X);
2422 int Y = (int)((m_scene.RegionInfo.RegionLocY * Constants.RegionSize) + pos.Y); 2425 int Y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y);
2423 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y); 2426 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y);
2424 // If X and Y is NaN, target_region will be null 2427 // If X and Y is NaN, target_region will be null
2425 if (target_region == null) 2428 if (target_region == null)
@@ -2430,7 +2433,7 @@ namespace OpenSim.Region.Framework.Scenes
2430 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene)) 2433 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene))
2431 targetScene = m_scene; 2434 targetScene = m_scene;
2432 2435
2433 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % Constants.RegionSize), (int)(pos.Y % Constants.RegionSize)]; 2436 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
2434 pos.Z = Math.Max(terrainHeight, pos.Z); 2437 pos.Z = Math.Max(terrainHeight, pos.Z);
2435 2438
2436 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is 2439 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is
@@ -3466,10 +3469,14 @@ namespace OpenSim.Region.Framework.Scenes
3466 if (!IsInTransit) 3469 if (!IsInTransit)
3467 { 3470 {
3468 Vector3 pos2 = AbsolutePosition; 3471 Vector3 pos2 = AbsolutePosition;
3472 Vector3 origPosition = pos2;
3469 Vector3 vel = Velocity; 3473 Vector3 vel = Velocity;
3470 int neighbor = 0; 3474 int neighbor = 0;
3471 int[] fix = new int[2]; 3475 int[] fix = new int[2];
3472 3476
3477 // Compute the avatar position in the next physics tick.
3478 // If the avatar will be crossing, we force the crossing to happen now
3479 // in the hope that this will make the avatar movement smoother when crossing.
3473 float timeStep = 0.1f; 3480 float timeStep = 0.1f;
3474 pos2.X = pos2.X + (vel.X * timeStep); 3481 pos2.X = pos2.X + (vel.X * timeStep);
3475 pos2.Y = pos2.Y + (vel.Y * timeStep); 3482 pos2.Y = pos2.Y + (vel.Y * timeStep);
@@ -3477,111 +3484,44 @@ namespace OpenSim.Region.Framework.Scenes
3477 3484
3478 if (!IsInTransit) 3485 if (!IsInTransit)
3479 { 3486 {
3480// m_log.DebugFormat( 3487 if (!m_scene.PositionIsInCurrentRegion(pos2))
3481// "[SCENE PRESENCE]: Testing border check for projected position {0} of {1} in {2}",
3482// pos2, Name, Scene.Name);
3483
3484 // Checks if where it's headed exists a region
3485 bool needsTransit = false;
3486 if (m_scene.TestBorderCross(pos2, Cardinals.W))
3487 {
3488 if (m_scene.TestBorderCross(pos2, Cardinals.S))
3489 {
3490 needsTransit = true;
3491 neighbor = m_scene.HaveNeighbor(Cardinals.SW, ref fix);
3492 }
3493 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3494 {
3495 needsTransit = true;
3496 neighbor = m_scene.HaveNeighbor(Cardinals.NW, ref fix);
3497 }
3498 else
3499 {
3500 needsTransit = true;
3501 neighbor = m_scene.HaveNeighbor(Cardinals.W, ref fix);
3502 }
3503 }
3504 else if (m_scene.TestBorderCross(pos2, Cardinals.E))
3505 { 3488 {
3506 if (m_scene.TestBorderCross(pos2, Cardinals.S)) 3489 m_log.DebugFormat("{0} CheckForBorderCrossing: position outside region. {1} in {2} at pos {3}",
3490 LogHeader, Name, Scene.Name, pos2);
3491
3492 // Disconnect from the current region
3493 bool isFlying = Flying;
3494 RemoveFromPhysicalScene();
3495 // pos2 is the forcasted position so make that the 'current' position so the crossing
3496 // code will move us into the newly addressed region.
3497 m_pos = pos2;
3498 if (CrossToNewRegion())
3507 { 3499 {
3508 needsTransit = true; 3500 AddToPhysicalScene(isFlying);
3509 neighbor = m_scene.HaveNeighbor(Cardinals.SE, ref fix);
3510 }
3511 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3512 {
3513 needsTransit = true;
3514 neighbor = m_scene.HaveNeighbor(Cardinals.NE, ref fix);
3515 } 3501 }
3516 else 3502 else
3517 { 3503 {
3518 needsTransit = true; 3504 // Tried to make crossing happen but it failed.
3519 neighbor = m_scene.HaveNeighbor(Cardinals.E, ref fix);
3520 }
3521 }
3522 else if (m_scene.TestBorderCross(pos2, Cardinals.S))
3523 {
3524 needsTransit = true;
3525 neighbor = m_scene.HaveNeighbor(Cardinals.S, ref fix);
3526 }
3527 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3528 {
3529 needsTransit = true;
3530 neighbor = m_scene.HaveNeighbor(Cardinals.N, ref fix);
3531 }
3532
3533 // Makes sure avatar does not end up outside region
3534 if (neighbor <= 0)
3535 {
3536 if (needsTransit)
3537 {
3538 if (m_requestedSitTargetUUID == UUID.Zero)
3539 {
3540 bool isFlying = Flying;
3541 RemoveFromPhysicalScene();
3542
3543 Vector3 pos = AbsolutePosition;
3544 if (AbsolutePosition.X < 0)
3545 pos.X += Velocity.X * 2;
3546 else if (AbsolutePosition.X > Constants.RegionSize)
3547 pos.X -= Velocity.X * 2;
3548 if (AbsolutePosition.Y < 0)
3549 pos.Y += Velocity.Y * 2;
3550 else if (AbsolutePosition.Y > Constants.RegionSize)
3551 pos.Y -= Velocity.Y * 2;
3552 Velocity = Vector3.Zero;
3553 AbsolutePosition = pos;
3554
3555// m_log.DebugFormat("[SCENE PRESENCE]: Prevented flyoff for {0} at {1}", Name, AbsolutePosition);
3556
3557 AddToPhysicalScene(isFlying);
3558 }
3559 }
3560 }
3561 else if (neighbor > 0)
3562 {
3563 if (!CrossToNewRegion())
3564 {
3565 if (m_requestedSitTargetUUID == UUID.Zero) 3505 if (m_requestedSitTargetUUID == UUID.Zero)
3566 { 3506 {
3567 bool isFlying = Flying; 3507 m_log.DebugFormat("{0} CheckForBorderCrossing: Crossing failed. Restoring old position.", LogHeader);
3568 RemoveFromPhysicalScene(); 3508 const float borderFudge = 0.1f;
3569 3509
3570 Vector3 pos = AbsolutePosition; 3510 if (origPosition.X < 0)
3571 if (AbsolutePosition.X < 0) 3511 origPosition.X = borderFudge;
3572 pos.X += Velocity.X * 2; 3512 else if (origPosition.X > (float)m_scene.RegionInfo.RegionSizeX)
3573 else if (AbsolutePosition.X > Constants.RegionSize) 3513 origPosition.X = (float)m_scene.RegionInfo.RegionSizeX - borderFudge;
3574 pos.X -= Velocity.X * 2; 3514 if (origPosition.Y < 0)
3575 if (AbsolutePosition.Y < 0) 3515 origPosition.Y = borderFudge;
3576 pos.Y += Velocity.Y * 2; 3516 else if (origPosition.Y > (float)m_scene.RegionInfo.RegionSizeY)
3577 else if (AbsolutePosition.Y > Constants.RegionSize) 3517 origPosition.Y = (float)m_scene.RegionInfo.RegionSizeY - borderFudge;
3578 pos.Y -= Velocity.Y * 2;
3579 Velocity = Vector3.Zero; 3518 Velocity = Vector3.Zero;
3580 AbsolutePosition = pos; 3519 AbsolutePosition = origPosition;
3581 3520
3582 AddToPhysicalScene(isFlying); 3521 AddToPhysicalScene(isFlying);
3583 } 3522 }
3584 } 3523 }
3524
3585 } 3525 }
3586 } 3526 }
3587 else 3527 else
@@ -3623,7 +3563,7 @@ namespace OpenSim.Region.Framework.Scenes
3623 3563
3624 // Put the child agent back at the center 3564 // Put the child agent back at the center
3625 AbsolutePosition 3565 AbsolutePosition
3626 = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); 3566 = new Vector3(((float)m_scene.RegionInfo.RegionSizeX * 0.5f), ((float)m_scene.RegionInfo.RegionSizeY * 0.5f), 70);
3627 3567
3628 Animator.ResetAnimations(); 3568 Animator.ResetAnimations();
3629 } 3569 }
@@ -3650,9 +3590,7 @@ namespace OpenSim.Region.Framework.Scenes
3650 if (handle != Scene.RegionInfo.RegionHandle) 3590 if (handle != Scene.RegionInfo.RegionHandle)
3651 { 3591 {
3652 uint x, y; 3592 uint x, y;
3653 Utils.LongToUInts(handle, out x, out y); 3593 Util.RegionHandleToRegionLoc(handle, out x, out y);
3654 x = x / Constants.RegionSize;
3655 y = y / Constants.RegionSize;
3656 3594
3657// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); 3595// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
3658// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); 3596// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
@@ -3733,8 +3671,9 @@ namespace OpenSim.Region.Framework.Scenes
3733 return; 3671 return;
3734 3672
3735 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); 3673 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY);
3736 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; 3674 // Find the distance (in meters) between the two regions
3737 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; 3675 uint shiftx = Util.RegionToWorldLoc(rRegionX - tRegionX);
3676 uint shifty = Util.RegionToWorldLoc(rRegionY - tRegionY);
3738 3677
3739 Vector3 offset = new Vector3(shiftx, shifty, 0f); 3678 Vector3 offset = new Vector3(shiftx, shifty, 0f);
3740 3679
@@ -4770,6 +4709,7 @@ namespace OpenSim.Region.Framework.Scenes
4770 } 4709 }
4771 } 4710 }
4772 4711
4712 // Modify landing point based on possible banning, telehubs or parcel restrictions.
4773 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4713 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4774 { 4714 {
4775 string reason; 4715 string reason;
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index c0ca48e..b4b1823 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,146 @@ 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 // Create channel passed a heightmap and expected dimensions of the region.
84 // The heightmap might not fit the passed size so accomodations must be made.
85 public TerrainChannel(double[,] pM, int pSizeX, int pSizeY, int pAltitude)
66 { 86 {
67 map = import; 87 int hmSizeX = pM.GetLength(0);
68 taint = new bool[import.GetLength(0),import.GetLength(1)]; 88 int hmSizeY = pM.GetLength(1);
69 }
70 89
71 public TerrainChannel(bool createMap) 90 m_terrainData = new HeightmapTerrainData(pSizeX, pSizeY, pAltitude);
72 { 91
73 if (createMap) 92 for (int xx = 0; xx < pSizeX; xx++)
74 { 93 for (int yy = 0; yy < pSizeY; yy++)
75 map = new double[Constants.RegionSize,Constants.RegionSize]; 94 if (xx > hmSizeX || yy > hmSizeY)
76 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; 95 m_terrainData[xx, yy] = TerrainData.DefaultTerrainHeight;
77 } 96 else
97 m_terrainData[xx, yy] = (float)pM[xx, yy];
78 } 98 }
79 99
80 public TerrainChannel(int w, int h) 100 public TerrainChannel(TerrainData pTerrData)
81 { 101 {
82 map = new double[w,h]; 102 m_terrainData = pTerrData;
83 taint = new bool[w / 16,h / 16];
84 } 103 }
85 104
86 #region ITerrainChannel Members 105 #region ITerrainChannel Members
87 106
88 public int Width 107 // ITerrainChannel.MakeCopy()
108 public ITerrainChannel MakeCopy()
89 { 109 {
90 get { return map.GetLength(0); } 110 return this.Copy();
91 } 111 }
92 112
93 public int Height 113 // ITerrainChannel.GetTerrainData()
114 public TerrainData GetTerrainData()
94 { 115 {
95 get { return map.GetLength(1); } 116 return m_terrainData;
96 } 117 }
97 118
98 public ITerrainChannel MakeCopy() 119 // ITerrainChannel.GetFloatsSerialized()
120 // This one dimensional version is ordered so height = map[y*sizeX+x];
121 // DEPRECATED: don't use this function as it does not retain the dimensions of the terrain
122 // and the caller will probably do the wrong thing if the terrain is not the legacy 256x256.
123 public float[] GetFloatsSerialised()
99 { 124 {
100 TerrainChannel copy = new TerrainChannel(false); 125 int points = Width * Height;
101 copy.map = (double[,]) map.Clone(); 126 float[] heights = new float[points];
102 127
103 return copy; 128 int idx = 0;
129 for (int jj = 0; jj < Height; jj++)
130 for (int ii = 0; ii < Width; ii++)
131 {
132 heights[idx++] = m_terrainData[ii, jj];
133 }
134
135 return heights;
104 } 136 }
105 137
106 public float[] GetFloatsSerialised() 138 // ITerrainChannel.GetDoubles()
139 public double[,] GetDoubles()
107 { 140 {
108 // Move the member variables into local variables, calling 141 double[,] heights = new double[Width, Height];
109 // member variables 256*256 times gets expensive
110 int w = Width;
111 int h = Height;
112 float[] heights = new float[w * h];
113 142
114 int i, j; // map coordinates
115 int idx = 0; // index into serialized array 143 int idx = 0; // index into serialized array
116 for (i = 0; i < h; i++) 144 for (int ii = 0; ii < Width; ii++)
117 { 145 {
118 for (j = 0; j < w; j++) 146 for (int jj = 0; jj < Height; jj++)
119 { 147 {
120 heights[idx++] = (float)map[j, i]; 148 heights[ii, jj] = (double)m_terrainData[ii, jj];
149 idx++;
121 } 150 }
122 } 151 }
123 152
124 return heights; 153 return heights;
125 } 154 }
126 155
127 public double[,] GetDoubles() 156 // ITerrainChannel.this[x,y]
128 {
129 return map;
130 }
131
132 public double this[int x, int y] 157 public double this[int x, int y]
133 { 158 {
134 get { return map[x, y]; } 159 get {
160 if (x < 0 || x >= Width || y < 0 || y >= Height)
161 return 0;
162 return (double)m_terrainData[x, y];
163 }
135 set 164 set
136 { 165 {
137 // Will "fix" terrain hole problems. Although not fantastically.
138 if (Double.IsNaN(value) || Double.IsInfinity(value)) 166 if (Double.IsNaN(value) || Double.IsInfinity(value))
139 return; 167 return;
140 168
141 if (map[x, y] != value) 169 m_terrainData[x, y] = (float)value;
142 {
143 taint[x / 16, y / 16] = true;
144 map[x, y] = value;
145 }
146 } 170 }
147 } 171 }
148 172
149 public bool Tainted(int x, int y) 173 // ITerrainChannel.GetHieghtAtXYZ(x, y, z)
174 public float GetHeightAtXYZ(float x, float y, float z)
150 { 175 {
151 if (taint[x / 16, y / 16]) 176 if (x < 0 || x >= Width || y < 0 || y >= Height)
152 { 177 return 0;
153 taint[x / 16, y / 16] = false; 178 return m_terrainData[(int)x, (int)y];
154 return true;
155 }
156 return false;
157 } 179 }
158 180
159 #endregion 181 // ITerrainChannel.Tainted()
160 182 public bool Tainted(int x, int y)
161 public TerrainChannel Copy()
162 { 183 {
163 TerrainChannel copy = new TerrainChannel(false); 184 return m_terrainData.IsTaintedAt(x, y);
164 copy.map = (double[,]) map.Clone();
165
166 return copy;
167 } 185 }
168 186
187 // ITerrainChannel.SaveToXmlString()
169 public string SaveToXmlString() 188 public string SaveToXmlString()
170 { 189 {
171 XmlWriterSettings settings = new XmlWriterSettings(); 190 XmlWriterSettings settings = new XmlWriterSettings();
@@ -181,13 +200,7 @@ namespace OpenSim.Region.Framework.Scenes
181 } 200 }
182 } 201 }
183 202
184 private void WriteXml(XmlWriter writer) 203 // 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) 204 public void LoadFromXmlString(string data)
192 { 205 {
193 StringReader sr = new StringReader(data); 206 StringReader sr = new StringReader(data);
@@ -199,12 +212,50 @@ namespace OpenSim.Region.Framework.Scenes
199 sr.Close(); 212 sr.Close();
200 } 213 }
201 214
215 #endregion
216
217 public TerrainChannel Copy()
218 {
219 TerrainChannel copy = new TerrainChannel();
220 copy.m_terrainData = m_terrainData.Clone();
221 return copy;
222 }
223
224 private void WriteXml(XmlWriter writer)
225 {
226 if (Width == Constants.RegionSize && Height == Constants.RegionSize)
227 {
228 // Downward compatibility for legacy region terrain maps.
229 // If region is exactly legacy size, return the old format XML.
230 writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
231 ToXml(writer);
232 writer.WriteEndElement();
233 }
234 else
235 {
236 // New format XML that includes width and length.
237 writer.WriteStartElement(String.Empty, "TerrainMap2", String.Empty);
238 ToXml2(writer);
239 writer.WriteEndElement();
240 }
241 }
242
202 private void ReadXml(XmlReader reader) 243 private void ReadXml(XmlReader reader)
203 { 244 {
204 reader.ReadStartElement("TerrainMap"); 245 // Check the first element. If legacy element, use the legacy reader.
205 FromXml(reader); 246 if (reader.IsStartElement("TerrainMap"))
247 {
248 reader.ReadStartElement("TerrainMap");
249 FromXml(reader);
250 }
251 else
252 {
253 reader.ReadStartElement("TerrainMap2");
254 FromXml2(reader);
255 }
206 } 256 }
207 257
258 // Write legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
208 private void ToXml(XmlWriter xmlWriter) 259 private void ToXml(XmlWriter xmlWriter)
209 { 260 {
210 float[] mapData = GetFloatsSerialised(); 261 float[] mapData = GetFloatsSerialised();
@@ -218,12 +269,15 @@ namespace OpenSim.Region.Framework.Scenes
218 serializer.Serialize(xmlWriter, buffer); 269 serializer.Serialize(xmlWriter, buffer);
219 } 270 }
220 271
272 // Read legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
221 private void FromXml(XmlReader xmlReader) 273 private void FromXml(XmlReader xmlReader)
222 { 274 {
223 XmlSerializer serializer = new XmlSerializer(typeof(byte[])); 275 XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
224 byte[] dataArray = (byte[])serializer.Deserialize(xmlReader); 276 byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
225 int index = 0; 277 int index = 0;
226 278
279 m_terrainData = new HeightmapTerrainData(Height, Width, (int)Constants.RegionHeight);
280
227 for (int y = 0; y < Height; y++) 281 for (int y = 0; y < Height; y++)
228 { 282 {
229 for (int x = 0; x < Width; x++) 283 for (int x = 0; x < Width; x++)
@@ -236,35 +290,63 @@ namespace OpenSim.Region.Framework.Scenes
236 } 290 }
237 } 291 }
238 292
293 private class TerrainChannelXMLPackage
294 {
295 public int Version;
296 public int SizeX;
297 public int SizeY;
298 public int SizeZ;
299 public float CompressionFactor;
300 public short[] Map;
301 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, short[] pMap)
302 {
303 Version = 1;
304 SizeX = pX;
305 SizeY = pY;
306 SizeZ = pZ;
307 CompressionFactor = pCompressionFactor;
308 Map = pMap;
309 }
310 }
311
312 // New terrain serialization format that includes the width and length.
313 private void ToXml2(XmlWriter xmlWriter)
314 {
315 TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.CompressionFactor,
316 m_terrainData.GetCompressedMap());
317 XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
318 serializer.Serialize(xmlWriter, package);
319 }
320
321 // New terrain serialization format that includes the width and length.
322 private void FromXml2(XmlReader xmlReader)
323 {
324 XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
325 TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader);
326 m_terrainData = new HeightmapTerrainData(package.Map, package.CompressionFactor, package.SizeX, package.SizeY, package.SizeZ);
327 }
328
329 // Fill the heightmap with the center bump terrain
239 private void PinHeadIsland() 330 private void PinHeadIsland()
240 { 331 {
241 int x; 332 for (int x = 0; x < Width; x++)
242 for (x = 0; x < Constants.RegionSize; x++)
243 { 333 {
244 int y; 334 for (int y = 0; y < Height; y++)
245 for (y = 0; y < Constants.RegionSize; y++)
246 { 335 {
247 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10; 336 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; 337 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; 338 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) 339 if (m_terrainData[x, y]< spherFacA)
251 map[x, y] = spherFacA; 340 m_terrainData[x, y]= spherFacA;
252 if (map[x, y] < spherFacB) 341 if (m_terrainData[x, y]< spherFacB)
253 map[x, y] = spherFacB; 342 m_terrainData[x, y] = spherFacB;
254 } 343 }
255 } 344 }
256 } 345 }
257 346
258 private void FlatLand() 347 private void FlatLand()
259 { 348 {
260 int x; 349 m_terrainData.ClearLand();
261 for (x = 0; x < Constants.RegionSize; x++)
262 {
263 int y;
264 for (y = 0; y < Constants.RegionSize; y++)
265 map[x, y] = 21;
266 }
267 } 350 }
268
269 } 351 }
270} 352}
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
new file mode 100644
index 0000000..ced62e2
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -0,0 +1,944 @@
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 // Create a land packet for a single patch.
112 public static LayerDataPacket CreateLandPacket(TerrainData terrData, int patchX, int patchY)
113 {
114 int[] xPieces = new int[1];
115 int[] yPieces = new int[1];
116 xPieces[0] = patchX; // patch X dimension
117 yPieces[0] = patchY;
118
119 byte landPacketType = (byte)TerrainPatch.LayerType.Land;
120 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
121 {
122 // libOMV does not have a packet type defined for the extended parcel format.
123 // We just happen to know the extended parcel format code is one more than the usual code.
124 landPacketType++;
125 }
126
127 return CreateLandPacket(terrData, xPieces, yPieces, landPacketType);
128 }
129
130 /// <summary>
131 /// Creates a LayerData packet for compressed land data given a full
132 /// simulator heightmap and an array of indices of patches to compress
133 /// </summary>
134 /// <param name="terrData">
135 /// Terrain data that can result in a meter square heightmap.
136 /// </param>
137 /// <param name="x">
138 /// Array of indexes in the grid of patches
139 /// for this simulator.
140 /// If creating a packet for multiple patches, there will be entries in
141 /// both the X and Y arrays for each of the patches.
142 /// For example if patches 1 and 17 are to be sent,
143 /// x[] = {1,1} and y[] = {0,1} which specifies the patches at
144 /// indexes <1,0> and <1,1> (presuming the terrain size is 16x16 patches).
145 /// </param>
146 /// <param name="y">
147 /// Array of indexes in the grid of patches.
148 /// </param>
149 /// <param name="type"></param>
150 /// <param name="pRegionSizeX"></param>
151 /// <param name="pRegionSizeY"></param>
152 /// <returns></returns>
153 public static LayerDataPacket CreateLandPacket(TerrainData terrData, int[] x, int[] y, byte type)
154 {
155 LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}};
156
157 TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
158 {Stride = STRIDE, PatchSize = Constants.TerrainPatchSize};
159
160 byte[] data = new byte[x.Length * Constants.TerrainPatchSize * Constants.TerrainPatchSize * 2];
161 BitPack bitpack = new BitPack(data, 0);
162 bitpack.PackBits(header.Stride, 16);
163 bitpack.PackBits(header.PatchSize, 8);
164 bitpack.PackBits(type, 8);
165
166 for (int i = 0; i < x.Length; i++)
167 CreatePatchFromHeightmap(bitpack, terrData, x[i], y[i]);
168
169 bitpack.PackBits(END_OF_PATCHES, 8);
170
171 layer.LayerData.Data = new byte[bitpack.BytePos + 1];
172 Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);
173
174 return layer;
175 }
176
177 // Unused: left for historical reference.
178 public static void CreatePatch(BitPack output, float[] patchData, int x, int y, int pRegionSizeX, int pRegionSizeY)
179 {
180 TerrainPatch.Header header = PrescanPatch(patchData);
181 header.QuantWBits = 136;
182 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize)
183 {
184 header.PatchIDs = (y & 0xFFFF);
185 header.PatchIDs += (x << 16);
186 }
187 else
188 {
189 header.PatchIDs = (y & 0x1F);
190 header.PatchIDs += (x << 5);
191 }
192
193 // NOTE: No idea what prequant and postquant should be or what they do
194
195 int wbits;
196 int[] patch = CompressPatch(patchData, header, 10, out wbits);
197 wbits = EncodePatchHeader(output, header, patch, (uint)pRegionSizeX, (uint)pRegionSizeY, wbits);
198 EncodePatch(output, patch, 0, wbits);
199 }
200
201 /// <summary>
202 /// Add a patch of terrain to a BitPacker
203 /// </summary>
204 /// <param name="output">BitPacker to write the patch to</param>
205 /// <param name="heightmap">
206 /// Heightmap of the simulator. Presumed to be an sizeX*sizeY array.
207 /// </param>
208 /// <param name="patchX">
209 /// X offset of the patch to create.
210 /// </param>
211 /// <param name="patchY">
212 /// Y offset of the patch to create.
213 /// </param>
214 /// <param name="pRegionSizeX"></param>
215 /// <param name="pRegionSizeY"></param>
216 public static void CreatePatchFromHeightmap(BitPack output, TerrainData terrData, int patchX, int patchY)
217 {
218 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY);
219 header.QuantWBits = 136;
220
221 // If larger than legacy region size, pack patch X and Y info differently.
222 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
223 {
224 header.PatchIDs = (patchY & 0xFFFF);
225 header.PatchIDs += (patchX << 16);
226 }
227 else
228 {
229 header.PatchIDs = (patchY & 0x1F);
230 header.PatchIDs += (patchX << 5);
231 }
232
233 // m_log.DebugFormat("{0} CreatePatchFromHeightmap. patchX={1}, patchY={2}, DCOffset={3}, range={4}",
234 // LogHeader, patchX, patchY, header.DCOffset, header.Range);
235
236 // NOTE: No idea what prequant and postquant should be or what they do
237 int wbits;
238 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits);
239 wbits = EncodePatchHeader(output, header, patch, (uint)terrData.SizeX, (uint)terrData.SizeY, wbits);
240 EncodePatch(output, patch, 0, wbits);
241 }
242
243 private static TerrainPatch.Header PrescanPatch(float[] patch)
244 {
245 TerrainPatch.Header header = new TerrainPatch.Header();
246 float zmax = -99999999.0f;
247 float zmin = 99999999.0f;
248
249 for (int i = 0; i < Constants.TerrainPatchSize*Constants.TerrainPatchSize; i++)
250 {
251 float val = patch[i];
252 if (val > zmax) zmax = val;
253 if (val < zmin) zmin = val;
254 }
255
256 header.DCOffset = zmin;
257 header.Range = (int) ((zmax - zmin) + 1.0f);
258
259 return header;
260 }
261
262 // Scan the height info we're returning and return a patch packet header for this patch.
263 private static TerrainPatch.Header PrescanPatch(TerrainData terrData, int patchX, int patchY)
264 {
265 TerrainPatch.Header header = new TerrainPatch.Header();
266 float zmax = -99999999.0f;
267 float zmin = 99999999.0f;
268
269 for (int j = patchY*Constants.TerrainPatchSize; j < (patchY + 1)*Constants.TerrainPatchSize; j++)
270 {
271 for (int i = patchX*Constants.TerrainPatchSize; i < (patchX + 1)*Constants.TerrainPatchSize; i++)
272 {
273 float val = terrData[i, j];
274 if (val > zmax) zmax = val;
275 if (val < zmin) zmin = val;
276 }
277 }
278
279 header.DCOffset = zmin;
280 header.Range = (int)(zmax - zmin + 1.0f);
281
282 return header;
283 }
284
285 public static TerrainPatch.Header DecodePatchHeader(BitPack bitpack)
286 {
287 TerrainPatch.Header header = new TerrainPatch.Header {QuantWBits = bitpack.UnpackBits(8)};
288
289 // Quantized word bits
290 if (header.QuantWBits == END_OF_PATCHES)
291 return header;
292
293 // DC offset
294 header.DCOffset = bitpack.UnpackFloat();
295
296 // Range
297 header.Range = bitpack.UnpackBits(16);
298
299 // Patch IDs (10 bits)
300 header.PatchIDs = bitpack.UnpackBits(10);
301
302 // Word bits
303 header.WordBits = (uint) ((header.QuantWBits & 0x0f) + 2);
304
305 return header;
306 }
307
308 private static int EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, uint pRegionSizeX,
309 uint pRegionSizeY, int wbits)
310 {
311 /*
312 int temp;
313 int wbits = (header.QuantWBits & 0x0f) + 2;
314 uint maxWbits = (uint)wbits + 5;
315 uint minWbits = ((uint)wbits >> 1);
316 int wbitsMaxValue;
317 */
318 // goal is to determ minimum number of bits to use so all data fits
319 /*
320 wbits = (int)minWbits;
321 wbitsMaxValue = (1 << wbits);
322
323 for (int i = 0; i < patch.Length; i++)
324 {
325 temp = patch[i];
326 if (temp != 0)
327 {
328 // Get the absolute value
329 if (temp < 0) temp *= -1;
330
331 no coments..
332
333 for (int j = (int)maxWbits; j > (int)minWbits; j--)
334 {
335 if ((temp & (1 << j)) != 0)
336 {
337 if (j > wbits) wbits = j;
338 break;
339 }
340 }
341
342 while (temp > wbitsMaxValue)
343 {
344 wbits++;
345 if (wbits == maxWbits)
346 goto Done;
347 wbitsMaxValue = 1 << wbits;
348 }
349 }
350 }
351
352 Done:
353
354 // wbits += 1;
355 */
356 // better check
357 if (wbits > 17)
358 wbits = 16;
359 else if (wbits < 3)
360 wbits = 3;
361
362 header.QuantWBits &= 0xf0;
363
364 header.QuantWBits |= (wbits - 2);
365
366 output.PackBits(header.QuantWBits, 8);
367 output.PackFloat(header.DCOffset);
368 output.PackBits(header.Range, 16);
369 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize)
370 output.PackBits(header.PatchIDs, 32);
371 else
372 output.PackBits(header.PatchIDs, 10);
373
374 return wbits;
375 }
376
377 private static void IDCTColumn16(float[] linein, float[] lineout, int column)
378 {
379 for (int n = 0; n < Constants.TerrainPatchSize; n++)
380 {
381 float total = OO_SQRT2*linein[column];
382
383 for (int u = 1; u < Constants.TerrainPatchSize; u++)
384 {
385 int usize = u*Constants.TerrainPatchSize;
386 total += linein[usize + column]*CosineTable16[usize + n];
387 }
388
389 lineout[Constants.TerrainPatchSize*n + column] = total;
390 }
391 }
392
393 private static void IDCTLine16(float[] linein, float[] lineout, int line)
394 {
395 const float oosob = 2.0f/Constants.TerrainPatchSize;
396 int lineSize = line*Constants.TerrainPatchSize;
397
398 for (int n = 0; n < Constants.TerrainPatchSize; n++)
399 {
400 float total = OO_SQRT2*linein[lineSize];
401
402 for (int u = 1; u < Constants.TerrainPatchSize; u++)
403 {
404 total += linein[lineSize + u]*CosineTable16[u*Constants.TerrainPatchSize + n];
405 }
406
407 lineout[lineSize + n] = total*oosob;
408 }
409 }
410
411/*
412 private static void DCTLine16(float[] linein, float[] lineout, int line)
413 {
414 float total = 0.0f;
415 int lineSize = line * Constants.TerrainPatchSize;
416
417 for (int n = 0; n < Constants.TerrainPatchSize; n++)
418 {
419 total += linein[lineSize + n];
420 }
421
422 lineout[lineSize] = OO_SQRT2 * total;
423
424 int uptr = 0;
425 for (int u = 1; u < Constants.TerrainPatchSize; u++)
426 {
427 total = 0.0f;
428 uptr += Constants.TerrainPatchSize;
429
430 for (int n = 0; n < Constants.TerrainPatchSize; n++)
431 {
432 total += linein[lineSize + n] * CosineTable16[uptr + n];
433 }
434
435 lineout[lineSize + u] = total;
436 }
437 }
438*/
439
440 private static void DCTLine16(float[] linein, float[] lineout, int line)
441 {
442 // outputs transpose data (lines exchanged with coluns )
443 // so to save a bit of cpu when doing coluns
444 float total = 0.0f;
445 int lineSize = line*Constants.TerrainPatchSize;
446
447 for (int n = 0; n < Constants.TerrainPatchSize; n++)
448 {
449 total += linein[lineSize + n];
450 }
451
452 lineout[line] = OO_SQRT2*total;
453
454 for (int u = Constants.TerrainPatchSize;
455 u < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
456 u += Constants.TerrainPatchSize)
457 {
458 total = 0.0f;
459 for (int ptrn = lineSize, ptru = u; ptrn < lineSize + Constants.TerrainPatchSize; ptrn++,ptru++)
460 {
461 total += linein[ptrn]*CosineTable16[ptru];
462 }
463
464 lineout[line + u] = total;
465 }
466 }
467
468
469 /*
470 private static void DCTColumn16(float[] linein, int[] lineout, int column)
471 {
472 float total = 0.0f;
473 // const float oosob = 2.0f / Constants.TerrainPatchSize;
474
475 for (int n = 0; n < Constants.TerrainPatchSize; n++)
476 {
477 total += linein[Constants.TerrainPatchSize * n + column];
478 }
479
480 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
481 lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * QuantizeTable16[column]);
482
483 for (int uptr = Constants.TerrainPatchSize; uptr < Constants.TerrainPatchSize * Constants.TerrainPatchSize; uptr += Constants.TerrainPatchSize)
484 {
485 total = 0.0f;
486
487 for (int n = 0; n < Constants.TerrainPatchSize; n++)
488 {
489 total += linein[Constants.TerrainPatchSize * n + column] * CosineTable16[uptr + n];
490 }
491
492 // lineout[CopyMatrix16[Constants.TerrainPatchSize * u + column]] = (int)(total * oosob * QuantizeTable16[Constants.TerrainPatchSize * u + column]);
493 lineout[CopyMatrix16[uptr + column]] = (int)(total * QuantizeTable16[uptr + column]);
494 }
495 }
496 */
497
498 private static void DCTColumn16(float[] linein, int[] lineout, int column)
499 {
500 // input columns are in fact stored in lines now
501
502 float total = 0.0f;
503// const float oosob = 2.0f / Constants.TerrainPatchSize;
504 int inlinesptr = Constants.TerrainPatchSize*column;
505
506 for (int n = 0; n < Constants.TerrainPatchSize; n++)
507 {
508 total += linein[inlinesptr + n];
509 }
510
511 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
512 lineout[CopyMatrix16[column]] = (int) (OO_SQRT2*total*QuantizeTable16[column]);
513
514 for (int uptr = Constants.TerrainPatchSize;
515 uptr < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
516 uptr += Constants.TerrainPatchSize)
517 {
518 total = 0.0f;
519
520 for (int n = inlinesptr, ptru = uptr; n < inlinesptr + Constants.TerrainPatchSize; n++, ptru++)
521 {
522 total += linein[n]*CosineTable16[ptru];
523 }
524
525// lineout[CopyMatrix16[Constants.TerrainPatchSize * u + column]] = (int)(total * oosob * QuantizeTable16[Constants.TerrainPatchSize * u + column]);
526 lineout[CopyMatrix16[uptr + column]] = (int) (total*QuantizeTable16[uptr + column]);
527 }
528 }
529
530 private static int DCTColumn16Wbits(float[] linein, int[] lineout, int column, int wbits, int maxwbits)
531 {
532 // input columns are in fact stored in lines now
533
534 bool dowbits = wbits != maxwbits;
535 int wbitsMaxValue = 1 << wbits;
536
537 float total = 0.0f;
538 // const float oosob = 2.0f / Constants.TerrainPatchSize;
539 int inlinesptr = Constants.TerrainPatchSize*column;
540
541 for (int n = 0; n < Constants.TerrainPatchSize; n++)
542 {
543 total += linein[inlinesptr + n];
544 }
545
546 // lineout[CopyMatrix16[column]] = (int)(OO_SQRT2 * total * oosob * QuantizeTable16[column]);
547 int tmp = (int) (OO_SQRT2*total*QuantizeTable16[column]);
548 lineout[CopyMatrix16[column]] = tmp;
549
550 if (dowbits)
551 {
552 if (tmp < 0) tmp *= -1;
553 while (tmp > wbitsMaxValue)
554 {
555 wbits++;
556 wbitsMaxValue = 1 << wbits;
557 if (wbits == maxwbits)
558 {
559 dowbits = false;
560 break;
561 }
562 }
563 }
564
565 for (int uptr = Constants.TerrainPatchSize;
566 uptr < Constants.TerrainPatchSize*Constants.TerrainPatchSize;
567 uptr += Constants.TerrainPatchSize)
568 {
569 total = 0.0f;
570
571 for (int n = inlinesptr, ptru = uptr; n < inlinesptr + Constants.TerrainPatchSize; n++, ptru++)
572 {
573 total += linein[n]*CosineTable16[ptru];
574 }
575
576 tmp = (int) (total*QuantizeTable16[uptr + column]);
577 lineout[CopyMatrix16[uptr + column]] = tmp;
578
579 if (dowbits)
580 {
581 if (tmp < 0) tmp *= -1;
582 while (tmp > wbitsMaxValue)
583 {
584 wbits++;
585 wbitsMaxValue = 1 << wbits;
586 if (wbits == maxwbits)
587 {
588 dowbits = false;
589 break;
590 }
591 }
592 }
593 }
594 return wbits;
595 }
596
597 public static void DecodePatch(int[] patches, BitPack bitpack, TerrainPatch.Header header, int size)
598 {
599 for (int n = 0; n < size*size; n++)
600 {
601 // ?
602 int temp = bitpack.UnpackBits(1);
603 if (temp != 0)
604 {
605 // Value or EOB
606 temp = bitpack.UnpackBits(1);
607 if (temp != 0)
608 {
609 // Value
610 temp = bitpack.UnpackBits(1);
611 if (temp != 0)
612 {
613 // Negative
614 temp = bitpack.UnpackBits((int) header.WordBits);
615 patches[n] = temp*-1;
616 }
617 else
618 {
619 // Positive
620 temp = bitpack.UnpackBits((int) header.WordBits);
621 patches[n] = temp;
622 }
623 }
624 else
625 {
626 // Set the rest to zero
627 // TODO: This might not be necessary
628 for (int o = n; o < size*size; o++)
629 {
630 patches[o] = 0;
631 }
632 break;
633 }
634 }
635 else
636 {
637 patches[n] = 0;
638 }
639 }
640 }
641
642 private static void EncodePatch(BitPack output, int[] patch, int postquant, int wbits)
643 {
644 int maxwbitssize = (1 << wbits) - 1;
645
646 if (postquant > Constants.TerrainPatchSize*Constants.TerrainPatchSize || postquant < 0)
647 {
648 Logger.Log("Postquant is outside the range of allowed values in EncodePatch()", Helpers.LogLevel.Error);
649 return;
650 }
651
652 if (postquant != 0) patch[Constants.TerrainPatchSize*Constants.TerrainPatchSize - postquant] = 0;
653
654 for (int i = 0; i < Constants.TerrainPatchSize*Constants.TerrainPatchSize; i++)
655 {
656 int temp = patch[i];
657
658 if (temp == 0)
659 {
660 bool eob = true;
661
662 for (int j = i; j < Constants.TerrainPatchSize*Constants.TerrainPatchSize - postquant; j++)
663 {
664 if (patch[j] != 0)
665 {
666 eob = false;
667 break;
668 }
669 }
670
671 if (eob)
672 {
673 output.PackBits(ZERO_EOB, 2);
674 return;
675 }
676 output.PackBits(ZERO_CODE, 1);
677 }
678 else
679 {
680 if (temp < 0)
681 {
682 temp *= -1;
683
684 if (temp > maxwbitssize) temp = maxwbitssize;
685
686 output.PackBits(NEGATIVE_VALUE, 3);
687 output.PackBits(temp, wbits);
688 }
689 else
690 {
691 if (temp > maxwbitssize) temp = maxwbitssize;
692
693 output.PackBits(POSITIVE_VALUE, 3);
694 output.PackBits(temp, wbits);
695 }
696 }
697 }
698 }
699
700 public static float[] DecompressPatch(int[] patches, TerrainPatch.Header header, TerrainPatch.GroupHeader group)
701 {
702 float[] block = new float[group.PatchSize*group.PatchSize];
703 float[] output = new float[group.PatchSize*group.PatchSize];
704 int prequant = (header.QuantWBits >> 4) + 2;
705 int quantize = 1 << prequant;
706 float ooq = 1.0f/quantize;
707 float mult = ooq*header.Range;
708 float addval = mult*(1 << (prequant - 1)) + header.DCOffset;
709
710 if (group.PatchSize == Constants.TerrainPatchSize)
711 {
712 for (int n = 0; n < Constants.TerrainPatchSize*Constants.TerrainPatchSize; n++)
713 {
714 block[n] = patches[CopyMatrix16[n]]*DequantizeTable16[n];
715 }
716
717 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
718
719 for (int o = 0; o < Constants.TerrainPatchSize; o++)
720 IDCTColumn16(block, ftemp, o);
721 for (int o = 0; o < Constants.TerrainPatchSize; o++)
722 IDCTLine16(ftemp, block, o);
723 }
724 else
725 {
726 for (int n = 0; n < Constants.TerrainPatchSize*2*Constants.TerrainPatchSize*2; n++)
727 {
728 block[n] = patches[CopyMatrix32[n]]*DequantizeTable32[n];
729 }
730
731 Logger.Log("Implement IDCTPatchLarge", Helpers.LogLevel.Error);
732 }
733
734 for (int j = 0; j < block.Length; j++)
735 {
736 output[j] = block[j]*mult + addval;
737 }
738
739 return output;
740 }
741
742 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits)
743 {
744 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
745 int wordsize = (prequant - 2) & 0x0f;
746 float oozrange = 1.0f/header.Range;
747 float range = (1 << prequant);
748 float premult = oozrange*range;
749 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
750
751 header.QuantWBits = wordsize;
752 header.QuantWBits |= wordsize << 4;
753
754 int k = 0;
755 for (int j = 0; j < Constants.TerrainPatchSize; j++)
756 {
757 for (int i = 0; i < Constants.TerrainPatchSize; i++)
758 block[k++] = patchData[j*Constants.TerrainPatchSize + i]*premult - sub;
759 }
760
761 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
762 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
763
764
765 int maxWbits = prequant + 5;
766 wbits = (prequant >> 1);
767
768 for (int o = 0; o < Constants.TerrainPatchSize; o++)
769 DCTLine16(block, ftemp, o);
770 for (int o = 0; o < Constants.TerrainPatchSize; o++)
771 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
772
773 return itemp;
774 }
775
776 private static int[] CompressPatch(float[,] patchData, TerrainPatch.Header header, int prequant, out int wbits)
777 {
778 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
779 float oozrange = 1.0f/header.Range;
780 float range = (1 << prequant);
781 float premult = oozrange*range;
782 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
783 int wordsize = (prequant - 2) & 0x0f;
784
785 header.QuantWBits = wordsize;
786 header.QuantWBits |= wordsize << 4;
787
788 int k = 0;
789 for (int j = 0; j < Constants.TerrainPatchSize; j++)
790 {
791 for (int i = 0; i < Constants.TerrainPatchSize; i++)
792 block[k++] = patchData[j, i]*premult - sub;
793 }
794
795 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
796 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
797
798 int maxWbits = prequant + 5;
799 wbits = (prequant >> 1);
800
801 for (int o = 0; o < Constants.TerrainPatchSize; o++)
802 DCTLine16(block, ftemp, o);
803 for (int o = 0; o < Constants.TerrainPatchSize; o++)
804 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
805
806 return itemp;
807 }
808
809 private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header,
810 int prequant, out int wbits)
811 {
812 float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
813 int wordsize = prequant;
814 float oozrange = 1.0f/header.Range;
815 float range = (1 << prequant);
816 float premult = oozrange*range;
817 float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
818
819 header.QuantWBits = wordsize - 2;
820 header.QuantWBits |= (prequant - 2) << 4;
821
822 int k = 0;
823
824 int yPatchLimit = patchY >= (terrData.SizeY / Constants.TerrainPatchSize) ?
825 (terrData.SizeY - Constants.TerrainPatchSize) / Constants.TerrainPatchSize : patchY;
826 yPatchLimit = (yPatchLimit + 1) * Constants.TerrainPatchSize;
827
828 int xPatchLimit = patchX >= (terrData.SizeX / Constants.TerrainPatchSize) ?
829 (terrData.SizeX - Constants.TerrainPatchSize) / Constants.TerrainPatchSize : patchX;
830 xPatchLimit = (xPatchLimit + 1) * Constants.TerrainPatchSize;
831
832 for (int yy = patchY * Constants.TerrainPatchSize; yy < yPatchLimit; yy++)
833 {
834 for (int xx = patchX * Constants.TerrainPatchSize; xx < xPatchLimit; xx++)
835 {
836 block[k++] = terrData[xx, yy] * premult - sub;
837 }
838 }
839
840 float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
841 int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
842
843 int maxWbits = prequant + 5;
844 wbits = (prequant >> 1);
845
846 for (int o = 0; o < Constants.TerrainPatchSize; o++)
847 DCTLine16(block, ftemp, o);
848 for (int o = 0; o < Constants.TerrainPatchSize; o++)
849 wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
850
851 return itemp;
852 }
853
854 #region Initialization
855
856 private static void BuildDequantizeTable16()
857 {
858 for (int j = 0; j < Constants.TerrainPatchSize; j++)
859 {
860 for (int i = 0; i < Constants.TerrainPatchSize; i++)
861 {
862 DequantizeTable16[j*Constants.TerrainPatchSize + i] = 1.0f + 2.0f*(i + j);
863 }
864 }
865 }
866
867 private static void BuildQuantizeTable16()
868 {
869 const float oosob = 2.0f/Constants.TerrainPatchSize;
870 for (int j = 0; j < Constants.TerrainPatchSize; j++)
871 {
872 for (int i = 0; i < Constants.TerrainPatchSize; i++)
873 {
874// QuantizeTable16[j * Constants.TerrainPatchSize + i] = 1.0f / (1.0f + 2.0f * ((float)i + (float)j));
875 QuantizeTable16[j*Constants.TerrainPatchSize + i] = oosob/(1.0f + 2.0f*(i + (float) j));
876 }
877 }
878 }
879
880 private static void SetupCosines16()
881 {
882 const float hposz = (float) Math.PI*0.5f/Constants.TerrainPatchSize;
883
884 for (int u = 0; u < Constants.TerrainPatchSize; u++)
885 {
886 for (int n = 0; n < Constants.TerrainPatchSize; n++)
887 {
888 CosineTable16[u*Constants.TerrainPatchSize + n] = (float) Math.Cos((2.0f*n + 1.0f)*u*hposz);
889 }
890 }
891 }
892
893 private static void BuildCopyMatrix16()
894 {
895 bool diag = false;
896 bool right = true;
897 int i = 0;
898 int j = 0;
899 int count = 0;
900
901 while (i < Constants.TerrainPatchSize && j < Constants.TerrainPatchSize)
902 {
903 CopyMatrix16[j*Constants.TerrainPatchSize + i] = count++;
904
905 if (!diag)
906 {
907 if (right)
908 {
909 if (i < Constants.TerrainPatchSize - 1) i++;
910 else j++;
911
912 right = false;
913 diag = true;
914 }
915 else
916 {
917 if (j < Constants.TerrainPatchSize - 1) j++;
918 else i++;
919
920 right = true;
921 diag = true;
922 }
923 }
924 else
925 {
926 if (right)
927 {
928 i++;
929 j--;
930 if (i == Constants.TerrainPatchSize - 1 || j == 0) diag = false;
931 }
932 else
933 {
934 i--;
935 j++;
936 if (j == Constants.TerrainPatchSize - 1 || i == 0) diag = false;
937 }
938 }
939 }
940 }
941
942 #endregion Initialization
943 }
944}
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
index b3fdd22..c8320d0 100644
--- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
+++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
@@ -516,7 +516,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
516 516
517 public Vector3 StartPos 517 public Vector3 StartPos
518 { 518 {
519 get { return new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 50); } 519 get { return new Vector3(m_scene.RegionInfo.RegionSizeX * 0.5f, m_scene.RegionInfo.RegionSizeY * 0.5f, 50f); }
520 set { } 520 set { }
521 } 521 }
522 522
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
index c5cba8e..f5bd44d 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
@@ -52,6 +52,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
52 52
53 // Local constants 53 // Local constants
54 54
55 // This computation is not the real region center if the region is larger than 256.
56 // This computation isn't fixed because there is not a handle back to the region.
55 private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); 57 private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20);
56 private static readonly char[] CS_SPACE = { ' ' }; 58 private static readonly char[] CS_SPACE = { ' ' };
57 59
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
index d4fe5e0..5505001 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
@@ -44,6 +44,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
44 private static readonly ILog m_log = 44 private static readonly ILog m_log =
45 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 // This computation is not the real region center if the region is larger than 256.
48 // This computation isn't fixed because there is not a handle back to the region.
47 private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); 49 private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20);
48 private const int DEBUG_CHANNEL = 2147483647; 50 private const int DEBUG_CHANNEL = 2147483647;
49 51
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
index eb386fe..296ab87 100644
--- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
@@ -170,7 +170,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
170 c.Channel = m_channelNotify; 170 c.Channel = m_channelNotify;
171 c.Message += numScriptsFailed.ToString() + "," + message; 171 c.Message += numScriptsFailed.ToString() + "," + message;
172 c.Type = ChatTypeEnum.Region; 172 c.Type = ChatTypeEnum.Region;
173 c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30); 173 if (m_scene != null)
174 c.Position = new Vector3((m_scene.RegionInfo.RegionSizeX * 0.5f), (m_scene.RegionInfo.RegionSizeY * 0.5f), 30);
175 else
176 c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
174 c.Sender = null; 177 c.Sender = null;
175 c.SenderUUID = UUID.Zero; 178 c.SenderUUID = UUID.Zero;
176 c.Scene = m_scene; 179 c.Scene = m_scene;
diff --git a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
index 8144870..e4a3382 100644
--- a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
+++ b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
@@ -748,8 +748,8 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
748 position.X = s_tree.AbsolutePosition.X + (float)randX; 748 position.X = s_tree.AbsolutePosition.X + (float)randX;
749 position.Y = s_tree.AbsolutePosition.Y + (float)randY; 749 position.Y = s_tree.AbsolutePosition.Y + (float)randY;
750 750
751 if (position.X <= ((int)Constants.RegionSize - 1) && position.X >= 0 && 751 if (position.X <= (m_scene.RegionInfo.RegionSizeX - 1) && position.X >= 0 &&
752 position.Y <= ((int)Constants.RegionSize - 1) && position.Y >= 0 && 752 position.Y <= (m_scene.RegionInfo.RegionSizeY - 1) && position.Y >= 0 &&
753 Util.GetDistanceTo(position, copse.m_seed_point) <= copse.m_range) 753 Util.GetDistanceTo(position, copse.m_seed_point) <= copse.m_range)
754 { 754 {
755 UUID uuid = m_scene.RegionInfo.EstateSettings.EstateOwner; 755 UUID uuid = m_scene.RegionInfo.EstateSettings.EstateOwner;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index 17ebed2..aca1ed4 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -1311,7 +1311,7 @@ private sealed class BulletConstraintXNA : BulletConstraint
1311 /* TODO */ 1311 /* TODO */
1312 ConfigurationParameters[] configparms = new ConfigurationParameters[1]; 1312 ConfigurationParameters[] configparms = new ConfigurationParameters[1];
1313 configparms[0] = parms; 1313 configparms[0] = parms;
1314 Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); 1314 Vector3 worldExtent = maxPosition;
1315 m_maxCollisions = maxCollisions; 1315 m_maxCollisions = maxCollisions;
1316 m_maxUpdatesPerFrame = maxUpdates; 1316 m_maxUpdatesPerFrame = maxUpdates;
1317 specialCollisionObjects = new Dictionary<uint, GhostObject>(); 1317 specialCollisionObjects = new Dictionary<uint, GhostObject>();
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 15b7090..edec949 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -376,18 +376,19 @@ public class BSPrim : BSPhysObject
376 { 376 {
377 bool ret = false; 377 bool ret = false;
378 378
379 uint wayOutThere = Constants.RegionSize * Constants.RegionSize; 379 int wayOverThere = -1000;
380 int wayOutThere = 10000;
380 // There have been instances of objects getting thrown way out of bounds and crashing 381 // There have been instances of objects getting thrown way out of bounds and crashing
381 // the border crossing code. 382 // the border crossing code.
382 if ( RawPosition.X < -Constants.RegionSize || RawPosition.X > wayOutThere 383 if ( RawPosition.X < wayOverThere || RawPosition.X > wayOutThere
383 || RawPosition.Y < -Constants.RegionSize || RawPosition.Y > wayOutThere 384 || RawPosition.Y < wayOverThere || RawPosition.X > wayOutThere
384 || RawPosition.Z < -Constants.RegionSize || RawPosition.Z > wayOutThere) 385 || RawPosition.Z < wayOverThere || RawPosition.X > wayOutThere)
385 { 386 {
386 RawPosition = new OMV.Vector3(10, 10, 50); 387 RawPosition = new OMV.Vector3(10, 10, 50);
387 ZeroMotion(inTaintTime); 388 ZeroMotion(inTaintTime);
388 ret = true; 389 ret = true;
389 } 390 }
390 if (RawVelocity.LengthSquared() > BSParam.MaxLinearVelocity) 391 if (RawVelocity.LengthSquared() > BSParam.MaxLinearVelocitySquared)
391 { 392 {
392 RawVelocity = Util.ClampV(RawVelocity, BSParam.MaxLinearVelocity); 393 RawVelocity = Util.ClampV(RawVelocity, BSParam.MaxLinearVelocity);
393 ret = true; 394 ret = true;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index b3dfa41..fe014fc 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -208,8 +208,17 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
208 Name = EngineType + "/" + RegionName; 208 Name = EngineType + "/" + RegionName;
209 } 209 }
210 210
211 // Old version of initialization that assumes legacy sized regions (256x256)
211 public override void Initialise(IMesher meshmerizer, IConfigSource config) 212 public override void Initialise(IMesher meshmerizer, IConfigSource config)
212 { 213 {
214 m_log.ErrorFormat("{0} WARNING WARNING WARNING! BulletSim initialized without region extent specification. Terrain will be messed up.");
215 Vector3 regionExtent = new Vector3( Constants.RegionSize, Constants.RegionSize, Constants.RegionSize);
216 Initialise(meshmerizer, config, regionExtent);
217
218 }
219
220 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
221 {
213 mesher = meshmerizer; 222 mesher = meshmerizer;
214 _taintOperations = new List<TaintCallbackEntry>(); 223 _taintOperations = new List<TaintCallbackEntry>();
215 _postTaintOperations = new Dictionary<string, TaintCallbackEntry>(); 224 _postTaintOperations = new Dictionary<string, TaintCallbackEntry>();
@@ -250,13 +259,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
250 // a child in a mega-region. 259 // a child in a mega-region.
251 // Bullet actually doesn't care about the extents of the simulated 260 // Bullet actually doesn't care about the extents of the simulated
252 // area. It tracks active objects no matter where they are. 261 // area. It tracks active objects no matter where they are.
253 Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); 262 Vector3 worldExtent = regionExtent;
254 263
255 World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray); 264 World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray);
256 265
257 Constraints = new BSConstraintCollection(World); 266 Constraints = new BSConstraintCollection(World);
258 267
259 TerrainManager = new BSTerrainManager(this); 268 TerrainManager = new BSTerrainManager(this, worldExtent);
260 TerrainManager.CreateInitialGroundPlaneAndTerrain(); 269 TerrainManager.CreateInitialGroundPlaneAndTerrain();
261 270
262 // Put some informational messages into the log file. 271 // Put some informational messages into the log file.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index 8888d6d..d70b2fb 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
58 { 58 {
59 initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; 59 initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
60 } 60 }
61 m_mapInfo = new BulletHMapInfo(id, initialMap); 61 m_mapInfo = new BulletHMapInfo(id, initialMap, regionSize.X, regionSize.Y);
62 m_mapInfo.minCoords = minTerrainCoords; 62 m_mapInfo.minCoords = minTerrainCoords;
63 m_mapInfo.maxCoords = maxTerrainCoords; 63 m_mapInfo.maxCoords = maxTerrainCoords;
64 m_mapInfo.terrainRegionBase = TerrainBase; 64 m_mapInfo.terrainRegionBase = TerrainBase;
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
72 Vector3 minCoords, Vector3 maxCoords) 72 Vector3 minCoords, Vector3 maxCoords)
73 : base(physicsScene, regionBase, id) 73 : base(physicsScene, regionBase, id)
74 { 74 {
75 m_mapInfo = new BulletHMapInfo(id, initialMap); 75 m_mapInfo = new BulletHMapInfo(id, initialMap, maxCoords.X - minCoords.X, maxCoords.Y - minCoords.Y);
76 m_mapInfo.minCoords = minCoords; 76 m_mapInfo.minCoords = minCoords;
77 m_mapInfo.maxCoords = maxCoords; 77 m_mapInfo.maxCoords = maxCoords;
78 m_mapInfo.minZ = minCoords.Z; 78 m_mapInfo.minZ = minCoords.Z;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index 441d2d3..3013077 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -111,9 +111,11 @@ public sealed class BSTerrainManager : IDisposable
111 private Vector3 m_worldMax; 111 private Vector3 m_worldMax;
112 private PhysicsScene MegaRegionParentPhysicsScene { get; set; } 112 private PhysicsScene MegaRegionParentPhysicsScene { get; set; }
113 113
114 public BSTerrainManager(BSScene physicsScene) 114 public BSTerrainManager(BSScene physicsScene, Vector3 regionSize)
115 { 115 {
116 m_physicsScene = physicsScene; 116 m_physicsScene = physicsScene;
117 DefaultRegionSize = regionSize;
118
117 m_terrains = new Dictionary<Vector3,BSTerrainPhys>(); 119 m_terrains = new Dictionary<Vector3,BSTerrainPhys>();
118 120
119 // Assume one region of default size 121 // Assume one region of default size
@@ -268,7 +270,7 @@ public sealed class BSTerrainManager : IDisposable
268 { 270 {
269 // There is already a terrain in this spot. Free the old and build the new. 271 // There is already a terrain in this spot. Free the old and build the new.
270 DetailLog("{0},BSTErrainManager.UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}", 272 DetailLog("{0},BSTErrainManager.UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}",
271 BSScene.DetailLogZero, id, terrainRegionBase, minCoords, minCoords); 273 BSScene.DetailLogZero, id, terrainRegionBase, minCoords, maxCoords);
272 274
273 // Remove old terrain from the collection 275 // Remove old terrain from the collection
274 m_terrains.Remove(terrainRegionBase); 276 m_terrains.Remove(terrainRegionBase);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 971ff9f..3425d9e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -165,14 +165,15 @@ public class BulletConstraint
165// than making copies. 165// than making copies.
166public class BulletHMapInfo 166public class BulletHMapInfo
167{ 167{
168 public BulletHMapInfo(uint id, float[] hm) { 168 public BulletHMapInfo(uint id, float[] hm, float pSizeX, float pSizeY) {
169 ID = id; 169 ID = id;
170 heightMap = hm; 170 heightMap = hm;
171 terrainRegionBase = OMV.Vector3.Zero; 171 terrainRegionBase = OMV.Vector3.Zero;
172 minCoords = new OMV.Vector3(100f, 100f, 25f); 172 minCoords = new OMV.Vector3(100f, 100f, 25f);
173 maxCoords = new OMV.Vector3(101f, 101f, 26f); 173 maxCoords = new OMV.Vector3(101f, 101f, 26f);
174 minZ = maxZ = 0f; 174 minZ = maxZ = 0f;
175 sizeX = sizeY = 256f; 175 sizeX = pSizeX;
176 sizeY = pSizeY;
176 } 177 }
177 public uint ID; 178 public uint ID;
178 public float[] heightMap; 179 public float[] heightMap;
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index 8ccfda5..9b06353 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -32,6 +32,7 @@ using System.Reflection;
32using Nini.Config; 32using Nini.Config;
33using log4net; 33using log4net;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenMetaverse;
35 36
36namespace OpenSim.Region.Physics.Manager 37namespace OpenSim.Region.Physics.Manager
37{ 38{
@@ -66,7 +67,8 @@ namespace OpenSim.Region.Physics.Manager
66 /// <param name="meshEngineName"></param> 67 /// <param name="meshEngineName"></param>
67 /// <param name="config"></param> 68 /// <param name="config"></param>
68 /// <returns></returns> 69 /// <returns></returns>
69 public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName, IConfigSource config, string regionName) 70 public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName,
71 IConfigSource config, string regionName, Vector3 regionExtent)
70 { 72 {
71 if (String.IsNullOrEmpty(physEngineName)) 73 if (String.IsNullOrEmpty(physEngineName))
72 { 74 {
@@ -94,7 +96,7 @@ namespace OpenSim.Region.Physics.Manager
94 { 96 {
95 m_log.Info("[PHYSICS]: creating " + physEngineName); 97 m_log.Info("[PHYSICS]: creating " + physEngineName);
96 PhysicsScene result = _PhysPlugins[physEngineName].GetScene(regionName); 98 PhysicsScene result = _PhysPlugins[physEngineName].GetScene(regionName);
97 result.Initialise(meshEngine, config); 99 result.Initialise(meshEngine, config, regionExtent);
98 return result; 100 return result;
99 } 101 }
100 else 102 else
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index c93206d..71ad795 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -126,8 +126,17 @@ namespace OpenSim.Region.Physics.Manager
126 } 126 }
127 } 127 }
128 128
129 // Deprecated. Do not use this for new physics engines.
129 public abstract void Initialise(IMesher meshmerizer, IConfigSource config); 130 public abstract void Initialise(IMesher meshmerizer, IConfigSource config);
130 131
132 // For older physics engines that do not implement non-legacy region sizes.
133 // If the physics engine handles the region extent feature, it overrides this function.
134 public virtual void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
135 {
136 // If not overridden, call the old initialization entry.
137 Initialise(meshmerizer, config);
138 }
139
131 /// <summary> 140 /// <summary>
132 /// Add an avatar 141 /// Add an avatar
133 /// </summary> 142 /// </summary>
diff --git a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
index fba51d2..62a3a91 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
@@ -64,12 +64,12 @@ namespace OpenSim.Region.RegionCombinerModule
64 /// <summary> 64 /// <summary>
65 /// The X meters position of this connection. 65 /// The X meters position of this connection.
66 /// </summary> 66 /// </summary>
67 public uint PosX { get { return X * Constants.RegionSize; } } 67 public uint PosX { get { return Util.RegionToWorldLoc(X); } }
68 68
69 /// <summary> 69 /// <summary>
70 /// The Y meters co-ordinate of this connection. 70 /// The Y meters co-ordinate of this connection.
71 /// </summary> 71 /// </summary>
72 public uint PosY { get { return Y * Constants.RegionSize; } } 72 public uint PosY { get { return Util.RegionToWorldLoc(Y); } }
73 73
74 /// <summary> 74 /// <summary>
75 /// The size of the megaregion in meters. 75 /// The size of the megaregion in meters.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index e54b697..7b56abf 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2107,7 +2107,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2107 // 2107 //
2108 // This workaround is to prevent silent failure of this function. 2108 // This workaround is to prevent silent failure of this function.
2109 // According to the specification on the SL Wiki, providing a position outside of the 2109 // According to the specification on the SL Wiki, providing a position outside of the
2110 if (pos.x < 0 || pos.x > Constants.RegionSize || pos.y < 0 || pos.y > Constants.RegionSize) 2110 if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
2111 { 2111 {
2112 return 0; 2112 return 0;
2113 } 2113 }
@@ -2117,9 +2117,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2117 m_host.ParentGroup.IsAttachment || // return FALSE if attachment 2117 m_host.ParentGroup.IsAttachment || // return FALSE if attachment
2118 ( 2118 (
2119 pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region. 2119 pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
2120 pos.x > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a east-adjacent region. 2120 pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
2121 pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region. 2121 pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
2122 pos.y > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a north-adjacent region. 2122 pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
2123 pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m 2123 pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
2124 ) 2124 )
2125 ) 2125 )
@@ -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.WorldLocX, World.RegionInfo.WorldLocY, 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)
@@ -4336,7 +4333,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4336 m_host.AddScriptLPS(1); 4333 m_host.AddScriptLPS(1);
4337 UUID agentId = new UUID(); 4334 UUID agentId = new UUID();
4338 4335
4339 ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y); 4336 ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
4340 4337
4341 if (UUID.TryParse(agent, out agentId)) 4338 if (UUID.TryParse(agent, out agentId))
4342 { 4339 {
@@ -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.WorldLocX, World.RegionInfo.WorldLocY, 0);
5485 } 5482 }
5486 5483
5487 /// <summary> 5484 /// <summary>
@@ -5628,7 +5625,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5628 LSL_Float mag; 5625 LSL_Float mag;
5629 if (dir.x > 0) 5626 if (dir.x > 0)
5630 { 5627 {
5631 mag = (Constants.RegionSize - pos.x) / dir.x; 5628 mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
5632 } 5629 }
5633 else 5630 else
5634 { 5631 {
@@ -5639,7 +5636,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5639 5636
5640 edge.y = pos.y + (dir.y * mag); 5637 edge.y = pos.y + (dir.y * mag);
5641 5638
5642 if (edge.y > Constants.RegionSize || edge.y < 0) 5639 if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
5643 { 5640 {
5644 // Y goes out of bounds first 5641 // Y goes out of bounds first
5645 edge.y = dir.y / Math.Abs(dir.y); 5642 edge.y = dir.y / Math.Abs(dir.y);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 15fbbfd..73174b4 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -450,7 +450,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
450 { 450 {
451 m_host.AddScriptLPS(1); 451 m_host.AddScriptLPS(1);
452 452
453 if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0) 453 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
454 OSSLError("osSetTerrainHeight: Coordinate out of bounds"); 454 OSSLError("osSetTerrainHeight: Coordinate out of bounds");
455 455
456 if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0))) 456 if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
@@ -480,7 +480,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
480 private LSL_Float GetTerrainHeight(int x, int y) 480 private LSL_Float GetTerrainHeight(int x, int y)
481 { 481 {
482 m_host.AddScriptLPS(1); 482 m_host.AddScriptLPS(1);
483 if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0) 483 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
484 OSSLError("osGetTerrainHeight: Coordinate out of bounds"); 484 OSSLError("osGetTerrainHeight: Coordinate out of bounds");
485 485
486 return World.Heightmap[x, y]; 486 return World.Heightmap[x, y];
@@ -814,7 +814,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
814 private void TeleportAgent(string agent, int regionX, int regionY, 814 private void TeleportAgent(string agent, int regionX, int regionY,
815 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 815 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
816 { 816 {
817 ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); 817 // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
818 ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
818 819
819 m_host.AddScriptLPS(1); 820 m_host.AddScriptLPS(1);
820 UUID agentId = new UUID(); 821 UUID agentId = new UUID();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 02a3541..9c060e5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -713,16 +713,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
713 } 713 }
714 private void Save() 714 private void Save()
715 { 715 {
716 /* Remove temporarily until we have a handle to the region size
716 if (Position.x > ((int)Constants.RegionSize - 1)) 717 if (Position.x > ((int)Constants.RegionSize - 1))
717 Position.x = ((int)Constants.RegionSize - 1); 718 Position.x = ((int)Constants.RegionSize - 1);
718 if (Position.x < 0)
719 Position.x = 0;
720 if (Position.y > ((int)Constants.RegionSize - 1)) 719 if (Position.y > ((int)Constants.RegionSize - 1))
721 Position.y = ((int)Constants.RegionSize - 1); 720 Position.y = ((int)Constants.RegionSize - 1);
721 */
722 if (Position.z > Constants.RegionHeight)
723 Position.z = Constants.RegionHeight;
724 if (Position.x < 0)
725 Position.x = 0;
722 if (Position.y < 0) 726 if (Position.y < 0)
723 Position.y = 0; 727 Position.y = 0;
724 if (Position.z > 768)
725 Position.z = 768;
726 if (Position.z < 0) 728 if (Position.z < 0)
727 Position.z = 0; 729 Position.z = 0;
728 prim.OSSL.llSetPos(Position); 730 prim.OSSL.llSetPos(Position);
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
index c63b409..16d9b7d 100644
--- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Server.Handlers.Grid
48 public class GridServerPostHandler : BaseStreamHandler 48 public class GridServerPostHandler : BaseStreamHandler
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 = "[GRID HANDLER]";
51 52
52 private IGridService m_GridService; 53 private IGridService m_GridService;
53 54
@@ -281,8 +282,8 @@ namespace OpenSim.Server.Handlers.Grid
281 else 282 else
282 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); 283 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
283 284
285 // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y);
284 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); 286 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
285 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
286 287
287 Dictionary<string, object> result = new Dictionary<string, object>(); 288 Dictionary<string, object> result = new Dictionary<string, object>();
288 if (rinfo == null) 289 if (rinfo == null)
diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
index 5d03097..f25e6e0 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -105,6 +105,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
105 hash["uuid"] = regInfo.RegionID.ToString(); 105 hash["uuid"] = regInfo.RegionID.ToString();
106 hash["x"] = regInfo.RegionLocX.ToString(); 106 hash["x"] = regInfo.RegionLocX.ToString();
107 hash["y"] = regInfo.RegionLocY.ToString(); 107 hash["y"] = regInfo.RegionLocY.ToString();
108 hash["size_x"] = regInfo.RegionSizeX.ToString();
109 hash["size_y"] = regInfo.RegionSizeY.ToString();
108 hash["region_name"] = regInfo.RegionName; 110 hash["region_name"] = regInfo.RegionName;
109 hash["hostname"] = regInfo.ExternalHostName; 111 hash["hostname"] = regInfo.ExternalHostName;
110 hash["http_port"] = regInfo.HttpPort.ToString(); 112 hash["http_port"] = regInfo.HttpPort.ToString();
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
index 7137836..15b5b31 100644
--- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
@@ -132,6 +132,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
132 hash["uuid"] = regInfo.RegionID.ToString(); 132 hash["uuid"] = regInfo.RegionID.ToString();
133 hash["x"] = regInfo.RegionLocX.ToString(); 133 hash["x"] = regInfo.RegionLocX.ToString();
134 hash["y"] = regInfo.RegionLocY.ToString(); 134 hash["y"] = regInfo.RegionLocY.ToString();
135 hash["size_x"] = regInfo.RegionSizeX.ToString();
136 hash["size_y"] = regInfo.RegionSizeY.ToString();
135 hash["region_name"] = regInfo.RegionName; 137 hash["region_name"] = regInfo.RegionName;
136 hash["hostname"] = regInfo.ExternalHostName; 138 hash["hostname"] = regInfo.ExternalHostName;
137 hash["http_port"] = regInfo.HttpPort.ToString(); 139 hash["http_port"] = regInfo.HttpPort.ToString();
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
index d438fc7..4d1729e 100644
--- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
@@ -116,9 +116,9 @@ namespace OpenSim.Server.Handlers.MapImage
116 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; 116 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest;
117 return FailureResult("Bad request."); 117 return FailureResult("Bad request.");
118 } 118 }
119 int x = 0, y = 0; 119 uint x = 0, y = 0;
120 Int32.TryParse(request["X"].ToString(), out x); 120 UInt32.TryParse(request["X"].ToString(), out x);
121 Int32.TryParse(request["Y"].ToString(), out y); 121 UInt32.TryParse(request["Y"].ToString(), out y);
122 122
123 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); 123 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y);
124 124
@@ -130,7 +130,7 @@ namespace OpenSim.Server.Handlers.MapImage
130 if (m_GridService != null) 130 if (m_GridService != null)
131 { 131 {
132 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); 132 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
133 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize); 133 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y));
134 if (r != null) 134 if (r != null)
135 { 135 {
136 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) 136 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString())
@@ -151,7 +151,7 @@ namespace OpenSim.Server.Handlers.MapImage
151 byte[] data = Convert.FromBase64String(request["DATA"].ToString()); 151 byte[] data = Convert.FromBase64String(request["DATA"].ToString());
152 152
153 string reason = string.Empty; 153 string reason = string.Empty;
154 bool result = m_MapService.AddMapTile(x, y, data, out reason); 154 bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason);
155 155
156 if (result) 156 if (result)
157 return SuccessResult(); 157 return SuccessResult();
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index c9c6c31..5d7dcfd 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -255,6 +255,18 @@ namespace OpenSim.Services.Connectors.Hypergrid
255 region.RegionLocY = n; 255 region.RegionLocY = n;
256 //m_log.Debug(">> HERE, y: " + region.RegionLocY); 256 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
257 } 257 }
258 if (hash["size_x"] != null)
259 {
260 Int32.TryParse((string)hash["size_x"], out n);
261 region.RegionSizeX = n;
262 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
263 }
264 if (hash["size_y"] != null)
265 {
266 Int32.TryParse((string)hash["size_y"], out n);
267 region.RegionSizeY = n;
268 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
269 }
258 if (hash["region_name"] != null) 270 if (hash["region_name"] != null)
259 { 271 {
260 region.RegionName = (string)hash["region_name"]; 272 region.RegionName = (string)hash["region_name"];
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index 2511c08..d0a0b17 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -242,6 +242,18 @@ namespace OpenSim.Services.Connectors.Hypergrid
242 region.RegionLocY = n; 242 region.RegionLocY = n;
243 //m_log.Debug(">> HERE, y: " + region.RegionLocY); 243 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
244 } 244 }
245 if (hash["size_x"] != null)
246 {
247 Int32.TryParse((string)hash["x"], out n);
248 region.RegionSizeX = n;
249 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
250 }
251 if (hash["size_y"] != null)
252 {
253 Int32.TryParse((string)hash["y"], out n);
254 region.RegionSizeY = n;
255 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
256 }
245 if (hash["region_name"] != null) 257 if (hash["region_name"] != null)
246 { 258 {
247 region.RegionName = (string)hash["region_name"]; 259 region.RegionName = (string)hash["region_name"];
diff --git a/OpenSim/Services/Connectors/Land/LandServicesConnector.cs b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
index 30a73a4..644331a 100644
--- a/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
@@ -78,7 +78,7 @@ namespace OpenSim.Services.Connectors
78 try 78 try
79 { 79 {
80 uint xpos = 0, ypos = 0; 80 uint xpos = 0, ypos = 0;
81 Utils.LongToUInts(regionHandle, out xpos, out ypos); 81 Util.RegionHandleToWorldLoc(regionHandle, out xpos, out ypos);
82 GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos); 82 GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos);
83 if (info != null) // just to be sure 83 if (info != null) // just to be sure
84 { 84 {
diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
index 774fe2a..beead97 100644
--- a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
@@ -69,7 +69,7 @@ namespace OpenSim.Services.Connectors
69 public virtual GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) 69 public virtual GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
70 { 70 {
71 uint x = 0, y = 0; 71 uint x = 0, y = 0;
72 Utils.LongToUInts(regionHandle, out x, out y); 72 Util.RegionHandleToWorldLoc(regionHandle, out x, out y);
73 GridRegion regInfo = m_GridService.GetRegionByPosition(thisRegion.ScopeID, (int)x, (int)y); 73 GridRegion regInfo = m_GridService.GetRegionByPosition(thisRegion.ScopeID, (int)x, (int)y);
74 if ((regInfo != null) && 74 if ((regInfo != null) &&
75 // Don't remote-call this instance; that's a startup hickup 75 // Don't remote-call this instance; that's a startup hickup
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
index c928f16..6b59f94 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
@@ -101,7 +101,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
101 public string RegisterRegion(UUID scopeID, GridRegion regionInfo) 101 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
102 { 102 {
103 Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0); 103 Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0);
104 Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); 104 Vector3d maxPosition = minPosition + new Vector3d(regionInfo.RegionSizeX, regionInfo.RegionSizeY, Constants.RegionHeight);
105 105
106 OSDMap extraData = new OSDMap 106 OSDMap extraData = new OSDMap
107 { 107 {
@@ -156,15 +156,15 @@ namespace OpenSim.Services.Connectors.SimianGrid
156 156
157 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) 157 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
158 { 158 {
159 const int NEIGHBOR_RADIUS = 128;
160
161 GridRegion region = GetRegionByUUID(scopeID, regionID); 159 GridRegion region = GetRegionByUUID(scopeID, regionID);
162 160
161 int NEIGHBOR_RADIUS = Math.Max(region.RegionSizeX, region.RegionSizeY) / 2;
162
163 if (region != null) 163 if (region != null)
164 { 164 {
165 List<GridRegion> regions = GetRegionRange(scopeID, 165 List<GridRegion> regions = GetRegionRange(scopeID,
166 region.RegionLocX - NEIGHBOR_RADIUS, region.RegionLocX + (int)Constants.RegionSize + NEIGHBOR_RADIUS, 166 region.RegionLocX - NEIGHBOR_RADIUS, region.RegionLocX + region.RegionSizeX + NEIGHBOR_RADIUS,
167 region.RegionLocY - NEIGHBOR_RADIUS, region.RegionLocY + (int)Constants.RegionSize + NEIGHBOR_RADIUS); 167 region.RegionLocY - NEIGHBOR_RADIUS, region.RegionLocY + region.RegionSizeY + NEIGHBOR_RADIUS);
168 168
169 for (int i = 0; i < regions.Count; i++) 169 for (int i = 0; i < regions.Count; i++)
170 { 170 {
@@ -229,7 +229,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
229 else 229 else
230 { 230 {
231 // m_log.InfoFormat("[SIMIAN GRID CONNECTOR]: Grid service did not find a match for region at {0},{1}", 231 // m_log.InfoFormat("[SIMIAN GRID CONNECTOR]: Grid service did not find a match for region at {0},{1}",
232 // x / Constants.RegionSize, y / Constants.RegionSize); 232 // Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y));
233 return null; 233 return null;
234 } 234 }
235 } 235 }
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs b/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs
index 504fcaf..2cbf967 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs
@@ -100,6 +100,11 @@ namespace OpenSim.Services.Connectors
100 return m_database.LoadObjects(regionUUID); 100 return m_database.LoadObjects(regionUUID);
101 } 101 }
102 102
103 public void StoreTerrain(TerrainData terrain, UUID regionID)
104 {
105 m_database.StoreTerrain(terrain, regionID);
106 }
107
103 public void StoreTerrain(double[,] terrain, UUID regionID) 108 public void StoreTerrain(double[,] terrain, UUID regionID)
104 { 109 {
105 m_database.StoreTerrain(terrain, regionID); 110 m_database.StoreTerrain(terrain, regionID);
@@ -110,6 +115,11 @@ namespace OpenSim.Services.Connectors
110 return m_database.LoadTerrain(regionID); 115 return m_database.LoadTerrain(regionID);
111 } 116 }
112 117
118 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
119 {
120 return m_database.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ);
121 }
122
113 public void StoreLandObject(ILandObject Parcel) 123 public void StoreLandObject(ILandObject Parcel)
114 { 124 {
115 m_database.StoreLandObject(Parcel); 125 m_database.StoreLandObject(Parcel);
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 137ce04..8198592 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -313,6 +313,7 @@ namespace OpenSim.Services.GridService
313 if (region != null) 313 if (region != null)
314 { 314 {
315 // Not really? Maybe? 315 // Not really? Maybe?
316 // The adjacent regions are presumed to be the same size as the current region
316 List<RegionData> rdatas = m_Database.Get( 317 List<RegionData> rdatas = m_Database.Get(
317 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1, 318 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1,
318 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID); 319 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID);
@@ -643,20 +644,20 @@ namespace OpenSim.Services.GridService
643 return; 644 return;
644 } 645 }
645 646
646 int x, y; 647 uint x, y;
647 if (!int.TryParse(cmd[3], out x)) 648 if (!uint.TryParse(cmd[3], out x))
648 { 649 {
649 MainConsole.Instance.Output("x-coord must be an integer"); 650 MainConsole.Instance.Output("x-coord must be an integer");
650 return; 651 return;
651 } 652 }
652 653
653 if (!int.TryParse(cmd[4], out y)) 654 if (!uint.TryParse(cmd[4], out y))
654 { 655 {
655 MainConsole.Instance.Output("y-coord must be an integer"); 656 MainConsole.Instance.Output("y-coord must be an integer");
656 return; 657 return;
657 } 658 }
658 659
659 RegionData region = m_Database.Get(x * (int)Constants.RegionSize, y * (int)Constants.RegionSize, UUID.Zero); 660 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y), UUID.Zero);
660 if (region == null) 661 if (region == null)
661 { 662 {
662 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y); 663 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y);
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index 4024295..4ebfd5c 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -183,8 +183,8 @@ namespace OpenSim.Services.GridService
183 public GridRegion LinkRegion(UUID scopeID, string regionDescriptor) 183 public GridRegion LinkRegion(UUID scopeID, string regionDescriptor)
184 { 184 {
185 string reason = string.Empty; 185 string reason = string.Empty;
186 int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize; 186 uint xloc = Util.RegionToWorldLoc((uint)random.Next(0, Int16.MaxValue));
187 return TryLinkRegionToCoords(scopeID, regionDescriptor, xloc, 0, out reason); 187 return TryLinkRegionToCoords(scopeID, regionDescriptor, (int)xloc, 0, out reason);
188 } 188 }
189 189
190 private static Random random = new Random(); 190 private static Random random = new Random();
@@ -260,7 +260,7 @@ namespace OpenSim.Services.GridService
260 { 260 {
261 m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}", 261 m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}",
262 ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), 262 ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI),
263 remoteRegionName, xloc / Constants.RegionSize, yloc / Constants.RegionSize); 263 remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc));
264 264
265 reason = string.Empty; 265 reason = string.Empty;
266 Uri uri = null; 266 Uri uri = null;
@@ -311,7 +311,7 @@ namespace OpenSim.Services.GridService
311 if (region != null) 311 if (region != null)
312 { 312 {
313 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}", 313 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}",
314 regInfo.RegionLocX / Constants.RegionSize, regInfo.RegionLocY / Constants.RegionSize, 314 Util.WorldToRegionLoc((uint)regInfo.RegionLocX), Util.WorldToRegionLoc((uint)regInfo.RegionLocY),
315 region.RegionName, region.RegionID); 315 region.RegionName, region.RegionID);
316 reason = "Coordinates are already in use"; 316 reason = "Coordinates are already in use";
317 return false; 317 return false;
@@ -347,7 +347,7 @@ namespace OpenSim.Services.GridService
347 if (region != null) 347 if (region != null)
348 { 348 {
349 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", 349 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}",
350 region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize); 350 Util.WorldToRegionLoc((uint)regInfo.RegionLocX), Util.WorldToRegionLoc((uint)regInfo.RegionLocY));
351 regInfo = region; 351 regInfo = region;
352 return true; 352 return true;
353 } 353 }
@@ -424,10 +424,10 @@ namespace OpenSim.Services.GridService
424// { 424// {
425// uint ux = 0, uy = 0; 425// uint ux = 0, uy = 0;
426// Utils.LongToUInts(realHandle, out ux, out uy); 426// Utils.LongToUInts(realHandle, out ux, out uy);
427// x = ux / Constants.RegionSize; 427// x = Util.WorldToRegionLoc(ux);
428// y = uy / Constants.RegionSize; 428// y = Util.WorldToRegionLoc(uy);
429// 429//
430// const uint limit = (4096 - 1) * Constants.RegionSize; 430// const uint limit = Util.RegionToWorldLoc(4096 - 1);
431// uint xmin = ux - limit; 431// uint xmin = ux - limit;
432// uint xmax = ux + limit; 432// uint xmax = ux + limit;
433// uint ymin = uy - limit; 433// uint ymin = uy - limit;
@@ -502,9 +502,14 @@ namespace OpenSim.Services.GridService
502 MainConsole.Instance.Output(new string('-', 72)); 502 MainConsole.Instance.Output(new string('-', 72));
503 foreach (RegionData r in regions) 503 foreach (RegionData r in regions)
504 { 504 {
505 MainConsole.Instance.Output(String.Format("{0}\n{2,-32} {1}\n", 505 MainConsole.Instance.Output(
506 r.RegionName, r.RegionID, String.Format("{0},{1} ({2},{3})", r.posX, r.posY, 506 String.Format("{0}\n{2,-32} {1}\n",
507 r.posX / Constants.RegionSize, r.posY / Constants.RegionSize))); 507 r.RegionName, r.RegionID,
508 String.Format("{0},{1} ({2},{3})", r.posX, r.posY,
509 Util.WorldToRegionLoc((uint)r.posX), Util.WorldToRegionLoc((uint)r.posY)
510 )
511 )
512 );
508 } 513 }
509 return; 514 return;
510 } 515 }
@@ -529,8 +534,8 @@ namespace OpenSim.Services.GridService
529 int xloc, yloc; 534 int xloc, yloc;
530 string serverURI; 535 string serverURI;
531 string remoteName = null; 536 string remoteName = null;
532 xloc = Convert.ToInt32(cmdparams[0]) * (int)Constants.RegionSize; 537 xloc = (int)Util.RegionToWorldLoc((uint)Convert.ToInt32(cmdparams[0]));
533 yloc = Convert.ToInt32(cmdparams[1]) * (int)Constants.RegionSize; 538 yloc = (int)Util.RegionToWorldLoc((uint)Convert.ToInt32(cmdparams[1]));
534 serverURI = cmdparams[2]; 539 serverURI = cmdparams[2];
535 if (cmdparams.Length > 3) 540 if (cmdparams.Length > 3)
536 remoteName = string.Join(" ", cmdparams, 3, cmdparams.Length - 3); 541 remoteName = string.Join(" ", cmdparams, 3, cmdparams.Length - 3);
@@ -601,13 +606,13 @@ namespace OpenSim.Services.GridService
601 { 606 {
602 // old format 607 // old format
603 GridRegion regInfo; 608 GridRegion regInfo;
604 int xloc, yloc; 609 uint xloc, yloc;
605 uint externalPort; 610 uint externalPort;
606 string externalHostName; 611 string externalHostName;
607 try 612 try
608 { 613 {
609 xloc = Convert.ToInt32(cmdparams[0]); 614 xloc = Convert.ToUInt32(cmdparams[0]);
610 yloc = Convert.ToInt32(cmdparams[1]); 615 yloc = Convert.ToUInt32(cmdparams[1]);
611 externalPort = Convert.ToUInt32(cmdparams[3]); 616 externalPort = Convert.ToUInt32(cmdparams[3]);
612 externalHostName = cmdparams[2]; 617 externalHostName = cmdparams[2];
613 //internalPort = Convert.ToUInt32(cmdparams[4]); 618 //internalPort = Convert.ToUInt32(cmdparams[4]);
@@ -621,10 +626,11 @@ namespace OpenSim.Services.GridService
621 } 626 }
622 627
623 // Convert cell coordinates given by the user to meters 628 // Convert cell coordinates given by the user to meters
624 xloc = xloc * (int)Constants.RegionSize; 629 xloc = Util.RegionToWorldLoc(xloc);
625 yloc = yloc * (int)Constants.RegionSize; 630 yloc = Util.RegionToWorldLoc(yloc);
626 string reason = string.Empty; 631 string reason = string.Empty;
627 if (TryCreateLink(UUID.Zero, xloc, yloc, string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason)) 632 if (TryCreateLink(UUID.Zero, (int)xloc, (int)yloc,
633 string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason))
628 { 634 {
629 // What is this? The GridRegion instance will be discarded anyway, 635 // What is this? The GridRegion instance will be discarded anyway,
630 // which effectively ignores any local name given with the command. 636 // which effectively ignores any local name given with the command.
@@ -704,13 +710,13 @@ namespace OpenSim.Services.GridService
704 private void ReadLinkFromConfig(IConfig config) 710 private void ReadLinkFromConfig(IConfig config)
705 { 711 {
706 GridRegion regInfo; 712 GridRegion regInfo;
707 int xloc, yloc; 713 uint xloc, yloc;
708 uint externalPort; 714 uint externalPort;
709 string externalHostName; 715 string externalHostName;
710 uint realXLoc, realYLoc; 716 uint realXLoc, realYLoc;
711 717
712 xloc = Convert.ToInt32(config.GetString("xloc", "0")); 718 xloc = Convert.ToUInt32(config.GetString("xloc", "0"));
713 yloc = Convert.ToInt32(config.GetString("yloc", "0")); 719 yloc = Convert.ToUInt32(config.GetString("yloc", "0"));
714 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); 720 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
715 externalHostName = config.GetString("externalHostName", ""); 721 externalHostName = config.GetString("externalHostName", "");
716 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); 722 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
@@ -718,18 +724,19 @@ namespace OpenSim.Services.GridService
718 724
719 if (m_enableAutoMapping) 725 if (m_enableAutoMapping)
720 { 726 {
721 xloc = (int)((xloc % 100) + m_autoMappingX); 727 xloc = (xloc % 100) + m_autoMappingX;
722 yloc = (int)((yloc % 100) + m_autoMappingY); 728 yloc = (yloc % 100) + m_autoMappingY;
723 } 729 }
724 730
725 if (((realXLoc == 0) && (realYLoc == 0)) || 731 if (((realXLoc == 0) && (realYLoc == 0)) ||
726 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && 732 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
727 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) 733 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
728 { 734 {
729 xloc = xloc * (int)Constants.RegionSize; 735 xloc = Util.RegionToWorldLoc(xloc);
730 yloc = yloc * (int)Constants.RegionSize; 736 yloc = Util.RegionToWorldLoc(yloc);
731 string reason = string.Empty; 737 string reason = string.Empty;
732 if (TryCreateLink(UUID.Zero, xloc, yloc, string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason)) 738 if (TryCreateLink(UUID.Zero, (int)xloc, (int)yloc,
739 string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason))
733 { 740 {
734 regInfo.RegionName = config.GetString("localName", ""); 741 regInfo.RegionName = config.GetString("localName", "");
735 } 742 }
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 739e279..8e6279e 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -175,12 +175,12 @@ namespace OpenSim.Services.Interfaces
175 /// <summary> 175 /// <summary>
176 /// The co-ordinate of this region. 176 /// The co-ordinate of this region.
177 /// </summary> 177 /// </summary>
178 public int RegionCoordX { get { return RegionLocX / (int)Constants.RegionSize; } } 178 public int RegionCoordX { get { return (int)Util.WorldToRegionLoc((uint)RegionLocX); } }
179 179
180 /// <summary> 180 /// <summary>
181 /// The co-ordinate of this region 181 /// The co-ordinate of this region
182 /// </summary> 182 /// </summary>
183 public int RegionCoordY { get { return RegionLocY / (int)Constants.RegionSize; } } 183 public int RegionCoordY { get { return (int)Util.WorldToRegionLoc((uint)RegionLocY); } }
184 184
185 /// <summary> 185 /// <summary>
186 /// The location of this region in meters. 186 /// The location of this region in meters.
@@ -259,8 +259,8 @@ namespace OpenSim.Services.Interfaces
259 259
260 public GridRegion(uint xcell, uint ycell) 260 public GridRegion(uint xcell, uint ycell)
261 { 261 {
262 m_regionLocX = (int)(xcell * Constants.RegionSize); 262 m_regionLocX = (int)Util.RegionToWorldLoc(xcell);
263 m_regionLocY = (int)(ycell * Constants.RegionSize); 263 m_regionLocY = (int)Util.RegionToWorldLoc(ycell);
264 RegionSizeX = (int)Constants.RegionSize; 264 RegionSizeX = (int)Constants.RegionSize;
265 RegionSizeY = (int)Constants.RegionSize; 265 RegionSizeY = (int)Constants.RegionSize;
266 } 266 }
@@ -268,8 +268,8 @@ namespace OpenSim.Services.Interfaces
268 public GridRegion(RegionInfo ConvertFrom) 268 public GridRegion(RegionInfo ConvertFrom)
269 { 269 {
270 m_regionName = ConvertFrom.RegionName; 270 m_regionName = ConvertFrom.RegionName;
271 m_regionLocX = (int)(ConvertFrom.RegionLocX * Constants.RegionSize); 271 m_regionLocX = (int)(ConvertFrom.WorldLocX);
272 m_regionLocY = (int)(ConvertFrom.RegionLocY * Constants.RegionSize); 272 m_regionLocY = (int)(ConvertFrom.WorldLocY);
273 RegionSizeX = (int)ConvertFrom.RegionSizeX; 273 RegionSizeX = (int)ConvertFrom.RegionSizeX;
274 RegionSizeY = (int)ConvertFrom.RegionSizeY; 274 RegionSizeY = (int)ConvertFrom.RegionSizeY;
275 m_internalEndPoint = ConvertFrom.InternalEndPoint; 275 m_internalEndPoint = ConvertFrom.InternalEndPoint;
diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
index 5256b74..e67ecf0 100644
--- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -258,7 +258,7 @@ namespace OpenSim.Services.LLLoginService
258 LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z); 258 LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
259 259
260 FillOutRegionData(destination); 260 FillOutRegionData(destination);
261 // m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX=<{0},{1}>", RegionSizeX, RegionSizeY); 261 m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
262 262
263 FillOutSeedCap(aCircuit, destination, clientIP); 263 FillOutSeedCap(aCircuit, destination, clientIP);
264 264
@@ -361,7 +361,8 @@ namespace OpenSim.Services.LLLoginService
361 361
362 private void FillOutHomeData(GridUserInfo pinfo, GridRegion home) 362 private void FillOutHomeData(GridUserInfo pinfo, GridRegion home)
363 { 363 {
364 int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize; 364 int x = (int)Util.RegionToWorldLoc(1000);
365 int y = (int)Util.RegionToWorldLoc(1000);
365 if (home != null) 366 if (home != null)
366 { 367 {
367 x = home.RegionLocX; 368 x = home.RegionLocX;
@@ -435,10 +436,23 @@ namespace OpenSim.Services.LLLoginService
435 ErrorReason = "key"; 436 ErrorReason = "key";
436 welcomeMessage = "Welcome to OpenSim!"; 437 welcomeMessage = "Welcome to OpenSim!";
437 seedCapability = String.Empty; 438 seedCapability = String.Empty;
438 home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" + 439 home = "{'region_handle':["
439 userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" + 440 + "r" + Util.RegionToWorldLoc(1000).ToString()
440 userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" + 441 + ","
441 userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}"; 442 + "r" + Util.RegionToWorldLoc(1000).ToString()
443 + "], 'position':["
444 + "r" + userProfile.homepos.X.ToString()
445 + ","
446 + "r" + userProfile.homepos.Y.ToString()
447 + ","
448 + "r" + userProfile.homepos.Z.ToString()
449 + "], 'look_at':["
450 + "r" + userProfile.homelookat.X.ToString()
451 + ","
452 + "r" + userProfile.homelookat.Y.ToString()
453 + ","
454 + "r" + userProfile.homelookat.Z.ToString()
455 + "]}";
442 lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; 456 lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
443 RegionX = (uint) 255232; 457 RegionX = (uint) 255232;
444 RegionY = (uint) 254976; 458 RegionY = (uint) 254976;
@@ -533,7 +547,7 @@ namespace OpenSim.Services.LLLoginService
533 responseData["region_y"] = (Int32)(RegionY); 547 responseData["region_y"] = (Int32)(RegionY);
534 responseData["region_size_x"] = (Int32)RegionSizeX; 548 responseData["region_size_x"] = (Int32)RegionSizeX;
535 responseData["region_size_y"] = (Int32)RegionSizeY; 549 responseData["region_size_y"] = (Int32)RegionSizeY;
536 // m_log.DebugFormat("[LOGIN RESPONSE] returning sizeX=<{0},{1}>", RegionSizeX, RegionSizeY); 550 m_log.DebugFormat("[LOGIN RESPONSE] returning sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
537 551
538 if (searchURL != String.Empty) 552 if (searchURL != String.Empty)
539 responseData["search"] = searchURL; 553 responseData["search"] = searchURL;
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index e2f9966..150c2c0 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -684,7 +684,7 @@ namespace OpenSim.Services.LLLoginService
684 private GridRegion FindAlternativeRegion(UUID scopeID) 684 private GridRegion FindAlternativeRegion(UUID scopeID)
685 { 685 {
686 List<GridRegion> hyperlinks = null; 686 List<GridRegion> hyperlinks = null;
687 List<GridRegion> regions = m_GridService.GetFallbackRegions(scopeID, 1000 * (int)Constants.RegionSize, 1000 * (int)Constants.RegionSize); 687 List<GridRegion> regions = m_GridService.GetFallbackRegions(scopeID, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000));
688 if (regions != null && regions.Count > 0) 688 if (regions != null && regions.Count > 0)
689 { 689 {
690 hyperlinks = m_GridService.GetHyperlinks(scopeID); 690 hyperlinks = m_GridService.GetHyperlinks(scopeID);
diff --git a/OpenSim/Tests/Clients/Grid/GridClient.cs b/OpenSim/Tests/Clients/Grid/GridClient.cs
index 8e33373..fed7a16 100644
--- a/OpenSim/Tests/Clients/Grid/GridClient.cs
+++ b/OpenSim/Tests/Clients/Grid/GridClient.cs
@@ -150,16 +150,16 @@ namespace OpenSim.Tests.Clients.GridClient
150 150
151 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 2 regions)"); 151 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 2 regions)");
152 regions = m_Connector.GetRegionRange(UUID.Zero, 152 regions = m_Connector.GetRegionRange(UUID.Zero,
153 900 * (int)Constants.RegionSize, 1002 * (int) Constants.RegionSize, 153 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002),
154 900 * (int)Constants.RegionSize, 1002 * (int) Constants.RegionSize); 154 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002) );
155 if (regions == null) 155 if (regions == null)
156 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null"); 156 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
157 else 157 else
158 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions"); 158 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
159 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 0 regions)"); 159 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 0 regions)");
160 regions = m_Connector.GetRegionRange(UUID.Zero, 160 regions = m_Connector.GetRegionRange(UUID.Zero,
161 900 * (int)Constants.RegionSize, 950 * (int)Constants.RegionSize, 161 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950),
162 900 * (int)Constants.RegionSize, 950 * (int)Constants.RegionSize); 162 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950) );
163 if (regions == null) 163 if (regions == null)
164 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null"); 164 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
165 else 165 else
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
index 52a17e7..049200c 100644
--- a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
@@ -69,9 +69,7 @@ namespace OpenSim.Tests.Common
69 tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) => 69 tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) =>
70 { 70 {
71 uint x, y; 71 uint x, y;
72 Utils.LongToUInts(neighbourHandle, out x, out y); 72 Util.RegionHandleToRegionLoc(neighbourHandle, out x, out y);
73 x /= Constants.RegionSize;
74 y /= Constants.RegionSize;
75 73
76 m_log.DebugFormat( 74 m_log.DebugFormat(
77 "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}", 75 "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}",
@@ -104,9 +102,7 @@ namespace OpenSim.Tests.Common
104 += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) => 102 += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) =>
105 { 103 {
106 uint x, y; 104 uint x, y;
107 Utils.LongToUInts(regionHandle, out x, out y); 105 Util.RegionHandleToRegionLoc(regionHandle, out x, out y);
108 x /= Constants.RegionSize;
109 y /= Constants.RegionSize;
110 106
111 m_log.DebugFormat( 107 m_log.DebugFormat(
112 "[TEST CLIENT]: Processing send region teleport for destination at {0},{1} at {2}", 108 "[TEST CLIENT]: Processing send region teleport for destination at {0},{1} at {2}",
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
index 4cdfe98..008f2d0 100644
--- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -186,8 +186,9 @@ namespace OpenSim.Tests.Common
186 186
187 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); 187 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
188 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); 188 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
189 Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
189 testScene.PhysicsScene 190 testScene.PhysicsScene
190 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test"); 191 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
191 192
192 testScene.RegionInfo.EstateSettings = new EstateSettings(); 193 testScene.RegionInfo.EstateSettings = new EstateSettings();
193 testScene.LoginsEnabled = true; 194 testScene.LoginsEnabled = true;
diff --git a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
index ed29c39..5df8e04 100644
--- a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
@@ -69,11 +69,21 @@ namespace OpenSim.Data.Null
69 m_store.StoreTerrain(terrain, regionID); 69 m_store.StoreTerrain(terrain, regionID);
70 } 70 }
71 71
72 public void StoreTerrain(TerrainData terrain, UUID regionID)
73 {
74 m_store.StoreTerrain(terrain, regionID);
75 }
76
72 public double[,] LoadTerrain(UUID regionID) 77 public double[,] LoadTerrain(UUID regionID)
73 { 78 {
74 return m_store.LoadTerrain(regionID); 79 return m_store.LoadTerrain(regionID);
75 } 80 }
76 81
82 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
83 {
84 return m_store.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ);
85 }
86
77 public void StoreLandObject(ILandObject Parcel) 87 public void StoreLandObject(ILandObject Parcel)
78 { 88 {
79 m_store.StoreLandObject(Parcel); 89 m_store.StoreLandObject(Parcel);
@@ -154,7 +164,7 @@ namespace OpenSim.Data.Null
154 protected Dictionary<UUID, SceneObjectPart> m_sceneObjectParts = new Dictionary<UUID, SceneObjectPart>(); 164 protected Dictionary<UUID, SceneObjectPart> m_sceneObjectParts = new Dictionary<UUID, SceneObjectPart>();
155 protected Dictionary<UUID, ICollection<TaskInventoryItem>> m_primItems 165 protected Dictionary<UUID, ICollection<TaskInventoryItem>> m_primItems
156 = new Dictionary<UUID, ICollection<TaskInventoryItem>>(); 166 = new Dictionary<UUID, ICollection<TaskInventoryItem>>();
157 protected Dictionary<UUID, double[,]> m_terrains = new Dictionary<UUID, double[,]>(); 167 protected Dictionary<UUID, TerrainData> m_terrains = new Dictionary<UUID, TerrainData>();
158 protected Dictionary<UUID, LandData> m_landData = new Dictionary<UUID, LandData>(); 168 protected Dictionary<UUID, LandData> m_landData = new Dictionary<UUID, LandData>();
159 169
160 public void Initialise(string dbfile) 170 public void Initialise(string dbfile)
@@ -299,12 +309,17 @@ namespace OpenSim.Data.Null
299 return new List<SceneObjectGroup>(objects.Values); 309 return new List<SceneObjectGroup>(objects.Values);
300 } 310 }
301 311
302 public void StoreTerrain(double[,] ter, UUID regionID) 312 public void StoreTerrain(TerrainData ter, UUID regionID)
303 { 313 {
304 m_terrains[regionID] = ter; 314 m_terrains[regionID] = ter;
305 } 315 }
306 316
307 public double[,] LoadTerrain(UUID regionID) 317 public void StoreTerrain(double[,] ter, UUID regionID)
318 {
319 m_terrains[regionID] = new HeightmapTerrainData(ter);
320 }
321
322 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
308 { 323 {
309 if (m_terrains.ContainsKey(regionID)) 324 if (m_terrains.ContainsKey(regionID))
310 return m_terrains[regionID]; 325 return m_terrains[regionID];
@@ -312,6 +327,14 @@ namespace OpenSim.Data.Null
312 return null; 327 return null;
313 } 328 }
314 329
330 public double[,] LoadTerrain(UUID regionID)
331 {
332 if (m_terrains.ContainsKey(regionID))
333 return m_terrains[regionID].GetDoubles();
334 else
335 return null;
336 }
337
315 public void RemoveLandObject(UUID globalID) 338 public void RemoveLandObject(UUID globalID)
316 { 339 {
317 if (m_landData.ContainsKey(globalID)) 340 if (m_landData.ContainsKey(globalID))
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index 28369a3..b692758 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -308,6 +308,18 @@
308 ;; got a large number of objects, so you can turn it off here if you'd like. 308 ;; got a large number of objects, so you can turn it off here if you'd like.
309 ; DrawPrimOnMapTile = true 309 ; DrawPrimOnMapTile = true
310 310
311 ;# {TexturePrims} {} {Texture prims on map tiles?} {true false} true
312 ;; Texture the faces of the prims that are rendered on the map tiles.
313 ; TexturePrims = true
314
315 ;# {TexturePrimSize} {} {Size of prims to texture faces?} {} 48
316 ;; Only texture prims that have a diagonal size greater than this number
317 ; TexturePrimSize = 48
318
319 ;# {RenderMeshes} {} {Render meshes and sculpties on map tiles?} {true false} false
320 ;; Attempt to render meshes and sculpties on the map
321 ; RenderMeshes = false;
322
311 323
312[Permissions] 324[Permissions]
313 ;# {permissionmodules} {} {Permission modules to use (may specify multiple modules, separated by comma} {} DefaultPermissionsModule 325 ;# {permissionmodules} {} {Permission modules to use (may specify multiple modules, separated by comma} {} DefaultPermissionsModule
diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini
index 0da99ba..df94239 100644
--- a/bin/OpenSimDefaults.ini
+++ b/bin/OpenSimDefaults.ini
@@ -310,6 +310,15 @@
310 ; Use terrain texture for maptiles if true, use shaded green if false 310 ; Use terrain texture for maptiles if true, use shaded green if false
311 TextureOnMapTile = true 311 TextureOnMapTile = true
312 312
313 ; Texture prims
314 TexturePrims = true
315
316 ; Only texture prims that have a diagonal size greater than this number
317 TexturePrimSize = 48
318
319 ; Attempt to render meshes and sculpties on the map
320 RenderMeshes = false;
321
313[Permissions] 322[Permissions]
314 ; ## 323 ; ##
315 ; ## PERMISSIONS 324 ; ## PERMISSIONS