From 7693a7dac9e6b4c8ed6d4028e210c611ad9d01ce Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 27 Apr 2008 23:54:16 +0000 Subject: * Added String(FileExtension) property to ITerrainLoader to allow us to determine which file extension this loader is capable of handling. * Added ITerrainLoader import capability to Terrain Plugins module - this allows you to write new terrain format plugins without modifying the terrain module directly. --- .../Terrain/FileLoaders/GenericSystemDrawing.cs | 5 +++++ .../Environment/Modules/Terrain/FileLoaders/JPEG.cs | 5 +++++ .../Environment/Modules/Terrain/FileLoaders/LLRAW.cs | 6 ++++++ .../Environment/Modules/Terrain/FileLoaders/RAW32.cs | 5 +++++ .../Modules/Terrain/FileLoaders/Terragen.cs | 5 +++++ .../Environment/Modules/Terrain/ITerrainLoader.cs | 1 + .../Environment/Modules/Terrain/TerrainException.cs | 6 +++--- .../Environment/Modules/Terrain/TerrainModule.cs | 19 ++++++++++++++++--- 8 files changed, 46 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs index 47e0e4cb..b05c1cd 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs @@ -42,6 +42,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { #region ITerrainLoader Members + public string FileExtension + { + get { return ".gsd"; } + } + /// /// Loads a file from a specified filename on the disk, /// parses the image using the System.Drawing parsers diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs index f25b29b..c2ac9d0 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs @@ -36,6 +36,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { #region ITerrainLoader Members + public string FileExtension + { + get { return ".jpg"; } + } + public ITerrainChannel LoadFile(string filename) { throw new NotImplementedException(); diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs index fda46f0..6ed7340 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs @@ -132,6 +132,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders s.Close(); } + + public string FileExtension + { + get { return ".raw"; } + } + #endregion public override string ToString() diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs index d496069..edc379b 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs @@ -34,6 +34,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { #region ITerrainLoader Members + public string FileExtension + { + get { return ".r32"; } + } + public ITerrainChannel LoadFile(string filename) { TerrainChannel retval = new TerrainChannel(); diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs index 9f9edbc..2a4a8f8 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs @@ -107,6 +107,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders throw new NotImplementedException(); } + public string FileExtension + { + get { return ".ter"; } + } + public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) { throw new NotImplementedException(); diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs index 992ed1e..c718a32 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs @@ -31,6 +31,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain { public interface ITerrainLoader { + string FileExtension { get; } ITerrainChannel LoadFile(string filename); ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); void SaveFile(string filename, ITerrainChannel map); diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainException.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainException.cs index 307553b..d357063 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainException.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainException.cs @@ -31,15 +31,15 @@ namespace OpenSim.Region.Environment.Modules.Terrain { public class TerrainException : Exception { - public TerrainException(): base() + public TerrainException() : base() { } - public TerrainException(string msg): base(msg) + public TerrainException(string msg) : base(msg) { } - public TerrainException(string msg, Exception e): base(msg, e) + public TerrainException(string msg, Exception e) : base(msg, e) { } } diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs index dc8a023..67acef7 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs @@ -185,7 +185,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain { m_log.Error( "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)"); - throw new TerrainException(String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename)); + throw new TerrainException( + String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename)); } } CheckForTerrainUpdates(); @@ -244,8 +245,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain if (pluginType.GetInterface("ITerrainEffect", false) != null) { ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString())); - m_plugineffects.Add(pluginType.Name, terEffect); - m_log.Info("... " + pluginType.Name); + if (!m_plugineffects.ContainsKey(pluginType.Name)) + { + m_plugineffects.Add(pluginType.Name, terEffect); + m_log.Info("E ... " + pluginType.Name); + } else + { + m_log.Warn("E ... " + pluginType.Name + " (Already added)"); + } + } + else if (pluginType.GetInterface("ITerrainLoader", false) != null) + { + ITerrainLoader terLoader = (ITerrainLoader) Activator.CreateInstance(library.GetType(pluginType.ToString())); + m_loaders[terLoader.FileExtension] = terLoader; + m_log.Info("L ... " + pluginType.Name); } } catch (AmbiguousMatchException) -- cgit v1.1