29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Console;
38 using OpenSim.Region.Framework.Interfaces;
41 namespace OpenSim.
Region.Framework.Scenes
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 #pragma warning disable 414
48 private static readonly
string LogHeader =
"[SCENE]";
49 #pragma warning restore 414
59 public string Name {
get {
return RegionInfo.RegionName; } }
61 public IConfigSource Config
63 get {
return GetConfig(); }
74 public Dictionary<string, IRegionModuleBase> RegionModules
76 get {
return m_regionModules; }
78 private Dictionary<string, IRegionModuleBase> m_regionModules =
new Dictionary<string, IRegionModuleBase>();
83 protected Dictionary<Type, List<object>> ModuleInterfaces =
new Dictionary<Type, List<object>>();
89 protected List<UUID> FormatsOffered =
new List<UUID>();
90 protected Dictionary<object, List<UUID>> FormatsWanted =
new Dictionary<object, List<UUID>>();
92 protected Dictionary<string, object> ModuleAPIMethods =
new Dictionary<string, object>();
97 protected Dictionary<string, ICommander> m_moduleCommanders =
new Dictionary<string, ICommander>();
102 protected Dictionary<PCode, IEntityCreator> m_entityCreators =
new Dictionary<PCode, IEntityCreator>();
108 protected uint m_lastAllocatedLocalId = 720000;
110 private readonly Mutex _primAllocateMutex =
new Mutex(
false);
114 public bool LoginsEnabled
118 return m_loginsEnabled;
123 if (m_loginsEnabled != value)
125 m_loginsEnabled = value;
126 EventManager.TriggerRegionLoginsStatusChange(
this);
130 private bool m_loginsEnabled;
141 if (m_ready != value)
144 EventManager.TriggerRegionReadyStatusChange(
this);
148 private bool m_ready;
150 public float TimeDilation
168 get {
return m_eventManager; }
175 get {
return m_permissions; }
182 get {
return m_regStatus; }
183 set { m_regStatus = value; }
193 #region Update Methods
203 public abstract void Update(
int frames);
207 #region Terrain Methods
212 public abstract void LoadWorldMap();
221 ITerrainModule terrModule = RequestModuleInterface<ITerrainModule>();
222 if (terrModule != null)
224 terrModule.PushTerrain(RemoteClient);
230 #region Add/Remove Agent/Avatar
234 public abstract bool CloseAgent(UUID agentID,
bool force);
238 scenePresence = null;
240 if (TryGetScenePresence(agentID, out sp))
255 public abstract bool TryGetScenePresence(UUID agentID, out
ScenePresence scenePresence);
267 public abstract void OtherRegionUp(
GridRegion otherRegion);
271 return "OpenSimulator Server";
285 EventManager.TriggerShutdown();
289 m_log.Error(string.Format(
"[SCENE]: SceneBase.cs: Close() - Failed with exception ", e));
303 _primAllocateMutex.WaitOne();
304 myID = ++m_lastAllocatedLocalId;
305 _primAllocateMutex.ReleaseMutex();
310 #region Module Methods
319 if (!RegionModules.ContainsKey(name))
321 RegionModules.Add(name, module);
327 RegionModules.Remove(name);
336 lock (m_moduleCommanders)
338 m_moduleCommanders.Add(commander.Name, commander);
348 lock (m_moduleCommanders)
351 if (m_moduleCommanders.TryGetValue(name, out commander))
352 m_moduleCommanders.Remove(name);
363 lock (m_moduleCommanders)
365 if (m_moduleCommanders.ContainsKey(name))
366 return m_moduleCommanders[name];
374 return m_moduleCommanders;
379 List<UUID> ret =
new List<UUID>(FormatsOffered);
389 IAgentStatefulModule m = (IAgentStatefulModule)mod;
391 List<UUID> renderFormats = m.GetRenderStateFormats();
392 List<UUID> acceptFormats = m.GetAcceptStateFormats();
394 foreach (
UUID render
in renderFormats)
396 if (!(FormatsOffered.Contains(render)))
397 FormatsOffered.Add(render);
400 if (acceptFormats.Count == 0)
403 if (FormatsWanted.ContainsKey(mod))
406 FormatsWanted[mod] = acceptFormats;
415 public void RegisterModuleInterface<M>(M mod)
419 List<Object> l = null;
420 if (!ModuleInterfaces.TryGetValue(typeof(M), out l))
422 l =
new List<Object>();
423 ModuleInterfaces.Add(typeof(M), l);
431 CheckAndAddAgentDataFormats(mod);
435 IEntityCreator entityCreator = (IEntityCreator)mod;
436 foreach (PCode pcode
in entityCreator.CreationCapabilities)
438 m_entityCreators[pcode] = entityCreator;
443 public void UnregisterModuleInterface<M>(M mod)
454 if (ModuleInterfaces.TryGetValue(typeof(M), out l))
460 IEntityCreator entityCreator = (IEntityCreator)mod;
461 foreach (PCode pcode
in entityCreator.CreationCapabilities)
463 m_entityCreators[pcode] = null;
470 public void StackModuleInterface<M>(M mod)
473 if (ModuleInterfaces.ContainsKey(typeof(M)))
474 l = ModuleInterfaces[typeof(M)];
476 l =
new List<Object>();
483 CheckAndAddAgentDataFormats(mod);
487 IEntityCreator entityCreator = (IEntityCreator)mod;
488 foreach (PCode pcode
in entityCreator.CreationCapabilities)
490 m_entityCreators[pcode] = entityCreator;
494 ModuleInterfaces[typeof(M)] = l;
501 public T RequestModuleInterface<T>()
503 if (ModuleInterfaces.ContainsKey(typeof(T)) &&
504 (ModuleInterfaces[typeof(T)].Count > 0))
505 return (T)ModuleInterfaces[typeof(T)][0];
514 public T[] RequestModuleInterfaces<T>()
516 if (ModuleInterfaces.ContainsKey(typeof(T)))
518 List<T> ret =
new List<T>();
520 foreach (
Object o
in ModuleInterfaces[typeof(T)])
522 return ret.ToArray();
542 AddCommand(module, command, shorthelp, longhelp,
string.Empty, callback);
562 AddCommand(category, module, command, shorthelp, longhelp,
string.Empty, callback);
576 string moduleName =
"";
579 moduleName = module.Name;
581 AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
598 string shorthelp,
string longhelp,
string descriptivehelp,
CommandDelegate callback)
608 MainConsole.Instance.Commands.AddCommand(
609 category, shared, command, shorthelp, longhelp, descriptivehelp, callback);
617 public virtual bool AllowScriptCrossings
619 get {
return false; }
629 restart handlerPhysicsCrash = OnRestart;
630 if (handlerPhysicsCrash != null)
634 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep);
uint AllocateLocalId()
Returns a new unallocated local ID
OpenSim.Services.Interfaces.GridRegion GridRegion
void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
Call this from a region module to add a command to the OpenSim console.
ICommander GetCommander(string name)
Get a module commander
void AddRegionModule(string name, IRegionModuleBase module)
Add a region-module to this scene. TODO: This will replace AddModule in the future.
delegate void CommandDelegate(string module, string[] cmd)
EventManager m_eventManager
Dictionary< string, ICommander > GetCommanders()
virtual void Start()
Start the scene and associated scripts within it.
ITerrainChannel Heightmap
virtual IConfigSource GetConfig()
bool TryGetScenePresence(UUID agentID, out object scenePresence)
void UnregisterModuleCommander(string name)
Unregister a module commander and all its commands
virtual void SendLayerData(IClientAPI RemoteClient)
Send the region heightmap to the client
void RegisterModuleCommander(ICommander commander)
Register a module commander.
PresenceType
Indicate the type of ScenePresence.
virtual ISceneObject DeserializeObject(string representation)
virtual string GetSimulatorVersion()
static ICommandConsole Instance
void AddCommand(string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
Call this from a region module to add a command to the OpenSim console.
Interface to a class that is capable of creating entities
SceneBase(RegionInfo regInfo)
delegate void restart(RegionInfo thisRegion)
A class for triggering remote scene events.
virtual void Close()
Tidy before shutdown
Maps from client AgentID and RemoteEndPoint values to IClientAPI references for all of the connected ...
void AddCommand(string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
Call this from a region module to add a command to the OpenSim console.
ScenePermissions m_permissions
void CheckAndAddAgentDataFormats(object mod)
OpenSim.Services.Interfaces.GridRegion GridRegion
void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
Call this from a region module to add a command to the OpenSim console.
List< UUID > GetFormatsOffered()
void RemoveRegionModule(string name)