aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-26 13:16:11 +0000
committerMelanie Thielker2008-09-26 13:16:11 +0000
commit824283ca3c2ab54868ed61fdb0a329221d69e5fa (patch)
tree9013892fa2afa579bffe8bdcd6a46e2242ed085c /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
parent* Wind updates. Still random.. but in 4 directions instead of two! (diff)
downloadopensim-SC_OLD-824283ca3c2ab54868ed61fdb0a329221d69e5fa.zip
opensim-SC_OLD-824283ca3c2ab54868ed61fdb0a329221d69e5fa.tar.gz
opensim-SC_OLD-824283ca3c2ab54868ed61fdb0a329221d69e5fa.tar.bz2
opensim-SC_OLD-824283ca3c2ab54868ed61fdb0a329221d69e5fa.tar.xz
Remove all the subclassing complexity and script server interfaces from
DNE and move all of DNE into the DotNetEngine directory. Remove references that would cause the script runtime to load the entire engine + scene into each script appdomain. This might help DNE memory consumption.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs317
1 files changed, 0 insertions, 317 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
deleted file mode 100644
index f259ec1..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
+++ /dev/null
@@ -1,317 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenSim.Region.Interfaces;
34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenMetaverse;
38using OpenSim.Region.ScriptEngine.Shared;
39
40namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
41{
42 /// <summary>
43 /// This is the root object for ScriptEngine. Objects access each other trough this class.
44 /// </summary>
45 ///
46 [Serializable]
47 public abstract class ScriptEngine : IRegionModule, IScriptModule, iScriptEngineFunctionModule, IEventReceiver
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 public static List<ScriptEngine> ScriptEngines = new List<ScriptEngine>();
52 private Scene m_Scene;
53 public Scene World
54 {
55 get { return m_Scene; }
56 }
57 public EventManager m_EventManager; // Handles and queues incoming events from OpenSim
58 public EventQueueManager m_EventQueueManager; // Executes events, handles script threads
59 public ScriptManager m_ScriptManager; // Load, unload and execute scripts
60 public AppDomainManager m_AppDomainManager; // Handles loading/unloading of scripts into AppDomains
61 public static MaintenanceThread m_MaintenanceThread; // Thread that does different kinds of maintenance, for example refreshing config and killing scripts that has been running too long
62
63 public IConfigSource ConfigSource;
64 public IConfig ScriptConfigSource;
65 public abstract string ScriptEngineName { get; }
66 private bool m_enabled = false;
67 private bool m_hookUpToServer = false;
68
69 public IConfig Config
70 {
71 get { return ScriptConfigSource; }
72 }
73
74 /// <summary>
75 /// How many seconds between re-reading config-file. 0 = never. ScriptEngine will try to adjust to new config changes.
76 /// </summary>
77 public int RefreshConfigFileSeconds {
78 get { return (int)(RefreshConfigFilens / 10000000); }
79 set { RefreshConfigFilens = value * 10000000; }
80 }
81 public long RefreshConfigFilens;
82
83 public ScriptManager GetScriptManager()
84 {
85 return _GetScriptManager();
86 }
87
88 public abstract ScriptManager _GetScriptManager();
89
90 public ILog Log
91 {
92 get { return m_log; }
93 }
94
95 public ScriptEngine()
96 {
97 Common.mySE = this; // For logging, just need any instance, doesn't matter
98 lock (ScriptEngines)
99 {
100 ScriptEngines.Add(this); // Keep a list of ScriptEngines for shared threads to process all instances
101 }
102 }
103
104 public void InitializeEngine(Scene Sceneworld, IConfigSource config, bool HookUpToServer, ScriptManager newScriptManager)
105 {
106 m_Scene = Sceneworld;
107 ConfigSource = config;
108 m_hookUpToServer = HookUpToServer;
109
110 m_log.Info("[" + ScriptEngineName + "]: ScriptEngine initializing");
111
112 // Make sure we have config
113 if (ConfigSource.Configs[ScriptEngineName] == null)
114 ConfigSource.AddConfig(ScriptEngineName);
115 ScriptConfigSource = ConfigSource.Configs[ScriptEngineName];
116
117 m_enabled = ScriptConfigSource.GetBoolean("Enabled", true);
118 if (!m_enabled)
119 return;
120
121 //m_log.Info("[" + ScriptEngineName + "]: InitializeEngine");
122
123 // Create all objects we'll be using
124 m_EventQueueManager = new EventQueueManager(this);
125 m_EventManager = new EventManager(this, HookUpToServer);
126 // We need to start it
127 m_ScriptManager = newScriptManager;
128 m_ScriptManager.Setup();
129 m_AppDomainManager = new AppDomainManager(this);
130 if (m_MaintenanceThread == null)
131 m_MaintenanceThread = new MaintenanceThread();
132
133 m_log.Info("[" + ScriptEngineName + "]: Reading configuration from config section \"" + ScriptEngineName + "\"");
134 ReadConfig();
135
136 m_Scene.StackModuleInterface<IScriptModule>(this);
137 }
138
139 public void PostInitialise()
140 {
141 if (!m_enabled)
142 return;
143
144 if (m_hookUpToServer)
145 m_EventManager.HookUpEvents();
146
147 m_ScriptManager.Start();
148 }
149
150 public void Shutdown()
151 {
152 // We are shutting down
153 lock (ScriptEngines)
154 {
155 ScriptEngines.Remove(this);
156 }
157 }
158
159 public void ReadConfig()
160 {
161#if DEBUG
162 //m_log.Debug("[" + ScriptEngineName + "]: Refreshing configuration for all modules");
163#endif
164 RefreshConfigFileSeconds = ScriptConfigSource.GetInt("RefreshConfig", 30);
165
166
167 // Create a new object (probably not necessary?)
168// ScriptConfigSource = ConfigSource.Configs[ScriptEngineName];
169
170 if (m_EventQueueManager != null) m_EventQueueManager.ReadConfig();
171 if (m_EventManager != null) m_EventManager.ReadConfig();
172 if (m_ScriptManager != null) m_ScriptManager.ReadConfig();
173 if (m_AppDomainManager != null) m_AppDomainManager.ReadConfig();
174 if (m_MaintenanceThread != null) m_MaintenanceThread.ReadConfig();
175 }
176
177 #region IRegionModule
178
179 public abstract void Initialise(Scene scene, IConfigSource config);
180
181 public void Close()
182 {
183 }
184
185 public string Name
186 {
187 get { return "Common." + ScriptEngineName; }
188 }
189
190 public bool IsSharedModule
191 {
192 get { return false; }
193 }
194
195 public bool PostObjectEvent(uint localID, EventParams p)
196 {
197 return m_EventQueueManager.AddToObjectQueue(localID, p.EventName, p.DetectParams, p.Params);
198 }
199
200 public bool PostScriptEvent(UUID itemID, EventParams p)
201 {
202 uint localID = m_ScriptManager.GetLocalID(itemID);
203 return m_EventQueueManager.AddToScriptQueue(localID, itemID, p.EventName, p.DetectParams, p.Params);
204 }
205
206 public DetectParams GetDetectParams(UUID itemID, int number)
207 {
208 uint localID = m_ScriptManager.GetLocalID(itemID);
209 if (localID == 0)
210 return null;
211
212 IScript Script = m_ScriptManager.GetScript(localID, itemID);
213
214 if (Script == null)
215 return null;
216
217 DetectParams[] det = m_ScriptManager.GetDetectParams(Script);
218
219 if (number < 0 || number >= det.Length)
220 return null;
221
222 return det[number];
223 }
224
225 public int GetStartParameter(UUID itemID)
226 {
227 return 0;
228 }
229 #endregion
230
231 public void SetState(UUID itemID, string state)
232 {
233 uint localID = m_ScriptManager.GetLocalID(itemID);
234 if (localID == 0)
235 return;
236
237 IScript Script = m_ScriptManager.GetScript(localID, itemID);
238
239 if (Script == null)
240 return;
241
242 string currentState = Script.State;
243
244 if (currentState != state)
245 {
246 try
247 {
248 m_EventManager.state_exit(localID);
249
250 }
251 catch (AppDomainUnloadedException)
252 {
253 Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance");
254 }
255
256 Script.State = state;
257
258 try
259 {
260 int eventFlags = m_ScriptManager.GetStateEventFlags(localID, itemID);
261 SceneObjectPart part = m_Scene.GetSceneObjectPart(itemID);
262 if (part != null)
263 part.SetScriptEvents(itemID, eventFlags);
264 m_EventManager.state_entry(localID);
265 }
266 catch (AppDomainUnloadedException)
267 {
268 Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance");
269 }
270 }
271 }
272
273 public bool GetScriptState(UUID itemID)
274 {
275 uint localID = m_ScriptManager.GetLocalID(itemID);
276 if (localID == 0)
277 return false;
278
279 IScript script = m_ScriptManager.GetScript(localID, itemID);
280 if (script == null)
281 return false;
282
283 return script.Exec.Running?true:false;
284 }
285
286 public void SetScriptState(UUID itemID, bool state)
287 {
288 uint localID = m_ScriptManager.GetLocalID(itemID);
289 if (localID == 0)
290 return;
291
292 IScript script = m_ScriptManager.GetScript(localID, itemID);
293 if (script == null)
294 return;
295
296 script.Exec.Running = state;
297 }
298
299 public void ApiResetScript(UUID itemID)
300 {
301 uint localID = m_ScriptManager.GetLocalID(itemID);
302 if (localID == 0)
303 return;
304
305 m_ScriptManager.ResetScript(localID, itemID);
306 }
307
308 public void ResetScript(UUID itemID)
309 {
310 uint localID = m_ScriptManager.GetLocalID(itemID);
311 if (localID == 0)
312 return;
313
314 m_ScriptManager.ResetScript(localID, itemID);
315 }
316 }
317}