* Disabled ancient TerrainEngine.

* Enabled new TerrainModule.  (The king is dead, long live the king!)
* Use the console command: "script terrain save file.r32" / "script terrain load file.r32" to load/save terrain. Now uses the extension to determine file format.
* MANY of the old terrain features do not have a replacement function in the new module yet, this needs to be corrected, but has not been done so far. This being said, the new module is faster and more efficient and should be a good replacement.
0.6.0-stable
Adam Frisby 2008-03-06 15:49:53 +00:00
parent 0cb4e401ad
commit a360116502
16 changed files with 127 additions and 214 deletions

View File

@ -164,7 +164,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
if (m_app.SceneManager.TryGetScene(regionID, out region))
{
region.LoadWorldMap(file);
//region.LoadWorldMap(file);
responseData["success"] = "true";
}
else

View File

@ -35,5 +35,6 @@ namespace OpenSim.Framework
public class Constants
{
public const uint RegionSize = 256;
public const byte TerrainPatchSize = 16;
}
}

View File

@ -126,7 +126,7 @@ namespace OpenSim.Region.ClientStack
scene.RegisterRegionWithGrid();
scene.PhysicsScene = GetPhysicsScene();
scene.PhysicsScene.SetTerrain(scene.Terrain.GetHeights1D());
scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
//Master Avatar Setup
UserProfileData masterAvatar;

View File

@ -137,13 +137,10 @@ namespace OpenSim.Region.Environment
{
// Water Height
m_regInfo.EstateSettings.waterHeight = WaterHeight;
m_scene.Terrain.watermap.Fill(WaterHeight);
// Terraforming limits
m_regInfo.EstateSettings.terrainRaiseLimit = TerrainRaiseLimit;
m_regInfo.EstateSettings.terrainLowerLimit = TerrainLowerLimit;
m_scene.Terrain.maxRaise = TerrainRaiseLimit;
m_scene.Terrain.minLower = TerrainLowerLimit;
// Time of day / fixed sun
m_regInfo.EstateSettings.useFixedSun = UseFixedSun;

View File

@ -34,6 +34,7 @@ namespace OpenSim.Region.Environment.Interfaces
double this[int x, int y] { get; set; }
int Width { get; }
float[] GetFloatsSerialised();
double[,] GetDoubles();
bool Tainted(int x, int y);
}
}

View File

@ -440,11 +440,11 @@ namespace OpenSim.Region.Environment.LandManagement
}
}
landData.AABBMin =
new LLVector3((float) (min_x*4), (float) (min_y*4),
(float) m_scene.Terrain.GetHeight((min_x*4), (min_y*4)));
new LLVector3((float)(min_x * 4), (float)(min_y * 4),
(float)m_scene.Heightmap[(min_x * 4), (min_y * 4)]);
landData.AABBMax =
new LLVector3((float) (max_x*4), (float) (max_y*4),
(float) m_scene.Terrain.GetHeight((max_x*4), (max_y*4)));
new LLVector3((float)(max_x * 4), (float)(max_y * 4),
(float)m_scene.Heightmap[(max_x * 4), (max_y * 4)]);
landData.area = tempArea;
}

View File

@ -96,6 +96,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain
return heights;
}
public double[,] GetDoubles()
{
return map;
}
public double this[int x, int y]
{
get
@ -104,14 +109,25 @@ namespace OpenSim.Region.Environment.Modules.Terrain
}
set
{
taint[x / 16, y / 16] = true;
map[x, y] = value;
if (map[x, y] != value)
{
taint[x / 16, y / 16] = true;
map[x, y] = value;
}
}
}
public bool Tainted(int x, int y)
{
return taint[x / 16, y / 16];
if (taint[x / 16, y / 16] != false)
{
taint[x / 16, y / 16] = false;
return true;
}
else
{
return false;
}
}
public TerrainChannel()
@ -163,6 +179,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
private Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
Scene m_scene;
ITerrainChannel m_channel;
bool m_tainted = false;
private IConfigSource m_gConfig;
private void InstallDefaultEffects()
@ -241,6 +258,44 @@ namespace OpenSim.Region.Environment.Modules.Terrain
}
m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
}
void EventManager_OnTerrainTick()
{
if (m_tainted)
{
m_tainted = false;
m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised());
m_scene.SaveTerrain();
//m_scene.CreateTerrainTexture(true);
}
}
void EventManager_OnPluginConsole(string[] args)
{
if (args[0] == "terrain")
{
string command = args[1];
string param = args[2];
switch (command)
{
case "load":
LoadFromFile(param);
SendUpdatedLayerData();
break;
case "save":
SaveToFile(param);
break;
default:
m_log.Warn("Unknown terrain command.");
break;
}
}
}
void EventManager_OnNewClient(IClientAPI client)
@ -248,6 +303,31 @@ namespace OpenSim.Region.Environment.Modules.Terrain
client.OnModifyTerrain += client_OnModifyTerrain;
}
void SendUpdatedLayerData()
{
bool shouldTaint = false;
float[] serialised = m_channel.GetFloatsSerialised();
int x, y;
for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
{
for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize)
{
if (m_channel.Tainted(x, y))
{
m_scene.ForEachClient(delegate(IClientAPI controller)
{
controller.SendLayerData(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised);
});
shouldTaint = true;
}
}
}
if (shouldTaint)
{
m_tainted = true;
}
}
void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, float south, float east, IClientAPI remoteClient)
{
// Not a good permissions check, if in area mode, need to check the entire area.
@ -261,11 +341,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain
m_painteffects[(StandardTerrainEffects)action].PaintEffect(
m_channel, west, south, Math.Pow(size, 2.0), seconds);
bool usingTerrainModule = false;
bool usingTerrainModule = true;
if (usingTerrainModule)
{
remoteClient.SendLayerData(m_channel.GetFloatsSerialised());
SendUpdatedLayerData();
}
}
else
@ -298,11 +378,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain
m_floodeffects[(StandardTerrainEffects)action].FloodEffect(
m_channel, fillArea, Math.Pow(size, 2.0));
bool usingTerrainModule = false;
bool usingTerrainModule = true;
if (usingTerrainModule)
{
remoteClient.SendLayerData(m_channel.GetFloatsSerialised());
SendUpdatedLayerData();
}
}
else

View File

@ -205,7 +205,7 @@ namespace OpenSim.Region.Environment.Modules
private void CreateTree(LLVector3 position)
{
position.Z = (float)m_scene.Terrain.heightmap.Get((int)position.X, (int)position.Y);
position.Z = (float)m_scene.Heightmap[(int)position.X, (int)position.Y];
SceneObjectGroup tree =
m_scene.AddTree(new LLVector3(0.1f, 0.1f, 0.1f),

View File

@ -36,29 +36,6 @@ namespace OpenSim.Region.Environment.Scenes
{
public partial class Scene
{
/// <summary>
/// Modifies terrain using the specified information
/// </summary>
/// <param name="height">The height at which the user started modifying the terrain</param>
/// <param name="seconds">The number of seconds the modify button was pressed</param>
/// <param name="brushsize">The size of the brush used</param>
/// <param name="action">The action to be performed</param>
/// <param name="north">Distance from the north border where the cursor is located</param>
/// <param name="west">Distance from the west border where the cursor is located</param>
public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west,
float south, float east,
IClientAPI remoteUser)
{
// Do a permissions check before allowing terraforming.
// random users are now no longer allowed to terraform
// if permissions are enabled.
if (!PermissionsMngr.CanTerraform(remoteUser.AgentId, new LLVector3(north, west, 0)))
return;
//if it wasn't for the permission checking we could have the terrain module directly subscribe to the OnModifyTerrain event
Terrain.ModifyTerrain(height, seconds, brushsize, action, north, west, south, east, remoteUser);
}
/// <summary>
///
/// </summary>

View File

@ -283,9 +283,6 @@ namespace OpenSim.Region.Environment.Scenes
//m_sceneObjects = new Dictionary<LLUUID, SceneObjectGroup>();
m_restorePresences = new Dictionary<LLUUID, ScenePresence>();
m_log.Info("[SCENE]: Creating LandMap");
Terrain = new TerrainEngine((int)RegionInfo.RegionLocX, (int)RegionInfo.RegionLocY);
m_httpListener = httpServer;
m_dumpAssetsToFile = dumpAssetsToFile;
@ -843,43 +840,7 @@ namespace OpenSim.Region.Environment.Scenes
private void UpdateTerrain()
{
if (Terrain.IsTainted() && !Terrain.IsUserStillEditing())
{
CreateTerrainTexture(true);
lock (Terrain.heightmap)
{
lock (SyncRoot)
{
PhysicsScene.SetTerrain(Terrain.GetHeights1D());
}
m_storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD(), RegionInfo.RegionID);
SendTerrainUpdate(true);
Terrain.ResetTaint();
}
}
}
public void SendTerrainUpdate(bool checkForTainted)
{
float[] terData = Heightmap.GetFloatsSerialised();
Broadcast(delegate(IClientAPI client)
{
for (int x = 0; x < 16; x++)
{
for (int y = 0; y < 16; y++)
{
if ((!checkForTainted) || (Terrain.IsTainted(x * 16, y * 16)))
{
client.SendLayerData(x, y, terData);
}
}
}
});
EventManager.TriggerTerrainTick();
}
private void UpdateStorageBackup()
@ -963,14 +924,9 @@ namespace OpenSim.Region.Environment.Scenes
mapTexture.Save(fileName, ImageFormat.Jpeg);
}
/// <summary>
/// Loads a world map from a specified R32 file
/// </summary>
/// <param name="filename">A working R32 file</param>
public void LoadWorldMap(string filename)
public void SaveTerrain()
{
Terrain.LoadFromFileF32(filename);
Terrain.SaveRevertMap();
m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
}
/// <summary>
@ -984,37 +940,15 @@ namespace OpenSim.Region.Environment.Scenes
double[,] map = m_storageManager.DataStore.LoadTerrain(RegionInfo.RegionID);
if (map == null)
{
if (string.IsNullOrEmpty(m_regInfo.EstateSettings.terrainFile))
{
m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
Terrain.SetDefaultTerrain();
m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
Heightmap = new Modules.Terrain.TerrainChannel();
m_storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD(), RegionInfo.RegionID);
}
else
{
try
{
Terrain.LoadFromFileF32(m_regInfo.EstateSettings.terrainFile);
Terrain *= m_regInfo.EstateSettings.terrainMultiplier;
}
catch
{
m_log.Info("[TERRAIN]: No terrain found in database or default. Generating a new terrain.");
Terrain.SetDefaultTerrain();
}
m_storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD(), RegionInfo.RegionID);
}
m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
}
else
{
// TODO: Install 'GetDefaultTerrainProvider' method here?
Heightmap = new Modules.Terrain.TerrainChannel(map);
Terrain.SetHeights2D(map);
}
CreateTerrainTexture(true);
//CommsManager.GridService.RegisterRegion(RegionInfo); //hack to update the terrain texture in grid mode so it shows on world map
}
catch (Exception e)
{
@ -1049,6 +983,8 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary>
public void CreateTerrainTexture(bool temporary)
{
//TODOADAM: Move this to TerrainModule
/*
//create a texture asset of the terrain
byte[] data = Terrain.WriteJpegImage("defaultstripe.png");
m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
@ -1060,6 +996,7 @@ namespace OpenSim.Region.Environment.Scenes
asset.Type = 0;
asset.Temporary = temporary;
AssetCache.AddAsset(asset);
*/
}
#endregion
@ -1382,7 +1319,6 @@ namespace OpenSim.Region.Environment.Scenes
{
client.OnRegionHandShakeReply += SendLayerData;
//remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
client.OnModifyTerrain += ModifyTerrain;
// client.OnRequestWearables += InformClientOfNeighbours;
client.OnAddPrim += AddNewPrim;
client.OnUpdatePrimGroupPosition += m_innerScene.UpdatePrimPosition;
@ -2443,7 +2379,7 @@ namespace OpenSim.Region.Environment.Scenes
public double GetLandHeight(int x, int y)
{
return Terrain.GetHeight(x, y);
return Heightmap[x, y];
}
public LLUUID GetLandOwner(float x, float y)

View File

@ -58,7 +58,7 @@ namespace OpenSim.Region.Environment.Scenes
protected string m_regionName;
protected RegionInfo m_regInfo;
public TerrainEngine Terrain;
//public TerrainEngine Terrain;
public ITerrainChannel Heightmap;
protected EventManager m_eventManager;
@ -112,16 +112,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="RemoteClient">Client to send to</param>
public virtual void SendLayerData(IClientAPI RemoteClient)
{
bool usingTerrainModule = false;
if (usingTerrainModule)
{
RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
}
else
{
RemoteClient.SendLayerData(Terrain.GetHeights1D());
}
RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
}
#endregion

View File

@ -48,6 +48,10 @@ namespace OpenSim.Region.Environment.Scenes
public event ClientMovement OnClientMovement;
public delegate void OnTerrainTickDelegate();
public event OnTerrainTickDelegate OnTerrainTick;
public delegate void OnBackupDelegate(IRegionDataStore datastore);
public event OnBackupDelegate OnBackup;
@ -189,6 +193,7 @@ namespace OpenSim.Region.Environment.Scenes
private NewGridInstantMessage handlerGridInstantMessageToFriends = null; //OnGridInstantMessageToFriendsModule;
private ClientClosed handlerClientClosed = null; //OnClientClosed;
private OnNewPresenceDelegate handlerMakeChildAgent = null; //OnMakeChildAgent;
private OnTerrainTickDelegate handlerTerrainTick = null; // OnTerainTick;
public void TriggerOnScriptChangedEvent(uint localID, uint change)
{
@ -277,6 +282,14 @@ namespace OpenSim.Region.Environment.Scenes
}
}
public void TriggerTerrainTick()
{
handlerTerrainTick = OnTerrainTick;
if (handlerTerrainTick != null)
{
handlerTerrainTick();
}
}
public void TriggerParcelPrimCountAdd(SceneObjectGroup obj)
{

View File

@ -178,29 +178,8 @@ namespace OpenSim.Region.Environment.Scenes
public bool RunTerrainCmdOnCurrentScene(string[] cmdparams, ref string result)
{
if (m_currentScene == null)
{
bool success = true;
foreach (Scene scene in m_localScenes)
{
if (!scene.Terrain.RunTerrainCmd(cmdparams, ref result, scene.RegionInfo.RegionName))
{
success = false;
}
// Messy way of preventing us printing out the same help text for each scene
if (cmdparams.Length <= 0 || cmdparams[0] == "help")
{
break;
}
}
return success;
}
else
{
return m_currentScene.Terrain.RunTerrainCmd(cmdparams, ref result, m_currentScene.RegionInfo.RegionName);
}
m_log.Warn("Terrain commands have been depreciated.");
return false;
}
public void SendCommandToCurrentSceneScripts(string[] cmdparams)

View File

@ -54,15 +54,7 @@ namespace SimpleApp
public override void LoadWorldMap()
{
float[] map = new float[65536];
for (int i = 0; i < 65536; i++)
{
map[i] = 25f;
}
Terrain.GetHeights1D(map);
CreateTerrainTexture(true);
}
public override void AddNewClient(IClientAPI client, bool child)

View File

@ -1851,61 +1851,7 @@ namespace OpenSim.Region.ScriptEngine.Common
double dsize;
if (World.PermissionsMngr.CanTerraform(m_host.OwnerID, new LLVector3(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, 0)))
{
switch (brush)
{
case 1:
dsize = 2;
break;
case 2:
dsize = 4;
break;
case 3:
dsize = 8;
break;
default:
if (brush < 0)
{
dsize = (double)(-1 * brush);
}
else
{
LSLError("Invalid brush size");
dsize = 0; // Should cease execution, but get unassigned local variable dsize on compile.
}
break;
}
switch (action)
{
case 0:
if (World.Terrain.GetHeight((int)m_host.AbsolutePosition.X, (int)m_host.AbsolutePosition.Y) < m_host.AbsolutePosition.Z)
{
World.Terrain.FlattenTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 1);
}
break;
case 1:
if (World.Terrain.GetHeight((int)m_host.AbsolutePosition.X, (int)m_host.AbsolutePosition.Y) < (double)m_host.AbsolutePosition.Z)
{
World.Terrain.RaiseTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 0.1);
}
break;
case 2:
if (World.Terrain.GetHeight((int)m_host.AbsolutePosition.X, (int)m_host.AbsolutePosition.Y) > 0)
{
World.Terrain.LowerTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 1);
}
break;
case 3:
World.Terrain.SmoothTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 1);
break;
case 4:
World.Terrain.NoiseTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 1);
break;
case 5:
World.Terrain.RevertTerrain(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, dsize, 1);
break;
default:
break;
}
NotImplemented("llModifyLand");
}
}
@ -4162,7 +4108,7 @@ namespace OpenSim.Region.ScriptEngine.Common
if (World.PermissionsMngr.CanTerraform(m_host.OwnerID, new LLVector3(x, y, 0)))
{
World.Terrain.Set(x, y, val);
World.Heightmap[x, y] = val;
return 1;
}
else
@ -4177,7 +4123,7 @@ namespace OpenSim.Region.ScriptEngine.Common
if (x > 255 || x < 0 || y > 255 || y < 0)
LSLError("osTerrainGetHeight: Coordinate out of bounds");
return World.Terrain.GetHeight(x, y);
return World.Heightmap[x, y];
}
public int osRegionRestart(double seconds)

View File

@ -299,7 +299,7 @@ namespace OpenSim.Region.Terrain
{
if (IsTainted(x * 16, y * 16))
{
bool usingTerrainModule = false;
bool usingTerrainModule = true;
if (!usingTerrainModule)
{