TerrainModule.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Net;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
  37. using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
  38. using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes;
  39. using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. namespace OpenSim.Region.CoreModules.World.Terrain
  43. {
  44. public class TerrainModule : INonSharedRegionModule, ICommandableModule, ITerrainModule
  45. {
  46. #region StandardTerrainEffects enum
  47. /// <summary>
  48. /// A standard set of terrain brushes and effects recognised by viewers
  49. /// </summary>
  50. public enum StandardTerrainEffects : byte
  51. {
  52. Flatten = 0,
  53. Raise = 1,
  54. Lower = 2,
  55. Smooth = 3,
  56. Noise = 4,
  57. Revert = 5,
  58. // Extended brushes
  59. Erode = 255,
  60. Weather = 254,
  61. Olsen = 253
  62. }
  63. #endregion
  64. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  65. private readonly Commander m_commander = new Commander("terrain");
  66. private readonly Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects =
  67. new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>();
  68. private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
  69. private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
  70. new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
  71. private ITerrainChannel m_channel;
  72. private Dictionary<string, ITerrainEffect> m_plugineffects;
  73. private ITerrainChannel m_revert;
  74. private Scene m_scene;
  75. private volatile bool m_tainted;
  76. private readonly Stack<LandUndoState> m_undo = new Stack<LandUndoState>(5);
  77. #region ICommandableModule Members
  78. public ICommander CommandInterface
  79. {
  80. get { return m_commander; }
  81. }
  82. #endregion
  83. #region INonSharedRegionModule Members
  84. /// <summary>
  85. /// Creates and initialises a terrain module for a region
  86. /// </summary>
  87. /// <param name="scene">Region initialising</param>
  88. /// <param name="config">Config for the region</param>
  89. public void Initialise(IConfigSource config)
  90. {
  91. }
  92. public void AddRegion(Scene scene)
  93. {
  94. m_scene = scene;
  95. // Install terrain module in the simulator
  96. lock (m_scene)
  97. {
  98. if (m_scene.Heightmap == null)
  99. {
  100. m_channel = new TerrainChannel();
  101. m_scene.Heightmap = m_channel;
  102. m_revert = new TerrainChannel();
  103. UpdateRevertMap();
  104. }
  105. else
  106. {
  107. m_channel = m_scene.Heightmap;
  108. m_revert = new TerrainChannel();
  109. UpdateRevertMap();
  110. }
  111. m_scene.RegisterModuleInterface<ITerrainModule>(this);
  112. m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
  113. m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
  114. m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
  115. }
  116. InstallDefaultEffects();
  117. LoadPlugins();
  118. }
  119. public void RegionLoaded(Scene scene)
  120. {
  121. //Do this here to give file loaders time to initialize and
  122. //register their supported file extensions and file formats.
  123. InstallInterfaces();
  124. }
  125. public void RemoveRegion(Scene scene)
  126. {
  127. lock (m_scene)
  128. {
  129. // remove the commands
  130. m_scene.UnregisterModuleCommander(m_commander.Name);
  131. // remove the event-handlers
  132. m_scene.EventManager.OnTerrainTick -= EventManager_OnTerrainTick;
  133. m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
  134. m_scene.EventManager.OnNewClient -= EventManager_OnNewClient;
  135. // remove the interface
  136. m_scene.UnregisterModuleInterface<ITerrainModule>(this);
  137. }
  138. }
  139. public void Close()
  140. {
  141. }
  142. public Type ReplaceableInterface
  143. {
  144. get { return null; }
  145. }
  146. public string Name
  147. {
  148. get { return "TerrainModule"; }
  149. }
  150. #endregion
  151. #region ITerrainModule Members
  152. public void UndoTerrain(ITerrainChannel channel)
  153. {
  154. m_channel = channel;
  155. }
  156. /// <summary>
  157. /// Loads a terrain file from disk and installs it in the scene.
  158. /// </summary>
  159. /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
  160. public void LoadFromFile(string filename)
  161. {
  162. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  163. {
  164. if (filename.EndsWith(loader.Key))
  165. {
  166. lock (m_scene)
  167. {
  168. try
  169. {
  170. ITerrainChannel channel = loader.Value.LoadFile(filename);
  171. if (channel.Width != Constants.RegionSize || channel.Height != Constants.RegionSize)
  172. {
  173. // TerrainChannel expects a RegionSize x RegionSize map, currently
  174. throw new ArgumentException(String.Format("wrong size, use a file with size {0} x {1}",
  175. Constants.RegionSize, Constants.RegionSize));
  176. }
  177. m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height);
  178. m_scene.Heightmap = channel;
  179. m_channel = channel;
  180. UpdateRevertMap();
  181. }
  182. catch (NotImplementedException)
  183. {
  184. m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value +
  185. " parser does not support file loading. (May be save only)");
  186. throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
  187. }
  188. catch (FileNotFoundException)
  189. {
  190. m_log.Error(
  191. "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)");
  192. throw new TerrainException(
  193. String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename));
  194. }
  195. catch (ArgumentException e)
  196. {
  197. m_log.ErrorFormat("[TERRAIN]: Unable to load heightmap: {0}", e.Message);
  198. throw new TerrainException(
  199. String.Format("Unable to load heightmap: {0}", e.Message));
  200. }
  201. }
  202. CheckForTerrainUpdates();
  203. m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
  204. return;
  205. }
  206. }
  207. m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format.");
  208. throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
  209. }
  210. /// <summary>
  211. /// Saves the current heightmap to a specified file.
  212. /// </summary>
  213. /// <param name="filename">The destination filename</param>
  214. public void SaveToFile(string filename)
  215. {
  216. try
  217. {
  218. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  219. {
  220. if (filename.EndsWith(loader.Key))
  221. {
  222. loader.Value.SaveFile(filename, m_channel);
  223. return;
  224. }
  225. }
  226. }
  227. catch (NotImplementedException)
  228. {
  229. m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented.");
  230. throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented"));
  231. }
  232. catch (IOException ioe)
  233. {
  234. m_log.Error(String.Format("[TERRAIN]: Unable to save to {0}, {1}", filename, ioe.Message));
  235. throw new TerrainException(String.Format("Unable to save heightmap: {0}", ioe.Message));
  236. }
  237. }
  238. /// <summary>
  239. /// Loads a terrain file from the specified URI
  240. /// </summary>
  241. /// <param name="filename">The name of the terrain to load</param>
  242. /// <param name="pathToTerrainHeightmap">The URI to the terrain height map</param>
  243. public void LoadFromStream(string filename, Uri pathToTerrainHeightmap)
  244. {
  245. LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
  246. }
  247. /// <summary>
  248. /// Loads a terrain file from a stream and installs it in the scene.
  249. /// </summary>
  250. /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
  251. /// <param name="stream"></param>
  252. public void LoadFromStream(string filename, Stream stream)
  253. {
  254. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  255. {
  256. if (filename.EndsWith(loader.Key))
  257. {
  258. lock (m_scene)
  259. {
  260. try
  261. {
  262. ITerrainChannel channel = loader.Value.LoadStream(stream);
  263. m_scene.Heightmap = channel;
  264. m_channel = channel;
  265. UpdateRevertMap();
  266. }
  267. catch (NotImplementedException)
  268. {
  269. m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value +
  270. " parser does not support file loading. (May be save only)");
  271. throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
  272. }
  273. }
  274. CheckForTerrainUpdates();
  275. m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
  276. return;
  277. }
  278. }
  279. m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format.");
  280. throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
  281. }
  282. private static Stream URIFetch(Uri uri)
  283. {
  284. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
  285. // request.Credentials = credentials;
  286. request.ContentLength = 0;
  287. request.KeepAlive = false;
  288. WebResponse response = request.GetResponse();
  289. Stream file = response.GetResponseStream();
  290. if (response.ContentLength == 0)
  291. throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
  292. // return new BufferedStream(file, (int) response.ContentLength);
  293. return new BufferedStream(file, 1000000);
  294. }
  295. /// <summary>
  296. /// Modify Land
  297. /// </summary>
  298. /// <param name="pos">Land-position (X,Y,0)</param>
  299. /// <param name="size">The size of the brush (0=small, 1=medium, 2=large)</param>
  300. /// <param name="action">0=LAND_LEVEL, 1=LAND_RAISE, 2=LAND_LOWER, 3=LAND_SMOOTH, 4=LAND_NOISE, 5=LAND_REVERT</param>
  301. /// <param name="agentId">UUID of script-owner</param>
  302. public void ModifyTerrain(UUID user, Vector3 pos, byte size, byte action, UUID agentId)
  303. {
  304. float duration = 0.25f;
  305. if (action == 0)
  306. duration = 4.0f;
  307. client_OnModifyTerrain(user, (float)pos.Z, duration, size, action, pos.Y, pos.X, pos.Y, pos.X, agentId);
  308. }
  309. /// <summary>
  310. /// Saves the current heightmap to a specified stream.
  311. /// </summary>
  312. /// <param name="filename">The destination filename. Used here only to identify the image type</param>
  313. /// <param name="stream"></param>
  314. public void SaveToStream(string filename, Stream stream)
  315. {
  316. try
  317. {
  318. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  319. {
  320. if (filename.EndsWith(loader.Key))
  321. {
  322. loader.Value.SaveStream(stream, m_channel);
  323. return;
  324. }
  325. }
  326. }
  327. catch (NotImplementedException)
  328. {
  329. m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented.");
  330. throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented"));
  331. }
  332. }
  333. public void TaintTerrain ()
  334. {
  335. CheckForTerrainUpdates();
  336. }
  337. #region Plugin Loading Methods
  338. private void LoadPlugins()
  339. {
  340. m_plugineffects = new Dictionary<string, ITerrainEffect>();
  341. string plugineffectsPath = "Terrain";
  342. // Load the files in the Terrain/ dir
  343. if (!Directory.Exists(plugineffectsPath))
  344. return;
  345. string[] files = Directory.GetFiles(plugineffectsPath);
  346. foreach (string file in files)
  347. {
  348. m_log.Info("Loading effects in " + file);
  349. try
  350. {
  351. Assembly library = Assembly.LoadFrom(file);
  352. foreach (Type pluginType in library.GetTypes())
  353. {
  354. try
  355. {
  356. if (pluginType.IsAbstract || pluginType.IsNotPublic)
  357. continue;
  358. string typeName = pluginType.Name;
  359. if (pluginType.GetInterface("ITerrainEffect", false) != null)
  360. {
  361. ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString()));
  362. InstallPlugin(typeName, terEffect);
  363. }
  364. else if (pluginType.GetInterface("ITerrainLoader", false) != null)
  365. {
  366. ITerrainLoader terLoader = (ITerrainLoader) Activator.CreateInstance(library.GetType(pluginType.ToString()));
  367. m_loaders[terLoader.FileExtension] = terLoader;
  368. m_log.Info("L ... " + typeName);
  369. }
  370. }
  371. catch (AmbiguousMatchException)
  372. {
  373. }
  374. }
  375. }
  376. catch (BadImageFormatException)
  377. {
  378. }
  379. }
  380. }
  381. public void InstallPlugin(string pluginName, ITerrainEffect effect)
  382. {
  383. lock (m_plugineffects)
  384. {
  385. if (!m_plugineffects.ContainsKey(pluginName))
  386. {
  387. m_plugineffects.Add(pluginName, effect);
  388. m_log.Info("E ... " + pluginName);
  389. }
  390. else
  391. {
  392. m_plugineffects[pluginName] = effect;
  393. m_log.Warn("E ... " + pluginName + " (Replaced)");
  394. }
  395. }
  396. }
  397. #endregion
  398. #endregion
  399. /// <summary>
  400. /// Installs into terrain module the standard suite of brushes
  401. /// </summary>
  402. private void InstallDefaultEffects()
  403. {
  404. // Draggable Paint Brush Effects
  405. m_painteffects[StandardTerrainEffects.Raise] = new RaiseSphere();
  406. m_painteffects[StandardTerrainEffects.Lower] = new LowerSphere();
  407. m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere();
  408. m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere();
  409. m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere();
  410. m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert);
  411. m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere();
  412. m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere();
  413. m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere();
  414. // Area of effect selection effects
  415. m_floodeffects[StandardTerrainEffects.Raise] = new RaiseArea();
  416. m_floodeffects[StandardTerrainEffects.Lower] = new LowerArea();
  417. m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea();
  418. m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea();
  419. m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea();
  420. m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert);
  421. // Filesystem load/save loaders
  422. m_loaders[".r32"] = new RAW32();
  423. m_loaders[".f32"] = m_loaders[".r32"];
  424. m_loaders[".ter"] = new Terragen();
  425. m_loaders[".raw"] = new LLRAW();
  426. m_loaders[".jpg"] = new JPEG();
  427. m_loaders[".jpeg"] = m_loaders[".jpg"];
  428. m_loaders[".bmp"] = new BMP();
  429. m_loaders[".png"] = new PNG();
  430. m_loaders[".gif"] = new GIF();
  431. m_loaders[".tif"] = new TIFF();
  432. m_loaders[".tiff"] = m_loaders[".tif"];
  433. }
  434. /// <summary>
  435. /// Saves the current state of the region into the revert map buffer.
  436. /// </summary>
  437. public void UpdateRevertMap()
  438. {
  439. int x;
  440. for (x = 0; x < m_channel.Width; x++)
  441. {
  442. int y;
  443. for (y = 0; y < m_channel.Height; y++)
  444. {
  445. m_revert[x, y] = m_channel[x, y];
  446. }
  447. }
  448. }
  449. /// <summary>
  450. /// Loads a tile from a larger terrain file and installs it into the region.
  451. /// </summary>
  452. /// <param name="filename">The terrain file to load</param>
  453. /// <param name="fileWidth">The width of the file in units</param>
  454. /// <param name="fileHeight">The height of the file in units</param>
  455. /// <param name="fileStartX">Where to begin our slice</param>
  456. /// <param name="fileStartY">Where to begin our slice</param>
  457. public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
  458. {
  459. int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX;
  460. int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY;
  461. if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
  462. {
  463. // this region is included in the tile request
  464. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  465. {
  466. if (filename.EndsWith(loader.Key))
  467. {
  468. lock (m_scene)
  469. {
  470. ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
  471. fileWidth, fileHeight,
  472. (int) Constants.RegionSize,
  473. (int) Constants.RegionSize);
  474. m_scene.Heightmap = channel;
  475. m_channel = channel;
  476. UpdateRevertMap();
  477. }
  478. return;
  479. }
  480. }
  481. }
  482. }
  483. /// <summary>
  484. /// Saves the terrain to a larger terrain file.
  485. /// </summary>
  486. /// <param name="filename">The terrain file to save</param>
  487. /// <param name="fileWidth">The width of the file in units</param>
  488. /// <param name="fileHeight">The height of the file in units</param>
  489. /// <param name="fileStartX">Where to begin our slice</param>
  490. /// <param name="fileStartY">Where to begin our slice</param>
  491. public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
  492. {
  493. int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX;
  494. int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY;
  495. if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
  496. {
  497. // this region is included in the tile request
  498. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  499. {
  500. if (filename.EndsWith(loader.Key))
  501. {
  502. lock (m_scene)
  503. {
  504. loader.Value.SaveFile(m_channel, filename, offsetX, offsetY,
  505. fileWidth, fileHeight,
  506. (int)Constants.RegionSize,
  507. (int)Constants.RegionSize);
  508. }
  509. return;
  510. }
  511. }
  512. }
  513. }
  514. /// <summary>
  515. /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections
  516. /// </summary>
  517. private void EventManager_OnTerrainTick()
  518. {
  519. if (m_tainted)
  520. {
  521. m_tainted = false;
  522. m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised());
  523. m_scene.SaveTerrain();
  524. // Clients who look at the map will never see changes after they looked at the map, so i've commented this out.
  525. //m_scene.CreateTerrainTexture(true);
  526. }
  527. }
  528. /// <summary>
  529. /// Processes commandline input. Do not call directly.
  530. /// </summary>
  531. /// <param name="args">Commandline arguments</param>
  532. private void EventManager_OnPluginConsole(string[] args)
  533. {
  534. if (args[0] == "terrain")
  535. {
  536. if (args.Length == 1)
  537. {
  538. m_commander.ProcessConsoleCommand("help", new string[0]);
  539. return;
  540. }
  541. string[] tmpArgs = new string[args.Length - 2];
  542. int i;
  543. for (i = 2; i < args.Length; i++)
  544. tmpArgs[i - 2] = args[i];
  545. m_commander.ProcessConsoleCommand(args[1], tmpArgs);
  546. }
  547. }
  548. /// <summary>
  549. /// Installs terrain brush hook to IClientAPI
  550. /// </summary>
  551. /// <param name="client"></param>
  552. private void EventManager_OnNewClient(IClientAPI client)
  553. {
  554. client.OnModifyTerrain += client_OnModifyTerrain;
  555. client.OnBakeTerrain += client_OnBakeTerrain;
  556. client.OnLandUndo += client_OnLandUndo;
  557. client.OnUnackedTerrain += client_OnUnackedTerrain;
  558. }
  559. /// <summary>
  560. /// Checks to see if the terrain has been modified since last check
  561. /// but won't attempt to limit those changes to the limits specified in the estate settings
  562. /// currently invoked by the command line operations in the region server only
  563. /// </summary>
  564. private void CheckForTerrainUpdates()
  565. {
  566. CheckForTerrainUpdates(false);
  567. }
  568. /// <summary>
  569. /// Checks to see if the terrain has been modified since last check.
  570. /// If it has been modified, every all the terrain patches are sent to the client.
  571. /// If the call is asked to respect the estate settings for terrain_raise_limit and
  572. /// terrain_lower_limit, it will clamp terrain updates between these values
  573. /// currently invoked by client_OnModifyTerrain only and not the Commander interfaces
  574. /// <param name="respectEstateSettings">should height map deltas be limited to the estate settings limits</param>
  575. /// </summary>
  576. private void CheckForTerrainUpdates(bool respectEstateSettings)
  577. {
  578. bool shouldTaint = false;
  579. float[] serialised = m_channel.GetFloatsSerialised();
  580. int x;
  581. for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
  582. {
  583. int y;
  584. for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize)
  585. {
  586. if (m_channel.Tainted(x, y))
  587. {
  588. // if we should respect the estate settings then
  589. // fixup and height deltas that don't respect them
  590. if (respectEstateSettings && LimitChannelChanges(x, y))
  591. {
  592. // this has been vetoed, so update
  593. // what we are going to send to the client
  594. serialised = m_channel.GetFloatsSerialised();
  595. }
  596. SendToClients(serialised, x, y);
  597. shouldTaint = true;
  598. }
  599. }
  600. }
  601. if (shouldTaint)
  602. {
  603. m_tainted = true;
  604. }
  605. }
  606. /// <summary>
  607. /// Checks to see height deltas in the tainted terrain patch at xStart ,yStart
  608. /// are all within the current estate limits
  609. /// <returns>true if changes were limited, false otherwise</returns>
  610. /// </summary>
  611. private bool LimitChannelChanges(int xStart, int yStart)
  612. {
  613. bool changesLimited = false;
  614. double minDelta = m_scene.RegionInfo.RegionSettings.TerrainLowerLimit;
  615. double maxDelta = m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
  616. // loop through the height map for this patch and compare it against
  617. // the revert map
  618. for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
  619. {
  620. for (int y = yStart; y < yStart + Constants.TerrainPatchSize; y++)
  621. {
  622. double requestedHeight = m_channel[x, y];
  623. double bakedHeight = m_revert[x, y];
  624. double requestedDelta = requestedHeight - bakedHeight;
  625. if (requestedDelta > maxDelta)
  626. {
  627. m_channel[x, y] = bakedHeight + maxDelta;
  628. changesLimited = true;
  629. }
  630. else if (requestedDelta < minDelta)
  631. {
  632. m_channel[x, y] = bakedHeight + minDelta; //as lower is a -ve delta
  633. changesLimited = true;
  634. }
  635. }
  636. }
  637. return changesLimited;
  638. }
  639. private void client_OnLandUndo(IClientAPI client)
  640. {
  641. lock (m_undo)
  642. {
  643. if (m_undo.Count > 0)
  644. {
  645. LandUndoState goback = m_undo.Pop();
  646. if (goback != null)
  647. goback.PlaybackState();
  648. }
  649. }
  650. }
  651. /// <summary>
  652. /// Sends a copy of the current terrain to the scenes clients
  653. /// </summary>
  654. /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param>
  655. /// <param name="x">The patch corner to send</param>
  656. /// <param name="y">The patch corner to send</param>
  657. private void SendToClients(float[] serialised, int x, int y)
  658. {
  659. m_scene.ForEachClient(
  660. delegate(IClientAPI controller)
  661. { controller.SendLayerData(
  662. x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised);
  663. }
  664. );
  665. }
  666. private void client_OnModifyTerrain(UUID user, float height, float seconds, byte size, byte action,
  667. float north, float west, float south, float east, UUID agentId)
  668. {
  669. bool god = m_scene.Permissions.IsGod(user);
  670. bool allowed = false;
  671. if (north == south && east == west)
  672. {
  673. if (m_painteffects.ContainsKey((StandardTerrainEffects) action))
  674. {
  675. bool[,] allowMask = new bool[m_channel.Width,m_channel.Height];
  676. allowMask.Initialize();
  677. int n = size + 1;
  678. if (n > 2)
  679. n = 4;
  680. int zx = (int) (west + 0.5);
  681. int zy = (int) (north + 0.5);
  682. int dx;
  683. for (dx=-n; dx<=n; dx++)
  684. {
  685. int dy;
  686. for (dy=-n; dy<=n; dy++)
  687. {
  688. int x = zx + dx;
  689. int y = zy + dy;
  690. if (x>=0 && y>=0 && x<m_channel.Width && y<m_channel.Height)
  691. {
  692. if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0)))
  693. {
  694. allowMask[x, y] = true;
  695. allowed = true;
  696. }
  697. }
  698. }
  699. }
  700. if (allowed)
  701. {
  702. StoreUndoState();
  703. m_painteffects[(StandardTerrainEffects) action].PaintEffect(
  704. m_channel, allowMask, west, south, height, size, seconds);
  705. CheckForTerrainUpdates(!god); //revert changes outside estate limits
  706. }
  707. }
  708. else
  709. {
  710. m_log.Debug("Unknown terrain brush type " + action);
  711. }
  712. }
  713. else
  714. {
  715. if (m_floodeffects.ContainsKey((StandardTerrainEffects) action))
  716. {
  717. bool[,] fillArea = new bool[m_channel.Width,m_channel.Height];
  718. fillArea.Initialize();
  719. int x;
  720. for (x = 0; x < m_channel.Width; x++)
  721. {
  722. int y;
  723. for (y = 0; y < m_channel.Height; y++)
  724. {
  725. if (x < east && x > west)
  726. {
  727. if (y < north && y > south)
  728. {
  729. if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0)))
  730. {
  731. fillArea[x, y] = true;
  732. allowed = true;
  733. }
  734. }
  735. }
  736. }
  737. }
  738. if (allowed)
  739. {
  740. StoreUndoState();
  741. m_floodeffects[(StandardTerrainEffects) action].FloodEffect(
  742. m_channel, fillArea, size);
  743. CheckForTerrainUpdates(!god); //revert changes outside estate limits
  744. }
  745. }
  746. else
  747. {
  748. m_log.Debug("Unknown terrain flood type " + action);
  749. }
  750. }
  751. }
  752. private void client_OnBakeTerrain(IClientAPI remoteClient)
  753. {
  754. // Not a good permissions check (see client_OnModifyTerrain above), need to check the entire area.
  755. // for now check a point in the centre of the region
  756. if (m_scene.Permissions.CanIssueEstateCommand(remoteClient.AgentId, true))
  757. {
  758. InterfaceBakeTerrain(null); //bake terrain does not use the passed in parameter
  759. }
  760. }
  761. protected void client_OnUnackedTerrain(IClientAPI client, int patchX, int patchY)
  762. {
  763. //m_log.Debug("Terrain packet unacked, resending patch: " + patchX + " , " + patchY);
  764. client.SendLayerData(patchX, patchY, m_scene.Heightmap.GetFloatsSerialised());
  765. }
  766. private void StoreUndoState()
  767. {
  768. lock (m_undo)
  769. {
  770. if (m_undo.Count > 0)
  771. {
  772. LandUndoState last = m_undo.Peek();
  773. if (last != null)
  774. {
  775. if (last.Compare(m_channel))
  776. return;
  777. }
  778. }
  779. LandUndoState nUndo = new LandUndoState(this, m_channel);
  780. m_undo.Push(nUndo);
  781. }
  782. }
  783. #region Console Commands
  784. private void InterfaceLoadFile(Object[] args)
  785. {
  786. LoadFromFile((string) args[0]);
  787. CheckForTerrainUpdates();
  788. }
  789. private void InterfaceLoadTileFile(Object[] args)
  790. {
  791. LoadFromFile((string) args[0],
  792. (int) args[1],
  793. (int) args[2],
  794. (int) args[3],
  795. (int) args[4]);
  796. CheckForTerrainUpdates();
  797. }
  798. private void InterfaceSaveFile(Object[] args)
  799. {
  800. SaveToFile((string) args[0]);
  801. }
  802. private void InterfaceSaveTileFile(Object[] args)
  803. {
  804. SaveToFile((string)args[0],
  805. (int)args[1],
  806. (int)args[2],
  807. (int)args[3],
  808. (int)args[4]);
  809. }
  810. private void InterfaceBakeTerrain(Object[] args)
  811. {
  812. UpdateRevertMap();
  813. }
  814. private void InterfaceRevertTerrain(Object[] args)
  815. {
  816. int x, y;
  817. for (x = 0; x < m_channel.Width; x++)
  818. for (y = 0; y < m_channel.Height; y++)
  819. m_channel[x, y] = m_revert[x, y];
  820. CheckForTerrainUpdates();
  821. }
  822. private void InterfaceFlipTerrain(Object[] args)
  823. {
  824. String direction = (String)args[0];
  825. if (direction.ToLower().StartsWith("y"))
  826. {
  827. for (int x = 0; x < Constants.RegionSize; x++)
  828. {
  829. for (int y = 0; y < Constants.RegionSize / 2; y++)
  830. {
  831. double height = m_channel[x, y];
  832. double flippedHeight = m_channel[x, (int)Constants.RegionSize - 1 - y];
  833. m_channel[x, y] = flippedHeight;
  834. m_channel[x, (int)Constants.RegionSize - 1 - y] = height;
  835. }
  836. }
  837. }
  838. else if (direction.ToLower().StartsWith("x"))
  839. {
  840. for (int y = 0; y < Constants.RegionSize; y++)
  841. {
  842. for (int x = 0; x < Constants.RegionSize / 2; x++)
  843. {
  844. double height = m_channel[x, y];
  845. double flippedHeight = m_channel[(int)Constants.RegionSize - 1 - x, y];
  846. m_channel[x, y] = flippedHeight;
  847. m_channel[(int)Constants.RegionSize - 1 - x, y] = height;
  848. }
  849. }
  850. }
  851. else
  852. {
  853. m_log.Error("Unrecognised direction - need x or y");
  854. }
  855. CheckForTerrainUpdates();
  856. }
  857. private void InterfaceRescaleTerrain(Object[] args)
  858. {
  859. double desiredMin = (double)args[0];
  860. double desiredMax = (double)args[1];
  861. // determine desired scaling factor
  862. double desiredRange = desiredMax - desiredMin;
  863. //m_log.InfoFormat("Desired {0}, {1} = {2}", new Object[] { desiredMin, desiredMax, desiredRange });
  864. if (desiredRange == 0d)
  865. {
  866. // delta is zero so flatten at requested height
  867. InterfaceFillTerrain(new Object[] { args[1] });
  868. }
  869. else
  870. {
  871. //work out current heightmap range
  872. double currMin = double.MaxValue;
  873. double currMax = double.MinValue;
  874. int width = m_channel.Width;
  875. int height = m_channel.Height;
  876. for (int x = 0; x < width; x++)
  877. {
  878. for (int y = 0; y < height; y++)
  879. {
  880. double currHeight = m_channel[x, y];
  881. if (currHeight < currMin)
  882. {
  883. currMin = currHeight;
  884. }
  885. else if (currHeight > currMax)
  886. {
  887. currMax = currHeight;
  888. }
  889. }
  890. }
  891. double currRange = currMax - currMin;
  892. double scale = desiredRange / currRange;
  893. //m_log.InfoFormat("Current {0}, {1} = {2}", new Object[] { currMin, currMax, currRange });
  894. //m_log.InfoFormat("Scale = {0}", scale);
  895. // scale the heightmap accordingly
  896. for (int x = 0; x < width; x++)
  897. {
  898. for (int y = 0; y < height; y++)
  899. {
  900. double currHeight = m_channel[x, y] - currMin;
  901. m_channel[x, y] = desiredMin + (currHeight * scale);
  902. }
  903. }
  904. CheckForTerrainUpdates();
  905. }
  906. }
  907. private void InterfaceElevateTerrain(Object[] args)
  908. {
  909. int x, y;
  910. for (x = 0; x < m_channel.Width; x++)
  911. for (y = 0; y < m_channel.Height; y++)
  912. m_channel[x, y] += (double) args[0];
  913. CheckForTerrainUpdates();
  914. }
  915. private void InterfaceMultiplyTerrain(Object[] args)
  916. {
  917. int x, y;
  918. for (x = 0; x < m_channel.Width; x++)
  919. for (y = 0; y < m_channel.Height; y++)
  920. m_channel[x, y] *= (double) args[0];
  921. CheckForTerrainUpdates();
  922. }
  923. private void InterfaceLowerTerrain(Object[] args)
  924. {
  925. int x, y;
  926. for (x = 0; x < m_channel.Width; x++)
  927. for (y = 0; y < m_channel.Height; y++)
  928. m_channel[x, y] -= (double) args[0];
  929. CheckForTerrainUpdates();
  930. }
  931. private void InterfaceFillTerrain(Object[] args)
  932. {
  933. int x, y;
  934. for (x = 0; x < m_channel.Width; x++)
  935. for (y = 0; y < m_channel.Height; y++)
  936. m_channel[x, y] = (double) args[0];
  937. CheckForTerrainUpdates();
  938. }
  939. private void InterfaceShowDebugStats(Object[] args)
  940. {
  941. double max = Double.MinValue;
  942. double min = double.MaxValue;
  943. double sum = 0;
  944. int x;
  945. for (x = 0; x < m_channel.Width; x++)
  946. {
  947. int y;
  948. for (y = 0; y < m_channel.Height; y++)
  949. {
  950. sum += m_channel[x, y];
  951. if (max < m_channel[x, y])
  952. max = m_channel[x, y];
  953. if (min > m_channel[x, y])
  954. min = m_channel[x, y];
  955. }
  956. }
  957. double avg = sum / (m_channel.Height * m_channel.Width);
  958. m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height);
  959. m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum);
  960. }
  961. private void InterfaceEnableExperimentalBrushes(Object[] args)
  962. {
  963. if ((bool) args[0])
  964. {
  965. m_painteffects[StandardTerrainEffects.Revert] = new WeatherSphere();
  966. m_painteffects[StandardTerrainEffects.Flatten] = new OlsenSphere();
  967. m_painteffects[StandardTerrainEffects.Smooth] = new ErodeSphere();
  968. }
  969. else
  970. {
  971. InstallDefaultEffects();
  972. }
  973. }
  974. private void InterfaceRunPluginEffect(Object[] args)
  975. {
  976. if ((string) args[0] == "list")
  977. {
  978. m_log.Info("List of loaded plugins");
  979. foreach (KeyValuePair<string, ITerrainEffect> kvp in m_plugineffects)
  980. {
  981. m_log.Info(kvp.Key);
  982. }
  983. return;
  984. }
  985. if ((string) args[0] == "reload")
  986. {
  987. LoadPlugins();
  988. return;
  989. }
  990. if (m_plugineffects.ContainsKey((string) args[0]))
  991. {
  992. m_plugineffects[(string) args[0]].RunEffect(m_channel);
  993. CheckForTerrainUpdates();
  994. }
  995. else
  996. {
  997. m_log.Warn("No such plugin effect loaded.");
  998. }
  999. }
  1000. private void InstallInterfaces()
  1001. {
  1002. // Load / Save
  1003. string supportedFileExtensions = "";
  1004. string supportedFilesSeparator = "";
  1005. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  1006. {
  1007. supportedFileExtensions += supportedFilesSeparator + loader.Key + " (" + loader.Value + ")";
  1008. supportedFilesSeparator = ", ";
  1009. }
  1010. Command loadFromFileCommand =
  1011. new Command("load", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadFile, "Loads a terrain from a specified file.");
  1012. loadFromFileCommand.AddArgument("filename",
  1013. "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
  1014. supportedFileExtensions, "String");
  1015. Command saveToFileCommand =
  1016. new Command("save", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveFile, "Saves the current heightmap to a specified file.");
  1017. saveToFileCommand.AddArgument("filename",
  1018. "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " +
  1019. supportedFileExtensions, "String");
  1020. Command loadFromTileCommand =
  1021. new Command("load-tile", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadTileFile, "Loads a terrain from a section of a larger file.");
  1022. loadFromTileCommand.AddArgument("filename",
  1023. "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
  1024. supportedFileExtensions, "String");
  1025. loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer");
  1026. loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer");
  1027. loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file",
  1028. "Integer");
  1029. loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file",
  1030. "Integer");
  1031. Command saveToTileCommand =
  1032. new Command("save-tile", CommandIntentions.COMMAND_HAZARDOUS, InterfaceSaveTileFile, "Saves the current heightmap to the larger file.");
  1033. saveToTileCommand.AddArgument("filename",
  1034. "The file you wish to save to, the file extension determines the loader to be used. Supported extensions include: " +
  1035. supportedFileExtensions, "String");
  1036. saveToTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer");
  1037. saveToTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer");
  1038. saveToTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file",
  1039. "Integer");
  1040. saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file",
  1041. "Integer");
  1042. // Terrain adjustments
  1043. Command fillRegionCommand =
  1044. new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value.");
  1045. fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.",
  1046. "Double");
  1047. Command elevateCommand =
  1048. new Command("elevate", CommandIntentions.COMMAND_HAZARDOUS, InterfaceElevateTerrain, "Raises the current heightmap by the specified amount.");
  1049. elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double");
  1050. Command lowerCommand =
  1051. new Command("lower", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount.");
  1052. lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double");
  1053. Command multiplyCommand =
  1054. new Command("multiply", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified.");
  1055. multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
  1056. Command bakeRegionCommand =
  1057. new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map.");
  1058. Command revertRegionCommand =
  1059. new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap.");
  1060. Command flipCommand =
  1061. new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis");
  1062. flipCommand.AddArgument("direction", "[x|y] the direction to flip the terrain in", "String");
  1063. Command rescaleCommand =
  1064. new Command("rescale", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRescaleTerrain, "Rescales the current terrain to fit between the given min and max heights");
  1065. rescaleCommand.AddArgument("min", "min terrain height after rescaling", "Double");
  1066. rescaleCommand.AddArgument("max", "max terrain height after rescaling", "Double");
  1067. // Debug
  1068. Command showDebugStatsCommand =
  1069. new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats,
  1070. "Shows some information about the regions heightmap for debugging purposes.");
  1071. Command experimentalBrushesCommand =
  1072. new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes,
  1073. "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
  1074. experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean");
  1075. //Plugins
  1076. Command pluginRunCommand =
  1077. new Command("effect", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRunPluginEffect, "Runs a specified plugin effect");
  1078. pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String");
  1079. m_commander.RegisterCommand("load", loadFromFileCommand);
  1080. m_commander.RegisterCommand("load-tile", loadFromTileCommand);
  1081. m_commander.RegisterCommand("save", saveToFileCommand);
  1082. m_commander.RegisterCommand("save-tile", saveToTileCommand);
  1083. m_commander.RegisterCommand("fill", fillRegionCommand);
  1084. m_commander.RegisterCommand("elevate", elevateCommand);
  1085. m_commander.RegisterCommand("lower", lowerCommand);
  1086. m_commander.RegisterCommand("multiply", multiplyCommand);
  1087. m_commander.RegisterCommand("bake", bakeRegionCommand);
  1088. m_commander.RegisterCommand("revert", revertRegionCommand);
  1089. m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
  1090. m_commander.RegisterCommand("stats", showDebugStatsCommand);
  1091. m_commander.RegisterCommand("effect", pluginRunCommand);
  1092. m_commander.RegisterCommand("flip", flipCommand);
  1093. m_commander.RegisterCommand("rescale", rescaleCommand);
  1094. // Add this to our scene so scripts can call these functions
  1095. m_scene.RegisterModuleCommander(m_commander);
  1096. }
  1097. #endregion
  1098. }
  1099. }