aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-03-30 09:03:38 +0000
committerAdam Frisby2008-03-30 09:03:38 +0000
commitfadd19f3140107d7c09e7a82a97dfb490146ccb9 (patch)
tree3ce4581ef1af79d451f0b24ce50128f09482f386 /OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
parentThis update has good news and bad news, first the bad. (diff)
downloadopensim-SC-fadd19f3140107d7c09e7a82a97dfb490146ccb9.zip
opensim-SC-fadd19f3140107d7c09e7a82a97dfb490146ccb9.tar.gz
opensim-SC-fadd19f3140107d7c09e7a82a97dfb490146ccb9.tar.bz2
opensim-SC-fadd19f3140107d7c09e7a82a97dfb490146ccb9.tar.xz
**Big ass update warning**
* Renamed plugin console message, to send a message to a plugin, use either "plugin <message>", or any unrecognised message will be sent ("plugin" sends explicitly) This replaces the old "script <message>". * Terrain commands - "terrain <command>" now works again. "Script terrain <command>" does not. Many of the commands have now been reimplemented, eg load-tile. However some have new syntax. * New console command handler, you can now use things like "terrain help" or "terrain save help". See TerrainModule.cs for an example of how to use the new "Commander" class. * Commander class - advanced processing of console input and also enables a script API to be generated from registered console commands.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs181
1 files changed, 143 insertions, 38 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index 742ea5b..745118b 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -33,11 +33,12 @@ using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Environment.Modules.ModuleFramework;
36 37
37 38
38namespace OpenSim.Region.Environment.Modules.Terrain 39namespace OpenSim.Region.Environment.Modules.Terrain
39{ 40{
40 public class TerrainModule : IRegionModule , ITerrainTemp 41 public class TerrainModule : IRegionModule , ITerrainTemp, ICommandableModule
41 { 42 {
42 public enum StandardTerrainEffects : byte 43 public enum StandardTerrainEffects : byte
43 { 44 {
@@ -51,6 +52,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain
51 52
52 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 53 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
53 54
55 private Commander m_commander = new Commander("Terrain");
56
54 private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = 57 private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
55 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 58 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
56 private Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects = 59 private Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects =
@@ -109,7 +112,44 @@ namespace OpenSim.Region.Environment.Modules.Terrain
109 { 112 {
110 lock (m_scene) 113 lock (m_scene)
111 { 114 {
112 ITerrainChannel channel = loader.Value.LoadFile(filename); 115 try
116 {
117 ITerrainChannel channel = loader.Value.LoadFile(filename);
118 m_scene.Heightmap = channel;
119 m_channel = channel;
120 UpdateRevertMap();
121 }
122 catch (NotImplementedException)
123 {
124 m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value.ToString() + " parser does not support file loading. (May be save only)");
125 return;
126 }
127 catch (System.IO.FileNotFoundException)
128 {
129 m_log.Error("[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)");
130 return;
131 }
132 }
133 m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
134 return;
135 }
136 }
137 m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format.");
138 }
139
140 public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
141 {
142 fileStartX -= (int)m_scene.RegionInfo.RegionLocX;
143 fileStartY -= (int)m_scene.RegionInfo.RegionLocY;
144
145 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
146 {
147 if (filename.EndsWith(loader.Key))
148 {
149 lock (m_scene)
150 {
151 ITerrainChannel channel = loader.Value.LoadFile(filename, fileStartX, fileStartY,
152 fileWidth, fileHeight, (int)Constants.RegionSize, (int)Constants.RegionSize);
113 m_scene.Heightmap = channel; 153 m_scene.Heightmap = channel;
114 m_channel = channel; 154 m_channel = channel;
115 UpdateRevertMap(); 155 UpdateRevertMap();
@@ -177,46 +217,101 @@ namespace OpenSim.Region.Environment.Modules.Terrain
177 } 217 }
178 } 218 }
179 219
180 void EventManager_OnPluginConsole(string[] args) 220 #region Console Commands
221
222 private void InterfaceLoadFile(Object[] args)
181 { 223 {
182 if (args[0] == "terrain") 224 LoadFromFile((string)args[0]);
225 }
226
227 private void InterfaceLoadTileFile(Object[] args)
228 {
229 LoadFromFile((string)args[0],
230 (int)args[1],
231 (int)args[2],
232 (int)args[3],
233 (int)args[4]);
234 }
235
236 private void InterfaceSaveFile(Object[] args)
237 {
238 SaveToFile((string)args[0]);
239 }
240
241 private void InterfaceFillTerrain(Object[] args)
242 {
243 int x, y;
244
245 for (x = 0; x < m_channel.Width; x++)
246 for (y = 0; y < m_channel.Height; y++)
247 m_channel[x, y] = (double)args[0];
248 SendUpdatedLayerData();
249 }
250
251 private void InterfaceEnableExperimentalBrushes(Object[] args)
252 {
253 if ((bool)args[0])
183 { 254 {
184 string command = args[1]; 255 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.WeatherSphere();
185 string param = args[2]; 256 m_painteffects[StandardTerrainEffects.Flatten] = new PaintBrushes.OlsenSphere();
257 m_painteffects[StandardTerrainEffects.Smooth] = new PaintBrushes.ErodeSphere();
258 }
259 else
260 {
261 InstallDefaultEffects();
262 }
263 }
186 264
187 int x, y; 265 private void InstallInterfaces()
266 {
267 // Load / Save
268 string supportedFileExtensions = "";
269 foreach (KeyValuePair<string,ITerrainLoader> loader in m_loaders)
270 supportedFileExtensions += " " + loader.Key + " (" + loader.Value.ToString() + ")";
271
272 Command loadFromFileCommand = new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file.");
273 loadFromFileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String");
274
275 Command saveToFileCommand = new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file.");
276 saveToFileCommand.AddArgument("filename", "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " + supportedFileExtensions, "String");
277
278 Command loadFromTileCommand = new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file.");
279 loadFromTileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String");
280 loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer");
281 loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer");
282 loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file", "Integer");
283 loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", "Integer");
284
285 // Terrain adjustments
286 Command fillRegionCommand = new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value.");
287 fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", "Double");
288
289 // Brushes
290 Command experimentalBrushesCommand = new Command("newbrushes", InterfaceEnableExperimentalBrushes, "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
291 experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean");
292
293 m_commander.RegisterCommand("load", loadFromFileCommand);
294 m_commander.RegisterCommand("load-tile", loadFromTileCommand);
295 m_commander.RegisterCommand("save", saveToFileCommand);
296 m_commander.RegisterCommand("fill", fillRegionCommand);
297 m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
298
299 // Add this to our scene so scripts can call these functions
300 //TMPm_scene.RegisterModuleCommander("Terrain", m_commander);
301 }
188 302
189 switch (command) 303 #endregion
190 { 304
191 case "load": 305 void EventManager_OnPluginConsole(string[] args)
192 LoadFromFile(param); 306 {
193 SendUpdatedLayerData(); 307 if (args[0] == "terrain")
194 break; 308 {
195 case "save": 309 string[] tmpArgs = new string[args.Length - 2];
196 SaveToFile(param); 310 int i = 0;
197 break; 311 for (i = 2; i < args.Length; i++)
198 case "fill": 312 tmpArgs[i - 2] = args[i];
199 for (x = 0; x < m_channel.Width; x++) 313
200 for (y = 0; y < m_channel.Height; y++) 314 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
201 m_channel[x, y] = Double.Parse(param);
202 SendUpdatedLayerData();
203 break;
204 case "newbrushes":
205 if (Boolean.Parse(param))
206 {
207 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.WeatherSphere();
208 m_painteffects[StandardTerrainEffects.Flatten] = new PaintBrushes.OlsenSphere();
209 m_painteffects[StandardTerrainEffects.Smooth] = new PaintBrushes.ErodeSphere();
210 }
211 else
212 {
213 InstallDefaultEffects();
214 }
215 break;
216 default:
217 m_log.Warn("Unknown terrain command.");
218 break;
219 }
220 } 315 }
221 } 316 }
222 317
@@ -363,6 +458,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
363 public void PostInitialise() 458 public void PostInitialise()
364 { 459 {
365 InstallDefaultEffects(); 460 InstallDefaultEffects();
461 InstallInterfaces();
366 } 462 }
367 463
368 public void Close() 464 public void Close()
@@ -378,5 +474,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
378 { 474 {
379 get { return false; } 475 get { return false; }
380 } 476 }
477
478 #region ICommandable Members
479
480 public ICommander CommandInterface
481 {
482 get { return m_commander; }
483 }
484
485 #endregion
381 } 486 }
382} 487}