From 253110293a785b6dda94147cbfc3343fb8ca0434 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 30 Apr 2014 18:04:47 +0100
Subject: Add "terrain show" console command which outputs terrain height for a
given region co-ordinate.
For debug purposes.
---
OpenSim/Framework/Console/ConsoleUtil.cs | 78 ++++++++++++++++++----
.../CoreModules/World/Terrain/TerrainModule.cs | 22 ++++++
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
/// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
/// Other than that, component values must be numeric.
///
- ///
+ ///
+ /// Behaviour if component is blank. If null then conversion fails on a blank component.
+ ///
///
///
public static bool TryParseConsoleVector(
string rawConsoleVector, Func blankComponentFunc, out Vector3 vector)
{
- List components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
-
- if (components.Count < 1 || components.Count > 3)
+ return Vector3.TryParse(CookVector(rawConsoleVector, 3, blankComponentFunc), out vector);
+ }
+
+ ///
+ /// Convert a vector input from the console to an OpenMetaverse.Vector2
+ ///
+ ///
+ /// A string in the form , where there is no space between values.
+ /// Any component can be missing (e.g. ,40). blankComponentFunc is invoked to replace the blank with a suitable value
+ /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40)
+ /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
+ /// Other than that, component values must be numeric.
+ ///
+ ///
+ /// Behaviour if component is blank. If null then conversion fails on a blank component.
+ ///
+ ///
+ ///
+ public static bool TryParseConsole2DVector(
+ string rawConsoleVector, Func blankComponentFunc, out Vector2 vector)
+ {
+ // We don't use Vector2.TryParse() for now because for some reason it expects an input with 3 components
+ // rather than 2.
+ string cookedVector = CookVector(rawConsoleVector, 2, blankComponentFunc);
+
+ if (cookedVector == null)
{
- vector = Vector3.Zero;
return false;
}
+ else
+ {
+ string[] cookedComponents = cookedVector.Split(VectorSeparatorChars);
+
+ vector = new Vector2(float.Parse(cookedComponents[0]), float.Parse(cookedComponents[1]));
+
+ return true;
+ }
+
+ //return Vector2.TryParse(CookVector(rawConsoleVector, 2, blankComponentFunc), out vector);
+ }
+
+ ///
+ /// Convert a raw console vector into a vector that can be be parsed by the relevant OpenMetaverse.TryParse()
+ ///
+ ///
+ ///
+ ///
+ /// null if conversion was not possible
+ private static string CookVector(
+ string rawConsoleVector, int dimensions, Func blankComponentFunc)
+ {
+ List components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
- for (int i = components.Count; i < 3; i++)
- components.Add("");
+ if (components.Count < 1 || components.Count > dimensions)
+ return null;
- List semiDigestedComponents
+ if (components.Count < dimensions)
+ {
+ if (blankComponentFunc == null)
+ return null;
+ else
+ for (int i = components.Count; i < dimensions; i++)
+ components.Add("");
+ }
+
+ List cookedComponents
= components.ConvertAll(
c =>
{
@@ -283,11 +339,7 @@ namespace OpenSim.Framework.Console
return c;
});
- string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray());
-
- // m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector);
-
- return Vector3.TryParse(semiDigestedConsoleVector, out vector);
+ return string.Join(VectorSeparator, cookedComponents.ToArray());
}
}
}
\ 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;
using OpenSim.Data;
using OpenSim.Framework;
+using OpenSim.Framework.Console;
using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes;
@@ -1203,6 +1204,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain
}
}
+ private void InterfaceShow(Object[] args)
+ {
+ Vector2 point;
+
+ if (!ConsoleUtil.TryParseConsole2DVector((string)args[0], null, out point))
+ {
+ Console.WriteLine("ERROR: {0} is not a valid vector", args[0]);
+ return;
+ }
+
+ double height = m_channel[(int)point.X, (int)point.Y];
+
+ Console.WriteLine("Terrain height at {0} is {1}", point, height);
+ }
+
private void InterfaceShowDebugStats(Object[] args)
{
double max = Double.MinValue;
@@ -1355,6 +1371,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats,
"Shows some information about the regions heightmap for debugging purposes.");
+ Command showCommand =
+ new Command("show", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceShow,
+ "Shows terrain height at a given co-ordinate.");
+ showCommand.AddArgument("point", "point in , format with no spaces (e.g. 45,45)", "String");
+
Command experimentalBrushesCommand =
new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes,
"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
m_commander.RegisterCommand("bake", bakeRegionCommand);
m_commander.RegisterCommand("revert", revertRegionCommand);
m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
+ m_commander.RegisterCommand("show", showCommand);
m_commander.RegisterCommand("stats", showDebugStatsCommand);
m_commander.RegisterCommand("effect", pluginRunCommand);
m_commander.RegisterCommand("flip", flipCommand);
--
cgit v1.1