From e9153e1d1aae50024d8cd05fe14a9bce34343a0e Mon Sep 17 00:00:00 2001 From: teravus Date: Thu, 15 Nov 2012 10:05:16 -0500 Subject: Revert "Merge master into teravuswork", it should have been avination, not master. This reverts commit dfac269032300872c4d0dc507f4f9062d102b0f4, reversing changes made to 619c39e5144f15aca129d6d999bcc5c34133ee64. --- .../Scripting/DynamicTexture/DynamicTexture.cs | 61 ---- .../DynamicTexture/DynamicTextureModule.cs | 277 ++++----------- .../CoreModules/Scripting/LSLHttp/UrlModule.cs | 17 - .../Scripting/LoadImageURL/LoadImageURLModule.cs | 49 +-- .../ScriptModuleComms/ScriptModuleCommsModule.cs | 383 --------------------- .../VectorRender/Tests/VectorRenderModuleTests.cs | 281 +-------------- .../Scripting/VectorRender/VectorRenderModule.cs | 159 +++------ .../Scripting/WorldComm/WorldCommModule.cs | 133 ++----- 8 files changed, 159 insertions(+), 1201 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs delete mode 100644 OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs (limited to 'OpenSim/Region/CoreModules/Scripting') diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs deleted file mode 100644 index fce9490..0000000 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Drawing; -using OpenSim.Region.Framework.Interfaces; - -namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture -{ - public class DynamicTexture : IDynamicTexture - { - public string InputCommands { get; private set; } - public Uri InputUri { get; private set; } - public string InputParams { get; private set; } - public byte[] Data { get; private set; } - public Size Size { get; private set; } - public bool IsReuseable { get; private set; } - - public DynamicTexture(string inputCommands, string inputParams, byte[] data, Size size, bool isReuseable) - { - InputCommands = inputCommands; - InputParams = inputParams; - Data = data; - Size = size; - IsReuseable = isReuseable; - } - - public DynamicTexture(Uri inputUri, string inputParams, byte[] data, Size size, bool isReuseable) - { - InputUri = inputUri; - InputParams = inputParams; - Data = data; - Size = size; - IsReuseable = isReuseable; - } - } -} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 93a045e..18bd018 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -42,29 +42,13 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture { public class DynamicTextureModule : IRegionModule, IDynamicTextureManager { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private const int ALL_SIDES = -1; public const int DISP_EXPIRE = 1; public const int DISP_TEMP = 2; - /// - /// If true then where possible dynamic textures are reused. - /// - public bool ReuseTextures { get; set; } - - /// - /// If false, then textures which have a low data size are not reused when ReuseTextures = true. - /// - /// - /// LL viewers 3.3.4 and before appear to not fully render textures pulled from the viewer cache if those - /// textures have a relatively high pixel surface but a small data size. Typically, this appears to happen - /// if the data size is smaller than the viewer's discard level 2 size estimate. So if this is setting is - /// false, textures smaller than the calculation in IsSizeReuseable are always regenerated rather than reused - /// to work around this problem. - public bool ReuseLowDataTextures { get; set; } - private Dictionary RegisteredScenes = new Dictionary(); private Dictionary RenderPlugins = @@ -72,15 +56,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture private Dictionary Updaters = new Dictionary(); - /// - /// Record dynamic textures that we can reuse for a given data and parameter combination rather than - /// regenerate. - /// - /// - /// Key is string.Format("{0}{1}", data - /// - private Cache m_reuseableDynamicTextures; - #region IDynamicTextureManager Members public void RegisterRender(string handleType, IDynamicTextureRender render) @@ -94,17 +69,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture /// /// Called by code which actually renders the dynamic texture to supply texture data. /// - /// - /// - public void ReturnData(UUID updaterId, IDynamicTexture texture) + /// + /// + public void ReturnData(UUID id, byte[] data) { DynamicTextureUpdater updater = null; lock (Updaters) { - if (Updaters.ContainsKey(updaterId)) + if (Updaters.ContainsKey(id)) { - updater = Updaters[updaterId]; + updater = Updaters[id]; } } @@ -113,16 +88,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture if (RegisteredScenes.ContainsKey(updater.SimUUID)) { Scene scene = RegisteredScenes[updater.SimUUID]; - UUID newTextureID = updater.DataReceived(texture.Data, scene); - - if (ReuseTextures - && !updater.BlendWithOldTexture - && texture.IsReuseable - && (ReuseLowDataTextures || IsDataSizeReuseable(texture))) - { - m_reuseableDynamicTextures.Store( - GenerateReusableTextureKey(texture.InputCommands, texture.InputParams), newTextureID); - } + updater.DataReceived(data, scene); } } @@ -138,27 +104,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } } - /// - /// Determines whether the texture is reuseable based on its data size. - /// - /// - /// This is a workaround for a viewer bug where very small data size textures relative to their pixel size - /// are not redisplayed properly when pulled from cache. The calculation here is based on the typical discard - /// level of 2, a 'rate' of 0.125 and 4 components (which makes for a factor of 0.5). - /// - /// - private bool IsDataSizeReuseable(IDynamicTexture texture) - { -// Console.WriteLine("{0} {1}", texture.Size.Width, texture.Size.Height); - int discardLevel2DataThreshold = (int)Math.Ceiling((texture.Size.Width >> 2) * (texture.Size.Height >> 2) * 0.5); - -// m_log.DebugFormat( -// "[DYNAMIC TEXTURE MODULE]: Discard level 2 threshold {0}, texture data length {1}", -// discardLevel2DataThreshold, texture.Data.Length); - - return discardLevel2DataThreshold < texture.Data.Length; - } - public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, string extraParams, int updateTimer) { @@ -222,61 +167,22 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, string extraParams, int updateTimer, bool SetBlending, int disp, byte AlphaValue, int face) { - if (!RenderPlugins.ContainsKey(contentType)) - return UUID.Zero; - - Scene scene; - RegisteredScenes.TryGetValue(simID, out scene); - - if (scene == null) - return UUID.Zero; - - SceneObjectPart part = scene.GetSceneObjectPart(primID); - - if (part == null) - return UUID.Zero; - - // If we want to reuse dynamic textures then we have to ignore any request from the caller to expire - // them. - if (ReuseTextures) - disp = disp & ~DISP_EXPIRE; - - DynamicTextureUpdater updater = new DynamicTextureUpdater(); - updater.SimUUID = simID; - updater.PrimID = primID; - updater.ContentType = contentType; - updater.BodyData = data; - updater.UpdateTimer = updateTimer; - updater.UpdaterID = UUID.Random(); - updater.Params = extraParams; - updater.BlendWithOldTexture = SetBlending; - updater.FrontAlpha = AlphaValue; - updater.Face = face; - updater.Url = "Local image"; - updater.Disp = disp; - - object objReusableTextureUUID = null; - - if (ReuseTextures && !updater.BlendWithOldTexture) + if (RenderPlugins.ContainsKey(contentType)) { - string reuseableTextureKey = GenerateReusableTextureKey(data, extraParams); - objReusableTextureUUID = m_reuseableDynamicTextures.Get(reuseableTextureKey); - - if (objReusableTextureUUID != null) - { - // If something else has removed this temporary asset from the cache, detect and invalidate - // our cached uuid. - if (scene.AssetService.GetMetadata(objReusableTextureUUID.ToString()) == null) - { - m_reuseableDynamicTextures.Invalidate(reuseableTextureKey); - objReusableTextureUUID = null; - } - } - } + DynamicTextureUpdater updater = new DynamicTextureUpdater(); + updater.SimUUID = simID; + updater.PrimID = primID; + updater.ContentType = contentType; + updater.BodyData = data; + updater.UpdateTimer = updateTimer; + updater.UpdaterID = UUID.Random(); + updater.Params = extraParams; + updater.BlendWithOldTexture = SetBlending; + updater.FrontAlpha = AlphaValue; + updater.Face = face; + updater.Url = "Local image"; + updater.Disp = disp; - // We cannot reuse a dynamic texture if the data is going to be blended with something already there. - if (objReusableTextureUUID == null) - { lock (Updaters) { if (!Updaters.ContainsKey(updater.UpdaterID)) @@ -285,29 +191,11 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } } -// m_log.DebugFormat( -// "[DYNAMIC TEXTURE MODULE]: Requesting generation of new dynamic texture for {0} in {1}", -// part.Name, part.ParentGroup.Scene.Name); - RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams); + return updater.UpdaterID; } - else - { -// m_log.DebugFormat( -// "[DYNAMIC TEXTURE MODULE]: Reusing cached texture {0} for {1} in {2}", -// objReusableTextureUUID, part.Name, part.ParentGroup.Scene.Name); - - // No need to add to updaters as the texture is always the same. Not that this functionality - // apppears to be implemented anyway. - updater.UpdatePart(part, (UUID)objReusableTextureUUID); - } - - return updater.UpdaterID; - } - - private string GenerateReusableTextureKey(string data, string extraParams) - { - return string.Format("{0}{1}", data, extraParams); + + return UUID.Zero; } public void GetDrawStringSize(string contentType, string text, string fontName, int fontSize, @@ -327,13 +215,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public void Initialise(Scene scene, IConfigSource config) { - IConfig texturesConfig = config.Configs["Textures"]; - if (texturesConfig != null) - { - ReuseTextures = texturesConfig.GetBoolean("ReuseDynamicTextures", false); - ReuseLowDataTextures = texturesConfig.GetBoolean("ReuseDynamicLowDataTextures", false); - } - if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) { RegisteredScenes.Add(scene.RegionInfo.RegionID, scene); @@ -343,11 +224,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public void PostInitialise() { - if (ReuseTextures) - { - m_reuseableDynamicTextures = new Cache(CacheMedium.Memory, CacheStrategy.Conservative); - m_reuseableDynamicTextures.DefaultTTL = new TimeSpan(24, 0, 0); - } } public void Close() @@ -393,60 +269,9 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } /// - /// Update the given part with the new texture. - /// - /// - /// The old texture UUID. - /// - public UUID UpdatePart(SceneObjectPart part, UUID textureID) - { - UUID oldID; - - lock (part) - { - // mostly keep the values from before - Primitive.TextureEntry tmptex = part.Shape.Textures; - - // FIXME: Need to return the appropriate ID if only a single face is replaced. - oldID = tmptex.DefaultTexture.TextureID; - - if (Face == ALL_SIDES) - { - oldID = tmptex.DefaultTexture.TextureID; - tmptex.DefaultTexture.TextureID = textureID; - } - else - { - try - { - Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face); - texface.TextureID = textureID; - tmptex.FaceTextures[Face] = texface; - } - catch (Exception) - { - tmptex.DefaultTexture.TextureID = textureID; - } - } - - // I'm pretty sure we always want to force this to true - // I'm pretty sure noone whats to set fullbright true if it wasn't true before. - // tmptex.DefaultTexture.Fullbright = true; - - part.UpdateTextureEntry(tmptex.GetBytes()); - } - - return oldID; - } - - /// /// Called once new texture data has been received for this updater. /// - /// - /// - /// True if the data given is reuseable. - /// The asset UUID given to the incoming data. - public UUID DataReceived(byte[] data, Scene scene) + public void DataReceived(byte[] data, Scene scene) { SceneObjectPart part = scene.GetSceneObjectPart(PrimID); @@ -456,8 +281,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say, 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false); - - return UUID.Zero; + return; } byte[] assetData = null; @@ -495,29 +319,56 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface(); if (cacheLayerDecode != null) { - if (!cacheLayerDecode.Decode(asset.FullID, asset.Data)) - m_log.WarnFormat( - "[DYNAMIC TEXTURE MODULE]: Decoding of dynamically generated asset {0} for {1} in {2} failed", - asset.ID, part.Name, part.ParentGroup.Scene.Name); + cacheLayerDecode.Decode(asset.FullID, asset.Data); + cacheLayerDecode = null; } - UUID oldID = UpdatePart(part, asset.FullID); + UUID oldID = UUID.Zero; - if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0)) + lock (part) { - if (oldAsset == null) - oldAsset = scene.AssetService.Get(oldID.ToString()); + // mostly keep the values from before + Primitive.TextureEntry tmptex = part.Shape.Textures; + + // remove the old asset from the cache + oldID = tmptex.DefaultTexture.TextureID; + + if (Face == ALL_SIDES) + { + tmptex.DefaultTexture.TextureID = asset.FullID; + } + else + { + try + { + Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face); + texface.TextureID = asset.FullID; + tmptex.FaceTextures[Face] = texface; + } + catch (Exception) + { + tmptex.DefaultTexture.TextureID = asset.FullID; + } + } + // I'm pretty sure we always want to force this to true + // I'm pretty sure noone whats to set fullbright true if it wasn't true before. + // tmptex.DefaultTexture.Fullbright = true; + + part.UpdateTextureEntry(tmptex.GetBytes()); + } + + if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0)) + { + if (oldAsset == null) oldAsset = scene.AssetService.Get(oldID.ToString()); if (oldAsset != null) { - if (oldAsset.Temporary) + if (oldAsset.Temporary == true) { scene.AssetService.Delete(oldID.ToString()); } } } - - return asset.FullID; } private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index 0b9174f..56221aa 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs @@ -58,7 +58,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp public string body; public int responseCode; public string responseBody; - public string responseType = "text/plain"; //public ManualResetEvent ev; public bool requestDone; public int startTime; @@ -271,22 +270,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp } } - public void HttpContentType(UUID request, string type) - { - lock (m_UrlMap) - { - if (m_RequestMap.ContainsKey(request)) - { - UrlData urlData = m_RequestMap[request]; - urlData.requests[request].responseType = type; - } - else - { - m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); - } - } - } - public void HttpResponse(UUID request, int status, string body) { lock (m_RequestMap) diff --git a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs index 45e6527..6f83948 100644 --- a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs @@ -32,7 +32,6 @@ using System.Net; using Nini.Config; using OpenMetaverse; using OpenMetaverse.Imaging; -using OpenSim.Region.CoreModules.Scripting.DynamicTexture; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using log4net; @@ -68,18 +67,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL return true; } -// public bool AlwaysIdenticalConversion(string bodyData, string extraParams) -// { -// // We don't support conversion of body data. -// return false; -// } - - public IDynamicTexture ConvertUrl(string url, string extraParams) + public byte[] ConvertUrl(string url, string extraParams) { return null; } - public IDynamicTexture ConvertData(string bodyData, string extraParams) + public byte[] ConvertStream(Stream data, string extraParams) { return null; } @@ -172,11 +165,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL private void HttpRequestReturn(IAsyncResult result) { + RequestState state = (RequestState) result.AsyncState; WebRequest request = (WebRequest) state.Request; Stream stream = null; byte[] imageJ2000 = new byte[0]; - Size newSize = new Size(0, 0); try { @@ -189,43 +182,37 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL try { Bitmap image = new Bitmap(stream); + Size newsize; // TODO: make this a bit less hard coded if ((image.Height < 64) && (image.Width < 64)) { - newSize.Width = 32; - newSize.Height = 32; + newsize = new Size(32, 32); } else if ((image.Height < 128) && (image.Width < 128)) { - newSize.Width = 64; - newSize.Height = 64; + newsize = new Size(64, 64); } else if ((image.Height < 256) && (image.Width < 256)) { - newSize.Width = 128; - newSize.Height = 128; + newsize = new Size(128, 128); } else if ((image.Height < 512 && image.Width < 512)) { - newSize.Width = 256; - newSize.Height = 256; + newsize = new Size(256, 256); } else if ((image.Height < 1024 && image.Width < 1024)) { - newSize.Width = 512; - newSize.Height = 512; + newsize = new Size(512, 512); } else { - newSize.Width = 1024; - newSize.Height = 1024; + newsize = new Size(1024, 1024); } - using (Bitmap resize = new Bitmap(image, newSize)) - { - imageJ2000 = OpenJPEG.EncodeFromImage(resize, true); - } + Bitmap resize = new Bitmap(image, newsize); + + imageJ2000 = OpenJPEG.EncodeFromImage(resize, true); } catch (Exception) { @@ -240,6 +227,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL } catch (WebException) { + } finally { @@ -248,14 +236,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL stream.Close(); } } - - m_log.DebugFormat("[LOADIMAGEURLMODULE]: Returning {0} bytes of image data for request {1}", + m_log.DebugFormat("[LOADIMAGEURLMODULE] Returning {0} bytes of image data for request {1}", imageJ2000.Length, state.RequestID); - - m_textureManager.ReturnData( - state.RequestID, - new OpenSim.Region.CoreModules.Scripting.DynamicTexture.DynamicTexture( - request.RequestUri, null, imageJ2000, newSize, false)); + m_textureManager.ReturnData(state.RequestID, imageJ2000); } #region Nested type: RequestState diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs deleted file mode 100644 index dc54c3f..0000000 --- a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Collections.Generic; -using Nini.Config; -using log4net; -using OpenSim.Framework; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using Mono.Addins; -using OpenMetaverse; -using System.Linq; -using System.Linq.Expressions; - -namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] - class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms - { - private static readonly ILog m_log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Dictionary m_constants = new Dictionary(); - -#region ScriptInvocation - protected class ScriptInvocationData - { - public Delegate ScriptInvocationDelegate { get; private set; } - public string FunctionName { get; private set; } - public Type[] TypeSignature { get; private set; } - public Type ReturnType { get; private set; } - - public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig) - { - FunctionName = fname; - ScriptInvocationDelegate = fn; - TypeSignature = callsig; - ReturnType = returnsig; - } - } - - private Dictionary m_scriptInvocation = new Dictionary(); -#endregion - - private IScriptModule m_scriptModule = null; - public event ScriptCommand OnScriptCommand; - -#region RegionModuleInterface - public void Initialise(IConfigSource config) - { - } - - public void AddRegion(Scene scene) - { - scene.RegisterModuleInterface(this); - } - - public void RemoveRegion(Scene scene) - { - } - - public void RegionLoaded(Scene scene) - { - m_scriptModule = scene.RequestModuleInterface(); - - if (m_scriptModule != null) - m_log.Info("[MODULE COMMANDS]: Script engine found, module active"); - } - - public string Name - { - get { return "ScriptModuleCommsModule"; } - } - - public Type ReplaceableInterface - { - get { return null; } - } - - public void Close() - { - } -#endregion - -#region ScriptModuleComms - - public void RaiseEvent(UUID script, string id, string module, string command, string k) - { - ScriptCommand c = OnScriptCommand; - - if (c == null) - return; - - c(script, id, module, command, k); - } - - public void DispatchReply(UUID script, int code, string text, string k) - { - if (m_scriptModule == null) - return; - - Object[] args = new Object[] {-1, code, text, k}; - - m_scriptModule.PostScriptEvent(script, "link_message", args); - } - - private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods) - { - BindingFlags getMethodFlags = - BindingFlags.NonPublic | BindingFlags.Public; - - if (searchInstanceMethods) - getMethodFlags |= BindingFlags.Instance; - else - getMethodFlags |= BindingFlags.Static; - - return target.GetMethod(meth, getMethodFlags); - } - - public void RegisterScriptInvocation(object target, string meth) - { - MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); - if (mi == null) - { - m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); - return; - } - - RegisterScriptInvocation(target, mi); - } - - public void RegisterScriptInvocation(object target, string[] meth) - { - foreach (string m in meth) - RegisterScriptInvocation(target, m); - } - - public void RegisterScriptInvocation(object target, MethodInfo mi) - { - m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, (target is Type) ? ((Type)target).Name : target.GetType().Name); - - Type delegateType; - List typeArgs = mi.GetParameters() - .Select(p => p.ParameterType) - .ToList(); - - if (mi.ReturnType == typeof(void)) - { - delegateType = Expression.GetActionType(typeArgs.ToArray()); - } - else - { - typeArgs.Add(mi.ReturnType); - delegateType = Expression.GetFuncType(typeArgs.ToArray()); - } - - Delegate fcall; - if (!(target is Type)) - fcall = Delegate.CreateDelegate(delegateType, target, mi); - else - fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name); - - lock (m_scriptInvocation) - { - ParameterInfo[] parameters = fcall.Method.GetParameters(); - if (parameters.Length < 2) // Must have two UUID params - return; - - // Hide the first two parameters - Type[] parmTypes = new Type[parameters.Length - 2]; - for (int i = 2; i < parameters.Length; i++) - parmTypes[i - 2] = parameters[i].ParameterType; - m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); - } - } - - public void RegisterScriptInvocation(Type target, string[] methods) - { - foreach (string method in methods) - { - MethodInfo mi = GetMethodInfoFromType(target, method, false); - if (mi == null) - m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", method); - else - RegisterScriptInvocation(target, mi); - } - } - - public void RegisterScriptInvocations(IRegionModuleBase target) - { - foreach(MethodInfo method in target.GetType().GetMethods( - BindingFlags.Public | BindingFlags.Instance | - BindingFlags.Static)) - { - if(method.GetCustomAttributes( - typeof(ScriptInvocationAttribute), true).Any()) - { - if(method.IsStatic) - RegisterScriptInvocation(target.GetType(), method); - else - RegisterScriptInvocation(target, method); - } - } - } - - public Delegate[] GetScriptInvocationList() - { - List ret = new List(); - - lock (m_scriptInvocation) - { - foreach (ScriptInvocationData d in m_scriptInvocation.Values) - ret.Add(d.ScriptInvocationDelegate); - } - return ret.ToArray(); - } - - public string LookupModInvocation(string fname) - { - lock (m_scriptInvocation) - { - ScriptInvocationData sid; - if (m_scriptInvocation.TryGetValue(fname,out sid)) - { - if (sid.ReturnType == typeof(string)) - return "modInvokeS"; - else if (sid.ReturnType == typeof(int)) - 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"; - - m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); - } - } - - return null; - } - - public Delegate LookupScriptInvocation(string fname) - { - lock (m_scriptInvocation) - { - ScriptInvocationData sid; - if (m_scriptInvocation.TryGetValue(fname,out sid)) - return sid.ScriptInvocationDelegate; - } - - return null; - } - - public Type[] LookupTypeSignature(string fname) - { - lock (m_scriptInvocation) - { - ScriptInvocationData sid; - if (m_scriptInvocation.TryGetValue(fname,out sid)) - return sid.TypeSignature; - } - - return null; - } - - public Type LookupReturnType(string fname) - { - lock (m_scriptInvocation) - { - ScriptInvocationData sid; - if (m_scriptInvocation.TryGetValue(fname,out sid)) - return sid.ReturnType; - } - - return null; - } - - public object InvokeOperation(UUID hostid, UUID scriptid, string fname, params object[] parms) - { - List olist = new List(); - olist.Add(hostid); - olist.Add(scriptid); - foreach (object o in parms) - olist.Add(o); - Delegate fn = LookupScriptInvocation(fname); - return fn.DynamicInvoke(olist.ToArray()); - } - - /// - /// Operation to for a region module to register a constant to be used - /// by the script engine - /// - public void RegisterConstant(string cname, object value) - { - m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString()); - lock (m_constants) - { - m_constants.Add(cname,value); - } - } - - public void RegisterConstants(IRegionModuleBase target) - { - foreach (FieldInfo field in target.GetType().GetFields( - BindingFlags.Public | BindingFlags.Static | - BindingFlags.Instance)) - { - if (field.GetCustomAttributes( - typeof(ScriptConstantAttribute), true).Any()) - { - RegisterConstant(field.Name, field.GetValue(target)); - } - } - } - - /// - /// Operation to check for a registered constant - /// - public object LookupModConstant(string cname) - { - // m_log.DebugFormat("[MODULE COMMANDS] lookup constant <{0}>",cname); - - lock (m_constants) - { - object value = null; - if (m_constants.TryGetValue(cname,out value)) - return value; - } - - return null; - } - - /// - /// Get all registered constants - /// - public Dictionary GetConstants() - { - Dictionary ret = new Dictionary(); - - lock (m_constants) - { - foreach (KeyValuePair kvp in m_constants) - ret[kvp.Key] = kvp.Value; - } - - return ret; - } - -#endregion - - } -} diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs index 41baccc..9787c8c 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs @@ -45,292 +45,31 @@ using OpenSim.Tests.Common.Mock; namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests { [TestFixture] - public class VectorRenderModuleTests : OpenSimTestCase + public class VectorRenderModuleTests { - Scene m_scene; - DynamicTextureModule m_dtm; - VectorRenderModule m_vrm; - - private void SetupScene(bool reuseTextures) - { - m_scene = new SceneHelpers().SetupScene(); - - m_dtm = new DynamicTextureModule(); - m_dtm.ReuseTextures = reuseTextures; -// m_dtm.ReuseLowDataTextures = reuseTextures; - - m_vrm = new VectorRenderModule(); - - SceneHelpers.SetupSceneModules(m_scene, m_dtm, m_vrm); - } - [Test] public void TestDraw() { TestHelpers.InMethod(); - SetupScene(false); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;", - "", - 0); - - Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDraw() - { - TestHelpers.InMethod(); - - string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;"; - - SetupScene(false); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDrawDifferentExtraParams() - { - TestHelpers.InMethod(); - - string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;"; - - SetupScene(false); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "alpha:250", - 0); - - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDrawContainingImage() - { - TestHelpers.InMethod(); - - string dtText - = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://localhost/shouldnotexist.png"; - - SetupScene(false); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestDrawReusingTexture() - { - TestHelpers.InMethod(); + Scene scene = new SceneHelpers().SetupScene(); + DynamicTextureModule dtm = new DynamicTextureModule(); + VectorRenderModule vrm = new VectorRenderModule(); + SceneHelpers.SetupSceneModules(scene, dtm, vrm); - SetupScene(true); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); + SceneObjectGroup so = SceneHelpers.AddSceneObject(scene); UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, + dtm.AddDynamicTextureData( + scene.RegionInfo.RegionID, so.UUID, - m_vrm.GetContentType(), + vrm.GetContentType(), "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;", "", 0); - Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDrawReusingTexture() - { - TestHelpers.InMethod(); -// TestHelpers.EnableLogging(); - - string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;"; - - SetupScene(true); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - Assert.That(firstDynamicTextureID, Is.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - /// - /// Test a low data dynamically generated texture such that it is treated as a low data texture that causes - /// problems for current viewers. - /// - /// - /// As we do not set DynamicTextureModule.ReuseLowDataTextures = true in this test, it should not reuse the - /// texture - /// - [Test] - public void TestRepeatSameDrawLowDataTexture() - { - TestHelpers.InMethod(); -// TestHelpers.EnableLogging(); - - string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;"; - - SetupScene(true); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "1024", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "1024", - 0); - - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDrawDifferentExtraParamsReusingTexture() - { - TestHelpers.InMethod(); - - string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;"; - - SetupScene(true); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "alpha:250", - 0); - - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); - } - - [Test] - public void TestRepeatSameDrawContainingImageReusingTexture() - { - TestHelpers.InMethod(); - - string dtText - = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://localhost/shouldnotexist.png"; - - SetupScene(true); - SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - - UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID; - - m_dtm.AddDynamicTextureData( - m_scene.RegionInfo.RegionID, - so.UUID, - m_vrm.GetContentType(), - dtText, - "", - 0); - Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); + Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID)); } } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index 673c2d1..8b2f2f8 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs @@ -30,12 +30,10 @@ using System.Drawing; using System.Drawing.Imaging; using System.Globalization; using System.IO; -using System.Linq; using System.Net; using Nini.Config; using OpenMetaverse; using OpenMetaverse.Imaging; -using OpenSim.Region.CoreModules.Scripting.DynamicTexture; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using log4net; @@ -47,13 +45,9 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender { public class VectorRenderModule : IRegionModule, IDynamicTextureRender { - // These fields exist for testing purposes, please do not remove. -// private static bool s_flipper; -// private static byte[] s_asset1Data; -// private static byte[] s_asset2Data; - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private string m_name = "VectorRenderModule"; private Scene m_scene; private IDynamicTextureManager m_textureManager; private Graphics m_graph; @@ -67,12 +61,12 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender public string GetContentType() { - return "vector"; + return ("vector"); } public string GetName() { - return Name; + return m_name; } public bool SupportsAsynchronous() @@ -80,20 +74,14 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender return true; } -// public bool AlwaysIdenticalConversion(string bodyData, string extraParams) -// { -// string[] lines = GetLines(bodyData); -// return lines.Any((str, r) => str.StartsWith("Image")); -// } - - public IDynamicTexture ConvertUrl(string url, string extraParams) + public byte[] ConvertUrl(string url, string extraParams) { return null; } - public IDynamicTexture ConvertData(string bodyData, string extraParams) + public byte[] ConvertStream(Stream data, string extraParams) { - return Draw(bodyData, extraParams); + return null; } public bool AsyncConvertUrl(UUID id, string url, string extraParams) @@ -103,28 +91,21 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender public bool AsyncConvertData(UUID id, string bodyData, string extraParams) { - // XXX: This isn't actually being done asynchronously! - m_textureManager.ReturnData(id, ConvertData(bodyData, extraParams)); - + Draw(bodyData, id, extraParams); return true; } public void GetDrawStringSize(string text, string fontName, int fontSize, out double xSize, out double ySize) { - lock (this) + using (Font myFont = new Font(fontName, fontSize)) { - using (Font myFont = new Font(fontName, fontSize)) + SizeF stringSize = new SizeF(); + lock (m_graph) { - SizeF stringSize = new SizeF(); - - // XXX: This lock may be unnecessary. - lock (m_graph) - { - stringSize = m_graph.MeasureString(text, myFont); - xSize = stringSize.Width; - ySize = stringSize.Height; - } + stringSize = m_graph.MeasureString(text, myFont); + xSize = stringSize.Width; + ySize = stringSize.Height; } } } @@ -163,13 +144,6 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender { m_textureManager.RegisterRender(GetContentType(), this); } - - // This code exists for testing purposes, please do not remove. -// s_asset1Data = m_scene.AssetService.Get("00000000-0000-1111-9999-000000000001").Data; -// s_asset1Data = m_scene.AssetService.Get("9f4acf0d-1841-4e15-bdb8-3a12efc9dd8f").Data; - - // Terrain dirt - smallest bin/assets file (6004 bytes) -// s_asset2Data = m_scene.AssetService.Get("b8d3965a-ad78-bf43-699b-bff8eca6c975").Data; } public void Close() @@ -178,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender public string Name { - get { return "VectorRenderModule"; } + get { return m_name; } } public bool IsSharedModule @@ -188,7 +162,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender #endregion - private IDynamicTexture Draw(string data, string extraParams) + private void Draw(string data, UUID id, string extraParams) { // We need to cater for old scripts that didnt use extraParams neatly, they use either an integer size which represents both width and height, or setalpha // we will now support multiple comma seperated params in the form width:256,height:512,alpha:255 @@ -331,57 +305,40 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender Bitmap bitmap = null; Graphics graph = null; - bool reuseable = false; try { - // XXX: In testing, it appears that if multiple threads dispose of separate GDI+ objects simultaneously, - // the native malloc heap can become corrupted, possibly due to a double free(). This may be due to - // bugs in the underlying libcairo used by mono's libgdiplus.dll on Linux/OSX. These problems were - // seen with both libcario 1.10.2-6.1ubuntu3 and 1.8.10-2ubuntu1. They go away if disposal is perfomed - // under lock. - lock (this) - { - if (alpha == 256) - bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); - else - bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); + if (alpha == 256) + bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); + else + bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); + + graph = Graphics.FromImage(bitmap); - graph = Graphics.FromImage(bitmap); - - // this is really just to save people filling the - // background color in their scripts, only do when fully opaque - if (alpha >= 255) + // this is really just to save people filling the + // background color in their scripts, only do when fully opaque + if (alpha >= 255) + { + using (SolidBrush bgFillBrush = new SolidBrush(bgColor)) { - using (SolidBrush bgFillBrush = new SolidBrush(bgColor)) - { - graph.FillRectangle(bgFillBrush, 0, 0, width, height); - } + graph.FillRectangle(bgFillBrush, 0, 0, width, height); } - - for (int w = 0; w < bitmap.Width; w++) + } + + for (int w = 0; w < bitmap.Width; w++) + { + if (alpha <= 255) { - if (alpha <= 255) + for (int h = 0; h < bitmap.Height; h++) { - for (int h = 0; h < bitmap.Height; h++) - { - bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); - } + bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); } } - - GDIDraw(data, graph, altDataDelim, out reuseable); } + GDIDraw(data, graph, altDataDelim); + byte[] imageJ2000 = new byte[0]; - - // This code exists for testing purposes, please do not remove. -// if (s_flipper) -// imageJ2000 = s_asset1Data; -// else -// imageJ2000 = s_asset2Data; -// -// s_flipper = !s_flipper; try { @@ -394,24 +351,15 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender e.Message, e.StackTrace); } - return new OpenSim.Region.CoreModules.Scripting.DynamicTexture.DynamicTexture( - data, extraParams, imageJ2000, new Size(width, height), reuseable); + m_textureManager.ReturnData(id, imageJ2000); } finally { - // XXX: In testing, it appears that if multiple threads dispose of separate GDI+ objects simultaneously, - // the native malloc heap can become corrupted, possibly due to a double free(). This may be due to - // bugs in the underlying libcairo used by mono's libgdiplus.dll on Linux/OSX. These problems were - // seen with both libcario 1.10.2-6.1ubuntu3 and 1.8.10-2ubuntu1. They go away if disposal is perfomed - // under lock. - lock (this) - { - if (graph != null) - graph.Dispose(); - - if (bitmap != null) - bitmap.Dispose(); - } + if (graph != null) + graph.Dispose(); + + if (bitmap != null) + bitmap.Dispose(); } } @@ -470,21 +418,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } */ - /// - /// Split input data into discrete command lines. - /// - /// - /// - /// - private string[] GetLines(string data, char dataDelim) - { - char[] lineDelimiter = { dataDelim }; - return data.Split(lineDelimiter); - } - - private void GDIDraw(string data, Graphics graph, char dataDelim, out bool reuseable) + private void GDIDraw(string data, Graphics graph, char dataDelim) { - reuseable = true; Point startPoint = new Point(0, 0); Point endPoint = new Point(0, 0); Pen drawPen = null; @@ -499,9 +434,11 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender myFont = new Font(fontName, fontSize); myBrush = new SolidBrush(Color.Black); + char[] lineDelimiter = {dataDelim}; char[] partsDelimiter = {','}; + string[] lines = data.Split(lineDelimiter); - foreach (string line in GetLines(data, dataDelim)) + foreach (string line in lines) { string nextLine = line.Trim(); //replace with switch, or even better, do some proper parsing @@ -532,10 +469,6 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } else if (nextLine.StartsWith("Image")) { - // We cannot reuse any generated texture involving fetching an image via HTTP since that image - // can change. - reuseable = false; - float x = 0; float y = 0; GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y); diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index e167e31..07bb291 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -28,7 +28,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Text.RegularExpressions; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; @@ -173,42 +172,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm /// UUID of the SceneObjectPart /// channel to listen on /// name to filter on - /// - /// key to filter on (user given, could be totally faked) - /// - /// msg to filter on - /// number of the scripts handle - public int Listen(uint localID, UUID itemID, UUID hostID, int channel, - string name, UUID id, string msg) - { - return m_listenerManager.AddListener(localID, itemID, hostID, - channel, name, id, msg); - } - - /// - /// Create a listen event callback with the specified filters. - /// The parameters localID,itemID are needed to uniquely identify - /// the script during 'peek' time. Parameter hostID is needed to - /// determine the position of the script. - /// - /// localID of the script engine - /// UUID of the script engine - /// UUID of the SceneObjectPart - /// channel to listen on - /// name to filter on - /// - /// key to filter on (user given, could be totally faked) - /// + /// key to filter on (user given, could be totally faked) /// msg to filter on - /// - /// Bitfield indicating which strings should be processed as regex. - /// /// number of the scripts handle - public int Listen(uint localID, UUID itemID, UUID hostID, int channel, - string name, UUID id, string msg, int regexBitfield) + public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg) { - return m_listenerManager.AddListener(localID, itemID, hostID, - channel, name, id, msg, regexBitfield); + return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg); } /// @@ -357,7 +326,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm if (channel == 0) { // Channel 0 goes to viewer ONLY - m_scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, target, false, false); + m_scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, false, false, target); return true; } @@ -501,25 +470,15 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm m_curlisteners = 0; } - public int AddListener(uint localID, UUID itemID, UUID hostID, - int channel, string name, UUID id, string msg) - { - return AddListener(localID, itemID, hostID, channel, name, id, - msg, 0); - } - - public int AddListener(uint localID, UUID itemID, UUID hostID, - int channel, string name, UUID id, string msg, - int regexBitfield) + public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg) { // do we already have a match on this particular filter event? - List coll = GetListeners(itemID, channel, name, id, - msg); + List coll = GetListeners(itemID, channel, name, id, msg); if (coll.Count > 0) { - // special case, called with same filter settings, return same - // handle (2008-05-02, tested on 1.21.1 server, still holds) + // special case, called with same filter settings, return same handle + // (2008-05-02, tested on 1.21.1 server, still holds) return coll[0].GetHandle(); } @@ -531,9 +490,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm if (newHandle > 0) { - ListenerInfo li = new ListenerInfo(newHandle, localID, - itemID, hostID, channel, name, id, msg, - regexBitfield); + ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg); List listeners; if (!m_listeners.TryGetValue(channel,out listeners)) @@ -674,22 +631,6 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm return -1; } - /// These are duplicated from ScriptBaseClass - /// http://opensimulator.org/mantis/view.php?id=6106#c21945 - #region Constants for the bitfield parameter of osListenRegex - - /// - /// process name parameter as regex - /// - public const int OS_LISTEN_REGEX_NAME = 0x1; - - /// - /// process message parameter as regex - /// - public const int OS_LISTEN_REGEX_MESSAGE = 0x2; - - #endregion - // Theres probably a more clever and efficient way to // do this, maybe with regex. // PM2008: Ha, one could even be smart and define a specialized Enumerator. @@ -715,10 +656,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { continue; } - if (li.GetName().Length > 0 && ( - ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) || - ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName())) - )) + if (li.GetName().Length > 0 && !li.GetName().Equals(name)) { continue; } @@ -726,10 +664,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { continue; } - if (li.GetMessage().Length > 0 && ( - ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) || - ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage())) - )) + if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg)) { continue; } @@ -762,13 +697,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { int idx = 0; Object[] item = new Object[6]; - int dataItemLength = 6; while (idx < data.Length) { - dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6; - item = new Object[dataItemLength]; - Array.Copy(data, idx, item, 0, dataItemLength); + Array.Copy(data, idx, item, 0, 6); ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item); @@ -780,12 +712,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm m_listeners[(int)item[2]].Add(info); } - idx+=dataItemLength; + idx+=6; } } } - public class ListenerInfo : IWorldCommListenerInfo + public class ListenerInfo: IWorldCommListenerInfo { private bool m_active; // Listener is active or not private int m_handle; // Assigned handle of this listener @@ -799,29 +731,16 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message) { - Initialise(handle, localID, ItemID, hostID, channel, name, id, - message, 0); - } - - public ListenerInfo(int handle, uint localID, UUID ItemID, - UUID hostID, int channel, string name, UUID id, - string message, int regexBitfield) - { - Initialise(handle, localID, ItemID, hostID, channel, name, id, - message, regexBitfield); + Initialise(handle, localID, ItemID, hostID, channel, name, id, message); } public ListenerInfo(ListenerInfo li, string name, UUID id, string message) { - Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0); - } - - public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield) - { - Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield); + Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message); } - private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield) + private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, + UUID id, string message) { m_active = true; m_handle = handle; @@ -832,12 +751,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm m_name = name; m_id = id; m_message = message; - RegexBitfield = regexBitfield; } public Object[] GetSerializationData() { - Object[] data = new Object[7]; + Object[] data = new Object[6]; data[0] = m_active; data[1] = m_handle; @@ -845,19 +763,16 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm data[3] = m_name; data[4] = m_id; data[5] = m_message; - data[6] = RegexBitfield; return data; } public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data) { - ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]); - linfo.m_active = (bool)data[0]; - if (data.Length >= 7) - { - linfo.RegexBitfield = (int)data[6]; - } + ListenerInfo linfo = new ListenerInfo((int)data[1], localID, + ItemID, hostID, (int)data[2], (string)data[3], + (UUID)data[4], (string)data[5]); + linfo.m_active=(bool)data[0]; return linfo; } @@ -916,7 +831,5 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { return m_id; } - - public int RegexBitfield { get; private set; } } } -- cgit v1.1