aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneBase.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-05 18:36:53 +0000
committerJustin Clarke Casey2009-02-05 18:36:53 +0000
commitd04025ff3dd6208a8939c320e15cc0182e045b05 (patch)
treeca26ec998d4803ece3f16c9e83d66afd56874a91 /OpenSim/Region/Environment/Scenes/SceneBase.cs
parentFrom: Christopher Yeoh <yeohc@au1.ibm.com> (diff)
downloadopensim-SC_OLD-d04025ff3dd6208a8939c320e15cc0182e045b05.zip
opensim-SC_OLD-d04025ff3dd6208a8939c320e15cc0182e045b05.tar.gz
opensim-SC_OLD-d04025ff3dd6208a8939c320e15cc0182e045b05.tar.bz2
opensim-SC_OLD-d04025ff3dd6208a8939c320e15cc0182e045b05.tar.xz
* refactor: Move module handling code up into SceneBase from Scene, reducing the large number of different things that Scene does
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneBase.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneBase.cs177
1 files changed, 173 insertions, 4 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs
index e6e2c93..4d6a39a 100644
--- a/OpenSim/Region/Environment/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs
@@ -48,6 +48,30 @@ namespace OpenSim.Region.Environment.Scenes
48 #endregion 48 #endregion
49 49
50 #region Fields 50 #region Fields
51
52 /// <value>
53 /// All the region modules attached to this scene.
54 /// </value>
55 public Dictionary<string, IRegionModule> Modules
56 {
57 get { return m_modules; }
58 }
59 protected Dictionary<string, IRegionModule> m_modules = new Dictionary<string, IRegionModule>();
60
61 /// <value>
62 /// The module interfaces available from this scene.
63 /// </value>
64 protected Dictionary<Type, List<object> > ModuleInterfaces = new Dictionary<Type, List<object> >();
65
66 protected Dictionary<string, object> ModuleAPIMethods = new Dictionary<string, object>();
67 protected Dictionary<string, ICommander> m_moduleCommanders = new Dictionary<string, ICommander>();
68
69 /// <value>
70 /// Registered classes that are capable of creating entities.
71 /// </value>
72 protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
73
74 //API module interfaces
51 75
52 /// <summary> 76 /// <summary>
53 /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is 77 /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
@@ -202,6 +226,16 @@ namespace OpenSim.Region.Environment.Scenes
202 /// </summary> 226 /// </summary>
203 public virtual void Close() 227 public virtual void Close()
204 { 228 {
229 // Shut down all non shared modules.
230 foreach (IRegionModule module in Modules.Values)
231 {
232 if (!module.IsSharedModule)
233 {
234 module.Close();
235 }
236 }
237 Modules.Clear();
238
205 try 239 try
206 { 240 {
207 EventManager.TriggerShutdown(); 241 EventManager.TriggerShutdown();
@@ -228,15 +262,150 @@ namespace OpenSim.Region.Environment.Scenes
228 262
229 return myID; 263 return myID;
230 } 264 }
265
266 #region Module Methods
267
268 /// <summary>
269 /// Add a module to this scene.
270 /// </summary>
271 /// <param name="name"></param>
272 /// <param name="module"></param>
273 public void AddModule(string name, IRegionModule module)
274 {
275 if (!Modules.ContainsKey(name))
276 {
277 Modules.Add(name, module);
278 }
279 }
280
281 public void RegisterModuleCommander(string name, ICommander commander)
282 {
283 lock (m_moduleCommanders)
284 {
285 m_moduleCommanders.Add(name, commander);
286 }
287 }
288
289 public ICommander GetCommander(string name)
290 {
291 lock (m_moduleCommanders)
292 {
293 return m_moduleCommanders[name];
294 }
295 }
296
297 public Dictionary<string, ICommander> GetCommanders()
298 {
299 return m_moduleCommanders;
300 }
301
302 /// <summary>
303 /// Register an interface to a region module. This allows module methods to be called directly as
304 /// well as via events. If there is already a module registered for this interface, it is not replaced
305 /// (is this the best behaviour?)
306 /// </summary>
307 /// <param name="mod"></param>
308 public void RegisterModuleInterface<M>(M mod)
309 {
310 if (!ModuleInterfaces.ContainsKey(typeof(M)))
311 {
312 List<Object> l = new List<Object>();
313 l.Add(mod);
314 ModuleInterfaces.Add(typeof(M), l);
315
316 if (mod is IEntityCreator)
317 {
318 IEntityCreator entityCreator = (IEntityCreator)mod;
319 foreach (PCode pcode in entityCreator.CreationCapabilities)
320 {
321 m_entityCreators[pcode] = entityCreator;
322 }
323 }
324 }
325 }
231 326
232 public virtual T RequestModuleInterface<T>() 327 public void StackModuleInterface<M>(M mod)
233 { 328 {
234 return default(T); 329 List<Object> l;
330 if (ModuleInterfaces.ContainsKey(typeof(M)))
331 l = ModuleInterfaces[typeof(M)];
332 else
333 l = new List<Object>();
334
335 if (l.Contains(mod))
336 return;
337
338 l.Add(mod);
339
340 if (mod is IEntityCreator)
341 {
342 IEntityCreator entityCreator = (IEntityCreator)mod;
343 foreach (PCode pcode in entityCreator.CreationCapabilities)
344 {
345 m_entityCreators[pcode] = entityCreator;
346 }
347 }
348
349 ModuleInterfaces[typeof(M)] = l;
235 } 350 }
236 351
237 public virtual T[] RequestModuleInterfaces<T>() 352 /// <summary>
353 /// For the given interface, retrieve the region module which implements it.
354 /// </summary>
355 /// <returns>null if there is no registered module implementing that interface</returns>
356 public T RequestModuleInterface<T>()
238 { 357 {
239 return new T[] { default(T) }; 358 if (ModuleInterfaces.ContainsKey(typeof(T)))
359 {
360 return (T)ModuleInterfaces[typeof(T)][0];
361 }
362 else
363 {
364 return default(T);
365 }
240 } 366 }
367
368 /// <summary>
369 /// For the given interface, retrieve an array of region modules that implement it.
370 /// </summary>
371 /// <returns>an empty array if there are no registered modules implementing that interface</returns>
372 public T[] RequestModuleInterfaces<T>()
373 {
374 if (ModuleInterfaces.ContainsKey(typeof(T)))
375 {
376 List<T> ret = new List<T>();
377
378 foreach (Object o in ModuleInterfaces[typeof(T)])
379 ret.Add((T)o);
380 return ret.ToArray();
381 }
382 else
383 {
384 return new T[] { default(T) };
385 }
386 }
387
388 #endregion
389
390 /// <summary>
391 /// Shows various details about the sim based on the parameters supplied by the console command in openSimMain.
392 /// </summary>
393 /// <param name="showParams">What to show</param>
394 public virtual void Show(string[] showParams)
395 {
396 switch (showParams[0])
397 {
398 case "modules":
399 m_log.Error("The currently loaded modules in " + RegionInfo.RegionName + " are:");
400 foreach (IRegionModule module in Modules.Values)
401 {
402 if (!module.IsSharedModule)
403 {
404 m_log.Error("Region Module: " + module.Name);
405 }
406 }
407 break;
408 }
409 }
241 } 410 }
242} 411}