From 1893164d26f5ff62784055ee00612bbc9984ae4e Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 19 Aug 2007 06:52:59 +0000 Subject: Moved script loading from ScriptManager to AppDomainManager. Now increases scripts loaded count in AppDomain properly. --- .../ScriptEngine/DotNetEngine/AppDomainManager.cs | 39 +++++++++++++++++++--- .../ScriptEngine/DotNetEngine/ScriptManager.cs | 30 ++--------------- 2 files changed, 36 insertions(+), 33 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs index 33e95d3..77c859f 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs @@ -5,6 +5,10 @@ using System.Reflection; using System.Threading; using System.Runtime.Remoting; using System.IO; +using OpenSim.Region.Environment.Scenes; +using OpenSim.Region.Environment.Scenes.Scripting; +using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; +using OpenSim.Region.ScriptEngine.Common; namespace OpenSim.Region.ScriptEngine.DotNetEngine { @@ -51,7 +55,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine /// Find a free AppDomain, creating one if necessary /// /// Free AppDomain - internal AppDomain GetFreeAppDomain() + private AppDomainStructure GetFreeAppDomain() { FreeAppDomains(); lock(GetLock) { @@ -78,9 +82,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine // - We assume that every time someone wants an AppDomain they will load into it // if this assumption is wrong we end up with a miscount and will never unload it. // - CurrentAD.ScriptsLoaded++; + // Return AppDomain - return CurrentAD.CurrentAppDomain; + return CurrentAD; } // lock } @@ -136,13 +140,37 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } // foreach } // lock } + + + + public OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName, IScriptHost host) + { + //LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script"); + //Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory); + // * Find next available AppDomain to put it in + AppDomainStructure FreeAppDomain = GetFreeAppDomain(); + + + LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); + //LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); + //Type mytype = mbrt.GetType(); + //Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); + + FreeAppDomain.ScriptsLoaded++; + + //mbrt.Start(); + return mbrt; + //return (LSL_BaseClass)mbrt; + + } + /// /// Increase "dead script" counter for an AppDomain /// /// - [Obsolete("Needs optimizing!!!")] - public void StopScriptInAppDomain(AppDomain ad) + [Obsolete("Needs fixing!!!")] + public void StopScript(AppDomain ad) { lock (FreeLock) { @@ -170,5 +198,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } // lock } + } } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 926ec74..9a65b5c 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -172,15 +172,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine // * Insert yield into code FileName = ProcessYield(FileName); - // * Find next available AppDomain to put it in - AppDomain FreeAppDomain = m_scriptEngine.myAppDomainManager.GetFreeAppDomain(); - // * Load and start script, for now with dummy host - //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); - OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName, ObjectID); + // Add it to our temporary active script keeper //Scripts.Add(FullScriptID, Script); @@ -207,30 +204,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine return FileName; } - /// - /// Does actual loading and initialization of script Assembly - /// - /// AppDomain to load script into - /// FileName of script assembly (.dll) - /// - private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName, IScriptHost host) - { - - //LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script"); - //Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory); - LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); - //LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); - Type mytype = mbrt.GetType(); - - Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); - - - //mbrt.Start(); - return mbrt; - //return (LSL_BaseClass)mbrt; - - } /// /// Execute a LL-event-function in Script -- cgit v1.1