From 838ffd779280115dee2d24ddd9531728d7426942 Mon Sep 17 00:00:00 2001
From: Charles Krinke
Date: Thu, 19 Jun 2008 20:57:00 +0000
Subject: Mantis#1543. Thank you kindly, Jonc for a patch that: Implements
terrain bake from Region/Estate dialog and respects estate settings during
terraforming
---
.../Environment/Modules/World/NPC/NPCAvatar.cs | 4 +-
.../Modules/World/Terrain/TerrainModule.cs | 81 +++++++++++++++++++++-
2 files changed, 81 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Region/Environment/Modules')
diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
index 4935672..a242ebe 100644
--- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
@@ -281,6 +281,7 @@ namespace OpenSim.Region.Environment.Modules.World.NPC
public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
+ public event BakeTerrain OnBakeTerrain;
public event EstateRestartSimRequest OnEstateRestartSimRequest;
public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
@@ -776,5 +777,6 @@ namespace OpenSim.Region.Environment.Modules.World.NPC
{
}
#endregion
- }
+
+ }
}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
index 9d8bbfc..49347b2 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
@@ -419,13 +419,28 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
private void EventManager_OnNewClient(IClientAPI client)
{
client.OnModifyTerrain += client_OnModifyTerrain;
+ client.OnBakeTerrain += client_OnBakeTerrain;
}
///
/// Checks to see if the terrain has been modified since last check
+ /// but won't attempt to limit those changes to the limits specified in the estate settings
+ /// currently invoked by the command line operations in the region server only
///
private void CheckForTerrainUpdates()
{
+ CheckForTerrainUpdates(false);
+ }
+
+ ///
+ /// Checks to see if the terrain has been modified since last check
+ /// if the call is asked to respect the estate settings for terrain_raise_limit and
+ /// terrain_lower_limit, it will clamp terrain updates between these values
+ /// currently invoked by client_OnModifyTerrain only and not the Commander interfaces
+ /// should height map deltas be limited to the estate settings limits
+ ///
+ private void CheckForTerrainUpdates(bool respectEstateSettings)
+ {
bool shouldTaint = false;
float[] serialised = m_channel.GetFloatsSerialised();
int x;
@@ -436,6 +451,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
{
if (m_channel.Tainted(x, y))
{
+ // if we should respect the estate settings then
+ // fixup and height deltas that don't respect them
+ if (respectEstateSettings && LimitChannelChanges(x, y))
+ {
+ // this has been vetoed, so update
+ // what we are going to send to the client
+ serialised = m_channel.GetFloatsSerialised();
+ }
SendToClients(serialised, x, y);
shouldTaint = true;
}
@@ -447,6 +470,46 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
}
}
+
+ ///
+ /// Checks to see height deltas in the tainted terrain patch at xStart ,yStart
+ /// are all within the current estate limits
+ /// true if changes were limited, false otherwise
+ ///
+ private bool LimitChannelChanges(int xStart, int yStart)
+ {
+ bool changesLimited = false;
+ double minDelta = m_scene.RegionInfo.EstateSettings.terrainLowerLimit;
+ double maxDelta = m_scene.RegionInfo.EstateSettings.terrainRaiseLimit;
+
+ // loop through the height map for this patch and compare it against
+ // the revert map
+ for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
+ {
+ for (int y = yStart; y < yStart + Constants.TerrainPatchSize; y++)
+ {
+
+ double requestedHeight = m_channel[x, y];
+ double bakedHeight = m_revert[x, y];
+ double requestedDelta = requestedHeight - bakedHeight;
+
+ if (requestedDelta > maxDelta )
+ {
+ m_channel[x, y] = bakedHeight + maxDelta;
+ changesLimited = true;
+ }
+ else if (requestedDelta < minDelta)
+ {
+ m_channel[x, y] = bakedHeight + minDelta; //as lower is a -ve delta
+ changesLimited = true;
+ }
+ }
+ }
+
+ return changesLimited;
+ }
+
+
///
/// Sends a copy of the current terrain to the scenes clients
///
@@ -472,7 +535,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
m_painteffects[(StandardTerrainEffects) action].PaintEffect(
m_channel, west, south, size, seconds);
- CheckForTerrainUpdates();
+ CheckForTerrainUpdates(true); //revert changes outside estate limits
}
else
{
@@ -505,7 +568,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
m_floodeffects[(StandardTerrainEffects) action].FloodEffect(
m_channel, fillArea, size);
- CheckForTerrainUpdates();
+ CheckForTerrainUpdates(true); //revert changes outside estate limits
}
else
{
@@ -515,6 +578,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
}
}
+ private void client_OnBakeTerrain(IClientAPI remoteClient)
+ {
+ // Not a good permissions check (see client_OnModifyTerrain above), need to check the entire area.
+ // for now check a point in the centre of the region
+
+ if (m_scene.ExternalChecks.ExternalChecksCanTerraformLand(remoteClient.AgentId, new LLVector3(127, 127, 0)))
+ {
+ InterfaceBakeTerrain(null); //bake terrain does not use the passed in parameter
+ }
+ }
+
+
#region Console Commands
private void InterfaceLoadFile(Object[] args)
@@ -745,4 +820,4 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
#endregion
}
-}
\ No newline at end of file
+}
--
cgit v1.1