From 164706043d68108a6144abf306739cccfc3133a3 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 23 Mar 2012 13:11:58 -0700 Subject: [PATCH 1/7] Have the PhysicsParameters module output console command responses directly to the console rather than logging at INFO (which doesn't output anything for WARN). There should really be a WriteLine method on ICommandConsole so all of the different commands don't have to figure out where the command output should go. --- .../PhysicsParameters/PhysicsParameters.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs index a3f68e58c6..e45212444d 100755 --- a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs +++ b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs @@ -264,14 +264,14 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters private void WriteOut(string msg, params object[] args) { - m_log.InfoFormat(msg, args); - // MainConsole.Instance.OutputFormat(msg, args); + // m_log.InfoFormat(msg, args); + MainConsole.Instance.OutputFormat(msg, args); } private void WriteError(string msg, params object[] args) { - m_log.ErrorFormat(msg, args); - // MainConsole.Instance.OutputFormat(msg, args); + // m_log.ErrorFormat(msg, args); + MainConsole.Instance.OutputFormat(msg, args); } } -} \ No newline at end of file +} From cf61c74e90324e07cb4b15f9c597fef00c047c75 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 24 Mar 2012 02:16:44 +0000 Subject: [PATCH 2/7] Give feedback when "terrain save-tile" is not successfully invoked. --- OpenSim/Framework/RegionInfo.cs | 6 ++ .../World/Terrain/ITerrainLoader.cs | 15 ++++ .../World/Terrain/TerrainModule.cs | 73 ++++++++++--------- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs index 5ba3863529..a5055247c7 100644 --- a/OpenSim/Framework/RegionInfo.cs +++ b/OpenSim/Framework/RegionInfo.cs @@ -421,12 +421,18 @@ namespace OpenSim.Framework set { m_internalEndPoint = value; } } + /// + /// The x co-ordinate of this region in map tiles (e.g. 1000). + /// public uint RegionLocX { get { return m_regionLocX.Value; } set { m_regionLocX = value; } } + /// + /// The y co-ordinate of this region in map tiles (e.g. 1000). + /// public uint RegionLocY { get { return m_regionLocY.Value; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs index 7237f90a38..d407617ec5 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs @@ -38,6 +38,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain ITerrainChannel LoadStream(Stream stream); void SaveFile(string filename, ITerrainChannel map); void SaveStream(Stream stream, ITerrainChannel map); + + /// + /// Save a number of map tiles to a single big image file. + /// + /// + /// If the image file already exists then the tiles saved will replace those already in the file - other tiles + /// will be untouched. + /// + /// The terrain file to save + /// The map x co-ordinate at which to begin the save. + /// The may y co-ordinate at which to begin the save. + /// The number of tiles to save along the X axis. + /// The number of tiles to save along the Y axis. + /// The width of a map tile. + /// The height of a map tile. void SaveFile(ITerrainChannel map, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY); } } \ 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 9cd8f2beb3..7c5ea2975a 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs @@ -561,49 +561,56 @@ namespace OpenSim.Region.CoreModules.World.Terrain } /// - /// Saves the terrain to a larger terrain file. + /// Save a number of map tiles to a single big image file. /// + /// + /// If the image file already exists then the tiles saved will replace those already in the file - other tiles + /// will be untouched. + /// /// The terrain file to save - /// The width of the file in units - /// The height of the file in units - /// Where to begin our slice - /// Where to begin our slice + /// The number of tiles to save along the X axis. + /// The number of tiles to save along the Y axis. + /// The map x co-ordinate at which to begin the save. + /// The may y co-ordinate at which to begin the save. public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) { int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX; int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY; - if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) + if (offsetX < 0 || offsetX >= fileWidth || offsetY < 0 || offsetY >= fileHeight) { - // this region is included in the tile request - foreach (KeyValuePair loader in m_loaders) - { - if (filename.EndsWith(loader.Key)) - { - lock (m_scene) - { - loader.Value.SaveFile(m_channel, filename, offsetX, offsetY, - fileWidth, fileHeight, - (int)Constants.RegionSize, - (int)Constants.RegionSize); + MainConsole.Instance.OutputFormat( + "ERROR: file width + minimum X tile and file height + minimum Y tile must incorporate the current region at ({0},{1}). File width {2} from {3} and file height {4} from {5} does not.", + m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, fileWidth, fileStartX, fileHeight, fileStartY); - m_log.InfoFormat("[TERRAIN]: Saved terrain from {0} to {1}", m_scene.RegionInfo.RegionName, filename); - } - - return; - } - } - - m_log.ErrorFormat( - "[TERRAIN]: Could not save terrain from {0} to {1}. Valid file extensions are {2}", - m_scene.RegionInfo.RegionName, filename, m_supportedFileExtensions); + return; } -// else -// { -// m_log.ErrorFormat( -// "[TERRAIN]: Could not save terrain from {0} to {1}. {2} {3} {4} {5} {6} {7}", -// m_scene.RegionInfo.RegionName, filename, fileWidth, fileHeight, fileStartX, fileStartY, offsetX, offsetY); -// } + + // this region is included in the tile request + foreach (KeyValuePair loader in m_loaders) + { + if (filename.EndsWith(loader.Key)) + { + lock (m_scene) + { + loader.Value.SaveFile(m_channel, filename, offsetX, offsetY, + fileWidth, fileHeight, + (int)Constants.RegionSize, + (int)Constants.RegionSize); + + MainConsole.Instance.OutputFormat( + "Saved terrain from ({0},{1}) to ({2},{3}) from {4} to {5}", + fileStartX, fileStartY, fileStartX + fileWidth - 1, fileStartY + fileHeight - 1, + m_scene.RegionInfo.RegionName, filename); + } + + return; + } + } + + MainConsole.Instance.OutputFormat( + "ERROR: Could not save terrain from {0} to {1}. Valid file extensions are {2}", + m_scene.RegionInfo.RegionName, filename, m_supportedFileExtensions); } /// From f53c6b25940a51fce208b3dae21fad49ab8d1efe Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 24 Mar 2012 02:30:21 +0000 Subject: [PATCH 3/7] Use system provided temporary file in "terrain save-tile" to avoid problems with drive letters on windows Thanks to Garmin Kawaguichi for picking up on this and providing an initial solution (which I adapted). --- .../World/Terrain/FileLoaders/GenericSystemDrawing.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index 21a9999ba0..58925fd624 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs @@ -132,13 +132,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { // We need to do this because: // "Saving the image to the same file it was constructed from is not allowed and throws an exception." - string tempName = offsetX + "_ " + offsetY + "_" + filename; + string tempName = Path.GetTempFileName(); Bitmap entireBitmap = null; Bitmap thisBitmap = null; if (File.Exists(filename)) { - File.Copy(filename, tempName); + File.Copy(filename, tempName, true); entireBitmap = new Bitmap(tempName); if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY) { @@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders } thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); - Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); +// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); for (int x = 0; x < regionSizeX; x++) for (int y = 0; y < regionSizeY; y++) entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); From f03c3c062e7829309d76ac76d5d2b2e7bc8b62dc Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 24 Mar 2012 02:41:45 +0000 Subject: [PATCH 4/7] Hack example on to "terrain save-tile" extended help. Thanks to Garmin Kawaguichi for the initially suggested text. --- OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index 7c5ea2975a..17e97372b0 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs @@ -1199,6 +1199,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain "Integer"); saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", "Integer"); + saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first tile on the file\n" + + "= Example =\n" + + "To save a PNG file for a set of map tiles 2 regions wide and 3 regions high from map co-ordinate (9910,10234)\n" + + " # terrain save-tile ST06.png 2 3 9910 10234\n", + "Integer"); + // Terrain adjustments Command fillRegionCommand = new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); From 4f17537555856823cd3c3cc80708cc1d8bc574b4 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 24 Mar 2012 03:07:01 +0000 Subject: [PATCH 5/7] Allow the user to enter help topics in upper or lowercase. Forcing uppercase (e.g. help Assets) is too annoying. Thanks to WhiteStar for pointing this out. --- OpenSim/Framework/Console/CommandConsole.cs | 22 +++++++++++---------- OpenSim/Region/Application/OpenSimBase.cs | 11 ++++++----- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index 2bb7de1cae..c5d6b78686 100644 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs @@ -188,19 +188,21 @@ namespace OpenSim.Framework.Console { lock (m_modulesCommands) { - if (m_modulesCommands.ContainsKey(moduleName)) + foreach (string key in m_modulesCommands.Keys) { - List commands = m_modulesCommands[moduleName]; - var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help)); - ourHelpText.Sort(); - helpText.AddRange(ourHelpText); + // Allow topic help requests to succeed whether they are upper or lowercase. + if (moduleName.ToLower() == key.ToLower()) + { + List commands = m_modulesCommands[key]; + var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help)); + ourHelpText.Sort(); + helpText.AddRange(ourHelpText); - return true; - } - else - { - return false; + return true; + } } + + return false; } } diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 484159ce15..5de3f25b7d 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -248,15 +248,16 @@ namespace OpenSim { string capitalizedTopic = char.ToUpper(topic[0]) + topic.Substring(1); + // This is a hack to allow the user to enter the help command in upper or lowercase. This will go + // away at some point. + m_console.Commands.AddCommand(capitalizedTopic, false, "help " + topic, + "help " + capitalizedTopic, + "Get help on plugin command '" + topic + "'", + HandleCommanderHelp); m_console.Commands.AddCommand(capitalizedTopic, false, "help " + capitalizedTopic, "help " + capitalizedTopic, "Get help on plugin command '" + topic + "'", HandleCommanderHelp); -// -// m_console.Commands.AddCommand("General", false, topic, -// topic, -// "Execute subcommand for plugin '" + topic + "'", -// null); ICommander commander = null; From a14437ad5abf4d4dc95897216224548515a599e7 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Sat, 24 Mar 2012 22:43:42 -0700 Subject: [PATCH 6/7] Add support for key, vector, rotation and list types for both arguments and return values to the modInvoke family of functions. See http://opensimulator.org/wiki/OSSL_Script_Library/ModInvoke --- .../ScriptModuleCommsModule.cs | 8 + .../Shared/Api/Implementation/MOD_Api.cs | 245 ++++++++++++++---- .../Shared/Api/Interface/IMOD_Api.cs | 26 +- .../Shared/Api/Runtime/MOD_Stub.cs | 34 ++- 4 files changed, 238 insertions(+), 75 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index a90362e974..0661c6575c 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -147,6 +147,14 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms return "modInvokeI"; else if (sid.ReturnType == typeof(float)) return "modInvokeF"; + else if (sid.ReturnType == typeof(UUID)) + return "modInvokeK"; + else if (sid.ReturnType == typeof(OpenMetaverse.Vector3)) + return "modInvokeV"; + else if (sid.ReturnType == typeof(OpenMetaverse.Quaternion)) + return "modInvokeR"; + else if (sid.ReturnType == typeof(object[])) + return "modInvokeL"; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 294210419b..1bcbcd3e1e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -120,33 +120,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// /// /// The name of the function to invoke - /// List of parameters + /// List of parameters /// string result of the invocation - public string modInvokeS(string fname, params object[] parms) + public LSL_String modInvokeS(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(string)) MODError(String.Format("return type mismatch for {0}",fname)); - return (string)modInvoke(fname,parms); + string result = (string)modInvoke(fname,parms); + return new LSL_String(result); } - public int modInvokeI(string fname, params object[] parms) + public LSL_Integer modInvokeI(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(int)) MODError(String.Format("return type mismatch for {0}",fname)); - return (int)modInvoke(fname,parms); + int result = (int)modInvoke(fname,parms); + return new LSL_Integer(result); } - public float modInvokeF(string fname, params object[] parms) + public LSL_Float modInvokeF(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(float)) MODError(String.Format("return type mismatch for {0}",fname)); - return (float)modInvoke(fname,parms); + float result = (float)modInvoke(fname,parms); + return new LSL_Float(result); + } + + public LSL_Key modInvokeK(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(UUID)) + MODError(String.Format("return type mismatch for {0}",fname)); + + UUID result = (UUID)modInvoke(fname,parms); + return new LSL_Key(result.ToString()); + } + + public LSL_Vector modInvokeV(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(OpenMetaverse.Vector3)) + MODError(String.Format("return type mismatch for {0}",fname)); + + OpenMetaverse.Vector3 result = (OpenMetaverse.Vector3)modInvoke(fname,parms); + return new LSL_Vector(result.X,result.Y,result.Z); + } + + public LSL_Rotation modInvokeR(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(OpenMetaverse.Quaternion)) + MODError(String.Format("return type mismatch for {0}",fname)); + + OpenMetaverse.Quaternion result = (OpenMetaverse.Quaternion)modInvoke(fname,parms); + return new LSL_Rotation(result.X,result.Y,result.Z,result.W); + } + + public LSL_List modInvokeL(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(object[])) + MODError(String.Format("return type mismatch for {0}",fname)); + + object[] result = (object[])modInvoke(fname,parms); + object[] llist = new object[result.Length]; + for (int i = 0; i < result.Length; i++) + { + if (result[i] is string) + llist[i] = new LSL_String((string)result[i]); + else if (result[i] is int) + llist[i] = new LSL_Integer((int)result[i]); + else if (result[i] is float) + llist[i] = new LSL_Float((float)result[i]); + else if (result[i] is OpenMetaverse.Vector3) + { + OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i]; + llist[i] = new LSL_Vector(vresult.X,vresult.Y,vresult.Z); + } + else if (result[i] is OpenMetaverse.Quaternion) + { + OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i]; + llist[i] = new LSL_Rotation(qresult.X,qresult.Y,qresult.Z,qresult.W); + } + else + { + MODError(String.Format("unknown list element returned by {0}",fname)); + } + } + + return new LSL_List(llist); } /// @@ -168,63 +236,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api MODError(String.Format("wrong number of parameters to function {0}",fname)); object[] convertedParms = new object[parms.Length]; - for (int i = 0; i < parms.Length; i++) + convertedParms[i] = ConvertFromLSL(parms[i],signature[i]); + + // now call the function, the contract with the function is that it will always return + // non-null but don't trust it completely + try { - if (parms[i] is LSL_String) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + object result = m_comms.InvokeOperation(m_itemID,fname,convertedParms); + if (result != null) + return result; - convertedParms[i] = (string)(LSL_String)parms[i]; - } - else if (parms[i] is LSL_Integer) - { - if (signature[i] != typeof(int)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (int)(LSL_Integer)parms[i]; - } - else if (parms[i] is LSL_Float) - { - if (signature[i] != typeof(float)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (float)(LSL_Float)parms[i]; - } - else if (parms[i] is LSL_Key) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_Key)parms[i]; - } - else if (parms[i] is LSL_Rotation) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_Rotation)parms[i]; - } - else if (parms[i] is LSL_Vector) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_Vector)parms[i]; - } - else - { - if (signature[i] != parms[i].GetType()) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = parms[i]; - } + MODError(String.Format("Invocation of {0} failed; null return value",fname)); + } + catch (Exception e) + { + MODError(String.Format("Invocation of {0} failed; {1}",fname,e.Message)); } - return m_comms.InvokeOperation(m_itemID,fname,convertedParms); + return null; } + /// + /// Send a command to functions registered on an event + /// public string modSendCommand(string module, string command, string k) { if (!m_MODFunctionsEnabled) @@ -239,5 +274,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return req.ToString(); } + + /// + /// + protected object ConvertFromLSL(object lslparm, Type type) + { + // ---------- String ---------- + if (lslparm is LSL_String) + { + if (type == typeof(string)) + return (string)(LSL_String)lslparm; + + // Need to check for UUID since keys are often treated as strings + if (type == typeof(UUID)) + return new UUID((string)(LSL_String)lslparm); + } + + // ---------- Integer ---------- + else if (lslparm is LSL_Integer) + { + if (type == typeof(int)) + return (int)(LSL_Integer)lslparm; + } + + // ---------- Float ---------- + else if (lslparm is LSL_Float) + { + if (type == typeof(float)) + return (float)(LSL_Float)lslparm; + } + + // ---------- Key ---------- + else if (lslparm is LSL_Key) + { + if (type == typeof(UUID)) + return new UUID((LSL_Key)lslparm); + } + + // ---------- Rotation ---------- + else if (lslparm is LSL_Rotation) + { + if (type == typeof(OpenMetaverse.Quaternion)) + { + LSL_Rotation rot = (LSL_Rotation)lslparm; + return new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s); + } + } + + // ---------- Vector ---------- + else if (lslparm is LSL_Vector) + { + if (type == typeof(OpenMetaverse.Vector3)) + { + LSL_Vector vect = (LSL_Vector)lslparm; + return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + } + } + + // ---------- List ---------- + else if (lslparm is LSL_List) + { + if (type == typeof(object[])) + { + object[] plist = (lslparm as LSL_List).Data; + object[] result = new object[plist.Length]; + for (int i = 0; i < plist.Length; i++) + { + if (plist[i] is LSL_String) + result[i] = (string)(LSL_String)plist[i]; + else if (plist[i] is LSL_Integer) + result[i] = (int)(LSL_Integer)plist[i]; + else if (plist[i] is LSL_Float) + result[i] = (float)(LSL_Float)plist[i]; + else if (plist[i] is LSL_Key) + result[i] = new UUID((LSL_Key)plist[i]); + else if (plist[i] is LSL_Rotation) + { + LSL_Rotation rot = (LSL_Rotation)plist[i]; + result[i] = new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s); + } + else if (plist[i] is LSL_Vector) + { + LSL_Vector vect = (LSL_Vector)plist[i]; + result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + } + else + MODError("unknown LSL list element type"); + } + + return result; + } + } + + MODError(String.Format("parameter type mismatch; expecting {0}",type.Name)); + return null; + } + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs index 756a59f3e7..d258f76841 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs @@ -28,26 +28,26 @@ using System.Collections; using OpenSim.Region.ScriptEngine.Interfaces; -using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; -using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; -using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; -using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; +using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; +using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; +using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces { public interface IMOD_Api { // Invocation functions - string modInvokeS(string fname, params object[] parms); - int modInvokeI(string fname, params object[] parms); - float modInvokeF(string fname, params object[] parms); - // vector modInvokeV(string fname, params object[] parms); - // rotation modInvokeV(string fname, params object[] parms); - // key modInvokeK(string fname, params object[] parms); - // list modInvokeL(string fname, params object[] parms); + LSL_String modInvokeS(string fname, params object[] parms); + LSL_Integer modInvokeI(string fname, params object[] parms); + LSL_Float modInvokeF(string fname, params object[] parms); + LSL_Key modInvokeK(string fname, params object[] parms); + LSL_Vector modInvokeV(string fname, params object[] parms); + LSL_Rotation modInvokeR(string fname, params object[] parms); + LSL_List modInvokeL(string fname, params object[] parms); //Module functions string modSendCommand(string modules, string command, string k); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs index 04b7f14b4e..e7a4b2b524 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs @@ -39,10 +39,14 @@ using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; -using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; + using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; +using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; +using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { @@ -58,21 +62,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_MOD_Functions = (IMOD_Api)api; } - public string modInvokeS(string fname, params object[] parms) + public LSL_String modInvokeS(string fname, params object[] parms) { return m_MOD_Functions.modInvokeS(fname, parms); } - public int modInvokeI(string fname, params object[] parms) + public LSL_Integer modInvokeI(string fname, params object[] parms) { return m_MOD_Functions.modInvokeI(fname, parms); } - public float modInvokeF(string fname, params object[] parms) + public LSL_Float modInvokeF(string fname, params object[] parms) { return m_MOD_Functions.modInvokeF(fname, parms); } + public LSL_Key modInvokeK(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeK(fname, parms); + } + + public LSL_Vector modInvokeV(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeV(fname, parms); + } + + public LSL_Rotation modInvokeR(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeR(fname, parms); + } + + public LSL_List modInvokeL(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeL(fname, parms); + } + public string modSendCommand(string module, string command, string k) { return m_MOD_Functions.modSendCommand(module, command, k); From cb44808504e48125d630823880ee8e710afcd9ea Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 25 Mar 2012 19:52:38 +0100 Subject: [PATCH 7/7] Simplify the module invocation registration. The types and method name can be pulled fromt he delegate so we don't need to pass them explicitly --- .../Interfaces/IScriptModuleComms.cs | 3 ++- .../ScriptModuleCommsModule.cs | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index bb4c7885f5..8bfbbf8c32 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs @@ -46,7 +46,8 @@ namespace OpenSim.Region.Framework.Interfaces /// event ScriptCommand OnScriptCommand; - void RegisterScriptInvocation(string name, ScriptInvocation fn, Type[] csig, Type rsig); + void RegisterScriptInvocation(ScriptInvocation fn); + ScriptInvocation[] GetScriptInvocationList(); ScriptInvocation LookupScriptInvocation(string fname); string LookupModInvocation(string fname); diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 0661c6575c..8e8a0b63d8 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -126,14 +126,30 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms m_scriptModule.PostScriptEvent(script, "link_message", args); } - public void RegisterScriptInvocation(string fname, ScriptInvocation fcall, Type[] csig, Type rsig) + public void RegisterScriptInvocation(ScriptInvocation fcall) { lock (m_scriptInvocation) { - m_scriptInvocation[fname] = new ScriptInvocationData(fname,fcall,csig,rsig); + ParameterInfo[] parameters = fcall.Method.GetParameters (); + Type[] parmTypes = new Type[parameters.Length]; + for (int i = 0 ; i < parameters.Length ; i++) + parmTypes[i] = parameters[i].ParameterType; + m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); } } + public ScriptInvocation[] GetScriptInvocationList() + { + List ret = new List(); + + lock (m_scriptInvocation) + { + foreach (ScriptInvocationData d in m_scriptInvocation.Values) + ret.Add(d.ScriptInvocationFn); + } + return ret.ToArray(); + } + public string LookupModInvocation(string fname) { lock (m_scriptInvocation)