aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-04-30 18:04:47 +0100
committerJustin Clark-Casey (justincc)2014-04-30 18:04:47 +0100
commit253110293a785b6dda94147cbfc3343fb8ca0434 (patch)
tree74bdc4c7070fb7c8db6b459cad78522d00d79b73
parentminor: convert back some tabs to spaces that got into ScenePresence via recen... (diff)
downloadopensim-SC-253110293a785b6dda94147cbfc3343fb8ca0434.zip
opensim-SC-253110293a785b6dda94147cbfc3343fb8ca0434.tar.gz
opensim-SC-253110293a785b6dda94147cbfc3343fb8ca0434.tar.bz2
opensim-SC-253110293a785b6dda94147cbfc3343fb8ca0434.tar.xz
Add "terrain show" console command which outputs terrain height for a given region co-ordinate.
For debug purposes.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/ConsoleUtil.cs78
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs22
2 files changed, 87 insertions, 13 deletions
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index 794bfaf..b7a3494 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -252,24 +252,80 @@ namespace OpenSim.Framework.Console
252 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue 252 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
253 /// Other than that, component values must be numeric. 253 /// Other than that, component values must be numeric.
254 /// </param> 254 /// </param>
255 /// <param name='blankComponentFunc'></param> 255 /// <param name='blankComponentFunc'>
256 /// Behaviour if component is blank. If null then conversion fails on a blank component.
257 /// </param>
256 /// <param name='vector'></param> 258 /// <param name='vector'></param>
257 /// <returns></returns> 259 /// <returns></returns>
258 public static bool TryParseConsoleVector( 260 public static bool TryParseConsoleVector(
259 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector) 261 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector)
260 { 262 {
261 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList(); 263 return Vector3.TryParse(CookVector(rawConsoleVector, 3, blankComponentFunc), out vector);
262 264 }
263 if (components.Count < 1 || components.Count > 3) 265
266 /// <summary>
267 /// Convert a vector input from the console to an OpenMetaverse.Vector2
268 /// </summary>
269 /// <param name='rawConsoleVector'>
270 /// A string in the form <x>,<y> where there is no space between values.
271 /// Any component can be missing (e.g. ,40). blankComponentFunc is invoked to replace the blank with a suitable value
272 /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40)
273 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
274 /// Other than that, component values must be numeric.
275 /// </param>
276 /// <param name='blankComponentFunc'>
277 /// Behaviour if component is blank. If null then conversion fails on a blank component.
278 /// </param>
279 /// <param name='vector'></param>
280 /// <returns></returns>
281 public static bool TryParseConsole2DVector(
282 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector2 vector)
283 {
284 // We don't use Vector2.TryParse() for now because for some reason it expects an input with 3 components
285 // rather than 2.
286 string cookedVector = CookVector(rawConsoleVector, 2, blankComponentFunc);
287
288 if (cookedVector == null)
264 { 289 {
265 vector = Vector3.Zero;
266 return false; 290 return false;
267 } 291 }
292 else
293 {
294 string[] cookedComponents = cookedVector.Split(VectorSeparatorChars);
295
296 vector = new Vector2(float.Parse(cookedComponents[0]), float.Parse(cookedComponents[1]));
297
298 return true;
299 }
300
301 //return Vector2.TryParse(CookVector(rawConsoleVector, 2, blankComponentFunc), out vector);
302 }
303
304 /// <summary>
305 /// Convert a raw console vector into a vector that can be be parsed by the relevant OpenMetaverse.TryParse()
306 /// </summary>
307 /// <param name='rawConsoleVector'></param>
308 /// <param name='dimensions'></param>
309 /// <param name='blankComponentFunc'></param>
310 /// <returns>null if conversion was not possible</returns>
311 private static string CookVector(
312 string rawConsoleVector, int dimensions, Func<string, string> blankComponentFunc)
313 {
314 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
268 315
269 for (int i = components.Count; i < 3; i++) 316 if (components.Count < 1 || components.Count > dimensions)
270 components.Add(""); 317 return null;
271 318
272 List<string> semiDigestedComponents 319 if (components.Count < dimensions)
320 {
321 if (blankComponentFunc == null)
322 return null;
323 else
324 for (int i = components.Count; i < dimensions; i++)
325 components.Add("");
326 }
327
328 List<string> cookedComponents
273 = components.ConvertAll<string>( 329 = components.ConvertAll<string>(
274 c => 330 c =>
275 { 331 {
@@ -283,11 +339,7 @@ namespace OpenSim.Framework.Console
283 return c; 339 return c;
284 }); 340 });
285 341
286 string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); 342 return string.Join(VectorSeparator, cookedComponents.ToArray());
287
288 // m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector);
289
290 return Vector3.TryParse(semiDigestedConsoleVector, out vector);
291 } 343 }
292 } 344 }
293} \ No newline at end of file 345} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 3901482..ae6fdac 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -39,6 +39,7 @@ using Mono.Addins;
39 39
40using OpenSim.Data; 40using OpenSim.Data;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.Console;
42using OpenSim.Region.CoreModules.Framework.InterfaceCommander; 43using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
43using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; 44using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
44using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; 45using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes;
@@ -1203,6 +1204,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1203 } 1204 }
1204 } 1205 }
1205 1206
1207 private void InterfaceShow(Object[] args)
1208 {
1209 Vector2 point;
1210
1211 if (!ConsoleUtil.TryParseConsole2DVector((string)args[0], null, out point))
1212 {
1213 Console.WriteLine("ERROR: {0} is not a valid vector", args[0]);
1214 return;
1215 }
1216
1217 double height = m_channel[(int)point.X, (int)point.Y];
1218
1219 Console.WriteLine("Terrain height at {0} is {1}", point, height);
1220 }
1221
1206 private void InterfaceShowDebugStats(Object[] args) 1222 private void InterfaceShowDebugStats(Object[] args)
1207 { 1223 {
1208 double max = Double.MinValue; 1224 double max = Double.MinValue;
@@ -1355,6 +1371,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1355 new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, 1371 new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats,
1356 "Shows some information about the regions heightmap for debugging purposes."); 1372 "Shows some information about the regions heightmap for debugging purposes.");
1357 1373
1374 Command showCommand =
1375 new Command("show", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceShow,
1376 "Shows terrain height at a given co-ordinate.");
1377 showCommand.AddArgument("point", "point in <x>,<y> format with no spaces (e.g. 45,45)", "String");
1378
1358 Command experimentalBrushesCommand = 1379 Command experimentalBrushesCommand =
1359 new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes, 1380 new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes,
1360 "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); 1381 "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
@@ -1376,6 +1397,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1376 m_commander.RegisterCommand("bake", bakeRegionCommand); 1397 m_commander.RegisterCommand("bake", bakeRegionCommand);
1377 m_commander.RegisterCommand("revert", revertRegionCommand); 1398 m_commander.RegisterCommand("revert", revertRegionCommand);
1378 m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand); 1399 m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
1400 m_commander.RegisterCommand("show", showCommand);
1379 m_commander.RegisterCommand("stats", showDebugStatsCommand); 1401 m_commander.RegisterCommand("stats", showDebugStatsCommand);
1380 m_commander.RegisterCommand("effect", pluginRunCommand); 1402 m_commander.RegisterCommand("effect", pluginRunCommand);
1381 m_commander.RegisterCommand("flip", flipCommand); 1403 m_commander.RegisterCommand("flip", flipCommand);