Add "terrain show" console command which outputs terrain height for a given region co-ordinate.

For debug purposes.
0.8.0.3
Justin Clark-Casey (justincc) 2014-04-30 18:04:47 +01:00
parent 5fc61942e0
commit 253110293a
2 changed files with 87 additions and 13 deletions

View File

@ -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 /// 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. /// Other than that, component values must be numeric.
/// </param> /// </param>
/// <param name='blankComponentFunc'></param> /// <param name='blankComponentFunc'>
/// Behaviour if component is blank. If null then conversion fails on a blank component.
/// </param>
/// <param name='vector'></param> /// <param name='vector'></param>
/// <returns></returns> /// <returns></returns>
public static bool TryParseConsoleVector( public static bool TryParseConsoleVector(
string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector) string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector)
{ {
List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList(); return Vector3.TryParse(CookVector(rawConsoleVector, 3, blankComponentFunc), out vector);
if (components.Count < 1 || components.Count > 3)
{
vector = Vector3.Zero;
return false;
} }
for (int i = components.Count; i < 3; i++) /// <summary>
components.Add(""); /// Convert a vector input from the console to an OpenMetaverse.Vector2
/// </summary>
/// <param name='rawConsoleVector'>
/// A string in the form <x>,<y> 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.
/// </param>
/// <param name='blankComponentFunc'>
/// Behaviour if component is blank. If null then conversion fails on a blank component.
/// </param>
/// <param name='vector'></param>
/// <returns></returns>
public static bool TryParseConsole2DVector(
string rawConsoleVector, Func<string, string> 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);
List<string> semiDigestedComponents if (cookedVector == null)
{
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);
}
/// <summary>
/// Convert a raw console vector into a vector that can be be parsed by the relevant OpenMetaverse.TryParse()
/// </summary>
/// <param name='rawConsoleVector'></param>
/// <param name='dimensions'></param>
/// <param name='blankComponentFunc'></param>
/// <returns>null if conversion was not possible</returns>
private static string CookVector(
string rawConsoleVector, int dimensions, Func<string, string> blankComponentFunc)
{
List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
if (components.Count < 1 || components.Count > dimensions)
return null;
if (components.Count < dimensions)
{
if (blankComponentFunc == null)
return null;
else
for (int i = components.Count; i < dimensions; i++)
components.Add("");
}
List<string> cookedComponents
= components.ConvertAll<string>( = components.ConvertAll<string>(
c => c =>
{ {
@ -283,11 +339,7 @@ namespace OpenSim.Framework.Console
return c; return c;
}); });
string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); return string.Join(VectorSeparator, cookedComponents.ToArray());
// m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector);
return Vector3.TryParse(semiDigestedConsoleVector, out vector);
} }
} }
} }

View File

@ -39,6 +39,7 @@ using Mono.Addins;
using OpenSim.Data; using OpenSim.Data;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.CoreModules.Framework.InterfaceCommander; using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; 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) private void InterfaceShowDebugStats(Object[] args)
{ {
double max = Double.MinValue; double max = Double.MinValue;
@ -1355,6 +1371,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats,
"Shows some information about the regions heightmap for debugging purposes."); "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 <x>,<y> format with no spaces (e.g. 45,45)", "String");
Command experimentalBrushesCommand = Command experimentalBrushesCommand =
new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes, 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."); "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("bake", bakeRegionCommand);
m_commander.RegisterCommand("revert", revertRegionCommand); m_commander.RegisterCommand("revert", revertRegionCommand);
m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand); m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
m_commander.RegisterCommand("show", showCommand);
m_commander.RegisterCommand("stats", showDebugStatsCommand); m_commander.RegisterCommand("stats", showDebugStatsCommand);
m_commander.RegisterCommand("effect", pluginRunCommand); m_commander.RegisterCommand("effect", pluginRunCommand);
m_commander.RegisterCommand("flip", flipCommand); m_commander.RegisterCommand("flip", flipCommand);