From a3601165029f8484988b5c322798a341ff1e9400 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 6 Mar 2008 15:49:53 +0000 Subject: * 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. --- .../Environment/Scenes/Scene.PacketHandlers.cs | 23 ------ OpenSim/Region/Environment/Scenes/Scene.cs | 84 +++------------------- OpenSim/Region/Environment/Scenes/SceneBase.cs | 13 +--- OpenSim/Region/Environment/Scenes/SceneEvents.cs | 13 ++++ OpenSim/Region/Environment/Scenes/SceneManager.cs | 25 +------ 5 files changed, 27 insertions(+), 131 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes') diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index 20154ea..b269e75 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -37,29 +37,6 @@ namespace OpenSim.Region.Environment.Scenes public partial class Scene { /// - /// Modifies terrain using the specified information - /// - /// The height at which the user started modifying the terrain - /// The number of seconds the modify button was pressed - /// The size of the brush used - /// The action to be performed - /// Distance from the north border where the cursor is located - /// Distance from the west border where the cursor is located - 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); - } - - /// /// /// /// diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 29f1af4..ec1563a 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -283,9 +283,6 @@ namespace OpenSim.Region.Environment.Scenes //m_sceneObjects = new Dictionary(); m_restorePresences = new Dictionary(); - 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); } - /// - /// Loads a world map from a specified R32 file - /// - /// A working R32 file - public void LoadWorldMap(string filename) + public void SaveTerrain() { - Terrain.LoadFromFileF32(filename); - Terrain.SaveRevertMap(); + m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); } /// @@ -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 /// 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) diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index 2a2dea1..12635c8 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -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 /// Client to send to 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 diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs index ac8f91e..5f8c977 100644 --- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs @@ -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) { diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs index 24f71af..3ad9342 100644 --- a/OpenSim/Region/Environment/Scenes/SceneManager.cs +++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs @@ -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) -- cgit v1.1